aboutsummaryrefslogtreecommitdiff
path: root/api/src
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2021-11-08 23:15:08 +0800
committershedaniel <daniel@shedaniel.me>2021-11-08 23:19:59 +0800
commitaba4c079befd4bb32f732b65c746a22559644d35 (patch)
treebba42a67cb78edc54fc6ad600ea983fcd9873bc0 /api/src
parentdac507c52b7f8e6363d8ca90f533aa789c4adc09 (diff)
downloadRoughlyEnoughItems-aba4c079befd4bb32f732b65c746a22559644d35.tar.gz
RoughlyEnoughItems-aba4c079befd4bb32f732b65c746a22559644d35.tar.bz2
RoughlyEnoughItems-aba4c079befd4bb32f732b65c746a22559644d35.zip
Big Visual and Functional Changes
- Fix #503 - Shift Click to select page, normal click to go back to page 1 - Allow non-consuming draggable visitors - Add scale down animation when dragging a stack to the main item list to dismiss it - Make Cheat Mode not active in Display Screens - Add colors to cosmetic transfer handler errors - Implement JEI animations, fix #501 - Allow favorites dragged stacks to go back to where they are if they are ignored, instead of being at the end of the favorites - Implement favorites & entry list column and row limits - Implement display page height limit - Updated localizations
Diffstat (limited to 'api/src')
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java12
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java18
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStack.java9
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStackVisitor.java23
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStackVisitorWidget.java25
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggedAcceptorResult.java44
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggingContext.java11
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandler.java19
8 files changed, 145 insertions, 16 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java b/api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java
index adc1cb968..1af65d4ad 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java
@@ -24,18 +24,22 @@
package me.shedaniel.rei.api.client;
import me.shedaniel.math.Rectangle;
+import me.shedaniel.rei.api.client.config.ConfigObject;
import me.shedaniel.rei.api.client.gui.config.SearchFieldLocation;
import me.shedaniel.rei.api.client.gui.widgets.TextField;
import me.shedaniel.rei.api.client.gui.widgets.Tooltip;
import me.shedaniel.rei.api.client.overlay.ScreenOverlay;
import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
+import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry;
import me.shedaniel.rei.api.common.plugins.PluginManager;
import me.shedaniel.rei.api.common.registry.Reloadable;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
+import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.resources.ResourceLocation;
+import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import java.util.Optional;
@@ -80,7 +84,13 @@ public interface REIRuntime extends Reloadable<REIClientPlugin> {
SearchFieldLocation getContextualSearchFieldLocation();
- Rectangle calculateEntryListArea();
+ @ApiStatus.ScheduledForRemoval
+ @Deprecated
+ default Rectangle calculateEntryListArea() {
+ return calculateEntryListArea(ScreenRegistry.getInstance().getOverlayBounds(ConfigObject.getInstance().getDisplayPanelLocation(), Minecraft.getInstance().screen));
+ }
+
+ Rectangle calculateEntryListArea(Rectangle bounds);
Rectangle calculateFavoritesListArea();
}
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java b/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java
index 040704236..8d35049c2 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java
@@ -89,6 +89,8 @@ public interface ConfigObject {
int getMaxRecipePerPage();
+ int getMaxRecipesPageHeight();
+
boolean doesDisableRecipeBook();
boolean doesFixTabCloseContainer();
@@ -163,10 +165,22 @@ public interface ConfigObject {
boolean isInventoryHighlightingAllowed();
@ApiStatus.Experimental
- double getHorizontalEntriesBoundaries();
+ double getHorizontalEntriesBoundariesPercentage();
+
+ @ApiStatus.Experimental
+ double getVerticalEntriesBoundariesPercentage();
+
+ @ApiStatus.Experimental
+ double getHorizontalEntriesBoundariesColumns();
+
+ @ApiStatus.Experimental
+ double getVerticalEntriesBoundariesRows();
+
+ @ApiStatus.Experimental
+ double getFavoritesHorizontalEntriesBoundariesPercentage();
@ApiStatus.Experimental
- double getVerticalEntriesBoundaries();
+ double getFavoritesHorizontalEntriesBoundariesColumns();
@ApiStatus.Experimental
SyntaxHighlightingMode getSyntaxHighlightingMode();
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStack.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStack.java
index 6dfaa9097..b5ccc97f2 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStack.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStack.java
@@ -26,13 +26,20 @@ package me.shedaniel.rei.api.client.gui.drag;
import com.mojang.blaze3d.vertex.PoseStack;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.common.entry.EntryStack;
+import org.jetbrains.annotations.ApiStatus;
public interface DraggableStack {
EntryStack<?> getStack();
void drag();
- void release(boolean accepted);
+ @Deprecated
+ @ApiStatus.ScheduledForRemoval
+ default void release(boolean consumed) {}
+
+ default void release(DraggedAcceptorResult result) {
+ release(result != DraggedAcceptorResult.PASS);
+ }
default void render(PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta) {
getStack().render(matrices, bounds, mouseX, mouseY, delta);
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStackVisitor.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStackVisitor.java
index ae973be16..d893eccd4 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStackVisitor.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStackVisitor.java
@@ -29,6 +29,7 @@ import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.ApiStatus;
+import java.util.Objects;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Stream;
@@ -51,14 +52,14 @@ public interface DraggableStackVisitor<T extends Screen> extends Comparable<Drag
}
@Override
- public boolean acceptDraggedStack(DraggingContext<T> context, DraggableStack stack) {
+ public DraggedAcceptorResult acceptDraggedStackWithResult(DraggingContext<T> context, DraggableStack stack) {
for (DraggableStackVisitor<T> visitor : visitors.get()) {
if (visitor.isHandingScreen(context.getScreen())) {
- boolean visited = visitor.acceptDraggedStack(context, stack);
- if (visited) return true;
+ DraggedAcceptorResult result = Objects.requireNonNull(visitor.acceptDraggedStackWithResult(context, stack));
+ if (result != DraggedAcceptorResult.PASS) return result;
}
}
- return false;
+ return DraggedAcceptorResult.PASS;
}
@Override
@@ -84,6 +85,8 @@ public interface DraggableStackVisitor<T extends Screen> extends Comparable<Drag
* @param stack the stack being dragged
* @return whether the stack is accepted by the visitor
*/
+ @ApiStatus.ScheduledForRemoval
+ @Deprecated
default boolean acceptDraggedStack(DraggingContext<T> context, DraggableStack stack) {
Optional<Acceptor> acceptor = visitDraggedStack(context, stack);
if (acceptor.isPresent()) {
@@ -95,6 +98,18 @@ public interface DraggableStackVisitor<T extends Screen> extends Comparable<Drag
}
/**
+ * Accepts a dragged stack, implementations of this function should check if the {@code context} is within
+ * boundaries of the accepting boundaries.
+ *
+ * @param context the context of the current dragged stack on the overlay
+ * @param stack the stack being dragged
+ * @return the result of the visitor
+ */
+ default DraggedAcceptorResult acceptDraggedStackWithResult(DraggingContext<T> context, DraggableStack stack) {
+ return acceptDraggedStack(context, stack) ? DraggedAcceptorResult.CONSUMED : DraggedAcceptorResult.PASS;
+ }
+
+ /**
* Returns the accepting bounds for the dragging stack, this should only be called once on drag.
* The bounds are used to overlay to indicate to the users that the area is accepting entries.
*
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStackVisitorWidget.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStackVisitorWidget.java
index 7bb813d4d..4234b2b6b 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStackVisitorWidget.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStackVisitorWidget.java
@@ -39,9 +39,12 @@ public interface DraggableStackVisitorWidget {
static DraggableStackVisitorWidget from(Function<DraggingContext<Screen>, Iterable<DraggableStackVisitorWidget>> providers) {
return new DraggableStackVisitorWidget() {
@Override
- public boolean acceptDraggedStack(DraggingContext<Screen> context, DraggableStack stack) {
+ public DraggedAcceptorResult acceptDraggedStackWithResult(DraggingContext<Screen> context, DraggableStack stack) {
return StreamSupport.stream(providers.apply(context).spliterator(), false)
- .anyMatch(visitor -> visitor.acceptDraggedStack(context, stack));
+ .map(visitor -> visitor.acceptDraggedStackWithResult(context, stack))
+ .filter(result -> result != DraggedAcceptorResult.PASS)
+ .findFirst()
+ .orElse(DraggedAcceptorResult.PASS);
}
@Override
@@ -66,6 +69,8 @@ public interface DraggableStackVisitorWidget {
* @param stack the stack being dragged
* @return whether the stack is accepted by the widget
*/
+ @ApiStatus.ScheduledForRemoval
+ @Deprecated
default boolean acceptDraggedStack(DraggingContext<Screen> context, DraggableStack stack) {
Optional<DraggableStackVisitor.Acceptor> acceptor = visitDraggedStack(context, stack);
if (acceptor.isPresent()) {
@@ -77,6 +82,18 @@ public interface DraggableStackVisitorWidget {
}
/**
+ * Accepts a dragged stack, implementations of this function should check if the {@code context} is within
+ * boundaries of the widget.
+ *
+ * @param context the context of the current dragged stack on the overlay
+ * @param stack the stack being dragged
+ * @return the result of the visitor
+ */
+ default DraggedAcceptorResult acceptDraggedStackWithResult(DraggingContext<Screen> context, DraggableStack stack) {
+ return acceptDraggedStack(context, stack) ? DraggedAcceptorResult.CONSUMED : DraggedAcceptorResult.PASS;
+ }
+
+ /**
* Returns the accepting bounds for the dragging stack, this should only be called once on drag.
* The bounds are used to overlay to indicate to the users that the widget is accepting entries.
*
@@ -95,8 +112,8 @@ public interface DraggableStackVisitorWidget {
static DraggableStackVisitor<Screen> toVisitor(DraggableStackVisitorWidget widget, double priority) {
return new DraggableStackVisitor<>() {
@Override
- public boolean acceptDraggedStack(DraggingContext<Screen> context, DraggableStack stack) {
- return widget.acceptDraggedStack(context, stack);
+ public DraggedAcceptorResult acceptDraggedStackWithResult(DraggingContext<Screen> context, DraggableStack stack) {
+ return widget.acceptDraggedStackWithResult(context, stack);
}
@Override
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggedAcceptorResult.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggedAcceptorResult.java
new file mode 100644
index 000000000..05731ef0c
--- /dev/null
+++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggedAcceptorResult.java
@@ -0,0 +1,44 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021 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.api.client.gui.drag;
+
+/**
+ * The result of the visitor, this is used to determine if the visitor consumed the stack or not.
+ */
+public enum DraggedAcceptorResult {
+ /**
+ * The visitor consumed the stack, the stack will not be returned to the original stack.
+ */
+ CONSUMED,
+ /**
+ * The visitor did not consume the stack, the stack will be returned to the original stack,
+ * other visitors will not be called.
+ */
+ ACCEPTED,
+ /**
+ * The visitor did not consume the stack, the stack will be passed to the next visitor.
+ */
+ PASS,
+ ;
+} \ No newline at end of file
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggingContext.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggingContext.java
index 626d9aa29..20e2c1fe2 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggingContext.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggingContext.java
@@ -24,6 +24,7 @@
package me.shedaniel.rei.api.client.gui.drag;
import me.shedaniel.math.Point;
+import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.REIRuntime;
import net.minecraft.client.gui.screens.Screen;
import org.jetbrains.annotations.Nullable;
@@ -82,6 +83,16 @@ public interface DraggingContext<S extends Screen> {
*/
void renderBackToPosition(DraggableStack stack, Point initialPosition, Supplier<Point> position);
+ /**
+ * Renders the draggable stack back to the bounds {@code bounds}.
+ * This may be used to animate an unaccepted draggable stack returning to its initial position.
+ *
+ * @param stack the stack to use for render
+ * @param initialPosition the initial bounds of the stack
+ * @param bounds the boundary supplier of the destination
+ */
+ void renderBackToPosition(DraggableStack stack, Rectangle initialPosition, Supplier<Rectangle> bounds);
+
default <T extends Screen> DraggingContext<T> cast() {
return (DraggingContext<T>) this;
}
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandler.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandler.java
index 3c3ea6462..9ec3a3a15 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandler.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandler.java
@@ -69,7 +69,7 @@ public interface TransferHandler extends Comparable<TransferHandler> {
* Creates a successful result, no further handlers will be called.
*/
static Result createSuccessful() {
- return new ResultImpl();
+ return new ResultImpl().color(0x00000000);
}
/**
@@ -77,7 +77,7 @@ public interface TransferHandler extends Comparable<TransferHandler> {
* This will also mark the handler as not applicable.
*/
static Result createNotApplicable() {
- return new ResultImpl(false);
+ return new ResultImpl(false).color(0x00000000);
}
/**
@@ -86,7 +86,7 @@ public interface TransferHandler extends Comparable<TransferHandler> {
* @param error The error itself
*/
static Result createFailed(Component error) {
- return new ResultImpl(error, new IntArrayList(), 1744764928);
+ return new ResultImpl(error, new IntArrayList(), 0x67ff0000);
}
/**
@@ -107,7 +107,7 @@ public interface TransferHandler extends Comparable<TransferHandler> {
* @param redSlots A list of slots to be marked as red. Will be passed to {@link TransferDisplayCategory}.
*/
static Result createFailed(Component error, IntList redSlots) {
- return new ResultImpl(error, redSlots, 1744764928);
+ return new ResultImpl(error, redSlots, 0x67ff0000);
}
/**
@@ -138,6 +138,11 @@ public interface TransferHandler extends Comparable<TransferHandler> {
* @return the color in which the button should be displayed in.
*/
int getColor();
+
+ /**
+ * Sets the color in which the button should be displayed in.
+ */
+ Result color(int color);
/**
* @return whether this handler has successfully handled the transfer.
@@ -244,6 +249,12 @@ public interface TransferHandler extends Comparable<TransferHandler> {
}
@Override
+ public TransferHandler.Result color(int color) {
+ this.color = color;
+ return this;
+ }
+
+ @Override
public boolean isSuccessful() {
return successful;
}