diff --git a/src/main/java/org/saturnclient/modules/ModDimensions.java b/src/main/java/org/saturnclient/modules/ModDimensions.java index a177b48..2db4d34 100644 --- a/src/main/java/org/saturnclient/modules/ModDimensions.java +++ b/src/main/java/org/saturnclient/modules/ModDimensions.java @@ -6,19 +6,19 @@ import org.saturnclient.saturnclient.config.NamedProperty; import org.saturnclient.saturnclient.config.Property; public class ModDimensions { - public Property x = new Property<>(0); - public Property y = new Property<>(0); - public Property scale = new Property<>(1.0f); - public Property bgColor = new Property<>(0x00000000, Property.PropertyType.HEX); - public Property fgColor = new Property<>(0xFFffffff, Property.PropertyType.HEX); - public Property radius = new Property<>(0); + public Property x = Property.integer(0); + public Property y = Property.integer(0); + public Property scale = Property.floatProp(1.0f); + public Property bgColor = Property.color(0x00000000); + public Property fgColor = Property.color(0xFFffffff); + public Property radius = Property.integer(0); public Property font = Property.font(0); public int width = 0; public int height = 0; public NamedProperty>> prop() { - return new Property>>(Map.of( + return Property.namespace(Map.of( "X", x, "Y", y, "Scale", scale, diff --git a/src/main/java/org/saturnclient/modules/mods/ArmorDisplay.java b/src/main/java/org/saturnclient/modules/mods/ArmorDisplay.java index bdfaa84..1102323 100644 --- a/src/main/java/org/saturnclient/modules/mods/ArmorDisplay.java +++ b/src/main/java/org/saturnclient/modules/mods/ArmorDisplay.java @@ -13,7 +13,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.Items; public class ArmorDisplay extends Module implements HudMod { - private static Property enabled = new Property<>(true); + private static Property enabled = Property.bool(true); private static ModDimensions dimensions = new ModDimensions(40, 60); public ArmorDisplay() { diff --git a/src/main/java/org/saturnclient/modules/mods/AutoSprint.java b/src/main/java/org/saturnclient/modules/mods/AutoSprint.java index 8c26798..d91a7ad 100644 --- a/src/main/java/org/saturnclient/modules/mods/AutoSprint.java +++ b/src/main/java/org/saturnclient/modules/mods/AutoSprint.java @@ -8,7 +8,7 @@ import org.saturnclient.saturnclient.SaturnClient; import org.saturnclient.saturnclient.config.Property; public class AutoSprint extends Module { - private static Property enabled = new Property<>(true); + private static Property enabled = Property.bool(false); public AutoSprint() { super( diff --git a/src/main/java/org/saturnclient/modules/mods/Crosshair.java b/src/main/java/org/saturnclient/modules/mods/Crosshair.java index 385e159..2f9f7cb 100644 --- a/src/main/java/org/saturnclient/modules/mods/Crosshair.java +++ b/src/main/java/org/saturnclient/modules/mods/Crosshair.java @@ -10,7 +10,7 @@ import org.saturnclient.ui2.resources.Textures; import net.minecraft.client.render.RenderLayer; public class Crosshair extends Module { - public static Property enabled = new Property<>(false); + public static Property enabled = Property.bool(false); public Crosshair() { super( diff --git a/src/main/java/org/saturnclient/modules/mods/Fps.java b/src/main/java/org/saturnclient/modules/mods/Fps.java index bd9db41..c71f320 100644 --- a/src/main/java/org/saturnclient/modules/mods/Fps.java +++ b/src/main/java/org/saturnclient/modules/mods/Fps.java @@ -10,8 +10,7 @@ import org.saturnclient.ui2.RenderScope; import org.saturnclient.ui2.resources.Fonts; public class Fps extends Module implements HudMod { - private static Property enabled = new Property<>(false); - private static Property fgColor = new Property<>(-1, Property.PropertyType.HEX); + private static Property enabled = Property.bool(false); private static ModDimensions dimensions = new ModDimensions(60, Fonts.getHeight()); public Fps() { @@ -26,14 +25,14 @@ public class Fps extends Module implements HudMod { @Override public void renderHud(RenderScope scope) { String text = String.valueOf(SaturnClient.client.getCurrentFps()) + " FPS"; - scope.drawText(text, 0, 0, dimensions.font.value, fgColor.value); + scope.drawText(text, 0, 0, dimensions.font.value, dimensions.fgColor.value); dimensions.width = Fonts.getWidth(text, dimensions.font.value); } @Override public void renderDummy(RenderScope scope) { String text = "369 FPS"; - scope.drawText(text, 0, 0, dimensions.font.value, fgColor.value); + scope.drawText(text, 0, 0, dimensions.font.value, dimensions.fgColor.value); dimensions.width = Fonts.getWidth(text, dimensions.font.value); } diff --git a/src/main/java/org/saturnclient/modules/mods/PotionDisplay.java b/src/main/java/org/saturnclient/modules/mods/PotionDisplay.java index 91a1066..28a1b93 100644 --- a/src/main/java/org/saturnclient/modules/mods/PotionDisplay.java +++ b/src/main/java/org/saturnclient/modules/mods/PotionDisplay.java @@ -21,8 +21,9 @@ import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; public class PotionDisplay extends Module implements HudMod { - public static Property enabled = new Property<>(false); + public static Property enabled = Property.bool(false); private static ModDimensions dimensions = new ModDimensions(60, 0); + private final StatusEffectInstance[] dummyEffects = { new StatusEffectInstance(Registries.STATUS_EFFECT.getEntry(Identifier.ofVanilla("speed")).get(), 12000, 2), new StatusEffectInstance(Registries.STATUS_EFFECT.getEntry(Identifier.ofVanilla("strength")).get(), 12000, 2), diff --git a/src/main/java/org/saturnclient/saturnclient/SaturnClientConfig.java b/src/main/java/org/saturnclient/saturnclient/SaturnClientConfig.java index 5d112ec..26f8573 100644 --- a/src/main/java/org/saturnclient/saturnclient/SaturnClientConfig.java +++ b/src/main/java/org/saturnclient/saturnclient/SaturnClientConfig.java @@ -10,11 +10,9 @@ import net.minecraft.util.Identifier; public class SaturnClientConfig { public static ConfigManager config; - public static Property realisticLogo = - new Property<>(false); + public static Property realisticLogo = Property.bool(false); - public static Property saturnTitleScreen = - new Property<>(true); + public static Property saturnTitleScreen = Property.bool(true); public static Identifier getLogo() { return realisticLogo.value ? Textures.REALISTIC_LOGO : Textures.LOGO; diff --git a/src/main/java/org/saturnclient/saturnclient/config/ConfigManager.java b/src/main/java/org/saturnclient/saturnclient/config/ConfigManager.java index 5affa2d..9a49376 100644 --- a/src/main/java/org/saturnclient/saturnclient/config/ConfigManager.java +++ b/src/main/java/org/saturnclient/saturnclient/config/ConfigManager.java @@ -32,8 +32,7 @@ public class ConfigManager { public ConfigManager(ConfigManager config, String namespace) { currentMap = new LinkedHashMap<>(); - Property>> namespaceProperty = new Property<>(currentMap, - Property.PropertyType.NAMESPACE); + Property>> namespaceProperty = Property.namespace(currentMap); config.property(namespace, namespaceProperty); // Update the parent's state config.currentMap.put(namespace, namespaceProperty); @@ -41,8 +40,7 @@ public class ConfigManager { } public void sub(String namespace) { - Property>> namespaceProperty = new Property<>(currentMap, - Property.PropertyType.NAMESPACE); + Property>> namespaceProperty = Property.namespace(currentMap); property(namespace, namespaceProperty); } diff --git a/src/main/java/org/saturnclient/saturnclient/config/Property.java b/src/main/java/org/saturnclient/saturnclient/config/Property.java index d1d92fe..a91d304 100644 --- a/src/main/java/org/saturnclient/saturnclient/config/Property.java +++ b/src/main/java/org/saturnclient/saturnclient/config/Property.java @@ -23,43 +23,60 @@ public class Property { private String[] availableValues; private PropertyType type; - public Property(T value) { - this.value = value; - this.defaultValue = value; - if (value instanceof Boolean) { - type = PropertyType.BOOLEAN; - } else if (value instanceof Integer) { - type = PropertyType.INTEGER; - } else if (value instanceof Float) { - type = PropertyType.FLOAT; - } else if (value instanceof String) { - type = PropertyType.STRING; - } else if (valueIsNamespace(value)) { - type = PropertyType.NAMESPACE; - } - } - - public Property(T value, PropertyType type) { + private Property(T value, PropertyType type) { this.value = value; this.defaultValue = value; this.type = type; } + public static Property from(T value) { + if (value instanceof Boolean) { + return new Property<>(value, PropertyType.BOOLEAN); + } else if (value instanceof Integer) { + return new Property<>(value, PropertyType.INTEGER); + } else if (value instanceof Float) { + return new Property<>(value, PropertyType.FLOAT); + } else if (value instanceof String) { + return new Property<>(value, PropertyType.STRING); + } else if (valueIsNamespace(value)) { + return new Property<>(value, PropertyType.NAMESPACE); + } else { + return null; + } + } + + public static Property font(int value) { + return select(value, "Default", "Inter", "Inter bold"); + } + public static Property select(Integer value, String... availableValues) { Property property = new Property<>(value, PropertyType.SELECT); property.availableValues = availableValues; return property; } - public static Property font(int value) { - return select(value, "Default", "Inter", "Inter bold"); + public static Property>> namespace(Map> value) { + return new Property<>(value, PropertyType.NAMESPACE); } - @SuppressWarnings("unchecked") - public static Property namespace(Map> value) { - Property property = new Property<>((T) value, PropertyType.NAMESPACE); - property.type = PropertyType.NAMESPACE; - return property; + public static Property bool(boolean value) { + return new Property<>(value, PropertyType.BOOLEAN); + } + + public static Property integer(int value) { + return new Property<>(value, PropertyType.INTEGER); + } + + public static Property floatProp(float value) { + return new Property<>(value, PropertyType.FLOAT); + } + + public static Property string(String value) { + return new Property<>(value, PropertyType.STRING); + } + + public static Property color(int value) { + return new Property<>(value, PropertyType.HEX); } public void next() { diff --git a/src/main/java/org/saturnclient/saturnclient/config/ThemeManager.java b/src/main/java/org/saturnclient/saturnclient/config/ThemeManager.java index 5135f52..f19aabd 100644 --- a/src/main/java/org/saturnclient/saturnclient/config/ThemeManager.java +++ b/src/main/java/org/saturnclient/saturnclient/config/ThemeManager.java @@ -74,13 +74,13 @@ public class ThemeManager { // Generic method to store any type of property public Property property(String name, Property prop) { for (String state : states) { - Property property = new Property(prop.value); + Property property = Property.from(prop.value); properties.get(namespace+"@"+state).put(name, property); loadProp(state, name, property); } loadProp(null, name, prop); - properties.get(namespace).put(name, new Property(prop.value)); + properties.get(namespace).put(name, Property.from(prop.value)); currentStyling.put(name, prop); return prop; diff --git a/src/main/java/org/saturnclient/ui2/components/CosmeticPreview.java b/src/main/java/org/saturnclient/ui2/components/CosmeticPreview.java index 3a021ef..2abc35c 100644 --- a/src/main/java/org/saturnclient/ui2/components/CosmeticPreview.java +++ b/src/main/java/org/saturnclient/ui2/components/CosmeticPreview.java @@ -11,10 +11,10 @@ import net.minecraft.util.Identifier; public class CosmeticPreview extends Element { private static ThemeManager theme = new ThemeManager("CosmeticPreview", "selected", "hovering"); - private static Property bgColor = theme.property("bg-color", new Property(0xAA000000)); - private static Property fgColor = theme.property("fg-color", new Property(0xFFFFFFFF)); - private static Property padding = theme.property("padding", new Property(14)); - private static Property cornerRadius = theme.property("corner-radius", new Property(10)); + private static Property bgColor = theme.property("bg-color", Property.color(0xAA000000)); + private static Property fgColor = theme.property("fg-color", Property.color(0xFFFFFFFF)); + private static Property padding = theme.property("padding", Property.integer(14)); + private static Property cornerRadius = theme.property("corner-radius", Property.integer(10)); static {} diff --git a/src/main/java/org/saturnclient/ui2/components/SaturnModule.java b/src/main/java/org/saturnclient/ui2/components/SaturnModule.java index f9b2393..a9c0059 100644 --- a/src/main/java/org/saturnclient/ui2/components/SaturnModule.java +++ b/src/main/java/org/saturnclient/ui2/components/SaturnModule.java @@ -16,14 +16,14 @@ import net.minecraft.client.render.RenderLayer; public class SaturnModule extends Element { private static ThemeManager theme = new ThemeManager("Module", "enabled", "hovering"); - private static Property bgColor = theme.property("bg", new Property<>(0xFF1d202d)); - private static Property fgColor = theme.property("fg", new Property<>(0xFFA1A2B8)); - private static Property iconFg = theme.property("icon-fg", new Property<>(0xFFA1A2B8)); - private static Property iconBg = theme.property("icon-bg", new Property<>(0xFF2e3248)); - private static Property tagBg = theme.property("tag-bg", new Property<>(0xFF2e3248)); - private static Property iconRadius = theme.property("icon-radius", new Property<>(10)); + private static Property bgColor = theme.property("bg", Property.color(0xFF1d202d)); + private static Property fgColor = theme.property("fg", Property.color(0xFFA1A2B8)); + private static Property iconFg = theme.property("icon-fg", Property.color(0xFFA1A2B8)); + private static Property iconBg = theme.property("icon-bg", Property.color(0xFF2e3248)); + private static Property tagBg = theme.property("tag-bg", Property.color(0xFF2e3248)); + private static Property iconRadius = theme.property("icon-radius", Property.color(10)); private static Property font = theme.property("font", Property.font(1)); - private static Property radius = theme.property("radius", new Property<>(10)); + private static Property radius = theme.property("radius", Property.color(10)); static { theme.propertyStateDefault("enabled", "bg", 0xFF1d202d); diff --git a/src/main/java/org/saturnclient/ui2/components/Sidebar.java b/src/main/java/org/saturnclient/ui2/components/Sidebar.java index 69a5d9f..5fb5f1f 100644 --- a/src/main/java/org/saturnclient/ui2/components/Sidebar.java +++ b/src/main/java/org/saturnclient/ui2/components/Sidebar.java @@ -18,13 +18,13 @@ import net.minecraft.util.Identifier; public class Sidebar extends Element { private static ThemeManager theme = new ThemeManager("SideBar", "hovering"); - private static Property bgColor = theme.property("bg-color", new Property(0x90000000)); - private static Property iconFg = theme.property("icon-fg", new Property(-1)); - private static Property iconBg = theme.property("icon-bg", new Property(0x00000000)); + private static Property bgColor = theme.property("bg-color", Property.color(0x90000000)); + private static Property iconFg = theme.property("icon-fg", Property.color(0xFFFFFFFF)); + private static Property iconBg = theme.property("icon-bg", Property.color(0x00000000)); - private static Property cornerRadius = theme.property("corner-radius", new Property(10)); - private static Property iconRadius = theme.property("icon-radius", new Property(10)); - private static Property padding = theme.property("padding", new Property(10)); + private static Property cornerRadius = theme.property("corner-radius", Property.integer(10)); + private static Property iconRadius = theme.property("icon-radius", Property.integer(10)); + private static Property padding = theme.property("padding", Property.integer(10)); static { theme.propertyStateDefault("hovering", "icon-bg", -7643914); diff --git a/src/main/java/org/saturnclient/ui2/components/inputs/Select.java b/src/main/java/org/saturnclient/ui2/components/inputs/Select.java index 88994b8..c4d207c 100644 --- a/src/main/java/org/saturnclient/ui2/components/inputs/Select.java +++ b/src/main/java/org/saturnclient/ui2/components/inputs/Select.java @@ -11,8 +11,8 @@ import net.minecraft.client.render.RenderLayer; public class Select extends Element { private static ThemeManager theme = new ThemeManager("Toggle"); - private static Property fgColor = theme.property("fg-color", new Property(0xAAAAAA)); - private static Property arrowColor = theme.property("arrow-color", new Property(0xff8B5CF6)); + private static Property fgColor = theme.property("fg-color", Property.color(0xAAAAAA)); + private static Property arrowColor = theme.property("arrow-color", Property.color(0xff8B5CF6)); private static Property font = theme.property("font", Property.font(1)); private Property prop; diff --git a/src/main/java/org/saturnclient/ui2/components/inputs/Toggle.java b/src/main/java/org/saturnclient/ui2/components/inputs/Toggle.java index be58056..09c4e99 100644 --- a/src/main/java/org/saturnclient/ui2/components/inputs/Toggle.java +++ b/src/main/java/org/saturnclient/ui2/components/inputs/Toggle.java @@ -8,9 +8,9 @@ import org.saturnclient.ui2.RenderScope; public class Toggle extends Element { private static ThemeManager theme = new ThemeManager("Toggle", "hovering", "enabled"); - private static Property bgColor = theme.property("bg-color", new Property(0xFF808080)); - private static Property fgColor = theme.property("fg-color", new Property(0xFF909090)); - private static Property cornerRadius = theme.property("corner-radius", new Property(30)); + private static Property bgColor = theme.property("bg-color", Property.color(0xFF808080)); + private static Property fgColor = theme.property("fg-color", Property.color(0xFF909090)); + private static Property cornerRadius = theme.property("corner-radius", Property.integer(30)); static { theme.propertyStateDefault("enabled", "bg-color", 0xaf8B5CF6); diff --git a/src/main/java/org/saturnclient/ui2/elements/Button.java b/src/main/java/org/saturnclient/ui2/elements/Button.java index a126f61..0b74643 100644 --- a/src/main/java/org/saturnclient/ui2/elements/Button.java +++ b/src/main/java/org/saturnclient/ui2/elements/Button.java @@ -9,9 +9,9 @@ import org.saturnclient.ui2.resources.Fonts; public class Button extends Element { private static ThemeManager theme = new ThemeManager("Button", "hovering"); - private static Property bgColor = theme.property("bg-color", new Property(0xFF000000)); - private static Property fgColor = theme.property("fg-color", new Property(0xFFFFFFFF)); - private static Property cornerRadius = theme.property("corner-radius", new Property(10)); + private static Property bgColor = theme.property("bg-color", Property.color(0xFF000000)); + private static Property fgColor = theme.property("fg-color", Property.color(0xFFFFFFFF)); + private static Property cornerRadius = theme.property("corner-radius", Property.integer(10)); private static Property font = theme.property("font", Property.font(1)); static { diff --git a/src/main/java/org/saturnclient/ui2/elements/ClickableTexture.java b/src/main/java/org/saturnclient/ui2/elements/ClickableTexture.java index 33f377f..0a8aff1 100644 --- a/src/main/java/org/saturnclient/ui2/elements/ClickableTexture.java +++ b/src/main/java/org/saturnclient/ui2/elements/ClickableTexture.java @@ -11,7 +11,7 @@ import net.minecraft.util.Identifier; public class ClickableTexture extends Element { private static ThemeManager theme = new ThemeManager("ClickableTexture", "hovering"); - private static Property fgColor = theme.property("fg-color", new Property(0xFFFFFFFF)); + private static Property fgColor = theme.property("fg-color", Property.color(0xFFFFFFFF)); Identifier sprite; private Runnable onClick; diff --git a/src/main/java/org/saturnclient/ui2/elements/Scroll.java b/src/main/java/org/saturnclient/ui2/elements/Scroll.java index b51a4b1..00683cc 100644 --- a/src/main/java/org/saturnclient/ui2/elements/Scroll.java +++ b/src/main/java/org/saturnclient/ui2/elements/Scroll.java @@ -12,13 +12,13 @@ import org.saturnclient.ui2.components.ElementRenderer; public class Scroll extends Element { private static ThemeManager theme = new ThemeManager("Scroll"); - private static Property bgColor = theme.property("bg-color", new Property(0x90000000)); - private static Property scrollBarColor = theme.property("scrollbar-color", new Property(-7643914)); + private static Property bgColor = theme.property("bg-color", Property.color(0x90000000)); + private static Property scrollBarColor = theme.property("scrollbar-color", Property.color(-7643914)); - private static Property scrollBarRadius = theme.property("scrollbar-radius", new Property(10)); - private static Property scrollBarWidth = theme.property("scrollbar-width", new Property(5)); - private static Property scrollBarPadding = theme.property("scrollbar-padding", new Property(5)); - private static Property cornerRadius = theme.property("corner-radius", new Property(10)); + private static Property scrollBarRadius = theme.property("scrollbar-radius", Property.integer(10)); + private static Property scrollBarWidth = theme.property("scrollbar-width", Property.integer(5)); + private static Property scrollBarPadding = theme.property("scrollbar-padding", Property.integer(5)); + private static Property cornerRadius = theme.property("corner-radius", Property.integer(10)); int padding = 0; diff --git a/src/main/java/org/saturnclient/ui2/elements/Text.java b/src/main/java/org/saturnclient/ui2/elements/Text.java index b952206..d4453d3 100644 --- a/src/main/java/org/saturnclient/ui2/elements/Text.java +++ b/src/main/java/org/saturnclient/ui2/elements/Text.java @@ -8,7 +8,7 @@ import org.saturnclient.ui2.RenderScope; public class Text extends Element { private static ThemeManager theme = new ThemeManager("Text"); - private static Property fgColor = theme.property("fg-color", new Property(0xFFFFFFFF)); + private static Property fgColor = theme.property("fg-color", Property.color(0xFFFFFFFF)); public static Property font = theme.property("font", Property.font(1)); private String text; diff --git a/src/main/java/org/saturnclient/ui2/elements/TextureButton.java b/src/main/java/org/saturnclient/ui2/elements/TextureButton.java index f1575d4..d345bf3 100644 --- a/src/main/java/org/saturnclient/ui2/elements/TextureButton.java +++ b/src/main/java/org/saturnclient/ui2/elements/TextureButton.java @@ -11,10 +11,10 @@ import net.minecraft.util.Identifier; public class TextureButton extends Element { private static ThemeManager theme = new ThemeManager("TextureButton", "hovering"); - private static Property bgColor = theme.property("bg-color", new Property(0xFF000000)); - private static Property fgColor = theme.property("fg-color", new Property(0xFFFFFFFF)); - private static Property padding = theme.property("padding", new Property(14)); - private static Property cornerRadius = theme.property("corner-radius", new Property(10)); + private static Property bgColor = theme.property("bg-color", Property.color(0xFF000000)); + private static Property fgColor = theme.property("fg-color", Property.color(0xFFFFFFFF)); + private static Property padding = theme.property("padding", Property.integer(14)); + private static Property cornerRadius = theme.property("corner-radius", Property.integer(10)); static {