diff options
author | xander <xander@isxander.dev> | 2022-09-02 11:16:48 +0100 |
---|---|---|
committer | xander <xander@isxander.dev> | 2022-09-02 11:16:48 +0100 |
commit | dd24e4f8e84ed02913196c8ad6093275acc92219 (patch) | |
tree | a9b846f6efad8f122c8364c499b098d95a23034d /src/main/java/dev/isxander | |
parent | 7c58fdd5aa54e88c1526c49adacaf97cf3810eba (diff) | |
download | YetAnotherConfigLib-dd24e4f8e84ed02913196c8ad6093275acc92219.tar.gz YetAnotherConfigLib-dd24e4f8e84ed02913196c8ad6093275acc92219.tar.bz2 YetAnotherConfigLib-dd24e4f8e84ed02913196c8ad6093275acc92219.zip |
button options now consume YACLScreen
Diffstat (limited to 'src/main/java/dev/isxander')
10 files changed, 49 insertions, 41 deletions
diff --git a/src/main/java/dev/isxander/yacl/api/ButtonOption.java b/src/main/java/dev/isxander/yacl/api/ButtonOption.java index 346bfa4..f3d1e6b 100644 --- a/src/main/java/dev/isxander/yacl/api/ButtonOption.java +++ b/src/main/java/dev/isxander/yacl/api/ButtonOption.java @@ -1,5 +1,6 @@ package dev.isxander.yacl.api; +import dev.isxander.yacl.gui.YACLScreen; import dev.isxander.yacl.impl.ButtonOptionImpl; import net.minecraft.text.MutableText; import net.minecraft.text.Text; @@ -8,10 +9,11 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; +import java.util.function.Consumer; import java.util.function.Function; -public interface ButtonOption extends Option<Runnable> { - Runnable action(); +public interface ButtonOption extends Option<Consumer<YACLScreen>> { + Consumer<YACLScreen> action(); static Builder createBuilder() { return new Builder(); @@ -20,8 +22,8 @@ public interface ButtonOption extends Option<Runnable> { class Builder { private Text name; private final List<Text> tooltipLines = new ArrayList<>(); - private Function<ButtonOption, Controller<Runnable>> controlGetter; - private Runnable action; + private Function<ButtonOption, Controller<Consumer<YACLScreen>>> controlGetter; + private Consumer<YACLScreen> action; private Builder() { @@ -41,14 +43,14 @@ public interface ButtonOption extends Option<Runnable> { return this; } - public Builder action(@NotNull Runnable action) { + public Builder action(@NotNull Consumer<YACLScreen> action) { Validate.notNull(action, "`action` cannot be null"); this.action = action; return this; } - public Builder controller(@NotNull Function<ButtonOption, Controller<Runnable>> control) { + public Builder controller(@NotNull Function<ButtonOption, Controller<Consumer<YACLScreen>>> control) { Validate.notNull(control, "`control` cannot be null"); this.controlGetter = control; diff --git a/src/main/java/dev/isxander/yacl/api/Controller.java b/src/main/java/dev/isxander/yacl/api/Controller.java index 2c0a5e1..198e5df 100644 --- a/src/main/java/dev/isxander/yacl/api/Controller.java +++ b/src/main/java/dev/isxander/yacl/api/Controller.java @@ -1,8 +1,8 @@ package dev.isxander.yacl.api; import dev.isxander.yacl.api.utils.Dimension; +import dev.isxander.yacl.gui.YACLScreen; import dev.isxander.yacl.gui.controllers.ControllerWidget; -import net.minecraft.client.gui.screen.Screen; import net.minecraft.text.Text; import org.jetbrains.annotations.ApiStatus; @@ -26,5 +26,5 @@ public interface Controller<T> { * @param screen parent screen */ @ApiStatus.Internal - ControllerWidget<?> provideWidget(Screen screen, Dimension<Integer> widgetDimension); + ControllerWidget<?> provideWidget(YACLScreen screen, Dimension<Integer> widgetDimension); } diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/ActionController.java b/src/main/java/dev/isxander/yacl/gui/controllers/ActionController.java index b632c5f..92ef3d5 100644 --- a/src/main/java/dev/isxander/yacl/gui/controllers/ActionController.java +++ b/src/main/java/dev/isxander/yacl/gui/controllers/ActionController.java @@ -3,15 +3,17 @@ package dev.isxander.yacl.gui.controllers; import dev.isxander.yacl.api.ButtonOption; import dev.isxander.yacl.api.Controller; import dev.isxander.yacl.api.utils.Dimension; -import net.minecraft.client.gui.screen.Screen; +import dev.isxander.yacl.gui.YACLScreen; import net.minecraft.text.Text; import org.jetbrains.annotations.ApiStatus; +import java.util.function.Consumer; + /** * Simple controller that simply runs the button action on press * and renders a {@link} Text on the right. */ -public class ActionController implements Controller<Runnable> { +public class ActionController implements Controller<Consumer<YACLScreen>> { public static final Text DEFAULT_TEXT = Text.translatable("yacl.control.action.execute"); private final ButtonOption option; @@ -59,13 +61,13 @@ public class ActionController implements Controller<Runnable> { * {@inheritDoc} */ @Override - public ControllerWidget<ActionController> provideWidget(Screen screen, Dimension<Integer> widgetDimension) { + public ControllerWidget<ActionController> provideWidget(YACLScreen screen, Dimension<Integer> widgetDimension) { return new ActionControllerElement(this, screen, widgetDimension); } @ApiStatus.Internal public static class ActionControllerElement extends ControllerWidget<ActionController> { - public ActionControllerElement(ActionController control, Screen screen, Dimension<Integer> dim) { + public ActionControllerElement(ActionController control, YACLScreen screen, Dimension<Integer> dim) { super(control, screen, dim); } @@ -73,7 +75,7 @@ public class ActionController implements Controller<Runnable> { public boolean mouseClicked(double mouseX, double mouseY, int button) { if (isMouseOver(mouseX, mouseY)) { playDownSound(); - control.option().action().run(); + control.option().action().accept(screen); return true; } return false; diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/BooleanController.java b/src/main/java/dev/isxander/yacl/gui/controllers/BooleanController.java index 9effd26..6bf0b80 100644 --- a/src/main/java/dev/isxander/yacl/gui/controllers/BooleanController.java +++ b/src/main/java/dev/isxander/yacl/gui/controllers/BooleanController.java @@ -3,6 +3,7 @@ package dev.isxander.yacl.gui.controllers; import dev.isxander.yacl.api.Controller; import dev.isxander.yacl.api.Option; import dev.isxander.yacl.api.utils.Dimension; +import dev.isxander.yacl.gui.YACLScreen; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; @@ -96,13 +97,13 @@ public class BooleanController implements Controller<Boolean> { * {@inheritDoc} */ @Override - public ControllerWidget<BooleanController> provideWidget(Screen screen, Dimension<Integer> widgetDimension) { + public ControllerWidget<BooleanController> provideWidget(YACLScreen screen, Dimension<Integer> widgetDimension) { return new BooleanControllerElement(this, screen, widgetDimension); } @ApiStatus.Internal public static class BooleanControllerElement extends ControllerWidget<BooleanController> { - private BooleanControllerElement(BooleanController control, Screen screen, Dimension<Integer> dim) { + private BooleanControllerElement(BooleanController control, YACLScreen screen, Dimension<Integer> dim) { super(control, screen, dim); } diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java b/src/main/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java index fe78b2e..77ac9ca 100644 --- a/src/main/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java +++ b/src/main/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java @@ -3,8 +3,8 @@ package dev.isxander.yacl.gui.controllers; import dev.isxander.yacl.api.Controller; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.gui.AbstractWidget; +import dev.isxander.yacl.gui.YACLScreen; import net.minecraft.client.gui.DrawableHelper; -import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.OrderedText; @@ -17,14 +17,14 @@ public abstract class ControllerWidget<T extends Controller<?>> extends Abstract protected final List<OrderedText> wrappedTooltip; protected Dimension<Integer> dim; - protected final Screen screen; + protected final YACLScreen screen; protected boolean hovered = false; protected float hoveredTicks = 0; private int prevMouseX, prevMouseY; - public ControllerWidget(T control, Screen screen, Dimension<Integer> dim) { + public ControllerWidget(T control, YACLScreen screen, Dimension<Integer> dim) { this.control = control; this.dim = dim; this.screen = screen; diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/EnumController.java b/src/main/java/dev/isxander/yacl/gui/controllers/EnumController.java index d88401c..f4c4006 100644 --- a/src/main/java/dev/isxander/yacl/gui/controllers/EnumController.java +++ b/src/main/java/dev/isxander/yacl/gui/controllers/EnumController.java @@ -4,6 +4,7 @@ import dev.isxander.yacl.api.Controller; import dev.isxander.yacl.api.NameableEnum; import dev.isxander.yacl.api.Option; import dev.isxander.yacl.api.utils.Dimension; +import dev.isxander.yacl.gui.YACLScreen; import net.minecraft.client.gui.screen.Screen; import net.minecraft.text.Text; import org.jetbrains.annotations.ApiStatus; @@ -71,7 +72,7 @@ public class EnumController<T extends Enum<T>> implements Controller<T> { * {@inheritDoc} */ @Override - public ControllerWidget<EnumController<T>> provideWidget(Screen screen, Dimension<Integer> widgetDimension) { + public ControllerWidget<EnumController<T>> provideWidget(YACLScreen screen, Dimension<Integer> widgetDimension) { return new EnumControllerElement<>(this, screen, widgetDimension, enumClass.getEnumConstants()); } @@ -79,7 +80,7 @@ public class EnumController<T extends Enum<T>> implements Controller<T> { public static class EnumControllerElement<T extends Enum<T>> extends ControllerWidget<EnumController<T>> { private final T[] values; - public EnumControllerElement(EnumController<T> control, Screen screen, Dimension<Integer> dim, T[] values) { + public EnumControllerElement(EnumController<T> control, YACLScreen screen, Dimension<Integer> dim, T[] values) { super(control, screen, dim); this.values = values; } diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/TickBoxController.java b/src/main/java/dev/isxander/yacl/gui/controllers/TickBoxController.java index 00df45b..1d78c78 100644 --- a/src/main/java/dev/isxander/yacl/gui/controllers/TickBoxController.java +++ b/src/main/java/dev/isxander/yacl/gui/controllers/TickBoxController.java @@ -3,14 +3,13 @@ package dev.isxander.yacl.gui.controllers; import dev.isxander.yacl.api.Controller; import dev.isxander.yacl.api.Option; import dev.isxander.yacl.api.utils.Dimension; +import dev.isxander.yacl.gui.YACLScreen; import net.minecraft.client.gui.DrawableHelper; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; import org.jetbrains.annotations.ApiStatus; -import java.util.function.Function; - /** * This controller renders a tickbox */ @@ -46,13 +45,13 @@ public class TickBoxController implements Controller<Boolean> { * {@inheritDoc} */ @Override - public ControllerWidget<TickBoxController> provideWidget(Screen screen, Dimension<Integer> widgetDimension) { + public ControllerWidget<TickBoxController> provideWidget(YACLScreen screen, Dimension<Integer> widgetDimension) { return new TickBoxControllerElement(this, screen, widgetDimension); } @ApiStatus.Internal public static class TickBoxControllerElement extends ControllerWidget<TickBoxController> { - private TickBoxControllerElement(TickBoxController control, Screen screen, Dimension<Integer> dim) { + private TickBoxControllerElement(TickBoxController control, YACLScreen screen, Dimension<Integer> dim) { super(control, screen, dim); } diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/slider/ISliderController.java b/src/main/java/dev/isxander/yacl/gui/controllers/slider/ISliderController.java index 0f6c2d5..ede3456 100644 --- a/src/main/java/dev/isxander/yacl/gui/controllers/slider/ISliderController.java +++ b/src/main/java/dev/isxander/yacl/gui/controllers/slider/ISliderController.java @@ -2,8 +2,8 @@ package dev.isxander.yacl.gui.controllers.slider; import dev.isxander.yacl.api.Controller; import dev.isxander.yacl.api.utils.Dimension; +import dev.isxander.yacl.gui.YACLScreen; import dev.isxander.yacl.gui.controllers.ControllerWidget; -import net.minecraft.client.gui.screen.Screen; /** * Simple custom slider implementation that shifts the current value across when shown. @@ -48,7 +48,7 @@ public interface ISliderController<T extends Number> extends Controller<T> { * {@inheritDoc} */ @Override - default ControllerWidget<?> provideWidget(Screen screen, Dimension<Integer> widgetDimension) { + default ControllerWidget<?> provideWidget(YACLScreen screen, Dimension<Integer> widgetDimension) { return new SliderControllerElement(this, screen, widgetDimension, min(), max(), interval()); } } diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java b/src/main/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java index 997ba7d..8af2433 100644 --- a/src/main/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java +++ b/src/main/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java @@ -1,6 +1,7 @@ package dev.isxander.yacl.gui.controllers.slider; import dev.isxander.yacl.api.utils.Dimension; +import dev.isxander.yacl.gui.YACLScreen; import dev.isxander.yacl.gui.controllers.ControllerWidget; import net.minecraft.client.gui.DrawableHelper; import net.minecraft.client.gui.screen.Screen; @@ -18,7 +19,7 @@ public class SliderControllerElement extends ControllerWidget<ISliderController< private boolean mouseDown = false; - public SliderControllerElement(ISliderController<?> option, Screen screen, Dimension<Integer> dim, double min, double max, double interval) { + public SliderControllerElement(ISliderController<?> option, YACLScreen screen, Dimension<Integer> dim, double min, double max, double interval) { super(option, screen, dim); this.min = min; this.max = max; diff --git a/src/main/java/dev/isxander/yacl/impl/ButtonOptionImpl.java b/src/main/java/dev/isxander/yacl/impl/ButtonOptionImpl.java index 4104ff0..748dd0c 100644 --- a/src/main/java/dev/isxander/yacl/impl/ButtonOptionImpl.java +++ b/src/main/java/dev/isxander/yacl/impl/ButtonOptionImpl.java @@ -3,26 +3,28 @@ package dev.isxander.yacl.impl; import dev.isxander.yacl.api.Binding; import dev.isxander.yacl.api.ButtonOption; import dev.isxander.yacl.api.Controller; +import dev.isxander.yacl.gui.YACLScreen; import net.minecraft.text.Text; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.function.Consumer; import java.util.function.Function; @ApiStatus.Internal public class ButtonOptionImpl implements ButtonOption { private final Text name; private final Text tooltip; - private final Runnable action; - private final Controller<Runnable> controller; - private final Binding<Runnable> binding; + private final Consumer<YACLScreen> action; + private final Controller<Consumer<YACLScreen>> controller; + private final Binding<Consumer<YACLScreen>> binding; public ButtonOptionImpl( @NotNull Text name, @Nullable Text tooltip, - @NotNull Runnable action, - @NotNull Function<ButtonOption, Controller<Runnable>> controlGetter + @NotNull Consumer<YACLScreen> action, + @NotNull Function<ButtonOption, Controller<Consumer<YACLScreen>>> controlGetter ) { this.name = name; this.tooltip = tooltip; @@ -42,17 +44,17 @@ public class ButtonOptionImpl implements ButtonOption { } @Override - public Runnable action() { + public Consumer<YACLScreen> action() { return action; } @Override - public @NotNull Controller<Runnable> controller() { + public @NotNull Controller<Consumer<YACLScreen>> controller() { return controller; } @Override - public @NotNull Binding<Runnable> binding() { + public @NotNull Binding<Consumer<YACLScreen>> binding() { return binding; } @@ -62,12 +64,12 @@ public class ButtonOptionImpl implements ButtonOption { } @Override - public @NotNull Runnable pendingValue() { + public @NotNull Consumer<YACLScreen> pendingValue() { throw new UnsupportedOperationException(); } @Override - public void requestSet(Runnable value) { + public void requestSet(Consumer<YACLScreen> value) { throw new UnsupportedOperationException(); } @@ -86,19 +88,19 @@ public class ButtonOptionImpl implements ButtonOption { } - private static class EmptyBinderImpl implements Binding<Runnable> { + private static class EmptyBinderImpl implements Binding<Consumer<YACLScreen>> { @Override - public void setValue(Runnable value) { + public void setValue(Consumer<YACLScreen> value) { } @Override - public Runnable getValue() { + public Consumer<YACLScreen> getValue() { throw new UnsupportedOperationException(); } @Override - public Runnable defaultValue() { + public Consumer<YACLScreen> defaultValue() { throw new UnsupportedOperationException(); } } |