diff options
| author | shedaniel <daniel@shedaniel.me> | 2020-04-01 20:01:34 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2020-04-01 20:01:34 +0800 |
| commit | 66abc317e5fc36a397ca1cc919e388fbe143956b (patch) | |
| tree | 915cc4799d89297b8d4bd2dbe1046c177f4d1627 /src | |
| parent | 3919ec1e15d6eb9a8aa4564bb2d4e4dfdbeb54e3 (diff) | |
| download | RoughlyEnoughItems-66abc317e5fc36a397ca1cc919e388fbe143956b.tar.gz RoughlyEnoughItems-66abc317e5fc36a397ca1cc919e388fbe143956b.tar.bz2 RoughlyEnoughItems-66abc317e5fc36a397ca1cc919e388fbe143956b.zip | |
ScrollingContainer & SubsetsMenu && 20w18b
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'src')
26 files changed, 1329 insertions, 789 deletions
diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index 617f246b0..34ada2efb 100644 --- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -63,10 +63,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.ApiStatus; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -81,6 +78,8 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { private static final Map<Identifier, REIPluginEntry> plugins = Maps.newHashMap(); private static final ExecutorService SYNC_RECIPES = Executors.newSingleThreadScheduledExecutor(r -> new Thread(r, "REI-SyncRecipes")); private static ConfigManager configManager; + @ApiStatus.Experimental + public static boolean isLeftModePressed = false; @ApiStatus.Internal public static RecipeHelper getRecipeHelper() { @@ -248,12 +247,15 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { } private boolean shouldReturn(Class<?> screen) { - for (OverlayDecider decider : DisplayHelper.getInstance().getAllOverlayDeciders()) { - if (!decider.isHandingScreen(screen)) - continue; - ActionResult result = decider.shouldScreenBeOverlayed(screen); - if (result != ActionResult.PASS) - return result == ActionResult.FAIL || ScreenHelper.getLastHandledScreen() == null; + try { + for (OverlayDecider decider : DisplayHelper.getInstance().getAllOverlayDeciders()) { + if (!decider.isHandingScreen(screen)) + continue; + ActionResult result = decider.shouldScreenBeOverlayed(screen); + if (result != ActionResult.PASS) + return result == ActionResult.FAIL || ScreenHelper.getLastHandledScreen() == null; + } + } catch (ConcurrentModificationException ignored) { } return true; } @@ -298,6 +300,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { return ActionResult.PASS; }); ClothClientHooks.SCREEN_MOUSE_CLICKED.register((minecraftClient, screen, v, v1, i) -> { + isLeftModePressed = true; if (screen instanceof CreativeInventoryScreen) if (ScreenHelper.isOverlayVisible() && ScreenHelper.getLastOverlay().mouseClicked(v, v1, i)) { screen.setFocused(ScreenHelper.getLastOverlay()); @@ -307,6 +310,10 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { } return ActionResult.PASS; }); + ClothClientHooks.SCREEN_MOUSE_RELEASED.register((minecraftClient, screen, v, v1, i) -> { + isLeftModePressed = false; + return ActionResult.PASS; + }); ClothClientHooks.SCREEN_MOUSE_SCROLLED.register((minecraftClient, screen, v, v1, v2) -> { if (shouldReturn(screen.getClass())) return ActionResult.PASS; diff --git a/src/main/java/me/shedaniel/rei/api/ConfigObject.java b/src/main/java/me/shedaniel/rei/api/ConfigObject.java index 5070d2da0..08a70ab04 100644 --- a/src/main/java/me/shedaniel/rei/api/ConfigObject.java +++ b/src/main/java/me/shedaniel/rei/api/ConfigObject.java @@ -152,4 +152,7 @@ public interface ConfigObject { @ApiStatus.Experimental boolean doDebugSearchTimeRequired(); + + @ApiStatus.Experimental + boolean isSubsetsEnabled(); } diff --git a/src/main/java/me/shedaniel/rei/api/subsets/SubsetsRegistry.java b/src/main/java/me/shedaniel/rei/api/subsets/SubsetsRegistry.java new file mode 100644 index 000000000..3c7e46304 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/subsets/SubsetsRegistry.java @@ -0,0 +1,40 @@ +package me.shedaniel.rei.api.subsets; + +import me.shedaniel.rei.api.EntryStack; +import me.shedaniel.rei.impl.subsets.SubsetsRegistryImpl; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Set; + +@ApiStatus.Experimental +public interface SubsetsRegistry { + SubsetsRegistry INSTANCE = new SubsetsRegistryImpl(); + + /** + * Gets all paths an entry is in, note that this is a really slow call as it looks through all paths. + */ + @NotNull + List<String> getEntryPaths(@NotNull EntryStack stack); + + @Nullable + Set<EntryStack> getPathEntries(@NotNull String path); + + @NotNull + Set<EntryStack> getOrCreatePathEntries(@NotNull String path); + + @NotNull + Set<String> getPaths(); + + void registerPathEntry(@NotNull String path, @NotNull EntryStack stack); + + void registerPathEntries(@NotNull String path, @NotNull Collection<EntryStack> stacks); + + default void registerPathEntries(@NotNull String path, @NotNull EntryStack... stacks) { + registerPathEntries(path, Arrays.asList(stacks)); + } +} diff --git a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java index 82bd199e5..fc7f8f950 100644 --- a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java +++ b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java @@ -34,7 +34,9 @@ import me.shedaniel.rei.api.widgets.Button; import me.shedaniel.rei.api.widgets.Tooltip; import me.shedaniel.rei.api.widgets.Widgets; import me.shedaniel.rei.gui.config.SearchFieldLocation; +import me.shedaniel.rei.gui.subsets.SubsetsMenu; import me.shedaniel.rei.gui.widget.*; +import me.shedaniel.rei.impl.ClientHelperImpl; import me.shedaniel.rei.impl.InternalWidgets; import me.shedaniel.rei.impl.ScreenHelper; import me.shedaniel.rei.impl.Weather; @@ -110,8 +112,13 @@ public class ContainerScreenOverlay extends WidgetWithBounds { }; private Rectangle bounds; private Window window; - private List<LateRenderable> lateRenderables = Lists.newArrayList(); private Button leftButton, rightButton; + @ApiStatus.Experimental + private Rectangle subsetsButtonBounds; + @ApiStatus.Experimental + @Nullable + private SubsetsMenu subsetsMenu = null; + private Widget wrappedSubsetsMenu = null; public static EntryListWidget getEntryListWidget() { return ENTRY_LIST_WIDGET; @@ -122,6 +129,12 @@ public class ContainerScreenOverlay extends WidgetWithBounds { return favoritesListWidget; } + @ApiStatus.Experimental + @Nullable + public SubsetsMenu getSubsetsMenu() { + return subsetsMenu; + } + public void init(boolean useless) { init(); } @@ -130,6 +143,8 @@ public class ContainerScreenOverlay extends WidgetWithBounds { this.shouldReInit = false; //Update Variables this.children().clear(); + this.wrappedSubsetsMenu = null; + this.subsetsMenu = null; this.window = MinecraftClient.getInstance().getWindow(); @SuppressWarnings({"RawTypeCanBeGeneric", "rawtypes"}) DisplayHelper.DisplayBoundsHandler boundsHandler = DisplayHelper.getInstance().getResponsibleBoundsHandler(MinecraftClient.getInstance().currentScreen.getClass()); @@ -171,8 +186,8 @@ public class ContainerScreenOverlay extends WidgetWithBounds { } final Rectangle configButtonArea = getConfigButtonArea(); - LateRenderable tmp; - widgets.add((Widget) (tmp = InternalWidgets.wrapLateRenderable(InternalWidgets.mergeWidgets( + Widget tmp; + widgets.add(tmp = InternalWidgets.wrapLateRenderable(InternalWidgets.mergeWidgets( Widgets.createButton(configButtonArea, NarratorManager.EMPTY) .onClick(button -> { if (Screen.hasShiftDown()) { @@ -209,17 +224,8 @@ public class ContainerScreenOverlay extends WidgetWithBounds { helper.drawTexture(configButtonArea.x + 3, configButtonArea.y + 3, 0, 0, 14, 14); }) ) - ))); - ((Widget) tmp).setZ(600); - lateRenderables.add(tmp); -// widgets.add((Widget) (tmp = InternalWidgets.wrapLateRenderable(Widgets.createTexturedWidget(CHEST_GUI_TEXTURE, configButtonArea.x + 3, configButtonArea.y + 3, 0, 0, 14, 14)))); -// widgets.add((Widget) (tmp = InternalWidgets.wrapLateRenderable(Widgets.createDrawableWidget((helper, mouseX, mouseY, delta) -> { -// RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); -// MinecraftClient.getInstance().getTextureManager().bindTexture(CHEST_GUI_TEXTURE); -// helper.blit(configButtonArea.x + 3, configButtonArea.y + 3, 0, 0, 14, 14); -// })))); -// ((Widget) tmp).setZ(600); -// lateRenderables.add(tmp); + )); + tmp.setZ(600); if (ConfigObject.getInstance().doesShowUtilsButtons()) { widgets.add(Widgets.createButton(ConfigObject.getInstance().isLowerConfigButton() ? new Rectangle(ConfigObject.getInstance().isLeftHandSidePanel() ? window.getScaledWidth() - 30 : 10, 10, 20, 20) : new Rectangle(ConfigObject.getInstance().isLeftHandSidePanel() ? window.getScaledWidth() - 55 : 35, 10, 20, 20), NarratorManager.EMPTY) .onClick(button -> MinecraftClient.getInstance().player.sendChatMessage(ConfigObject.getInstance().getGamemodeCommand().replaceAll("\\{gamemode}", getNextGameMode(Screen.hasShiftDown()).getName()))) @@ -243,6 +249,20 @@ public class ContainerScreenOverlay extends WidgetWithBounds { xxx += ConfigObject.getInstance().isLeftHandSidePanel() ? -25 : 25; } } + subsetsButtonBounds = getSubsetsButtonBounds(); + if (ConfigObject.getInstance().isSubsetsEnabled()) { + widgets.add(InternalWidgets.wrapLateRenderable(Widgets.createButton(subsetsButtonBounds, ((ClientHelperImpl) ClientHelper.getInstance()).isAprilFools.get() ? I18n.translate("text.rei.tiny_potato") : I18n.translate("text.rei.subsets")) + .onClick(button -> { + if (subsetsMenu == null) { + wrappedSubsetsMenu = InternalWidgets.wrapTranslate(InternalWidgets.wrapLateRenderable(this.subsetsMenu = SubsetsMenu.createFromRegistry(new Point(this.subsetsButtonBounds.x, this.subsetsButtonBounds.getMaxY()))), 0, 0, 400); + this.widgets.add(this.wrappedSubsetsMenu); + } else { + this.widgets.remove(this.wrappedSubsetsMenu); + this.subsetsMenu = null; + this.wrappedSubsetsMenu = null; + } + }))); + } if (!ConfigObject.getInstance().isEntryListWidgetScrolled()) { widgets.add(Widgets.createClickableLabel(new Point(bounds.x + (bounds.width / 2), bounds.y + (ConfigObject.getInstance().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 10), "", label -> { ENTRY_LIST_WIDGET.setPage(0); @@ -256,7 +276,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds { Rectangle area = getCraftableToggleArea(); ItemRenderer itemRenderer = MinecraftClient.getInstance().getItemRenderer(); ItemStack icon = new ItemStack(Blocks.CRAFTING_TABLE); - this.widgets.add((Widget) (tmp = InternalWidgets.wrapLateRenderable(InternalWidgets.mergeWidgets( + this.widgets.add(tmp = InternalWidgets.wrapLateRenderable(InternalWidgets.mergeWidgets( Widgets.createButton(area, NarratorManager.EMPTY) .focusable(false) .onClick(button -> { @@ -271,12 +291,27 @@ public class ContainerScreenOverlay extends WidgetWithBounds { itemRenderer.renderGuiItemIcon(icon, area.x + 2, area.y + 2); itemRenderer.zOffset = 0.0F; })) - ))); - ((Widget) tmp).setZ(600); - lateRenderables.add(tmp); + )); + tmp.setZ(600); } } + @ApiStatus.Experimental + private Rectangle getSubsetsButtonBounds() { + if (ConfigObject.getInstance().isSubsetsEnabled()) { + if (MinecraftClient.getInstance().currentScreen instanceof RecipeViewingScreen) { + RecipeViewingScreen widget = (RecipeViewingScreen) MinecraftClient.getInstance().currentScreen; + return new Rectangle(widget.getBounds().x, 3, widget.getBounds().width, 18); + } + if (MinecraftClient.getInstance().currentScreen instanceof VillagerRecipeViewingScreen) { + VillagerRecipeViewingScreen widget = (VillagerRecipeViewingScreen) MinecraftClient.getInstance().currentScreen; + return new Rectangle(widget.bounds.x, 3, widget.bounds.width, 18); + } + return new Rectangle(((ContainerScreenHooks) ScreenHelper.getLastHandledScreen()).rei_getContainerLeft(), 3, ((ContainerScreenHooks) ScreenHelper.getLastHandledScreen()).rei_getContainerWidth(), 18); + } + return null; + } + private Weather getNextWeather() { try { Weather current = getCurrentWeather(); @@ -417,10 +452,15 @@ public class ContainerScreenOverlay extends WidgetWithBounds { public void lateRender(int mouseX, int mouseY, float delta) { if (ScreenHelper.isOverlayVisible()) { ScreenHelper.getSearchField().laterRender(mouseX, mouseY, delta); - for (LateRenderable lateRenderable : lateRenderables) { - lateRenderable.lateRender(mouseX, mouseY, delta); + for (Widget widget : widgets) { + if (widget instanceof LateRenderable && wrappedSubsetsMenu != widget) + widget.render(mouseX, mouseY, delta); } } + if (wrappedSubsetsMenu != null) { + TOOLTIPS.clear(); + wrappedSubsetsMenu.render(mouseX, mouseY, delta); + } Screen currentScreen = MinecraftClient.getInstance().currentScreen; if (!(currentScreen instanceof RecipeViewingScreen) || !((RecipeViewingScreen) currentScreen).choosePageActivated) for (Tooltip tooltip : TOOLTIPS) { @@ -462,7 +502,8 @@ public class ContainerScreenOverlay extends WidgetWithBounds { rightButton.setEnabled(ENTRY_LIST_WIDGET.getTotalPages() > 1); } for (Widget widget : widgets) { - widget.render(int_1, int_2, float_1); + if (!(widget instanceof LateRenderable)) + widget.render(int_1, int_2, float_1); } } @@ -470,6 +511,8 @@ public class ContainerScreenOverlay extends WidgetWithBounds { public boolean mouseScrolled(double i, double j, double amount) { if (!ScreenHelper.isOverlayVisible()) return false; + if (wrappedSubsetsMenu != null && wrappedSubsetsMenu.mouseScrolled(i, j, amount)) + return true; if (isInside(PointHelper.ofMouse())) { if (!ConfigObject.getInstance().isEntryListWidgetScrolled()) { if (amount > 0 && leftButton.isEnabled()) @@ -487,7 +530,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds { return true; } for (Widget widget : widgets) - if (widget != ENTRY_LIST_WIDGET && (favoritesListWidget == null || widget != favoritesListWidget) && widget.mouseScrolled(i, j, amount)) + if (widget != ENTRY_LIST_WIDGET && (favoritesListWidget == null || widget != favoritesListWidget) && (wrappedSubsetsMenu == null || widget != wrappedSubsetsMenu) && widget.mouseScrolled(i, j, amount)) return true; return false; } @@ -540,7 +583,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds { } @Override - public List<? extends Element> children() { + public List<Widget> children() { return widgets; } @@ -548,6 +591,13 @@ public class ContainerScreenOverlay extends WidgetWithBounds { public boolean mouseClicked(double double_1, double double_2, int int_1) { if (!ScreenHelper.isOverlayVisible()) return false; + if (wrappedSubsetsMenu != null && wrappedSubsetsMenu.mouseClicked(double_1, double_2, int_1)) { + this.setFocused(wrappedSubsetsMenu); + if (int_1 == 0) + this.setDragging(true); + ScreenHelper.getSearchField().setFocused(false); + return true; + } if (MinecraftClient.getInstance().currentScreen instanceof HandledScreen && ConfigObject.getInstance().areClickableRecipeArrowsEnabled()) { ContainerScreenHooks hooks = (ContainerScreenHooks) MinecraftClient.getInstance().currentScreen; for (RecipeHelper.ScreenClickArea area : RecipeHelper.getInstance().getScreenClickAreas()) @@ -559,7 +609,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds { } } for (Element element : widgets) - if (element.mouseClicked(double_1, double_2, int_1)) { + if (element != wrappedSubsetsMenu && element.mouseClicked(double_1, double_2, int_1)) { this.setFocused(element); if (int_1 == 0) this.setDragging(true); diff --git a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java index b6f28ee09..6c5e91278 100644 --- a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java @@ -35,6 +35,7 @@ import me.shedaniel.rei.api.widgets.Button; import me.shedaniel.rei.api.widgets.Tooltip; import me.shedaniel.rei.api.widgets.Widgets; import me.shedaniel.rei.gui.entries.RecipeEntry; +import me.shedaniel.rei.gui.widget.ScrollingContainer; import me.shedaniel.rei.gui.widget.TabWidget; import me.shedaniel.rei.gui.widget.Widget; import me.shedaniel.rei.impl.ClientHelperImpl; @@ -44,9 +45,6 @@ import me.shedaniel.rei.utils.CollectionUtils; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.Element; import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.render.BufferBuilder; -import net.minecraft.client.render.Tessellator; -import net.minecraft.client.render.VertexFormats; import net.minecraft.client.resource.language.I18n; import net.minecraft.client.sound.PositionedSoundInstance; import net.minecraft.client.util.NarratorManager; @@ -76,14 +74,24 @@ public class VillagerRecipeViewingScreen extends Screen implements RecipeScreen private int tabsPerPage = 8; private int selectedCategoryIndex = 0; private int selectedRecipeIndex = 0; - private double scrollAmount = 0; - private double target; - private long start; - private long duration; + private final ScrollingContainer scrolling = new ScrollingContainer() { + @Override + public Rectangle getBounds() { + return new Rectangle(scrollListBounds.x + 1, scrollListBounds.y + 1, scrollListBounds.width - 2, scrollListBounds.height - 2); + } + + @Override + public int getMaxScrollHeight() { + int i = 0; + for (Button button : buttonList) { + i += button.getBounds().height; + } + return i; + } + }; private float scrollBarAlpha = 0; private float scrollBarAlphaFuture = 0; private long scrollBarAlphaFutureTime = -1; - private boolean draggingScrollBar = false; private int tabsPage = -1; private EntryStack ingredientStackToNotice = EntryStack.empty(); private EntryStack resultStackToNotice = EntryStack.empty(); @@ -132,7 +140,7 @@ public class VillagerRecipeViewingScreen extends Screen implements RecipeScreen super.init(); boolean isCompactTabs = ConfigObject.getInstance().isUsingCompactTabs(); int tabSize = isCompactTabs ? 24 : 28; - this.draggingScrollBar = false; + scrolling.draggingScrollBar = false; this.children.clear(); this.widgets.clear(); this.buttonList.clear(); @@ -246,23 +254,12 @@ public class VillagerRecipeViewingScreen extends Screen implements RecipeScreen ScreenHelper.getLastOverlay().init(); } - private double getMaxScroll() { - return Math.max(0, this.getMaxScrollPosition() - (scrollListBounds.height - 2)); - } - @Override public boolean mouseClicked(double mouseX, double mouseY, int int_1) { - double height = getMaxScrollPosition(); - int actualHeight = scrollListBounds.height - 2; - if (height > actualHeight && scrollBarAlpha > 0 && mouseY >= scrollListBounds.y + 1 && mouseY <= scrollListBounds.getMaxY() - 1) { - double scrollbarPositionMinX = scrollListBounds.getMaxX() - 6; - if (mouseX >= scrollbarPositionMinX & mouseX <= scrollbarPositionMinX + 8) { - this.draggingScrollBar = true; - scrollBarAlpha = 1; - return false; - } + if (scrolling.updateDraggingState(mouseX, mouseY, int_1)) { + scrollBarAlpha = 1; + return true; } - this.draggingScrollBar = false; return super.mouseClicked(mouseX, mouseY, int_1); } @@ -274,29 +271,11 @@ public class VillagerRecipeViewingScreen extends Screen implements RecipeScreen return super.charTyped(char_1, int_1); } - public void offset(double value, boolean animated) { - scrollTo(target + value, animated); - } - - public void scrollTo(double value, boolean animated) { - scrollTo(value, animated, ClothConfigInitializer.getScrollDuration()); - } - - public void scrollTo(double value, boolean animated, long duration) { - target = ClothConfigInitializer.clamp(value, getMaxScroll()); - - if (animated) { - start = System.currentTimeMillis(); - this.duration = duration; - } else - scrollAmount = target; - } - @Override public boolean mouseScrolled(double double_1, double double_2, double double_3) { - double height = CollectionUtils.sumInt(buttonList, b -> b.getBounds().getHeight()); + double height = scrolling.getMaxScrollHeight(); if (scrollListBounds.contains(double_1, double_2) && height > scrollListBounds.height - 2) { - offset(ClothConfigInitializer.getScrollStep() * -double_3, true); + scrolling.offset(ClothConfigInitializer.getScrollStep() * -double_3, true); if (scrollBarAlphaFuture == 0) scrollBarAlphaFuture = 1f; if (System.currentTimeMillis() - scrollBarAlphaFutureTime > 300f) @@ -323,10 +302,6 @@ public class VillagerRecipeViewingScreen extends Screen implements RecipeScreen return super.mouseScrolled(double_1, double_2, double_3); } - private double getMaxScrollPosition() { - return CollectionUtils.sumInt(buttonList, b -> b.getBounds().getHeight()); - } - @Override public void render(int mouseX, int mouseY, float delta) { if (ConfigObject.getInstance().doesVillagerScreenHavePermanentScrollBar()) { @@ -351,7 +326,7 @@ public class VillagerRecipeViewingScreen extends Screen implements RecipeScreen scrollBarAlpha = Math.max(Math.min(1f, l / 300f), scrollBarAlpha); } } - updatePosition(delta); + scrolling.updatePosition(delta); this.fillGradient(0, 0, this.width, this.height, -1072689136, -804253680); int yOffset = 0; for (Widget widget : widgets) { @@ -359,9 +334,9 @@ public class VillagerRecipeViewingScreen extends Screen implements RecipeScreen } ScreenHelper.getLastOverlay().render(mouseX, mouseY, delta); RenderSystem.pushMatrix(); - ScissorsHandler.INSTANCE.scissor(new Rectangle(0, scrollListBounds.y + 1, width, scrollListBounds.height - 2)); + ScissorsHandler.INSTANCE.scissor(scrolling.getBounds()); for (Button button : buttonList) { - button.getBounds().y = scrollListBounds.y + 1 + yOffset - (int) scrollAmount; + button.getBounds().y = scrollListBounds.y + 1 + yOffset - (int) scrolling.scrollAmount; if (button.getBounds().getMaxY() > scrollListBounds.getMinY() && button.getBounds().getMinY() < scrollListBounds.getMaxY()) { button.render(mouseX, mouseY, delta); } @@ -374,65 +349,18 @@ public class VillagerRecipeViewingScreen extends Screen implements RecipeScreen Optional.ofNullable(recipeRenderers.get(i).getTooltip(new Point(mouseX, mouseY))).ifPresent(Tooltip::queue); } } - double maxScroll = getMaxScrollPosition(); - if (maxScroll > scrollListBounds.height - 2) { - Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder buffer = tessellator.getBuffer(); - int height = (int) (((scrollListBounds.height - 2) * (scrollListBounds.height - 2)) / this.getMaxScrollPosition()); - height = MathHelper.clamp(height, 32, scrollListBounds.height - 2 - 8); - height -= Math.min((scrollAmount < 0 ? (int) -scrollAmount : scrollAmount > getMaxScroll() ? (int) scrollAmount - getMaxScroll() : 0), height * .95); - height = Math.max(10, height); - int minY = (int) Math.min(Math.max((int) scrollAmount * (scrollListBounds.height - 2 - height) / getMaxScroll() + scrollListBounds.y + 1, scrollListBounds.y + 1), scrollListBounds.getMaxY() - 1 - height); - int scrollbarPositionMinX = scrollListBounds.getMaxX() - 6, scrollbarPositionMaxX = scrollListBounds.getMaxX() - 1; - boolean hovered = (new Rectangle(scrollbarPositionMinX, minY, scrollbarPositionMaxX - scrollbarPositionMinX, height)).contains(PointHelper.ofMouse()); - float bottomC = (hovered ? .67f : .5f) * (REIHelper.getInstance().isDarkThemeEnabled() ? 0.8f : 1f); - float topC = (hovered ? .87f : .67f) * (REIHelper.getInstance().isDarkThemeEnabled() ? 0.8f : 1f); - RenderSystem.disableTexture(); - RenderSystem.enableBlend(); - RenderSystem.disableAlphaTest(); - RenderSystem.blendFuncSeparate(770, 771, 1, 0); - RenderSystem.shadeModel(7425); - buffer.begin(7, VertexFormats.POSITION_COLOR); - buffer.vertex(scrollbarPositionMinX, minY + height, 800).color(bottomC, bottomC, bottomC, scrollBarAlpha).next(); - buffer.vertex(scrollbarPositionMaxX, minY + height, 800).color(bottomC, bottomC, bottomC, scrollBarAlpha).next(); - buffer.vertex(scrollbarPositionMaxX, minY, 800).color(bottomC, bottomC, bottomC, scrollBarAlpha).next(); - buffer.vertex(scrollbarPositionMinX, minY, 800).color(bottomC, bottomC, bottomC, scrollBarAlpha).next(); - tessellator.draw(); - buffer.begin(7, VertexFormats.POSITION_COLOR); - buffer.vertex(scrollbarPositionMinX, minY + height - 1, 800).color(topC, topC, topC, scrollBarAlpha).next(); - buffer.vertex(scrollbarPositionMaxX - 1, minY + height - 1, 800).color(topC, topC, topC, scrollBarAlpha).next(); - buffer.vertex(scrollbarPositionMaxX - 1, minY, 800).color(topC, topC, topC, scrollBarAlpha).next(); - buffer.vertex(scrollbarPositionMinX, minY, 800).color(topC, topC, topC, scrollBarAlpha).next(); - tessellator.draw(); - RenderSystem.shadeModel(7424); - RenderSystem.disableBlend(); - RenderSystem.enableAlphaTest(); - RenderSystem.enableTexture(); - } + scrolling.renderScrollBar(0, scrollBarAlpha); ScissorsHandler.INSTANCE.removeLastScissor(); RenderSystem.popMatrix(); ScreenHelper.getLastOverlay().lateRender(mouseX, mouseY, delta); } - private void updatePosition(float delta) { - double[] target = new double[]{this.target}; - this.scrollAmount = ClothConfigInitializer.handleScrollingPosition(target, this.scrollAmount, this.getMaxScroll(), delta, this.start, this.duration); - this.target = target[0]; - } - @Override public boolean mouseDragged(double mouseX, double mouseY, int int_1, double double_3, double double_4) { - if (int_1 == 0 && scrollBarAlpha > 0 && draggingScrollBar) { - double height = CollectionUtils.sumInt(buttonList, b -> b.getBounds().getHeight()); - int actualHeight = scrollListBounds.height - 2; |
