Merge remote-tracking branch 'origin/gui' into gui

This commit is contained in:
Yvonne Schmidt 2024-11-26 19:42:01 +01:00
commit 3ce27023c2
5 changed files with 69 additions and 35 deletions

View File

@ -1,14 +1,15 @@
package pp.monopoly.client.gui;
import java.util.List;
import java.util.Random;
import com.jme3.font.BitmapText;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.simsilica.lemur.*;
import com.simsilica.lemur.Axis;
import com.simsilica.lemur.Button;
import com.simsilica.lemur.Container;
import com.simsilica.lemur.HAlignment;
import com.simsilica.lemur.Label;
import com.simsilica.lemur.VAlignment;
import com.simsilica.lemur.component.IconComponent;
import com.simsilica.lemur.component.QuadBackgroundComponent;
import com.simsilica.lemur.component.SpringGridLayout;
@ -24,6 +25,7 @@ import pp.monopoly.message.client.RollDice;
import pp.monopoly.notification.DiceRollEvent;
import pp.monopoly.notification.GameEventListener;
import pp.monopoly.notification.Sound;
import pp.monopoly.notification.UpdatePlayerView;
/**
* Toolbar Klasse, die am unteren Rand der Szene angezeigt wird.
@ -66,25 +68,10 @@ public class Toolbar extends Dialog implements GameEventListener{
// Menü-Container: Ein Nested-Container für Kontostand und "Meine Gulag Frei Karten"
accountContainer = toolbarContainer.addChild(new Container());
accountContainer.addChild(new Label("Kontostand", new ElementId("label-Bold")));
accountContainer.addChild(new Label(playerHandler.getPlayerById(app.getId()).getAccountBalance() + " EUR", new ElementId("label-Text")));
accountContainer.addChild(new Label("Gulag Frei Karten", new ElementId("label-Bold")));
accountContainer.addChild(new Label(playerHandler.getPlayerById(app.getId()).getNumJailCard()+"", new ElementId("label-Text")));
accountContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
// Menü-Container: Ein Container für Übersicht
overviewContainer = toolbarContainer.addChild(new Container());
overviewContainer.addChild(new Label("Übersicht", new ElementId("label-Bold")));
for (Player player : playerHandler.getPlayers()) {
if (player.getId() != app.getId()) { // Skip the current player (host)
overviewContainer.addChild(new Label(
player.getName() + ": " + player.getAccountBalance() + " EUR",
new ElementId("label-Text")
));
}
}
receivedEvent(new UpdatePlayerView());
overviewContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
@ -206,6 +193,40 @@ public class Toolbar extends Dialog implements GameEventListener{
updateDiceImages(event.a(), event.b());
}
@Override
public void receivedEvent(UpdatePlayerView event) {
// Clear existing accountContainer and overviewContainer content
accountContainer.clearChildren();
overviewContainer.clearChildren();
// Update accountContainer
accountContainer.addChild(new Label("Kontostand", new ElementId("label-Bold")));
accountContainer.addChild(new Label(
playerHandler.getPlayerById(app.getId()).getAccountBalance() + " EUR",
new ElementId("label-Text")
));
accountContainer.addChild(new Label("Gulag Karten", new ElementId("label-Bold")));
accountContainer.addChild(new Label(
playerHandler.getPlayerById(app.getId()).getNumJailCard() + "",
new ElementId("label-Text")
));
accountContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
// Update overviewContainer
overviewContainer.addChild(new Label("Übersicht", new ElementId("label-Bold")));
for (Player player : playerHandler.getPlayers()) {
if (player.getId() != app.getId()) { // Skip the current player
overviewContainer.addChild(new Label(
player.getName() + ": " + player.getAccountBalance() + " EUR",
new ElementId("label-Text")
));
}
}
overviewContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
System.out.println("pdate");
}
private void updateDiceImages(int a, int b) {
//TODO dice toll animation

View File

@ -19,7 +19,6 @@ public class PlayerHandler {
private List<Player> players = new LinkedList<>();
private Set<Player> readyPlayers = new HashSet<>();
private transient ServerGameLogic logic;
private Player hostPlayer;
private Player extra = null;
/**
@ -55,14 +54,6 @@ public class PlayerHandler {
players.addAll(players);
}
/**
* Return the host player
* @return the host player
*/
public Player getHostPlayer() {
return hostPlayer;
}
/**
* Return the number of players
* @return number of players in the game
@ -114,9 +105,6 @@ public class PlayerHandler {
throw new IllegalArgumentException("Player already registered");
}
players.add(player);
if(hostPlayer == null) {
hostPlayer = player;
}
}
/**

View File

@ -189,7 +189,7 @@ public class ServerGameLogic implements ClientInterpreter {
@Override
public void received(PlayerReady msg, int from) {
Player player = playerHandler.getPlayerById(from);
if(player == playerHandler.getHostPlayer()) {
if(player.getId() == 0) {
startMoney = msg.getStartMoney();
}

View File

@ -46,5 +46,17 @@ public interface GameEventListener {
*/
default void receivedEvent(ClientStateEvent event) { /* do nothing */ }
/**
* Indicates that the dice result has changed.
*
* @param event the received event
*/
default void receivedEvent(DiceRollEvent event) { /*Do nothing */}
/**
* Indicates that the players assets have changed.
*
* @param event the received event
*/
default void receivedEvent(UpdatePlayerView event) { /*Do nothing */}
}

View File

@ -0,0 +1,13 @@
package pp.monopoly.notification;
public record UpdatePlayerView() implements GameEvent{
/**
* Notifies the game event listener of this event.
*
* @param listener the game event listener
*/
@Override
public void notifyListener(GameEventListener listener) {
listener.receivedEvent(this);
}
}