diff options
| author | shedaniel <daniel@shedaniel.me> | 2020-03-18 00:35:36 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2020-03-18 00:35:36 +0800 |
| commit | 550fe32e612801daa99493aa0bade083f3330133 (patch) | |
| tree | 7825027dd8933d542a831e2bda6626c63f4cd8db /src/main/java/me/shedaniel/rei/api/widgets/Widgets.java | |
| parent | 9e990de7685960391d78ca2cca0ff68bebe1a8cd (diff) | |
| download | RoughlyEnoughItems-550fe32e612801daa99493aa0bade083f3330133.tar.gz RoughlyEnoughItems-550fe32e612801daa99493aa0bade083f3330133.tar.bz2 RoughlyEnoughItems-550fe32e612801daa99493aa0bade083f3330133.zip | |
4.0.14: Better widgets system
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'src/main/java/me/shedaniel/rei/api/widgets/Widgets.java')
| -rw-r--r-- | src/main/java/me/shedaniel/rei/api/widgets/Widgets.java | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/main/java/me/shedaniel/rei/api/widgets/Widgets.java b/src/main/java/me/shedaniel/rei/api/widgets/Widgets.java index da1f1ad02..9ab31a290 100644 --- a/src/main/java/me/shedaniel/rei/api/widgets/Widgets.java +++ b/src/main/java/me/shedaniel/rei/api/widgets/Widgets.java @@ -32,12 +32,19 @@ import me.shedaniel.rei.gui.widget.EntryWidget; import me.shedaniel.rei.gui.widget.Widget; import me.shedaniel.rei.impl.widgets.*; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.Drawable; +import net.minecraft.client.gui.DrawableHelper; +import net.minecraft.client.gui.Element; import net.minecraft.client.sound.PositionedSoundInstance; import net.minecraft.sound.SoundEvents; +import net.minecraft.text.Text; import net.minecraft.util.Identifier; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; +import java.util.List; +import java.util.Objects; import java.util.function.Consumer; public final class Widgets { @@ -49,6 +56,32 @@ public final class Widgets { } @NotNull + public static Widget wrapVanillaWidget(@NotNull Element element) { + return new VanillaWrappedWidget(element); + } + + private static class VanillaWrappedWidget extends Widget { + private Element element; + + public VanillaWrappedWidget(Element element) { + this.element = Objects.requireNonNull(element); + } + + @Override + public void render(int mouseX, int mouseY, float delta) { + if (element instanceof DrawableHelper) + ((DrawableHelper) element).setZOffset(getZ()); + if (element instanceof Drawable) + ((Drawable) element).render(mouseX, mouseY, delta); + } + + @Override + public List<? extends Element> children() { + return Collections.singletonList(element); + } + } + + @NotNull public static Widget createTexturedWidget(@NotNull Identifier identifier, @NotNull Rectangle bounds) { return createTexturedWidget(identifier, bounds, 0, 0); } @@ -167,6 +200,16 @@ public final class Widgets { return EntryWidget.create(point.x, point.y); } + @NotNull + public static Button createButton(@NotNull Rectangle bounds, @NotNull String text) { + return new ButtonWidget(bounds, text); + } + + @NotNull + public static Button createButton(@NotNull Rectangle bounds, @NotNull Text text) { + return new ButtonWidget(bounds, text); + } + public static void produceClickSound() { MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F)); } |
