From c5ad241dd34bb329717a551fef1202d468e28463 Mon Sep 17 00:00:00 2001 From: Jeasonfire Date: Sun, 17 May 2015 00:12:24 +0300 Subject: [PATCH] Added level change text. --- ...tGUICreator.java => InGameGUICreator.java} | 12 ++++++- .../gladiator/gui/nodes/GUINode.java | 32 +++++++++++++------ .../gladiator/gui/nodes/TextNode.java | 5 +++ .../com/saltosion/gladiator/level/Level.java | 2 ++ .../saltosion/gladiator/level/TestLevel.java | 5 +++ .../gladiator/state/InGameState.java | 29 ++++++++++++++--- .../gladiator/systems/RenderingSystem.java | 3 ++ 7 files changed, 73 insertions(+), 15 deletions(-) rename core/src/com/saltosion/gladiator/gui/creators/{TestGUICreator.java => InGameGUICreator.java} (76%) diff --git a/core/src/com/saltosion/gladiator/gui/creators/TestGUICreator.java b/core/src/com/saltosion/gladiator/gui/creators/InGameGUICreator.java similarity index 76% rename from core/src/com/saltosion/gladiator/gui/creators/TestGUICreator.java rename to core/src/com/saltosion/gladiator/gui/creators/InGameGUICreator.java index 108dc70..fad095a 100644 --- a/core/src/com/saltosion/gladiator/gui/creators/TestGUICreator.java +++ b/core/src/com/saltosion/gladiator/gui/creators/InGameGUICreator.java @@ -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; } } diff --git a/core/src/com/saltosion/gladiator/gui/nodes/GUINode.java b/core/src/com/saltosion/gladiator/gui/nodes/GUINode.java index 8a5ea13..6cd60b5 100644 --- a/core/src/com/saltosion/gladiator/gui/nodes/GUINode.java +++ b/core/src/com/saltosion/gladiator/gui/nodes/GUINode.java @@ -4,36 +4,38 @@ import com.badlogic.gdx.math.Vector2; import java.util.ArrayList; public class GUINode { + private final Vector2 position; private final ArrayList children; private String ID = ""; + private boolean visible = true; public GUINode(String ID) { this.ID = ID; this.position = new Vector2(); this.children = new ArrayList(); } - + 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 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; + } + } diff --git a/core/src/com/saltosion/gladiator/gui/nodes/TextNode.java b/core/src/com/saltosion/gladiator/gui/nodes/TextNode.java index 840363d..a7d0c28 100644 --- a/core/src/com/saltosion/gladiator/gui/nodes/TextNode.java +++ b/core/src/com/saltosion/gladiator/gui/nodes/TextNode.java @@ -16,4 +16,9 @@ public class TextNode extends GUINode implements TextProperty { return text; } + public TextNode setText(String text) { + this.text = text; + return this; + } + } diff --git a/core/src/com/saltosion/gladiator/level/Level.java b/core/src/com/saltosion/gladiator/level/Level.java index ab8e665..2545c21 100644 --- a/core/src/com/saltosion/gladiator/level/Level.java +++ b/core/src/com/saltosion/gladiator/level/Level.java @@ -2,6 +2,8 @@ package com.saltosion.gladiator.level; public interface Level { + public String getLevelName(); + public void generate(); } diff --git a/core/src/com/saltosion/gladiator/level/TestLevel.java b/core/src/com/saltosion/gladiator/level/TestLevel.java index fde4c16..e4e27e5 100644 --- a/core/src/com/saltosion/gladiator/level/TestLevel.java +++ b/core/src/com/saltosion/gladiator/level/TestLevel.java @@ -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 diff --git a/core/src/com/saltosion/gladiator/state/InGameState.java b/core/src/com/saltosion/gladiator/state/InGameState.java index 1fe1f67..6abdd8e 100644 --- a/core/src/com/saltosion/gladiator/state/InGameState.java +++ b/core/src/com/saltosion/gladiator/state/InGameState.java @@ -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 diff --git a/core/src/com/saltosion/gladiator/systems/RenderingSystem.java b/core/src/com/saltosion/gladiator/systems/RenderingSystem.java index ee9fbf2..dbe73b4 100644 --- a/core/src/com/saltosion/gladiator/systems/RenderingSystem.java +++ b/core/src/com/saltosion/gladiator/systems/RenderingSystem.java @@ -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();