mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 06:25:11 +00:00
Better Working GUI Component Editor
This commit is contained in:
1 parent
3c1f7f9e60
commit
cba1f6268f
8 files changed
+178
-206
No files matched your search
@@ -37,19 +37,19 @@ public abstract class AbstractEditorComponent extends Gui implements IEditorComp
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a 2-pixel thick yellow border if selected.
|
||||
* Draws an outline around the component.
|
||||
* Yellow if selected; grey if not.
|
||||
*/
|
||||
protected void renderSelectionOutline() {
|
||||
if (!selected)
|
||||
return;
|
||||
// Top
|
||||
drawRect(posX - 2, posY - 2, posX + width + 2, posY - 1, 0xFFFFFF00);
|
||||
// Bottom
|
||||
drawRect(posX - 2, posY + height + 1, posX + width + 2, posY + height + 2, 0xFFFFFF00);
|
||||
// Left
|
||||
drawRect(posX - 2, posY - 2, posX - 1, posY + height + 2, 0xFFFFFF00);
|
||||
// Right
|
||||
drawRect(posX + width + 1, posY - 2, posX + width + 2, posY + height + 2, 0xFFFFFF00);
|
||||
int outlineColor = selected ? 0xFFFFFF00 : 0xFF888888;
|
||||
// Top border
|
||||
drawRect(posX - 1, posY - 1, posX + width + 1, posY, outlineColor);
|
||||
// Bottom border
|
||||
drawRect(posX - 1, posY + height, posX + width + 1, posY + height + 1, outlineColor);
|
||||
// Left border
|
||||
drawRect(posX - 1, posY - 1, posX, posY + height + 1, outlineColor);
|
||||
// Right border
|
||||
drawRect(posX + width, posY - 1, posX + width + 1, posY + height + 1, outlineColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,7 +3,6 @@ package kamkeel.npcs.editorgui;
|
||||
import noppes.npcs.scripted.gui.ScriptGuiButton;
|
||||
import noppes.npcs.client.gui.custom.components.CustomGuiButton;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import java.util.List;
|
||||
|
||||
@@ -43,7 +42,7 @@ public class EditorButtonComponent extends AbstractEditorComponent {
|
||||
|
||||
@Override
|
||||
public void mouseDragged(int mouseX, int mouseY, int mouseButton) {
|
||||
if(selected) {
|
||||
if (selected) {
|
||||
buttonComponent.setPos(posX, posY);
|
||||
}
|
||||
}
|
||||
@@ -71,6 +70,7 @@ public class EditorButtonComponent extends AbstractEditorComponent {
|
||||
|
||||
@Override
|
||||
public void onEditorButtonPressed(GuiButton button) {
|
||||
GuiCustomGuiEditor editor = (GuiCustomGuiEditor) Minecraft.getMinecraft().currentScreen;
|
||||
switch (button.id) {
|
||||
case 101:
|
||||
width += 5;
|
||||
@@ -89,72 +89,58 @@ public class EditorButtonComponent extends AbstractEditorComponent {
|
||||
buttonComponent.setSize(width, height);
|
||||
break;
|
||||
case 105:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("Scale", Float.toString(buttonComponent.getScale()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("Scale", Float.toString(buttonComponent.getScale()),
|
||||
newValue -> {
|
||||
try {
|
||||
float newScale = Float.parseFloat(newValue);
|
||||
buttonComponent.setScale(newScale);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() {
|
||||
// Return to editor: do nothing extra.
|
||||
}
|
||||
}, () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 106:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("Alpha", Float.toString(buttonComponent.getAlpha()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("Alpha", Float.toString(buttonComponent.getAlpha()),
|
||||
newValue -> {
|
||||
try {
|
||||
float newAlpha = Float.parseFloat(newValue);
|
||||
buttonComponent.setAlpha(newAlpha);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}, () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 107:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("Rotation", Float.toString(buttonComponent.getRotation()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("Rotation", Float.toString(buttonComponent.getRotation()),
|
||||
newValue -> {
|
||||
try {
|
||||
float newRotation = Float.parseFloat(newValue);
|
||||
buttonComponent.setRotation(newRotation);
|
||||
float newRot = Float.parseFloat(newValue);
|
||||
buttonComponent.setRotation(newRot);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}, () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 108:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("Label", buttonComponent.getLabel(), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
buttonComponent.setLabel(newValue);
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("Label", buttonComponent.getLabel(),
|
||||
newValue -> buttonComponent.setLabel(newValue), () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 110:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("ID", Integer.toString(buttonComponent.getID()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("ID", Integer.toString(buttonComponent.getID()),
|
||||
newValue -> {
|
||||
try {
|
||||
int newID = Integer.parseInt(newValue);
|
||||
buttonComponent.setID(newID);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}, () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -3,13 +3,9 @@ package kamkeel.npcs.editorgui;
|
||||
import noppes.npcs.scripted.gui.ScriptGuiLabel;
|
||||
import noppes.npcs.client.gui.custom.components.CustomGuiLabel;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* EditorLabelComponent wraps a ScriptGuiLabel.
|
||||
*/
|
||||
public class EditorLabelComponent extends AbstractEditorComponent {
|
||||
private ScriptGuiLabel labelComponent;
|
||||
|
||||
@@ -44,7 +40,7 @@ public class EditorLabelComponent extends AbstractEditorComponent {
|
||||
|
||||
@Override
|
||||
public void mouseDragged(int mouseX, int mouseY, int mouseButton) {
|
||||
if(selected) {
|
||||
if (selected) {
|
||||
labelComponent.setPos(posX, posY);
|
||||
}
|
||||
}
|
||||
@@ -72,6 +68,7 @@ public class EditorLabelComponent extends AbstractEditorComponent {
|
||||
|
||||
@Override
|
||||
public void onEditorButtonPressed(GuiButton button) {
|
||||
GuiCustomGuiEditor editor = (GuiCustomGuiEditor) Minecraft.getMinecraft().currentScreen;
|
||||
switch(button.id) {
|
||||
case 201:
|
||||
width += 5;
|
||||
@@ -90,70 +87,58 @@ public class EditorLabelComponent extends AbstractEditorComponent {
|
||||
labelComponent.setSize(width, height);
|
||||
break;
|
||||
case 205:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("Scale", Float.toString(labelComponent.getScale()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("Scale", Float.toString(labelComponent.getScale()),
|
||||
newValue -> {
|
||||
try {
|
||||
float newScale = Float.parseFloat(newValue);
|
||||
labelComponent.setScale(newScale);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}, () -> {
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 206:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("Alpha", Float.toString(labelComponent.getAlpha()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("Alpha", Float.toString(labelComponent.getAlpha()),
|
||||
newValue -> {
|
||||
try {
|
||||
float newAlpha = Float.parseFloat(newValue);
|
||||
labelComponent.setAlpha(newAlpha);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}, () -> {
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 207:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("Rotation", Float.toString(labelComponent.getRotation()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("Rotation", Float.toString(labelComponent.getRotation()),
|
||||
newValue -> {
|
||||
try {
|
||||
float newRot = Float.parseFloat(newValue);
|
||||
labelComponent.setRotation(newRot);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}, () -> {
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 208:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("Text", labelComponent.getText(), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
labelComponent.setText(newValue);
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("Text", labelComponent.getText(),
|
||||
newValue -> labelComponent.setText(newValue), () -> {
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 210:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("ID", Integer.toString(labelComponent.getID()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("ID", Integer.toString(labelComponent.getID()),
|
||||
newValue -> {
|
||||
try {
|
||||
int newID = Integer.parseInt(newValue);
|
||||
labelComponent.setID(newID);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}, () -> {
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package kamkeel.npcs.editorgui;
|
||||
import noppes.npcs.scripted.gui.ScriptGuiTextField;
|
||||
import noppes.npcs.client.gui.custom.components.CustomGuiTextField;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import java.util.List;
|
||||
|
||||
@@ -15,6 +14,7 @@ public class EditorTextFieldComponent extends AbstractEditorComponent {
|
||||
private ScriptGuiTextField textFieldComponent;
|
||||
|
||||
public EditorTextFieldComponent(ScriptGuiTextField textField) {
|
||||
// TextField uses its original width, height, and position.
|
||||
super(textField.getPosX(), textField.getPosY(), textField.getWidth(), textField.getHeight());
|
||||
this.textFieldComponent = textField;
|
||||
this.id = textField.getID();
|
||||
@@ -31,8 +31,8 @@ public class EditorTextFieldComponent extends AbstractEditorComponent {
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
if(mouseX >= posX && mouseX < posX + width &&
|
||||
mouseY >= posY && mouseY < posY + height) {
|
||||
if (mouseX >= posX && mouseX < posX + width &&
|
||||
mouseY >= posY && mouseY < posY + height) {
|
||||
selected = true;
|
||||
return true;
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public class EditorTextFieldComponent extends AbstractEditorComponent {
|
||||
|
||||
@Override
|
||||
public void mouseDragged(int mouseX, int mouseY, int mouseButton) {
|
||||
if(selected) {
|
||||
if (selected) {
|
||||
textFieldComponent.setPos(posX, posY);
|
||||
}
|
||||
}
|
||||
@@ -67,6 +67,7 @@ public class EditorTextFieldComponent extends AbstractEditorComponent {
|
||||
|
||||
@Override
|
||||
public void onEditorButtonPressed(GuiButton button) {
|
||||
GuiCustomGuiEditor editor = (GuiCustomGuiEditor) Minecraft.getMinecraft().currentScreen;
|
||||
switch(button.id) {
|
||||
case 301:
|
||||
width += 5;
|
||||
@@ -85,28 +86,22 @@ public class EditorTextFieldComponent extends AbstractEditorComponent {
|
||||
textFieldComponent.setSize(width, height);
|
||||
break;
|
||||
case 307:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("Default Text", textFieldComponent.getText(), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
textFieldComponent.setText(newValue);
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("Default Text", textFieldComponent.getText(),
|
||||
newValue -> textFieldComponent.setText(newValue), () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 310:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("ID", Integer.toString(textFieldComponent.getID()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("ID", Integer.toString(textFieldComponent.getID()),
|
||||
newValue -> {
|
||||
try {
|
||||
int newID = Integer.parseInt(newValue);
|
||||
textFieldComponent.setID(newID);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}, () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -3,15 +3,9 @@ package kamkeel.npcs.editorgui;
|
||||
import noppes.npcs.scripted.gui.ScriptGuiTexturedRect;
|
||||
import noppes.npcs.client.gui.custom.components.CustomGuiTexturedRect;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* EditorTexturedRectComponent wraps a ScriptGuiTexturedRect.
|
||||
* It renders the actual textured rectangle and provides editing buttons for width, height, scale, alpha,
|
||||
* rotation, texture string, texture X/Y offsets, and ID.
|
||||
*/
|
||||
public class EditorTexturedRectComponent extends AbstractEditorComponent {
|
||||
private ScriptGuiTexturedRect texturedRect;
|
||||
|
||||
@@ -35,8 +29,8 @@ public class EditorTexturedRectComponent extends AbstractEditorComponent {
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
if(mouseX >= posX && mouseX < posX + width &&
|
||||
mouseY >= posY && mouseY < posY + height) {
|
||||
if (mouseX >= posX && mouseX < posX + width &&
|
||||
mouseY >= posY && mouseY < posY + height) {
|
||||
selected = true;
|
||||
return true;
|
||||
}
|
||||
@@ -46,7 +40,7 @@ public class EditorTexturedRectComponent extends AbstractEditorComponent {
|
||||
|
||||
@Override
|
||||
public void mouseDragged(int mouseX, int mouseY, int mouseButton) {
|
||||
if(selected) {
|
||||
if (selected) {
|
||||
texturedRect.setPos(posX, posY);
|
||||
}
|
||||
}
|
||||
@@ -76,6 +70,7 @@ public class EditorTexturedRectComponent extends AbstractEditorComponent {
|
||||
|
||||
@Override
|
||||
public void onEditorButtonPressed(GuiButton button) {
|
||||
GuiCustomGuiEditor editor = (GuiCustomGuiEditor) Minecraft.getMinecraft().currentScreen;
|
||||
switch(button.id) {
|
||||
case 401:
|
||||
width += 5;
|
||||
@@ -94,98 +89,82 @@ public class EditorTexturedRectComponent extends AbstractEditorComponent {
|
||||
texturedRect.setSize(width, height);
|
||||
break;
|
||||
case 405:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("Scale", Float.toString(texturedRect.getScale()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("Scale", Float.toString(texturedRect.getScale()),
|
||||
newValue -> {
|
||||
try {
|
||||
float newScale = Float.parseFloat(newValue);
|
||||
texturedRect.setScale(newScale);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}, () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 406:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("Alpha", Float.toString(texturedRect.getAlpha()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("Alpha", Float.toString(texturedRect.getAlpha()),
|
||||
newValue -> {
|
||||
try {
|
||||
float newAlpha = Float.parseFloat(newValue);
|
||||
texturedRect.setAlpha(newAlpha);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}, () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 407:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("Rotation", Float.toString(texturedRect.getRotation()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("Rotation", Float.toString(texturedRect.getRotation()),
|
||||
newValue -> {
|
||||
try {
|
||||
float newRot = Float.parseFloat(newValue);
|
||||
texturedRect.setRotation(newRot);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}, () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 408:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("Texture", texturedRect.getTexture(), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
texturedRect.setTexture(newValue);
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("Texture", texturedRect.getTexture(),
|
||||
newValue -> texturedRect.setTexture(newValue), () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 409:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("TxX", Integer.toString(texturedRect.getTextureX()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("TxX", Integer.toString(texturedRect.getTextureX()),
|
||||
newValue -> {
|
||||
try {
|
||||
int newX = Integer.parseInt(newValue);
|
||||
texturedRect.setTextureOffset(newX, texturedRect.getTextureY());
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}, () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 410:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("TxY", Integer.toString(texturedRect.getTextureY()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("TxY", Integer.toString(texturedRect.getTextureY()),
|
||||
newValue -> {
|
||||
try {
|
||||
int newY = Integer.parseInt(newValue);
|
||||
texturedRect.setTextureOffset(texturedRect.getTextureX(), newY);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}, () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
case 411:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("ID", Integer.toString(texturedRect.getID()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
editor.setSubGuiOverlay(new SubGuiEditProperty("ID", Integer.toString(texturedRect.getID()),
|
||||
newValue -> {
|
||||
try {
|
||||
int newID = Integer.parseInt(newValue);
|
||||
texturedRect.setID(newID);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}, () ->{
|
||||
editor.clearSubGuiOverlay();
|
||||
editor.setSelectedComponent(this);
|
||||
}));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class EditorToolBar extends Gui {
|
||||
}
|
||||
|
||||
private int getDefaultId() {
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
public void actionPerformed(GuiButton button, GuiCustomGuiEditor editor) {
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.List;
|
||||
* The toolbar is positioned at the bottom.
|
||||
* Custom editing buttons (IDs 101–500) are arranged in a single row at the top.
|
||||
* Components are sorted by ID so that higher IDs render on top.
|
||||
* A SubGuiEditProperty overlay is used (instead of changing screens) for property editing.
|
||||
* A SubGuiEditProperty overlay is used for property editing.
|
||||
*/
|
||||
public class GuiCustomGuiEditor extends GuiScreen {
|
||||
// Full-screen canvas.
|
||||
@@ -67,28 +67,28 @@ public class GuiCustomGuiEditor extends GuiScreen {
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
drawDefaultBackground();
|
||||
// Sort components by ID ascending so that higher IDs render on top.
|
||||
Collections.sort(editorComponents, new Comparator<IEditorComponent>() {
|
||||
@Override
|
||||
public int compare(IEditorComponent o1, IEditorComponent o2) {
|
||||
int id1 = ((AbstractEditorComponent) o1).getID();
|
||||
int id2 = ((AbstractEditorComponent) o2).getID();
|
||||
return Integer.compare(id1, id2);
|
||||
}
|
||||
});
|
||||
for (IEditorComponent comp : editorComponents) {
|
||||
comp.render(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
toolBar.render(mouseX, mouseY, partialTicks);
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
// If a sub–GUI overlay is open, draw it on top.
|
||||
if (subGuiOverlay != null) {
|
||||
subGuiOverlay.drawScreen(mouseX, mouseY, partialTicks);
|
||||
} else {
|
||||
Collections.sort(editorComponents, new Comparator<IEditorComponent>() {
|
||||
@Override
|
||||
public int compare(IEditorComponent o1, IEditorComponent o2) {
|
||||
int id1 = ((AbstractEditorComponent) o1).getID();
|
||||
int id2 = ((AbstractEditorComponent) o2).getID();
|
||||
return Integer.compare(id1, id2);
|
||||
}
|
||||
});
|
||||
for (IEditorComponent comp : editorComponents) {
|
||||
comp.render(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
}
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
// If a sub–GUI overlay is open, forward the click to it.
|
||||
if (subGuiOverlay != null) {
|
||||
subGuiOverlay.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
return;
|
||||
@@ -146,7 +146,6 @@ public class GuiCustomGuiEditor extends GuiScreen {
|
||||
@Override
|
||||
public void mouseClickMove(int mouseX, int mouseY, int mouseButton, long timeSinceLastClick) {
|
||||
if (subGuiOverlay != null) {
|
||||
// Optionally forward dragging events to the overlay.
|
||||
subGuiOverlay.mouseClickMove(mouseX, mouseY, mouseButton, timeSinceLastClick);
|
||||
return;
|
||||
}
|
||||
@@ -241,6 +240,13 @@ public class GuiCustomGuiEditor extends GuiScreen {
|
||||
editorComponents.add(comp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the selected editor component.
|
||||
*/
|
||||
public void setSelectedComponent(IEditorComponent comp) {
|
||||
this.selectedComponent = comp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a ScriptGui from the editor components, saves it, and closes the editor.
|
||||
*/
|
||||
@@ -258,6 +264,7 @@ public class GuiCustomGuiEditor extends GuiScreen {
|
||||
* Sets the current sub–GUI overlay (for property editing) and forwards events to it.
|
||||
*/
|
||||
public void setSubGuiOverlay(SubGuiEditProperty overlay) {
|
||||
overlay.initGui();
|
||||
this.subGuiOverlay = overlay;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
package kamkeel.npcs.editorgui;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
/**
|
||||
* SubGuiEditProperty is a modal overlay for editing a single property.
|
||||
* It overlays on top of the current screen rather than switching screens.
|
||||
*
|
||||
* Usage: Pass the property name, the current value (as a string),
|
||||
* an IPropertyEditorCallback to receive the updated value,
|
||||
* and an ISubGuiCallback to notify when the overlay is closed.
|
||||
* It overlays on top of the current editor screen.
|
||||
* When "Done" is pressed, the provided property callback is invoked and the overlay is closed.
|
||||
* All overridden methods are declared public.
|
||||
*/
|
||||
public class SubGuiEditProperty extends GuiScreen {
|
||||
private ISubGuiCallback subGuiCallback;
|
||||
@@ -28,7 +29,7 @@ public class SubGuiEditProperty extends GuiScreen {
|
||||
* @param propertyName the name of the property being edited
|
||||
* @param initialValue the current value (as String)
|
||||
* @param propCallback callback for when the property is updated
|
||||
* @param subGuiCallback callback for when the overlay closes
|
||||
* @param subGuiCallback callback for when the overlay is closed
|
||||
*/
|
||||
public SubGuiEditProperty(String propertyName, String initialValue, IPropertyEditorCallback propCallback, ISubGuiCallback subGuiCallback) {
|
||||
this.propertyName = propertyName;
|
||||
@@ -40,16 +41,25 @@ public class SubGuiEditProperty extends GuiScreen {
|
||||
@Override
|
||||
public void initGui() {
|
||||
Keyboard.enableRepeatEvents(true);
|
||||
this.mc = Minecraft.getMinecraft();
|
||||
ScaledResolution res = new ScaledResolution(this.mc, this.mc.displayWidth, this.mc.displayHeight);
|
||||
if (this.fontRendererObj == null) {
|
||||
this.fontRendererObj = Minecraft.getMinecraft().fontRenderer;
|
||||
}
|
||||
|
||||
// Use the current width/height from this screen.
|
||||
this.width = res.getScaledWidth();
|
||||
this.height = res.getScaledHeight();
|
||||
overlayWidth = 150;
|
||||
overlayHeight = 20;
|
||||
overlayX = (width - overlayWidth) / 2;
|
||||
overlayY = (height - overlayHeight) / 2;
|
||||
textField = new GuiTextField(fontRendererObj, overlayX, overlayY, overlayWidth, overlayHeight);
|
||||
overlayX = (this.width - overlayWidth) / 2;
|
||||
overlayY = (this.height - overlayHeight) / 2;
|
||||
textField = new GuiTextField(this.fontRendererObj, overlayX, overlayY, overlayWidth, overlayHeight);
|
||||
textField.setText(initialValue);
|
||||
textField.setFocused(true);
|
||||
buttonList.clear();
|
||||
// "Done" button below the text field.
|
||||
buttonList.add(new GuiButton(0, overlayX, overlayY + overlayHeight + 5, overlayWidth, 20, "Done"));
|
||||
// "Done" button positioned below the text field.
|
||||
buttonList.add(new GuiButton(1000000, overlayX, overlayY + overlayHeight + 5, overlayWidth, 20, "Done"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,15 +69,25 @@ public class SubGuiEditProperty extends GuiScreen {
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
// Draw a semi-transparent dark overlay over the whole screen.
|
||||
drawRect(0, 0, width, height, 0x88000000);
|
||||
drawCenteredString(fontRendererObj, "Edit " + propertyName, width / 2, overlayY - 30, 0xFFFFFF);
|
||||
if (this.fontRendererObj == null) {
|
||||
this.fontRendererObj = Minecraft.getMinecraft().fontRenderer;
|
||||
}
|
||||
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
|
||||
// Draw semi-transparent background and overlay elements
|
||||
drawRect(0, 0, this.width, this.height, 0x88000000);
|
||||
drawCenteredString(this.fontRendererObj, "Edit " + propertyName, this.width / 2, overlayY - 30, 0xFFFFFF);
|
||||
textField.drawTextBox();
|
||||
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) {
|
||||
public void keyTyped(char typedChar, int keyCode) {
|
||||
textField.textboxKeyTyped(typedChar, keyCode);
|
||||
if (keyCode == Keyboard.KEY_ESCAPE) {
|
||||
closeOverlay();
|
||||
@@ -75,8 +95,8 @@ public class SubGuiEditProperty extends GuiScreen {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
if (button.id == 0) {
|
||||
public void actionPerformed(GuiButton button) {
|
||||
if (button.id == 1000000) {
|
||||
if (propCallback != null) {
|
||||
propCallback.propertyUpdated(textField.getText());
|
||||
}
|
||||
@@ -99,7 +119,7 @@ public class SubGuiEditProperty extends GuiScreen {
|
||||
super.mouseClickMove(mouseX, mouseY, mouseButton, timeSinceLastClick);
|
||||
}
|
||||
|
||||
private void closeOverlay() {
|
||||
public void closeOverlay() {
|
||||
Keyboard.enableRepeatEvents(false);
|
||||
if (subGuiCallback != null) {
|
||||
subGuiCallback.onSubGuiClosed();
|
||||
|
||||
Reference in new issue
Block a user