aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/config
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/config
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/config')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/annotations/ConfigPage.java5
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/annotations/Option.java7
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/data/OptionCategory.java4
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/data/OptionSubcategory.java118
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java10
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java24
6 files changed, 155 insertions, 13 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/ConfigPage.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/ConfigPage.java
index f9d7c19..432d65c 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/annotations/ConfigPage.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/ConfigPage.java
@@ -29,4 +29,9 @@ public @interface ConfigPage {
* The category of the page
*/
String category() default "General";
+
+ /**
+ * The subcategory of the page
+ */
+ String subcategory() default "";
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Option.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Option.java
index d5e9fc7..efcadc8 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Option.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Option.java
@@ -29,7 +29,7 @@ public @interface Option {
/**
* The subcategory of the component (displayed as header)
*/
- String subcategory();
+ String subcategory() default "";
/**
* The width of the option (1 = half width, 2 = full width)
@@ -82,4 +82,9 @@ public @interface Option {
* Option for info option type
*/
InfoType infoType() default InfoType.INFO;
+
+ /**
+ * Text displayed inside button
+ */
+ String buttonText() default "Activate";
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionCategory.java b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionCategory.java
index 14111f4..363cfda 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionCategory.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionCategory.java
@@ -7,7 +7,5 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
public class OptionCategory {
- public final LinkedHashMap<String, ArrayList<BasicOption>> subcategories = new LinkedHashMap<>();
- public final ArrayList<ConfigPageButton> topPages = new ArrayList<>();
- public final ArrayList<ConfigPageButton> bottomPages = new ArrayList<>();
+ public final ArrayList<OptionSubcategory> subcategories = new ArrayList<>();
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionSubcategory.java b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionSubcategory.java
new file mode 100644
index 0000000..cdd9c51
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionSubcategory.java
@@ -0,0 +1,118 @@
+package cc.polyfrost.oneconfig.config.data;
+
+import cc.polyfrost.oneconfig.config.OneConfigConfig;
+import cc.polyfrost.oneconfig.config.interfaces.BasicOption;
+import cc.polyfrost.oneconfig.gui.OneConfigGui;
+import cc.polyfrost.oneconfig.gui.elements.config.ConfigPageButton;
+import cc.polyfrost.oneconfig.lwjgl.RenderManager;
+import cc.polyfrost.oneconfig.lwjgl.font.Fonts;
+
+import java.util.ArrayList;
+
+public class OptionSubcategory {
+ private final String name;
+ public ArrayList<BasicOption> options = new ArrayList<>();
+ public ArrayList<ConfigPageButton> topButtons = new ArrayList<>();
+ public ArrayList<ConfigPageButton> bottomButtons = new ArrayList<>();
+
+ public OptionSubcategory(String name) {
+ this.name = name;
+ }
+
+ public int draw(long vg, int x, int y) {
+ String filter = OneConfigGui.INSTANCE == null ? "" : OneConfigGui.INSTANCE.getSearchValue().toLowerCase().trim();
+ ArrayList<BasicOption> filteredOptions = new ArrayList<>(options);
+ ArrayList<ConfigPageButton> filteredTop = new ArrayList<>(topButtons);
+ ArrayList<ConfigPageButton> filteredBottom = new ArrayList<>(bottomButtons);
+ if (!filter.equals("") && !name.toLowerCase().contains(filter)) {
+ filteredOptions.clear();
+ filteredTop.clear();
+ filteredBottom.clear();
+ for (BasicOption option : options) {
+ if (option.getName().toLowerCase().contains(filter)) filteredOptions.add(option);
+ }
+ for (ConfigPageButton page : topButtons) {
+ if (page.getName().toLowerCase().contains(filter) || page.description.toLowerCase().contains(filter))
+ filteredTop.add(page);
+ }
+ for (ConfigPageButton page : bottomButtons) {
+ if (page.getName().toLowerCase().contains(filter) || page.description.toLowerCase().contains(filter))
+ filteredBottom.add(page);
+ }
+ }
+ if (filteredOptions.size() == 0 && filteredTop.size() == 0 && filteredBottom.size() == 0) return 0;
+ int optionY = y;
+ if (!name.equals("")) {
+ RenderManager.drawString(vg, name, x, y + 12, OneConfigConfig.WHITE_90, 24, Fonts.MEDIUM);
+ optionY += 36;
+ }
+
+ for (ConfigPageButton page : filteredTop) {
+ page.draw(vg, x, optionY);
+ optionY += page.getHeight() + 16;
+ }
+
+ if (filteredOptions.size() > 0) {
+ int backgroundSize = 16;
+ for (int i = 0; i < filteredOptions.size(); i++) {
+ BasicOption option = filteredOptions.get(i);
+ if (i + 1 < filteredOptions.size()) {
+ BasicOption nextOption = filteredOptions.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 - 16, optionY, 1024, backgroundSize, OneConfigConfig.GRAY_900, 20);
+ optionY += 16;
+ }
+
+ int drawLastY = optionY;
+ if (filteredOptions.size() > 0) {
+ for (int i = 0; i < filteredOptions.size(); i++) {
+ BasicOption option = filteredOptions.get(i);
+ option.draw(vg, x, optionY);
+ if (i + 1 < filteredOptions.size()) {
+ BasicOption nextOption = filteredOptions.get(i + 1);
+ if (option.size == 1 && option.hasHalfSize() && nextOption.size == 1 && nextOption.hasHalfSize()) {
+ nextOption.draw(vg, x + 512, optionY);
+ optionY += Math.max(option.getHeight(), nextOption.getHeight()) + 16;
+ i++;
+ continue;
+ }
+ }
+ optionY += option.getHeight() + 16;
+ }
+ optionY += 16;
+ }
+
+ for (ConfigPageButton page : filteredBottom) {
+ page.draw(vg, x, optionY);
+ optionY += page.getHeight() + 16;
+ }
+
+ for (int i = 0; i < filteredOptions.size(); i++) {
+ BasicOption option = filteredOptions.get(i);
+ option.drawLast(vg, x, drawLastY);
+ if (i + 1 < filteredOptions.size()) {
+ BasicOption nextOption = filteredOptions.get(i + 1);
+ if (option.size == 1 && option.hasHalfSize() && nextOption.size == 1 && nextOption.hasHalfSize()) {
+ nextOption.drawLast(vg, x + 512, drawLastY);
+ drawLastY += Math.max(option.getHeight(), nextOption.getHeight()) + 16;
+ i++;
+ continue;
+ }
+ }
+ drawLastY += option.getHeight() + 16;
+ }
+
+ return optionY - y;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java
index a9b9a6a..6fe5733 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java
@@ -36,11 +36,15 @@ public enum OptionType {
DROPDOWN,
//MULTI_DROPDOWN,
/**
- * Type: String
+ * Type: doesn't matter
*/
INFO,
/**
- * Type: class that extends BasicHud
+ * Type: doesn't matter
+ */
+ HEADER,
+ /**
+ * Type: runnable
*/
- HUD
+ BUTTON
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java
index 756d3c3..9eecc52 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java
@@ -6,6 +6,7 @@ import cc.polyfrost.oneconfig.config.core.ConfigCore;
import cc.polyfrost.oneconfig.config.data.Mod;
import cc.polyfrost.oneconfig.config.data.OptionCategory;
import cc.polyfrost.oneconfig.config.data.OptionPage;
+import cc.polyfrost.oneconfig.config.data.OptionSubcategory;
import cc.polyfrost.oneconfig.config.profiles.Profiles;
import cc.polyfrost.oneconfig.gui.OneConfigGui;
import cc.polyfrost.oneconfig.gui.elements.config.*;
@@ -84,6 +85,10 @@ public class Config {
ConfigPage option = field.getAnnotation(ConfigPage.class);
if (!page.categories.containsKey(option.category()))
page.categories.put(option.category(), new OptionCategory());
+ OptionCategory category = page.categories.get(option.category());
+ if (category.subcategories.size() == 0 || !category.subcategories.get(category.subcategories.size() - 1).getName().equals(option.subcategory()))
+ category.subcategories.add(new OptionSubcategory(option.subcategory()));
+ OptionSubcategory subcategory = category.subcategories.get(category.subcategories.size() - 1);
OptionPage newPage = new OptionPage(option.name(), mod);
try {
field.setAccessible(true);
@@ -91,10 +96,10 @@ public class Config {
generateOptionList(object.getClass(), newPage, mod);
switch (option.location()) {
case TOP:
- page.categories.get(option.category()).topPages.add(new ConfigPageButton(field, option.name(), option.description(), newPage));
+ subcategory.topButtons.add(new ConfigPageButton(field, option.name(), option.description(), newPage));
break;
case BOTTOM:
- page.categories.get(option.category()).bottomPages.add(new ConfigPageButton(field, option.name(), option.description(), newPage));
+ subcategory.bottomButtons.add(new ConfigPageButton(field, option.name(), option.description(), newPage));
break;
}
} catch (IllegalAccessException e) {
@@ -105,9 +110,10 @@ public class Config {
Option option = field.getAnnotation(Option.class);
if (!page.categories.containsKey(option.category()))
page.categories.put(option.category(), new OptionCategory());
- if (!page.categories.get(option.category()).subcategories.containsKey(option.subcategory()))
- page.categories.get(option.category()).subcategories.put(option.subcategory(), new ArrayList<>());
- ArrayList<BasicOption> options = page.categories.get(option.category()).subcategories.get(option.subcategory());
+ OptionCategory category = page.categories.get(option.category());
+ if (category.subcategories.size() == 0 || !category.subcategories.get(category.subcategories.size() - 1).getName().equals(option.subcategory()))
+ category.subcategories.add(new OptionSubcategory(option.subcategory()));
+ ArrayList<BasicOption> options = category.subcategories.get(category.subcategories.size() - 1).options;
switch (option.type()) {
case SWITCH:
options.add(new ConfigSwitch(field, option.name(), option.size()));
@@ -136,6 +142,12 @@ public class Config {
case COLOR:
options.add(new ConfigColorElement(field, option.name(), option.size()));
break;
+ case HEADER:
+ options.add(new ConfigHeader(field, option.name(), option.size()));
+ break;
+ case BUTTON:
+ options.add(new ConfigButton(field, option.name(), option.size(), option.buttonText()));
+ break;
}
}
}
@@ -172,7 +184,7 @@ public class Config {
Object object = adapter.fromJsonTree(value);
field.setAccessible(true);
field.set(this, object);
- } catch (NoSuchFieldException | IllegalAccessException ignored) {
+ } catch (Exception ignored) {
}
}
}