aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2022-06-19 03:34:00 +0800
committershedaniel <daniel@shedaniel.me>2022-06-19 03:34:00 +0800
commit0113979945feb54c5f23218fe5cb1283e9f47d4b (patch)
treec59b4de9f29ec86fcbbdcf7b9dddaff0b1d1316c
parenta3bc9909f1f78e7872094b7a415fb6c1af51a3dc (diff)
downloadRoughlyEnoughItems-0113979945feb54c5f23218fe5cb1283e9f47d4b.tar.gz
RoughlyEnoughItems-0113979945feb54c5f23218fe5cb1283e9f47d4b.tar.bz2
RoughlyEnoughItems-0113979945feb54c5f23218fe5cb1283e9f47d4b.zip
Refactor EntryListWidget into two classes
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java76
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListWidget.java216
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/PaginatedEntryListWidget.java123
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/ScrolledEntryListWidget.java164
4 files changed, 354 insertions, 225 deletions
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 fe21077a9..2784fd5d1 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
@@ -72,6 +72,8 @@ import me.shedaniel.rei.impl.client.gui.widget.InternalWidgets;
import me.shedaniel.rei.impl.client.gui.widget.LateRenderable;
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.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 me.shedaniel.rei.impl.common.util.Weather;
@@ -108,7 +110,7 @@ public class ScreenOverlayImpl extends ScreenOverlay {
private static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("roughlyenoughitems", "textures/gui/recipecontainer.png");
private static final List<Tooltip> TOOLTIPS = Lists.newArrayList();
private static final List<Runnable> AFTER_RENDER = Lists.newArrayList();
- private static final EntryListWidget ENTRY_LIST_WIDGET = new EntryListWidget();
+ private static EntryListWidget entryListWidget = null;
private static FavoritesListWidget favoritesListWidget = null;
private final List<Widget> widgets = Lists.newLinkedList();
public boolean shouldReload = false;
@@ -127,7 +129,25 @@ public class ScreenOverlayImpl extends ScreenOverlay {
public static EntryListWidget getEntryListWidget() {
- return ENTRY_LIST_WIDGET;
+ if (entryListWidget != null) {
+ if (ConfigObject.getInstance().isEntryListWidgetScrolled() && entryListWidget instanceof ScrolledEntryListWidget) {
+ return entryListWidget;
+ } else if (!ConfigObject.getInstance().isEntryListWidgetScrolled() && entryListWidget instanceof PaginatedEntryListWidget) {
+ return entryListWidget;
+ }
+ }
+
+ if (ConfigObject.getInstance().isEntryListWidgetScrolled()) {
+ entryListWidget = new ScrolledEntryListWidget();
+ } else if (!ConfigObject.getInstance().isEntryListWidgetScrolled()) {
+ entryListWidget = new PaginatedEntryListWidget();
+ }
+
+ Rectangle overlayBounds = ScreenOverlayImpl.getInstance().bounds;
+ entryListWidget.updateArea(Objects.requireNonNullElse(overlayBounds, new Rectangle()), REIRuntimeImpl.getSearchField() == null ? "" : REIRuntimeImpl.getSearchField().getText());
+ entryListWidget.updateEntriesPosition();
+
+ return entryListWidget;
}
@Nullable
@@ -252,18 +272,18 @@ public class ScreenOverlayImpl extends ScreenOverlay {
favoritesListWidget.favoritePanel.resetRows();
widgets.add(favoritesListWidget);
}
- ENTRY_LIST_WIDGET.updateArea(this.bounds, REIRuntimeImpl.getSearchField() == null ? "" : REIRuntimeImpl.getSearchField().getText());
- widgets.add(ENTRY_LIST_WIDGET);
+ getEntryListWidget().updateArea(this.bounds, REIRuntimeImpl.getSearchField() == null ? "" : REIRuntimeImpl.getSearchField().getText());
+ widgets.add(getEntryListWidget());
REIRuntimeImpl.getSearchField().getBounds().setBounds(getSearchFieldArea());
this.widgets.add(REIRuntimeImpl.getSearchField());
- REIRuntimeImpl.getSearchField().setResponder(s -> ENTRY_LIST_WIDGET.updateSearch(s, false));
+ REIRuntimeImpl.getSearchField().setResponder(s -> getEntryListWidget().updateSearch(s, false));
if (!ConfigObject.getInstance().isEntryListWidgetScrolled()) {
widgets.add(leftButton = Widgets.createButton(new Rectangle(bounds.x, bounds.y + (ConfigObject.getInstance().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 5, 16, 16), new TranslatableComponent("text.rei.left_arrow"))
.onClick(button -> {
- ENTRY_LIST_WIDGET.previousPage();
- if (ENTRY_LIST_WIDGET.getPage() < 0)
- ENTRY_LIST_WIDGET.setPage(ENTRY_LIST_WIDGET.getTotalPages() - 1);
- ENTRY_LIST_WIDGET.updateEntriesPosition();
+ getEntryListWidget().previousPage();
+ if (getEntryListWidget().getPage() < 0)
+ getEntryListWidget().setPage(getEntryListWidget().getTotalPages() - 1);
+ getEntryListWidget().updateEntriesPosition();
})
.containsMousePredicate((button, point) -> button.getBounds().contains(point) && isNotInExclusionZones(point.x, point.y))
.tooltipLine(new TranslatableComponent("text.rei.previous_page"))
@@ -288,10 +308,10 @@ public class ScreenOverlayImpl extends ScreenOverlay {
}));
widgets.add(rightButton = Widgets.createButton(new Rectangle(bounds.x + bounds.width - 18, bounds.y + (ConfigObject.getInstance().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 5, 16, 16), new TranslatableComponent("text.rei.right_arrow"))
.onClick(button -> {
- ENTRY_LIST_WIDGET.nextPage();
- if (ENTRY_LIST_WIDGET.getPage() >= ENTRY_LIST_WIDGET.getTotalPages())
- ENTRY_LIST_WIDGET.setPage(0);
- ENTRY_LIST_WIDGET.updateEntriesPosition();
+ getEntryListWidget().nextPage();
+ if (getEntryListWidget().getPage() >= getEntryListWidget().getTotalPages())
+ getEntryListWidget().setPage(0);
+ getEntryListWidget().updateEntriesPosition();
})
.containsMousePredicate((button, point) -> button.getBounds().contains(point) && isNotInExclusionZones(point.x, point.y))
.tooltipLine(new TranslatableComponent("text.rei.next_page"))
@@ -355,17 +375,17 @@ public class ScreenOverlayImpl extends ScreenOverlay {
if (!ConfigObject.getInstance().isEntryListWidgetScrolled()) {
widgets.add(Widgets.createClickableLabel(new Point(bounds.x + ((bounds.width - 18) / 2), bounds.y + (ConfigObject.getInstance().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 10), NarratorChatListener.NO_TITLE, label -> {
if (!Screen.hasShiftDown()) {
- ENTRY_LIST_WIDGET.setPage(0);
- ENTRY_LIST_WIDGET.updateEntriesPosition();
+ getEntryListWidget().setPage(0);
+ getEntryListWidget().updateEntriesPosition();
} else {
ScreenOverlayImpl.getInstance().choosePageWidget = new DefaultDisplayChoosePageWidget(page -> {
- ENTRY_LIST_WIDGET.setPage(page);
- ENTRY_LIST_WIDGET.updateEntriesPosition();
- }, ENTRY_LIST_WIDGET.getPage(), ENTRY_LIST_WIDGET.getTotalPages());
+ getEntryListWidget().setPage(page);
+ getEntryListWidget().updateEntriesPosition();
+ }, getEntryListWidget().getPage(), getEntryListWidget().getTotalPages());
}
}).tooltip(new TranslatableComponent("text.rei.go_back_first_page"), new TextComponent(" "), new TranslatableComponent("text.rei.shift_click_to", new TranslatableComponent("text.rei.choose_page")).withStyle(ChatFormatting.GRAY)).focusable(false).onRender((matrices, label) -> {
- label.setClickable(ENTRY_LIST_WIDGET.getTotalPages() > 1);
- label.setMessage(new TextComponent(String.format("%s/%s", ENTRY_LIST_WIDGET.getPage() + 1, Math.max(ENTRY_LIST_WIDGET.getTotalPages(), 1))));
+ label.setClickable(getEntryListWidget().getTotalPages() > 1);
+ label.setMessage(new TextComponent(String.format("%s/%s", getEntryListWidget().getPage() + 1, Math.max(getEntryListWidget().getTotalPages(), 1))));
}).rainbow(new Random().nextFloat() < 1.0E-4D || ClientHelperImpl.getInstance().isAprilFools.get()));
}
if (ConfigObject.getInstance().isCraftableFilterEnabled()) {
@@ -377,7 +397,7 @@ public class ScreenOverlayImpl extends ScreenOverlay {
.focusable(false)
.onClick(button -> {
ConfigManager.getInstance().toggleCraftableOnly();
- ENTRY_LIST_WIDGET.updateSearch(REIRuntimeImpl.getSearchField().getText(), true);
+ getEntryListWidget().updateSearch(REIRuntimeImpl.getSearchField().getText(), true);
})
.onRender((matrices, button) -> button.setTint(ConfigManager.getInstance().isCraftableOnlyEnabled() ? 939579655 : 956235776))
.containsMousePredicate((button, point) -> button.getBounds().contains(point) && isNotInExclusionZones(point.x, point.y))
@@ -593,7 +613,7 @@ public class ScreenOverlayImpl extends ScreenOverlay {
public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
if (shouldReload || !calculateOverlayBounds().equals(bounds)) {
init();
- ENTRY_LIST_WIDGET.updateSearch(REIRuntimeImpl.getSearchField().getText(), true);
+ getEntryListWidget().updateSearch(REIRuntimeImpl.getSearchField().getText(), true);
} else {
for (OverlayDecider decider : ScreenRegistry.getInstance().getDeciders(minecraft.screen)) {
if (decider != null && decider.shouldRecalculateArea(ConfigObject.getInstance().getDisplayPanelLocation(), bounds)) {
@@ -604,7 +624,7 @@ public class ScreenOverlayImpl extends ScreenOverlay {
}
if (shouldReloadSearch || (ConfigManager.getInstance().isCraftableOnlyEnabled() && CraftableFilter.INSTANCE.wasDirty())) {
shouldReloadSearch = false;
- ENTRY_LIST_WIDGET.updateSearch(REIRuntimeImpl.getSearchField().getText(), true);
+ getEntryListWidget().updateSearch(REIRuntimeImpl.getSearchField().getText(), true);
}
if (OverlaySearchField.isHighlighting) {
RenderSystem.disableDepthTest();
@@ -732,8 +752,8 @@ public class ScreenOverlayImpl extends ScreenOverlay {
if (!REIRuntime.getInstance().isOverlayVisible())
return;
if (!ConfigObject.getInstance().isEntryListWidgetScrolled()) {
- leftButton.setEnabled(ENTRY_LIST_WIDGET.getTotalPages() > 1);
- rightButton.setEnabled(ENTRY_LIST_WIDGET.getTotalPages() > 1);
+ leftButton.setEnabled(getEntryListWidget().getTotalPages() > 1);
+ rightButton.setEnabled(getEntryListWidget().getTotalPages() > 1);
}
for (Widget widget : widgets) {
if (!(widget instanceof LateRenderable))
@@ -748,7 +768,7 @@ public class ScreenOverlayImpl extends ScreenOverlay {
if (overlayMenu != null && overlayMenu.wrappedMenu.mouseScrolled(mouseX, mouseY, amount))
return true;
if (isInside(PointHelper.ofMouse())) {
- if (ENTRY_LIST_WIDGET.mouseScrolled(mouseX, mouseY, amount)) {
+ if (getEntryListWidget().mouseScrolled(mouseX, mouseY, amount)) {
return true;
}
if (!Screen.hasControlDown() && !ConfigObject.getInstance().isEntryListWidgetScrolled()) {
@@ -766,7 +786,7 @@ public class ScreenOverlayImpl extends ScreenOverlay {
return true;
}
for (Widget widget : widgets)
- if (widget != ENTRY_LIST_WIDGET && (favoritesListWidget == null || widget != favoritesListWidget)
+ if (widget != getEntryListWidget() && (favoritesListWidget == null || widget != favoritesListWidget)
&& (overlayMenu == null || widget != overlayMenu.wrappedMenu)
&& widget.mouseScrolled(mouseX, mouseY, amount))
return true;
@@ -978,7 +998,7 @@ public class ScreenOverlayImpl extends ScreenOverlay {
@Override
public OverlayListWidget getEntryList() {
- return ENTRY_LIST_WIDGET;
+ return getEntryListWidget();
}
@Override
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListWidget.java
index e52ca1cb8..ad6b38e4b 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListWidget.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListWidget.java
@@ -23,37 +23,27 @@
package me.shedaniel.rei.impl.client.gui.widget.entrylist;
-import com.google.common.base.Predicates;
-import com.google.common.collect.Lists;
-import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
-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.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.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.TooltipContext;
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.screen.OverlayDecider;
import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry;
-import me.shedaniel.rei.api.client.util.ClientEntryStacks;
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;
@@ -61,8 +51,6 @@ 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.gui.widget.BatchedEntryRendererManager;
-import me.shedaniel.rei.impl.client.gui.widget.CachedEntryListRender;
import me.shedaniel.rei.impl.client.gui.widget.EntryWidget;
import me.shedaniel.rei.impl.client.gui.widget.favorites.FavoritesListWidget;
import me.shedaniel.rei.impl.client.gui.widget.region.RegionRenderingDebugger;
@@ -75,35 +63,19 @@ import net.minecraft.util.Mth;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.ApiStatus;
-import org.jetbrains.annotations.Nullable;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
+@SuppressWarnings("UnstableApiUsage")
@ApiStatus.Internal
-public class EntryListWidget extends WidgetWithBounds implements OverlayListWidget, DraggableStackVisitorWidget {
+public abstract class EntryListWidget extends WidgetWithBounds implements OverlayListWidget, DraggableStackVisitorWidget {
private static final int SIZE = 18;
- private 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 final RegionRenderingDebugger debugger = new RegionRenderingDebugger();
- private Rectangle bounds, innerBounds;
- private List<EntryStack<?>> allStacks = null;
- private List<EntryListStackEntry> entries = Collections.emptyList();
- private List<Widget> renders = Collections.emptyList();
- private List<Widget> children = Collections.emptyList();
+ protected final RegionRenderingDebugger debugger = new RegionRenderingDebugger();
+ protected Rectangle bounds, innerBounds;
+ protected List<EntryStack<?>> allStacks = Collections.emptyList();
+ protected List<EntryListStackEntry> entries = Collections.emptyList();
public final NumberAnimator<Double> scaleIndicator = ValueAnimator.ofDouble(0.0D)
.withConvention(() -> 0.0D, 8000);
@@ -209,11 +181,9 @@ public class EntryListWidget extends WidgetWithBounds implements OverlayListWidg
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);
}
@@ -222,99 +192,26 @@ public class EntryListWidget extends WidgetWithBounds implements OverlayListWidg
return bounds;
}
- public int getPage() {
- return page;
- }
+ public abstract int getPage();
- public void setPage(int page) {
- this.page = page;
- }
+ public abstract void setPage(int page);
public void previousPage() {
- page--;
+ setPage(getPage() - 1);
}
public void nextPage() {
- page++;
+ setPage(getPage() + 1);
}
- public int getTotalPages() {
- if (ConfigObject.getInstance().isEntryListWidgetScrolled())
- return 1;
- return Mth.ceil(allStacks.size() / (float) entries.size());
- }
+ public abstract int getTotalPages();
@Override
public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
if (!hasSpace()) return;
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++) {
- EntryListStackEntry 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)) {
- EntryStack<?> stack = allStacks.get(i++);
- entry.clearStacks();
- if (!stack.isEmpty()) {
- entry.entry(stack);
- helper.add(entry);
- }
- } else {
- blockedCount++;
- }
- }
-
- helper.render(debugger.debugTime, debugger.size, debugger.time, matrices, mouseX, mouseY, delta);
-
- scrolling.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 (EntryListStackEntry entry : entries) {
- if (entry.our == null) {
- CachedEntryListRender.Sprite sprite = CachedEntryListRender.get(entry.getCurrentEntry());
- if (sprite != null) {
- entry.our = ClientEntryStacks.setRenderer(entry.getCurrentEntry().copy().cast(), stack -> new EntryRenderer<Object>() {
- @Override
- public void render(EntryStack<Object> 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<Object> entry, TooltipContext context) {
- return stack.getDefinition().getRenderer().getTooltip(entry.cast(), context);
- }
- });
- }
- }
- }
-
- BatchedEntryRendererManager.renderSlow(debugger.debugTime, debugger.size, debugger.time, matrices, mouseX, mouseY, delta, entries);
- } else {
- new BatchedEntryRendererManager(entries).render(debugger.debugTime, debugger.size, debugger.time, matrices, mouseX, mouseY, delta);
- }
- }
+ renderEntries(fastEntryRendering, matrices, mouseX, mouseY, delta);
debugger.render(matrices, bounds.x, bounds.y, delta);
@@ -345,17 +242,12 @@ public class EntryListWidget extends WidgetWithBounds implements OverlayListWidg
}
}
- @Override
- public boolean mouseDragged(double mouseX, double mouseY, int button, double dx, double dy) {
- if (hasSpace() && scrolling.mouseDragged(mouseX, mouseY, button, dx, dy))
- return true;
- return super.mouseDragged(mouseX, mouseY, button, dx, dy);
- }
+ protected abstract void renderEntries(boolean fastEntryRendering, PoseStack matrices, int mouseX, int mouseY, float delta);
@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (containsChecked(mouse(), false))
- for (Widget widget : children)
+ for (Widget widget : entries)
if (widget.keyPressed(keyCode, scanCode, modifiers))
return true;
return false;
@@ -385,11 +277,7 @@ public class EntryListWidget extends WidgetWithBounds implements OverlayListWidg
int entrySize = entrySize();
boolean zoomed = ConfigObject.getInstance().isFocusModeZoomed();
this.innerBounds = updateInnerBounds(bounds);
- if (ConfigObject.getInstance().isEntryListWidgetScrolled()) {
- updateScrolledEntries(entrySize, zoomed);
- } else {
- updatePaginatedEntries(entrySize, zoomed);
- }
+ updateEntries(entrySize, zoomed);
FavoritesListWidget favoritesListWidget = ScreenOverlayImpl.getFavoritesListWidget();
if (favoritesListWidget != null) {
favoritesListWidget.getSystemRegion().updateEntriesPosition(entry -> true);
@@ -397,54 +285,7 @@ public class EntryListWidget extends WidgetWithBounds implements OverlayListWidg
}
}
- private void updateScrolledEntries(int entrySize, boolean zoomed) {
- 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<EntryListStackEntry> entries = Lists.newArrayList();
- for (int i = 0; i < slotsToPrepare; i++) {
- int xPos = currentX * entrySize + innerBounds.x;
- int yPos = currentY * entrySize + innerBounds.y;
- entries.add((EntryListStackEntry) new EntryListStackEntry(this, xPos, yPos, entrySize, zoomed).noBackground());
- currentX++;
- if (currentX >= width) {
- currentX = 0;
- currentY++;
- }
- }
- this.entries = entries;
- this.children = Lists.newArrayList(renders);
- this.children.addAll(entries);
- }
-
- private void updatePaginatedEntries(int entrySize, boolean zoomed) {
- this.renders = Lists.newArrayList();
- page = Math.max(page, 0);
- List<EntryListStackEntry> 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)) {
- entries.add((EntryListStackEntry) new EntryListStackEntry(this, slotX, slotY, entrySize, zoomed).noBackground());
- }
- }
- }
- page = Math.max(Math.min(page, getTotalPages() - 1), 0);
- List<EntryStack<?>> 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.children = Lists.newArrayList(renders);
- this.children.addAll(entries);
- }
+ protected abstract void updateEntries(int entrySize, boolean zoomed);
@ApiStatus.Internal
public List<EntryStack<?>> getAllStacks() {
@@ -465,16 +306,12 @@ public class EntryListWidget extends WidgetWithBounds implements OverlayListWidg
@Override
public List<? extends Widget> children() {
- return children;
+ return entries;
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (!hasSpace()) return false;
- if (ConfigObject.getInstance().isEntryListWidgetScrolled()) {
- if (scrolling.updateDraggingState(mouseX, mouseY, button))
- return true;
- }
for (Widget widget : children())
if (widget.mouseClicked(mouseX, mouseY, button))
return true;
@@ -527,19 +364,4 @@ public class EntryListWidget extends WidgetWithBounds implements OverlayListWidg
}
return EntryStack.empty();
}
-
- @Override
- public Stream<EntryStack<?>> getEntries() {
- if (ConfigObject.getInstance().isEntryListWidgetScrolled()) {
- int skip = Math.max(0, Mth.floor(scrolling.scrollAmount() / (float) entrySize()));
- int nextIndex = skip * innerBounds.width / entrySize();
- return (Stream<EntryStack<?>>) (Stream<? extends EntryStack<?>>) entries.stream()
- .skip(nextIndex)
- .filter(entry -> entry.getBounds().y <= this.bounds.getMaxY())
- .map(EntryWidget::getCurrentEntry)
- .filter(Predicates.not(EntryStack::isEmpty));
- } else {
- return entries.stream().map(EntryWidget::getCurrentEntry);
- }
- }
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/PaginatedEntryListWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/PaginatedEntryListWidget.java
new file mode 100644
index 000000000..2f0329149
--- /dev/null
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/PaginatedEntryListWidget.java
@@ -0,0 +1,123 @@
+/*
+ * 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.entrylist;
+
+import com.google.common.collect.Lists;
+import com.mojang.blaze3d.systems.RenderSystem;
+import com.mojang.blaze3d.vertex.PoseStack;
+import me.shedaniel.math.Rectangle;
+import me.shedaniel.rei.api.client.config.ConfigObject;
+import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer;
+import me.shedaniel.rei.api.client.gui.widgets.Tooltip;
+import me.shedaniel.rei.api.client.gui.widgets.TooltipContext;
+import me.shedaniel.rei.api.client.gui.widgets.Widget;
+import me.shedaniel.rei.api.client.util.ClientEntryStacks;
+import me.shedaniel.rei.api.common.entry.EntryStack;
+import me.shedaniel.rei.impl.client.gui.widget.BatchedEntryRendererManager;
+import me.shedaniel.rei.impl.client.gui.widget.CachedEntryListRender;
+import me.shedaniel.rei.impl.client.gui.widget.EntryWidget;
+import net.minecraft.util.Mth;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class PaginatedEntryListWidget extends EntryListWidget {
+ private int page;
+
+ @Override
+ public int getPage() {
+ return page;
+ }
+
+ @Override
+ public void setPage(int page) {
+ this.page = page;
+ }
+
+ @Override
+ protected void renderEntries(boolean fastEntryRendering, PoseStack matrices, int mouseX, int mouseY, float delta) {
+ if (ConfigObject.getInstance().doesCacheEntryRendering()) {
+ for (EntryListStackEntry entry : entries) {
+ if (entry.our == null) {
+ CachedEntryListRender.Sprite sprite = CachedEntryListRender.get(entry.getCurrentEntry());
+ if (sprite != null) {
+ entry.our = ClientEntryStacks.setRenderer(entry.getCurrentEntry().copy().cast(), stack -> new EntryRenderer<Object>() {
+ @Override
+ public void render(EntryStack<Object> 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<Object> entry, TooltipContext context) {
+ return stack.getDefinition().getRenderer().getTooltip(entry.cast(), context);
+ }
+ });
+ }
+ }
+ }
+
+ BatchedEntryRendererManager.renderSlow(debugger.debugTime, debugger.size, debugger.time, matrices, mouseX, mouseY, delta, entries);
+ } else {
+ new BatchedEntryRendererManager(entries).render(debugger.debugTime, debugger.size, debugger.time, matrices, mouseX, mouseY, delta);
+ }
+ }
+
+ @Override
+ public int getTotalPages() {
+ return Mth.ceil(allStacks.size() / (float) entries.size());
+ }
+
+ @Override
+ protected void updateEntries(int entrySize, boolean zoomed) {
+ page = Math.max(page, 0);
+ List<EntryListStackEntry> 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)) {
+ entries.add((EntryListStackEntry) new EntryListStackEntry(this, slotX, slotY, entrySize, zoomed).noBackground());
+ }
+ }
+ }
+ page = Math.max(Math.min(page, getTotalPages() - 1), 0);
+ List<EntryStack<?>> 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;
+ }
+
+ @Override
+ public Stream<EntryStack<?>> getEntries() {
+ return entries.stream().map(EntryWidget::getCurrentEntry);
+ }
+}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/ScrolledEntryListWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/ScrolledEntryListWidget.java
new file mode 100644
index 000000000..2e4cd8b20
--- /dev/null
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/ScrolledEntryListWidget.java
@@ -0,0 +1,164 @@
+/*
+ * 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.entrylist;
+
+import com.google.common.base.Predicates;
+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.Rectangle;
+import me.shedaniel.rei.api.client.REIRuntime;
+import me.shedaniel.rei.api.common.entry.EntryStack;
+import me.shedaniel.rei.impl.client.gui.widget.BatchedEntryRendererManager;
+import me.shedaniel.rei.impl.client.gui.widget.EntryWidget;
+import net.minecraft.client.gui.screens.Screen;
+import net.minecraft.util.Mth;
+
+import java.util.List;