diff options
3 files changed, 150 insertions, 2 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java index 27944c92..22f56f35 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java @@ -1,4 +1,4 @@ - package io.github.moulberry.notenoughupdates.commands.dev; +package io.github.moulberry.notenoughupdates.commands.dev; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.commands.ClientCommandBase; @@ -10,6 +10,7 @@ import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.Specia import io.github.moulberry.notenoughupdates.miscgui.GuiPriceGraph; import io.github.moulberry.notenoughupdates.util.SBInfo; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.util.BlockPos; @@ -24,7 +25,17 @@ import java.util.List; public class DevTestCommand extends ClientCommandBase { private static final List<String> DEV_TESTERS = - Arrays.asList("moulberry", "lucycoconut", "ironm00n", "ariyio", "throwpo", "lrg89", "dediamondpro", "lulonaut", "craftyoldminer"); + Arrays.asList( + "moulberry", + "lucycoconut", + "ironm00n", + "ariyio", + "throwpo", + "lrg89", + "dediamondpro", + "lulonaut", + "craftyoldminer" + ); private static final String[] DEV_FAIL_STRINGS = { "No.", @@ -132,6 +143,16 @@ public class DevTestCommand extends ClientCommandBase { "I would never search")); return; } + if (args.length == 2 && args[0].equalsIgnoreCase("openGui")) { + try { + NotEnoughUpdates.INSTANCE.openGui = (GuiScreen) Class.forName(args[1]).newInstance(); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( + "Opening gui: " + NotEnoughUpdates.INSTANCE.openGui)); + } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | ClassCastException e) { + e.printStackTrace(); + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("Failed to open this gui.")); + } + } if (args.length == 1 && args[0].equalsIgnoreCase("center")) { double x = Math.floor(Minecraft.getMinecraft().thePlayer.posX) + 0.5f; double z = Math.floor(Minecraft.getMinecraft().thePlayer.posZ) + 0.5f; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiNavigation.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiNavigation.java new file mode 100644 index 00000000..cd71ec1a --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiNavigation.java @@ -0,0 +1,127 @@ +package io.github.moulberry.notenoughupdates.miscgui; + +import io.github.moulberry.notenoughupdates.core.GuiElementTextField; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.util.ResourceLocation; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +public class GuiNavigation extends GuiScreen { + + public static ResourceLocation BACKGROUND = new ResourceLocation( + "notenoughupdates", + "textures/gui/navigation.png" + ); + + public static final int PIN_POSITION_U = 182; + public static final int PIN_POSITION_V = 3; + public static final int TICK_POSITION_U = 182; + public static final int TICK_POSITION_V = 34; + public static final int ICON_SIZE = 26; + + public static final int SEARCH_BAR_X = 14; + public static final int SEARCH_BAR_Y = 11; + public static final int SEARCH_BAR_WIDTH = 151; + public static final int SEARCH_BAR_HEIGHT = 24; + + public static final int LIST_START_X = 14; + public static final int LIST_START_Y = 43; + public static final int LIST_OFFSET_Y = 28; + public static final int TEXT_OFFSET_X = 28; + public static final int LIST_COUNT = 6; + + List<String> mockNpcs = Arrays.asList( + "hoho", + "§aOphelia (NPC)", + "§lN" + ); + List<String> result = new ArrayList<>(); + + public int xSize = 176; + public int ySize = 222; + public int guiLeft, guiTop; + + public GuiElementTextField textField = new GuiElementTextField("", SEARCH_BAR_WIDTH, SEARCH_BAR_HEIGHT, 0); + + @Override + public void initGui() { + super.initGui(); + guiLeft = (width - xSize) / 2; + guiTop = (height - ySize) / 2; + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + drawDefaultBackground(); + Minecraft.getMinecraft().getTextureManager().bindTexture(BACKGROUND); + this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); + textField.render(guiLeft + SEARCH_BAR_X, guiTop + SEARCH_BAR_Y); + + refreshResults(); + for (int i = 0; i < LIST_COUNT; i++) { + if (i < result.size()) { + Minecraft.getMinecraft().getTextureManager().bindTexture(BACKGROUND); + String text = result.get(i); + boolean selected = text.equals("hoho"); + int baseX = guiLeft + LIST_START_X; + int baseY = guiTop + LIST_START_Y + LIST_OFFSET_Y * i; + + GlStateManager.color(1F, 1F, 1F); + drawTexturedModalRect( + baseX, + baseY, + selected ? TICK_POSITION_U : PIN_POSITION_U, selected ? TICK_POSITION_V : PIN_POSITION_V, + ICON_SIZE, ICON_SIZE + ); + Utils.drawStringF( + text, + Minecraft.getMinecraft().fontRendererObj, + baseX + TEXT_OFFSET_X, + baseY + LIST_OFFSET_Y / 2F - Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT / 2F, + false, + 0x000000 + ); + } + } + } + + private void refreshResults() { + String text = textField.getText().toLowerCase(); + result = mockNpcs + .stream() + .filter(it -> it.toLowerCase().contains(text.toLowerCase())) + .sorted(Comparator.comparing(String::length).thenComparing(String.CASE_INSENSITIVE_ORDER)) + .collect(Collectors.toList()); + } + + @Override + protected void keyTyped(char p_keyTyped_1_, int p_keyTyped_2_) throws IOException { + super.keyTyped(p_keyTyped_1_, p_keyTyped_2_); + textField.keyTyped(p_keyTyped_1_, p_keyTyped_2_); + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + super.mouseClicked(mouseX, mouseY, mouseButton); + if (Utils.isWithinRect( + mouseX, + mouseY, + guiLeft + SEARCH_BAR_X, + guiTop + SEARCH_BAR_Y, + SEARCH_BAR_WIDTH, + SEARCH_BAR_HEIGHT + )) { + textField.mouseClicked(mouseX, mouseY, mouseButton); + } else { + textField.setFocus(false); + } + } +} diff --git a/src/main/resources/assets/notenoughupdates/textures/gui/navigation.png b/src/main/resources/assets/notenoughupdates/textures/gui/navigation.png Binary files differnew file mode 100644 index 00000000..137dd3c5 --- /dev/null +++ b/src/main/resources/assets/notenoughupdates/textures/gui/navigation.png |