From 0dcd02c5a0823dadc1ae2eb6b907fea832dc2009 Mon Sep 17 00:00:00 2001 From: bigguy345 Date: Mon, 22 Dec 2025 13:51:57 +0200 Subject: [PATCH] Slight OverlayKeyPreset logic improvements --- .../npcs/client/gui/util/GuiScriptTextArea.java | 13 +++++++------ .../gui/util/key/OverlayKeyPresetViewer.java | 15 +++++++++++---- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiScriptTextArea.java b/src/main/java/noppes/npcs/client/gui/util/GuiScriptTextArea.java index a20f37da3..38284c219 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiScriptTextArea.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiScriptTextArea.java @@ -477,7 +477,7 @@ public class GuiScriptTextArea extends GuiNpcTextField { int wheelDelta = ((GuiNPCInterface) listener).mouseScroll = Mouse.getDWheel(); if (listener instanceof GuiNPCInterface) { ((GuiNPCInterface) listener).mouseScroll = wheelDelta; - if (wheelDelta != 0 && !KEYS_OVERLAY.showOverlay) + if (wheelDelta != 0 && !KEYS_OVERLAY.isVisible()) scroll.applyWheelScroll(wheelDelta, maxScroll); } @@ -939,8 +939,8 @@ public class GuiScriptTextArea extends GuiNpcTextField { */ private void initializeKeyBindings() { // Helper: execute action only if text area is active and enabled - Supplier isActive = () -> active && isEnabled() && !KEYS_OVERLAY.showOverlay; - Supplier openBoxes = () -> !KEYS_OVERLAY.showOverlay; + Supplier isActive = () -> active && isEnabled() && !KEYS_OVERLAY.isVisible(); + Supplier openBoxes = () -> !KEYS_OVERLAY.isVisible(); // CUT: Copy selection to clipboard and delete it. If no selection, cut the current sentence. KEYS.CUT.setTask(e -> { @@ -1204,8 +1204,9 @@ public class GuiScriptTextArea extends GuiNpcTextField { // Handle search bar input first if it has focus if (searchBar.isVisible() && searchBar.keyTyped(c, i)) return true; - - if (!active || KEYS_OVERLAY.showOverlay) return false; + + if (!active) + return false; if (this.isKeyComboCtrlA(i)) { selection.selectAll(text.length()); @@ -1796,7 +1797,7 @@ public class GuiScriptTextArea extends GuiNpcTextField { } public boolean closeOnEsc(){ - return !KEYS_OVERLAY.showOverlay && !searchBar.isVisible() && !goToLineDialog.isVisible() && !renameHandler.isActive(); + return !KEYS_OVERLAY.isVisible() && !searchBar.isVisible() && !goToLineDialog.isVisible() && !renameHandler.isActive(); } // ==================== KEYBOARD MODIFIERS ==================== diff --git a/src/main/java/noppes/npcs/client/gui/util/key/OverlayKeyPresetViewer.java b/src/main/java/noppes/npcs/client/gui/util/key/OverlayKeyPresetViewer.java index d94242e21..5ae01dcf9 100644 --- a/src/main/java/noppes/npcs/client/gui/util/key/OverlayKeyPresetViewer.java +++ b/src/main/java/noppes/npcs/client/gui/util/key/OverlayKeyPresetViewer.java @@ -140,7 +140,8 @@ public class OverlayKeyPresetViewer { public boolean mouseClicked(int mouseX, int mouseY, int button) { // Always allow clicking the view button to toggle when openOnClick is enabled - if (viewButton.isMouseAbove(mouseX, mouseY)) { + boolean isAboveButton = viewButton.isMouseAbove(mouseX, mouseY); + if (isAboveButton) { if (openOnClick) { showOverlay = !showOverlay; return true; @@ -154,14 +155,15 @@ public class OverlayKeyPresetViewer { // If overlay is not visible, no other clicks matter if (!showOverlay) return false; - + + boolean isAboveOverlay = isMouseAbove(mouseX, mouseY); // In click-to-open mode, clicking outside the overlay (and not the button) should close it - if (openOnClick && !isMouseAbove(mouseX, mouseY) && !viewButton.isMouseAbove(mouseX, mouseY)) { + if (openOnClick && !isAboveOverlay && !isAboveButton) { showOverlay = false; return true; } - boolean consumed = false; + boolean consumed = isAboveOverlay; for (PresetElement element : list) { if (!element.isMouseAboveBox(mouseX, mouseY)) { if (element.isEditing) { @@ -194,6 +196,11 @@ public class OverlayKeyPresetViewer { return (int) (width / scale); } + public boolean isVisible() { + return showOverlay; + } + + public class Scrollable { private float scrollY, targetScrollY, maxScroll; private int totalHeight, scrollbarHeight, barWidth = 2;