aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cc')
-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.java2
-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.java6
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java19
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java32
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java16
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java73
9 files changed, 258 insertions, 17 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..633e7b9 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)
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..c89ef2b 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,11 @@ public enum OptionType {
DROPDOWN,
//MULTI_DROPDOWN,
/**
- * Type: String
+ * Type: doesn't matter
*/
INFO,
/**
- * Type: class that extends BasicHud
+ * Type: doesn't matter
*/
- HUD
+ HEADER,
}
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 e8ffe42..35115b1 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,9 @@ 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;
}
}
}
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..9daa965
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java
@@ -0,0 +1,32 @@
+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 net.minecraftforge.fml.client.FMLClientHandler;
+import net.minecraftforge.fml.relauncher.FMLLaunchHandler;
+
+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/pages/ModConfigPage.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java
index 790d0e4..bdc7242 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;
@@ -38,7 +39,7 @@ 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("")) {
@@ -141,7 +142,14 @@ public class ModConfigPage extends Page {
optionLastY += option.getHeight() + 16;
}
}
+ }*/
+
+ if (page.categories.size() == 0) return;
+ int optionY = y + (page.categories.size() == 1 ? 16 : 64);
+ for (OptionSubcategory subCategory : page.categories.get(selectedCategory).subcategories) {
+ optionY += subCategory.draw(vg, x + 30, optionY);
}
+ totalSize = optionY - y;
}
@Override
@@ -166,9 +174,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);
}
}
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java
index a741865..141f975 100644
--- a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java
+++ b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java
@@ -195,6 +195,7 @@ public class TestConfig extends Config {
max = 25
)
public static int slider1;
+
@Option(
name = "Stepped Slider",
subcategory = "Sliders",
@@ -207,8 +208,78 @@ public class TestConfig extends Config {
)
public static float slider2;
+ @Option(
+ name = "Slider",
+ type = OptionType.SLIDER,
+ category = "subcategory test",
+ min = 5,
+ max = 3287
+ )
+ public static float slider = 26;
+
+ @Option(
+ name = "Slider",
+ type = OptionType.SLIDER,
+ category = "subcategory test",
+ min = 5,
+ max = 3287
+ )
+ public static float slider10 = 26;
+
+ @Option(
+ name = "Slider",
+ type = OptionType.SLIDER,
+ category = "subcategory test",
+ min = 5,
+ max = 3287,
+ subcategory = "Second subcategory"
+ )
+ public static float slider11 = 26;
- TestHud testHud = new TestHud();
+ @Option(
+ name = "Header Test",
+ type = OptionType.HEADER,
+ category = "subcategory test",
+ subcategory = "Second subcategory",
+ size = 2
+ )
+ public static boolean somethingHere;
+
+
+ @Option(
+ name = "Slider",
+ type = OptionType.SLIDER,
+ category = "subcategory test",
+ min = 5,
+ max = 3287,
+ subcategory = "Second subcategory"
+ )
+ public static float slider12 = 26;
+
+ @ConfigPage(
+ name = "Test page",
+ location = PageLocation.TOP,
+ category = "subcategory test",
+ subcategory = "Second subcategory"
+ )
+ public static TestPage testPage23 = new TestPage();
+
+ @ConfigPage(
+ name = "Test page",
+ location = PageLocation.BOTTOM,
+ category = "subcategory test",
+ subcategory = "Second subcategory"
+ )
+ public static TestPage testPage24 = new TestPage();
+
+ @Option(
+ name = "Slider",
+ type = OptionType.SLIDER,
+ category = "subcategory test",
+ min = 5,
+ max = 3287
+ )
+ public static float slider13 = 26;
public TestConfig() {