diff options
6 files changed, 128 insertions, 120 deletions
diff --git a/api/OneConfig.api b/api/OneConfig.api index c59b18e..553b87c 100644 --- a/api/OneConfig.api +++ b/api/OneConfig.api @@ -496,23 +496,23 @@ public abstract interface class cc/polyfrost/oneconfig/gui/GuiPause { public abstract fun doesGuiPauseGame ()Z } -public class cc/polyfrost/oneconfig/gui/OneConfigGui : cc/polyfrost/oneconfig/libs/universal/UScreen, cc/polyfrost/oneconfig/gui/GuiPause { +public class cc/polyfrost/oneconfig/gui/OneConfigGui : cc/polyfrost/oneconfig/utils/gui/OneUIScreen { public static field INSTANCE Lcc/polyfrost/oneconfig/gui/OneConfigGui; public field allowClose Z public field currentColorSelector Lcc/polyfrost/oneconfig/gui/elements/ColorSelector; protected field currentPage Lcc/polyfrost/oneconfig/gui/pages/Page; - public field mouseDown Z protected field prevPage Lcc/polyfrost/oneconfig/gui/pages/Page; public fun <init> ()V public fun <init> (Lcc/polyfrost/oneconfig/gui/pages/Page;)V public fun closeColorSelector ()Lcc/polyfrost/oneconfig/config/core/OneColor; public static fun create ()Lcc/polyfrost/oneconfig/gui/OneConfigGui; public fun doesGuiPauseGame ()Z + public fun draw (JFLcc/polyfrost/oneconfig/utils/InputHandler;)V public fun getColor ()Lcc/polyfrost/oneconfig/config/core/OneColor; public fun getScaleFactor ()F public fun getSearchValue ()Ljava/lang/String; + public fun hasBackgroundBlur ()Z public fun initColorSelector (Lcc/polyfrost/oneconfig/gui/elements/ColorSelector;)V - public fun onDrawScreen (Lcc/polyfrost/oneconfig/libs/universal/UMatrixStack;IIF)V public fun onKeyPressed (ICLcc/polyfrost/oneconfig/libs/universal/UKeyboard$Modifiers;)V public fun onScreenClose ()V public fun openPage (Lcc/polyfrost/oneconfig/gui/pages/Page;)V @@ -1592,6 +1592,7 @@ public abstract class cc/polyfrost/oneconfig/utils/gui/OneUIScreen : cc/polyfros public fun <init> (ZZ)V public fun doesGuiPauseGame ()Z public abstract fun draw (JFLcc/polyfrost/oneconfig/utils/InputHandler;)V + public fun hasBackgroundBlur ()Z public final fun onDrawScreen (Lcc/polyfrost/oneconfig/libs/universal/UMatrixStack;IIF)V } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java index c0c4c96..9017230 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java @@ -47,15 +47,15 @@ import cc.polyfrost.oneconfig.renderer.scissor.ScissorManager; import cc.polyfrost.oneconfig.utils.InputHandler; import cc.polyfrost.oneconfig.utils.color.ColorPalette; import cc.polyfrost.oneconfig.utils.gui.GuiUtils; +import cc.polyfrost.oneconfig.utils.gui.OneUIScreen; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.lwjgl.nanovg.NanoVG; import java.util.ArrayList; -public class OneConfigGui extends UScreen implements GuiPause { +public class OneConfigGui extends OneUIScreen { 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<>(); @@ -63,7 +63,6 @@ public class OneConfigGui extends UScreen implements GuiPause { private final BasicElement backArrow = new BasicElement(40, 40, new ColorPalette(Colors.GRAY_700, Colors.GRAY_500, Colors.GRAY_500_80), true); private final BasicElement forwardArrow = new BasicElement(40, 40, new ColorPalette(Colors.GRAY_700, Colors.GRAY_500, Colors.GRAY_500_80), true); public ColorSelector currentColorSelector; - public boolean mouseDown; public boolean allowClose = true; protected Page currentPage; protected Page prevPage; @@ -84,125 +83,121 @@ public class OneConfigGui extends UScreen implements GuiPause { } @Override - public void onDrawScreen(@NotNull UMatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { - super.onDrawScreen(matrixStack, mouseX, mouseY, partialTicks); + public void draw(long vg, float partialTicks, InputHandler inputHandler) { long start = System.nanoTime(); - RenderManager.setupAndDraw((vg) -> { - if (currentPage == null) { - currentPage = new ModsPage(); - currentPage.parents.add(currentPage); - } - if (OneConfigConfig.australia) { - NanoVG.nvgTranslate(vg, UResolution.getWindowWidth(), UResolution.getWindowHeight()); - NanoVG.nvgRotate(vg, (float) Math.toRadians(180)); - } - scale = Preferences.enableCustomScale ? Preferences.customScale : Math.min(UResolution.getWindowWidth() / 1920f, UResolution.getWindowHeight() / 1080f); - if (scale < 1 && !Preferences.enableCustomScale) - scale = Math.min(Math.min(1f, UResolution.getWindowWidth() / 1280f), Math.min(1f, UResolution.getWindowHeight() / 800f)); - scale = (float) (Math.floor(scale / 0.05f) * 0.05f); - 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); + if (currentPage == null) { + currentPage = new ModsPage(); + currentPage.parents.add(currentPage); + } + if (OneConfigConfig.australia) { + NanoVG.nvgTranslate(vg, UResolution.getWindowWidth(), UResolution.getWindowHeight()); + NanoVG.nvgRotate(vg, (float) Math.toRadians(180)); + } + scale = Preferences.enableCustomScale ? Preferences.customScale : Math.min(UResolution.getWindowWidth() / 1920f, UResolution.getWindowHeight() / 1080f); + if (scale < 1 && !Preferences.enableCustomScale) + scale = Math.min(Math.min(1f, UResolution.getWindowWidth() / 1280f), Math.min(1f, UResolution.getWindowHeight() / 800f)); + scale = (float) (Math.floor(scale / 0.05f) * 0.05f); + 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); - RenderManager.drawRoundedRect(vg, x, y, 244, 800, Colors.GRAY_800_95, 20f); - RenderManager.drawRect(vg, x + 224, y, 20, 800, Colors.GRAY_800); - RenderManager.drawHollowRoundRect(vg, x - 1, y - 1, 1282, 802, 0x4DCCCCCC, 20, scale < 1 ? 1 / scale : 1); + RenderManager.drawDropShadow(vg, x, y, 1280, 800, 32, 0, 20); + RenderManager.drawRoundedRect(vg, x + 224, y, 1056, 800, Colors.GRAY_800, 20f); + RenderManager.drawRoundedRect(vg, x, y, 244, 800, Colors.GRAY_800_95, 20f); + RenderManager.drawRect(vg, x + 224, y, 20, 800, Colors.GRAY_800); + RenderManager.drawHollowRoundRect(vg, x - 1, y - 1, 1282, 802, 0x4DCCCCCC, 20, scale < 1 ? 1 / scale : 1); - RenderManager.drawLine(vg, x + 224, y + 72, x + 1280, y + 72, 1, Colors.GRAY_700); - RenderManager.drawLine(vg, x + 224, y, x + 222, y + 800, 1, Colors.GRAY_700); + RenderManager.drawLine(vg, x + 224, y + 72, x + 1280, y + 72, 1, Colors.GRAY_700); + 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, -1, 18f, Fonts.BOLD); // added half line height to center text - RenderManager.drawText(vg, "By Polyfrost", x + 69, y + 51, -1, 12f, Fonts.REGULAR); + RenderManager.drawSvg(vg, SVGs.ONECONFIG, x + 19, y + 19, 42, 42); + 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, inputHandler); - sideBar.draw(vg, x, y, inputHandler); - backArrow.draw(vg, x + 240, y + 16, inputHandler); - forwardArrow.draw(vg, x + 288, y + 16, inputHandler); + 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); - RenderManager.setAlpha(vg, 0.5f); - } else { - backArrow.disable(false); - if (!backArrow.isHovered() || Platform.getMousePlatform().isButtonDown(0)) - RenderManager.setAlpha(vg, 0.8f); - } - RenderManager.drawSvg(vg, SVGs.CARET_LEFT, x + 246, y + 22, 28, 28); - RenderManager.setAlpha(vg, 1f); - if (nextPages.size() == 0) { - forwardArrow.disable(true); - RenderManager.setAlpha(vg, 0.5f); - } else { - forwardArrow.disable(false); - if (!forwardArrow.isHovered() || Platform.getMousePlatform().isButtonDown(0)) - RenderManager.setAlpha(vg, 0.8f); - } - RenderManager.drawSvg(vg, SVGs.CARET_RIGHT, x + 294, y + 22, 28, 28); - RenderManager.setAlpha(vg, 1f); + if (previousPages.size() == 0) { + backArrow.disable(true); + RenderManager.setAlpha(vg, 0.5f); + } else { + backArrow.disable(false); + if (!backArrow.isHovered() || Platform.getMousePlatform().isButtonDown(0)) + RenderManager.setAlpha(vg, 0.8f); + } + RenderManager.drawSvg(vg, SVGs.CARET_LEFT, x + 246, y + 22, 28, 28); + RenderManager.setAlpha(vg, 1f); + if (nextPages.size() == 0) { + forwardArrow.disable(true); + RenderManager.setAlpha(vg, 0.5f); + } else { + forwardArrow.disable(false); + if (!forwardArrow.isHovered() || Platform.getMousePlatform().isButtonDown(0)) + RenderManager.setAlpha(vg, 0.8f); + } + RenderManager.drawSvg(vg, SVGs.CARET_RIGHT, x + 294, y + 22, 28, 28); + RenderManager.setAlpha(vg, 1f); - if (backArrow.isClicked() && previousPages.size() > 0) { - try { - nextPages.add(0, currentPage); - openPage(previousPages.get(0), false); - previousPages.remove(0); - } catch (Exception ignored) { - } - } else if (forwardArrow.isClicked() && nextPages.size() > 0) { - try { - previousPages.add(0, currentPage); - openPage(nextPages.get(0), new EaseInOutQuad(300, 224, 2128, true), false); - nextPages.remove(0); - } catch (Exception ignored) { - } + if (backArrow.isClicked() && previousPages.size() > 0) { + try { + nextPages.add(0, currentPage); + openPage(previousPages.get(0), false); + previousPages.remove(0); + } catch (Exception ignored) { + } + } else if (forwardArrow.isClicked() && nextPages.size() > 0) { + try { + previousPages.add(0, currentPage); + openPage(nextPages.get(0), new EaseInOutQuad(300, 224, 2128, true), false); + nextPages.remove(0); + } catch (Exception ignored) { } + } - ScissorManager.scissor(vg, x + 224, y + 72, 1056, 728); - 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, inputHandler); - currentPage.scrollWithDraw(vg, (int) (x - 1904 + pageProgress), y + 72, inputHandler); - } else { - prevPage.scrollWithDraw(vg, (int) (x - 1904 + pageProgress), y + 72, inputHandler); - currentPage.scrollWithDraw(vg, (int) (x + pageProgress), y + 72, inputHandler); - } - if (animation.isFinished()) { - prevPage = null; - } + ScissorManager.scissor(vg, x + 224, y + 72, 1056, 728); + 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, inputHandler); + currentPage.scrollWithDraw(vg, (int) (x - 1904 + pageProgress), y + 72, inputHandler); } else { - currentPage.scrollWithDraw(vg, x + 224, y + 72, inputHandler); + prevPage.scrollWithDraw(vg, (int) (x - 1904 + pageProgress), y + 72, inputHandler); + currentPage.scrollWithDraw(vg, (int) (x + pageProgress), y + 72, inputHandler); } - ScissorManager.clearScissors(vg); - 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 = 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 && inputHandler.isClicked()) openPage(currentPage.parents.get(i)); - breadcrumbX += width + 32; + if (animation.isFinished()) { + prevPage = null; } + } else { + currentPage.scrollWithDraw(vg, x + 224, y + 72, inputHandler); + } + ScissorManager.clearScissors(vg); + inputHandler.stopBlock(blockedClicks); - long end = System.nanoTime() - start; - String s = (" draw: " + end / 1000000f + "ms"); - RenderManager.drawText(vg, s, x + 1170, y + 792, Colors.GRAY_300, 10f, Fonts.MEDIUM); - if (currentColorSelector != null) { - currentColorSelector.draw(vg); - } - }); - mouseDown = Platform.getMousePlatform().isButtonDown(0); + 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 = 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 && inputHandler.isClicked()) openPage(currentPage.parents.get(i)); + breadcrumbX += width + 32; + } + + long end = System.nanoTime() - start; + String s = (" draw: " + end / 1000000f + "ms"); + RenderManager.drawText(vg, s, x + 1170, y + 792, Colors.GRAY_300, 10f, Fonts.MEDIUM); + if (currentColorSelector != null) { + currentColorSelector.draw(vg); + } } @Override @@ -303,4 +298,9 @@ public class OneConfigGui extends UScreen implements GuiPause { public boolean doesGuiPauseGame() { return false; } + + @Override + public boolean hasBackgroundBlur() { + return Preferences.enableBlur; + } } 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 0fa5514..d93445b 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java @@ -47,6 +47,7 @@ import cc.polyfrost.oneconfig.utils.IOUtils; import cc.polyfrost.oneconfig.utils.InputHandler; import cc.polyfrost.oneconfig.utils.NetworkUtils; import cc.polyfrost.oneconfig.utils.color.ColorPalette; +import cc.polyfrost.oneconfig.utils.gui.GuiUtils; import java.awt.*; import java.util.ArrayList; @@ -358,7 +359,7 @@ public class ColorSelector { color.setChromaSpeed((int) speedInput.getCurrentValue()); } setXYFromColor(); - } else if (OneConfigGui.INSTANCE.mouseDown) { + } else if (GuiUtils.wasMouseDown()) { saturationInput.setInput(String.format("%.01f", (float) color.getSaturation())); brightnessInput.setInput(String.format("%.01f", (float) color.getBrightness())); if (!alphaInput.arrowsClicked()) { 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 45242b2..2eb3349 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java @@ -91,6 +91,13 @@ public abstract class OneUIScreen extends UScreen implements GuiPause { */ public abstract void draw(long vg, float partialTicks, InputHandler inputHandler); + /** + * @return If this gui has background blur + */ + public boolean hasBackgroundBlur() { + return false; + } + @Override public boolean doesGuiPauseGame() { return false; diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/internal/gui/impl/BlurHandlerImpl.java b/versions/src/main/java/cc/polyfrost/oneconfig/internal/gui/impl/BlurHandlerImpl.java index eed82a2..50e8cef 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/internal/gui/impl/BlurHandlerImpl.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/internal/gui/impl/BlurHandlerImpl.java @@ -29,8 +29,6 @@ package cc.polyfrost.oneconfig.internal.gui.impl; import cc.polyfrost.oneconfig.events.event.RenderEvent; import cc.polyfrost.oneconfig.events.event.ScreenOpenEvent; import cc.polyfrost.oneconfig.events.event.Stage; -import cc.polyfrost.oneconfig.gui.OneConfigGui; -import cc.polyfrost.oneconfig.internal.config.Preferences; import cc.polyfrost.oneconfig.internal.gui.BlurHandler; import cc.polyfrost.oneconfig.internal.mixin.ShaderGroupAccessor; //#if FABRIC==1 @@ -39,6 +37,7 @@ import cc.polyfrost.oneconfig.internal.mixin.ShaderGroupAccessor; import cc.polyfrost.oneconfig.libs.eventbus.Subscribe; import cc.polyfrost.oneconfig.libs.universal.UMinecraft; import cc.polyfrost.oneconfig.libs.universal.UScreen; +import cc.polyfrost.oneconfig.utils.gui.OneUIScreen; import net.minecraft.client.shader.Shader; import net.minecraft.client.shader.ShaderUniform; import net.minecraft.util.ResourceLocation; @@ -130,7 +129,7 @@ public class BlurHandlerImpl implements BlurHandler { // If a shader is not already active and the UI is // a one of ours, we should load our own blur! - if (!isShaderActive() && gui instanceof OneConfigGui && Preferences.enableBlur) { + if (!isShaderActive() && (gui instanceof OneUIScreen && ((OneUIScreen) gui).hasBackgroundBlur())) { //#if FABRIC==1 //$$ ((GameRendererAccessor) UMinecraft.getMinecraft().gameRenderer).invokeLoadShader(this.blurShader); //#else @@ -141,7 +140,7 @@ public class BlurHandlerImpl implements BlurHandler { this.progress = 0; // If a shader is active and the incoming UI is null or we have blur disabled, stop using the shader. - } else if (isShaderActive() && (gui == null || !Preferences.enableBlur)) { + } else if (isShaderActive() && (gui == null || (gui instanceof OneUIScreen && !((OneUIScreen) gui).hasBackgroundBlur()))) { String name = UMinecraft.getMinecraft().entityRenderer.getShaderGroup().getShaderGroupName(); // Only stop our specific blur ;) diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/OptifineConfigHook.java b/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/OptifineConfigHook.java index 197d9c2..124c44e 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/OptifineConfigHook.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/internal/plugin/hooks/OptifineConfigHook.java @@ -26,20 +26,20 @@ package cc.polyfrost.oneconfig.internal.plugin.hooks; -import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.platform.Platform; import cc.polyfrost.oneconfig.utils.gui.GuiUtils; +import cc.polyfrost.oneconfig.utils.gui.OneUIScreen; import java.util.Optional; public class OptifineConfigHook { public static boolean shouldNotApplyFastRender() { - if (Platform.getGuiPlatform().getCurrentScreen() instanceof OneConfigGui) { + if (Platform.getGuiPlatform().getCurrentScreen() instanceof OneUIScreen && ((OneUIScreen) Platform.getGuiPlatform().getCurrentScreen()).hasBackgroundBlur()) { return true; } for (Optional screen : GuiUtils.getScreenQueue()) { - if (screen.isPresent() && screen.get() instanceof OneConfigGui) { + if (screen.isPresent() && screen.get() instanceof OneUIScreen && ((OneUIScreen) screen.get()).hasBackgroundBlur()) { return true; } } |