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.SpriteLoader;
|
||||
|
||||
public class TestGUICreator implements GUICreator {
|
||||
public class InGameGUICreator implements GUICreator {
|
||||
|
||||
private TextNode levelChangeText;
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
@ -33,6 +35,14 @@ public class TestGUICreator implements GUICreator {
|
||||
TextNode text = new TextNode("test-text", "Test!");
|
||||
text.setPosition(0.8f, 0.5f);
|
||||
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;
|
||||
|
||||
public class GUINode {
|
||||
|
||||
private final Vector2 position;
|
||||
private final ArrayList<GUINode> children;
|
||||
private String ID = "";
|
||||
private boolean visible = true;
|
||||
|
||||
public GUINode(String ID) {
|
||||
this.ID = ID;
|
||||
this.position = new Vector2();
|
||||
this.children = new ArrayList<GUINode>();
|
||||
}
|
||||
|
||||
|
||||
public GUINode setPosition(float x, float y) {
|
||||
this.position.set(x, y);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public GUINode setPosition(Vector2 pos) {
|
||||
this.position.set(pos);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public GUINode setID(String ID) {
|
||||
this.ID = ID;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public GUINode addChild(GUINode node) {
|
||||
this.children.add(node);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public GUINode removeChild(String id) {
|
||||
for (GUINode child : this.children) {
|
||||
if (child.ID.equals(id)) {
|
||||
@ -43,26 +45,36 @@ public class GUINode {
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public GUINode removeChild(GUINode node) {
|
||||
this.children.remove(node);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public GUINode clearChildren() {
|
||||
this.children.clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<GUINode> getChildren() {
|
||||
return this.children;
|
||||
}
|
||||
|
||||
|
||||
public Vector2 getPosition() {
|
||||
return this.position;
|
||||
}
|
||||
|
||||
|
||||
public String getID() {
|
||||
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;
|
||||
}
|
||||
|
||||
public TextNode setText(String text) {
|
||||
this.text = text;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package com.saltosion.gladiator.level;
|
||||
|
||||
public interface Level {
|
||||
|
||||
public String getLevelName();
|
||||
|
||||
public void generate();
|
||||
|
||||
}
|
||||
|
@ -14,6 +14,11 @@ import com.saltosion.gladiator.util.SpriteSequence;
|
||||
|
||||
public class TestLevel implements Level {
|
||||
|
||||
@Override
|
||||
public String getLevelName() {
|
||||
return "Test level";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generate() {
|
||||
// Audience
|
||||
|
@ -1,8 +1,7 @@
|
||||
package com.saltosion.gladiator.state;
|
||||
|
||||
import com.saltosion.gladiator.gui.creators.GUICreator;
|
||||
import com.saltosion.gladiator.gui.creators.TestGUICreator;
|
||||
import com.saltosion.gladiator.gui.nodes.ButtonNode;
|
||||
import com.saltosion.gladiator.gui.creators.InGameGUICreator;
|
||||
import com.saltosion.gladiator.level.Level;
|
||||
import com.saltosion.gladiator.level.TestLevel;
|
||||
import com.saltosion.gladiator.util.AppUtil;
|
||||
@ -10,7 +9,11 @@ import com.saltosion.gladiator.util.AppUtil;
|
||||
public class InGameState extends BaseState {
|
||||
|
||||
private Level level;
|
||||
private GUICreator guiCreator;
|
||||
private InGameGUICreator guiCreator;
|
||||
|
||||
private float timeSinceLevelChange;
|
||||
private final float levelChangeTextDelay = 2;
|
||||
private boolean levelChangeTextChanged = false;
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
@ -20,13 +23,31 @@ public class InGameState extends BaseState {
|
||||
|
||||
level = new TestLevel();
|
||||
level.generate();
|
||||
timeSinceLevelChange = 0;
|
||||
|
||||
guiCreator = new TestGUICreator();
|
||||
guiCreator = new InGameGUICreator();
|
||||
guiCreator.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
|
@ -232,6 +232,9 @@ public class RenderingSystem extends EntitySystem {
|
||||
}
|
||||
|
||||
private void renderGUINode(GUINode node, Vector2 position) {
|
||||
if (!node.isVisible()) {
|
||||
return;
|
||||
}
|
||||
position.add(node.getPosition());
|
||||
if (node instanceof ImageProperty) {
|
||||
Sprite s = ((ImageProperty) node).getImage();
|
||||
|
Loading…
Reference in New Issue
Block a user