aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kr/syeyoung/dungeonsguide/gui
diff options
context:
space:
mode:
authorsyeyoung <cyong06@naver.com>2021-02-05 17:29:09 +0900
committersyeyoung <cyong06@naver.com>2021-02-05 17:29:09 +0900
commit6b4e2499ece7f4328381a88380baea85fe24246d (patch)
tree07a1da8b9d2b6f543d5905a29adc2a5a1c46736d /src/main/java/kr/syeyoung/dungeonsguide/gui
parent3d20d63e025b827ae9a8e7bd62b436fda7986071 (diff)
downloadSkyblock-Dungeons-Guide-6b4e2499ece7f4328381a88380baea85fe24246d.tar.gz
Skyblock-Dungeons-Guide-6b4e2499ece7f4328381a88380baea85fe24246d.tar.bz2
Skyblock-Dungeons-Guide-6b4e2499ece7f4328381a88380baea85fe24246d.zip
Gui Overhaul part 1
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/gui')
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java7
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/gui/elements/MButton.java2
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/gui/elements/MNavigatingPane.java171
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTabbedPane.java28
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java2
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/gui/elements/MToggleButton.java56
6 files changed, 253 insertions, 13 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java
index 4eae2298..50d5b85f 100755
--- a/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java
@@ -42,6 +42,8 @@ public class MPanel {
return getBounds().getSize();
}
+ public Dimension getPreferredSize() { return getSize(); }
+
public void setBounds(Rectangle bounds) {
if (bounds == null) return;
this.bounds.x = bounds.x;
@@ -69,7 +71,6 @@ public class MPanel {
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;
@@ -97,7 +98,7 @@ public class MPanel {
GlStateManager.popMatrix();
GL11.glDisable(GL11.GL_SCISSOR_TEST);
- GL11.glPopAttrib();
+ GlStateManager.popAttrib();
Point newPt = new Point(parentPoint.x + getBounds().x, parentPoint.y + getBounds().y);
@@ -112,6 +113,8 @@ public class MPanel {
}
public void clip(ScaledResolution resolution, int x, int y, int width, int height) {
+ if (width < 0 || height < 0) return;
+
int scale = resolution.getScaleFactor();
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/MButton.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MButton.java
index 17196ebc..ff420a32 100755
--- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MButton.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MButton.java
@@ -39,7 +39,7 @@ public class MButton extends MPanel {
FontRenderer renderer = Minecraft.getMinecraft().fontRendererObj;
int width = renderer.getStringWidth(getText());
int x = (getBounds().width - width) / 2;
- int y = (getBounds().height - renderer.FONT_HEIGHT) / 2;
+ int y = (getBounds().height - renderer.FONT_HEIGHT) / 2 + 1;
renderer.drawString(getText(), x,y, foreground.getRGB());
}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MNavigatingPane.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MNavigatingPane.java
new file mode 100755
index 00000000..c59b3b4f
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MNavigatingPane.java
@@ -0,0 +1,171 @@
+package kr.syeyoung.dungeonsguide.gui.elements;
+
+import com.google.common.base.Function;
+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 scala.collection.mutable.Stack;
+
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class MNavigatingPane extends MPanel {
+
+ private Map<String, MPanel> pages = new HashMap<String, MPanel>();
+ private List<MTabButton> bookMarks = new ArrayList<MTabButton>();
+
+ @Getter
+ @Setter
+ private Function<String, MPanel> pageGenerator;
+
+ @Getter
+ private String currentPage = "";
+
+ public void setCurrentPage(String currentPage) {
+ this.history.push(this.currentPage);
+ this.currentPage = currentPage;
+ }
+
+ @Getter
+ private Color background2;
+
+ private Stack<String> history = new Stack<String>();
+
+ private MButton back = new MButton();
+
+ public MNavigatingPane() {
+ back.setText("<");
+ back.setOnActionPerformed(new Runnable() {
+ @Override
+ public void run() {
+ if (history.size() > 0)
+ currentPage = history.pop();
+ }
+ });
+ back.setBackgroundColor(Color.darkGray);
+ back.setBounds(new Rectangle(3,18,12,12));
+ add(back);
+ }
+
+ public void setBackground2(Color background2) {
+ this.background2 = background2;
+ for (MPanel value : pages.values()) {
+ value.setBackgroundColor(background2);
+ }
+ }
+
+ @Override
+ public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) {
+
+ Gui.drawRect(0, 15, getBounds().width, getBounds().height, 0xFF444444);
+ Gui.drawRect(1, 16, getBounds().width-1, getBounds().height-1, background2 != null ? background2.getRGB() : 0);
+ FontRenderer fr = Minecraft.getMinecraft().fontRendererObj;
+
+ fr.drawString(currentPage.replace(".", " > "), 20, 20, 0xFFFFFFFF);
+
+ }
+
+ public void addBookmark(String name, String addr) {
+ FontRenderer fr = Minecraft.getMinecraft().fontRendererObj;
+ MTabButton button = new MTabButton(this, name, addr);
+ int totalX = 0;
+ for (MTabButton button1:bookMarks)
+ totalX += button1.getBounds().width;
+ button.setBounds(new Rectangle(totalX, 0, Math.max(25, fr.getStringWidth(name) + 6), 15));
+ bookMarks.add(button);
+ if (bookMarks.size() == 1)
+ currentPage = addr;
+ }
+
+ @Override
+ public List<MPanel> getChildComponents() {
+ ArrayList<MPanel> dynamic = new ArrayList<MPanel>(bookMarks);
+ if (!pages.containsKey(currentPage)) {
+ MPanel panel = pageGenerator.apply(currentPage);
+ MPanel panel2 = new MPanel() ;
+ panel2.add(panel);
+ panel2.setBackgroundColor(background2);
+ pages.put(currentPage, panel2);
+ panel2.setBounds(new Rectangle(1,30,getBounds().width-2, getBounds().height-31));
+ }
+ dynamic.add(pages.get(currentPage));
+ dynamic.add(back);
+ return dynamic;
+ }
+
+ @Override
+ public void resize(int parentWidth, int parentHeight) {
+ this.setBounds(new Rectangle(0,0,parentWidth, parentHeight));
+ for (MPanel ma:pages.values())
+ ma.setBounds(new Rectangle(1,30,getBounds().width-2, getBounds().height-31));
+ }
+
+ @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;
+ }
+
+ @Getter
+ @Setter
+ public static class MTabButton extends MPanel {
+ private String text;
+ private String address;
+
+ private Color foreground = Color.white;
+ private Color hover = new Color(154, 154, 154, 255);
+ private Color clicked = new Color(88, 88, 88,255);
+ private Color selected = new Color(111, 111, 111,255);
+ private Color disabled = new Color(0,0,0);
+
+ private boolean enabled = true;
+
+ private MNavigatingPane tabbedPane;
+
+ public MTabButton(MNavigatingPane tabbedPane, String key, String address) {
+ this.tabbedPane = tabbedPane;
+ this.text = key;
+ this.address = address;
+ }
+
+ @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.getCurrentPage().equals(address)) {
+ bg = selected;
+ } else if (new Rectangle(new Point(0,0),bounds).contains(relMousex0, relMousey0)) {
+ bg = hover;
+ }
+ Gui.drawRect(0, tabbedPane.getCurrentPage().equals(address) ? 0 : 2, getBounds().width, getBounds().height, 0xFF444444);
+ if (bg != null)
+ Gui.drawRect(1,tabbedPane.getCurrentPage().equals(address) ? 1 : 3,getBounds().width - 1, getBounds().height, bg.getRGB());
+
+ FontRenderer renderer = Minecraft.getMinecraft().fontRendererObj;
+ int width = renderer.getStringWidth(text);
+ int x = (getBounds().width - width) / 2;
+ int y = (getBounds().height - 3 - renderer.FONT_HEIGHT) / 2 + 3;
+
+ 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.setCurrentPage(address);
+ }
+ }
+ }
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTabbedPane.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTabbedPane.java
index ddf1c8a9..dc14264b 100755
--- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTabbedPane.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTabbedPane.java
@@ -1,6 +1,7 @@
package kr.syeyoung.dungeonsguide.gui.elements;
import kr.syeyoung.dungeonsguide.gui.MPanel;
+import kr.syeyoung.dungeonsguide.utils.RenderUtils;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.client.Minecraft;
@@ -35,16 +36,24 @@ public class MTabbedPane extends MPanel {
}
}
+ @Override
+ public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) {
+ Gui.drawRect(0, 15, getBounds().width, getBounds().height, 0xFF444444);
+ }
+
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));
+ panel2.setBounds(new Rectangle(1,16,getBounds().width-2, getBounds().height-17));
+ FontRenderer fr = Minecraft.getMinecraft().fontRendererObj;
MTabButton button = new MTabButton(this, tab);
- button.setBackgroundColor(background2.brighter());
- button.setBounds(new Rectangle(buttons.size()* 50, 0, 50, 15));
+ int totalX = 0;
+ for (MTabButton button1:buttons.values())
+ totalX += button1.getBounds().width;
+ button.setBounds(new Rectangle(totalX, 0, Math.max(25, fr.getStringWidth(tab) + 6), 15));
buttons.put(tab, button);
if (tabs.size() == 1)
selectedKey = tab;
@@ -61,7 +70,7 @@ public class MTabbedPane extends MPanel {
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));
+ ma.setBounds(new Rectangle(1,16,getBounds().width-2, getBounds().height-17));
}
@Override
@@ -79,9 +88,9 @@ public class MTabbedPane 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 hover = new Color(154, 154, 154, 255);
+ private Color clicked = new Color(88, 88, 88,255);
+ private Color selected = new Color(111, 111, 111,255);
private Color disabled = new Color(0,0,0);
private boolean enabled = true;
@@ -105,13 +114,14 @@ public class MTabbedPane extends MPanel {
} else if (new Rectangle(new Point(0,0),bounds).contains(relMousex0, relMousey0)) {
bg = hover;
}
+ Gui.drawRect(0, tabbedPane.getSelectedKey().equals(text) ? 0 : 2, getBounds().width, getBounds().height, 0xFF444444);
if (bg != null)
- Gui.drawRect(0,0,getBounds().width, getBounds().height, bg.getRGB());
+ Gui.drawRect(1,tabbedPane.getSelectedKey().equals(text) ? 1 : 3,getBounds().width - 1, 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;
+ int y = (getBounds().height - 3 - renderer.FONT_HEIGHT) / 2 + 3;
renderer.drawString(text, x,y, foreground.getRGB());
}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java
index 57232f7f..d3f2b2c0 100755
--- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MTextField.java
@@ -43,7 +43,7 @@ public class MTextField extends MPanel {
@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());
+ Gui.drawRect(1,1,getBounds().width - 1, getBounds().height - 1, Color.black.getRGB());
Minecraft mc = Minecraft.getMinecraft();
clip(new ScaledResolution(mc), clip.x + 1, clip.y + 1, clip.width - 2, clip.height - 2);
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MToggleButton.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MToggleButton.java
new file mode 100755
index 00000000..5d2d4d67
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MToggleButton.java
@@ -0,0 +1,56 @@
+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 net.minecraft.client.renderer.GlStateManager;
+import org.lwjgl.opengl.GL11;
+
+import java.awt.*;
+
+@Getter
+@Setter
+public class MToggleButton extends MPanel {
+ private boolean enabled = true;
+ private Runnable onToggle;
+
+ @Override
+ public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle clip) {
+ Dimension bounds = getSize();
+
+ int gap = 1;
+
+ Gui.drawRect(0, 0, bounds.width, bounds.height, 0xFF333333);
+ Gui.drawRect(gap, gap, bounds.width-gap, bounds.height-gap, 0xFF171717);
+
+
+ FontRenderer fr = Minecraft.getMinecraft().fontRendererObj;
+ double scale = 2;
+ if (enabled) {
+ int x = (int) ((scale * bounds.height - fr.FONT_HEIGHT)/2 + gap);
+ GlStateManager.pushMatrix();
+ GlStateManager.scale(1.0/scale,1.0/scale,0);
+ fr.drawString("ON", x, x, 0xFF9B9B9B);
+ GlStateManager.popMatrix();
+ Gui.drawRect(bounds.width - bounds.height+gap,gap, bounds.width - gap, bounds.height - gap, 0xFF00B200);
+ } else {
+ GlStateManager.pushMatrix();
+ GlStateManager.scale(1.0/scale,1.0/scale,0);
+ int x = (int) ((scale * bounds.height - fr.FONT_HEIGHT)/2 + gap);
+ fr.drawString("OFF", (int) (scale * bounds.width - x - fr.getStringWidth("OFF")), x, 0xFF9B9B9B);
+ GlStateManager.popMatrix();
+ Gui.drawRect(gap,gap, bounds.height - gap, bounds.height - gap, 0xFFCD4000);
+ }
+ }
+
+ @Override
+ public void mouseClicked(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int mouseButton) {
+ if (onToggle != null && lastAbsClip.contains(absMouseX, absMouseY)) {
+ enabled = !enabled;
+ onToggle.run();
+ }
+ }
+}