diff options
| author | shedaniel <daniel@shedaniel.me> | 2020-03-10 02:03:11 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2020-03-10 02:03:11 +0800 |
| commit | 9ce069457bca016c8793c73844e5cc984deac365 (patch) | |
| tree | 367195b8ec8402638a2d9af267eb45c2dd08ae89 | |
| parent | b31a280413f5ec916f44fbd96d0690f8ce1a9186 (diff) | |
| download | RoughlyEnoughItems-9ce069457bca016c8793c73844e5cc984deac365.tar.gz RoughlyEnoughItems-9ce069457bca016c8793c73844e5cc984deac365.tar.bz2 RoughlyEnoughItems-9ce069457bca016c8793c73844e5cc984deac365.zip | |
new widget api
Signed-off-by: shedaniel <daniel@shedaniel.me>
43 files changed, 1901 insertions, 295 deletions
diff --git a/build.gradle b/build.gradle index fad593335..5b654b4c6 100755 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ import net.fabricmc.loom.task.RemapJarTask import java.text.SimpleDateFormat plugins { - id 'fabric-loom' version '0.2.6-SNAPSHOT' + id 'fabric-loom' version '0.2.7-SNAPSHOT' id 'maven-publish' id 'net.minecrell.licenser' version '0.4.1' id 'com.matthewprenger.cursegradle' version '1.4.0' diff --git a/gradle.properties b/gradle.properties index f032e476b..15e8dec3c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,9 +1,9 @@ -mod_version=4.0.9-unstable +mod_version=4.0.10-unstable minecraft_version=20w10a yarn_version=20w10a+build.2 fabricloader_version=0.7.8+build.186 cloth_events_version=2.0.0-unstable.202003051905 -cloth_config_version=3.0.1-unstable.202003051928 +cloth_config_version=3.0.2-unstable.202003090708 modmenu_version=1.10.1+build.30 fabric_api=0.4.34+build.303-1.16 autoconfig1u=1.2.4 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,22 +81,40 @@ public interface RecipeCategory<T extends RecipeDisplay> { * @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<Widget> setupDisplay(Supplier<T> recipeDisplaySupplier, Rectangle bounds) { + @ApiStatus.ScheduledForRemoval + @Deprecated + default List<Widget> setupDisplay(Supplier<T> 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<Widget> setupDisplay(T recipeDisplay, Rectangle bounds) { + return setupDisplay(() -> recipeDisplay, new me.shedaniel.math.api.Rectangle(bounds)); + } + + /** * Draws the category background, used in {@link RecipeViewingScreen} * * @param bounds the bounds of the whole recipe viewing screen * @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<Label> getOnClick(); + + public abstract void setOnClick(@Nullable Consumer<Label> onClick); + + public final Label onClick(@Nullable Consumer<Label> onClick) { + setOnClick(onClick); + return this; + } + + @Nullable + public abstract Consumer<Label> getOnRender(); + + public abstract void setOnRender(@Nullable Consumer<Label> onRender); + + public final Label onRender(@Nullable Consumer<Label> onRender) { + setOnRender(onRender); + return this; + } + + public abstract boolean isFocusable(); + + public abstract void setFocusable(boolean focusable); + + public final Label focusable(boolean focusable) { + setFocusable(focusable); + return this; + } + + @Nullable + public abstract String getTooltip(); + + public abstract void setTooltip(@Nullable Function<Label, @Nullable String> tooltip); + + public final Label tooltipLines(@NotNull String... tooltip) { + return tooltipLine(String.join("\n", tooltip)); + } + + public final Label tooltipLine(@Nullable String tooltip) { + return tooltipSupplier(label -> tooltip); + } + + public final Label tooltipSupplier(@Nullable Function<Label, @Nullable String> tooltip) { + setTooltip(tooltip); + return this; + } + + public abstract int getHorizontalAlignment(); + + public final Label centered() { + return horizontalAlignment(CENTER); + } + + public final Label leftAligned() { + return horizontalAlignment(LEFT_ALIGNED); + } + + public final Label rightAligned() { + return horizontalAlignment(RIGHT_ALIGNED); + } + + public abstract void setHorizontalAlignment(int horizontalAlignment); + + public final Label horizontalAlignment(int horizontalAlignment) { + setHorizontalAlignment(horizontalAlignment); + return this; + } + + public abstract boolean hasShadow(); + + public final Label noShadow() { + return shadow(false); + } + + public final Label shadow() { + return shadow(true); + } + + public abstract void setShadow(boolean hasShadow); + + public final Label shadow(boolean hasShadow) { + setShadow(hasShadow); + return this; + } + + public abstract int getColor(); + + public abstract void setColor(int color); + + public final Label color(int lightModeColor, int darkModeColor) { + return color(REIHelper.getInstance().isDarkThemeEnabled() ? darkModeColor : lightModeColor); + } + + public final Label color(int color) { + setColor(color); + return this; + } + + public abstract int getHoveredColor(); + + public abstract void setHoveredColor(int hoveredColor); + + public final Label hoveredColor(int lightModeColor, int darkModeColor) { + return hoveredColor(REIHelper.getInstance().isDarkThemeEnabled() ? darkModeColor : lightModeColor); + } + + public final Label hoveredColor(int color) { + setHoveredColor(color); + return this; + } + + @NotNull + public abstract Point getPoint(); + + public final int getX() { + return getPoint().getX(); + } + + public final int getY() { + return getPoint().getY(); + } + + public abstract void setPoint(@NotNull Point point); + + public final Label point(@NotNull Point point) { + setPoint(point); + return this; + } + + @NotNull + public abstract String getText(); + + public abstract void setText(@NotNull String text); + + public final Label text(@NotNull String text) { + setText(text); + return this; + } +} diff --git a/src/main/java/me/shedaniel/rei/api/widgets/Panel.java b/src/main/java/me/shedaniel/rei/api/widgets/Panel.java new file mode 100644 index 000000000..441068b62 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/widgets/Panel.java @@ -0,0 +1,86 @@ +/* + * 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.api.REIHelper; +import me.shedaniel.rei.gui.widget.WidgetWithBounds; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Predicate; + +public abstract class Panel extends WidgetWithBounds { + public abstract int getInnerColor(); + + public abstract void setInnerColor(int innerColor); + + public final Panel innerColor(int innerColor) { + setInnerColor(innerColor); + return this; + } + + public final Panel innerColor(int lightColor, int darkColor) { + return innerColor(REIHelper.getInstance().isDarkThemeEnabled() ? darkColor : lightColor); + } + + public abstract int getXTextureOffset(); + + public abstract void setXTextureOffset(int xTextureOffset); + + public final Panel xTextureOffset(int xTextureOffset) { + setXTextureOffset(xTextureOffset); + return this; + } + + public abstract int getYTextureOffset(); + + public abstract void setYTextureOffset(int yTextureOffset); + + public final Panel yTextureOffset(int yTextureOffset) { + setYTextureOffset(yTextureOffset); + return this; + } + + public abstract int getColor(); + + public abstract void setColor(int color); + + public final Panel color(int color) { + setColor(color); + return this; + } + + public final Panel color(int lightColor, int darkColor) { + return color(REIHelper.getInstance().isDarkThemeEnabled() ? darkColor : lightColor); + } + + @NotNull + public abstract Predicate<Panel> getRendering(); + + public abstract void setRendering(@NotNull Predicate<Panel> rendering); + + public final Panel rendering(@NotNull Predicate<Panel> rendering) { + setRendering(rendering); + return this; + } +} diff --git a/src/main/java/me/shedaniel/rei/api/widgets/Slot.java b/src/main/java/me/shedaniel/rei/api/widgets/Slot.java new file mode 100644 index 000000000..e12143d0e --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/widget |
