Added TextNode and Property to the gui system.
This commit is contained in:
parent
43ca403385
commit
d3092a17ec
@ -13,6 +13,9 @@ import com.saltosion.gladiator.components.CPhysics;
|
||||
import com.saltosion.gladiator.components.CRenderedObject;
|
||||
import com.saltosion.gladiator.gui.ButtonNode;
|
||||
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.listeners.CombatListener;
|
||||
import com.saltosion.gladiator.listeners.ai.DummyAI;
|
||||
@ -202,6 +205,10 @@ public class GladiatorBrawler extends ApplicationAdapter {
|
||||
};
|
||||
button.setPosition(0.12f, 0.5f);
|
||||
guiManager.getRootNode().addChild(button);
|
||||
|
||||
TextNode text = new TextNode("test-text", "Test!");
|
||||
text.setPosition(0.01f, 0.99f);
|
||||
guiManager.getRootNode().addChild(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,10 +3,6 @@ package com.saltosion.gladiator.components;
|
||||
import com.badlogic.ashley.core.Component;
|
||||
import com.saltosion.gladiator.listeners.AIListener;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jens "Jeasonfire" Pitkänen <jeasonfire@gmail.com>
|
||||
*/
|
||||
public class CAI extends Component {
|
||||
|
||||
private AIListener listener;
|
||||
|
17
core/src/com/saltosion/gladiator/gui/TextNode.java
Normal file
17
core/src/com/saltosion/gladiator/gui/TextNode.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
7
core/src/com/saltosion/gladiator/gui/TextProperty.java
Normal file
7
core/src/com/saltosion/gladiator/gui/TextProperty.java
Normal file
@ -0,0 +1,7 @@
|
||||
package com.saltosion.gladiator.gui;
|
||||
|
||||
public interface TextProperty {
|
||||
|
||||
public String getText();
|
||||
|
||||
}
|
@ -3,10 +3,6 @@ package com.saltosion.gladiator.input;
|
||||
import com.saltosion.gladiator.systems.RenderingSystem;
|
||||
import com.saltosion.gladiator.util.AppUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jens "Jeasonfire" Pitkänen <jeasonfire@gmail.com>
|
||||
*/
|
||||
public class IRDebugToggle implements InputReceiver {
|
||||
|
||||
@Override
|
||||
|
@ -3,10 +3,6 @@ package com.saltosion.gladiator.listeners;
|
||||
import com.badlogic.ashley.core.Entity;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jens "Jeasonfire" Pitkänen <jeasonfire@gmail.com>
|
||||
*/
|
||||
public interface AIListener {
|
||||
|
||||
/**
|
||||
|
@ -3,10 +3,6 @@ package com.saltosion.gladiator.listeners;
|
||||
import com.badlogic.ashley.core.Entity;
|
||||
import com.saltosion.gladiator.util.Direction;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jens "Jeasonfire" Pitkänen <jeasonfire@gmail.com>
|
||||
*/
|
||||
public interface CollisionListener {
|
||||
|
||||
/**
|
||||
|
@ -8,10 +8,6 @@ import com.saltosion.gladiator.listeners.AIListener;
|
||||
import com.saltosion.gladiator.util.Direction;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jens "Jeasonfire" Pitkänen <jeasonfire@gmail.com>
|
||||
*/
|
||||
public class DummyAI implements AIListener {
|
||||
|
||||
private static final ComponentMapper<CPhysics> pm = ComponentMapper.getFor(CPhysics.class);
|
||||
|
@ -11,10 +11,6 @@ import com.saltosion.gladiator.components.CCombat;
|
||||
import com.saltosion.gladiator.components.CPhysics;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jens "Jeasonfire" Pitkänen <jeasonfire@gmail.com>
|
||||
*/
|
||||
public class AISystem extends EntitySystem {
|
||||
|
||||
private static final ComponentMapper<CPhysics> pm = ComponentMapper.getFor(CPhysics.class);
|
||||
|
@ -10,10 +10,6 @@ import com.saltosion.gladiator.components.CCombat;
|
||||
import com.saltosion.gladiator.components.CPhysics;
|
||||
import com.saltosion.gladiator.util.Direction;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jens "Jeasonfire" Pitkänen <jeasonfire@gmail.com>
|
||||
*/
|
||||
public class PhysicsSystem extends EntitySystem {
|
||||
|
||||
private static final float MAX_VEL = 0.5f;
|
||||
|
@ -21,8 +21,11 @@ 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.gui.TextNode;
|
||||
import com.saltosion.gladiator.gui.TextProperty;
|
||||
import com.saltosion.gladiator.util.AppUtil;
|
||||
import com.saltosion.gladiator.util.Global;
|
||||
import com.saltosion.gladiator.util.Log;
|
||||
import com.saltosion.gladiator.util.SpriteSequence;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -54,7 +57,7 @@ public class RenderingSystem extends EntitySystem {
|
||||
batch = new SpriteBatch();
|
||||
|
||||
font = new BitmapFont(Gdx.files.internal("fonts/roman.fnt"));
|
||||
font.setUseIntegerPositions(true);
|
||||
font.setUseIntegerPositions(false);
|
||||
|
||||
debugRenderer = new ShapeRenderer();
|
||||
|
||||
@ -77,20 +80,20 @@ public class RenderingSystem extends EntitySystem {
|
||||
CPhysics phys = pm.get(AppUtil.player);
|
||||
camera.position.set(phys.getPosition().x, phys.getPosition().y, 0);
|
||||
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();
|
||||
|
||||
Gdx.gl.glClearColor(0, 0, 0, 0);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
batch.setProjectionMatrix(camera.combined);
|
||||
|
||||
renderEntities(deltaTime);
|
||||
renderGUI(Vector2.Zero);
|
||||
renderGUI(new Vector2(0, 0));
|
||||
renderDebug(camera);
|
||||
renderFont(fontCamera);
|
||||
}
|
||||
|
||||
private void renderEntities(float deltaTime) {
|
||||
batch.setProjectionMatrix(camera.combined);
|
||||
batch.begin();
|
||||
for (int i = 0; i < entities.size(); i++) {
|
||||
CRenderedObject renderedObject = rom.get(entities.get(i));
|
||||
@ -114,6 +117,7 @@ public class RenderingSystem extends EntitySystem {
|
||||
}
|
||||
|
||||
private void renderGUI(Vector2 rootPosition) {
|
||||
batch.setProjectionMatrix(camera.combined);
|
||||
batch.begin();
|
||||
renderGUINode(AppUtil.guiManager.getRootNode(), rootPosition);
|
||||
batch.end();
|
||||
@ -127,8 +131,14 @@ public class RenderingSystem extends EntitySystem {
|
||||
position.y * AppUtil.VPHEIGHT_CONST - s.getHeight() / 2 + camera.position.y);
|
||||
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()) {
|
||||
renderGUINode(child, position);
|
||||
renderGUINode(child, new Vector2(position));
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,7 +174,7 @@ public class RenderingSystem extends EntitySystem {
|
||||
batch.setProjectionMatrix(fontCamera.combined);
|
||||
batch.begin();
|
||||
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();
|
||||
batch.end();
|
||||
|
@ -1,9 +1,5 @@
|
||||
package com.saltosion.gladiator.util;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jens "Jeasonfire" Pitkänen <jeasonfire@gmail.com>
|
||||
*/
|
||||
public enum Direction {
|
||||
|
||||
UP, DOWN, LEFT, RIGHT, CENTRE
|
||||
|
Loading…
Reference in New Issue
Block a user