diff options
author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-04-28 19:34:42 +0200 |
---|---|---|
committer | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-04-28 19:34:42 +0200 |
commit | 7c5123ff64c751c19411982189321be3511a9815 (patch) | |
tree | 0258163a1cdd33b2711d121055751e027f7d6e41 /src/main/java/io | |
parent | ff0a0079ffc9dccdf1fffd0616ec724eb048f771 (diff) | |
parent | 9c028b9e55f3968ec3651c7063c0ffd81b027596 (diff) | |
download | OneConfig-7c5123ff64c751c19411982189321be3511a9815.tar.gz OneConfig-7c5123ff64c751c19411982189321be3511a9815.tar.bz2 OneConfig-7c5123ff64c751c19411982189321be3511a9815.zip |
Merge branch 'master' of github.com:Polyfrost/OneConfig
Diffstat (limited to 'src/main/java/io')
-rw-r--r-- | src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java | 21 | ||||
-rw-r--r-- | src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java | 12 |
2 files changed, 28 insertions, 5 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java index 214bd16..89cc6f8 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java @@ -14,19 +14,28 @@ import org.lwjgl.input.Mouse; import java.lang.reflect.Field; +import static org.lwjgl.nanovg.NanoVG.nvgResetScissor; +import static org.lwjgl.nanovg.NanoVG.nvgScissor; + public class ConfigSwitch extends BasicOption { private int color; private float percentOn = 0f; private boolean clicked = false; - private boolean toggled = false; + private boolean toggled ; public ConfigSwitch(Field field, String name, int size) { super(field, name, size); + try { + toggled = (boolean) get(); + } catch (IllegalAccessException e) { + System.err.println("failed to get config value: class=" + this + " fieldWatching=" + field); + } } @Override public void draw(long vg, int x, int y) { - boolean hovered = InputUtils.isAreaHovered(x, y, 480, 32); + nvgScissor(vg, x, y, size == 0 ? 480 : 992, 32); + boolean hovered = InputUtils.isAreaHovered(x, y, size == 0 ? 480 : 992, 32); int x2 = x + 19 + (int) (percentOn * 18); color = ColorUtils.smoothColor(color, OneConfigConfig.GRAY_400, OneConfigConfig.BLUE_500, toggled, 20f); if(color == -15123643) { @@ -36,17 +45,19 @@ public class ConfigSwitch extends BasicOption { RenderManager.drawRoundedRect(vg, x2, y + 7, 18, 18, OneConfigConfig.WHITE, 9f); RenderManager.drawString(vg, name, x + 66, y + 17, OneConfigConfig.WHITE, 18f, Fonts.INTER_MEDIUM); - if (Mouse.isButtonDown(0) && !this.clicked && hovered) + if (InputUtils.isClicked(x, y, size == 0 ? 480 : 992, 32) && !this.clicked && hovered) { toggled = !toggled; try { set(toggled); } catch (IllegalAccessException e) { - throw new RuntimeException(e); + System.err.println("failed to write config value: class=" + this + " fieldWatching=" + field + " valueWrite=" + toggled); + e.printStackTrace(); } } - this.clicked = Mouse.isButtonDown(0) && hovered; + this.clicked = InputUtils.isClicked(x, y, size == 0 ? 480 : 992, 32) && hovered; percentOn = MathUtils.clamp(MathUtils.easeOut(percentOn, toggled ? 1f : 0f, 10)); + nvgResetScissor(vg); diff --git a/src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java b/src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java index 1ce1a30..e030c29 100644 --- a/src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java +++ b/src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java @@ -14,4 +14,16 @@ public class InputUtils { int mouseY = Minecraft.getMinecraft().displayHeight - Math.abs(Mouse.getY()); return mouseX > x && mouseY > y && mouseX < x + width && mouseY < y + height; // TODO add scaling info } + + public static boolean isClicked(int x, int y, int width, int height) { + return isAreaHovered(x, y, width, height) && Mouse.isButtonDown(0); // TODO make actually do what its meant to do (only 1 event) + } + + public static int mouseX() { + return Mouse.getX(); + } + + public static int mouseY() { + return Minecraft.getMinecraft().displayHeight - Math.abs(Mouse.getY()); + } } |