diff options
author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-04-28 20:45:50 +0200 |
---|---|---|
committer | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-04-28 20:45:50 +0200 |
commit | 117d80ff0e343eecf260fd363db896166d8061d7 (patch) | |
tree | 8ef0ead687b69caf646874458beefa1d1710a38a /src/main/java/io/polyfrost/oneconfig/gui/elements | |
parent | 7c5123ff64c751c19411982189321be3511a9815 (diff) | |
download | OneConfig-117d80ff0e343eecf260fd363db896166d8061d7.tar.gz OneConfig-117d80ff0e343eecf260fd363db896166d8061d7.tar.bz2 OneConfig-117d80ff0e343eecf260fd363db896166d8061d7.zip |
better mousepressed handling, some more option types and some other things I forgor
Diffstat (limited to 'src/main/java/io/polyfrost/oneconfig/gui/elements')
5 files changed, 59 insertions, 22 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicElement.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicElement.java index dd72217..c4bab72 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicElement.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/BasicElement.java @@ -41,13 +41,13 @@ public class BasicElement { public void update(int x, int y) { hovered = InputUtils.isAreaHovered(x - hitBoxX, y - hitBoxY, width + hitBoxX, height + hitBoxY); + clicked = InputUtils.isClicked(); if (hovered) { - if (Mouse.isButtonDown(0) && !clicked) { + if (clicked) { toggled = !toggled; onClick(); } - clicked = Mouse.isButtonDown(0); } } @@ -92,5 +92,4 @@ public class BasicElement { public boolean isToggled() { return toggled; } - } diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java new file mode 100644 index 0000000..a2c4510 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java @@ -0,0 +1,21 @@ +package io.polyfrost.oneconfig.gui.elements.config; + +import io.polyfrost.oneconfig.config.interfaces.BasicOption; + +import java.lang.reflect.Field; + +public class ConfigCheckbox extends BasicOption { + public ConfigCheckbox(Field field, String name, int size) { + super(field, name, size); + } + + @Override + public void draw(long vg, int x, int y) { + + } + + @Override + public int getHeight() { + return 0; + } +} diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPage.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPage.java index 8a718bb..5386fc9 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPage.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigPage.java @@ -9,7 +9,6 @@ import io.polyfrost.oneconfig.lwjgl.RenderManager; import io.polyfrost.oneconfig.lwjgl.font.Fonts; import io.polyfrost.oneconfig.utils.ColorUtils; import io.polyfrost.oneconfig.utils.InputUtils; -import org.lwjgl.input.Mouse; import org.lwjgl.nanovg.NanoVG; import java.lang.reflect.Field; @@ -18,7 +17,6 @@ public class ConfigPage extends BasicOption { public final OptionPage page; public final String description; private int backgroundColor = OneConfigConfig.GRAY_500; - private boolean pressed = false; public ConfigPage(Field field, String name, String description, int size, OptionPage page) { super(field, name, size); @@ -28,22 +26,23 @@ public class ConfigPage extends BasicOption { @Override public void draw(long vg, int x, int y) { - boolean hovered = InputUtils.isAreaHovered(x - 2, y, 1023, description.equals("") ? 64 : 96); - boolean clicked = pressed && !Mouse.isButtonDown(0); - pressed = hovered && Mouse.isButtonDown(0); + int height = description.equals("") ? 64 : 96; + NanoVG.nvgScissor(vg, x - 2, y, 1024, height); + boolean hovered = InputUtils.isAreaHovered(x - 2, y, 1024, height); + boolean clicked = InputUtils.isAreaClicked(x - 2, y, 1024, height); backgroundColor = ColorUtils.smoothColor(backgroundColor, OneConfigConfig.GRAY_500, OneConfigConfig.GRAY_400, hovered, 100); if (clicked) NanoVG.nvgGlobalAlpha(vg, 0.8f); - RenderManager.drawRoundedRect(vg, x - 2, y, 1024, description.equals("") ? 64 : 96, backgroundColor, 20); + RenderManager.drawRoundedRect(vg, x - 2, y, 1024, height, backgroundColor, 20); RenderManager.drawString(vg, name, x + 24, y + 32, OneConfigConfig.WHITE, 24, Fonts.INTER_MEDIUM); if (!description.equals("")) RenderManager.drawString(vg, name, x + 24, y + 70, OneConfigConfig.WHITE, 14, Fonts.INTER_MEDIUM); RenderManager.drawImage(vg, "/assets/oneconfig/textures/arrow.png", x + 995f, y + (description.equals("") ? 20f : 36f), 13, 22); - if (clicked) OneConfigGui.INSTANCE.openPage(new ModConfigPage(page)); NanoVG.nvgGlobalAlpha(vg, 1f); + NanoVG.nvgResetScissor(vg); } @Override 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 89cc6f8..804fc62 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 @@ -7,10 +7,6 @@ import io.polyfrost.oneconfig.lwjgl.font.Fonts; import io.polyfrost.oneconfig.utils.ColorUtils; import io.polyfrost.oneconfig.utils.InputUtils; import io.polyfrost.oneconfig.utils.MathUtils; -import net.minecraft.client.Minecraft; -import net.minecraft.util.ChatComponentText; -import org.lwjgl.input.Cursor; -import org.lwjgl.input.Mouse; import java.lang.reflect.Field; @@ -20,7 +16,6 @@ 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 ; public ConfigSwitch(Field field, String name, int size) { @@ -34,8 +29,7 @@ public class ConfigSwitch extends BasicOption { @Override public void draw(long vg, int x, int y) { - nvgScissor(vg, x, y, size == 0 ? 480 : 992, 32); - boolean hovered = InputUtils.isAreaHovered(x, y, size == 0 ? 480 : 992, 32); + nvgScissor(vg, x, y, size == 1 ? 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) { @@ -45,7 +39,7 @@ 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 (InputUtils.isClicked(x, y, size == 0 ? 480 : 992, 32) && !this.clicked && hovered) + if (InputUtils.isAreaClicked(x + 16, y, 42, 32)) { toggled = !toggled; try { @@ -55,12 +49,8 @@ public class ConfigSwitch extends BasicOption { e.printStackTrace(); } } - this.clicked = InputUtils.isClicked(x, y, size == 0 ? 480 : 992, 32) && hovered; percentOn = MathUtils.clamp(MathUtils.easeOut(percentOn, toggled ? 1f : 0f, 10)); nvgResetScissor(vg); - - - } @Override diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java new file mode 100644 index 0000000..e09ad77 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java @@ -0,0 +1,28 @@ +package io.polyfrost.oneconfig.gui.elements.config; + +import io.polyfrost.oneconfig.config.interfaces.BasicOption; + +import java.lang.reflect.Field; + +public class ConfigTextBox extends BasicOption { + private final String placeholder; + private final boolean secure; + private final boolean multiLine; + + public ConfigTextBox(Field field, String name, int size, String placeholder, boolean secure, boolean multiLine) { + super(field, name, size); + this.placeholder = placeholder; + this.secure = secure; + this.multiLine = multiLine; + } + + @Override + public void draw(long vg, int x, int y) { + + } + + @Override + public int getHeight() { + return 0; + } +} |