aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java
diff options
context:
space:
mode:
authorUnknown <shekwancheung0528@gmail.com>2019-08-11 23:28:33 +0800
committerUnknown <shekwancheung0528@gmail.com>2019-08-11 23:28:33 +0800
commit28025895e0da1e6079264dbfe951e7fd9bf069d8 (patch)
treebd28e2f6bf02a2806c4b7802fac912ed43444e43 /src/main/java/me/shedaniel/rei/impl/ScreenHelper.java
parent019aa13875ca639dda2f34c66e3160f72b923cfd (diff)
downloadRoughlyEnoughItems-28025895e0da1e6079264dbfe951e7fd9bf069d8.tar.gz
RoughlyEnoughItems-28025895e0da1e6079264dbfe951e7fd9bf069d8.tar.bz2
RoughlyEnoughItems-28025895e0da1e6079264dbfe951e7fd9bf069d8.zip
Scrollable Entry List?
Diffstat (limited to 'src/main/java/me/shedaniel/rei/impl/ScreenHelper.java')
-rw-r--r--src/main/java/me/shedaniel/rei/impl/ScreenHelper.java97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java b/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java
new file mode 100644
index 000000000..18bb3f2e0
--- /dev/null
+++ b/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java
@@ -0,0 +1,97 @@
+/*
+ * Roughly Enough Items by Danielshe.
+ * Licensed under the MIT License.
+ */
+
+package me.shedaniel.rei.impl;
+
+import com.google.common.collect.Lists;
+import me.shedaniel.cloth.hooks.ClothClientHooks;
+import me.shedaniel.rei.RoughlyEnoughItemsCore;
+import me.shedaniel.rei.gui.ContainerScreenOverlay;
+import me.shedaniel.rei.gui.widget.SearchFieldWidget;
+import me.shedaniel.rei.listeners.ContainerScreenHooks;
+import net.fabricmc.api.ClientModInitializer;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen;
+import net.minecraft.client.util.Window;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.ActionResult;
+import org.apache.logging.log4j.util.TriConsumer;
+
+import java.util.List;
+import java.util.Optional;
+
+public class ScreenHelper implements ClientModInitializer {
+
+ public static SearchFieldWidget searchField;
+ public static List<ItemStack> inventoryStacks = Lists.newArrayList();
+ private static boolean overlayVisible = true;
+ private static ContainerScreenOverlay overlay;
+ private static AbstractContainerScreen<?> lastContainerScreen = null;
+
+ public static boolean isOverlayVisible() {
+ return overlayVisible;
+ }
+
+ public static void toggleOverlayVisible() {
+ overlayVisible = !overlayVisible;
+ }
+
+ public static Optional<ContainerScreenOverlay> getOptionalOverlay() {
+ return Optional.ofNullable(overlay);
+ }
+
+ public static ContainerScreenOverlay getLastOverlay(boolean reset, boolean setPage) {
+ if (overlay == null || reset) {
+ overlay = new ContainerScreenOverlay();
+ overlay.init(setPage);
+ }
+ return overlay;
+ }
+
+ public static ContainerScreenOverlay getLastOverlay() {
+ return getLastOverlay(false, false);
+ }
+
+ public static AbstractContainerScreen<?> getLastContainerScreen() {
+ return lastContainerScreen;
+ }
+
+ public static void setLastContainerScreen(AbstractContainerScreen<?> lastContainerScreen) {
+ ScreenHelper.lastContainerScreen = lastContainerScreen;
+ }
+
+ public static ContainerScreenHooks getLastContainerScreenHooks() {
+ return (ContainerScreenHooks) lastContainerScreen;
+ }
+
+ public static void drawHoveringWidget(int x, int y, TriConsumer<Integer, Integer, Float> consumer, int width, int height, float delta) {
+ Window window = MinecraftClient.getInstance().window;
+ drawHoveringWidget(window.getScaledWidth(), window.getScaledHeight(), x, y, consumer, width, height, delta);
+ }
+
+ public static void drawHoveringWidget(int screenWidth, int screenHeight, int x, int y, TriConsumer<Integer, Integer, Float> consumer, int width, int height, float delta) {
+ int actualX = Math.max(x + 12, 6);
+ int actualY = Math.min(y - height / 2, screenHeight - height - 6);
+ if (actualX + width > screenWidth)
+ actualX -= 24 + width;
+ if (actualY < 6)
+ actualY += 24;
+ consumer.accept(actualX, actualY, delta);
+ }
+
+ public static boolean isDarkModeEnabled() {
+ return RoughlyEnoughItemsCore.getConfigManager().getConfig().isUsingDarkTheme();
+ }
+
+ @Override
+ public void onInitializeClient() {
+ ClothClientHooks.SCREEN_INIT_PRE.register((client, screen, screenHooks) -> {
+ if (lastContainerScreen != screen && screen instanceof AbstractContainerScreen)
+ lastContainerScreen = (AbstractContainerScreen<?>) screen;
+ return ActionResult.PASS;
+ });
+ }
+
+}