mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-11 21:57:40 +00:00
cool PanelTextBox QoL
This commit is contained in:
1 parent
5f04b6fa69
commit
ff33ebfe8d
4 files changed
+64
-24
No files matched your search
@@ -222,5 +222,22 @@ public class GuiNpcTextField extends GuiTextField {
|
||||
floatingPrecision = "%." + decimalPlaces + "f";
|
||||
}
|
||||
|
||||
public void setInt(int value) {
|
||||
setText(ValueUtil.clamp(value, min, max) + "");
|
||||
}
|
||||
|
||||
public void setFloat(float value) {
|
||||
value = ValueUtil.clamp(value, minFloat, maxFloat);
|
||||
setText(ValueUtil.format(floatingPrecision, value));
|
||||
}
|
||||
|
||||
public void setDouble(double value) {
|
||||
value = ValueUtil.clamp(value, minDouble, maxDouble);
|
||||
setText(ValueUtil.format(floatingPrecision, value));
|
||||
}
|
||||
|
||||
public boolean isNumbersOnly() {
|
||||
return integersOnly || floatsOnly || doublesOnly;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,8 +16,8 @@ public class PanelActiveFrame {
|
||||
public float scale = 0.6f;
|
||||
|
||||
public PanelTextBox frame = new PanelTextBox() {
|
||||
public void cancelEdit(byte operation) {
|
||||
super.cancelEdit(operation);
|
||||
public void finishEdit(byte operation) {
|
||||
super.finishEdit(operation);
|
||||
GridPointManager.Point p = graph.pointManager.selectedPoint;
|
||||
if (p != null) {
|
||||
p.setX(text.getDouble());
|
||||
@@ -27,8 +27,8 @@ public class PanelActiveFrame {
|
||||
}.setDoublesOnly(0, 0, 9999);
|
||||
|
||||
public PanelTextBox value = new PanelTextBox() {
|
||||
public void cancelEdit(byte operation) {
|
||||
super.cancelEdit(operation);
|
||||
public void finishEdit(byte operation) {
|
||||
super.finishEdit(operation);
|
||||
GridPointManager.Point p = graph.pointManager.selectedPoint;
|
||||
if (p != null)
|
||||
p.setY(-text.getDouble());
|
||||
@@ -59,7 +59,7 @@ public class PanelActiveFrame {
|
||||
value.click(mouseX - startX, mouseY - startY, button);
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
public void draw(int wheel) {
|
||||
int mouseX = graph.parent.mouseX, mouseY = graph.parent.mouseY;
|
||||
|
||||
GL11.glPushMatrix();
|
||||
@@ -110,7 +110,7 @@ public class PanelActiveFrame {
|
||||
|
||||
boolean isAboveFrame = frame.isMouseAbove(mouseX - startX, mouseY - startY);
|
||||
frame.boxColor = new Color(frame.isEditing() ? 0x111111 : isAboveFrame ? 0x797979 : 0x545454);
|
||||
frame.draw(mouseX - startX, graph.mc.fontRenderer);
|
||||
frame.draw(mouseX - startX,mouseY - startY, graph.mc.fontRenderer, wheel);
|
||||
|
||||
value.screenX = 29; //remove scaling from maxStringWidth
|
||||
value.screenY = 20;
|
||||
@@ -118,7 +118,7 @@ public class PanelActiveFrame {
|
||||
value.textScale = scale;
|
||||
boolean isAboveValue = value.isMouseAbove(mouseX - startX, mouseY - startY);
|
||||
value.boxColor = new Color(value.isEditing() ? 0x111111 : isAboveValue ? 0x797979 : 0x545454);
|
||||
value.draw(mouseX - startX, graph.mc.fontRenderer);
|
||||
value.draw(mouseX - startX, mouseY - startY, graph.mc.fontRenderer, wheel);
|
||||
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class PanelFrameType {
|
||||
this.height = endY - startY;
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
public void draw(int wheel) {
|
||||
GuiUtil.drawRectD(startX - 1, startY, endX, endY, 0xff1d1d1d);
|
||||
|
||||
GL11.glPushMatrix();
|
||||
@@ -68,7 +68,7 @@ public class PanelFrameType {
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Element element = list.get(i);
|
||||
element.draw(i);
|
||||
element.draw(i, wheel);
|
||||
}
|
||||
|
||||
GL11.glPopMatrix();
|
||||
@@ -99,9 +99,9 @@ public class PanelFrameType {
|
||||
public float elementStartY;
|
||||
|
||||
public PanelTextBox box = new PanelTextBox() {
|
||||
public void cancelEdit(byte operation) {
|
||||
super.cancelEdit(operation);
|
||||
graph.pointManager.addPoint(type, graph.pointManager.playhead.worldX, -text.getDouble());
|
||||
public void finishEdit(byte operation) {
|
||||
super.finishEdit(operation);
|
||||
graph.pointManager.setSelectedPoint(graph.pointManager.addPoint(type, graph.pointManager.playhead.worldX, -text.getDouble()));
|
||||
}
|
||||
}.setDoublesOnly(0, -9999, 9999);
|
||||
|
||||
@@ -116,7 +116,7 @@ public class PanelFrameType {
|
||||
return mouseX >= 0 && mouseX < box.screenX - 3 && mouseY >= elementStartY && mouseY < elementStartY + elementHeight + elementSpacing;
|
||||
}
|
||||
|
||||
public void draw(int index) {
|
||||
public void draw(int index, int wheel) {
|
||||
////////////////////////////////////////////
|
||||
////////////////////////////////////////////
|
||||
//Type names
|
||||
@@ -145,13 +145,14 @@ public class PanelFrameType {
|
||||
box.screenX = width / 1.25F * scale + 8; //remove scaling from maxStringWidth
|
||||
box.screenY = elementStartY - 7.5f;
|
||||
box.textScale = scale;
|
||||
boolean isAboveFrame = box.isMouseAbove(graph.grid.mouseX - startX, graph.grid.mouseY - startY);
|
||||
|
||||
if (graph.pointManager.getPoint(type, graph.pointManager.playhead.worldX) != null)
|
||||
box.boxColor = isEditing ? new Color(0x83752a, 1).multiply(0.65f) : new Color(0x83752a, 1);
|
||||
box.boxColor = isEditing ? new Color(0x83752a).multiply(0.65f) : new Color(isAboveFrame ? 0xd1b727 : 0x83752a);
|
||||
else
|
||||
box.boxColor = isEditing ? new Color(0x467d2a, 1).multiply(0.65f) : new Color(0x467d2a, 1);
|
||||
box.boxColor = isEditing ? new Color(0x467d2a).multiply(0.65f) : new Color(isAboveFrame ? 0x5fc729 : 0x467d2a);
|
||||
|
||||
box.draw(graph.grid.mouseX - startX, graph.mc.fontRenderer);
|
||||
box.draw(graph.grid.mouseX - startX, graph.grid.mouseY - startY, graph.mc.fontRenderer, wheel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,14 @@ import net.minecraft.client.gui.FontRenderer;
|
||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||
import noppes.npcs.client.gui.util.GuiUtil;
|
||||
import noppes.npcs.client.gui.util.animation.OverlayKeyPresetViewer;
|
||||
import noppes.npcs.client.gui.util.animation.keys.KeyPreset;
|
||||
import noppes.npcs.client.utils.Color;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class PanelTextBox {
|
||||
|
||||
public int mouseX, mouseY;
|
||||
public float screenX, screenY, textScreenX, textScale;
|
||||
public float boxScaleX = 0.85f, boxScaleY = 0.85f;
|
||||
public GuiNpcTextField text;
|
||||
@@ -32,13 +34,26 @@ public class PanelTextBox {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void draw(int mouseX, FontRenderer font) {
|
||||
public void draw(int mouseX, int mouseY, FontRenderer font, int wheel) {
|
||||
this.mouseX = mouseX;
|
||||
this.mouseY = mouseY;
|
||||
|
||||
if (this.font == null)
|
||||
this.font = font;
|
||||
|
||||
if (Mouse.isButtonDown(0) && isEditing && text.isFocused())
|
||||
setCursorPositionToMouse(mouseX);
|
||||
|
||||
boolean mouseAbove = isMouseAbove(mouseX, mouseY);
|
||||
if (mouseAbove && wheel != 0) {
|
||||
if (text.isDouble()) {
|
||||
double presets = KeyPreset.isAltKeyDown() ? 45 : KeyPreset.isCtrlKeyDown() ? 10 : KeyPreset.isShiftKeyDown() ? 0.1 : 1;
|
||||
double value = text.getDouble() + Math.copySign(presets, wheel);
|
||||
text.setDouble(value);
|
||||
finishEdit(M_WHEEL);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////
|
||||
////////////////////////////////////////////
|
||||
//Box texture
|
||||
@@ -93,9 +108,12 @@ public class PanelTextBox {
|
||||
return isEditing;
|
||||
}
|
||||
|
||||
public static byte ENTER_KEY = 0, CLICK_OUT = 1;
|
||||
public static byte ENTER_KEY = 0, CLICK_OUT = 1, M_WHEEL = 2;
|
||||
|
||||
public void finishEdit(byte operation) {
|
||||
if (operation == M_WHEEL)
|
||||
return;
|
||||
|
||||
public void cancelEdit(byte operation) {
|
||||
text.toDefaults();
|
||||
text.setFocused(false);
|
||||
isEditing = false;
|
||||
@@ -106,7 +124,7 @@ public class PanelTextBox {
|
||||
return;
|
||||
|
||||
if (i == 28) {
|
||||
cancelEdit(ENTER_KEY);
|
||||
finishEdit(ENTER_KEY);
|
||||
} else
|
||||
text.textboxKeyTyped(c, i);
|
||||
}
|
||||
@@ -114,11 +132,15 @@ public class PanelTextBox {
|
||||
public void click(int mouseX, int mouseY, int button) {
|
||||
if (!isMouseAbove(mouseX, mouseY)) {
|
||||
if (isEditing())
|
||||
cancelEdit(CLICK_OUT);
|
||||
finishEdit(CLICK_OUT);
|
||||
} else {
|
||||
text.setFocused(true);
|
||||
text.setCursorPositionEnd();
|
||||
isEditing = true;
|
||||
if (button == 0) {
|
||||
text.setFocused(true);
|
||||
text.setCursorPositionEnd();
|
||||
isEditing = true;
|
||||
} else if (button == 1) {
|
||||
text.setText(text.isNumbersOnly() ? "0" : "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user