aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/config/compatibility
diff options
context:
space:
mode:
authorWyvest <45589059+Wyvest@users.noreply.github.com>2022-05-22 21:39:52 +0700
committerWyvest <45589059+Wyvest@users.noreply.github.com>2022-05-22 21:39:52 +0700
commitea41af7ba66dec2bf64bc72e0eac31279120cc7f (patch)
tree567b0e4963b369ba4bee38f455c3eeb9e498a367 /src/main/java/cc/polyfrost/oneconfig/config/compatibility
parentffcb16e4c7f0f4414c69541238178ce3a128bb74 (diff)
downloadOneConfig-ea41af7ba66dec2bf64bc72e0eac31279120cc7f.tar.gz
OneConfig-ea41af7ba66dec2bf64bc72e0eac31279120cc7f.tar.bz2
OneConfig-ea41af7ba66dec2bf64bc72e0eac31279120cc7f.zip
support for color
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/config/compatibility')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilanceConfig.java41
1 files changed, 38 insertions, 3 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilanceConfig.java b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilanceConfig.java
index 14d1e72..4b0ddd8 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilanceConfig.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilanceConfig.java
@@ -1,6 +1,7 @@
package cc.polyfrost.oneconfig.config.compatibility;
import cc.polyfrost.oneconfig.config.core.ConfigCore;
+import cc.polyfrost.oneconfig.config.core.OneColor;
import cc.polyfrost.oneconfig.config.data.Mod;
import cc.polyfrost.oneconfig.config.data.OptionCategory;
import cc.polyfrost.oneconfig.config.data.OptionPage;
@@ -13,6 +14,7 @@ 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;
@@ -80,9 +82,9 @@ public class VigilanceConfig extends Config {
case SLIDER:
options.add(new ConfigSlider(getFieldOfProperty(option), option.getInstance(), attributes.getName(), 2, attributes.getMin(), attributes.getMax(), 0));
break;
- /*case COLOR: TODO: find a way to go from Color to OneColor
- options.add(new ConfigColorElement(getFieldOfProperty(option), option.getInstance(), attributes.getName(), 2));
- break;*/
+ case COLOR:
+ options.add(new CompatConfigColorElement(getFieldOfProperty(option), option.getInstance(), attributes.getName(), 2));
+ break;
case BUTTON:
options.add(new ConfigButton(() -> ((CallablePropertyValue) option.getValue()).invoke(option.getInstance()), option.getInstance(), attributes.getName(), 2, attributes.getPlaceholder()));
break;
@@ -132,4 +134,37 @@ public class VigilanceConfig extends Config {
option.setDependency(() -> Objects.equals(dependency.getValue().getValue(vigilant), true));
}
}
+
+ private static class CompatConfigColorElement extends ConfigColorElement {
+ private Color prevColor = null;
+ private final Field color;
+ private OneColor cachedColor = null;
+
+ public CompatConfigColorElement(Field color, Vigilant parent, String name, int size) {
+ super(null, parent, name, size);
+ this.color = color;
+ }
+
+ @Override
+ protected 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) {
+
+ }
+ }
+ }
+ }
}