diff options
author | nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> | 2022-04-28 18:17:12 +0100 |
---|---|---|
committer | nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> | 2022-04-28 18:17:12 +0100 |
commit | d99504188ba1866043cd7f652df8b66c24ea3052 (patch) | |
tree | 874a77ab6884d66cd556611c4d756c280e9ecc55 /src/main/java/io/polyfrost | |
parent | ef8d18075904cad5c66b6cd97f0963f8405ac4d4 (diff) | |
download | OneConfig-d99504188ba1866043cd7f652df8b66c24ea3052.tar.gz OneConfig-d99504188ba1866043cd7f652df8b66c24ea3052.tar.bz2 OneConfig-d99504188ba1866043cd7f652df8b66c24ea3052.zip |
config switch
Diffstat (limited to 'src/main/java/io/polyfrost')
3 files changed, 37 insertions, 3 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/TextInputField.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/TextInputField.java index f9a9111..6f3c1b4 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/TextInputField.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/TextInputField.java @@ -9,7 +9,6 @@ import net.minecraft.util.ChatAllowedCharacters; import org.jetbrains.annotations.NotNull; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; -import org.lwjgl.nanovg.NanoVG; import java.awt.*; import java.awt.datatransfer.DataFlavor; 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 eb341f7..1ae4fef 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 @@ -40,8 +40,6 @@ public class ConfigPage extends BasicOption { 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); - RenderManager.drawRect(vg, x, y, 1024, 20, OneConfigConfig.WHITE); - RenderManager.drawRect(vg, x, y + 64 - 20, 1024, 20, OneConfigConfig.WHITE); if (clicked) OneConfigGui.INSTANCE.openPage(new ModConfigPage(page)); 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 a65e873..214bd16 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 @@ -1,10 +1,24 @@ 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.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; public class ConfigSwitch extends BasicOption { + private int color; + private float percentOn = 0f; + private boolean clicked = false; + private boolean toggled = false; public ConfigSwitch(Field field, String name, int size) { super(field, name, size); @@ -12,6 +26,29 @@ public class ConfigSwitch extends BasicOption { @Override public void draw(long vg, int x, int y) { + boolean hovered = InputUtils.isAreaHovered(x, y, 480, 32); + int x2 = x + 19 + (int) (percentOn * 18); + color = ColorUtils.smoothColor(color, OneConfigConfig.GRAY_400, OneConfigConfig.BLUE_500, toggled, 20f); + if(color == -15123643) { + color = OneConfigConfig.GRAY_400; + } + RenderManager.drawRoundedRect(vg, x + 16, y + 4, 42, 24, color, 12f); + 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) + { + toggled = !toggled; + try { + set(toggled); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + this.clicked = Mouse.isButtonDown(0) && hovered; + percentOn = MathUtils.clamp(MathUtils.easeOut(percentOn, toggled ? 1f : 0f, 10)); + + } |