From 7a04b439ac7eed268660e4de803d2607cfff0f05 Mon Sep 17 00:00:00 2001 From: Allexit Date: Mon, 11 May 2015 15:09:11 +0300 Subject: [PATCH] Unfinished rendering system for GUI --- build.gradle | 17 --------------- .../saltosion/gladiator/GladiatorBrawler.java | 1 + .../com/saltosion/gladiator/gui/GUINode.java | 4 ++++ .../gladiator/systems/RenderingSystem.java | 21 +++++++++++++++++++ settings.gradle | 2 +- 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/build.gradle b/build.gradle index 33db62a..08fee70 100644 --- a/build.gradle +++ b/build.gradle @@ -2,10 +2,8 @@ buildscript { repositories { mavenCentral() maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } - jcenter() } dependencies { - classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6' } } @@ -42,21 +40,6 @@ project(":desktop") { } } -project(":html") { - apply plugin: "gwt" - apply plugin: "war" - - - dependencies { - compile project(":core") - compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion" - compile "com.badlogicgames.gdx:gdx:$gdxVersion:sources" - compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources" - compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion:sources" - compile "com.badlogicgames.gdx:gdx-box2d-gwt:$gdxVersion:sources" - compile "com.badlogicgames.ashley:ashley:$ashleyVersion:sources" - } -} project(":core") { apply plugin: "java" diff --git a/core/src/com/saltosion/gladiator/GladiatorBrawler.java b/core/src/com/saltosion/gladiator/GladiatorBrawler.java index d80dc84..1d17de8 100644 --- a/core/src/com/saltosion/gladiator/GladiatorBrawler.java +++ b/core/src/com/saltosion/gladiator/GladiatorBrawler.java @@ -188,6 +188,7 @@ public class GladiatorBrawler extends ApplicationAdapter { super.resize(width, height); RenderingSystem rs = engine.getSystem(RenderingSystem.class); float aspectratio = ((float) width) / ((float) height); + rs.aspectratio = aspectratio; rs.setViewport((int) (AppUtil.VPHEIGHT_CONST * aspectratio), AppUtil.VPHEIGHT_CONST); } } diff --git a/core/src/com/saltosion/gladiator/gui/GUINode.java b/core/src/com/saltosion/gladiator/gui/GUINode.java index b11de33..fcfd466 100644 --- a/core/src/com/saltosion/gladiator/gui/GUINode.java +++ b/core/src/com/saltosion/gladiator/gui/GUINode.java @@ -54,6 +54,10 @@ public class GUINode { return this; } + public ArrayList getChildren() { + return this.children; + } + public Vector2 getPosition() { return this.position; } diff --git a/core/src/com/saltosion/gladiator/systems/RenderingSystem.java b/core/src/com/saltosion/gladiator/systems/RenderingSystem.java index 0f2c6a1..17f8534 100644 --- a/core/src/com/saltosion/gladiator/systems/RenderingSystem.java +++ b/core/src/com/saltosion/gladiator/systems/RenderingSystem.java @@ -15,9 +15,13 @@ import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType; +import com.badlogic.gdx.math.Vector2; import com.saltosion.gladiator.components.CPhysics; import com.saltosion.gladiator.components.CRenderedObject; +import com.saltosion.gladiator.gui.GUINode; +import com.saltosion.gladiator.gui.ImageNode; import com.saltosion.gladiator.util.AppUtil; +import com.saltosion.gladiator.util.Log; import com.saltosion.gladiator.util.SpriteSequence; public class RenderingSystem extends EntitySystem { @@ -30,6 +34,7 @@ public class RenderingSystem extends EntitySystem { private BitmapFont font; private ShapeRenderer debugRenderer; private OrthographicCamera camera; + public float aspectratio; private boolean debug = true; private final Color debugColor = new Color(0, 1, 0, 1); @@ -79,6 +84,8 @@ public class RenderingSystem extends EntitySystem { float nextFrame = renderedObject.getCurrentFrame() + deltaTime * currSequence.getPlayspeed(); renderedObject.setCurrentFrame(nextFrame % currSequence.frameCount()); } + renderGUINode(AppUtil.guiManager.getRootNode(), Vector2.Zero); + batch.end(); if (debug) { @@ -100,6 +107,20 @@ public class RenderingSystem extends EntitySystem { debugRenderer.end(); } } + + public void renderGUINode(GUINode node, Vector2 position) { + position.add(node.getPosition()); + if (node instanceof ImageNode) { + Log.info("Node found with ImageNode"); + Sprite s = ((ImageNode) node).getImage(); + s.setPosition(position.x*AppUtil.VPHEIGHT_CONST*aspectratio+camera.position.x, + position.y*AppUtil.VPHEIGHT_CONST+camera.position.y); + s.draw(batch); + } + for (GUINode child : node.getChildren()) { + renderGUINode(child, position); + } + } public void updateEntities(Engine engine) { entities = engine.getEntitiesFor(Family.getFor(CRenderedObject.class, CPhysics.class)); diff --git a/settings.gradle b/settings.gradle index 7c74fc5..74fc652 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include 'desktop', 'html', 'core' \ No newline at end of file +include 'desktop', 'core' \ No newline at end of file