feat: add option to allow unfocused search bars in Arcane Workbench and Lectern

This commit is contained in:
WinDanesz
2025-06-07 01:21:01 +02:00
parent 9673a6c0f6
commit 550b600424
4 changed files with 31 additions and 8 deletions
@@ -397,6 +397,8 @@ public final class Settings {
/** <b>[Client-only]</b> 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;
/** <b>[Client-only]</b> Whether to allow the Arcane Workbench and lectern search field to lose focus and start unfocused. */
public boolean unfocusedSearchBars = false;
/** <b>[Client-only]</b> 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");
@@ -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){
@@ -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