aboutsummaryrefslogtreecommitdiff
path: root/src
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
parentffcb16e4c7f0f4414c69541238178ce3a128bb74 (diff)
downloadOneConfig-ea41af7ba66dec2bf64bc72e0eac31279120cc7f.tar.gz
OneConfig-ea41af7ba66dec2bf64bc72e0eac31279120cc7f.tar.bz2
OneConfig-ea41af7ba66dec2bf64bc72e0eac31279120cc7f.zip
support for color
Diffstat (limited to 'src')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/compatibility/VigilanceConfig.java41
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java4
2 files changed, 40 insertions, 5 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) {
+
+ }
+ }
+ }
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java
index 2068882..4be79c4 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java
@@ -1,12 +1,12 @@
package cc.polyfrost.oneconfig.gui.elements.config;
import cc.polyfrost.oneconfig.config.OneConfigConfig;
+import cc.polyfrost.oneconfig.config.core.OneColor;
import cc.polyfrost.oneconfig.config.interfaces.BasicOption;
import cc.polyfrost.oneconfig.gui.OneConfigGui;
import cc.polyfrost.oneconfig.gui.elements.BasicElement;
import cc.polyfrost.oneconfig.gui.elements.ColorSelector;
import cc.polyfrost.oneconfig.gui.elements.text.TextInputField;
-import cc.polyfrost.oneconfig.config.core.OneColor;
import cc.polyfrost.oneconfig.lwjgl.RenderManager;
import cc.polyfrost.oneconfig.lwjgl.font.Fonts;
import cc.polyfrost.oneconfig.lwjgl.image.Images;
@@ -86,7 +86,7 @@ public class ConfigColorElement extends BasicOption {
hexField.keyTyped(key, keyCode);
}
- private void setColor(OneColor color) {
+ protected void setColor(OneColor color) {
try {
set(color);
} catch (IllegalAccessException ignored) {