From a1d8c20c7b34c12b5d95c1d61131a253cdd8affd Mon Sep 17 00:00:00 2001 From: shedaniel Date: Mon, 25 Apr 2022 22:20:34 +0800 Subject: Code refactor on entry lists --- .../shedaniel/rei/impl/client/REIRuntimeImpl.java | 2 +- .../rei/impl/client/config/ConfigObjectImpl.java | 3 +- .../client/config/entries/FilteringScreen.java | 23 +- .../entry/filtering/rules/SearchFilteringRule.java | 6 +- .../rei/impl/client/gui/ScreenOverlayImpl.java | 8 +- .../client/gui/performance/PerformanceScreen.java | 13 +- .../gui/performance/entry/EntryListEntry.java | 71 -- .../performance/entry/PerformanceEntryImpl.java | 71 ++ .../client/gui/widget/DisplayedEntryWidget.java | 110 +++ .../client/gui/widget/EntryListEntryWidget.java | 110 --- .../impl/client/gui/widget/EntryListWidget.java | 738 ------------------- .../client/gui/widget/EntryStacksRegionWidget.java | 506 ------------- .../rei/impl/client/gui/widget/EntryWidget.java | 3 +- .../client/gui/widget/FavoritesListWidget.java | 820 --------------------- .../widget/entrylist/EntryListSearchManager.java | 94 +++ .../gui/widget/entrylist/EntryListStackEntry.java | 193 +++++ .../gui/widget/entrylist/EntryListWidget.java | 510 +++++++++++++ .../gui/widget/favorites/FavoritesListWidget.java | 280 +++++++ .../listeners/FavoritesRegionListener.java | 84 +++ .../listeners/FavoritesSystemRegionListener.java | 56 ++ .../panel/FadingFavoritesPanelButton.java | 126 ++++ .../gui/widget/favorites/panel/FavoritesPanel.java | 179 +++++ .../panel/FavoritesTogglePanelButton.java | 75 ++ .../panel/rows/FavoritesPanelEmptyRow.java | 52 ++ .../panel/rows/FavoritesPanelEntriesRow.java | 211 ++++++ .../favorites/panel/rows/FavoritesPanelRow.java | 33 + .../panel/rows/FavoritesPanelSectionRow.java | 61 ++ .../panel/rows/FavoritesPanelSeparatorRow.java | 47 ++ .../gui/widget/favorites/trash/TrashWidget.java | 101 +++ .../gui/widget/region/EntryStacksRegionWidget.java | 504 +++++++++++++ .../client/gui/widget/region/RealRegionEntry.java | 9 +- .../gui/widget/region/RegionDraggableStack.java | 1 - .../gui/widget/region/RegionEntryListEntry.java | 146 ---- .../gui/widget/region/RegionEntryWidget.java | 146 ++++ .../client/gui/widget/region/RegionListener.java | 2 +- .../gui/widget/region/RegionRenderingDebugger.java | 77 ++ .../client/runtime/DefaultClientRuntimePlugin.java | 6 +- 37 files changed, 3045 insertions(+), 2432 deletions(-) delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/entry/EntryListEntry.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/entry/PerformanceEntryImpl.java create 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/EntryListEntryWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryListWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryStacksRegionWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/FavoritesListWidget.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListSearchManager.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListStackEntry.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListWidget.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/FavoritesListWidget.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/listeners/FavoritesRegionListener.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/listeners/FavoritesSystemRegionListener.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/panel/FadingFavoritesPanelButton.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/panel/FavoritesPanel.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/panel/FavoritesTogglePanelButton.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/panel/rows/FavoritesPanelEmptyRow.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/panel/rows/FavoritesPanelEntriesRow.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/panel/rows/FavoritesPanelRow.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/panel/rows/FavoritesPanelSectionRow.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/panel/rows/FavoritesPanelSeparatorRow.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/favorites/trash/TrashWidget.java create 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/RegionEntryListEntry.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/region/RegionEntryWidget.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/region/RegionRenderingDebugger.java (limited to 'runtime/src/main/java/me') 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 792c66586..8791301b0 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 @@ -58,7 +58,7 @@ import org.jetbrains.annotations.Nullable; import java.util.*; -import static me.shedaniel.rei.impl.client.gui.widget.EntryListWidget.entrySize; +import static me.shedaniel.rei.impl.client.gui.widget.entrylist.EntryListWidget.entrySize; @ApiStatus.Internal @Environment(EnvType.CLIENT) diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java index 0f273b7e8..1189436c2 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java @@ -249,7 +249,7 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { @Override public boolean doesSnapToRows() { - return advanced.accessibility.snapToRows; + return false; } @Override @@ -633,7 +633,6 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { @UsePercentage(min = 0.25, max = 4.0) private double entrySize = 1.0; @Comment("Declares the position of the entry panel.") @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) private DisplayPanelLocation displayPanelLocation = DisplayPanelLocation.RIGHT; - @Comment("Declares whether scrolled entry panel should snap to rows.") private boolean snapToRows = false; @Comment("Declares how the scrollbar in composite screen should act.") private boolean compositeScrollBarPermanent = false; private boolean toastDisplayedOnCopyIdentifier = true; @Comment("Declares whether REI should use compact tabs for categories.") private boolean useCompactTabs = true; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringScreen.java index 5fcd5790e..83490fa16 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringScreen.java @@ -35,7 +35,6 @@ 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.config.ConfigObject; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; import me.shedaniel.rei.api.client.registry.entry.EntryRegistry; import me.shedaniel.rei.api.client.search.SearchFilter; @@ -62,7 +61,7 @@ import java.util.Collections; import java.util.List; import java.util.Set; -import static me.shedaniel.rei.impl.client.gui.widget.EntryListWidget.entrySize; +import static me.shedaniel.rei.impl.client.gui.widget.entrylist.EntryListWidget.entrySize; @ApiStatus.Internal public class FilteringScreen extends Screen { @@ -89,7 +88,7 @@ public class FilteringScreen extends Screen { private Tooltip tooltip = null; private List> entryStacks = null; private Rectangle innerBounds; - private List entries = Collections.emptyList(); + private List entries = Collections.emptyList(); private List elements = Collections.emptyList(); private Point selectionPoint = null; @@ -128,7 +127,7 @@ public class FilteringScreen extends Screen { this.hideButton = new Button(0, 0, Minecraft.getInstance().font.width(hideText) + 10, 20, hideText, button -> { for (int i = 0; i < entryStacks.size(); i++) { EntryStack stack = entryStacks.get(i); - EntryListEntry entry = entries.get(i); + FilteringListEntry entry = entries.get(i); entry.getBounds().y = entry.backupY - scrolling.scrollAmountInt(); if (entry.isSelected() && !entry.isFiltered()) { filteringEntry.configFiltered.add(stack); @@ -143,7 +142,7 @@ public class FilteringScreen extends Screen { this.showButton = new Button(0, 0, Minecraft.getInstance().font.width(showText) + 10, 20, showText, button -> { for (int i = 0; i < entryStacks.size(); i++) { EntryStack stack = entryStacks.get(i); - EntryListEntry entry = entries.get(i); + FilteringListEntry entry = entries.get(i); entry.getBounds().y = entry.backupY - scrolling.scrollAmountInt(); if (entry.isSelected() && filteringEntry.configFiltered.remove(stack)) { filteringEntry.edited = true; @@ -216,7 +215,7 @@ public class FilteringScreen extends Screen { if (bounds.isEmpty()) return; ScissorsHandler.INSTANCE.scissor(bounds); - for (EntryListEntry entry : entries) + for (FilteringListEntry entry : entries) entry.clearStacks(); int skip = Math.max(0, Mth.floor(scrolling.scrollAmount() / (float) entrySize())); int nextIndex = skip * innerBounds.width / entrySize(); @@ -224,7 +223,7 @@ public class FilteringScreen extends Screen { BatchedEntryRendererManager manager = new BatchedEntryRendererManager(); for (; i < entryStacks.size(); i++) { EntryStack stack = entryStacks.get(i); - EntryListEntry entry = entries.get(nextIndex); + FilteringListEntry entry = entries.get(nextIndex); entry.getBounds().y = entry.backupY - scrolling.scrollAmountInt(); if (entry.getBounds().y > bounds.getMaxY()) break; @@ -294,7 +293,7 @@ public class FilteringScreen extends Screen { @Override public boolean mouseDragged(double mouseX, double mouseY, int button, double dx, double dy) { - if (scrolling.mouseDragged(mouseX, mouseY, button, dx, dy, ConfigObject.getInstance().doesSnapToRows(), entrySize())) + if (scrolling.mouseDragged(mouseX, mouseY, button, dx, dy)) return true; return super.mouseDragged(mouseX, mouseY, button, dx, dy); } @@ -328,11 +327,11 @@ public class FilteringScreen extends Screen { int slotsToPrepare = Math.max(entryStacks.size() * 3, width * pageHeight * 3); int currentX = 0; int currentY = 0; - List entries = Lists.newArrayList(); + List entries = Lists.newArrayList(); for (int i = 0; i < slotsToPrepare; i++) { int xPos = currentX * entrySize + innerBounds.x; int yPos = currentY * entrySize + innerBounds.y; - entries.add(new EntryListEntry(xPos, yPos, entrySize)); + entries.add(new FilteringListEntry(xPos, yPos, entrySize)); currentX++; if (currentX >= width) { currentX = 0; @@ -440,12 +439,12 @@ public class FilteringScreen extends Screen { return true; } - private class EntryListEntry extends EntryWidget { + private class FilteringListEntry extends EntryWidget { private int backupY; private boolean filtered = false; private boolean dirty = true; - private EntryListEntry(int x, int y, int entrySize) { + private FilteringListEntry(int x, int y, int entrySize) { super(new Point(x, y)); this.backupY = y; getBounds().width = getBounds().height = entrySize; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/SearchFilteringRule.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/SearchFilteringRule.java index 0e48f1b97..175ac532a 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/SearchFilteringRule.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/SearchFilteringRule.java @@ -26,9 +26,7 @@ package me.shedaniel.rei.impl.client.entry.filtering.rules; import com.google.common.base.Suppliers; import com.google.common.collect.Lists; import com.mojang.blaze3d.vertex.PoseStack; -import me.shedaniel.clothconfig2.api.ScissorsHandler; import me.shedaniel.math.Rectangle; -import me.shedaniel.rei.api.client.REIRuntime; import me.shedaniel.rei.api.client.registry.entry.EntryRegistry; import me.shedaniel.rei.api.client.search.SearchFilter; import me.shedaniel.rei.api.client.search.SearchProvider; @@ -36,7 +34,6 @@ import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.impl.client.config.entries.FilteringEntry; import me.shedaniel.rei.impl.client.config.entries.FilteringRuleOptionsScreen; -import me.shedaniel.rei.impl.client.config.entries.FilteringScreen; import me.shedaniel.rei.impl.client.entry.filtering.AbstractFilteringRule; import me.shedaniel.rei.impl.client.entry.filtering.FilteringCache; import me.shedaniel.rei.impl.client.entry.filtering.FilteringContext; @@ -53,7 +50,6 @@ import net.minecraft.client.gui.screens.Screen; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TranslatableComponent; -import net.minecraft.util.Mth; import net.minecraft.util.StringUtil; import java.util.*; @@ -67,7 +63,7 @@ import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; -import static me.shedaniel.rei.impl.client.gui.widget.EntryListWidget.entrySize; +import static me.shedaniel.rei.impl.client.gui.widget.entrylist.EntryListWidget.entrySize; @Environment(EnvType.CLIENT) public class SearchFilteringRule extends AbstractFilteringRule { 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 index 74c010f83..b15bae714 100644 --- 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 @@ -57,7 +57,6 @@ import me.shedaniel.rei.api.client.view.ViewSearchBuilder; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.plugins.PluginManager; import me.shedaniel.rei.api.common.util.EntryStacks; -import me.shedaniel.rei.api.common.util.ImmutableTextComponent; import me.shedaniel.rei.impl.client.ClientHelperImpl; import me.shedaniel.rei.impl.client.REIRuntimeImpl; import me.shedaniel.rei.impl.client.config.ConfigManagerImpl; @@ -69,6 +68,9 @@ import me.shedaniel.rei.impl.client.gui.modules.Menu; import me.shedaniel.rei.impl.client.gui.modules.MenuEntry; import me.shedaniel.rei.impl.client.gui.modules.entries.*; import me.shedaniel.rei.impl.client.gui.widget.*; +import me.shedaniel.rei.impl.client.gui.widget.entrylist.EntryListSearchManager; +import me.shedaniel.rei.impl.client.gui.widget.entrylist.EntryListWidget; +import me.shedaniel.rei.impl.client.gui.widget.favorites.FavoritesListWidget; import me.shedaniel.rei.impl.client.gui.widget.search.OverlaySearchField; import me.shedaniel.rei.impl.common.util.Weather; import net.minecraft.ChatFormatting; @@ -97,7 +99,7 @@ import java.util.*; import java.util.function.Consumer; import java.util.function.Predicate; -import static me.shedaniel.rei.impl.client.gui.widget.EntryListWidget.entrySize; +import static me.shedaniel.rei.impl.client.gui.widget.entrylist.EntryListWidget.entrySize; @ApiStatus.Internal public class ScreenOverlayImpl extends ScreenOverlay { @@ -610,7 +612,7 @@ public class ScreenOverlayImpl extends ScreenOverlay { if (Minecraft.getInstance().screen instanceof AbstractContainerScreen containerScreen) { int x = containerScreen.leftPos, y = containerScreen.topPos; for (Slot slot : containerScreen.getMenu().slots) { - if (!slot.hasItem() || !ENTRY_LIST_WIDGET.matches(EntryStacks.of(slot.getItem()))) { + if (!slot.hasItem() || !EntryListSearchManager.INSTANCE.matches(EntryStacks.of(slot.getItem()))) { matrices.pushPose(); matrices.translate(0, 0, 500f); fillGradient(matrices, x + slot.x, y + slot.y, x + slot.x + 16, y + slot.y + 16, 0xdc202020, 0xdc202020); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/PerformanceScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/PerformanceScreen.java index 7e1b11719..048a20bce 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/PerformanceScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/PerformanceScreen.java @@ -29,7 +29,7 @@ import me.shedaniel.clothconfig2.gui.widget.DynamicElementListWidget; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.common.plugins.REIPlugin; import me.shedaniel.rei.api.common.plugins.REIPluginProvider; -import me.shedaniel.rei.impl.client.gui.performance.entry.EntryListEntry; +import me.shedaniel.rei.impl.client.gui.performance.entry.PerformanceEntryImpl; import me.shedaniel.rei.impl.client.gui.performance.entry.SubCategoryListEntry; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -147,9 +147,9 @@ public class PerformanceScreen extends Screen { list = new PerformanceEntryListWidget(); long[] totalTime = {0}; RoughlyEnoughItemsCore.PERFORMANCE_LOGGER.getStages().forEach((stage, inner) -> { - List entries = new ArrayList<>(); + List entries = new ArrayList<>(); inner.times().forEach((obj, time) -> { - entries.add(new EntryListEntry(new TextComponent(obj instanceof Pair ? ((Pair, REIPlugin>) obj).getFirst().getPluginProviderName() : Objects.toString(obj)), time)); + entries.add(new PerformanceEntryImpl(new TextComponent(obj instanceof Pair ? ((Pair, REIPlugin>) obj).getFirst().getPluginProviderName() : Objects.toString(obj)), time)); }); Collection values = inner.times().values(); long separateTime; @@ -157,13 +157,13 @@ public class PerformanceScreen extends Screen { separateTime = values.stream().collect(Collectors.summarizingLong(value -> value)).getSum(); } if ((inner.totalNano() - separateTime) > 1000000) { - entries.add(new EntryListEntry(new TextComponent("Miscellaneous Operations"), inner.totalNano() - separateTime)); + entries.add(new PerformanceEntryImpl(new TextComponent("Miscellaneous Operations"), inner.totalNano() - separateTime)); } totalTime[0] += Math.max(inner.totalNano(), separateTime); - entries.sort(Comparator.comparingLong(value -> value.time).reversed()); + entries.sort(Comparator.comparingLong(value -> value.time).reversed()); list.addItem(new SubCategoryListEntry(new TextComponent(stage), (List) (List) entries, Math.max(inner.totalNano(), separateTime), false)); }); - list.children().add(0, new EntryListEntry(new TextComponent("Total Load Time"), totalTime[0])); + list.children().add(0, new PerformanceEntryImpl(new TextComponent("Total Load Time"), totalTime[0])); addWidget(list); } @@ -176,7 +176,6 @@ public class PerformanceScreen extends Screen { } public static abstract class PerformanceEntry extends DynamicElementListWidget.ElementEntry { - } private class PerformanceEntryListWidget extends DynamicElementListWidget { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/entry/EntryListEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/entry/EntryListEntry.java deleted file mode 100644 index 8e897debf..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/entry/EntryListEntry.java +++ /dev/null @@ -1,71 +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.performance.entry; - -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; -import me.shedaniel.rei.impl.client.gui.performance.PerformanceScreen; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.gui.narration.NarratableEntry; -import net.minecraft.network.chat.Component; -import net.minecraft.util.FormattedCharSequence; - -import java.util.Collections; -import java.util.List; - -@Environment(EnvType.CLIENT) -public class EntryListEntry extends PerformanceScreen.PerformanceEntry { - private final Component name; - public final long time; - - public EntryListEntry(Component name, long time) { - this.name = name; - this.time = time; - } - - public void render(PoseStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isHovered, float delta) { - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - Minecraft.getInstance().font.drawShadow(matrices, this.name.getVisualOrderText(), (float) x, (float) (y + 6), -1); - FormattedCharSequence timeText = PerformanceScreen.formatTime(time, false); - Minecraft.getInstance().font.drawShadow(matrices, timeText, (float) x + entryWidth - 6 - 4 - Minecraft.getInstance().font.width(timeText), (float) (y + 6), -1); - } - - @Override - public int getItemHeight() { - return 24; - } - - @Override - public List children() { - return Collections.emptyList(); - } - - @Override - public List narratables() { - return Collections.emptyList(); - } -} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/entry/PerformanceEntryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/entry/PerformanceEntryImpl.java new file mode 100644 index 000000000..4c08eac0c --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/entry/PerformanceEntryImpl.java @@ -0,0 +1,71 @@ +/* + * 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.performance.entry; + +import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; +import me.shedaniel.rei.impl.client.gui.performance.PerformanceScreen; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.gui.narration.NarratableEntry; +import net.minecraft.network.chat.Component; +import net.minecraft.util.FormattedCharSequence; + +import java.util.Collections; +import java.util.List; + +@Environment(EnvType.CLIENT) +public class PerformanceEntryImpl extends PerformanceScreen.PerformanceEntry { + private final Component name; + public final long time; + + public PerformanceEntryImpl(Component name, long time) { + this.name = name; + this.time = time; + } + + public void render(PoseStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isHovered, float delta) { + RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); + Minecraft.getInstance().font.drawShadow(matrices, this.name.getVisualOrderText(), (float) x, (float) (y + 6), -1); + FormattedCharSequence timeText = PerformanceScreen.formatTime(time, false); + Minecraft.getInstance().font.drawShadow(matrices, timeText, (float) x + entryWidth - 6 - 4 - Minecraft.getInstance().font.width(timeText), (float) (y + 6), -1); + } + + @Override + public int getItemHeight() { + return 24; + } + + @Override + public List children() { + return Collections.emptyList(); + } + + @Override + public List narratables() { + return Collections.emptyList(); + } +} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DisplayedEntryWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DisplayedEntryWidget.java new file mode 100644 index 000000000..2dbc66f93 --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/DisplayedEntryWidget.java @@ -0,0 +1,110 @@ +/* + * 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.widget; + +import com.mojang.blaze3d.vertex.PoseStack; +import me.shedaniel.math.Point; +import me.shedaniel.rei.api.client.ClientHelper; +import me.shedaniel.rei.api.client.config.ConfigObject; +import me.shedaniel.rei.api.client.gui.config.ItemCheatingMode; +import me.shedaniel.rei.api.client.gui.screen.DisplayScreen; +import me.shedaniel.rei.api.common.entry.EntryStack; +import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; +import me.shedaniel.rei.api.common.util.EntryStacks; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.world.item.ItemStack; + +public abstract class DisplayedEntryWidget extends EntryWidget { + public int backupY; + + protected DisplayedEntryWidget(Point point, int entrySize) { + super(point); + this.backupY = point.y; + getBounds().width = getBounds().height = entrySize; + } + + @Override + protected void drawHighlighted(PoseStack matrices, int mouseX, int mouseY, float delta) { + if (!getCurrentEntry().isEmpty()) + super.drawHighlighted(matrices, mouseX, mouseY, delta); + } + + @Override + public void queueTooltip(PoseStack matrices, int mouseX, int mouseY, float delta) { + if (ClientHelper.getInstance().isCheating() && !(Minecraft.getInstance().screen instanceof DisplayScreen) && !minecraft.player.containerMenu.getCarried().isEmpty()) { + return; + } + super.queueTooltip(matrices, mouseX, mouseY, delta); + } + + @Override + public boolean mouseReleased(double mouseX, double mouseY, int button) { + if (!interactable) + return super.mouseReleased(mouseX, mouseY, button); + if (containsMouse(mouseX, mouseY)) { + if (wasClicked()) { + if (doAction(mouseX, mouseY, button)) { + return true; + } else { + wasClicked = true; + } + } + } + return super.mouseReleased(mouseX, mouseY, button); + } + + protected boolean doAction(double mouseX, double mouseY, int button) { + if (!(ClientHelper.getInstance().isCheating() && !(Minecraft.getInstance().screen instanceof DisplayScreen))) return false; + EntryStack entry = getCurrentEntry().copy(); + if (!entry.isEmpty()) { + if (entry.getType() != VanillaEntryTypes.ITEM) { + EntryStack cheatsAs = entry.cheatsAs(); + entry = cheatsAs.isEmpty() ? entry : cheatsAs; + } + if (entry.getValueType() == ItemStack.class) + entry.castValue().setCount(button != 1 && !Screen.hasShiftDown() == (ConfigObject.getInstance().getItemCheatingMode() == ItemCheatingMode.REI_LIKE) ? 1 : entry.castValue().getMaxStackSize()); + return ClientHelper.getInstance().tryCheatingEntry(entry); + } + + return false; + } + + @Override + public boolean cancelDeleteItems(EntryStack stack) { + if (!interactable || !ConfigObject.getInstance().isGrabbingItems()) + return super.cancelDeleteItems(stack); + if (ClientHelper.getInstance().isCheating() && !(Minecraft.getInstance().screen instanceof DisplayScreen)) { + EntryStack entry = getCurrentEntry().copy(); + if (!entry.isEmpty()) { + if (entry.getType() != VanillaEntryTypes.ITEM) { + EntryStack cheatsAs = entry.cheatsAs(); + entry = cheatsAs.isEmpty() ? entry : cheatsAs; + } + return EntryStacks.equalsExact(entry, stack); + } + } + return super.cancelDeleteItems(stack); + } +} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryListEntryWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryListEntryWidget.java deleted file mode 100644 index 85cbc89f7..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryListEntryWidget.java +++ /dev/null @@ -1,110 +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.widget; - -import com.mojang.blaze3d.vertex.PoseStack; -import me.shedaniel.math.Point; -import me.shedaniel.rei.api.client.ClientHelper; -import me.shedaniel.rei.api.client.config.ConfigObject; -import me.shedaniel.rei.api.client.gui.config.ItemCheatingMode; -import me.shedaniel.rei.api.client.gui.screen.DisplayScreen; -import me.shedaniel.rei.api.common.entry.EntryStack; -import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; -import me.shedaniel.rei.api.common.util.EntryStacks; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.world.item.ItemStack; - -public abstract class EntryListEntryWidget extends EntryWidget { - public int backupY; - - protected EntryListEntryWidget(Point point, int entrySize) { - super(point); - this.backupY = point.y; - getBounds().width = getBounds().height = entrySize; - } - - @Override - protected void drawHighlighted(PoseStack matrices, int mouseX, int mouseY, float delta) { - if (!getCurrentEntry().isEmpty()) - super.drawHighlighted(matrices, mouseX, mouseY, delta); - } - - @Override - public void queueTooltip(PoseStack matrices, int mouseX, int mouseY, float delta) { - if (ClientHelper.getInstance().isCheating() && !(Minecraft.getInstance().screen instanceof DisplayScreen) && !minecraft.player.containerMenu.getCarried().isEmpty()) { - return; - } - super.queueTooltip(matrices, mouseX, mouseY, delta); - } - - @Override - public boolean mouseReleased(double mouseX, double mouseY, int button) { - if (!interactable) - return super.mouseReleased(mouseX, mouseY, button); - if (containsMouse(mouseX, mouseY)) { - if (wasClicked()) { - if (doAction(mouseX, mouseY, button)) { - return true; - } else { - wasClicked = true; - } - } - } - return super.mouseReleased(mouseX, mouseY, button); - } - - protected boolean doAction(double mouseX, double mouseY, int button) { - if (!(ClientHelper.getInstance().isCheating() && !(Minecraft.getInstance().screen instanceof DisplayScreen))) return false; - EntryStack entry = getCurrentEntry().copy(); - if (!entry.isEmpty()) { - if (entry.getType() != VanillaEntryTypes.ITEM) { - EntryStack cheatsAs = entry.cheatsAs(); - entry = cheatsAs.isEmpty() ? entry : cheatsAs; - } - if (entry.getValueType() == ItemStack.class) - entry.castValue().setCount(button != 1 && !Screen.hasShiftDown() == (ConfigObject.getInstance().getItemCheatingMode() == ItemCheatingMode.REI_LIKE) ? 1 : entry.castValue().getMaxStackSize()); - return ClientHelper.getInstance().tryCheatingEntry(entry); - } - - return false; - } - - @Override - protected boolean cancelDeleteItems(EntryStack stack) { - if (!interactable || !ConfigObject.getInstance().isGrabbingItems()) - return super.cancelDeleteItems(stack); - if (ClientHelper.getInstance().isCheating() && !(Minecraft.getInstance().screen instanceof DisplayScreen)) { - EntryStack entry = getCurrentEntry().copy(); - if (!entry.isEmpty()) { - if (entry.getType() != VanillaEntryTypes.ITEM) { - EntryStack cheatsAs = entry.cheatsAs(); - entry = cheatsAs.isEmpty() ? entry : cheatsAs; - } - return EntryStacks.equalsExact(entry, stack); - } - } - return super.cancelDeleteItems(stack); - } -} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryListWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryListWidget.java deleted file mode 100644 index cde2ece23..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryListWidget.java +++ /dev/null @@ -1,738 +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.widget; - -import com.google.common.base.Predicates; -import com.google.common.base.Stopwatch; -import com.google.common.collect.Lists; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.blaze3d.vertex.Tesselator; -import com.mojang.math.Matrix4f; -import me.shedaniel.clothconfig2.ClothConfigInitializer; -import me.shedaniel.clothconfig2.api.ScissorsHandler; -import me.shedaniel.clothconfig2.api.animator.NumberAnimator; -import me.shedaniel.clothconfig2.api.animator.ValueAnimator; -import me.shedaniel.clothconfig2.api.scroll.ScrollingContainer; -import me.shedaniel.math.Point; -import me.shedaniel.math.Rectangle; -import me.shedaniel.math.impl.PointHelper; -import me.shedaniel.rei.RoughlyEnoughItemsCore; -import me.shedaniel.rei.api.client.ClientHelper; -import me.shedaniel.rei.api.client.REIRuntime; -import me.shedaniel.rei.api.client.config.ConfigManager; -import me.shedaniel.rei.api.client.config.ConfigObject; -import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer; -import me.shedaniel.rei.api.client.gui.config.EntryPanelOrdering; -import me.shedaniel.rei.api.client.gui.drag.DraggableStack; -import me.shedaniel.rei.api.client.gui.drag.DraggableStackVisitorWidget; -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.screen.DisplayScreen; -import me.shedaniel.rei.api.client.gui.widgets.Tooltip; -import me.shedaniel.rei.api.client.gui.widgets.Widget; -import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds; -import me.shedaniel.rei.api.client.overlay.OverlayListWidget; -import me.shedaniel.rei.api.client.overlay.ScreenOverlay; -import me.shedaniel.rei.api.client.registry.display.DisplayRegistry; -import me.shedaniel.rei.api.client.registry.screen.OverlayDecider; -import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry; -import me.shedaniel.rei.api.client.registry.transfer.TransferHandler; -import me.shedaniel.rei.api.common.display.Display; -import me.shedaniel.rei.api.common.entry.EntryStack; -import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; -import me.shedaniel.rei.api.common.plugins.PluginManager; -import me.shedaniel.rei.api.common.util.EntryStacks; -import me.shedaniel.rei.impl.client.ClientHelperImpl; -import me.shedaniel.rei.impl.client.config.ConfigManagerImpl; -import me.shedaniel.rei.impl.client.config.ConfigObjectImpl; -import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl; -import me.shedaniel.rei.impl.client.search.AsyncSearchManager; -import me.shedaniel.rei.impl.client.view.ViewsImpl; -import net.minecraft.ChatFormatting; -import net.minecraft.Util; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; -import net.minecraft.client.player.LocalPlayer; -import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.resources.sounds.SimpleSoundInstance; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TextComponent; -import net.minecraft.network.chat.TranslatableComponent; -import net.minecraft.sounds.SoundEvents; -import net.minecraft.util.Mth; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.item.CreativeModeTab; -import net.minecraft.world.item.ItemStack; -import org.apache.commons.lang3.mutable.MutableInt; -import org.apache.commons.lang3.mutable.MutableLong; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -@ApiStatus.Internal -public class EntryListWidget extends WidgetWithBounds implements OverlayListWidget, DraggableStackVisitorWidget { - static final Comparator> ENTRY_NAME_COMPARER = Comparator.comparing(stack -> stack.asFormatStrippedText().getString()); - static final Comparator> ENTRY_GROUP_COMPARER = Comparator.comparingInt(stack -> { - if (stack.getType() == VanillaEntryTypes.ITEM) { - CreativeModeTab group = ((ItemStack) stack.getValue()).getItem().getItemCategory(); - if (group != null) - return group.getId(); - } - return Integer.MAX_VALUE; - }); - private static final int SIZE = 18; - private static final boolean LAZY = true; - private static int page; - protected final ScrollingContainer scrolling = new ScrollingContainer() { - @Override - public Rectangle getBounds() { - return EntryListWidget.this.getBounds(); - } - - @Override - public int getMaxScrollHeight() { - return Mth.ceil((allStacks.size() + blockedCount) / (innerBounds.width / (float) entrySize())) * entrySize(); - } - }; - protected int blockedCount; - private boolean debugTime; - private double lastAverageDebugTime, averageDebugTime, lastTotalDebugTime, totalDebugTime, totalDebugTimeDelta; - private Rectangle bounds, innerBounds; - private List> allStacks = null; - private List entries = Collections.emptyList(); - private List renders = Collections.emptyList(); - private List widgets = Collections.emptyList(); - private AsyncSearchManager searchManager = AsyncSearchManager.createDefault(); - - public static int entrySize() { - return Mth.ceil(SIZE * ConfigObject.getInstance().getEntrySize()); - } - - public static boolean notSteppingOnExclusionZones(int left, int top, int width, int height, Rectangle listArea) { - Minecraft instance = Minecraft.getInstance(); - for (OverlayDecider decider : ScreenRegistry.getInstance().getDeciders(instance.screen)) { - InteractionResult fit = canItemSlotWidgetFit(left, top, width, height, decider); - if (fit != InteractionResult.PASS) - return fit == InteractionResult.SUCCESS; - } - return true; - } - - private static InteractionResult canItemSlotWidgetFit(int left, int top, int width, int height, OverlayDecider decider) { - InteractionResult fit; - fit = decider.isInZone(left, top); - if (fit != InteractionResult.PASS) - return fit; - fit = decider.isInZone(left + width, top); - if (fit != InteractionResult.PASS) - return fit; - fit = decider.isInZone(left, top + height); - if (fit != InteractionResult.PASS) - return fit; - fit = decider.isInZone(left + width, top + height); - return fit; - } - - private boolean containsChecked(Point point, boolean inner) { - return containsChecked(point.x, point.y, inner); - } - - @Override - public boolean containsMouse(double mouseX, double mouseY) { - return hasSpace() && super.containsMouse(mouseX, mouseY); - } - - public boolean innerContainsMouse(double mouseX, double mouseY) { - return hasSpace() && innerBounds.contains(mouseX, mouseY); - } - - private boolean containsChecked(double x, double y, boolean inner) { - if (inner) { - if (!innerContainsMouse(x, y)) return false; - } else { - if (!containsMouse(x, y)) return false; - } - Minecraft instance = Minecraft.getInstance(); - for (OverlayDecider decider : ScreenRegistry.getInstance().getDeciders(instance.screen)) { - InteractionResult result = decider.isInZone(x, y); - if (result != InteractionResult.PASS) - return result == InteractionResult.SUCCESS; - } - return true; - } - - private static Rectangle updateInnerBounds(Rectangle bounds) { - bounds = bounds.clone(); - int heightReduction = (int) Math.round(bounds.height * (1 - ConfigObject.getInstance().getVerticalEntriesBoundariesPercentage())); - bounds.y += heightReduction / 2; - bounds.height -= heightReduction; - int maxHeight = (int) Math.ceil(entrySize() * ConfigObject.getInstance().getVerticalEntriesBoundariesRows()); - if (bounds.height > maxHeight) { - bounds.y += (bounds.height - maxHeight) / 2; - bounds.height = maxHeight; - } - int entrySize = entrySize(); - if (ConfigObject.getInstance().isEntryListWidgetScrolled()) { - int width = Math.max(Mth.floor((bounds.width - 2 - 6) / (float) entrySize), 1); - if (ConfigObject.getInstance().isLeftHandSidePanel()) { - return new Rectangle((int) (bounds.getCenterX() - width * (entrySize / 2f) + 3), bounds.y, width * entrySize, bounds.height); - } - return new Rectangle((int) (bounds.getCenterX() - width * (entrySize / 2f) - 3), bounds.y, width * entrySize, bounds.height); - } else { - int width = Math.max(Mth.floor((bounds.width - 2) / (float) entrySize), 1); - int height = Math.max(Mth.floor((bounds.height - 2) / (float) entrySize), 1); - return new Rectangle((int) (bounds.getCenterX() - width * (entrySize / 2f)), (int) (bounds.getCenterY() - height * (entrySize / 2f)), width * entrySize, height * entrySize); - } - } - - @Override - public DraggedAcceptorResult acceptDraggedStack(DraggingContext context, DraggableStack stack) { - if (innerBounds.contains(context.getCurrentPosition())) { - context.renderToVoid(stack); - return DraggedAcceptorResult.CONSUMED; - } else { - return DraggedAcceptorResult.PASS; - } - } - - @Override - public boolean mouseScrolled(double mouseX, double mouseY, double amount) { - if (containsChecked(mouseX, mouseY, false)) { - if (Screen.hasControlDown()) { - ConfigObjectImpl config = ConfigManagerImpl.getInstance().getConfig(); - if (config.setEntrySize(config.getEntrySize() + amount * 0.075)) { - ConfigManager.getInstance().saveConfig(); - REIRuntime.getInstance().getOverlay().ifPresent(ScreenOverlay::queueReloadOverlay); - return true; - } - } else if (ConfigObject.getInstance().isEntryListWidgetScrolled()) { - scrolling.offset(ClothConfigInitializer.getScrollStep() * -amount, true); - return true; - } - } - return super.mouseScrolled(mouseX, mouseY, amount); - } - - @Override - public Rectangle getBounds() { - return bounds; - } - - public int getPage() { - return page; - } - - public void setPage(int page) { - EntryListWidget.page = page; - } - - public void previousPage() { - page--; - } - - public void nextPage() { - page++; - } - - public int getTotalPages() { - if (ConfigObject.getInstance().isEntryListWidgetScrolled()) - return 1; - return Mth.ceil(allStacks.size() / (float) entries.size()); - } - - @Override - public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { - if (!hasSpace()) return; - - MutableInt size = new MutableInt(); - MutableLong time = new MutableLong(); - long totalTimeStart = debugTime ? System.nanoTime() : 0; - boolean fastEntryRendering = ConfigObject.getInstance().doesFastEntryRendering(); - if (ConfigObject.getInstance().isEntryListWidgetScrolled()) { - ScissorsHandler.INSTANCE.scissor(bounds); - - int skip = Math.max(0, Mth.floor(scrolling.scrollAmount() / (float) entrySize())); - int nextIndex = skip * innerBounds.width / entrySize(); - this.blockedCount = 0; - BatchedEntryRendererManager helper = new BatchedEntryRendererManager(); - - int i = nextIndex; - for (int cont = nextIndex; cont < entries.size(); cont++) { - EntryListEntry entry = entries.get(cont); - Rectangle entryBounds = entry.getBounds(); - - entryBounds.y = entry.backupY - scrolling.scrollAmountInt(); - if (entryBounds.y > this.bounds.getMaxY()) break; - if (allStacks.size() <= i) break; - if (notSteppingOnExclusionZones(entryBounds.x, entryBounds.y, entryBounds.width, entryBounds.height, innerBounds)) { - EntryStack stack = allStacks.get(i++); - entry.clearStacks(); - if (!stack.isEmpty()) { - entry.entry(stack); - helper.add(entry); - } - } else { - blockedCount++; - } - } - - helper.render(debugTime, size, time, matrices, mouseX, mouseY, delta); - - updatePosition(delta); - ScissorsHandler.INSTANCE.removeLastScissor(); - if (scrolling.getMaxScroll() > 0) { - scrolling.renderScrollBar(0, 1, REIRuntime.getInstance().isDarkThemeEnabled() ? 0.8f : 1f); - } - } else { - for (Widget widget : renders) { - widget.render(matrices, mouseX, mouseY, delta); - } - if (ConfigObject.getInstance().doesCacheEntryRendering()) { - for (EntryListEntry entry : entries) { - if (entry.our == null) { - CachedEntryListRender.Sprite sprite = CachedEntryListRender.get(entry.getCurrentEntry()); - if (sprite != null) { - entry.our = entry.getCurrentEntry().copy().setting(EntryStack.Settings.RENDERER, stack -> new EntryRenderer() { - @Override - public void render(EntryStack entry, PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta) { - RenderSystem.setShaderTexture(0, CachedEntryListRender.cachedTextureLocation); - innerBlit(matrices.last().pose(), bounds.x, bounds.getMaxX(), bounds.y, bounds.getMaxY(), getBlitOffset(), sprite.u0, sprite.u1, sprite.v0, sprite.v1); - } - - @Override - @Nullable - public Tooltip getTooltip(EntryStack entry, Point mouse) { - return stack.getDefinition().getRenderer().getTooltip(entry.cast(), mouse); - } - }); - } - } - } - - BatchedEntryRendererManager.renderSlow(debugTime, size, time, matrices, mouseX, mouseY, delta, entries); - } else { - new BatchedEntryRendererManager(entries).render(debugTime, size, time, matrices, mouseX, mouseY, delta); - } - } - - if (debugTime) { - long totalTime = System.nanoTime() - totalTimeStart; - averageDebugTime += (time.getValue() / size.doubleValue()) * delta; - totalDebugTime += totalTime / 1000000d * delta; - totalDebugTimeDelta += delta; - if (totalDebugTimeDelta >= 20) { - lastAverageDebugTime = averageDebugTime / totalDebugTimeDelta; - lastTotalDebugTime = totalDebugTime / totalDebugTimeDelta; - averageDebugTime = 0; - totalDebugTime = 0; - totalDebugTimeDelta = 0; - } else if (lastAverageDebugTime == 0) { - lastAverageDebugTime = time.getValue() / size.doubleValue(); - totalDebugTime = totalTime / 1000000d; - } - int z = getZ(); - setZ(500); - Component debugText = new TextComponent(String.format("%d entries, avg. %.0fns, ttl. %.2fms, %s fps", size.getValue(), lastAverageDebugTime, lastTotalDebugTime, minecraft.fpsString.split(" ")[0])); - int stringWidth = font.width(debugText); - fillGradient(matrices, Math.min(bounds.x, minecraft.screen.width - stringWidth - 2), bounds.y, bounds.x + stringWidth + 2, bounds.y + font.lineHeight + 2, -16777216, -16777216); - MultiBufferSource.BufferSource immediate = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder()); - matrices.pushPose(); - matrices.translate(0.0D, 0.0D, getZ()); - Matrix4f matrix = matrices.last().pose(); - font.drawInBatch(debugText.getVisualOrderText(), Math.min(bounds.x + 2, minecraft.screen.width - stringWidth), bounds.y + 2, -1, false, matrix, immediate, false, 0, 15728880); - immediate.endBatch(); - setZ(z); - matrices.popPose(); - } - - if (containsChecked(mouseX, mouseY, false) && ClientHelper.getInstance().isCheating() && !(Minecraft.getInstance().screen instanceof DisplayScreen) && !minecraft.player.containerMenu.getCarried().isEmpty() && ClientHelperImpl.getInstance().canDeleteItems()) { - EntryStack stack = EntryStacks.of(minecraft.player.containerMenu.getCarried().copy()); - if (stack.getType() != VanillaEntryTypes.ITEM) { - EntryStack cheatsAs = stack.cheatsAs(); - stack = cheatsAs.isEmpty() ? stack : cheatsAs; - } - for (Widget child : children()) { - if (child.containsMouse(mouseX, mouseY) && child instanceof EntryWidget widget) { - if (widget.cancelDeleteItems(stack)) { - return; - } - } - } - Tooltip.create(new TranslatableComponent("text.rei.delete_items")).queue(); - } - } - - private int getScrollbarMinX() { - if (ConfigObject.getInstance().isLeftHandSidePanel()) - return bounds.x + 1; - return bounds.getMaxX() - 7; - } - - @Override - public boolean mouseDragged(double mouseX, double mouseY, int button, double dx, double dy) { - if (hasSpace() && scrolling.mouseDragged(mouseX, mouseY, button, dx, dy, ConfigObject.getInstance().doesSnapToRows(), entrySize())) - return true; - return super.mouseDragged(mouseX, mouseY, button, dx, dy); - } - - private void updatePosition(float delta) { - // TODO: Snap to rows -// if (ConfigObject.getInstance().doesSnapToRows() && scrolling.scrollTarget() >= 0 && scrolling.scrollTarget() <= scrolling.getMaxScroll()) { -// double nearestRow = Math.round(scrolling.scrollTarget() / (double) entrySize()) * (double) entrySize(); -// if (!DynamicNewSmoothScrollingEntryListWidget.Precision.almostEquals(scrolling.scrollTarget(), nearestRow, DynamicNewSmoothScrollingEntryListWidget.Precision.FLOAT_EPSILON)) -// scrolling.scrollTarget += (nearestRow - scrolling.scrollTarget()) * Math.min(delta / 2.0, 1.0); -// else -// scrolling.scrollTarget = nearestRow; -// } - scrolling.updatePosition(delta); - } - - @Override - public boolean keyPressed(int keyCode, int scanCode, int modifiers) { - if (containsChecked(PointHelper.ofMouse(), false)) - for (Widget widget : widgets) - if (widget.keyPressed(keyCode, scanCode, modifiers)) - return true; - return false; - } - - public void updateArea(Rectangle bounds, String searchTerm) { - this.bounds = REIRuntime.getInstance().calculateEntryListArea(bounds); - FavoritesListWidget favoritesListWidget = ScreenOverlayImpl.getFavoritesListWidget(); - if (favoritesListWidget != null) { - favoritesListWidget.updateFavoritesBounds(searchTerm); - } - if (allStacks == null || (ConfigObject.getInstance().isFavoritesEnabled() && favoritesListWidget == null)) { - updateSearch(searchTerm, true); - } else { - updateEntriesPosition(); - } - } - - public boolean hasSpace() { - int entrySize = entrySize(); - int width = innerBounds.width / entrySize; - int height = innerBounds.height / entrySize; - return width * height > 0; - } - - public void updateEntriesPosition() { - int entrySize = entrySize(); - boolean focusModeZoomed = ConfigObject.getInstance().isFocusModeZoomed(); - this.innerBounds = updateInnerBounds(bounds); - if (!ConfigObject.getInstance().isEntryListWidgetScrolled()) { - this.renders = Lists.newArrayList(); - page = Math.max(page, 0); - List entries = Lists.newArrayList(); - int width = innerBounds.width / entrySize; - int height = innerBounds.height / entrySize; - for (int currentY = 0; currentY < height; currentY++) { - for (int currentX = 0; currentX < width; currentX++) { - int slotX = currentX * entrySize + innerBounds.x; - int slotY = currentY * entrySize + innerBounds.y; - if (notSteppingOnExclusionZones(slotX - 1, slotY - 1, entrySize, entrySize, innerBounds)) { - entries.add((EntryListEntry) new EntryListEntry(slotX, slotY, entrySize, focusModeZoomed).noBackground()); - } - } - } - page = Math.max(Math.min(page, getTotalPages() - 1), 0); - List> subList = allStacks.stream().skip(Math.max(0, page * entries.size())).limit(Math.max(0, entries.size() - Math.max(0, -page * entries.size()))).collect(Collectors.toList()); - for (int i = 0; i < subList.size(); i++) { - EntryStack stack = subList.get(i); - entries.get(i + Math.max(0, -page * entries.size())).clearStacks().entry(stack); - } - this.entries = entries; - this.widgets = Lists.newArrayList(renders); - this.widgets.addAll(entries); - } else { - page = 0; - int width = innerBounds.width / entrySize; - int pageHeight = innerBounds.height / entrySize; - int slotsToPrepare = Math.max(allStacks.size() * 3, width * pageHeight * 3); - int currentX = 0; - int currentY = 0; - List entries = Lists.newArrayList(); - for (int i = 0; i < slotsToPrepare; i++) { - int xPos = currentX * entrySize + innerBounds.x; - int yPos = currentY * entrySize + innerBounds.y; - entries.add((EntryListEntry) new EntryListEntry(xPos, yPos, entrySize, focusModeZoomed).noBackground()); - currentX++; - if (currentX >= width) { - currentX = 0; -