diff --git a/assets/assets.txt b/assets/assets.txt index bee8d06..857256a 100644 --- a/assets/assets.txt +++ b/assets/assets.txt @@ -24,7 +24,9 @@ images/planet-field-down.png images/planet-field-color.png images/map-done.png images/board-background.png -images/player.png +images/player0.png +images/player1.png +images/player2.png animations/planet/tatuine.atlas animations/planet/centre.atlas animations/planet/pluto.atlas diff --git a/assets/images/player.png b/assets/images/player.png deleted file mode 100644 index 5aae374..0000000 Binary files a/assets/images/player.png and /dev/null differ diff --git a/assets/images/player0.png b/assets/images/player0.png new file mode 100644 index 0000000..bb83b94 Binary files /dev/null and b/assets/images/player0.png differ diff --git a/assets/images/player1.png b/assets/images/player1.png new file mode 100644 index 0000000..eb7d594 Binary files /dev/null and b/assets/images/player1.png differ diff --git a/assets/images/player2.png b/assets/images/player2.png new file mode 100644 index 0000000..c881883 Binary files /dev/null and b/assets/images/player2.png differ diff --git a/assets/skin/ui.skin.atlas b/assets/skin/ui.skin.atlas index 5a912e0..f19ef9a 100644 --- a/assets/skin/ui.skin.atlas +++ b/assets/skin/ui.skin.atlas @@ -110,6 +110,13 @@ panel orig: 57, 96 offset: 0, 0 index: -1 +white-pixel + rotate: false + xy: 126, 112 + size: 1, 1 + orig: 1, 1 + offset: 0, 0 + index: -1 panel-margin rotate: false xy: 60, 71 diff --git a/assets/skin/ui.skin.json b/assets/skin/ui.skin.json index 5181811..4fd54ef 100644 Binary files a/assets/skin/ui.skin.json and b/assets/skin/ui.skin.json differ diff --git a/assets/skin/ui.skin.png b/assets/skin/ui.skin.png index 5f80d51..33d761f 100644 Binary files a/assets/skin/ui.skin.png and b/assets/skin/ui.skin.png differ diff --git a/core/src/xyz/magicjourney/nebulaquest/NebulaQuest.java b/core/src/xyz/magicjourney/nebulaquest/NebulaQuest.java index 3f70857..8af18ff 100644 --- a/core/src/xyz/magicjourney/nebulaquest/NebulaQuest.java +++ b/core/src/xyz/magicjourney/nebulaquest/NebulaQuest.java @@ -22,7 +22,6 @@ public class NebulaQuest extends Game { protected ScreenManager screenManager; protected MusicManager musicManager; - @Override public void create () { this.batch = new SpriteBatch(); diff --git a/core/src/xyz/magicjourney/nebulaquest/player/Player.java b/core/src/xyz/magicjourney/nebulaquest/player/Player.java index 0fe88dc..4aa8333 100644 --- a/core/src/xyz/magicjourney/nebulaquest/player/Player.java +++ b/core/src/xyz/magicjourney/nebulaquest/player/Player.java @@ -1,13 +1,30 @@ package xyz.magicjourney.nebulaquest.player; +import com.badlogic.gdx.assets.AssetManager; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable; + public class Player { + private static int nextID = 0; + + protected int id; protected String name; public Player(String name) { this.name = name; + this.id = generateId(); + } + + private int generateId() { + return Player.nextID++; } public String getName() { return this.name; } + + public TextureRegionDrawable getShip(AssetManager assets) { + return new TextureRegionDrawable(new TextureRegion(assets.get("images/player" + id + ".png", Texture.class))); + } } diff --git a/core/src/xyz/magicjourney/nebulaquest/screen/GameScreen.java b/core/src/xyz/magicjourney/nebulaquest/screen/GameScreen.java index 1734393..e0a142e 100644 --- a/core/src/xyz/magicjourney/nebulaquest/screen/GameScreen.java +++ b/core/src/xyz/magicjourney/nebulaquest/screen/GameScreen.java @@ -16,28 +16,41 @@ import xyz.magicjourney.nebulaquest.entity.entities.planet.Planet; import xyz.magicjourney.nebulaquest.entity.entities.planet.PlanetRegion; import xyz.magicjourney.nebulaquest.music.MusicManager; +import xyz.magicjourney.nebulaquest.player.Player; import xyz.magicjourney.nebulaquest.ui.panel.InteractivePanel; import xyz.magicjourney.nebulaquest.ui.panel.MenuPanel; import xyz.magicjourney.nebulaquest.ui.panel.OptionPanel; import xyz.magicjourney.nebulaquest.ui.panel.TourPanel; public class GameScreen extends AbstractScreen { - ArrayList regions; - ArrayList entities; - Board board; - InteractivePanel interactivePanel; - OptionPanel optionsPanel; - TourPanel tourPanel; - MenuPanel menuPanel; - Dice dice; + protected Player activePlayer; + protected ArrayList players; + protected ArrayList regions; + protected ArrayList entities; + protected Board board; + protected InteractivePanel interactivePanel; + protected OptionPanel optionsPanel; + protected TourPanel tourPanel; + protected MenuPanel menuPanel; + protected Dice dice; public GameScreen(SpriteBatch batch, AssetManager assets, ScreenManager screenManager, MusicManager musicManager) { super(batch, assets, screenManager, musicManager); + this.players = new ArrayList<>(); this.regions = new ArrayList<>(); this.entities = new ArrayList<>(); + this.populatePlayers(); this.populateRegions(); this.populateBoard(); + + this.activePlayer = this.players.get(0); + } + + public void populatePlayers() { + this.players.add(new Player("Player 1")); + this.players.add(new Player("Player 2")); + this.players.add(new Player("Player 3")); } protected void populateRegions() { @@ -115,7 +128,7 @@ public void create() { this.optionsPanel = new OptionPanel(assets); this.optionsPanel.setPosition(751, 189); - this.tourPanel = new TourPanel(assets); + this.tourPanel = new TourPanel(assets, this.players); this.tourPanel.setPosition(751, 72); this.menuPanel = new MenuPanel(assets); @@ -128,7 +141,11 @@ public void create() { this.board.onFieldSelect().subscribe(this::handleFieldSelect); this.board.onFieldUnselect().subscribe(this::handlePanelUnselect); - this.tourPanel.onRoll().subscribe(() -> dice.roll((r) -> System.out.println(r))); + this.tourPanel.onRoll().subscribe(() -> dice.roll((r) -> { + System.out.println(r); + this.tourPanel.setTurnEndMode(); + })); + this.tourPanel.onTurnStarted().subscribe((player) -> this.activePlayer = player); this.dice.setPosition(0, 0); this.stage.addActor(board); diff --git a/core/src/xyz/magicjourney/nebulaquest/ui/dialog/MessageBox.java b/core/src/xyz/magicjourney/nebulaquest/ui/dialog/MessageBox.java new file mode 100644 index 0000000..1afb9ff --- /dev/null +++ b/core/src/xyz/magicjourney/nebulaquest/ui/dialog/MessageBox.java @@ -0,0 +1,62 @@ +package xyz.magicjourney.nebulaquest.ui.dialog; + +import com.badlogic.gdx.assets.AssetManager; +import com.badlogic.gdx.scenes.scene2d.Stage; +import com.badlogic.gdx.scenes.scene2d.ui.Label; +import com.badlogic.gdx.scenes.scene2d.ui.Skin; +import com.badlogic.gdx.scenes.scene2d.ui.TextButton; +import com.badlogic.gdx.scenes.scene2d.ui.Window; + +import xyz.magicjourney.nebulaquest.event.Event; +import xyz.magicjourney.nebulaquest.event.EventGetter; +import xyz.magicjourney.nebulaquest.listener.Listener; + +public class MessageBox extends Window { + protected Skin skin; + protected Label message; + protected TextButton okBtn; + protected Event acceptedEvent; + + public MessageBox(String text, AssetManager assets) { + super("", assets.get("skin/ui.skin.json", Skin.class)); + + this.skin = super.getSkin(); + this.acceptedEvent = new Event(); + this.message = new Label(text, this.skin, "small"); + this.okBtn = new TextButton("Ok", this.skin, "orange"); + + this.setWidth(300); + this.setHeight(100); + + this.clear(); + this.pad(6); + this.add(this.message).expandX().center().row(); + this.add(okBtn).minWidth(100).expandX().center().pad(10); + + this.okBtn.addListener(new Listener(this::handleOkButtonClick)); + } + + public EventGetter onAccepted() { + return this.acceptedEvent; + } + + public void show(Stage stage) { + stage.addActor(this); + + this.center(stage.getWidth(), stage.getHeight()); + } + + protected void center(float width, float height) { + this.setX((width - this.getWidth()) / 2); + this.setY((height - this.getHeight()) / 2); + } + + protected void handleOkButtonClick() { + this.remove(); + this.acceptedEvent.emit(); + } + + public void setText(String text) { + this.message.setText(text); + } +} diff --git a/core/src/xyz/magicjourney/nebulaquest/ui/panel/TourPanel.java b/core/src/xyz/magicjourney/nebulaquest/ui/panel/TourPanel.java index ff1ba01..2188424 100644 --- a/core/src/xyz/magicjourney/nebulaquest/ui/panel/TourPanel.java +++ b/core/src/xyz/magicjourney/nebulaquest/ui/panel/TourPanel.java @@ -1,40 +1,64 @@ package xyz.magicjourney.nebulaquest.ui.panel; +import java.util.ArrayList; + import com.badlogic.gdx.assets.AssetManager; -import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.scenes.scene2d.ui.Cell; import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; +import com.badlogic.gdx.utils.Queue; import xyz.magicjourney.nebulaquest.event.Event; import xyz.magicjourney.nebulaquest.event.EventGetter; +import xyz.magicjourney.nebulaquest.event.ParameterizedEvent; +import xyz.magicjourney.nebulaquest.event.ParameterizedEventGetter; import xyz.magicjourney.nebulaquest.listener.Listener; +import xyz.magicjourney.nebulaquest.player.Player; +import xyz.magicjourney.nebulaquest.ui.dialog.MessageBox; public class TourPanel extends Panel { + protected Queue players; protected TextButton roll; + protected TextButton endTurn; + protected Cell buttonCell; protected Label money; - protected Image player; + protected Image playerImage; + protected MessageBox playerTurnMsg; + protected AssetManager assets; protected Event rollEvent; + protected ParameterizedEvent turnStartedEvent; - public TourPanel(AssetManager assets) { + public TourPanel(AssetManager assets, ArrayList players) { super(207, 115, assets); + this.assets = assets; + this.players = new Queue<>(); + players.forEach(this.players::addLast); + + this.playerTurnMsg = new MessageBox("", assets); this.roll = new TextButton("Roll", this.skin, "orange"); + this.endTurn = new TextButton("End turn", this.skin); this.money = new Label("1000$", this.skin); - this.player = new Image(assets.get("images/player.png", Texture.class)); + this.playerImage = new Image(this.players.first().getShip(assets)); + this.rollEvent = new Event(); + this.turnStartedEvent = new ParameterizedEvent<>(); Table playerDescription = new Table(); - playerDescription.add(player).expand().center(); + playerDescription.add(playerImage).expand().center(); playerDescription.add(money).expand().center(); + this.content.add(playerDescription).expand().fill(); this.content.row(); - this.content.add(roll).fillX(); - + this.buttonCell = this.content.add(roll).fillX(); + this.roll.addListener(new Listener(rollEvent::emit)); + this.endTurn.addListener(new Listener(this::handleTurnEnd)); + this.playerTurnMsg.onAccepted().subscribe(() -> turnStartedEvent.emit(this.players.first())); } @Override @@ -45,4 +69,26 @@ public void act(float delta) { public EventGetter onRoll() { return this.rollEvent; } + + public ParameterizedEventGetter onTurnStarted() { + return this.turnStartedEvent; + } + + public void setRollMode() { + this.buttonCell.clearActor(); + this.buttonCell.setActor(roll); + } + + public void setTurnEndMode() { + this.buttonCell.clearActor(); + this.buttonCell.setActor(endTurn); + } + + protected void handleTurnEnd() { + this.players.addLast(this.players.removeFirst()); + this.playerImage.setDrawable(this.players.first().getShip(assets)); + this.playerTurnMsg.setText("It is the turn of " + this.players.first().getName() + "!"); + this.playerTurnMsg.show(this.getStage()); + this.setRollMode(); + } }