diff options
author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-05-10 17:48:05 +0200 |
---|---|---|
committer | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-05-10 17:48:05 +0200 |
commit | e299255d82e69e461893ce8ff0ec945c253d945f (patch) | |
tree | 24dea1adb3987d997db37bc3c636a65a55040426 /src/main | |
parent | f0aac9cac78fc14e2991741061c67b622c039f37 (diff) | |
download | OneConfig-e299255d82e69e461893ce8ff0ec945c253d945f.tar.gz OneConfig-e299255d82e69e461893ce8ff0ec945c253d945f.tar.bz2 OneConfig-e299255d82e69e461893ce8ff0ec945c253d945f.zip |
button
Diffstat (limited to 'src/main')
7 files changed, 66 insertions, 107 deletions
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 633e7b9..efcadc8 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/annotations/Option.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/Option.java @@ -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/OptionType.java b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java index c89ef2b..6fe5733 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java @@ -43,4 +43,8 @@ public enum OptionType { * Type: doesn't matter */ HEADER, + /** + * Type: runnable + */ + 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 35115b1..c00c62e 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java @@ -145,6 +145,9 @@ public class Config { 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; } } } 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 index 9daa965..3ef3d06 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java @@ -6,8 +6,6 @@ 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; 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 bdc7242..797f573 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java @@ -39,111 +39,6 @@ public class ModConfigPage extends Page { @Override public void draw(long vg, int x, int y) { - /* - 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; - } - 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; - } - } - }*/ - if (page.categories.size() == 0) return; int optionY = y + (page.categories.size() == 1 ? 16 : 64); for (OptionSubcategory subCategory : page.categories.get(selectedCategory).subcategories) { diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java index 141f975..d314354 100644 --- a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java @@ -5,6 +5,7 @@ import cc.polyfrost.oneconfig.config.annotations.Option; import cc.polyfrost.oneconfig.config.data.*; import cc.polyfrost.oneconfig.config.interfaces.Config; import cc.polyfrost.oneconfig.lwjgl.OneColor; +import net.minecraftforge.fml.common.FMLCommonHandler; public class TestConfig extends Config { @@ -18,6 +19,23 @@ public class TestConfig extends Config { public static boolean ignored; @Option( + name = "Crash game", + subcategory = "Test", + type = OptionType.BUTTON, + buttonText = "Crash!" + ) + public static Runnable runnable = () -> FMLCommonHandler.instance().exitJava(69, false); + + @Option( + name = "Crash game", + subcategory = "Test", + type = OptionType.BUTTON, + size = 2, + buttonText = "Crash!" + ) + public static Runnable runnable2 = () -> FMLCommonHandler.instance().exitJava(69, false); + + @Option( name = "Test color selector", subcategory = "Test", type = OptionType.COLOR, |