Slight OverlayKeyPreset logic improvements

This commit is contained in:
bigguy345 committed 2025-12-22 13:51:57 +02:00
1 parent f0740c6d7a
commit 0dcd02c5a0
2 files changed
+18 -10

No files matched your search

@@ -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<Boolean> isActive = () -> active && isEnabled() && !KEYS_OVERLAY.showOverlay;
Supplier<Boolean> openBoxes = () -> !KEYS_OVERLAY.showOverlay;
Supplier<Boolean> isActive = () -> active && isEnabled() && !KEYS_OVERLAY.isVisible();
Supplier<Boolean> 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 ====================
@@ -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;