aboutsummaryrefslogtreecommitdiff
path: root/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2020-08-27 20:11:03 +0800
committershedaniel <daniel@shedaniel.me>2020-08-27 20:11:03 +0800
commitff9c8e83f0eaf3791e4939b491979d23bdca5577 (patch)
treeef323a6dc477a03f05b00c3d2e405f121ec97650 /RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java
parent5bf10e476366e9aff291d55c050a324734bae911 (diff)
downloadRoughlyEnoughItems-ff9c8e83f0eaf3791e4939b491979d23bdca5577.tar.gz
RoughlyEnoughItems-ff9c8e83f0eaf3791e4939b491979d23bdca5577.tar.bz2
RoughlyEnoughItems-ff9c8e83f0eaf3791e4939b491979d23bdca5577.zip
Put the search bar to the side automatically if there is no space.
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java')
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java34
1 files changed, 27 insertions, 7 deletions
diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java
index 154d5b191..60914d080 100644
--- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java
+++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java
@@ -33,10 +33,7 @@ import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.math.api.Executor;
import me.shedaniel.rei.RoughlyEnoughItemsState;
-import me.shedaniel.rei.api.ConfigManager;
-import me.shedaniel.rei.api.ConfigObject;
-import me.shedaniel.rei.api.REIHelper;
-import me.shedaniel.rei.api.REIOverlay;
+import me.shedaniel.rei.api.*;
import me.shedaniel.rei.api.widgets.Tooltip;
import me.shedaniel.rei.gui.ContainerScreenOverlay;
import me.shedaniel.rei.gui.OverlaySearchField;
@@ -48,6 +45,7 @@ import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.event.client.ClientTickCallback;
+import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
@@ -227,13 +225,35 @@ public class ScreenHelper implements ClientModInitializer, REIHelper {
attachInstance(instance, REIHelper.class);
}
+ public static SearchFieldLocation getContextualSearchFieldLocation() {
+ Window window = Minecraft.getInstance().getWindow();
+ for (OverlayDecider decider : DisplayHelper.getInstance().getSortedOverlayDeciders(Minecraft.getInstance().screen.getClass())) {
+ if (decider instanceof DisplayHelper.DisplayBoundsProvider) {
+ Rectangle containerBounds = ((DisplayHelper.DisplayBoundsProvider<Screen>) decider).getScreenBounds(Minecraft.getInstance().screen);
+ if (window.getGuiScaledHeight() - 20 <= containerBounds.getMaxY())
+ return SearchFieldLocation.BOTTOM_SIDE;
+ else break;
+ }
+ }
+ return ConfigObject.getInstance().getSearchFieldLocation();
+ }
+
public static Rectangle getItemListArea(Rectangle bounds) {
- return new Rectangle(bounds.x, bounds.y + 2 + (ConfigObject.getInstance().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + (ConfigObject.getInstance().isEntryListWidgetScrolled() ? 0 : 22), bounds.width, bounds.height - (ConfigObject.getInstance().getSearchFieldLocation() != SearchFieldLocation.CENTER ? 27 + 22 : 27) + (!ConfigObject.getInstance().isEntryListWidgetScrolled() ? 0 : 22));
+ SearchFieldLocation searchFieldLocation = ScreenHelper.getContextualSearchFieldLocation();
+
+ int yOffset = 2;
+ if (searchFieldLocation == SearchFieldLocation.TOP_SIDE) yOffset += 24;
+ if (!ConfigObject.getInstance().isEntryListWidgetScrolled()) yOffset += 22;
+ int heightOffset = 0;
+ if (searchFieldLocation == SearchFieldLocation.BOTTOM_SIDE) heightOffset += 24;
+ return new Rectangle(bounds.x, bounds.y + yOffset, bounds.width, bounds.height - 1 - yOffset - heightOffset);
}
public static Rectangle getFavoritesListArea(Rectangle bounds) {
- int offset = 6 + (!ConfigObject.getInstance().isLowerConfigButton() ? 25 : 0) + (ConfigObject.getInstance().doesShowUtilsButtons() ? 25 : 0);
- return new Rectangle(bounds.x, bounds.y + 2 + offset, bounds.width, bounds.height - 5 - offset);
+ int yOffset = 8;
+ if (ConfigObject.getInstance().doesShowUtilsButtons()) yOffset += 50;
+ else if (!ConfigObject.getInstance().isLowerConfigButton()) yOffset += 25;
+ return new Rectangle(bounds.x, bounds.y + yOffset, bounds.width, bounds.height - 3 - yOffset);
}
@Override