aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2021-11-11 01:01:30 +0800
committershedaniel <daniel@shedaniel.me>2021-11-11 01:09:42 +0800
commit57f59e7da8ae83f1ad952e410601409eecf2e1c4 (patch)
tree13770a0c6b3a24b71ab8a575259a3f19a4ef7977 /runtime
parentaba4c079befd4bb32f732b65c746a22559644d35 (diff)
downloadRoughlyEnoughItems-57f59e7da8ae83f1ad952e410601409eecf2e1c4.tar.gz
RoughlyEnoughItems-57f59e7da8ae83f1ad952e410601409eecf2e1c4.tar.bz2
RoughlyEnoughItems-57f59e7da8ae83f1ad952e410601409eecf2e1c4.zip
Add Dispose Here region, introduce ValueAnimator
Diffstat (limited to 'runtime')
-rw-r--r--runtime/build.gradle1
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/dragging/CurrentDraggingStack.java40
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/UncertainDisplayViewingScreen.java5
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryListWidget.java4
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryStacksRegionWidget.java6
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/FavoritesListWidget.java101
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/ButtonWidget.java18
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/FillRectangleDrawableConsumer.java10
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/LabelWidget.java36
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/region/RealRegionEntry.java24
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/region/RegionDraggableStack.java2
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/region/RegionEntryListEntry.java5
-rwxr-xr-xruntime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json1
13 files changed, 153 insertions, 100 deletions
diff --git a/runtime/build.gradle b/runtime/build.gradle
index b77410d22..25b8d9fed 100644
--- a/runtime/build.gradle
+++ b/runtime/build.gradle
@@ -16,6 +16,7 @@ dependencies {
modCompileOnly("net.fabricmc:fabric-loader:${project.fabricloader_version}")
modApi("me.shedaniel.cloth:cloth-config:${cloth_config_version}")
modApi("dev.architectury:architectury:${architectury_version}")
+ compileClasspath(annotationProcessor("org.projectlombok:lombok:1.18.22"))
compileClasspath(project(path: ":api", configuration: "namedElements"))
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/dragging/CurrentDraggingStack.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/dragging/CurrentDraggingStack.java
index 4d8bb74f8..32a2e08a5 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/dragging/CurrentDraggingStack.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/dragging/CurrentDraggingStack.java
@@ -24,13 +24,15 @@
package me.shedaniel.rei.impl.client.gui.dragging;
import com.mojang.blaze3d.vertex.PoseStack;
+import me.shedaniel.math.FloatingRectangle;
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.math.impl.PointHelper;
import me.shedaniel.rei.RoughlyEnoughItemsCoreClient;
+import me.shedaniel.rei.api.client.gui.animator.NumberAnimator;
+import me.shedaniel.rei.api.client.gui.animator.ValueAnimator;
import me.shedaniel.rei.api.client.gui.drag.*;
import me.shedaniel.rei.api.client.gui.widgets.Widget;
-import me.shedaniel.rei.api.common.util.Animator;
import me.shedaniel.rei.impl.client.gui.widget.LateRenderable;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.events.GuiEventListener;
@@ -98,7 +100,7 @@ public class CurrentDraggingStack extends Widget implements LateRenderable, Drag
while (iterator.hasNext()) {
ShapeBounds bounds = iterator.next();
bounds.update(delta);
- if (bounds.alpha.target() == 0 && bounds.alpha.doubleValue() <= 2) {
+ if (bounds.alpha.target() == 0 && bounds.alpha.value() <= 2) {
iterator.remove();
} else {
bounds.shape.forAllBoxes((x1, y1, z1, x2, y2, z2) -> {
@@ -115,12 +117,14 @@ public class CurrentDraggingStack extends Widget implements LateRenderable, Drag
while (iterator.hasNext()) {
RenderBackEntry renderBackEntry = iterator.next();
renderBackEntry.update(delta);
- if (renderBackEntry.width.doubleValue() < 2 || renderBackEntry.height.doubleValue() < 2 || (Math.abs(renderBackEntry.x.doubleValue() - renderBackEntry.x.target()) <= 2 && Math.abs(renderBackEntry.y.doubleValue() - renderBackEntry.y.target()) <= 2 && Math.abs(renderBackEntry.width.doubleValue() - renderBackEntry.width.target()) <= 1 && Math.abs(renderBackEntry.height.doubleValue() - renderBackEntry.height.target()) <= 1)) {
+ FloatingRectangle value = renderBackEntry.bounds.value();
+ FloatingRectangle target = renderBackEntry.bounds.target();
+ if (value.width < 2 || value.height < 2 || (Math.abs(value.x - target.x) <= 2 && Math.abs(value.y - target.y) <= 2 && Math.abs(value.width - target.width) <= 1 && Math.abs(value.height - target.height) <= 1)) {
iterator.remove();
} else {
matrices.pushPose();
matrices.translate(0, 0, 600);
- renderBackEntry.stack.render(matrices, new Rectangle(Math.round(renderBackEntry.x.floatValue()), Math.round(renderBackEntry.y.floatValue()), Math.round(renderBackEntry.width.floatValue()), Math.round(renderBackEntry.height.floatValue())), mouseX, mouseY, delta);
+ renderBackEntry.stack.render(matrices, value.getBounds(), mouseX, mouseY, delta);
matrices.popPose();
}
}
@@ -215,12 +219,12 @@ public class CurrentDraggingStack extends Widget implements LateRenderable, Drag
private static class ShapeBounds {
private VoxelShape shape;
- private Animator alpha;
+ private NumberAnimator<Double> alpha;
private int hash;
public ShapeBounds(VoxelShape shape) {
this.shape = shape;
- this.alpha = new Animator(0);
+ this.alpha = ValueAnimator.ofDouble(0);
this.hash = shape.toAabbs().hashCode();
}
@@ -244,18 +248,12 @@ public class CurrentDraggingStack extends Widget implements LateRenderable, Drag
private static class RenderBackEntry {
private final DraggableStack stack;
private final Supplier<Rectangle> position;
- private Animator x = new Animator();
- private Animator y = new Animator();
- private Animator width = new Animator();
- private Animator height = new Animator();
+ private ValueAnimator<FloatingRectangle> bounds = ValueAnimator.ofFloatingRectangle();
private int lastDestination = -1;
public RenderBackEntry(DraggableStack stack, Rectangle initialPosition, Supplier<Rectangle> position) {
this.stack = stack;
- this.x.setAs(initialPosition.x);
- this.y.setAs(initialPosition.y);
- this.width.setAs(initialPosition.width);
- this.height.setAs(initialPosition.height);
+ this.bounds.setAs(new FloatingRectangle(initialPosition));
this.position = position;
}
@@ -264,18 +262,8 @@ public class CurrentDraggingStack extends Widget implements LateRenderable, Drag
}
public void update(double delta) {
- this.x.update(delta);
- this.y.update(delta);
- this.width.update(delta);
- this.height.update(delta);
- Rectangle position = getPosition();
- if (lastDestination != position.hashCode()) {
- lastDestination = position.hashCode();
- this.x.setTo(position.x, 200);
- this.y.setTo(position.y, 200);
- this.width.setTo(position.width, 200);
- this.height.setTo(position.height, 200);
- }
+ this.bounds.update(delta);
+ this.bounds.setTo(new FloatingRectangle(getPosition()), 200);
}
}
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/UncertainDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/UncertainDisplayViewingScreen.java
index 5f98de662..ed20332c2 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/UncertainDisplayViewingScreen.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/UncertainDisplayViewingScreen.java
@@ -39,12 +39,13 @@ import me.shedaniel.rei.RoughlyEnoughItemsCoreClient;
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.gui.animator.NumberAnimator;
+import me.shedaniel.rei.api.client.gui.animator.ValueAnimator;
import me.shedaniel.rei.api.client.gui.config.DisplayScreenType;
import me.shedaniel.rei.api.client.gui.widgets.Button;
import me.shedaniel.rei.api.client.gui.widgets.Widget;
import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds;
import me.shedaniel.rei.api.client.gui.widgets.Widgets;
-import me.shedaniel.rei.api.common.util.Animator;
import me.shedaniel.rei.api.common.util.ImmutableTextComponent;
import me.shedaniel.rei.impl.ClientInternals;
import me.shedaniel.rei.impl.client.config.ConfigManagerImpl;
@@ -82,7 +83,7 @@ public class UncertainDisplayViewingScreen extends Screen {
private Screen parent;
private Widget slider;
private boolean showTips;
- private Animator scroll = new Animator();
+ public NumberAnimator<Double> scroll = ValueAnimator.ofDouble();
private List<String> allModsUsingJEI = null;
private boolean jeiEnabled = false;
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
index df9f034d4..a41a305a8 100644
--- 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
@@ -191,9 +191,7 @@ public class EntryListWidget extends WidgetWithBounds implements OverlayListWidg
@Override
public DraggedAcceptorResult acceptDraggedStackWithResult(DraggingContext<Screen> context, DraggableStack stack) {
if (innerBounds.contains(context.getCurrentPosition())) {
- Point currentPosition = context.getCurrentPosition();
- Rectangle targetBounds = new Rectangle(currentPosition.x, currentPosition.y, 1, 1);
- context.renderBackToPosition(stack, new Rectangle(currentPosition.x - 8, currentPosition.y - 8, 16, 16), () -> targetBounds);
+ context.renderToVoid(stack);
return DraggedAcceptorResult.CONSUMED;
} else {
return DraggedAcceptorResult.PASS;
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryStacksRegionWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryStacksRegionWidget.java
index 7fdc454f5..c68c7bb46 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryStacksRegionWidget.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryStacksRegionWidget.java
@@ -32,6 +32,7 @@ import me.shedaniel.clothconfig2.ClothConfigInitializer;
import me.shedaniel.clothconfig2.api.ScissorsHandler;
import me.shedaniel.clothconfig2.api.ScrollingContainer;
import me.shedaniel.clothconfig2.gui.widget.DynamicNewSmoothScrollingEntryListWidget;
+import me.shedaniel.math.FloatingPoint;
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.math.impl.PointHelper;
@@ -424,7 +425,7 @@ public class EntryStacksRegionWidget<T extends RegionEntry<T>> extends WidgetWit
public boolean drop(RealRegionEntry<T> entry, double x, double y) {
boolean contains = bounds.contains(x, y);
- int newIndex = contains ? getReleaseIndex(new Point(x, y)) : Math.max(0, Iterables.indexOf(entries.values(), e -> e == entry));
+ int newIndex = contains ? getReleaseIndex(new Point(x, y)) : Math.max(-1, Iterables.indexOf(entries.values(), e -> e == entry));
return drop(entry, x, y, newIndex < 0 ? entries.size() : newIndex);
}
@@ -434,8 +435,7 @@ public class EntryStacksRegionWidget<T extends RegionEntry<T>> extends WidgetWit
return false;
}
- entry.x.setAs(x - 8);
- entry.y.setAs(y - 8);
+ entry.pos.setAs(new FloatingPoint(x - 8, y - 8));
if (entries.size() <= newIndex) {
RealRegionEntry<T> remove = this.entries.remove(entry.hashIgnoreAmount());
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/FavoritesListWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/FavoritesListWidget.java
index d5c16f184..aec7a5950 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/FavoritesListWidget.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/FavoritesListWidget.java
@@ -30,6 +30,7 @@ import me.shedaniel.clothconfig2.ClothConfigInitializer;
import me.shedaniel.clothconfig2.api.LazyResettable;
import me.shedaniel.clothconfig2.api.ScissorsHandler;
import me.shedaniel.clothconfig2.api.ScrollingContainer;
+import me.shedaniel.math.FloatingPoint;
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.math.impl.PointHelper;
@@ -40,9 +41,10 @@ import me.shedaniel.rei.api.client.favorites.FavoriteEntry;
import me.shedaniel.rei.api.client.favorites.FavoriteEntryType;
import me.shedaniel.rei.api.client.favorites.SystemFavoriteEntryProvider;
import me.shedaniel.rei.api.client.gui.AbstractContainerEventHandler;
-import me.shedaniel.rei.api.client.gui.drag.DraggableStack;
-import me.shedaniel.rei.api.client.gui.drag.DraggableStackProviderWidget;
-import me.shedaniel.rei.api.client.gui.drag.DraggingContext;
+import me.shedaniel.rei.api.client.gui.animator.NumberAnimator;
+import me.shedaniel.rei.api.client.gui.animator.ProgressValueAnimator;
+import me.shedaniel.rei.api.client.gui.animator.ValueAnimator;
+import me.shedaniel.rei.api.client.gui.drag.*;
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;
@@ -50,7 +52,6 @@ import me.shedaniel.rei.api.client.overlay.OverlayListWidget;
import me.shedaniel.rei.api.client.overlay.ScreenOverlay;
import me.shedaniel.rei.api.client.util.ClientEntryStacks;
import me.shedaniel.rei.api.common.entry.EntryStack;
-import me.shedaniel.rei.api.common.util.Animator;
import me.shedaniel.rei.api.common.util.CollectionUtils;
import me.shedaniel.rei.api.common.util.ImmutableTextComponent;
import me.shedaniel.rei.impl.client.config.ConfigManagerImpl;
@@ -83,7 +84,7 @@ import static me.shedaniel.rei.impl.client.gui.widget.EntryListWidget.entrySize;
import static me.shedaniel.rei.impl.client.gui.widget.EntryListWidget.notSteppingOnExclusionZones;
@ApiStatus.Internal
-public class FavoritesListWidget extends WidgetWithBounds implements DraggableStackProviderWidget, OverlayListWidget, RegionListener<FavoriteEntry> {
+public class FavoritesListWidget extends WidgetWithBounds implements DraggableStackProviderWidget, DraggableStackVisitorWidget, OverlayListWidget, RegionListener<FavoriteEntry> {
private Rectangle fullBounds;
private EntryStacksRegionWidget<FavoriteEntry> systemRegion = new EntryStacksRegionWidget<>(new RegionListener<FavoriteEntry>() {
@Override
@@ -117,6 +118,13 @@ public class FavoritesListWidget extends WidgetWithBounds implements DraggableSt
private List<FavoriteEntry> lastSystemEntries = new ArrayList<>();
public final AddFavoritePanel favoritePanel = new AddFavoritePanel(this);
+ private final NumberAnimator<Double> trashBoundsHeight = ValueAnimator.ofDouble().withConvention(() -> {
+ if (DraggingContext.getInstance().isDraggingStack() && fullBounds.contains(DraggingContext.getInstance().getCurrentPosition())) {
+ return Math.min(60D, fullBounds.height * 0.15D);
+ }
+ return 0D;
+ }, ValueAnimator.typicalTransitionTime());
+ private final Rectangle trashBounds = new Rectangle();
public final ToggleAddFavoritePanelButton favoritePanelButton = new ToggleAddFavoritePanelButton(this);
private List<Widget> children = ImmutableList.of(favoritePanel, favoritePanelButton, systemRegion, region);
@@ -202,6 +210,19 @@ public class FavoritesListWidget extends WidgetWithBounds implements DraggableSt
}
@Override
+ public DraggedAcceptorResult acceptDraggedStackWithResult(DraggingContext<Screen> context, DraggableStack stack) {
+ if (favoritePanel.bounds.contains(context.getCurrentPosition()) || trashBounds.contains(context.getCurrentPosition())) {
+ context.renderToVoid(stack);
+ return DraggedAcceptorResult.CONSUMED;
+ }
+ return Stream.of(region, systemRegion)
+ .map(visitor -> visitor.acceptDraggedStackWithResult(context, stack))
+ .filter(result -> result != DraggedAcceptorResult.PASS)
+ .findFirst()
+ .orElse(DraggedAcceptorResult.PASS);
+ }
+
+ @Override
public EntryStack<?> getFocusedStack() {
Point mouse = PointHelper.ofMouse();
EntryStack<?> stack = region.getFocusedStack();
@@ -232,6 +253,29 @@ public class FavoritesListWidget extends WidgetWithBounds implements DraggableSt
if (fullBounds.isEmpty())
return;
+ this.trashBoundsHeight.update(delta);
+ double trashBoundsHeight = this.trashBoundsHeight.value();
+ if (trashBoundsHeight > 0) {
+ double trashBoundsHeightTarget = Math.min(150D, fullBounds.height * 0.15D);
+ double progress = Math.pow(Mth.clamp(trashBoundsHeight / trashBoundsHeightTarget, 0, 1), 7);
+ int y = this.fullBounds.getMaxY() - 4 - favoritePanel.getBounds().height;
+ trashBounds.setBounds(this.fullBounds.x + 4, (int) Math.round(y - trashBoundsHeight), this.fullBounds.width - 8, (int) Math.round(trashBoundsHeight - 4));
+ int alpha = 0x12 + (int) (0x22 * progress * (Mth.cos((float) (System.currentTimeMillis() % 2000 / 1000F * Math.PI)) + 1) / 2);
+ fillGradient(matrices, this.trashBounds.x, this.trashBounds.y, this.trashBounds.getMaxX(), this.trashBounds.getMaxY(), 0xFFFFFF | (alpha << 24), 0xFFFFFF | (alpha << 24));
+ int lineColor = (int) (0x60 * progress) << 24 | 0xFFFFFF;
+ fillGradient(matrices, this.trashBounds.x, this.trashBounds.y, this.trashBounds.getMaxX(), this.trashBounds.y + 1, lineColor, lineColor);
+ fillGradient(matrices, this.trashBounds.x, this.trashBounds.getMaxY() - 1, this.trashBounds.getMaxX(), this.trashBounds.getMaxY(), lineColor, lineColor);
+
+ fillGradient(matrices, this.trashBounds.x, this.trashBounds.y + 1, this.trashBounds.x + 1, this.trashBounds.getMaxY() - 1, lineColor, lineColor);
+ fillGradient(matrices, this.trashBounds.getMaxX() - 1, this.trashBounds.y + 1, this.trashBounds.getMaxX(), this.trashBounds.getMaxY() - 1, lineColor, lineColor);
+
+ Component text = new TranslatableComponent("text.rei.dispose_here");
+ if (0xAA * progress > 0x4) {
+ font.draw(matrices, text, this.trashBounds.getCenterX() - font.width(text) / 2, this.trashBounds.getCenterY() - 4F, (int) (0xAA * progress) << 24 | 0xFFFFFF);
+ }
+ } else {
+ trashBounds.setBounds(0, 0, 0, 0);
+ }
updateSystemRegion();
// systemRegion.getBounds().setBounds(this.fullBounds.x + 1, this.fullBounds.y - 1 + 14, this.fullBounds.width - 1, Math.max(1, systemRegion.scrolling.getMaxScrollHeight()));
systemRegion.getBounds().setBounds(this.fullBounds.x, this.fullBounds.y + 1, this.fullBounds.width, Math.max(1, systemRegion.scrolling.getMaxScrollHeight()));
@@ -245,8 +289,9 @@ public class FavoritesListWidget extends WidgetWithBounds implements DraggableSt
systemHeight += 4;
}
if (favoritePanel.getBounds().height > 20)
- region.getBounds().setBounds(this.fullBounds.x, this.fullBounds.y + systemHeight, this.fullBounds.width, this.fullBounds.height - systemHeight - (this.fullBounds.getMaxY() - this.favoritePanel.bounds.y) - 4);
- else region.getBounds().setBounds(this.fullBounds.x, this.fullBounds.y + systemHeight, this.fullBounds.width, this.fullBounds.height - systemHeight);
+ region.getBounds().setBounds(this.fullBounds.x, this.fullBounds.y + systemHeight, this.fullBounds.width, this.fullBounds.height - systemHeight - (this.fullBounds.getMaxY() - this.favoritePanel.bounds.y) - 4 - (trashBoundsHeight <= 0 ? 0 : trashBoundsHeight));
+ else
+ region.getBounds().setBounds(this.fullBounds.x, this.fullBounds.y + systemHeight, this.fullBounds.width, this.fullBounds.height - systemHeight - (trashBoundsHeight <= 0 ? 0 : trashBoundsHeight + 24));
systemRegion.render(matrices, mouseX, mouseY, delta);
region.render(matrices, mouseX, mouseY, delta);
renderAddFavorite(matrices, mouseX, mouseY, delta);
@@ -356,7 +401,7 @@ public class FavoritesListWidget extends WidgetWithBounds implements DraggableSt
@Override
protected void onClick() {
- widget.favoritePanel.expendState.setTo(widget.favoritePanel.expendState.target() == 1 ? 0 : 1, 1500);
+ widget.favoritePanel.expendState.setTo(!widget.favoritePanel.expendState.target(), 1500);
widget.favoritePanel.resetRows();
}
@@ -372,20 +417,20 @@ public class FavoritesListWidget extends WidgetWithBounds implements DraggableSt
@Override
protected boolean isAvailable(int mouseX, int mouseY) {
- float expendProgress = widget.favoritePanel.expendState.floatValue();
- return widget.fullBounds.contains(mouseX, mouseY) || REIRuntime.getInstance().getOverlay().orElseThrow().getEntryList().containsMouse(new Point(mouseX, mouseY)) || expendProgress > .1f;
+ boolean expended = widget.favoritePanel.expendState.value();
+ return widget.fullBounds.contains(mouseX, mouseY) || REIRuntime.getInstance().getOverlay().orElseThrow().getEntryList().containsMouse(new Point(mouseX, mouseY)) || expended;
}
@Override
protected void renderButtonText(PoseStack matrices, MultiBufferSource.BufferSource bufferSource) {
- float expendProgress = widget.favoritePanel.expendState.floatValue();
+ float expendProgress = (float) widget.favoritePanel.expendState.progress();
if (expendProgress < .9f) {
int textColor = 0xFFFFFF | (Math.round(0xFF * alpha.floatValue() * (1 - expendProgress)) << 24);
font.drawInBatch("+", bounds.getCenterX() - 2.5f, bounds.getCenterY() - 3, textColor, false, matrices.last().pose(), bufferSource, false, 0, 15728880);
}
if (expendProgress > .1f) {
int textColor = 0xFFFFFF | (Math.round(0xFF * alpha.floatValue() * expendProgress) << 24);
- font.drawInBatch("-", bounds.getCenterX() - 2.5f, bounds.getCenterY() - 3, textColor, false, matrices.last().pose(), bufferSource, false, 0, 15728880);
+ font.drawInBatch("+", bounds.getCenterX() - 2.5f, bounds.getCenterY() - 3, textColor, false, matrices.last().pose(), bufferSource, false, 0, 15728880);
}
}
}
@@ -393,7 +438,7 @@ public class FavoritesListWidget extends WidgetWithBounds implements DraggableSt
public abstract static class FadingFavoritePanelButton extends WidgetWithBounds {
protected final FavoritesListWidget widget;
public boolean wasClicked = false;
- public final Animator alpha = new Animator(0);
+ public final NumberAnimator<Double> alpha = ValueAnimator.ofDouble(0);
public final Rectangle bounds = new Rectangle();
@@ -469,7 +514,7 @@ public class FavoritesListWidget extends WidgetWithBounds implements DraggableSt
public static class AddFavoritePanel extends WidgetWithBounds {
private final FavoritesListWidget widget;
- public final Animator expendState = new Animator(0);
+ public final ProgressValueAnimator<Boolean> expendState = ValueAnimator.ofBoolean(0.1, false);
private final Rectangle bounds = new Rectangle();
private final Rectangle scrollBounds = new Rectangle();
private final LazyResettable<List<Row>> rows = new LazyResettable<>(() -> {
@@ -507,11 +552,11 @@ public class FavoritesListWidget extends WidgetWithBounds implements DraggableSt
this.bounds.setBounds(updatePanelArea(widget.fullBounds));
this.scrollBounds.setBounds(bounds.x + 4, bounds.y + 4, bounds.width - 8, bounds.height - 20);
this.expendState.update(delta);
- int buttonColor = 0xFFFFFF | (Math.round(0x34 * Math.min(expendState.floatValue() * 2, 1)) << 24);
+ int buttonColor = 0xFFFFFF | (Math.round(0x34 * Math.min((float) expendState.progress() * 2, 1)) << 24);
fillGradient(matrices, bounds.x, bounds.y, bounds.getMaxX(), bounds.getMaxY(), buttonColor, buttonColor);
scroller.updatePosition(delta);
- if (expendState.floatValue() > 0.1f) {
+ if (expendState.progress() > 0.1f) {
ScissorsHandler.INSTANCE.scissor(scrollBounds);
matrices.pushPose();
matrices.translate(0, scroller.scrollAmount, 0);
@@ -526,8 +571,8 @@ public class FavoritesListWidget extends WidgetWithBounds implements DraggableSt
}
private Rectangle updatePanelArea(Rectangle fullArea) {
- int currentWidth = 16 + Math.round(Math.min(expendState.floatValue(), 1) * (fullArea.getWidth() - 16 - 8));
- int currentHeight = 16 + Math.round(expendState.floatValue() * (fullArea.getHeight() * 0.4f - 16 - 8));
+ int currentWidth = 16 + Math.round(Math.min((float) expendState.progress(), 1) * (fullArea.getWidth() - 16 - 8));
+ int currentHeight = 16 + Math.round((float) expendState.progress() * (fullArea.getHeight() * 0.4f - 16 - 8));
return new Rectangle(fullArea.x + 4, fullArea.getMaxY() - currentHeight - 4, currentWidth, currentHeight);
}
@@ -649,9 +694,8 @@ public class FavoritesListWidget extends WidgetWithBounds implements DraggableSt
}
private class SectionFavoriteWidget extends EntryListEntryWidget {
- private Animator x = new Animator();
- private Animator y = new Animator();
- private Animator size = new Animator();
+ private ValueAnimator<FloatingPoint> pos = ValueAnimator.ofFloatingPoint();
+ private NumberAnimator<Double> size = ValueAnimator.ofDouble();
private FavoriteEntry entry;
protected SectionFavoriteWidget(Point point, int entrySize, FavoriteEntry entry) {
@@ -662,23 +706,16 @@ public class FavoritesListWidget extends WidgetWithBounds implements DraggableSt
}
public void moveTo(boolean animated, int xPos, int yPos) {
- if (animated) {
- x.setTo(xPos, 200);
- y.setTo(yPos, 200);
- } else {
- x.setAs(xPos);
- y.setAs(yPos);
- }
+ pos.setTo(new FloatingPoint(xPos, yPos), animated ? 200 : -1);
}
public void update(float delta) {
+ this.pos.update(delta);
this.size.update(delta);
- this.x.update(delta);
- this.y.update(delta);
this.getBounds().width = this.getBounds().height = (int) Math.round(this.size.doubleValue() / 100);
double offsetSize = (entrySize() - this.size.doubleValue() / 100) / 2;
- this.getBounds().x = (int) Math.round(x.doubleValue() + offsetSize);
- this.getBounds().y = (int) Math.round(y.doubleValue() + offsetSize) + lastY;
+ this.getBounds().x = (int) Math.round(pos.value().x + offsetSize);
+ this.getBounds().y = (int) Math.round(pos.value().y + offsetSize) + lastY;
}
@Override
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/ButtonWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/ButtonWidget.java
index f2e60bb88..642930980 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/ButtonWidget.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/ButtonWidget.java
@@ -26,9 +26,11 @@ package me.shedaniel.rei.impl.client.gui.widget.basewidgets;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix4f;
+import me.shedaniel.math.Color;
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.REIRuntime;
+import me.shedaniel.rei.api.client.gui.animator.ValueAnimator;
import me.shedaniel.rei.api.client.gui.widgets.Button;
import me.shedaniel.rei.api.client.gui.widgets.Tooltip;
import net.minecraft.client.gui.GuiComponent;
@@ -68,10 +70,13 @@ public class ButtonWidget extends Button {
private BiFunction<Button, Point, Integer> textColorFunction;
@Nullable
private BiFunction<Button, Point, Integer> textureIdFunction;
+ private final ValueAnimator<Color> darkBackground;
public ButtonWidget(Rectangle rectangle, Component text) {
this.bounds = new Rectangle(Objects.requireNonNull(rectangle));
this.text = Objects.requireNonNull(text);
+ this.darkBackground = ValueAnimator.ofColor()
+ .withConvention(() -> Color.ofTransparent(REIRuntime.getInstance().isDarkThemeEnabled() ? 0xFFFFFFFF : 0x00FFFFFF), ValueAnimator.typicalTransitionTime());
}
@Override
@@ -190,11 +195,13 @@ public class ButtonWidget extends Button {
@Override
public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
+ darkBackground.update(delta);
if (onRender != null) {
onRender.accept(matrices, this);
}
int x = bounds.x, y = bounds.y, width = bounds.width, height = bounds.height;
- renderBackground(matrices, x, y, width, height, this.getTextureId(new Point(mouseX, mouseY)));
+ renderBackground(matrices, x, y, width, height, this.getTextureId(new Point(mouseX, mouseY)), false, Color.ofTransparent(0xFFFFFFFF));
+ renderBackground(matrices, x, y, width, height, this.getTextureId(new Point(mouseX, mouseY)), true, darkBackground.value());
int color = 14737632;
if (!this.enabled) {
@@ -282,8 +289,12 @@ public class ButtonWidget extends Button {
}
protected void renderBackground(PoseStack matrices, int x, int y, int width, int height, int textureOffset) {
- RenderSystem.setShaderTexture(0, REIRuntime.getInstance().isDarkThemeEnabled() ? BUTTON_LOCATION_DARK : BUTTON_LOCATION);
- RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
+ renderBackground(matrices, x, y, width, height, textureOffset, REIRuntime.getInstance().isDarkThemeEnabled(), Color.ofTransparent(0xFFFFFFFF));
+ }
+
+ protected void renderBackground(PoseStack matrices, int x, int y, int width, int height, int textureOffset, boolean dark, Color color) {
+ RenderSystem.setShaderTexture(0, dark ? BUTTON_LOCATION_DARK : BUTTON_LOCATION);
+ RenderSystem.setShaderColor(color.getRed() / 255F, color.getGreen() / 255F, color.getBlue() / 255F, color.getAlpha() / 255F);
RenderSystem.enableBlend();
RenderSystem.blendFuncSeparate(770, 771, 1, 0);
RenderSystem.blendFunc(770, 771);
@@ -305,5 +316,6 @@ public class ButtonWidget extends Button {
// Center
GuiComponent.innerBlit(matrix, x + 8, x + width - 8, y + 8, y + height - 8, getZ(), (8) / 256f, (248) / 256f, (textureOffset * 80 + 8) / 512f, (textureOffset * 80 + 72) / 512f);
+ RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
}
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/FillRectangleDrawableConsumer.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/FillRectangleDrawableConsumer.java
index add96625e..5fd8a7af5 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/FillRectangleDrawableConsumer.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/FillRectangleDrawableConsumer.java
@@ -25,6 +25,7 @@ package me.shedaniel.rei.impl.client.gui.widget.basewidgets;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
+import com.mojang.math.Matrix4f;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.gui.DrawableConsumer;
import net.minecraft.client.gui.GuiComponent;
@@ -51,11 +52,12 @@ public final class FillRectangleDrawableConsumer implements DrawableConsumer {
Tesselator tesselator = Tesselator.getInstance();
BufferBuilder bufferBuilder = tesselator.getBuilder();
RenderSystem.setShader(GameRenderer::getPositionColorShader);
+ Matrix4f pose = matrices.last().pose();
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
- bufferBuilder.vertex(rectangle.getMaxX(), rectangle.getMinY(), helper.getBlitOffset()).color(r, g, b, a).endVertex();
- bufferBuilder.vertex(rectangle.getMinX(), rectangle.getMinY(), helper.getBlitOffset()).color(r, g, b, a).endVertex();
- bufferBuilder.vertex(rectangle.getMinX(), rectangle.getMaxY(), helper.getBlitOffset()).color(r, g, b, a).endVertex();
- bufferBuilder.vertex(rectangle.getMaxX(), rectangle.getMaxY(), helper.getBlitOffset()).color(r, g, b, a).endVertex();
+ bufferBuilder.vertex(pose, rectangle.getMaxX(), rectangle.getMinY(), helper.getBlitOffset()).color(r, g, b, a).endVertex();
+ bufferBuilder.vertex(pose, rectangle.getMinX(), rectangle.getMinY(), helper.getBlitOffset()).color(r, g, b, a).endVertex();
+ bufferBuilder.vertex(pose, rectangle.getMinX(), rectangle.getMaxY(), helper.getBlitOffset()).color(r, g, b, a).endVertex();
+ bufferBuilder.vertex(pose, rectangle.getMaxX(), rectangle.getMaxY(), helper.getBlitOffset()).color(r, g, b, a).endVertex();
tesselator.end();
RenderSystem.disableBlend();
RenderSystem.enableTexture();
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/LabelWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/LabelWidget.java
index 8ffa2d342..9566b7de0 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/LabelWidget.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/basewidgets/LabelWidget.java
@@ -25,9 +25,12 @@ package me.shedaniel.rei.impl.client.gui.widget.basewidgets;
import com.mojang.blaze3d.vertex.PoseS