aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kr/syeyoung/dungeonsguide/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/gui')
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java206
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/gui/elements/MButton.java52
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MColor.java30
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/gui/elements/MFloatSelectionButton.java74
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/gui/elements/MIntegerSelectionButton.java70
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/gui/elements/MLabel.java48
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/gui/elements/MLabelAndElement.java52
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/gui/elements/MParameter.java72
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/gui/elements/MStringSelectionButton.java74
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTabButton.java61
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTabbedPane.java72
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java346
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/gui/elements/MValue.java61
13 files changed, 1218 insertions, 0 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java
new file mode 100755
index 00000000..4eae2298
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java
@@ -0,0 +1,206 @@
+package kr.syeyoung.dungeonsguide.gui;
+
+import lombok.AccessLevel;
+import lombok.Getter;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.GuiScreen;
+import net.minecraft.client.gui.ScaledResolution;
+import net.minecraft.client.renderer.GlStateManager;
+import org.lwjgl.opengl.GL11;
+
+import java.awt.*;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+@Getter
+public class MPanel {
+ protected Rectangle bounds = new Rectangle(0,0,0,0); // relative to parent
+
+ protected List<MPanel> childComponents = new CopyOnWriteArrayList<MPanel>();
+
+ protected Color backgroundColor = new Color(0,0,0,0);
+
+ protected Rectangle lastAbsClip = new Rectangle(0,0,0,0);
+
+ @Getter(AccessLevel.PUBLIC)
+ protected boolean isFocused;
+
+ public void setBackgroundColor(Color c) {
+ if (c == null) return;
+ this.backgroundColor = c;
+ }
+
+ public void setPosition(Point pt) {
+ this.setBounds(new Rectangle(pt.x, pt.y, getBounds().width, getBounds().height));
+ }
+
+ public void setSize(Dimension dim) {
+ this.setBounds(new Rectangle(getBounds().x, getBounds().y, dim.width, dim.height));
+ }
+
+ public Dimension getSize() {
+ return getBounds().getSize();
+ }
+
+ public void setBounds(Rectangle bounds) {
+ if (bounds == null) return;
+ this.bounds.x = bounds.x;
+ this.bounds.y = bounds.y;
+ this.bounds.width = bounds.width;
+ this.bounds.height = bounds.height;
+
+ for (MPanel childComponent : childComponents) {
+ childComponent.resize0(getBounds().width, getBounds().height);
+ }
+ onBoundsUpdate();
+ }
+
+ public void onBoundsUpdate() {
+
+ }
+
+ public void add(MPanel child) {
+ this.childComponents.add(child);
+ }
+
+ public void remove(MPanel panel) {
+ this.childComponents.remove(panel);
+ }
+
+ public void render0(ScaledResolution resolution, Point parentPoint, Rectangle parentClip, int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks) { // 0,0 - a a
+
+
+ int relMousex = relMousex0 - getBounds().x;
+ int relMousey = relMousey0 - getBounds().y;
+
+ GlStateManager.translate(getBounds().x, getBounds().y, 0);
+ GlStateManager.color(1,1,1,0);
+
+
+ Rectangle absBound = getBounds().getBounds();
+ absBound.setLocation(absBound.x + parentPoint.x, absBound.y + parentPoint.y);
+ Rectangle clip = determineClip(parentClip, absBound);
+ lastAbsClip = clip;
+
+ clip(resolution, clip.x, clip.y, clip.width, clip.height);
+ GlStateManager.pushAttrib();
+ GL11.glEnable(GL11.GL_SCISSOR_TEST);
+
+ GlStateManager.pushAttrib();
+ GuiScreen.drawRect(0,0, getBounds().width, getBounds().height, backgroundColor.getRGB());
+ GlStateManager.popAttrib();
+
+ GlStateManager.pushMatrix();
+ GlStateManager.pushAttrib();
+ render(absMousex, absMousey, relMousex, relMousey, partialTicks, clip);
+ GlStateManager.popAttrib();
+ GlStateManager.popMatrix();
+
+ GL11.glDisable(GL11.GL_SCISSOR_TEST);
+ GL11.glPopAttrib();
+
+
+ Point newPt = new Point(parentPoint.x + getBounds().x, parentPoint.y + getBounds().y);
+
+ for (MPanel mPanel : getChildComponents()){
+ GlStateManager.pushMatrix();
+ GlStateManager.pushAttrib();
+ mPanel.render0(resolution, newPt, clip, absMousex, absMousey, relMousex, relMousey, partialTicks);
+ GlStateManager.popAttrib();
+ GlStateManager.popMatrix();
+ }
+ }
+
+ public void clip(ScaledResolution resolution, int x, int y, int width, int height) {
+ int scale = resolution.getScaleFactor();
+ GL11.glScissor((x ) * scale, Minecraft.getMinecraft().displayHeight - (y + height) * scale, (width) * scale, height * scale);
+ }
+
+ private Rectangle determineClip(Rectangle rect1, Rectangle rect2) {
+ int minX = Math.max(rect1.x, rect2.x);
+ int minY = Math.max(rect1.y, rect2.y);
+ int maxX = Math.min(rect1.x + rect1.width, rect2.x + rect2.width);
+ int maxY = Math.min(rect1.y + rect1.height, rect2.y +rect2.height);
+ if (minX > maxX) return new Rectangle(0,0,0,0);
+ if (minY > maxY) return new Rectangle(0,0,0,0);
+ return new Rectangle(minX, minY, maxX - minX, maxY - minY);
+ }
+
+ public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) {}
+
+ public void resize0(int parentWidth, int parentHeight) {
+ resize(parentWidth, parentHeight);
+ }
+
+ public void resize(int parentWidth, int parentHeight) {}
+
+
+ public void keyTyped0(char typedChar, int keyCode) {
+ for (MPanel childComponent : getChildComponents()) {
+ childComponent.keyTyped0(typedChar, keyCode);
+ }
+
+ if (isFocused)
+ keyTyped(typedChar, keyCode);
+ }
+ public void keyTyped(char typedChar, int keyCode) {}
+
+ public boolean mouseClicked0(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int mouseButton) {
+ int relMousex = relMouseX0 - getBounds().x;
+ int relMousey = relMouseY0 - getBounds().y;
+
+ boolean noClip = true;
+ boolean focusedOverall = false;
+ for (MPanel childComponent : getChildComponents()) {
+ if (childComponent.mouseClicked0(absMouseX, absMouseY, relMousex, relMousey, mouseButton)) {
+ noClip = false;
+ focusedOverall = true;
+ }
+ }
+
+ if (getBounds().contains(relMouseX0, relMouseY0) && noClip) {
+ isFocused = true;
+ focusedOverall = true;
+ } else {
+ isFocused = false;
+ }
+
+ mouseClicked(absMouseX, absMouseY, relMousex, relMousey, mouseButton);
+ return focusedOverall;
+ }
+
+ public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) {}
+
+ public void mouseReleased0(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int state) {
+ int relMousex = relMouseX0 - getBounds().x;
+ int relMousey = relMouseY0 - getBounds().y;
+
+ for (MPanel childComponent : getChildComponents()) {
+ childComponent.mouseReleased0(absMouseX, absMouseY, relMousex, relMousey, state);
+ }
+ mouseReleased(absMouseX, absMouseY, relMousex, relMousey, state);
+ }
+ public void mouseReleased(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int state) {}
+
+ public void mouseClickMove0(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int clickedMouseButton, long timeSinceLastClick) {
+ int relMousex = relMouseX0 - getBounds().x;
+ int relMousey = relMouseY0 - getBounds().y;
+
+ for (MPanel childComponent : getChildComponents()) {
+ childComponent.mouseClickMove0(absMouseX, absMouseY, relMousex, relMousey, clickedMouseButton, timeSinceLastClick);
+ }
+ mouseClickMove(absMouseX, absMouseY, relMousex, relMousey, clickedMouseButton, timeSinceLastClick);
+ }
+ public void mouseClickMove(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int clickedMouseButton, long timeSinceLastClick) {}
+
+ public void mouseScrolled0(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int scrollAmount) {
+ int relMousex = relMouseX0 - getBounds().x;
+ int relMousey = relMouseY0 - getBounds().y;
+
+ for (MPanel childComponent : getChildComponents()) {
+ childComponent.mouseScrolled0(absMouseX, absMouseY, relMousex, relMousey, scrollAmount);
+ }
+ mouseScrolled(absMouseX, absMouseY, relMousex, relMousey, scrollAmount);
+ }
+ public void mouseScrolled(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int scrollAmount) {}
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MButton.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MButton.java
new file mode 100755
index 00000000..17196ebc
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MButton.java
@@ -0,0 +1,52 @@
+package kr.syeyoung.dungeonsguide.gui.elements;
+
+import kr.syeyoung.dungeonsguide.gui.MPanel;
+import lombok.Getter;
+import lombok.Setter;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.FontRenderer;
+import net.minecraft.client.gui.Gui;
+
+import java.awt.*;
+
+@Getter
+@Setter
+public class MButton extends MPanel {
+ private String text;
+
+ private Color foreground = Color.white;
+ private Color hover = Color.gray;
+ private Color clicked = Color.lightGray;
+ private Color disabled = Color.darkGray;
+
+ private boolean enabled = true;
+
+ private Runnable onActionPerformed;
+
+ @Override
+ public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle clip) {
+ Dimension bounds = getSize();
+
+ Color bg = backgroundColor;
+ if (!enabled) {
+ bg = disabled;
+ } else if (new Rectangle(new Point(0,0),bounds).contains(relMousex0, relMousey0)) {
+ bg = hover;
+ }
+ if (bg != null)
+ Gui.drawRect(0,0,getBounds().width, getBounds().height, bg.getRGB());
+
+ FontRenderer renderer = Minecraft.getMinecraft().fontRendererObj;
+ int width = renderer.getStringWidth(getText());
+ int x = (getBounds().width - width) / 2;
+ int y = (getBounds().height - renderer.FONT_HEIGHT) / 2;
+
+ renderer.drawString(getText(), x,y, foreground.getRGB());
+ }
+
+ @Override
+ public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) {
+ if (onActionPerformed != null && lastAbsClip.contains(absMouseX, absMouseY))
+ onActionPerformed.run();
+ }
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MColor.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MColor.java
new file mode 100644
index 00000000..44be2d13
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MColor.java
@@ -0,0 +1,30 @@
+package kr.syeyoung.dungeonsguide.gui.elements;
+
+import kr.syeyoung.dungeonsguide.gui.MPanel;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import net.minecraft.client.gui.Gui;
+
+import java.awt.*;
+
+@AllArgsConstructor
+@NoArgsConstructor
+public class MColor extends MPanel {
+ @Getter
+ @Setter
+ private Color color = Color.white;
+ @Getter
+ @Setter
+ private Dimension size = new Dimension(20,15);
+ @Override
+ public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) {
+ Rectangle rectangle = getBounds();
+
+ int x = (rectangle.width - getSize().width) / 2;
+ int y = (rectangle.height - getSize().height) / 2;
+
+ Gui.drawRect(x,y,x+getSize().width,y+getSize().height, getColor().getRGB());
+ }
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MFloatSelectionButton.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MFloatSelectionButton.java
new file mode 100755
index 00000000..46e97cea
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MFloatSelectionButton.java
@@ -0,0 +1,74 @@
+package kr.syeyoung.dungeonsguide.gui.elements;
+
+import kr.syeyoung.dungeonsguide.gui.MPanel;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.awt.*;
+
+@Getter
+@Setter
+public class MFloatSelectionButton extends MPanel {
+
+ private float data;
+
+ private MButton dec;
+ private MButton inc;
+ private MTextField selected;
+
+ @Getter
+ @Setter
+ private Runnable onUpdate;
+
+ public MFloatSelectionButton(float data2) {
+ this.data = data2;
+
+ dec = new MButton(); dec.setText("<"); add(dec);
+ inc = new MButton(); inc.setText(">"); add(inc);
+ selected = new MTextField() {
+ @Override
+ public String getText() {
+ return data +"";
+ }
+ @Override
+ public void edit(String str) {
+ try {
+ data = Float.parseFloat(str);
+ onUpdate.run();
+ } catch (Exception e) {}
+ }
+ }; updateSelected(); add(selected);
+
+ dec.setOnActionPerformed(new Runnable() {
+ @Override
+ public void run() {
+ data--;
+ updateSelected();
+ onUpdate.run();
+ }
+ });
+ inc.setOnActionPerformed(new Runnable() {
+ @Override
+ public void run() {
+ data ++;
+ updateSelected();
+ onUpdate.run();
+ }
+ });
+ }
+
+ public float getSelected() {
+ return data;
+ }
+
+ public void updateSelected() {
+ selected.setText(data+"");
+ }
+
+ @Override
+ public void onBoundsUpdate() {
+ dec.setBounds(new Rectangle(0,0,getBounds().height, getBounds().height));
+ inc.setBounds(new Rectangle(getBounds().width - getBounds().height, 0, getBounds().height, getBounds().height));
+ selected.setBounds(new Rectangle(getBounds().height, 0, getBounds().width - getBounds().height - getBounds().height, getBounds().height));
+ }
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MIntegerSelectionButton.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MIntegerSelectionButton.java
new file mode 100755
index 00000000..6e66c4f0
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MIntegerSelectionButton.java
@@ -0,0 +1,70 @@
+package kr.syeyoung.dungeonsguide.gui.elements;
+
+import kr.syeyoung.dungeonsguide.gui.MPanel;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.awt.*;
+
+@Getter
+@Setter
+public class MIntegerSelectionButton extends MPanel {
+
+ private int data;
+
+ private MButton dec;
+ private MButton inc;
+ private MTextField selected;
+
+ @Getter
+ @Setter
+ private Runnable onUpdate;
+
+ public MIntegerSelectionButton(int data2) {
+ this.data = data2;
+
+ dec = new MButton(); dec.setText("<"); add(dec);
+ inc = new MButton(); inc.setText(">"); add(inc);
+ selected = new MTextField() {
+ @Override
+ public void edit(String str) {
+ try {
+ data = Integer.parseInt(str);
+ onUpdate.run();
+ } catch (Exception e) {}
+ }
+ }; updateSelected(); add(selected);
+
+ dec.setOnActionPerformed(new Runnable() {
+ @Override
+ public void run() {
+ data--;
+ updateSelected();
+ onUpdate.run();
+ }
+ });
+ inc.setOnActionPerformed(new Runnable() {
+ @Override
+ public void run() {
+ data ++;
+ updateSelected();
+ onUpdate.run();
+ }
+ });
+ }
+
+ public int getSelected() {
+ return data;
+ }
+
+ private void updateSelected() {
+ selected.setText(data+"");
+ }
+
+ @Override
+ public void onBoundsUpdate() {
+ dec.setBounds(new Rectangle(0,0,getBounds().height, getBounds().height));
+ inc.setBounds(new Rectangle(getBounds().width - getBounds().height, 0, getBounds().height, getBounds().height));
+ selected.setBounds(new Rectangle(getBounds().height, 0, getBounds().width - getBounds().height - getBounds().height, getBounds().height));
+ }
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MLabel.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MLabel.java
new file mode 100755
index 00000000..024f0c1f
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MLabel.java
@@ -0,0 +1,48 @@
+package kr.syeyoung.dungeonsguide.gui.elements;
+
+import kr.syeyoung.dungeonsguide.gui.MPanel;
+import lombok.Getter;
+import lombok.Setter;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.FontRenderer;
+
+import java.awt.*;
+
+public class MLabel extends MPanel {
+ @Getter
+ @Setter
+ private String text;
+
+ @Getter
+ @Setter
+ private Color foreground = Color.white;
+
+ public enum Alignment {
+ LEFT, CENTER, RIGHT
+ }
+ @Getter
+ @Setter
+ private Alignment alignment= Alignment.LEFT;
+
+ @Override
+ public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle clip) {
+ Dimension bounds = getSize();
+
+ FontRenderer renderer = Minecraft.getMinecraft().fontRendererObj;
+ int width = renderer.getStringWidth(getText());
+ int x,y;
+ if (alignment == Alignment.CENTER) {
+ x = (getBounds().width - width) / 2;
+ y = (getBounds().height - renderer.FONT_HEIGHT) / 2;
+ } else if (alignment == Alignment.LEFT) {
+ x = 0;
+ y = (getBounds().height - renderer.FONT_HEIGHT) / 2;
+ } else if (alignment == Alignment.RIGHT) {
+ x = getBounds().width - width;
+ y = (getBounds().height - renderer.FONT_HEIGHT) / 2;
+ } else{
+ return;
+ }
+ renderer.drawString(getText(), x,y, 0xffffff);
+ }
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MLabelAndElement.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MLabelAndElement.java
new file mode 100755
index 00000000..601cb1aa
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MLabelAndElement.java
@@ -0,0 +1,52 @@
+package kr.syeyoung.dungeonsguide.gui.elements;
+
+import kr.syeyoung.dungeonsguide.gui.MPanel;
+import lombok.Getter;
+import lombok.Setter;
+import net.minecraft.client.gui.Gui;
+
+import java.awt.*;
+
+public class MLabelAndElement extends MPanel {
+ private MLabel label;
+ private MPanel element;
+
+ @Getter @Setter
+ private Color hover;
+ @Getter @Setter
+ private Runnable onClick;
+
+ public MLabelAndElement(String label, MPanel element) {
+ this.add(this.label = new MLabel());
+ this.label.setText(label);
+ this.add(element);
+ this.element = element;
+ }
+
+ @Override
+ public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) {
+ if (hover != null && new Rectangle(new Point(0,0),getBounds().getSize()).contains(relMousex0, relMousey0)) {
+ Gui.drawRect(0,0,getBounds().width, getBounds().height, hover.getRGB());
+ }
+ }
+
+ @Override
+ public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) {
+ if (onClick!= null && lastAbsClip.contains(absMouseX, absMouseY)) {
+ onClick.run();
+ }
+ }
+
+ @Override
+ public void resize(int parentWidth, int parentHeight) {
+ this.setSize(new Dimension(parentWidth, getBounds().height));
+ label.setBounds(new Rectangle(0,0,parentHeight / 3, getBounds().height));
+ element.setBounds(new Rectangle(parentWidth / 3,0,parentWidth / 3 * 2, getBounds().height));
+ }
+
+ @Override
+ public void onBoundsUpdate() {
+ label.setBounds(new Rectangle(0,0,getBounds().width / 3, getBounds().height));
+ element.setBounds(new Rectangle(getBounds().width / 3,0,getBounds().width / 3 * 2, getBounds().height));
+ }
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MParameter.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MParameter.java
new file mode 100755
index 00000000..bc7f81e1
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MParameter.java
@@ -0,0 +1,72 @@
+package kr.syeyoung.dungeonsguide.gui.elements;
+
+import kr.syeyoung.dungeonsguide.roomedit.EditingContext;
+import kr.syeyoung.dungeonsguide.gui.MPanel;
+import kr.syeyoung.dungeonsguide.roomedit.Parameter;
+import kr.syeyoung.dungeonsguide.roomedit.gui.GuiDungeonParameterEdit;
+import kr.syeyoung.dungeonsguide.roomedit.panes.DynamicEditor;
+import lombok.Getter;
+import lombok.Setter;
+import net.minecraft.client.gui.Gui;
+
+import java.awt.*;
+
+public class MParameter extends MPanel {
+ private MLabel label;
+ private MLabel data;
+
+ @Getter @Setter
+ private Color hover = Color.gray;
+
+ @Getter @Setter
+ private Parameter parameter;
+ private DynamicEditor processorParameterEditPane;
+
+ public MParameter(final Parameter parameter, DynamicEditor processorParameterEditPane) {
+ this.processorParameterEditPane = processorParameterEditPane;
+ this.add(this.label = new MLabel() {
+ @Override
+ public String getText() {
+ return parameter.getName();
+ }
+ });
+ this.add(this.data = new MLabel() {
+ @Override
+ public String getText() {
+ return parameter.getNewData() != null ?parameter.getNewData().toString() :"-empty-";
+ }
+ });
+ this.label.setAlignment(MLabel.Alignment.LEFT);
+ this.data.setAlignment(MLabel.Alignment.RIGHT);
+
+ this.parameter = parameter;
+ }
+
+ @Override
+ public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) {
+ if (hover != null && new Rectangle(new Point(0,0),getBounds().getSize()).contains(relMousex0, relMousey0)) {
+ Gui.drawRect(0,0,getBounds().width, getBounds().height, hover.getRGB());
+ }
+ }
+
+ @Override
+ public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) {
+ if (this.getBounds().x > -20 && lastAbsClip.contains(absMouseX, absMouseY)) {
+ // open new gui;
+ EditingContext.getEditingContext().openGui(new GuiDungeonParameterEdit(this, processorParameterEditPane));
+ }
+ }
+
+ @Override
+ public void resize(int parentWidth, int parentHeight) {
+ this.setSize(new Dimension(parentWidth, getBounds().height));
+ label.setBounds(new Rectangle(0,0,parentHeight / 3, getBounds().height));
+ data.setBounds(new Rectangle(parentWidth / 3,0,parentWidth / 3 * 2, getBounds().height));
+ }
+
+ @Override
+ public void onBoundsUpdate() {
+ label.setBounds(new Rectangle(0,0,getBounds().width / 3, getBounds().height));
+ data.setBounds(new Rectangle(getBounds().width / 3,0,getBounds().width / 3 * 2, getBounds().height));
+ }
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MStringSelectionButton.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MStringSelectionButton.java
new file mode 100755
index 00000000..b3f78fa3
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MStringSelectionButton.java
@@ -0,0 +1,74 @@
+package kr.syeyoung.dungeonsguide.gui.elements;
+
+import kr.syeyoung.dungeonsguide.gui.MPanel;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.awt.*;
+import java.util.List;
+
+@Getter
+@Setter
+public class MStringSelectionButton extends MPanel {
+
+ private List<String> possible;
+ private int selectedIndex;
+
+ private MButton dec;
+ private MButton inc;
+ private MLabel selected;
+
+ @Getter
+ @Setter
+ private Runnable onUpdate;
+
+ public MStringSelectionButton(final List<String> possible, String defaultValue) {
+ this.possible = possible;
+ selectedIndex = possible.indexOf(defaultValue);
+ if (selectedIndex == -1) selectedIndex = 0;
+
+ dec = new MButton(); dec.setText("<"); add(dec);
+ inc = new MButton(); inc.setText(">"); add(inc);
+ selected = new MLabel(); updateSelected(); add(selected);
+
+ dec.setOnActionPerformed(new Runnable() {
+ @Override
+ public void run() {
+ selectedIndex++;
+ if (selectedIndex >= possible.size()) selectedIndex = 0;
+ updateSelected();
+ onUpdate.run();
+ }
+ });
+ inc.setOnActionPerformed(new Runnable() {
+ @Override
+ public void run() {
+ selectedIndex --;
+ if (selectedIndex < 0) selectedIndex = possible.size() - 1;
+ updateSelected();
+ onUpdate.run();
+ }
+ });
+ }
+
+ public String selectionToDisplay(String selection) {
+ return selection;
+ }
+
+ public String getSelected() {
+ if (possible.size() == 0) return null;
+ return possible.get(selectedIndex);
+ }
+
+ private void updateSelected() {
+ if (possible.size() == 0) selected.setText("-Empty-");
+ else selected.setText(selectionToDisplay(possible.get(selectedIndex)));
+ }
+
+ @Override
+ public void onBoundsUpdate() {
+ dec.setBounds(new Rectangle(0,0,getBounds().height, getBounds().height));
+ inc.setBounds(new Rectangle(getBounds().width - getBounds().height, 0, getBounds().height, getBounds().height));
+ selected.setBounds(new Rectangle(getBounds().height, 0, getBounds().width - getBounds().height - getBounds().height, getBounds().height));
+ }
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTabButton.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTabButton.java
new file mode 100755
index 00000000..cf6f6fc7
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTabButton.java
@@ -0,0 +1,61 @@
+package kr.syeyoung.dungeonsguide.gui.elements;
+
+import kr.syeyoung.dungeonsguide.gui.MPanel;
+import lombok.Getter;
+import lombok.Setter;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.FontRenderer;
+import net.minecraft.client.gui.Gui;
+
+import java.awt.*;
+
+@Getter
+@Setter
+public class MTabButton extends MPanel {
+ private String text;
+
+ private Color foreground = Color.white;
+ private Color hover = new Color(236, 236, 236, 64);
+ private Color clicked = new Color(30,30,30,0);
+ private Color selected = new Color(0,0,0,255);
+ private Color disabled = new Color(0,0,0);
+
+ private boolean enabled = true;
+
+ private MTabbedPane tabbedPane;
+
+ public MTabButton(MTabbedPane tabbedPane, String key) {
+ this.tabbedPane = tabbedPane;
+ this.text = key;
+ }
+
+ @Override
+ public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle clip) {
+ Dimension bounds = getSize();
+
+ Color bg = null;
+ if (!enabled) {
+ bg = disabled;
+ } else if (tabbedPane.getSelectedKey().equals(text)) {
+ bg = selected;
+ } else if (new Rectangle(new Point(0,0),bounds).contains(relMousex0, relMousey0)) {
+ bg = hover;
+ }
+ if (bg != null)
+ Gui.drawRect(0,0,getBounds().width, getBounds().height, bg.getRGB());
+
+ FontRenderer renderer = Minecraft.getMinecraft().fontRendererObj;
+ int width = renderer.getStringWidth(text);
+ int x = (getBounds().width - width) / 2;
+ int y = (getBounds().height - renderer.FONT_HEIGHT) / 2;
+
+ renderer.drawString(text, x,y, foreground.getRGB());
+ }
+
+ @Override
+ public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) {
+ if (lastAbsClip.contains(absMouseX, absMouseY)) {
+ tabbedPane.setSelectedKey(text);
+ }
+ }
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTabbedPane.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTabbedPane.java
new file mode 100755
index 00000000..96b2e81d
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTabbedPane.java
@@ -0,0 +1,72 @@
+package kr.syeyoung.dungeonsguide.gui.elements;
+
+import kr.syeyoung.dungeonsguide.gui.MPanel;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class MTabbedPane extends MPanel {
+
+ private Map<String, MPanel> tabs = new HashMap<String, MPanel>();
+ private Map<String, MTabButton> buttons = new HashMap<String, MTabButton>();
+
+ @Getter
+ @Setter
+ private String selectedKey = "";
+
+ @Getter
+ private Color background2;
+
+ public void setBackground2(Color background2) {
+ this.background2 = background2;
+ for (MPanel value : tabs.values()) {
+ value.setBackgroundColor(background2);
+ }
+ for (MTabButton value : buttons.values()) {
+ value.setBackgroundColor(background2.brighter());
+ }
+ }
+
+ public void addTab(String tab, MPanel panel) {
+ MPanel panel2 = new MPanel() ;
+ panel2.add(panel);
+ panel2.setBackgroundColor(background2);
+ tabs.put(tab, panel2);
+ panel2.setBounds(new Rectangle(0,15,getBounds().width, getBounds().height-15));
+
+ MTabButton button = new MTabButton(this, tab);
+ button.setBackgroundColor(background2.brighter());
+ button.setBounds(new Rectangle(buttons.size()* 50, 0, 50, 15));
+ buttons.put(tab, button);
+ if (tabs.size() == 1)
+ selectedKey = tab;
+ }
+
+ @Override
+ public List<MPanel> getChildComponents() {
+ ArrayList<MPanel> dynamic = new ArrayList<MPanel>(buttons.values());
+ dynamic.add(tabs.get(selectedKey));
+ return dynamic;
+ }
+
+ @Override
+ public void resize(int parentWidth, int parentHeight) {
+ this.setBounds(new Rectangle(0,0,parentWidth, parentHeight));
+ for (MPanel ma:tabs.values())
+ ma.setBounds(new Rectangle(0,15,parentWidth, parentHeight-15));
+ }
+
+ @Override
+ public void setBounds(Rectangle bounds) {
+ if (bounds == null) return;
+ this.bounds.x = bounds.x;
+ this.bounds.y = bounds.y;
+ this.bounds.width = bounds.width;
+ this.bounds.height = bounds.height;
+ }
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java
new file mode 100755
index 00000000..57232f7f
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java
@@ -0,0 +1,346 @@
+package kr.syeyoung.dungeonsguide.gui.elements;
+
+import kr.syeyoung.dungeonsguide.gui.MPanel;
+import lombok.Getter;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.FontRenderer;
+import net.minecraft.client.gui.Gui;
+import net.minecraft.client.gui.ScaledResolution;
+import org.lwjgl.input.Keyboard;
+
+import java.awt.*;
+import java.awt.datatransfer.*;
+import java.awt.event.KeyEvent;
+import java.io.IOException;
+
+@Getter
+public class MTextField extends MPanel {
+ private Color foreground = Color.white;
+
+ private String text = "asdasdasd";
+ private int cursorBlickTicker = 0;
+
+ private int selectionStart = 0;
+ private int selectionEnd = 0;
+
+ private int cursor = 0;
+
+ private int xOffset = 0;
+
+ public void edit(String str) {
+
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+ private void setText0(String text) {
+ this.text = text;
+ edit(text);
+ }
+
+
+ @Override
+ public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle clip) {
+ Gui.drawRect(0,0,getBounds().width, getBounds().height, isFocused ? Color.white.getRGB() : Color.gray.getRGB());
+ Gui.drawRect(1,1,getBounds().width - 2, getBounds().height - 2, Color.black.getRGB());
+
+ Minecraft mc = Minecraft.getMinecraft();
+ clip(new ScaledResolution(mc), clip.x + 1, clip.y + 1, clip.width - 2, clip.height - 2);
+ FontRenderer fr = mc.fontRendererObj;
+ int y = (getBounds().height - fr.FONT_HEIGHT) / 2;
+ fr.drawString(text, 3 - xOffset, y, foreground.getRGB());
+ // draw selection
+ if (isFocused) {
+ if (selectionStart != -1) {
+ int startX = fr.getStringWidth(text.substring(0, selectionStart)) - xOffset;
+ int endX = fr.getStringWidth(text.substring(0, selectionEnd)) - xOffset;
+ Gui.drawRect(3 + startX, y, 3 + endX, y + fr.FONT_HEIGHT, 0xFF00FF00);
+ fr.drawString(text.substring(selectionStart, selectionEnd), 3 + startX, y, foreground.getRGB());
+ }
+
+ // draw cursor
+ if (cursor != -1) {
+ if (cursor > text.length()) cursor = text.length();
+ int x = fr.getStringWidth(text.substring(0, cursor)) - xOffset;
+ cursorBlickTicker++;
+ if (cursorBlickTicker < 10)
+ Gui.drawRect(3 + x, y, 4 + x, y + fr.FONT_HEIGHT, 0xFFFFFFFF);
+ if (cursorBlickTicker == 20) cursorBlickTicker = 0;
+ }
+ }
+ }
+
+ @Override
+ public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) {
+ Rectangle actualField = new Rectangle(1, 3,getBounds().width - 2, getBounds().height - 6);
+ if (!actualField.contains(relMouseX, relMouseY)) return;
+ if (!lastAbsClip.contains(absMouseX, absMouseY)) return;
+
+
+
+
+ int relStartT = relMouseX-3;
+ int offseted = relStartT + xOffset;
+
+ selectionStart = -1;
+
+
+ FontRenderer fr = Minecraft.getMinecraft().fontRendererObj;
+
+ for (int i = 0; i < text.length(); i++) {
+ int totalWidth = fr.getStringWidth(text.substring(0, i));
+ if (offseted < totalWidth) {
+ cursor = i;
+ return;
+ }
+ }
+ cursor = text.length();
+ }
+
+ @Override
+ public void mouseClickMove(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int clickedMouseButton, long timeSinceLastClick) {
+ if (!isFocused) return;
+ selectionStart = cursor;
+ selectionEnd = cursor;
+
+ int relStartT = relMouseX-3;
+ int offseted = relStartT + xOffset;
+
+ FontRenderer fr = Minecraft.getMinecraft().fontRendererObj;
+
+ for (int i = 0; i < text.length(); i++) {
+ int totalWidth = fr.getStringWidth(text.substring(0, i));
+ if (offseted < totalWidth) {
+ if (i < cursor) {
+ selectionStart = i;
+ selectionEnd = cursor;
+ } else {
+ selectionStart = cursor;
+ selectionEnd = i;
+ }
+ return;
+ }
+ }
+ selectionEnd = text.length();
+ if (selectionStart == selectionEnd) {
+ selectionStart = -1;
+ }
+ }
+
+ @Override
+ public void mouseScrolled(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int scrollAmount) {
+ if (!isFocused) return;
+ if (scrollAmount > 0) {
+ xOffset += 5;
+ } else if (scrollAmount < 0){
+ xOffset -= 5;
+ }
+ if (xOffset < 0) {
+ xOffset = 0;
+ }
+ int width = Minecraft.getMinecraft().fontRendererObj.getStringWidth(text);
+ int overflow = getBounds().width - 3 - width;
+ if (overflow >= 0) {
+ xOffset = 0;
+ } else if (width - xOffset + 10 < getBounds().width) {
+ xOffset = width - getBounds().width+10;
+ }
+ }
+
+ @Override
+ public void keyTyped(char typedChar, int keycode) {
+ if (!isFocused) return;
+
+
+ if (selectionStart == -1) {
+ if (keycode == 199) { // home
+ cursor = 0;
+ return;
+ }
+
+ if (keycode == 207) { // end
+ cursor = text.length();
+ return;
+ }
+
+ if (keycode == 203) { // left
+ cursor--;
+ if (cursor < 0) cursor = 0;
+ return;
+ }
+
+ if (keycode == 205) { // right
+ cursor ++;
+ if (cursor > text.length()) cursor = text.length();
+ return;
+ }
+
+ // backspace
+ if (keycode == 14 && cursor > 0) {
+ setText0(this.text.substring(0, cursor - 1) + this.text.substring(cursor));
+ cursor--;
+ return;
+ }
+
+ //del
+ if (keycode == 211 && cursor < text.length()) {
+ setText0(this.text.substring(0, cursor) + this.text.substring(cursor+1));
+ return;
+ }
+
+ // paste
+ boolean shouldPaste = false;
+ if (keycode == 47) {
+ if (Minecraft.isRunningOnMac) { // mac
+ if (Keyboard.isKeyDown(219) || Keyboard.isKeyDown(220)) {
+ shouldPaste = true;
+ }
+ } else { // literally everything else
+ if (Keyboard.isKeyDown(29) || Keyboard.isKeyDown(157)) {
+ shouldPaste = true;
+ }
+ }
+ }
+ if (shouldPaste) {
+ Transferable transferable = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
+ if (transferable != null && transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
+ try {
+ Object theText = transferable.getTransferData(DataFlavor.stringFlavor);
+ setText0(
+ this.text.substring(0, this.cursor)
+ + theText
+ + this.text.substring(this.cursor));
+
+ cursor += theText.toString().length();
+ } catch (UnsupportedFlavorException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return;
+ }
+
+ // text
+ if (isPrintableChar(typedChar)) {
+ setText0(
+ this.text.substring(0, this.cursor)
+ + typedChar
+ + this.text.substring(this.cursor));
+ this.cursor++;
+ return;
+ }
+ } else {
+ if (keycode == 199) { // home
+ cursor = 0;
+ selectionStart = -1;
+ return;
+ }
+
+ if (keycode == 207) { // end
+ selectionStart = -1;
+ cursor = text.length();
+ return;
+ }
+
+ if (keycode == 203) { // left
+ cursor = selectionStart;
+ selectionStart = -1;
+ return;
+ }
+
+ if (keycode == 205) { // right
+ cursor = selectionEnd;
+ selectionStart = -1;
+ return;
+ }
+
+ // backspace
+ if (keycode == 14 && cursor > 0) {
+ setText0(this.text.substring(0, selectionStart) + this.text.substring(selectionEnd));
+ cursor = selectionStart;
+ selectionStart = -1;
+ return;
+ }
+
+ //del
+ if (keycode == 211 && cursor < text.length()) {
+ setText0(this.text.substring(0, selectionStart) + this.text.substring(selectionEnd));
+ cursor = selectionStart;
+ selectionStart = -1;
+ return;
+ }
+
+ // paste
+ boolean shouldPaste = false;
+ if (keycode == 47) {
+ if (Minecraft.isRunningOnMac) { // mac
+ if (Keyboard.isKeyDown(219) || Keyboard.isKeyDown(220)) {
+ shouldPaste = true;
+ }
+ } else { // literally everything else
+ if (Keyboard.isKeyDown(29) || Keyboard.isKeyDown(157)) {
+ shouldPaste = true;
+ }
+ }
+ }
+ if (shouldPaste) {
+ Transferable transferable = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
+ if (transferable != null && transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
+ try {
+ Object theText = transferable.getTransferData(DataFlavor.stringFlavor);
+ setText0(
+ this.text.substring(0, this.selectionStart)
+ + theText
+ + this.text.substring(this.selectionEnd));
+ cursor = this.selectionStart + theText.toString().length();
+ } catch (UnsupportedFlavorException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ selectionStart = -1;
+ }
+ return;
+ }
+ boolean shouldCopy = false;
+ if (keycode == 46) {
+ if (Minecraft.isRunningOnMac) { // mac
+ if (Keyboard.isKeyDown(219) || Keyboard.isKeyDown(220)) {
+ shouldCopy = true;
+ }
+ } else { // literally everything else
+ if (Keyboard.isKeyDown(29) || Keyboard.isKeyDown(157)) {
+ shouldCopy = true;
+ }
+ }
+ }
+ if (shouldCopy) {
+ StringSelection selection = new StringSelection(text.substring(selectionStart, selectionEnd));
+ Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
+ clipboard.setContents(selection, selection);
+ return;
+ }
+
+ // text
+ if (isPrintableChar(typedChar)) {
+ setText0(
+ this.text.substring(0, this.selectionStart)
+ + typedChar
+ + this.text.substring(this.selectionEnd));
+ this.cursor = this.selectionStart + 1;
+ selectionStart = -1;
+ return;
+ }
+ }
+ }
+ public boolean isPrintableChar( char c ) {
+ Character.UnicodeBlock block = Character.UnicodeBlock.of( c );
+ return (!Character.isISOControl(c)) &&
+ c != KeyEvent.CHAR_UNDEFINED &&
+ block != null &&
+ block != Character.UnicodeBlock.SPECIALS;
+ }
+
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MValue.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MValue.java
new file mode 100755
index 00000000..e4e51841
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MValue.java
@@ -0,0 +1,61 @@
+package kr.syeyoung.dungeonsguide.gui.elements;
+
+import kr.syeyoung.dungeonsguide.roomedit.EditingContext;
+import kr.syeyoung.dungeonsguide.gui.MPanel;
+import kr.syeyoung.dungeonsguide.roomedit.gui.GuiDungeonValueEdit;
+import kr.syeyoung.dungeonsguide.roomedit.valueedit.ValueEditOffsetPointSet;
+import lombok.Getter;
+import lombok.Setter;
+import net.minecraft.client.gui.Gui;
+
+import java.awt.*;
+import java.util.List;
+public class MValue<T> extends MPanel {
+ @Getter
+ private T data;
+ private ValueEditOffsetPointSet valueEditOffsetPointSet;
+ private MLabel dataLab;
+
+ @Getter @Setter
+ private Color hover = Color.gray;
+
+ private List<MPanel> addons;
+
+ public MValue(final T parameter, List<MPanel> addons) {
+ this.addons = addons;
+ this.add(this.dataLab = new MLabel() {
+ @Override
+ public String getText() {
+ return data != null ?data.toString() :"-empty-";
+ }
+ });
+ this.dataLab.setAlignment(MLabel.Alignment.RIGHT);
+
+ this.data = parameter;
+ }
+
+ @Override
+ public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) {
+ if (hover != null && new Rectangle(new Point(0,0),getBounds().getSize()).contains(relMousex0, relMousey0)) {
+ Gui.drawRect(0,0,getBounds().width, getBounds().height, hover.getRGB());
+ }
+ }
+
+ @Override
+ public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) {
+ if (this.getBounds().x > -20 && lastAbsClip.contains(absMouseX, absMouseY)) {
+ EditingContext.getEditingContext().openGui(new GuiDungeonValueEdit(data, addons));
+ }
+ }
+
+ @Override
+ public void resize(int parentWidth, int parentHeight) {
+ this.setSize(new Dimension(parentWidth, getBounds().height));
+ dataLab.setBounds(new Rectangle(0,0,parentWidth, getBounds().height));
+ }
+
+ @Override
+ public void onBoundsUpdate() {
+ dataLab.setBounds(new Rectangle(0,0,getBounds().width, getBounds().height));
+ }
+}