This commit is contained in:
Johannes Schmelz 2024-12-08 16:03:21 +01:00
parent 31fe60807f
commit e498c6f179
2 changed files with 203 additions and 411 deletions

View File

@ -1,120 +1,46 @@
package pp.monopoly.client.gui; package pp.monopoly.client.gui;
import com.jme3.input.event.MouseButtonEvent;
import com.jme3.input.event.MouseMotionEvent;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector2f; import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.scene.Spatial;
import com.jme3.texture.Texture; import com.jme3.texture.Texture;
import com.simsilica.lemur.Axis; import com.simsilica.lemur.*;
import com.simsilica.lemur.Button; import com.simsilica.lemur.component.*;
import com.simsilica.lemur.Container; import com.simsilica.lemur.event.MouseEventControl;
import com.simsilica.lemur.HAlignment; import com.simsilica.lemur.event.MouseListener;
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;
import com.simsilica.lemur.style.ElementId; import com.simsilica.lemur.style.ElementId;
import pp.dialog.Dialog; import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp; import pp.monopoly.client.MonopolyApp;
import pp.monopoly.client.gui.popups.Bankrupt; import pp.monopoly.client.gui.popups.Bankrupt;
import pp.monopoly.game.server.Player; import pp.monopoly.game.server.Player;
import pp.monopoly.game.server.PlayerColor;
import pp.monopoly.game.server.PlayerHandler; import pp.monopoly.game.server.PlayerHandler;
import pp.monopoly.message.client.EndTurn; import pp.monopoly.message.client.EndTurn;
import pp.monopoly.message.client.RollDice; import pp.monopoly.message.client.RollDice;
import pp.monopoly.notification.ButtonStatusEvent; import pp.monopoly.notification.*;
import pp.monopoly.notification.DiceRollEvent;
import pp.monopoly.notification.GameEventListener;
import pp.monopoly.notification.Sound;
import pp.monopoly.notification.UpdatePlayerView;
/** /**
* Represents the toolbar interface in the Monopoly application. * Represents the toolbar interface in the Monopoly application.
* <p> * Provides game controls, player information, and event handling.
* This class provides game controls, player information, and event handling
* for actions such as dice rolling, trading, and ending turns.
* Implements {@link GameEventListener} to respond to game events.
* </p>
*/ */
public class Toolbar extends Dialog implements GameEventListener { public class Toolbar extends Dialog implements GameEventListener {
/**
* Reference to the Monopoly application instance.
*/
private final MonopolyApp app; private final MonopolyApp app;
/**
* The main container for the toolbar interface.
*/
private final Container toolbarContainer; private final Container toolbarContainer;
/**
* Container for displaying an overview of other players.
*/
private Container overviewContainer; private Container overviewContainer;
/**
* Container for displaying account-related information.
*/
private Container accountContainer; private Container accountContainer;
/**
* Handles player-related data and actions.
*/
private PlayerHandler playerHandler; private PlayerHandler playerHandler;
/**
* Label for the first dice display.
*/
private Label imageLabel; private Label imageLabel;
/**
* Label for the second dice display.
*/
private Label imageLabel2; private Label imageLabel2;
private boolean canRollDice = false;
/**
* Button for rolling the dice.
*/
private Button diceButton;
/**
* Button for initiating trades.
*/
private Button tradeButton; private Button tradeButton;
/**
* Button for accessing the property menu.
*/
private Button propertyMenuButton; private Button propertyMenuButton;
/**
* Button for ending the player's turn.
*/
private Button endTurnButton; private Button endTurnButton;
/**
* Stores the most recent dice roll event.
*/
private DiceRollEvent latestDiceRollEvent = null; private DiceRollEvent latestDiceRollEvent = null;
/**Indicates if the bankrupt PopUp has already been shown */
private boolean bankruptPopUp = false; private boolean bankruptPopUp = false;
/**
* Constructs the toolbar for the Monopoly application.
* <p>
* Initializes the toolbar interface, adds event listeners, and sets up
* the GUI elements such as dice, buttons, and player information displays.
* </p>
*
* @param app the Monopoly application instance
*/
public Toolbar(MonopolyApp app) { public Toolbar(MonopolyApp app) {
super(app.getDialogManager()); super(app.getDialogManager());
this.app = app; this.app = app;
@ -122,149 +48,118 @@ public class Toolbar extends Dialog implements GameEventListener {
app.getGameLogic().addListener(this); app.getGameLogic().addListener(this);
this.playerHandler = app.getGameLogic().getPlayerHandler(); this.playerHandler = app.getGameLogic().getPlayerHandler();
toolbarContainer = createToolbarContainer(); toolbarContainer = setupToolbar();
app.getGuiNode().attachChild(toolbarContainer); app.getGuiNode().attachChild(toolbarContainer);
Button dice2Button = createDice2Button();
app.getGuiNode().attachChild(dice2Button);
// Neues Label mit Bild als Hintergrund
Label imageLabel = new Label("");
IconComponent imageIcon = new IconComponent("Pictures/CyanBackground.png");
imageIcon.setIconSize(new Vector2f(450, 200));
imageLabel.setIcon(imageIcon);
// Setze die Position des Labels
imageLabel.setLocalTranslation(20, 205, 0);
// Füge das Label zur GUI hinzu
app.getGuiNode().attachChild(imageLabel);
} }
private Container createToolbarContainer() { private Container setupToolbar() {
Container container = new Container(new SpringGridLayout(Axis.X, Axis.Y), "toolbar"); Container container = new Container(new SpringGridLayout(Axis.X, Axis.Y), "toolbar");
container.setLocalTranslation(0, 200, 0); container.setLocalTranslation(0, 200, 0);
container.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 200, 0)); container.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 200, 0));
Texture backgroundToolbar = app.getAssetManager().loadTexture("Pictures/toolbarbg.png"); Texture backgroundToolbar = app.getAssetManager().loadTexture("Pictures/toolbarbg.png");
QuadBackgroundComponent background = new QuadBackgroundComponent(backgroundToolbar); QuadBackgroundComponent background = new QuadBackgroundComponent(backgroundToolbar);
background.setMargin(0, 0); // Removes any internal margin
container.setBackground(background); container.setBackground(background);
// Spielerfarbe des aktuellen Spielers abrufen
Player currentPlayer = playerHandler.getPlayerById(app.getId());
PlayerColor currentPlayerColor = Player.getColor(currentPlayer.getId());
// Oberer Balken mit der Spielerfarbe
Container playerColorBar = new Container();
playerColorBar.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 5, 0)); // Höhe des oberen Balkens
playerColorBar.setBackground(new QuadBackgroundComponent(ColorRGBA.DarkGray));
playerColorBar.setLocalTranslation(0, 205, 3); // Position über der Toolbar
app.getGuiNode().attachChild(playerColorBar);
setupBorders(container);
// unterer Balken setupPlayerInfoSection(container);
Container playerColorBarbot = new Container(); setupDiceSection(container);
playerColorBarbot.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 10, 0)); // Höhe des oberen Balkens setupActionMenu(container);
playerColorBarbot.setBackground(new QuadBackgroundComponent(ColorRGBA.DarkGray));
playerColorBarbot.setLocalTranslation(0, 5, 3); // Position über der Toolbar
app.getGuiNode().attachChild(playerColorBarbot);
// Linker Balken
Container leftBar = new Container();
leftBar.setPreferredSize(new Vector3f(5, 210, 0)); // Breite 10, Höhe 210
leftBar.setBackground(new QuadBackgroundComponent(ColorRGBA.DarkGray));
leftBar.setLocalTranslation(0, 200, 3); // Position am linken Rand
app.getGuiNode().attachChild(leftBar);
// Rechter Balken
Container rightBar = new Container();
rightBar.setPreferredSize(new Vector3f(5, 210, 0)); // Breite 10, Höhe 210
rightBar.setBackground(new QuadBackgroundComponent(ColorRGBA.DarkGray));
rightBar.setLocalTranslation(app.getCamera().getWidth() - 5, 200, 2); // Position am rechten Rand
app.getGuiNode().attachChild(rightBar);
// Übersicht und Konto
accountContainer = container.addChild(new Container());
overviewContainer = container.addChild(new Container());
accountContainer.setBackground(new QuadBackgroundComponent(ColorRGBA.Yellow)); // Debug-Farbe
overviewContainer.setBackground(new QuadBackgroundComponent(ColorRGBA.Green)); // Debug-Farbe;
receivedEvent(new UpdatePlayerView()); // Initiale Aktualisierung
// Würfel-Bereich
container.addChild(createDiceSection());
// Aktionsmenü
Container menuContainer = container.addChild(new Container());
menuContainer.addChild(createTradeButton(currentPlayerColor));
menuContainer.addChild(createPropertyMenuButton(currentPlayerColor));
menuContainer.addChild(createEndTurnButton(currentPlayerColor));
menuContainer.setBackground(null);
return container; return container;
} }
private Container createDiceSection() { private void setupBorders(Container container) {
Container diceContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y)); addBorder(0, 205, app.getCamera().getWidth(), 5, ColorRGBA.DarkGray); // Top
diceContainer.addChild(createDiceDisplay()); addBorder(0, 5, app.getCamera().getWidth(), 10, ColorRGBA.DarkGray); // Bottom
diceContainer.setBackground(null); addBorder(0, 200, 5, 210, ColorRGBA.DarkGray); // Left
addBorder(app.getCamera().getWidth() - 5, 200, 5, 210, ColorRGBA.DarkGray); // Right
diceButton = new Button("", new ElementId("button-toolbar2"));
diceButton.setPreferredSize(new Vector3f(200, 50, 10));
// Unsichtbaren Hintergrund setzen
QuadBackgroundComponent transparentBackground = new QuadBackgroundComponent(new ColorRGBA(0, 0, 0, 0.0f)); // Transparent
diceButton.setBackground(transparentBackground);
// Verschieben um 200 nach links
diceButton.setLocalTranslation(-200, 0, 0); // X: -200, Y: 0, Z: 0 (bleibt in derselben Höhe)
diceButton.addClickCommands(s -> ifTopDialog(() -> {
diceButton.setEnabled(false);
endTurnButton.setEnabled(true);
startDiceAnimation();
app.getGameLogic().send(new RollDice());
app.getGameLogic().playSound(Sound.BUTTON);
}));
diceContainer.addChild(diceButton);
return diceContainer;
} }
private Button createDice2Button() { private void addBorder(float x, float y, float width, float height, ColorRGBA color) {
// Erstelle den Button Container border = new Container();
Button dice2Button = new Button("", new ElementId("button-toolbar2")); border.setPreferredSize(new Vector3f(width, height, 0));
dice2Button.setPreferredSize(new Vector3f(300, 200, 10)); // Setze die Größe border.setBackground(new QuadBackgroundComponent(color));
border.setLocalTranslation(x, y, 3);
// Setze einen unsichtbaren Hintergrund app.getGuiNode().attachChild(border);
QuadBackgroundComponent transparentBackground = new QuadBackgroundComponent(new ColorRGBA(0, 0, 0, 0.2f)); // Halbdurchsichtig }
dice2Button.setBackground(transparentBackground);
private void setupPlayerInfoSection(Container parentContainer) {
// Positioniere den Button unabhängig Container playerInfoSection = parentContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
dice2Button.setLocalTranslation(500, 200, 8); // Setze X, Y, Z für eine feste Position playerInfoSection.setPreferredSize(new Vector3f(600, 300, 0)); // Adjust size for both containers
// Füge Klickverhalten hinzu Texture backgroundTexture = app.getAssetManager().loadTexture("Pictures/"+ Player.getColor(app.getId()).getColorName()+ "Background.png");
dice2Button.addClickCommands(s -> ifTopDialog(() -> { QuadBackgroundComponent background = new QuadBackgroundComponent(backgroundTexture);
dice2Button.setEnabled(false); // Deaktiviere den Button nach Klick playerInfoSection.setBackground(background);
endTurnButton.setEnabled(true); // Aktiviere den EndTurn-Button
startDiceAnimation(); // Starte die Animation accountContainer = playerInfoSection.addChild(new Container());
app.getGameLogic().send(new RollDice()); // Sende die Nachricht accountContainer.setPreferredSize(new Vector3f(300, 300, 0));
app.getGameLogic().playSound(Sound.BUTTON); // Spiele den Sound accountContainer.setBackground(null);
}));
overviewContainer = playerInfoSection.addChild(new Container());
return dice2Button; overviewContainer.setPreferredSize(new Vector3f(300, 300, 0));
overviewContainer.setBackground(null);
refreshPlayerView();
}
private void setupDiceSection(Container container) {
Container diceContainer = container.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
diceContainer.addChild(createDiceDisplay());
diceContainer.setBackground(null);
}
private void setupActionMenu(Container container) {
Container menuContainer = container.addChild(new Container());
menuContainer.addChild(createTradeButton(getCurrentPlayerColor()));
menuContainer.addChild(createPropertyMenuButton(getCurrentPlayerColor()));
menuContainer.addChild(createEndTurnButton(getCurrentPlayerColor()));
menuContainer.setBackground(null);
}
private ColorRGBA getCurrentPlayerColor() {
Player currentPlayer = playerHandler.getPlayerById(app.getId());
return Player.getColor(currentPlayer.getId()).getColor();
} }
private Container createDiceDisplay() { private Container createDiceDisplay() {
Container horizontalContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y)); Container horizontalContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
horizontalContainer.setPreferredSize(new Vector3f(200, 150, 0)); horizontalContainer.setPreferredSize(new Vector3f(200, 150, 0));
horizontalContainer.setBackground(null);
imageLabel = createDiceLabel("Pictures/dice/one.png"); imageLabel = createDiceLabel("Pictures/dice/one.png");
imageLabel2 = createDiceLabel("Pictures/dice/two.png"); imageLabel2 = createDiceLabel("Pictures/dice/two.png");
horizontalContainer.setBackground(null);
horizontalContainer.addChild(createDiceContainer(imageLabel)); horizontalContainer.addChild(createDiceContainer(imageLabel));
horizontalContainer.addChild(createDiceContainer(imageLabel2)); horizontalContainer.addChild(createDiceContainer(imageLabel2));
// Add mouse event control for click handling
MouseEventControl.addListenersToSpatial(horizontalContainer, new MouseListener() {
@Override
public void mouseButtonEvent(MouseButtonEvent event, Spatial target, Spatial capture) {
if (event.isPressed()) {
handleDiceRoll();
}
}
@Override
public void mouseEntered(MouseMotionEvent event, Spatial target, Spatial capture) {
// Do nothing
}
@Override
public void mouseExited(MouseMotionEvent event, Spatial target, Spatial capture) {
// Do nothing
}
@Override
public void mouseMoved(MouseMotionEvent event, Spatial target, Spatial capture) {
// Do nothing
}
});
return horizontalContainer; return horizontalContainer;
} }
@ -284,116 +179,65 @@ public class Toolbar extends Dialog implements GameEventListener {
return container; return container;
} }
private Button createTradeButton(PlayerColor playerColor) { private void handleDiceRoll() {
tradeButton = new Button("", new ElementId("button-toolbar2")); ifTopDialog(() -> {
tradeButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe setzen if (!canRollDice) return;
canRollDice = false;
// Setze den Hintergrund if (endTurnButton != null) endTurnButton.setEnabled(true);
QuadBackgroundComponent background = new QuadBackgroundComponent(playerColor.getColor()); startDiceAnimation();
Texture gradientTexture = app.getAssetManager().loadTexture("Textures/gradient.png"); app.getGameLogic().send(new RollDice());
if (gradientTexture != null) {
background.setTexture(gradientTexture);
}
tradeButton.setBackground(background);
// Icon hinzufügen
String iconTradePath = "icons/icon-handeln.png";
IconComponent iconTrade = new IconComponent(iconTradePath);
iconTrade.setHAlignment(HAlignment.Center);
iconTrade.setVAlignment(VAlignment.Center);
iconTrade.setIconSize(new Vector2f(100, 100));
tradeButton.setIcon(iconTrade);
// Klickverhalten
tradeButton.addClickCommands(source -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON); app.getGameLogic().playSound(Sound.BUTTON);
new ChoosePartner(app).open(); });
}));
return tradeButton;
} }
private Button createPropertyMenuButton(PlayerColor playerColor) { private Button createTradeButton(ColorRGBA playerColor) {
propertyMenuButton = new Button("", new ElementId("button-toolbar2")); return createActionButton(playerColor, "icons/icon-handeln.png", 100, () -> new ChoosePartner(app).open());
propertyMenuButton.setPreferredSize(new Vector3f(150, 50, 0));
// Setze den Hintergrund
QuadBackgroundComponent background = new QuadBackgroundComponent(playerColor.getColor());
Texture gradientTexture = app.getAssetManager().loadTexture("Textures/gradient.png");
if (gradientTexture != null) {
background.setTexture(gradientTexture);
}
propertyMenuButton.setBackground(background);
// Icon hinzufügen
String iconBuildingPath = "icons/icon-gebaude.png";
IconComponent iconBuilding = new IconComponent(iconBuildingPath);
iconBuilding.setHAlignment(HAlignment.Center);
iconBuilding.setVAlignment(VAlignment.Center);
iconBuilding.setIconSize(new Vector2f(75, 75));
propertyMenuButton.setIcon(iconBuilding);
// Schriftgröße und Klick-Kommandos
propertyMenuButton.setFontSize(30);
propertyMenuButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON);
new BuildingAdminMenu(app).open();
}));
return propertyMenuButton;
} }
private Button createEndTurnButton(PlayerColor playerColor) { private Button createPropertyMenuButton(ColorRGBA playerColor) {
// Erstelle den Button return createActionButton(playerColor, "icons/icon-gebaude.png", 75, () -> new BuildingAdminMenu(app).open());
endTurnButton = new Button("", new ElementId("button-toolbar2")); }
endTurnButton.setFontSize(28); // Setze die Schriftgröße
endTurnButton.setPreferredSize(new Vector3f(150, 50, 0)); // Setze die Größe private Button createEndTurnButton(ColorRGBA playerColor) {
return createActionButton(playerColor, "icons/icon-zugbeenden.png", 75, () -> handleEndTurn());
// Setze den Hintergrund }
QuadBackgroundComponent background = new QuadBackgroundComponent(ColorRGBA.Gray); // Standardgrau
Texture gradientTexture = app.getAssetManager().loadTexture("Textures/gradient.png"); // Lade Gradient-Textur private Button createActionButton(ColorRGBA color, String iconPath, int iconSize, Runnable action) {
if (gradientTexture != null) { Button button = new Button("", new ElementId("button-toolbar2"));
background.setTexture(gradientTexture); // Füge die Textur hinzu, wenn verfügbar button.setPreferredSize(new Vector3f(150, 50, 0));
button.setBackground(createButtonBackground(color));
IconComponent icon = new IconComponent(iconPath);
icon.setHAlignment(HAlignment.Center);
icon.setVAlignment(VAlignment.Center);
icon.setIconSize(new Vector2f(iconSize, iconSize));
button.setIcon(icon);
button.addClickCommands(source -> ifTopDialog(action));
return button;
}
private QuadBackgroundComponent createButtonBackground(ColorRGBA color) {
QuadBackgroundComponent background = new QuadBackgroundComponent(color);
Texture gradient = app.getAssetManager().loadTexture("Textures/gradient.png");
if (gradient != null) background.setTexture(gradient);
return background;
}
private void handleEndTurn() {
Player currentPlayer = playerHandler.getPlayerById(app.getId());
if (currentPlayer.getAccountBalance() < 0 && !bankruptPopUp) {
new Bankrupt(app).open();
bankruptPopUp = true;
} else { } else {
System.err.println("Gradient texture not found for EndTurn button!"); bankruptPopUp = false;
app.getGameLogic().send(new EndTurn());
receivedEvent(new ButtonStatusEvent(false));
} }
endTurnButton.setBackground(background);
// Füge das Icon hinzu
String iconEndTurnPath = "icons/icon-zugbeenden.png";
IconComponent iconEndTurn = new IconComponent(iconEndTurnPath);
iconEndTurn.setHAlignment(HAlignment.Center);
iconEndTurn.setVAlignment(VAlignment.Center);
iconEndTurn.setIconSize(new Vector2f(75, 75)); // Größe des Icons
endTurnButton.setIcon(iconEndTurn);
// Klickverhalten für den Button
endTurnButton.addClickCommands(source -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON); // Spiele den Klick-Sound ab
Player currentPlayer = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId());
// Überprüfe den Kontostand des Spielers
if (currentPlayer.getAccountBalance() < 0 && !bankruptPopUp) {
new Bankrupt(app).open(); // Öffne den Bankrott-Dialog
bankruptPopUp = true;
} else {
bankruptPopUp = false;
app.getGameLogic().send(new EndTurn()); // Sende EndTurn-Nachricht
receivedEvent(new ButtonStatusEvent(false)); // Aktualisiere die Button-Statusanzeige
}
}));
// Debug-Log hinzufügen
System.out.println("End Turn Button created successfully.");
return endTurnButton;
} }
private void startDiceAnimation() { private void startDiceAnimation() {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
new Thread(() -> { new Thread(() -> {
try { try {
animateDice(startTime); animateDice(startTime);
@ -406,165 +250,113 @@ public class Toolbar extends Dialog implements GameEventListener {
}).start(); }).start();
} }
/**
* Animates the dice roll by cycling through dice images.
*/
private void animateDice(long startTime) throws InterruptedException { private void animateDice(long startTime) throws InterruptedException {
int[] currentFace = {1}; int[] currentFace = {1};
while (System.currentTimeMillis() - startTime < 2000) { // Animation duration while (System.currentTimeMillis() - startTime < 2000) {
currentFace[0] = (currentFace[0] % 6) + 1; currentFace[0] = (currentFace[0] % 6) + 1;
updateDiceIcons(currentFace[0]);
String rotatingImage1 = diceToString(currentFace[0]); Thread.sleep(100);
String rotatingImage2 = diceToString((currentFace[0] % 6) + 1);
app.enqueue(() -> {
setDiceIcon(imageLabel, rotatingImage1);
setDiceIcon(imageLabel2, rotatingImage2);
});
Thread.sleep(100); // Time between frame updates
} }
} }
/** private void updateDiceIcons(int face) {
* Displays the final dice result after animation. app.enqueue(() -> {
* setDiceIcon(imageLabel, diceToString(face));
* @param event the dice roll event containing the result setDiceIcon(imageLabel2, diceToString((face % 6) + 1));
*/ });
}
private void showFinalDiceResult(DiceRollEvent event) { private void showFinalDiceResult(DiceRollEvent event) {
app.enqueue(() -> { app.enqueue(() -> {
setDiceIcon(imageLabel, diceToString(event.a())); setDiceIcon(imageLabel, diceToString(event.a()));
setDiceIcon(imageLabel2, diceToString(event.b())); setDiceIcon(imageLabel2, diceToString(event.b()));
}); });
} }
private void setDiceIcon(Label label, String imagePath) { private void setDiceIcon(Label label, String imagePath) {
IconComponent icon = new IconComponent(imagePath); IconComponent icon = new IconComponent(imagePath);
icon.setIconSize(new Vector2f(80, 80)); // Set consistent dice size icon.setIconSize(new Vector2f(80, 80));
label.setIcon(icon); label.setIcon(icon);
} }
private String diceToString(int i) { private String diceToString(int i) {
switch (i) { return "Pictures/dice/" + switch (i) {
case 1: return "Pictures/dice/one.png"; case 1 -> "one";
case 2: return "Pictures/dice/two.png"; case 2 -> "two";
case 3: return "Pictures/dice/three.png"; case 3 -> "three";
case 4: return "Pictures/dice/four.png"; case 4 -> "four";
case 5: return "Pictures/dice/five.png"; case 5 -> "five";
case 6: return "Pictures/dice/six.png"; case 6 -> "six";
default: throw new IllegalArgumentException("Invalid dice number: " + i); default -> throw new IllegalArgumentException("Invalid dice number: " + i);
} } + ".png";
} }
/**
* Handles dice roll events by updating the dice display.
*
* @param event the dice roll event containing dice values
*/
@Override @Override
public void receivedEvent(DiceRollEvent event) { public void receivedEvent(DiceRollEvent event) {
latestDiceRollEvent = event; latestDiceRollEvent = event;
} }
/**
* Updates the player view with the latest account and overview data.
*
* @param event the update event for the player view
*/
@Override @Override
public void receivedEvent(UpdatePlayerView event) { public void receivedEvent(UpdatePlayerView event) {
playerHandler = app.getGameLogic().getPlayerHandler(); refreshPlayerView();
System.out.println("Update Player View"); }
private void refreshPlayerView() {
accountContainer.clearChildren(); accountContainer.clearChildren();
overviewContainer.clearChildren(); overviewContainer.clearChildren();
accountContainer.addChild(new Label("Kontostand", new ElementId("label-toolbar"))); addAccountDetails();
accountContainer.addChild(new Label( addOverviewDetails();
playerHandler.getPlayerById(app.getId()).getAccountBalance() + " EUR",
new ElementId("label-account")
));
accountContainer.addChild(new Label("Gulag Karten", new ElementId("label-toolbar")));
accountContainer.addChild(new Label(
playerHandler.getPlayerById(app.getId()).getNumJailCard() + "",
new ElementId("label-account")
));
// Setze accountContainer auf Z-Ebene 2
accountContainer.setLocalTranslation(accountContainer.getLocalTranslation().x, accountContainer.getLocalTranslation().y, 5);
// Setze overviewContainer auf Z-Ebene 2
overviewContainer.setLocalTranslation(overviewContainer.getLocalTranslation().x, overviewContainer.getLocalTranslation().y, 5);
accountContainer.setBackground(null); accountContainer.setBackground(null);
overviewContainer.addChild(new Label("Übersicht", new ElementId("label-toolbar")));
for (Player player : playerHandler.getPlayers()) {
if (player.getId() != app.getId()) {
// Spielerfarbe abrufen
ColorRGBA playerColor = (Player.getColor(player.getId()).getColor());
// Label für den Spieler erstellen
Label playerLabel = new Label(
player.getName() + ": " + player.getAccountBalance() + " EUR",
new ElementId("label-Text")
);
// Farbe setzen
playerLabel.setColor(playerColor);
// Label zum Container hinzufügen
overviewContainer.addChild(playerLabel);
}
}
overviewContainer.setBackground(null); overviewContainer.setBackground(null);
} }
/** private void addAccountDetails() {
* Updates the enabled status of toolbar buttons based on the event. Player currentPlayer = playerHandler.getPlayerById(app.getId());
* accountContainer.addChild(new Label("Kontostand", new ElementId("label-toolbar")));
* @param event the button status event accountContainer.addChild(new Label(currentPlayer.getAccountBalance() + " EUR", new ElementId("label-account")));
*/ accountContainer.addChild(new Label("Gulag Karten", new ElementId("label-toolbar")));
@Override accountContainer.addChild(new Label(String.valueOf(currentPlayer.getNumJailCard()), new ElementId("label-account")));
public void receivedEvent(ButtonStatusEvent event) { }
boolean enabled = event.buttonsEnabled();
if (diceButton != null) { private void addOverviewDetails() {
diceButton.setEnabled(enabled); overviewContainer.addChild(new Label("Übersicht", new ElementId("label-toolbar")));
} for (Player player : playerHandler.getPlayers()) {
if (tradeButton != null) { if (player.getId() != app.getId()) {
tradeButton.setEnabled(enabled); Label playerLabel = new Label(
} player.getName() + ": " + player.getAccountBalance() + " EUR",
if (propertyMenuButton != null) { new ElementId("label-Text")
propertyMenuButton.setEnabled(enabled); );
} playerLabel.setColor(Player.getColor(player.getId()).getColor());
if (endTurnButton != null) { overviewContainer.addChild(playerLabel);
endTurnButton.setEnabled(false); }
} }
} }
/** @Override
* Closes the toolbar and detaches it from the GUI. public void receivedEvent(ButtonStatusEvent event) {
*/ boolean enabled = event.buttonsEnabled();
canRollDice = enabled;
if (tradeButton != null) tradeButton.setEnabled(enabled);
if (propertyMenuButton != null) propertyMenuButton.setEnabled(enabled);
if (endTurnButton != null) endTurnButton.setEnabled(false);
}
@Override @Override
public void close() { public void close() {
app.getGuiNode().detachChild(toolbarContainer); app.getGuiNode().detachChild(toolbarContainer);
super.close(); super.close();
} }
/**
* Opens the settings menu when the escape key is pressed.
*/
@Override @Override
public void escape() { public void escape() {
new SettingsMenu(app).open(); new SettingsMenu(app).open();
} }
/**
* Updates the toolbar by refreshing player information.
*/
@Override @Override
public void update() { public void update() {
receivedEvent(new UpdatePlayerView()); refreshPlayerView();
super.update(); super.update();
} }
} }

