From 94e323f75c17e297c33fba1d3afb5c47ae66a8ad Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sun, 28 Aug 2022 18:50:24 +0900 Subject: Separate EntryListWidget and FavoritesListWidget more --- .../rei/impl/client/ClientHelperImpl.java | 12 - .../rei/impl/client/ClientNetworkHelperImpl.java | 2 +- .../shedaniel/rei/impl/client/REIRuntimeImpl.java | 11 +- .../rei/impl/client/gui/DisplayScreenStack.java | 23 + .../rei/impl/client/gui/ScreenOverlayImpl.java | 208 --------- .../client/gui/dragging/CurrentDraggingStack.java | 312 ------------- .../rei/impl/client/gui/error/ErrorsScreen.java | 12 +- .../impl/client/gui/menu/AbstractMenuEntry.java | 77 ---- .../shedaniel/rei/impl/client/gui/menu/Menu.java | 210 --------- .../rei/impl/client/gui/menu/MenuAccess.java | 64 --- .../rei/impl/client/gui/menu/MenuAccessImpl.java | 136 ------ .../rei/impl/client/gui/menu/MenuEntry.java | 44 -- .../client/gui/menu/entries/EmptyMenuEntry.java | 58 --- .../gui/menu/entries/SeparatorMenuEntry.java | 53 --- .../impl/client/gui/menu/entries/SubMenuEntry.java | 153 ------- .../client/gui/menu/entries/TextMenuEntry.java | 70 --- .../client/gui/menu/entries/ToggleMenuEntry.java | 144 ------ .../client/gui/overlay/AbstractScreenOverlay.java | 351 -------------- .../client/gui/overlay/InternalOverlayBounds.java | 51 --- .../client/gui/widget/CachedEntryListRender.java | 190 -------- .../impl/client/gui/widget/ConfigButtonWidget.java | 185 -------- .../gui/widget/CraftableFilterButtonWidget.java | 165 ------- .../client/gui/widget/DisplayTooltipComponent.java | 82 ---- .../client/gui/widget/DisplayedEntryWidget.java | 236 ---------- .../impl/client/gui/widget/EntryHighlighter.java | 64 --- .../impl/client/gui/widget/InternalWidgets.java | 47 -- .../rei/impl/client/gui/widget/LateRenderable.java | 30 -- .../gui/widget/entrylist/CachingEntryRenderer.java | 102 ----- .../widget/entrylist/CollapsedEntriesTooltip.java | 87 ---- .../gui/widget/entrylist/CollapsedStack.java | 60 --- .../entrylist/CollapsingEntryListWidget.java | 101 ----- .../gui/widget/entrylist/EntryListEntries.java | 48 -- .../widget/entrylist/EntryListSearchManager.java | 151 ------ .../gui/widget/entrylist/EntryListStackEntry.java | 218 --------- .../gui/widget/entrylist/EntryListWidget.java | 367 --------------- .../widget/entrylist/PaginatedEntryListWidget.java | 294 ------------ .../widget/entrylist/ScrolledEntryListWidget.java | 208 --------- .../gui/widget/favorites/FavoritesListWidget.java | 237 ---------- .../gui/widget/favorites/history/DisplayEntry.java | 325 ------------- .../favorites/history/DisplayHistoryManager.java | 147 ------ .../favorites/history/DisplayHistoryWidget.java | 407 ----------------- .../listeners/FavoritesRegionListener.java | 74 --- .../panel/FadingFavoritesPanelButton.java | 126 ----- .../gui/widget/favorites/panel/FavoritesPanel.java | 179 -------- .../panel/FavoritesTogglePanelButton.java | 75 --- .../panel/rows/FavoritesPanelEmptyRow.java | 53 --- .../panel/rows/FavoritesPanelEntriesRow.java | 222 --------- .../favorites/panel/rows/FavoritesPanelRow.java | 34 -- .../panel/rows/FavoritesPanelSectionRow.java | 62 --- .../panel/rows/FavoritesPanelSeparatorRow.java | 48 -- .../gui/widget/favorites/trash/TrashWidget.java | 110 ----- .../gui/widget/region/EntryStacksRegionWidget.java | 505 --------------------- .../client/gui/widget/region/RealRegionEntry.java | 89 ---- .../gui/widget/region/RegionDraggableStack.java | 88 ---- .../gui/widget/region/RegionEntryWidget.java | 131 ------ .../client/gui/widget/region/RegionListener.java | 75 --- .../gui/widget/region/RegionRenderingDebugger.java | 80 ---- .../gui/widget/search/OverlaySearchField.java | 46 +- .../rei/impl/common/util/RectangleUtils.java | 52 --- .../client/runtime/DefaultClientRuntimePlugin.java | 4 +- 60 files changed, 73 insertions(+), 7722 deletions(-) delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/dragging/CurrentDraggingStack.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/AbstractMenuEntry.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/Menu.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuAccess.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuAccessImpl.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuEntry.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/entries/EmptyMenuEntry.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/entries/SeparatorMenuEntry.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/entries/SubMenuEntry.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/entries/TextMenuEntry.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/entries/ToggleMenuEntry.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/AbstractScreenOverlay.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/overlay/InternalOverlayBounds.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/CachedEntryListRender.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/ConfigButtonWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/CraftableFilterButtonWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DisplayTooltipComponent.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DisplayedEntryWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryHighlighter.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/InternalWidgets.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/LateRenderable.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/CachingEntryRenderer.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/CollapsedEntriesTooltip.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/CollapsedStack.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/CollapsingEntryListWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListEntries.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListSearchManager.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListStackEntry.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/PaginatedEntryListWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/ScrolledEntryListWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/FavoritesListWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/history/DisplayEntry.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/history/DisplayHistoryManager.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/history/DisplayHistoryWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/listeners/FavoritesRegionListener.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/panel/FadingFavoritesPanelButton.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/panel/FavoritesPanel.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/panel/FavoritesTogglePanelButton.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/panel/rows/FavoritesPanelEmptyRow.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/panel/rows/FavoritesPanelEntriesRow.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/panel/rows/FavoritesPanelRow.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/panel/rows/FavoritesPanelSectionRow.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/panel/rows/FavoritesPanelSeparatorRow.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/trash/TrashWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/region/EntryStacksRegionWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/region/RealRegionEntry.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/region/RegionDraggableStack.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/region/RegionEntryWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/region/RegionListener.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/region/RegionRenderingDebugger.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/common/util/RectangleUtils.java (limited to 'runtime/src/main/java/me') diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java index 3c1cbcb01..c132fa569 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java @@ -23,7 +23,6 @@ package me.shedaniel.rei.impl.client; -import com.google.common.base.Suppliers; import me.shedaniel.rei.api.client.ClientHelper; import me.shedaniel.rei.api.client.config.ConfigManager; import me.shedaniel.rei.api.client.config.ConfigObject; @@ -44,23 +43,12 @@ import net.minecraft.client.gui.screens.Screen; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import java.time.LocalDateTime; import java.util.List; import java.util.Map; -import java.util.function.Supplier; @ApiStatus.Internal @Environment(EnvType.CLIENT) public class ClientHelperImpl extends ClientNetworkHelperImpl implements ClientModNameHelperImpl { - public final Supplier isAprilFools = Suppliers.memoize(() -> { - try { - LocalDateTime now = LocalDateTime.now(); - return now.getMonthValue() == 4 && now.getDayOfMonth() == 1; - } catch (Throwable ignored) { - } - return false; - }); - /** * @return the instance of {@link ClientHelperImpl} * @see ClientHelper#getInstance() diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientNetworkHelperImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientNetworkHelperImpl.java index 18efbbf22..746c29a06 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientNetworkHelperImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientNetworkHelperImpl.java @@ -68,7 +68,7 @@ public abstract class ClientNetworkHelperImpl implements ClientHelper { return NetworkManager.canServerReceive(RoughlyEnoughItemsNetwork.CREATE_ITEMS_HOTBAR_PACKET); } - public boolean canDeleteItems() { + public boolean canUseDeletePackets() { return hasPermissionToUsePackets() || Minecraft.getInstance().gameMode.hasInfiniteItems(); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java index 0c4007509..a38354ff6 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java @@ -28,7 +28,6 @@ import com.mojang.blaze3d.systems.RenderSystem; import dev.architectury.event.EventResult; import dev.architectury.event.events.client.ClientGuiEvent; import dev.architectury.event.events.client.ClientTickEvent; -import dev.architectury.platform.Platform; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.REIRuntime; import me.shedaniel.rei.api.client.config.ConfigObject; @@ -52,7 +51,6 @@ import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import java.lang.reflect.InvocationTargetException; import java.util.Optional; import static me.shedaniel.rei.impl.client.gui.widget.entrylist.EntryListWidget.entrySize; @@ -76,14 +74,7 @@ public class REIRuntimeImpl implements REIRuntime { @Override public Optional getOverlay(boolean reset, boolean init) { if ((overlay == null && init) || reset) { - try { - overlay = (ScreenOverlayImpl) Class.forName(Platform.isForge() ? "me.shedaniel.rei.impl.client.gui.forge.ScreenOverlayImplForge" - : "me.shedaniel.rei.impl.client.gui.fabric.ScreenOverlayImplFabric") - .getDeclaredConstructor() - .newInstance(); - } catch (InstantiationException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { - throw new RuntimeException(e); - } + overlay = new ScreenOverlayImpl(); overlay.init(); overlay.getSearchField().setFocused(false); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/DisplayScreenStack.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/DisplayScreenStack.java index 4b12aa5d6..9b590da56 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/DisplayScreenStack.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/DisplayScreenStack.java @@ -1,3 +1,26 @@ +/* + * 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; import com.google.common.collect.Iterables; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java deleted file mode 100644 index 1943ad379..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java +++ /dev/null @@ -1,208 +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; - -import com.mojang.blaze3d.platform.Window; -import me.shedaniel.math.Rectangle; -import me.shedaniel.rei.api.client.REIRuntime; -import me.shedaniel.rei.api.client.config.ConfigObject; -import me.shedaniel.rei.api.client.gui.config.SearchFieldLocation; -import me.shedaniel.rei.api.client.gui.widgets.TextField; -import me.shedaniel.rei.api.client.overlay.OverlayListWidget; -import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry; -import me.shedaniel.rei.impl.client.gui.overlay.AbstractScreenOverlay; -import me.shedaniel.rei.impl.client.gui.widget.ConfigButtonWidget; -import me.shedaniel.rei.impl.client.gui.widget.CraftableFilterButtonWidget; -import me.shedaniel.rei.impl.client.gui.widget.entrylist.EntryListWidget; -import me.shedaniel.rei.impl.client.gui.widget.entrylist.PaginatedEntryListWidget; -import me.shedaniel.rei.impl.client.gui.widget.entrylist.ScrolledEntryListWidget; -import me.shedaniel.rei.impl.client.gui.widget.favorites.FavoritesListWidget; -import me.shedaniel.rei.impl.client.gui.widget.search.OverlaySearchField; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.components.events.GuiEventListener; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.Nullable; - -import java.util.Objects; -import java.util.Optional; - -@ApiStatus.Internal -public abstract class ScreenOverlayImpl extends AbstractScreenOverlay { - private EntryListWidget entryListWidget = null; - private FavoritesListWidget favoritesListWidget = null; - private OverlaySearchField searchField = null; - - public static EntryListWidget getEntryListWidget() { - return getInstance().getEntryList(); - } - - @Nullable - public static FavoritesListWidget getFavoritesListWidget() { - return getInstance().getFavoritesListNullable(); - } - - public static ScreenOverlayImpl getInstance() { - return (ScreenOverlayImpl) REIRuntime.getInstance().getOverlay().get(); - } - - @Override - public void init() { - super.init(); - - TextField searchField = getSearchField(); - searchField.asWidget().getBounds().setBounds(getSearchFieldArea()); - this.children().add(searchField.asWidget()); - - if (ConfigObject.getInstance().isFavoritesEnabled()) { - getFavoritesListWidget().favoritePanel.resetRows(); - this.children().add(getFavoritesListWidget()); - } - - EntryListWidget entryListWidget = getEntryListWidget(); - entryListWidget.updateArea(this.getBounds(), searchField.getText()); - this.children().add(entryListWidget); - searchField.setResponder(s -> entryListWidget.updateSearch(s, false)); - entryListWidget.init(this); - - this.children().add(ConfigButtonWidget.create(this)); - if (ConfigObject.getInstance().isCraftableFilterEnabled()) { - this.children().add(CraftableFilterButtonWidget.create(this)); - } - } - - private Rectangle getSearchFieldArea() { - int widthRemoved = 1; - if (ConfigObject.getInstance().isCraftableFilterEnabled()) widthRemoved += 22; - if (ConfigObject.getInstance().isLowerConfigButton()) widthRemoved += 22; - SearchFieldLocation searchFieldLocation = REIRuntime.getInstance().getContextualSearchFieldLocation(); - return switch (searchFieldLocation) { - case TOP_SIDE -> getTopSideSearchFieldArea(widthRemoved); - case BOTTOM_SIDE -> getBottomSideSearchFieldArea(widthRemoved); - case CENTER -> getCenterSearchFieldArea(widthRemoved); - }; - } - - private Rectangle getTopSideSearchFieldArea(int widthRemoved) { - return new Rectangle(getBounds().x + 2, 4, getBounds().width - 6 - widthRemoved, 18); - } - - private Rectangle getBottomSideSearchFieldArea(int widthRemoved) { - Window window = Minecraft.getInstance().getWindow(); - return new Rectangle(getBounds().x + 2, window.getGuiScaledHeight() - 22, getBounds().width - 6 - widthRemoved, 18); - } - - private Rectangle getCenterSearchFieldArea(int widthRemoved) { - Window window = Minecraft.getInstance().getWindow(); - Rectangle screenBounds = ScreenRegistry.getInstance().getScreenBounds(minecraft.screen); - return new Rectangle(screenBounds.x, window.getGuiScaledHeight() - 22, screenBounds.width - widthRemoved, 18); - } - - @Override - protected void updateSearch() { - getEntryListWidget().updateSearch(getSearchField().getText(), true); - } - - @Override - public boolean keyPressed(int keyCode, int scanCode, int modifiers) { - if (super.keyPressed(keyCode, scanCode, modifiers)) return true; - if (!hasSpace()) return false; - if (!REIRuntime.getInstance().isOverlayVisible()) return false; - if (ConfigObject.getInstance().getFocusSearchFieldKeybind().matchesKey(keyCode, scanCode)) { - getSearchField().setFocused(true); - setFocused(getSearchField()); - getSearchField().keybindFocusTime = System.currentTimeMillis(); - getSearchField().keybindFocusKey = keyCode; - return true; - } - return false; - } - - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (super.mouseClicked(mouseX, mouseY, button)) return true; - boolean visible = REIRuntime.getInstance().isOverlayVisible(); - if (!hasSpace() || !visible) return false; - if (ConfigObject.getInstance().getFocusSearchFieldKeybind().matchesMouse(button)) { - getSearchField().setFocused(true); - setFocused(getSearchField().asWidget()); - getSearchField().keybindFocusTime = -1; - getSearchField().keybindFocusKey = -1; - return true; - } - return false; - } - - @Override - public void setFocused(@Nullable GuiEventListener focused) { - super.setFocused(focused); - getSearchField().setFocused(focused == getSearchField().asWidget()); - } - - @Override - public EntryListWidget getEntryList() { - boolean widgetScrolled = ConfigObject.getInstance().isEntryListWidgetScrolled(); - - if (entryListWidget != null) { - if (widgetScrolled && entryListWidget instanceof ScrolledEntryListWidget) { - return entryListWidget; - } else if (!widgetScrolled && entryListWidget instanceof PaginatedEntryListWidget) { - return entryListWidget; - } - } - - entryListWidget = widgetScrolled ? new ScrolledEntryListWidget() : new PaginatedEntryListWidget(); - - Rectangle overlayBounds = getBounds(); - entryListWidget.updateArea(Objects.requireNonNullElse(overlayBounds, new Rectangle()), getSearchField().getText()); - entryListWidget.updateEntriesPosition(); - - return entryListWidget; - } - - @Override - public Optional getFavoritesList() { - return Optional.ofNullable(getFavoritesListNullable()); - } - - private FavoritesListWidget getFavoritesListNullable() { - if (ConfigObject.getInstance().isFavoritesEnabled()) { - if (favoritesListWidget == null) { - favoritesListWidget = new FavoritesListWidget(); - } - - return favoritesListWidget; - } else { - return favoritesListWidget = null; - } - } - - @Override - public OverlaySearchField getSearchField() { - if (searchField == null) { - searchField = new OverlaySearchField(0, 0, 0, 0); - } - - return searchField; - } -} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/dragging/CurrentDraggingStack.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/dragging/CurrentDraggingStack.java deleted file mode 100644 index 50d6ab020..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/dragging/CurrentDraggingStack.java +++ /dev/null @@ -1,312 +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.dragging; - -import com.mojang.blaze3d.vertex.PoseStack; -import me.shedaniel.clothconfig2.api.animator.NumberAnimator; -import me.shedaniel.clothconfig2.api.animator.ValueAnimator; -import me.shedaniel.math.FloatingRectangle; -import me.shedaniel.math.Point; -import me.shedaniel.math.Rectangle; -import me.shedaniel.rei.api.client.gui.drag.DraggableBoundsProvider; -import me.shedaniel.rei.api.client.gui.drag.DraggableStack; -import me.shedaniel.rei.api.client.gui.drag.DraggedAcceptorResult; -import me.shedaniel.rei.api.client.gui.drag.DraggingContext; -import me.shedaniel.rei.api.client.gui.drag.component.DraggableComponent; -import me.shedaniel.rei.api.client.gui.drag.component.DraggableComponentProvider; -import me.shedaniel.rei.api.client.gui.drag.component.DraggableComponentVisitor; -import me.shedaniel.rei.api.client.gui.widgets.Widget; -import me.shedaniel.rei.impl.client.gui.InternalCursorState; -import me.shedaniel.rei.impl.client.gui.widget.LateRenderable; -import net.minecraft.Util; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.world.phys.Vec2; -import net.minecraft.world.phys.shapes.VoxelShape; -import org.jetbrains.annotations.Nullable; - -import java.util.*; -import java.util.function.Supplier; - -@SuppressWarnings("UnstableApiUsage") -public class CurrentDraggingStack extends Widget implements LateRenderable, DraggingContext { - private DraggableComponentProvider provider; - private DraggableComponentVisitor visitor; - @Nullable - private DraggableEntry entry; - private final List backToOriginals = new ArrayList<>(); - private final Set bounds = new HashSet<>(); - - public void set(DraggableComponentProvider provider, DraggableComponentVisitor visitor) { - this.provider = provider; - this.visitor = visitor; - } - - @Override - public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { - Integer hash = null; - - if (entry != null) { - if (!entry.dragging) { - Point startPoint = entry.start; - double xDistance = Math.abs(startPoint.x - mouseX); - double yDistance = Math.abs(startPoint.y - mouseY); - double requiredDistance = 8; - - if (xDistance * xDistance + yDistance * yDistance > requiredDistance * requiredDistance) { - entry.dragging = true; - entry.startDragging = Util.getMillis(); - entry.component.drag(); - } - } - - if (entry.dragging) { - matrices.pushPose(); - matrices.translate(0, 0, 600); - entry.bounds.update(delta); - int width = entry.component.getWidth(); - int height = entry.component.getHeight(); - Vec2 mouseStartOffset = entry.mouseStartOffset; - entry.bounds.setTo(new FloatingRectangle(mouseX - width / 2 - mouseStartOffset.x, mouseY - height / 2 - mouseStartOffset.y, width, height), - 30); - entry.component.render(matrices, entry.bounds.value().getBounds(), mouseX, mouseY, delta); - matrices.popPose(); - - VoxelShape shape = entry.getBoundsProvider().bounds(); - ShapeBounds shapeBounds = new ShapeBounds(shape); - shapeBounds.alpha.setTo(60, 300); - bounds.add(shapeBounds); - hash = shapeBounds.hash; - } - - if (!InternalCursorState.isLeftMousePressed) { - drop(); - } - } - - for (ShapeBounds bound : bounds) { - if ((hash == null || hash != bound.hash) && bound.alpha.target() != 0) { - bound.alpha.setTo(0, 300); - } - } - - { - Iterator iterator = bounds.iterator(); - while (iterator.hasNext()) { - ShapeBounds bounds = iterator.next(); - bounds.update(delta); - if (bounds.alpha.target() == 0 && bounds.alpha.value() <= 2) { - iterator.remove(); - } else { - bounds.shape.forAllBoxes((x1, y1, z1, x2, y2, z2) -> { - matrices.pushPose(); - matrices.translate(0, 0, 500); - fillGradient(matrices, (int) x1, (int) y1, (int) x2, (int) y2, 0xfdff6b | (bounds.alpha.intValue() << 24), 0xfdff6b | (bounds.alpha.intValue() << 24)); - matrices.popPose(); - }); - } - } - } - - Iterator iterator = backToOriginals.iterator(); - while (iterator.hasNext()) { - RenderBackEntry renderBackEntry = iterator.next(); - renderBackEntry.update(delta); - FloatingRectangle value = renderBackEntry.bounds.value(); - FloatingRectangle target = renderBackEntry.bounds.target(); - if (value.width < 2 || value.height < 2 || (Math.abs(value.x - target.x) <= 1.3 && Math.abs(value.y - target.y) <= 1.3 && Math.abs(value.width - target.width) <= 1 && Math.abs(value.height - target.height) <= 1)) { - iterator.remove(); - } else { - matrices.pushPose(); - matrices.translate(0, 0, 600); - renderBackEntry.component.render(matrices, value.getBounds(), mouseX, mouseY, delta); - matrices.popPose(); - } - } - } - - @Override - public List children() { - return Collections.emptyList(); - } - - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - drop(); - DraggableComponent hoveredStack = provider.getHovered(this, mouseX, mouseY); - if (hoveredStack != null) { - entry = new DraggableEntry(hoveredStack, new Point(mouseX, mouseY)); - } - return false; - } - - @Override - public boolean mouseReleased(double d, double e, int i) { - return false; - } - - @Override - public boolean mouseDragged(double mouseX1, double mouseY1, int button, double mouseX2, double mouseY2) { - return entry != null && entry.dragging; - } - - private boolean drop() { - if (entry != null && entry.dragging) { - DraggedAcceptorResult result = visitor.acceptDragged(this, entry.component); - entry.component.release(result); - entry = null; - return true; - } - - entry = null; - return false; - } - - @Override - public Screen getScreen() { - return Minecraft.getInstance().screen; - } - - @Override - @Nullable - public DraggableStack getCurrentStack() { - DraggableComponent dragged = getDragged(); - return dragged instanceof DraggableStack ? (DraggableStack) dragged : null; - } - - @Override - @Nullable - public DraggableComponent getDragged() { - return entry != null && entry.dragging ? entry.component : null; - } - - @Override - @Nullable - public Point getCurrentPosition() { - if (!isDraggingComponent()) return null; - Vec2 mouseStartOffset = entry.mouseStartOffset; - FloatingRectangle rectangle = entry.bounds.value(); - return new Point(rectangle.getCenterX() + mouseStartOffset.x, rectangle.getCenterY() + mouseStartOffset.y); - } - - @Override - @Nullable - public Rectangle getCurrentBounds() { - if (!isDraggingComponent()) return null; - FloatingRectangle rectangle = entry.bounds.value(); - return rectangle.getBounds(); - } - - @Override - public void renderBack(DraggableComponent component, Point initialPosition, Supplier position) { - int width = component.getWidth(); - int height = component.getHeight(); - backToOriginals.add(new RenderBackEntry(component, new Rectangle(initialPosition.x - width / 2, initialPosition.y - height / 2, width, height), () -> { - Point point = position.get(); - return new Rectangle(point.x, point.y, width, height); - })); - } - - @Override - public void renderBack(DraggableComponent component, Rectangle initialPosition, Supplier bounds) { - backToOriginals.add(new RenderBackEntry(component, initialPosition, bounds)); - } - - private class DraggableEntry { - private final DraggableComponent component; - private final Point start; - private long startDragging = -1; - private final ValueAnimator bounds; - private final Vec2 mouseStartOffset; - private boolean dragging = false; - private DraggableBoundsProvider boundsProvider; - - private DraggableEntry(DraggableComponent component, Point start) { - this.component = component; - this.start = start; - this.bounds = ValueAnimator.ofFloatingRectangle() - .setAs(component.getOriginBounds(start).getFloatingBounds()); - this.mouseStartOffset = new Vec2((float) (start.x - bounds.value().getCenterX()), (float) (start.y - bounds.value().getCenterY())); - } - - public DraggableBoundsProvider getBoundsProvider() { - if (boundsProvider == null) { - boundsProvider = DraggableBoundsProvider.concat(visitor.getDraggableAcceptingBounds(CurrentDraggingStack.this, component).toList()); - } - - return boundsProvider; - } - } - - private static class ShapeBounds { - private VoxelShape shape; - private NumberAnimator alpha; - private int hash; - - public ShapeBounds(VoxelShape shape) { - this.shape = shape; - this.alpha = ValueAnimator.ofDouble(0); - this.hash = shape.toAabbs().hashCode(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ShapeBounds shapeBounds)) return false; - return hash == shapeBounds.hash; - } - - @Override - public int hashCode() { - return hash; - } - - public void update(double delta) { - this.alpha.update(delta); - } - } - - private static class RenderBackEntry { - private final DraggableComponent component; - private final Supplier position; - private ValueAnimator bounds = ValueAnimator.ofFloatingRectangle(); - private int lastDestination = -1; - - public RenderBackEntry(DraggableComponent component, Rectangle initialPosition, Supplier position) { - this.component = component; - this.bounds.setAs(new FloatingRectangle(initialPosition)); - this.position = position; - } - - public Rectangle getPosition() { - return position.get(); - } - - public void update(double delta) { - this.bounds.update(delta); - this.bounds.setTo(new FloatingRectangle(getPosition()), 200); - } - } -} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/error/ErrorsScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/error/ErrorsScreen.java index ab0006ea0..ce6abd0eb 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/error/ErrorsScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/error/ErrorsScreen.java @@ -27,7 +27,6 @@ import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.rei.impl.client.gui.error.ErrorsEntryListWidget.TextEntry; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.chat.NarratorChatListener; -import net.minecraft.client.gui.components.AbstractButton; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.screens.GenericDirtMessageScreen; import net.minecraft.client.gui.screens.Screen; @@ -40,11 +39,10 @@ import java.util.function.Function; @ApiStatus.Internal public class ErrorsScreen extends Screen { - private List components; - private AbstractButton doneButton; + private final List components; + private final Screen parent; + private final boolean quitable; private ErrorsEntryListWidget listWidget; - private Screen parent; - private boolean quitable; public ErrorsScreen(Component title, List components, Screen parent, boolean quitable) { super(title); @@ -81,9 +79,9 @@ public class ErrorsScreen extends Screen { } listWidget._addEntry(new TextEntry(NarratorChatListener.NO_TITLE, listWidget.getItemWidth())); if (quitable) { - addRenderableWidget(doneButton = new Button(width / 2 - 100, height - 26, 200, 20, new TranslatableComponent("gui.done"), button -> Minecraft.getInstance().setScreen(parent))); + addRenderableWidget(new Button(width / 2 - 100, height - 26, 200, 20, new TranslatableComponent("gui.done"), button -> Minecraft.getInstance().setScreen(parent))); } else { - addRenderableWidget(doneButton = new Button(width / 2 - 100, height - 26, 200, 20, new TranslatableComponent("menu.quit"), button -> exit())); + addRenderableWidget(new Button(width / 2 - 100, height - 26, 200, 20, new TranslatableComponent("menu.quit"), button -> exit())); } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/AbstractMenuEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/AbstractMenuEntry.java deleted file mode 100644 index 0debff33b..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/AbstractMenuEntry.java +++ /dev/null @@ -1,77 +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; - -public abstract class AbstractMenuEntry extends MenuEntry { - private int x, y, width; - private boolean selected, containsMouse, rendering; - - @Override - public void updateInformation(int xPos, int yPos, boolean selected, boolean containsMouse, boolean rendering, int width) { - this.x = xPos; - this.y = yPos; - this.selected = selected; - this.containsMouse = containsMouse; - this.rendering = rendering; - this.width = width; - } - - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (isRendering() && mouseX >= getX() && mouseX <= getX() + getWidth() && mouseY >= getY() && mouseY < getY() + getEntryHeight()) { - if (onClick(mouseX, mouseY, button)) { - return true; - } - } - return super.mouseClicked(mouseX, mouseY, button); - } - - protected boolean onClick(double mouseX, double mouseY, int button) { - return false; - } - - public int getX() { - return x; - } - - public int getY() { - return y; - } - - public int getWidth() { - return width; - } - - public boolean isSelected() { - return selected; - } - - public boolean containsMouse() { - return containsMouse; - } - - public boolean isRendering() { - return rendering; - } -} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/Menu.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/Menu.java deleted file mode 100644 index 010294296..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/Menu.java +++ /dev/null @@ -1,210 +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 com.google.common.collect.Lists; -import com.mojang.blaze3d.vertex.PoseStack; -import me.shedaniel.clothconfig2.ClothConfigInitializer; -import me.shedaniel.clothconfig2.api.ScissorsHandler; -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.gui.widgets.WidgetWithBounds; -import me.shedaniel.rei.impl.client.gui.menu.entries.SubMenuEntry; -import me.shedaniel.rei.impl.client.gui.widget.LateRenderable; -import net.minecraft.client.Minecraft; -import org.jetbrains.annotations.ApiStatus; - -import java.util.Collection; -import java.util.Comparator; -import java.util.List; -import java.util.UUID; - -@ApiStatus.Internal -public class Menu extends WidgetWithBounds implements LateRenderable { - public static final UUID WEATHER = UUID.randomUUID(); - public static final UUID GAME_TYPE = UUID.randomUUID(); - - public final Point menuStartPoint; - public final boolean facingRight; - public final boolean facingDownwards; - private final List entries = Lists.newArrayList(); - public final ScrollingContainer scrolling = new ScrollingContainer() { - @Override - public int getMaxScrollHeight() { - int i = 0; - for (MenuEntry entry : children()) { - i += entry.getEntryHeight(); - } - return i; - } - - @Override - public Rectangle getBounds() { - return Menu.this.getInnerBounds(); - } - - @Override - public boolean hasScrollBar() { - return Menu.this.hasScrollBar(); - } - }; - - public Menu(Rectangle menuStart, Collection entries, boolean sort) { - buildEntries(entries, sort); - int fullWidth = Minecraft.getInstance().screen.width; - int fullHeight = Minecraft.getInstance().screen.height; - boolean facingRight = true; - this.facingDownwards = fullHeight - menuStart.getMaxY() > menuStart.y; - int y = facingDownwards ? menuStart.getMaxY() : menuStart.y - (scrolling.getMaxScrollHeight() + 2); - boolean hasScrollBar = scrolling.getMaxScrollHeight() > getInnerHeight(y); - int menuWidth = getMaxEntryWidth() + 2 + (hasScrollBar ? 6 : 0); - if (facingRight && fullWidth - menuStart.getMaxX() < menuWidth + 10) { - facingRight = false; - } else if (!facingRight && menuStart.x < menuWidth + 10) { - facingRight = true; - } - this.facingRight = facingRight; - int x = facingRight ? menuStart.x : menuStart.getMaxX() - (getMaxEntryWidth() + 2 + (hasScrollBar ? 6 : 0)); - this.menuStartPoint = new Point(x, y); - } - - @SuppressWarnings("deprecation") - private void buildEntries(Collection 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; - } - } - - @Override - public Rectangle getBounds() { - return new Rectangle(menuStartPoint.x, menuStartPoint.y, getMaxEntryWidth() + 2 + (hasScrollBar() ? 6 : 0), getInnerHeight(menuStartPoint.y) + 2); - } - - public Rectangle getInnerBounds() { - return new Rectangle(menuStartPoint.x + 1, menuStartPoint.y + 1, getMaxEntryWidth() + (hasScrollBar() ? 6 : 0), getInnerHeight(menuStartPoint.y)); - } - - public boolean hasScrollBar() { - return scrolling.getMaxScrollHeight() > getInnerHeight(menuStartPoint.y); - } - - public int getInnerHeight(int y) { - return Math.min(scrolling.getMaxScrollHeight(), minecraft.screen.height - 20 - y); - } - - public int getMaxEntryWidth() { - int i = 0; - for (MenuEntry entry : children()) { - if (entry.getEntryWidth() > i) - i = entry.getEntryWidth(); - } - return Math.max(10, i); - } - - @Override - public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { - Rectangle bounds = getBounds(); - Rectangle innerBounds = getInnerBounds(); - 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; - int currentY = innerBounds.y - scrolling.scrollAmountInt(); - for (MenuEntry child : children()) { - boolean containsMouse = contains && mouseY >= currentY && mouseY < currentY + child.getEntryHeight(); - if (containsMouse) { - focused = child; - } - currentY += child.getEntryHeight(); - } - currentY = innerBounds.y - scrolling.scrollAmountInt(); - ScissorsHandler.INSTANCE.scissor(scrolling.getScissorBounds()); - for (MenuEntry 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()); - if (rendering) { - child.render(matrices, mouseX, mouseY, delta); - } - currentY += child.getEntryHeight(); - } - ScissorsHandler.INSTANCE.removeLastScissor(); - setFocused(focused); - scrolling.renderScrollBar(0, 1, ConfigObject.getInstance().isUsingDarkTheme() ? 0.8f : 1f); - scrolling.updatePosition(delta); - } - - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (scrolling.updateDraggingState(mouseX, mouseY, button)) - return true; - return super.mouseClicked(mouseX, mouseY, button) || getInnerBounds().contains(mouseX, mouseY); - } - - @Override - public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { - if (scrolling.mouseDragged(mouseX, mouseY, button, deltaX, deltaY)) - return true; - return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); - } - - @Override - public boolean mouseScrolled(double mouseX, double mouseY, double amount) { - if (getInnerBounds().contains(mouseX, mouseY)) { - scrolling.offset(ClothConfigInitializer.getScrollStep() * -amount, true); - return true; - } - for (MenuEntry child : children()) { - if (child instanceof SubMenuEntry) { - if (child.mouseScrolled(mouseX, mouseY, amount)) - return true; - } - } - return super.mouseScrolled(mouseX, mouseY, amount); - } - - @Override - public boolean containsMouse(double mouseX, double mouseY) { - if (super.containsMouse(mouseX, mouseY)) return true; - for (MenuEntry child : children()) { - if (child.containsMouse(mouseX, mouseY)) { - return true; - } - } - return false; - } - - @Override - public List children() { - return entries; - } -} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuAccess.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuAccess.java deleted file mode 100644 index b890ccd94..000000000 --- a/runtime/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 or, Predicate and); - - default void openOrClose(UUID uuid, Rectangle selfBounds, Supplier> 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/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuAccessImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuAccessImpl.java deleted file mode 100644 index c51330f94..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuAccessImpl.java +++ /dev/null @@ -1,136 +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 com.google.common.collect.Lists; -import com.mojang.blaze3d.vertex.PoseStack; -import me.shedaniel.math.Point; -import me.shedaniel.math.impl.PointHelper; -import me.shedaniel.rei.api.client.REIRuntime; -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.ScreenOverlayImpl; -import org.jetbrains.annotations.Nullable; - -import java.util.List; -import java.util.UUID; -import java.util.function.Consumer; -import java.util.function.Predicate; - -public class MenuAccessImpl implements MenuAccess { - public final List afterRenders = Lists.newArrayList(); - @Nullable - private OverlayMenu menu = null; - - @Override - public boolean isOpened(UUID uuid) { - return menu != null && menu.uuid.equals(uuid); - } - - @Override - public boolean isAnyOpened() { - return menu != null; - } - - @Override - public boolean isInBounds(UUID uuid) { - return isOpened(uuid) && menu.inBounds.test(PointHelper.ofMouse()); - } - - private void proceedOpenMenu(UUID uuid, Runnable runnable) { - proceedOpenMenuOrElse(uuid, runnable, menu -> {}); - } - - private void proceedOpenMenuOrElse(UUID uuid, Runnable runnable, Consumer orElse) { - if (menu == null || !menu.uuid.equals(uuid)) { - close(); - runnable.run(); - } else { - orElse.accept(this.menu); - } - } - - @Override - public void open(UUID uuid, Menu menu) { - open(uuid, menu, point -> false, point -> true); - } - - @Override - public void open(UUID uuid, Menu menu, Predicate or, Predicate and) { - this.menu = new OverlayMenu(uuid, menu, Widgets.withTranslate(menu, 0, 0, 400), or, and); - } - - @Override - public boolean isValidPoint(Point point) { - return ScreenOverlayImpl.getInstance().isNotInExclusionZones(point.x, point.y); - } - - @Override - public void close() { - this.menu = null; - } - - public void afterRender() { - for (Runnable runnable : afterRenders) { - runnable.run(); - } - afterRenders.clear(); - } - - @Nullable - public Widget widget() { - return menu != null ? menu.wrappedMenu : null; - } - - public void lateRender(PoseStack matrices, int mouseX, int mouseY, float delta) { - if (menu != null) { - if (!menu.inBounds.test(PointHelper.ofMouse())) { - close(); - } else { - if (menu.wrappedMenu.containsMouse(mouseX, mouseY)) { - REIRuntime.getInstance().clearTooltips(); - } - menu.wrappedMenu.render(matrices, mouseX, mouseY, delta); - } - } - } - - public boolean mouseScrolled(double mouseX, double mouseY, double amount) { - return menu != null && menu.wrappedMenu.mouseScrolled(mouseX, mouseY, amount); - } - - private static class OverlayMenu { - private UUID uuid; - private Menu menu; - private Widget wrappedMenu; - private Predicate inBounds; - - public OverlayMenu(UUID uuid, Menu menu, Widget wrappedMenu, Predicate or, Predicate and) { - this.uuid = uuid; - this.menu = menu; - this.wrappedMenu = wrappedMenu; - this.inBounds = or.or(menu::containsMouse).and(and); - } - } -} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuEntry.java deleted file mode 100644 index e5c7109d8..000000000 --- a/runtime/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/src/main/java/me/shedaniel/rei/impl/client/gui/menu/entries/EmptyMenuEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/entries/EmptyMenuEntry.java deleted file mode 100644 index e269a496d..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/menu/entries/EmptyMenuEntry.java +++ /dev/null @@ -1,58 +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,