aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kr/syeyoung/dungeonsguide/gui
diff options
context:
space:
mode:
authorsyeyoung <cyong06@naver.com>2021-07-18 23:35:41 +0900
committersyeyoung <cyong06@naver.com>2021-07-18 23:35:41 +0900
commit0af44a60844be83fb371c2f0eaeb2feccd1f0207 (patch)
tree1ac67087eeb7afb1afb7b7afa2d22d3f3c7b3748 /src/main/java/kr/syeyoung/dungeonsguide/gui
parente4ac7cf162d4383424a0798f160073b8d5bc1f1b (diff)
downloadSkyblock-Dungeons-Guide-0af44a60844be83fb371c2f0eaeb2feccd1f0207.tar.gz
Skyblock-Dungeons-Guide-0af44a60844be83fb371c2f0eaeb2feccd1f0207.tar.bz2
Skyblock-Dungeons-Guide-0af44a60844be83fb371c2f0eaeb2feccd1f0207.zip
Modification to GUI Framework
- Mostly removes Scaled GUI - Also has done some fixes to gui relocation
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/gui')
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/gui/MGui.java172
-rw-r--r--[-rwxr-xr-x]src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java31
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MRootPanel.java50
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/gui/elements/MToggleButton.java2
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTooltip.java86
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTooltipText.java44
6 files changed, 379 insertions, 6 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/MGui.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/MGui.java
new file mode 100644
index 00000000..7c35306d
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/MGui.java
@@ -0,0 +1,172 @@
+/*
+ * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod
+ * Copyright (C) 2021 cyoung06
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package kr.syeyoung.dungeonsguide.gui;
+
+import kr.syeyoung.dungeonsguide.gui.elements.MRootPanel;
+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.input.Mouse;
+import org.lwjgl.opengl.GL11;
+
+import java.awt.*;
+import java.io.IOException;
+
+public class MGui extends GuiScreen {
+
+ @Getter
+ private final MPanel mainPanel = new MRootPanel();
+
+
+ @Override
+ public void initGui() {
+ super.initGui();
+ ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
+ mainPanel.setBounds(new Rectangle(0,0,Minecraft.getMinecraft().displayWidth,Minecraft.getMinecraft().displayHeight));
+ }
+
+ @Override
+ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
+ try {
+
+ int i = Mouse.getEventX();
+ int j = this.mc.displayHeight - Mouse.getEventY();
+ ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
+ GlStateManager.pushMatrix();
+ GlStateManager.pushAttrib();
+ GlStateManager.disableLighting();
+ GlStateManager.disableFog();
+ GlStateManager.disableDepth();
+ GL11.glDisable(GL11.GL_FOG);
+ GlStateManager.enableBlend();
+ GlStateManager.enableAlpha();
+ GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
+ GlStateManager.color(1, 1, 1, 1);
+ GlStateManager.scale(1.0/scaledResolution.getScaleFactor(), 1.0/scaledResolution.getScaleFactor(), 1.0d);
+ mainPanel.render0(scaledResolution, new Point(0,0), new Rectangle(0,0,Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight), i, j, i, j, partialTicks);
+ GlStateManager.popAttrib();
+ GlStateManager.popMatrix();
+ GlStateManager.enableBlend();
+ GlStateManager.enableLighting();
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ GL11.glDisable(GL11.GL_SCISSOR_TEST);
+ }
+
+ @Override
+ public void keyTyped(char typedChar, int keyCode) throws IOException {
+ try {
+ mainPanel.keyTyped0(typedChar, keyCode);
+ super.keyTyped(typedChar, keyCode);
+ } catch (Throwable e) {
+ if (!e.getMessage().contains("hack to stop"))
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
+ try {
+ super.mouseClicked(mouseX, mouseY, mouseButton);
+ mainPanel.mouseClicked0(mouseX, mouseY
+ ,mouseX, mouseY, mouseButton);
+ } catch (Throwable e) {
+ if (!e.getMessage().contains("hack to stop"))
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void onGuiClosed() {
+ super.onGuiClosed();
+ }
+
+ @Override
+ public void mouseReleased(int mouseX, int mouseY, int state) {
+ try {
+ mainPanel.mouseReleased0(mouseX, mouseY
+ ,mouseX,mouseY , state);
+ } catch (Throwable e) {
+ if (!e.getMessage().contains("hack to stop"))
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
+ try {
+ mainPanel.mouseClickMove0(mouseX, mouseY
+ ,mouseX ,mouseY, clickedMouseButton, timeSinceLastClick);
+ } catch (Throwable e) {
+ if (!e.getMessage().contains("hack to stop"))
+ e.printStackTrace();
+ }
+ }
+
+ private int touchValue;
+ private int eventButton;
+ private long lastMouseEvent;
+
+ @Override
+ public void handleMouseInput() throws IOException {
+ try {
+ int i = Mouse.getEventX();
+ int j = this.mc.displayHeight - Mouse.getEventY();
+ int k = Mouse.getEventButton();
+
+ if (Mouse.getEventButtonState())
+ {
+ if (this.mc.gameSettings.touchscreen && this.touchValue++ > 0)
+ {
+ return;
+ }
+
+ this.eventButton = k;
+ this.lastMouseEvent = Minecraft.getSystemTime();
+ this.mouseClicked(i, j, this.eventButton);
+ }
+ else if (k != -1)
+ {
+ if (this.mc.gameSettings.touchscreen && --this.touchValue > 0)
+ {
+ return;
+ }
+
+ this.eventButton = -1;
+ this.mouseReleased(i, j, k);
+ }
+ else if (this.eventButton != -1 && this.lastMouseEvent > 0L)
+ {
+ long l = Minecraft.getSystemTime() - this.lastMouseEvent;
+ this.mouseClickMove(i, j, this.eventButton, l);
+ }
+
+
+ int wheel = Mouse.getDWheel();
+ if (wheel != 0) {
+ mainPanel.mouseScrolled0(i, j,i,j, wheel);
+ }
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java
index 911038f2..5f7ff538 100755..100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java
@@ -18,15 +18,13 @@
package kr.syeyoung.dungeonsguide.gui;
+import kr.syeyoung.dungeonsguide.gui.elements.MTooltip;
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 net.minecraft.client.renderer.Tessellator;
-import net.minecraft.client.renderer.WorldRenderer;
-import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import org.lwjgl.opengl.GL11;
import java.awt.*;
@@ -46,6 +44,9 @@ public class MPanel {
@Getter(AccessLevel.PUBLIC)
protected boolean isFocused;
+ @Getter
+ protected MPanel parent;
+
public void setBackgroundColor(Color c) {
if (c == null) return;
this.backgroundColor = c;
@@ -83,19 +84,31 @@ public class MPanel {
}
public void add(MPanel child) {
+ if (child.parent != null) throw new IllegalArgumentException("What have you done");
this.childComponents.add(child);
+ child.parent = this;
+ }
+
+ public void openTooltip(MTooltip mPanel) {
+ parent.openTooltip(mPanel);
+ }
+ public int getTooltipsOpen() {
+ return parent.getTooltipsOpen();
}
public void remove(MPanel panel) {
+ panel.parent = null;
this.childComponents.remove(panel);
}
+ protected Point lastParentPoint;
public void render0(ScaledResolution resolution, Point parentPoint, Rectangle parentClip, int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks) { // 0,0 - a a
+ lastParentPoint = parentPoint;
int relMousex = relMousex0 - getBounds().x;
int relMousey = relMousey0 - getBounds().y;
- GlStateManager.translate(getBounds().x, getBounds().y, 0);
+ GlStateManager.translate(getBounds().x, getBounds().y, 5);
GlStateManager.color(1,1,1,0);
@@ -103,6 +116,7 @@ public class MPanel {
absBound.setLocation(absBound.x + parentPoint.x, absBound.y + parentPoint.y);
Rectangle clip = determineClip(parentClip, absBound);
lastAbsClip = clip;
+ if (clip.getSize().height * clip.getSize().width == 0) return;
clip(resolution, clip.x, clip.y, clip.width, clip.height);
GlStateManager.pushAttrib();
@@ -115,6 +129,12 @@ public class MPanel {
GlStateManager.pushMatrix();
GlStateManager.pushAttrib();
+
+ GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
+ GlStateManager.enableBlend();
+ GlStateManager.enableAlpha();
+ GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
+
render(absMousex, absMousey, relMousex, relMousey, partialTicks, clip);
GlStateManager.popAttrib();
GlStateManager.popMatrix();
@@ -137,7 +157,8 @@ public class MPanel {
public static void clip(ScaledResolution resolution, int x, int y, int width, int height) {
if (width < 0 || height < 0) return;
- int scale = resolution.getScaleFactor();
+// int scale = resolution.getScaleFactor();
+ int scale = 1;
GL11.glScissor((x ) * scale, Minecraft.getMinecraft().displayHeight - (y + height) * scale, (width) * scale, height * scale);
}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MRootPanel.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MRootPanel.java
new file mode 100644
index 00000000..a6987241
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MRootPanel.java
@@ -0,0 +1,50 @@
+/*
+ * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod
+ * Copyright (C) 2021 cyoung06
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package kr.syeyoung.dungeonsguide.gui.elements;
+
+import kr.syeyoung.dungeonsguide.gui.MPanel;
+import lombok.Getter;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+@Getter
+public class MRootPanel extends MPanel {
+ @Getter
+ private List<MTooltip> tooltips = new CopyOnWriteArrayList<>();
+
+
+ @Override
+ public void openTooltip(MTooltip mPanel) {
+ mPanel.setRoot(this);
+ tooltips.add(mPanel);
+ add(mPanel);
+ }
+
+ @Override
+ public int getTooltipsOpen() {
+ return tooltips.size();
+ }
+
+ public void removeTooltip(MTooltip mTooltip) {
+ mTooltip.setRoot(null);
+ tooltips.remove(mTooltip);
+ remove(mTooltip);
+ }
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MToggleButton.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MToggleButton.java
index 432fd0a8..5b99959f 100755
--- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MToggleButton.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MToggleButton.java
@@ -48,7 +48,7 @@ public class MToggleButton extends MPanel {
FontRenderer fr = Minecraft.getMinecraft().fontRendererObj;
- double scale = 2;
+ double scale = 1;
GlStateManager.enableBlend();
GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTooltip.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTooltip.java
new file mode 100644
index 00000000..56eb2821
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTooltip.java
@@ -0,0 +1,86 @@
+/*
+ * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod
+ * Copyright (C) 2021 cyoung06
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package kr.syeyoung.dungeonsguide.gui.elements;
+
+import kr.syeyoung.dungeonsguide.gui.MPanel;
+import lombok.Getter;
+import lombok.Setter;
+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.*;
+
+public class MTooltip extends MPanel {
+ @Getter @Setter
+ private MRootPanel root;
+
+ public void open(MPanel component) {
+ component.openTooltip(this);
+ }
+ public void close() {
+ if (root != null)
+ root.removeTooltip(this);
+ }
+
+ @Override
+ public int getTooltipsOpen() {
+ return super.getTooltipsOpen() - 1;
+ }
+
+ 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, 300);
+ GlStateManager.color(1,1,1,0);
+
+
+ Rectangle clip = getBounds().getBounds();
+ GlStateManager.pushAttrib();
+ GL11.glEnable(GL11.GL_SCISSOR_TEST);
+ clip(resolution, clip.x, clip.y, clip.width, clip.height);
+
+ GlStateManager.pushAttrib();
+ GuiScreen.drawRect(0,0, getBounds().width, getBounds().height, backgroundColor.getRGB());
+ GlStateManager.enableBlend();
+ GlStateManager.popAttrib();
+
+ GlStateManager.pushMatrix();
+ GlStateManager.pushAttrib();
+ render(absMousex, absMousey, relMousex, relMousey, partialTicks, clip);
+ GlStateManager.popAttrib();
+ GlStateManager.popMatrix();
+
+ GL11.glDisable(GL11.GL_SCISSOR_TEST);
+ GlStateManager.popAttrib();
+
+
+ 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();
+ }
+ }
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTooltipText.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTooltipText.java
new file mode 100644
index 00000000..fe93d82a
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTooltipText.java
@@ -0,0 +1,44 @@
+/*
+ * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod
+ * Copyright (C) 2021 cyoung06
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package kr.syeyoung.dungeonsguide.gui.elements;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+import net.minecraft.client.Minecraft;
+import net.minecraftforge.fml.client.config.GuiUtils;
+
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.List;
+
+@AllArgsConstructor
+public class MTooltipText extends MTooltip {
+ @Getter @Setter
+ private List<String> tooltipText = new ArrayList<>();
+ @Override
+ public Rectangle getBounds() {
+ return new Rectangle(0,0, Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight);
+ }
+
+ @Override
+ public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) {
+ GuiUtils.drawHoveringText(tooltipText, relMousex0, relMousey0, Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight, -1, Minecraft.getMinecraft().fontRendererObj);
+ }
+}