diff options
Diffstat (limited to 'src')
35 files changed, 317 insertions, 321 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java b/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java index 64c31cf..82d8b31 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/BasicOption.java @@ -27,6 +27,7 @@ package cc.polyfrost.oneconfig.config.elements; import cc.polyfrost.oneconfig.config.Config; +import cc.polyfrost.oneconfig.utils.InputHandler; import java.lang.reflect.Field; import java.util.ArrayList; @@ -91,7 +92,7 @@ public abstract class BasicOption { * @param x x position * @param y y position */ - public abstract void draw(long vg, int x, int y); + public abstract void draw(long vg, int x, int y, InputHandler inputHandler); /** * Function that gets called last drawing option, @@ -101,7 +102,7 @@ public abstract class BasicOption { * @param x x position * @param y y position */ - public void drawLast(long vg, int x, int y) { + public void drawLast(long vg, int x, int y , InputHandler inputHandler) { } /** diff --git a/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java index 80e8964..282f30f 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/elements/OptionSubcategory.java @@ -32,6 +32,7 @@ import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.elements.config.ConfigPageButton; import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.renderer.font.Fonts; +import cc.polyfrost.oneconfig.utils.InputHandler; import java.util.ArrayList; import java.util.List; @@ -49,7 +50,7 @@ public class OptionSubcategory { this.name = name; } - public int draw(long vg, int x, int y) { + public int draw(long vg, int x, int y, InputHandler inputHandler) { String filter = OneConfigGui.INSTANCE == null ? "" : OneConfigGui.INSTANCE.getSearchValue().toLowerCase().trim(); filteredOptions = options.stream().filter(option -> !option.isHidden() && (filter.equals("") || name.toLowerCase().contains(filter) || option.name.toLowerCase().contains(filter))).collect(Collectors.toList()); List<ConfigPageButton> filteredTop = topButtons.stream().filter(page -> !page.isHidden() && (filter.equals("") || name.toLowerCase().contains(filter) || page.name.toLowerCase().contains(filter) || page.description.toLowerCase().contains(filter))).collect(Collectors.toList()); @@ -62,7 +63,7 @@ public class OptionSubcategory { } for (ConfigPageButton page : filteredTop) { - page.draw(vg, x, optionY); + page.draw(vg, x, optionY, inputHandler); optionY += page.getHeight() + 16; } @@ -88,11 +89,11 @@ public class OptionSubcategory { if (filteredOptions.size() > 0) { for (int i = 0; i < filteredOptions.size(); i++) { BasicOption option = filteredOptions.get(i); - option.draw(vg, x, optionY); + option.draw(vg, x, optionY, inputHandler); if (i + 1 < filteredOptions.size()) { BasicOption nextOption = filteredOptions.get(i + 1); if (option.size == 1 && nextOption.size == 1) { - nextOption.draw(vg, x + 512, optionY); + nextOption.draw(vg, x + 512, optionY, inputHandler); optionY += Math.max(option.getHeight(), nextOption.getHeight()) + 16; i++; continue; @@ -104,21 +105,21 @@ public class OptionSubcategory { } for (ConfigPageButton page : filteredBottom) { - page.draw(vg, x, optionY); + page.draw(vg, x, optionY, inputHandler); optionY += page.getHeight() + 16; } return optionY - y; } - public void drawLast(long vg, int x) { + public void drawLast(long vg, int x, InputHandler inputHandler) { for (int i = 0; i < filteredOptions.size(); i++) { BasicOption option = filteredOptions.get(i); - option.drawLast(vg, x, drawLastY); + option.drawLast(vg, x, drawLastY, inputHandler); if (i + 1 < filteredOptions.size()) { BasicOption nextOption = filteredOptions.get(i + 1); if (option.size == 1 && nextOption.size == 1) { - nextOption.drawLast(vg, x + 512, drawLastY); + nextOption.drawLast(vg, x + 512, drawLastY, inputHandler); drawLastY += Math.max(option.getHeight(), nextOption.getHeight()) + 16; i++; continue; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java index ba04aff..c0c4c96 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java @@ -38,16 +38,13 @@ import cc.polyfrost.oneconfig.internal.assets.Colors; import cc.polyfrost.oneconfig.internal.assets.SVGs; import cc.polyfrost.oneconfig.internal.config.OneConfigConfig; import cc.polyfrost.oneconfig.internal.config.Preferences; -import cc.polyfrost.oneconfig.libs.universal.UKeyboard; -import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; -import cc.polyfrost.oneconfig.libs.universal.UResolution; -import cc.polyfrost.oneconfig.libs.universal.UScreen; +import cc.polyfrost.oneconfig.libs.universal.*; 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.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.gui.GuiUtils; import org.jetbrains.annotations.NotNull; @@ -58,6 +55,7 @@ import java.util.ArrayList; public class OneConfigGui extends UScreen implements GuiPause { public static OneConfigGui INSTANCE; + private InputHandler inputHandler = new InputHandler(); private final SideBar sideBar = new SideBar(); private final TextInputField textInputField = new TextInputField(248, 40, "Search...", false, false, SVGs.MAGNIFYING_GLASS_BOLD); private final ArrayList<Page> previousPages = new ArrayList<>(); @@ -105,6 +103,7 @@ public class OneConfigGui extends UScreen implements GuiPause { int x = (int) ((UResolution.getWindowWidth() - 1280 * scale) / 2f / scale); int y = (int) ((UResolution.getWindowHeight() - 800 * scale) / 2f / scale); RenderManager.scale(vg, scale, scale); + inputHandler.scale(scale, scale); RenderManager.drawDropShadow(vg, x, y, 1280, 800, 32, 0, 20); RenderManager.drawRoundedRect(vg, x + 224, y, 1056, 800, Colors.GRAY_800, 20f); @@ -119,10 +118,10 @@ public class OneConfigGui extends UScreen implements GuiPause { RenderManager.drawText(vg, "OneConfig", x + 69, y + 32, -1, 18f, Fonts.BOLD); // added half line height to center text RenderManager.drawText(vg, "By Polyfrost", x + 69, y + 51, -1, 12f, Fonts.REGULAR); - textInputField.draw(vg, x + 1020, y + 16); - sideBar.draw(vg, x, y); - backArrow.draw(vg, x + 240, y + 16); - forwardArrow.draw(vg, x + 288, y + 16); + textInputField.draw(vg, x + 1020, y + 16, inputHandler); + sideBar.draw(vg, x, y, inputHandler); + backArrow.draw(vg, x + 240, y + 16, inputHandler); + forwardArrow.draw(vg, x + 288, y + 16, inputHandler); if (previousPages.size() == 0) { backArrow.disable(true); @@ -162,37 +161,37 @@ public class OneConfigGui extends UScreen implements GuiPause { } ScissorManager.scissor(vg, x + 224, y + 72, 1056, 728); - Scissor blockedClicks = InputUtils.blockInputArea(x + 224, y, 1056, 72); + Scissor blockedClicks = inputHandler.blockInputArea(x + 224, y, 1056, 72); if (prevPage != null && animation != null) { float pageProgress = animation.get(GuiUtils.getDeltaTime()); if (!animation.isReversed()) { - prevPage.scrollWithDraw(vg, (int) (x + pageProgress), y + 72); - currentPage.scrollWithDraw(vg, (int) (x - 1904 + pageProgress), y + 72); + prevPage.scrollWithDraw(vg, (int) (x + pageProgress), y + 72, inputHandler); + currentPage.scrollWithDraw(vg, (int) (x - 1904 + pageProgress), y + 72, inputHandler); } else { - prevPage.scrollWithDraw(vg, (int) (x - 1904 + pageProgress), y + 72); - currentPage.scrollWithDraw(vg, (int) (x + pageProgress), y + 72); + prevPage.scrollWithDraw(vg, (int) (x - 1904 + pageProgress), y + 72, inputHandler); + currentPage.scrollWithDraw(vg, (int) (x + pageProgress), y + 72, inputHandler); } if (animation.isFinished()) { prevPage = null; } } else { - currentPage.scrollWithDraw(vg, x + 224, y + 72); + currentPage.scrollWithDraw(vg, x + 224, y + 72, inputHandler); } ScissorManager.clearScissors(vg); - InputUtils.stopBlock(blockedClicks); + inputHandler.stopBlock(blockedClicks); float breadcrumbX = x + 352; for (int i = 0; i < currentPage.parents.size(); i++) { String title = currentPage.parents.get(i).getTitle(); float width = RenderManager.getTextWidth(vg, title, 24f, Fonts.SEMIBOLD); - boolean hovered = InputUtils.isAreaHovered((int) breadcrumbX, y + 24, (int) width, 36); + boolean hovered = inputHandler.isAreaHovered((int) breadcrumbX, y + 24, (int) width, 36); int color = Colors.WHITE_60; if (i == currentPage.parents.size() - 1) color = Colors.WHITE; else if (hovered && !Platform.getMousePlatform().isButtonDown(0)) color = Colors.WHITE_80; RenderManager.drawText(vg, title, breadcrumbX, y + 38, color, 24f, Fonts.SEMIBOLD); if (i != 0) RenderManager.drawSvg(vg, SVGs.CARET_RIGHT, breadcrumbX - 28, y + 25, 24, 24, color); - if (hovered && InputUtils.isClicked()) openPage(currentPage.parents.get(i)); + if (hovered && inputHandler.isClicked()) openPage(currentPage.parents.get(i)); breadcrumbX += width + 32; } @@ -264,7 +263,7 @@ public class OneConfigGui extends UScreen implements GuiPause { /** * initialize a new ColorSelector and add it to the draw script. This method is used to make sure it is always rendered on top. * <p> - * Correct usage: <code>OneConfigGui.INSTANCE.initColorSelector(new ColorSelector(color, InputUtils.mouseX(), InputUtils.mouseY()));</code> + * Correct usage: <code>OneConfigGui.INSTANCE.initColorSelector(new ColorSelector(color, inputUtils.mouseX(), inputUtils.mouseY()));</code> */ public void initColorSelector(ColorSelector colorSelector) { if (currentColorSelector != null) closeColorSelector(); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java index cad5a07..bd0503c 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/SideBar.java @@ -39,6 +39,7 @@ import cc.polyfrost.oneconfig.internal.config.Preferences; import cc.polyfrost.oneconfig.internal.gui.HudGui; 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 cc.polyfrost.oneconfig.utils.gui.GuiUtils; @@ -78,7 +79,7 @@ public class SideBar { } } - public void draw(long vg, int x, int y) { + public void draw(long vg, int x, int y, InputHandler inputHandler) { this.y = y; for (BasicButton button : buttons) { if (!button.isClicked()) continue; @@ -94,19 +95,19 @@ public class SideBar { } } - buttons.get(0).draw(vg, x + 16, y + 80); - buttons.get(1).draw(vg, x + 16, y + 116); + buttons.get(0).draw(vg, x + 16, y + 80, inputHandler); + buttons.get(1).draw(vg, x + 16, y + 116, inputHandler); RenderManager.drawText(vg, "MOD CONFIG", x + 16, y + 178, Colors.WHITE, 12, Fonts.SEMIBOLD); - buttons.get(2).draw(vg, x + 16, y + 192); - buttons.get(3).draw(vg, x + 16, y + 228); - buttons.get(4).draw(vg, x + 16, y + 264); - buttons.get(5).draw(vg, x + 16, y + 300); + buttons.get(2).draw(vg, x + 16, y + 192, inputHandler); + buttons.get(3).draw(vg, x + 16, y + 228, inputHandler); + buttons.get(4).draw(vg, x + 16, y + 264, inputHandler); + buttons.get(5).draw(vg, x + 16, y + 300, inputHandler); RenderManager.drawText(vg, "PERSONALIZATION", x + 16, y + 362, Colors.WHITE, 12, Fonts.SEMIBOLD); - buttons.get(6).draw(vg, x + 16, y + 376); - buttons.get(7).draw(vg, x + 16, y + 412); - buttons.get(8).draw(vg, x + 16, y + 448); - HUDButton.draw(vg, x + 16, y + 704); - CloseButton.draw(vg, x + 16, y + 748); + buttons.get(6).draw(vg, x + 16, y + 376, inputHandler); + buttons.get(7).draw(vg, x + 16, y + 412, inputHandler); + buttons.get(8).draw(vg, x + 16, y + 448, inputHandler); + HUDButton.draw(vg, x + 16, y + 704, inputHandler); + CloseButton.draw(vg, x + 16, y + 748, inputHandler); } public void pageOpened(String page) { 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))); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/CreditsPage.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/CreditsPage.java index df97ba6..e8a44e5 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/CreditsPage.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/CreditsPage.java @@ -29,6 +29,7 @@ package cc.polyfrost.oneconfig.gui.pages; 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.InputHandler; public class CreditsPage extends Page { public CreditsPage() { @@ -36,7 +37,7 @@ public class CreditsPage extends Page { } @Override - public void draw(long vg, int x, int y) { + public void draw(long vg, int x, int y, InputHandler inputHandler) { RenderManager.drawSvg(vg, SVGs.ONECONFIG, x + 20f, y + 20f, 96, 96); RenderManager.drawText(vg, "OneConfig", x + 130, y + 46, -1, 42, Fonts.BOLD); RenderManager.drawText(vg, "ALPHA - By Polyfrost", x + 132, y + 76, -1, 18, Fonts.MEDIUM); 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 69c3cd1..be40b3b 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java @@ -30,6 +30,7 @@ import cc.polyfrost.oneconfig.internal.assets.Colors; 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.InputHandler; public class HomePage extends Page { /*private final BasicButton socialsBtn = new BasicButton(184, 36, "Socials", SVGs.SHARE, SVGs.POP_OUT, BasicButton.ALIGNMENT_CENTER, ColorUtils.PRIMARY); @@ -57,7 +58,7 @@ public class HomePage extends Page { } - public void draw(long vg, int x, int y) { + public void draw(long vg, int x, int y, InputHandler inputHandler) { RenderManager.drawRoundedRect(vg, x, y, 184, 36, -1, 12f); RenderManager.drawText(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, Colors.PRIMARY_600, 14f); @@ -65,7 +66,7 @@ public class HomePage extends Page { RenderManager.drawText(vg, "Info", x + 52, y + 618, Colors.WHITE_90, 24f, Fonts.MEDIUM); RenderManager.drawRoundedRect(vg, x + 16, y + 644, 1024, 64, Colors.GRAY_700, 20f); - RenderManager.drawURL(vg, "https://www.youtube.com/watch?v=dQw4w9WgXcQ", x + 100, y + 205, 24, Fonts.MEDIUM); + RenderManager.drawURL(vg, "https://www.youtube.com/watch?v=dQw4w9WgXcQ", x + 100, y + 205, 24, Fonts.MEDIUM, inputHandler); /*discordBtn.draw(vg, x + 32, y + 658); webBtn.draw(vg, x + 232, y + 658); diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java index db8949c..ec1e4a1 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModConfigPage.java @@ -29,10 +29,10 @@ package cc.polyfrost.oneconfig.gui.pages; import cc.polyfrost.oneconfig.config.elements.OptionPage; import cc.polyfrost.oneconfig.config.elements.OptionSubcategory; import cc.polyfrost.oneconfig.config.elements.BasicOption; -import cc.polyfrost.oneconfig.gui.animations.DummyAnimation; import cc.polyfrost.oneconfig.gui.elements.BasicButton; 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.util.ArrayList; @@ -70,26 +70,26 @@ public class ModConfigPage extends Page { } @Override - public void draw(long vg, int x, int y) { + public void draw(long vg, int x, int y, InputHandler inputHandler) { if (page.categories.size() == 0) return; int optionY = y + (page.categories.size() == 1 ? 16 : 64); for (OptionSubcategory subCategory : page.categories.get(selectedCategory).subcategories) { - optionY += subCategory.draw(vg, x + 30, optionY); + optionY += subCategory.draw(vg, x + 30, optionY, inputHandler); } for (OptionSubcategory subCategory : page.categories.get(selectedCategory).subcategories) { - subCategory.drawLast(vg, x + 30); + subCategory.drawLast(vg, x + 30, inputHandler); } totalSize = optionY - y; } @Override - public int drawStatic(long vg, int x, int y) { + public int drawStatic(long vg, int x, int y, InputHandler inputHandler) { if (categories.size() <= 1) return 0; int buttonX = x + 16; for (BasicButton button : categories) { if (button.getWidth() == 0) button.setWidth((int) (Math.ceil(RenderManager.getTextWidth(vg, button.getText(), 12f, Fonts.MEDIUM) / 8f) * 8 + 16)); - button.draw(vg, buttonX, y + 16); + button.draw(vg, buttonX, y + 16, inputHandler); buttonX += button.getWidth() + 16; } return 60; diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java index d2df082..7dad8f0 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/ModsPage.java @@ -37,6 +37,7 @@ import cc.polyfrost.oneconfig.internal.config.core.ConfigCore; import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.renderer.TextRenderer; import cc.polyfrost.oneconfig.renderer.font.Fonts; +import cc.polyfrost.oneconfig.utils.InputHandler; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import java.util.ArrayList; @@ -65,14 +66,14 @@ public class ModsPage extends Page { modCategories.get(0).setToggled(true); } - public void draw(long vg, int x, int y) { + public void draw(long vg, int x, int y, InputHandler inputHandler) { String filter = OneConfigGui.INSTANCE == null ? "" : OneConfigGui.INSTANCE.getSearchValue().toLowerCase().trim(); int iX = x + 16; int iY = y + 72; ArrayList<ModCard> finalModCards = new ArrayList<>(modCards); for (ModCard modCard : finalModCards) { if (inSelection(modCard) && (filter.equals("") || modCard.getModData().name.toLowerCase().contains(filter))) { - if (iY + 135 >= y - scroll && iY <= y + 728 - scroll) modCard.draw(vg, iX, iY); + if (iY + 135 >= y - scroll && iY <= y + 728 - scroll) modCard.draw(vg, iX, iY, inputHandler); iX += 260; if (iX > x + 796) { iX = x + 16; @@ -87,11 +88,11 @@ public class ModsPage extends Page { } @Override - public int drawStatic(long vg, int x, int y) { + public int drawStatic(long vg, int x, int y, InputHandler inputHandler) { int iXCat = x + 16; boolean selected = false; for (BasicButton btn : modCategories) { - btn.draw(vg, iXCat, y + 16); + btn.draw(vg, iXCat, y + 16, inputHandler); iXCat += btn.getWidth() + 8; if (btn.isToggled()) selected = true; } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java index 01a1a8c..9b9b4d3 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java @@ -34,7 +34,7 @@ import cc.polyfrost.oneconfig.platform.Platform; import cc.polyfrost.oneconfig.renderer.RenderManager; 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 java.util.ArrayList; @@ -57,27 +57,27 @@ public abstract class Page { this.title = title; } - public abstract void draw(long vg, int x, int y); + public abstract void draw(long vg, int x, int y, InputHandler inputHandler); /** * Use this method to draw elements that are static on the page (ignore the scrolling). * * @return the total height of the elements, so they are excluded from the scissor rectangle. */ - public int drawStatic(long vg, int x, int y) { + public int drawStatic(long vg, int x, int y, InputHandler inputHandler) { return 0; } public void finishUpAndClose() { } - public void scrollWithDraw(long vg, int x, int y) { + public void scrollWithDraw(long vg, int x, int y, InputHandler inputHandler) { int maxScroll = getMaxScrollHeight(); - int scissorOffset = drawStatic(vg, x, y); + int scissorOffset = drawStatic(vg, x, y, inputHandler); scroll = scrollAnimation == null ? scrollTarget : scrollAnimation.get(); final float scrollBarLength = (728f / maxScroll) * 728f; Scissor scissor = ScissorManager.scissor(vg, x, y + scissorOffset, x + 1056, y + 728 - scissorOffset); - Scissor inputScissor = InputUtils.blockInputArea(x, y,1056, scissorOffset); + Scissor inputScissor = inputHandler.blockInputArea(x, y,1056, scissorOffset); float dWheel = (float) Platform.getMousePlatform().getDWheel(); if (dWheel != 0) { scrollTarget += dWheel; @@ -89,31 +89,31 @@ public abstract class Page { scrollTime = System.currentTimeMillis(); } else if (scrollAnimation != null && scrollAnimation.isFinished()) scrollAnimation = null; if (maxScroll <= 728) { - draw(vg, x, y); + draw(vg, x, y, inputHandler); ScissorManager.resetScissor(vg, scissor); - InputUtils.stopBlock(inputScissor); + inputHandler.stopBlock(inputScissor); return; } - draw(vg, x, (int) (y + scroll)); - if (dragging && InputUtils.isClicked(true)) { + draw(vg, x, (int) (y + scroll), inputHandler); + if (dragging && inputHandler.isClicked(true)) { dragging = false; } ScissorManager.resetScissor(vg, scissor); - InputUtils.stopBlock(inputScissor); + inputHandler.stopBlock(inputScissor); if (!(scrollBarLength > 727f)) { final float scrollBarY = (scroll / maxScroll) * 720f; final boolean isMouseDown = Platform.getMousePlatform().isButtonDown(0); - final boolean scrollHover = InputUtils.isAreaHovered(x + 1042, (int) (y - scrollBarY), 12, (int) scrollBarLength); + final boolean scrollHover = inputHandler.isAreaHovered(x + 1042, (int) (y - scrollBarY), 12, (int) scrollBarLength); final boolean scrollTimePeriod = (System.currentTimeMillis() - scrollTime < 1000); final boolean hovered = (scrollHover || scrollTimePeriod) && Platform.getMousePlatform().isButtonDown(0); if (scrollHover && isMouseDown && !mouseWasDown) { - yStart = InputUtils.mouseY(); + yStart = inputHandler.mouseY(); dragging = true; } mouseWasDown = isMouseDown; if (dragging) { - scrollTarget = -(InputUtils.mouseY() - yStart) * maxScroll / 728f; + scrollTarget = -(inputHandler.mouseY() - yStart) * maxScroll / 728f; if (scrollTarget > 0f) scrollTarget = 0f; else if (scrollTarget < -maxScroll + 728) scrollTarget = -maxScroll + 728; scrollAnimation = new EaseOutQuad(150, scroll, scrollTarget, false); diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/command/OneConfigCommand.java b/src/main/java/cc/polyfrost/oneconfig/internal/command/OneConfigCommand.java index 3c1aebb..4b4b4e7 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/command/OneConfigCommand.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/command/OneConfigCommand.java @@ -26,15 +26,14 @@ package cc.polyfrost.oneconfig.internal.command; +import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.internal.config.OneConfigConfig; import cc.polyfrost.oneconfig.internal.config.profiles.Profiles; import cc.polyfrost.oneconfig.internal.gui.HudGui; -import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.libs.universal.ChatColor; import cc.polyfrost.oneconfig.libs.universal.UChat; import cc.polyfrost.oneconfig.utils.commands.annotations.*; import cc.polyfrost.oneconfig.utils.gui.GuiUtils; -import cc.polyfrost.oneconfig.utils.InputUtils; /** * The main OneConfig command. @@ -60,7 +59,6 @@ public class OneConfigCommand { @Main private static void main() { OneConfigGui.INSTANCE = null; - InputUtils.stopBlockingInput(); } } diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java b/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java index 1d1670c..5e9c996 100644 --- a/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/renderer/RenderManager.java @@ -36,7 +36,7 @@ import cc.polyfrost.oneconfig.platform.NanoVGPlatform; import cc.polyfrost.oneconfig.platform.Platform; import cc.polyfrost.oneconfig.renderer.font.Font; import cc.polyfrost.oneconfig.renderer.font.FontManager; -import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.utils.InputHandler; import cc.polyfrost.oneconfig.utils.NetworkUtils; import org.lwjgl.nanovg.NVGColor; import org.lwjgl.nanovg.NVGPaint; @@ -337,13 +337,13 @@ public final class RenderManager { * <p><b>This does NOT scale to Minecraft's GUI scale!</b></p> * * @see RenderManager#drawText(long, String, float, float, int, float, Font) - * @see InputUtils#isAreaClicked(float, float, float, float) + * @see InputHandler#isAreaClicked(float, float, float, float) */ - public static void drawURL(long vg, String url, float x, float y, float size, Font font) { + public static void drawURL(long vg, String url, float x, float y, float size, Font font, InputHandler inputHandler) { drawText(vg, url, x, y, Colors.PRIMARY_500, size, font); float length = getTextWidth(vg, url, size, font); drawRect(vg, x, y + size / 2, length, 1, Colors.PRIMARY_500); - if (InputUtils.isAreaClicked((int) (x - 2), (int) (y - 1), (int) (length + 4), (int) (size / 2 + 3))) { + if (inputHandler.isAreaClicked((int) (x - 2), (int) (y - 1), (int) (length + 4), (int) (size / 2 + 3))) { NetworkUtils.browseLink(url); } } diff --git a/src/main/java/cc/polyfrost/oneconfig/renderer/TextRenderer.java b/src/main/java/cc/polyfrost/oneconfig/renderer/TextRenderer.java index 84b45a1..2eed6d7 100644 --- a/src/main/java/cc/polyfrost/oneconfig/renderer/TextRenderer.java +++ b/src/main/java/cc/polyfrost/oneconfig/renderer/TextRenderer.java @@ -28,7 +28,7 @@ package cc.polyfrost.oneconfig.renderer; import cc.polyfrost.oneconfig.internal.assets.Colors; import cc.polyfrost.oneconfig.renderer.font.Font; -import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.utils.InputHandler; import cc.polyfrost.oneconfig.utils.NetworkUtils; import com.google.common.annotations.Beta; import org.lwjgl.nanovg.NVGColor; @@ -148,13 +148,13 @@ public class TextRenderer { * <p><b>This does NOT scale to Minecraft's GUI scale!</b></p> * * @see RenderManager#drawText(long, String, float, float, int, float, Font) - * @see InputUtils#isAreaClicked(float, float, float, float) + * @see InputHandler#isAreaClicked(float, float, float, float) */ - public static void drawURL(long vg, String url, float x, float y, float size, Font font) { + public static void drawURL(long vg, String url, float x, float y, float size, Font font, InputHandler inputHandler) { drawText(vg, url, x, y, Colors.PRIMARY_500, size, font); float length = getTextWidth(vg, url, size, font); RenderManager.drawRect(vg, x, y + size / 2, length, 1, Colors.PRIMARY_500); - if (InputUtils.isAreaClicked((int) (x - 2), (int) (y - 1), (int) (length + 4), (int) (size / 2 + 3))) { + if (inputHandler.isAreaClicked((int) (x - 2), (int) (y - 1), (int) (length + 4), (int) (size / 2 + 3))) { NetworkUtils.browseLink(url); } } diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/InputHandler.java index 3fb32f7..6bd8207 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/InputHandler.java @@ -26,10 +26,10 @@ package cc.polyfrost.oneconfig.utils; -import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.libs.universal.UResolution; import cc.polyfrost.oneconfig.platform.Platform; import cc.polyfrost.oneconfig.renderer.scissor.Scissor; +import cc.polyfrost.oneconfig.utils.gui.GuiUtils; import java.util.ArrayList; @@ -40,15 +40,37 @@ import java.util.ArrayList; * For scaled values, see {@link cc.polyfrost.oneconfig.libs.universal.UMouse}. * </p> */ -public final class InputUtils { - private static final ArrayList<Scissor> blockScissors = new ArrayList<>(); +public class InputHandler { + private final ArrayList<Scissor> blockScissors = new ArrayList<>(); + private double scaleX = 1d; + private double scaleY = 1d; + + /** + * Push a scale for the input utils to use + * + * @param scaleX X scale + * @param scaleY Y scale + */ + public void scale(double scaleX, double scaleY) { + this.scaleX = scaleX; + this.scaleY = scaleY; + } + + /** + * Reset the scale input utils uses + */ + public void resetScale() { + scaleX = 1d; + scaleY = 1d; + } + /** * function to determine weather the mouse is currently over a specific region. Uses the current nvgScale to fix to any scale. * * @return true if mouse is over region, false if not. */ - public static boolean isAreaHovered(float x, float y, float width, float height, boolean ignoreBlock) { + public boolean isAreaHovered(float x, float y, float width, float height, boolean ignoreBlock) { float mouseX = mouseX(); float mouseY = mouseY(); return (ignoreBlock || blockScissors.size() == 0 || !shouldBlock(mouseX, mouseY)) && mouseX > x && mouseY > y && mouseX < x + width && mouseY < y + height; @@ -59,7 +81,7 @@ public final class InputUtils { * * @return true if mouse is over region, false if not. */ - public static boolean isAreaHovered(float x, float y, float width, float height) { + public boolean isAreaHovered(float x, float y, float width, float height) { return isAreaHovered(x, y, width, height, false); } @@ -72,9 +94,9 @@ public final class InputUtils { * @param height the height of the region * @param ignoreBlock if true, will ignore * @return true if the mouse is clicked and is over the region, false if not - * @see InputUtils#isAreaHovered(float, float, float, float) + * @see InputHandler#isAreaHovered(float, float, float, float) */ - public static boolean isAreaClicked(float x, float y, float width, float height, boolean ignoreBlock) { + public boolean isAreaClicked(float x, float y, float width, float height, boolean ignoreBlock) { return isAreaHovered(x, y, width, height, ignoreBlock) && isClicked(false); } @@ -86,9 +108,9 @@ public final class InputUtils { * @param width the width of the region * @param height the height of the region * @return true if the mouse is clicked and is over the region, false if not - * @see InputUtils#isAreaClicked(float, float, float, float, boolean) + * @see InputHandler#isAreaClicked(float, float, float, float, boolean) */ - public static boolean isAreaClicked(float x, float y, float width, float height) { + public boolean isAreaClicked(float x, float y, float width, float height) { return isAreaClicked(x, y, width, height, false); } @@ -98,17 +120,17 @@ public final class InputUtils { * @param ignoreBlock if true, will ignore * @return true if the mouse is clicked, false if not */ - public static boolean isClicked(boolean ignoreBlock) { - return OneConfigGui.INSTANCE != null && OneConfigGui.INSTANCE.mouseDown && !Platform.getMousePlatform().isButtonDown(0) && (ignoreBlock || blockScissors.size() == 0 || !shouldBlock(mouseX(), mouseY())); + public boolean isClicked(boolean ignoreBlock) { + return GuiUtils.wasMouseDown() && !Platform.getMousePlatform().isButtonDown(0) && (ignoreBlock || blockScissors.size() == 0 || !shouldBlock(mouseX(), mouseY())); } /** * Checks whether the mouse is clicked or not. * * @return true if the mouse is clicked, false if not - * @see InputUtils#isClicked(boolean) + * @see InputHandler#isClicked(boolean) */ - public static boolean isClicked() { + public boolean isClicked() { return isClicked(false); } @@ -121,9 +143,8 @@ public final class InputUtils { * * @return the current mouse X position */ - public static float mouseX() { - if (OneConfigGui.INSTANCE == null) return (float) Platform.getMousePlatform().getMouseX(); - return (float) (Platform.getMousePlatform().getMouseX() / OneConfigGui.INSTANCE.getScaleFactor()); + public float mouseX() { + return (float) (Platform.getMousePlatform().getMouseX() / scaleX); } /** @@ -135,9 +156,8 @@ public final class InputUtils { * * @return the current mouse Y position */ - public static float mouseY() { - if (OneConfigGui.INSTANCE == null) return (float) (UResolution.getWindowHeight() - Math.abs(Platform.getMousePlatform().getMouseY())); - return (float) ((UResolution.getWindowHeight() - Math.abs(Platform.getMousePlatform().getMouseY())) / OneConfigGui.INSTANCE.getScaleFactor()); + public float mouseY() { + return (float) ((UResolution.getWindowHeight() - Math.abs(Platform.getMousePlatform().getMouseY())) / scaleY); } /** @@ -148,7 +168,7 @@ public final class InputUtils { * @param width Width * @param height Height */ - public static Scissor blockInputArea(float x, float y, float width, float height) { + public Scissor blockInputArea(float x, float y, float width, float height) { Scissor scissor = new Scissor(new Scissor(x, y, width, height)); blockScissors.add(scissor); return scissor; @@ -157,7 +177,7 @@ public final class InputUtils { /** * Should be used if there is something above other components and you don't want it clicking trough */ - public static Scissor blockAllInput() { + public Scissor blockAllInput() { return blockInputArea(0, 0, 1920, 1080); } @@ -166,14 +186,14 @@ public final class InputUtils { * * @param scissor The scissor area */ - public static void stopBlock(Scissor scissor) { + public void stopBlock(Scissor scissor) { blockScissors.remove(scissor); } /** * Clears all blocking areas */ - public static void stopBlockingInput() { + public void stopBlockingInput() { blockScissors.clear(); } @@ -182,11 +202,11 @@ public final class InputUtils { * * @return true if clicks are blocked, false if not */ - public static boolean isBlockingInput() { + public boolean isBlockingInput() { return blockScissors.size() > 0; } - private static boolean shouldBlock(float x, float y) { + private boolean shouldBlock(float x, float y) { for (Scissor block : blockScissors) { if (block.isInScissor(x, y)) return true; } diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/gui/GuiUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/gui/GuiUtils.java index e3dffb6..71bba26 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/gui/GuiUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/gui/GuiUtils.java @@ -41,6 +41,7 @@ import cc.polyfrost.oneconfig.utils.TickDelay; public final class GuiUtils { private static long time = -1L; private static long deltaTime = 17L; + private static boolean wasMouseDown = false; static { EventManager.INSTANCE.register(new GuiUtils()); @@ -86,6 +87,13 @@ public final class GuiUtils { return deltaTime; } + /** + * @return If the mouse was down last frame + */ + public static boolean wasMouseDown() { + return wasMouseDown; + } + @Subscribe private void onRenderEvent(RenderEvent event) { if (event.stage == Stage.START) { @@ -95,6 +103,8 @@ public final class GuiUtils { deltaTime = currentTime - time; time = currentTime; } + } else if (event.stage == Stage.END) { + wasMouseDown = Platform.getMousePlatform().isButtonDown(0); } } } diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java b/src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java index 5f93c7b..45242b2 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java @@ -28,115 +28,68 @@ package cc.polyfrost.oneconfig.utils.gui; import cc.polyfrost.oneconfig.gui.GuiPause; import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; +import cc.polyfrost.oneconfig.libs.universal.UResolution; import cc.polyfrost.oneconfig.libs.universal.UScreen; -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 org.jetbrains.annotations.NotNull; /** * <h1>OneUIScreen</h1> * OneUIScreen is a GUI that can be used to render things on the client's screen. - * It contains many handy methods for rendering, including {@link #draw(long, float)} for drawing using OneConfig's {@link RenderManager}. - * <p> It also contains methods for mouse input. (see {@link InputUtils} for more utils). + * It contains many handy methods for rendering, including {@link #draw(long, float, InputHandler)} for drawing using OneConfig's {@link RenderManager}. + * <p> It also contains methods for mouse input. (see {@link InputHandler} for more utils). * <p></p> * Use GuiUtils to display a screen; and GuiUtils.closeScreen to close it. */ public abstract class OneUIScreen extends UScreen implements GuiPause { - private boolean mouseDown; - private boolean blockClicks; + private final boolean useMinecraftScale; + private final InputHandler inputHandler = new InputHandler(); /** * Create a new OneUIScreen. * + * @param useMinecraftScale wether to use Minecraft scale * @param restoreGuiOnClose use this to declare weather or not to open the Gui that was open before it when this screen is closed. */ - public OneUIScreen(boolean restoreGuiOnClose) { + public OneUIScreen(boolean useMinecraftScale, boolean restoreGuiOnClose) { super(restoreGuiOnClose); + this.useMinecraftScale = useMinecraftScale; + } + + /** + * Create a new OneUIScreen. + * + * @param useMinecraftScale wether to use Minecraft scale + */ + public OneUIScreen(boolean useMinecraftScale) { + this(useMinecraftScale, false); } /** * Create a new OneUIScreen. */ public OneUIScreen() { - super(false); + this(false, false); } @Override public final void onDrawScreen(@NotNull UMatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { super.onDrawScreen(matrixStack, mouseX, mouseY, partialTicks); - RenderManager.setupAndDraw(ignoreMinecraftScale(), vg -> draw(vg, partialTicks)); - mouseDown = Platform.getMousePlatform().isButtonDown(0); + if (useMinecraftScale) inputHandler.scale(UResolution.getScaleFactor(), UResolution.getScaleFactor()); + RenderManager.setupAndDraw(useMinecraftScale, vg -> draw(vg, partialTicks, inputHandler)); } - /** * Use this method to draw things on the screen. It is called every render tick, and has a handy <code>vg</code> (NanoVG context) that can be used with the {@link RenderManager} to draw things. * <p></p> * For example: <d> <code>{@link RenderManager#drawRoundedRect(long, float, float, float, float, int, float)} </code> * - * @param vg the NanoVG context you can use to render things with - * @param partialTicks the time between ticks (You can use this as a deltaTime equivalent) - */ - public abstract void draw(long vg, float partialTicks); - - /** - * Use this method to set whether to use the Minecraft scale on the GUI. Its default is true, and that is recommended for the NanoVG rendering. - */ - public boolean ignoreMinecraftScale() { - return true; - } - - /** - * Get the current x position of the mouse. - */ - protected float getMouseX() { - return InputUtils.mouseX(); - } - - /** - * Get the current y position of the mouse. - */ - protected float getMouseY() { - return InputUtils.mouseY(); - } - - /** - * Retrieve the click status of the mouse. This method uses a boolean to store the status of the mouse, so it will only return true once per click. (very useful) - * - * @param ignoreBlockClicks whether to ignore the current click blocker. - */ - protected boolean isClicked(boolean ignoreBlockClicks) { - return mouseDown && !Platform.getMousePlatform().isButtonDown(0) && (!blockClicks || ignoreBlockClicks); - } - - /** - * Retrieve the click status of the mouse. This method uses a boolean to store the status of the mouse, so it will only return true once per click. (very useful) - */ - protected boolean isClicked() { - return isClicked(false); - } - - /** - * Retrieve weather or not the mouse is currently down. Will constantly return true if its clicked. See {@link #isClicked()} for a method that only executes once per tick. - */ - protected boolean isMouseDown() { - return Platform.getMousePlatform().isButtonDown(0); - } - - /** - * Click blocking can be useful when you are drawing buttons for example over the top of other elements, so a click blocker can be used to ensure that the mouse doesn't click through things. + * @param vg The NanoVG context you can use to render things with + * @param partialTicks The time between ticks (You can use this as a deltaTime equivalent) + * @param inputHandler The input handler */ - public void shouldBlockClicks(boolean state) { - blockClicks = state; - } - - /** - * Click blocking can be useful when you are drawing buttons for example over the top of other elements, so a click blocker can be used to ensure that the mouse doesn't click through things. - */ - public boolean isBlockingClicks() { - return blockClicks; - } + public abstract void draw(long vg, float partialTicks, InputHandler inputHandler); @Override public boolean doesGuiPauseGame() { diff --git a/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/RenderManagerDSL.kt b/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/RenderManagerDSL.kt index 1dd3499..ac6ff9c 100644 --- a/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/RenderManagerDSL.kt +++ b/src/main/kotlin/cc/polyfrost/oneconfig/utils/dsl/RenderManagerDSL.kt @@ -31,6 +31,7 @@ import cc.polyfrost.oneconfig.renderer.RenderManager import cc.polyfrost.oneconfig.renderer.font.Font import cc.polyfrost.oneconfig.renderer.Image import cc.polyfrost.oneconfig.renderer.SVG +import cc.polyfrost.oneconfig.utils.InputHandler import cc.polyfrost.oneconfig.utils.color.ColorUtils import org.lwjgl.nanovg.NVGColor @@ -169,10 +170,11 @@ fun Long.drawWrappedString(text: String, x: Number, y: Number, width: Number, co fun VG.drawWrappedString(text: String, x: Number, y: Number, width: Number, color: Int, size: Number, font: Font) = instance.drawWrappedString(text, x, y, width, color, size, font) -fun Long.drawURL(url: String, x: Number, y: Number, size: Number, font: Font) = - RenderManager.drawURL(this, url, x.toFloat(), y.toFloat(), size.toFloat(), font) +fun Long.drawURL(url: String, x: Number, y: Number, size: Number, font: Font, inputHandler: InputHandler) = + RenderManager.drawURL(this, url, x.toFloat(), y.toFloat(), size.toFloat(), font, inputHandler) -fun VG.drawURL(url: String, x: Number, y: Number, size: Number, font: Font) = instance.drawURL(url, x, y, size, font) +fun VG.drawURL(url: String, x: Number, y: Number, size: Number, font: Font, inputHandler: InputHandler) = + instance.drawURL(url, x, y, size, font, inputHandler) fun Long.drawImage(filePath: String, x: Number, y: Number, width: Number, height: Number) = |