Buttons work
Clicking and disabling now works
This commit is contained in:
parent
411780b120
commit
6e1b0e3f69
@ -12,6 +12,7 @@ import ru.windcorp.progressia.client.graphics.backend.InputTracker;
|
|||||||
import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
|
import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
|
||||||
import ru.windcorp.progressia.client.graphics.font.Font;
|
import ru.windcorp.progressia.client.graphics.font.Font;
|
||||||
import ru.windcorp.progressia.client.graphics.Colors;
|
import ru.windcorp.progressia.client.graphics.Colors;
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.event.FocusEvent;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.event.HoverEvent;
|
import ru.windcorp.progressia.client.graphics.gui.event.HoverEvent;
|
||||||
import ru.windcorp.progressia.client.graphics.input.bus.InputListener;
|
import ru.windcorp.progressia.client.graphics.input.bus.InputListener;
|
||||||
import ru.windcorp.progressia.client.graphics.input.InputEvent;
|
import ru.windcorp.progressia.client.graphics.input.InputEvent;
|
||||||
@ -40,19 +41,20 @@ public class Button extends Component {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Button inButton = this;
|
|
||||||
|
|
||||||
addListener(new Object() {
|
addListener(new Object() {
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onLeftClick(KeyEvent e) {
|
public void onFocusChanged(FocusEvent e) {
|
||||||
if (e.isLeftMouseButton())
|
|
||||||
{
|
|
||||||
isClicked = e.isPress();
|
|
||||||
onClick.accept(inButton);
|
|
||||||
requestReassembly();
|
requestReassembly();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Button inButton = this;
|
||||||
|
|
||||||
|
addListener((Class<KeyEvent>) KeyEvent.class, (InputListener<KeyEvent>) e -> {isClicked = e.isPress();
|
||||||
|
if (!inButton.isDisabled())
|
||||||
|
onClick.accept(inButton);
|
||||||
|
requestReassembly();
|
||||||
|
return true;});
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isClicked()
|
public boolean isClicked()
|
||||||
@ -70,43 +72,49 @@ public class Button extends Component {
|
|||||||
return isDisabled;
|
return isDisabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setText(String newText)
|
||||||
|
{
|
||||||
|
text = newText;
|
||||||
|
requestReassembly();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void assembleSelf(RenderTarget target) {
|
protected void assembleSelf(RenderTarget target) {
|
||||||
//Border
|
//Border
|
||||||
if (isClicked() || isHovered() || isFocused())
|
if (isDisabled())
|
||||||
{
|
|
||||||
target.fill(getX(), getY(), getWidth(), getHeight(), 0xFF37A2E6);
|
|
||||||
}
|
|
||||||
else if (!isDisabled())
|
|
||||||
{
|
|
||||||
target.fill(getX(), getY(), getWidth(), getHeight(), 0xFFCBCBD0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
target.fill(getX(), getY(), getWidth(), getHeight(), 0xFFE5E5E5);
|
target.fill(getX(), getY(), getWidth(), getHeight(), 0xFFE5E5E5);
|
||||||
}
|
}
|
||||||
|
else if (isClicked() || isHovered() || isFocused())
|
||||||
|
{
|
||||||
|
target.fill(getX(), getY(), getWidth(), getHeight(), 0xFF37A2E6);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
target.fill(getX(), getY(), getWidth(), getHeight(), 0xFFCBCBD0);
|
||||||
|
}
|
||||||
//Inside area
|
//Inside area
|
||||||
if (isHovered())
|
if (!isClicked() && isHovered() && !isDisabled())
|
||||||
{
|
{
|
||||||
target.fill(getX()+2, getY()+2, getWidth()-4, getHeight()-4, 0xFFC3E4F7);
|
target.fill(getX()+2, getY()+2, getWidth()-4, getHeight()-4, 0xFFC3E4F7);
|
||||||
}
|
}
|
||||||
else if (!isClicked())
|
else if (!isClicked() || isDisabled())
|
||||||
{
|
{
|
||||||
target.fill(getX()+2, getY()+2, getWidth()-4, getHeight()-4, Colors.WHITE);
|
target.fill(getX()+2, getY()+2, getWidth()-4, getHeight()-4, Colors.WHITE);
|
||||||
}
|
}
|
||||||
//text
|
//text
|
||||||
Font tempFont;
|
Font tempFont;
|
||||||
if (isClicked())
|
if (isDisabled())
|
||||||
|
{
|
||||||
|
tempFont = font.withColor(Colors.GRAY_A);
|
||||||
|
}
|
||||||
|
else if (isClicked())
|
||||||
{
|
{
|
||||||
tempFont = font.withColor(Colors.WHITE);
|
tempFont = font.withColor(Colors.WHITE);
|
||||||
}
|
}
|
||||||
else if (!isDisabled())
|
|
||||||
{
|
|
||||||
tempFont = font.withColor(Colors.BLACK);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tempFont = font.withColor(Colors.GRAY_A);
|
tempFont = font.withColor(Colors.BLACK);
|
||||||
}
|
}
|
||||||
target.pushTransform(new Mat4().identity().translate(getX(), getY(), -1000).scale(2));
|
target.pushTransform(new Mat4().identity().translate(getX(), getY(), -1000).scale(2));
|
||||||
target.addCustomRenderer(tempFont.assemble( (CharSequence) this.text, this.getWidth()));
|
target.addCustomRenderer(tempFont.assemble( (CharSequence) this.text, this.getWidth()));
|
||||||
|
@ -59,7 +59,11 @@ 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", b -> {}));
|
Button disableButton = new Button("TestButton", new Font().withColor(Colors.BLACK), "I'm in TestGUI", b -> {b.setDisable(!b.isDisabled());});
|
||||||
|
|
||||||
|
panel.addChild(disableButton);
|
||||||
|
|
||||||
|
panel.addChild(new Button("TestButton", new Font().withColor(Colors.BLACK), "I enable the above button", b -> {disableButton.setDisable(false);}));
|
||||||
|
|
||||||
panel.addChild(
|
panel.addChild(
|
||||||
new Label(
|
new Label(
|
||||||
|
Reference in New Issue
Block a user