diff options
Diffstat (limited to 'src/main')
6 files changed, 33 insertions, 16 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/Config.java b/src/main/java/cc/polyfrost/oneconfig/config/Config.java index d4b6022..ee1d2bd 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/Config.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/Config.java @@ -95,12 +95,13 @@ public class Config { protected void generateOptionList(Object instance, OptionPage page, Mod mod, boolean migrate) { for (Field field : instance.getClass().getDeclaredFields()) { Option option = ConfigUtils.findAnnotation(field, Option.class); + CustomOption customOption = ConfigUtils.findAnnotation(field, CustomOption.class); String optionName = (page.equals(mod.defaultPage) ? "" : page.name + ".") + field.getName(); if (option != null) { BasicOption configOption = ConfigUtils.addOptionToPage(page, option, field, instance, migrate ? mod.migrator : null); optionNames.put(optionName, configOption); - } else if (field.isAnnotationPresent(CustomOption.class)) { - BasicOption configOption = getCustomOption(field, page, mod, migrate); + } else if (customOption != null) { + BasicOption configOption = getCustomOption(field, customOption, page, mod, migrate); if (configOption == null) continue; optionNames.put(optionName, configOption); } else if (field.isAnnotationPresent(Page.class)) { @@ -122,12 +123,13 @@ public class Config { /** * All fields with the CustomOption annotation are sent to this function * - * @param field Target field - * @param page Page to add options too - * @param mod The data of the mod - * @param migrate If the data should be migrated + * @param field Target field + * @param annotation The annotation the field has + * @param page Page to add options too + * @param mod The data of the mod + * @param migrate If the data should be migrated */ - protected BasicOption getCustomOption(Field field, OptionPage page, Mod mod, boolean migrate) { + protected BasicOption getCustomOption(Field field, CustomOption annotation, OptionPage page, Mod mod, boolean migrate) { return null; } diff --git a/src/main/java/cc/polyfrost/oneconfig/config/annotations/CustomOption.java b/src/main/java/cc/polyfrost/oneconfig/config/annotations/CustomOption.java index 6a1109b..dcfca53 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/annotations/CustomOption.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/annotations/CustomOption.java @@ -11,4 +11,5 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface CustomOption { + String id() default ""; } diff --git a/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java b/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java index 93069c5..aaa7cca 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java @@ -72,6 +72,7 @@ public class ConfigUtils { } public static <T extends Annotation> T findAnnotation(Field field, Class<T> annotationType) { + if (field.isAnnotationPresent(annotationType)) return field.getAnnotation(annotationType); for (Annotation ann : field.getDeclaredAnnotations()) { if (ann.annotationType().isAnnotationPresent(annotationType)) return ann.annotationType().getAnnotation(annotationType); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java index 1f7e621..9ae82e1 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java @@ -69,7 +69,6 @@ public class OneConfigGui extends UScreen { RenderManager.setupAndDraw((vg) -> { if (currentPage == null) { currentPage = new ModsPage(); - currentPage.parents = new ArrayList<>(); currentPage.parents.add(currentPage); } if (OneConfigConfig.australia) { @@ -203,8 +202,8 @@ public class OneConfigGui extends UScreen { if (page == currentPage) return; currentPage.finishUpAndClose(); textInputField.setInput(""); - if (page.parents == null) { - page.parents = new ArrayList<>(currentPage.parents); + if (page.parents.size() == 0) { + page.parents.addAll(currentPage.parents); if (!page.isBase()) { boolean alreadyInParents = false; for (int i = 0; i < page.parents.size(); i++) { @@ -221,6 +220,7 @@ public class OneConfigGui extends UScreen { page.parents.add(page); } } + sideBar.pageOpened(page.parents.get(0).getTitle()); if (addToPrevious) { previousPages.add(0, currentPage); nextPages.clear(); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java index 4652ae0..fd8d3d6 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java @@ -54,11 +54,8 @@ public class SideBar { public void draw(long vg, int x, int y) { for (BasicButton button : buttons) { if (!button.isClicked()) continue; - if (button.equals(buttons.get(selected))) break; - buttons.get(selected).setColorPalette(ColorPalette.TERTIARY); - moveAnimation = new EaseInOutQuart(300, buttons.get(selected).y, button.y, false); - sizeAnimation = new DummyAnimation(36); - selected = buttons.indexOf(button); + moveSideBar(button); + break; } if (moveAnimation != null) { RenderManager.drawRoundedRect(vg, x + 16, moveAnimation.get() - (sizeAnimation.get() - 36) / 2f, 192, sizeAnimation.get(0), Colors.PRIMARY_600, 12); @@ -83,4 +80,20 @@ public class SideBar { HUDButton.draw(vg, x + 16, y + 704); CloseButton.draw(vg, x + 16, y + 748); } + + public void pageOpened(String page) { + for (BasicButton button : buttons) { + if (!button.getText().equalsIgnoreCase(page)) continue; + moveSideBar(button); + return; + } + } + + private void moveSideBar(BasicButton button) { + if (button.equals(buttons.get(selected))) return; + buttons.get(selected).setColorPalette(ColorPalette.TERTIARY); + moveAnimation = new EaseInOutQuart(300, buttons.get(selected).y, button.y, false); + sizeAnimation = new DummyAnimation(36); + selected = buttons.indexOf(button); + } } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java index 5ce6561..9a4b1eb 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java @@ -24,7 +24,7 @@ public abstract class Page { private long scrollTime; private boolean mouseWasDown, dragging; private float yStart; - public ArrayList<Page> parents = null; + public final ArrayList<Page> parents = new ArrayList<>(); public Page(String title) { this.title = title; |