DisplayHelper.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * Roughly Enough Items by Danielshe.
  3. * Licensed under the MIT License.
  4. */
  5. package me.shedaniel.rei.api;
  6. import me.shedaniel.math.api.Rectangle;
  7. import me.shedaniel.rei.RoughlyEnoughItemsCore;
  8. import me.shedaniel.rei.gui.config.SearchFieldLocation;
  9. import net.minecraft.util.ActionResult;
  10. import java.util.List;
  11. import static net.minecraft.util.ActionResult.PASS;
  12. public interface DisplayHelper {
  13. @SuppressWarnings("deprecation")
  14. static DisplayHelper getInstance() {
  15. return RoughlyEnoughItemsCore.getDisplayHelper();
  16. }
  17. /**
  18. * Gets the sorted version of all responsible bounds handlers
  19. *
  20. * @param screenClass the class for checking responsible bounds handlers
  21. * @return the sorted list of responsible bounds handlers
  22. * @see DisplayHelper#getResponsibleBoundsHandler(Class) for the unsorted version
  23. */
  24. List<DisplayBoundsHandler<?>> getSortedBoundsHandlers(Class<?> screenClass);
  25. /**
  26. * Gets all registered bounds handlers
  27. *
  28. * @return the list of registered bounds handlers
  29. */
  30. List<DisplayBoundsHandler<?>> getAllBoundsHandlers();
  31. /**
  32. * Gets all responsible bounds handlers
  33. *
  34. * @param screenClass the class for checking responsible bounds handlers
  35. * @return the the list of responsible bounds handlers
  36. * @see DisplayHelper#getSortedBoundsHandlers(Class) for the sorted version
  37. */
  38. DisplayBoundsHandler<?> getResponsibleBoundsHandler(Class<?> screenClass);
  39. /**
  40. * Registers a bounds handler
  41. *
  42. * @param handler the handler to register
  43. */
  44. void registerBoundsHandler(DisplayBoundsHandler<?> handler);
  45. /**
  46. * Gets the base bounds handler api for exclusion zones
  47. *
  48. * @return the base bounds handler
  49. */
  50. BaseBoundsHandler getBaseBoundsHandler();
  51. public static interface DisplayBoundsHandler<T> {
  52. /**
  53. * Gets the base supported class for the bounds handler
  54. *
  55. * @return the base class
  56. */
  57. Class<?> getBaseSupportedClass();
  58. /**
  59. * Gets the left bounds of the overlay
  60. *
  61. * @param screen the current screen
  62. * @return the left bounds
  63. */
  64. Rectangle getLeftBounds(T screen);
  65. /**
  66. * Gets the right bounds of the overlay
  67. *
  68. * @param screen the current screen
  69. * @return the right bounds
  70. */
  71. Rectangle getRightBounds(T screen);
  72. /**
  73. * Checks if item slot can fit the screen
  74. *
  75. * @param isOnRightSide whether the user has set the overlay to the right
  76. * @param left the left x coordinates of the stack
  77. * @param top the top y coordinates for the stack
  78. * @param screen the current screen
  79. * @param fullBounds the current bounds
  80. * @return whether the item slot can fit
  81. * @see BaseBoundsHandler#registerExclusionZones(Class, BaseBoundsHandler.ExclusionZoneSupplier) for easier api
  82. */
  83. default ActionResult canItemSlotWidgetFit(boolean isOnRightSide, int left, int top, T screen, Rectangle fullBounds) {
  84. return PASS;
  85. }
  86. /**
  87. * Checks if mouse is inside the overlay
  88. *
  89. * @param isOnRightSide whether the user has set the overlay to the right
  90. * @param mouseX mouse's x coordinates
  91. * @param mouseY mouse's y coordinates
  92. * @return whether mouse is inside the overlay
  93. */
  94. default ActionResult isInZone(boolean isOnRightSide, double mouseX, double mouseY) {
  95. return PASS;
  96. }
  97. /**
  98. * Gets the item list bounds by the overlay bounds
  99. *
  100. * @param rectangle the overlay bounds
  101. * @return the item list bounds
  102. */
  103. default Rectangle getItemListArea(Rectangle rectangle) {
  104. return new Rectangle(rectangle.x + 1, rectangle.y + 2 + (ConfigObject.getInstance().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + (ConfigObject.getInstance().isEntryListWidgetScrolled() ? 0 : 22), rectangle.width - 2, rectangle.height - (ConfigObject.getInstance().getSearchFieldLocation() != SearchFieldLocation.CENTER ? 27 + 22 : 27) + (!ConfigObject.getInstance().isEntryListWidgetScrolled() ? 0 : 22));
  105. }
  106. /**
  107. * Checks if REI should recalculate the overlay bounds
  108. *
  109. * @param isOnRightSide whether the user has set the overlay to the right
  110. * @param rectangle the current overlay bounds
  111. * @return whether REI should recalculate the overlay bounds
  112. */
  113. default boolean shouldRecalculateArea(boolean isOnRightSide, Rectangle rectangle) {
  114. return false;
  115. }
  116. /**
  117. * Gets the priority of the handler, the higher it is, the earlier it is called.
  118. *
  119. * @return the priority in float
  120. */
  121. default float getPriority() {
  122. return 0f;
  123. }
  124. }
  125. }