diff options
author | nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> | 2022-05-25 18:45:34 +0100 |
---|---|---|
committer | nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> | 2022-05-25 18:45:34 +0100 |
commit | a183b82c9ee063a6377554ea8c797953b1ded994 (patch) | |
tree | cf0ebdccf1771adf99fe08714301cc19212a13c5 /src/main/java | |
parent | a651c8b71d2b30b0da3182de48a213ca94acae54 (diff) | |
download | OneConfig-a183b82c9ee063a6377554ea8c797953b1ded994.tar.gz OneConfig-a183b82c9ee063a6377554ea8c797953b1ded994.tar.bz2 OneConfig-a183b82c9ee063a6377554ea8c797953b1ded994.zip |
OC-38 almost finish basic button rewrite
Diffstat (limited to 'src/main/java')
12 files changed, 234 insertions, 152 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/command/OneConfigCommand.java b/src/main/java/cc/polyfrost/oneconfig/command/OneConfigCommand.java index fac2112..4ea67d9 100644 --- a/src/main/java/cc/polyfrost/oneconfig/command/OneConfigCommand.java +++ b/src/main/java/cc/polyfrost/oneconfig/command/OneConfigCommand.java @@ -42,6 +42,9 @@ public class OneConfigCommand extends CommandBase { case "lwjgl": new TickDelay(() -> UScreen.displayScreen(new TestNanoVGGui()), 1); break; + case "destroy": + OneConfigGui.instanceToRestore = null; + break; } } } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java index 9399012..df35ee0 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java @@ -35,7 +35,7 @@ public class OneConfigGui extends UScreen { public ColorSelector currentColorSelector; public boolean mouseDown; private float scale = 1f; - private static OneConfigGui instanceToRestore = null; + public static OneConfigGui instanceToRestore = null; private long time = -1L; private long deltaTime = 17L; public boolean allowClose = true; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java index c86dc81..bc18253 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java @@ -13,27 +13,34 @@ import cc.polyfrost.oneconfig.libs.universal.UScreen; import java.util.ArrayList; import java.util.List; +import static cc.polyfrost.oneconfig.gui.elements.BasicButton.*; + public class SideBar { private final List<BasicButton> btnList = new ArrayList<>(); private float targetY = 0, currentY = 0; public SideBar() { - btnList.add(new BasicButton(192, 36, "Dashboard", SVGs.DASHBOARD, null, -3, BasicButton.ALIGNMENT_LEFT, new HomePage())); - btnList.add(new BasicButton(192, 36, "Global Search", SVGs.SEARCH, null, -3, BasicButton.ALIGNMENT_LEFT)); - btnList.add(new BasicButton(192, 36, "Screenshots", SVGs.IMAGE, null, -3, BasicButton.ALIGNMENT_LEFT)); - btnList.add(new BasicButton(192, 36, "Preferences", SVGs.SETTINGS, null, -3, BasicButton.ALIGNMENT_LEFT)); - btnList.add(new BasicButton(192, 36, "Mods", SVGs.MODS, null, -3, BasicButton.ALIGNMENT_LEFT, new ModsPage())); - btnList.add(new BasicButton(192, 36, "Performance", SVGs.PERFORMANCE, null, -3, BasicButton.ALIGNMENT_LEFT)); - btnList.add(new BasicButton(192, 36, "Profiles", SVGs.PROFILES, null, -3, BasicButton.ALIGNMENT_LEFT)); - btnList.add(new BasicButton(192, 36, "Updates", SVGs.UPDATE, null, -3, BasicButton.ALIGNMENT_LEFT)); - btnList.add(new BasicButton(192, 36, "Themes Library", SVGs.THEME, null, -3, BasicButton.ALIGNMENT_LEFT)); - btnList.add(new BasicButton(192, 36, "Themes Browser", SVGs.SEARCH, null, -3, BasicButton.ALIGNMENT_LEFT)); - btnList.add(new BasicButton(192, 36, "Packs Library", SVGs.BOX, null, -3, BasicButton.ALIGNMENT_LEFT)); - btnList.add(new BasicButton(192, 36, "Packs Browser", SVGs.SEARCH, null, -3, BasicButton.ALIGNMENT_LEFT)); - btnList.add(new BasicButton(192, 36, "Close", SVGs.X_CIRCLE, null, -1, BasicButton.ALIGNMENT_LEFT, () -> UScreen.displayScreen(null))); - btnList.add(new BasicButton(192, 36, "Minimize", SVGs.MINIMISE, null, -1, BasicButton.ALIGNMENT_LEFT, () -> UScreen.displayScreen(null))); - btnList.add(new BasicButton(192, 36, "Edit HUD", SVGs.HUD, null, 0, BasicButton.ALIGNMENT_LEFT, () -> UScreen.displayScreen(new HudGui()))); + btnList.add(new BasicButton(192, SIZE_36, "Dashboard", SVGs.DASHBOARD, null, ALIGNMENT_LEFT, -2)); + btnList.get(0).setClickAction(new HomePage()); + btnList.add(new BasicButton(192, SIZE_36, "Global Search", SVGs.SEARCH, null, ALIGNMENT_LEFT, -2)); + btnList.add(new BasicButton(192, SIZE_36, "Screenshots", SVGs.IMAGE, null, ALIGNMENT_LEFT, -2)); + btnList.add(new BasicButton(192, SIZE_36, "Preferences", SVGs.SETTINGS, null, ALIGNMENT_LEFT, -2)); + btnList.add(new BasicButton(192, 36, "Mods", SVGs.MODS, null, ALIGNMENT_LEFT, -2)); + btnList.get(4).setClickAction(new ModsPage()); + btnList.add(new BasicButton(192, SIZE_36, "Performance", SVGs.PERFORMANCE, null, ALIGNMENT_LEFT, -2)); + btnList.add(new BasicButton(192, SIZE_36, "Profiles", SVGs.PROFILES, null, ALIGNMENT_LEFT, -2)); + btnList.add(new BasicButton(192, SIZE_36, "Updates", SVGs.UPDATE, null, ALIGNMENT_LEFT, -2)); + btnList.add(new BasicButton(192, SIZE_36, "Themes Library", SVGs.THEME, null, ALIGNMENT_LEFT, -2)); + btnList.add(new BasicButton(192, SIZE_36, "Themes Browser", SVGs.SEARCH, null, ALIGNMENT_LEFT, -2)); + btnList.add(new BasicButton(192, SIZE_36, "Packs Library", SVGs.BOX, null, ALIGNMENT_LEFT, -2)); + btnList.add(new BasicButton(192, SIZE_36, "Packs Browser", SVGs.SEARCH, null, ALIGNMENT_LEFT, -2)); + btnList.add(new BasicButton(192, SIZE_36, "Close", SVGs.X_CIRCLE, null, ALIGNMENT_LEFT, -1)); + btnList.get(12).setClickAction(() -> UScreen.displayScreen(null)); + btnList.add(new BasicButton(192, SIZE_36, "Minimize", SVGs.MINIMISE, null, ALIGNMENT_LEFT, -1)); + btnList.get(13).setClickAction(() -> UScreen.displayScreen(null)); + btnList.add(new BasicButton(192, SIZE_36, "Edit HUD", SVGs.HUD, null, ALIGNMENT_LEFT, -1)); + btnList.get(14).setClickAction(() -> UScreen.displayScreen(new HudGui())); } public void draw(long vg, int x, int y) { diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java index 24ea612..58638fd 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java @@ -7,130 +7,155 @@ import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; import cc.polyfrost.oneconfig.utils.ColorUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; + +import java.util.zip.ZipEntry; public class BasicButton extends BasicElement { protected String text; - protected SVGs fileNameLeftIco, fileNameRightIco; - private final int thisAlignment; - private final float fontSize; - private final int colorPalette; + protected SVGs icon1, icon2; + private final int alignment, colorPalette; + private final float fontSize, cornerRadius; + private final int xSpacing, xPadding; + private final int iconSize; public int x, y; public static final int ALIGNMENT_LEFT = 0; - public static final int ALIGNMENT_CENTER = 1; - private boolean toggleable; + @Deprecated + public static final int ALIGNMENT_RIGHT = 1; + public static final int ALIGNMENT_CENTER = 2; + public static final int ALIGNMENT_JUSTIFIED = 3; + + public static final int SIZE_32 = 32; + public static final int SIZE_36 = 36; + public static final int SIZE_40 = 40; + public static final int SIZE_48 = 48; + private boolean toggleable = false; private Page page; private Runnable runnable; - private boolean alignIconLeft = false; - - /** - * 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 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 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 SVGs fileNameLeftIco, @Nullable SVGs fileNameRightIco, int colorPalette, int alignment) { - super(width, height, colorPalette, true); - this.text = text; - if (fileNameLeftIco != null) this.fileNameLeftIco = fileNameLeftIco; - if (fileNameRightIco != null) this.fileNameRightIco = fileNameRightIco; - this.thisAlignment = alignment; - if (colorPalette == -2) { - fontSize = 24f; - this.colorPalette = -1; - } else { - if (colorPalette == 0) fontSize = 12; - else fontSize = 14f; - this.colorPalette = colorPalette; - } + + public BasicButton(int width, int size, String text, int align, int colorPalette) { + this(width, size, text, null, null, colorPalette, align); } - public BasicButton(int width, int height, @NotNull String text, @Nullable SVGs fileNameLeftIco, @Nullable SVGs fileNameRightIco, int colorPalette, int alignment, Page page) { - this(width, height, text, fileNameLeftIco, fileNameRightIco, colorPalette, alignment); - this.page = page; + public BasicButton(int width, int size, String text, SVGs icon1, SVGs icon2, int align, int colorPalette) { + super(width, 32, colorPalette, true); + if(text != null) this.text = text; + if (icon1 != null) this.icon1 = icon1; + if (icon2 != null) this.icon2 = icon2; + this.colorPalette = colorPalette; + this.alignment = align; + this.cornerRadius = size == SIZE_48 ? 16f : 12f; + this.xSpacing = size == SIZE_48 ? 12 : 8; + if(size == SIZE_36 || size == SIZE_40) { + this.xPadding = 16; + } else this.xPadding = size == SIZE_48 ? 20 : 12; + this.height = size; + this.iconSize = this.height / 2; + this.fontSize = size == SIZE_48 ? 20 : (float) (size / 2 - 4); } - public BasicButton(int width, int height, @NotNull String text, @Nullable SVGs fileNameLeftIco, @Nullable SVGs fileNameRightIco, int colorPalette, int alignment, boolean toggleable) { - this(width, height, text, fileNameLeftIco, fileNameRightIco, colorPalette, alignment); - this.toggleable = toggleable; + public BasicButton(int width, int size, SVGs icon, int align, int colorPalette) { + this(width, size, null, icon, null, align, colorPalette); } - public BasicButton(int width, int height, @NotNull String text, @Nullable SVGs fileNameLeftIco, @Nullable SVGs fileNameRightIco, int colorPalette, int alignment, Runnable runnable) { - this(width, height, text, fileNameLeftIco, fileNameRightIco, colorPalette, alignment); - this.runnable = runnable; + public void setToggleable(boolean state) { + this.toggleable = state; } - public BasicButton(int width, int height, @NotNull String text, @Nullable SVGs fileNameLeftIco, @Nullable SVGs fileNameRightIco, int colorPalette, int alignment, boolean toggleable, Runnable runnable) { - this(width, height, text, fileNameLeftIco, fileNameRightIco, colorPalette, alignment, runnable); - this.toggleable = toggleable; + public void setClickAction(Page page) { + this.page = page; + } + + public void setClickAction(Runnable runnable) { + this.runnable = runnable; } @Override public void draw(long vg, int x, int y) { this.x = x; this.y = y; + RenderManager.drawRoundedRect(vg, x, y, this.width, this.height, currentColor, this.cornerRadius); + float contentWidth = 0f; int textColor = -1; - RenderManager.drawRectangle(vg, x, y, this.width, this.height, this.currentColor); - float contentWidth = RenderManager.getTextWidth(vg, text, fontSize, Fonts.MEDIUM); - if (fileNameLeftIco != null && !alignIconLeft) { - contentWidth += 28; - } - if (fileNameRightIco != null) { - contentWidth += 28; + final float middle = x + width / 2f; + final float middleYIcon = y + height / 2f - iconSize / 2f; + final float middleYText = y + height / 2f + fontSize / 8f; + if(this.text != null) { + if (this.colorPalette == -2) { + textColor = OneConfigConfig.WHITE_80; + if (hovered) textColor = OneConfigConfig.WHITE; + if (clicked) textColor = OneConfigConfig.WHITE_80; + if (page == null) textColor = OneConfigConfig.WHITE_50; + } + contentWidth += RenderManager.getTextWidth(vg, text, fontSize, Fonts.MEDIUM); } - - if (this.colorPalette == -3) { - textColor = OneConfigConfig.WHITE_80; - if (hovered) textColor = OneConfigConfig.WHITE; - if (clicked) textColor = OneConfigConfig.WHITE_80; - if (page == null) textColor = OneConfigConfig.WHITE_50; + if(alignment == ALIGNMENT_CENTER) { + if (icon1 != null) { + contentWidth += iconSize + xSpacing; + } + if (icon2 != null) { + contentWidth += iconSize + xSpacing; + } + if(text != null) { + RenderManager.drawString(vg, text, middle - contentWidth / 2 + (icon1 == null ? 0 : iconSize + xSpacing), middleYText, textColor, fontSize, Fonts.MEDIUM); + } + if(icon1 != null) { + RenderManager.drawSvg(vg, icon1, middle - contentWidth / 2, middleYIcon, iconSize, iconSize); + } + if(icon2 != null) { + RenderManager.drawSvg(vg, icon2, middle + contentWidth / 2 - iconSize, middleYIcon, iconSize, iconSize); + } + this.update(x, y); + return; } - - if (thisAlignment == ALIGNMENT_CENTER) { - int middle = x + this.width / 2; - if (alignIconLeft) - RenderManager.drawString(vg, text, middle - contentWidth / 2, y + ((float) height / 2) + 1, textColor, fontSize, Fonts.MEDIUM); - else - RenderManager.drawString(vg, text, middle - contentWidth / 2 + (fileNameLeftIco != null ? 28 : 0), y + ((float) height / 2) + 1, textColor, fontSize, Fonts.MEDIUM); - if (fileNameLeftIco != null) { - if (alignIconLeft) RenderManager.drawSvg(vg, fileNameLeftIco, x + 12, y + height / 2f - 10, 20, 20); - else RenderManager.drawSvg(vg, fileNameLeftIco, middle - contentWidth / 2, y + 8, 20, 20); + if(alignment == ALIGNMENT_JUSTIFIED) { + if(text != null) { + RenderManager.drawString(vg, text, middle - contentWidth / 2, middleYText, textColor, fontSize, Fonts.MEDIUM); } - if (fileNameRightIco != null) { - RenderManager.drawSvg(vg, fileNameRightIco, middle + contentWidth / 2 - (fileNameLeftIco != null ? 20 : 24), y + 8, 20, 20); + if(icon1 != null) { + RenderManager.drawSvg(vg, icon1, x + xSpacing, middleYIcon, iconSize, iconSize); } + if(icon2 != null) { + RenderManager.drawSvg(vg, icon2, x + width - xSpacing - iconSize, middleYIcon, iconSize, iconSize); + } + this.update(x, y); + return; } - if (thisAlignment == ALIGNMENT_LEFT) { - if (fileNameLeftIco != null) { - RenderManager.drawSvg(vg, fileNameLeftIco, x + 12, y + 8, 20, 20, textColor); - RenderManager.drawString(vg, text, x + 40, y + ((float) height / 2) + 1, textColor, fontSize, Fonts.MEDIUM); - } else { - RenderManager.drawString(vg, text, x + 12, y + ((float) height / 2) + 1, textColor, fontSize, Fonts.MEDIUM); + if(alignment == ALIGNMENT_LEFT) { + contentWidth = xSpacing; + if(icon1 != null) { + RenderManager.drawSvg(vg, icon1, x + contentWidth, middleYIcon, iconSize, iconSize); + contentWidth += iconSize + xSpacing; + } + if(text != null) { + RenderManager.drawString(vg, text, x + contentWidth, middleYText, textColor, fontSize, Fonts.MEDIUM); + contentWidth += RenderManager.getTextWidth(vg, text, fontSize, Fonts.MEDIUM) + xSpacing; } - if (fileNameRightIco != null) { - RenderManager.drawSvg(vg, fileNameRightIco, x + width - 28, y + 8, 20, 20); + if(icon2 != null) { + RenderManager.drawSvg(vg, icon2, x + contentWidth, middleYIcon, iconSize, iconSize); } + this.update(x, y); + return; } - this.update(x, y); - if (hoverFx) { - if (colorPalette == -3) { - currentColor = OneConfigConfig.TRANSPARENT; - return; + if(alignment == ALIGNMENT_RIGHT) { + contentWidth = width - xSpacing; + if(icon2 != null) { + contentWidth -= iconSize; + RenderManager.drawSvg(vg, icon2, x + contentWidth, middleYIcon, iconSize, iconSize); + contentWidth -= xSpacing; } - if (!toggleable) { - currentColor = ColorUtils.getColor(currentColor, colorPalette, hovered, clicked); - } else { - if (toggled) { - currentColor = ColorUtils.smoothColor(currentColor, OneConfigConfig.GRAY_500, OneConfigConfig.PRIMARY_600, true, 30f); - } else currentColor = ColorUtils.getColor(currentColor, colorPalette, hovered, clicked); + if(text != null) { + contentWidth -= RenderManager.getTextWidth(vg, text, fontSize, Fonts.MEDIUM); + RenderManager.drawString(vg, text, x + contentWidth, middleYText, textColor, fontSize, Fonts.MEDIUM); + contentWidth -= xSpacing; + } + if(icon1 != null) { + contentWidth -= iconSize; + RenderManager.drawSvg(vg, icon1, x + contentWidth, middleYIcon, iconSize, iconSize); } + this.update(x, y); } + } @@ -145,8 +170,22 @@ public class BasicButton extends BasicElement { @Override public void update(int x, int y) { - if (toggleable && toggled) return; super.update(x, y); + if (hoverFx) { + if (colorPalette == -2) { + currentColor = OneConfigConfig.TRANSPARENT; + return; + } + if (!toggleable) { + currentColor = ColorUtils.getColor(currentColor, colorPalette, hovered, clicked); + } else { + if (toggled) { + currentColor = ColorUtils.smoothColor(currentColor, OneConfigConfig.GRAY_500, OneConfigConfig.PRIMARY_600, true, 30f); + } else currentColor = ColorUtils.getColor(currentColor, colorPalette, hovered, clicked); + } + } + + } public Page getPage() { @@ -160,8 +199,4 @@ public class BasicButton extends BasicElement { public void setText(String text) { this.text = text; } - - public void alignIconLeft(boolean value) { - alignIconLeft = value; - } } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java index 2040364..3607d24 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java @@ -9,8 +9,8 @@ import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.Images; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; -import cc.polyfrost.oneconfig.utils.IOUtils; import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.utils.InternetUtils; import cc.polyfrost.oneconfig.utils.MathUtils; import org.lwjgl.input.Mouse; @@ -322,7 +322,7 @@ public class ColorSelector { hueInput.setInput(String.format("%.01f", (float) color.getHue())); hexInput.setInput("#" + color.getHex()); } - if(guideBtn.isClicked()) IOUtils.browseLink("https://www.youtube.com/watch?v=dQw4w9WgXcQ"); + if(guideBtn.isClicked()) InternetUtils.browseLink("https://www.youtube.com/watch?v=dQw4w9WgXcQ"); // draw the color preview diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java index afedef4..3caa51f 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java @@ -13,12 +13,14 @@ public class ConfigButton extends BasicOption { public ConfigButton(Runnable runnable, Object parent, String name, int size, String text) { super(null, parent, name, size); - this.button = new BasicButton(size == 1 ? 128 : 256, 32, text, null, null, 1, BasicButton.ALIGNMENT_CENTER, runnable); + this.button = new BasicButton(size == 1 ? 128 : 256, 32, text, BasicButton.ALIGNMENT_CENTER, 1); + this.button.setClickAction(runnable); } public ConfigButton(Field field, Object parent, String name, int size, String text) { super(field, parent, name, size); - this.button = new BasicButton(size == 1 ? 128 : 256, 32, text, null, null, 1, BasicButton.ALIGNMENT_CENTER, getRunnableFromField(field, parent)); + this.button = new BasicButton(size == 1 ? 128 : 256, 32, text, BasicButton.ALIGNMENT_CENTER, 1); + this.button.setClickAction(getRunnableFromField(field, parent)); } @Override diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java index 4ea65f9..898d6d7 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java @@ -18,8 +18,8 @@ public class ConfigKeyBind extends BasicOption { public ConfigKeyBind(Field field, Object parent, String name, int size) { super(field, parent, name, size); - button = new BasicButton(256, 32, "", SVGs.KEYSTROKE, null, 0, BasicButton.ALIGNMENT_CENTER, true); - button.alignIconLeft(true); + button = new BasicButton(256, 32, "", SVGs.KEYSTROKE, null, BasicButton.ALIGNMENT_LEFT, 0); + button.setToggleable(true); } @Override diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java index ca0fe0e..050b055 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java @@ -8,21 +8,35 @@ import cc.polyfrost.oneconfig.config.core.OneColor; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; -import cc.polyfrost.oneconfig.utils.IOUtils; import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.utils.InternetUtils; import java.awt.*; public class HomePage extends Page { - private final BasicButton socialsBtn = new BasicButton(184, 36, "Socials", SVGs.SHARE, SVGs.POP_OUT, 1, BasicButton.ALIGNMENT_CENTER, () -> IOUtils.browseLink("https://twitter.com/polyfrost")); - private final BasicButton discordBtn = new BasicButton(184, 36, "Discord", SVGs.WEBSITE, SVGs.LINK_DIAGONAL, 1, BasicButton.ALIGNMENT_CENTER, () -> IOUtils.browseLink("https://discord.gg/4BdUuGpMdf")); - private final BasicButton webBtn = new BasicButton(184, 36, "Website", SVGs.WEBSITE, null, 1, BasicButton.ALIGNMENT_CENTER, () -> IOUtils.browseLink("https://polyfrost.cc")); - private final BasicButton creditsBtn = new BasicButton(184, 36, "Credits", SVGs.AUDIO_PLAY, SVGs.LINK_DIAGONAL, 0, BasicButton.ALIGNMENT_CENTER, () -> OneConfigGui.INSTANCE.openPage(new CreditsPage())); - private final BasicButton guideBtn = new BasicButton(184, 36, "Online Guide", SVGs.HELP_CIRCLE, null, 0, BasicButton.ALIGNMENT_CENTER, () -> IOUtils.browseLink("https://www.youtube.com/watch?v=dQw4w9WgXcQ")); + private final BasicButton socialsBtn = new BasicButton(184, 36, "Socials", SVGs.SHARE, SVGs.POP_OUT, BasicButton.ALIGNMENT_CENTER, 1); + private final BasicButton discordBtn = new BasicButton(184, 36, "Discord", SVGs.WEBSITE, SVGs.LINK_DIAGONAL, BasicButton.ALIGNMENT_CENTER, 1); + private final BasicButton webBtn = new BasicButton(184, 36, "Website", SVGs.WEBSITE, null, BasicButton.ALIGNMENT_CENTER, 1); + private final BasicButton creditsBtn = new BasicButton(184, 36, "Credits", SVGs.AUDIO_PLAY, SVGs.LINK_DIAGONAL, BasicButton.ALIGNMENT_CENTER, 0); + private final BasicButton guideBtn = new BasicButton(184, 36, "Online Guide", SVGs.HELP_CIRCLE, null, BasicButton.ALIGNMENT_CENTER, 0); + private final BasicButton button1 = new BasicButton(184, BasicButton.SIZE_32, "HELLO", SVGs.MICROSOFT_ICON, SVGs.AUDIO_PLAY, BasicButton.ALIGNMENT_CENTER, 1); + private final BasicButton button2 = new BasicButton(184, BasicButton.SIZE_36, "TESTING", SVGs.MICROSOFT_ICON, null, BasicButton.ALIGNMENT_LEFT, 1); + private final BasicButton button3 = new BasicButton(184, BasicButton.SIZE_40, "BOBFISH", SVGs.MICROSOFT_ICON, null, BasicButton.ALIGNMENT_CENTER, -2); + private final BasicButton button4 = new BasicButton(184, BasicButton.SIZE_48, "THIS is cool", null, SVGs.AUDIO_PLAY, BasicButton.ALIGNMENT_CENTER, 1); + private final BasicButton button5 = new BasicButton(184, BasicButton.SIZE_36, "dhwuai", SVGs.MICROSOFT_ICON, SVGs.AUDIO_PLAY, BasicButton.ALIGNMENT_JUSTIFIED, 1); + private final BasicButton button6 = new BasicButton(184, BasicButton.SIZE_32, "yes", SVGs.MICROSOFT_ICON, SVGs.AUDIO_PLAY, BasicButton.ALIGNMENT_RIGHT, 1); + private final BasicButton button7 = new BasicButton(184, BasicButton.SIZE_32, "HELLO", SVGs.MICROSOFT_ICON, SVGs.AUDIO_PLAY, BasicButton.ALIGNMENT_CENTER, 1); + private final BasicButton button8 = new BasicButton(184, BasicButton.SIZE_40, "HELLO", SVGs.MICROSOFT_ICON, SVGs.AUDIO_PLAY, BasicButton.ALIGNMENT_CENTER, 1); public HomePage() { super("Home Dashboard"); + socialsBtn.setClickAction(() -> InternetUtils.browseLink("https://twitter.com/polyfrost")); + discordBtn.setClickAction(() -> InternetUtils.browseLink("https://discord.gg/4BdUuGpMdf")); + webBtn.setClickAction(() -> InternetUtils.browseLink("https://polyfrost.cc")); + creditsBtn.setClickAction(new CreditsPage()); + guideBtn.setClickAction(() -> InternetUtils.browseLink("https://www.youtube.com/watch?v=dQw4w9WgXcQ")); + } public void draw(long vg, int x, int y) { @@ -41,6 +55,15 @@ public class HomePage extends Page { if(socialsBtn.isClicked()) { OneConfigGui.INSTANCE.initColorSelector(new ColorSelector(new OneColor(new Color(255, 0, 255, 127)), InputUtils.mouseX(), InputUtils.mouseY())); } + + button1.draw(vg, x + 100, y + 100); + button2.draw(vg, x + 100, y + 150); + button3.draw(vg, x + 100, y + 250); + button4.draw(vg, x + 100, y + 400); + button5.draw(vg, x + 100, y + 600); + button6.draw(vg, x + 350, y + 100); + button7.draw(vg, x + 350, y + 300); + button8.draw(vg, x + 350, y + 450); } @Override diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java index 74eea3a..d024fb4 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java @@ -9,6 +9,8 @@ import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import java.util.ArrayList; +import static cc.polyfrost.oneconfig.gui.elements.BasicButton.SIZE_32; + public class ModConfigPage extends Page { private final OptionPage page; private final ArrayList<BasicButton> categories = new ArrayList<>(); @@ -25,7 +27,9 @@ public class ModConfigPage extends Page { } if (page.categories.size() < 2) return; for (String category : page.categories.keySet()) { - BasicButton button = new BasicButton(0, 32, category, null, null, 0, BasicButton.ALIGNMENT_CENTER, true, () -> switchCategory(category)); + BasicButton button = new BasicButton(0, SIZE_32, category, BasicButton.ALIGNMENT_CENTER, 0); + button.setClickAction(() -> switchCategory(category)); + button.setToggleable(true); if (category.equals(selectedCategory)) button.setToggled(true); categories.add(button); } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java index 4cd1a32..1065731 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java @@ -24,14 +24,21 @@ public class ModsPage extends Page { for (Mod modData : OneConfig.loadedMods) { modCards.add(OneConfigConfig.favoriteMods.contains(modData.name) ? 0 : modCards.size(), new ModCard(modData, modData.config == null || modData.config.enabled, false, OneConfigConfig.favoriteMods.contains(modData.name))); } - modCategories.add(new BasicButton(64, 32, "All", null, null, 0, BasicButton.ALIGNMENT_CENTER, true, () -> unselect(0))); - modCategories.add(new BasicButton(80, 32, "Combat", null, null, 0, BasicButton.ALIGNMENT_CENTER, true, () -> unselect(1))); - modCategories.add(new BasicButton(64, 32, "HUD", null, null, 0, BasicButton.ALIGNMENT_CENTER, true, () -> unselect(2))); - modCategories.add(new BasicButton(104, 32, "Utility & QoL", null, null, 0, BasicButton.ALIGNMENT_CENTER, true, () -> unselect(3))); - modCategories.add(new BasicButton(80, 32, "Hypixel", null, null, 0, BasicButton.ALIGNMENT_CENTER, true, () -> unselect(4))); - modCategories.add(new BasicButton(80, 32, "Skyblock", null, null, 0, BasicButton.ALIGNMENT_CENTER, true, () -> unselect(5))); - modCategories.add(new BasicButton(88, 32, "3rd Party", null, null, 0, BasicButton.ALIGNMENT_CENTER, true, () -> unselect(6))); + modCategories.add(new BasicButton(64, 32, "All", BasicButton.ALIGNMENT_CENTER, 0)); + modCategories.add(new BasicButton(80, 32, "Combat", BasicButton.ALIGNMENT_CENTER, 0)); + modCategories.add(new BasicButton(64, 32, "HUD", BasicButton.ALIGNMENT_CENTER, 0)); + modCategories.add(new BasicButton(104, 32, "Utility & QoL", BasicButton.ALIGNMENT_CENTER, 0)); + modCategories.add(new BasicButton(80, 32, "Hypixel", BasicButton.ALIGNMENT_CENTER, 0)); + modCategories.add(new BasicButton(80, 32, "Skyblock", BasicButton.ALIGNMENT_CENTER, 0)); + modCategories.add(new BasicButton(88, 32, "3rd Party", BasicButton.ALIGNMENT_CENTER, 0)); modCategories.get(0).setToggled(true); + int i = 0; + for(BasicButton button : modCategories) { + button.setToggleable(true); + int finalI = i; + button.setClickAction(() -> unselect(finalI)); + i++; + } } public void draw(long vg, int x, int y) { diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/IOUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/IOUtils.java index 73a8a13..7263a19 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/IOUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/IOUtils.java @@ -1,11 +1,9 @@ package cc.polyfrost.oneconfig.utils; -import java.awt.*; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.net.URI; import java.net.URL; import java.nio.Buffer; import java.nio.ByteBuffer; @@ -54,23 +52,4 @@ public final class IOUtils { } } - public static void browseLink(String uri) { - try { - browseLink(new URI(uri)); - } catch (Exception e) { - e.printStackTrace(); - System.err.println("Invalid URI: " + uri); - } - } - public static void browseLink(URI uri) { - if(Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { - try { - Desktop.getDesktop().browse(uri); - } catch (IOException e) { - e.printStackTrace(); - System.err.println("Failed to open URL in browser: " + uri); - } - } - } - }
\ No newline at end of file diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/InternetUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/InternetUtils.java index db83825..6d6d7ed 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/InternetUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/InternetUtils.java @@ -3,8 +3,10 @@ package cc.polyfrost.oneconfig.utils; import com.google.gson.JsonElement; import org.apache.commons.io.IOUtils; +import java.awt.*; import java.io.*; import java.net.HttpURLConnection; +import java.net.URI; import java.net.URL; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; @@ -83,4 +85,24 @@ public class InternetUtils { } return stringBuffer.toString(); } + + public static void browseLink(String uri) { + try { + browseLink(new URI(uri)); + } catch (Exception e) { + e.printStackTrace(); + System.err.println("Invalid URI: " + uri); + } + } + + public static void browseLink(URI uri) { + if(Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { + try { + Desktop.getDesktop().browse(uri); + } catch (IOException e) { + e.printStackTrace(); + System.err.println("Failed to open URL in browser: " + uri); + } + } + } } |