diff options
author | nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> | 2022-06-11 11:16:01 +0100 |
---|---|---|
committer | nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> | 2022-06-11 11:16:01 +0100 |
commit | 6239cf215a789a21e702cb793706ca0fa5a4bcca (patch) | |
tree | 6cc87eb30fe4606d54481b955dc76e6861299d9d /src/main/java/cc/polyfrost/oneconfig/gui | |
parent | 1ab7422957a76158883e0449ed593ac216c9ef80 (diff) | |
download | OneConfig-6239cf215a789a21e702cb793706ca0fa5a4bcca.tar.gz OneConfig-6239cf215a789a21e702cb793706ca0fa5a4bcca.tar.bz2 OneConfig-6239cf215a789a21e702cb793706ca0fa5a4bcca.zip |
Slideyboi, a couple fixes, replace print calls and test feature
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/gui')
5 files changed, 57 insertions, 19 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java index 3172336..c3ecb0c 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java @@ -8,8 +8,10 @@ import cc.polyfrost.oneconfig.gui.elements.ColorSelector; import cc.polyfrost.oneconfig.gui.elements.text.TextInputField; import cc.polyfrost.oneconfig.gui.pages.ModsPage; import cc.polyfrost.oneconfig.gui.pages.Page; +import cc.polyfrost.oneconfig.internal.OneConfig; import cc.polyfrost.oneconfig.internal.assets.Colors; import cc.polyfrost.oneconfig.internal.config.OneConfigConfig; +import cc.polyfrost.oneconfig.libs.universal.*; import cc.polyfrost.oneconfig.renderer.RenderManager; import cc.polyfrost.oneconfig.renderer.font.Fonts; import cc.polyfrost.oneconfig.internal.assets.SVGs; @@ -17,10 +19,6 @@ import cc.polyfrost.oneconfig.renderer.scissor.ScissorManager; import cc.polyfrost.oneconfig.utils.gui.GuiUtils; import cc.polyfrost.oneconfig.utils.InputUtils; import cc.polyfrost.oneconfig.utils.color.ColorPalette; -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 org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.lwjgl.input.Mouse; @@ -69,8 +67,6 @@ public class OneConfigGui extends UScreen { public void onDrawScreen(@NotNull UMatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { super.onDrawScreen(matrixStack, mouseX, mouseY, partialTicks); long start = System.nanoTime(); - int x2 = 0; - int y2 = 0; RenderManager.setupAndDraw((vg) -> { if (currentPage == null) { currentPage = new ModsPage(); @@ -96,8 +92,8 @@ public class OneConfigGui extends UScreen { RenderManager.drawLine(vg, x + 224, y, x + 222, y + 800, 1, Colors.GRAY_700); RenderManager.drawSvg(vg, SVGs.ONECONFIG, x + 19, y + 19, 42, 42); - RenderManager.drawText(vg, "OneConfig", x + 69, y + 32, Colors.WHITE, 18f, Fonts.BOLD); // added half line height to center text - RenderManager.drawText(vg, "By Polyfrost", x + 69, y + 51, Colors.WHITE, 12f, Fonts.REGULAR); + 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); @@ -139,7 +135,7 @@ public class OneConfigGui extends UScreen { } } - ScissorManager.scissor(vg, x + 224, y + 88, 1056, 698); + ScissorManager.scissor(vg, x + 224, y + 72, 1056, 728); if (prevPage != null && animation != null) { float pageProgress = animation.get(GuiUtils.getDeltaTime()); if (!animation.isReversed()) { @@ -191,8 +187,7 @@ public class OneConfigGui extends UScreen { if (currentColorSelector != null) currentColorSelector.keyTyped(typedChar, keyCode); currentPage.keyTyped(typedChar, keyCode); } catch (Exception e) { - e.printStackTrace(); - System.out.println("this should literally never happen"); + OneConfig.LOGGER.error("Error while processing keyboard input; ignoring!"); } } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/ColorAnimation.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/ColorAnimation.java index 98b2377..0c62443 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/animations/ColorAnimation.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/ColorAnimation.java @@ -3,6 +3,7 @@ package cc.polyfrost.oneconfig.gui.animations; import cc.polyfrost.oneconfig.utils.color.ColorPalette; public class ColorAnimation { + private int speed = 100; private ColorPalette palette; /** * 0 = nothing @@ -35,15 +36,25 @@ public class ColorAnimation { int state = pressed ? 2 : hovered ? 1 : 0; if (state != prevState) { float[] newColors = pressed ? palette.getPressedColorf() : hovered ? palette.getHoveredColorf() : palette.getNormalColorf(); - redAnimation = new EaseInOutQuad(100, redAnimation.get(), newColors[0], false); - greenAnimation = new EaseInOutQuad(100, greenAnimation.get(), newColors[1], false); - blueAnimation = new EaseInOutQuad(100, blueAnimation.get(), newColors[2], false); - alphaAnimation = new EaseInOutQuad(100, alphaAnimation.get(), newColors[3], false); + redAnimation = new EaseInOutQuad(speed, redAnimation.get(), newColors[0], false); + greenAnimation = new EaseInOutQuad(speed, greenAnimation.get(), newColors[1], false); + blueAnimation = new EaseInOutQuad(speed, blueAnimation.get(), newColors[2], false); + alphaAnimation = new EaseInOutQuad(speed, alphaAnimation.get(), newColors[3], false); prevState = state; } return ((int) (alphaAnimation.get() * 255) << 24) | ((int) (redAnimation.get() * 255) << 16) | ((int) (greenAnimation.get() * 255) << 8) | ((int) (blueAnimation.get() * 255)); } + /** Set the speed in milliseconds for the animation. */ + public void setSpeed(int speed) { + this.speed = speed; + } + + /** Get the speed in milliseconds for the animation. */ + public int getSpeed() { + return speed; + } + /** * Return the current alpha of the color. This method is used to get the alpha of pressed buttons that have text/icons on them, so they also darken accordingly. */ 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 0e6695f..b85d113 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 @@ -29,7 +29,7 @@ public class ConfigPageButton extends BasicOption { @Override public void draw(long vg, int x, int y) { int height = description.equals("") ? 64 : 96; - boolean hovered = InputUtils.isAreaHovered(x - 2, y, 1024, height) && isEnabled(); + boolean hovered = InputUtils.isAreaHovered(x - 16, y, 1024, height) && isEnabled(); boolean clicked = hovered && InputUtils.isClicked(); if (!isEnabled()) RenderManager.setAlpha(vg, 0.5f); 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 a43b969..c33896a 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 @@ -455,7 +455,6 @@ public class TextInputField extends BasicElement { endLine = caretLine; start = x + 12 + this.getTextWidth(vg, wrappedText.get(caretLine).substring(0, getLineCaret(prevCaret, startLine))); end = this.getTextWidth(vg, wrappedText.get(caretLine).substring(getLineCaret(prevCaret, startLine), getLineCaret(caretPos, startLine))); - System.out.println(wrappedText.get(caretLine).substring(getLineCaret(prevCaret, startLine), getLineCaret(caretPos, startLine))); } else { start = x + 12 + this.getTextWidth(vg, input.substring(0, prevCaret)); end = this.getTextWidth(vg, input.substring(prevCaret, caretPos)); 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 b1bc083..882289d 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/Page.java @@ -1,9 +1,14 @@ package cc.polyfrost.oneconfig.gui.pages; import cc.polyfrost.oneconfig.gui.animations.Animation; +import cc.polyfrost.oneconfig.gui.animations.ColorAnimation; import cc.polyfrost.oneconfig.gui.animations.EaseOutQuad; +import cc.polyfrost.oneconfig.internal.assets.Colors; +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.color.ColorPalette; import org.lwjgl.input.Mouse; /** @@ -12,9 +17,14 @@ import org.lwjgl.input.Mouse; public abstract class Page { protected final String title; private Animation scrollAnimation; + private final ColorAnimation colorAnimation = new ColorAnimation(new ColorPalette(Colors.TRANSPARENT, Colors.GRAY_400_60, Colors.GRAY_400_60)); private float scrollTarget; + private long scrollTime; + private boolean mouseWasDown, dragging; + private float yStart; - protected Page(String title) { + public Page(String title) { + colorAnimation.setSpeed(200); this.title = title; } @@ -32,10 +42,11 @@ public abstract class Page { public void finishUpAndClose() { } - public void scrollWithDraw(long vg, int x, int y) { // TODO scroll bar + public void scrollWithDraw(long vg, int x, int y) { int maxScroll = getMaxScrollHeight(); int scissorOffset = drawStatic(vg, x, y); float 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); int dWheel = Mouse.getDWheel(); if (dWheel != 0) { @@ -45,6 +56,7 @@ public abstract class Page { else if (scrollTarget < -maxScroll + 728) scrollTarget = -maxScroll + 728; scrollAnimation = new EaseOutQuad(150, scroll, scrollTarget, false); + scrollTime = System.currentTimeMillis(); } else if (scrollAnimation != null && scrollAnimation.isFinished()) scrollAnimation = null; if (maxScroll <= 728) { draw(vg, x, y); @@ -52,8 +64,29 @@ public abstract class Page { return; } draw(vg, x, (int) (y + scroll)); + if (dragging && InputUtils.isClicked(true)) { + dragging = false; + } ScissorManager.resetScissor(vg, scissor); + if(!(scrollBarLength > 727f)) { + final float scrollBarY = (scroll / maxScroll) * 720f; + final boolean isMouseDown = Mouse.isButtonDown(0); + final boolean scrollHover = InputUtils.isAreaHovered(x + 1042, (int) (y - scrollBarY), 12, (int) scrollBarLength) || (System.currentTimeMillis() - scrollTime < 1000); + final boolean hovered = scrollHover && Mouse.isButtonDown(0); + if (hovered && isMouseDown && !mouseWasDown) { + yStart = InputUtils.mouseY(); + dragging = true; + } + mouseWasDown = isMouseDown; + if(dragging) { + scrollTarget = -(InputUtils.mouseY() - yStart) * maxScroll / 728f; + if (scrollTarget > 0f) scrollTarget = 0f; + else if (scrollTarget < -maxScroll + 728) scrollTarget = -maxScroll + 728; + scrollAnimation = new EaseOutQuad(150, scroll, scrollTarget, false); + } + RenderManager.drawRoundedRect(vg, x + 1044, y - scrollBarY, 8, scrollBarLength, colorAnimation.getColor(scrollHover, dragging), 4f); + } } public String getTitle() { |