Add stage for future ui elements and unit names
This commit is contained in:
parent
36b7e0dda9
commit
3c7115f8b9
2 changed files with 38 additions and 6 deletions
|
@ -1,18 +1,15 @@
|
|||
package com.redstrate.watersymbol;
|
||||
|
||||
public class Unit {
|
||||
public String name;
|
||||
public int health = 10;
|
||||
|
||||
public int positionX;
|
||||
public int positionY;
|
||||
|
||||
public enum Team {
|
||||
Player,
|
||||
Enemy,
|
||||
Ally
|
||||
}
|
||||
|
||||
public Team team;
|
||||
|
||||
public int maxDistance = 5;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,9 @@ import com.badlogic.gdx.maps.tiled.TmxMapLoader;
|
|||
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||
import com.badlogic.gdx.utils.ScreenUtils;
|
||||
import com.redstrate.watersymbol.*;
|
||||
import org.w3c.dom.Text;
|
||||
|
@ -49,6 +52,11 @@ public class GameScreen implements Screen {
|
|||
|
||||
boolean currentlyAwaitingAuxilaryAction = false;
|
||||
|
||||
private Stage stage;
|
||||
private Table table;
|
||||
|
||||
TextButton unitNameButton;
|
||||
|
||||
GameScreen(WaterSymbol game) {
|
||||
this.game = game;
|
||||
|
||||
|
@ -60,6 +68,7 @@ public class GameScreen implements Screen {
|
|||
tiledMapRenderer = new OrthogonalTiledMapRenderer(tiledMap);
|
||||
|
||||
Unit player = new Unit();
|
||||
player.name = "Unit";
|
||||
player.positionX = 11;
|
||||
player.positionY = 16;
|
||||
player.team = Unit.Team.Player;
|
||||
|
@ -67,6 +76,7 @@ public class GameScreen implements Screen {
|
|||
units.add(player);
|
||||
|
||||
Unit player2 = new Unit();
|
||||
player2.name = "Unit 2";
|
||||
player2.positionX = 11;
|
||||
player2.positionY = 20;
|
||||
player2.team = Unit.Team.Player;
|
||||
|
@ -74,6 +84,7 @@ public class GameScreen implements Screen {
|
|||
units.add(player2);
|
||||
|
||||
Unit enemy = new Unit();
|
||||
enemy.name = "Bandit A";
|
||||
enemy.positionX = 15;
|
||||
enemy.positionY = 18;
|
||||
enemy.team = Unit.Team.Enemy;
|
||||
|
@ -81,6 +92,7 @@ public class GameScreen implements Screen {
|
|||
units.add(enemy);
|
||||
|
||||
Unit enemy2 = new Unit();
|
||||
enemy2.name = "Bandit B";
|
||||
enemy2.positionX = 15;
|
||||
enemy2.positionY = 18;
|
||||
enemy2.team = Unit.Team.Enemy;
|
||||
|
@ -93,6 +105,23 @@ public class GameScreen implements Screen {
|
|||
|
||||
arrowSpritesheet = new ArrowSpritesheet();
|
||||
|
||||
stage = new Stage();
|
||||
Gdx.input.setInputProcessor(stage);
|
||||
|
||||
table = new Table();
|
||||
table.setFillParent(true);
|
||||
stage.addActor(table);
|
||||
|
||||
table.setDebug(true); // This is optional, but enables debug lines for tables.
|
||||
|
||||
TextButton.TextButtonStyle style = new TextButton.TextButtonStyle();
|
||||
//style.up = new TextureRegionDrawable(upRegion);
|
||||
//style.down = new TextureRegionDrawable(downRegion);
|
||||
style.font = game.font;
|
||||
|
||||
unitNameButton = new TextButton("<unit name>", style);
|
||||
table.top().left().add(unitNameButton);
|
||||
|
||||
startNewTeamTurn(Unit.Team.Player);
|
||||
}
|
||||
|
||||
|
@ -108,6 +137,7 @@ public class GameScreen implements Screen {
|
|||
if(units.get(i).team == currentTurnTeam) {
|
||||
currentUnit = units.get(i);
|
||||
currentUnitIndex = i;
|
||||
unitNameButton.setText(currentUnit.name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -318,6 +348,9 @@ public class GameScreen implements Screen {
|
|||
tiledMapRenderer.setView(camera);
|
||||
tiledMapRenderer.render();
|
||||
|
||||
stage.act(Gdx.graphics.getDeltaTime());
|
||||
stage.draw();
|
||||
|
||||
game.batch.begin();
|
||||
game.batch.setProjectionMatrix(camera.combined);
|
||||
|
||||
|
@ -470,7 +503,7 @@ public class GameScreen implements Screen {
|
|||
spriteRegion = arrowSpritesheet.getBendBottomLeftToRight();
|
||||
}
|
||||
|
||||
game.font.draw(game.batch, entrance.toString() + " to " + exit.toString(), newPosition.x * 16, newPosition.y * 16);
|
||||
//game.font.draw(game.batch, entrance.toString() + " to " + exit.toString(), newPosition.x * 16, newPosition.y * 16);
|
||||
|
||||
if (spriteRegion != null) {
|
||||
game.batch.draw(spriteRegion, newPosition.x * 16, newPosition.y * 16);
|
||||
|
@ -640,6 +673,8 @@ public class GameScreen implements Screen {
|
|||
public void resize(int width, int height) {
|
||||
camera.viewportWidth = 230;
|
||||
camera.viewportHeight = 230 * ((float)height / (float)width);
|
||||
|
||||
stage.getViewport().update(width, height, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -659,6 +694,6 @@ public class GameScreen implements Screen {
|
|||
|
||||
@Override
|
||||
public void dispose() {
|
||||
|
||||
stage.dispose();
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue