From 550fe32e612801daa99493aa0bade083f3330133 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Wed, 18 Mar 2020 00:35:36 +0800 Subject: 4.0.14: Better widgets system Signed-off-by: shedaniel --- .../java/me/shedaniel/rei/api/widgets/Arrow.java | 22 +- .../me/shedaniel/rei/api/widgets/BaseWidget.java | 30 +++ .../me/shedaniel/rei/api/widgets/BurningFire.java | 22 +- .../java/me/shedaniel/rei/api/widgets/Button.java | 160 ++++++++++++ .../java/me/shedaniel/rei/api/widgets/Label.java | 112 ++++++++ .../java/me/shedaniel/rei/api/widgets/Panel.java | 7 + .../java/me/shedaniel/rei/api/widgets/Slot.java | 32 ++- .../java/me/shedaniel/rei/api/widgets/Tooltip.java | 5 + .../java/me/shedaniel/rei/api/widgets/Widgets.java | 43 ++++ .../shedaniel/rei/gui/ContainerScreenOverlay.java | 273 +++++++++----------- .../shedaniel/rei/gui/PreRecipeViewingScreen.java | 22 +- .../me/shedaniel/rei/gui/RecipeViewingScreen.java | 132 +++++----- .../rei/gui/VillagerRecipeViewingScreen.java | 104 ++++---- .../rei/gui/widget/AutoCraftingButtonWidget.java | 192 -------------- .../me/shedaniel/rei/gui/widget/ButtonWidget.java | 9 + .../gui/widget/CraftableToggleButtonWidget.java | 82 ------ .../shedaniel/rei/gui/widget/EntryListWidget.java | 2 + .../me/shedaniel/rei/gui/widget/EntryWidget.java | 8 + .../rei/gui/widget/FavoritesListWidget.java | 2 + .../me/shedaniel/rei/gui/widget/LabelWidget.java | 2 + .../rei/gui/widget/LateRenderedButton.java | 35 --- .../me/shedaniel/rei/gui/widget/PanelWidget.java | 2 + .../me/shedaniel/rei/gui/widget/QueuedTooltip.java | 10 + .../rei/gui/widget/RecipeArrowWidget.java | 2 + .../rei/gui/widget/RecipeChoosePageWidget.java | 16 +- .../me/shedaniel/rei/gui/widget/TabWidget.java | 2 + .../shedaniel/rei/gui/widget/TextFieldWidget.java | 7 + .../shedaniel/rei/gui/widget/WidgetWithBounds.java | 2 + .../me/shedaniel/rei/impl/InternalWidgets.java | 242 ++++++++++++++++++ .../java/me/shedaniel/rei/impl/ScreenHelper.java | 3 + .../me/shedaniel/rei/impl/widgets/ArrowWidget.java | 5 +- .../rei/impl/widgets/BurningFireWidget.java | 2 +- .../shedaniel/rei/impl/widgets/ButtonWidget.java | 284 +++++++++++++++++++++ .../widgets/FillRectangleDrawableConsumer.java | 2 +- .../me/shedaniel/rei/impl/widgets/LabelWidget.java | 1 + .../me/shedaniel/rei/impl/widgets/PanelWidget.java | 1 + .../rei/impl/widgets/TexturedDrawableConsumer.java | 2 +- .../plugin/beacon/DefaultBeaconBaseCategory.java | 2 + .../information/DefaultInformationCategory.java | 2 + 39 files changed, 1269 insertions(+), 614 deletions(-) create mode 100644 src/main/java/me/shedaniel/rei/api/widgets/BaseWidget.java create mode 100644 src/main/java/me/shedaniel/rei/api/widgets/Button.java delete mode 100644 src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java delete mode 100644 src/main/java/me/shedaniel/rei/gui/widget/CraftableToggleButtonWidget.java delete mode 100644 src/main/java/me/shedaniel/rei/gui/widget/LateRenderedButton.java create mode 100644 src/main/java/me/shedaniel/rei/impl/InternalWidgets.java create mode 100644 src/main/java/me/shedaniel/rei/impl/widgets/ButtonWidget.java (limited to 'src/main/java') diff --git a/src/main/java/me/shedaniel/rei/api/widgets/Arrow.java b/src/main/java/me/shedaniel/rei/api/widgets/Arrow.java index 90d840ce2..98a0da428 100644 --- a/src/main/java/me/shedaniel/rei/api/widgets/Arrow.java +++ b/src/main/java/me/shedaniel/rei/api/widgets/Arrow.java @@ -24,12 +24,19 @@ package me.shedaniel.rei.api.widgets; import me.shedaniel.rei.gui.widget.WidgetWithBounds; +import org.jetbrains.annotations.NotNull; public abstract class Arrow extends WidgetWithBounds { + /** + * @return the x coordinate for the top left corner of this widget. + */ public final int getX() { return getBounds().getX(); } + /** + * @return the y coordinate for the top left corner of this widget. + */ public final int getY() { return getBounds().getY(); } @@ -42,16 +49,17 @@ public abstract class Arrow extends WidgetWithBounds { /** * Sets the animation duration in milliseconds. * - * @param animationDurationMS animation duration in milliseconds, animation is disabled when below or equals to 0 + * @param animationDurationMS animation duration in milliseconds, animation is disabled when below or equals to 0. */ public abstract void setAnimationDuration(double animationDurationMS); /** * Sets the animation duration in milliseconds. * - * @param animationDurationMS animation duration in milliseconds, animation is disabled when below or equals to 0 - * @return the arrow itself + * @param animationDurationMS animation duration in milliseconds, animation is disabled when below or equals to 0. + * @return the arrow itself. */ + @NotNull public final Arrow animationDurationMS(double animationDurationMS) { setAnimationDuration(animationDurationMS); return this; @@ -60,9 +68,10 @@ public abstract class Arrow extends WidgetWithBounds { /** * Sets the animation duration in ticks. * - * @param animationDurationTicks animation duration in ticks, animation is disabled when below or equals to 0 - * @return the arrow itself + * @param animationDurationTicks animation duration in ticks, animation is disabled when below or equals to 0. + * @return the arrow itself. */ + @NotNull public final Arrow animationDurationTicks(double animationDurationTicks) { return animationDurationMS(animationDurationTicks * 50); } @@ -70,8 +79,9 @@ public abstract class Arrow extends WidgetWithBounds { /** * Disables the animation. * - * @return the arrow itself + * @return the arrow itself. */ + @NotNull public final Arrow disableAnimation() { return animationDurationMS(-1); } diff --git a/src/main/java/me/shedaniel/rei/api/widgets/BaseWidget.java b/src/main/java/me/shedaniel/rei/api/widgets/BaseWidget.java new file mode 100644 index 000000000..fe6212473 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/widgets/BaseWidget.java @@ -0,0 +1,30 @@ +package me.shedaniel.rei.api.widgets; + +import me.shedaniel.math.Point; +import me.shedaniel.rei.gui.widget.WidgetWithBounds; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.function.BiPredicate; + +public abstract class BaseWidget> extends WidgetWithBounds { + @Nullable + private BiPredicate containsMousePredicate; + + public final void setContainsMousePredicate(@Nullable BiPredicate predicate) { + this.containsMousePredicate = predicate; + } + + @NotNull + public final T containsMousePredicate(@Nullable BiPredicate predicate) { + setContainsMousePredicate(predicate); + return (T) this; + } + + @Override + public boolean containsMouse(double mouseX, double mouseY) { + if (containsMousePredicate != null) + return containsMousePredicate.test((T) this, new Point(mouseX, mouseY)); + return super.containsMouse(mouseX, mouseY); + } +} diff --git a/src/main/java/me/shedaniel/rei/api/widgets/BurningFire.java b/src/main/java/me/shedaniel/rei/api/widgets/BurningFire.java index 8ea7759e9..fab8f95b9 100644 --- a/src/main/java/me/shedaniel/rei/api/widgets/BurningFire.java +++ b/src/main/java/me/shedaniel/rei/api/widgets/BurningFire.java @@ -24,12 +24,19 @@ package me.shedaniel.rei.api.widgets; import me.shedaniel.rei.gui.widget.WidgetWithBounds; +import org.jetbrains.annotations.NotNull; public abstract class BurningFire extends WidgetWithBounds { + /** + * @return the x coordinate for the top left corner of this widget. + */ public final int getX() { return getBounds().getX(); } + /** + * @return the y coordinate for the top left corner of this widget. + */ public final int getY() { return getBounds().getY(); } @@ -42,16 +49,17 @@ public abstract class BurningFire extends WidgetWithBounds { /** * Sets the animation duration in milliseconds. * - * @param animationDurationMS animation duration in milliseconds, animation is disabled when below or equals to 0 + * @param animationDurationMS animation duration in milliseconds, animation is disabled when below or equals to 0. */ public abstract void setAnimationDuration(double animationDurationMS); /** * Sets the animation duration in milliseconds. * - * @param animationDurationMS animation duration in milliseconds, animation is disabled when below or equals to 0 - * @return the arrow itself + * @param animationDurationMS animation duration in milliseconds, animation is disabled when below or equals to 0. + * @return the arrow itself. */ + @NotNull public final BurningFire animationDurationMS(double animationDurationMS) { setAnimationDuration(animationDurationMS); return this; @@ -60,9 +68,10 @@ public abstract class BurningFire extends WidgetWithBounds { /** * Sets the animation duration in ticks. * - * @param animationDurationTicks animation duration in ticks, animation is disabled when below or equals to 0 - * @return the arrow itself + * @param animationDurationTicks animation duration in ticks, animation is disabled when below or equals to 0. + * @return the arrow itself. */ + @NotNull public final BurningFire animationDurationTicks(double animationDurationTicks) { return animationDurationMS(animationDurationTicks * 50); } @@ -70,8 +79,9 @@ public abstract class BurningFire extends WidgetWithBounds { /** * Disables the animation. * - * @return the arrow itself + * @return the arrow itself. */ + @NotNull public final BurningFire disableAnimation() { return animationDurationMS(-1); } diff --git a/src/main/java/me/shedaniel/rei/api/widgets/Button.java b/src/main/java/me/shedaniel/rei/api/widgets/Button.java new file mode 100644 index 000000000..2bf51e5bc --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/widgets/Button.java @@ -0,0 +1,160 @@ +package me.shedaniel.rei.api.widgets; + +import me.shedaniel.math.api.Point; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.OptionalInt; +import java.util.function.BiFunction; +import java.util.function.Consumer; +import java.util.function.Function; + +public abstract class Button extends BaseWidget