diff options
author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-04-30 18:10:49 +0200 |
---|---|---|
committer | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-04-30 18:10:49 +0200 |
commit | 5514e4b97ab2a7a37bf25cf4a4a57baf8f94e052 (patch) | |
tree | 6bc07d092ae94f89f6013563fa7c5d3ceccfdbae /src/main/java/io/polyfrost/oneconfig/gui/elements | |
parent | 0283a6618360ed473da42c1144da5b44146155bb (diff) | |
download | OneConfig-5514e4b97ab2a7a37bf25cf4a4a57baf8f94e052.tar.gz OneConfig-5514e4b97ab2a7a37bf25cf4a4a57baf8f94e052.tar.bz2 OneConfig-5514e4b97ab2a7a37bf25cf4a4a57baf8f94e052.zip |
uni selector
Diffstat (limited to 'src/main/java/io/polyfrost/oneconfig/gui/elements')
-rw-r--r-- | src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java | 33 |
1 files changed, 25 insertions, 8 deletions
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 index b20e8bc..5acdae0 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java @@ -5,12 +5,15 @@ 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 org.lwjgl.nanovg.NanoVG; import java.lang.reflect.Field; public class ConfigUniSelector extends BasicOption { - String[] options; + private final String[] options; + private float percentMove = 1f; + private int previous = -1; public ConfigUniSelector(Field field, String name, int size, String[] options) { super(field, name, size); @@ -31,7 +34,17 @@ public class ConfigUniSelector extends BasicOption { } String option = options[selected] + " " + (selected + 1) + "/" + options.length; RenderManager.drawString(vg, name, x, y + 16, OneConfigConfig.WHITE_90, 18f, Fonts.INTER_MEDIUM); - RenderManager.drawString(vg, option, x + 352 - RenderManager.getTextWidth(vg, option, 14f, Fonts.INTER_MEDIUM) / 2f, y + 15, OneConfigConfig.WHITE_90, 14f, Fonts.INTER_MEDIUM); + + if (previous == -1) { + RenderManager.drawString(vg, option, x + 352 - RenderManager.getTextWidth(vg, option, 14f, Fonts.INTER_MEDIUM) / 2f, y + 15, OneConfigConfig.WHITE_90, 14f, Fonts.INTER_MEDIUM); + } else { + String prevOption = options[previous] + " " + (previous + 1) + "/" + options.length; + NanoVG.nvgScissor(vg, x + 256, y, 192, 32); + RenderManager.drawString(vg, selected < previous ? prevOption : option, x + 352 - RenderManager.getTextWidth(vg, selected < previous ? prevOption : option, 14f, Fonts.INTER_MEDIUM) / 2f + 192 * percentMove, y + 15, OneConfigConfig.WHITE_90, 14f, Fonts.INTER_MEDIUM); + RenderManager.drawString(vg, selected < previous ? option : prevOption, x + 352 - RenderManager.getTextWidth(vg, selected < previous ? option : prevOption, 14f, Fonts.INTER_MEDIUM) / 2f - 192 * (1 - percentMove), y + 15, OneConfigConfig.WHITE_90, 14f, Fonts.INTER_MEDIUM); + + NanoVG.nvgResetScissor(vg); + } // actual coordinates: 240, 7 NanoVG.nvgTranslate(vg, x + 248, y + 21); @@ -40,20 +53,24 @@ public class ConfigUniSelector extends BasicOption { NanoVG.nvgResetTransform(vg); RenderManager.drawImage(vg, "/assets/oneconfig/textures/arrow.png", x + 456, y + 7, 8, 14, OneConfigConfig.BLUE_400); - if (InputUtils.isAreaClicked(x + 240, y + 7, 8, 14)) { - if (selected > 0) selected -= 1; - else selected = options.length - 1; + if (InputUtils.isAreaClicked(x + 235, y + 5, 18, 18) && selected > 0) { + previous = selected; + selected -= 1; try { set(selected); } catch (IllegalAccessException ignored) { } - } else if (InputUtils.isAreaClicked(x + 456, y + 7, 8, 14)) { - if (selected < options.length - 1) selected += 1; - else selected = 0; + percentMove = selected < previous ? 0f : 1f; + } else if (InputUtils.isAreaClicked(x + 451, y + 5, 18, 18) && selected < options.length - 1) { + previous = selected; + selected += 1; try { set(selected); } catch (IllegalAccessException ignored) { } + percentMove = selected < previous ? 0f : 1f; } + if (previous != -1) percentMove = MathUtils.easeOut(percentMove, selected < previous ? 1f : 0f, 10); + if ((selected < previous ? 1f : 0f) == percentMove) previous = -1; } } |