From 9ce069457bca016c8793c73844e5cc984deac365 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 10 Mar 2020 02:03:11 +0800 Subject: new widget api Signed-off-by: shedaniel --- .../me/shedaniel/rei/api/DrawableConsumer.java | 33 +++ .../java/me/shedaniel/rei/api/RecipeCategory.java | 24 +- .../java/me/shedaniel/rei/api/widgets/Arrow.java | 78 ++++++ .../me/shedaniel/rei/api/widgets/BurningFire.java | 78 ++++++ .../java/me/shedaniel/rei/api/widgets/Label.java | 191 +++++++++++++++ .../java/me/shedaniel/rei/api/widgets/Panel.java | 86 +++++++ .../java/me/shedaniel/rei/api/widgets/Slot.java | 104 ++++++++ .../java/me/shedaniel/rei/api/widgets/Widgets.java | 142 +++++++++++ .../shedaniel/rei/gui/ContainerScreenOverlay.java | 28 +-- .../shedaniel/rei/gui/PreRecipeViewingScreen.java | 6 +- .../me/shedaniel/rei/gui/RecipeViewingScreen.java | 29 +-- .../rei/gui/VillagerRecipeViewingScreen.java | 18 +- .../rei/gui/widget/ClickableLabelWidget.java | 18 +- .../shedaniel/rei/gui/widget/EntryListWidget.java | 3 +- .../me/shedaniel/rei/gui/widget/EntryWidget.java | 86 ++++++- .../me/shedaniel/rei/gui/widget/LabelWidget.java | 40 ++- .../me/shedaniel/rei/gui/widget/QueuedTooltip.java | 24 +- .../rei/gui/widget/RecipeArrowWidget.java | 5 + .../shedaniel/rei/gui/widget/RecipeBaseWidget.java | 10 + .../shedaniel/rei/gui/widget/SlotBaseWidget.java | 10 + .../java/me/shedaniel/rei/gui/widget/Widget.java | 1 + .../me/shedaniel/rei/impl/ConfigObjectImpl.java | 2 +- .../me/shedaniel/rei/impl/widgets/ArrowWidget.java | 78 ++++++ .../rei/impl/widgets/BurningFireWidget.java | 78 ++++++ .../shedaniel/rei/impl/widgets/DrawableWidget.java | 49 ++++ .../widgets/FillRectangleDrawableConsumer.java | 67 ++++++ .../me/shedaniel/rei/impl/widgets/LabelWidget.java | 268 +++++++++++++++++++++ .../me/shedaniel/rei/impl/widgets/PanelWidget.java | 162 +++++++++++++ .../rei/impl/widgets/TexturedDrawableConsumer.java | 75 ++++++ .../shedaniel/rei/impl/widgets/package-info.java | 27 +++ .../plugin/beacon/DefaultBeaconBaseCategory.java | 25 +- .../rei/plugin/brewing/DefaultBrewingCategory.java | 42 ++-- .../plugin/campfire/DefaultCampfireCategory.java | 44 ++-- .../composting/DefaultCompostingCategory.java | 32 +-- .../rei/plugin/cooking/DefaultCookingCategory.java | 47 ++-- .../plugin/crafting/DefaultCraftingCategory.java | 39 ++- .../rei/plugin/fuel/DefaultFuelCategory.java | 49 ++-- .../information/DefaultInformationCategory.java | 31 +-- .../stonecutting/DefaultStoneCuttingCategory.java | 29 +-- .../plugin/stripping/DefaultStrippingCategory.java | 30 +-- .../me/shedaniel/rei/utils/CollectionUtils.java | 2 - 41 files changed, 1898 insertions(+), 292 deletions(-) create mode 100644 src/main/java/me/shedaniel/rei/api/DrawableConsumer.java create mode 100644 src/main/java/me/shedaniel/rei/api/widgets/Arrow.java create mode 100644 src/main/java/me/shedaniel/rei/api/widgets/BurningFire.java create mode 100644 src/main/java/me/shedaniel/rei/api/widgets/Label.java create mode 100644 src/main/java/me/shedaniel/rei/api/widgets/Panel.java create mode 100644 src/main/java/me/shedaniel/rei/api/widgets/Slot.java create mode 100644 src/main/java/me/shedaniel/rei/api/widgets/Widgets.java create mode 100644 src/main/java/me/shedaniel/rei/impl/widgets/ArrowWidget.java create mode 100644 src/main/java/me/shedaniel/rei/impl/widgets/BurningFireWidget.java create mode 100644 src/main/java/me/shedaniel/rei/impl/widgets/DrawableWidget.java create mode 100644 src/main/java/me/shedaniel/rei/impl/widgets/FillRectangleDrawableConsumer.java create mode 100644 src/main/java/me/shedaniel/rei/impl/widgets/LabelWidget.java create mode 100644 src/main/java/me/shedaniel/rei/impl/widgets/PanelWidget.java create mode 100644 src/main/java/me/shedaniel/rei/impl/widgets/TexturedDrawableConsumer.java create mode 100644 src/main/java/me/shedaniel/rei/impl/widgets/package-info.java (limited to 'src/main/java/me') diff --git a/src/main/java/me/shedaniel/rei/api/DrawableConsumer.java b/src/main/java/me/shedaniel/rei/api/DrawableConsumer.java new file mode 100644 index 000000000..77ebfd9f7 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/DrawableConsumer.java @@ -0,0 +1,33 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api; + +import net.minecraft.client.gui.DrawableHelper; + +/** + * Consumer of a {@link DrawableHelper} and information of mouse and delta. + */ +public interface DrawableConsumer { + void render(DrawableHelper helper, int mouseX, int mouseY, float delta); +} diff --git a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java index 826c0add1..631217963 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java @@ -23,7 +23,7 @@ package me.shedaniel.rei.api; -import me.shedaniel.math.api.Rectangle; +import me.shedaniel.math.Rectangle; import me.shedaniel.rei.gui.RecipeViewingScreen; import me.shedaniel.rei.gui.entries.RecipeEntry; import me.shedaniel.rei.gui.entries.SimpleRecipeEntry; @@ -81,12 +81,27 @@ public interface RecipeCategory { * @param recipeDisplaySupplier the supplier for getting the recipe * @param bounds the bounds of the display, configurable with overriding the width, height methods. * @return the list of widgets + * @deprecated use {@link #setupDisplay(RecipeDisplay, me.shedaniel.math.Rectangle)} */ @ApiStatus.OverrideOnly - default List setupDisplay(Supplier recipeDisplaySupplier, Rectangle bounds) { + @ApiStatus.ScheduledForRemoval + @Deprecated + default List setupDisplay(Supplier recipeDisplaySupplier, me.shedaniel.math.api.Rectangle bounds) { return Collections.singletonList(new RecipeBaseWidget(bounds)); } + /** + * Setup the widgets for displaying the recipe + * + * @param recipeDisplay the recipe + * @param bounds the bounds of the display, configurable with overriding the width, height methods. + * @return the list of widgets + */ + @ApiStatus.OverrideOnly + default List setupDisplay(T recipeDisplay, Rectangle bounds) { + return setupDisplay(() -> recipeDisplay, new me.shedaniel.math.api.Rectangle(bounds)); + } + /** * Draws the category background, used in {@link RecipeViewingScreen} * @@ -94,9 +109,12 @@ public interface RecipeCategory { * @param mouseX the x coordinates for the mouse * @param mouseY the y coordinates for the mouse * @param delta the delta + * @deprecated there is no replacement for this as this is just a dumb idea, please contact me if you want to change my mind */ @ApiStatus.OverrideOnly - default void drawCategoryBackground(Rectangle bounds, int mouseX, int mouseY, float delta) { + @Deprecated + @ApiStatus.ScheduledForRemoval + default void drawCategoryBackground(me.shedaniel.math.api.Rectangle bounds, int mouseX, int mouseY, float delta) { PanelWidget.render(bounds, -1); if (REIHelper.getInstance().isDarkThemeEnabled()) { DrawableHelper.fill(bounds.x + 17, bounds.y + 5, bounds.x + bounds.width - 17, bounds.y + 17, 0xFF404040); diff --git a/src/main/java/me/shedaniel/rei/api/widgets/Arrow.java b/src/main/java/me/shedaniel/rei/api/widgets/Arrow.java new file mode 100644 index 000000000..90d840ce2 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/widgets/Arrow.java @@ -0,0 +1,78 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.widgets; + +import me.shedaniel.rei.gui.widget.WidgetWithBounds; + +public abstract class Arrow extends WidgetWithBounds { + public final int getX() { + return getBounds().getX(); + } + + public final int getY() { + return getBounds().getY(); + } + + /** + * Gets the animation duration in milliseconds, -1 if animation is disabled. + */ + public abstract double getAnimationDuration(); + + /** + * Sets the animation duration in milliseconds. + * + * @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 + */ + public final Arrow animationDurationMS(double animationDurationMS) { + setAnimationDuration(animationDurationMS); + return this; + } + + /** + * 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 + */ + public final Arrow animationDurationTicks(double animationDurationTicks) { + return animationDurationMS(animationDurationTicks * 50); + } + + /** + * Disables the animation. + * + * @return the arrow itself + */ + public final Arrow disableAnimation() { + return animationDurationMS(-1); + } +} diff --git a/src/main/java/me/shedaniel/rei/api/widgets/BurningFire.java b/src/main/java/me/shedaniel/rei/api/widgets/BurningFire.java new file mode 100644 index 000000000..8ea7759e9 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/widgets/BurningFire.java @@ -0,0 +1,78 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.widgets; + +import me.shedaniel.rei.gui.widget.WidgetWithBounds; + +public abstract class BurningFire extends WidgetWithBounds { + public final int getX() { + return getBounds().getX(); + } + + public final int getY() { + return getBounds().getY(); + } + + /** + * Gets the animation duration in milliseconds, -1 if animation is disabled. + */ + public abstract double getAnimationDuration(); + + /** + * Sets the animation duration in milliseconds. + * + * @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 + */ + public final BurningFire animationDurationMS(double animationDurationMS) { + setAnimationDuration(animationDurationMS); + return this; + } + + /** + * 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 + */ + public final BurningFire animationDurationTicks(double animationDurationTicks) { + return animationDurationMS(animationDurationTicks * 50); + } + + /** + * Disables the animation. + * + * @return the arrow itself + */ + public final BurningFire disableAnimation() { + return animationDurationMS(-1); + } +} diff --git a/src/main/java/me/shedaniel/rei/api/widgets/Label.java b/src/main/java/me/shedaniel/rei/api/widgets/Label.java new file mode 100644 index 000000000..8d4d0247f --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/widgets/Label.java @@ -0,0 +1,191 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.widgets; + +import me.shedaniel.math.Point; +import me.shedaniel.rei.api.REIHelper; +import me.shedaniel.rei.gui.widget.WidgetWithBounds; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.function.Consumer; +import java.util.function.Function; + +public abstract class Label extends WidgetWithBounds { + public static final int LEFT_ALIGNED = -1; + public static final int CENTER = 0; + public static final int RIGHT_ALIGNED = 1; + + public abstract boolean isClickable(); + + public abstract void setClickable(boolean clickable); + + public final Label clickable() { + return clickable(true); + } + + public final Label clickable(boolean clickable) { + setClickable(clickable); + return this; + } + + @Nullable + public abstract Consumer