diff options
Diffstat (limited to 'src/main')
24 files changed, 159 insertions, 135 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java b/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java index 407afdf..d0697bd 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java @@ -37,14 +37,14 @@ public class OneConfigConfig extends Config { public static final int GRAY_300 = new Color(73, 79, 92, 255).getRGB(); // Gray 300 // button gray hover public static final int GRAY_200 = new Color(100, 107, 125, 255).getRGB(); // Gray 200 public static final int GRAY_400_80 = new Color(55, 59, 69, 204).getRGB(); // Gray 400 80% // button gray pressed - public static final int BLUE_800 = new Color(13, 51, 128, 255).getRGB(); // Blue 800 - public static final int BLUE_700 = new Color(18, 71, 178, 255).getRGB(); // Blue 700 - public static final int BLUE_700_80 = new Color(18, 71, 178, 204).getRGB(); // Blue 700 80% - public static final int BLUE_600 = new Color(20, 82, 204, 255).getRGB(); // Blue 600 // button blue normal - public static final int BLUE_600_80 = new Color(20, 82, 204, 204).getRGB(); // Blue 600 80% // button blue click - public static final int BLUE_500 = new Color(25, 103, 255, 255).getRGB(); // Blue 500 // button blue hover - public static final int BLUE_400 = new Color(48, 129, 242, 255).getRGB(); - public static final int BLUE_400_80 = new Color(48, 129, 242, 204).getRGB(); + public static final int PRIMARY_800 = new Color(13, 51, 128, 255).getRGB(); // Blue 800 + public static final int PRIMARY_700 = new Color(18, 71, 178, 255).getRGB(); // Blue 700 + public static final int PRIMARY_700_80 = new Color(18, 71, 178, 204).getRGB(); // Blue 700 80% + public static final int PRIMARY_600 = new Color(20, 82, 204, 255).getRGB(); // Blue 600 // button blue normal + public static final int PRIMARY_600_80 = new Color(20, 82, 204, 204).getRGB(); // Blue 600 80% // button blue click + public static final int PRIMARY_500 = new Color(25, 103, 255, 255).getRGB(); // Blue 500 // button blue hover + public static final int PRIMARY_400 = new Color(48, 129, 242, 255).getRGB(); + public static final int PRIMARY_400_80 = new Color(48, 129, 242, 204).getRGB(); public static final int WHITE_50 = new Color(255, 255, 255, 127).getRGB(); // White 60% public static final int WHITE_60 = new Color(255, 255, 255, 153).getRGB(); // White 60% public static final int WHITE_80 = new Color(255, 255, 255, 204).getRGB(); // White 80% diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java index 884b2d1..21686cd 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java @@ -10,7 +10,6 @@ import cc.polyfrost.oneconfig.lwjgl.OneColor; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; -import cc.polyfrost.oneconfig.lwjgl.scissor.Scissor; import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager; import cc.polyfrost.oneconfig.utils.InputUtils; import cc.polyfrost.oneconfig.utils.MathUtils; @@ -102,22 +101,22 @@ public class OneConfigGui extends UScreen { if (previousPages.size() == 0) { backArrow.disable(true); - RenderManager.withAlpha(vg, 0.5f); + RenderManager.setAlpha(vg, 0.5f); } else { backArrow.disable(false); - if (!backArrow.isHovered() || Mouse.isButtonDown(0)) RenderManager.withAlpha(vg, 0.8f); + if (!backArrow.isHovered() || Mouse.isButtonDown(0)) RenderManager.setAlpha(vg, 0.8f); } RenderManager.drawSvg(vg, SVGs.ARROW_CIRCLE_LEFT, x + 249, y + 25, 22, 22); - RenderManager.withAlpha(vg, 1f); + RenderManager.setAlpha(vg, 1f); if (nextPages.size() == 0) { forwardArrow.disable(true); - RenderManager.withAlpha(vg, 0.5f); + RenderManager.setAlpha(vg, 0.5f); } else { forwardArrow.disable(false); - if (!forwardArrow.isHovered() || Mouse.isButtonDown(0)) RenderManager.withAlpha(vg, 0.8f); + if (!forwardArrow.isHovered() || Mouse.isButtonDown(0)) RenderManager.setAlpha(vg, 0.8f); } RenderManager.drawSvg(vg, SVGs.ARROW_CIRCLE_RIGHT, x + 289, y + 25, 22, 22); - RenderManager.withAlpha(vg, 1f); + RenderManager.setAlpha(vg, 1f); if (backArrow.isClicked() && previousPages.size() > 0) { try { @@ -135,7 +134,7 @@ public class OneConfigGui extends UScreen { } } - Scissor scissor = ScissorManager.scissor(vg, x + 224, y + 88, 1056, 698); + ScissorManager.scissor(vg, x + 224, y + 88, 1056, 698); if (prevPage != null) { pageProgress = MathUtils.easeInOutCirc(50, pageProgress, 832 - pageProgress, 600); prevPage.scrollWithDraw(vg, (int) (x - pageProgress), y + 72); @@ -148,7 +147,7 @@ public class OneConfigGui extends UScreen { } else { currentPage.scrollWithDraw(vg, (int) (x - pageProgress), y + 72); } - ScissorManager.resetScissor(vg, scissor); + ScissorManager.clearScissors(vg); float breadcrumbX = x + 336; for (int i = 0; i < parents.size(); i++) { diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java index 78b3a3c..c86dc81 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java @@ -38,7 +38,7 @@ public class SideBar { public void draw(long vg, int x, int y) { currentY = MathUtils.easeInOutCirc(50, currentY, targetY - currentY, 400); - RenderManager.drawRoundedRect(vg, x + 16, y + currentY, 192, 36, OneConfigConfig.BLUE_600, OneConfigConfig.CORNER_RADIUS); + RenderManager.drawRoundedRect(vg, x + 16, y + currentY, 192, 36, OneConfigConfig.PRIMARY_600, OneConfigConfig.CORNER_RADIUS); int i = 0; if (targetY == 0) { targetY = 96; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java index 2b2f590..24ea612 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java @@ -5,7 +5,6 @@ import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.gui.pages.Page; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; -import cc.polyfrost.oneconfig.lwjgl.image.Images; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; import cc.polyfrost.oneconfig.utils.ColorUtils; import org.jetbrains.annotations.NotNull; @@ -128,7 +127,7 @@ public class BasicButton extends BasicElement { currentColor = ColorUtils.getColor(currentColor, colorPalette, hovered, clicked); } else { if (toggled) { - currentColor = ColorUtils.smoothColor(currentColor, OneConfigConfig.GRAY_500, OneConfigConfig.BLUE_600, true, 30f); + currentColor = ColorUtils.smoothColor(currentColor, OneConfigConfig.GRAY_500, OneConfigConfig.PRIMARY_600, true, 30f); } else currentColor = ColorUtils.getColor(currentColor, colorPalette, hovered, clicked); } } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java index dc257a8..f32abc3 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java @@ -107,7 +107,7 @@ public class ColorSelector { // TODO favorite stuff RenderManager.drawRoundedRect(vg, x + 16, y + 64, 384, 32, OneConfigConfig.GRAY_500, 12f); - RenderManager.drawRoundedRect(vg, x + 18 + (percentMove * 128), y + 66, 124, 28, OneConfigConfig.BLUE_600, 10f); + RenderManager.drawRoundedRect(vg, x + 18 + (percentMove * 128), y + 66, 124, 28, OneConfigConfig.PRIMARY_600, 10f); int i = 18; for(BasicElement button : buttons) { button.draw(vg, x + i, y + 66); @@ -361,7 +361,7 @@ public class ColorSelector { @Override public void draw(long vg, int x, int y) { - RenderManager.drawRoundedRect(vg, x, y, 32, 32, toggled ? OneConfigConfig.BLUE_600 : OneConfigConfig.GRAY_300, 12f); + RenderManager.drawRoundedRect(vg, x, y, 32, 32, toggled ? OneConfigConfig.PRIMARY_600 : OneConfigConfig.GRAY_300, 12f); RenderManager.drawRoundedRect(vg, x + 2, y + 2, 28, 28, OneConfigConfig.GRAY_800, 8f); RenderManager.drawRoundedRect(vg, x + 4, y + 4, 24, 24, color.getRGB(), 8f); } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java index 9518579..d11956d 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java @@ -3,7 +3,6 @@ package cc.polyfrost.oneconfig.gui.elements; import cc.polyfrost.oneconfig.OneConfig; import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.config.data.Mod; -import cc.polyfrost.oneconfig.config.data.ModType; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.pages.ModConfigPage; import cc.polyfrost.oneconfig.lwjgl.RenderManager; @@ -25,7 +24,7 @@ public class ModCard extends BasicElement { private final BasicElement favoriteHitbox = new BasicElement(32, 32, -2, true); private boolean active, disabled, favorite; private int colorGray = OneConfigConfig.GRAY_600; - private int colorPrimary = OneConfigConfig.BLUE_600; + private int colorPrimary = OneConfigConfig.PRIMARY_600; private boolean isHoveredMain = false; public ModCard(@NotNull Mod mod, @Nullable String iconPath, boolean active, boolean disabled, boolean favorite) { @@ -42,7 +41,7 @@ public class ModCard extends BasicElement { @Override public void draw(long vg, int x, int y) { - if (disabled) RenderManager.withAlpha(vg, 0.5f); + if (disabled) RenderManager.setAlpha(vg, 0.5f); RenderManager.drawRoundedRectVaried(vg, x, y, width, 87, colorGray, 12f, 12f, 0f, 0f); RenderManager.drawRoundedRectVaried(vg, x, y + 87, width, 32, colorPrimary, 0f, 0f, 12f, 12f); RenderManager.drawLine(vg, x, y + 86, x + width, y + 86, 2, OneConfigConfig.GRAY_300); @@ -78,7 +77,7 @@ public class ModCard extends BasicElement { if (!active & disabled) toggled = false; active = toggled; - RenderManager.withAlpha(vg, 1f); + RenderManager.setAlpha(vg, 1f); } public void onClick() { diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/Slider.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/Slider.java index f03ecfc..08a2823 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/Slider.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/Slider.java @@ -24,7 +24,7 @@ public class Slider extends BasicElement { public void draw(long vg, int x, int y) { update(x, y); RenderManager.drawRoundedRect(vg, x, y + 2, width, height - 4, OneConfigConfig.GRAY_300, 3f); - RenderManager.drawRoundedRect(vg, x, y + 2, width * value, height - 4, OneConfigConfig.BLUE_500, 3f); + RenderManager.drawRoundedRect(vg, x, y + 2, width * value, height - 4, OneConfigConfig.PRIMARY_500, 3f); RenderManager.drawRoundedRect(vg, currentDragPoint - dragPointerSize / 2, y - 8, 24, 24, OneConfigConfig.WHITE, 12f); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java index d2a996d..afedef4 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigButton.java @@ -24,10 +24,10 @@ public class ConfigButton extends BasicOption { @Override public void draw(long vg, int x, int y) { button.disable(!isEnabled()); - if(!isEnabled()) RenderManager.withAlpha(vg, 0.5f); + if(!isEnabled()) RenderManager.setAlpha(vg, 0.5f); RenderManager.drawString(vg, name, x, y + 17, OneConfigConfig.WHITE, 14f, Fonts.MEDIUM); button.draw(vg, x + (size == 1 ? 352 : 736), y); - RenderManager.withAlpha(vg, 1f); + RenderManager.setAlpha(vg, 1f); } @Override diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java index b969ce1..764edcf 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigCheckbox.java @@ -2,7 +2,6 @@ package cc.polyfrost.oneconfig.gui.elements.config; import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.config.interfaces.BasicOption; -import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; @@ -23,7 +22,7 @@ public class ConfigCheckbox extends BasicOption { @Override public void draw(long vg, int x, int y) { - if (!isEnabled()) RenderManager.withAlpha(vg, 0.5f); + if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); boolean toggled = false; try { toggled = (boolean) get(); @@ -49,14 +48,14 @@ public class ConfigCheckbox extends BasicOption { RenderManager.drawString(vg, name, x + 32, y + 17, OneConfigConfig.WHITE_90, 14f, Fonts.MEDIUM); percentOn = MathUtils.clamp(MathUtils.easeOut(percentOn, toggled ? 1f : 0f, 50f)); if (percentOn != 0 && percentOn != 1f) { - RenderManager.drawRoundedRect(vg, x, y + 4, 24, 24, ColorUtils.setAlpha(OneConfigConfig.BLUE_500, (int) (percentOn * 255)), 6f); + RenderManager.drawRoundedRect(vg, x, y + 4, 24, 24, ColorUtils.setAlpha(OneConfigConfig.PRIMARY_500, (int) (percentOn * 255)), 6f); RenderManager.drawSvg(vg, SVGs.CHECKBOX_TICK, x, y + 4, 24, 24, new Color(1f, 1f, 1f, percentOn).getRGB()); } else if (percentOn != 0) { - RenderManager.drawRoundedRect(vg, x, y + 4, 24, 24, OneConfigConfig.BLUE_500, 6f); + RenderManager.drawRoundedRect(vg, x, y + 4, 24, 24, OneConfigConfig.PRIMARY_500, 6f); RenderManager.drawSvg(vg, SVGs.CHECKBOX_TICK, x, y + 4, 24, 24); } - if(percentOn != 0 && hover) RenderManager.drawHollowRoundRect(vg, x - 1, y + 3, 24, 24, OneConfigConfig.BLUE_600, 6f, 2f); - RenderManager.withAlpha(vg, 1f); + if(percentOn != 0 && hover) RenderManager.drawHollowRoundRect(vg, x - 1, y + 3, 24, 24, OneConfigConfig.PRIMARY_600, 6f, 2f); + RenderManager.setAlpha(vg, 1f); } @Override diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java index d39566d..51d43ea 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDropdown.java @@ -2,7 +2,6 @@ package cc.polyfrost.oneconfig.gui.elements.config; import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.config.interfaces.BasicOption; -import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; @@ -26,7 +25,7 @@ public class ConfigDropdown extends BasicOption { // TODO: remove dividers and f @Override public void draw(long vg, int x, int y) { - if (!isEnabled()) RenderManager.withAlpha(vg, 0.5f); + if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); RenderManager.drawString(vg, name, x, y + 16, OneConfigConfig.WHITE_90, 14f, Fonts.MEDIUM); boolean hovered; @@ -48,19 +47,19 @@ public class ConfigDropdown extends BasicOption { // TODO: remove dividers and f } catch (IllegalAccessException ignored) { } - if (hovered && Mouse.isButtonDown(0)) RenderManager.withAlpha(vg, 0.8f); + if (hovered && Mouse.isButtonDown(0)) RenderManager.setAlpha(vg, 0.8f); if (size == 1) { RenderManager.drawRoundedRect(vg, x + 224, y, 256, 32, backgroundColor, 12); RenderManager.drawString(vg, options[selected], x + 236, y + 16, OneConfigConfig.WHITE_80, 14f, Fonts.MEDIUM); - RenderManager.drawRoundedRect(vg, x + 452, y + 4, 24, 24, OneConfigConfig.BLUE_600, 8); + RenderManager.drawRoundedRect(vg, x + 452, y + 4, 24, 24, OneConfigConfig.PRIMARY_600, 8); RenderManager.drawSvg(vg, SVGs.DROPDOWN_LIST, x + 452, y + 4, 24, 24); } else { RenderManager.drawRoundedRect(vg, x + 352, y, 640, 32, backgroundColor, 12); RenderManager.drawString(vg, options[selected], x + 364, y + 16, OneConfigConfig.WHITE_80, 14f, Fonts.MEDIUM); - RenderManager.drawRoundedRect(vg, x + 964, y + 4, 24, 24, OneConfigConfig.BLUE_600, 8); + RenderManager.drawRoundedRect(vg, x + 964, y + 4, 24, 24, OneConfigConfig.PRIMARY_600, 8); RenderManager.drawSvg(vg, SVGs.DROPDOWN_LIST, x + 964, y + 4, 24, 24); } - RenderManager.withAlpha(vg, 1f); + RenderManager.setAlpha(vg, 1f); } @Override @@ -71,22 +70,22 @@ public class ConfigDropdown extends BasicOption { // TODO: remove dividers and f if (size == 1) hovered = InputUtils.isAreaHovered(x + 224, y, 256, 32); else hovered = InputUtils.isAreaHovered(x + 352, y, 640, 32); - backgroundColor = ColorUtils.smoothColor(backgroundColor, OneConfigConfig.BLUE_800, OneConfigConfig.BLUE_700, hovered, 100); + backgroundColor = ColorUtils.smoothColor(backgroundColor, OneConfigConfig.PRIMARY_800, OneConfigConfig.PRIMARY_700, hovered, 100); int selected = 0; try { selected = (int) get(); } catch (IllegalAccessException ignored) { } - if (hovered && Mouse.isButtonDown(0)) RenderManager.withAlpha(vg, 0.8f); + if (hovered && Mouse.isButtonDown(0)) RenderManager.setAlpha(vg, 0.8f); if (size == 1) { RenderManager.drawRoundedRect(vg, x + 224, y, 256, 32, backgroundColor, 12); RenderManager.drawString(vg, options[selected], x + 236, y + 16, OneConfigConfig.WHITE_80, 14f, Fonts.MEDIUM); - if (hovered && Mouse.isButtonDown(0)) RenderManager.withAlpha(vg, 0.8f); - RenderManager.drawRoundedRect(vg, x + 452, y + 4, 24, 24, OneConfigConfig.BLUE_600, 8); + if (hovered && Mouse.isButtonDown(0)) RenderManager.setAlpha(vg, 0.8f); + RenderManager.drawRoundedRect(vg, x + 452, y + 4, 24, 24, OneConfigConfig.PRIMARY_600, 8); RenderManager.drawSvg(vg, SVGs.DROPDOWN_LIST, x + 452, y + 4, 24, 24); - RenderManager.withAlpha(vg, 1f); + RenderManager.setAlpha(vg, 1f); RenderManager.drawRoundedRect(vg, x + 224, y + 48, 256, options.length * 32 + 8, OneConfigConfig.GRAY_700, 12); RenderManager.drawHollowRoundRect(vg, x + 223, y + 47, 258, options.length * 32 + 10, new Color(204, 204, 204, 77).getRGB(), 12, 1); int optionY = y + 52; @@ -94,9 +93,9 @@ public class ConfigDropdown extends BasicOption { // TODO: remove dividers and f int color = OneConfigConfig.WHITE_80; boolean optionHovered = InputUtils.isAreaHovered(x + 224, optionY, 252, 32); if (optionHovered && Mouse.isButtonDown(0)) { - RenderManager.drawRoundedRect(vg, x + 228, optionY + 2, 248, 28, OneConfigConfig.BLUE_700_80, 8); + RenderManager.drawRoundedRect(vg, x + 228, optionY + 2, 248, 28, OneConfigConfig.PRIMARY_700_80, 8); } else if (optionHovered) { - RenderManager.drawRoundedRect(vg, x + 228, optionY + 2, 248, 28, OneConfigConfig.BLUE_700, 8); + RenderManager.drawRoundedRect(vg, x + 228, optionY + 2, 248, 28, OneConfigConfig.PRIMARY_700, 8); color = OneConfigConfig.WHITE; } if (optionHovered && InputUtils.isClicked(true)) { @@ -114,11 +113,11 @@ public class ConfigDropdown extends BasicOption { // TODO: remove dividers and f } else { RenderManager.drawRoundedRect(vg, x + 352, y, 640, 32, backgroundColor, 12); RenderManager.drawString(vg, options[selected], x + 364, y + 16, OneConfigConfig.WHITE_80, 14f, Fonts.MEDIUM); - if (hovered && Mouse.isButtonDown(0)) RenderManager.withAlpha(vg, 0.8f); - RenderManager.drawRoundedRect(vg, x + 964, y + 4, 24, 24, OneConfigConfig.BLUE_600, 8); + if (hovered && Mouse.isButtonDown(0)) RenderManager.setAlpha(vg, 0.8f); + RenderManager.drawRoundedRect(vg, x + 964, y + 4, 24, 24, OneConfigConfig.PRIMARY_600, 8); RenderManager.drawSvg(vg, SVGs.DROPDOWN_LIST, x + 964, y + 4, 24, 24); - RenderManager.withAlpha(vg, 1f); + RenderManager.setAlpha(vg, 1f); RenderManager.drawRoundedRect(vg, x + 352, y + 48, 640, options.length * 32 + 8, OneConfigConfig.GRAY_700, 12); RenderManager.drawHollowRoundRect(vg, x + 351, y + 47, 642, options.length * 32 + 10, new Color(204, 204, 204, 77).getRGB(), 12, 1); int optionY = y + 52; @@ -126,9 +125,9 @@ public class ConfigDropdown extends BasicOption { // TODO: remove dividers and f int color = OneConfigConfig.WHITE_80; boolean optionHovered = InputUtils.isAreaHovered(x + 352, optionY, 640, 36); if (optionHovered && Mouse.isButtonDown(0)) { - RenderManager.drawRoundedRect(vg, x + 356, optionY + 2, 632, 28, OneConfigConfig.BLUE_700_80, 8); + RenderManager.drawRoundedRect(vg, x + 356, optionY + 2, 632, 28, OneConfigConfig.PRIMARY_700_80, 8); } else if (optionHovered) { - RenderManager.drawRoundedRect(vg, x + 356, optionY + 2, 632, 28, OneConfigConfig.BLUE_700, 8); + RenderManager.drawRoundedRect(vg, x + 356, optionY + 2, 632, 28, OneConfigConfig.PRIMARY_700, 8); color = OneConfigConfig.WHITE; } @@ -145,7 +144,7 @@ public class ConfigDropdown extends BasicOption { // TODO: remove dividers and f optionY += 32; } } - RenderManager.withAlpha(vg, 1f); + RenderManager.setAlpha(vg, 1f); } @Override diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java index a87db85..08343a9 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigDualOption.java @@ -2,7 +2,6 @@ package cc.polyfrost.oneconfig.gui.elements.config; import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.config.interfaces.BasicOption; -import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.utils.ColorUtils; @@ -14,8 +13,6 @@ import java.lang.reflect.Field; public class ConfigDualOption extends BasicOption { private float percentMove = 0f; private final String left, right; - int colorSelected; - int colorUnselected; public ConfigDualOption(Field field, Object parent, String name, int size, String[] options) { super(field, parent, name, size); @@ -36,19 +33,21 @@ public class ConfigDualOption extends BasicOption { toggled = (boolean) get(); } catch (IllegalAccessException ignored) { } - if (!isEnabled()) RenderManager.withAlpha(vg, 0.5f); - boolean hovered = InputUtils.isAreaHovered(x + 226, y, 256, 32) && isEnabled(); - colorSelected = ColorUtils.smoothColor(colorSelected, OneConfigConfig.BLUE_600, OneConfigConfig.BLUE_500, hovered, 40f); - colorUnselected = ColorUtils.smoothColor(colorUnselected, OneConfigConfig.GRAY_500, OneConfigConfig.GRAY_400, hovered, 40f); + if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); + boolean hoveredLeft = InputUtils.isAreaHovered(x + 226, y, 128, 32) && isEnabled(); + boolean hoveredRight = InputUtils.isAreaHovered(x + 354, y, 128, 32) && isEnabled(); RenderManager.drawString(vg, name, x, y + 16, OneConfigConfig.WHITE_90, 14f, Fonts.MEDIUM); - RenderManager.drawRoundedRect(vg, x + 226, y, 256, 32, colorUnselected, 12f); + RenderManager.drawRoundedRect(vg, x + 226, y, 256, 32, OneConfigConfig.GRAY_600, 12f); int x1 = (int) (x + 228 + (percentMove * 128)); - RenderManager.drawRoundedRect(vg, x1, y + 2, 124, 28, colorSelected, 10f); - RenderManager.drawString(vg, left, x + 290 - RenderManager.getTextWidth(vg, left, 12f, Fonts.MEDIUM) / 2, y + 17, OneConfigConfig.WHITE_90, 12f, Fonts.MEDIUM); - RenderManager.drawString(vg, right, x + 418 - RenderManager.getTextWidth(vg, right, 12f, Fonts.MEDIUM) / 2, y + 17, OneConfigConfig.WHITE_90, 12f, Fonts.MEDIUM); - - RenderManager.withAlpha(vg, 1); - if (hovered && InputUtils.isClicked()) { + RenderManager.drawRoundedRect(vg, x1, y + 2, 124, 28, OneConfigConfig.PRIMARY_600, 10f); + if (!hoveredLeft && isEnabled()) RenderManager.setAlpha(vg, 0.8f); + RenderManager.drawString(vg, left, x + 290 - RenderManager.getTextWidth(vg, left, 12f, Fonts.MEDIUM) / 2, y + 17, OneConfigConfig.WHITE, 12f, Fonts.MEDIUM); + if (isEnabled()) RenderManager.setAlpha(vg, 1f); + if (!hoveredRight && isEnabled()) RenderManager.setAlpha(vg, 0.8f); + RenderManager.drawString(vg, right, x + 418 - RenderManager.getTextWidth(vg, right, 12f, Fonts.MEDIUM) / 2, y + 17, OneConfigConfig.WHITE, 12f, Fonts.MEDIUM); + + RenderManager.setAlpha(vg, 1); + if ((hoveredLeft && toggled || hoveredRight && !toggled) && InputUtils.isClicked()) { toggled = !toggled; try { set(toggled); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java index 0ddcab3..4ea65f9 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java @@ -24,7 +24,7 @@ public class ConfigKeyBind extends BasicOption { @Override public void draw(long vg, int x, int y) { - if (!isEnabled()) RenderManager.withAlpha(vg, 0.5f); + if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); RenderManager.drawString(vg, name, x, y + 17, OneConfigConfig.WHITE, 14f, Fonts.MEDIUM); OneKeyBind keyBind = getKeyBind(); String text = keyBind.getDisplay(); @@ -45,7 +45,7 @@ public class ConfigKeyBind extends BasicOption { } else if (text.equals("")) text = "None"; button.setText(text); button.draw(vg, x + (size == 1 ? 224 : 736), y); - RenderManager.withAlpha(vg, 1f); + RenderManager.setAlpha(vg, 1f); } @Override diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java index 5878cc0..edd44e1 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigPageButton.java @@ -32,8 +32,8 @@ public class ConfigPageButton extends BasicOption { boolean clicked = hovered && InputUtils.isClicked(); backgroundColor = ColorUtils.smoothColor(backgroundColor, OneConfigConfig.GRAY_500, OneConfigConfig.GRAY_400, hovered, 100); - if (hovered && Mouse.isButtonDown(0)) RenderManager.withAlpha(vg, 0.8f); - if (!isEnabled()) RenderManager.withAlpha(vg, 0.5f); + if (hovered && Mouse.isButtonDown(0)) RenderManager.setAlpha(vg, 0.8f); + if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); RenderManager.drawRoundedRect(vg, x - 16, y, 1024, height, backgroundColor, 20); RenderManager.drawString(vg, name, x + 10, y + 32, OneConfigConfig.WHITE_90, 24, Fonts.MEDIUM); @@ -42,7 +42,7 @@ public class ConfigPageButton extends BasicOption { RenderManager.drawSvg(vg, SVGs.CHEVRON_RIGHT, x + 981f, y + (description.equals("") ? 20f : 36f), 13, 22); if (clicked) OneConfigGui.INSTANCE.openPage(new ModConfigPage(page)); - RenderManager.withAlpha(vg, 1f); + RenderManager.setAlpha(vg, 1f); } @Override diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java index 3f8a2d9..b367934 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSlider.java @@ -33,7 +33,7 @@ public class ConfigSlider extends BasicOption { float value = 0; boolean hovered = InputUtils.isAreaHovered(x + 352, y, 512, 32) && isEnabled(); inputField.disable(!isEnabled()); - if (!isEnabled()) RenderManager.withAlpha(vg, 0.5f); + if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); boolean isMouseDown = Mouse.isButtonDown(0); if (hovered && isMouseDown && !mouseWasDown) dragging = true; mouseWasDown = isMouseDown; @@ -69,17 +69,17 @@ public class ConfigSlider extends BasicOption { RenderManager.drawString(vg, name, x, y + 17, OneConfigConfig.WHITE_90, 14f, Fonts.MEDIUM); RenderManager.drawRoundedRect(vg, x + 352, y + 13, 512, 6, OneConfigConfig.GRAY_300, 4f); - RenderManager.drawRoundedRect(vg, x + 352, y + 13, xCoordinate - x - 352, 6, OneConfigConfig.BLUE_500, 4f); + RenderManager.drawRoundedRect(vg, x + 352, y + 13, xCoordinate - x - 352, 6, OneConfigConfig.PRIMARY_500, 4f); if (step > 0) { for (float i = x + 352; i <= x + 864; i += 512 / ((max - min) / step)) { - int color = xCoordinate > i - 2 ? OneConfigConfig.BLUE_500 : OneConfigConfig.GRAY_300; + int color = xCoordinate > i - 2 ? OneConfigConfig.PRIMARY_500 : OneConfigConfig.GRAY_300; RenderManager.drawRoundedRect(vg, i - 2, y + 9, 4, 14, color, 2f); } } if (step == 0) RenderManager.drawRoundedRect(vg, xCoordinate - 12, y + 4, 24, 24, OneConfigConfig.WHITE, 12f); else RenderManager.drawRoundedRect(vg, xCoordinate - 4, y + 4, 8, 24, OneConfigConfig.WHITE, 4f); inputField.draw(vg, x + 892, y); - RenderManager.withAlpha(vg, 1f); + RenderManager.setAlpha(vg, 1f); } private int getStepCoordinate(int xCoordinate, int x) { diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java index 4c3658f..a63a106 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java @@ -2,7 +2,6 @@ package cc.polyfrost.oneconfig.gui.elements.config; import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.config.interfaces.BasicOption; -import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.utils.ColorUtils; @@ -31,8 +30,8 @@ public class ConfigSwitch extends BasicOption { int x2 = x + 3 + (int) (percentOn * 18); boolean hovered = InputUtils.isAreaHovered(x, y, 42, 32); colorDisabled = ColorUtils.smoothColor(colorDisabled, OneConfigConfig.GRAY_400, OneConfigConfig.GRAY_300, hovered, 40f); - colorEnabled = ColorUtils.smoothColor(colorEnabled, OneConfigConfig.BLUE_600, OneConfigConfig.BLUE_500, hovered, 40f); - if (!isEnabled()) RenderManager.withAlpha(vg, 0.5f); + colorEnabled = ColorUtils.smoothColor(colorEnabled, OneConfigConfig.PRIMARY_600, OneConfigConfig.PRIMARY_500, hovered, 40f); + if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); RenderManager.drawRoundedRect(vg, x, y + 4, 42, 24, colorDisabled, 12f); if (percentOn != 0) RenderManager.drawRoundedRect(vg, x, y + 4, 42, 24, ColorUtils.setAlpha(colorEnabled, (int) (255 * percentOn)), 12f); @@ -49,7 +48,7 @@ public class ConfigSwitch extends BasicOption { } } percentOn = MathUtils.clamp(MathUtils.easeOut(percentOn, toggled ? 1f : 0f, 75)); - RenderManager.withAlpha(vg, 1f); + RenderManager.setAlpha(vg, 1f); } @Override diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java index 7398ddb..4fa57b8 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigTextBox.java @@ -9,7 +9,6 @@ import cc.polyfrost.oneconfig.lwjgl.image.SVGs; import cc.polyfrost.oneconfig.utils.InputUtils; import org.lwjgl.input.Mouse; -import java.awt.*; import java.lang.reflect.Field; public class ConfigTextBox extends BasicOption { @@ -26,7 +25,7 @@ public class ConfigTextBox extends BasicOption { @Override public void draw(long vg, int x, int y) { - if (!isEnabled()) RenderManager.withAlpha(vg, 0.5f); + if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); textField.disable(!isEnabled()); RenderManager.drawString(vg, name, x, y + 16, OneConfigConfig.WHITE_90, 14, Fonts.MEDIUM); @@ -45,10 +44,10 @@ public class ConfigTextBox extends BasicOption { boolean hovered = InputUtils.isAreaHovered(x + 967, y + 7, 18, 18) && isEnabled(); int color = hovered ? OneConfigConfig.WHITE : OneConfigConfig.WHITE_80; if (hovered && InputUtils.isClicked()) textField.setPassword(!textField.getPassword()); - if (hovered && Mouse.isButtonDown(0)) RenderManager.withAlpha(vg, 0.5f); + if (hovered && Mouse.isButtonDown(0)) RenderManager.setAlpha(vg, 0.5f); RenderManager.drawSvg(vg, icon, x + 967, y + 7, 18, 18, color); } - RenderManager.withAlpha(vg, 1f); + RenderManager.setAlpha(vg, 1f); } @Override diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java index 98aa6e0..f11a3fd 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java @@ -2,7 +2,6 @@ package cc.polyfrost.oneconfig.gui.elements.config; import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.config.interfaces.BasicOption; -import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; @@ -38,7 +37,7 @@ public class ConfigUniSelector extends BasicOption { selected = (int) get(); } catch (IllegalAccessException ignored) { } - if (!isEnabled()) RenderManager.withAlpha(vg, 0.5f); + if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); String option = options[selected] + " " + (selected + 1) + "/" + options.length; RenderManager.drawString(vg, name, x, y + 16, OneConfigConfig.WHITE_90, 14f, Fonts.MEDIUM); @@ -54,14 +53,14 @@ public class ConfigUniSelector extends BasicOption { boolean hoveredLeft = InputUtils.isAreaHovered(x + 231, y + 7, 18, 18) && selected > 0 && isEnabled(); boolean hoveredRight = InputUtils.isAreaHovered(x + 455, y + 7, 18, 18) && selected < options.length - 1 && isEnabled(); - colorLeft = ColorUtils.smoothColor(colorLeft, OneConfigConfig.BLUE_500, OneConfigConfig.BLUE_400, hoveredLeft, 40f); - colorRight = ColorUtils.smoothColor(colorRight, OneConfigConfig.BLUE_500, OneConfigConfig.BLUE_400, hoveredRight, 40f); + colorLeft = ColorUtils.smoothColor(colorLeft, OneConfigConfig.PRIMARY_500, OneConfigConfig.PRIMARY_400, hoveredLeft, 40f); + colorRight = ColorUtils.smoothColor(colorRight, OneConfigConfig.PRIMARY_500, OneConfigConfig.PRIMARY_400, hoveredRight, 40f); - if (selected <= 0 && isEnabled()) RenderManager.withAlpha(vg, 0.5f); + if (selected <= 0 && isEnabled()) RenderManager.setAlpha(vg, 0.5f); RenderManager.drawSvg(vg, SVGs.CHEVRON_LEFT, x + 231, y + 7, 18, 18, colorLeft); - if (isEnabled()) RenderManager.withAlpha(vg, selected >= options.length - 1 ? 0.5f : 1f); + if (isEnabled()) RenderManager.setAlpha(vg, selected >= options.length - 1 ? 0.5f : 1f); RenderManager.drawSvg(vg, SVGs.CHEVRON_RIGHT, x + 455, y + 7, 18, 18, colorRight); - if (isEnabled()) RenderManager.withAlpha(vg, 1f); + if (isEnabled()) RenderManager.setAlpha(vg, 1f); if (hoveredLeft && InputUtils.isClicked()) { previous = selected; @@ -82,6 +81,6 @@ public class ConfigUniSelector extends BasicOption { } if (previous != -1) percentMove = MathUtils.easeOut(percentMove, selected < previous ? 1f : 0f, 75); if ((selected < previous ? 1f : 0f) == percentMove) previous = -1; - RenderManager.withAlpha(vg, 1f); + RenderManager.setAlpha(vg, 1f); } } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java index 08e8597..3b6fa43 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java @@ -1,7 +1,6 @@ package cc.polyfrost.oneconfig.gui.elements.text; import cc.polyfrost.oneconfig.config.OneConfigConfig; -import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.elements.BasicElement; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; @@ -61,20 +60,20 @@ public class NumberInputField extends TextInputField { setCurrentValue(current); } if (current >= max && !disabled) { - RenderManager.withAlpha(vg, 0.3f); + RenderManager.setAlpha(vg, 0.3f); upArrow.disable(true); } RenderManager.drawRoundedRectVaried(vg, x + width + 4, y, 12, 14, colorTop, 6f, 6f, 0f, 0f); RenderManager.drawSvg(vg, SVGs.CHEVRON_UP, x + width + 5, y + 2, 10, 10); - if (current >= max && !disabled) RenderManager.withAlpha(vg, 1f); + if (current >= max && !disabled) RenderManager.setAlpha(vg, 1f); if (current <= min && !disabled) { - RenderManager.withAlpha(vg, 0.3f); + RenderManager.setAlpha(vg, 0.3f); downArrow.disable(true); } RenderManager.drawRoundedRectVaried(vg, x + width + 4, y + 14, 12, 14, colorBottom, 0f, 0f, 6f, 6f); RenderManager.drawSvg(vg, SVGs.CHEVRON_DOWN, x + width + 5, y + 15, 10, 10); - RenderManager.withAlpha(vg, 1f); + RenderManager.setAlpha(vg, 1f); try { super.draw(vg, x, y - 2); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java index c08d9f6..6d93be7 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java @@ -8,9 +8,9 @@ import cc.polyfrost.oneconfig.lwjgl.image.SVGs; import cc.polyfrost.oneconfig.lwjgl.scissor.Scissor; import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager; import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.utils.MathUtils; import cc.polyfrost.oneconfig.utils.TextUtils; import cc.polyfrost.oneconfig.libs.universal.UKeyboard; -import kotlin.Pair; import org.jetbrains.annotations.NotNull; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; @@ -19,7 +19,6 @@ import java.awt.*; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.StringSelection; import java.util.ArrayList; -import java.util.Map; public class TextInputField extends BasicElement { @@ -31,6 +30,7 @@ public class TextInputField extends BasicElement { protected int caretPos; protected int x, y; protected float start, end; + protected int startLine, endLine; private long clickTimeD1; protected long vg; protected int prevCaret = 0; @@ -98,9 +98,16 @@ public class TextInputField extends BasicElement { this.y = y; this.vg = vg; try { - Scissor scissor = ScissorManager.scissor(vg, x, y, width, height); int colorOutline = errored ? OneConfigConfig.ERROR_700 : OneConfigConfig.GRAY_700; - RenderManager.drawHollowRoundRect(vg, x, y, width - 0.5f, height - 0.5f, colorOutline, 12f, 2f); + if (!toggled) + RenderManager.drawHollowRoundRect(vg, x, y, width - 0.5f, height - 0.5f, colorOutline, 12f, 2f); + else { + RenderManager.setAlpha(vg, 0.15f); + RenderManager.drawRoundedRect(vg, x - 4, y - 4, width + 8, height + 8, OneConfigConfig.PRIMARY_600, 16); + RenderManager.setAlpha(vg, 1f); + RenderManager.drawHollowRoundRect(vg, x, y, width - 0.5f, height - 0.5f, OneConfigConfig.PRIMARY_600, 12f, 2f); + } + Scissor scissor = ScissorManager.scissor(vg, x, y, width, height); super.update(x, y); if (Mouse.isButtonDown(0) && !InputUtils.isAreaHovered(x - 40, y - 20, width + 90, height + 20)) { onClose(); @@ -123,7 +130,7 @@ public class TextInputField extends BasicElement { wrappedText = TextUtils.wrapText(vg, input, this.width - 24, 14f, Fonts.REGULAR); lines = wrappedText.size(); if (!toggled) caretPos = wrappedText.get(wrappedText.size() - 1).length(); - int caretLine = getCaretLine(caretPos); + int caretLine = (int) MathUtils.clamp(getCaretLine(caretPos), 0, wrappedText.size() - 1); width = RenderManager.getTextWidth(vg, wrappedText.get(caretLine).substring(0, getLineCaret(caretPos, caretLine)), 14f, Fonts.REGULAR); } else if (!password) { width = RenderManager.getTextWidth(vg, input.substring(0, caretPos), 14f, Fonts.REGULAR); @@ -165,13 +172,24 @@ public class TextInputField extends BasicElement { } float halfTextWidth = this.getTextWidth(vg, input) / 2f; if (start != 0f && end != 0f && toggled) { - RenderManager.drawRect(vg, start, y + height / 2f - 10, end, 20, OneConfigConfig.GRAY_300); + if (!multiLine) { + RenderManager.drawRect(vg, start, y + height / 2f - 10, end, 20, OneConfigConfig.GRAY_300); + } else if (startLine == endLine) { + RenderManager.drawRect(vg, start, y + 10 + 24 * startLine, end, 20, OneConfigConfig.GRAY_300); + } else { + RenderManager.drawRect(vg, start, y + 10 + 24 * startLine, this.width - 24, 20, OneConfigConfig.GRAY_300); + for (int i = startLine + 1; i < endLine; i++) { + RenderManager.drawRect(vg, x + 12, y + 10 + 24 * i, this.width - 24, 20, OneConfigConfig.GRAY_300); + } + RenderManager.drawRect(vg, x + 12, y + 10 + 24 * endLine, end, 20, OneConfigConfig.GRAY_300); + } } if (hovered) { if (Mouse.isButtonDown(0) && !isDoubleClick) { if (multiLine) { int caretLine = Math.max(0, Math.min(wrappedText.size() - 1, (int) Math.floor((InputUtils.mouseY() - y - 10) / 24f))); caretPos = calculatePos(InputUtils.mouseX(), wrappedText.get(caretLine)); + for (int i = 0; i < caretLine; i++) caretPos += wrappedText.get(i).length(); } else caretPos = calculatePos(InputUtils.mouseX(), input); if (caretPos > prevCaret) { if (!centered) start = x + 12 + this.getTextWidth(vg, input.substring(0, prevCaret)); @@ -228,7 +246,8 @@ public class TextInputField extends BasicElement { RenderManager.drawString(vg, s.toString(), x + 12, y + height / 2f + 1, color, 14f, Fonts.REGULAR); } ScissorManager.resetScissor(vg, scissor); - } catch (Exception e) { + } catch ( + Exception e) { e.printStackTrace(); } @@ -243,7 +262,7 @@ public class TextInputField extends BasicElement { } return; } - if (UKeyboard.isKeyComboCtrlV(key) || key == Keyboard.KEY_INSERT) { //todo find the UKeyboard equivalent for insert + if (UKeyboard.isKeyComboCtrlV(key) || key == Keyboard.KEY_INSERT) { // TODO: find the UKeyboard equivalent for insert try { String clip = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null).getTransferData(DataFlavor.stringFlavor).toString(); input = input.substring(0, caretPos) + clip + input.substring(caretPos); @@ -274,7 +293,12 @@ public class TextInputField extends BasicElement { caretPos = input.length(); start = !centered ? x + 12 : x + this.width / 2f - this.getTextWidth(vg, input) / 2f; selectedText = input; - end = this.getTextWidth(vg, input); + if (!multiLine) end = this.getTextWidth(vg, input); + if (multiLine) { + end = this.getTextWidth(vg, wrappedText.get(wrappedText.size() - 1)); + startLine = 0; + endLine = wrappedText.size() - 1; + } return; } if (UKeyboard.isKeyComboCtrlX(key)) { @@ -421,10 +445,17 @@ public class TextInputField extends BasicElement { caretPos = input.indexOf(' ', caretPos); if (caretPos == -1) caretPos = input.length(); selectedText = input.substring(prevCaret, caretPos); - if (!centered) start = x + 12 + this.getTextWidth(vg, input.substring(0, prevCaret)); - else - start = x + this.width / 2f - this.getTextWidth(vg, input) / 2f + this.getTextWidth(vg, input.substring(0, prevCaret)); - end = this.getTextWidth(vg, input.substring(prevCaret, caretPos)); + if (multiLine) { + int caretLine = Math.max(0, Math.min(wrappedText.size() - 1, (int) Math.floor((InputUtils.mouseY() - y - 10) / 24f))); + startLine = caretLine; + endLine = caretLine; + start = x + 12 + this.getTextWidth(vg, wrappedText.get(caretLine).substring(0, getLineCaret(prevCaret, startLine))); + end = this.getTextWidth(vg, wrappedText.get(caretLine).substring(getLineCaret(prevCaret, startLine), getLineCaret(caretPos, startLine))); + System.out.println(wrappedText.get(caretLine).substring(getLineCaret(prevCaret, startLine), getLineCaret(caretPos, startLine))); + } else { + start = x + 12 + this.getTextWidth(vg, input.substring(0, prevCaret)); + end = this.getTextWidth(vg, input.substring(prevCaret, caretPos)); + } } private int calculatePos(int pos, String string) { @@ -465,10 +496,8 @@ public class TextInputField extends BasicElement { private int getCaretLine(int caret) { int pos = 0; for (int i = 0; i < wrappedText.size(); i++) { - String text = wrappedText.get(i); - float length = RenderManager.getTextWidth(vg, text, 14.0f, Fonts.REGULAR); - pos += length; - if (pos < caret) continue; + pos += wrappedText.get(i).length(); + if (pos < caret - 1) continue; return i; } return 0; @@ -490,8 +519,8 @@ public class TextInputField extends BasicElement { private int getLineCaret(int caret, int line) { int pos = 0; for (String text : wrappedText) { - float length = RenderManager.getTextWidth(vg, text, 14.0f, Fonts.REGULAR); - if (pos + length < caret) { + int length = text.length(); + if (pos + length < caret - 1) { pos += length; continue; } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java index a65f227..91f4181 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java @@ -7,7 +7,6 @@ import cc.polyfrost.oneconfig.gui.elements.ColorSelector; import cc.polyfrost.oneconfig.lwjgl.OneColor; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; -import cc.polyfrost.oneconfig.lwjgl.image.Images; import cc.polyfrost.oneconfig.lwjgl.image.SVGs; import cc.polyfrost.oneconfig.utils.InputUtils; @@ -23,7 +22,7 @@ public class HomePage extends Page { public void draw(long vg, int x, int y) { RenderManager.drawRoundedRect(vg, x, y, 184, 36, -1, 12f); RenderManager.drawString(vg, "This is a cool string to test pages", x + 32, y + 72, -1, 36f, Fonts.BOLD); - RenderManager.drawRoundedRect(vg, x + 350, y + 310, 300, 200, OneConfigConfig.BLUE_600, 14f); + RenderManager.drawRoundedRect(vg, x + 350, y + 310, 300, 200, OneConfigConfig.PRIMARY_600, 14f); //RenderManager.drawRoundedRect(vg); btn.draw(vg, x + 432, y + 658); if(btn.isClicked()) { diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java index c1df2fe..a04d287 100644 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java @@ -302,7 +302,7 @@ public final class RenderManager { nvgScale(vg, x, y); } - public static void withAlpha(long vg, float alpha) { + public static void setAlpha(long vg, float alpha) { nvgGlobalAlpha(vg, alpha); } diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/scissor/ScissorManager.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/scissor/ScissorManager.java index 0f821c9..1697b7e 100644 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/scissor/ScissorManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/scissor/ScissorManager.java @@ -22,6 +22,11 @@ public class ScissorManager { } } + public static void clearScissors(long vg) { + scissors.clear(); + NanoVG.nvgResetScissor(vg); + } + private static void applyScissors(long vg) { NanoVG.nvgResetScissor(vg); if (scissors.size() <= 0) return; diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/ColorUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/ColorUtils.java index 165d201..400dc39 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/ColorUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/ColorUtils.java @@ -19,7 +19,7 @@ public class ColorUtils { case 0: return OneConfigConfig.GRAY_400_80; case 1: - return OneConfigConfig.BLUE_600_80; + return OneConfigConfig.PRIMARY_600_80; } } @@ -32,7 +32,7 @@ public class ColorUtils { case 0: return getColorComponents(color, splitColor(OneConfigConfig.GRAY_600), splitColor(OneConfigConfig.GRAY_300), hover, 25f); case 1: - return getColorComponents(color, splitColor(OneConfigConfig.BLUE_600), splitColor(OneConfigConfig.BLUE_500), hover, 150f); + return getColorComponents(color, splitColor(OneConfigConfig.PRIMARY_600), splitColor(OneConfigConfig.PRIMARY_500), hover, 150f); case 2: return getColorComponents(color, splitColor(OneConfigConfig.GRAY_500), splitColor(OneConfigConfig.GRAY_300), hover, 50f); case 3: diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java index f574ea1..22baee0 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/TextUtils.java @@ -4,28 +4,29 @@ import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; public class TextUtils { public static ArrayList<String> wrapText(long vg, String text, float maxWidth, float fontSize, Fonts font) { ArrayList<String> wrappedText = new ArrayList<>(); - List<String> split = Arrays.asList(text.split(" ")); - for (int i = split.size(); i >= 0; i--) { - String textPart = String.join(" ", split.subList(0, i)); + text += " "; + int prevIndex = 0; + for (int i = text.indexOf(" "); i >= 0; i = text.indexOf(" ", i + 1)) { + String textPart = text.substring(0, i); float textWidth = RenderManager.getTextWidth(vg, textPart, fontSize, font); - if (textWidth > maxWidth) continue; - wrappedText.add(textPart); - if (i != split.size()) - wrappedText.addAll(wrapText(vg, String.join(" ", split.subList(i, split.size())), maxWidth, fontSize, font)); + if (textWidth < maxWidth) { + prevIndex = i; + continue; + } + wrappedText.add(text.substring(0, prevIndex) + " "); + wrappedText.addAll(wrapText(vg, text.substring(prevIndex + 1), maxWidth, fontSize, font)); break; } - if (text.endsWith(" ")) { - String lastLine = wrappedText.get(wrappedText.size() - 1); - lastLine += " "; + if (wrappedText.size() == 0) wrappedText.add(text); + String temp = wrappedText.get(wrappedText.size() - 1); + if (temp.length() != 0) { wrappedText.remove(wrappedText.size() - 1); - wrappedText.add(lastLine); + wrappedText.add(temp.substring(0, temp.length() - 1)); } return wrappedText; } |