mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 13:25:10 +00:00
OverlayKeyPreset tweaks
This commit is contained in:
1 parent
d717b00de0
commit
37cd4f1b7a
3 files changed
+36
-22
No files matched your search
@@ -94,10 +94,11 @@ public class GuiScriptTextArea extends GuiNpcTextField {
|
||||
|
||||
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.elementSpacing = 0;
|
||||
KEYS_OVERLAY.initGui(endX - (width / 2) , y + (height / 4), endX - 7, endY - 27);
|
||||
|
||||
KEYS_OVERLAY.viewButton.scale = 0.4f;
|
||||
KEYS_OVERLAY.viewButton.initGui(endX - 8, endY - 25);
|
||||
KEYS_OVERLAY.viewButton.scale = 0.45f;
|
||||
KEYS_OVERLAY.viewButton.initGui(endX - 7, endY - 26);
|
||||
}
|
||||
|
||||
// ==================== RENDERING ====================
|
||||
|
||||
@@ -154,13 +154,18 @@ public class OverlayKeyPresetViewer {
|
||||
totalHeight = 0;
|
||||
for (PresetElement element : list)
|
||||
totalHeight += element.getHeight();
|
||||
// contentTotal includes top spacing before first element
|
||||
float contentTotal = totalHeight + yStartSpacing;
|
||||
|
||||
totalHeight -= yStartSpacing;
|
||||
scroll.maxScroll = Math.max(0, totalHeight - height);
|
||||
// maxScroll is how much content exceeds the visible area
|
||||
maxScroll = Math.max(0f, contentTotal - height);
|
||||
|
||||
heightFactor = height / totalHeight;
|
||||
// compute scrollbar height proportional to visible area vs content
|
||||
heightFactor = contentTotal > 0f ? (float) height / contentTotal : 1f;
|
||||
scrollbarHeight = Math.max((int) (height * heightFactor), 20);
|
||||
scrollFactor = (height - yStartSpacing - scrollbarHeight) / maxScroll;
|
||||
|
||||
// scrollFactor maps scrollY -> pixel offset for scrollbar
|
||||
scrollFactor = maxScroll > 0f ? (height - yStartSpacing - scrollbarHeight) / maxScroll : 0f;
|
||||
}
|
||||
|
||||
public void update(int wheel) {
|
||||
@@ -216,14 +221,17 @@ public class OverlayKeyPresetViewer {
|
||||
}
|
||||
|
||||
public void drawDescription() {
|
||||
boolean hasDescription = key.description != null;
|
||||
String name = String.format("> %s", key.name);
|
||||
font.drawString(name, 0, 0, 0xffffff);
|
||||
font.drawString(name, 0, hasDescription ? 0 : 10, 0xffffff);
|
||||
|
||||
if (!key.shouldConflict)
|
||||
font.drawString("(Conflict-free)", font.getStringWidth(name) + 5, 0, 0xface40);
|
||||
|
||||
String description = String.format("- %s", key.description);
|
||||
font.drawSplitString(description, 9, font.FONT_HEIGHT+3, getMaxStringWidth() - 9, 0x888888);
|
||||
if (hasDescription) {
|
||||
String description = String.format("- %s", key.description);
|
||||
font.drawSplitString(description, 9, font.FONT_HEIGHT + 3, getMaxStringWidth() - 9, 0x888888);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawBox(int offsetY) {
|
||||
@@ -235,7 +243,13 @@ public class OverlayKeyPresetViewer {
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
float boxScaleX = 1.75f;
|
||||
float boxWidth = 32 * boxScaleX;
|
||||
boxScreenX = getMaxStringWidth() * scale + 8; //remove scaling from maxStringWidth
|
||||
// compute desired box X based on description width
|
||||
float desiredBoxX = getMaxStringWidth() * scale + 8; //remove scaling from maxStringWidth
|
||||
// clamp so the box + reset button always fit inside the content area
|
||||
float resetWidth = 10f;
|
||||
float contentAvailable = (scroll.maxScroll > 0 ? width - scroll.barWidth : width) - 4f; // small padding
|
||||
float maxBoxX = Math.max(0f, contentAvailable - boxWidth - resetWidth - 4f);
|
||||
boxScreenX = Math.min(desiredBoxX, maxBoxX);
|
||||
GL11.glScalef(boxScaleX, 1, 0);
|
||||
|
||||
if (isEditing)
|
||||
@@ -249,7 +263,7 @@ public class OverlayKeyPresetViewer {
|
||||
|
||||
//Reset box
|
||||
boolean isDefault = key.isDefault();
|
||||
float resetWidth = 10;
|
||||
resetWidth = 10;
|
||||
float resetScreenX = boxScreenX + boxWidth + 2;
|
||||
|
||||
if (isMouseAboveReset(mouseX, mouseY) && !isDefault)
|
||||
|
||||
@@ -8,16 +8,15 @@ public class ScriptEditorKeys extends KeyPresetManager {
|
||||
|
||||
////////////////////
|
||||
// Editor shortcuts (mapped from GuiScriptTextArea.handleShortcutKeys)
|
||||
public final KeyPreset CUT = add("Cut").setDefaultState(Keyboard.KEY_X, true, false, false).setDescription("Cut selection or current line");
|
||||
public final KeyPreset COPY = add("Copy").setDefaultState(Keyboard.KEY_C, true, false, false).setDescription("Copy selection");
|
||||
public final KeyPreset PASTE = add("Paste").setDefaultState(Keyboard.KEY_V, true, false, false).setDescription("Paste clipboard at caret");
|
||||
public final KeyPreset DUPLICATE = add("Duplicate").setDefaultState(Keyboard.KEY_D, true, false, false).setDescription("Duplicate selection or current line");
|
||||
|
||||
|
||||
public final KeyPreset UNDO = add("Undo").setDefaultState(Keyboard.KEY_Z, true, false, false).setDescription("Undo last edit");
|
||||
public final KeyPreset REDO = add("Redo").setDefaultState(Keyboard.KEY_Y, true, false, false).setDescription("Redo last undone edit");
|
||||
public final KeyPreset FORMAT = add("Format").setDefaultState(Keyboard.KEY_F, true, false, false).setDescription("Format code / indent");
|
||||
public final KeyPreset TOGGLE_COMMENT = add("Toggle Comment").setDefaultState(Keyboard.KEY_SLASH, true, false, false).setDescription("Toggle comment for selection or line");
|
||||
public final KeyPreset COPY = add("Copy").setDefaultState(Keyboard.KEY_C, true, false, false);
|
||||
public final KeyPreset PASTE = add("Paste").setDefaultState(Keyboard.KEY_V, true, false, false);
|
||||
public final KeyPreset CUT = add("Cut").setDefaultState(Keyboard.KEY_X, true, false, false);
|
||||
public final KeyPreset DUPLICATE = add("Duplicate").setDefaultState(Keyboard.KEY_D, true, false, false);
|
||||
public final KeyPreset UNDO = add("Undo").setDefaultState(Keyboard.KEY_Z, true, false, false);
|
||||
public final KeyPreset REDO = add("Redo").setDefaultState(Keyboard.KEY_Y, true, false, false);
|
||||
|
||||
public final KeyPreset FORMAT = add("Format Code").setDefaultState(Keyboard.KEY_F, true, false, false);
|
||||
public final KeyPreset TOGGLE_COMMENT = add("Toggle Comment").setDefaultState(Keyboard.KEY_SLASH, true, false, false);
|
||||
|
||||
public ScriptEditorKeys() {
|
||||
super("script_editor");
|
||||
|
||||
Reference in new issue
Block a user