From b09f774d422263ce15b97d6d0804beddf856176d Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Sun, 27 Feb 2022 11:53:57 -0500 Subject: feat: improve formating :) --- .../moulberry/notenoughupdates/NEUOverlay.java | 5411 ++++++++++---------- 1 file changed, 2796 insertions(+), 2615 deletions(-) (limited to 'src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java') 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 searchedItems = null; - private final List searchedItemsArr = new ArrayList<>(); - - private HashMap> searchedItemsSubgroup = new HashMap<>(); - - private long selectedItemMillis = 0; - private int selectedItemGroupX = -1; - private int selectedItemGroupY = -1; - private List 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 infoPaneLoadingJob = CompletableFuture.completedFuture(null); - - private List 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 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 children = Lists.newArrayList(createSettingsButton(this), createSearchBar(), createHelpButton(this)); - return new MBGuiGroupAligned(children, false) { - public int getPadding() { - return getPaddingUnscaled() * 4; - } - }; - } - - private MBGuiGroupFloating createGuiGroup() { - LinkedHashMap 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 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 infoPane "slide" out. - */ - public void displayInformationPane(InfoPane pane) { - infoPaneLoadingJob.cancel(false); - if (pane == null) { - infoPaneOffsetFactor.setTarget(0); - } else { - infoPaneOffsetFactor.setTarget(1 / 3f); - } - infoPaneOffsetFactor.resetTimer(); - this.activeInfoPane = pane; - } - - public InfoPane getActiveInfoPane() { - return activeInfoPane; - } - - /** - * Finds the index of the character inside the search bar that was clicked, used to set the caret. - */ - public int getClickedIndex(int mouseX, int mouseY) { - int width = Utils.peekGuiScale().getScaledWidth(); - int height = Utils.peekGuiScale().getScaledHeight(); - - int xComp = mouseX - (width / 2 - getSearchBarXSize() / 2 + 5); - - String trimmed = Minecraft.getMinecraft().fontRendererObj.trimStringToWidth(textField.getText(), xComp); - int linePos = trimmed.length(); - if (linePos != textField.getText().length()) { - char after = textField.getText().charAt(linePos); - int trimmedWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(trimmed); - int charWidth = Minecraft.getMinecraft().fontRendererObj.getCharWidth(after); - if (trimmedWidth + charWidth / 2 < xComp - 5) { - linePos++; - } - } - return linePos; - } - - public void setSearchBarFocus(boolean focus) { - if (focus) { - itemPaneOpen = true; - } - searchBarHasFocus = focus; - } - - /** - * Handles the keyboard input, cancelling the forge event if the search bar has focus. - */ - public boolean keyboardInput(boolean hoverInv) { - if (Minecraft.getMinecraft().currentScreen == null) return false; - Keyboard.enableRepeatEvents(true); - - int keyPressed = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter() + 256 : Keyboard.getEventKey(); - - if (disabled) { - if (Keyboard.getEventKeyState() && keyPressed == manager.keybindToggleDisplay.getKeyCode()) { - disabled = !disabled; - } - return false; - } - - if (Keyboard.isKeyDown(Keyboard.KEY_Y) && NotEnoughUpdates.INSTANCE.config.hidden.dev) { - displayInformationPane(new DevInfoPane(this, manager)); - } - - if (Keyboard.getEventKeyState()) { - if (!NotEnoughUpdates.INSTANCE.config.toolbar.searchBar) { - searchBarHasFocus = false; - } - if (searchBarHasFocus) { - if (keyPressed == 1) { - searchBarHasFocus = false; - } else { - if (textField.textboxKeyTyped(Keyboard.getEventCharacter(), keyPressed)) { - updateSearch(); - } - } - } else { - if (activeInfoPane != null) { - if (activeInfoPane.keyboardInput()) { - return true; - } - } - - if (keyPressed == manager.keybindClosePanes.getKeyCode()) { - itemPaneOffsetFactor.setValue(1); - itemPaneTabOffset.setValue(20); - itemPaneOpen = false; - displayInformationPane(null); - } - - if (keyPressed == manager.keybindToggleDisplay.getKeyCode()) { - disabled = !disabled; - return true; - } - - AtomicReference internalname = new AtomicReference<>(null); - AtomicReference itemstack = new AtomicReference<>(null); - if (Minecraft.getMinecraft().currentScreen instanceof GuiContainer && - Utils.getSlotUnderMouse((GuiContainer) Minecraft.getMinecraft().currentScreen) != null) { - Slot slot = Utils.getSlotUnderMouse((GuiContainer) Minecraft.getMinecraft().currentScreen); - ItemStack hover = slot.getStack(); - if (hover != null) { - internalname.set(manager.getInternalNameForItem(hover)); - itemstack.set(hover); - } - } else if (!hoverInv) { - 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 (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) { - internalname.set(selectedItemGroup.get(i).get("internalname").getAsString()); - } - } - } - } else { - 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) { - JsonObject json = getSearchedItemPage(id); - if (json != null) internalname.set(json.get("internalname").getAsString()); - } - } - } - }); - } - - Utils.pushGuiScale(-1); - } - if (internalname.get() != null) { - if (itemstack.get() != null) { - if (NotEnoughUpdates.INSTANCE.config.hidden.enableItemEditing && Keyboard.getEventCharacter() == 'k') { - Minecraft.getMinecraft().displayGuiScreen(new NEUItemEditor(manager, - internalname.get(), manager.getJsonForItem(itemstack.get()))); - return true; - } - } - JsonObject item = manager.getItemInformation().get(internalname.get()); - if (item != null) { - if (keyPressed == manager.keybindViewUsages.getKeyCode()) { - manager.displayGuiItemUsages(internalname.get()); - return true; - } else if (keyPressed == manager.keybindFavourite.getKeyCode()) { - toggleFavourite(item.get("internalname").getAsString()); - return true; - } else if (keyPressed == manager.keybindViewRecipe.getKeyCode()) { - manager.showRecipe(item); - return true; - } else if (keyPressed == manager.keybindGive.getKeyCode()) { - if (Minecraft.getMinecraft().thePlayer.capabilities.isCreativeMode) { - Minecraft.getMinecraft().thePlayer.inventory.addItemStackToInventory( - manager.jsonToStack(item)); - } - } else if (NotEnoughUpdates.INSTANCE.config.hidden.enableItemEditing && Keyboard.getEventCharacter() == 'k') { - Minecraft.getMinecraft().displayGuiScreen(new NEUItemEditor(manager, - internalname.get(), item)); - return true; - } else if (keyPressed == manager.keybindItemSelect.getKeyCode() && NotEnoughUpdates.INSTANCE.config.toolbar.searchBar) { - textField.setText("id:" + internalname.get()); - itemPaneOpen = true; - updateSearch(); - } else if (keyPressed == NotEnoughUpdates.INSTANCE.config.ahGraph.graphKey && NotEnoughUpdates.INSTANCE.config.ahGraph.graphEnabled) { - NotEnoughUpdates.INSTANCE.openGui = new GuiPriceGraph(internalname.get()); - return true; - } - } - } - } - } - - return searchBarHasFocus; //Cancels keyboard events if the search bar has focus - } - - public void toggleFavourite(String internalname) { - if (getFavourites().contains(internalname)) { - getFavourites().remove(internalname); - } else { - getFavourites().add(internalname); - } - updateSearch(); - } - - String[] rarityArr = new String[]{ - EnumChatFormatting.WHITE + EnumChatFormatting.BOLD.toString() + "COMMON", - EnumChatFormatting.GREEN + EnumChatFormatting.BOLD.toString() + "UNCOMMON", - EnumChatFormatting.BLUE + EnumChatFormatting.BOLD.toString() + "RARE", - EnumChatFormatting.DARK_PURPLE + EnumChatFormatting.BOLD.toString() + "EPIC", - EnumChatFormatting.GOLD + EnumChatFormatting.BOLD.toString() + "LEGENDARY", - EnumChatFormatting.LIGHT_PURPLE + EnumChatFormatting.BOLD.toString() + "MYTHIC", - EnumChatFormatting.RED + EnumChatFormatting.BOLD.toString() + "SPECIAL", - }; - - /** - * Finds the rarity from the lore of an item. - * -1 = UNKNOWN - * 0 = COMMON - * 1 = UNCOMMON - * 2 = RARE - * 3 = EPIC - * 4 = LEGENDARY - * 5 = MYTHIC - * 6 = SPECIAL - */ - public int getRarity(JsonArray lore) { - for (int i = lore.size() - 1; i >= 0; i--) { - String line = lore.get(i).getAsString(); - - for (int j = 0; j < rarityArr.length; j++) { - if (line.startsWith(rarityArr[j])) { - return j; - } - } - } - return -1; - } - - /** - * Convenience functions that get various compare/sort modes from the config. - */ - private int getCompareMode() { - return NotEnoughUpdates.INSTANCE.config.hidden.compareMode; - } - - private int getSortMode() { - return NotEnoughUpdates.INSTANCE.config.hidden.sortMode; - } - - private List getCompareAscending() { - return NotEnoughUpdates.INSTANCE.config.hidden.compareAscending; - } - - private List getFavourites() { - return NotEnoughUpdates.INSTANCE.config.hidden.favourites; - } - - /** - * Creates an item comparator used to sort the list of items according to the favourite set then compare mode. - * Defaults to alphabetical sorting if the above factors cannot distinguish between two items. - */ - private Comparator getItemComparator() { - return (o1, o2) -> { - //1 (mult) if o1 should appear after o2 - //-1 (-mult) if o2 should appear after o1 - if (getFavourites().contains(o1.get("internalname").getAsString()) && !getFavourites().contains(o2.get("internalname").getAsString())) { - return -1; - } - if (!getFavourites().contains(o1.get("internalname").getAsString()) && getFavourites().contains(o2.get("internalname").getAsString())) { - return 1; - } - - int mult = getCompareAscending().get(getCompareMode()) ? 1 : -1; - if (getCompareMode() == COMPARE_MODE_RARITY) { - int rarity1 = getRarity(o1.get("lore").getAsJsonArray()); - int rarity2 = getRarity(o2.get("lore").getAsJsonArray()); - - if (rarity1 < rarity2) return mult; - if (rarity1 > rarity2) return -mult; - } else if (getCompareMode() == COMPARE_MODE_VALUE) { - String internal1 = o1.get("internalname").getAsString(); - String internal2 = o2.get("internalname").getAsString(); - - float cost1 = manager.auctionManager.getLowestBin(internal1); - float cost2 = manager.auctionManager.getLowestBin(internal2); - - if (cost1 < cost2) return mult; - if (cost1 > cost2) return -mult; - } - - String i1 = o1.get("internalname").getAsString(); - String[] split1 = i1.split("_"); - String last1 = split1[split1.length - 1]; - String start1 = i1.substring(0, i1.length() - last1.length()); - - String i2 = o2.get("internalname").getAsString(); - String[] split2 = i2.split("_"); - String last2 = split2[split2.length - 1]; - String start2 = i2.substring(0, i2.length() - last2.length()); - - mult = getCompareAscending().get(COMPARE_MODE_ALPHABETICAL) ? 1 : -1; - if (start1.equals(start2)) { - String[] order = new String[]{"HELMET", "CHESTPLATE", "LEGGINGS", "BOOTS"}; - int type1 = checkItemType(o1.get("lore").getAsJsonArray(), order); - int type2 = checkItemType(o2.get("lore").getAsJsonArray(), order); - - if (type1 < type2) return -mult; - if (type1 > type2) return mult; - } - - int nameComp = mult * o1.get("displayname").getAsString().replaceAll("(?i)\\u00A7.", "") - .compareTo(o2.get("displayname").getAsString().replaceAll("(?i)\\u00A7.", "")); - if (nameComp != 0) { - return nameComp; - } - return mult * o1.get("internalname").getAsString().compareTo(o2.get("internalname").getAsString()); - }; - } - - /** - * Checks whether an item matches a certain type, i.e. whether the item lore ends in "{rarity} {item type}" - * eg. "SHOVEL" will return >0 for "COMMON SHOVEL", "EPIC SHOVEL", etc. - * - * @return the index of the type that matched, or -1 otherwise. - */ - public int checkItemType(JsonArray lore, String... typeMatches) { - for (int i = lore.size() - 1; i >= 0; i--) { - String line = lore.get(i).getAsString(); - - for (String rarity : rarityArr) { - for (int j = 0; j < typeMatches.length; j++) { - if (line.trim().equals(rarity + " " + typeMatches[j])) { - return j; - } - } - } - } - return -1; - } - - /** - * Checks whether an item matches the current sort mode. - */ - public boolean checkMatchesSort(String internalname, JsonObject item) { - if (!NotEnoughUpdates.INSTANCE.config.itemlist.showVanillaItems && item.has("vanilla") && item.get("vanilla").getAsBoolean()) { - return false; - } - - if (getSortMode() == SORT_MODE_ALL) { - return !internalname.matches(mobRegex); - } else if (getSortMode() == SORT_MODE_MOB) { - return internalname.matches(mobRegex); - } else if (getSortMode() == SORT_MODE_PET) { - return internalname.matches(petRegex) && item.get("displayname").getAsString().contains("["); - } else if (getSortMode() == SORT_MODE_TOOL) { - return checkItemType(item.get("lore").getAsJsonArray(), - "SWORD", "BOW", "AXE", "PICKAXE", "FISHING ROD", "WAND", "SHOVEL", "HOE", "DUNGEON SWORD", "DUNGEON BOW", "DRILL", "GAUNTLET") >= 0; - } else if (getSortMode() == SORT_MODE_ARMOR) { - return checkItemType(item.get("lore").getAsJsonArray(), "HELMET", "CHESTPLATE", "LEGGINGS", "BOOTS", "DUNGEON HELMET", "DUNGEON CHESTPLATE", "DUNGEON LEGGINGS", "DUNGEON BOOTS") >= 0; - } else if (getSortMode() == SORT_MODE_ACCESSORY) { - return checkItemType(item.get("lore").getAsJsonArray(), "ACCESSORY", "HATCCESSORY", "DUNGEON ACCESSORY") >= 0; - } - return true; - } - - private final HashMap parentMap = new HashMap<>(); - - private final ExecutorService searchES = Executors.newSingleThreadExecutor(); - - /** - * Clears the current item list, creating a new TreeSet if necessary. - * Adds all items that match the search AND match the sort mode to the current item list. - * Also adds some easter egg items. (Also I'm very upset if you came here to find them :'( ) - */ - public void updateSearch() { - SunTzu.randomizeQuote(); - - if (searchedItems == null) searchedItems = new TreeSet<>(getItemComparator()); - - searchES.submit(() -> { - TreeSet searchedItems = new TreeSet<>(getItemComparator()); - HashMap> searchedItemsSubgroup = new HashMap<>(); - - Set removeChildItems = new HashSet<>(); - Set itemsMatch = manager.search(textField.getText(), true); - for (String itemname : itemsMatch) { - JsonObject item = manager.getItemInformation().get(itemname); - if (checkMatchesSort(itemname, item)) { - if (Constants.PARENTS != null) { - if (Constants.PARENTS.has(itemname) && Constants.PARENTS.get(itemname).isJsonArray()) { - List children = new ArrayList<>(); - for (JsonElement e : Constants.PARENTS.get(itemname).getAsJsonArray()) { - if (e.isJsonPrimitive()) { - children.add(e.getAsString()); - } - } - children.retainAll(itemsMatch); - for (String child : children) { - removeChildItems.add(manager.getItemInformation().get(child)); - } - searchedItemsSubgroup.put(itemname, children); - } - } - searchedItems.add(item); - } - } - searchedItems.removeAll(removeChildItems); - out: - for (Map.Entry> entry : searchedItemsSubgroup.entrySet()) { - if (searchedItems.contains(manager.getItemInformation().get(entry.getKey()))) { - continue; - } - for (String itemname : entry.getValue()) { - JsonObject item = manager.getItemInformation().get(itemname); - if (item != null) searchedItems.add(item); - } - } - switch (textField.getText().toLowerCase().trim()) { - case "nullzee": - searchedItems.add(CustomItems.NULLZEE); - break; - case "rune": - searchedItems.add(CustomItems.RUNE); - break; - case "2b2t": - searchedItems.add(CustomItems.TWOBEETWOTEE); - break; - case "ducttape": - case "ducttapedigger": - searchedItems.add(CustomItems.DUCTTAPE); - break; - case "thirtyvirus": - searchedItems.add(manager.getItemInformation().get("SPIKED_BAIT")); - break; - case "leocthl": - searchedItems.add(CustomItems.LEOCTHL); - break; - case "spinaxx": - searchedItems.add(CustomItems.SPINAXX); - break; - case "credits": - case "credit": - case "who made this mod": - searchedItems.add(CustomItems.CREDITS); - break; - case "ironmoon": - case "ironm00n": - searchedItems.add(CustomItems.IRONM00N); - break; - case "nopo": - case "nopothegamer": - searchedItems.add(CustomItems.NOPO); - break; - } - - this.searchedItems = searchedItems; - this.searchedItemsSubgroup = searchedItemsSubgroup; - - synchronized (this.searchedItemsArr) { - this.searchedItemsArr.clear(); - } - - redrawItems = true; - }); - } - - /** - * Returns an index-able array containing the elements in searchedItems. - * Whenever searchedItems is updated in updateSearch(), the array is recreated here. - */ - public List getSearchedItems() { - if (searchedItems == null) { - updateSearch(); - return new ArrayList<>(); - } - - if (searchedItems.size() > 0 && searchedItemsArr.size() == 0) { - synchronized (searchedItemsArr) { - searchedItemsArr.addAll(searchedItems); - } - } - return searchedItemsArr; - } - - /** - * Gets the item in searchedItemArr corresponding to the certain index on the current page. - * - * @return item, if the item exists. null, otherwise. - */ - public JsonObject getSearchedItemPage(int index) { - if (index < getSlotsXSize() * getSlotsYSize()) { - int actualIndex = index + getSlotsXSize() * getSlotsYSize() * page; - List searchedItems = getSearchedItems(); - if (actualIndex < searchedItems.size()) { - return searchedItems.get(actualIndex); - } else { - return null; - } - } else { - return null; - } - } - - public int getItemBoxXPadding() { - int width = Utils.peekGuiScale().getScaledWidth(); - return (((int) (width / 3 * getWidthMult()) - 2 * getBoxPadding()) % (ITEM_SIZE + ITEM_PADDING) + ITEM_PADDING) / 2; - } - - public int getBoxPadding() { - double panePadding = Math.max(0, Math.min(20, NotEnoughUpdates.INSTANCE.config.itemlist.panePadding)); - return (int) (panePadding * 2 / Utils.peekGuiScale().getScaleFactor() + 5); - } - - private abstract static class ItemSlotConsumer { - public abstract void consume(int x, int y, int id); - } - - public void iterateItemSlots(ItemSlotConsumer itemSlotConsumer) { - int width = Utils.peekGuiScale().getScaledWidth(); - int itemBoxXPadding = getItemBoxXPadding(); - iterateItemSlots(itemSlotConsumer, (int) (width * getItemPaneOffsetFactor()) + getBoxPadding() + itemBoxXPadding); - } - - /** - * Iterates through all the item slots in the right panel and calls a ItemSlotConsumer for each slot with - * arguments equal to the slot's x and y position respectively. This is used in order to prevent - * code duplication issues. - */ - public void iterateItemSlots(ItemSlotConsumer itemSlotConsumer, int xStart) { - int width = Utils.peekGuiScale().getScaledWidth(); - int height = Utils.peekGuiScale().getScaledHeight(); - - int paneWidth = (int) (width / 3 * getWidthMult()); - int itemBoxYPadding = ((height - getSearchBarYSize() - 2 * getBoxPadding() - ITEM_SIZE - 2) % (ITEM_SIZE + ITEM_PADDING) + ITEM_PADDING) / 2; - - int yStart = getBoxPadding() + getSearchBarYSize() + itemBoxYPadding; - int itemBoxXPadding = getItemBoxXPadding(); - int xEnd = xStart + paneWidth - getBoxPadding() * 2 - ITEM_SIZE - itemBoxXPadding; - int yEnd = height - getBoxPadding() - ITEM_SIZE - 2 - itemBoxYPadding; - - //Render the items, displaying the tooltip if the cursor is over the item - int id = 0; - for (int y = yStart; y < yEnd; y += IT