Bettering the Button
Not really TPS is 20 now
This commit is contained in:
parent
f9aae94bbc
commit
5359b93738
@ -2,6 +2,8 @@ package ru.windcorp.progressia.client.graphics.gui;
|
|||||||
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import com.google.common.eventbus.Subscribe;
|
||||||
|
|
||||||
import glm.mat._4.Mat4;
|
import glm.mat._4.Mat4;
|
||||||
import glm.vec._2.i.Vec2i;
|
import glm.vec._2.i.Vec2i;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
@ -9,6 +11,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.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;
|
||||||
import ru.windcorp.progressia.client.graphics.input.KeyEvent;
|
import ru.windcorp.progressia.client.graphics.input.KeyEvent;
|
||||||
@ -20,19 +23,37 @@ public class Button extends Component {
|
|||||||
private Vec2i currentSize;
|
private Vec2i currentSize;
|
||||||
private String text;
|
private String text;
|
||||||
private boolean isDisabled;
|
private boolean isDisabled;
|
||||||
|
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) {//, InputListener<T> onClick, Class<? extends T> onClickClass) {
|
||||||
super(name);
|
super(name);
|
||||||
this.font = font;
|
this.font = font;
|
||||||
this.text = text;
|
this.text = text;
|
||||||
setPosition(400, 400);
|
setPreferredSize(107,34);
|
||||||
setSize(107,34);
|
|
||||||
//super.addListener(onClickClass, onClick);
|
//super.addListener(onClickClass, onClick);
|
||||||
|
|
||||||
|
addListener(new Object() {
|
||||||
|
@Subscribe
|
||||||
|
public void onHoverChanged(HoverEvent e) {
|
||||||
|
requestReassembly();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
addListener(new Object() {
|
||||||
|
@Subscribe
|
||||||
|
public void onLeftClick(KeyEvent e) {
|
||||||
|
if (e.isLeftMouseButton())
|
||||||
|
{
|
||||||
|
isClicked = e.isPress();
|
||||||
|
requestReassembly();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isClicked()
|
public boolean isClicked()
|
||||||
{
|
{
|
||||||
return super.containsCursor() && InputTracker.isKeyPressed(GLFW.GLFW_MOUSE_BUTTON_LEFT);
|
return containsCursor() && isClicked;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDisable(boolean isDisabled)
|
public void setDisable(boolean isDisabled)
|
||||||
@ -63,11 +84,11 @@ public class Button extends Component {
|
|||||||
//Inside area
|
//Inside area
|
||||||
if (isHovered())
|
if (isHovered())
|
||||||
{
|
{
|
||||||
target.fill(getX()+1, getY()+1, getWidth()-2, getHeight()-2, 0xFFC3E4F7);
|
target.fill(getX()+2, getY()+2, getWidth()-4, getHeight()-4, 0xFFC3E4F7);
|
||||||
}
|
}
|
||||||
else if (!isClicked())
|
else if (!isClicked())
|
||||||
{
|
{
|
||||||
target.fill(getX()+1, getY()+1, getWidth()-2, getHeight()-2, Colors.WHITE);
|
target.fill(getX()+2, getY()+2, getWidth()-4, getHeight()-4, Colors.WHITE);
|
||||||
}
|
}
|
||||||
//text
|
//text
|
||||||
Font tempFont;
|
Font tempFont;
|
||||||
|
@ -64,7 +64,7 @@ public class ServerThread implements Runnable {
|
|||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
ticker.start();
|
ticker.start();
|
||||||
executor.scheduleAtFixedRate(this, 0, 1000, TimeUnit.MILLISECONDS);
|
executor.scheduleAtFixedRate(this, 0, 1000 / 20, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -29,6 +29,7 @@ import ru.windcorp.progressia.client.graphics.font.Font;
|
|||||||
import ru.windcorp.progressia.client.graphics.gui.Button;
|
import ru.windcorp.progressia.client.graphics.gui.Button;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.DynamicLabel;
|
import ru.windcorp.progressia.client.graphics.gui.DynamicLabel;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.GUILayer;
|
import ru.windcorp.progressia.client.graphics.gui.GUILayer;
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.Button;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.Label;
|
import ru.windcorp.progressia.client.graphics.gui.Label;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.Panel;
|
import ru.windcorp.progressia.client.graphics.gui.Panel;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
|
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
|
||||||
@ -58,6 +59,8 @@ 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(
|
panel.addChild(
|
||||||
new Label(
|
new Label(
|
||||||
"IsFlyingDisplay",
|
"IsFlyingDisplay",
|
||||||
|
@ -18,9 +18,6 @@
|
|||||||
|
|
||||||
package ru.windcorp.progressia.test;
|
package ru.windcorp.progressia.test;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
@ -32,34 +29,18 @@ import ru.windcorp.progressia.client.graphics.Colors;
|
|||||||
import ru.windcorp.progressia.client.graphics.backend.GraphicsInterface;
|
import ru.windcorp.progressia.client.graphics.backend.GraphicsInterface;
|
||||||
import ru.windcorp.progressia.client.graphics.flat.AssembledFlatLayer;
|
import ru.windcorp.progressia.client.graphics.flat.AssembledFlatLayer;
|
||||||
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.gui.Button;
|
|
||||||
import ru.windcorp.progressia.client.graphics.gui.Label;
|
|
||||||
import ru.windcorp.progressia.client.graphics.input.KeyEvent;
|
import ru.windcorp.progressia.client.graphics.input.KeyEvent;
|
||||||
import ru.windcorp.progressia.client.graphics.input.bus.Input;
|
import ru.windcorp.progressia.client.graphics.input.bus.Input;
|
||||||
import ru.windcorp.progressia.client.graphics.model.LambdaModel;
|
import ru.windcorp.progressia.client.graphics.model.LambdaModel;
|
||||||
import ru.windcorp.progressia.client.graphics.texture.SimpleTextures;
|
import ru.windcorp.progressia.client.graphics.texture.SimpleTextures;
|
||||||
import ru.windcorp.progressia.client.graphics.texture.Texture;
|
import ru.windcorp.progressia.client.graphics.texture.Texture;
|
||||||
import ru.windcorp.progressia.client.graphics.world.Camera;
|
import ru.windcorp.progressia.client.graphics.world.Camera;
|
||||||
import ru.windcorp.progressia.client.localization.MutableString;
|
|
||||||
import ru.windcorp.progressia.client.localization.MutableStringLocalized;
|
|
||||||
|
|
||||||
public class LayerTestUI extends AssembledFlatLayer {
|
public class LayerTestUI extends AssembledFlatLayer {
|
||||||
|
|
||||||
private Button testButton;
|
|
||||||
private Label tl;
|
|
||||||
|
|
||||||
public LayerTestUI() {
|
public LayerTestUI() {
|
||||||
super("TestUI");
|
super("TestUI");
|
||||||
|
|
||||||
TestPlayerControls tpc = TestPlayerControls.getInstance();
|
|
||||||
|
|
||||||
testButton = new Button("TestButton", new Font().withColor(Colors.BLACK), "Hi");
|
|
||||||
tl = new Label(
|
|
||||||
"IsFlyingDisplay",
|
|
||||||
new Font().withColor(Colors.BLACK),
|
|
||||||
tmp_dynFormat("LayerTestGUI.IsFlyingDisplay", tpc::isFlying)
|
|
||||||
);
|
|
||||||
GraphicsInterface.subscribeToInputEvents(this);
|
GraphicsInterface.subscribeToInputEvents(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,8 +88,6 @@ public class LayerTestUI extends AssembledFlatLayer {
|
|||||||
);
|
);
|
||||||
target.popTransform();
|
target.popTransform();
|
||||||
|
|
||||||
testButton.requestReassembly();
|
|
||||||
|
|
||||||
drawCross(target);
|
drawCross(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,22 +158,4 @@ public class LayerTestUI extends AssembledFlatLayer {
|
|||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MutableString tmp_dynFormat(String formatKey, Supplier<?>... suppliers) {
|
|
||||||
return new MutableStringLocalized(formatKey).apply(s -> {
|
|
||||||
Object[] args = new Object[suppliers.length];
|
|
||||||
|
|
||||||
for (int i = 0; i < suppliers.length; ++i) {
|
|
||||||
Supplier<?> supplier = suppliers[i];
|
|
||||||
|
|
||||||
Object value = supplier != null ? supplier.get() : "null";
|
|
||||||
if (!(value instanceof Number)) {
|
|
||||||
value = Objects.toString(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
args[i] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return String.format(s, args);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user