From 026aebb4748747f08d5088947056a75740550b17 Mon Sep 17 00:00:00 2001 From: nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> Date: Sat, 30 Apr 2022 11:54:24 +0100 Subject: config elements --- .../gui/elements/config/ConfigDualOption.java | 53 ++++++++++++++++++++++ .../gui/elements/config/ConfigUniSelector.java | 34 ++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java create mode 100644 src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java (limited to 'src/main/java/io/polyfrost/oneconfig/gui/elements/config') diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java new file mode 100644 index 0000000..705ab1a --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java @@ -0,0 +1,53 @@ +package io.polyfrost.oneconfig.gui.elements.config; + +import io.polyfrost.oneconfig.config.OneConfigConfig; +import io.polyfrost.oneconfig.config.interfaces.BasicOption; +import io.polyfrost.oneconfig.lwjgl.RenderManager; +import io.polyfrost.oneconfig.lwjgl.font.Fonts; +import io.polyfrost.oneconfig.utils.InputUtils; +import io.polyfrost.oneconfig.utils.MathUtils; + +import java.lang.reflect.Field; + +public class ConfigDualOption extends BasicOption { + private float percentMove = 0f; + private final String left, right; + + public ConfigDualOption(Field field, String name, int size, String left, String right) { + super(field, name, size); + this.left = left; + this.right = right; + + } + + @Override + public int getHeight() { + return 32; + } + + @Override + public void draw(long vg, int x, int y) { + boolean toggled = false; + try { + toggled = (boolean) get(); + } catch (IllegalAccessException ignored) { + } + RenderManager.drawString(vg, name, x, y + 16, OneConfigConfig.WHITE_90, 18f, Fonts.INTER_MEDIUM); + RenderManager.drawRoundedRect(vg, x + 226, y, 256, 32, OneConfigConfig.GRAY_500, 12f); + int x1 = (int) (x + 228 + (percentMove * 128)); + RenderManager.drawRoundedRect(vg, x1, y + 2, 124, 28, OneConfigConfig.BLUE_600, 10f); + RenderManager.drawString(vg, left, x + 290 - RenderManager.getTextWidth(vg, left, 14f, Fonts.INTER_MEDIUM) / 2, y + 16, OneConfigConfig.WHITE_90, 14f, Fonts.INTER_MEDIUM); + RenderManager.drawString(vg, right, x + 418 - RenderManager.getTextWidth(vg, right, 14f, Fonts.INTER_MEDIUM) / 2, y + 16, OneConfigConfig.WHITE_90, 14f, Fonts.INTER_MEDIUM); + + if (InputUtils.isAreaClicked(x + 226, y, 256, 32)) { + toggled = !toggled; + try { + set(toggled); + } catch (IllegalAccessException e) { + System.err.println("failed to write config value: class=" + this + " fieldWatching=" + field + " valueWrite=" + toggled); + e.printStackTrace(); + } + } + percentMove = MathUtils.clamp(MathUtils.easeOut(percentMove, toggled ? 1f : 0f, 10)); + } +} diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java new file mode 100644 index 0000000..39f8cf9 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java @@ -0,0 +1,34 @@ +package io.polyfrost.oneconfig.gui.elements.config; + +import io.polyfrost.oneconfig.config.OneConfigConfig; +import io.polyfrost.oneconfig.config.interfaces.BasicOption; +import io.polyfrost.oneconfig.lwjgl.RenderManager; +import io.polyfrost.oneconfig.lwjgl.font.Fonts; + +import java.lang.reflect.Field; + +public class ConfigUniSelector extends BasicOption { + String[] options; + + public ConfigUniSelector(Field field, String name, int size, String[] options) { + super(field, name, size); + this.options = options; + } + + @Override + public int getHeight() { + return 0; + } + + @Override + public void draw(long vg, int x, int y) { + int selected = 0; + try { + selected = (int) get(); + } catch (IllegalAccessException ignored) { + } + RenderManager.drawString(vg, name, x, y + 16, OneConfigConfig.WHITE_90, 18f, Fonts.INTER_MEDIUM); + RenderManager.drawString(vg, options[selected], x + 16, y + 16, OneConfigConfig.WHITE_90, 18f, Fonts.INTER_MEDIUM); + RenderManager.drawImage(vg, "/assets/oneconfig/textures/arrow.png", x + 230, y + 7, 13, 22, OneConfigConfig.BLUE_400); // TODO + } +} -- cgit