From a11a04cc1161a4ed55b85fa9bec877094f1e8e9d Mon Sep 17 00:00:00 2001 From: nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> Date: Sat, 23 Apr 2022 13:51:31 +0100 Subject: mod page, pages, and some more stuff --- .../oneconfig/gui/elements/BasicButton.java | 28 ++++++++++++++-- .../oneconfig/gui/elements/BasicElement.java | 18 +++++++++-- .../polyfrost/oneconfig/gui/elements/ModCard.java | 37 ++++++++++++++++++++++ .../oneconfig/gui/elements/SearchField.java | 14 ++++++++ 4 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java create mode 100644 src/main/java/io/polyfrost/oneconfig/gui/elements/SearchField.java (limited to 'src/main/java/io/polyfrost/oneconfig/gui/elements') 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 39d5e9c..1de952e 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicButton.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicButton.java @@ -1,14 +1,14 @@ package io.polyfrost.oneconfig.gui.elements; import io.polyfrost.oneconfig.config.OneConfigConfig; +import io.polyfrost.oneconfig.gui.OneConfigGui; +import io.polyfrost.oneconfig.gui.pages.Page; import io.polyfrost.oneconfig.lwjgl.RenderManager; import io.polyfrost.oneconfig.lwjgl.font.Fonts; import io.polyfrost.oneconfig.utils.ColorUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import static org.lwjgl.nanovg.NanoVG.nvgTextBounds; - public class BasicButton extends BasicElement { protected String text; @@ -21,6 +21,10 @@ public class BasicButton extends BasicElement { public static final int ALIGNMENT_LEFT = 0; public static final int ALIGNMENT_CENTER = 1; + private boolean toggleable; + + private Page page; + /** * 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. @@ -45,6 +49,17 @@ public class BasicButton extends BasicElement { } } + public BasicButton(int width, int height, @NotNull String text, @Nullable String fileNameLeftIco, @Nullable String fileNameRightIco, int colorPalette, int alignment, Page page) { + this(width, height, text, fileNameLeftIco, fileNameRightIco, colorPalette, alignment); + this.page = page; + } + + public BasicButton(int width, int height, @NotNull String text, @Nullable String fileNameLeftIco, @Nullable String fileNameRightIco, int colorPalette, int alignment, boolean toggleable) { + this(width, height, text, fileNameLeftIco, fileNameRightIco, colorPalette, alignment); + this.toggleable = toggleable; + } + + @Override public void draw(long vg, int x, int y) { @@ -94,9 +109,18 @@ public class BasicButton extends BasicElement { return; } currentColor = ColorUtils.getColor(currentColor, colorPalette, hovered, clicked); + if(toggleable && toggled) { + currentColor = OneConfigConfig.BLUE_600; + } } } + @Override + public void onClick() { + if(this.page != null) { + OneConfigGui.INSTANCE.openPage(page); + } + } } diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicElement.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicElement.java index 765a271..68e25f6 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicElement.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicElement.java @@ -3,8 +3,13 @@ package io.polyfrost.oneconfig.gui.elements; import io.polyfrost.oneconfig.lwjgl.RenderManager; import io.polyfrost.oneconfig.utils.ColorUtils; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.util.ChatComponentText; import org.lwjgl.input.Mouse; +import java.lang.reflect.Method; +import java.util.function.Consumer; + public class BasicElement { protected int width, height; protected int colorPalette; @@ -46,13 +51,20 @@ public class BasicElement { int buttonBottom = y + height; hovered = mouseX > x - hitBoxX && mouseY > y - hitBoxY && mouseX < buttonRight + hitBoxX && mouseY < buttonBottom + hitBoxY; - if (Mouse.isButtonDown(0) && clicked) { - toggled = !toggled; + if (hovered) { + if (Mouse.isButtonDown(0) && !clicked) { + toggled = !toggled; + onClick(); + } + clicked = Mouse.isButtonDown(0); } - clicked = Mouse.isButtonDown(0) && hovered; } + public void onClick() { + + } + public void setCustomHitbox(int x, int y) { hitBoxX = x; hitBoxY = y; diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java new file mode 100644 index 0000000..dd4fe87 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java @@ -0,0 +1,37 @@ +package io.polyfrost.oneconfig.gui.elements; + +import io.polyfrost.oneconfig.config.OneConfigConfig; +import io.polyfrost.oneconfig.lwjgl.RenderManager; +import io.polyfrost.oneconfig.lwjgl.font.Fonts; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class ModCard extends BasicElement { + private final String modName, iconPath; + private boolean active, disabled, favorite; + + public ModCard(@NotNull String modName, @Nullable String iconPath, boolean active, boolean disabled, boolean favorite) { + super(224, 119, true); + this.modName = modName; + this.iconPath = iconPath; + this.active = active; + this.disabled = disabled; + this.favorite = favorite; + } + + @Override + public void draw(long vg, int x, int y) { + RenderManager.drawRoundedRect(vg, x, y, width, 100, OneConfigConfig.GRAY_600, 12f); + RenderManager.drawRoundedRect(vg, x, y + 75, width, 32, OneConfigConfig.BLUE_600, 12f); + RenderManager.drawRect(vg, x, y + 75, width, 12, OneConfigConfig.BLUE_600); + if(iconPath != null) { + RenderManager.drawImage(vg, iconPath, x, y, width, 87); + } else { + RenderManager.drawImage(vg, "assets/oneconfig/textures/box.png", x + 98, y + 19, 40, 40); + } + RenderManager.drawString(vg, modName, x + 12, y + 92, OneConfigConfig.WHITE, 14f, Fonts.INTER_MEDIUM); + if(favorite) { + // TODO + } + } +} diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/SearchField.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/SearchField.java new file mode 100644 index 0000000..93df1b4 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/SearchField.java @@ -0,0 +1,14 @@ +package io.polyfrost.oneconfig.gui.elements; + +public class SearchField extends TextInputField{ + + public SearchField(int width, int height, String defaultText, boolean multiLine, boolean password) { + super(width, height, defaultText, multiLine, password); + } + + @Override + public void draw(long vg, int x, int y) { + super.draw(vg, x, y); + // TODO + } +} -- cgit From 5417c7bd2d43c306863707bb91e7c88a651a696b Mon Sep 17 00:00:00 2001 From: nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> Date: Sun, 24 Apr 2022 13:32:23 +0100 Subject: mod cards, loading of mods, fixes, and some more stuff --- .../oneconfig/gui/elements/BasicButton.java | 16 ++-- .../oneconfig/gui/elements/BasicElement.java | 13 +--- .../polyfrost/oneconfig/gui/elements/ModCard.java | 87 +++++++++++++++++++--- 3 files changed, 88 insertions(+), 28 deletions(-) (limited to 'src/main/java/io/polyfrost/oneconfig/gui/elements') 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 1de952e..8fc2a63 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicButton.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicButton.java @@ -83,7 +83,7 @@ public class BasicButton extends BasicElement { 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), textColor, fontSize, Fonts.INTER_MEDIUM); + RenderManager.drawString(vg, text, middle - contentWidth / 2 + (fileNameLeftIco != null ? 28 : 0), y + ((float) height / 2) + 1, textColor, fontSize, Fonts.INTER_MEDIUM); if (fileNameLeftIco != null) { RenderManager.drawImage(vg, fileNameLeftIco, middle - contentWidth / 2, y + 8, 20, 20); } @@ -94,9 +94,9 @@ public class BasicButton extends BasicElement { 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), textColor, fontSize, Fonts.INTER_MEDIUM); + 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), textColor, fontSize, Fonts.INTER_MEDIUM); + RenderManager.drawString(vg, text, x + 12, y + ((float) height / 2) + 1, textColor, fontSize, Fonts.INTER_MEDIUM); } if(fileNameRightIco != null) { RenderManager.drawImage(vg, fileNameRightIco, x + width - 28, y + 8, 20, 20); @@ -108,11 +108,13 @@ public class BasicButton extends BasicElement { currentColor = OneConfigConfig.TRANSPARENT; return; } - currentColor = ColorUtils.getColor(currentColor, colorPalette, hovered, clicked); - if(toggleable && toggled) { - currentColor = OneConfigConfig.BLUE_600; + if(!toggleable) { + currentColor = ColorUtils.getColor(currentColor, colorPalette, hovered, clicked); + } else { + if (toggled) { + currentColor = ColorUtils.smoothColor(currentColor, OneConfigConfig.GRAY_500, OneConfigConfig.BLUE_600, true, 30f); + } else currentColor = ColorUtils.getColor(currentColor, colorPalette, hovered, clicked); } - } } diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicElement.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicElement.java index 68e25f6..dd72217 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicElement.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicElement.java @@ -2,14 +2,9 @@ package io.polyfrost.oneconfig.gui.elements; import io.polyfrost.oneconfig.lwjgl.RenderManager; import io.polyfrost.oneconfig.utils.ColorUtils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; -import net.minecraft.util.ChatComponentText; +import io.polyfrost.oneconfig.utils.InputUtils; import org.lwjgl.input.Mouse; -import java.lang.reflect.Method; -import java.util.function.Consumer; - public class BasicElement { protected int width, height; protected int colorPalette; @@ -45,12 +40,8 @@ public class BasicElement { } public void update(int x, int y) { - int mouseX = Mouse.getX(); - int mouseY = Minecraft.getMinecraft().displayHeight - Math.abs(Mouse.getY()); - int buttonRight = x + width; - int buttonBottom = y + height; + hovered = InputUtils.isAreaHovered(x - hitBoxX, y - hitBoxY, width + hitBoxX, height + hitBoxY); - hovered = mouseX > x - hitBoxX && mouseY > y - hitBoxY && mouseX < buttonRight + hitBoxX && mouseY < buttonBottom + hitBoxY; if (hovered) { if (Mouse.isButtonDown(0) && !clicked) { toggled = !toggled; diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java index dd4fe87..38304e4 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java @@ -1,37 +1,104 @@ package io.polyfrost.oneconfig.gui.elements; import io.polyfrost.oneconfig.config.OneConfigConfig; +import io.polyfrost.oneconfig.config.data.ModData; import io.polyfrost.oneconfig.lwjgl.RenderManager; import io.polyfrost.oneconfig.lwjgl.font.Fonts; +import io.polyfrost.oneconfig.utils.ColorUtils; +import io.polyfrost.oneconfig.utils.InputUtils; +import net.minecraft.client.Minecraft; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.lwjgl.nanovg.NanoVG; public class ModCard extends BasicElement { - private final String modName, iconPath; + private final String iconPath; + private final ModData modData; + private final BasicElement favoriteHitbox = new BasicElement(32, 32, -2, true); private boolean active, disabled, favorite; + private int colorGray = OneConfigConfig.GRAY_600; + private int colorPrimary = OneConfigConfig.BLUE_600; + private boolean isHoveredMain = false; - public ModCard(@NotNull String modName, @Nullable String iconPath, boolean active, boolean disabled, boolean favorite) { - super(224, 119, true); - this.modName = modName; + public ModCard(@NotNull ModData mod, @Nullable String iconPath, boolean active, boolean disabled, boolean favorite) { + super(244, 119, false); + this.modData = mod; this.iconPath = iconPath; this.active = active; + toggled = active; this.disabled = disabled; this.favorite = favorite; } @Override public void draw(long vg, int x, int y) { - RenderManager.drawRoundedRect(vg, x, y, width, 100, OneConfigConfig.GRAY_600, 12f); - RenderManager.drawRoundedRect(vg, x, y + 75, width, 32, OneConfigConfig.BLUE_600, 12f); - RenderManager.drawRect(vg, x, y + 75, width, 12, OneConfigConfig.BLUE_600); + if(disabled) NanoVG.nvgGlobalAlpha(vg, 0.5f); + RenderManager.drawRoundedRectVaried(vg, x, y, width, 87, colorGray, 12f, 12f, 0f, 0f); + RenderManager.drawRoundedRectVaried(vg, x, y + 87, width, 32, colorPrimary, 0f, 0f, 12f, 12f); + RenderManager.drawLine(vg, x, y + 86, x + width, y + 86, 2,OneConfigConfig.GRAY_300); + //RenderManager.drawRect(vg, x, y + 87, width, 12, colorPrimary); if(iconPath != null) { RenderManager.drawImage(vg, iconPath, x, y, width, 87); } else { - RenderManager.drawImage(vg, "assets/oneconfig/textures/box.png", x + 98, y + 19, 40, 40); + RenderManager.drawImage(vg, "/assets/oneconfig/textures/box.png", x + 98, y + 19, 48, 48); } - RenderManager.drawString(vg, modName, x + 12, y + 92, OneConfigConfig.WHITE, 14f, Fonts.INTER_MEDIUM); + //favoriteHitbox.draw(vg, x + 212, y + 87); + favoriteHitbox.update(x + 212, y + 87); + favoriteHitbox.currentColor = ColorUtils.getColor(favoriteHitbox.currentColor, favoriteHitbox.colorPalette, favoriteHitbox.hovered, favoriteHitbox.clicked); + RenderManager.drawRoundedRectVaried(vg, x + 212, y + 87, 32, 32, favoriteHitbox.currentColor, 0f, 0f, 12f, 0f); + favorite = favoriteHitbox.isToggled(); + RenderManager.drawString(vg, modData.name, x + 12, y + 102, OneConfigConfig.WHITE, 14f, Fonts.INTER_MEDIUM); if(favorite) { - // TODO + RenderManager.drawImage(vg, "/assets/oneconfig/textures/love.png", x + 220, y + 95, 16, 16); + } else { + RenderManager.drawImage(vg, "/assets/oneconfig/textures/love_empty.png", x + 220, y + 95, 16, 16); + } + super.update(x, y); + isHoveredMain = InputUtils.isAreaHovered(x, y, width, 87); + boolean isHoveredSecondary = InputUtils.isAreaHovered(x, y + 87, width - 32, 32) && !disabled; + colorGray = ColorUtils.getColor(colorGray, 0, isHoveredMain, clicked && isHoveredMain); + if(active && !disabled) { + colorPrimary = ColorUtils.getColor(colorPrimary, 1, isHoveredSecondary, clicked && isHoveredSecondary); + } else colorPrimary = ColorUtils.smoothColor(colorPrimary, OneConfigConfig.GRAY_500, OneConfigConfig.GRAY_400, isHoveredSecondary, 20f); + + if(clicked && isHoveredMain) { + if(!active) toggled = false; + } + if(clicked && favoriteHitbox.hovered) toggled = false; + if(clicked && !isHoveredSecondary && active) toggled = true; + if(!active & disabled) toggled = false; + //RenderManager.drawString(vg, "active=" + active, x + 300, y + 12, OneConfigConfig.WHITE, 12f, Fonts.INTER_MEDIUM); // TODO remove debug stuff + //RenderManager.drawString(vg, "disabled=" + disabled, x + 300, y + 24, OneConfigConfig.WHITE, 12f, Fonts.INTER_MEDIUM); + //RenderManager.drawString(vg, "favorite=" + favorite, x + 300, y + 36, OneConfigConfig.WHITE, 12f, Fonts.INTER_MEDIUM); + + + active = toggled; + NanoVG.nvgGlobalAlpha(vg, 1f); + } + + public void onClick() { + if(isHoveredMain) { + Minecraft.getMinecraft().thePlayer.sendChatMessage("you thought you opened the config for " + modData.name + " but actually it doesnt exist"); } } + + public ModData getModData() { + return modData; + } + + public boolean isDisabled() { + return disabled; + } + + public boolean isActive() { + return active; + } + + public void setDisabled(boolean disabled) { + this.disabled = disabled; + } + + public boolean isFavorite() { + return favorite; + } } -- cgit