Added TextNode and Property to the gui system.

This commit is contained in:
Jeasonfire 2015-05-13 22:19:09 +03:00
parent 43ca403385
commit d3092a17ec
12 changed files with 57 additions and 48 deletions

View File

@ -13,6 +13,9 @@ import com.saltosion.gladiator.components.CPhysics;
import com.saltosion.gladiator.components.CRenderedObject; import com.saltosion.gladiator.components.CRenderedObject;
import com.saltosion.gladiator.gui.ButtonNode; import com.saltosion.gladiator.gui.ButtonNode;
import com.saltosion.gladiator.gui.GUIManager; import com.saltosion.gladiator.gui.GUIManager;
import com.saltosion.gladiator.gui.GUINode;
import com.saltosion.gladiator.gui.TextNode;
import com.saltosion.gladiator.gui.TextProperty;
import com.saltosion.gladiator.input.InputHandler; import com.saltosion.gladiator.input.InputHandler;
import com.saltosion.gladiator.listeners.CombatListener; import com.saltosion.gladiator.listeners.CombatListener;
import com.saltosion.gladiator.listeners.ai.DummyAI; import com.saltosion.gladiator.listeners.ai.DummyAI;
@ -202,6 +205,10 @@ public class GladiatorBrawler extends ApplicationAdapter {
}; };
button.setPosition(0.12f, 0.5f); button.setPosition(0.12f, 0.5f);
guiManager.getRootNode().addChild(button); guiManager.getRootNode().addChild(button);
TextNode text = new TextNode("test-text", "Test!");
text.setPosition(0.01f, 0.99f);
guiManager.getRootNode().addChild(text);
} }
@Override @Override

View File

@ -3,10 +3,6 @@ package com.saltosion.gladiator.components;
import com.badlogic.ashley.core.Component; import com.badlogic.ashley.core.Component;
import com.saltosion.gladiator.listeners.AIListener; import com.saltosion.gladiator.listeners.AIListener;
/**
*
* @author Jens "Jeasonfire" Pitkänen <jeasonfire@gmail.com>
*/
public class CAI extends Component { public class CAI extends Component {
private AIListener listener; private AIListener listener;

View File

@ -0,0 +1,17 @@
package com.saltosion.gladiator.gui;
public class TextNode extends GUINode implements TextProperty {
private String text;
public TextNode(String ID, String text) {
super(ID);
this.text = text;
}
@Override
public String getText() {
return text;
}
}

View File

@ -0,0 +1,7 @@
package com.saltosion.gladiator.gui;
public interface TextProperty {
public String getText();
}

View File

@ -3,10 +3,6 @@ package com.saltosion.gladiator.input;
import com.saltosion.gladiator.systems.RenderingSystem; import com.saltosion.gladiator.systems.RenderingSystem;
import com.saltosion.gladiator.util.AppUtil; import com.saltosion.gladiator.util.AppUtil;
/**
*
* @author Jens "Jeasonfire" Pitkänen <jeasonfire@gmail.com>
*/
public class IRDebugToggle implements InputReceiver { public class IRDebugToggle implements InputReceiver {
@Override @Override

View File

@ -3,10 +3,6 @@ package com.saltosion.gladiator.listeners;
import com.badlogic.ashley.core.Entity; import com.badlogic.ashley.core.Entity;
import java.util.ArrayList; import java.util.ArrayList;
/**
*
* @author Jens "Jeasonfire" Pitkänen <jeasonfire@gmail.com>
*/
public interface AIListener { public interface AIListener {
/** /**

View File

@ -3,21 +3,17 @@ package com.saltosion.gladiator.listeners;
import com.badlogic.ashley.core.Entity; import com.badlogic.ashley.core.Entity;
import com.saltosion.gladiator.util.Direction; import com.saltosion.gladiator.util.Direction;
/**
*
* @author Jens "Jeasonfire" Pitkänen <jeasonfire@gmail.com>
*/
public interface CollisionListener { public interface CollisionListener {
/** /**
* This method will be called when host collides with other * This method will be called when host collides with other
* *
* @param side The side which host is colliding other with. Eg. if host is * @param side The side which host is colliding other with. Eg. if host is
* falling towards other, this argument will be CollisionSide.BOTTOM when * falling towards other, this argument will be CollisionSide.BOTTOM when
* the collision happens. * the collision happens.
* @param host * @param host
* @param other * @param other
*/ */
public void collision(Direction side, Entity host, Entity other); public void collision(Direction side, Entity host, Entity other);
} }

View File

@ -8,10 +8,6 @@ import com.saltosion.gladiator.listeners.AIListener;
import com.saltosion.gladiator.util.Direction; import com.saltosion.gladiator.util.Direction;
import java.util.ArrayList; import java.util.ArrayList;
/**
*
* @author Jens "Jeasonfire" Pitkänen <jeasonfire@gmail.com>
*/
public class DummyAI implements AIListener { public class DummyAI implements AIListener {
private static final ComponentMapper<CPhysics> pm = ComponentMapper.getFor(CPhysics.class); private static final ComponentMapper<CPhysics> pm = ComponentMapper.getFor(CPhysics.class);

View File

@ -11,10 +11,6 @@ import com.saltosion.gladiator.components.CCombat;
import com.saltosion.gladiator.components.CPhysics; import com.saltosion.gladiator.components.CPhysics;
import java.util.ArrayList; import java.util.ArrayList;
/**
*
* @author Jens "Jeasonfire" Pitkänen <jeasonfire@gmail.com>
*/
public class AISystem extends EntitySystem { public class AISystem extends EntitySystem {
private static final ComponentMapper<CPhysics> pm = ComponentMapper.getFor(CPhysics.class); private static final ComponentMapper<CPhysics> pm = ComponentMapper.getFor(CPhysics.class);

View File

@ -10,10 +10,6 @@ import com.saltosion.gladiator.components.CCombat;
import com.saltosion.gladiator.components.CPhysics; import com.saltosion.gladiator.components.CPhysics;
import com.saltosion.gladiator.util.Direction; import com.saltosion.gladiator.util.Direction;
/**
*
* @author Jens "Jeasonfire" Pitkänen <jeasonfire@gmail.com>
*/
public class PhysicsSystem extends EntitySystem { public class PhysicsSystem extends EntitySystem {
private static final float MAX_VEL = 0.5f; private static final float MAX_VEL = 0.5f;

View File

@ -21,8 +21,11 @@ import com.saltosion.gladiator.components.CPhysics;
import com.saltosion.gladiator.components.CRenderedObject; import com.saltosion.gladiator.components.CRenderedObject;
import com.saltosion.gladiator.gui.GUINode; import com.saltosion.gladiator.gui.GUINode;
import com.saltosion.gladiator.gui.ImageNode; import com.saltosion.gladiator.gui.ImageNode;
import com.saltosion.gladiator.gui.TextNode;
import com.saltosion.gladiator.gui.TextProperty;
import com.saltosion.gladiator.util.AppUtil; import com.saltosion.gladiator.util.AppUtil;
import com.saltosion.gladiator.util.Global; import com.saltosion.gladiator.util.Global;
import com.saltosion.gladiator.util.Log;
import com.saltosion.gladiator.util.SpriteSequence; import com.saltosion.gladiator.util.SpriteSequence;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -54,7 +57,7 @@ public class RenderingSystem extends EntitySystem {
batch = new SpriteBatch(); batch = new SpriteBatch();
font = new BitmapFont(Gdx.files.internal("fonts/roman.fnt")); font = new BitmapFont(Gdx.files.internal("fonts/roman.fnt"));
font.setUseIntegerPositions(true); font.setUseIntegerPositions(false);
debugRenderer = new ShapeRenderer(); debugRenderer = new ShapeRenderer();
@ -77,20 +80,20 @@ public class RenderingSystem extends EntitySystem {
CPhysics phys = pm.get(AppUtil.player); CPhysics phys = pm.get(AppUtil.player);
camera.position.set(phys.getPosition().x, phys.getPosition().y, 0); camera.position.set(phys.getPosition().x, phys.getPosition().y, 0);
camera.update(); camera.update();
fontCamera.position.set(phys.getPosition().x * Global.FONT_SCALE, phys.getPosition().y * Global.FONT_SCALE, 0); fontCamera.position.set(camera.position.x * Global.FONT_SCALE, camera.position.y * Global.FONT_SCALE, 0);
fontCamera.update(); fontCamera.update();
Gdx.gl.glClearColor(0, 0, 0, 0); Gdx.gl.glClearColor(0, 0, 0, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.setProjectionMatrix(camera.combined);
renderEntities(deltaTime); renderEntities(deltaTime);
renderGUI(Vector2.Zero); renderGUI(new Vector2(0, 0));
renderDebug(camera); renderDebug(camera);
renderFont(fontCamera); renderFont(fontCamera);
} }
private void renderEntities(float deltaTime) { private void renderEntities(float deltaTime) {
batch.setProjectionMatrix(camera.combined);
batch.begin(); batch.begin();
for (int i = 0; i < entities.size(); i++) { for (int i = 0; i < entities.size(); i++) {
CRenderedObject renderedObject = rom.get(entities.get(i)); CRenderedObject renderedObject = rom.get(entities.get(i));
@ -114,6 +117,7 @@ public class RenderingSystem extends EntitySystem {
} }
private void renderGUI(Vector2 rootPosition) { private void renderGUI(Vector2 rootPosition) {
batch.setProjectionMatrix(camera.combined);
batch.begin(); batch.begin();
renderGUINode(AppUtil.guiManager.getRootNode(), rootPosition); renderGUINode(AppUtil.guiManager.getRootNode(), rootPosition);
batch.end(); batch.end();
@ -127,8 +131,14 @@ public class RenderingSystem extends EntitySystem {
position.y * AppUtil.VPHEIGHT_CONST - s.getHeight() / 2 + camera.position.y); position.y * AppUtil.VPHEIGHT_CONST - s.getHeight() / 2 + camera.position.y);
s.draw(batch); s.draw(batch);
} }
if (node instanceof TextNode) {
Log.info("X: " + position.x);
Log.info("Y: " + position.y);
drawString(((TextProperty) node).getText(), new Vector2(position.x * AppUtil.VPHEIGHT_CONST * aspectratio + camera.position.x,
position.y * AppUtil.VPHEIGHT_CONST + camera.position.y));
}
for (GUINode child : node.getChildren()) { for (GUINode child : node.getChildren()) {
renderGUINode(child, position); renderGUINode(child, new Vector2(position));
} }
} }
@ -164,7 +174,7 @@ public class RenderingSystem extends EntitySystem {
batch.setProjectionMatrix(fontCamera.combined); batch.setProjectionMatrix(fontCamera.combined);
batch.begin(); batch.begin();
for (TextObject obj : drawableText) { for (TextObject obj : drawableText) {
font.draw(batch, obj.text, obj.position.x / Global.FONT_SCALE, obj.position.y / Global.FONT_SCALE); font.draw(batch, obj.text, obj.position.x * Global.FONT_SCALE, obj.position.y * Global.FONT_SCALE);
} }
drawableText.clear(); drawableText.clear();
batch.end(); batch.end();

View File

@ -1,9 +1,5 @@
package com.saltosion.gladiator.util; package com.saltosion.gladiator.util;
/**
*
* @author Jens "Jeasonfire" Pitkänen <jeasonfire@gmail.com>
*/
public enum Direction { public enum Direction {
UP, DOWN, LEFT, RIGHT, CENTRE UP, DOWN, LEFT, RIGHT, CENTRE