aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/gui
diff options
context:
space:
mode:
authornextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com>2022-05-10 20:19:07 +0100
committernextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com>2022-05-10 20:19:07 +0100
commitcefe13f6c232ed5ca2d458b896a76df2ee25a8a3 (patch)
treed64f34e2ee55124ce9c3469fea9333d94ccfb23f /src/main/java/cc/polyfrost/oneconfig/gui
parentb5a1aea2239b0beace4d4407d2ab75294c6eab12 (diff)
parent3872c0ae8746e69671ac9b44ff94dc3c7b194817 (diff)
downloadOneConfig-cefe13f6c232ed5ca2d458b896a76df2ee25a8a3.tar.gz
OneConfig-cefe13f6c232ed5ca2d458b896a76df2ee25a8a3.tar.bz2
OneConfig-cefe13f6c232ed5ca2d458b896a76df2ee25a8a3.zip
reduce dependency on minecraft + stuff
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/gui')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java5
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java5
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java29
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java3
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java36
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java30
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java7
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java109
8 files changed, 97 insertions, 127 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java
index a67c1d1..5465652 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java
@@ -3,7 +3,6 @@ package cc.polyfrost.oneconfig.gui;
import cc.polyfrost.oneconfig.hud.HudCore;
import cc.polyfrost.oneconfig.hud.BasicHud;
import cc.polyfrost.oneconfig.lwjgl.RenderManager;
-import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiScreen;
import org.lwjgl.input.Keyboard;
@@ -26,7 +25,7 @@ public class HudGui extends GuiScreen {
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
- Gui.drawRect(0, 0, this.width, this.height, new Color(80, 80, 80, 50).getRGB());
+ RenderManager.drawGlRect(0, 0, this.width, this.height, new Color(80, 80, 80, 50).getRGB());
if (isDragging) {
setPosition(mouseX - xOffset, mouseY - yOffset, true);
@@ -67,7 +66,7 @@ public class HudGui extends GuiScreen {
if (editingHud == hud) {
color = new Color(43, 159, 235).getRGB();
if (isDragging)
- Gui.drawRect(x, y, x + width, y + height, new Color(108, 176, 255, 60).getRGB());
+ RenderManager.drawGlRect(x, y, width, height, new Color(108, 176, 255, 60).getRGB());
}
int finalColor = color;
RenderManager.setupAndDraw(true, (vg) -> {
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
index 45d92b7..ae70758 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
@@ -1,5 +1,6 @@
package cc.polyfrost.oneconfig.gui;
+import cc.polyfrost.oneconfig.OneConfig;
import cc.polyfrost.oneconfig.config.OneConfigConfig;
import cc.polyfrost.oneconfig.gui.elements.BasicElement;
import cc.polyfrost.oneconfig.gui.elements.ColorSelector;
@@ -14,14 +15,12 @@ import cc.polyfrost.oneconfig.lwjgl.font.Fonts;
import cc.polyfrost.oneconfig.lwjgl.image.Images;
import cc.polyfrost.oneconfig.utils.InputUtils;
import cc.polyfrost.oneconfig.utils.MathUtils;
-import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.nanovg.NanoVG;
-import java.awt.*;
import java.util.ArrayList;
public class OneConfigGui extends GuiScreen {
@@ -71,7 +70,7 @@ public class OneConfigGui extends GuiScreen {
currentPage = new HomePage();
parents.add(currentPage);
}
- scale = Minecraft.getMinecraft().displayWidth / 1920f;
+ scale = OneConfig.getDisplayWidth() / 1920f;
NanoVG.nvgScale(vg, scale, scale);
if (OneConfigConfig.ROUNDED_CORNERS) {
RenderManager.drawRoundedRect(vg, x + 224, y, 1056, 800, OneConfigConfig.GRAY_800, OneConfigConfig.CORNER_RADIUS_WIN);
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java
index 1850367..bec14b1 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java
@@ -20,14 +20,16 @@ public class SideBar {
public SideBar() {
btnList.add(new BasicButton(192, 36, "Dashboard", Images.DASHBOARD, null, -3, BasicButton.ALIGNMENT_LEFT, new HomePage()));
btnList.add(new BasicButton(192, 36, "Global Search", Images.SEARCH, null, -3, BasicButton.ALIGNMENT_LEFT));
+ btnList.add(new BasicButton(192, 36, "Screenshots", Images.SCREENSHOT, null, -3, BasicButton.ALIGNMENT_LEFT));
+ btnList.add(new BasicButton(192, 36, "Preferences", Images.PREFERENCES, null, -3, BasicButton.ALIGNMENT_LEFT));
btnList.add(new BasicButton(192, 36, "Mods", Images.MODS, null, -3, BasicButton.ALIGNMENT_LEFT, new ModsPage()));
btnList.add(new BasicButton(192, 36, "Performance", Images.PERFORMANCE, null, -3, BasicButton.ALIGNMENT_LEFT));
btnList.add(new BasicButton(192, 36, "Profiles", Images.PROFILES, null, -3, BasicButton.ALIGNMENT_LEFT));
btnList.add(new BasicButton(192, 36, "Updates", Images.UPDATES, null, -3, BasicButton.ALIGNMENT_LEFT));
- btnList.add(new BasicButton(192, 36, "Theme", Images.THEMES, null, -3, BasicButton.ALIGNMENT_LEFT));
- btnList.add(new BasicButton(192, 36, "Screenshots", Images.SCREENSHOT, null, -3, BasicButton.ALIGNMENT_LEFT));
- btnList.add(new BasicButton(192, 36, "HUD Settings", Images.HUD_SETTINGS, null, -3, BasicButton.ALIGNMENT_LEFT));
- btnList.add(new BasicButton(192, 36, "Preferences", Images.PREFERENCES, null, -3, BasicButton.ALIGNMENT_LEFT));
+ btnList.add(new BasicButton(192, 36, "Themes Library", Images.THEMES, null, -3, BasicButton.ALIGNMENT_LEFT));
+ btnList.add(new BasicButton(192, 36, "Themes Browser", Images.SEARCH, null, -3, BasicButton.ALIGNMENT_LEFT));
+ btnList.add(new BasicButton(192, 36, "Packs Library", Images.MOD_BOX, null, -3, BasicButton.ALIGNMENT_LEFT));
+ btnList.add(new BasicButton(192, 36, "Packs Browser", Images.SEARCH, null, -3, BasicButton.ALIGNMENT_LEFT));
btnList.add(new BasicButton(192, 36, "Close", Images.CLOSE, null, -1, BasicButton.ALIGNMENT_LEFT, () -> RenderManager.displayGuiScreen(null)));
btnList.add(new BasicButton(192, 36, "Minimize", Images.MINIMIZE, null, -1, BasicButton.ALIGNMENT_LEFT, () -> {
OneConfigGui.instanceToRestore = OneConfigGui.INSTANCE;
@@ -37,8 +39,6 @@ public class SideBar {
}
public void draw(long vg, int x, int y) {
- //percentMove = 36f;
-
currentY = MathUtils.easeInOutCirc(50, currentY, targetY - currentY, 120);
RenderManager.drawRoundedRect(vg, x + 16, currentY, 192, 36, OneConfigConfig.BLUE_600, OneConfigConfig.CORNER_RADIUS);
int i = 0;
@@ -48,16 +48,17 @@ public class SideBar {
}
for (BasicButton btn : btnList) {
btn.draw(vg, x + 16, y + 96 + i);
- i += 44;
- if (i == 88) { // +88
- RenderManager.drawString(vg, "MOD CONFIG", x + 16, y + 200, OneConfigConfig.WHITE_90, 12f, Fonts.SEMIBOLD);
- i = 122;
+ if (i >= 562) i += 44;
+ else i += 36;
+ if (i == 144) {
+ RenderManager.drawString(vg, "MOD CONFIG", x + 16, y + 266, OneConfigConfig.WHITE_90, 12f, Fonts.SEMIBOLD);
+ i = 180;
}
- if (i == 298) {
- RenderManager.drawString(vg, "PERSONALIZATION", x + 16, y + 420, OneConfigConfig.WHITE_90, 12f, Fonts.SEMIBOLD);
- i = 342;
+ if (i == 324) {
+ RenderManager.drawString(vg, "PERSONALIZATION", x + 16, y + 446, OneConfigConfig.WHITE_90, 12f, Fonts.SEMIBOLD);
+ i = 360;
}
- if (i == 518) {
+ if (i == 504) {
i = 562;
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java
index 48a6218..8d2ad16 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java
@@ -12,7 +12,6 @@ import cc.polyfrost.oneconfig.lwjgl.image.Images;
import cc.polyfrost.oneconfig.utils.ColorUtils;
import cc.polyfrost.oneconfig.utils.InputUtils;
import net.minecraft.client.Minecraft;
-import net.minecraft.command.CommandException;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.fml.common.ModMetadata;
import org.jetbrains.annotations.NotNull;
@@ -109,7 +108,7 @@ public class ModCard extends BasicElement {
if (possibleCommands.contains(command)) {
try {
ClientCommandHandler.instance.getCommands().get(command).processCommand(Minecraft.getMinecraft().thePlayer, new String[]{});
- } catch (CommandException e) {
+ } catch (Exception e) {
throw new RuntimeException(e);
}
break;
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
new file mode 100644
index 0000000..fdb0157
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java
@@ -0,0 +1,36 @@
+package cc.polyfrost.oneconfig.gui.elements.config;
+
+import cc.polyfrost.oneconfig.config.OneConfigConfig;
+import cc.polyfrost.oneconfig.config.interfaces.BasicOption;
+import cc.polyfrost.oneconfig.gui.elements.BasicButton;
+import cc.polyfrost.oneconfig.lwjgl.RenderManager;
+import cc.polyfrost.oneconfig.lwjgl.font.Fonts;
+
+import java.lang.reflect.Field;
+
+public class ConfigButton extends BasicOption {
+ private final BasicButton button;
+
+ public ConfigButton(Field field, String name, int size, String text) {
+ super(field, name, size);
+ Runnable runnable = () -> {
+ };
+ try {
+ runnable = (Runnable) get();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ this.button = new BasicButton(size == 1 ? 128 : 256, 32, text, null, null, 1, BasicButton.ALIGNMENT_CENTER, runnable);
+ }
+
+ @Override
+ public void draw(long vg, int x, int y) {
+ RenderManager.drawString(vg, name, x, y + 17, OneConfigConfig.WHITE, 14f, Fonts.MEDIUM);
+ button.draw(vg, x + (size == 1 ? 352 : 736), y);
+ }
+
+ @Override
+ public int getHeight() {
+ return 32;
+ }
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java
new file mode 100644
index 0000000..3ef3d06
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java
@@ -0,0 +1,30 @@
+package cc.polyfrost.oneconfig.gui.elements.config;
+
+import cc.polyfrost.oneconfig.config.OneConfigConfig;
+import cc.polyfrost.oneconfig.config.interfaces.BasicOption;
+import cc.polyfrost.oneconfig.lwjgl.RenderManager;
+import cc.polyfrost.oneconfig.lwjgl.font.Fonts;
+import cc.polyfrost.oneconfig.lwjgl.scissor.Scissor;
+import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager;
+
+import java.lang.reflect.Field;
+
+public class ConfigHeader extends BasicOption {
+
+ public ConfigHeader(Field field, String name, int size) {
+ super(field, name, size);
+ }
+
+ @Override
+ public void draw(long vg, int x, int y) {
+ Scissor scissor = ScissorManager.scissor(vg, x, y, size == 1 ? 480 : 992, 32);
+ RenderManager.drawString(vg, name, x, y + 17, OneConfigConfig.WHITE_90, 24, Fonts.MEDIUM);
+ ScissorManager.resetScissor(vg, scissor);
+ }
+
+
+ @Override
+ public int getHeight() {
+ return 32;
+ }
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java
index dbca002..349e7af 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java
@@ -8,7 +8,6 @@ import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager;
import cc.polyfrost.oneconfig.lwjgl.font.Fonts;
import cc.polyfrost.oneconfig.utils.InputUtils;
import net.minecraft.client.gui.GuiScreen;
-import net.minecraft.util.ChatAllowedCharacters;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
@@ -344,7 +343,7 @@ public class TextInputField extends BasicElement {
if (!Character.isDefined(key)) return;
if (!Character.isDefined(c)) return;
if (GuiScreen.isCtrlKeyDown()) return;
- if (ChatAllowedCharacters.isAllowedCharacter(c)) {
+ if (isAllowedCharacter(c)) {
if (selectedText != null) {
if (caretPos > prevCaret) {
input = input.substring(0, prevCaret) + input.substring(prevCaret, caretPos);
@@ -426,4 +425,8 @@ public class TextInputField extends BasicElement {
return RenderManager.getTextWidth(vg, s, 14.0f, Fonts.REGULAR);
}
}
+
+ public static boolean isAllowedCharacter(char character) {
+ return character != 167 && character >= ' ' && character != 127;
+ }
}
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 790d0e4..797f573 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java
@@ -2,6 +2,7 @@ package cc.polyfrost.oneconfig.gui.pages;
import cc.polyfrost.oneconfig.config.OneConfigConfig;
import cc.polyfrost.oneconfig.config.data.OptionPage;
+import cc.polyfrost.oneconfig.config.data.OptionSubcategory;
import cc.polyfrost.oneconfig.config.interfaces.BasicOption;
import cc.polyfrost.oneconfig.gui.OneConfigGui;
import cc.polyfrost.oneconfig.gui.elements.BasicButton;
@@ -39,109 +40,11 @@ public class ModConfigPage extends Page {
@Override
public void draw(long vg, int x, int y) {
if (page.categories.size() == 0) return;
- String filter = OneConfigGui.INSTANCE == null ? "" : OneConfigGui.INSTANCE.getSearchValue().toLowerCase().trim();
- LinkedHashMap<String, ArrayList<BasicOption>> filteredSubcategories = new LinkedHashMap<>(page.categories.get(selectedCategory).subcategories);
- if (!filter.equals("")) {
- filteredSubcategories.clear();
- for (String subCategory : page.categories.get(selectedCategory).subcategories.keySet()) {
- if (subCategory.toLowerCase().contains(filter)) {
- filteredSubcategories.put(subCategory, page.categories.get(selectedCategory).subcategories.get(subCategory));
- continue;
- }
- for (BasicOption option : page.categories.get(selectedCategory).subcategories.get(subCategory)) {
- if (!option.getName().toLowerCase().contains(filter)) continue;
- if (!filteredSubcategories.containsKey(subCategory))
- filteredSubcategories.put(subCategory, new ArrayList<>());
- filteredSubcategories.get(subCategory).add(option);
- }
- }
- }
- int optionX = x + 30;
int optionY = y + (page.categories.size() == 1 ? 16 : 64);
-
- // Top page buttons
- for (ConfigPageButton page : page.categories.get(selectedCategory).topPages) {
- if (!page.getName().toLowerCase().contains(filter) && !page.description.toLowerCase().contains(filter))
- continue;
- page.draw(vg, optionX, optionY);
- optionY += page.getHeight() + 16;
- }
-
- // Background
- if (filteredSubcategories.keySet().size() > 0) {
- int backgroundSize = 16;
- for (String subCategory : filteredSubcategories.keySet()) {
- backgroundSize += 48;
- for (int i = 0; i < filteredSubcategories.get(subCategory).size(); i++) {
- BasicOption option = filteredSubcategories.get(subCategory).get(i);
- if (i + 1 < filteredSubcategories.get(subCategory).size()) {
- BasicOption nextOption = filteredSubcategories.get(subCategory).get(i + 1);
- if (option.size == 1 && option.hasHalfSize() && nextOption.size == 1 && nextOption.hasHalfSize()) {
- backgroundSize += Math.max(option.getHeight(), nextOption.getHeight()) + 16;
- i++;
- continue;
- }
- }
- backgroundSize += option.getHeight() + 16;
- }
- }
- RenderManager.drawRoundedRect(vg, x + 14, optionY, 1024, backgroundSize, OneConfigConfig.GRAY_900, 20);
- }
-
- // draw options
- int optionLastY = optionY + 16;
- if (filteredSubcategories.keySet().size() > 0) {
- optionY += 16;
- for (String subCategory : filteredSubcategories.keySet()) {
- RenderManager.drawString(vg, subCategory, optionX, optionY + 16, OneConfigConfig.WHITE_90, 24f, Fonts.MEDIUM);
- optionY += 48;
- for (int i = 0; i < filteredSubcategories.get(subCategory).size(); i++) {
- BasicOption option = filteredSubcategories.get(subCategory).get(i);
- option.draw(vg, optionX, optionY);
- if (i + 1 < filteredSubcategories.get(subCategory).size()) {
- BasicOption nextOption = filteredSubcategories.get(subCategory).get(i + 1);
- if (option.size == 1 && option.hasHalfSize() && nextOption.size == 1 && nextOption.hasHalfSize()) {
- nextOption.draw(vg, optionX + 512, optionY);
- optionY += Math.max(option.getHeight(), nextOption.getHeight()) + 16;
- i++;
- continue;
- }
- }
- optionY += option.getHeight() + 16;
- }
- }
- optionY += 16;
- }
-
- // Bottom page buttons
- for (ConfigPageButton page : page.categories.get(selectedCategory).bottomPages) {
- if (!page.getName().toLowerCase().contains(filter) && !page.description.toLowerCase().contains(filter))
- continue;
- page.draw(vg, optionX, optionY);
- optionY += page.getHeight() + 16;
+ for (OptionSubcategory subCategory : page.categories.get(selectedCategory).subcategories) {
+ optionY += subCategory.draw(vg, x + 30, optionY);
}
totalSize = optionY - y;
-
- // Draw last options
- if (filteredSubcategories.keySet().size() > 0) {
- for (String subCategory : filteredSubcategories.keySet()) {
- optionLastY += 48;
- for (int i = 0; i < filteredSubcategories.get(subCategory).size(); i++) {
- BasicOption option = filteredSubcategories.get(subCategory).get(i);
- option.drawLast(vg, optionX, optionLastY);
- if (i + 1 < filteredSubcategories.get(subCategory).size()) {
- BasicOption nextOption = filteredSubcategories.get(subCategory).get(i + 1);
- if (option.size == 1 && option.hasHalfSize() && nextOption.size == 1 && nextOption.hasHalfSize()) {
- nextOption.drawLast(vg, optionX + 512, optionLastY);
- optionLastY += Math.max(option.getHeight(), nextOption.getHeight()) + 16;
- i++;
- continue;
- }
- }
- optionLastY += option.getHeight() + 16;
- }
- }
- }
}
@Override
@@ -166,9 +69,9 @@ public class ModConfigPage extends Page {
@Override
public void keyTyped(char key, int keyCode) {
if (page.categories.size() == 0) return;
- for (String subCategory : page.categories.get(selectedCategory).subcategories.keySet()) {
- for (int i = 0; i < page.categories.get(selectedCategory).subcategories.get(subCategory).size(); i++) {
- page.categories.get(selectedCategory).subcategories.get(subCategory).get(i).keyTyped(key, keyCode);
+ for (OptionSubcategory subCategory : page.categories.get(selectedCategory).subcategories) {
+ for (BasicOption option : subCategory.options) {
+ option.keyTyped(key, keyCode);
}
}
}