View File

@ -7,11 +7,11 @@ import com.jme3.math.ColorRGBA;
*/ */
public enum PlayerColor { public enum PlayerColor {
CYAN(new ColorRGBA(1 / 255f, 190 / 255f, 254 / 255f, 1), "Cyan"), CYAN(new ColorRGBA(1 / 255f, 190 / 255f, 254 / 255f, 1), "Cyan"),
YELLOW(new ColorRGBA(255 / 255f, 255 / 255f, 0 / 255f, 1), "Gelb"), YELLOW(new ColorRGBA(255 / 255f, 255 / 255f, 0 / 255f, 1), "Yellow"),
RED(new ColorRGBA(255 / 255f, 0 / 255f, 0 / 255f, 1), "Rot"), RED(new ColorRGBA(255 / 255f, 0 / 255f, 0 / 255f, 1), "Red"),
PINK(new ColorRGBA(255 / 255f, 77 / 255f, 166 / 255f, 1), "Pink"), PINK(new ColorRGBA(255 / 255f, 77 / 255f, 166 / 255f, 1), "Pink"),
GREEN(new ColorRGBA(0 / 255f, 204 / 255f, 0 / 255f, 1), "Grün"), GREEN(new ColorRGBA(0 / 255f, 204 / 255f, 0 / 255f, 1), "Green"),
PURPLE(new ColorRGBA(143 / 255f, 0 / 255f, 255 / 255f, 1), "Lila"); PURPLE(new ColorRGBA(143 / 255f, 0 / 255f, 255 / 255f, 1), "Purple");
private final ColorRGBA color; private final ColorRGBA color;
private final String colorName; private final String colorName;