diff options
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java')
| -rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java | 5411 |
1 files changed, 2796 insertions, 2615 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java index 2d5c6e1d..d1bfed14 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java @@ -74,2619 +74,2800 @@ import java.util.concurrent.atomic.AtomicReference; import static io.github.moulberry.notenoughupdates.util.GuiTextures.*; public class NEUOverlay extends Gui { - private static final ResourceLocation SUPERGEHEIMNISVERMOGEN = new ResourceLocation("notenoughupdates:supersecretassets/bald.png"); - private static final ResourceLocation SEARCH_BAR = new ResourceLocation("notenoughupdates:search_bar.png"); - private static final ResourceLocation SEARCH_BAR_GOLD = new ResourceLocation("notenoughupdates:search_bar_gold.png"); - - private static final ResourceLocation ARMOR_DISPLAY = new ResourceLocation("notenoughupdates:armordisplay/armordisplay.png"); - private static final ResourceLocation ARMOR_DISPLAY_GREY = new ResourceLocation("notenoughupdates:armordisplay/armordisplay_grey.png"); - private static final ResourceLocation ARMOR_DISPLAY_DARK = new ResourceLocation("notenoughupdates:armordisplay/armordisplay_phq_dark.png"); - private static final ResourceLocation ARMOR_DISPLAY_FSR = new ResourceLocation("notenoughupdates:armordisplay/armordisplay_fsr.png"); - private static final ResourceLocation ARMOR_DISPLAY_TRANSPARENT = new ResourceLocation("notenoughupdates:armordisplay/armordisplay_transparent.png"); - private static final ResourceLocation ARMOR_DISPLAY_TRANSPARENT_PET = new ResourceLocation("notenoughupdates:armordisplay/armordisplay_transparent_pet.png"); - - private static final ResourceLocation QUESTION_MARK = new ResourceLocation("notenoughupdates:pv_unknown.png"); - - private static final ResourceLocation PET_DISPLAY = new ResourceLocation("notenoughupdates:petdisplay/petdisplaysolo.png"); - private static final ResourceLocation PET_DISPLAY_GREY = new ResourceLocation("notenoughupdates:petdisplay/petdisplaysolo_dark.png"); - private static final ResourceLocation PET_DISPLAY_DARK = new ResourceLocation("notenoughupdates:petdisplay/petdisplaysolo_phqdark.png"); - private static final ResourceLocation PET_DISPLAY_FSR = new ResourceLocation("notenoughupdates:petdisplay/petdisplaysolo_fsr.png"); - private static final ResourceLocation PET_DISPLAY_TRANSPARENT = new ResourceLocation("notenoughupdates:petdisplay/petdisplaysolo_transparent.png"); - - - private static final ResourceLocation PET_ARMOR_DISPLAY = new ResourceLocation("notenoughupdates:petdisplay/petdisplayarmor.png"); - private static final ResourceLocation PET_ARMOR_DISPLAY_GREY = new ResourceLocation("notenoughupdates:petdisplay/petdisplayarmor_dark.png"); - private static final ResourceLocation PET_ARMOR_DISPLAY_DARK = new ResourceLocation("notenoughupdates:petdisplay/petdisplayarmor_phqdark.png"); - private static final ResourceLocation PET_ARMOR_DISPLAY_FSR = new ResourceLocation("notenoughupdates:petdisplay/petdisplayarmor_fsr.png"); - private static final ResourceLocation PET_ARMOR_DISPLAY_TRANSPARENT = new ResourceLocation("notenoughupdates:petdisplay/petdisplayarmor_transparent.png"); - - private static boolean renderingArmorHud; - private static boolean renderingPetHud; - public static boolean shouldUseCachedPet; - public static long cachedPetTimer; - - private final NEUManager manager; - - private final String mobRegex = ".*?((_MONSTER)|(_ANIMAL)|(_MINIBOSS)|(_BOSS)|(_SC))$"; - private final String petRegex = ".*?;[0-5]$"; - - private final ResourceLocation[] sortIcons = new ResourceLocation[]{ - sort_all, sort_mob, sort_pet, sort_tool, sort_armor, sort_accessory - }; - private final ResourceLocation[] sortIconsActive = new ResourceLocation[]{ - sort_all_active, sort_mob_active, sort_pet_active, sort_tool_active, sort_armor_active, sort_accessory_active - }; - - private final ResourceLocation[] orderIcons = new ResourceLocation[]{ - order_alphabetical, order_rarity, order_value - }; - private final ResourceLocation[] orderIconsActive = new ResourceLocation[]{ - order_alphabetical_active, order_rarity_active, order_value_active - }; - - //Various constants used for GUI structure - private final int searchBarYOffset = 10; - private final int searchBarPadding = 2; - private long lastSearchMode = 0; - - private float oldWidthMult = 0; - - public static final int ITEM_PADDING = 4; - public static final int ITEM_SIZE = 16; - - private Color bg = new Color(90, 90, 140, 50); - private Color fg = new Color(100, 100, 100, 255); - - private InfoPane activeInfoPane = null; - - private TreeSet<JsonObject> searchedItems = null; - private final List<JsonObject> searchedItemsArr = new ArrayList<>(); - - private HashMap<String, List<String>> searchedItemsSubgroup = new HashMap<>(); - - private long selectedItemMillis = 0; - private int selectedItemGroupX = -1; - private int selectedItemGroupY = -1; - private List<JsonObject> selectedItemGroup = null; - - private boolean itemPaneOpen = false; - - private int page = 0; - - private final LerpingFloat itemPaneOffsetFactor = new LerpingFloat(1); - private final LerpingInteger itemPaneTabOffset = new LerpingInteger(20, 50); - private final LerpingFloat infoPaneOffsetFactor = new LerpingFloat(0); - - public boolean searchMode = false; - private long millisLastLeftClick = 0; - private long millisLastMouseMove = 0; - private int lastMouseX = 0; - private int lastMouseY = 0; - - public static final int overlayColourDark = new Color(0, 0, 0, 120).getRGB(); - public static final int overlayColourLight = new Color(255, 255, 255, 120).getRGB(); - - boolean mouseDown = false; - - private boolean redrawItems = false; - - private boolean searchBarHasFocus = false; - private final GuiTextField textField = new GuiTextField(0, null, 0, 0, 0, 0); - - private static final int COMPARE_MODE_ALPHABETICAL = 0; - private static final int COMPARE_MODE_RARITY = 1; - private static final int COMPARE_MODE_VALUE = 2; - - private static final int SORT_MODE_ALL = 0; - private static final int SORT_MODE_MOB = 1; - private static final int SORT_MODE_PET = 2; - private static final int SORT_MODE_TOOL = 3; - private static final int SORT_MODE_ARMOR = 4; - private static final int SORT_MODE_ACCESSORY = 5; - - private boolean disabled = false; - - private int lastScreenWidth; - private int lastScreenHeight; - private int lastScale; - - private CompletableFuture<Void> infoPaneLoadingJob = CompletableFuture.completedFuture(null); - - private List<String> textToDisplay = null; - - public MBGuiGroupFloating guiGroup = null; - - public NEUOverlay(NEUManager manager) { - this.manager = manager; - textField.setFocused(true); - textField.setCanLoseFocus(false); - - guiGroup = createGuiGroup(); - } - - private MBGuiElement createSearchBar() { - return new MBGuiElement() { - public int getWidth() { - int paddingUnscaled = getPaddingUnscaled(); - - return getSearchBarXSize() + 2 * paddingUnscaled; - } - - public int getHeight() { - int paddingUnscaled = getPaddingUnscaled(); - - return getSearchBarYSize() + 2 * paddingUnscaled; - } - - @Override - public void mouseClick(float x, float y, int mouseX, int mouseY) { - if (!NotEnoughUpdates.INSTANCE.config.toolbar.searchBar) { - return; - } - if (Mouse.getEventButtonState()) { - setSearchBarFocus(true); - if (Mouse.getEventButton() == 1) { //Right mouse button down - textField.setText(""); - updateSearch(); - } else { - if (System.currentTimeMillis() - millisLastLeftClick < 300) { - searchMode = !searchMode; - lastSearchMode = System.currentTimeMillis(); - if (searchMode && NotEnoughUpdates.INSTANCE.config.hidden.firstTimeSearchFocus) { - NEUEventListener.displayNotification(Lists.newArrayList( - "\u00a7eSearch Highlight", - "\u00a77In this mode NEU will gray out non matching items in", - "\u00a77your inventory or chests.", - "\u00a77This allows you easily find items as the item will stand out.", - "\u00a77To toggle this please double click on the search bar in your inventory.", - "\u00a77", - "\u00a77Press X on your keyboard to close this notification"), true, true); - NotEnoughUpdates.INSTANCE.config.hidden.firstTimeSearchFocus = false; - - } - } - textField.setCursorPosition(getClickedIndex(mouseX, mouseY)); - millisLastLeftClick = System.currentTimeMillis(); - if (searchMode) { - lastSearchMode = System.currentTimeMillis(); - } - } - } - } - - @Override - public void mouseClickOutside() { - setSearchBarFocus(false); - } - - @Override - public void render(float x, float y) { - if (!NotEnoughUpdates.INSTANCE.config.toolbar.searchBar) { - return; - } - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - int paddingUnscaled = getPaddingUnscaled(); - - GlStateManager.color(1, 1, 1, 1); - - Minecraft.getMinecraft().getTextureManager().bindTexture(searchMode ? SEARCH_BAR_GOLD : SEARCH_BAR); - - int w = getWidth(); - int h = getHeight(); - - for (int yIndex = 0; yIndex <= 2; yIndex++) { - for (int xIndex = 0; xIndex <= 2; xIndex++) { - float uMin = 0; - float uMax = 4 / 20f; - int partX = (int) x; - int partW = 4; - if (xIndex == 1) { - partX += 4; - uMin = 4 / 20f; - uMax = 16 / 20f; - partW = w - 8; - } else if (xIndex == 2) { - partX += w - 4; - uMin = 16 / 20f; - uMax = 20 / 20f; - } - - float vMin = 0; - float vMax = 4 / 20f; - int partY = (int) y; - int partH = 4; - if (yIndex == 1) { - partY += 4; - vMin = 4 / 20f; - vMax = 16 / 20f; - partH = h - 8; - } else if (yIndex == 2) { - partY += h - 4; - vMin = 16 / 20f; - vMax = 20 / 20f; - } - - Utils.drawTexturedRect(partX, partY, partW, partH, uMin, uMax, vMin, vMax, GL11.GL_NEAREST); - } - } - - //Search bar text - fr.drawString(textField.getText(), (int) x + 5, - (int) y - 4 + getHeight() / 2, Color.WHITE.getRGB()); - - //Determines position of cursor. Cursor blinks on and off every 500ms. - if (searchBarHasFocus && System.currentTimeMillis() % 1000 > 500) { - String textBeforeCursor = textField.getText().substring(0, textField.getCursorPosition()); - int textBeforeCursorWidth = fr.getStringWidth(textBeforeCursor); - drawRect((int) x + 5 + textBeforeCursorWidth, - (int) y - 5 + getHeight() / 2, - (int) x + 5 + textBeforeCursorWidth + 1, - (int) y - 4 + 9 + getHeight() / 2, Color.WHITE.getRGB()); - } - - String selectedText = textField.getSelectedText(); - if (!selectedText.isEmpty()) { - int selectionWidth = fr.getStringWidth(selectedText); - - int leftIndex = Math.min(textField.getCursorPosition(), textField.getSelectionEnd()); - String textBeforeSelection = textField.getText().substring(0, leftIndex); - int textBeforeSelectionWidth = fr.getStringWidth(textBeforeSelection); - - drawRect((int) x + 5 + textBeforeSelectionWidth, - (int) y - 5 + getHeight() / 2, - (int) x + 5 + textBeforeSelectionWidth + selectionWidth, - (int) y - 4 + 9 + getHeight() / 2, Color.LIGHT_GRAY.getRGB()); - - fr.drawString(selectedText, - (int) x + 5 + textBeforeSelectionWidth, - (int) y - 4 + getHeight() / 2, Color.BLACK.getRGB()); - } - - } - - @Override - public void recalculate() {} - }; - } - - private MBGuiElement createSettingsButton(NEUOverlay overlay) { - return new MBGuiElement() { - @Override - public int getWidth() { - return getSearchBarYSize() + getPaddingUnscaled() * 2; - } - - @Override - public int getHeight() { - return getWidth(); - } - - @Override - public void recalculate() {} - - @Override - public void mouseClick(float x, float y, int mouseX, int mouseY) { - if (!NotEnoughUpdates.INSTANCE.config.toolbar.enableSettingsButton) { - return; - } - if (Mouse.getEventButtonState()) { - NotEnoughUpdates.INSTANCE.openGui = new GuiScreenElementWrapper(NEUConfigEditor.editor); - } - } - - @Override - public void mouseClickOutside() {} - - @Override - public void render(float x, float y) { - int paddingUnscaled = getPaddingUnscaled(); - int searchYSize = getSearchBarYSize(); - - if (!NotEnoughUpdates.INSTANCE.config.toolbar.enableSettingsButton) { - return; - } - Minecraft.getMinecraft().getTextureManager().bindTexture(quickcommand_background); - GlStateManager.color(1, 1, 1, 1); - Utils.drawTexturedRect(x, y, - searchYSize + paddingUnscaled * 2, searchYSize + paddingUnscaled * 2, GL11.GL_NEAREST); - - Minecraft.getMinecraft().getTextureManager().bindTexture(settings); - GlStateManager.color(1f, 1f, 1f, 1f); - Utils.drawTexturedRect((int) x + paddingUnscaled, (int) y + paddingUnscaled, - searchYSize, searchYSize); - - GlStateManager.bindTexture(0); - } - }; - } - - private MBGuiElement createHelpButton(NEUOverlay overlay) { - return new MBGuiElement() { - @Override - public int getWidth() { - return getSearchBarYSize() + getPaddingUnscaled() * 2; - } - - @Override - public int getHeight() { - return getWidth(); - } - - @Override - public void recalculate() {} - - @Override - public void mouseClick(float x, float y, int mouseX, int mouseY) { - if (!NotEnoughUpdates.INSTANCE.config.toolbar.enableHelpButton) { - return; - } - if (Mouse.getEventButtonState()) { - //displayInformationPane(HTMLInfoPane.createFromWikiUrl(overlay, manager, "Help", - // "https://moulberry.github.io/files/neu_help.html")); - //Minecraft.getMinecraft().displayGuiScreen(new HelpGUI()); - ClientCommandHandler.instance.executeCommand(Minecraft.getMinecraft().thePlayer, "/neuhelp"); - Utils.playPressSound(); - } - } - - @Override - public void mouseClickOutside() {} - - @Override - public void render(float x, float y) { - int paddingUnscaled = getPaddingUnscaled(); - int searchYSize = getSearchBarYSize(); - - if (!NotEnoughUpdates.INSTANCE.config.toolbar.enableHelpButton) { - return; - } - - Minecraft.getMinecraft().getTextureManager().bindTexture(quickcommand_background); - GlStateManager.color(1, 1, 1, 1); - Utils.drawTexturedRect(x, y, - searchYSize + paddingUnscaled * 2, searchYSize + paddingUnscaled * 2, GL11.GL_NEAREST); - - Minecraft.getMinecraft().getTextureManager().bindTexture(help); - GlStateManager.color(1f, 1f, 1f, 1f); - Utils.drawTexturedRect((int) x + paddingUnscaled, (int) y + paddingUnscaled, - getSearchBarYSize(), getSearchBarYSize()); - GlStateManager.bindTexture(0); - - } - }; - } - - private MBGuiElement createQuickCommand(String quickCommandStr) { - return new MBGuiElement() { - @Override - public int getWidth() { - return getSearchBarYSize() + getPaddingUnscaled() * 2; - } - - @Override - public int getHeight() { - return getWidth(); - } - - @Override - public void recalculate() {} - - @Override - public void mouseClick(float x, float y, int mouseX, int mouseY) { - if (!NotEnoughUpdates.INSTANCE.config.toolbar.quickCommands) return; - - if ((NotEnoughUpdates.INSTANCE.config.toolbar.quickCommandsClickType != 0 && Mouse.getEventButtonState()) || - (NotEnoughUpdates.INSTANCE.config.toolbar.quickCommandsClickType == 0 && !Mouse.getEventButtonState() && Mouse.getEventButton() != -1)) { - if (quickCommandStr.contains(":")) { - String command = quickCommandStr.split(":")[0].trim(); - if (command.startsWith("/")) { - NotEnoughUpdates.INSTANCE.sendChatMessage(command); - } else { - ClientCommandHandler.instance.executeCommand(Minecraft.getMinecraft().thePlayer, "/" + command); - } - Utils.playPressSound(); - } - } - } - - @Override - public void mouseClickOutside() {} - - @Override - public void render(float x, float y) { - if (!NotEnoughUpdates.INSTANCE.config.toolbar.quickCommands) return; - - int paddingUnscaled = getPaddingUnscaled(); - int bigItemSize = getSearchBarYSize(); - - String[] quickCommandStrSplit = quickCommandStr.split(":"); - if (quickCommandStrSplit.length != 3) { - return; - } - String display = quickCommandStrSplit[2]; - ItemStack render = null; - float extraScale = 1; - if (display.length() > 20) { //Custom head - render = new ItemStack(Items.skull, 1, 3); - NBTTagCompound nbt = new NBTTagCompound(); - NBTTagCompound skullOwner = new NBTTagCompound(); - NBTTagCompound properties = new NBTTagCompound(); - NBTTagList textures = new NBTTagList(); - NBTTagCompound textures_0 = new NBTTagCompound(); - - String uuid = UUID.nameUUIDFromBytes(display.getBytes()).toString(); - skullOwner.setString("Id", uuid); - skullOwner.setString("Name", uuid); - - textures_0.setString("Value", display); - textures.appendTag(textures_0); - - properties.setTag("textures", textures); - skullOwner.setTag("Properties", properties); - nbt.setTag("SkullOwner", skullOwner); - render.setTagCompound(nbt); - - extraScale = 1.3f; - } else if (manager.getItemInformation().containsKey(display)) { - render = manager.jsonToStack(manager.getItemInformation().get(display), true, true); - } else { - Item item = Item.itemRegistry.getObject(new ResourceLocation(display.toLowerCase())); - if (item != null) { - render = new ItemStack(item); - } - } - if (render != null) { - NBTTagCompound tag = render.getTagCompound() != null ? render.getTagCompound() : new NBTTagCompound(); - tag.setString("qc_id", quickCommandStrSplit[0].toLowerCase().trim()); - render.setTagCompound(tag); - - Minecraft.getMinecraft().getTextureManager().bindTexture(quickcommand_background); - GlStateManager.color(1, 1, 1, 1); - Utils.drawTexturedRect(x, y, - bigItemSize + paddingUnscaled * 2, bigItemSize + paddingUnscaled * 2, GL11.GL_NEAREST); - - int mouseX = Mouse.getX() * Utils.peekGuiScale().getScaledWidth() / Minecraft.getMinecraft().displayWidth; - int mouseY = Utils.peekGuiScale().getScaledHeight() - Mouse.getY() * Utils.peekGuiScale().getScaledHeight() / Minecraft.getMinecraft().displayHeight - 1; - - if (mouseX > x && mouseX < x + bigItemSize) { - if (mouseY > y && mouseY < y + bigItemSize) { - textToDisplay = new ArrayList<>(); - textToDisplay.add(EnumChatFormatting.GRAY + quickCommandStrSplit[1]); - } - } - - GlStateManager.enableDepth(); - float itemScale = bigItemSize / (float) ITEM_SIZE * extraScale; - GlStateManager.pushMatrix(); - GlStateManager.scale(itemScale, itemScale, 1); - GlStateManager.translate((x - (extraScale - 1) * bigItemSize / 2 + paddingUnscaled) / itemScale, - (y - (extraScale - 1) * bigItemSize / 2 + paddingUnscaled) / itemScale, 0f); - Utils.drawItemStack(render, 0, 0); - GlStateManager.popMatrix(); - } - } - }; - } - - private MBGuiGroupAligned createQuickCommandGroup() { - List<MBGuiElement> children = new ArrayList<>(); - for (String quickCommand : NotEnoughUpdates.INSTANCE.config.hidden.quickCommands) { - children.add(createQuickCommand(quickCommand)); - } - return new MBGuiGroupAligned(children, false) { - public int getPadding() { - return getPaddingUnscaled() * 4; - } - }; - } - - private MBGuiGroupAligned createSearchBarGroup() { - List<MBGuiElement> children = Lists.newArrayList(createSettingsButton(this), createSearchBar(), createHelpButton(this)); - return new MBGuiGroupAligned(children, false) { - public int getPadding() { - return getPaddingUnscaled() * 4; - } - }; - } - - private MBGuiGroupFloating createGuiGroup() { - LinkedHashMap<MBGuiElement, MBAnchorPoint> map = new LinkedHashMap<>(); - - MBAnchorPoint searchBarAnchor = MBAnchorPoint.createFromString(NotEnoughUpdates.INSTANCE.config.hidden.overlaySearchBar); - MBAnchorPoint quickCommandAnchor = MBAnchorPoint.createFromString(NotEnoughUpdates.INSTANCE.config.hidden.overlayQuickCommand); - - searchBarAnchor = searchBarAnchor != null ? searchBarAnchor : - new MBAnchorPoint(MBAnchorPoint.AnchorPoint.BOTMID, new Vector2f(0, -searchBarYOffset)); - quickCommandAnchor = quickCommandAnchor != null ? quickCommandAnchor : - new MBAnchorPoint(MBAnchorPoint.AnchorPoint.BOTMID, new Vector2f(0, - -searchBarYOffset - getSearchBarYSize() - getPaddingUnscaled() * 4)); - - map.put(createSearchBarGroup(), searchBarAnchor); - map.put(createQuickCommandGroup(), quickCommandAnchor); - - return new MBGuiGroupFloating(Utils.peekGuiScale().getScaledWidth(), Utils.peekGuiScale().getScaledHeight(), map); - } - - public void resetAnchors(boolean onlyIfNull) { - MBAnchorPoint searchBarAnchor = MBAnchorPoint.createFromString(NotEnoughUpdates.INSTANCE.config.hidden.overlaySearchBar); - MBAnchorPoint quickCommandAnchor = MBAnchorPoint.createFromString(NotEnoughUpdates.INSTANCE.config.hidden.overlayQuickCommand); - - if (onlyIfNull) { - searchBarAnchor = searchBarAnchor != null ? null : - new MBAnchorPoint(MBAnchorPoint.AnchorPoint.BOTMID, new Vector2f(0, -searchBarYOffset)); - quickCommandAnchor = quickCommandAnchor != null ? null : - new MBAnchorPoint(MBAnchorPoint.AnchorPoint.BOTMID, new Vector2f(0, - -searchBarYOffset - getSearchBarYSize() - getPaddingUnscaled() * 4)); - } else { - searchBarAnchor = searchBarAnchor != null ? searchBarAnchor : - new MBAnchorPoint(MBAnchorPoint.AnchorPoint.BOTMID, new Vector2f(0, -searchBarYOffset)); - quickCommandAnchor = quickCommandAnchor != null ? quickCommandAnchor : - new MBAnchorPoint(MBAnchorPoint.AnchorPoint.BOTMID, new Vector2f(0, - -searchBarYOffset - getSearchBarYSize() - getPaddingUnscaled() * 4)); - } - - int index = 0; - Set<MBGuiElement> set = new LinkedHashSet<>(guiGroup.getChildrenMap().keySet()); - for (MBGuiElement element : set) { - switch (index) { - case 0: - if (searchBarAnchor == null) continue; - guiGroup.getChildrenMap().get(element).anchorPoint = searchBarAnchor.anchorPoint; - guiGroup.getChildrenMap().get(element).offset = searchBarAnchor.offset; - break; - case 1: - if (quickCommandAnchor == null) continue; - guiGroup.getChildrenMap().get(element).anchorPoint = quickCommandAnchor.anchorPoint; - guiGroup.getChildrenMap().get(element).offset = quickCommandAnchor.offset; - break; - } - index++; - } - } - - /** - * Disables searchBarFocus and resets the item pane position. Called whenever NEUOverlay is opened. - */ - public void reset() { - searchBarHasFocus = false; - if (!(searchMode || (NotEnoughUpdates.INSTANCE.config.itemlist.keepopen && itemPaneOpen))) { - itemPaneOpen = false; - displayInformationPane(null); - itemPaneOffsetFactor.setValue(1); - itemPaneTabOffset.setValue(20); - } - if (activeInfoPane != null) activeInfoPane.reset(); - guiGroup.recalculate(); - } - - /** - * Calls #displayInformationPane with a HTMLInfoPane created from item.info and item.infoType. - */ - public void showInfo(JsonObject item) { - if (item.has("info") && item.has("infoType")) { - JsonArray lore = item.get("info").getAsJsonArray(); - StringBuilder loreBuilder = new StringBuilder(); - for (int i = 0; i < lore.size(); i++) { - loreBuilder.append(lore.get(i).getAsString()); - if (i != lore.size() - 1) - loreBuilder.append("\n"); - } - String infoText = loreBuilder.toString(); - String internalname = item.get("internalname").getAsString(); - String name = item.get("displayname").getAsString(); - String infoType = item.get("infoType").getAsString(); - displayInformationPane(new TextInfoPane(this, manager, "Loading", "Loading your requested information about " + name + ".")); - infoPaneLoadingJob = InfoPane.create(this, manager, infoType, name, internalname, infoText) - .thenAccept(this::displayInformationPane); - } - } - - public void mouseInputInv() { - if (Minecraft.getMinecraft().currentScreen instanceof GuiContainer) { - if (Mouse.getEventButton() == manager.keybindItemSelect.getKeyCode() + 100 && NotEnoughUpdates.INSTANCE.config.toolbar.searchBar) { - Slot slot = Utils.getSlotUnderMouse((GuiContainer) Minecraft.getMinecraft().currentScreen); - if (slot != null) { - ItemStack hover = slot.getStack(); - if (hover != null) { - textField.setText("id:" + manager.getInternalNameForItem(hover)); - itemPaneOpen = true; - updateSearch(); - } - } - } - } - } - - /** - * Handles the mouse input, cancelling the forge event if a NEU gui element is clicked. - */ - public boolean mouseInput() { - if (disabled) { - return false; - } - - Utils.pushGuiScale(NotEnoughUpdates.INSTANCE.config.itemlist.paneGuiScale); - - int width = Utils.peekGuiScale().getScaledWidth(); - int height = Utils.peekGuiScale().getScaledHeight(); - int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; - int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; - - //if(lastMouseX != mouseX || lastMouseY != mouseY) { - // millisLastMouseMove = System.currentTimeMillis(); - //} - - lastMouseX = mouseX; - lastMouseY = mouseY; - - if (Mouse.getEventButtonState()) { - mouseDown = true; - } else if (Mouse.getEventButton() != -1) { - mouseDown = false; - } - - //Unfocuses the search bar by default. Search bar is focused if the click is on the bar itself. - if (Mouse.getEventButtonState()) setSearchBarFocus(false); - - guiGroup.mouseClick(0, 0, mouseX, mouseY); - - if (selectedItemGroup != null) { - int selectedX = Math.min(selectedItemGroupX, width - getBoxPadding() - 18 * selectedItemGroup.size()); - if (mouseY > selectedItemGroupY + 17 && mouseY < selectedItemGroupY + 35) { - for (int i = 0; i < selectedItemGroup.size(); i++) { - if (mouseX >= selectedX - 1 + 18 * i && mouseX <= selectedX + 17 + 18 * i) { - JsonObject item = selectedItemGroup.get(i); - if (item != null) { - if (Mouse.getEventButton() == 0) { - manager.showRecipe(item); - } else if (Mouse.getEventButton() == 1) { - showInfo(item); - } else if (Mouse.getEventButton() == manager.keybindItemSelect.getKeyCode() + 100 && NotEnoughUpdates.INSTANCE.config.toolbar.searchBar) { - textField.setText("id:" + item.get("internalname").getAsString()); - updateSearch(); - searchMode = true; - } - } - Utils.pushGuiScale(-1); - return true; - } - } - } - } - - //Item selection (right) gui - if (mouseX > width * getItemPaneOffsetFactor()) { - if (!Mouse.getEventButtonState()) { - Utils.pushGuiScale(-1); - return true; //End early if the mouse isn't pressed, but still cancel event. - } - - AtomicBoolean clickedItem = new AtomicBoolean(false); - iterateItemSlots(new ItemSlotConsumer() { - public void consume(int x, int y, int id) { - if (mouseX >= x - 1 && mouseX <= x + ITEM_SIZE + 1) { - if (mouseY >= y - 1 && mouseY <= y + ITEM_SIZE + 1) { - clickedItem.set(true); - - JsonObject item = getSearchedItemPage(id); - if (item != null) { - if (Mouse.getEventButton() == 0) { - manager.showRecipe(item); - } else if (Mouse.getEventButton() == 1) { - showInfo(item); - } else if (Mouse.getEventButton() == manager.keybindItemSelect.getKeyCode() + 100 && NotEnoughUpdates.INSTANCE.config.toolbar.searchBar) { - textField.setText("id:" + item.get("internalname").getAsString()); - updateSearch(); - searchMode = true; - } - } - } - } - } - }); - if (!clickedItem.get()) { - int paneWidth = (int) (width / 3 * getWidthMult()); - int leftSide = (int) (width * getItemPaneOffsetFactor()); - int rightSide = leftSide + paneWidth - getBoxPadding() - getItemBoxXPadding(); - leftSide = leftSide + getBoxPadding() + getItemBoxXPadding(); - - FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - int maxPages = getMaxPages(); - String name = Utils.peekGuiScale().getScaleFactor() < 4 ? "Page: " : ""; - float maxStrLen = fr.getStringWidth(EnumChatFormatting.BOLD + name + maxPages + "/" + maxPages); - float maxButtonXSize = (rightSide - leftSide + 2 - maxStrLen * 0.5f - 10) / 2f; - int buttonXSize = (int) Math.min(maxButtonXSize, getSearchBarYSize() * 480 / 160f); - int ySize = (int) (buttonXSize / 480f * 160); - int yOffset = (int) ((getSearchBarYSize() - ySize) / 2f); - int top = getBoxPadding() + yOffset; - - if (mouseY >= top && mouseY <= top + ySize) { - int leftPrev = leftSide - 1; - if (mouseX > leftPrev && mouseX < leftPrev + buttonXSize) { //"Previous" button - setPage(page - 1); - Utils.playPressSound(); - } - int leftNext = rightSide + 1 - buttonXSize; - if (mouseX > leftNext && mouseX < leftNext + buttonXSize) { //"Next" button - setPage(page + 1); - Utils.playPressSound(); - } - } - - float sortIconsMinX = (sortIcons.length + orderIcons.length) * (ITEM_SIZE + ITEM_PADDING) + ITEM_SIZE; - float availableX = rightSide - leftSide; - float sortOrderScaleFactor = Math.min(1, availableX / sortIconsMinX); - - int scaledITEM_SIZE = (int) (ITEM_SIZE * sortOrderScaleFactor); - int scaledItemPaddedSize = (int) ((ITEM_SIZE + ITEM_PADDING) * sortOrderScaleFactor); - int iconTop = height - getBoxPadding() - (ITEM_SIZE + scaledITEM_SIZE) / 2 - 1; - - if (mouseY >= iconTop && mouseY <= iconTop + scaledITEM_SIZE) { - for (int i = 0; i < orderIcons.length; i++) { - int orderIconX = leftSide + i * scaledItemPaddedSize; - if (mouseX >= orderIconX && mouseX <= orderIconX + scaledITEM_SIZE) { - if (Mouse.getEventButton() == 0) { - NotEnoughUpdates.INSTANCE.config.hidden.compareMode = i; - updateSearch(); - Utils.playPressSound(); - } else if (Mouse.getEventButton() == 1) { - NotEnoughUpdates.INSTANCE.config.hidden.compareAscending.set(i, - !NotEnoughUpdates.INSTANCE.config.hidden.compareAscending.get(i)); - updateSearch(); - Utils.playPressSound(); - } - } - } - - for (int i = 0; i < sortIcons.length; i++) { - int sortIconX = rightSide - scaledITEM_SIZE - i * scaledItemPaddedSize; - if (mouseX >= sortIconX && mouseX <= sortIconX + scaledITEM_SIZE) { - NotEnoughUpdates.INSTANCE.config.hidden.sortMode = i; - updateSearch(); - Utils.playPressSound(); - } - } - } - } - Utils.pushGuiScale(-1); - return true; - } - - //Clicking on "close info pane" button - if (mouseX > width * getInfoPaneOffsetFactor() - getBoxPadding() - 8 && mouseX < width * getInfoPaneOffsetFactor() - getBoxPadding() + 8) { - if (mouseY > getBoxPadding() - 8 && mouseY < getBoxPadding() + 8) { - if (Mouse.getEventButtonState() && Mouse.getEventButton() < 2) { //Left or right click up - displayInformationPane(null); - Utils.pushGuiScale(-1); - return true; - } - } - } - - if (activeInfoPane != null) { - if (mouseX < width * getInfoPaneOffsetFactor()) { - activeInfoPane.mouseInput(width, height, mouseX, mouseY, mouseDown); - Utils.pushGuiScale(-1); - return true; - } else if (Mouse.getEventButton() <= 1 && Mouse.getEventButtonState()) { //Left or right click - activeInfoPane.mouseInputOutside(); - } - } - - Utils.pushGuiScale(-1); - return false; - } - - public int getPaddingUnscaled() { - int paddingUnscaled = searchBarPadding / Utils.peekGuiScale().getScaleFactor(); - if (paddingUnscaled < 1) paddingUnscaled = 1; - - return paddingUnscaled; - } - - public GuiTextField getTextField() { - return textField; - } - - /** - * Returns searchBarXSize, scaled by 0.8 if gui scale == AUTO. - */ - public int getSearchBarXSize() { - int searchBarXSize = NotEnoughUpdates.INSTANCE.config.toolbar.searchBarWidth; - if (Utils.peekGuiScale().getScaleFactor() == 4) return (int) (searchBarXSize * 0.8); - return searchBarXSize; - } - - /** - * Sets the activeInfoPane and sets the target of the infoPaneOffsetFactor to make the |
