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 d68735f91..3fe7de850 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiScriptTextArea.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiScriptTextArea.java @@ -261,6 +261,11 @@ public class GuiScriptTextArea extends GuiNpcTextField { } // Draw outer border around entire area drawRect(x - 1, y - 1, x + width + 1, y + height + 1, 0xffa0a0a0); + + int searchHeight = searchBar.getTotalHeight(); + y += searchHeight; + height -= searchHeight; + // Draw line number gutter background drawRect(x, y, x + LINE_NUMBER_GUTTER_WIDTH, y + height, 0xff000000); // Draw text viewport background (starts after gutter) @@ -271,8 +276,8 @@ public class GuiScriptTextArea extends GuiNpcTextField { // Enable scissor test to clip drawing to the TEXT viewport rectangle (excludes gutter) GL11.glEnable(GL11.GL_SCISSOR_TEST); scissorViewport(); - - container.visibleLines = height / container.lineHeight-1; + + container.visibleLines = (height / container.lineHeight); int maxScroll = Math.max(0, this.container.linesCount - container.visibleLines); @@ -550,6 +555,8 @@ public class GuiScriptTextArea extends GuiNpcTextField { goToLineDialog.draw(xMouse, yMouse); KEYS_OVERLAY.draw(xMouse, yMouse, wheelDelta); + y -= searchHeight; + height += searchHeight; } private void scissorViewport() { diff --git a/src/main/java/noppes/npcs/client/gui/util/script/SearchReplaceBar.java b/src/main/java/noppes/npcs/client/gui/util/script/SearchReplaceBar.java index 22717623b..bab0de897 100644 --- a/src/main/java/noppes/npcs/client/gui/util/script/SearchReplaceBar.java +++ b/src/main/java/noppes/npcs/client/gui/util/script/SearchReplaceBar.java @@ -71,6 +71,7 @@ public class SearchReplaceBar { // ==================== HOVER STATE ==================== private boolean hoverClose = false; + private boolean hoverSearchUnwind = false; private boolean hoverMatchCase = false; private boolean hoverWholeWord = false; private boolean hoverPrev = false; @@ -323,6 +324,9 @@ public class SearchReplaceBar { int closeX = x + width - buttonSize - padding; drawCloseButton(closeX, rowY, hoverClose); + + int replaceUnwindButton = closeX - buttonSize - buttonSpacing; + drawActionButton(replaceUnwindButton, rowY, showReplace ? "▼" : "◀", hoverSearchUnwind, true); } private void drawReplaceRow(int mouseX, int mouseY) { @@ -480,7 +484,10 @@ public class SearchReplaceBar { int closeX = x + width - buttonSize - padding; hoverClose = isMouseOver(mouseX, mouseY, closeX, rowY, buttonSize, buttonSize); - + + int replaceUnwindButton = closeX - buttonSize - buttonSpacing; + hoverSearchUnwind = isMouseOver(mouseX, mouseY, replaceUnwindButton, rowY, buttonSize, buttonSize); + if (showReplace) { int replaceRowY = y + barHeight + 2; currentX = x + padding + textFieldWidth + buttonSpacing + 4; @@ -595,7 +602,12 @@ public class SearchReplaceBar { close(); return true; } - + + if (hoverSearchUnwind) { + showReplace = !showReplace; + return true; + } + if (showReplace) { int replaceRowY = y + barHeight + 2; diff --git a/src/main/java/noppes/npcs/client/key/KeyPreset.java b/src/main/java/noppes/npcs/client/key/KeyPreset.java index cbc7cfb86..8c21d86c5 100644 --- a/src/main/java/noppes/npcs/client/key/KeyPreset.java +++ b/src/main/java/noppes/npcs/client/key/KeyPreset.java @@ -8,7 +8,7 @@ import org.lwjgl.input.Mouse; import java.util.function.Consumer; -public class KeyPreset { +public class KeyPreset implements Comparable { /** * @field SINGLE_PRESS => on releasing before 5 ticks press time * @field PRESS_RELEASE => on pressing and releasing @@ -148,6 +148,26 @@ public class KeyPreset { return false; } + @Override + public int compareTo(KeyPreset o) { + int mySpecialCount = getSpecialKeyCount(this); + int otherSpecialCount = getSpecialKeyCount(o); + + return otherSpecialCount - mySpecialCount; + } + + private static int getSpecialKeyCount(KeyPreset preset) { + int res = 0; + if (preset.hasAlt()) + res += 1; + if (preset.hasCtrl()) + res += 1; + if (preset.hasShift()) + res += 1; + + return res; + } + public static class KeyState { public int keyCode = -1; diff --git a/src/main/java/noppes/npcs/client/key/KeyPresetManager.java b/src/main/java/noppes/npcs/client/key/KeyPresetManager.java index 61b74a610..8d25c43ac 100644 --- a/src/main/java/noppes/npcs/client/key/KeyPresetManager.java +++ b/src/main/java/noppes/npcs/client/key/KeyPresetManager.java @@ -11,8 +11,11 @@ import java.util.List; public class KeyPresetManager { public List keys = new ArrayList<>(); + public List keysSorted = new ArrayList<>(); public String fileName; + private boolean wasSorted = false; + public KeyPresetManager(String fileName) { this.fileName = fileName; } @@ -20,12 +23,22 @@ public class KeyPresetManager { public KeyPreset add(String name) { KeyPreset preset = new KeyPreset(name); keys.add(preset); + keysSorted.add(preset); + wasSorted = false; return preset; } public void tick() { - for (KeyPreset key : keys) + if (!wasSorted) { + keysSorted.sort(KeyPreset::compareTo); + wasSorted = true; + } + + for (KeyPreset key : keysSorted) { key.tick(); + if (key.isDown && key.shouldConflict) + return; + } }