From d4bb5a94308d4379ef3d6cc7b9221ea0d98ff051 Mon Sep 17 00:00:00 2001 From: Wyvest <45589059+Wyvest@users.noreply.github.com> Date: Sat, 2 Jul 2022 06:12:23 +0700 Subject: Separate Minecraft dependant and non-dependant code --- .../cc/polyfrost/oneconfig/utils/gui/GuiUtils.java | 27 +++++-------------- .../polyfrost/oneconfig/utils/gui/OneUIScreen.java | 31 +++++++--------------- 2 files changed, 16 insertions(+), 42 deletions(-) (limited to 'src/main/java/cc/polyfrost/oneconfig/utils/gui') 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 6ff0254..63203e4 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/gui/GuiUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/gui/GuiUtils.java @@ -6,13 +6,8 @@ import cc.polyfrost.oneconfig.events.event.Stage; import cc.polyfrost.oneconfig.gui.OneConfigGui; 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.platform.Platform; import cc.polyfrost.oneconfig.utils.TickDelay; -import net.minecraft.client.gui.GuiScreen; - -import java.util.Deque; -import java.util.Optional; -import java.util.concurrent.ConcurrentLinkedDeque; /** * A class containing utility methods for working with GuiScreens. @@ -20,7 +15,6 @@ import java.util.concurrent.ConcurrentLinkedDeque; public final class GuiUtils { private static long time = -1L; private static long deltaTime = 17L; - private static final Deque> screenQueue = new ConcurrentLinkedDeque<>(); static { EventManager.INSTANCE.register(new GuiUtils()); @@ -30,8 +24,10 @@ public final class GuiUtils { * Displays a screen after a tick, preventing mouse sync issues. * * @param screen the screen to display. + * @deprecated Not actually deprecated, but should not be used. */ - public static void displayScreen(GuiScreen screen) { + @Deprecated + public static void displayScreen(Object screen) { displayScreen(screen, screen instanceof OneConfigGui ? 2 : 1); } @@ -41,24 +37,15 @@ public final class GuiUtils { * @param screen the screen to display. * @param ticks the amount of ticks to wait for before displaying the screen. */ - public static void displayScreen(GuiScreen screen, int ticks) { - Optional optional = Optional.of(screen); - screenQueue.add(optional); - new TickDelay(() -> { - UScreen.displayScreen(screen); - screenQueue.remove(optional); - }, ticks); - } - - public static Deque> getScreenQueue() { - return screenQueue; + public static void displayScreen(Object screen, int ticks) { + new TickDelay(() -> Platform.getGuiPlatform().setCurrentScreen(screen), ticks); } /** * Close the current open GUI screen. */ public static void closeScreen() { - UScreen.displayScreen(null); + Platform.getGuiPlatform().setCurrentScreen(null); } /** 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 7459224..2dd961e 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java @@ -1,12 +1,12 @@ package cc.polyfrost.oneconfig.utils.gui; -import cc.polyfrost.oneconfig.renderer.RenderManager; -import cc.polyfrost.oneconfig.utils.InputUtils; +import cc.polyfrost.oneconfig.gui.GuiPause; import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; import cc.polyfrost.oneconfig.libs.universal.UScreen; -import net.minecraft.client.gui.GuiScreen; +import cc.polyfrost.oneconfig.platform.Platform; +import cc.polyfrost.oneconfig.renderer.RenderManager; +import cc.polyfrost.oneconfig.utils.InputUtils; import org.jetbrains.annotations.NotNull; -import org.lwjgl.input.Mouse; /** *

OneUIScreen

@@ -14,9 +14,9 @@ import org.lwjgl.input.Mouse; * It contains many handy methods for rendering, including {@link #draw(long, float)} for drawing using OneConfig's {@link RenderManager}. *

It also contains methods for mouse input. (see {@link InputUtils} for more utils). *

- * Use {@link GuiUtils#displayScreen(GuiScreen)} to display a screen; and {@link GuiUtils#closeScreen()} to close it. + * Use GuiUtils to display a screen; and GuiUtils.closeScreen to close it. */ -public abstract class OneUIScreen extends UScreen { +public abstract class OneUIScreen extends UScreen implements GuiPause { private boolean mouseDown; private boolean blockClicks; @@ -40,7 +40,7 @@ public abstract class OneUIScreen extends UScreen { public 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 = Mouse.isButtonDown(0); + mouseDown = Platform.getMousePlatform().isButtonDown(0); } /** @@ -76,19 +76,6 @@ public abstract class OneUIScreen extends UScreen { return true; } - /** - * Use this method to declare weather or not this Screen pauses the game when it is open. (Single-player only) Its default is false. - */ - public boolean doesScreenPauseGame() { - return false; - } - - @Override - public boolean doesGuiPauseGame() { - return doesScreenPauseGame(); - } - - /** * Get the current x position of the mouse. */ @@ -114,7 +101,7 @@ public abstract class OneUIScreen extends UScreen { * @param ignoreBlockClicks whether to ignore the current click blocker. */ public boolean isClicked(boolean ignoreBlockClicks) { - return mouseDown && !Mouse.isButtonDown(0) && (!blockClicks || ignoreBlockClicks); + return mouseDown && !Platform.getMousePlatform().isButtonDown(0) && (!blockClicks || ignoreBlockClicks); } /** @@ -128,7 +115,7 @@ public abstract class OneUIScreen extends UScreen { * 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. */ public boolean isMouseDown() { - return Mouse.isButtonDown(0); + return Platform.getMousePlatform().isButtonDown(0); } /** -- cgit