Bettering the Button

Not really
TPS is 20 now
This commit is contained in:
opfromthestart 2021-04-17 08:07:01 -04:00
parent f9aae94bbc
commit 5359b93738
4 changed files with 32 additions and 47 deletions

View File

@ -2,6 +2,8 @@ package ru.windcorp.progressia.client.graphics.gui;
import java.util.function.Supplier;
import com.google.common.eventbus.Subscribe;
import glm.mat._4.Mat4;
import glm.vec._2.i.Vec2i;
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.font.Font;
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.InputEvent;
import ru.windcorp.progressia.client.graphics.input.KeyEvent;
@ -20,19 +23,37 @@ public class Button extends Component {
private Vec2i currentSize;
private String text;
private boolean isDisabled;
private boolean isClicked;
public <T extends InputEvent> Button(String name, Font font, String text) {//, InputListener<T> onClick, Class<? extends T> onClickClass) {
super(name);
this.font = font;
this.text = text;
setPosition(400, 400);
setSize(107,34);
setPreferredSize(107,34);
//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()
{
return super.containsCursor() && InputTracker.isKeyPressed(GLFW.GLFW_MOUSE_BUTTON_LEFT);
return containsCursor() && isClicked;
}
public void setDisable(boolean isDisabled)
@ -63,11 +84,11 @@ public class Button extends Component {
//Inside area
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())
{
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
Font tempFont;

View File

@ -64,7 +64,7 @@ public class ServerThread implements Runnable {
public void start() {
ticker.start();
executor.scheduleAtFixedRate(this, 0, 1000, TimeUnit.MILLISECONDS);
executor.scheduleAtFixedRate(this, 0, 1000 / 20, TimeUnit.MILLISECONDS);
}
@Override

View File

@ -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.DynamicLabel;
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.Panel;
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
@ -57,6 +58,8 @@ public class LayerTestGUI extends GUILayer {
Font font = new Font().withColor(color).deriveOutlined();
TestPlayerControls tpc = TestPlayerControls.getInstance();
panel.addChild(new Button("TestButton", new Font().withColor(Colors.BLACK), "I'm in TestGUI"));
panel.addChild(
new Label(

View File

@ -18,9 +18,6 @@
package ru.windcorp.progressia.test;
import java.util.Objects;
import java.util.function.Supplier;
import org.lwjgl.glfw.GLFW;
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.flat.AssembledFlatLayer;
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.bus.Input;
import ru.windcorp.progressia.client.graphics.model.LambdaModel;
import ru.windcorp.progressia.client.graphics.texture.SimpleTextures;
import ru.windcorp.progressia.client.graphics.texture.Texture;
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 {
private Button testButton;
private Label tl;
public LayerTestUI() {
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);
}
@ -106,9 +87,7 @@ public class LayerTestUI extends AssembledFlatLayer {
)
);
target.popTransform();
testButton.requestReassembly();
drawCross(target);
}
@ -178,23 +157,5 @@ public class LayerTestUI extends AssembledFlatLayer {
flag = event.isPress();
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);
});
}
}