diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/gui/Background.java b/src/main/java/ru/windcorp/progressia/client/graphics/gui/Background.java new file mode 100644 index 0000000..a3312dd --- /dev/null +++ b/src/main/java/ru/windcorp/progressia/client/graphics/gui/Background.java @@ -0,0 +1,28 @@ +package ru.windcorp.progressia.client.graphics.gui; + +import glm.mat._4.Mat4; +import glm.vec._3.Vec3; +import ru.windcorp.progressia.client.graphics.flat.RenderTarget; +import ru.windcorp.progressia.client.graphics.texture.Texture; + +public class Background extends GUILayer { + + protected Texture backgroundTexture; + + public Background(String name, Layout layout, Texture inTexture) { + super(name, layout); + + backgroundTexture = inTexture; + } + + @Override + protected void assemble(RenderTarget target) { + getRoot().setBounds(0, 0, getWidth(), getHeight()); + getRoot().invalidate(); + target.pushTransform(new Mat4(1).translate(new Vec3(0,0,500))); + target.drawTexture(0, 0, getWidth(), getHeight(), backgroundTexture); + target.popTransform(); + getRoot().assemble(target); + } + +} diff --git a/src/main/java/ru/windcorp/progressia/client/graphics/gui/TextureComponent.java b/src/main/java/ru/windcorp/progressia/client/graphics/gui/TextureComponent.java new file mode 100644 index 0000000..98c238b --- /dev/null +++ b/src/main/java/ru/windcorp/progressia/client/graphics/gui/TextureComponent.java @@ -0,0 +1,23 @@ +package ru.windcorp.progressia.client.graphics.gui; + +import ru.windcorp.progressia.client.graphics.flat.RenderTarget; +import ru.windcorp.progressia.client.graphics.texture.Texture; + +public class TextureComponent extends Component { + + private Texture texture; + + public TextureComponent(String name, Texture texture2) { + super(name); + + texture = texture2; + setPreferredSize(texture.getSprite().getWidth(),texture.getSprite().getHeight()); + } + + @Override + protected void assembleSelf(RenderTarget target) + { + target.drawTexture(getX(), getY(), getWidth(), getHeight(), texture); + } + +} diff --git a/src/main/java/ru/windcorp/progressia/test/CubeComponent.java b/src/main/java/ru/windcorp/progressia/test/CubeComponent.java index 8cc9331..cce31a2 100644 --- a/src/main/java/ru/windcorp/progressia/test/CubeComponent.java +++ b/src/main/java/ru/windcorp/progressia/test/CubeComponent.java @@ -13,17 +13,19 @@ import ru.windcorp.progressia.client.graphics.gui.Component; public class CubeComponent extends Component { private Mat4 transforms[]; + private Vec4[] normals; private final double pi2 = Math.PI/2; private final double r3 = Math.sqrt(3); private ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); - private int size = 100; + private int size = 250; public CubeComponent(String name) { super(name); transforms = new Mat4[6]; + normals = new Vec4[6]; setPreferredSize((int) Math.ceil(r3*size),(int) Math.ceil(r3*size)); executor.scheduleAtFixedRate(() -> requestReassembly(), 1, 60, TimeUnit.MILLISECONDS); } @@ -45,17 +47,24 @@ public class CubeComponent extends Component { long time = System.currentTimeMillis(); + normals[0] = new Vec4(0,0,-1,0); + normals[1] = new Vec4(0,1,0,0); + normals[2] = new Vec4(1,0,0,0); + normals[3] = new Vec4(0,0,1,0); + normals[4] = new Vec4(0,-1,0,0); + normals[5] = new Vec4(-1,0,0,0); + for (int i=0;i<6;i++) { - transforms[i].rotate((float) (time%(1000*6.28) )/ 1000, new Vec3(0,1,0)).rotate((float) (time%(6777*6.28) )/ 6777, new Vec3(1,0,0)); + normals[i] = transforms[i].rotate((float) (time%(6000*6.28) )/ 6000, new Vec3(0,1,0)).rotate((float) 24, new Vec3(1,.5,0)).mul_(normals[i]); } - transforms[0] = transforms[0].translate(new Vec3(-50,-50,60)); - transforms[1] = transforms[1].translate(new Vec3(-50,-60,-50)).rotate((float) pi2, new Vec3(1,0,0)); - transforms[2] = transforms[2].translate(new Vec3(-40,-50,50)).rotate((float) pi2, new Vec3(0,1,0)); - transforms[3] = transforms[3].translate(new Vec3(-50,-50,-40)); - transforms[4] = transforms[4].translate(new Vec3(-50,40,-50)).rotate((float) pi2, new Vec3(1,0,0)); - transforms[5] = transforms[5].translate(new Vec3(60,-50,50)).rotate((float) pi2, new Vec3(0,1,0)); + transforms[0].translate(new Vec3(-size/2,-size/2,size/2+13)); + transforms[1].translate(new Vec3(-size/2,-size/2-13,-size/2)).rotate((float) pi2, new Vec3(1,0,0)); + transforms[2].translate(new Vec3(-size/2+13,-size/2,size/2)).rotate((float) pi2, new Vec3(0,1,0)); + transforms[3].translate(new Vec3(-size/2,-size/2,-size/2+13)); + transforms[4].translate(new Vec3(-size/2,size/2-13,-size/2)).rotate((float) pi2, new Vec3(1,0,0)); + transforms[5].translate(new Vec3(size/2+13,-size/2,size/2)).rotate((float) pi2, new Vec3(0,1,0)); } @Override @@ -63,27 +72,17 @@ public class CubeComponent extends Component { { computeTransforms(); - int b=0; + target.pushTransform(new Mat4(1).translate(new Vec3(getX()+size*r3/2,getY()+size*r3/2,0))); - target.pushTransform(new Mat4(1).translate(new Vec3(size,size,0))); - - for (Mat4 tr : transforms) + for (int b=0; b<6;b++) { - target.pushTransform(tr); - switch (b%3) - { - case 0: - target.fill(0, 0, size, size, new Vec4(255,0,0,255)); - break; - case 1: - target.fill(0, 0, size, size, new Vec4(0,255,0,255)); - break; - case 2: - target.fill(0, 0, size, size, new Vec4(0,0,255,255)); - break; - } + target.pushTransform(transforms[b]); + + float dot = normals[b].dot(new Vec4(-1,0,0,0)); + Vec4 color = new Vec4(.4+.3*dot, .4+.3*dot, .6+.4*dot,1.0); + + target.fill(0,0, size, size, color); - b++; target.popTransform(); } diff --git a/src/main/java/ru/windcorp/progressia/test/LayerTitle.java b/src/main/java/ru/windcorp/progressia/test/LayerTitle.java index fd40e3a..850fb61 100644 --- a/src/main/java/ru/windcorp/progressia/test/LayerTitle.java +++ b/src/main/java/ru/windcorp/progressia/test/LayerTitle.java @@ -4,13 +4,15 @@ import ru.windcorp.progressia.client.ClientState; import ru.windcorp.progressia.client.graphics.Colors; import ru.windcorp.progressia.client.graphics.GUI; import ru.windcorp.progressia.client.graphics.font.Font; +import ru.windcorp.progressia.client.graphics.gui.Background; import ru.windcorp.progressia.client.graphics.gui.BasicButton; import ru.windcorp.progressia.client.graphics.gui.Button; -import ru.windcorp.progressia.client.graphics.gui.GUILayer; 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.LayoutVertical; +import ru.windcorp.progressia.client.graphics.texture.SimpleTextures; import ru.windcorp.progressia.client.localization.MutableString; import ru.windcorp.progressia.client.localization.MutableStringLocalized; import ru.windcorp.progressia.common.util.crash.CrashReports; @@ -24,17 +26,16 @@ import java.nio.file.Paths; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; -public class LayerTitle extends GUILayer { +public class LayerTitle extends Background { private final BasicButton resetButton; public LayerTitle(String name) { - super(name, new LayoutAlign(0.5f, 0.7f, 15)); + super(name, new LayoutAlign(0.5f, 0.7f, 15), SimpleTextures.get("title/background")); Group content = new Group("Layer" + name + ".Group", new LayoutVertical(15)); - MutableString title = new MutableStringLocalized("Layer" + name + ".Title"); - Font titleFont = new Font().deriveBold().withColor(Colors.BLACK).withAlign(0.5f); - content.addChild(new Label(name + ".Title", titleFont, title)); + Font titleFont = new Font().deriveBold().withColor(Colors.BLUE).withAlign(0.5f); + content.addChild(new TextureComponent(name + ".Title", SimpleTextures.get("title/progressia"))); Font buttonFont = titleFont.deriveNotBold(); MutableString playText = new MutableStringLocalized("Layer" + name + ".Play"); diff --git a/src/main/resources/assets/textures/title/background.png b/src/main/resources/assets/textures/title/background.png new file mode 100644 index 0000000..21b7d76 Binary files /dev/null and b/src/main/resources/assets/textures/title/background.png differ diff --git a/src/main/resources/assets/textures/title/progressia.png b/src/main/resources/assets/textures/title/progressia.png new file mode 100644 index 0000000..7d8ff7c Binary files /dev/null and b/src/main/resources/assets/textures/title/progressia.png differ