diff options
| author | shedaniel <daniel@shedaniel.me> | 2022-08-28 20:48:46 +0900 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2022-08-28 21:14:21 +0900 |
| commit | fb91ed996b01f986492de4007cb86be5e68ad192 (patch) | |
| tree | b1176be6374ac6d56094c9bcf2b48226b31e68ec /runtime-frontend/overlay/src/main/java | |
| parent | 94e323f75c17e297c33fba1d3afb5c47ae66a8ad (diff) | |
| download | RoughlyEnoughItems-fb91ed996b01f986492de4007cb86be5e68ad192.tar.gz RoughlyEnoughItems-fb91ed996b01f986492de4007cb86be5e68ad192.tar.bz2 RoughlyEnoughItems-fb91ed996b01f986492de4007cb86be5e68ad192.zip | |
More internal changes
Diffstat (limited to 'runtime-frontend/overlay/src/main/java')
16 files changed, 116 insertions, 172 deletions
diff --git a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuAccess.java b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuAccess.java deleted file mode 100644 index b890ccd94..000000000 --- a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuAccess.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.shedaniel.rei.impl.client.gui.menu; - -import me.shedaniel.math.Point; -import me.shedaniel.math.Rectangle; -import me.shedaniel.math.impl.PointHelper; - -import java.util.Collection; -import java.util.UUID; -import java.util.function.Predicate; -import java.util.function.Supplier; - -public interface MenuAccess { - boolean isOpened(UUID uuid); - - boolean isAnyOpened(); - - boolean isInBounds(UUID uuid); - - void open(UUID uuid, Menu menu); - - void open(UUID uuid, Menu menu, Predicate<Point> or, Predicate<Point> and); - - default void openOrClose(UUID uuid, Rectangle selfBounds, Supplier<Collection<MenuEntry>> menuSupplier) { - boolean isOpened = isOpened(uuid); - if (isOpened || !isAnyOpened()) { - boolean inBounds = (isValidPoint(PointHelper.ofMouse()) && selfBounds.contains(PointHelper.ofMouse())) || isInBounds(uuid); - if (isOpened != inBounds) { - if (inBounds) { - Menu menu = new Menu(selfBounds.clone(), menuSupplier.get(), false); - open(uuid, menu, selfBounds::contains, point -> true); - } else { - close(); - } - } - } - } - - boolean isValidPoint(Point point); - - void close(); -} diff --git a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuEntry.java b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuEntry.java deleted file mode 100644 index e5c7109d8..000000000 --- a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuEntry.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.shedaniel.rei.impl.client.gui.menu; - -import me.shedaniel.rei.api.client.gui.widgets.Widget; -import org.jetbrains.annotations.ApiStatus; - -@ApiStatus.Internal -public abstract class MenuEntry extends Widget { - @ApiStatus.Internal - @Deprecated - Menu parent = null; - - public final Menu getParent() { - return parent; - } - - public abstract int getEntryWidth(); - - public abstract int getEntryHeight(); - - public abstract void updateInformation(int xPos, int yPos, boolean selected, boolean containsMouse, boolean rendering, int width); -} diff --git a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/AbstractScreenOverlay.java b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/AbstractScreenOverlay.java index 611a55748..d1c3a5f22 100644 --- a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/AbstractScreenOverlay.java +++ b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/AbstractScreenOverlay.java @@ -44,9 +44,9 @@ import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry; import me.shedaniel.rei.api.client.view.ViewSearchBuilder; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.impl.client.ClientInternals; -import me.shedaniel.rei.impl.client.gui.dragging.DraggingContextImpl; +import me.shedaniel.rei.impl.client.gui.overlay.dragging.DraggingContextImpl; import me.shedaniel.rei.impl.client.gui.menu.MenuAccess; -import me.shedaniel.rei.impl.client.gui.menu.MenuAccessImpl; +import me.shedaniel.rei.impl.client.gui.overlay.menu.MenuAccessImpl; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.Screen; diff --git a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/InternalOverlayBounds.java b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/InternalOverlayBounds.java index 29160b394..bf98c858f 100644 --- a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/InternalOverlayBounds.java +++ b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/InternalOverlayBounds.java @@ -27,16 +27,10 @@ import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.config.ConfigObject; import me.shedaniel.rei.api.client.gui.config.DisplayPanelLocation; import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry; +import me.shedaniel.rei.impl.client.util.InternalEntryBounds; import net.minecraft.client.Minecraft; -import net.minecraft.util.Mth; public class InternalOverlayBounds { - private static final int SIZE = 18; - - public static int entrySize() { - return Mth.ceil(SIZE * ConfigObject.getInstance().getEntrySize()); - } - static Rectangle calculateOverlayBounds() { Rectangle bounds = ScreenRegistry.getInstance().getOverlayBounds(ConfigObject.getInstance().getDisplayPanelLocation(), Minecraft.getInstance().screen); @@ -44,7 +38,7 @@ public class InternalOverlayBounds { if (ConfigObject.getInstance().getDisplayPanelLocation() == DisplayPanelLocation.RIGHT) bounds.x += widthReduction; bounds.width -= widthReduction; - int maxWidth = (int) Math.ceil(entrySize() * ConfigObject.getInstance().getHorizontalEntriesBoundariesColumns() + entrySize() * 0.75); + int maxWidth = (int) Math.ceil(InternalEntryBounds.entrySize() * ConfigObject.getInstance().getHorizontalEntriesBoundariesColumns() + InternalEntryBounds.entrySize() * 0.75); if (bounds.width > maxWidth) { if (ConfigObject.getInstance().getDisplayPanelLocation() == DisplayPanelLocation.RIGHT) bounds.x += bounds.width - maxWidth; diff --git a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/ScreenOverlayImpl.java b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/ScreenOverlayImpl.java index 1dc6d2326..ba55096b4 100644 --- a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/ScreenOverlayImpl.java +++ b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/ScreenOverlayImpl.java @@ -23,6 +23,7 @@ package me.shedaniel.rei.impl.client.gui.overlay; +import com.mojang.blaze3d.platform.InputConstants; import com.mojang.blaze3d.platform.Window; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.REIRuntime; @@ -33,6 +34,7 @@ import me.shedaniel.rei.api.client.gui.widgets.TextField; import me.shedaniel.rei.api.client.gui.widgets.Widget; import me.shedaniel.rei.api.client.gui.widgets.Widgets; import me.shedaniel.rei.api.client.overlay.OverlayListWidget; +import me.shedaniel.rei.api.client.overlay.ScreenOverlay; import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry; import me.shedaniel.rei.api.client.search.SearchFilter; import me.shedaniel.rei.impl.client.ClientInternals; @@ -61,16 +63,20 @@ public final class ScreenOverlayImpl extends AbstractScreenOverlay { private TextField searchField = null; public static EntryListWidget getEntryListWidget() { - return getInstance().getEntryList(); + return getInstanceInternal().getEntryList(); } @Nullable public static FavoritesListWidget getFavoritesListWidget() { - return getInstance().getFavoritesListNullable(); + return getInstanceInternal().getFavoritesListNullable(); } - public static ScreenOverlayImpl getInstance() { - return (ScreenOverlayImpl) REIRuntime.getInstance().getOverlay().get(); + private static ScreenOverlayImpl getInstanceInternal() { + return (ScreenOverlayImpl) ScreenOverlay.getInstance().orElseThrow(); + } + + public ScreenOverlayImpl() { + this.init(); } @Override @@ -149,10 +155,8 @@ public final class ScreenOverlayImpl extends AbstractScreenOverlay { if (!hasSpace()) return false; if (!REIRuntime.getInstance().isOverlayVisible()) return false; if (ConfigObject.getInstance().getFocusSearchFieldKeybind().matchesKey(keyCode, scanCode)) { - getSearchField().setFocused(true); + getSearchField().setFocusedFromKey(true, InputConstants.getKey(keyCode, scanCode)); setFocused(getSearchField().asWidget()); - getSearchField().keybindFocusTime = System.currentTimeMillis(); - getSearchField().keybindFocusKey = keyCode; return true; } return false; @@ -164,10 +168,8 @@ public final class ScreenOverlayImpl extends AbstractScreenOverlay { boolean visible = REIRuntime.getInstance().isOverlayVisible(); if (!hasSpace() || !visible) return false; if (ConfigObject.getInstance().getFocusSearchFieldKeybind().matchesMouse(button)) { - getSearchField().setFocused(true); + getSearchField().setFocusedFromKey(true, InputConstants.Type.MOUSE.getOrCreate(button)); setFocused(getSearchField().asWidget()); - getSearchField().keybindFocusTime = -1; - getSearchField().keybindFocusKey = -1; return true; } return false; diff --git a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/ScreenOverlayProviderImpl.java b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/ScreenOverlayProviderImpl.java new file mode 100644 index 000000000..0f7adad5e --- /dev/null +++ b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/ScreenOverlayProviderImpl.java @@ -0,0 +1,11 @@ +package me.shedaniel.rei.impl.client.gui.overlay; + +import me.shedaniel.rei.api.client.overlay.ScreenOverlay; +import me.shedaniel.rei.impl.client.provider.OverlayProvider; + +public class ScreenOverlayProviderImpl implements OverlayProvider { + @Override + public ScreenOverlay provide() { + return new ScreenOverlayImpl(); + } +} diff --git a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/dragging/DraggingContextImpl.java b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/dragging/DraggingContextImpl.java index ea78fa47a..383f13e13 100644 --- a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/dragging/DraggingContextImpl.java +++ b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/dragging/DraggingContextImpl.java @@ -21,7 +21,7 @@ * SOFTWARE. */ -package me.shedaniel.rei.impl.client.gui.dragging; +package me.shedaniel.rei.impl.client.gui.overlay.dragging; import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.clothconfig2.api.animator.NumberAnimator; diff --git a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/menu/AbstractMenuEntry.java b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/menu/AbstractMenuEntry.java index 0debff33b..6cd269c3c 100644 --- a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/menu/AbstractMenuEntry.java +++ b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/menu/AbstractMenuEntry.java @@ -21,9 +21,11 @@ * SOFTWARE. */ -package me.shedaniel.rei.impl.client.gui.menu; +package me.shedaniel.rei.impl.client.gui.overlay.menu; -public abstract class AbstractMenuEntry extends MenuEntry { +import me.shedaniel.rei.api.client.favorites.FavoriteMenuEntry; + +public abstract class AbstractMenuEntry extends FavoriteMenuEntry { private int x, y, width; private boolean selected, containsMouse, rendering; diff --git a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/menu/Menu.java b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/menu/Menu.java index 4bbb47671..89675b0be 100644 --- a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/menu/Menu.java +++ b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/menu/Menu.java @@ -21,7 +21,7 @@ * SOFTWARE. */ -package me.shedaniel.rei.impl.client.gui.menu; +package me.shedaniel.rei.impl.client.gui.overlay.menu; import com.google.common.collect.Lists; import com.mojang.blaze3d.vertex.PoseStack; @@ -31,8 +31,9 @@ import me.shedaniel.clothconfig2.api.scroll.ScrollingContainer; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.config.ConfigObject; +import me.shedaniel.rei.api.client.favorites.FavoriteMenuEntry; import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds; -import me.shedaniel.rei.impl.client.gui.menu.entries.SubMenuEntry; +import me.shedaniel.rei.impl.client.gui.overlay.menu.entries.SubMenuEntry; import net.minecraft.client.Minecraft; import org.jetbrains.annotations.ApiStatus; @@ -49,12 +50,12 @@ public class Menu extends WidgetWithBounds { public final Point menuStartPoint; public final boolean facingRight; public final boolean facingDownwards; - private final List<MenuEntry> entries = Lists.newArrayList(); + private final List<FavoriteMenuEntry> entries = Lists.newArrayList(); public final ScrollingContainer scrolling = new ScrollingContainer() { @Override public int getMaxScrollHeight() { int i = 0; - for (MenuEntry entry : children()) { + for (FavoriteMenuEntry entry : children()) { i += entry.getEntryHeight(); } return i; @@ -71,7 +72,7 @@ public class Menu extends WidgetWithBounds { } }; - public Menu(Rectangle menuStart, Collection<MenuEntry> entries, boolean sort) { + public Menu(Rectangle menuStart, Collection<FavoriteMenuEntry> entries, boolean sort) { buildEntries(entries, sort); int fullWidth = Minecraft.getInstance().screen.width; int fullHeight = Minecraft.getInstance().screen.height; @@ -91,15 +92,17 @@ public class Menu extends WidgetWithBounds { } @SuppressWarnings("deprecation") - private void buildEntries(Collection<MenuEntry> entries, boolean sort) { + private void buildEntries(Collection<FavoriteMenuEntry> entries, boolean sort) { this.entries.clear(); this.entries.addAll(entries); if (sort) { this.entries.sort(Comparator.comparing(entry -> entry instanceof SubMenuEntry ? 0 : 1) .thenComparing(entry -> entry instanceof SubMenuEntry menuEntry ? menuEntry.text.getString() : "")); } - for (MenuEntry entry : this.entries) { - entry.parent = this; + for (FavoriteMenuEntry entry : this.entries) { + if (entry instanceof SubMenuEntry) { + ((SubMenuEntry) entry).parentMenu = this; + } } } @@ -122,7 +125,7 @@ public class Menu extends WidgetWithBounds { public int getMaxEntryWidth() { int i = 0; - for (MenuEntry entry : children()) { + for (FavoriteMenuEntry entry : children()) { if (entry.getEntryWidth() > i) i = entry.getEntryWidth(); } @@ -136,9 +139,9 @@ public class Menu extends WidgetWithBounds { fill(matrices, bounds.x, bounds.y, bounds.getMaxX(), bounds.getMaxY(), containsMouse(mouseX, mouseY) ? (ConfigObject.getInstance().isUsingDarkTheme() ? -17587 : -1) : -6250336); fill(matrices, innerBounds.x, innerBounds.y, innerBounds.getMaxX(), innerBounds.getMaxY(), -16777216); boolean contains = innerBounds.contains(mouseX, mouseY); - MenuEntry focused = getFocused() instanceof MenuEntry menuEntry ? menuEntry : null; + FavoriteMenuEntry focused = getFocused() instanceof FavoriteMenuEntry menuEntry ? menuEntry : null; int currentY = innerBounds.y - scrolling.scrollAmountInt(); - for (MenuEntry child : children()) { + for (FavoriteMenuEntry child : children()) { boolean containsMouse = contains && mouseY >= currentY && mouseY < currentY + child.getEntryHeight(); if (containsMouse) { focused = child; @@ -147,7 +150,7 @@ public class Menu extends WidgetWithBounds { } currentY = innerBounds.y - scrolling.scrollAmountInt(); ScissorsHandler.INSTANCE.scissor(scrolling.getScissorBounds()); - for (MenuEntry child : children()) { + for (FavoriteMenuEntry child : children()) { boolean rendering = currentY + child.getEntryHeight() >= innerBounds.y && currentY <= innerBounds.getMaxY(); boolean containsMouse = contains && mouseY >= currentY && mouseY < currentY + child.getEntryHeight(); child.updateInformation(innerBounds.x, currentY, focused == child || containsMouse, containsMouse, rendering, getMaxEntryWidth()); @@ -182,7 +185,7 @@ public class Menu extends WidgetWithBounds { scrolling.offset(ClothConfigInitializer.getScrollStep() * -amount, true); return true; } - for (MenuEntry child : children()) { + for (FavoriteMenuEntry child : children()) { if (child instanceof SubMenuEntry) { if (child.mouseScrolled(mouseX, mouseY, amount)) return true; @@ -194,7 +197,7 @@ public class Menu extends WidgetWithBounds { @Override public boolean containsMouse(double mouseX, double mouseY) { if (super.containsMouse(mouseX, mouseY)) return true; - for (MenuEntry child : children()) { + for (FavoriteMenuEntry child : children()) { if (child.containsMouse(mouseX, mouseY)) { return true; } @@ -203,7 +206,7 @@ public class Menu extends WidgetWithBounds { } @Override - public List<MenuEntry> children() { + public List<FavoriteMenuEntry> children() { return entries; } } diff --git a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuAccessImpl.java b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/menu/MenuAccessImpl.java index e7be8c3e3..2a5a40fbe 100644 --- a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuAccessImpl.java +++ b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/menu/MenuAccessImpl.java @@ -21,22 +21,27 @@ * SOFTWARE. */ -package me.shedaniel.rei.impl.client.gui.menu; +package me.shedaniel.rei.impl.client.gui.overlay.menu; import com.google.common.collect.Lists; import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.math.Point; +import me.shedaniel.math.Rectangle; import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.api.client.REIRuntime; +import me.shedaniel.rei.api.client.favorites.FavoriteMenuEntry; import me.shedaniel.rei.api.client.gui.widgets.Widget; import me.shedaniel.rei.api.client.gui.widgets.Widgets; -import me.shedaniel.rei.impl.client.gui.overlay.ScreenOverlayImpl; +import me.shedaniel.rei.api.client.overlay.ScreenOverlay; +import me.shedaniel.rei.impl.client.gui.menu.MenuAccess; import org.jetbrains.annotations.Nullable; +import java.util.Collection; import java.util.List; import java.util.UUID; import java.util.function.Consumer; import java.util.function.Predicate; +import java.util.function.Supplier; public class MenuAccessImpl implements MenuAccess { public final List<Runnable> afterRenders = Lists.newArrayList(); @@ -72,18 +77,34 @@ public class MenuAccessImpl implements MenuAccess { } @Override - public void open(UUID uuid, Menu menu) { - open(uuid, menu, point -> false, point -> true); + public void open(UUID uuid, Rectangle selfBounds, Supplier<Collection<FavoriteMenuEntry>> menuSupplier) { + open(uuid, selfBounds, menuSupplier, point -> false, point -> true); } @Override - public void open(UUID uuid, Menu menu, Predicate<Point> or, Predicate<Point> and) { + public void open(UUID uuid, Rectangle selfBounds, Supplier<Collection<FavoriteMenuEntry>> menuSupplier, Predicate<Point> or, Predicate<Point> and) { + Menu menu = new Menu(selfBounds, menuSupplier.get(), false); this.menu = new OverlayMenu(uuid, menu, Widgets.withTranslate(menu, 0, 0, 400), or, and); } @Override + public void openOrClose(UUID uuid, Rectangle selfBounds, Supplier<Collection<FavoriteMenuEntry>> menuSupplier) { + boolean isOpened = isOpened(uuid); + if (isOpened || !isAnyOpened()) { + boolean inBounds = (isValidPoint(PointHelper.ofMouse()) && selfBounds.contains(PointHelper.ofMouse())) || isInBounds(uuid); + if (isOpened != inBounds) { + if (inBounds) { + open(uuid, selfBounds.clone(), menuSupplier, selfBounds::contains, point -> true); + } else { + close(); + } + } + } + } + + @Override public boolean isValidPoint(Point point) { - return ScreenOverlayImpl.getInstance().isNotInExclusionZones(point.x, point.y); + return ScreenOverlay.getInstance().orElseThrow().isNotInExclusionZones(point.x, point.y); } @Override diff --git a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/menu/entries/EmptyMenuEntry.java b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/menu/entries/EmptyMenuEntry.java index e269a496d..092ef0e48 100644 --- a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/menu/entries/EmptyMenuEntry.java +++ b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/menu/entries/EmptyMenuEntry.java @@ -21,10 +21,10 @@ * SOFTWARE. */ -package me.shedaniel.rei.impl.client.gui.menu.entries; +package me.shedaniel.rei.impl.client.gui.overlay.menu.entries; import com.mojang.blaze3d.vertex.PoseStack; -import me.shedaniel.rei.impl.client.gui.menu.AbstractMenuEntry; +import me.shedaniel.rei.impl.client.gui.overlay.menu.AbstractMenuEntry; import net.minecraft.client.gui.components.events.GuiEventListener; import java.util.Collections; diff --git a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/menu/entries/SeparatorMenuEntry.java b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/menu/entries/SeparatorMenuEntry.java index bd0425e74..792039877 100644 --- a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/menu/entries/SeparatorMenuEntry.java +++ b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/menu/entries/SeparatorMenuEntry.java @@ -21,10 +21,10 @@ * SOFTWARE. */ -package me.shedaniel.rei.impl.client.gui.menu.entries; +package me.shedaniel.rei.impl.client.gui.overlay.menu.entries; import com.mojang.blaze3d.vertex.PoseStack; -import me.shedaniel.rei.impl.client.gui.menu.AbstractMenuEntry; +import me.shedaniel.rei.impl.client.gui.overlay.menu.AbstractMenuEntry; import net.minecraft.client.gui.components.events.GuiEventListener; import java.util.Collections; diff --git a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/menu/entries/SubMenuEntry.java b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/menu/entries/SubMenuEntry.java index 24ae2249c..8de4d621d 100644 --- a/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/menu/entries/SubMenuEntry.java +++ b/runtime-frontend/overlay/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/menu/entries/SubMenuEntry.java @@ -21,7 +21,7 @@ * SOFTWARE. */ -package me.shedaniel.rei.impl.client.gui.menu.entries; +package me.shedaniel.rei.impl.client.gui.overlay.menu.entries; import com.google.common.base.MoreObjects; import com.google.common.collect.Lists; @@ -29,11 +29,11 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.clothconfig2.api.ScissorsHandler; import me.shedaniel.math.Rectangle; -import me.shedaniel.rei.impl.client.gui.InternalTextures; +import me.shedaniel.rei.api.client.favorites.FavoriteMenuEntry; import me.shedaniel.rei.api.common.util.ImmutableTextComponent; -import me.shedaniel.rei.impl.client.gui.menu.AbstractMenuEntry; -import me.shedaniel.rei.impl.client.gui.menu.Menu; -import me.shedaniel.rei.impl.client.gui.menu.MenuEntry; +import me.shedaniel.rei.impl.client.gui.InternalTextures; +import me.shedaniel.rei.impl.client.gui.overlay.menu.AbstractMenuEntry; +import me.shedaniel.rei.impl.client.gui.overlay.menu.Menu; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.network.chat.Component; @@ -45,18 +45,19 @@ import java.util.function.Supplier; public class SubMenuEntry extends AbstractMenuEntry { public final Component text; private int textWidth = -69; - protected List<MenuEntry> entries; + protected List<FavoriteMenuEntry> entries; + public Menu parentMenu; protected Menu childMenu; public SubMenuEntry(Component text) { this(text, Collections.emptyList()); } - public SubMenuEntry(Component text, Supplier<Li |
