Added level change text.
This commit is contained in:
parent
78d9890437
commit
c5ad241dd3
@ -8,7 +8,9 @@ import com.saltosion.gladiator.util.Log;
|
|||||||
import com.saltosion.gladiator.util.Name;
|
import com.saltosion.gladiator.util.Name;
|
||||||
import com.saltosion.gladiator.util.SpriteLoader;
|
import com.saltosion.gladiator.util.SpriteLoader;
|
||||||
|
|
||||||
public class TestGUICreator implements GUICreator {
|
public class InGameGUICreator implements GUICreator {
|
||||||
|
|
||||||
|
private TextNode levelChangeText;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create() {
|
public void create() {
|
||||||
@ -33,6 +35,14 @@ public class TestGUICreator implements GUICreator {
|
|||||||
TextNode text = new TextNode("test-text", "Test!");
|
TextNode text = new TextNode("test-text", "Test!");
|
||||||
text.setPosition(0.8f, 0.5f);
|
text.setPosition(0.8f, 0.5f);
|
||||||
AppUtil.guiManager.getRootNode().addChild(text);
|
AppUtil.guiManager.getRootNode().addChild(text);
|
||||||
|
|
||||||
|
levelChangeText = new TextNode("Level-Change-Text", "Level change");
|
||||||
|
levelChangeText.setPosition(0.4f, 0.5f);
|
||||||
|
AppUtil.guiManager.getRootNode().addChild(levelChangeText);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextNode getLevelChangeText() {
|
||||||
|
return this.levelChangeText;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -4,36 +4,38 @@ import com.badlogic.gdx.math.Vector2;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class GUINode {
|
public class GUINode {
|
||||||
|
|
||||||
private final Vector2 position;
|
private final Vector2 position;
|
||||||
private final ArrayList<GUINode> children;
|
private final ArrayList<GUINode> children;
|
||||||
private String ID = "";
|
private String ID = "";
|
||||||
|
private boolean visible = true;
|
||||||
|
|
||||||
public GUINode(String ID) {
|
public GUINode(String ID) {
|
||||||
this.ID = ID;
|
this.ID = ID;
|
||||||
this.position = new Vector2();
|
this.position = new Vector2();
|
||||||
this.children = new ArrayList<GUINode>();
|
this.children = new ArrayList<GUINode>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public GUINode setPosition(float x, float y) {
|
public GUINode setPosition(float x, float y) {
|
||||||
this.position.set(x, y);
|
this.position.set(x, y);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GUINode setPosition(Vector2 pos) {
|
public GUINode setPosition(Vector2 pos) {
|
||||||
this.position.set(pos);
|
this.position.set(pos);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GUINode setID(String ID) {
|
public GUINode setID(String ID) {
|
||||||
this.ID = ID;
|
this.ID = ID;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GUINode addChild(GUINode node) {
|
public GUINode addChild(GUINode node) {
|
||||||
this.children.add(node);
|
this.children.add(node);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GUINode removeChild(String id) {
|
public GUINode removeChild(String id) {
|
||||||
for (GUINode child : this.children) {
|
for (GUINode child : this.children) {
|
||||||
if (child.ID.equals(id)) {
|
if (child.ID.equals(id)) {
|
||||||
@ -43,26 +45,36 @@ public class GUINode {
|
|||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GUINode removeChild(GUINode node) {
|
public GUINode removeChild(GUINode node) {
|
||||||
this.children.remove(node);
|
this.children.remove(node);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GUINode clearChildren() {
|
public GUINode clearChildren() {
|
||||||
this.children.clear();
|
this.children.clear();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<GUINode> getChildren() {
|
public ArrayList<GUINode> getChildren() {
|
||||||
return this.children;
|
return this.children;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector2 getPosition() {
|
public Vector2 getPosition() {
|
||||||
return this.position;
|
return this.position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getID() {
|
public String getID() {
|
||||||
return this.ID;
|
return this.ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GUINode setVisible(boolean visible) {
|
||||||
|
this.visible = visible;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isVisible() {
|
||||||
|
return this.visible;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,4 +16,9 @@ public class TextNode extends GUINode implements TextProperty {
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TextNode setText(String text) {
|
||||||
|
this.text = text;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ package com.saltosion.gladiator.level;
|
|||||||
|
|
||||||
public interface Level {
|
public interface Level {
|
||||||
|
|
||||||
|
public String getLevelName();
|
||||||
|
|
||||||
public void generate();
|
public void generate();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,11 @@ import com.saltosion.gladiator.util.SpriteSequence;
|
|||||||
|
|
||||||
public class TestLevel implements Level {
|
public class TestLevel implements Level {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLevelName() {
|
||||||
|
return "Test level";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generate() {
|
public void generate() {
|
||||||
// Audience
|
// Audience
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package com.saltosion.gladiator.state;
|
package com.saltosion.gladiator.state;
|
||||||
|
|
||||||
import com.saltosion.gladiator.gui.creators.GUICreator;
|
import com.saltosion.gladiator.gui.creators.GUICreator;
|
||||||
import com.saltosion.gladiator.gui.creators.TestGUICreator;
|
import com.saltosion.gladiator.gui.creators.InGameGUICreator;
|
||||||
import com.saltosion.gladiator.gui.nodes.ButtonNode;
|
|
||||||
import com.saltosion.gladiator.level.Level;
|
import com.saltosion.gladiator.level.Level;
|
||||||
import com.saltosion.gladiator.level.TestLevel;
|
import com.saltosion.gladiator.level.TestLevel;
|
||||||
import com.saltosion.gladiator.util.AppUtil;
|
import com.saltosion.gladiator.util.AppUtil;
|
||||||
@ -10,7 +9,11 @@ import com.saltosion.gladiator.util.AppUtil;
|
|||||||
public class InGameState extends BaseState {
|
public class InGameState extends BaseState {
|
||||||
|
|
||||||
private Level level;
|
private Level level;
|
||||||
private GUICreator guiCreator;
|
private InGameGUICreator guiCreator;
|
||||||
|
|
||||||
|
private float timeSinceLevelChange;
|
||||||
|
private final float levelChangeTextDelay = 2;
|
||||||
|
private boolean levelChangeTextChanged = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create() {
|
public void create() {
|
||||||
@ -20,13 +23,31 @@ public class InGameState extends BaseState {
|
|||||||
|
|
||||||
level = new TestLevel();
|
level = new TestLevel();
|
||||||
level.generate();
|
level.generate();
|
||||||
|
timeSinceLevelChange = 0;
|
||||||
|
|
||||||
guiCreator = new TestGUICreator();
|
guiCreator = new InGameGUICreator();
|
||||||
guiCreator.create();
|
guiCreator.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(float deltaTime) {
|
public void update(float deltaTime) {
|
||||||
|
if (timeSinceLevelChange < levelChangeTextDelay) {
|
||||||
|
timeSinceLevelChange += deltaTime;
|
||||||
|
if (!levelChangeTextChanged) {
|
||||||
|
guiCreator.getLevelChangeText().setVisible(true);
|
||||||
|
guiCreator.getLevelChangeText().setText(level.getLevelName());
|
||||||
|
levelChangeTextChanged = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
guiCreator.getLevelChangeText().setVisible(false);
|
||||||
|
levelChangeTextChanged = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void changeLevel(Level level) {
|
||||||
|
AppUtil.engine.removeAllEntities();
|
||||||
|
this.level = level;
|
||||||
|
this.timeSinceLevelChange = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -232,6 +232,9 @@ public class RenderingSystem extends EntitySystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void renderGUINode(GUINode node, Vector2 position) {
|
private void renderGUINode(GUINode node, Vector2 position) {
|
||||||
|
if (!node.isVisible()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
position.add(node.getPosition());
|
position.add(node.getPosition());
|
||||||
if (node instanceof ImageProperty) {
|
if (node instanceof ImageProperty) {
|
||||||
Sprite s = ((ImageProperty) node).getImage();
|
Sprite s = ((ImageProperty) node).getImage();
|
||||||
|
Loading…
Reference in New Issue
Block a user