Fully implemented OverlayKeyPresetViewer to GuiScriptTextArea

This commit is contained in:
bigguy345 committed 2025-12-19 16:04:07 +02:00
1 parent 7a74a599f2
commit d717b00de0
3 files changed
+32 -12

No files matched your search

@@ -6,6 +6,7 @@ import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.util.ChatAllowedCharacters;
import noppes.npcs.NoppesStringUtils;
import noppes.npcs.client.ClientProxy;
import noppes.npcs.client.gui.util.key.OverlayKeyPresetViewer;
import noppes.npcs.client.gui.util.script.*;
import noppes.npcs.client.gui.util.script.JavaTextContainer.LineData;
import noppes.npcs.client.key.impl.ScriptEditorKeys;
@@ -72,6 +73,8 @@ public class GuiScriptTextArea extends GuiNpcTextField {
// ==================== KEYS ====================
public static final ScriptEditorKeys KEYS = new ScriptEditorKeys();
public OverlayKeyPresetViewer KEYS_OVERLAY = new OverlayKeyPresetViewer(KEYS);
// ==================== CONSTRUCTOR ====================
@@ -86,6 +89,15 @@ public class GuiScriptTextArea extends GuiNpcTextField {
this.setText(text);
this.undoing = false;
initializeKeyBindings();
initGui();
}
public void initGui() {
int endX = x + width, endY = y + height;
KEYS_OVERLAY.initGui(endX - (width / 2) - 23, y + (height / 4), endX - 9, endY - 26);
KEYS_OVERLAY.viewButton.scale = 0.4f;
KEYS_OVERLAY.viewButton.initGui(endX - 8, endY - 25);
}
// ==================== RENDERING ====================
@@ -119,9 +131,10 @@ public class GuiScriptTextArea extends GuiNpcTextField {
int maxScroll = Math.max(0, this.container.linesCount - container.visibleLines);
// Handle mouse wheel scroll
int wheelDelta = ((GuiNPCInterface) listener).mouseScroll = Mouse.getDWheel();
if (listener instanceof GuiNPCInterface) {
int wheelDelta = ((GuiNPCInterface) listener).mouseScroll = Mouse.getDWheel();
if (wheelDelta != 0)
((GuiNPCInterface) listener).mouseScroll = wheelDelta;
if (wheelDelta != 0 && !KEYS_OVERLAY.showOverlay)
scroll.applyWheelScroll(wheelDelta, maxScroll);
}
@@ -351,6 +364,8 @@ public class GuiScriptTextArea extends GuiNpcTextField {
drawRect(posX, posY, posX + 5, posY + sbSize + 2, 0xFFe0e0e0);
}
KEYS_OVERLAY.draw(xMouse, yMouse, wheelDelta);
}
private void scissorViewport() {
@@ -436,9 +451,8 @@ public class GuiScriptTextArea extends GuiNpcTextField {
private void initializeKeyBindings() {
// Helper: execute action only if text area is active and enabled
Consumer<Runnable> executeIfActive = (action) -> {
if (active && isEnabled()) {
if (active && isEnabled() && !KEYS_OVERLAY.showOverlay)
action.run();
}
};
// CUT: Copy selection to clipboard and delete it
@@ -582,7 +596,9 @@ public class GuiScriptTextArea extends GuiNpcTextField {
*/
@Override
public boolean textboxKeyTyped(char c, int i) {
if (!active) return false;
KEYS_OVERLAY.keyTyped(c, i);
if (!active || KEYS_OVERLAY.showOverlay) return false;
if (this.isKeyComboCtrlA(i)) {
selection.selectAll(text.length());
@@ -1358,7 +1374,7 @@ public class GuiScriptTextArea extends GuiNpcTextField {
public void mouseClicked(int xMouse, int yMouse, int mouseButton) {
// Determine whether click occurred inside the text area bounds
this.active = xMouse >= this.x && xMouse < this.x + this.width && yMouse >= this.y && yMouse < this.y + this.height;
if (this.active) {
if (this.active && !KEYS_OVERLAY.showOverlay) {
// Compute logical click position in text and reset selection/caret
int clickPos = this.getSelectionPos(xMouse, yMouse);
selection.reset(clickPos);
@@ -1407,6 +1423,8 @@ public class GuiScriptTextArea extends GuiNpcTextField {
this.lastClicked = time;
activeTextfield = this;
}
KEYS_OVERLAY.mouseClicked(xMouse, yMouse, mouseButton);
}
// Called from GuiScreen.updateScreen()
@@ -29,6 +29,8 @@ public class OverlayKeyPresetViewer {
public OverlayButton viewButton = new OverlayButton();
public LinkedList<PresetElement> list = new LinkedList<>();
// from 0-1, where 0.5 is half overlay width;
public float RELATIVE_MAX_DESC_WIDTH = 0.5f;
private final FontRenderer font = Minecraft.getMinecraft().fontRenderer;
public OverlayKeyPresetViewer(KeyPresetManager manager) {
@@ -65,7 +67,6 @@ public class OverlayKeyPresetViewer {
if (!aboveOverlay && !aboveButton)
showOverlay = false;
}
viewButton.drawButton();
}
@@ -74,8 +75,6 @@ public class OverlayKeyPresetViewer {
GL11.glEnable(GL11.GL_SCISSOR_TEST);
GuiUtil.drawGradientRect(startX, startY, endX, endY, 0x88000000, 0x88303030);
if (scroll.maxScroll > 0)
scroll.drawBar();
GuiUtil.setScissorClip(startX, startY, scroll.maxScroll > 0 ? width - scroll.barWidth : width, height);
GL11.glPushMatrix();
@@ -95,6 +94,9 @@ public class OverlayKeyPresetViewer {
GL11.glPopMatrix();
GL11.glDisable(GL11.GL_SCISSOR_TEST);
if (scroll.maxScroll > 0)
scroll.drawBar();
}
public void keyTyped(char c, int i) {
@@ -189,7 +191,7 @@ public class OverlayKeyPresetViewer {
public void drawBar() {
GL11.glPushMatrix();
GL11.glTranslatef(endX - barWidth - 2, startY + yStartSpacing + scrollY * scrollFactor, 0);
GL11.glTranslatef(endX - barWidth - 2, startY + yStartSpacing + scrollY * scrollFactor, 1);
GuiUtil.drawRectD(0, 0, barWidth, scrollbarHeight, (isMouseAboveBar(mouseX, mouseY) || isMouseDragging) ? 0xffbababa : 0xff767676);
GL11.glPopMatrix();
}
@@ -221,7 +223,7 @@ public class OverlayKeyPresetViewer {
font.drawString("(Conflict-free)", font.getStringWidth(name) + 5, 0, 0xface40);
String description = String.format("- %s", key.description);
font.drawSplitString(description, 9, font.FONT_HEIGHT, getMaxStringWidth() - 9, 0x888888);
font.drawSplitString(description, 9, font.FONT_HEIGHT+3, getMaxStringWidth() - 9, 0x888888);
}
public void drawBox(int offsetY) {
@@ -376,7 +378,7 @@ public class OverlayKeyPresetViewer {
}
public int getMaxStringWidth() {
return (int) (getWidth() * 2.5f / 4);
return (int) (getWidth() * RELATIVE_MAX_DESC_WIDTH);
}
}