Button things
Moved button to LayerTestUI Saved all_buttons.png in resources Idk it still wont render the button
This commit is contained in:
parent
468b6dc327
commit
5c57a57e9a
@ -4,8 +4,11 @@ import java.util.function.Supplier;
|
|||||||
|
|
||||||
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 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.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;
|
||||||
@ -16,18 +19,72 @@ public class Button extends Component {
|
|||||||
private String currentText;
|
private String currentText;
|
||||||
private Vec2i currentSize;
|
private Vec2i currentSize;
|
||||||
private String text;
|
private String text;
|
||||||
|
private boolean isDisabled;
|
||||||
|
|
||||||
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;
|
||||||
super.addListener(onClickClass, onClick);
|
setPosition(400, 400);
|
||||||
|
setSize(107,34);
|
||||||
|
//super.addListener(onClickClass, onClick);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isClicked()
|
||||||
|
{
|
||||||
|
return super.containsCursor() && InputTracker.isKeyPressed(GLFW.GLFW_MOUSE_BUTTON_LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisable(boolean isDisabled)
|
||||||
|
{
|
||||||
|
this.isDisabled = isDisabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDisabled()
|
||||||
|
{
|
||||||
|
return isDisabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void assembleSelf(RenderTarget target) {
|
protected void assembleSelf(RenderTarget target) {
|
||||||
|
//Border
|
||||||
|
if (isClicked() || isHovered() || isFocused())
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
//Inside area
|
||||||
|
if (isHovered())
|
||||||
|
{
|
||||||
|
target.fill(getX()+1, getY()+1, getWidth()-2, getHeight()-2, 0xFFC3E4F7);
|
||||||
|
}
|
||||||
|
else if (!isClicked())
|
||||||
|
{
|
||||||
|
target.fill(getX()+1, getY()+1, getWidth()-2, getHeight()-2, Colors.WHITE);
|
||||||
|
}
|
||||||
|
//text
|
||||||
|
Font tempFont;
|
||||||
|
if (isClicked())
|
||||||
|
{
|
||||||
|
tempFont = font.withColor(Colors.WHITE);
|
||||||
|
}
|
||||||
|
else if (!isDisabled())
|
||||||
|
{
|
||||||
|
tempFont = font.withColor(Colors.BLACK);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tempFont = font.withColor(Colors.GRAY_A);
|
||||||
|
}
|
||||||
target.pushTransform(new Mat4().identity().translate(getX(), getY(), -1000).scale(2));
|
target.pushTransform(new Mat4().identity().translate(getX(), getY(), -1000).scale(2));
|
||||||
target.addCustomRenderer(font.assembleDynamic(getContentSupplier(), Float.POSITIVE_INFINITY));
|
target.addCustomRenderer(tempFont.assemble( (CharSequence) this.text, this.getWidth()));
|
||||||
target.popTransform();
|
target.popTransform();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import ru.windcorp.progressia.client.graphics.Colors;
|
|||||||
import ru.windcorp.progressia.client.graphics.backend.GraphicsBackend;
|
import ru.windcorp.progressia.client.graphics.backend.GraphicsBackend;
|
||||||
import ru.windcorp.progressia.client.graphics.backend.GraphicsInterface;
|
import ru.windcorp.progressia.client.graphics.backend.GraphicsInterface;
|
||||||
import ru.windcorp.progressia.client.graphics.font.Font;
|
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.DynamicLabel;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.GUILayer;
|
import ru.windcorp.progressia.client.graphics.gui.GUILayer;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.Label;
|
import ru.windcorp.progressia.client.graphics.gui.Label;
|
||||||
|
@ -18,6 +18,9 @@
|
|||||||
|
|
||||||
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;
|
||||||
@ -29,18 +32,34 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +106,9 @@ public class LayerTestUI extends AssembledFlatLayer {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
target.popTransform();
|
target.popTransform();
|
||||||
|
|
||||||
|
testButton.requestReassembly();
|
||||||
|
|
||||||
drawCross(target);
|
drawCross(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,5 +178,23 @@ public class LayerTestUI extends AssembledFlatLayer {
|
|||||||
flag = event.isPress();
|
flag = event.isPress();
|
||||||
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
BIN
src/main/resources/assets/textures/all_buttons.png
Normal file
BIN
src/main/resources/assets/textures/all_buttons.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 94 KiB |
Reference in New Issue
Block a user