diff --git a/logs/game.log b/logs/game.log new file mode 100644 index 0000000..7244071 --- /dev/null +++ b/logs/game.log @@ -0,0 +1 @@ +22:26:25.948 [Music Thread ] WARN ru.windcorp.progressia.test.TestMusicPlayer > No music found 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 5d42241..e5bc3ef 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 @@ -23,6 +23,10 @@ import ru.windcorp.progressia.client.graphics.flat.RenderTarget; import ru.windcorp.progressia.client.graphics.font.Font; import ru.windcorp.progressia.client.graphics.Colors; +/** Class for a traditional button that gets clicked to activate + * + * @author opfromthestart + */ public class Button extends BasicButton { public Button(String name, String label, Font labelFont) { diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutAlign.java b/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutAlign.java index d521914..3c75711 100644 --- a/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutAlign.java +++ b/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutAlign.java @@ -27,8 +27,8 @@ import ru.windcorp.progressia.client.graphics.gui.Layout; public class LayoutAlign implements Layout { - private final int margin; - private double alignX, alignY; + protected final int margin; + protected double alignX, alignY; public LayoutAlign(double alignX, double alignY, int margin) { this.alignX = alignX; diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutEdges.java b/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutEdges.java new file mode 100644 index 0000000..2265411 --- /dev/null +++ b/src/main/java/ru/windcorp/progressia/client/graphics/gui/layout/LayoutEdges.java @@ -0,0 +1,60 @@ +package ru.windcorp.progressia.client.graphics.gui.layout; + +import glm.vec._2.i.Vec2i; +import ru.windcorp.progressia.client.graphics.gui.Component; +import ru.windcorp.progressia.client.graphics.gui.Layout; +import ru.windcorp.progressia.client.localization.MutableStringLocalized; + +import static java.lang.Math.max; +import static java.lang.Math.min; + +public class LayoutEdges implements Layout { + + private int margin; + + public LayoutEdges(int margin) { + this.margin = margin; + } + + @Override + public void layout(Component c) { + for (int i=0;i<2;i++) + { + Component child = c.getChild(i); + + Vec2i size = child.getPreferredSize(); + + int cWidth = c.getWidth() - 2 * margin; + int cHeight = c.getHeight() - 2 * margin; + + size.x = min(size.x, cWidth); + size.y = min(size.y, cHeight); + + if (i==0) { + child.setBounds( + c.getX() + margin, + c.getY(), + size + ); + } else { + child.setBounds( + 1920 - size.x - margin, + c.getY(), + size + ); + } + + } + } + + @Override + public Vec2i calculatePreferredSize(Component c) { + Vec2i result = new Vec2i(1920,0); + c.getChildren().stream() + .map(child -> child.getPreferredSize()) + .forEach(size -> { + result.y = max(Math.abs(size.y), result.y); + }); + return result; + } +} diff --git a/src/main/java/ru/windcorp/progressia/test/CubeComponent.java b/src/main/java/ru/windcorp/progressia/test/CubeComponent.java index 90eaf30..e3c029c 100644 --- a/src/main/java/ru/windcorp/progressia/test/CubeComponent.java +++ b/src/main/java/ru/windcorp/progressia/test/CubeComponent.java @@ -21,9 +21,14 @@ public class CubeComponent extends Component { private ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); private int size = 400; - - public CubeComponent(String name) { + + public CubeComponent(String name) + { + this(name, 400); + } + public CubeComponent(String name, int size) { super(name); + this.size = size; transforms = new Mat4[6]; normals = new Vec4[6]; setPreferredSize((int) Math.ceil(r3*size),(int) Math.ceil(r3*size)); diff --git a/src/main/java/ru/windcorp/progressia/test/LayerAbout.java b/src/main/java/ru/windcorp/progressia/test/LayerAbout.java index fae2357..36d1b65 100644 --- a/src/main/java/ru/windcorp/progressia/test/LayerAbout.java +++ b/src/main/java/ru/windcorp/progressia/test/LayerAbout.java @@ -30,6 +30,8 @@ import ru.windcorp.progressia.client.localization.MutableStringLocalized; public class LayerAbout extends GUILayer { + public static String version = "pre-alpha 3"; + public LayerAbout() { super("LayerAbout", new LayoutAlign(1, 1, 5)); @@ -50,7 +52,7 @@ public class LayerAbout extends GUILayer { new Label( "Version", font, - new MutableStringLocalized("LayerAbout.Version").format("pre-alpha 3") + new MutableStringLocalized("LayerAbout.Version").format(version) ) ); diff --git a/src/main/java/ru/windcorp/progressia/test/LayerTitle.java b/src/main/java/ru/windcorp/progressia/test/LayerTitle.java index baa5e06..101712d 100644 --- a/src/main/java/ru/windcorp/progressia/test/LayerTitle.java +++ b/src/main/java/ru/windcorp/progressia/test/LayerTitle.java @@ -11,6 +11,7 @@ import ru.windcorp.progressia.client.graphics.gui.Group; import ru.windcorp.progressia.client.graphics.gui.Label; import ru.windcorp.progressia.client.graphics.gui.TextureComponent; import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign; +import ru.windcorp.progressia.client.graphics.gui.layout.LayoutEdges; import ru.windcorp.progressia.client.graphics.gui.layout.LayoutVertical; import ru.windcorp.progressia.client.graphics.texture.SimpleTextures; import ru.windcorp.progressia.client.localization.MutableString; @@ -33,11 +34,28 @@ public class LayerTitle extends Background { public LayerTitle(String name) { super(name, new LayoutAlign(0, 1f, 15), SimpleTextures.get("title/background")); Group content = new Group("Layer" + name + ".Group", new LayoutVertical(15)); - Group buttonContent = new Group("Layer" + name + ".ButtonGroup", new LayoutVertical(15)); + Group info = new Group("Layer"+name+".InfoGroup", new LayoutEdges(30)); + Group buttonContent = new Group("Layer" + name + ".ButtonGroup", new LayoutColumn(15, 320)); Font titleFont = new Font().deriveBold().withColor(Colors.BLUE).withAlign(0.5f); content.addChild(new TextureComponent(name + ".Title", SimpleTextures.get("title/progressia"))); + info.addChild(new Label( + "About", + titleFont, + new MutableStringLocalized("LayerAbout.Title") + ) + ); + + info.addChild( + new Label( + "Version", + titleFont, + new MutableStringLocalized("LayerAbout.Version").format(LayerAbout.version) + ) + ); + content.addChild(info); + Font buttonFont = titleFont.deriveNotBold(); MutableString playText = new MutableStringLocalized("Layer" + name + ".Play"); buttonContent.addChild(new Button(name + ".Play", new Label(name + ".Play", buttonFont, playText)).addAction(this::startGame)); @@ -57,7 +75,7 @@ public class LayerTitle extends Background { getRoot().addChild(content); buttonContent.setPreferredSize(500, 1000); - CubeComponent cube = new CubeComponent(name+".Cube"); + CubeComponent cube = new CubeComponent(name+".Cube",300); getRoot().addChild(cube); } diff --git a/src/main/java/ru/windcorp/progressia/test/LayoutColumn.java b/src/main/java/ru/windcorp/progressia/test/LayoutColumn.java new file mode 100644 index 0000000..7a87cac --- /dev/null +++ b/src/main/java/ru/windcorp/progressia/test/LayoutColumn.java @@ -0,0 +1,36 @@ +package ru.windcorp.progressia.test; + +import glm.vec._2.i.Vec2i; +import ru.windcorp.progressia.client.graphics.gui.Component; +import ru.windcorp.progressia.client.graphics.gui.layout.LayoutVertical; + +import static java.lang.Math.min; + +public class LayoutColumn extends LayoutVertical { + + protected int maxWidth; + private int margin; + + public LayoutColumn(int gap, int maxWidth) + { + super(gap); + this.maxWidth = maxWidth; + margin = gap; + } + + @Override + public void layout(Component c) { + int x = c.getX() + margin, + y = c.getY() + c.getHeight(); + + synchronized (c.getChildren()) { + for (Component child : c.getChildren()) { + + int height = child.getPreferredSize().y; + y -= margin + height; + child.setBounds(x, y, maxWidth, height); + + } + } + } +}