Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'Hide Item List Until Searching' option #572

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/codechicken/nei/BookmarkPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/codechicken/nei/ItemHistoryPanel.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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());
}
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/codechicken/nei/ItemPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/codechicken/nei/ItemsGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/codechicken/nei/NEIClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,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")
Expand Down Expand Up @@ -875,6 +887,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");
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/codechicken/nei/PanelWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/codechicken/nei/SearchField.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/assets/nei/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down