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/main/java/me/shedaniel/rei/plugin | |
| 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/main/java/me/shedaniel/rei/plugin')
3 files changed, 72 insertions, 233 deletions
diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java index 703e8dabc..fd10e33bb 100644 --- a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java +++ b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java @@ -31,6 +31,7 @@ import me.shedaniel.math.Rectangle; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.*; import me.shedaniel.rei.api.plugins.REIPluginV0; +import me.shedaniel.rei.api.subsets.SubsetsRegistry; import me.shedaniel.rei.api.widgets.Panel; import me.shedaniel.rei.api.widgets.Tooltip; import me.shedaniel.rei.gui.RecipeViewingScreen; @@ -171,7 +172,7 @@ public class DefaultPlugin implements REIPluginV0 { @Override public boolean isEmpty() { - return !((ClientHelperImpl) ClientHelper.getInstance()).ok.get(); + return !((ClientHelperImpl) ClientHelper.getInstance()).isAprilFools.get(); } @Override @@ -296,22 +297,6 @@ public class DefaultPlugin implements REIPluginV0 { return Collections.emptyList(); return Collections.singletonList(widget.getBounds().clone()); }); -// displayHelper.registerHandler(new OverlayDecider() { -// @Override -// public boolean isHandingScreen(Class<?> screen) { -// return InventoryScreen.class.isAssignableFrom(screen); -// } -// -// @Override -// public ActionResult shouldScreenBeOverlayed(Class<?> screen) { -// return isHandingScreen(screen) ? ActionResult.FAIL : ActionResult.PASS; -// } -// -// @Override -// public float getPriority() { -// return 10f; -// } -// }); displayHelper.registerHandler(new DisplayHelper.DisplayBoundsHandler<HandledScreen<?>>() { @Override public Class<?> getBaseSupportedClass() { @@ -404,6 +389,9 @@ public class DefaultPlugin implements REIPluginV0 { recipeHelper.registerScreenClickArea(new Rectangle(78, 32, 28, 23), FurnaceScreen.class, SMELTING); recipeHelper.registerScreenClickArea(new Rectangle(78, 32, 28, 23), SmokerScreen.class, SMOKING); recipeHelper.registerScreenClickArea(new Rectangle(78, 32, 28, 23), BlastFurnaceScreen.class, BLASTING); +// SubsetsRegistry subsetsRegistry = SubsetsRegistry.INSTANCE; +// subsetsRegistry.registerPathEntry("roughlyenoughitems:food", EntryStack.create(Items.MILK_BUCKET)); +// subsetsRegistry.registerPathEntry("roughlyenoughitems:food/roughlyenoughitems:cookies", EntryStack.create(Items.COOKIE)); } @Override diff --git a/src/main/java/me/shedaniel/rei/plugin/beacon/DefaultBeaconBaseCategory.java b/src/main/java/me/shedaniel/rei/plugin/beacon/DefaultBeaconBaseCategory.java index 9f7d3d0df..9434d0971 100644 --- a/src/main/java/me/shedaniel/rei/plugin/beacon/DefaultBeaconBaseCategory.java +++ b/src/main/java/me/shedaniel/rei/plugin/beacon/DefaultBeaconBaseCategory.java @@ -24,18 +24,16 @@ package me.shedaniel.rei.plugin.beacon; import com.google.common.collect.Lists; -import com.mojang.blaze3d.systems.RenderSystem; import me.shedaniel.clothconfig2.ClothConfigInitializer; import me.shedaniel.clothconfig2.api.ScissorsHandler; -import me.shedaniel.clothconfig2.gui.widget.DynamicEntryListWidget; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; -import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.api.EntryStack; import me.shedaniel.rei.api.RecipeCategory; import me.shedaniel.rei.api.widgets.Slot; 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.Widget; import me.shedaniel.rei.gui.widget.WidgetWithBounds; import me.shedaniel.rei.plugin.DefaultPlugin; @@ -43,9 +41,6 @@ import me.shedaniel.rei.utils.CollectionUtils; import net.minecraft.block.Blocks; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.Element; -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.util.Identifier; import net.minecraft.util.math.MathHelper; @@ -109,10 +104,18 @@ public class DefaultBeaconBaseCategory implements RecipeCategory<DefaultBeaconBa private static class ScrollableSlotsWidget extends WidgetWithBounds { private Rectangle bounds; private List<Slot> widgets; - private double target; - private double scroll; - private long start; - private long duration; + private final ScrollingContainer scrolling = new ScrollingContainer() { + @Override + public Rectangle getBounds() { + Rectangle bounds = ScrollableSlotsWidget.this.getBounds(); + return new Rectangle(bounds.x + 1, bounds.y + 1, bounds.width - 2, bounds.height - 2); + } + + @Override + public int getMaxScrollHeight() { + return MathHelper.ceil(widgets.size() / 8f) * 18; + } + }; public ScrollableSlotsWidget(Rectangle bounds, List<Slot> widgets) { this.bounds = Objects.requireNonNull(bounds); @@ -122,56 +125,36 @@ public class DefaultBeaconBaseCategory implements RecipeCategory<DefaultBeaconBa @Override public boolean mouseScrolled(double double_1, double double_2, double double_3) { if (containsMouse(double_1, double_2)) { - offset(ClothConfigInitializer.getScrollStep() * -double_3, true); + scrolling.offset(ClothConfigInitializer.getScrollStep() * -double_3, true); return true; } return false; } - 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 = clamp(value); - - if (animated) { - start = System.currentTimeMillis(); - this.duration = duration; - } else - scroll = target; - } - - public final double clamp(double v) { - return clamp(v, DynamicEntryListWidget.SmoothScrollingSettings.CLAMP_EXTENSION); - } - - public final double clamp(double v, double clampExtension) { - return MathHelper.clamp(v, -clampExtension, getMaxScroll() + clampExtension); - } - - protected int getMaxScroll() { - return Math.max(0, this.getMaxScrollPosition() - this.getBounds().height + 1); + @NotNull + @Override + public Rectangle getBounds() { + return bounds; } - protected int getMaxScrollPosition() { - return MathHelper.ceil(widgets.size() / 8f) * 18; + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + if (scrolling.updateDraggingState(mouseX, mouseY, button)) + return true; + return super.mouseClicked(mouseX, mouseY, button); } - @NotNull @Override - public Rectangle getBounds() { - return bounds; + public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { + if (scrolling.mouseDragged(mouseX, mouseY, button, deltaX, deltaY)) + return true; + return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); } @Override public void render(int mouseX, int mouseY, float delta) { - updatePosition(delta); - Rectangle innerBounds = new Rectangle(bounds.x + 1, bounds.y + 1, bounds.width - 7, bounds.height - 2); + scrolling.updatePosition(delta); + Rectangle innerBounds = scrolling.getScissorBounds(); ScissorsHandler.INSTANCE.scissor(innerBounds); for (int y = 0; y < MathHelper.ceil(widgets.size() / 8f); y++) { for (int x = 0; x < 8; x++) { @@ -179,75 +162,16 @@ public class DefaultBeaconBaseCategory implements RecipeCategory<DefaultBeaconBa if (widgets.size() <= index) break; Slot widget = widgets.get(index); - widget.getBounds().setLocation(bounds.x + 1 + x * 18, (int) (bounds.y + 1 + y * 18 - scroll)); + widget.getBounds().setLocation(bounds.x + 1 + x * 18, (int) (bounds.y + 1 + y * 18 - scrolling.scrollAmount)); widget.render(mouseX, mouseY, delta); } } ScissorsHandler.INSTANCE.removeLastScissor(); - ScissorsHandler.INSTANCE.scissor(bounds); - RenderSystem.enableBlend(); - RenderSystem.blendFuncSeparate(770, 771, 0, 1); - RenderSystem.disableAlphaTest(); - RenderSystem.shadeModel(7425); - RenderSystem.disableTexture(); - renderScrollBar(); - RenderSystem.enableTexture(); - RenderSystem.shadeModel(7424); - RenderSystem.enableAlphaTest(); - RenderSystem.disableBlend(); + ScissorsHandler.INSTANCE.scissor(scrolling.getBounds()); + scrolling.renderScrollBar(0xff000000, 1); ScissorsHandler.INSTANCE.removeLastScissor(); } - @SuppressWarnings("deprecation") - private void renderScrollBar() { - int maxScroll = getMaxScroll(); - int scrollbarPositionMinX = getBounds().getMaxX() - 7; - int scrollbarPositionMaxX = scrollbarPositionMinX + 6; - Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder buffer = tessellator.getBuffer(); - if (maxScroll > 0) { - int height = (int) (((this.getBounds().height - 2f) * (this.getBounds().height - 2f)) / this.getMaxScrollPosition()); - height = MathHelper.clamp(height, 32, this.getBounds().height - 2); - height -= Math.min((scroll < 0 ? (int) -scroll : scroll > maxScroll ? (int) scroll - maxScroll : 0), height * .95); - height = Math.max(10, height); - int minY = Math.min(Math.max((int) scroll * (this.getBounds().height - 2 - height) / maxScroll + getBounds().y + 1, getBounds().y + 1), getBounds().getMaxY() - 1 - height); - - boolean hovered = new Rectangle(scrollbarPositionMinX, minY, scrollbarPositionMaxX - scrollbarPositionMinX, height).contains(PointHelper.ofMouse()); - int bottomC = hovered ? 168 : 128; - int topC = hovered ? 222 : 172; - - // Black Bar - buffer.begin(7, VertexFormats.POSITION_TEXTURE_COLOR); - buffer.vertex(scrollbarPositionMinX, this.getBounds().y + 1, 0.0D).texture(0, 1).color(0, 0, 0, 255).next(); - buffer.vertex(scrollbarPositionMaxX, this.getBounds().y + 1, 0.0D).texture(1, 1).color(0, 0, 0, 255).next(); - buffer.vertex(scrollbarPositionMaxX, getBounds().getMaxY() - 1, 0.0D).texture(1, 0).color(0, 0, 0, 255).next(); - buffer.vertex(scrollbarPositionMinX, getBounds().getMaxY() - 1, 0.0D).texture(0, 0).color(0, 0, 0, 255).next(); - tessellator.draw(); - - // Bottom - buffer.begin(7, VertexFormats.POSITION_TEXTURE_COLOR); - buffer.vertex(scrollbarPositionMinX, minY + height, 0.0D).texture(0, 1).color(bottomC, bottomC, bottomC, 255).next(); - buffer.vertex(scrollbarPositionMaxX, minY + height, 0.0D).texture(1, 1).color(bottomC, bottomC, bottomC, 255).next(); - buffer.vertex(scrollbarPositionMaxX, minY, 0.0D).texture(1, 0).color(bottomC, bottomC, bottomC, 255).next(); - buffer.vertex(scrollbarPositionMinX, minY, 0.0D).texture(0, 0).color(bottomC, bottomC, bottomC, 255).next(); - tessellator.draw(); - - // Top - buffer.begin(7, VertexFormats.POSITION_TEXTURE_COLOR); - buffer.vertex(scrollbarPositionMinX, (minY + height - 1), 0.0D).texture(0, 1).color(topC, topC, topC, 255).next(); - buffer.vertex((scrollbarPositionMaxX - 1), (minY + height - 1), 0.0D).texture(1, 1).color(topC, topC, topC, 255).next(); - buffer.vertex((scrollbarPositionMaxX - 1), minY, 0.0D).texture(1, 0).color(topC, topC, topC, 255).next(); - buffer.vertex(scrollbarPositionMinX, minY, 0.0D).texture(0, 0).color(topC, topC, topC, 255).next(); - tessellator.draw(); - } - } - - private void updatePosition(float delta) { - double[] target = new double[]{this.target}; - this.scroll = ClothConfigInitializer.handleScrollingPosition(target, this.scroll, this.getMaxScroll(), delta, this.start, this.duration); - this.target = target[0]; - } - @Override public List<? extends Element> children() { return widgets; diff --git a/src/main/java/me/shedaniel/rei/plugin/information/DefaultInformationCategory.java b/src/main/java/me/shedaniel/rei/plugin/information/DefaultInformationCategory.java index c0bedc509..44c301ca4 100644 --- a/src/main/java/me/shedaniel/rei/plugin/information/DefaultInformationCategory.java +++ b/src/main/java/me/shedaniel/rei/plugin/information/DefaultInformationCategory.java @@ -27,15 +27,14 @@ import com.google.common.collect.Lists; import com.mojang.blaze3d.systems.RenderSystem; import me.shedaniel.clothconfig2.ClothConfigInitializer; import me.shedaniel.clothconfig2.api.ScissorsHandler; -import me.shedaniel.clothconfig2.gui.widget.DynamicEntryListWidget; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; -import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.api.EntryStack; import me.shedaniel.rei.api.REIHelper; import me.shedaniel.rei.api.RecipeCategory; 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.Widget; import me.shedaniel.rei.gui.widget.WidgetWithBounds; import me.shedaniel.rei.impl.RenderingEntry; @@ -51,7 +50,6 @@ import net.minecraft.client.util.Texts; import net.minecraft.client.util.math.Matrix4f; import net.minecraft.text.Text; import net.minecraft.util.Identifier; -import net.minecraft.util.math.MathHelper; import org.jetbrains.annotations.NotNull; import java.util.Collections; @@ -133,10 +131,22 @@ public class DefaultInformationCategory implements RecipeCategory<DefaultInforma private static class ScrollableTextWidget extends WidgetWithBounds { private Rectangle bounds; private List<Text> texts; - private double target; - private double scroll; - private long start; - private long duration; + private final ScrollingContainer scrolling = new ScrollingContainer() { + @Override + public Rectangle getBounds() { + Rectangle bounds = ScrollableTextWidget.this.getBounds(); + return new Rectangle(bounds.x + 1, bounds.y + 1, bounds.width - 2, bounds.height - 2); + } + + @Override + public int getMaxScrollHeight() { + int i = 2; + for (Text entry : texts) { + i += entry == null ? 4 : font.fontHeight; + } + return i; + } + }; public ScrollableTextWidget(Rectangle bounds, List<Text> texts) { this.bounds = Objects.requireNonNull(bounds); @@ -151,48 +161,24 @@ public class DefaultInformationCategory implements RecipeCategory<DefaultInforma @Override public boolean mouseScrolled(double double_1, double double_2, double double_3) { if (containsMouse(double_1, double_2)) { - offset(ClothConfigInitializer.getScrollStep() * -double_3, true); + scrolling.offset(ClothConfigInitializer.getScrollStep() * -double_3, true); return true; } return false; } - - 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 = clamp(value); - - if (animated) { - start = System.currentTimeMillis(); - this.duration = duration; - } else - scroll = target; - } - - public final double clamp(double v) { - return clamp(v, DynamicEntryListWidget.SmoothScrollingSettings.CLAMP_EXTENSION); - } - - public final double clamp(double v, double clampExtension) { - return MathHelper.clamp(v, -clampExtension, getMaxScroll() + clampExtension); - } - - protected int getMaxScroll() { - return Math.max(0, this.getMaxScrollPosition() - this.getBounds().height + 4); + + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + if (scrolling.updateDraggingState(mouseX, mouseY, button)) + return true; + return super.mouseClicked(mouseX, mouseY, button); } - - protected int getMaxScrollPosition() { - int i = 0; - for (Text entry : texts) { - i += entry == null ? 4 : font.fontHeight; - } - return i; + + @Override + public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { + if (scrolling.mouseDragged(mouseX, mouseY, button, deltaX, deltaY)) + return true; + return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); } @NotNull @@ -203,10 +189,10 @@ public class DefaultInformationCategory implements RecipeCategory<DefaultInforma @Override public void render(int mouseX, int mouseY, float delta) { - updatePosition(delta); - Rectangle innerBounds = new Rectangle(bounds.x + 1, bounds.y + 1, bounds.width - 7, bounds.height - 2); + scrolling.updatePosition(delta); + Rectangle innerBounds = scrolling.getScissorBounds(); ScissorsHandler.INSTANCE.scissor(innerBounds); - int currentY = (int) -scroll + innerBounds.y; + int currentY = (int) -scrolling.scrollAmount + innerBounds.y; for (Text text : texts) { if (text != null && currentY + font.fontHeight >= innerBounds.y && currentY <= innerBounds.getMaxY()) { font.draw(text.asFormattedString(), innerBounds.x + 2, currentY + 2, REIHelper.getInstance().isDarkThemeEnabled() ? 0xFFBBBBBB : 0xFF090909); @@ -214,70 +200,11 @@ public class DefaultInformationCategory implements RecipeCategory<DefaultInforma currentY += text == null ? 4 : font.fontHeight; } ScissorsHandler.INSTANCE.removeLastScissor(); - ScissorsHandler.INSTANCE.scissor(bounds); - RenderSystem.enableBlend(); - RenderSystem.blendFuncSeparate(770, 771, 0, 1); - RenderSystem.disableAlphaTest(); - RenderSystem.shadeModel(7425); - RenderSystem.disableTexture(); - renderScrollBar(); - RenderSystem.enableTexture(); - RenderSystem.shadeModel(7424); - RenderSystem.enableAlphaTest(); - RenderSystem.disableBlend(); + ScissorsHandler.INSTANCE.scissor(scrolling.getBounds()); + scrolling.renderScrollBar(0xff000000, 1); ScissorsHandler.INSTANCE.removeLastScissor(); } - @SuppressWarnings("deprecation") - private void renderScrollBar() { - int maxScroll = getMaxScroll(); - int scrollbarPositionMinX = getBounds().getMaxX() - 7; - int scrollbarPositionMaxX = scrollbarPositionMinX + 6; - Tessellator tessellator = Tessellator.getInstance(); - BufferBuilder buffer = tessellator.getBuffer(); - if (maxScroll > 0) { - int height = (int) (((this.getBounds().height - 2f) * (this.getBounds().height - 2f)) / this.getMaxScrollPosition()); - height = MathHelper.clamp(height, 32, this.getBounds().height - 2); - height -= Math.min((scroll < 0 ? (int) -scroll : scroll > maxScroll ? (int) scroll - maxScroll : 0), height * .95); - height = Math.max(10, height); - int minY = Math.min(Math.max((int) scroll * (this.getBounds().height - 2 - height) / maxScroll + getBounds().y + 1, getBounds().y + 1), getBounds().getMaxY() - 1 - height); - - boolean hovered = new Rectangle(scrollbarPositionMinX, minY, scrollbarPositionMaxX - scrollbarPositionMinX, height).contains(PointHelper.ofMouse()); - int bottomC = hovered ? 168 : 128; - int topC = hovered ? 222 : 172; - - // Black Bar - buffer.begin(7, VertexFormats.POSITION_TEXTURE_COLOR); - buffer.vertex(scrollbarPositionMinX, this.getBounds().y + 1, 0.0D).texture(0, 1).color(0, 0, 0, 255).next(); - buffer.vertex(scrollbarPositionMaxX, this.getBounds().y + 1, 0.0D).texture(1, 1).color(0, 0, 0, 255).next(); - buffer.vertex(scrollbarPositionMaxX, getBounds().getMaxY() - 1, 0.0D).texture(1, 0).color(0, 0, 0, 255).next(); - buffer.vertex(scrollbarPositionMinX, getBounds().getMaxY() - 1, 0.0D).texture(0, 0).color(0, 0, 0, 255).next(); - tessellator.draw(); - - // Bottom - buffer.begin(7, VertexFormats.POSITION_TEXTURE_COLOR); - buffer.vertex(scrollbarPositionMinX, minY + height, 0.0D).texture(0, 1).color(bottomC, bottomC, bottomC, 255).next(); - buffer.vertex(scrollbarPositionMaxX, minY + height, 0.0D).texture(1, 1).color(bottomC, bottomC, bottomC, 255).next(); - buffer.vertex(scrollbarPositionMaxX, minY, 0.0D).texture(1, 0).color(bottomC, bottomC, bottomC, 255).next(); - buffer.vertex(scrollbarPositionMinX, minY, 0.0D).texture(0, 0).color(bottomC, bottomC, bottomC, 255).next(); - tessellator.draw(); - - // Top - buffer.begin(7, VertexFormats.POSITION_TEXTURE_COLOR); - buffer.vertex(scrollbarPositionMinX, (minY + height - 1), 0.0D).texture(0, 1).color(topC, topC, topC, 255).next(); - buffer.vertex((scrollbarPositionMaxX - 1), (minY + height - 1), 0.0D).texture(1, 1).color(topC, topC, topC, 255).next(); - buffer.vertex((scrollbarPositionMaxX - 1), minY, 0.0D).texture(1, 0).color(topC, topC, topC, 255).next(); - buffer.vertex(scrollbarPositionMinX, minY, 0.0D).texture(0, 0).color(topC, topC, topC, 255).next(); - tessellator.draw(); - } - } - - private void updatePosition(float delta) { - double[] target = new double[]{this.target}; - this.scroll = ClothConfigInitializer.handleScrollingPosition(target, this.scroll, this.getMaxScroll(), delta, this.start, this.duration); - this.target = target[0]; - } - @Override public List<? extends Element> children() { return Collections.emptyList(); |
