aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kr/syeyoung/dungeonsguide/roomedit
diff options
context:
space:
mode:
authorsyeyoung <42869671+cyoung06@users.noreply.github.com>2020-11-23 17:38:00 +0900
committersyeyoung <42869671+cyoung06@users.noreply.github.com>2020-11-23 17:38:00 +0900
commit8292e2b632d34a92f98e8dd896750b5b5ab011bd (patch)
tree5d714771d737b866e33b840c21ed004ccc9dac72 /src/main/java/kr/syeyoung/dungeonsguide/roomedit
parentfdc4638c4bbd84e1429812387d0f3a2626b95ae6 (diff)
downloadSkyblock-Dungeons-Guide-8292e2b632d34a92f98e8dd896750b5b5ab011bd.tar.gz
Skyblock-Dungeons-Guide-8292e2b632d34a92f98e8dd896750b5b5ab011bd.tar.bz2
Skyblock-Dungeons-Guide-8292e2b632d34a92f98e8dd896750b5b5ab011bd.zip
gui stuff
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/roomedit')
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/roomedit/GuiDungeonRoomEdit.java81
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/roomedit/MPanel.java168
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MButton.java51
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MLabel.java31
4 files changed, 331 insertions, 0 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomedit/GuiDungeonRoomEdit.java b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/GuiDungeonRoomEdit.java
new file mode 100644
index 00000000..0ce2b72b
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/GuiDungeonRoomEdit.java
@@ -0,0 +1,81 @@
+package kr.syeyoung.dungeonsguide.roomedit;
+
+import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom;
+import kr.syeyoung.dungeonsguide.roomedit.elements.MButton;
+import kr.syeyoung.dungeonsguide.roomedit.elements.MLabel;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.GuiScreen;
+import net.minecraft.client.gui.ScaledResolution;
+import org.lwjgl.input.Mouse;
+
+import java.awt.*;
+import java.io.IOException;
+
+public class GuiDungeonRoomEdit extends GuiScreen {
+
+ private MPanel mainPanel = new MPanel();
+
+ private DungeonRoom room;
+
+ public GuiDungeonRoomEdit(DungeonRoom room) {
+ this.room = room;
+
+ mainPanel.setBackgroundColor(Color.green);
+ MLabel label = new MLabel();
+ label.setText("blah blah is great!");
+ label.setBackgroundColor(Color.BLACK);
+ label.setBounds(new Rectangle(0,0,50,10));
+ mainPanel.add(label);
+
+ MButton mButton = new MButton();
+ mButton.setText("this is awesome");
+ label.setBounds(new Rectangle(30,20,50,10));
+ mainPanel.add(label);
+ }
+
+ @Override
+ public void initGui() {
+ // update bounds
+ ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
+ mainPanel.setBounds(new Rectangle((scaledResolution.getScaledWidth() - 500) / 2, (scaledResolution.getScaledHeight() - 300) / 2,500,300));
+ }
+
+ @Override
+ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
+ ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
+ mainPanel.render0(new Rectangle(0,0,scaledResolution.getScaledWidth(),scaledResolution.getScaledHeight()), mouseX, mouseY, mouseX, mouseY, partialTicks);
+ }
+
+ @Override
+ protected void keyTyped(char typedChar, int keyCode) throws IOException {
+ mainPanel.keyTyped0(typedChar, keyCode);
+ }
+
+ @Override
+ protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
+ mainPanel.mouseClicked0(mouseX, mouseY,mouseX,mouseY, mouseButton);
+ }
+
+ @Override
+ protected void mouseReleased(int mouseX, int mouseY, int state) {
+ mainPanel.mouseReleased0(mouseX, mouseY,mouseX,mouseY, state);
+ }
+
+ @Override
+ protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
+ mainPanel.mouseClickMove0(mouseX,mouseY,mouseX,mouseY,clickedMouseButton,timeSinceLastClick);
+ }
+
+ @Override
+ public void handleMouseInput() throws IOException {
+ super.handleMouseInput();
+
+ int i = Mouse.getEventX() * this.width / this.mc.displayWidth;
+ int j = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
+
+ int wheel = Mouse.getDWheel();
+ if (wheel != 0) {
+ mainPanel.mouseScrolled0(i, j,i,j, wheel);
+ }
+ }
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomedit/MPanel.java b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/MPanel.java
new file mode 100644
index 00000000..6c8a1f50
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/MPanel.java
@@ -0,0 +1,168 @@
+package kr.syeyoung.dungeonsguide.roomedit;
+
+import lombok.AccessLevel;
+import lombok.Getter;
+import org.lwjgl.opengl.GL11;
+import org.w3c.dom.css.Rect;
+
+import java.awt.*;
+import java.io.IOException;
+import java.util.List;
+import java.util.ArrayList;
+
+@Getter
+public class MPanel {
+ protected Rectangle bounds = new Rectangle(0,0,0,0); // relative to parent
+
+ protected List<MPanel> childComponents = new ArrayList<MPanel>();
+
+ protected Color backgroundColor;
+
+ @Getter(AccessLevel.PUBLIC)
+ protected boolean isFocused;
+
+ public void setBackgroundColor(Color c) {
+ this.backgroundColor = c;
+ }
+
+ public void setPosition(Point pt) {
+ this.bounds.x = pt.x;
+ this.bounds.y = pt.y;
+ }
+
+ public void setSize(Dimension dim) {
+ this.bounds.width = dim.width;
+ this.bounds.height = dim.height;
+ }
+
+ public Dimension getSize() {
+ return bounds.getSize();
+ }
+
+ public void setBounds(Rectangle bounds) {
+ this.bounds.x = bounds.x;
+ this.bounds.y = bounds.y;
+ this.bounds.width = bounds.width;
+ this.bounds.height = bounds.height;
+ }
+
+ public void add(MPanel child) {
+ this.childComponents.add(child);
+ }
+
+ public void remove(MPanel panel) {
+ this.childComponents.remove(panel);
+ }
+
+ public void render0(Rectangle parentClip, int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks) { // 0,0 - a a
+ int relMousex = relMousex0 - bounds.x;
+ int relMousey = relMousey0 - bounds.y;
+
+ Rectangle absParent = parentClip.getBounds();
+
+ GL11.glPushAttrib(GL11.GL_SCISSOR_BIT);
+ GL11.glTranslated(bounds.x, bounds.y, 0);
+ absParent.add(-bounds.x, -bounds.y);
+
+ Rectangle absBound = bounds.getBounds(); // 0,0 - a a
+ Rectangle clip = determineClip(parentClip, absBound);
+
+ GL11.glEnable(GL11.GL_SCISSOR_TEST);
+ GL11.glScissor(clip.x, clip.y, clip.width, clip.height);
+
+ GL11.glClearColor(backgroundColor.getRed(), backgroundColor.getGreen(), backgroundColor.getBlue(), backgroundColor.getAlpha());
+
+ GL11.glPushMatrix();
+ render(absMousex, absMousey, relMousex, relMousey, partialTicks);
+ GL11.glPopMatrix();
+
+ GL11.glDisable(GL11.GL_SCISSOR_TEST);
+
+ GL11.glPopAttrib();
+
+ for (MPanel mPanel : childComponents){
+ GL11.glPushMatrix();
+ mPanel.render0(clip, absMousex, absMousey, relMousex, relMousey, partialTicks);
+ GL11.glPopMatrix();
+ }
+ }
+
+ 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) {}
+
+ protected void keyTyped0(char typedChar, int keyCode) {
+ for (MPanel childComponent : childComponents) {
+ childComponent.keyTyped0(typedChar, keyCode);
+ }
+
+ if (isFocused)
+ keyTyped(typedChar, keyCode);
+ }
+ protected void keyTyped(char typedChar, int keyCode) {};
+
+ protected boolean mouseClicked0(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int mouseButton) {
+ int relMousex = relMouseX0 - bounds.x;
+ int relMousey = relMouseY0 - bounds.y;
+
+ boolean noClip = true;
+ boolean focusedOverall = false;
+ for (MPanel childComponent : childComponents) {
+ if (childComponent.mouseClicked0(absMouseX, absMouseY, relMouseX0, relMouseY0, mouseButton)) {
+ noClip = false;
+ focusedOverall = true;
+ }
+ }
+
+ if (bounds.contains(relMousex, relMousey) && noClip) {
+ isFocused = true;
+ focusedOverall = true;
+ }
+
+ mouseClicked(absMouseX, absMouseY, relMousex, relMousey, mouseButton);
+ return focusedOverall;
+ }
+
+ protected void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) {}
+
+ protected void mouseReleased0(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int state) {
+ int relMousex = relMouseX0 - bounds.x;
+ int relMousey = relMouseY0 - bounds.y;
+
+ for (MPanel childComponent : childComponents) {
+ childComponent.mouseReleased0(absMouseX, absMouseY, relMousex, relMousey, state);
+ }
+ mouseReleased(absMouseX, absMouseY, relMousex, relMousey, state);
+ }
+ protected void mouseReleased(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int state) {}
+
+ protected void mouseClickMove0(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int clickedMouseButton, long timeSinceLastClick) {
+ int relMousex = relMouseX0 - bounds.x;
+ int relMousey = relMouseY0 - bounds.y;
+
+ for (MPanel childComponent : childComponents) {
+ childComponent.mouseClickMove0(absMouseX, absMouseY, relMousex, relMousey, clickedMouseButton, timeSinceLastClick);
+ }
+ mouseClickMove(absMouseX, absMouseY, relMousex, relMousey, clickedMouseButton, timeSinceLastClick);
+ }
+ protected void mouseClickMove(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int clickedMouseButton, long timeSinceLastClick) {}
+
+ protected void mouseScrolled0(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int scrollAmount) {
+ int relMousex = relMouseX0 - bounds.x;
+ int relMousey = relMouseY0 - bounds.y;
+
+ for (MPanel childComponent : childComponents) {
+ childComponent.mouseScrolled0(absMouseX, absMouseY, relMousex, relMousey, scrollAmount);
+ }
+ mouseScrolled(absMouseX, absMouseY, relMousex, relMousey, scrollAmount);
+ }
+ protected void mouseScrolled(int absMouseX, int absMouseY, int relMouseX0, int relMouseY0, int scrollAmount) {}
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MButton.java b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MButton.java
new file mode 100644
index 00000000..e6c675ca
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MButton.java
@@ -0,0 +1,51 @@
+package kr.syeyoung.dungeonsguide.roomedit.elements;
+
+import kr.syeyoung.dungeonsguide.roomedit.MPanel;
+import lombok.Getter;
+import lombok.Setter;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.FontRenderer;
+import org.lwjgl.opengl.GL11;
+import org.w3c.dom.css.Rect;
+
+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 disabled = Color.darkGray;
+
+ private boolean enabled;
+
+ private Runnable onActionPerformed;
+
+ @Override
+ public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks) {
+ Dimension bounds = getSize();
+
+ Color bg = backgroundColor;
+ if (!enabled) {
+ bg = disabled;
+ } else if (new Rectangle(new Point(0,0),bounds).contains(relMousex0, relMousey0)) {
+ bg = hover;
+ }
+ GL11.glClearColor(bg.getRed(), bg.getGreen(), bg.getBlue(), bg.getAlpha());
+
+ FontRenderer renderer = Minecraft.getMinecraft().fontRendererObj;
+ int width = renderer.getStringWidth(text);
+ int x = (bounds.width - width) / 2;
+ int y = (bounds.height - renderer.FONT_HEIGHT) / 2;
+
+ renderer.drawString(text, x,y, foreground.getRGB());
+ }
+
+ @Override
+ protected void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) {
+ if (onActionPerformed != null && new Rectangle(new Point(0,0),getSize()).contains(relMouseX, relMouseY))
+ onActionPerformed.run();
+ }
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MLabel.java b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MLabel.java
new file mode 100644
index 00000000..1bc0c0f7
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MLabel.java
@@ -0,0 +1,31 @@
+package kr.syeyoung.dungeonsguide.roomedit.elements;
+
+import kr.syeyoung.dungeonsguide.roomedit.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;
+
+ @Override
+ public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks) {
+ Dimension bounds = getSize();
+
+ FontRenderer renderer = Minecraft.getMinecraft().fontRendererObj;
+ int width = renderer.getStringWidth(text);
+ int x = (bounds.width - width) / 2;
+ int y = (bounds.height - renderer.FONT_HEIGHT) / 2;
+
+ renderer.drawString(text, x,y, foreground.getRGB());
+ }
+}