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 | |
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')
3 files changed, 61 insertions, 8 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/config/interfaces/BasicOption.java b/src/main/java/io/polyfrost/oneconfig/config/interfaces/BasicOption.java index 7c9771c..8d19b55 100644 --- a/src/main/java/io/polyfrost/oneconfig/config/interfaces/BasicOption.java +++ b/src/main/java/io/polyfrost/oneconfig/config/interfaces/BasicOption.java @@ -55,6 +55,18 @@ public abstract class BasicOption { public abstract void draw(long vg, int x, int y); /** + * Function that gets called last drawing option, + * should be used for things that draw above other options + * + * @param vg NanoVG context + * @param x x position + * @param y y position + */ + public void drawLast(long vg, int x, int y) { + + } + + /** * Function that gets called when a key is typed * * @param key char that has been typed 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; } } diff --git a/src/main/java/io/polyfrost/oneconfig/gui/pages/ModConfigPage.java b/src/main/java/io/polyfrost/oneconfig/gui/pages/ModConfigPage.java index 4827ebe..f3224b5 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/pages/ModConfigPage.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/pages/ModConfigPage.java @@ -22,11 +22,13 @@ public class ModConfigPage extends Page { int optionX = x + 30; int optionY = y + (page.categories.size() == 1 ? 16 : 64); + // Top page buttons for (ConfigPageButton page : page.categories.get(selectedCategory).topPages) { page.draw(vg, optionX, optionY); optionY += page.getHeight() + 16; } + // Background int backgroundSize = 48; for (String subCategory : page.categories.get(selectedCategory).subcategories.keySet()) { backgroundSize += 32; @@ -45,7 +47,9 @@ public class ModConfigPage extends Page { } RenderManager.drawRoundedRect(vg, x + 14, optionY, 1024, backgroundSize, OneConfigConfig.GRAY_900, 20); + // draw options optionY += 16; + int optionLastY = optionX; for (String subCategory : page.categories.get(selectedCategory).subcategories.keySet()) { RenderManager.drawString(vg, subCategory, optionX, optionY + 16, OneConfigConfig.WHITE_90, 24f, Fonts.INTER_MEDIUM); optionY += 48; @@ -66,10 +70,30 @@ public class ModConfigPage extends Page { } optionY += 16; + // Bottom page buttons for (ConfigPageButton page : page.categories.get(selectedCategory).bottomPages) { page.draw(vg, optionX, optionY); optionY += page.getHeight() + 16; } + + // Draw last options + for (String subCategory : page.categories.get(selectedCategory).subcategories.keySet()) { + optionLastY += 48; + for (int i = 0; i < page.categories.get(selectedCategory).subcategories.get(subCategory).size(); i++) { + BasicOption option = page.categories.get(selectedCategory).subcategories.get(subCategory).get(i); + option.drawLast(vg, optionX, optionLastY); + if (i + 1 < page.categories.get(selectedCategory).subcategories.get(subCategory).size()) { + BasicOption nextOption = page.categories.get(selectedCategory).subcategories.get(subCategory).get(i + 1); + if (option.size == 1 && option.hasHalfSize() && nextOption.size == 1 && nextOption.hasHalfSize()) { + nextOption.drawLast(vg, optionX + 512, optionLastY); + optionLastY += Math.max(option.getHeight(), nextOption.getHeight()) + 16; + i++; + continue; + } + } + optionLastY += option.getHeight() + 16; + } + } } @Override |