aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java1
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/SideBar.java7
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/BasicButton.java48
3 files changed, 34 insertions, 22 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java
index bc30257..6f8aeea 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java
@@ -102,5 +102,4 @@ public class OneConfigGui extends GuiScreen {
public boolean doesGuiPauseGame() {
return false;
}
-
}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/SideBar.java b/src/main/java/io/polyfrost/oneconfig/gui/SideBar.java
index 7f84049..fd8f92e 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/SideBar.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/SideBar.java
@@ -7,6 +7,9 @@ import io.polyfrost.oneconfig.gui.pages.ModsPage;
import io.polyfrost.oneconfig.lwjgl.RenderManager;
import io.polyfrost.oneconfig.lwjgl.font.Fonts;
import io.polyfrost.oneconfig.utils.MathUtils;
+import io.polyfrost.oneconfig.utils.TickDelay;
+import net.minecraft.client.Minecraft;
+import scala.collection.parallel.ParIterableLike;
import java.util.ArrayList;
import java.util.List;
@@ -26,9 +29,9 @@ public class SideBar {
btnList.add(new BasicButton(192, 36, "Screenshots", "/assets/oneconfig/textures/share.png", null, -3, BasicButton.ALIGNMENT_LEFT));
btnList.add(new BasicButton(192, 36, "HUD Settings", "/assets/oneconfig/textures/share.png", null, -3, BasicButton.ALIGNMENT_LEFT));
btnList.add(new BasicButton(192, 36, "General", "/assets/oneconfig/textures/share.png", null, -3, BasicButton.ALIGNMENT_LEFT));
- btnList.add(new BasicButton(192, 36, "Close", "/assets/oneconfig/textures/share.png", null, -1, BasicButton.ALIGNMENT_LEFT));
+ btnList.add(new BasicButton(192, 36, "Close", "/assets/oneconfig/textures/share.png", null, -1, BasicButton.ALIGNMENT_LEFT, () -> Minecraft.getMinecraft().displayGuiScreen(null)));
btnList.add(new BasicButton(192, 36, "Minimize", "/assets/oneconfig/textures/share.png", null, -1, BasicButton.ALIGNMENT_LEFT));
- btnList.add(new BasicButton(192, 36, "Edit HUD", "/assets/oneconfig/textures/share.png", null, 0, BasicButton.ALIGNMENT_LEFT));
+ btnList.add(new BasicButton(192, 36, "Edit HUD", "/assets/oneconfig/textures/share.png", null, 0, BasicButton.ALIGNMENT_LEFT, () -> Minecraft.getMinecraft().displayGuiScreen(new HudGui())));
}
public void draw(long vg, int x, int y) {
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicButton.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicButton.java
index 8fc2a63..c0d4cec 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicButton.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicButton.java
@@ -9,6 +9,9 @@ import io.polyfrost.oneconfig.utils.ColorUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import java.util.function.Consumer;
+import java.util.function.Supplier;
+
public class BasicButton extends BasicElement {
protected String text;
@@ -24,15 +27,17 @@ public class BasicButton extends BasicElement {
private boolean toggleable;
private Page page;
+ private Runnable runnable;
/**
* Create a new basic button. Used mostly on the homepage and the sidebar. Note: The button will not be drawn until you call {@link #draw(long, int, int)}.
* The button's content is centered on its total length, so the text is not always in the middle.
- * @param text Text to display on the button. Has to be there.
- * @param fileNameLeftIco file path of the icon to display on the left. Can be null if you don't want to display an icon on the left.
+ *
+ * @param text Text to display on the button. Has to be there.
+ * @param fileNameLeftIco file path of the icon to display on the left. Can be null if you don't want to display an icon on the left.
* @param fileNameRightIco file path of the icon to display on the right. Can be null if you don't want to display an icon on the right.
- * @param colorPalette color palette to use. see {@link io.polyfrost.oneconfig.utils.ColorUtils} for more info. Can support color palette of -2, which is larger font and icons. Also supports -3, which is just the text changing color.
- * @param alignment alignment of the button. ALIGNMENT_LEFT or ALIGNMENT_CENTER.
+ * @param colorPalette color palette to use. see {@link io.polyfrost.oneconfig.utils.ColorUtils} for more info. Can support color palette of -2, which is larger font and icons. Also supports -3, which is just the text changing color.
+ * @param alignment alignment of the button. ALIGNMENT_LEFT or ALIGNMENT_CENTER.
*/
public BasicButton(int width, int height, @NotNull String text, @Nullable String fileNameLeftIco, @Nullable String fileNameRightIco, int colorPalette, int alignment) {
super(width, height, colorPalette, true);
@@ -40,7 +45,7 @@ public class BasicButton extends BasicElement {
this.fileNameLeftIco = fileNameLeftIco;
this.fileNameRightIco = fileNameRightIco;
this.thisAlignment = alignment;
- if(colorPalette == -2) {
+ if (colorPalette == -2) {
fontSize = 24f;
this.colorPalette = -1;
} else {
@@ -59,7 +64,10 @@ public class BasicButton extends BasicElement {
this.toggleable = toggleable;
}
-
+ public BasicButton(int width, int height, @NotNull String text, @Nullable String fileNameLeftIco, @Nullable String fileNameRightIco, int colorPalette, int alignment, Runnable runnable) {
+ this(width, height, text, fileNameLeftIco, fileNameRightIco, colorPalette, alignment);
+ this.runnable = runnable;
+ }
@Override
public void draw(long vg, int x, int y) {
@@ -68,20 +76,20 @@ public class BasicButton extends BasicElement {
int textColor = -1;
RenderManager.drawRectangle(vg, x, y, this.width, this.height, this.currentColor);
float contentWidth = RenderManager.getTextWidth(vg, text, fontSize);
- if(fileNameLeftIco != null) {
+ if (fileNameLeftIco != null) {
contentWidth += 28;
}
- if(fileNameRightIco != null) {
+ if (fileNameRightIco != null) {
contentWidth += 28;
}
- if(this.colorPalette == -3) {
+ if (this.colorPalette == -3) {
textColor = OneConfigConfig.WHITE_80;
- if(hovered) textColor = OneConfigConfig.WHITE;
- if(clicked) textColor = OneConfigConfig.WHITE_80;
+ if (hovered) textColor = OneConfigConfig.WHITE;
+ if (clicked) textColor = OneConfigConfig.WHITE_80;
}
- if(thisAlignment == ALIGNMENT_CENTER) {
+ if (thisAlignment == ALIGNMENT_CENTER) {
int middle = x + this.width / 2;
RenderManager.drawString(vg, text, middle - contentWidth / 2 + (fileNameLeftIco != null ? 28 : 0), y + ((float) height / 2) + 1, textColor, fontSize, Fonts.INTER_MEDIUM);
if (fileNameLeftIco != null) {
@@ -91,24 +99,24 @@ public class BasicButton extends BasicElement {
RenderManager.drawImage(vg, fileNameRightIco, middle + contentWidth / 2 - (fileNameLeftIco != null ? 20 : 24), y + 8, 20, 20);
}
}
- if(thisAlignment == ALIGNMENT_LEFT) {
- if(fileNameLeftIco != null) {
+ if (thisAlignment == ALIGNMENT_LEFT) {
+ if (fileNameLeftIco != null) {
RenderManager.drawImage(vg, fileNameLeftIco, x + 12, y + 8, 20, 20);
RenderManager.drawString(vg, text, x + 40, y + ((float) height / 2) + 1, textColor, fontSize, Fonts.INTER_MEDIUM);
} else {
RenderManager.drawString(vg, text, x + 12, y + ((float) height / 2) + 1, textColor, fontSize, Fonts.INTER_MEDIUM);
}
- if(fileNameRightIco != null) {
+ if (fileNameRightIco != null) {
RenderManager.drawImage(vg, fileNameRightIco, x + width - 28, y + 8, 20, 20);
}
}
this.update(x, y);
- if(hoverFx) {
- if(colorPalette == -3) {
+ if (hoverFx) {
+ if (colorPalette == -3) {
currentColor = OneConfigConfig.TRANSPARENT;
return;
}
- if(!toggleable) {
+ if (!toggleable) {
currentColor = ColorUtils.getColor(currentColor, colorPalette, hovered, clicked);
} else {
if (toggled) {
@@ -121,8 +129,10 @@ public class BasicButton extends BasicElement {
@Override
public void onClick() {
- if(this.page != null) {
+ if (this.page != null) {
OneConfigGui.INSTANCE.openPage(page);
+ } else if (this.runnable != null) {
+ runnable.run();
}
}
}