From 550b600424e6acc3213b15d33d99585f18a4ae4b Mon Sep 17 00:00:00 2001
From: WinDanesz <31292708+WinDanesz@users.noreply.github.com>
Date: Sat, 7 Jun 2025 01:21:01 +0200
Subject: [PATCH] feat: add option to allow unfocused search bars in Arcane
Workbench and Lectern
---
src/main/java/electroblob/wizardry/Settings.java | 10 +++++++++-
.../wizardry/client/gui/GuiArcaneWorkbench.java | 14 ++++++++++++--
.../wizardry/client/gui/GuiLectern.java | 14 +++++++++-----
.../resources/assets/ebwizardry/lang/en_us.lang | 1 +
4 files changed, 31 insertions(+), 8 deletions(-)
diff --git a/src/main/java/electroblob/wizardry/Settings.java b/src/main/java/electroblob/wizardry/Settings.java
index e6559349..e6eb637c 100644
--- a/src/main/java/electroblob/wizardry/Settings.java
+++ b/src/main/java/electroblob/wizardry/Settings.java
@@ -397,6 +397,8 @@ public final class Settings {
/** [Client-only] Whether to initialise the handbook's data. Setting this to false will break the in-game handbook, but might help with some
* startup crashes */
public boolean loadHandbook = true;
+ /** [Client-only] Whether to allow the Arcane Workbench and lectern search field to lose focus and start unfocused. */
+ public boolean unfocusedSearchBars = false;
/** [Client-only] The position of the spell HUD. */
public GuiPosition spellHUDPosition = GuiPosition.BOTTOM_LEFT;
@@ -1203,13 +1205,19 @@ public final class Settings {
Wizardry.proxy.setToNamedBooleanEntry(property);
showChargeMeter = property.getBoolean();
propOrder.add(property.getName());
-
property = config.get(CLIENT_CATEGORY, "loadHandbook", true, "Whether to initialise the in-game handbook. Setting this to false will brick the in-game handbook, but it might help if you have startup crashes.");
property.setLanguageKey("config." + Wizardry.MODID + ".load_handbook");
property.setRequiresWorldRestart(false);
Wizardry.proxy.setToNamedBooleanEntry(property);
loadHandbook = property.getBoolean();
propOrder.add(property.getName());
+
+ property = config.get(CLIENT_CATEGORY, "unfocusedSearchBars", false, "Whether to allow the Arcane Workbench and lectern search field to lose focus and start unfocused. If true, the search field won't automatically capture keyboard input.");
+ property.setLanguageKey("config." + Wizardry.MODID + ".unfocused_search_bars");
+ property.setRequiresWorldRestart(false);
+ Wizardry.proxy.setToNamedBooleanEntry(property);
+ unfocusedSearchBars = property.getBoolean();
+ propOrder.add(property.getName());
property = config.get(CLIENT_CATEGORY, "spellHUDPosition", GuiPosition.BOTTOM_LEFT.name, "The position of the spell HUD.", GuiPosition.names);
property.setLanguageKey("config." + Wizardry.MODID + ".spell_hud_position");
diff --git a/src/main/java/electroblob/wizardry/client/gui/GuiArcaneWorkbench.java b/src/main/java/electroblob/wizardry/client/gui/GuiArcaneWorkbench.java
index 78d1e66b..6037008c 100644
--- a/src/main/java/electroblob/wizardry/client/gui/GuiArcaneWorkbench.java
+++ b/src/main/java/electroblob/wizardry/client/gui/GuiArcaneWorkbench.java
@@ -137,8 +137,8 @@ public class GuiArcaneWorkbench extends GuiContainer {
this.searchField.setEnableBackgroundDrawing(false);
this.searchField.setVisible(true);
this.searchField.setTextColor(16777215);
- this.searchField.setCanLoseFocus(false);
- this.searchField.setFocused(true);
+ this.searchField.setCanLoseFocus(Wizardry.settings.unfocusedSearchBars); // false by default
+ this.searchField.setFocused(!Wizardry.settings.unfocusedSearchBars); // true by default
this.tooltipElements.clear();
this.tooltipElements.add(new TooltipElementItemName(new Style().setColor(TextFormatting.WHITE), LINE_SPACING_WIDE));
@@ -431,6 +431,16 @@ public class GuiArcaneWorkbench extends GuiContainer {
// Controls
+ @Override
+ protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
+ super.mouseClicked(mouseX, mouseY, mouseButton);
+ if (this.searchField != null) {
+ this.searchField.mouseClicked(mouseX, mouseY, mouseButton);
+ // Set focus depending on whether the click was inside the search field
+ this.searchField.setFocused(this.searchField.isFocused());
+ }
+ }
+
@Override
protected void actionPerformed(GuiButton button){
diff --git a/src/main/java/electroblob/wizardry/client/gui/GuiLectern.java b/src/main/java/electroblob/wizardry/client/gui/GuiLectern.java
index 71c5bde2..5cb03778 100644
--- a/src/main/java/electroblob/wizardry/client/gui/GuiLectern.java
+++ b/src/main/java/electroblob/wizardry/client/gui/GuiLectern.java
@@ -184,9 +184,8 @@ public class GuiLectern extends GuiSpellInfo implements ISpellSortable {
this.searchField.setEnableBackgroundDrawing(false);
this.searchField.setVisible(true);
this.searchField.setTextColor(16777215);
- this.searchField.setCanLoseFocus(false);
- this.searchField.setFocused(true);
-
+ this.searchField.setCanLoseFocus(Wizardry.settings.unfocusedSearchBars); // false by default
+ this.searchField.setFocused(!Wizardry.settings.unfocusedSearchBars); // true by default
refreshAvailableSpells(); // Must be done last
}
@@ -269,8 +268,13 @@ public class GuiLectern extends GuiSpellInfo implements ISpellSortable {
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
- super.mouseClicked(mouseX, mouseY, mouseButton);
- searchNeedsClearing = true;
+ super.mouseClicked(mouseX, mouseY, mouseButton);
+ if (this.searchField != null) {
+ this.searchField.mouseClicked(mouseX, mouseY, mouseButton);
+ // Set focus depending on whether the click was inside the search field
+ this.searchField.setFocused(this.searchField.isFocused());
+ }
+ searchNeedsClearing = true;
}
@Override
diff --git a/src/main/resources/assets/ebwizardry/lang/en_us.lang b/src/main/resources/assets/ebwizardry/lang/en_us.lang
index 640395ab..412aabcc 100644
--- a/src/main/resources/assets/ebwizardry/lang/en_us.lang
+++ b/src/main/resources/assets/ebwizardry/lang/en_us.lang
@@ -1581,6 +1581,7 @@ config.ebwizardry.category.difficulty.tooltip=Configure wizardry's difficulty
config.ebwizardry.title.difficulty=Difficulty Settings
config.ebwizardry.subtitle.difficulty=Settings that affect the mod's difficulty.
+config.ebwizardry.unfocused_search_bars=Whether to autofocus search bar in Arcane Workbench and lectern
config.ebwizardry.discovery_mode=Discovery Mode
config.ebwizardry.discovery_mode.tooltip=For those who like a sense of mystery! When enabled, spells you haven't cast yet will be unreadable until you cast them (on a per-world basis). Has no effect when in creative mode. Spells of identification will be unobtainable in survival mode if this is disabled.
config.ebwizardry.legacy_wand_levelling=Legacy Wand Levelling