From 5dde3b2e2f7d54f78bfc6bee5082e70d7a4f0371 Mon Sep 17 00:00:00 2001 From: OvermindDL1 Date: Tue, 11 Jun 2024 12:18:49 -0600 Subject: [PATCH] More inventory interaction enhancements - autofocus-quickclose (#493) * Added option (default on because it just feels so much better) to instantly close the inventory when it was just opened with it when pressing the inventory close key is the first input the screen receives, letting you flash open and close it again as is common when inspecting inventory * Forgot to add the vanilla survival inventory to the autofocus allowlist defaults (should this be hardcoded instead?) Added missing loadEnableAutoFocus() call. * Removed logging entry, added a new autofocus default that tests successful (and it overwrites the vanilla inventory gui so needed anyway for it), shortened config comment. --- src/main/java/codechicken/nei/ClientHandler.java | 1 + src/main/java/codechicken/nei/LayoutManager.java | 12 +++++++++++- src/main/java/codechicken/nei/NEIClientConfig.java | 12 +++++++++++- .../resources/assets/nei/cfg/enableautofocus.cfg | 2 ++ src/main/resources/assets/nei/lang/en_US.lang | 3 +++ 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/main/java/codechicken/nei/ClientHandler.java b/src/main/java/codechicken/nei/ClientHandler.java index 7d1ccab2..f002dcd4 100644 --- a/src/main/java/codechicken/nei/ClientHandler.java +++ b/src/main/java/codechicken/nei/ClientHandler.java @@ -149,6 +149,7 @@ public class ClientHandler { loadSerialHandlers(); loadHeightHackHandlers(); loadHiddenHandlers(); + loadEnableAutoFocus(); ItemInfo.preInit(); StackInfo.loadGuidFilters(); } diff --git a/src/main/java/codechicken/nei/LayoutManager.java b/src/main/java/codechicken/nei/LayoutManager.java index cfe89029..ee57ad34 100644 --- a/src/main/java/codechicken/nei/LayoutManager.java +++ b/src/main/java/codechicken/nei/LayoutManager.java @@ -40,6 +40,7 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.gui.inventory.GuiContainerCreative; import net.minecraft.client.renderer.InventoryEffectRenderer; +import net.minecraft.client.settings.GameSettings; import net.minecraft.inventory.Slot; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -176,6 +177,8 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH return true; } } + // Maybe make this an option to make it easier to figure out what GPU class to add to the configuration? + // NEIClientConfig.logger.info("Checking for autofocus on " + guiClassName + " had no match"); return false; } @@ -227,7 +230,14 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH public boolean keyTyped(GuiContainer gui, char keyChar, int keyID) { if (isEnabled() && !isHidden()) { - searchInitFocusedCancellable = false; + if (searchInitFocusedCancellable) { + searchInitFocusedCancellable = false; + if (NEIClientConfig.isFirstInvCloseClosesInSearch() + && GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindInventory)) { + searchField.setFocus(false); + setInputFocused(null); + } + } if (inputFocused != null) return inputFocused.handleKeyPress(keyID, keyChar); for (Widget widget : controlWidgets) if (widget.handleKeyPress(keyID, keyChar)) return true; diff --git a/src/main/java/codechicken/nei/NEIClientConfig.java b/src/main/java/codechicken/nei/NEIClientConfig.java index fac54812..4ee7ae79 100644 --- a/src/main/java/codechicken/nei/NEIClientConfig.java +++ b/src/main/java/codechicken/nei/NEIClientConfig.java @@ -279,10 +279,16 @@ public class NEIClientConfig { API.addOption(new OptionToggleButton("inventory.centerSearchWidget", true)); tag.getTag("inventory.focusSearchWidgetOnOpen") - .setComment("Focus Search Widget on Open, blurs on mouse move unless typing has started first") + .setComment( + "Focus Search Widget on Open, blurs/unfocuses on mouse move unless typing has started first") .getBooleanValue(false); API.addOption(new OptionToggleButton("inventory.focusSearchWidgetOnOpen", true)); + tag.getTag("inventory.firstInvCloseClosesInSearch").setComment( + "Pressing the open inventory key when the inventory was just opened when the search is focused will close it instead of typing in the search") + .getBooleanValue(true); + API.addOption(new OptionToggleButton("inventory.firstInvCloseClosesInSearch", true)); + tag.getTag("inventory.jei_style_tabs").setComment("Enable/disable JEI Style Tabs").getBooleanValue(true); API.addOption(new OptionToggleButtonBoubs("inventory.jei_style_tabs", true)); @@ -629,6 +635,10 @@ public class NEIClientConfig { return getBooleanSetting("inventory.focusSearchWidgetOnOpen"); } + public static boolean isFirstInvCloseClosesInSearch() { + return getBooleanSetting("inventory.firstInvCloseClosesInSearch"); + } + public static boolean areJEIStyleTabsVisible() { return getBooleanSetting("inventory.jei_style_tabs"); } diff --git a/src/main/resources/assets/nei/cfg/enableautofocus.cfg b/src/main/resources/assets/nei/cfg/enableautofocus.cfg index e1525ca9..b5269415 100644 --- a/src/main/resources/assets/nei/cfg/enableautofocus.cfg +++ b/src/main/resources/assets/nei/cfg/enableautofocus.cfg @@ -1,3 +1,5 @@ # Each line in this file should either be a comment (line starts with '#'), or a prefix of a fully-qualified class name # (that includes the package name) for a Minecraft GUI Container screen. # If you delete this file, it will be regenerated with the default enable autofocus list. +net.minecraft.client.gui.inventory.GuiInventory +makamys.satchels.gui.GuiSatchelsInventory diff --git a/src/main/resources/assets/nei/lang/en_US.lang b/src/main/resources/assets/nei/lang/en_US.lang index b4ba5a71..bad7a6d2 100644 --- a/src/main/resources/assets/nei/lang/en_US.lang +++ b/src/main/resources/assets/nei/lang/en_US.lang @@ -182,6 +182,9 @@ nei.options.inventory.centerSearchWidget.false=No nei.options.inventory.focusSearchWidgetOnOpen=Focus Search Widget on Open nei.options.inventory.focusSearchWidgetOnOpen.true=Yes nei.options.inventory.focusSearchWidgetOnOpen.false=No +nei.options.inventory.firstInvCloseClosesInSearch=First Inventory Close Closes in Search +nei.options.inventory.firstInvCloseClosesInSearch.true=Yes +nei.options.inventory.firstInvCloseClosesInSearch.false=No nei.options.inventory.creative_tab_style=Creative or JEI tab style nei.options.inventory.creative_tab_style.true=Creative nei.options.inventory.creative_tab_style.false=JEI