aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/OneConfig.java28
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java4
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java53
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/SideBar.java14
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/BasicButton.java40
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/BasicElement.java23
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java104
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/SearchField.java14
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/pages/HomePage.java21
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/pages/ModsPage.java52
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/pages/Page.java19
-rw-r--r--src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java27
-rw-r--r--src/main/java/io/polyfrost/oneconfig/lwjgl/image/ImageLoader.java12
-rw-r--r--src/main/java/io/polyfrost/oneconfig/test/TestNanoVGGui.java18
-rw-r--r--src/main/java/io/polyfrost/oneconfig/utils/ColorUtils.java25
-rw-r--r--src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java16
-rw-r--r--src/main/resources/assets/oneconfig/textures/box.pngbin0 -> 1472 bytes
-rw-r--r--src/main/resources/assets/oneconfig/textures/love.pngbin0 -> 323 bytes
-rw-r--r--src/main/resources/assets/oneconfig/textures/love_empty.pngbin0 -> 426 bytes
19 files changed, 409 insertions, 61 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/OneConfig.java b/src/main/java/io/polyfrost/oneconfig/OneConfig.java
index 5d20af3..0f8fed9 100644
--- a/src/main/java/io/polyfrost/oneconfig/OneConfig.java
+++ b/src/main/java/io/polyfrost/oneconfig/OneConfig.java
@@ -2,16 +2,26 @@ package io.polyfrost.oneconfig;
import io.polyfrost.oneconfig.command.OneConfigCommand;
import io.polyfrost.oneconfig.config.OneConfigConfig;
+import io.polyfrost.oneconfig.config.core.ConfigCore;
+import io.polyfrost.oneconfig.config.data.ModData;
+import io.polyfrost.oneconfig.config.data.ModType;
import io.polyfrost.oneconfig.hud.HudCore;
import io.polyfrost.oneconfig.test.TestConfig;
import net.minecraft.client.Minecraft;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.common.MinecraftForge;
+import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.Mod;
+import net.minecraftforge.fml.common.ModContainer;
+import net.minecraftforge.fml.common.ModMetadata;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
+import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import java.io.File;
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.util.List;
@Mod(modid = "@ID@", name = "@NAME@", version = "@VER@")
public class OneConfig {
@@ -21,6 +31,8 @@ public class OneConfig {
public static File themesDir = new File(oneConfigDir, "themes/");
public static OneConfigConfig config;
public static TestConfig testConfig;
+ public static List<ModData> loadedMods = new ArrayList<>();
+ public static List<ModMetadata> loadedOtherMods = new ArrayList<>();
@Mod.EventHandler
public void onPreFMLInit(FMLPreInitializationEvent event) {
@@ -37,4 +49,20 @@ public class OneConfig {
MinecraftForge.EVENT_BUS.register(this);
MinecraftForge.EVENT_BUS.register(new HudCore());
}
+
+ @Mod.EventHandler
+ public void onPostFMLInit(FMLPostInitializationEvent event) {
+ loadedMods.addAll(ConfigCore.settings.keySet());
+ LinkedHashSet<ModData> modData = new LinkedHashSet<>(ConfigCore.settings.keySet());
+ for(ModContainer mod : Loader.instance().getActiveModList()) {
+ ModMetadata metadata = mod.getMetadata();
+ loadedOtherMods.add(metadata);
+ String author = metadata.authorList.size() > 0 ? metadata.authorList.get(0) : "";
+ ModData newMod = new ModData(metadata.name, ModType.OTHER, author, metadata.version);
+ if(newMod.name.equals("OneConfig") || newMod.name.equals("Minecraft Coder Pack") || newMod.name.equals("Forge Mod Loader") || newMod.name.equals("Minecraft Forge")) {
+ continue;
+ }
+ if(modData.add(newMod)) loadedMods.add(newMod); // anti duplicate fix
+ }
+ }
}
diff --git a/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java b/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java
index 04cc24f..3ebc876 100644
--- a/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java
+++ b/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java
@@ -25,7 +25,9 @@ public class OneConfigConfig extends Config {
public static final int GRAY_500 = new Color(49, 51, 56, 255).getRGB(); // Gray 500 // button sidebar hover, button gray normal
public static final int GRAY_500_80 = new Color(49, 51, 56, 204).getRGB(); // Gray 500 80% // button sidebar pressed
- public static final int GRAY_400 = new Color(55, 59, 69, 255).getRGB(); // Gray 400 // button gray hover
+ public static final int GRAY_400 = new Color(55, 59, 69, 255).getRGB(); // Gray 400
+ public static final int GRAY_300 = new Color(73, 79, 92, 255).getRGB(); // Gray 300 // button gray hover
+ public static final int GRAY_200 = new Color(100, 107, 125, 255).getRGB(); // Gray 200
public static final int GRAY_400_80 = new Color(55, 59, 69, 204).getRGB(); // Gray 400 80% // button gray pressed
public static final int BLUE_700 = new Color(18, 71, 178, 255).getRGB(); // Blue 700
public static final int BLUE_600 = new Color(20, 82, 204, 255).getRGB(); // Blue 600 // button blue normal
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java
index 0879bd4..bc30257 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java
@@ -1,15 +1,18 @@
package io.polyfrost.oneconfig.gui;
import io.polyfrost.oneconfig.config.OneConfigConfig;
-import io.polyfrost.oneconfig.gui.elements.BasicButton;
import io.polyfrost.oneconfig.gui.elements.BasicElement;
import io.polyfrost.oneconfig.gui.elements.TextInputField;
+import io.polyfrost.oneconfig.gui.pages.HomePage;
+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.MathUtils;
import net.minecraft.client.gui.GuiScreen;
+import org.jetbrains.annotations.NotNull;
import org.lwjgl.input.Keyboard;
-import org.lwjgl.nanovg.NVGColor;
-import org.lwjgl.nanovg.NanoVG;
+
+import static org.lwjgl.nanovg.NanoVG.*;
public class OneConfigGui extends GuiScreen {
public static OneConfigGui INSTANCE;
@@ -20,8 +23,12 @@ public class OneConfigGui extends GuiScreen {
private final SideBar sideBar = new SideBar();
+ protected Page currentPage;
+ protected Page prevPage;
+ private float pageProgress = -224f;
+
private final TextInputField textInputField = new TextInputField(776, 32, "Search all of OneConfig...", false, false);
- private final BasicButton btn = new BasicButton(184, 36, "Socials", "/assets/oneconfig/textures/share.png", "/assets/oneconfig/textures/share2.png", 1, BasicButton.ALIGNMENT_CENTER);
+
public OneConfigGui() {
INSTANCE = this;
@@ -30,6 +37,8 @@ public class OneConfigGui extends GuiScreen {
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
super.drawScreen(mouseX, mouseY, partialTicks);
RenderManager.setupAndDraw((vg) -> {
+ if(currentPage == null) currentPage = new HomePage();
+ //nvgScale(vg, 0.5f, 0.5f);
if(OneConfigConfig.ROUNDED_CORNERS) {
RenderManager.drawRoundedRect(vg, 544, 140, 1056, 800, OneConfigConfig.GRAY_800, OneConfigConfig.CORNER_RADIUS_WIN);
RenderManager.drawRoundedRect(vg, 320, 140, 244, 800, OneConfigConfig.GRAY_900_80, OneConfigConfig.CORNER_RADIUS_WIN);
@@ -43,17 +52,28 @@ public class OneConfigGui extends GuiScreen {
RenderManager.drawLine(vg, 544, 140, 544, 940, 1, OneConfigConfig.GRAY_700);
RenderManager.drawImage(vg, "/assets/oneconfig/textures/icon.png", x + 19, y + 19, 42, 42);
- RenderManager.drawString(vg, "OneConfig", x + 69, y + 23, OneConfigConfig.WHITE, 18f, Fonts.INTER_BOLD);
- RenderManager.drawString(vg, "By Polyfrost", 389, 183, OneConfigConfig.WHITE, 12f, Fonts.INTER_REGULAR);
+ RenderManager.drawString(vg, "OneConfig", x + 69, y + 32, OneConfigConfig.WHITE, 18f, Fonts.INTER_BOLD); // added half line height to center text
+ RenderManager.drawString(vg, "By Polyfrost", x + 69, y + 51, OneConfigConfig.WHITE, 12f, Fonts.INTER_REGULAR);
//element.setColorPalette(0);
- try {
- sideBar.draw(vg, x, y);
- //element.draw(vg, 0, 0);
- textInputField.draw(vg, 792, 548);
- btn.draw(vg, 976, 870);
- } catch (Exception e) {
- e.printStackTrace();
+ sideBar.draw(vg, x, y);
+ nvgScissor(vg, x + 224, y + 72, 1056, 728);
+ if(prevPage != null) {
+ pageProgress = MathUtils.easeInOutCirc(50, pageProgress, 832 - pageProgress, 220);
+ prevPage.draw(vg, (int) (x - pageProgress), y + 72);
+ RenderManager.drawLine(vg, (int) (x - pageProgress + 1055), y + 72, (int) (x - pageProgress + 1057), y + 800, 2, OneConfigConfig.GRAY_700); // TODO might remove this
+ currentPage.draw(vg, (int) (x - pageProgress + 1056), y + 72);
+ if(pageProgress > 828f) {
+ prevPage = null;
+ pageProgress = -224f;
+ }
+ } else {
+ currentPage.draw(vg, (int) (x - pageProgress), y + 72);
}
+ nvgResetScissor(vg);
+ RenderManager.drawString(vg, currentPage.getTitle(), x + 336, y + 36, OneConfigConfig.WHITE_90, 32f, Fonts.INTER_SEMIBOLD);
+
+ //textInputField.draw(vg, 792, 548);
+ //btn.draw(vg, 976, 870);
//RenderManager.drawGradientRoundedRect(vg, 100, 100, 500, 100, OneConfigConfig.BLUE_600, OneConfigConfig.BLUE_500, OneConfigConfig.CORNER_RADIUS_WIN);
@@ -70,6 +90,13 @@ public class OneConfigGui extends GuiScreen {
}
}
+ public void openPage(@NotNull Page page) {
+ if(prevPage == null) {
+ prevPage = currentPage;
+ }
+ currentPage = page;
+ }
+
@Override
public boolean doesGuiPauseGame() {
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/SideBar.java b/src/main/java/io/polyfrost/oneconfig/gui/SideBar.java
index 0b8659f..7f84049 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/SideBar.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/SideBar.java
@@ -2,6 +2,8 @@ package io.polyfrost.oneconfig.gui;
import io.polyfrost.oneconfig.config.OneConfigConfig;
import io.polyfrost.oneconfig.gui.elements.BasicButton;
+import io.polyfrost.oneconfig.gui.pages.HomePage;
+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;
@@ -15,17 +17,17 @@ public class SideBar {
private float targetY = 0, currentY = 0;
public SideBar() {
- btnList.add(new BasicButton(192, 36, "Dashboard", "/assets/oneconfig/textures/share.png", null, -3, BasicButton.ALIGNMENT_LEFT));
+ btnList.add(new BasicButton(192, 36, "Dashboard", "/assets/oneconfig/textures/share.png", null, -3, BasicButton.ALIGNMENT_LEFT, new HomePage()));
btnList.add(new BasicButton(192, 36, "Global Search", "/assets/oneconfig/textures/share.png", null, -3, BasicButton.ALIGNMENT_LEFT));
- btnList.add(new BasicButton(192, 36, "Mods", "/assets/oneconfig/textures/share.png", null, -3, BasicButton.ALIGNMENT_LEFT));
+ btnList.add(new BasicButton(192, 36, "Mods", "/assets/oneconfig/textures/share.png", null, -3, BasicButton.ALIGNMENT_LEFT, new ModsPage()));
btnList.add(new BasicButton(192, 36, "Performance", "/assets/oneconfig/textures/share.png", null, -3, BasicButton.ALIGNMENT_LEFT));
btnList.add(new BasicButton(192, 36, "Profiles", "/assets/oneconfig/textures/share.png", null, -3, BasicButton.ALIGNMENT_LEFT));
btnList.add(new BasicButton(192, 36, "Updates", "/assets/oneconfig/textures/share.png", null, -3, BasicButton.ALIGNMENT_LEFT));
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, -3, BasicButton.ALIGNMENT_LEFT));
- btnList.add(new BasicButton(192, 36, "Minimize", "/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, "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));
}
@@ -36,7 +38,7 @@ public class SideBar {
RenderManager.drawRoundedRect(vg, x + 16, currentY, 192, 36, OneConfigConfig.BLUE_600, OneConfigConfig.CORNER_RADIUS);
int i = 0;
if (targetY == 0) {
- targetY = x + 16;
+ targetY = y + 96;
currentY = targetY;
}
for (BasicButton btn : btnList) {
@@ -55,7 +57,7 @@ public class SideBar {
}
if (btn.isClicked()) {
- targetY = btn.y;
+ if(i < 520) targetY = btn.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 39d5e9c..8fc2a63 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) {
@@ -68,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);
}
@@ -79,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);
@@ -93,10 +108,21 @@ public class BasicButton extends BasicElement {
currentColor = OneConfigConfig.TRANSPARENT;
return;
}
- currentColor = ColorUtils.getColor(currentColor, colorPalette, hovered, clicked);
-
+ 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);
+ }
}
}
+ @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..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,7 +2,7 @@ package io.polyfrost.oneconfig.gui.elements;
import io.polyfrost.oneconfig.lwjgl.RenderManager;
import io.polyfrost.oneconfig.utils.ColorUtils;
-import net.minecraft.client.Minecraft;
+import io.polyfrost.oneconfig.utils.InputUtils;
import org.lwjgl.input.Mouse;
public class BasicElement {
@@ -40,19 +40,22 @@ 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 = mouseX > x - hitBoxX && mouseY > y - hitBoxY && mouseX < buttonRight + hitBoxX && mouseY < buttonBottom + hitBoxY;
- if (Mouse.isButtonDown(0) && clicked) {
- toggled = !toggled;
+ hovered = InputUtils.isAreaHovered(x - hitBoxX, y - hitBoxY, width + hitBoxX, height + hitBoxY);
+
+ 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..38304e4
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/ModCard.java
@@ -0,0 +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 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 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) {
+ 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, 48, 48);
+ }
+ //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) {
+ 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;
+ }
+}
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
+ }
+}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/pages/HomePage.java b/src/main/java/io/polyfrost/oneconfig/gui/pages/HomePage.java
new file mode 100644
index 0000000..d38f565
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/gui/pages/HomePage.java
@@ -0,0 +1,21 @@
+package io.polyfrost.oneconfig.gui.pages;
+
+import io.polyfrost.oneconfig.config.OneConfigConfig;
+import io.polyfrost.oneconfig.gui.elements.BasicButton;
+import io.polyfrost.oneconfig.lwjgl.RenderManager;
+import io.polyfrost.oneconfig.lwjgl.font.Fonts;
+
+public class HomePage extends Page {
+ private final BasicButton btn = new BasicButton(184, 36, "Socials", "/assets/oneconfig/textures/share.png", "/assets/oneconfig/textures/share2.png", 1, BasicButton.ALIGNMENT_CENTER);
+ public HomePage() {
+ super("Home Dashboard");
+ }
+
+ public void draw(long vg, int x, int y) {
+ RenderManager.drawRoundedRect(vg, x, y, 184, 36, -1, 12f);
+ RenderManager.drawString(vg, "This is a cool string to test pages", x + 32, y + 72, -1, 36f, Fonts.INTER_BOLD);
+ RenderManager.drawRoundedRect(vg, x + 350, y + 310, 300, 200, OneConfigConfig.BLUE_600, 14f);
+ //RenderManager.drawRoundedRect(vg);
+ btn.draw(vg, x + 432, y + 658);
+ }
+}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/pages/ModsPage.java b/src/main/java/io/polyfrost/oneconfig/gui/pages/ModsPage.java
new file mode 100644
index 0000000..856b2f3
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/gui/pages/ModsPage.java
@@ -0,0 +1,52 @@
+package io.polyfrost.oneconfig.gui.pages;
+
+import io.polyfrost.oneconfig.OneConfig;
+import io.polyfrost.oneconfig.config.data.ModData;
+import io.polyfrost.oneconfig.gui.elements.BasicButton;
+import io.polyfrost.oneconfig.gui.elements.ModCard;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ModsPage extends Page {
+ private final BasicButton allBtn = new BasicButton(49, 40, "All", null, null, 0, BasicButton.ALIGNMENT_CENTER, true);
+ private final BasicButton newBtn = new BasicButton(64, 40, "New", null, null, 0, BasicButton.ALIGNMENT_CENTER, true);
+ private final BasicButton combatBtn = new BasicButton(104, 40, "Combat", null, null, 0, BasicButton.ALIGNMENT_CENTER, true);
+ private final BasicButton hudBtn = new BasicButton(104, 40, "HUD & QoL", null, null, 0, BasicButton.ALIGNMENT_CENTER, true);
+ private final BasicButton hypixelBtn = new BasicButton(104, 40, "Hypixel", null, null, 0, BasicButton.ALIGNMENT_CENTER, true);
+ private final BasicButton skyblockBtn = new BasicButton(104, 40, "Skyblock", null, null, 0, BasicButton.ALIGNMENT_CENTER, true);
+ private final BasicButton utilBtn = new BasicButton(104, 40, "Utility", null, null, 0, BasicButton.ALIGNMENT_CENTER, true);
+ private final BasicButton customBtn = new BasicButton(104, 40, "Custom", null, null, 0, BasicButton.ALIGNMENT_CENTER, true);
+
+ private final List<ModCard> modCards = new ArrayList<>();
+
+ public ModsPage() {
+ super("Mods");
+ for(ModData modData : OneConfig.loadedMods) {
+ modCards.add(new ModCard(modData, null, true, false, false));
+ }
+ }
+
+ public void draw(long vg, int x, int y) {
+ allBtn.draw(vg, x + 16, y + 16);
+ newBtn.draw(vg, x + 92, y + 16);
+ combatBtn.draw(vg, x + 168, y + 16);
+ hudBtn.draw(vg, x + 284, y + 16);
+ hypixelBtn.draw(vg, x + 400, y + 16);
+ skyblockBtn.draw(vg, x + 516, y + 16);
+ utilBtn.draw(vg, x + 632, y + 16);
+ customBtn.draw(vg, x + 748, y + 16);
+
+ int iX = x + 16;
+ int iY = y + 72;
+ for(ModCard modCard : modCards) {
+ modCard.draw(vg, iX, iY);
+ iX += 260;
+ if(iX > x + 796) {
+ iX = x + 16;
+ iY += 135;
+ }
+ }
+
+ }
+}
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/pages/Page.java b/src/main/java/io/polyfrost/oneconfig/gui/pages/Page.java
index 72fa3a3..492a1f9 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/pages/Page.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/pages/Page.java
@@ -1,4 +1,23 @@
package io.polyfrost.oneconfig.gui.pages;
+import io.polyfrost.oneconfig.lwjgl.RenderManager;
+import io.polyfrost.oneconfig.lwjgl.font.Fonts;
+
+/**
+ * A page is a 1056x728 rectangle of the GUI. It is the main content of the gui, and can be switched back and forwards easily. All the content of OneConfig is in a page.
+ */
public class Page {
+ protected final String title;
+
+ Page(String title) {
+ this.title = title;
+ }
+
+ public void draw(long vg, int x, int y) {
+ RenderManager.drawString(vg, "If you are seeing this, something went quite wrong.", x + 12, y + 12, -1, 24f, Fonts.INTER_BOLD);
+ }
+
+ public String getTitle() {
+ return title;
+ }
}
diff --git a/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java
index fa4b6bc..066218a 100644
--- a/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java
+++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/RenderManager.java
@@ -124,6 +124,15 @@ public final class RenderManager {
nvgColor.free();
}
+ public static void drawRoundedRectVaried(long vg, float x, float y, float width, float height, int color, float radiusTL, float radiusTR, float radiusBR, float radiusBL) {
+ nvgBeginPath(vg);
+ nvgRoundedRectVarying(vg, x, y, width, height, radiusTL, radiusTR, radiusBR, radiusBL);
+ color(vg, color);
+ NVGColor nvgColor = color(vg, color);
+ nvgFill(vg);
+ nvgColor.free();
+ }
+
public static void drawHollowRoundRect(long vg, float x, float y, float width, float height, int color, float radius, float thickness) {
nvgBeginPath(vg);
nvgRoundedRect(vg, x + thickness, y + thickness, width - thickness, height - thickness, radius);
@@ -192,9 +201,9 @@ public final class RenderManager {
NSVGPath path;
int i;
for (shape = image.shapes(); shape != null; shape.next()) {
- //if ((shape.flags() == NSVG_FLAGS_VISIBLE)) {
- // continue;
- //}
+ if ((shape.flags() == NSVG_FLAGS_VISIBLE)) {
+ continue;
+ }
nvgFillColor(vg, color(vg, shape.fill().color()));
nvgStrokeColor(vg, color(vg, shape.stroke().color()));
@@ -204,21 +213,15 @@ public final class RenderManager {
nvgBeginPath(vg);
FloatBuffer points = path.pts();
nvgMoveTo(vg, points.get(0), points.get(1));
- for (i = 0; i < path.npts() - 1; i += 3) {
- float[] p = new float[10];
- for (int j = 0; j < i * 2 + 3; j++) { // THIS WONT WORK WHy why why why
- p[j] = points.get(j);
- System.out.println(j + " " + p[j]);
- }
- nvgBezierTo(vg, p[2], p[3], p[4], p[5], p[6], p[7]);
+ for (i = 1; i < path.npts() - 1; i += 3) {
+ int b = i * 2;
+ nvgBezierTo(vg, points.get(b), points.get(b + 1), points.get(b + 2), points.get(b + 3), points.get(b + 4), points.get(b + 5));
}
if (path.closed() == 1) {
nvgLineTo(vg, points.get(0), points.get(1));
}
nvgStroke(vg);
}
-
-
}
} catch (Exception e) {
//e.printStackTrace();
diff --git a/src/main/java/io/polyfrost/oneconfig/lwjgl/image/ImageLoader.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/image/ImageLoader.java
index 6fbd27f..4a35959 100644
--- a/src/main/java/io/polyfrost/oneconfig/lwjgl/image/ImageLoader.java
+++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/image/ImageLoader.java
@@ -10,6 +10,7 @@ import org.lwjgl.stb.STBImage;
import org.lwjgl.system.MemoryStack;
import java.io.BufferedReader;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
@@ -46,7 +47,16 @@ public class ImageLoader {
public boolean loadSVGImage(String fileName) {
if(!NSVGImageHashMap.containsKey(fileName)) {
try {
- CharSequence s = new BufferedReader(new InputStreamReader(Minecraft.getMinecraft().getResourceManager().getResource(new ResourceLocation("oneconfig", fileName)).getInputStream())).readLine();
+ InputStream inputStream = Minecraft.getMinecraft().getResourceManager().getResource(new ResourceLocation("oneconfig", fileName)).getInputStream();
+ StringBuilder resultStringBuilder = new StringBuilder();
+ try (BufferedReader br
+ = new BufferedReader(new InputStreamReader(inputStream))) {
+ String line;
+ while ((line = br.readLine()) != null) {
+ resultStringBuilder.append(line);
+ }
+ }
+ CharSequence s = resultStringBuilder.toString();
System.out.println(s);
NSVGImage image = NanoSVG.nsvgParse(s, "px", 96f);
NSVGImageHashMap.put(fileName, image);
diff --git a/src/main/java/io/polyfrost/oneconfig/test/TestNanoVGGui.java b/src/main/java/io/polyfrost/oneconfig/test/TestNanoVGGui.java
index 313da70..88ec1ee 100644
--- a/src/main/java/io/polyfrost/oneconfig/test/TestNanoVGGui.java
+++ b/src/main/java/io/polyfrost/oneconfig/test/TestNanoVGGui.java
@@ -14,15 +14,15 @@ public class TestNanoVGGui extends GuiScreen {
drawRect(0, 0, width, height, Color.BLACK.getRGB());
long startTime = System.nanoTime();
RenderManager.setupAndDraw((vg) -> {
- RenderManager.drawRect(vg, 0, 0, 100, 100, Color.BLUE.getRGB());
- RenderManager.drawRoundedRect(vg, 305, 305, 100, 100, Color.YELLOW.getRGB(), 8);
- RenderManager.drawString(vg, "Hello!", 80, 20, Color.WHITE.getRGB(), 50, Fonts.MC_REGULAR);
- RenderManager.drawString(vg, "Hello!", 100, 100, Color.WHITE.getRGB(), 50, Fonts.INTER_BOLD);
- RenderManager.drawImage(vg, "/assets/oneconfig/textures/hudsettings.png", 10, 10, 400, 400);
- RenderManager.drawSVGImage(vg, "textures/pc.svg", 1000, 1000, 500, 500);
- RenderManager.drawLine(vg, 0, 0, 100, 100, 7, Color.PINK.getRGB());
- RenderManager.drawCircle(vg, 200, 200, 50, Color.WHITE.getRGB());
- RenderManager.drawString(vg, (float) (System.nanoTime() - startTime) / 1000000f + "ms", 500, 500, Color.WHITE.getRGB(), 100, Fonts.INTER_BOLD);
+ //RenderManager.drawRect(vg, 0, 0, 100, 100, Color.BLUE.getRGB());
+ //RenderManager.drawRoundedRect(vg, 305, 305, 100, 100, Color.YELLOW.getRGB(), 8);
+ //RenderManager.drawString(vg, "Hello!", 80, 20, Color.WHITE.getRGB(), 50, Fonts.MC_REGULAR);
+ //RenderManager.drawString(vg, "Hello!", 100, 100, Color.WHITE.getRGB(), 50, Fonts.INTER_BOLD);
+ //RenderManager.drawImage(vg, "/assets/oneconfig/textures/hudsettings.png", 10, 10, 400, 400);
+ RenderManager.drawSVGImage(vg, "icons/TestIcon.svg", 10, 10, 100, 100);
+ //RenderManager.drawLine(vg, 0, 0, 100, 100, 7, Color.PINK.getRGB());
+ //RenderManager.drawCircle(vg, 200, 200, 50, Color.WHITE.getRGB());
+ //RenderManager.drawString(vg, (float) (System.nanoTime() - startTime) / 1000000f + "ms", 500, 500, Color.WHITE.getRGB(), 100, Fonts.INTER_BOLD);
});
drawString(fontRendererObj, "Hello!", 0, 0, -1);
} // hi
diff --git a/src/main/java/io/polyfrost/oneconfig/utils/ColorUtils.java b/src/main/java/io/polyfrost/oneconfig/utils/ColorUtils.java
index b8d56bd..dd9a78e 100644
--- a/src/main/java/io/polyfrost/oneconfig/utils/ColorUtils.java
+++ b/src/main/java/io/polyfrost/oneconfig/utils/ColorUtils.java
@@ -1,6 +1,8 @@
package io.polyfrost.oneconfig.utils;
import io.polyfrost.oneconfig.config.OneConfigConfig;
+import org.jetbrains.annotations.Contract;
+import org.jetbrains.annotations.NotNull;
import java.awt.*;
@@ -10,6 +12,8 @@ public class ColorUtils {
float[] color = splitColor(currentColor);
if(click) {
switch (colorPalette) {
+ case -2:
+ return new Color(0.9f,0.9f,0.9f,0.2f).getRGB();
case -1:
return OneConfigConfig.GRAY_500_80;
default:
@@ -21,11 +25,13 @@ public class ColorUtils {
}
switch (colorPalette) {
+ case -2:
+ return getColorComponents(color, splitColor(OneConfigConfig.TRANSPARENT), new float[]{0.9f,0.9f,0.9f,0.3f}, hover, 20f);
case -1:
return getColorComponents(color, splitColor(OneConfigConfig.TRANSPARENT), splitColor(OneConfigConfig.GRAY_500), hover, 10f);
default:
case 0:
- return getColorComponents(color, splitColor(OneConfigConfig.GRAY_500), splitColor(OneConfigConfig.GRAY_400), hover, 130f);
+ return getColorComponents(color, splitColor(OneConfigConfig.GRAY_600), splitColor(OneConfigConfig.GRAY_300), hover, 25f);
case 1:
return getColorComponents(color, splitColor(OneConfigConfig.BLUE_600), splitColor(OneConfigConfig.BLUE_500), hover, 150f);
@@ -33,7 +39,22 @@ public class ColorUtils {
}
- private static float[] splitColor(int color) {
+ /**
+ * Smooths the transition of a color between two colors.
+ * @param currentColor the current color (also the one you want to change)
+ * @param direction false to move towards initColor, true to move towards finalColor
+ * @param speed speed of the transition
+ * @return currentColor but with the new color
+ */
+ public static int smoothColor(int currentColor, int initColor, int finalColor, boolean direction, float speed) {
+ float[] init = splitColor(initColor);
+ float[] finalC = splitColor(finalColor);
+ float[] current = splitColor(currentColor);
+ return getColorComponents(current, init, finalC, direction, speed);
+ }
+
+ @Contract(value = "_ -> new", pure = true)
+ private static float @NotNull [] splitColor(int color) {
return new float[] { (color >> 16 & 255) / 255f, (color >> 8 & 255) / 255f, (color & 255) / 255f, (color >> 24 & 255) /255f };
}
diff --git a/src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java b/src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java
new file mode 100644
index 0000000..d5ad44b
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java
@@ -0,0 +1,16 @@
+package io.polyfrost.oneconfig.utils;
+
+import net.minecraft.client.Minecraft;
+import org.lwjgl.input.Mouse;
+
+public class InputUtils {
+ /**
+ * function to determine weather the mouse is currently over a specific region. Uses the current nvgScale to fix to any scale.
+ * @return true if mouse is over region, false if not.
+ */
+ public static boolean isAreaHovered(int x, int y, int width, int height) {
+ int mouseX = Mouse.getX();
+ int mouseY = Minecraft.getMinecraft().displayHeight - Math.abs(Mouse.getY());
+ return mouseX > x && mouseY > y && mouseX < x + width && mouseY < y + height; // TODO add scaling info
+ }
+}
diff --git a/src/main/resources/assets/oneconfig/textures/box.png b/src/main/resources/assets/oneconfig/textures/box.png
new file mode 100644
index 0000000..8a7630b
--- /dev/null
+++ b/src/main/resources/assets/oneconfig/textures/box.png
Binary files differ
diff --git a/src/main/resources/assets/oneconfig/textures/love.png b/src/main/resources/assets/oneconfig/textures/love.png
new file mode 100644
index 0000000..39acd3a
--- /dev/null
+++ b/src/main/resources/assets/oneconfig/textures/love.png
Binary files differ
diff --git a/src/main/resources/assets/oneconfig/textures/love_empty.png b/src/main/resources/assets/oneconfig/textures/love_empty.png
new file mode 100644
index 0000000..f91d77c
--- /dev/null
+++ b/src/main/resources/assets/oneconfig/textures/love_empty.png
Binary files differ