aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/shedaniel/rei/api/DisplayHelper.java
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2020-07-05 15:31:12 +0800
committershedaniel <daniel@shedaniel.me>2020-07-05 15:31:12 +0800
commit17150bedcdf80944a64e165976cf2491d409b1c0 (patch)
treef71725bf6c37fd2bc82fbf8bf07a4b98ba2d1584 /src/main/java/me/shedaniel/rei/api/DisplayHelper.java
parentaf1b3f780d8edb361c00421cdd991f3f2b86849c (diff)
downloadRoughlyEnoughItems-17150bedcdf80944a64e165976cf2491d409b1c0.tar.gz
RoughlyEnoughItems-17150bedcdf80944a64e165976cf2491d409b1c0.tar.bz2
RoughlyEnoughItems-17150bedcdf80944a64e165976cf2491d409b1c0.zip
Fix #370 and changes to how screens are handled
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'src/main/java/me/shedaniel/rei/api/DisplayHelper.java')
-rw-r--r--src/main/java/me/shedaniel/rei/api/DisplayHelper.java83
1 files changed, 64 insertions, 19 deletions
diff --git a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java
index 52936de0e..fbf753a98 100644
--- a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java
+++ b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java
@@ -25,14 +25,19 @@ package me.shedaniel.rei.api;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.RoughlyEnoughItemsCore;
+import me.shedaniel.rei.gui.config.DisplayPanelLocation;
import me.shedaniel.rei.gui.config.SearchFieldLocation;
+import net.fabricmc.api.EnvType;
+import net.fabricmc.api.Environment;
import net.minecraft.util.ActionResult;
+import org.jetbrains.annotations.ApiStatus;
import java.util.List;
import java.util.function.Supplier;
import static net.minecraft.util.ActionResult.PASS;
+@Environment(EnvType.CLIENT)
public interface DisplayHelper {
/**
@@ -49,8 +54,12 @@ public interface DisplayHelper {
* @return the sorted list of responsible bounds handlers
* @see DisplayHelper#getResponsibleBoundsHandler(Class) for the unsorted version
*/
+ @Deprecated
+ @ApiStatus.ScheduledForRemoval
List<DisplayBoundsHandler<?>> getSortedBoundsHandlers(Class<?> screenClass);
+ List<OverlayDecider> getSortedOverlayDeciders(Class<?> screenClass);
+
/**
* Gets all registered overlay deciders
*
@@ -59,12 +68,14 @@ public interface DisplayHelper {
List<OverlayDecider> getAllOverlayDeciders();
/**
- * Gets all responsible bounds handlers
+ * Gets the responsible bounds handlers
*
* @param screenClass the class for checking responsible bounds handlers
* @return the the list of responsible bounds handlers
* @see DisplayHelper#getSortedBoundsHandlers(Class) for the sorted version
*/
+ @Deprecated
+ @ApiStatus.ScheduledForRemoval
DisplayBoundsHandler<?> getResponsibleBoundsHandler(Class<?> screenClass);
/**
@@ -74,6 +85,40 @@ public interface DisplayHelper {
*/
void registerHandler(OverlayDecider decider);
+ default <T> void registerProvider(DisplayBoundsProvider<T> provider) {
+ registerHandler(provider);
+ }
+
+ /**
+ * Gets the left bounds of the overlay
+ *
+ * @param screen the current screen
+ * @return the left bounds
+ */
+ <T> Rectangle getOverlayBounds(DisplayPanelLocation location, T screen);
+
+ interface DisplayBoundsProvider<T> extends OverlayDecider {
+ /**
+ * @param screen the screen
+ * @return the boundary of the base container panel.
+ */
+ Rectangle getScreenBounds(T screen);
+
+ /**
+ * Gets the base supported class for the bounds handler
+ *
+ * @return the base class
+ */
+ Class<?> getBaseSupportedClass();
+
+ @Override
+ default boolean isHandingScreen(Class<?> screen) {
+ return getBaseSupportedClass().isAssignableFrom(screen);
+ }
+ }
+
+ @Deprecated
+ @ApiStatus.ScheduledForRemoval
interface DisplayBoundsHandler<T> extends OverlayDecider {
/**
* Gets the base supported class for the bounds handler
@@ -114,18 +159,20 @@ public interface DisplayHelper {
* @see BaseBoundsHandler#registerExclusionZones(Class, Supplier) for easier api
*/
default ActionResult canItemSlotWidgetFit(int left, int top, T screen, Rectangle fullBounds) {
+ ActionResult fit = isInZone(left, top);
+ if (fit == ActionResult.FAIL)
+ return ActionResult.FAIL;
+ ActionResult fit2 = isInZone(left + 18, top + 18);
+ if (fit2 == ActionResult.FAIL)
+ return ActionResult.FAIL;
+ if (fit == ActionResult.SUCCESS && fit2 == ActionResult.SUCCESS)
+ return ActionResult.SUCCESS;
return PASS;
}
- /**
- * Checks if mouse is inside the overlay
- *
- * @param mouseX mouse's x coordinates
- * @param mouseY mouse's y coordinates
- * @return whether mouse is inside the overlay
- */
+ @Override
default ActionResult isInZone(double mouseX, double mouseY) {
- return PASS;
+ return OverlayDecider.super.isInZone(mouseX, mouseY);
}
/**
@@ -143,26 +190,24 @@ public interface DisplayHelper {
return new Rectangle(rectangle.x + 1, rectangle.y + 2 + offset, rectangle.width - 2, rectangle.height - 5 - offset);
}
- /**
- * Checks if REI should recalculate the overlay bounds
- *
- * @param isOnRightSide whether the user has set the overlay to the right
- * @param rectangle the current overlay bounds
- * @return whether REI should recalculate the overlay bounds
- */
+ @Deprecated
+ @ApiStatus.ScheduledForRemoval
default boolean shouldRecalculateArea(boolean isOnRightSide, Rectangle rectangle) {
return false;
}
+ @Override
+ default boolean shouldRecalculateArea(DisplayPanelLocation location, Rectangle rectangle) {
+ return shouldRecalculateArea(location == DisplayPanelLocation.RIGHT, rectangle);
+ }
+
/**
* Gets the priority of the handler, the higher it is, the earlier it is called.
*
* @return the priority in float
*/
@Override
- default float getPriority() {
- return 0f;
- }
+ float getPriority();
}
}