diff options
author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-08-17 17:43:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-17 17:43:23 +0200 |
commit | 97f788ecd4be15b1556ee1f3d8bd057bdf06bf5f (patch) | |
tree | 2bccc96007025fbccf1758ac66d4665a97d6c315 /src/main/java/cc/polyfrost/oneconfig/gui/elements | |
parent | e18629af6aee276b0be6cec473e4099cca9100f1 (diff) | |
download | OneConfig-97f788ecd4be15b1556ee1f3d8bd057bdf06bf5f.tar.gz OneConfig-97f788ecd4be15b1556ee1f3d8bd057bdf06bf5f.tar.bz2 OneConfig-97f788ecd4be15b1556ee1f3d8bd057bdf06bf5f.zip |
Input revamp (#93)
* hud fix
* api
* things
* stuff
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/gui/elements')
19 files changed, 150 insertions, 142 deletions
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 e1f7789..948ec11 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicButton.java @@ -32,6 +32,7 @@ import cc.polyfrost.oneconfig.internal.assets.Colors; import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.renderer.SVG; import cc.polyfrost.oneconfig.renderer.font.Fonts; +import cc.polyfrost.oneconfig.utils.InputHandler; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import cc.polyfrost.oneconfig.utils.color.ColorUtils; import org.jetbrains.annotations.NotNull; @@ -83,10 +84,10 @@ public class BasicButton extends BasicElement { } @Override - public void draw(long vg, float x, float y) { + public void draw(long vg, float x, float y, InputHandler inputHandler) { this.x = x; this.y = y; - this.update(x, y); + this.update(x, y, inputHandler); if (disabled) RenderManager.setAlpha(vg, 0.5f); float contentWidth = 0f; int color; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java index 807b8aa..e390880 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java @@ -29,7 +29,7 @@ package cc.polyfrost.oneconfig.gui.elements; import cc.polyfrost.oneconfig.gui.animations.ColorAnimation; import cc.polyfrost.oneconfig.platform.Platform; import cc.polyfrost.oneconfig.renderer.RenderManager; -import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.utils.InputHandler; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import org.jetbrains.annotations.NotNull; @@ -70,7 +70,7 @@ public class BasicElement { public int currentColor; protected final float radius; /** - * Boolean to determine if this element is allowed to be clicked when {@link InputUtils#isBlockingInput()} is true. + * Boolean to determine if this element is allowed to be clicked when {@link InputHandler#isBlockingInput()} is true. */ private boolean block = false; /** @@ -98,29 +98,29 @@ public class BasicElement { /** * Draw script for the element. - * <br> <b>Make sure to call {@link #update(float, float)} to update the elements states!</b> + * <br> <b>Make sure to call {@link #update(float, float, InputHandler)} to update the elements states!</b> * * @param vg NanoVG context (see {@link RenderManager}) * @param x x position of the element * @param y y position of the element */ - public void draw(long vg, float x, float y) { - this.update(x, y); + public void draw(long vg, float x, float y, InputHandler inputHandler) { + this.update(x, y, inputHandler); RenderManager.drawRoundedRect(vg, x, y, width, height, currentColor, radius); } /** * Update this element's clicked, hovered, toggled, and pressed states, invoke any necessary methods, and update the color animation. */ - public void update(float x, float y) { + public void update(float x, float y, InputHandler inputHandler) { if (disabled) { hovered = false; pressed = false; clicked = false; } else { - hovered = InputUtils.isAreaHovered(x - hitBoxX, y - hitBoxY, width + hitBoxX, height + hitBoxY); + hovered = inputHandler.isAreaHovered(x - hitBoxX, y - hitBoxY, width + hitBoxX, height + hitBoxY); pressed = hovered && Platform.getMousePlatform().isButtonDown(0); - clicked = InputUtils.isClicked(block) && hovered; + clicked = inputHandler.isClicked(block) && hovered; if (clicked) { toggled = !toggled; 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 b03f868..0fa5514 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java @@ -44,7 +44,7 @@ import cc.polyfrost.oneconfig.renderer.font.Fonts; import cc.polyfrost.oneconfig.renderer.scissor.Scissor; import cc.polyfrost.oneconfig.renderer.scissor.ScissorManager; import cc.polyfrost.oneconfig.utils.IOUtils; -import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.utils.InputHandler; import cc.polyfrost.oneconfig.utils.NetworkUtils; import cc.polyfrost.oneconfig.utils.color.ColorPalette; @@ -80,12 +80,14 @@ public class ColorSelector { private boolean dragging, mouseWasDown; private final boolean hasAlpha; private Scissor inputScissor = null; + private final InputHandler inputHandler; - public ColorSelector(OneColor color, float mouseX, float mouseY) { - this(color, mouseX, mouseY, true); + public ColorSelector(OneColor color, float mouseX, float mouseY, InputHandler inputHandler) { + this(color, mouseX, mouseY, true, inputHandler); } - public ColorSelector(OneColor color, float mouseX, float mouseY, boolean hasAlpha) { + public ColorSelector(OneColor color, float mouseX, float mouseY, boolean hasAlpha, InputHandler inputHandler) { + this.inputHandler = inputHandler; this.color = color; this.hasAlpha = hasAlpha; buttons.add(new BasicButton(124, 28, "HSB Box", BasicButton.ALIGNMENT_CENTER, ColorPalette.TERTIARY)); @@ -132,7 +134,7 @@ public class ColorSelector { } public void draw(long vg) { - if (inputScissor != null) InputUtils.stopBlock(inputScissor); + if (inputScissor != null) inputHandler.stopBlock(inputScissor); doDrag(); int width = 416; int height = 768; @@ -141,7 +143,7 @@ public class ColorSelector { RenderManager.drawRoundedRect(vg, x, y, width, height, Colors.GRAY_800, 20f); RenderManager.drawText(vg, "Color Selector", x + 16, y + 32, Colors.WHITE_90, 18f, Fonts.SEMIBOLD); if (!closeBtn.isHovered()) RenderManager.setAlpha(vg, 0.8f); - closeBtn.draw(vg, x + 368, y + 16); + closeBtn.draw(vg, x + 368, y + 16, inputHandler); RenderManager.drawSvg(vg, SVGs.X_CIRCLE_BOLD, x + 368, y + 16, 32, 32, closeBtn.isHovered() ? Colors.ERROR_600 : -1); RenderManager.setAlpha(vg, 1f); @@ -151,13 +153,13 @@ public class ColorSelector { } // TODO favorite stuff - faveBtn.draw(vg, x + 16, y + 672); - recentBtn.draw(vg, x + 16, y + 720); + faveBtn.draw(vg, x + 16, y + 672, inputHandler); + recentBtn.draw(vg, x + 16, y + 720, inputHandler); for (int i = 0; i < 7; i++) { - favoriteColors.get(i).draw(vg, x + 104 + i * 44, y + 672); + favoriteColors.get(i).draw(vg, x + 104 + i * 44, y + 672, inputHandler); } for (int i = 0; i < 7; i++) { - recentColors.get(i).draw(vg, x + 104 + i * 44, y + 720); + recentColors.get(i).draw(vg, x + 104 + i * 44, y + 720, inputHandler); } RenderManager.drawRoundedRect(vg, x + 16, y + 64, 384, 32, Colors.GRAY_500, 12f); @@ -167,7 +169,7 @@ public class ColorSelector { int i = 18; for (BasicElement button : buttons) { - button.draw(vg, x + i, y + 66); + button.draw(vg, x + i, y + 66, inputHandler); if (button.isClicked()) { int prevMode = mode; mode = buttons.indexOf(button); @@ -181,36 +183,36 @@ public class ColorSelector { float percentMoveMain = moveAnimation.get(); RenderManager.drawText(vg, "Saturation", x + 224, y + 560, Colors.WHITE_80, 12f, Fonts.MEDIUM); - saturationInput.draw(vg, x + 312, y + 544); + saturationInput.draw(vg, x + 312, y + 544, inputHandler); RenderManager.drawText(vg, "Brightness", x + 16, y + 599, Colors.WHITE_80, 12f, Fonts.MEDIUM); - brightnessInput.draw(vg, x + 104, y + 584); + brightnessInput.draw(vg, x + 104, y + 584, inputHandler); RenderManager.drawText(vg, "Alpha (%)", x + 224, y + 599, Colors.WHITE_80, 12f, Fonts.MEDIUM); - alphaInput.draw(vg, x + 312, y + 584); + alphaInput.draw(vg, x + 312, y + 584, inputHandler); RenderManager.drawText(vg, color.getDataBit() == -1 ? "Hex (RGB):" : "Color Code:", x + 16, y + 641, Colors.WHITE_80, 12f, Fonts.MEDIUM); - hexInput.draw(vg, x + 104, y + 624); + hexInput.draw(vg, x + 104, y + 624, inputHandler); - copyBtn.draw(vg, x + 204, y + 624); - pasteBtn.draw(vg, x + 244, y + 624); + copyBtn.draw(vg, x + 204, y + 624, inputHandler); + pasteBtn.draw(vg, x + 244, y + 624, inputHandler); if (mode != 2) { RenderManager.drawText(vg, "Hue", x + 16, y + 560, Colors.WHITE_80, 12f, Fonts.MEDIUM); - hueInput.draw(vg, x + 104, y + 544); + hueInput.draw(vg, x + 104, y + 544, inputHandler); } else { RenderManager.drawText(vg, "Speed (s)", x + 16, y + 560, Colors.WHITE_80, 12f, Fonts.MEDIUM); - speedInput.draw(vg, x + 104, y + 544); + speedInput.draw(vg, x + 104, y + 544, inputHandler); } - guideBtn.draw(vg, x + 288, y + 624); + guideBtn.draw(vg, x + 288, y + 624, inputHandler); setColorFromXY(); if (mode != 2) color.setChromaSpeed(-1); drawColorSelector(vg, mode, (x * percentMoveMain), y); - if (dragging && InputUtils.isClicked(true)) { + if (dragging && inputHandler.isClicked(true)) { dragging = false; } bottomSlider.setGradient(Colors.TRANSPARENT, color.getRGBNoAlpha()); RenderManager.drawRoundImage(vg, Images.ALPHA_GRID.filePath, x + 16, y + 456, 384, 16, 8f); - bottomSlider.draw(vg, x + 16, y + 456); + bottomSlider.draw(vg, x + 16, y + 456, inputHandler); if (percentMoveMain > 0.96f) { RenderManager.drawRoundedRect(vg, mouseX - 7, mouseY - 7, 14, 14, Colors.WHITE, 14f); @@ -227,7 +229,7 @@ public class ColorSelector { RenderManager.drawRoundImage(vg, Images.ALPHA_GRID.filePath, x + 20, y + 492, 376, 32, 8f); RenderManager.drawRoundedRect(vg, x + 20, y + 492, 376, 32, color.getRGB(), 8f); - inputScissor = InputUtils.blockInputArea(x - 3, y - 3, width + 6, height + 6); + inputScissor = inputHandler.blockInputArea(x - 3, y - 3, width + 6, height + 6); ScissorManager.resetScissor(vg, scissor); mouseWasDown = Platform.getMousePlatform().isButtonDown(0); if (closeBtn.isClicked()) { @@ -246,10 +248,10 @@ public class ColorSelector { if (mode == 0) { topSlider.setColor(color.getRGBMax(true)); - topSlider.draw(vg, x + 16, y + 424); + topSlider.draw(vg, x + 16, y + 424, inputHandler); } if (mode == 2) { - speedSlider.draw(vg, x + 60, y + 424); + speedSlider.draw(vg, x + 60, y + 424, inputHandler); RenderManager.drawText(vg, "SLOW", x + 16, y + 429, Colors.WHITE_80, 12f, Fonts.REGULAR); RenderManager.drawText(vg, "FAST", x + 370, y + 429, Colors.WHITE_80, 12f, Fonts.REGULAR); } @@ -261,13 +263,13 @@ public class ColorSelector { topSlider.setGradient(Colors.BLACK, color.getRGBMax(true)); topSlider.setImage(null); - topSlider.draw(vg, x + 16, y + 424); + topSlider.draw(vg, x + 16, y + 424, inputHandler); break; } } private void doDrag() { - if (InputUtils.isAreaHovered(x, y, 368, 64) && Platform.getMousePlatform().isButtonDown(0) && !dragging) { + if (inputHandler.isAreaHovered(x, y, 368, 64) && Platform.getMousePlatform().isButtonDown(0) && !dragging) { float dx = (float) (Platform.getMousePlatform().getMouseDX() / (OneConfigGui.INSTANCE == null ? 1 : OneConfigGui.INSTANCE.getScaleFactor())); float dy = (float) (Platform.getMousePlatform().getMouseDY() / (OneConfigGui.INSTANCE == null ? 1 : OneConfigGui.INSTANCE.getScaleFactor())); x += dx; @@ -279,14 +281,14 @@ public class ColorSelector { private void setColorFromXY() { boolean isMouseDown = Platform.getMousePlatform().isButtonDown(0); - boolean hovered = Platform.getMousePlatform().isButtonDown(0) && InputUtils.isAreaHovered(x + 16, y + 120, 384, 288); + boolean hovered = Platform.getMousePlatform().isButtonDown(0) && inputHandler.isAreaHovered(x + 16, y + 120, 384, 288); if (hovered && isMouseDown && !mouseWasDown) dragging = true; switch (mode) { case 0: case 2: if (dragging) { - mouseX = InputUtils.mouseX(); - mouseY = InputUtils.mouseY(); + mouseX = inputHandler.mouseX(); + mouseY = inputHandler.mouseY(); } if (mouseX < x + 16) mouseX = x + 16; if (mouseY < y + 120) mouseY = y + 120; @@ -307,7 +309,7 @@ public class ColorSelector { case 1: float circleCenterX = x + 208; float circleCenterY = y + 264; - double squareDist = Math.pow((circleCenterX - InputUtils.mouseX()), 2) + Math.pow((circleCenterY - InputUtils.mouseY()), 2); + double squareDist = Math.pow((circleCenterX - inputHandler.mouseX()), 2) + Math.pow((circleCenterY - inputHandler.mouseY()), 2); hovered = squareDist < 144 * 144 && Platform.getMousePlatform().isButtonDown(0); isMouseDown = Platform.getMousePlatform().isButtonDown(0); if (hovered && isMouseDown && !mouseWasDown) dragging = true; @@ -315,7 +317,7 @@ public class ColorSelector { int angle = 0; int saturation = color.getSaturation(); if (dragging) { - angle = (int) Math.toDegrees(Math.atan2(InputUtils.mouseY() - circleCenterY, InputUtils.mouseX() - circleCenterX)); + angle = (int) Math.toDegrees(Math.atan2(inputHandler.mouseY() - circleCenterY, inputHandler.mouseX() - circleCenterX)); if (angle < 0) angle += 360; if ((squareDist / (144 * 144) > 1f)) { saturation = 100; @@ -323,8 +325,8 @@ public class ColorSelector { mouseY = (float) (Math.cos(Math.toRadians(-angle) + 1.5708) * 144 + y + 264); } else { saturation = (int) (squareDist / (144 * 144) * 100); - mouseX = InputUtils.mouseX(); - mouseY = InputUtils.mouseY(); + mouseX = inputHandler.mouseX(); + mouseY = inputHandler.mouseY(); } } color.setHSBA(dragging ? angle : color.getHue(), saturation, (int) (topSlider.getValue() / 360 * 100), (int) bottomSlider.getValue()); @@ -419,7 +421,7 @@ public class ColorSelector { } public void onClose() { - if (inputScissor != null) InputUtils.stopBlock(inputScissor); + if (inputScissor != null) inputHandler.stopBlock(inputScissor); /*for (int i = 0; i < OneConfigConfig.recentColors.size(); i++) { OneColor color1 = OneConfigConfig.recentColors.get(i); if (color1.getRGB() == color.getRGB()) { @@ -455,8 +457,8 @@ public class ColorSelector { } @Override - public void draw(long vg, float x, float y) { - if (!disabled) update(x, y); + public void draw(long vg, float x, float y, InputHandler inputHandler) { + if (!disabled) update(x, y, inputHandler); else RenderManager.setAlpha(vg, 0.5f); super.dragPointerSize = 15f; if (image != null) { @@ -495,11 +497,11 @@ public class ColorSelector { } @Override - public void draw(long vg, float x, float y) { + public void draw(long vg, float x, float y, InputHandler inputHandler) { RenderManager.drawRoundedRect(vg, x, y, 32, 32, toggled ? Colors.PRIMARY_600 : Colors.GRAY_300, 12f); RenderManager.drawRoundedRect(vg, x + 2, y + 2, 28, 28, Colors.GRAY_800, 10f); RenderManager.drawRoundedRect(vg, x + 4, y + 4, 24, 24, color.getRGB(), 8f); - update(x, y); + update(x, y, inputHandler); } public OneColor getColor() { 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 5b30b59..afeaccd 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java @@ -42,7 +42,7 @@ import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.renderer.font.Fonts; import cc.polyfrost.oneconfig.renderer.scissor.Scissor; import cc.polyfrost.oneconfig.renderer.scissor.ScissorManager; -import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.utils.InputHandler; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import cc.polyfrost.oneconfig.utils.color.ColorUtils; import org.jetbrains.annotations.NotNull; @@ -70,13 +70,13 @@ public class ModCard extends BasicElement { } @Override - public void draw(long vg, float x, float y) { - super.update(x, y); + public void draw(long vg, float x, float y, InputHandler inputHandler) { + super.update(x, y, inputHandler); String cleanName = modData.name.replaceAll("ยง.", ""); Scissor scissor = ScissorManager.scissor(vg, x, y, width, height); - isHoveredMain = InputUtils.isAreaHovered(x, y, width, 87); - boolean isHoveredSecondary = InputUtils.isAreaHovered(x, y + 87, width - 32, 32) && !disabled; + isHoveredMain = inputHandler.isAreaHovered(x, y, width, 87); + boolean isHoveredSecondary = inputHandler.isAreaHovered(x, y + 87, width - 32, 32) && !disabled; if (disabled) RenderManager.setAlpha(vg, 0.5f); RenderManager.drawRoundedRectVaried(vg, x, y, width, 87, colorFrame.getColor(isHoveredMain, isHoveredMain && Platform.getMousePlatform().isButtonDown(0)), 12f, 12f, 0f, 0f); RenderManager.drawRoundedRectVaried(vg, x, y + 87, width, 32, colorToggle.getColor(isHoveredSecondary, isHoveredSecondary && Platform.getMousePlatform().isButtonDown(0)), 0f, 0f, 12f, 12f); @@ -88,7 +88,7 @@ public class ModCard extends BasicElement { } else { RenderManager.drawText(vg, cleanName, x + Math.max(0, (244 - RenderManager.getTextWidth(vg, cleanName, 16, Fonts.MINECRAFT_BOLD))) / 2f, y + 44, ColorUtils.setAlpha(Colors.WHITE, (int) (colorFrame.getAlpha() * 255)), 16, Fonts.MINECRAFT_BOLD); } - favoriteButton.draw(vg, x + 212, y + 87); + favoriteButton.draw(vg, x + 212, y + 87, inputHandler); favorite = favoriteButton.isToggled(); if (favoriteButton.isClicked()) { if (favorite) OneConfigConfig.favoriteMods.add(modData.name); 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 a43103b..ffb4470 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/Slider.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/Slider.java @@ -29,7 +29,7 @@ package cc.polyfrost.oneconfig.gui.elements; import cc.polyfrost.oneconfig.internal.assets.Colors; import cc.polyfrost.oneconfig.platform.Platform; import cc.polyfrost.oneconfig.renderer.RenderManager; -import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.utils.InputHandler; public class Slider extends BasicElement { private final float min, max; @@ -47,8 +47,8 @@ public class Slider extends BasicElement { } @Override - public void draw(long vg, float x, float y) { - if(!disabled) update(x, y); + public void draw(long vg, float x, float y, InputHandler inputHandler) { + if(!disabled) update(x, y, inputHandler); else RenderManager.setAlpha(vg, 0.5f); RenderManager.drawRoundedRect(vg, x, y + 2, width, height - 4, Colors.GRAY_300, 3f); RenderManager.drawRoundedRect(vg, x, y + 2, width * value, height - 4, Colors.PRIMARY_500, 3f); @@ -58,18 +58,18 @@ public class Slider extends BasicElement { } - public void update(float x, float y) { - super.update(x, y); + public void update(float x, float y, InputHandler inputHandler) { + super.update(x, y, inputHandler); boolean isMouseDown = Platform.getMousePlatform().isButtonDown(0); - boolean hovered = InputUtils.isAreaHovered(x - 6, y - 3, width + 12, height + 6); + boolean hovered = inputHandler.isAreaHovered(x - 6, y - 3, width + 12, height + 6); if (hovered && isMouseDown && !mouseWasDown) dragging = true; mouseWasDown = isMouseDown; if (dragging) { - value = (InputUtils.mouseX() - x) / width; + value = (inputHandler.mouseX() - x) / width; } - if (dragging && InputUtils.isClicked(true)) { + if (dragging && inputHandler.isClicked(true)) { dragging = false; - value = (InputUtils.mouseX() - x) / width; + value = (inputHandler.mouseX() - x) / width; } if (value < 0) value = 0; 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 d7c4103..fdd0c2f 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 @@ -32,6 +32,7 @@ import cc.polyfrost.oneconfig.gui.elements.BasicButton; import cc.polyfrost.oneconfig.internal.assets.Colors; import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.renderer.font.Fonts; +import cc.polyfrost.oneconfig.utils.InputHandler; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import java.lang.reflect.Field; @@ -90,11 +91,11 @@ public class ConfigButton extends BasicOption { } @Override - public void draw(long vg, int x, int y) { + public void draw(long vg, int x, int y, InputHandler inputHandler) { button.disable(!isEnabled()); if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); RenderManager.drawText(vg, name, x, y + 17, Colors.WHITE, 14f, Fonts.MEDIUM); - button.draw(vg, x + (size == 1 ? 352 : 736), y); + button.draw(vg, x + (size == 1 ? 352 : 736), y, inputHandler); RenderManager.setAlpha(vg, 1f); } 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 491eaf4..9cc60c9 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 @@ -37,7 +37,7 @@ import cc.polyfrost.oneconfig.platform.Platform; import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.renderer.font.Fonts; import cc.polyfrost.oneconfig.internal.assets.SVGs; -import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.utils.InputHandler; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import cc.polyfrost.oneconfig.utils.color.ColorUtils; @@ -58,7 +58,7 @@ public class ConfigCheckbox extends BasicOption { } @Override - public void draw(long vg, int x, int y) { + public void draw(long vg, int x, int y, InputHandler inputHandler) { if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); boolean toggled = false; try { @@ -66,9 +66,9 @@ public class ConfigCheckbox extends BasicOption { if (animation == null) animation = new DummyAnimation(toggled ? 1 : 0); } catch (IllegalAccessException ignored) { } - boolean hover = InputUtils.isAreaHovered(x, y + 4, 24, 24); + boolean hover = inputHandler.isAreaHovered(x, y + 4, 24, 24); - boolean clicked = InputUtils.isClicked() && hover; + boolean clicked = inputHandler.isClicked() && hover; if (clicked && isEnabled()) { toggled = !toggled; animation = new EaseInOutQuad(100, 0, 1, !toggled); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java index 39b88a6..39780a1 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java @@ -37,7 +37,7 @@ import cc.polyfrost.oneconfig.gui.elements.text.TextInputField; import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.renderer.font.Fonts; import cc.polyfrost.oneconfig.internal.assets.Images; -import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.utils.InputHandler; import java.lang.reflect.Field; @@ -62,7 +62,7 @@ public class ConfigColorElement extends BasicOption { } @Override - public void draw(long vg, int x, int y) { + public void draw(long vg, int x, int y, InputHandler inputHandler) { if(OneConfigGui.INSTANCE == null) return; if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); hexField.disable(!isEnabled()); @@ -86,7 +86,7 @@ public class ConfigColorElement extends BasicOption { hexField.setErrored(true); } } - hexField.draw(vg, x1 + 224, y); + hexField.draw(vg, x1 + 224, y, inputHandler); if (!alphaField.isToggled()) alphaField.setInput(Math.round(color.getAlpha() / 2.55f) + "%"); alphaField.setErrored(false); @@ -106,15 +106,15 @@ public class ConfigColorElement extends BasicOption { alphaField.setErrored(true); } } - alphaField.draw(vg, x1 + 336, y); + alphaField.draw(vg, x1 + 336, y, inputHandler); - element.update(x1 + 416, y); + element.update(x1 + 416, y, inputHandler); RenderManager.drawHollowRoundRect(vg, x1 + 415, y - 1, 64, 32, Colors.GRAY_300, 12f, 2f); RenderManager.drawRoundImage(vg, Images.ALPHA_GRID.filePath, x1 + 420, y + 4, 56, 24, 8f); RenderManager.drawRoundedRect(vg, x1 + 420, y + 4, 56, 24, color.getRGB(), 8f); if (element.isClicked() && !open) { open = true; - OneConfigGui.INSTANCE.initColorSelector(new ColorSelector(color, InputUtils.mouseX(), InputUtils.mouseY(), allowAlpha)); + OneConfigGui.INSTANCE.initColorSelector(new ColorSelector(color, inputHandler.mouseX(), inputHandler.mouseY(), allowAlpha, inputHandler)); } if (OneConfigGui.INSTANCE.currentColorSelector == null) open = false; else if (open) color = (OneConfigGui.INSTANCE.getColor()); 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 24e0a9b..2660266 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 @@ -35,7 +35,7 @@ import cc.polyfrost.oneconfig.platform.Platform; import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.renderer.font.Fonts; import cc.polyfrost.oneconfig.renderer.scissor.Scissor; -import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.utils.InputHandler; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import java.awt.*; @@ -60,21 +60,21 @@ public class ConfigDropdown extends BasicOption { } @Override - public void draw(long vg, int x, int y) { + public void draw(long vg, int x, int y, InputHandler inputHandler) { if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); RenderManager.drawText(vg, name, x, y + 16, Colors.WHITE_90, 14f, Fonts.MEDIUM); boolean hovered; - if (size == 1) hovered = InputUtils.isAreaHovered(x + 224, y, 256, 32) && isEnabled(); - else hovered = InputUtils.isAreaHovered(x + 352, y, 640, 32) && isEnabled(); + if (size == 1) hovered = inputHandler.isAreaHovered(x + 224, y, 256, 32) && isEnabled(); + else hovered = inputHandler.isAreaHovered(x + 352, y, 640, 32) && isEnabled(); - if (hovered && InputUtils.isClicked() || opened && InputUtils.isClicked(true) && - (size == 1 && !InputUtils.isAreaHovered(x + 224, y + 40, 256, options.length * 32, true) || - size == 2 && !InputUtils.isAreaHovered(x + 352, y + 40, 640, options.length * 32, true))) { + if (hovered && inputHandler.isClicked() || opened && inputHandler.isClicked(true) && + (size == 1 && !inputHandler.isAreaHovered(x + 224, y + 40, 256, options.length * 32, true) || + size == 2 && !inputHandler.isAreaHovered(x + 352, y + 40, 640, options.length * 32, true))) { opened = !opened; backgroundColor.setPalette(opened ? ColorPalette.PRIMARY : ColorPalette.SECONDARY); - if (opened) inputScissor = InputUtils.blockAllInput(); - else if (inputScissor != null) InputUtils.stopBlock(inputScissor); + if (opened) inputScissor = inputHandler.blockAllInput(); + else if (inputScissor != null) inputHandler.stopBlock(inputScissor); } if (opened) return; @@ -100,12 +100,12 @@ public class ConfigDropdown extends BasicOption { } @Override - public void drawLast(long vg, int x, int y) { + public void drawLast(long vg, int x, int y, InputHandler inputHandler) { if (!opened) return; boolean hovered; - if (size == 1) hovered = InputUtils.isAreaHovered(x + 224, y, 256, 32, true); - else hovered = InputUtils.isAreaHovered(x + 352, y, 640, 32, true); + if (size == 1) hovered = inputHandler.isAreaHovered(x + 224, y, 256, 32, true); + else hovered = inputHandler.isAreaHovered(x + 352, y, 640, 32, true); int selected = 0; try { @@ -127,21 +127,21 @@ public class ConfigDropdown extends BasicOption { int optionY = y + 44; for (String option : options) { int color = Colors.WHITE_80; - boolean optionHovered = InputUtils.isAreaHovered(x + 224, optionY, 252, 32, true); + boolean optionHovered = inputHandler.isAreaHovered(x + 224, optionY, 252, 32, true); if (optionHovered && Platform.getMousePlatform().isButtonDown(0)) { RenderManager.drawRoundedRect(vg, x + 228, optionY + 2, 248, 28, Colors.PRIMARY_700_80, 8); } else if (optionHovered) { RenderManager.drawRoundedRect(vg, x + 228, optionY + 2, 248, 28, Colors.PRIMARY_700, 8); color = Colors.WHITE; } - if (optionHovered && InputUtils.isClicked(true)) { + if (optionHovered && inputHandler.isClicked(true)) { try { set(Arrays.asList(options).indexOf(option)); } catch (IllegalAccessException ignored) { } opened = false; backgroundColor.setPalette(ColorPalette.SECONDARY); - if (inputScissor != null) InputUtils.stopBlock(inputScissor); + if (inputScissor != null) inputHandler.stopBlock(inputScissor); } RenderManager.drawText(vg, option, x + 240, optionY + 18, color, 14, Fonts.MEDIUM); @@ -160,7 +160,7 @@ public class ConfigDropdown extends BasicOption { int optionY = y + 44; for (String option : options) { int color = Colors.WHITE_80; - boolean optionHovered = InputUtils.isAreaHovered(x + 352, optionY, 640, 36, true); + boolean optionHovered = inputHandler.isAreaHovered(x + 352, optionY, 640, 36, true); if (optionHovered && Platform.getMousePlatform().isButtonDown(0)) { RenderManager.drawRoundedRect(vg, x + 356, optionY + 2, 632, 28, Colors.PRIMARY_700_80, 8); } else if (optionHovered) { @@ -170,14 +170,14 @@ public class ConfigDropdown extends BasicOption { RenderManager.drawText(vg, option, x + 368, optionY + 18, color, 14, Fonts.MEDIUM); - if (optionHovered && InputUtils.isClicked(true)) { + if (optionHovered && inputHandler.isClicked(true)) { try { set(Arrays.asList(options).indexOf(option)); } catch (IllegalAccessException ignored) { } opened = false; backgroundColor.setPalette(ColorPalette.SECONDARY); - if (inputScissor != null) InputUtils.stopBlock(inputScissor); + if (inputScissor != null) inputHandler.stopBlock(inputScissor); } optionY += 32; } 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 eaea946..c8582d1 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 @@ -34,7 +34,7 @@ import cc.polyfrost.oneconfig.gui.animations.DummyAnimation; import cc.polyfrost.oneconfig.gui.animations.EaseInOutCubic; import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.renderer.font.Fonts; -import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.utils.InputHandler; import java.lang.reflect.Field; @@ -59,7 +59,7 @@ public class ConfigDualOption extends BasicOption { } @Override - public void draw(long vg, int x, int y) { + public void draw(long vg, int x, int y, InputHandler inputHandler) { boolean toggled = false; try { toggled = (boolean) get(); @@ -67,8 +67,8 @@ public class ConfigDualOption extends BasicOption { } catch (IllegalAccessException ignored) { } 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(); + boolean hoveredLeft = inputHandler.isAreaHovered(x + 226, y, 128, 32) && isEnabled(); + boolean hoveredRight = inputHandler.isAreaHovered(x + 354, y, 128, 32) && isEnabled(); RenderManager.drawText(vg, name, x, y + 16, Colors.WHITE_90, 14f, Fonts.MEDIUM); RenderManager.drawRoundedRect(vg, x + 226, y, 256, 32, Colors.GRAY_600, 12f); RenderManager.drawRoundedRect(vg, x + posAnimation.get(), y + 2, 124, 28, Colors.PRIMARY_600, 10f); @@ -79,7 +79,7 @@ public class ConfigDualOption extends BasicOption { RenderManager.drawText(vg, right, x + 418 - RenderManager.getTextWidth(vg, right, 12f, Fonts.MEDIUM) / 2, y + 17, Colors.WHITE, 12f, Fonts.MEDIUM); RenderManager.setAlpha(vg, 1); - if ((hoveredLeft && toggled || hoveredRight && !toggled) && InputUtils.isClicked()) { + if ((hoveredLeft && toggled || hoveredRight && !toggled) && inputHandler.isClicked()) { toggled = !toggled; posAnimation = new EaseInOutCubic(175, 228, 356, !toggled); try { diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java index 5ac87dc..45865fe 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigHeader.java @@ -33,6 +33,7 @@ import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.renderer.font.Fonts; import cc.polyfrost.oneconfig.renderer.scissor.Scissor; import cc.polyfrost.oneconfig.renderer.scissor.ScissorManager; +import cc.polyfrost.oneconfig.utils.InputHandler; import java.lang.reflect.Field; @@ -48,7 +49,7 @@ public class ConfigHeader extends BasicOption { } @Override - public void draw(long vg, int x, int y) { + public void draw(long vg, int x, int y, InputHandler inputHandler) { Scissor scissor = ScissorManager.scissor(vg, x, y, size == 1 ? 480 : 992, 32); RenderManager.drawText(vg, name, x, y + 17, Colors.WHITE_90, 24, Fonts.MEDIUM); ScissorManager.resetScissor(vg, scissor); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigInfo.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigInfo.java index 2760cb6..c44c50d 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigInfo.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigInfo.java @@ -34,6 +34,7 @@ import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.renderer.font.Fonts; import cc.polyfrost.oneconfig.renderer.scissor.Scissor; import cc.polyfrost.oneconfig.renderer.scissor.ScissorManager; +import cc.polyfrost.oneconfig.utils.InputHandler; import java.lang.reflect.Field; @@ -51,7 +52,7 @@ public class ConfigInfo extends BasicOption { } @Override - public void draw(long vg, int x, int y) { + public void draw(long vg, int x, int y, InputHandler inputHandler) { Scissor scissor = ScissorManager.scissor(vg, x, y, size == 1 ? 448 : 960, 32); RenderManager.drawInfo(vg, type, x, y + 4, 24); RenderManager.drawText(vg, name, x + 32, y + 18, Colors.WHITE_90, 14, Fonts.MEDIUM); 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 e14da52..daa034f 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 @@ -36,6 +36,7 @@ import cc.polyfrost.oneconfig.internal.assets.SVGs; import cc.polyfrost.oneconfig.libs.universal.UKeyboard; import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.renderer.font.Fonts; +import cc.polyfrost.oneconfig.utils.InputHandler; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import java.lang.reflect.Field; @@ -56,7 +57,7 @@ public class ConfigKeyBind extends BasicOption { } @Override - public void draw(long vg, int x, int y) { + public void draw(long vg, int x, int y, InputHandler inputHandler) { if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); RenderManager.drawText(vg, name, x, y + 17, Colors.WHITE, 14f, Fonts.MEDIUM); OneKeyBind keyBind = getKeyBind(); @@ -77,7 +78,7 @@ public class ConfigKeyBind extends BasicOption { } } else if (text.equals("")) text = "None"; button.setText(text); - button.draw(vg, x + (size == 1 ? 224 : 736), y); + button.draw(vg, x + (size == 1 ? 224 : 736), y, inputHandler); RenderManager.setAlpha(vg, 1f); } 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 4dbcd14..de10600 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 @@ -37,7 +37,7 @@ import cc.polyfrost.oneconfig.platform.Platform; import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.renderer.font.Fonts; import cc.polyfrost.oneconfig.internal.assets.SVGs; -import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.utils.InputHandler; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import java.lang.reflect.Field; @@ -60,10 +60,10 @@ public class ConfigPageButton extends BasicOption { } @Override - public void draw(long vg, int x, int y) { + public void draw(long vg, int x, int y, InputHandler inputHandler) { int height = description.equals("") ? 64 : 96; - boolean hovered = InputUtils.isAreaHovered(x - 16, y, 1024, height) && isEnabled(); - boolean clicked = hovered && InputUtils.isClicked(); + boolean hovered = inputHandler.isAreaHovered(x - 16, y, 1024, height) && isEnabled(); + boolean clicked = hovered && inputHandler.isClicked(); if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); 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 7e0f0a8..4e2dda5 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 @@ import cc.polyfrost.oneconfig.gui.elements.text.NumberInputField; import cc.polyfrost.oneconfig.platform.Platform; import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.renderer.font.Fonts; -import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.utils.InputHandler; import cc.polyfrost.oneconfig.utils.MathUtils; import java.lang.reflect.Field; @@ -60,24 +60,24 @@ public class ConfigSlider extends BasicOption { } @Override - public void draw(long vg, int x, int y) { + public void draw(long vg, int x, int y, InputHandler inputHandler) { int xCoordinate = 0; float value = 0; - boolean hovered = InputUtils.isAreaHovered(x + 352, y, 512, 32) && isEnabled(); + boolean hovered = inputHandler.isAreaHovered(x + 352, y, 512, 32) && isEnabled(); inputField.disable(!isEnabled()); if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); boolean isMouseDown = Platform.getMousePlatform().isButtonDown(0); if (hovered && isMouseDown && !mouseWasDown) dragging = true; mouseWasDown = isMouseDown; if (dragging) { - xCoordinate = (int) MathUtils.clamp(InputUtils.mouseX(), x + 352, x + 864); + xCoordinate = (int) MathUtils.clamp(inputHandler.mouseX(), x + 352, x + 864); if (step > 0) xCoordinate = getStepCoordinate(xCoordinate, x); value = MathUtils.map(xCoordinate, x + 352, x + 864, min, max); } else if (inputField.isToggled() || inputField.arrowsClicked()) { value = inputField.getCurrentValue(); xCoordinate = (int) MathUtils.clamp(MathUtils.map(value, min, max, x + 352, x + 864), x + 352, x + 864); } - if (dragging && InputUtils.isClicked() || inputField.isToggled() || inputField.arrowsClicked()) { + if (dragging && inputHandler.isClicked() || inputField.isToggled() || inputField.arrowsClicked()) { dragging = false; if (step > 0) { xCoordinate = getStepCoordinate(xCoordinate, x); @@ -110,7 +110,7 @@ public class ConfigSlider extends BasicOption { } if (step == 0) RenderManager.drawRoundedRect(vg, xCoordinate - 12, y + 4, 24, 24, Colors.WHITE, 12f); else RenderManager.drawRoundedRect(vg, xCoordinate - 4, y + 4, 8, 24, Colors.WHITE, 4f); - inputField.draw(vg, x + 892, y); + inputField.draw(vg, x + 892, y, inputHandler); RenderManager.setAlpha(vg, 1f); } 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 c4a52e7..9d13e3e 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 @@ -36,7 +36,7 @@ import cc.polyfrost.oneconfig.gui.animations.EaseInOutQuad; import cc.polyfrost.oneconfig.platform.Platform; import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.renderer.font.Fonts; -import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.utils.InputHandler; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import java.lang.reflect.Field; @@ -55,7 +55,7 @@ public class ConfigSwitch extends BasicOption { } @Override - public void draw(long vg, int x, int y) { + public void draw(long vg, int x, int y, InputHandler inputHandler) { boolean toggled = false; try { toggled = (boolean) get(); @@ -67,13 +67,13 @@ public class ConfigSwitch extends BasicOption { } float percentOn = animation.get(); int x2 = x + 3 + (int) (percentOn * 18); - boolean hovered = InputUtils.isAreaHovered(x, y, 42, 32); + boolean hovered = inputHandler.isAreaHovered(x, y, 42, 32); if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); RenderManager.drawRoundedRect(vg, x, y + 4, 42, 24, color.getColor(hovered, hovered && Platform.getMousePlatform().isButtonDown(0)), 12f); RenderManager.drawRoundedRect(vg, x2, y + 7, 18, 18, Colors.WHITE, 9f); RenderManager.drawText(vg, name, x + 50, y + 17, Colors.WHITE, 14f, Fonts.MEDIUM); - if (InputUtils.isAreaClicked(x, y, 42, 32) && isEnabled()) { + if (inputHandler.isAreaClicked(x, y, 42, 32) && isEnabled()) { toggled = !toggled; animation = new EaseInOutQuad(200, 0, 1, !toggled); color.setPalette(toggled ? ColorPalette.PRIMARY : ColorPalette.SECONDARY); 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 8bc1e20..adb9131 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 @@ -35,7 +35,7 @@ import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.renderer.SVG; import cc.polyfrost.oneconfig.renderer.font.Fonts; import cc.polyfrost.oneconfig.internal.assets.SVGs; -import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.utils.InputHandler; import java.lang.reflect.Field; @@ -57,7 +57,7 @@ public class ConfigTextBox extends BasicOption { } @Override - public void draw(long vg, int x, int y) { + public void draw(long vg, int x, int y, InputHandler inputHandler) { if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); textField.disable(!isEnabled()); RenderManager.drawText(vg, name, x, y + 16, Colors.WHITE_90, 14, Fonts.MEDIUM); @@ -70,13 +70,13 @@ public class ConfigTextBox extends BasicOption { if (multiLine && textField.getLines() > 2) textField.setHeight(64 + 24 * (textField.getLines() - 2)); else if (multiLine) textField.setHeight(64); - textField.draw(vg, x + (size == 1 ? 224 : 352), y); + textField.draw(vg, x + (size == 1 ? 224 : 352), y, inputHandler); if (secure) { final SVG icon = textField.getPassword() ? SVGs.EYE_OFF : SVGs.EYE; - boolean hovered = InputUtils.isAreaHovered(x + 967, y + 7, 18, 18) && isEnabled(); + boolean hovered = inputHandler.isAreaHovered(x + 967, y + 7, 18, 18) && isEnabled(); int color = hovered ? Colors.WHITE : Colors.WHITE_80; - if (hovered && InputUtils.isClicked()) textField.setPassword(!textField.getPassword()); + if (hovered && inputHandler.isClicked()) textField.setPassword(!textField.getPassword()); if (hovered && Platform.getMousePlatform().isButtonDown(0)) RenderManager.setAlpha(vg, 0.5f); RenderManager.drawSvg(vg, icon, x + 967, y + 7, 18, 18, color); } 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 50a792f..930a81f 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 @@ -31,6 +31,7 @@ import cc.polyfrost.oneconfig.gui.animations.ColorAnimation; import cc.polyfrost.oneconfig.gui.elements.BasicElement; import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.internal.assets.SVGs; +import cc.polyfrost.oneconfig.utils.InputHandler; import cc.polyfrost.oneconfig.utils.color.ColorPalette; public class NumberInputField extends TextInputField { @@ -53,14 +54,14 @@ public class NumberInputField extends TextInputField { } @Override - public void draw(long vg, float x, float y) { + public void draw(long vg, float x, float y, InputHandler inputHandler) { super.errored = false; - if(disabled) RenderManager.setAlpha(vg, 0.5f); + if (disabled) RenderManager.setAlpha(vg, 0.5f); RenderManager.drawRoundedRect(vg, x + width + 4, y, 12, 28, Colors.GRAY_500, 6f); upArrow.disable(disabled); downArrow.disable(disabled); - upArrow.update(x + width + 4, y); - downArrow.update(x + width + 4, y + 14); + upArrow.update(x + width + 4, y, inputHandler); + downArrow.update(x + width + 4, y + 14, inputHandler); try { current = Float.parseFloat(input); } catch (NumberFormatException e) { @@ -98,16 +99,16 @@ public class NumberInputField extends TextInputField { } RenderManager.drawRoundedRectVaried(vg, x + width + 4, y + 14, 12, 14, colorBottom.getColor(downArrow.isHovered(), downArrow.isPressed()), 0f, 0f, 6f, 6f); RenderManager.drawSvg(vg, SVGs.CHEVRON_DOWN, x + width + 5, y + 15, 10, 10); - if(!disabled) RenderManager.setAlpha(vg, 1f); + if (!disabled) RenderManager.setAlpha(vg, 1f); try { - super.draw(vg, x, y - 2); + super.draw(vg, x, y - 2, inputHandler); } catch (Exception e) { setCurrentValue(current); super.caretPos = 0; super.prevCaret = 0; } - if(disabled) RenderManager.setAlpha(vg, 1f); + if (disabled) RenderManager.setAlpha(vg, 1f); } 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 90a101c..9d470e4 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 @@ -36,7 +36,7 @@ import cc.polyfrost.oneconfig.renderer.font.Fonts; import cc.polyfrost.oneconfig.renderer.scissor.Scissor; import cc.polyfrost.oneconfig.renderer.scissor.ScissorManager; import cc.polyfrost.oneconfig.utils.IOUtils; -import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.utils.InputHandler; import cc.polyfrost.oneconfig.utils.MathUtils; import cc.polyfrost.oneconfig.utils.TextUtils; import org.jetbrains.annotations.NotNull; @@ -121,7 +121,7 @@ public class TextInputField extends BasicElement { } @Override - public void draw(long vg, float x, float y) { + public void draw(long vg, float x, float y, InputHandler inputHandler) { this.x = x; this.y = y; this.vg = vg; @@ -136,8 +136,8 @@ public class TextInputField extends BasicElement { RenderManager.drawHollowRoundRect(vg, x, y, width - 0.5f, height - 0.5f, errored ? Colors.ERROR_600 : Colors.PRIMARY_600, 12f, 2f); } Scissor scissor = ScissorManager.scissor(vg, x, y, width, height); - super.update(x, y); - if (Platform.getMousePlatform().isButtonDown(0) && !InputUtils.isAreaHovered(x - 40, y - 20, width + 90, height + 20)) { + super.update(x, y, inputHandler); + if (Platform.getMousePlatform().isButtonDown(0) && !inputHandler.isAreaHovered(x - 40, y - 20, width + 90, height + 20)) { onClose(); toggled = false; } @@ -172,11 +172,11 @@ public class TextInputField extends BasicElement { int state = Platform.getMousePlatform().getButtonState(0); //todo does this work if (state == 1) { 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)); - } else prevCaret = calculatePos(InputUtils.mouseX(), input); + int caretLine = Math.max(0, Math.min(wrappedText.size() - 1, (int) Math.floor((inputHandler.mouseY() - y - 10) / 24f))); + caretPos = calculatePos(inputHandler.mouseX(), wrappedText.get(caretLine)); + } else prevCaret = calculatePos(inputHandler.mouseX(), input); if (System.currentTimeMillis() - clickTimeD1 < 300) { - onDoubleClick(); + onDoubleClick(inputHandler); isDoubleClick = true; } clickTimeD1 = System.currentTimeMillis(); @@ -209,10 +209,10 @@ public class TextInputField extends BasicElement { if (hovered) { if (Platform.getMousePlatform().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)); + int caretLine = Math.max(0, Math.min(wrappedText.size() - 1, (int) Math.floor((inputHandler.mouseY() - y - 10) / 24f))); + caretPos = calculatePos(inputHandler.mouseX(), wrappedText.get(caretLine)); for (int i = 0; i < caretLine; i++) caretPos += wrappedText.get(i).length(); - } else caretPos = calculatePos(InputUtils.mouseX(), input); + } else caretPos = calculatePos(inputHandler.mouseX(), input); if (caretPos > prevCaret) { if (!centered) start = x + 12 + this.getTextWidth(vg, input.substring(0, prevCaret)); else @@ -462,13 +462,13 @@ public class TextInputField extends BasicElement { toggled = true; } - private void onDoubleClick() { + private void onDoubleClick(InputHandler inputHandler) { prevCaret = input.substring(0, caretPos).lastIndexOf(' ') + 1; caretPos = input.indexOf(' ', caretPos); if (caretPos == -1) caretPos = input.length(); selectedText = input.substring(prevCaret, caretPos); if (multiLine) { - int caretLine = Math.max(0, Math.min(wrappedText.size() - 1, (int) Math.floor((InputUtils.mouseY() - y - 10) / 24f))); + int caretLine = Math.max(0, Math.min(wrappedText.size() - 1, (int) Math.floor((inputHandler.mouseY() - y - 10) / 24f))); startLine = caretLine; endLine = caretLine; start = x + 12 + this.getTextWidth(vg, wrappedText.get(caretLine).substring(0, getLineCaret(prevCaret, startLine))); |