diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/gui/Button.java b/src/main/java/ru/windcorp/progressia/client/graphics/gui/Button.java index a09022a..ed87fd1 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/gui/Button.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/gui/Button.java @@ -4,8 +4,11 @@ import java.util.function.Supplier; import glm.mat._4.Mat4; 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.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.InputEvent; import ru.windcorp.progressia.client.graphics.input.KeyEvent; @@ -16,18 +19,72 @@ public class Button extends Component { private String currentText; private Vec2i currentSize; private String text; + private boolean isDisabled; - public Button(String name, Font font, String text, InputListener onClick, Class onClickClass) { + public Button(String name, Font font, String text) {//, InputListener onClick, Class onClickClass) { super(name); this.font = font; 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 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.addCustomRenderer(font.assembleDynamic(getContentSupplier(), Float.POSITIVE_INFINITY)); + target.addCustomRenderer(tempFont.assemble( (CharSequence) this.text, this.getWidth())); target.popTransform(); } } diff --git a/src/main/java/ru/windcorp/progressia/test/LayerTestGUI.java b/src/main/java/ru/windcorp/progressia/test/LayerTestGUI.java index 91a3df7..7bb1bce 100755 --- a/src/main/java/ru/windcorp/progressia/test/LayerTestGUI.java +++ b/src/main/java/ru/windcorp/progressia/test/LayerTestGUI.java @@ -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.GraphicsInterface; 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.Label; diff --git a/src/main/java/ru/windcorp/progressia/test/LayerTestUI.java b/src/main/java/ru/windcorp/progressia/test/LayerTestUI.java index c93a055..686a72e 100755 --- a/src/main/java/ru/windcorp/progressia/test/LayerTestUI.java +++ b/src/main/java/ru/windcorp/progressia/test/LayerTestUI.java @@ -18,6 +18,9 @@ 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; @@ -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.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); } @@ -87,7 +106,9 @@ public class LayerTestUI extends AssembledFlatLayer { ) ); target.popTransform(); - + + testButton.requestReassembly(); + drawCross(target); } @@ -157,5 +178,23 @@ 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); + }); + } } diff --git a/src/main/resources/assets/textures/all_buttons.png b/src/main/resources/assets/textures/all_buttons.png new file mode 100644 index 0000000..f9aa91a Binary files /dev/null and b/src/main/resources/assets/textures/all_buttons.png differ