mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-26 19:43:07 +00:00
Another Rendition Rewrite
This commit is contained in:
1 parent
f94f80ea41
commit
3c1f7f9e60
14 files changed
+378
-147
No files matched your search
@@ -3,11 +3,12 @@ package kamkeel.npcs.editorgui;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
|
||||
/**
|
||||
* AbstractEditorComponent provides common position/size fields and a method to draw
|
||||
* a yellow selection outline when the component is selected.
|
||||
* AbstractEditorComponent provides common fields and methods for all editor components.
|
||||
*/
|
||||
public abstract class AbstractEditorComponent extends Gui implements IEditorComponent {
|
||||
// These fields are public for easy access.
|
||||
// Store the editor component's ID.
|
||||
protected int id;
|
||||
// Position and size.
|
||||
public int posX, posY, width, height;
|
||||
protected boolean selected = false;
|
||||
|
||||
@@ -18,6 +19,13 @@ public abstract class AbstractEditorComponent extends Gui implements IEditorComp
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID for this editor component.
|
||||
*/
|
||||
public int getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(boolean selected) {
|
||||
this.selected = selected;
|
||||
@@ -29,18 +37,18 @@ public abstract class AbstractEditorComponent extends Gui implements IEditorComp
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a 2–pixel thick yellow border if this component is selected.
|
||||
* Draws a 2-pixel thick yellow border if selected.
|
||||
*/
|
||||
protected void renderSelectionOutline() {
|
||||
if (!selected)
|
||||
return;
|
||||
// Top edge
|
||||
// Top
|
||||
drawRect(posX - 2, posY - 2, posX + width + 2, posY - 1, 0xFFFFFF00);
|
||||
// Bottom edge
|
||||
// Bottom
|
||||
drawRect(posX - 2, posY + height + 1, posX + width + 2, posY + height + 2, 0xFFFFFF00);
|
||||
// Left edge
|
||||
// Left
|
||||
drawRect(posX - 2, posY - 2, posX - 1, posY + height + 2, 0xFFFFFF00);
|
||||
// Right edge
|
||||
// Right
|
||||
drawRect(posX + width + 1, posY - 2, posX + width + 2, posY + height + 2, 0xFFFFFF00);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
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 org.lwjgl.input.Mouse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* EditorButtonComponent wraps a ScriptGuiButton.
|
||||
* It supports dragging and provides custom editing buttons to modify width, height,
|
||||
* scale, label text, and the component ID.
|
||||
* EditorButtonComponent wraps a ScriptGuiButton for editing.
|
||||
*/
|
||||
public class EditorButtonComponent extends AbstractEditorComponent {
|
||||
private ScriptGuiButton buttonComponent;
|
||||
@@ -18,15 +16,17 @@ public class EditorButtonComponent extends AbstractEditorComponent {
|
||||
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) {
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
drawRect(posX, posY, posX + width, posY + height, 0xFF888888);
|
||||
String label = buttonComponent.getLabel();
|
||||
if (label != null)
|
||||
fr.drawStringWithShadow(label, posX + (width - fr.getStringWidth(label)) / 2, posY + (height - 8) / 2, buttonComponent.getColor());
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class EditorButtonComponent extends AbstractEditorComponent {
|
||||
|
||||
@Override
|
||||
public void mouseDragged(int mouseX, int mouseY, int mouseButton) {
|
||||
if (selected) {
|
||||
if(selected) {
|
||||
buttonComponent.setPos(posX, posY);
|
||||
}
|
||||
}
|
||||
@@ -58,15 +58,15 @@ public class EditorButtonComponent extends AbstractEditorComponent {
|
||||
|
||||
@Override
|
||||
public void addEditorButtons(List<GuiButton> buttonList) {
|
||||
// Create custom editing buttons with dummy positions.
|
||||
// The updateCustomButtons() in the editor repositions them to the top row.
|
||||
buttonList.add(new GuiButton(101, 0, 0, 0, 0, "W+"));
|
||||
buttonList.add(new GuiButton(102, 0, 0, 0, 0, "W-"));
|
||||
buttonList.add(new GuiButton(103, 0, 0, 0, 0, "H+"));
|
||||
buttonList.add(new GuiButton(104, 0, 0, 0, 0, "H-"));
|
||||
buttonList.add(new GuiButton(105, 0, 0, 0, 0, "Sc"));
|
||||
buttonList.add(new GuiButton(107, 0, 0, 0, 0, "Lbl"));
|
||||
buttonList.add(new GuiButton(110, 0, 0, 0, 0, "ID"));
|
||||
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
|
||||
@@ -89,7 +89,7 @@ public class EditorButtonComponent extends AbstractEditorComponent {
|
||||
buttonComponent.setSize(width, height);
|
||||
break;
|
||||
case 105:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty(Minecraft.getMinecraft().currentScreen, "Scale", Float.toString(buttonComponent.getScale()), new IPropertyEditorCallback() {
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("Scale", Float.toString(buttonComponent.getScale()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
try {
|
||||
@@ -97,18 +97,54 @@ public class EditorButtonComponent extends AbstractEditorComponent {
|
||||
buttonComponent.setScale(newScale);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() {
|
||||
// Return to editor: do nothing extra.
|
||||
}
|
||||
}));
|
||||
break;
|
||||
case 106:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("Alpha", Float.toString(buttonComponent.getAlpha()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
try {
|
||||
float newAlpha = Float.parseFloat(newValue);
|
||||
buttonComponent.setAlpha(newAlpha);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}));
|
||||
break;
|
||||
case 107:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty(Minecraft.getMinecraft().currentScreen, "Label", buttonComponent.getLabel(), new IPropertyEditorCallback() {
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("Rotation", Float.toString(buttonComponent.getRotation()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
try {
|
||||
float newRotation = Float.parseFloat(newValue);
|
||||
buttonComponent.setRotation(newRotation);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}));
|
||||
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() { }
|
||||
}));
|
||||
break;
|
||||
case 110:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty(Minecraft.getMinecraft().currentScreen, "ID", Integer.toString(buttonComponent.getID()), new IPropertyEditorCallback() {
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("ID", Integer.toString(buttonComponent.getID()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
try {
|
||||
@@ -116,6 +152,9 @@ public class EditorButtonComponent extends AbstractEditorComponent {
|
||||
buttonComponent.setID(newID);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
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 and adds editing buttons for width, height, scale, text, and ID.
|
||||
* EditorLabelComponent wraps a ScriptGuiLabel.
|
||||
*/
|
||||
public class EditorLabelComponent extends AbstractEditorComponent {
|
||||
private ScriptGuiLabel labelComponent;
|
||||
@@ -15,15 +16,18 @@ public class EditorLabelComponent extends AbstractEditorComponent {
|
||||
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) {
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
drawRect(posX, posY, posX + width, posY + height, 0xFFAAAAAA);
|
||||
String text = labelComponent.getText();
|
||||
if(text != null)
|
||||
fr.drawStringWithShadow(text, posX + 2, posY + (height - 8) / 2, labelComponent.getColor());
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -55,13 +59,15 @@ public class EditorLabelComponent extends AbstractEditorComponent {
|
||||
|
||||
@Override
|
||||
public void addEditorButtons(List<GuiButton> buttonList) {
|
||||
buttonList.add(new GuiButton(201, 0, 0, 0, 0, "W+"));
|
||||
buttonList.add(new GuiButton(202, 0, 0, 0, 0, "W-"));
|
||||
buttonList.add(new GuiButton(203, 0, 0, 0, 0, "H+"));
|
||||
buttonList.add(new GuiButton(204, 0, 0, 0, 0, "H-"));
|
||||
buttonList.add(new GuiButton(205, 0, 0, 0, 0, "Sc"));
|
||||
buttonList.add(new GuiButton(207, 0, 0, 0, 0, "Txt"));
|
||||
buttonList.add(new GuiButton(210, 0, 0, 0, 0, "ID"));
|
||||
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
|
||||
@@ -84,7 +90,7 @@ public class EditorLabelComponent extends AbstractEditorComponent {
|
||||
labelComponent.setSize(width, height);
|
||||
break;
|
||||
case 205:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty(Minecraft.getMinecraft().currentScreen, "Scale", Float.toString(labelComponent.getScale()), new IPropertyEditorCallback() {
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("Scale", Float.toString(labelComponent.getScale()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
try {
|
||||
@@ -92,18 +98,52 @@ public class EditorLabelComponent extends AbstractEditorComponent {
|
||||
labelComponent.setScale(newScale);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}));
|
||||
break;
|
||||
case 206:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("Alpha", Float.toString(labelComponent.getAlpha()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
try {
|
||||
float newAlpha = Float.parseFloat(newValue);
|
||||
labelComponent.setAlpha(newAlpha);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}));
|
||||
break;
|
||||
case 207:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty(Minecraft.getMinecraft().currentScreen, "Text", labelComponent.getText(), new IPropertyEditorCallback() {
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("Rotation", Float.toString(labelComponent.getRotation()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
try {
|
||||
float newRot = Float.parseFloat(newValue);
|
||||
labelComponent.setRotation(newRot);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}));
|
||||
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() { }
|
||||
}));
|
||||
break;
|
||||
case 210:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty(Minecraft.getMinecraft().currentScreen, "ID", Integer.toString(labelComponent.getID()), new IPropertyEditorCallback() {
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("ID", Integer.toString(labelComponent.getID()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
try {
|
||||
@@ -111,6 +151,9 @@ public class EditorLabelComponent extends AbstractEditorComponent {
|
||||
labelComponent.setID(newID);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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;
|
||||
@@ -8,8 +9,7 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* EditorTextFieldComponent wraps a ScriptGuiTextField.
|
||||
* Since ScriptGuiTextField only supports width, height, and default text,
|
||||
* this editor only provides editing buttons for width, height, and default text.
|
||||
* 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;
|
||||
@@ -17,22 +17,22 @@ public class EditorTextFieldComponent extends AbstractEditorComponent {
|
||||
public EditorTextFieldComponent(ScriptGuiTextField textField) {
|
||||
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) {
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
drawRect(posX, posY, posX + width, posY + height, 0xFFFFFFFF);
|
||||
String text = textFieldComponent.getText();
|
||||
if(text != null)
|
||||
fr.drawStringWithShadow(text, posX + 2, posY + (height - 8) / 2, textFieldComponent.getColor());
|
||||
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) {
|
||||
if(mouseX >= posX && mouseX < posX + width &&
|
||||
mouseY >= posY && mouseY < posY + height) {
|
||||
selected = true;
|
||||
return true;
|
||||
}
|
||||
@@ -57,12 +57,12 @@ public class EditorTextFieldComponent extends AbstractEditorComponent {
|
||||
|
||||
@Override
|
||||
public void addEditorButtons(List<GuiButton> buttonList) {
|
||||
buttonList.add(new GuiButton(301, 0, 0, 0, 0, "W+"));
|
||||
buttonList.add(new GuiButton(302, 0, 0, 0, 0, "W-"));
|
||||
buttonList.add(new GuiButton(303, 0, 0, 0, 0, "H+"));
|
||||
buttonList.add(new GuiButton(304, 0, 0, 0, 0, "H-"));
|
||||
buttonList.add(new GuiButton(307, 0, 0, 0, 0, "Text"));
|
||||
buttonList.add(new GuiButton(310, 0, 0, 0, 0, "ID"));
|
||||
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
|
||||
@@ -85,15 +85,18 @@ public class EditorTextFieldComponent extends AbstractEditorComponent {
|
||||
textFieldComponent.setSize(width, height);
|
||||
break;
|
||||
case 307:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty(Minecraft.getMinecraft().currentScreen, "Default Text", textFieldComponent.getText(), new IPropertyEditorCallback() {
|
||||
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() { }
|
||||
}));
|
||||
break;
|
||||
case 310:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty(Minecraft.getMinecraft().currentScreen, "ID", Integer.toString(textFieldComponent.getID()), new IPropertyEditorCallback() {
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("ID", Integer.toString(textFieldComponent.getID()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
try {
|
||||
@@ -101,6 +104,9 @@ public class EditorTextFieldComponent extends AbstractEditorComponent {
|
||||
textFieldComponent.setID(newID);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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;
|
||||
@@ -8,7 +9,8 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* EditorTexturedRectComponent wraps a ScriptGuiTexturedRect.
|
||||
* It adds editing buttons for width, height, scale, texture string, texture X/Y offsets, and ID.
|
||||
* 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;
|
||||
@@ -16,22 +18,25 @@ public class EditorTexturedRectComponent extends AbstractEditorComponent {
|
||||
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) {
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
drawRect(posX, posY, posX + width, posY + height, 0xFF000088);
|
||||
String tex = texturedRect.getTexture();
|
||||
if(tex != null)
|
||||
fr.drawStringWithShadow(tex, posX + 2, posY + 2, 0xFFFFFF);
|
||||
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) {
|
||||
if(mouseX >= posX && mouseX < posX + width &&
|
||||
mouseY >= posY && mouseY < posY + height) {
|
||||
selected = true;
|
||||
return true;
|
||||
}
|
||||
@@ -56,15 +61,17 @@ public class EditorTexturedRectComponent extends AbstractEditorComponent {
|
||||
|
||||
@Override
|
||||
public void addEditorButtons(List<GuiButton> buttonList) {
|
||||
buttonList.add(new GuiButton(401, 0, 0, 0, 0, "W+"));
|
||||
buttonList.add(new GuiButton(402, 0, 0, 0, 0, "W-"));
|
||||
buttonList.add(new GuiButton(403, 0, 0, 0, 0, "H+"));
|
||||
buttonList.add(new GuiButton(404, 0, 0, 0, 0, "H-"));
|
||||
buttonList.add(new GuiButton(405, 0, 0, 0, 0, "Sc"));
|
||||
buttonList.add(new GuiButton(407, 0, 0, 0, 0, "Tex"));
|
||||
buttonList.add(new GuiButton(408, 0, 0, 0, 0, "TxX"));
|
||||
buttonList.add(new GuiButton(409, 0, 0, 0, 0, "TxY"));
|
||||
buttonList.add(new GuiButton(410, 0, 0, 0, 0, "ID"));
|
||||
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
|
||||
@@ -87,7 +94,7 @@ public class EditorTexturedRectComponent extends AbstractEditorComponent {
|
||||
texturedRect.setSize(width, height);
|
||||
break;
|
||||
case 405:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty(Minecraft.getMinecraft().currentScreen, "Scale", Float.toString(texturedRect.getScale()), new IPropertyEditorCallback() {
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("Scale", Float.toString(texturedRect.getScale()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
try {
|
||||
@@ -95,18 +102,52 @@ public class EditorTexturedRectComponent extends AbstractEditorComponent {
|
||||
texturedRect.setScale(newScale);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}));
|
||||
break;
|
||||
case 406:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("Alpha", Float.toString(texturedRect.getAlpha()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
try {
|
||||
float newAlpha = Float.parseFloat(newValue);
|
||||
texturedRect.setAlpha(newAlpha);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}));
|
||||
break;
|
||||
case 407:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty(Minecraft.getMinecraft().currentScreen, "Texture", texturedRect.getTexture(), new IPropertyEditorCallback() {
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("Rotation", Float.toString(texturedRect.getRotation()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
try {
|
||||
float newRot = Float.parseFloat(newValue);
|
||||
texturedRect.setRotation(newRot);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}));
|
||||
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() { }
|
||||
}));
|
||||
break;
|
||||
case 408:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty(Minecraft.getMinecraft().currentScreen, "TxX", Integer.toString(texturedRect.getTextureX()), new IPropertyEditorCallback() {
|
||||
case 409:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("TxX", Integer.toString(texturedRect.getTextureX()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
try {
|
||||
@@ -114,10 +155,13 @@ public class EditorTexturedRectComponent extends AbstractEditorComponent {
|
||||
texturedRect.setTextureOffset(newX, texturedRect.getTextureY());
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}));
|
||||
break;
|
||||
case 409:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty(Minecraft.getMinecraft().currentScreen, "TxY", Integer.toString(texturedRect.getTextureY()), new IPropertyEditorCallback() {
|
||||
case 410:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("TxY", Integer.toString(texturedRect.getTextureY()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
try {
|
||||
@@ -125,10 +169,13 @@ public class EditorTexturedRectComponent extends AbstractEditorComponent {
|
||||
texturedRect.setTextureOffset(texturedRect.getTextureX(), newY);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}));
|
||||
break;
|
||||
case 410:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty(Minecraft.getMinecraft().currentScreen, "ID", Integer.toString(texturedRect.getID()), new IPropertyEditorCallback() {
|
||||
case 411:
|
||||
Minecraft.getMinecraft().displayGuiScreen(new SubGuiEditProperty("ID", Integer.toString(texturedRect.getID()), new IPropertyEditorCallback() {
|
||||
@Override
|
||||
public void propertyUpdated(String newValue) {
|
||||
try {
|
||||
@@ -136,6 +183,9 @@ public class EditorTexturedRectComponent extends AbstractEditorComponent {
|
||||
texturedRect.setID(newID);
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
}, new ISubGuiCallback() {
|
||||
@Override
|
||||
public void onSubGuiClosed() { }
|
||||
}));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -7,8 +7,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* EditorToolBar renders a toolbar with buttons for adding new components and saving the GUI.
|
||||
* Its dimensions are provided by the editor (full-screen canvas).
|
||||
* 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<>();
|
||||
@@ -33,7 +32,7 @@ public class EditorToolBar extends Gui {
|
||||
}
|
||||
|
||||
public void render(int mouseX, int mouseY, float partialTicks) {
|
||||
// Optionally, uncomment the background draw.
|
||||
// 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);
|
||||
|
||||
@@ -9,6 +9,8 @@ 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;
|
||||
|
||||
@@ -16,7 +18,9 @@ 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) appear in a single row at the top with a 20-pixel height.
|
||||
* 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.
|
||||
*/
|
||||
public class GuiCustomGuiEditor extends GuiScreen {
|
||||
// Full-screen canvas.
|
||||
@@ -30,6 +34,9 @@ public class GuiCustomGuiEditor extends GuiScreen {
|
||||
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;
|
||||
@@ -59,26 +66,43 @@ public class GuiCustomGuiEditor extends GuiScreen {
|
||||
@Override
|
||||
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);
|
||||
// If a sub–GUI overlay is open, draw it on top.
|
||||
if (subGuiOverlay != null) {
|
||||
subGuiOverlay.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
// FIRST, check if any custom editing button (IDs 101-500) is clicked.
|
||||
// If a sub–GUI overlay is open, forward the click to it.
|
||||
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)) {
|
||||
// Dispatch custom editing button; do not clear selection.
|
||||
this.actionPerformed(btn);
|
||||
updateCustomButtons();
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Next, let the toolbar buttons handle the click.
|
||||
// Let toolbar buttons handle clicks.
|
||||
for (GuiButton btn : toolBar.getButtons()) {
|
||||
if (btn.mousePressed(mc, mouseX, mouseY)) {
|
||||
toolBar.actionPerformed(btn, this);
|
||||
@@ -107,7 +131,11 @@ public class GuiCustomGuiEditor extends GuiScreen {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseMovedOrUp(int mouseX, int mouseY, int state) {
|
||||
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);
|
||||
}
|
||||
@@ -117,6 +145,11 @@ 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;
|
||||
}
|
||||
if (isDragging && selectedComponent != null) {
|
||||
int newX = mouseX - dragOffsetX;
|
||||
int newY = mouseY - dragOffsetY;
|
||||
@@ -135,6 +168,10 @@ public class GuiCustomGuiEditor extends GuiScreen {
|
||||
|
||||
@Override
|
||||
public void keyTyped(char typedChar, int keyCode) {
|
||||
if (subGuiOverlay != null) {
|
||||
subGuiOverlay.keyTyped(typedChar, keyCode);
|
||||
return;
|
||||
}
|
||||
if (keyCode == Keyboard.KEY_ESCAPE) {
|
||||
saveAndClose();
|
||||
return;
|
||||
@@ -169,7 +206,6 @@ public class GuiCustomGuiEditor extends GuiScreen {
|
||||
|
||||
/**
|
||||
* Updates custom editing buttons (IDs 101–500) so they appear in a single row at the top.
|
||||
* Uses a height of 20 pixels.
|
||||
*/
|
||||
private void updateCustomButtons() {
|
||||
for (int i = buttonList.size() - 1; i >= 0; i--) {
|
||||
@@ -183,8 +219,8 @@ public class GuiCustomGuiEditor extends GuiScreen {
|
||||
selectedComponent.addEditorButtons(customButtons);
|
||||
int startX = 5;
|
||||
int startY = 5;
|
||||
int buttonWidth = 30; // adjust if needed
|
||||
int buttonHeight = 20; // now 20 pixels tall
|
||||
int buttonWidth = 30;
|
||||
int buttonHeight = 20;
|
||||
int spacing = 5;
|
||||
int currentX = startX;
|
||||
for (GuiButton btn : customButtons) {
|
||||
@@ -206,7 +242,7 @@ public class GuiCustomGuiEditor extends GuiScreen {
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a ScriptGui from the editor components, saves it to file, and closes the editor.
|
||||
* Builds a ScriptGui from the editor components, saves it, and closes the editor.
|
||||
*/
|
||||
public void saveAndClose() {
|
||||
ScriptGui newGui = new ScriptGui();
|
||||
@@ -217,4 +253,18 @@ public class GuiCustomGuiEditor extends GuiScreen {
|
||||
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) {
|
||||
this.subGuiOverlay = overlay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the sub–GUI overlay.
|
||||
*/
|
||||
public void clearSubGuiOverlay() {
|
||||
this.subGuiOverlay = null;
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,6 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* IEditorComponent defines the methods that all editor wrappers must implement.
|
||||
* It handles rendering (with optional editing buttons), mouse events, updating,
|
||||
* conversion to the underlying ScriptGui component, and adding custom editor buttons.
|
||||
*/
|
||||
public interface IEditorComponent {
|
||||
void render(int mouseX, int mouseY, float partialTicks);
|
||||
@@ -20,13 +18,12 @@ public interface IEditorComponent {
|
||||
boolean isSelected();
|
||||
|
||||
/**
|
||||
* Adds custom editing buttons to the provided list.
|
||||
* (IDs 101–500 are reserved for custom editing.)
|
||||
* Add custom editing buttons (IDs 101–500) to the provided list.
|
||||
*/
|
||||
default void addEditorButtons(List<GuiButton> buttonList) { }
|
||||
|
||||
/**
|
||||
* Called when a custom editing button is pressed.
|
||||
* Called when one of the custom editing buttons is pressed.
|
||||
*/
|
||||
default void onEditorButtonPressed(GuiButton button) { }
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package kamkeel.npcs.editorgui;
|
||||
|
||||
/**
|
||||
* IPropertyEditorCallback is used by the property editor (SubGuiEditProperty)
|
||||
* IPropertyEditorCallback is used by the property editor overlay
|
||||
* to return the updated value.
|
||||
*/
|
||||
public interface IPropertyEditorCallback {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -6,37 +6,50 @@ import net.minecraft.client.gui.GuiTextField;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
/**
|
||||
* SubGuiEditProperty is a pop-up for editing a property.
|
||||
* It accepts a parent screen and returns to that parent when “Done” is pressed.
|
||||
* 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.
|
||||
*/
|
||||
public class SubGuiEditProperty extends GuiScreen {
|
||||
private GuiScreen parent;
|
||||
private IPropertyEditorCallback callback;
|
||||
private ISubGuiCallback subGuiCallback;
|
||||
private IPropertyEditorCallback propCallback;
|
||||
private GuiTextField textField;
|
||||
private String propertyName;
|
||||
private String initialValue;
|
||||
|
||||
public SubGuiEditProperty(GuiScreen parent, String propertyName, String initialValue, IPropertyEditorCallback callback) {
|
||||
this.parent = parent;
|
||||
// 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 closes
|
||||
*/
|
||||
public SubGuiEditProperty(String propertyName, String initialValue, IPropertyEditorCallback propCallback, ISubGuiCallback subGuiCallback) {
|
||||
this.propertyName = propertyName;
|
||||
// Ensure initialValue is not null
|
||||
this.initialValue = (initialValue == null ? "" : initialValue);
|
||||
this.callback = callback;
|
||||
this.propCallback = propCallback;
|
||||
this.subGuiCallback = subGuiCallback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
Keyboard.enableRepeatEvents(true);
|
||||
int w = 150;
|
||||
int h = 20;
|
||||
int x = (width - w) / 2;
|
||||
int y = (height - h) / 2;
|
||||
textField = new GuiTextField(fontRendererObj, x, y, w, h);
|
||||
// Ensure the text field is set with a non-null string.
|
||||
overlayWidth = 150;
|
||||
overlayHeight = 20;
|
||||
overlayX = (width - overlayWidth) / 2;
|
||||
overlayY = (height - overlayHeight) / 2;
|
||||
textField = new GuiTextField(fontRendererObj, overlayX, overlayY, overlayWidth, overlayHeight);
|
||||
textField.setText(initialValue);
|
||||
textField.setFocused(true);
|
||||
buttonList.clear();
|
||||
buttonList.add(new GuiButton(0, x, y + h + 5, w, 20, "Done"));
|
||||
// "Done" button below the text field.
|
||||
buttonList.add(new GuiButton(0, overlayX, overlayY + overlayHeight + 5, overlayWidth, 20, "Done"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -46,8 +59,9 @@ public class SubGuiEditProperty extends GuiScreen {
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
drawDefaultBackground();
|
||||
drawCenteredString(fontRendererObj, "Edit " + propertyName, width / 2, height / 2 - 40, 0xFFFFFF);
|
||||
// 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);
|
||||
textField.drawTextBox();
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
@@ -56,22 +70,39 @@ public class SubGuiEditProperty extends GuiScreen {
|
||||
protected void keyTyped(char typedChar, int keyCode) {
|
||||
textField.textboxKeyTyped(typedChar, keyCode);
|
||||
if (keyCode == Keyboard.KEY_ESCAPE) {
|
||||
mc.displayGuiScreen(parent);
|
||||
closeOverlay();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
if (button.id == 0) {
|
||||
if (callback != null) {
|
||||
callback.propertyUpdated(textField.getText());
|
||||
if (propCallback != null) {
|
||||
propCallback.propertyUpdated(textField.getText());
|
||||
}
|
||||
mc.displayGuiScreen(parent);
|
||||
closeOverlay();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiClosed() {
|
||||
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);
|
||||
}
|
||||
|
||||
private void closeOverlay() {
|
||||
Keyboard.enableRepeatEvents(false);
|
||||
if (subGuiCallback != null) {
|
||||
subGuiCallback.onSubGuiClosed();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,9 +23,9 @@ public class CustomGuiButton extends GuiButton implements IClickListener {
|
||||
String label;
|
||||
String[] hoverText;
|
||||
|
||||
int color;
|
||||
float alpha;
|
||||
float scale = 1.0F;
|
||||
public int color;
|
||||
public float alpha;
|
||||
public float scale = 1.0F;
|
||||
|
||||
public CustomGuiButton(int id, String buttonText, int x, int y) {
|
||||
super(id, x, y, buttonText);
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class CustomGuiLabel extends Gui implements IGuiComponent {
|
||||
int x, y, width, height;
|
||||
public int x, y, width, height;
|
||||
GuiCustom parent;
|
||||
String fullLabel;
|
||||
String[] hoverText;
|
||||
@@ -30,9 +30,9 @@ public class CustomGuiLabel extends Gui implements IGuiComponent {
|
||||
boolean labelBgEnabled = true;
|
||||
boolean labelShadowEnabled = false;
|
||||
|
||||
int color;
|
||||
float alpha;
|
||||
float rotation;
|
||||
public int color;
|
||||
public float alpha;
|
||||
public float rotation;
|
||||
|
||||
protected int field_146167_a;
|
||||
protected int field_146161_f;
|
||||
|
||||
@@ -15,20 +15,20 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
|
||||
GuiCustom parent;
|
||||
|
||||
ImageData imageData = null;
|
||||
String texture;
|
||||
int id;
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
int height;
|
||||
int textureX;
|
||||
int textureY;
|
||||
float scale;
|
||||
public String texture;
|
||||
public int id;
|
||||
public int x;
|
||||
public int y;
|
||||
public int width;
|
||||
public int height;
|
||||
public int textureX;
|
||||
public int textureY;
|
||||
public float scale;
|
||||
String[] hoverText;
|
||||
|
||||
int color;
|
||||
float alpha;
|
||||
float rotation;
|
||||
public int color;
|
||||
public float alpha;
|
||||
public float rotation;
|
||||
|
||||
public CustomGuiTexturedRect(int id, String texture, int x, int y, int width, int height) {
|
||||
this(id, texture, x, y, width, height, 0, 0);
|
||||
|
||||
Reference in new issue
Block a user