DisplayHelper.java 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Copyright (c) 2018, 2019, 2020 shedaniel
  3. * Licensed under the MIT License (the "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 java.util.function.Supplier;
  12. import static net.minecraft.util.ActionResult.PASS;
  13. public interface DisplayHelper {
  14. @SuppressWarnings("deprecation")
  15. static DisplayHelper getInstance() {
  16. return RoughlyEnoughItemsCore.getDisplayHelper();
  17. }
  18. /**
  19. * Gets the sorted version of all responsible bounds handlers
  20. *
  21. * @param screenClass the class for checking responsible bounds handlers
  22. * @return the sorted list of responsible bounds handlers
  23. * @see DisplayHelper#getResponsibleBoundsHandler(Class) for the unsorted version
  24. */
  25. List<DisplayBoundsHandler<?>> getSortedBoundsHandlers(Class<?> screenClass);
  26. /**
  27. * Gets all registered bounds handlers
  28. *
  29. * @return the list of registered bounds handlers
  30. */
  31. List<DisplayBoundsHandler<?>> getAllBoundsHandlers();
  32. /**
  33. * Gets all responsible bounds handlers
  34. *
  35. * @param screenClass the class for checking responsible bounds handlers
  36. * @return the the list of responsible bounds handlers
  37. * @see DisplayHelper#getSortedBoundsHandlers(Class) for the sorted version
  38. */
  39. DisplayBoundsHandler<?> getResponsibleBoundsHandler(Class<?> screenClass);
  40. /**
  41. * Registers a bounds handler
  42. *
  43. * @param handler the handler to register
  44. */
  45. void registerBoundsHandler(DisplayBoundsHandler<?> handler);
  46. /**
  47. * Gets the base bounds handler api for exclusion zones
  48. *
  49. * @return the base bounds handler
  50. */
  51. BaseBoundsHandler getBaseBoundsHandler();
  52. interface DisplayBoundsHandler<T> {
  53. /**
  54. * Gets the base supported class for the bounds handler
  55. *
  56. * @return the base class
  57. */
  58. Class<?> getBaseSupportedClass();
  59. /**
  60. * Gets the left bounds of the overlay
  61. *
  62. * @param screen the current screen
  63. * @return the left bounds
  64. */
  65. Rectangle getLeftBounds(T screen);
  66. /**
  67. * Gets the right bounds of the overlay
  68. *
  69. * @param screen the current screen
  70. * @return the right bounds
  71. */
  72. Rectangle getRightBounds(T screen);
  73. /**
  74. * Checks if item slot can fit the screen
  75. *
  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, Supplier) for easier api
  82. */
  83. default ActionResult canItemSlotWidgetFit(int left, int top, T screen, Rectangle fullBounds) {
  84. return PASS;
  85. }
  86. /**
  87. * Checks if item slot can fit the screen
  88. *
  89. * @param isOnRightSide whether the user has set the overlay to the right
  90. * @param left the left x coordinates of the stack
  91. * @param top the top y coordinates for the stack
  92. * @param screen the current screen
  93. * @param fullBounds the current bounds
  94. * @return whether the item slot can fit
  95. * @deprecated use {@link #canItemSlotWidgetFit(int, int, Object, Rectangle)}
  96. */
  97. @Deprecated
  98. default ActionResult canItemSlotWidgetFit(boolean isOnRightSide, int left, int top, T screen, Rectangle fullBounds) {
  99. return canItemSlotWidgetFit(left, top, screen, fullBounds);
  100. }
  101. /**
  102. * Checks if mouse is inside the overlay
  103. *
  104. * @param isOnRightSide whether the user has set the overlay to the right
  105. * @param mouseX mouse's x coordinates
  106. * @param mouseY mouse's y coordinates
  107. * @return whether mouse is inside the overlay
  108. * @deprecated use {@link #isInZone(double, double)}
  109. */
  110. @Deprecated
  111. default ActionResult isInZone(boolean isOnRightSide, double mouseX, double mouseY) {
  112. return isInZone(mouseX, mouseY);
  113. }
  114. /**
  115. * Checks if mouse is inside the overlay
  116. *
  117. * @param mouseX mouse's x coordinates
  118. * @param mouseY mouse's y coordinates
  119. * @return whether mouse is inside the overlay
  120. */
  121. default ActionResult isInZone(double mouseX, double mouseY) {
  122. return PASS;
  123. }
  124. /**
  125. * Gets the item list bounds by the overlay bounds
  126. *
  127. * @param rectangle the overlay bounds
  128. * @return the item list bounds
  129. */
  130. default Rectangle getItemListArea(Rectangle rectangle) {
  131. 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));
  132. }
  133. default Rectangle getFavoritesListArea(Rectangle rectangle) {
  134. int offset = 31 + (ConfigObject.getInstance().doesShowUtilsButtons() ? 25 : 0);
  135. return new Rectangle(rectangle.x + 1, rectangle.y + 2 + offset, rectangle.width - 2, rectangle.height - 5 - offset);
  136. }
  137. /**
  138. * Checks if REI should recalculate the overlay bounds
  139. *
  140. * @param isOnRightSide whether the user has set the overlay to the right
  141. * @param rectangle the current overlay bounds
  142. * @return whether REI should recalculate the overlay bounds
  143. */
  144. default boolean shouldRecalculateArea(boolean isOnRightSide, Rectangle rectangle) {
  145. return false;
  146. }
  147. /**
  148. * Gets the priority of the handler, the higher it is, the earlier it is called.
  149. *
  150. * @return the priority in float
  151. */
  152. default float getPriority() {
  153. return 0f;
  154. }
  155. }
  156. }