Made onClick

It should work but idk for sure
This commit is contained in:
opfromthestart 2021-04-17 08:21:29 -04:00
parent 5359b93738
commit 411780b120
2 changed files with 6 additions and 2 deletions

View File

@ -1,5 +1,6 @@
package ru.windcorp.progressia.client.graphics.gui; package ru.windcorp.progressia.client.graphics.gui;
import java.util.function.Consumer;
import java.util.function.Supplier; import java.util.function.Supplier;
import com.google.common.eventbus.Subscribe; import com.google.common.eventbus.Subscribe;
@ -25,7 +26,7 @@ public class Button extends Component {
private boolean isDisabled; private boolean isDisabled;
private boolean isClicked; private boolean isClicked;
public <T extends InputEvent> Button(String name, Font font, String text) {//, InputListener<T> onClick, Class<? extends T> onClickClass) { public <T extends InputEvent> Button(String name, Font font, String text, Consumer<Button> onClick) {//, InputListener<T> onClick, Class<? extends T> onClickClass) {
super(name); super(name);
this.font = font; this.font = font;
this.text = text; this.text = text;
@ -39,12 +40,15 @@ public class Button extends Component {
} }
}); });
Button inButton = this;
addListener(new Object() { addListener(new Object() {
@Subscribe @Subscribe
public void onLeftClick(KeyEvent e) { public void onLeftClick(KeyEvent e) {
if (e.isLeftMouseButton()) if (e.isLeftMouseButton())
{ {
isClicked = e.isPress(); isClicked = e.isPress();
onClick.accept(inButton);
requestReassembly(); requestReassembly();
} }
} }

View File

@ -59,7 +59,7 @@ public class LayerTestGUI extends GUILayer {
TestPlayerControls tpc = TestPlayerControls.getInstance(); TestPlayerControls tpc = TestPlayerControls.getInstance();
panel.addChild(new Button("TestButton", new Font().withColor(Colors.BLACK), "I'm in TestGUI")); panel.addChild(new Button("TestButton", new Font().withColor(Colors.BLACK), "I'm in TestGUI", b -> {}));
panel.addChild( panel.addChild(
new Label( new Label(