aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authornextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com>2022-04-28 18:33:19 +0100
committernextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com>2022-04-28 18:33:19 +0100
commit9c028b9e55f3968ec3651c7063c0ffd81b027596 (patch)
tree9d8d1d2a8afca7ccf2d006946c2d2b0eb8e08e76 /src/main/java
parentd99504188ba1866043cd7f652df8b66c24ea3052 (diff)
downloadOneConfig-9c028b9e55f3968ec3651c7063c0ffd81b027596.tar.gz
OneConfig-9c028b9e55f3968ec3651c7063c0ffd81b027596.tar.bz2
OneConfig-9c028b9e55f3968ec3651c7063c0ffd81b027596.zip
finish for today so no conflicts
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java21
-rw-r--r--src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java12
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());
+ }
}