From 6f8ef7daaafd71090b2c334c10eadc8dedc738d9 Mon Sep 17 00:00:00 2001 From: xander Date: Thu, 1 Sep 2022 08:57:59 +0100 Subject: GUI Implementation Added groups Added button "option" Added test mod --- .../yacl/gui/controllers/ActionControl.java | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/main/java/dev/isxander/yacl/gui/controllers/ActionControl.java (limited to 'src/main/java/dev/isxander/yacl/gui/controllers/ActionControl.java') 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 { + 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 provideWidget(Screen screen, Dimension widgetDimension) { + return new ActionControlElement(this, screen, widgetDimension); + } + + public static class ActionControlElement extends ControlWidget { + public ActionControlElement(ActionControl control, Screen screen, Dimension 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(); + } + } +} -- cgit