diff options
| author | xander <xander@isxander.dev> | 2022-09-01 08:57:59 +0100 |
|---|---|---|
| committer | xander <xander@isxander.dev> | 2022-09-01 08:57:59 +0100 |
| commit | 6f8ef7daaafd71090b2c334c10eadc8dedc738d9 (patch) | |
| tree | d4054a65d99070c944132be83d25e109750dc5f9 /src/main/java/dev/isxander/yacl/gui/controllers/ActionControl.java | |
| parent | 9d0a5e937f97c1c17d034393e01636d5241f376a (diff) | |
| download | YetAnotherConfigLib-6f8ef7daaafd71090b2c334c10eadc8dedc738d9.tar.gz YetAnotherConfigLib-6f8ef7daaafd71090b2c334c10eadc8dedc738d9.tar.bz2 YetAnotherConfigLib-6f8ef7daaafd71090b2c334c10eadc8dedc738d9.zip | |
GUI Implementation
Added groups
Added button "option"
Added test mod
Diffstat (limited to 'src/main/java/dev/isxander/yacl/gui/controllers/ActionControl.java')
| -rw-r--r-- | src/main/java/dev/isxander/yacl/gui/controllers/ActionControl.java | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/ActionControl.java b/src/main/java/dev/isxander/yacl/gui/controllers/ActionControl.java new file mode 100644 index 0000000..66e8e35 --- /dev/null +++ b/src/main/java/dev/isxander/yacl/gui/controllers/ActionControl.java @@ -0,0 +1,58 @@ +package dev.isxander.yacl.gui.controllers; + +import dev.isxander.yacl.api.ButtonOption; +import dev.isxander.yacl.api.Control; +import dev.isxander.yacl.api.utils.Dimension; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.text.Text; + +public class ActionControl implements Control<Runnable> { + private final ButtonOption option; + private final Text executeText; + + public ActionControl(ButtonOption option) { + this(option, Text.translatable("yacl.control.action.execute")); + } + + public ActionControl(ButtonOption option, Text executeText) { + this.option = option; + this.executeText = executeText; + + } + + @Override + public ButtonOption option() { + return option; + } + + @Override + public Text formatValue() { + return executeText; + } + + @Override + public ControlWidget<ActionControl> provideWidget(Screen screen, Dimension<Integer> widgetDimension) { + return new ActionControlElement(this, screen, widgetDimension); + } + + public static class ActionControlElement extends ControlWidget<ActionControl> { + public ActionControlElement(ActionControl control, Screen screen, Dimension<Integer> dim) { + super(control, screen, dim); + } + + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + if (isMouseOver(mouseX, mouseY)) { + playDownSound(); + control.option().action().run(); + return true; + } + return false; + } + + @Override + protected int getHoveredControlWidth() { + return getUnhoveredControlWidth(); + } + } +} |
