From 08d0986b2d6beaff2554f1b821dcefc996cb8c11 Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Mon, 4 Jul 2022 14:39:58 +0200 Subject: fix dropdown --- .../compatibility/vigilance/VigilanceConfig.java | 197 --------------------- .../compatibility/vigilance/VigilanceName.java | 16 -- .../compatibility/vigilance/VigilantAccessor.java | 11 -- .../config/migration/VigilanceMigrator.java | 2 +- .../oneconfig/config/profiles/Profiles.java | 2 +- .../gui/elements/config/ConfigDropdown.java | 8 +- .../compatibility/vigilance/VigilanceConfig.java | 197 +++++++++++++++++++++ .../compatibility/vigilance/VigilanceName.java | 16 ++ .../compatibility/vigilance/VigilantAccessor.java | 11 ++ .../internal/plugin/OneConfigMixinPlugin.java | 6 +- 10 files changed, 233 insertions(+), 233 deletions(-) delete mode 100644 src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceName.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilantAccessor.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilanceConfig.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilanceName.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilantAccessor.java (limited to 'src/main/java/cc') diff --git a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig.java b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig.java deleted file mode 100644 index 97dd0cb..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig.java +++ /dev/null @@ -1,197 +0,0 @@ -package cc.polyfrost.oneconfig.config.compatibility.vigilance; - -import cc.polyfrost.oneconfig.config.core.ConfigUtils; -import cc.polyfrost.oneconfig.internal.config.core.ConfigCore; -import cc.polyfrost.oneconfig.config.core.OneColor; -import cc.polyfrost.oneconfig.config.data.Mod; -import cc.polyfrost.oneconfig.config.elements.OptionPage; -import cc.polyfrost.oneconfig.config.elements.BasicOption; -import cc.polyfrost.oneconfig.config.Config; -import cc.polyfrost.oneconfig.gui.elements.config.*; -import cc.polyfrost.oneconfig.platform.Platform; -import gg.essential.vigilance.Vigilant; -import gg.essential.vigilance.data.*; -import kotlin.reflect.KMutableProperty0; -import kotlin.reflect.jvm.ReflectJvmMapping; - -import java.awt.*; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Objects; - -/** - * This class is used to convert the Vigilance config to the new config system. - * It is not meant to be used outside the config system. - */ -public class VigilanceConfig extends Config { - public final Vigilant vigilant; - - public VigilanceConfig(Mod modData, String configFile, Vigilant vigilant) { - super(modData, configFile); - this.vigilant = vigilant; - initialize(); - } - - @Override - public void initialize() { - if (vigilant != null) { - mod.config = this; - generateOptionsList(mod.defaultPage); - ConfigCore.mods.add(mod); - } - } - - @Override - public void save() { - vigilant.markDirty(); - vigilant.writeData(); - } - - @Override - public void load() { - //no-op - } - - private void generateOptionsList(OptionPage page) { - for (PropertyData option : ((VigilantAccessor) vigilant).getPropertyCollector().getProperties()) { - PropertyAttributesExt attributes = option.getAttributesExt(); - if (attributes.getHidden()) continue; - ArrayList options = ConfigUtils.getSubCategory(page, getCategory(attributes), getSubcategory(attributes)).options; - switch (attributes.getType()) { - case SWITCH: - options.add(new ConfigSwitch(getFieldOfProperty(option), option.getInstance(), getName(attributes), getCategory(attributes), getSubcategory(attributes), 2)); - break; - case CHECKBOX: - options.add(new ConfigCheckbox(getFieldOfProperty(option), option.getInstance(), getName(attributes),getCategory(attributes), getSubcategory(attributes), 2)); - break; - case PARAGRAPH: - case TEXT: - options.add(new ConfigTextBox(getFieldOfProperty(option), option.getInstance(), getName(attributes), getCategory(attributes), getSubcategory(attributes), 2, attributes.getPlaceholder(), attributes.getProtected(), attributes.getType() == PropertyType.PARAGRAPH)); - break; - case SELECTOR: - options.add(new ConfigDropdown(getFieldOfProperty(option), option.getInstance(), getName(attributes), getCategory(attributes), getSubcategory(attributes), 2, attributes.getOptions().toArray(new String[0]))); - break; - case PERCENT_SLIDER: - options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), getName(attributes), getCategory(attributes), getSubcategory(attributes), 0, 1, 0)); - break; - case DECIMAL_SLIDER: - options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), getName(attributes), getCategory(attributes), getSubcategory(attributes), attributes.getMinF(), attributes.getMaxF(), 0)); - break; - case NUMBER: - options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), getName(attributes), getCategory(attributes), getSubcategory(attributes), attributes.getMin(), attributes.getMax(), 1)); - break; - case SLIDER: - options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), getName(attributes), getCategory(attributes), getSubcategory(attributes), attributes.getMin(), attributes.getMax(), 0)); - break; - case COLOR: - options.add(new CompatConfigColorElement(getFieldOfProperty(option), option.getInstance(), getCategory(attributes), getSubcategory(attributes), getName(attributes), 2)); - break; - case BUTTON: - options.add(new ConfigButton(() -> ((CallablePropertyValue) option.getValue()).invoke(option.getInstance()), option.getInstance(), getName(attributes), getCategory(attributes), getSubcategory(attributes), 2, attributes.getPlaceholder().isEmpty() ? "Activate" : attributes.getPlaceholder())); - break; - } - if (attributes.getType() == PropertyType.SWITCH || attributes.getType() == PropertyType.CHECKBOX) { - optionNames.put(PropertyKt.fullPropertyPath(option.getAttributesExt()), options.get(options.size() - 1)); - } - } - } - - private Field getFieldOfProperty(PropertyData data) { - if (data.getValue() instanceof FieldBackedPropertyValue) { - FieldBackedPropertyValue fieldBackedPropertyValue = (FieldBackedPropertyValue) data.getValue(); - try { - Field field = fieldBackedPropertyValue.getClass().getDeclaredField("field"); - field.setAccessible(true); - return (Field) field.get(fieldBackedPropertyValue); - } catch (IllegalAccessException | NoSuchFieldException e) { - throw new RuntimeException(e); - } - } else if (data.getValue() instanceof ValueBackedPropertyValue) { - ValueBackedPropertyValue valueBackedPropertyValue = (ValueBackedPropertyValue) data.getValue(); - try { - Field field = valueBackedPropertyValue.getClass().getDeclaredField("obj"); - field.setAccessible(true); - return field; - } catch (NoSuchFieldException e) { - throw new RuntimeException(e); - } - } else if (data.getValue() instanceof KPropertyBackedPropertyValue) { - KPropertyBackedPropertyValue kPropertyBackedPropertyValue = (KPropertyBackedPropertyValue) data.getValue(); - try { - Field field = kPropertyBackedPropertyValue.getClass().getDeclaredField("property"); - field.setAccessible(true); - KMutableProperty0 property = (KMutableProperty0) field.get(kPropertyBackedPropertyValue); - return ReflectJvmMapping.getJavaField(property); - } catch (IllegalAccessException | NoSuchFieldException e) { - throw new RuntimeException(e); - } - } else throw new RuntimeException("Unknown property value type: " + data.getValue().getClass()); - } - - private String getName(PropertyAttributesExt ext) { - try { - PropertyAttributesExt.class.getDeclaredField("i18nName").setAccessible(true); - return Platform.getI18nPlatform().format((String) PropertyAttributesExt.class.getDeclaredField("i18nName").get(ext)); - } catch (IllegalAccessException | NoSuchFieldException e) { - return ext.getName(); - } - } - - private String getCategory(PropertyAttributesExt ext) { - try { - PropertyAttributesExt.class.getDeclaredField("i18nCategory").setAccessible(true); - return Platform.getI18nPlatform().format((String) PropertyAttributesExt.class.getDeclaredField("i18nCategory").get(ext)); - } catch (IllegalAccessException | NoSuchFieldException e) { - return ext.getCategory(); - } - } - - private String getSubcategory(PropertyAttributesExt ext) { - try { - PropertyAttributesExt.class.getDeclaredField("i18nSubcategory").setAccessible(true); - return Platform.getI18nPlatform().format((String) PropertyAttributesExt.class.getDeclaredField("i18nSubcategory").get(ext)); - } catch (IllegalAccessException | NoSuchFieldException e) { - return ext.getSubcategory(); - } - } - - @SuppressWarnings("unused") - public void addDependency(PropertyData property, PropertyData dependency) { - BasicOption option = optionNames.get(PropertyKt.fullPropertyPath(property.getAttributesExt())); - if (option != null) { - option.addDependency(() -> Objects.equals(dependency.getValue().getValue(vigilant), true)); - } - } - - private static class CompatConfigColorElement extends ConfigColorElement { - private final Field color; - private Color prevColor = null; - private OneColor cachedColor = null; - - public CompatConfigColorElement(Field color, Vigilant parent, String name, String category, String subcategory, int size) { - super(null, parent, name, category, subcategory, size, true); - this.color = color; - } - - @Override - public Object get() throws IllegalAccessException { - Color currentColor = (Color) color.get(parent); - if (cachedColor == null || prevColor != color.get(parent)) { - cachedColor = new OneColor(currentColor); - } - prevColor = currentColor; - return cachedColor; - } - - @Override - protected void setColor(OneColor color) { - if (cachedColor != color) { - Color newColor = new Color(color.getRGB(), true); - try { - this.color.set(parent, newColor); - } catch (IllegalAccessException ignored) { - } - } - } - } -} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceName.java b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceName.java deleted file mode 100644 index 8417ad8..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceName.java +++ /dev/null @@ -1,16 +0,0 @@ -package cc.polyfrost.oneconfig.config.compatibility.vigilance; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface VigilanceName { - String name(); - - String category(); - - String subcategory(); -} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilantAccessor.java b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilantAccessor.java deleted file mode 100644 index c449bd9..0000000 --- a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilantAccessor.java +++ /dev/null @@ -1,11 +0,0 @@ -package cc.polyfrost.oneconfig.config.compatibility.vigilance; - -import gg.essential.vigilance.data.PropertyCollector; - -/** - * Interface for accessing the {@link PropertyCollector} in a Vigilant config. - *

Not recommended for non-internal OneConfig usage, as Systemless will get really angry at us

- */ -public interface VigilantAccessor { - PropertyCollector getPropertyCollector(); -} diff --git a/src/main/java/cc/polyfrost/oneconfig/config/migration/VigilanceMigrator.java b/src/main/java/cc/polyfrost/oneconfig/config/migration/VigilanceMigrator.java index f09d648..aed1919 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/migration/VigilanceMigrator.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/migration/VigilanceMigrator.java @@ -1,6 +1,6 @@ package cc.polyfrost.oneconfig.config.migration; -import cc.polyfrost.oneconfig.config.compatibility.vigilance.VigilanceName; +import cc.polyfrost.oneconfig.internal.config.compatibility.vigilance.VigilanceName; import java.io.BufferedReader; import java.io.File; diff --git a/src/main/java/cc/polyfrost/oneconfig/config/profiles/Profiles.java b/src/main/java/cc/polyfrost/oneconfig/config/profiles/Profiles.java index 29a9daa..686fb69 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/profiles/Profiles.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/profiles/Profiles.java @@ -60,7 +60,7 @@ public class Profiles { public static void loadProfile(String profile) { ConfigCore.saveAll(); OneConfigConfig.currentProfile = profile; - //OneConfig.config.save(); todo do we actually need this + OneConfigConfig.getInstance().save(); ConfigCore.reInitAll(); } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java index ddcf6eb..fa48592 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java @@ -1,13 +1,13 @@ package cc.polyfrost.oneconfig.gui.elements.config; import cc.polyfrost.oneconfig.config.annotations.Dropdown; -import cc.polyfrost.oneconfig.internal.assets.Colors; import cc.polyfrost.oneconfig.config.elements.BasicOption; import cc.polyfrost.oneconfig.gui.animations.ColorAnimation; +import cc.polyfrost.oneconfig.internal.assets.Colors; +import cc.polyfrost.oneconfig.internal.assets.SVGs; import cc.polyfrost.oneconfig.platform.Platform; import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.renderer.font.Fonts; -import cc.polyfrost.oneconfig.internal.assets.SVGs; import cc.polyfrost.oneconfig.renderer.scissor.Scissor; import cc.polyfrost.oneconfig.utils.InputUtils; import cc.polyfrost.oneconfig.utils.color.ColorPalette; @@ -43,8 +43,8 @@ public class ConfigDropdown extends BasicOption { else hovered = InputUtils.isAreaHovered(x + 352, y, 640, 32) && isEnabled(); if (hovered && InputUtils.isClicked() || opened && InputUtils.isClicked(true) && - (size == 1 && !InputUtils.isAreaHovered(x + 224, y + 40, 256, options.length * 32) || - size == 2 && !InputUtils.isAreaHovered(x + 352, y + 40, 640, options.length * 32))) { + (size == 1 && !InputUtils.isAreaHovered(x + 224, y + 40, 256, options.length * 32, true) || + size == 2 && !InputUtils.isAreaHovered(x + 352, y + 40, 640, options.length * 32, true))) { opened = !opened; backgroundColor.setPalette(opened ? ColorPalette.PRIMARY : ColorPalette.SECONDARY); if (opened) inputScissor = InputUtils.blockAllInput(); diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilanceConfig.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilanceConfig.java new file mode 100644 index 0000000..689bf25 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilanceConfig.java @@ -0,0 +1,197 @@ +package cc.polyfrost.oneconfig.internal.config.compatibility.vigilance; + +import cc.polyfrost.oneconfig.config.core.ConfigUtils; +import cc.polyfrost.oneconfig.internal.config.core.ConfigCore; +import cc.polyfrost.oneconfig.config.core.OneColor; +import cc.polyfrost.oneconfig.config.data.Mod; +import cc.polyfrost.oneconfig.config.elements.OptionPage; +import cc.polyfrost.oneconfig.config.elements.BasicOption; +import cc.polyfrost.oneconfig.config.Config; +import cc.polyfrost.oneconfig.gui.elements.config.*; +import cc.polyfrost.oneconfig.platform.Platform; +import gg.essential.vigilance.Vigilant; +import gg.essential.vigilance.data.*; +import kotlin.reflect.KMutableProperty0; +import kotlin.reflect.jvm.ReflectJvmMapping; + +import java.awt.*; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Objects; + +/** + * This class is used to convert the Vigilance config to the new config system. + * It is not meant to be used outside the config system. + */ +public class VigilanceConfig extends Config { + public final Vigilant vigilant; + + public VigilanceConfig(Mod modData, String configFile, Vigilant vigilant) { + super(modData, configFile); + this.vigilant = vigilant; + initialize(); + } + + @Override + public void initialize() { + if (vigilant != null) { + mod.config = this; + generateOptionsList(mod.defaultPage); + ConfigCore.mods.add(mod); + } + } + + @Override + public void save() { + vigilant.markDirty(); + vigilant.writeData(); + } + + @Override + public void load() { + //no-op + } + + private void generateOptionsList(OptionPage page) { + for (PropertyData option : ((VigilantAccessor) vigilant).getPropertyCollector().getProperties()) { + PropertyAttributesExt attributes = option.getAttributesExt(); + if (attributes.getHidden()) continue; + ArrayList options = ConfigUtils.getSubCategory(page, getCategory(attributes), getSubcategory(attributes)).options; + switch (attributes.getType()) { + case SWITCH: + options.add(new ConfigSwitch(getFieldOfProperty(option), option.getInstance(), getName(attributes), getCategory(attributes), getSubcategory(attributes), 2)); + break; + case CHECKBOX: + options.add(new ConfigCheckbox(getFieldOfProperty(option), option.getInstance(), getName(attributes),getCategory(attributes), getSubcategory(attributes), 2)); + break; + case PARAGRAPH: + case TEXT: + options.add(new ConfigTextBox(getFieldOfProperty(option), option.getInstance(), getName(attributes), getCategory(attributes), getSubcategory(attributes), 2, attributes.getPlaceholder(), attributes.getProtected(), attributes.getType() == PropertyType.PARAGRAPH)); + break; + case SELECTOR: + options.add(new ConfigDropdown(getFieldOfProperty(option), option.getInstance(), getName(attributes), getCategory(attributes), getSubcategory(attributes), 2, attributes.getOptions().toArray(new String[0]))); + break; + case PERCENT_SLIDER: + options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), getName(attributes), getCategory(attributes), getSubcategory(attributes), 0, 1, 0)); + break; + case DECIMAL_SLIDER: + options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), getName(attributes), getCategory(attributes), getSubcategory(attributes), attributes.getMinF(), attributes.getMaxF(), 0)); + break; + case NUMBER: + options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), getName(attributes), getCategory(attributes), getSubcategory(attributes), attributes.getMin(), attributes.getMax(), 1)); + break; + case SLIDER: + options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), getName(attributes), getCategory(attributes), getSubcategory(attributes), attributes.getMin(), attributes.getMax(), 0)); + break; + case COLOR: + options.add(new CompatConfigColorElement(getFieldOfProperty(option), option.getInstance(), getCategory(attributes), getSubcategory(attributes), getName(attributes), 2)); + break; + case BUTTON: + options.add(new ConfigButton(() -> ((CallablePropertyValue) option.getValue()).invoke(option.getInstance()), option.getInstance(), getName(attributes), getCategory(attributes), getSubcategory(attributes), 2, attributes.getPlaceholder().isEmpty() ? "Activate" : attributes.getPlaceholder())); + break; + } + if (attributes.getType() == PropertyType.SWITCH || attributes.getType() == PropertyType.CHECKBOX) { + optionNames.put(PropertyKt.fullPropertyPath(option.getAttributesExt()), options.get(options.size() - 1)); + } + } + } + + private Field getFieldOfProperty(PropertyData data) { + if (data.getValue() instanceof FieldBackedPropertyValue) { + FieldBackedPropertyValue fieldBackedPropertyValue = (FieldBackedPropertyValue) data.getValue(); + try { + Field field = fieldBackedPropertyValue.getClass().getDeclaredField("field"); + field.setAccessible(true); + return (Field) field.get(fieldBackedPropertyValue); + } catch (IllegalAccessException | NoSuchFieldException e) { + throw new RuntimeException(e); + } + } else if (data.getValue() instanceof ValueBackedPropertyValue) { + ValueBackedPropertyValue valueBackedPropertyValue = (ValueBackedPropertyValue) data.getValue(); + try { + Field field = valueBackedPropertyValue.getClass().getDeclaredField("obj"); + field.setAccessible(true); + return field; + } catch (NoSuchFieldException e) { + throw new RuntimeException(e); + } + } else if (data.getValue() instanceof KPropertyBackedPropertyValue) { + KPropertyBackedPropertyValue kPropertyBackedPropertyValue = (KPropertyBackedPropertyValue) data.getValue(); + try { + Field field = kPropertyBackedPropertyValue.getClass().getDeclaredField("property"); + field.setAccessible(true); + KMutableProperty0 property = (KMutableProperty0) field.get(kPropertyBackedPropertyValue); + return ReflectJvmMapping.getJavaField(property); + } catch (IllegalAccessException | NoSuchFieldException e) { + throw new RuntimeException(e); + } + } else throw new RuntimeException("Unknown property value type: " + data.getValue().getClass()); + } + + private String getName(PropertyAttributesExt ext) { + try { + PropertyAttributesExt.class.getDeclaredField("i18nName").setAccessible(true); + return Platform.getI18nPlatform().format((String) PropertyAttributesExt.class.getDeclaredField("i18nName").get(ext)); + } catch (IllegalAccessException | NoSuchFieldException e) { + return ext.getName(); + } + } + + private String getCategory(PropertyAttributesExt ext) { + try { + PropertyAttributesExt.class.getDeclaredField("i18nCategory").setAccessible(true); + return Platform.getI18nPlatform().format((String) PropertyAttributesExt.class.getDeclaredField("i18nCategory").get(ext)); + } catch (IllegalAccessException | NoSuchFieldException e) { + return ext.getCategory(); + } + } + + private String getSubcategory(PropertyAttributesExt ext) { + try { + PropertyAttributesExt.class.getDeclaredField("i18nSubcategory").setAccessible(true); + return Platform.getI18nPlatform().format((String) PropertyAttributesExt.class.getDeclaredField("i18nSubcategory").get(ext)); + } catch (IllegalAccessException | NoSuchFieldException e) { + return ext.getSubcategory(); + } + } + + @SuppressWarnings("unused") + public void addDependency(PropertyData property, PropertyData dependency) { + BasicOption option = optionNames.get(PropertyKt.fullPropertyPath(property.getAttributesExt())); + if (option != null) { + option.addDependency(() -> Objects.equals(dependency.getValue().getValue(vigilant), true)); + } + } + + private static class CompatConfigColorElement extends ConfigColorElement { + private final Field color; + private Color prevColor = null; + private OneColor cachedColor = null; + + public CompatConfigColorElement(Field color, Vigilant parent, String name, String category, String subcategory, int size) { + super(null, parent, name, category, subcategory, size, true); + this.color = color; + } + + @Override + public Object get() throws IllegalAccessException { + Color currentColor = (Color) color.get(parent); + if (cachedColor == null || prevColor != color.get(parent)) { + cachedColor = new OneColor(currentColor); + } + prevColor = currentColor; + return cachedColor; + } + + @Override + protected void setColor(OneColor color) { + if (cachedColor != color) { + Color newColor = new Color(color.getRGB(), true); + try { + this.color.set(parent, newColor); + } catch (IllegalAccessException ignored) { + } + } + } + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilanceName.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilanceName.java new file mode 100644 index 0000000..ff84d3c --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilanceName.java @@ -0,0 +1,16 @@ +package cc.polyfrost.oneconfig.internal.config.compatibility.vigilance; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface VigilanceName { + String name(); + + String category(); + + String subcategory(); +} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilantAccessor.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilantAccessor.java new file mode 100644 index 0000000..f059dbc --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilantAccessor.java @@ -0,0 +1,11 @@ +package cc.polyfrost.oneconfig.internal.config.compatibility.vigilance; + +import gg.essential.vigilance.data.PropertyCollector; + +/** + * Interface for accessing the {@link PropertyCollector} in a Vigilant config. + *

Not recommended for non-internal OneConfig usage, as Systemless will get really angry at us

+ */ +public interface VigilantAccessor { + PropertyCollector getPropertyCollector(); +} diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java index 0ef2c58..bc9dc7b 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/plugin/OneConfigMixinPlugin.java @@ -59,11 +59,11 @@ public class OneConfigMixinPlugin implements IMixinConfigPlugin { * If anything here is changed, edit the corresponding method in OneConfigMixinPlugin! */ private void transform(ClassNode node) { - if (!node.interfaces.contains("cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilantAccessor")) { + if (!node.interfaces.contains("cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilantAccessor")) { node.fields.add(new FieldNode(Opcodes.ACC_PUBLIC, "oneconfig$config", "Lcc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig;", null, null)); node.fields.add(new FieldNode(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "oneconfig$file", Type.getDescriptor(File.class), null, null)); - node.interfaces.add("cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilantAccessor"); + node.interfaces.add("cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilantAccessor"); MethodNode methodNode = new MethodNode(Opcodes.ACC_PUBLIC, "getPropertyCollector", "()Lgg/essential/vigilance/data/PropertyCollector;", null, null); LabelNode labelNode = new LabelNode(); methodNode.instructions.add(labelNode); @@ -90,7 +90,7 @@ public class OneConfigMixinPlugin implements IMixinConfigPlugin { methodNode2.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "gg/essential/vigilance/Vigilant", "oneconfig$config", "Lcc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig;")); methodNode2.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1)); methodNode2.instructions.add(new VarInsnNode(Opcodes.ALOAD, 2)); - methodNode2.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "cc/polyfrost/oneconfig/config/compatibility/vigilance/VigilanceConfig", "addDependency", "(Lgg/essential/vigilance/data/PropertyData;Lgg/essential/vigilance/data/PropertyData;)V", false)); + methodNode2.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "cc/polyfrost/oneconfig/internal/config/compatibility/vigilance/VigilanceConfig", "addDependency", "(Lgg/essential/vigilance/data/PropertyData;Lgg/essential/vigilance/data/PropertyData;)V", false)); methodNode2.instructions.add(labelNode4); methodNode2.instructions.add(new LineNumberNode(15636438, labelNode4)); -- cgit