diff options
Diffstat (limited to 'src')
22 files changed, 142 insertions, 98 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java index 36351f6..519e890 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/data/OptionType.java @@ -50,4 +50,8 @@ public enum OptionType { * Type: OneKeyBind */ KEYBIND, + /** + * Type: ? extends BasicHud + */ + HUD, } diff --git a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/BasicOption.java b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/BasicOption.java index c036408..6fa3254 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/BasicOption.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/BasicOption.java @@ -9,16 +9,19 @@ public abstract class BasicOption { protected final String name; public final int size; private Supplier<Boolean> dependency; + protected final Object parent; /** * Initialize option * - * @param field variable attached to option (null for category) - * @param name name of option - * @param size size of option, 0 for single column, 1 for double. + * @param field variable attached to option (null for category) + * @param parent the parent object of the field, used for getting and setting the variable + * @param name name of option + * @param size size of option, 0 for single column, 1 for double. */ - public BasicOption(Field field, String name, int size) { + public BasicOption(Field field, Object parent, String name, int size) { this.field = field; + this.parent = parent; this.name = name; this.size = size; if (field != null) field.setAccessible(true); @@ -29,7 +32,7 @@ public abstract class BasicOption { */ protected void set(Object object) throws IllegalAccessException { if (field == null) return; - field.set(null, object); + field.set(parent, object); } /** @@ -37,7 +40,7 @@ public abstract class BasicOption { */ protected Object get() throws IllegalAccessException { if (field == null) return null; - return field.get(null); + return field.get(parent); } /** diff --git a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java index 9524723..cbd4b08 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/interfaces/Config.java @@ -3,14 +3,13 @@ package cc.polyfrost.oneconfig.config.interfaces; import cc.polyfrost.oneconfig.config.annotations.ConfigPage; import cc.polyfrost.oneconfig.config.annotations.Option; import cc.polyfrost.oneconfig.config.core.ConfigCore; -import cc.polyfrost.oneconfig.config.data.Mod; -import cc.polyfrost.oneconfig.config.data.OptionCategory; -import cc.polyfrost.oneconfig.config.data.OptionPage; -import cc.polyfrost.oneconfig.config.data.OptionSubcategory; +import cc.polyfrost.oneconfig.config.data.*; import cc.polyfrost.oneconfig.config.profiles.Profiles; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.elements.config.*; import cc.polyfrost.oneconfig.gui.pages.ModConfigPage; +import cc.polyfrost.oneconfig.hud.BasicHud; +import cc.polyfrost.oneconfig.hud.HudCore; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import com.google.gson.*; @@ -20,6 +19,7 @@ import java.lang.reflect.Modifier; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.*; +import java.util.function.Consumer; import java.util.function.Supplier; public class Config { @@ -42,7 +42,7 @@ public class Config { if (Profiles.getProfileFile(configFile).exists()) load(); else save(); mod.config = this; - generateOptionList(this.getClass(), mod.defaultPage, mod); + generateOptionList(this, mod.defaultPage, mod); ConfigCore.oneConfigMods.add(mod); this.mod = mod; } @@ -63,7 +63,7 @@ public class Config { */ public void load() { try (BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(Profiles.getProfileFile(configFile).toPath()), StandardCharsets.UTF_8))) { - deserializePart(new JsonParser().parse(reader).getAsJsonObject(), this.getClass()); + deserializePart(new JsonParser().parse(reader).getAsJsonObject(), this); } catch (IOException e) { e.printStackTrace(); } @@ -72,10 +72,12 @@ public class Config { /** * Generate the option list, for internal use only * - * @param clazz target class - * @param page page to add options too + * @param instance instance of target class + * @param page page to add options too + * @param mod data about the mod */ - protected void generateOptionList(Class<?> clazz, OptionPage page, Mod mod) { + protected void generateOptionList(Object instance, OptionPage page, Mod mod) { + Class<?> clazz = instance.getClass(); for (Field field : clazz.getDeclaredFields()) { String pagePrefix = page.equals(mod.defaultPage) ? "" : page.name + "."; if (!field.isAnnotationPresent(Option.class) && !field.isAnnotationPresent(ConfigPage.class)) { @@ -93,8 +95,8 @@ public class Config { try { field.setAccessible(true); Object object = field.get(clazz); - generateOptionList(object.getClass(), newPage, mod); - ConfigPageButton configPageButton = new ConfigPageButton(field, option.name(), option.description(), newPage); + generateOptionList(object, newPage, mod); + ConfigPageButton configPageButton = new ConfigPageButton(field, instance, option.name(), option.description(), newPage); switch (option.location()) { case TOP: subcategory.topButtons.add(configPageButton); @@ -117,43 +119,71 @@ public class Config { ArrayList<BasicOption> options = category.subcategories.get(category.subcategories.size() - 1).options; switch (option.type()) { case SWITCH: - options.add(new ConfigSwitch(field, option.name(), option.size())); + options.add(new ConfigSwitch(field, instance, option.name(), option.size())); break; case CHECKBOX: - options.add(new ConfigCheckbox(field, option.name(), option.size())); + options.add(new ConfigCheckbox(field, instance, option.name(), option.size())); break; case TEXT: - options.add(new ConfigTextBox(field, option.name(), option.size(), option.placeholder(), option.secure(), option.multiLine())); + options.add(new ConfigTextBox(field, instance, option.name(), option.size(), option.placeholder(), option.secure(), option.multiLine())); break; case DUAL_OPTION: - options.add(new ConfigDualOption(field, option.name(), option.size(), option.options())); + options.add(new ConfigDualOption(field, instance, option.name(), option.size(), option.options())); break; case UNI_SELECTOR: - options.add(new ConfigUniSelector(field, option.name(), option.size(), option.options())); + options.add(new ConfigUniSelector(field, instance, option.name(), option.size(), option.options())); break; case DROPDOWN: - options.add(new ConfigDropdown(field, option.name(), option.size(), option.options(), option.dividers())); + options.add(new ConfigDropdown(field, instance, option.name(), option.size(), option.options(), option.dividers())); break; case SLIDER: - options.add(new ConfigSlider(field, option.name(), option.size(), option.min(), option.max(), option.step())); + options.add(new ConfigSlider(field, instance, option.name(), option.size(), option.min(), option.max(), option.step())); break; case INFO: - options.add(new ConfigInfo(field, option.name(), option.size(), option.infoType())); + options.add(new ConfigInfo(field, instance, option.name(), option.size(), option.infoType())); break; case COLOR: - options.add(new ConfigColorElement(field, option.name(), option.size())); + options.add(new ConfigColorElement(field, instance, option.name(), option.size())); break; case HEADER: - options.add(new ConfigHeader(field, option.name(), option.size())); + options.add(new ConfigHeader(field, instance, option.name(), option.size())); break; case BUTTON: - options.add(new ConfigButton(field, option.name(), option.size(), option.buttonText())); + options.add(new ConfigButton(field, instance, option.name(), option.size(), option.buttonText())); break; case KEYBIND: - options.add(new ConfigKeyBind(field, option.name(), option.size())); + options.add(new ConfigKeyBind(field, instance, option.name(), option.size())); + break; + case HUD: + try { + field.setAccessible(true); + BasicHud hud = (BasicHud) field.get(instance); + HudCore.huds.add(hud); + options.add(new ConfigHeader(field, hud, option.name(), 1)); + options.add(new ConfigSwitch(hud.getClass().getField("enabled"), hud, "Enabled", 1)); + options.add(new ConfigCheckbox(hud.getClass().getField("rounded"), hud, "Rounded corners", 1)); + options.get(options.size() - 1).setDependency(() -> hud.enabled); + options.add(new ConfigCheckbox(hud.getClass().getField("border"), hud, "Outline/border", 1)); + options.get(options.size() - 1).setDependency(() -> hud.enabled); + options.add(new ConfigColorElement(hud.getClass().getField("bgColor"), hud, "Background color:", 1)); + options.get(options.size() - 1).setDependency(() -> hud.enabled); + options.add(new ConfigColorElement(hud.getClass().getField("borderColor"), hud, "Border color:", 1)); + options.get(options.size() - 1).setDependency(() -> hud.enabled && hud.border); + options.add(new ConfigSlider(hud.getClass().getField("cornerRadius"), hud, "Corner radius:", 2, 0, 10, 0)); + options.get(options.size() - 1).setDependency(() -> hud.enabled && hud.rounded); + options.add(new ConfigSlider(hud.getClass().getField("borderSize"), hud, "Border thickness:", 2, 0, 10, 0)); + options.get(options.size() - 1).setDependency(() -> hud.enabled && hud.border); + options.add(new ConfigSlider(hud.getClass().getField("paddingX"), hud, "X-Padding", 2, 0, 50, 0)); + options.get(options.size() - 1).setDependency(() -> hud.enabled); + options.add(new ConfigSlider(hud.getClass().getField("paddingY"), hud, "Y-Padding", 2, 0, 50, 0)); + options.get(options.size() - 1).setDependency(() -> hud.enabled); + } catch (IllegalAccessException | NoSuchFieldException e) { + e.printStackTrace(); + } break; } - optionNames.put(pagePrefix + field.getName(), options.get(options.size() - 1)); + if (!option.type().equals(OptionType.HUD)) + optionNames.put(pagePrefix + field.getName(), options.get(options.size() - 1)); } } @@ -169,10 +199,11 @@ public class Config { /** * Deserialize part of config and load values * - * @param json json to deserialize - * @param clazz target class + * @param json json to deserialize + * @param instance instance of target class */ - protected void deserializePart(JsonObject json, Class<?> clazz) { + protected void deserializePart(JsonObject json, Object instance) { + Class<?> clazz = instance.getClass(); for (Map.Entry<String, JsonElement> element : json.entrySet()) { String name = element.getKey(); JsonElement value = element.getValue(); @@ -188,7 +219,7 @@ public class Config { TypeAdapter<?> adapter = gson.getAdapter(field.getType()); Object object = adapter.fromJsonTree(value); field.setAccessible(true); - field.set(this, object); + field.set(instance, object); } catch (Exception ignored) { } } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java index 5465652..c31d2e1 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/HudGui.java @@ -1,5 +1,6 @@ package cc.polyfrost.oneconfig.gui; +import cc.polyfrost.oneconfig.config.core.ConfigCore; import cc.polyfrost.oneconfig.hud.HudCore; import cc.polyfrost.oneconfig.hud.BasicHud; import cc.polyfrost.oneconfig.lwjgl.RenderManager; @@ -90,6 +91,7 @@ public class HudGui extends GuiScreen { float width = editingHud.getWidth(editingHud.scale) + editingHud.paddingX * editingHud.scale; float height = editingHud.getHeight(editingHud.scale) + editingHud.paddingY * editingHud.scale; + /* Childing disabled since it still needs some extra work if (editingHud.childRight != null) { HudCore.huds.add(editingHud.childRight); editingHud.childRight.parent = null; @@ -107,7 +109,7 @@ public class HudGui extends GuiScreen { else if (editingHud.parent.childRight == editingHud) editingHud.parent.childRight = null; editingHud.parent = null; - } + }*/ if (newX < 0) newX = 0; @@ -181,7 +183,8 @@ public class HudGui extends GuiScreen { } } if (smallestDiff != -1) { - RenderManager.drawDottedLine(smallestLine, 0, smallestLine, this.height, 2, 12, new Color(255, 255, 255).getRGB()); + float finalSmallestLine = smallestLine; + RenderManager.setupAndDraw(true, (vg) -> RenderManager.drawLine(vg, finalSmallestLine, 0, finalSmallestLine, this.height, 1, new Color(255, 255, 255).getRGB())); return smallestLine - smallestOffset; } return pos; @@ -219,7 +222,8 @@ public class HudGui extends GuiScreen { } } if (smallestDiff != -1) { - RenderManager.drawDottedLine(0, smallestLine, this.width, smallestLine, 2, 12, new Color(255, 255, 255).getRGB()); + float finalSmallestLine = smallestLine; + RenderManager.setupAndDraw(true, (vg) -> RenderManager.drawLine(vg, 0, finalSmallestLine, this.width, finalSmallestLine, 1, new Color(255, 255, 255).getRGB())); return smallestLine - smallestOffset; } return pos; @@ -316,6 +320,7 @@ public class HudGui extends GuiScreen { public void onGuiClosed() { HudCore.editing = false; Keyboard.enableRepeatEvents(false); + ConfigCore.saveAll(); } @Override diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java index 643bc90..2e8cb4f 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java @@ -12,8 +12,8 @@ import java.lang.reflect.Field; public class ConfigButton extends BasicOption { private final BasicButton button; - public ConfigButton(Field field, String name, int size, String text) { - super(field, name, size); + public ConfigButton(Field field, Object parent, String name, int size, String text) { + super(field, parent, name, size); Runnable runnable = () -> { }; try { @@ -27,7 +27,7 @@ public class ConfigButton extends BasicOption { @Override public void draw(long vg, int x, int y) { button.disable(!isEnabled()); - NanoVG.nvgGlobalAlpha(vg, 0.5f); + if(!isEnabled()) NanoVG.nvgGlobalAlpha(vg, 0.5f); RenderManager.drawString(vg, name, x, y + 17, OneConfigConfig.WHITE, 14f, Fonts.MEDIUM); button.draw(vg, x + (size == 1 ? 352 : 736), y); NanoVG.nvgGlobalAlpha(vg, 1f); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java index a1c8b9c..8a30d71 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java @@ -17,8 +17,8 @@ public class ConfigCheckbox extends BasicOption { private int color; private float percentOn = 0f; - public ConfigCheckbox(Field field, String name, int size) { - super(field, name, size); + public ConfigCheckbox(Field field, Object parent, String name, int size) { + super(field, parent, name, size); } @Override 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 ba533da..aed367f 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 @@ -24,8 +24,8 @@ public class ConfigColorElement extends BasicOption { private final TextInputField alphaField = new TextInputField(72, 32, "", false, false); private final BasicElement element = new BasicElement(64, 32, false); - public ConfigColorElement(Field field, String name, int size) { - super(field, name, size); + public ConfigColorElement(Field field, Object parent, String name, int size) { + super(field, parent, name, size); hexField.setCentered(true); alphaField.setCentered(true); alphaField.onlyAcceptNumbers(true); 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 2805fd4..c2cb0cf 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 @@ -20,8 +20,8 @@ public class ConfigDropdown extends BasicOption { // TODO: chose where dividers private boolean opened = false; private int[] dividers; - public ConfigDropdown(Field field, String name, int size, String[] options, int [] dividers) { - super(field, name, size); + public ConfigDropdown(Field field, Object parent, String name, int size, String[] options, int [] dividers) { + super(field, parent, name, size); this.options = options; this.dividers = dividers; } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java index c05a370..42c8fea 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java @@ -14,8 +14,8 @@ public class ConfigDualOption extends BasicOption { private float percentMove = 0f; private final String left, right; - public ConfigDualOption(Field field, String name, int size, String[] options) { - super(field, name, size); + public ConfigDualOption(Field field, Object parent, String name, int size, String[] options) { + super(field, parent, name, size); this.left = options[0]; this.right = options[1]; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java index 3ef3d06..c7c7ea9 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java @@ -11,8 +11,8 @@ import java.lang.reflect.Field; public class ConfigHeader extends BasicOption { - public ConfigHeader(Field field, String name, int size) { - super(field, name, size); + public ConfigHeader(Field field, Object parent, String name, int size) { + super(field, parent, name, size); } @Override diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigInfo.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigInfo.java index 1eda01b..2e29328 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigInfo.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigInfo.java @@ -14,8 +14,8 @@ import java.lang.reflect.Field; public class ConfigInfo extends BasicOption { private Images image; - public ConfigInfo(Field field, String name, int size, InfoType type) { - super(field, name, size); + public ConfigInfo(Field field, Object parent, String name, int size, InfoType type) { + super(field, parent, name, size); switch (type) { case INFO: image = Images.INFO; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java index 476e58d..f8669a2 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java @@ -17,8 +17,8 @@ public class ConfigKeyBind extends BasicOption { private final BasicButton button; private boolean clicked = false; - public ConfigKeyBind(Field field, String name, int size) { - super(field, name, size); + public ConfigKeyBind(Field field, Object parent, String name, int size) { + super(field, parent, name, size); button = new BasicButton(256, 32, "", Images.KEYSTROKE, null, 0, BasicButton.ALIGNMENT_CENTER, true); button.alignIconLeft(true); } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java index 42f7568..3288123 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java @@ -20,8 +20,8 @@ public class ConfigPageButton extends BasicOption { public final String description; private int backgroundColor = OneConfigConfig.GRAY_500; - public ConfigPageButton(Field field, String name, String description, OptionPage page) { - super(field, name, 2); + public ConfigPageButton(Field field, Object parent, String name, String description, OptionPage page) { + super(field, parent, name, 2); this.description = description; this.page = page; } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java index 3a4253c..29d132a 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java @@ -19,8 +19,8 @@ public class ConfigSlider extends BasicOption { private final int step; private boolean dragging = false; - public ConfigSlider(Field field, String name, int size, float min, float max, int step) { - super(field, name, size); + public ConfigSlider(Field field, Object parent, String name, int size, float min, float max, int step) { + super(field, parent, name, size); this.min = min; this.max = max; this.step = step; @@ -32,6 +32,7 @@ public class ConfigSlider extends BasicOption { int xCoordinate = 0; float value = 0; boolean hovered = InputUtils.isAreaHovered(x + 352, y, 512, 32) && isEnabled(); + inputField.disable(!isEnabled()); if (!isEnabled()) NanoVG.nvgGlobalAlpha(vg, 0.5f); if (hovered && Mouse.isButtonDown(0)) dragging = true; if (dragging) { diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java index 3ce4693..aa0dc1d 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java @@ -15,8 +15,8 @@ public class ConfigSwitch extends BasicOption { private int color; private float percentOn = 0f; - public ConfigSwitch(Field field, String name, int size) { - super(field, name, size); + public ConfigSwitch(Field field, Object parent, String name, int size) { + super(field, parent, name, size); } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java index 1fb7c84..3aa4050 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java @@ -17,8 +17,8 @@ public class ConfigTextBox extends BasicOption { private final boolean multiLine; private final TextInputField textField; - public ConfigTextBox(Field field, String name, int size, String placeholder, boolean secure, boolean multiLine) { - super(field, name, size); + public ConfigTextBox(Field field, Object parent, String name, int size, String placeholder, boolean secure, boolean multiLine) { + super(field, parent, name, size); this.secure = secure; this.multiLine = multiLine; this.textField = new TextInputField(size == 1 && hasHalfSize() ? 256 : 640, multiLine ? 64 : 32, placeholder, multiLine, secure); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java index e77357f..a9b0ab1 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java @@ -18,8 +18,8 @@ public class ConfigUniSelector extends BasicOption { private float percentMove = 1f; private int previous = -1; - public ConfigUniSelector(Field field, String name, int size, String[] options) { - super(field, name, size); + public ConfigUniSelector(Field field, Object parent, String name, int size, String[] options) { + super(field, parent, name, size); this.options = options; } diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java index 12bc162..b15300e 100644 --- a/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java +++ b/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java @@ -1,17 +1,23 @@ package cc.polyfrost.oneconfig.hud; +import cc.polyfrost.oneconfig.lwjgl.OneColor; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import java.awt.*; public abstract class BasicHud { + public boolean enabled = true; + public boolean rounded = false; + public boolean border = false; + public OneColor bgColor = new OneColor(0, 0, 0, 120); + public OneColor borderColor = new OneColor(0, 0, 0); + public float cornerRadius = 2; + public float borderSize = 2; public double xUnscaled = 0; public double yUnscaled = 0; public float scale = 1; - public int paddingX = 5; - public int paddingY = 5; - public boolean background = true; - public boolean rounded = false; + public float paddingX = 5; + public float paddingY = 5; public BasicHud parent; public BasicHud childRight; public BasicHud childBottom; @@ -53,8 +59,15 @@ public abstract class BasicHud { } private void drawBackground(float x, float y, float width, float height, float scale) { - RenderManager.setupAndDraw(true, (vg) -> RenderManager.drawRoundedRect(vg, x, y, (width + paddingX * scale), - (height + paddingY * scale), new Color(0, 0, 0, 120).getRGB(), 2 * scale)); + RenderManager.setupAndDraw(true, (vg) -> { + if (rounded) { + RenderManager.drawRoundedRect(vg, x, y, (width + paddingX * scale), (height + paddingY * scale), bgColor.getRGB(), cornerRadius * scale); + if (border) RenderManager.drawHollowRoundRect(vg, x - borderSize * scale, y - borderSize * scale, (width + paddingX * scale) + borderSize * scale, (height + paddingY * scale) + borderSize * scale, borderColor.getRGB(), cornerRadius * scale, borderSize * scale); + } else { + RenderManager.drawRect(vg, x, y, (width + paddingX * scale), (height + paddingY * scale), bgColor.getRGB()); + if (border) RenderManager.drawHollowRoundRect(vg, x - borderSize * scale, y - borderSize * scale, (width + paddingX * scale) + borderSize * scale, (height + paddingY * scale) + borderSize * scale, borderColor.getRGB(), 0, borderSize * scale); + } + }); } public float getXScaled(int screenWidth) { diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/HudCore.java b/src/main/java/cc/polyfrost/oneconfig/hud/HudCore.java index 50303be..08baaee 100644 --- a/src/main/java/cc/polyfrost/oneconfig/hud/HudCore.java +++ b/src/main/java/cc/polyfrost/oneconfig/hud/HudCore.java @@ -15,7 +15,7 @@ public class HudCore { if (event.type != RenderGameOverlayEvent.ElementType.ALL || editing) return; int[] sr = OneConfig.getScaledResolution(); for (BasicHud hud : huds) { - hud.drawAll(hud.getXScaled(sr[0]), hud.getYScaled(sr[1]), hud.scale, true); + if(hud.enabled) hud.drawAll(hud.getXScaled(sr[0]), hud.getYScaled(sr[1]), hud.scale, true); } } } diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/OneColor.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/OneColor.java index e098390..508fc21 100644 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/OneColor.java +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/OneColor.java @@ -16,7 +16,7 @@ import java.awt.*; */ @SuppressWarnings("unused") public class OneColor { - transient private int rgba; + transient private Integer rgba = null; private short[] hsba; private int chroma = -1; @@ -134,13 +134,17 @@ public class OneColor { */ public int getRGB() { if (chroma == -1) { + // fix for when rgba is not set because of deserializing not calling constructor + if (rgba == null) rgba = HSBAtoRGBA(this.hsba[0], this.hsba[1], this.hsba[2], this.hsba[3]); return rgba; } else { return HSBAtoRGBA(System.currentTimeMillis() % chroma / (float) chroma, hsba[1], hsba[2], hsba[3]); } } - /** return the current color without its alpha. Internal method. */ + /** + * return the current color without its alpha. Internal method. + */ public int getRGBNoAlpha() { return 0xff000000 | rgba; } diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java index 0a9ccce..d23f1dd 100644 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java @@ -324,29 +324,6 @@ public final class RenderManager { GL11.glColor4f(f1, f2, f3, f); } - public static void drawDottedLine(float sx, float sy, float ex, float ey, int width, int factor, int color) { - GL11.glPushMatrix(); - GL11.glLineStipple(factor, (short) 0xAAAA); - GL11.glEnable(GL11.GL_LINE_STIPPLE); - GL11.glPushMatrix(); - GL11.glDisable(GL11.GL_TEXTURE_2D); - GL11.glEnable(GL11.GL_BLEND); - GL11.glDisable(GL11.GL_ALPHA); - GL14.glBlendFuncSeparate(770, 771, 1, 0); // this should never fail because it's a GL14 call, and we import GL31 - glColor(color); - GL11.glLineWidth(width); - GL11.glBegin(GL11.GL_LINES); - GL11.glVertex2d(sx, sy); - GL11.glVertex2d(ex, ey); - GL11.glEnd(); - GL11.glDisable(GL11.GL_BLEND); - GL11.glEnable(GL11.GL_ALPHA); - GL11.glEnable(GL11.GL_TEXTURE_2D); - GL11.glPopMatrix(); - GL11.glDisable(GL11.GL_LINE_STIPPLE); - GL11.glPopMatrix(); - } - public static void drawGlRect(int x, int y, int width, int height, int color) { Gui.drawRect(x, y, x + width, y + height, color); } diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java index 8dc2889..9bf9e58 100644 --- a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java @@ -8,11 +8,17 @@ import cc.polyfrost.oneconfig.config.interfaces.Config; import cc.polyfrost.oneconfig.lwjgl.OneColor; import net.minecraftforge.fml.common.FMLCommonHandler; -import java.lang.reflect.Field; - public class TestConfig extends Config { @Option( + name = "Very cool HUD", + subcategory = "Test", + type = OptionType.HUD, + size = 2 + ) + public static TestHud TestHud = new TestHud(); + + @Option( name = "This is all still in beta", subcategory = "Test", type = OptionType.INFO, |