Compare commits

...
7 Commits
Author SHA1 Message Date
Kam 0fe357d360 Remove Duplicate 2025-03-16 15:44:21 -04:00
Kam 0f6e190538 Merge branch 'dev' into edit-gui 2025-03-16 15:43:50 -04:00
Kam 500bfc3b3c FACTION TAB TAKES TO EDITOR - REMOVE 2025-03-05 04:47:54 -05:00
Kam b2fb46db64 Unfocus Textfield on Close 2025-03-05 04:45:38 -05:00
Kam cba1f6268f Better Working GUI Component Editor 2025-03-05 04:43:39 -05:00
Kam 3c1f7f9e60 Another Rendition Rewrite 2025-03-05 03:34:30 -05:00
Kam f94f80ea41 Push of Custom Editor GUI to Public 2025-03-05 03:19:29 -05:00
16 changed files with 1246 additions and 20 deletions

No files matched your search

@@ -0,0 +1,57 @@
package kamkeel.npcs.editorgui;
import net.minecraft.client.gui.Gui;
/**
* AbstractEditorComponent provides common fields and methods for all editor components.
*/
public abstract class AbstractEditorComponent extends Gui implements IEditorComponent {
// Store the editor component's ID.
protected int id;
// Position and size.
public int posX, posY, width, height;
protected boolean selected = false;
public AbstractEditorComponent(int posX, int posY, int width, int height) {
this.posX = posX;
this.posY = posY;
this.width = width;
this.height = height;
}
/**
* Returns the ID for this editor component.
*/
public int getID() {
return id;
}
@Override
public void setSelected(boolean selected) {
this.selected = selected;
}
@Override
public boolean isSelected() {
return selected;
}
/**
* Draws an outline around the component.
* Yellow if selected; grey if not.
*/
protected void renderSelectionOutline() {
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
public void update() { }
}
@@ -0,0 +1,42 @@
package kamkeel.npcs.editorgui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.scripted.gui.ScriptGui;
import noppes.npcs.util.NBTJsonUtil;
import java.io.File;
/**
* CustomGuiEditorController handles saving and loading of ScriptGui objects.
*/
public class CustomGuiEditorController {
private ScriptGui currentGui;
public CustomGuiEditorController() {
currentGui = new ScriptGui();
}
public void saveGui(File file, ScriptGui gui) {
NBTTagCompound compound = gui.toNBT();
try {
NBTJsonUtil.SaveFile(file, compound);
} catch(Exception e) {
e.printStackTrace();
}
currentGui = gui;
}
public ScriptGui loadGui(File file) {
try {
NBTTagCompound compound = NBTJsonUtil.LoadFile(file);
currentGui = (ScriptGui) (new ScriptGui()).fromNBT(compound);
} catch(Exception e) {
e.printStackTrace();
}
return currentGui;
}
public void applyGuiToPlayer(EntityPlayer player) {
// player.showCustomGui(currentGui);
}
}
@@ -0,0 +1,148 @@
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.GuiButton;
import java.util.List;
/**
* EditorButtonComponent wraps a ScriptGuiButton for editing.
*/
public class EditorButtonComponent extends AbstractEditorComponent {
private ScriptGuiButton buttonComponent;
public EditorButtonComponent(ScriptGuiButton button) {
super(button.getPosX(), button.getPosY(), button.getWidth(), button.getHeight());
this.buttonComponent = button;
this.id = button.getID();
}
@Override
public void render(int mouseX, int mouseY, float partialTicks) {
CustomGuiButton renderBtn = CustomGuiButton.fromComponent(buttonComponent);
renderBtn.xPosition = this.posX;
renderBtn.yPosition = this.posY;
renderBtn.scale = buttonComponent.getScale();
renderBtn.alpha = buttonComponent.getAlpha();
renderBtn.onRender(Minecraft.getMinecraft(), mouseX, mouseY, 0, partialTicks);
renderSelectionOutline();
}
@Override
public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) {
if (mouseX >= posX && mouseX <= posX + width &&
mouseY >= posY && mouseY <= posY + height) {
selected = true;
return true;
}
selected = false;
return false;
}
@Override
public void mouseDragged(int mouseX, int mouseY, int mouseButton) {
if (selected) {
buttonComponent.setPos(posX, posY);
}
}
@Override
public void mouseReleased(int mouseX, int mouseY, int state) { }
@Override
public Object toScriptComponent() {
return buttonComponent;
}
@Override
public void addEditorButtons(List<GuiButton> buttonList) {
buttonList.add(new GuiButton(101, 0, 0, 30, 20, "W+"));
buttonList.add(new GuiButton(102, 0, 0, 30, 20, "W-"));
buttonList.add(new GuiButton(103, 0, 0, 30, 20, "H+"));
buttonList.add(new GuiButton(104, 0, 0, 30, 20, "H-"));
buttonList.add(new GuiButton(105, 0, 0, 30, 20, "Sc"));
buttonList.add(new GuiButton(106, 0, 0, 30, 20, "Al"));
buttonList.add(new GuiButton(107, 0, 0, 30, 20, "Rt"));
buttonList.add(new GuiButton(108, 0, 0, 30, 20, "Lbl"));
buttonList.add(new GuiButton(110, 0, 0, 30, 20, "ID"));
}
@Override
public void onEditorButtonPressed(GuiButton button) {
GuiCustomGuiEditor editor = (GuiCustomGuiEditor) Minecraft.getMinecraft().currentScreen;
switch (button.id) {
case 101:
width += 5;
buttonComponent.setSize(width, height);
break;
case 102:
width = Math.max(10, width - 5);
buttonComponent.setSize(width, height);
break;
case 103:
height += 5;
buttonComponent.setSize(width, height);
break;
case 104:
height = Math.max(10, height - 5);
buttonComponent.setSize(width, height);
break;
case 105:
editor.setSubGuiOverlay(new SubGuiEditProperty("Scale", Float.toString(buttonComponent.getScale()),
newValue -> {
try {
float newScale = Float.parseFloat(newValue);
buttonComponent.setScale(newScale);
} catch (NumberFormatException e) { }
}, () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 106:
editor.setSubGuiOverlay(new SubGuiEditProperty("Alpha", Float.toString(buttonComponent.getAlpha()),
newValue -> {
try {
float newAlpha = Float.parseFloat(newValue);
buttonComponent.setAlpha(newAlpha);
} catch (NumberFormatException e) { }
}, () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 107:
editor.setSubGuiOverlay(new SubGuiEditProperty("Rotation", Float.toString(buttonComponent.getRotation()),
newValue -> {
try {
float newRot = Float.parseFloat(newValue);
buttonComponent.setRotation(newRot);
} catch (NumberFormatException e) { }
}, () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 108:
editor.setSubGuiOverlay(new SubGuiEditProperty("Label", buttonComponent.getLabel(),
newValue -> buttonComponent.setLabel(newValue), () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 110:
editor.setSubGuiOverlay(new SubGuiEditProperty("ID", Integer.toString(buttonComponent.getID()),
newValue -> {
try {
int newID = Integer.parseInt(newValue);
buttonComponent.setID(newID);
} catch (NumberFormatException e) { }
}, () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
}
}
}
@@ -0,0 +1,146 @@
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.GuiButton;
import java.util.List;
public class EditorLabelComponent extends AbstractEditorComponent {
private ScriptGuiLabel labelComponent;
public EditorLabelComponent(ScriptGuiLabel label) {
super(label.getPosX(), label.getPosY(), label.getWidth(), label.getHeight());
this.labelComponent = label;
this.id = label.getID();
}
@Override
public void render(int mouseX, int mouseY, float partialTicks) {
CustomGuiLabel renderLbl = CustomGuiLabel.fromComponent(labelComponent);
renderLbl.x = this.posX;
renderLbl.y = this.posY;
renderLbl.setScale(labelComponent.getScale());
renderLbl.alpha = labelComponent.getAlpha();
renderLbl.rotation = labelComponent.getRotation();
renderLbl.onRender(Minecraft.getMinecraft(), mouseX, mouseY, 0, partialTicks);
renderSelectionOutline();
}
@Override
public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) {
if (mouseX >= posX && mouseX <= posX + width &&
mouseY >= posY && mouseY <= posY + height) {
selected = true;
return true;
}
selected = false;
return false;
}
@Override
public void mouseDragged(int mouseX, int mouseY, int mouseButton) {
if (selected) {
labelComponent.setPos(posX, posY);
}
}
@Override
public void mouseReleased(int mouseX, int mouseY, int state) { }
@Override
public Object toScriptComponent() {
return labelComponent;
}
@Override
public void addEditorButtons(List<GuiButton> buttonList) {
buttonList.add(new GuiButton(201, 0, 0, 30, 20, "W+"));
buttonList.add(new GuiButton(202, 0, 0, 30, 20, "W-"));
buttonList.add(new GuiButton(203, 0, 0, 30, 20, "H+"));
buttonList.add(new GuiButton(204, 0, 0, 30, 20, "H-"));
buttonList.add(new GuiButton(205, 0, 0, 30, 20, "Sc"));
buttonList.add(new GuiButton(206, 0, 0, 30, 20, "Al"));
buttonList.add(new GuiButton(207, 0, 0, 30, 20, "Rt"));
buttonList.add(new GuiButton(208, 0, 0, 30, 20, "Txt"));
buttonList.add(new GuiButton(210, 0, 0, 30, 20, "ID"));
}
@Override
public void onEditorButtonPressed(GuiButton button) {
GuiCustomGuiEditor editor = (GuiCustomGuiEditor) Minecraft.getMinecraft().currentScreen;
switch(button.id) {
case 201:
width += 5;
labelComponent.setSize(width, height);
break;
case 202:
width = Math.max(10, width - 5);
labelComponent.setSize(width, height);
break;
case 203:
height += 5;
labelComponent.setSize(width, height);
break;
case 204:
height = Math.max(10, height - 5);
labelComponent.setSize(width, height);
break;
case 205:
editor.setSubGuiOverlay(new SubGuiEditProperty("Scale", Float.toString(labelComponent.getScale()),
newValue -> {
try {
float newScale = Float.parseFloat(newValue);
labelComponent.setScale(newScale);
} catch (NumberFormatException e) { }
}, () -> {
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 206:
editor.setSubGuiOverlay(new SubGuiEditProperty("Alpha", Float.toString(labelComponent.getAlpha()),
newValue -> {
try {
float newAlpha = Float.parseFloat(newValue);
labelComponent.setAlpha(newAlpha);
} catch (NumberFormatException e) { }
}, () -> {
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 207:
editor.setSubGuiOverlay(new SubGuiEditProperty("Rotation", Float.toString(labelComponent.getRotation()),
newValue -> {
try {
float newRot = Float.parseFloat(newValue);
labelComponent.setRotation(newRot);
} catch (NumberFormatException e) { }
}, () -> {
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 208:
editor.setSubGuiOverlay(new SubGuiEditProperty("Text", labelComponent.getText(),
newValue -> labelComponent.setText(newValue), () -> {
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 210:
editor.setSubGuiOverlay(new SubGuiEditProperty("ID", Integer.toString(labelComponent.getID()),
newValue -> {
try {
int newID = Integer.parseInt(newValue);
labelComponent.setID(newID);
} catch (NumberFormatException e) { }
}, () -> {
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
}
}
}
@@ -0,0 +1,109 @@
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.GuiButton;
import java.util.List;
/**
* EditorTextFieldComponent wraps a ScriptGuiTextField.
* It renders the actual text field and provides editing buttons for width, height, default text, and ID.
*/
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();
}
@Override
public void render(int mouseX, int mouseY, float partialTicks) {
CustomGuiTextField renderField = CustomGuiTextField.fromComponent(textFieldComponent);
renderField.xPosition = this.posX;
renderField.yPosition = this.posY;
renderField.drawTextBox();
renderSelectionOutline();
}
@Override
public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) {
if (mouseX >= posX && mouseX < posX + width &&
mouseY >= posY && mouseY < posY + height) {
selected = true;
return true;
}
selected = false;
return false;
}
@Override
public void mouseDragged(int mouseX, int mouseY, int mouseButton) {
if (selected) {
textFieldComponent.setPos(posX, posY);
}
}
@Override
public void mouseReleased(int mouseX, int mouseY, int state) { }
@Override
public Object toScriptComponent() {
return textFieldComponent;
}
@Override
public void addEditorButtons(List<GuiButton> buttonList) {
buttonList.add(new GuiButton(301, 0, 0, 30, 20, "W+"));
buttonList.add(new GuiButton(302, 0, 0, 30, 20, "W-"));
buttonList.add(new GuiButton(303, 0, 0, 30, 20, "H+"));
buttonList.add(new GuiButton(304, 0, 0, 30, 20, "H-"));
buttonList.add(new GuiButton(307, 0, 0, 30, 20, "Txt"));
buttonList.add(new GuiButton(310, 0, 0, 30, 20, "ID"));
}
@Override
public void onEditorButtonPressed(GuiButton button) {
GuiCustomGuiEditor editor = (GuiCustomGuiEditor) Minecraft.getMinecraft().currentScreen;
switch(button.id) {
case 301:
width += 5;
textFieldComponent.setSize(width, height);
break;
case 302:
width = Math.max(10, width - 5);
textFieldComponent.setSize(width, height);
break;
case 303:
height += 5;
textFieldComponent.setSize(width, height);
break;
case 304:
height = Math.max(10, height - 5);
textFieldComponent.setSize(width, height);
break;
case 307:
editor.setSubGuiOverlay(new SubGuiEditProperty("Default Text", textFieldComponent.getText(),
newValue -> textFieldComponent.setText(newValue), () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 310:
editor.setSubGuiOverlay(new SubGuiEditProperty("ID", Integer.toString(textFieldComponent.getID()),
newValue -> {
try {
int newID = Integer.parseInt(newValue);
textFieldComponent.setID(newID);
} catch (NumberFormatException e) { }
}, () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
}
}
}
@@ -0,0 +1,172 @@
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.GuiButton;
import java.util.List;
public class EditorTexturedRectComponent extends AbstractEditorComponent {
private ScriptGuiTexturedRect texturedRect;
public EditorTexturedRectComponent(ScriptGuiTexturedRect rect) {
super(rect.getPosX(), rect.getPosY(), rect.getWidth(), rect.getHeight());
this.texturedRect = rect;
this.id = rect.getID();
}
@Override
public void render(int mouseX, int mouseY, float partialTicks) {
CustomGuiTexturedRect renderRect = CustomGuiTexturedRect.fromComponent(texturedRect);
renderRect.x = this.posX;
renderRect.y = this.posY;
renderRect.scale = texturedRect.getScale();
renderRect.alpha = texturedRect.getAlpha();
renderRect.rotation = texturedRect.getRotation();
renderRect.onRender(Minecraft.getMinecraft(), mouseX, mouseY, 0, partialTicks);
renderSelectionOutline();
}
@Override
public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) {
if (mouseX >= posX && mouseX < posX + width &&
mouseY >= posY && mouseY < posY + height) {
selected = true;
return true;
}
selected = false;
return false;
}
@Override
public void mouseDragged(int mouseX, int mouseY, int mouseButton) {
if (selected) {
texturedRect.setPos(posX, posY);
}
}
@Override
public void mouseReleased(int mouseX, int mouseY, int state) { }
@Override
public Object toScriptComponent() {
return texturedRect;
}
@Override
public void addEditorButtons(List<GuiButton> buttonList) {
buttonList.add(new GuiButton(401, 0, 0, 30, 20, "W+"));
buttonList.add(new GuiButton(402, 0, 0, 30, 20, "W-"));
buttonList.add(new GuiButton(403, 0, 0, 30, 20, "H+"));
buttonList.add(new GuiButton(404, 0, 0, 30, 20, "H-"));
buttonList.add(new GuiButton(405, 0, 0, 30, 20, "Sc"));
buttonList.add(new GuiButton(406, 0, 0, 30, 20, "Al"));
buttonList.add(new GuiButton(407, 0, 0, 30, 20, "Rt"));
buttonList.add(new GuiButton(408, 0, 0, 30, 20, "Tex"));
buttonList.add(new GuiButton(409, 0, 0, 30, 20, "TxX"));
buttonList.add(new GuiButton(410, 0, 0, 30, 20, "TxY"));
buttonList.add(new GuiButton(411, 0, 0, 30, 20, "ID"));
}
@Override
public void onEditorButtonPressed(GuiButton button) {
GuiCustomGuiEditor editor = (GuiCustomGuiEditor) Minecraft.getMinecraft().currentScreen;
switch(button.id) {
case 401:
width += 5;
texturedRect.setSize(width, height);
break;
case 402:
width = Math.max(10, width - 5);
texturedRect.setSize(width, height);
break;
case 403:
height += 5;
texturedRect.setSize(width, height);
break;
case 404:
height = Math.max(10, height - 5);
texturedRect.setSize(width, height);
break;
case 405:
editor.setSubGuiOverlay(new SubGuiEditProperty("Scale", Float.toString(texturedRect.getScale()),
newValue -> {
try {
float newScale = Float.parseFloat(newValue);
texturedRect.setScale(newScale);
} catch (NumberFormatException e) { }
}, () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 406:
editor.setSubGuiOverlay(new SubGuiEditProperty("Alpha", Float.toString(texturedRect.getAlpha()),
newValue -> {
try {
float newAlpha = Float.parseFloat(newValue);
texturedRect.setAlpha(newAlpha);
} catch (NumberFormatException e) { }
}, () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 407:
editor.setSubGuiOverlay(new SubGuiEditProperty("Rotation", Float.toString(texturedRect.getRotation()),
newValue -> {
try {
float newRot = Float.parseFloat(newValue);
texturedRect.setRotation(newRot);
} catch (NumberFormatException e) { }
}, () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 408:
editor.setSubGuiOverlay(new SubGuiEditProperty("Texture", texturedRect.getTexture(),
newValue -> texturedRect.setTexture(newValue), () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 409:
editor.setSubGuiOverlay(new SubGuiEditProperty("TxX", Integer.toString(texturedRect.getTextureX()),
newValue -> {
try {
int newX = Integer.parseInt(newValue);
texturedRect.setTextureOffset(newX, texturedRect.getTextureY());
} catch (NumberFormatException e) { }
}, () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 410:
editor.setSubGuiOverlay(new SubGuiEditProperty("TxY", Integer.toString(texturedRect.getTextureY()),
newValue -> {
try {
int newY = Integer.parseInt(newValue);
texturedRect.setTextureOffset(texturedRect.getTextureX(), newY);
} catch (NumberFormatException e) { }
}, () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
case 411:
editor.setSubGuiOverlay(new SubGuiEditProperty("ID", Integer.toString(texturedRect.getID()),
newValue -> {
try {
int newID = Integer.parseInt(newValue);
texturedRect.setID(newID);
} catch (NumberFormatException e) { }
}, () ->{
editor.clearSubGuiOverlay();
editor.setSelectedComponent(this);
}));
break;
}
}
}
@@ -0,0 +1,91 @@
package kamkeel.npcs.editorgui;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiButton;
import java.util.ArrayList;
import java.util.List;
/**
* EditorToolBar renders a toolbar at the bottom with buttons to add components or save the GUI.
*/
public class EditorToolBar extends Gui {
private List<GuiButton> buttons = new ArrayList<>();
private int x, y, width, height;
public EditorToolBar(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
initButtons();
}
private void initButtons() {
buttons.clear();
// IDs: 1 = Add Button, 2 = Add Label, 3 = Add TextField, 4 = Add Rect, 8 = Save.
buttons.add(new GuiButton(1, x + 10, y + 10, 80, 20, "Add Button"));
buttons.add(new GuiButton(2, x + 100, y + 10, 80, 20, "Add Label"));
buttons.add(new GuiButton(3, x + 190, y + 10, 80, 20, "Add TextField"));
buttons.add(new GuiButton(4, x + 280, y + 10, 80, 20, "Add Rect"));
buttons.add(new GuiButton(8, x + 370, y + 10, 80, 20, "Save"));
}
public void render(int mouseX, int mouseY, float partialTicks) {
// Optionally draw a background (commented out if undesired).
// drawRect(x, y, x + width, y + height, 0xAA333333);
for (GuiButton btn : buttons) {
btn.drawButton(Minecraft.getMinecraft(), mouseX, mouseY);
}
}
public List<GuiButton> getButtons() {
return buttons;
}
public void updateDimensions(int newX, int newY, int newWidth, int newHeight) {
this.x = newX;
this.y = newY;
this.width = newWidth;
this.height = newHeight;
initButtons();
}
private int getDefaultId() {
return 1;
}
public void actionPerformed(GuiButton button, GuiCustomGuiEditor editor) {
int centerX = editor.canvasX + editor.canvasWidth / 2;
int centerY = editor.canvasY + editor.canvasHeight / 2;
switch (button.id) {
case 1:
noppes.npcs.scripted.gui.ScriptGuiButton newButton =
new noppes.npcs.scripted.gui.ScriptGuiButton(getDefaultId(), "New Button", centerX - 40, centerY - 10, 80, 20);
EditorButtonComponent eButton = new EditorButtonComponent(newButton);
editor.addEditorComponent(eButton);
break;
case 2:
noppes.npcs.scripted.gui.ScriptGuiLabel newLabel =
new noppes.npcs.scripted.gui.ScriptGuiLabel(getDefaultId(), "New Label", centerX - 40, centerY - 10, 80, 20);
EditorLabelComponent eLabel = new EditorLabelComponent(newLabel);
editor.addEditorComponent(eLabel);
break;
case 3:
noppes.npcs.scripted.gui.ScriptGuiTextField newField =
new noppes.npcs.scripted.gui.ScriptGuiTextField(getDefaultId(), centerX - 50, centerY - 10, 100, 20);
EditorTextFieldComponent eField = new EditorTextFieldComponent(newField);
editor.addEditorComponent(eField);
break;
case 4:
noppes.npcs.scripted.gui.ScriptGuiTexturedRect newRect =
new noppes.npcs.scripted.gui.ScriptGuiTexturedRect(getDefaultId(), "default:texture", centerX - 40, centerY - 10, 80, 20);
EditorTexturedRectComponent eRect = new EditorTexturedRectComponent(newRect);
editor.addEditorComponent(eRect);
break;
case 8:
editor.saveAndClose();
break;
}
}
}
@@ -0,0 +1,277 @@
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.ScaledResolution;
import noppes.npcs.scripted.gui.ScriptGui;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
/**
* GuiCustomGuiEditor is the main editor screen.
* The canvas covers the full scaled resolution.
* 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 for property editing.
*/
public class GuiCustomGuiEditor extends GuiScreen {
// Full-screen canvas.
public int canvasX = 0;
public int canvasY = 0;
public int canvasWidth;
public int canvasHeight;
private List<IEditorComponent> editorComponents = new ArrayList<>();
private EditorToolBar toolBar;
private IEditorComponent selectedComponent;
private CustomGuiEditorController controller;
// The sub–GUI overlay for property editing; null if none is open.
private SubGuiEditProperty subGuiOverlay = null;
// For dragging: offset from mouse to component's top–left.
private int dragOffsetX, dragOffsetY;
private boolean isDragging = false;
public GuiCustomGuiEditor() {
controller = new CustomGuiEditorController();
mc = Minecraft.getMinecraft();
}
@Override
public void initGui() {
ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
canvasWidth = res.getScaledWidth();
canvasHeight = res.getScaledHeight();
canvasX = 0;
canvasY = 0;
toolBar = new EditorToolBar(canvasX, canvasY + canvasHeight - 40, canvasWidth, 40);
toolBar.updateDimensions(canvasX, canvasY + canvasHeight - 40, canvasWidth, 40);
}
@Override
public void drawDefaultBackground() {
// Fill the full screen with a light background.
drawRect(canvasX, canvasY, canvasX + canvasWidth, canvasY + canvasHeight, 0xFFCCCCCC);
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
drawDefaultBackground();
// Sort components by ID ascending so that higher IDs render on top.
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);
}
}
}
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
if (subGuiOverlay != null) {
subGuiOverlay.mouseClicked(mouseX, mouseY, mouseButton);
return;
}
// Check if any custom editing button (IDs 101–500) is clicked.
for (Object obj : this.buttonList) {
GuiButton btn = (GuiButton) obj;
if (btn.id >= 101 && btn.id < 500 && btn.mousePressed(mc, mouseX, mouseY)) {
this.actionPerformed(btn);
updateCustomButtons();
return;
}
}
// Let toolbar buttons handle clicks.
for (GuiButton btn : toolBar.getButtons()) {
if (btn.mousePressed(mc, mouseX, mouseY)) {
toolBar.actionPerformed(btn, this);
updateCustomButtons();
return;
}
}
boolean anySelected = false;
for (IEditorComponent comp : editorComponents) {
if (comp.mouseClicked(mouseX, mouseY, mouseButton)) {
selectedComponent = comp;
anySelected = true;
} else {
comp.setSelected(false);
}
}
if (!anySelected) {
selectedComponent = null;
} else if (selectedComponent != null) {
dragOffsetX = mouseX - ((AbstractEditorComponent) selectedComponent).posX;
dragOffsetY = mouseY - ((AbstractEditorComponent) selectedComponent).posY;
isDragging = true;
}
updateCustomButtons();
super.mouseClicked(mouseX, mouseY, mouseButton);
}
@Override
public void mouseMovedOrUp(int mouseX, int mouseY, int state) {
if (subGuiOverlay != null) {
subGuiOverlay.mouseMovedOrUp(mouseX, mouseY, state);
return;
}
if (selectedComponent != null) {
selectedComponent.mouseReleased(mouseX, mouseY, state);
}
isDragging = false;
super.mouseMovedOrUp(mouseX, mouseY, state);
}
@Override
public void mouseClickMove(int mouseX, int mouseY, int mouseButton, long timeSinceLastClick) {
if (subGuiOverlay != null) {
subGuiOverlay.mouseClickMove(mouseX, mouseY, mouseButton, timeSinceLastClick);
return;
}
if (isDragging && selectedComponent != null) {
int newX = mouseX - dragOffsetX;
int newY = mouseY - dragOffsetY;
int compW = ((AbstractEditorComponent) selectedComponent).width;
int compH = ((AbstractEditorComponent) selectedComponent).height;
if (newX < canvasX) newX = canvasX;
if (newY < canvasY) newY = canvasY;
if (newX + compW > canvasWidth) newX = canvasWidth - compW;
if (newY + compH > canvasHeight) newY = canvasHeight - compH;
((AbstractEditorComponent) selectedComponent).posX = newX;
((AbstractEditorComponent) selectedComponent).posY = newY;
selectedComponent.mouseDragged(mouseX, mouseY, mouseButton);
}
super.mouseClickMove(mouseX, mouseY, mouseButton, timeSinceLastClick);
}
@Override
public void keyTyped(char typedChar, int keyCode) {
if (subGuiOverlay != null) {
subGuiOverlay.keyTyped(typedChar, keyCode);
return;
}
if (keyCode == Keyboard.KEY_ESCAPE) {
saveAndClose();
return;
}
if (keyCode == Keyboard.KEY_DELETE || keyCode == Keyboard.KEY_BACK) {
if (selectedComponent != null) {
Iterator<IEditorComponent> iter = editorComponents.iterator();
while (iter.hasNext()) {
IEditorComponent comp = iter.next();
if (comp == selectedComponent) {
iter.remove();
selectedComponent = null;
break;
}
}
}
}
updateCustomButtons();
super.keyTyped(typedChar, keyCode);
}
@Override
protected void actionPerformed(GuiButton button) {
if (button.id >= 101 && button.id < 500) {
if (selectedComponent != null)
selectedComponent.onEditorButtonPressed(button);
updateCustomButtons();
} else {
toolBar.actionPerformed(button, this);
}
}
/**
* Updates custom editing buttons (IDs 101–500) so they appear in a single row at the top.
*/
private void updateCustomButtons() {
for (int i = buttonList.size() - 1; i >= 0; i--) {
GuiButton btn = (GuiButton) buttonList.get(i);
if (btn.id >= 101 && btn.id < 500) {
buttonList.remove(i);
}
}
if (selectedComponent != null) {
List<GuiButton> customButtons = new ArrayList<>();
selectedComponent.addEditorButtons(customButtons);
int startX = 5;
int startY = 5;
int buttonWidth = 30;
int buttonHeight = 20;
int spacing = 5;
int currentX = startX;
for (GuiButton btn : customButtons) {
btn.xPosition = currentX;
btn.yPosition = startY;
btn.width = buttonWidth;
btn.height = buttonHeight;
currentX += buttonWidth + spacing;
}
buttonList.addAll(customButtons);
}
}
/**
* Adds a new editor component.
*/
public void addEditorComponent(IEditorComponent comp) {
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.
*/
public void saveAndClose() {
ScriptGui newGui = new ScriptGui();
for (IEditorComponent comp : editorComponents) {
newGui.updateComponent((noppes.npcs.api.gui.ICustomGuiComponent) comp.toScriptComponent());
}
CustomGuiEditorController controller = new CustomGuiEditorController();
controller.saveGui(new File("customgui.json"), newGui);
Minecraft.getMinecraft().displayGuiScreen(null);
}
/**
* Sets the current sub–GUI overlay (for property editing) and forwards events to it.
*/
public void setSubGuiOverlay(SubGuiEditProperty overlay) {
overlay.initGui();
this.subGuiOverlay = overlay;
}
/**
* Clears the sub–GUI overlay.
*/
public void clearSubGuiOverlay() {
this.subGuiOverlay = null;
}
}
@@ -0,0 +1,33 @@
package kamkeel.npcs.editorgui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.nbt.NBTTagCompound;
import java.util.List;
/**
* IEditorComponent defines the methods that all editor wrappers must implement.
*/
public interface IEditorComponent {
void render(int mouseX, int mouseY, float partialTicks);
boolean mouseClicked(int mouseX, int mouseY, int mouseButton);
void mouseDragged(int mouseX, int mouseY, int mouseButton);
void mouseReleased(int mouseX, int mouseY, int state);
void update();
Object toScriptComponent();
void setSelected(boolean selected);
boolean isSelected();
/**
* Add custom editing buttons (IDs 101–500) to the provided list.
*/
default void addEditorButtons(List<GuiButton> buttonList) { }
/**
* Called when one of the custom editing buttons is pressed.
*/
default void onEditorButtonPressed(GuiButton button) { }
default NBTTagCompound toEditorNBT() {
return new NBTTagCompound();
}
}
@@ -0,0 +1,9 @@
package kamkeel.npcs.editorgui;
/**
* IPropertyEditorCallback is used by the property editor overlay
* to return the updated value.
*/
public interface IPropertyEditorCallback {
void propertyUpdated(String newValue);
}
@@ -0,0 +1,8 @@
package kamkeel.npcs.editorgui;
/**
* ISubGuiCallback allows a sub–GUI overlay to notify its parent when it’s done.
*/
public interface ISubGuiCallback {
void onSubGuiClosed();
}
@@ -0,0 +1,131 @@
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 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;
private IPropertyEditorCallback propCallback;
private GuiTextField textField;
private String propertyName;
private String initialValue;
// Overlay dimensions
private int overlayX, overlayY, overlayWidth, overlayHeight;
/**
* Creates a new property editor overlay.
* @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 is closed
*/
public SubGuiEditProperty(String propertyName, String initialValue, IPropertyEditorCallback propCallback, ISubGuiCallback subGuiCallback) {
this.propertyName = propertyName;
this.initialValue = (initialValue == null ? "" : initialValue);
this.propCallback = propCallback;
this.subGuiCallback = subGuiCallback;
}
@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 = (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 positioned below the text field.
buttonList.add(new GuiButton(1000000, overlayX, overlayY + overlayHeight + 5, overlayWidth, 20, "Done"));
}
@Override
public void updateScreen() {
textField.updateCursorCounter();
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
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
public void keyTyped(char typedChar, int keyCode) {
textField.textboxKeyTyped(typedChar, keyCode);
if (keyCode == Keyboard.KEY_ESCAPE) {
closeOverlay();
}
}
@Override
public void actionPerformed(GuiButton button) {
if (button.id == 1000000) {
if (propCallback != null) {
propCallback.propertyUpdated(textField.getText());
}
closeOverlay();
}
}
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
super.mouseClicked(mouseX, mouseY, mouseButton);
}
@Override
public void mouseMovedOrUp(int mouseX, int mouseY, int state) {
super.mouseMovedOrUp(mouseX, mouseY, state);
}
@Override
public void mouseClickMove(int mouseX, int mouseY, int mouseButton, long timeSinceLastClick) {
super.mouseClickMove(mouseX, mouseY, mouseButton, timeSinceLastClick);
}
public void closeOverlay() {
Keyboard.enableRepeatEvents(false);
if(textField != null) {
textField.setFocused(false);
}
if (subGuiCallback != null) {
subGuiCallback.onSubGuiClosed();
}
}
}
@@ -6,6 +6,7 @@ import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.ObfuscationReflectionHelper; import cpw.mods.fml.common.ObfuscationReflectionHelper;
import kamkeel.npcs.addon.client.DBCClient; import kamkeel.npcs.addon.client.DBCClient;
import kamkeel.npcs.editorgui.GuiCustomGuiEditor;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.model.ModelBiped; import net.minecraft.client.model.ModelBiped;
@@ -268,7 +269,9 @@ public class ClientProxy extends CommonProxy {
return new GuiNpcPather(npc); return new GuiNpcPather(npc);
else if (gui == EnumGuiType.ManageFactions) else if (gui == EnumGuiType.ManageFactions)
return new GuiNPCManageFactions(npc); return new GuiCustomGuiEditor();
// TODO: CHANGE BACK
// return new GuiNPCManageFactions(npc);
else if (gui == EnumGuiType.ManageCustomForms) else if (gui == EnumGuiType.ManageCustomForms)
return DBCClient.Instance.manageCustomForms(npc); return DBCClient.Instance.manageCustomForms(npc);
@@ -23,9 +23,9 @@ public class CustomGuiButton extends GuiButton implements IClickListener {
String label; String label;
String[] hoverText; String[] hoverText;
int color; public int color;
float alpha; public float alpha;
float scale = 1.0F; public float scale = 1.0F;
public CustomGuiButton(int id, String buttonText, int x, int y) { public CustomGuiButton(int id, String buttonText, int x, int y) {
super(id, x, y, buttonText); super(id, x, y, buttonText);
@@ -20,7 +20,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
public class CustomGuiLabel extends Gui implements IGuiComponent { public class CustomGuiLabel extends Gui implements IGuiComponent {
int x, y, width, height; public int x, y, width, height;
GuiCustom parent; GuiCustom parent;
String fullLabel; String fullLabel;
String[] hoverText; String[] hoverText;
@@ -30,9 +30,9 @@ public class CustomGuiLabel extends Gui implements IGuiComponent {
boolean labelBgEnabled = true; boolean labelBgEnabled = true;
boolean labelShadowEnabled = false; boolean labelShadowEnabled = false;
int color; public int color;
float alpha; public float alpha;
float rotation; public float rotation;
protected int field_146167_a; protected int field_146167_a;
protected int field_146161_f; protected int field_146161_f;
@@ -15,20 +15,20 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
GuiCustom parent; GuiCustom parent;
ImageData imageData = null; ImageData imageData = null;
String texture; public String texture;
int id; public int id;
int x; public int x;
int y; public int y;
int width; public int width;
int height; public int height;
int textureX; public int textureX;
int textureY; public int textureY;
float scale; public float scale;
String[] hoverText; String[] hoverText;
int color; public int color;
float alpha; public float alpha;
float rotation; public float rotation;
public CustomGuiTexturedRect(int id, String texture, int x, int y, int width, int height) { public CustomGuiTexturedRect(int id, String texture, int x, int y, int width, int height) {
this(id, texture, x, y, width, height, 0, 0); this(id, texture, x, y, width, height, 0, 0);