aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/utils/gui
diff options
context:
space:
mode:
authorWyvest <45589059+Wyvest@users.noreply.github.com>2022-07-02 06:12:23 +0700
committerWyvest <45589059+Wyvest@users.noreply.github.com>2022-07-02 06:12:23 +0700
commitd4bb5a94308d4379ef3d6cc7b9221ea0d98ff051 (patch)
tree9bb9b53e2823f73084780673763504f4098bae69 /src/main/java/cc/polyfrost/oneconfig/utils/gui
parentd2b1d57120bb51e76191302a58d935afe52b89df (diff)
downloadOneConfig-d4bb5a94308d4379ef3d6cc7b9221ea0d98ff051.tar.gz
OneConfig-d4bb5a94308d4379ef3d6cc7b9221ea0d98ff051.tar.bz2
OneConfig-d4bb5a94308d4379ef3d6cc7b9221ea0d98ff051.zip
Separate Minecraft dependant and non-dependant code
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/utils/gui')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/gui/GuiUtils.java27
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java31
2 files changed, 16 insertions, 42 deletions
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<Optional<GuiScreen>> 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<GuiScreen> optional = Optional.of(screen);
- screenQueue.add(optional);
- new TickDelay(() -> {
- UScreen.displayScreen(screen);
- screenQueue.remove(optional);
- }, ticks);
- }
-
- public static Deque<Optional<GuiScreen>> 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;
/**
* <h1>OneUIScreen</h1>
@@ -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}.
* <p> It also contains methods for mouse input. (see {@link InputUtils} for more utils).
* <p></p>
- * 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);
}
/**
@@ -77,19 +77,6 @@ public abstract class OneUIScreen extends UScreen {
}
/**
- * 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.
*/
public int getMouseX() {
@@ -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);
}
/**