aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kr/syeyoung/dungeonsguide/gui
diff options
context:
space:
mode:
authorsyeyoung <cyong06@naver.com>2021-08-11 15:43:43 +0900
committersyeyoung <cyong06@naver.com>2021-08-11 15:43:43 +0900
commit21ec99c3e45e4557e228d026c148207b1227c14b (patch)
tree6b9972492da511c351cc07a9d215dd3b0ab77def /src/main/java/kr/syeyoung/dungeonsguide/gui
parenta48cb5c96e16fae589cb7d4f09146a17b3787924 (diff)
downloadSkyblock-Dungeons-Guide-21ec99c3e45e4557e228d026c148207b1227c14b.tar.gz
Skyblock-Dungeons-Guide-21ec99c3e45e4557e228d026c148207b1227c14b.tar.bz2
Skyblock-Dungeons-Guide-21ec99c3e45e4557e228d026c148207b1227c14b.zip
- X Started playing skyblock alarm
- Better Scrollbar - Modal Message - Inviting Friends in discord
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/gui')
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java2
-rwxr-xr-xsrc/main/java/kr/syeyoung/dungeonsguide/gui/elements/MButton.java25
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MList.java6
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MModal.java15
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MModalConfirmation.java1
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MModalMessage.java77
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MScrollBar.java73
-rw-r--r--src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MScrollablePanel.java6
8 files changed, 159 insertions, 46 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java
index d7f3223f..d155b9d4 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/MPanel.java
@@ -51,7 +51,7 @@ public class MPanel {
@Setter
protected MPanel parent;
- private boolean debug = false;
+ private boolean debug;
public void setBackgroundColor(Color c) {
if (c == null) return;
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 6f147472..1e9bcd0a 100755
--- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MButton.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MButton.java
@@ -45,6 +45,7 @@ public class MButton extends MPanel {
private int clicked = RenderUtils.blendAlpha(0xFF141414, 0.16f);
private int border = 0x0;
private int disabled =0xFF141414;
+ private int roundness = 0;
private boolean enabled = true;
@@ -55,19 +56,29 @@ public class MButton extends MPanel {
Dimension bounds = getSize();
int bg = background;
- if (getTooltipsOpen() > 0) {
- } else if (!enabled) {
+ if (!enabled) {
bg = disabled;
+ } else if (getTooltipsOpen() > 0) {
} else if (isclicked) {
bg = clicked;
} else if (new Rectangle(new Point(0,0),bounds).contains(relMousex0, relMousey0)) {
bg = hover;
}
- if (((border >> 24) & 0xFF) == 0)
- Gui.drawRect(0,0,getBounds().width, getBounds().height, bg);
- else {
- Gui.drawRect(0, 0, getBounds().width, getBounds().height, border);
- Gui.drawRect(1, 1, getBounds().width-1, getBounds().height-1, bg);
+ if (roundness == 0) {
+ if (((border >> 24) & 0xFF) == 0)
+ Gui.drawRect(0, 0, getBounds().width, getBounds().height, bg);
+ else {
+ Gui.drawRect(0, 0, getBounds().width, getBounds().height, border);
+ Gui.drawRect(1, 1, getBounds().width - 1, getBounds().height - 1, bg);
+ }
+ } else {
+ if (((border >> 24) & 0xFF) == 0)
+ RenderUtils.drawRoundedRectangle(0, 0, getBounds().width, getBounds().height, roundness, Math.PI/8, bg);
+ else {
+ RenderUtils.drawRoundedRectangle(0, 0, getBounds().width, getBounds().height, roundness, Math.PI/8, border);
+ RenderUtils.drawRoundedRectangle(1, 1, getBounds().width-2, getBounds().height-2, roundness, Math.PI/8, bg);
+ }
+ GlStateManager.enableTexture2D();
}
FontRenderer renderer = Minecraft.getMinecraft().fontRendererObj;
int width = renderer.getStringWidth(getText());
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MList.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MList.java
index 8823087e..cb755963 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MList.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MList.java
@@ -37,7 +37,8 @@ public class MList extends MPanel {
realignChildren();
}
- private final int gapLineColor = 0xFFFFFFFF;
+ @Getter @Setter
+ private int gapLineColor = 0xFFFFFFFF;
public void realignChildren() {
int y = 0;
@@ -73,7 +74,8 @@ public class MList extends MPanel {
for (int i = 1; i < getChildComponents().size(); i++) {
MPanel panel = getChildComponents().get(i);
Rectangle bound = panel.getBounds();
- Gui.drawRect(0, bound.y - gap, getBounds().width, bound.y, gapLineColor);
+ int top = bound.y - (int)Math.ceil(gap/2.0);
+ Gui.drawRect(0, top, getBounds().width, top + 1, gapLineColor);
}
}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MModal.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MModal.java
index 71a13c93..be2c64d6 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MModal.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MModal.java
@@ -30,6 +30,7 @@ import net.minecraft.client.renderer.GlStateManager;
import java.awt.*;
public class MModal extends MTooltip {
+ @Getter
private MPanel modalContent = new MPanel();
@Getter @Setter
@@ -50,8 +51,8 @@ public class MModal extends MTooltip {
@Override
- public void setBounds(Rectangle bounds) {
- super.setBounds(bounds);
+ public void onBoundsUpdate() {
+ super.onBoundsUpdate();
Dimension effDim = getEffectiveDimension();
modalContent.setBounds(new Rectangle((effDim.width - modalSize.width)/2, (effDim.height - modalSize.height)/2 + 16, modalSize.width, modalSize.height-16));
@@ -64,15 +65,15 @@ public class MModal extends MTooltip {
int x = (effDim.width-modalSize.width)/2;
int y = (effDim.height - modalSize.height)/2;
GlStateManager.translate(x,y, 0);
- RenderUtils.drawRoundedRectangle(0,0,modalSize.width, modalSize.height, 10, Math.PI/8, RenderUtils.blendAlpha(0x141414, 0.20f));
+ RenderUtils.drawRoundedRectangle(0,0,modalSize.width, modalSize.height, 3, Math.PI/8, RenderUtils.blendAlpha(0x141414, 0.20f));
Gui.drawRect(0,15, modalSize.width, 16, 0xFF02EE67);
Gui.drawRect(0,16,modalSize.width, 26, RenderUtils.blendAlpha(0x141414, 0.1f));
- RenderUtils.drawRoundedRectangle(0,16,modalSize.width, modalSize.height-16, 10, Math.PI/8, RenderUtils.blendAlpha(0x141414, 0.1f));
+ RenderUtils.drawRoundedRectangle(0,16,modalSize.width, modalSize.height-16, 3, Math.PI/8, RenderUtils.blendAlpha(0x141414, 0.1f));
GlStateManager.enableTexture2D();
FontRenderer fr = Minecraft.getMinecraft().fontRendererObj;
- fr.drawString(title, 10,(16-fr.FONT_HEIGHT)/2, -1);
+ fr.drawString(title, 5,(16-fr.FONT_HEIGHT)/2, -1);
}
@Override
@@ -80,6 +81,10 @@ public class MModal extends MTooltip {
modalContent.add(child);
}
+ protected void addSuper(MPanel child) {
+ super.add(child);
+ }
+
@Override
public void remove(MPanel panel) {
modalContent.remove(panel);
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MModalConfirmation.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MModalConfirmation.java
index 238392ed..92f3b258 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MModalConfirmation.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MModalConfirmation.java
@@ -67,7 +67,6 @@ public class MModalConfirmation extends MModal {
@Override
public void resize(int parentWidth, int parentHeight) {
setBounds(new Rectangle(0,0,parentWidth, parentHeight));
- System.out.println("Resized to "+parentWidth+"-"+parentHeight);
}
@Override
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MModalMessage.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MModalMessage.java
new file mode 100644
index 00000000..28d23d48
--- /dev/null
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MModalMessage.java
@@ -0,0 +1,77 @@
+/*
+ * 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 kr.syeyoung.dungeonsguide.utils.RenderUtils;
+import lombok.Getter;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.FontRenderer;
+import net.minecraft.client.renderer.GlStateManager;
+import org.lwjgl.opengl.GL11;
+
+import java.awt.*;
+
+public class MModalMessage extends MModal {
+ private String content;
+ private Runnable callBackOk;
+ @Getter
+ private MButton yes;
+ public MModalMessage(String title, String content, Runnable callBackOk) {
+ super();
+ setTitle(title);
+ this.content = content;
+ this.callBackOk = callBackOk;
+ this.yes = new MButton();
+ yes.setText("Ok");
+ yes.setOnActionPerformed(() -> {
+ close();
+ if (callBackOk != null) callBackOk.run();
+ });
+ yes.setBackground(RenderUtils.blendAlpha(0x141414, 0.15f));
+ yes.setHover(RenderUtils.blendAlpha(0x141414, 0.17f));
+
+ add(new MessageContent());
+ }
+
+ public class MessageContent extends MPanel {
+ public MessageContent() {
+ add(yes);
+ }
+
+ @Override
+ public void resize(int parentWidth, int parentHeight) {
+ setBounds(new Rectangle(0,0,parentWidth, parentHeight));
+ }
+
+ @Override
+ public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) {
+ GlStateManager.translate(5,5,0);
+ FontRenderer fr = Minecraft.getMinecraft().fontRendererObj;
+ GL11.glDisable(GL11.GL_SCISSOR_TEST);
+ fr.drawSplitString(content, 0,0, MModalMessage.MessageContent.this.bounds.width-10, -1);
+ }
+
+ @Override
+ public void setBounds(Rectangle bounds) {
+ super.setBounds(bounds);
+ yes.setBounds(new Rectangle(10,bounds.height-25,(bounds.width-20), 15));
+ }
+ }
+}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MScrollBar.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MScrollBar.java
index 82e91dab..dbc30e7e 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MScrollBar.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MScrollBar.java
@@ -43,34 +43,32 @@ public class MScrollBar extends MPanel {
private int width = 10;
public void setMax(int max) {
+ if (max < min) max = min;
this.max = max;
- current = MathHelper.clamp_int(current, min, max - thumbSize);
- if (max - min < thumbSize) current = min;
+ current = MathHelper.clamp_int(current, min, max);
if (onUpdate != null) onUpdate.run();
}
public void setMin(int min) {
+ if (max < min) max = min;
this.min = min;
- current = MathHelper.clamp_int(current, min, max - thumbSize);
- if (max - min < thumbSize) current = min;
+ current = MathHelper.clamp_int(current, min, max);
if (onUpdate != null) onUpdate.run();
}
public void setThumbSize(int thumbSize) {
this.thumbSize = thumbSize;
- current = MathHelper.clamp_int(current, min, max - thumbSize);
- if (max - min < thumbSize) current = min;
+ current = MathHelper.clamp_int(current, min, max);
if (onUpdate != null) onUpdate.run();
}
public void addToCurrent(int dv) {
int current2 = current + dv;
- current = MathHelper.clamp_int(current2, min, max - thumbSize);
- if (max - min < thumbSize) current = min;
+ current = MathHelper.clamp_int(current2, min, max);
if (onUpdate != null) onUpdate.run();
}
@@ -83,16 +81,16 @@ public class MScrollBar extends MPanel {
@Getter
@Setter
private int background = RenderUtils.blendAlpha(0xFF141414, 0.04f),
- thumb = RenderUtils.blendAlpha(0xFF141414, 0.08f),
- thumbHover = RenderUtils.blendAlpha(0xFF141414, 0.09f),
- thumbClick = RenderUtils.blendAlpha(0xFF141414, 0.14f);
+ thumb = RenderUtils.blendAlpha(0xFF141414, 0.14f),
+ thumbHover = RenderUtils.blendAlpha(0xFF141414, 0.15f),
+ thumbClick = RenderUtils.blendAlpha(0xFF141414, 0.20f);
private Runnable onUpdate;
public MScrollBar(int min, int max, int thumbSize, int current, Axis axis, Runnable onUpdate) {
+ if (max < min) max = min;
this.min = min; this.min = max; this.thumbSize = thumbSize; this.current = current; this.axis = axis;
- this.current = MathHelper.clamp_int(current, min, max - thumbSize);
- if (max - min < thumbSize) this.current = min;
+ this.current = MathHelper.clamp_int(current, min, max);
this.onUpdate = onUpdate;
}
@@ -106,13 +104,22 @@ public class MScrollBar extends MPanel {
@Override
public void render(int absMousex, int absMousey, int relMousex0, int relMousey0, float partialTicks, Rectangle scissor) {
// RENDER SUPER NICE SCROLL BAR
+ int minimalThumbLen = 20;
+
Gui.drawRect(0,0,getBounds().width, getBounds().height, background);
- double startPerc, endPerc;
+ int length = axis == Axis.X ? bounds.width :bounds.height;
+ int totalUnscaledLength = max-min + thumbSize;
+ double subPoint = ((double)max-min) * length / totalUnscaledLength;
+ if (length - subPoint < minimalThumbLen) {
+ subPoint = length - minimalThumbLen;
+ }
+ double thumbSize = length - subPoint;
+
+ double startPt;
if (max - min == 0) {
- startPerc =0; endPerc = 1;
+ startPt =0;
} else {
- startPerc = (current - min)/((double)max - min);
- endPerc = (current+thumbSize - min)/((double)max - min);
+ startPt = subPoint * (current - min)/((double)max - min);
}
int color = thumbHover;
@@ -120,16 +127,14 @@ public class MScrollBar extends MPanel {
if (grabbed) color = thumbClick;
if (axis == Axis.X) {
- int startX = (int) (startPerc * getBounds().width);
- int endX = (int) (endPerc * getBounds().width);
- endX = Math.max(endX, startX + 20);
+ int startX = (int) startPt;
+ int endX = (int) (startPt + thumbSize);
Gui.drawRect(startX,0,endX,getBounds().height, color);
lastThumbRect.x = startX; lastThumbRect.y = 0; lastThumbRect.width = endX - startX; lastThumbRect.height = getBounds().height;
} else if (axis == Axis.Y) {
- int startY = (int) (startPerc * getBounds().height);
- int endY = (int) (endPerc * getBounds().height);
- endY = Math.max(endY, startY + 20);
+ int startY = (int) startPt;
+ int endY = (int) (startPt + thumbSize);
Gui.drawRect(0,startY,getBounds().width,endY, color);
lastThumbRect.x = 0; lastThumbRect.y = startY; lastThumbRect.width = getBounds().width; lastThumbRect.height = endY - startY;
@@ -153,21 +158,33 @@ public class MScrollBar extends MPanel {
@Override
public void mouseClickMove(int absMouseX, int absMouseY, int relMouseX, int relMouseY, int clickedMouseButton, long timeSinceLastClick) {
if (!grabbed) return;
+
+ int minimalThumbLen = 20;
+
+ Gui.drawRect(0,0,getBounds().width, getBounds().height, background);
+ int length = axis == Axis.X ? bounds.width :bounds.height;
+ int totalUnscaledLength = max-min + thumbSize;
+ double subPoint = ((double)max-min) * length / totalUnscaledLength;
+ if (length - subPoint < minimalThumbLen) {
+ subPoint = length - minimalThumbLen;
+ }
+ double thumbSize = length - subPoint;
+
+
+
int dx = absMouseX - lastX, dy = absMouseY - lastY;
lastX = absMouseX;
lastY = absMouseY;
int prevVal = current;
-
if (axis == Axis.Y) {
- actualValue += dy * (max - min) / getBounds().height;
+ actualValue += dy * (max - min) / subPoint;
} else if (axis == Axis.X) {
- actualValue += dx * (max - min) / getBounds().width;
+ actualValue += dx * (max - min) / subPoint;
}
- current = MathHelper.clamp_int(actualValue, min, max - thumbSize);
- if (max - min < thumbSize) current = min;
+ current = MathHelper.clamp_int(actualValue, min, max);
if (onUpdate != null && prevVal != current) onUpdate.run();
}
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MScrollablePanel.java b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MScrollablePanel.java
index d09b7c5a..d5f27227 100644
--- a/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MScrollablePanel.java
+++ b/src/main/java/kr/syeyoung/dungeonsguide/gui/elements/MScrollablePanel.java
@@ -125,9 +125,9 @@ public class MScrollablePanel extends MPanel {
}
contentAreaDim = new Rectangle(minX, minY, maxX - minX, maxY - minY);
scrollBarX.setMin(contentAreaDim.x);
- scrollBarX.setMax(contentAreaDim.x + contentAreaDim.width);
+ scrollBarX.setMax(contentAreaDim.x + contentAreaDim.width-scrollBarX.getThumbSize());
scrollBarY.setMin(contentAreaDim.y);
- scrollBarY.setMax(contentAreaDim.y + contentAreaDim.height);
+ scrollBarY.setMax(contentAreaDim.y + contentAreaDim.height-scrollBarY.getThumbSize());
}
@Override
@@ -161,6 +161,8 @@ public class MScrollablePanel extends MPanel {
scrollBarX.setThumbSize(viewPort.getBounds().width);
scrollBarY.setThumbSize(viewPort.getBounds().height);
+ scrollBarX.setMax(contentAreaDim.x + contentAreaDim.width-scrollBarX.getThumbSize());
+ scrollBarY.setMax(contentAreaDim.y + contentAreaDim.height-scrollBarY.getThumbSize());
evalulateContentArea();
}