From 17150bedcdf80944a64e165976cf2491d409b1c0 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sun, 5 Jul 2020 15:31:12 +0800 Subject: Fix #370 and changes to how screens are handled Signed-off-by: shedaniel --- .../java/me/shedaniel/rei/api/DisplayHelper.java | 83 +++++++++++++++++----- 1 file changed, 64 insertions(+), 19 deletions(-) (limited to 'src/main/java/me/shedaniel/rei/api/DisplayHelper.java') 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> getSortedBoundsHandlers(Class screenClass); + List getSortedOverlayDeciders(Class screenClass); + /** * Gets all registered overlay deciders * @@ -59,12 +68,14 @@ public interface DisplayHelper { List 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 void registerProvider(DisplayBoundsProvider provider) { + registerHandler(provider); + } + + /** + * Gets the left bounds of the overlay + * + * @param screen the current screen + * @return the left bounds + */ + Rectangle getOverlayBounds(DisplayPanelLocation location, T screen); + + interface DisplayBoundsProvider 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 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(); } } -- cgit