From 43545da3cef2f12cfa8e940738373f63d6a58171 Mon Sep 17 00:00:00 2001 From: slprime Date: Sun, 15 Dec 2024 13:18:39 +0200 Subject: [PATCH] Add 'Hide Item List Until Searching' option --- src/main/java/codechicken/nei/BookmarkPanel.java | 2 +- .../java/codechicken/nei/ItemHistoryPanel.java | 13 ++++++++----- src/main/java/codechicken/nei/ItemPanel.java | 4 ++-- src/main/java/codechicken/nei/ItemsGrid.java | 4 ++++ .../java/codechicken/nei/NEIClientConfig.java | 16 ++++++++++++++++ src/main/java/codechicken/nei/PanelWidget.java | 2 +- src/main/java/codechicken/nei/SearchField.java | 8 +++++++- src/main/resources/assets/nei/lang/en_US.lang | 3 +++ 8 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/main/java/codechicken/nei/BookmarkPanel.java b/src/main/java/codechicken/nei/BookmarkPanel.java index a951b2e8f..dc2118315 100644 --- a/src/main/java/codechicken/nei/BookmarkPanel.java +++ b/src/main/java/codechicken/nei/BookmarkPanel.java @@ -2059,7 +2059,7 @@ protected int resizeFooter(GuiContainer gui) { public void setVisible() { super.setVisible(); - if (grid.getPerPage() > 0) { + if (grid.getPerPage() > 0 && getNamespaceSize() > 1) { LayoutManager.addWidget(namespacePrev); LayoutManager.addWidget(namespaceNext); LayoutManager.addWidget(namespaceLabel); diff --git a/src/main/java/codechicken/nei/ItemHistoryPanel.java b/src/main/java/codechicken/nei/ItemHistoryPanel.java index 4c46cf5de..81f2ce96a 100644 --- a/src/main/java/codechicken/nei/ItemHistoryPanel.java +++ b/src/main/java/codechicken/nei/ItemHistoryPanel.java @@ -1,12 +1,11 @@ package codechicken.nei; -import static codechicken.lib.gui.GuiDraw.drawRect; - import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.item.ItemStack; import org.lwjgl.opengl.GL11; +import codechicken.lib.gui.GuiDraw; import codechicken.nei.ItemPanel.ItemPanelSlot; import codechicken.nei.recipe.GuiCraftingRecipe; import codechicken.nei.recipe.GuiRecipe; @@ -22,10 +21,14 @@ public ItemHistoryPanel() { grid = new ItemsGrid(); } + public boolean isEmpty() { + return grid.isEmpty(); + } + public void draw(int mousex, int mousey) { if (NEIClientConfig.getIntSetting("inventory.history.splittingMode") == 0) { - drawRect(x, y, w, h, NEIClientConfig.getSetting("inventory.history.historyColor").getHexValue()); + GuiDraw.drawRect(x, y, w, h, NEIClientConfig.getSetting("inventory.history.historyColor").getHexValue()); } else { drawSplittingArea(x, y, w, h, NEIClientConfig.getSetting("inventory.history.historyColor").getHexValue()); } @@ -44,8 +47,8 @@ public void addItem(ItemStack stack) { grid.realItems.removeIf(historyStack -> StackInfo.equalItemAndNBT(historyStack, stack, true)); grid.realItems.add(0, is); - if (grid.realItems.size() > (grid.rows * grid.columns)) { - grid.realItems.remove(grid.rows * grid.columns); + if (grid.realItems.size() > Math.max(50, grid.rows * grid.columns)) { + grid.realItems.remove(grid.realItems.size() - 1); } grid.onItemsChanged(); diff --git a/src/main/java/codechicken/nei/ItemPanel.java b/src/main/java/codechicken/nei/ItemPanel.java index aa0a065ac..4aea6c22e 100644 --- a/src/main/java/codechicken/nei/ItemPanel.java +++ b/src/main/java/codechicken/nei/ItemPanel.java @@ -482,11 +482,11 @@ public void setVisible() { LayoutManager.addWidget(quantity); } - if (!CollapsibleItems.isEmpty()) { + if (!CollapsibleItems.isEmpty() && !grid.isEmpty()) { LayoutManager.addWidget(toggleGroups); } - if (NEIClientConfig.showHistoryPanelWidget()) { + if (NEIClientConfig.showHistoryPanelWidget() && (!grid.isEmpty() || !historyPanel.isEmpty())) { LayoutManager.addWidget(historyPanel); } } diff --git a/src/main/java/codechicken/nei/ItemsGrid.java b/src/main/java/codechicken/nei/ItemsGrid.java index e518ef39d..138818bf6 100644 --- a/src/main/java/codechicken/nei/ItemsGrid.java +++ b/src/main/java/codechicken/nei/ItemsGrid.java @@ -66,6 +66,10 @@ public int size() { return realItems.size(); } + public boolean isEmpty() { + return realItems.isEmpty(); + } + public int indexOf(ItemStack stackA, boolean useNBT) { for (int idx = 0; idx < realItems.size(); idx++) { diff --git a/src/main/java/codechicken/nei/NEIClientConfig.java b/src/main/java/codechicken/nei/NEIClientConfig.java index 2e414fc63..7b0960003 100644 --- a/src/main/java/codechicken/nei/NEIClientConfig.java +++ b/src/main/java/codechicken/nei/NEIClientConfig.java @@ -425,6 +425,18 @@ private static void setInventorySearchDefaults(ConfigTagParent tag) { tag.getTag("inventory.search.widgetPosition").setComment("Widget Position").getBooleanValue(true); API.addOption(new OptionToggleButton("inventory.search.widgetPosition", true)); + tag.getTag("inventory.search.hideUntilSearching").setComment("Hide Items Until Searching") + .getBooleanValue(false); + API.addOption(new OptionToggleButton("inventory.search.hideUntilSearching", true) { + + @Override + public boolean onClick(int button) { + super.onClick(button); + ItemList.updateFilter.restart(); + return true; + } + }); + tag.getTag("inventory.search.widgetAutofocus") .setComment( "Focus Search Widget on Open, blurs/unfocuses on mouse move unless typing has started first") @@ -808,6 +820,10 @@ public static boolean showItemQuantityWidget() { return getBooleanSetting("inventory.showItemQuantityWidget"); } + public static boolean hideItemsUntilSearching() { + return getBooleanSetting("inventory.search.hideUntilSearching"); + } + public static boolean isSearchWidgetCentered() { return getBooleanSetting("inventory.search.widgetPosition"); } diff --git a/src/main/java/codechicken/nei/PanelWidget.java b/src/main/java/codechicken/nei/PanelWidget.java index 9c5774688..0674ae879 100644 --- a/src/main/java/codechicken/nei/PanelWidget.java +++ b/src/main/java/codechicken/nei/PanelWidget.java @@ -171,7 +171,7 @@ protected int resizeHeader(GuiContainer gui) { protected abstract int resizeFooter(GuiContainer gui); public void setVisible() { - if (grid.getPerPage() > 0) { + if (grid.getPerPage() > 0 && !grid.isEmpty()) { LayoutManager.addWidget(pagePrev); LayoutManager.addWidget(pageNext); LayoutManager.addWidget(pageLabel); diff --git a/src/main/java/codechicken/nei/SearchField.java b/src/main/java/codechicken/nei/SearchField.java index 71733cdf6..d5a4cf904 100644 --- a/src/main/java/codechicken/nei/SearchField.java +++ b/src/main/java/codechicken/nei/SearchField.java @@ -144,7 +144,8 @@ public void setVisible(boolean visible) { @Override public int getTextColour() { - if (ItemPanels.itemPanel.getItems().isEmpty()) { + if (ItemPanels.itemPanel.getItems().isEmpty() + && (!this.field.getText().isEmpty() || !NEIClientConfig.hideItemsUntilSearching())) { return focused() ? 0xFFcc3300 : 0xFF993300; } else { return focused() ? 0xFFE0E0E0 : 0xFF909090; @@ -315,6 +316,11 @@ public static String getEscapedSearchText(String text) { @Override public ItemFilter getFilter() { + + if (field.getText().isEmpty() && NEIClientConfig.hideItemsUntilSearching()) { + return new NothingItemFilter(); + } + return ((GuiSearchField) field).getFilter(); } diff --git a/src/main/resources/assets/nei/lang/en_US.lang b/src/main/resources/assets/nei/lang/en_US.lang index ab968623f..6537c8215 100644 --- a/src/main/resources/assets/nei/lang/en_US.lang +++ b/src/main/resources/assets/nei/lang/en_US.lang @@ -216,6 +216,9 @@ nei.options.inventory.search=Search Widget nei.options.inventory.search.widgetPosition=Widget Position nei.options.inventory.search.widgetPosition.true=Center nei.options.inventory.search.widgetPosition.false=Right +nei.options.inventory.search.hideUntilSearching=Hide Until Searching +nei.options.inventory.search.hideUntilSearching.true=Yes +nei.options.inventory.search.hideUntilSearching.false=No nei.options.inventory.search.widgetAutofocus=Autofocus nei.options.inventory.search.widgetAutofocus.0=No nei.options.inventory.search.widgetAutofocus.1=Yes