diff options
| author | shedaniel <daniel@shedaniel.me> | 2020-08-27 20:11:03 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2020-08-27 20:11:03 +0800 |
| commit | ff9c8e83f0eaf3791e4939b491979d23bdca5577 (patch) | |
| tree | ef323a6dc477a03f05b00c3d2e405f121ec97650 /RoughlyEnoughItems-runtime/src/main/java/me | |
| parent | 5bf10e476366e9aff291d55c050a324734bae911 (diff) | |
| download | RoughlyEnoughItems-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')
| -rw-r--r-- | RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java | 41 | ||||
| -rw-r--r-- | RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java | 34 |
2 files changed, 57 insertions, 18 deletions
diff --git a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java index 5e0af4f96..d97953d72 100644 --- a/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java +++ b/RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java @@ -435,19 +435,38 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl } private Rectangle getSearchFieldArea() { - int widthRemoved = 1 + (ConfigObject.getInstance().isCraftableFilterEnabled() ? 22 : 0) + (ConfigObject.getInstance().isLowerConfigButton() ? 22 : 0); - SearchFieldLocation searchFieldLocation = ConfigObject.getInstance().getSearchFieldLocation(); - if (searchFieldLocation == SearchFieldLocation.BOTTOM_SIDE) - return new Rectangle(bounds.x + 2, window.getGuiScaledHeight() - 22, bounds.width - 6 - widthRemoved, 18); - if (searchFieldLocation == SearchFieldLocation.TOP_SIDE) - return new Rectangle(bounds.x + 2, 4, bounds.width - 6 - widthRemoved, 18); - 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); - return new Rectangle(containerBounds.x, window.getGuiScaledHeight() - 22, containerBounds.width - widthRemoved, 18); + int widthRemoved = 1; + if (ConfigObject.getInstance().isCraftableFilterEnabled()) widthRemoved += 22; + if (ConfigObject.getInstance().isLowerConfigButton()) widthRemoved += 22; + SearchFieldLocation searchFieldLocation = ScreenHelper.getContextualSearchFieldLocation(); + switch (searchFieldLocation) { + case TOP_SIDE: + return getTopSideSearchFieldArea(widthRemoved); + case BOTTOM_SIDE: + return getBottomSideSearchFieldArea(widthRemoved); + default: + case CENTER: { + 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); + return getBottomCenterSearchFieldArea(containerBounds, widthRemoved); + } + } + return new Rectangle(); } } - return new Rectangle(); + } + + private Rectangle getTopSideSearchFieldArea(int widthRemoved) { + return new Rectangle(bounds.x + 2, 4, bounds.width - 6 - widthRemoved, 18); + } + + private Rectangle getBottomSideSearchFieldArea(int widthRemoved) { + return new Rectangle(bounds.x + 2, window.getGuiScaledHeight() - 22, bounds.width - 6 - widthRemoved, 18); + } + + private Rectangle getBottomCenterSearchFieldArea(Rectangle containerBounds, int widthRemoved) { + return new Rectangle(containerBounds.x, window.getGuiScaledHeight() - 22, containerBounds.width - widthRemoved, 18); } private Rectangle getCraftableToggleArea() { 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 |
