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;
import com.jme3.input.event.MouseButtonEvent;
import com.jme3.input.event.MouseMotionEvent;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.scene.Spatial;
import com.jme3.texture.Texture;
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;
import com.simsilica.lemur.*;
import com.simsilica.lemur.component.*;
import com.simsilica.lemur.event.MouseEventControl;
import com.simsilica.lemur.event.MouseListener;
import com.simsilica.lemur.style.ElementId;
import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp;
import pp.monopoly.client.gui.popups.Bankrupt;
import pp.monopoly.game.server.Player;
import pp.monopoly.game.server.PlayerColor;
import pp.monopoly.game.server.PlayerHandler;
import pp.monopoly.message.client.EndTurn;
import pp.monopoly.message.client.RollDice;
import pp.monopoly.notification.ButtonStatusEvent;
import pp.monopoly.notification.DiceRollEvent;
import pp.monopoly.notification.GameEventListener;
import pp.monopoly.notification.Sound;
import pp.monopoly.notification.UpdatePlayerView;
import pp.monopoly.notification.*;
/**
* Represents the toolbar interface in the Monopoly application.
* <p>
* 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>
* Provides game controls, player information, and event handling.
*/
public class Toolbar extends Dialog implements GameEventListener {
/**
* Reference to the Monopoly application instance.
*/
private final MonopolyApp app;
/**
* The main container for the toolbar interface.
*/
private final Container toolbarContainer;
/**
* Container for displaying an overview of other players.
*/
private Container overviewContainer;
/**
* Container for displaying account-related information.
*/
private Container accountContainer;
/**
* Handles player-related data and actions.
*/
private PlayerHandler playerHandler;
/**
* Label for the first dice display.
*/
private Label imageLabel;
/**
* Label for the second dice display.
*/
private Label imageLabel2;
/**
* Button for rolling the dice.
*/
private Button diceButton;
/**
* Button for initiating trades.
*/
private boolean canRollDice = false;
private Button tradeButton;
/**
* Button for accessing the property menu.
*/
private Button propertyMenuButton;
/**
* Button for ending the player's turn.
*/
private Button endTurnButton;
/**
* Stores the most recent dice roll event.
*/
private DiceRollEvent latestDiceRollEvent = null;
/**Indicates if the bankrupt PopUp has already been shown */
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) {
super(app.getDialogManager());
this.app = app;
@ -122,149 +48,118 @@ public class Toolbar extends Dialog implements GameEventListener {
app.getGameLogic().addListener(this);
this.playerHandler = app.getGameLogic().getPlayerHandler();
toolbarContainer = createToolbarContainer();
toolbarContainer = setupToolbar();
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.setLocalTranslation(0, 200, 0);
container.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 200, 0));
Texture backgroundToolbar = app.getAssetManager().loadTexture("Pictures/toolbarbg.png");
QuadBackgroundComponent background = new QuadBackgroundComponent(backgroundToolbar);
background.setMargin(0, 0); // Removes any internal margin
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);
// unterer Balken
Container playerColorBarbot = new Container();
playerColorBarbot.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 10, 0)); // Höhe des oberen Balkens
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);
setupBorders(container);
setupPlayerInfoSection(container);
setupDiceSection(container);
setupActionMenu(container);
return container;
}
private Container createDiceSection() {
Container diceContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
diceContainer.addChild(createDiceDisplay());
diceContainer.setBackground(null);
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 void setupBorders(Container container) {
addBorder(0, 205, app.getCamera().getWidth(), 5, ColorRGBA.DarkGray); // Top
addBorder(0, 5, app.getCamera().getWidth(), 10, ColorRGBA.DarkGray); // Bottom
addBorder(0, 200, 5, 210, ColorRGBA.DarkGray); // Left
addBorder(app.getCamera().getWidth() - 5, 200, 5, 210, ColorRGBA.DarkGray); // Right
}
private Button createDice2Button() {
// Erstelle den Button
Button dice2Button = new Button("", new ElementId("button-toolbar2"));
dice2Button.setPreferredSize(new Vector3f(300, 200, 10)); // Setze die Größe
private void addBorder(float x, float y, float width, float height, ColorRGBA color) {
Container border = new Container();
border.setPreferredSize(new Vector3f(width, height, 0));
border.setBackground(new QuadBackgroundComponent(color));
border.setLocalTranslation(x, y, 3);
app.getGuiNode().attachChild(border);
}
// Setze einen unsichtbaren Hintergrund
QuadBackgroundComponent transparentBackground = new QuadBackgroundComponent(new ColorRGBA(0, 0, 0, 0.2f)); // Halbdurchsichtig
dice2Button.setBackground(transparentBackground);
private void setupPlayerInfoSection(Container parentContainer) {
Container playerInfoSection = parentContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
playerInfoSection.setPreferredSize(new Vector3f(600, 300, 0)); // Adjust size for both containers
// Positioniere den Button unabhängig
dice2Button.setLocalTranslation(500, 200, 8); // Setze X, Y, Z für eine feste Position
Texture backgroundTexture = app.getAssetManager().loadTexture("Pictures/"+ Player.getColor(app.getId()).getColorName()+ "Background.png");
QuadBackgroundComponent background = new QuadBackgroundComponent(backgroundTexture);
playerInfoSection.setBackground(background);
// Füge Klickverhalten hinzu
dice2Button.addClickCommands(s -> ifTopDialog(() -> {
dice2Button.setEnabled(false); // Deaktiviere den Button nach Klick
endTurnButton.setEnabled(true); // Aktiviere den EndTurn-Button
startDiceAnimation(); // Starte die Animation
app.getGameLogic().send(new RollDice()); // Sende die Nachricht
app.getGameLogic().playSound(Sound.BUTTON); // Spiele den Sound
}));
accountContainer = playerInfoSection.addChild(new Container());
accountContainer.setPreferredSize(new Vector3f(300, 300, 0));
accountContainer.setBackground(null);
return dice2Button;
overviewContainer = playerInfoSection.addChild(new Container());
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() {
Container horizontalContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
horizontalContainer.setPreferredSize(new Vector3f(200, 150, 0));
horizontalContainer.setBackground(null);
imageLabel = createDiceLabel("Pictures/dice/one.png");
imageLabel2 = createDiceLabel("Pictures/dice/two.png");
horizontalContainer.setBackground(null);
horizontalContainer.addChild(createDiceContainer(imageLabel));
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;
}
@ -284,116 +179,65 @@ public class Toolbar extends Dialog implements GameEventListener {
return container;
}
private Button createTradeButton(PlayerColor playerColor) {
tradeButton = new Button("", new ElementId("button-toolbar2"));
tradeButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe setzen
// Setze den Hintergrund
QuadBackgroundComponent background = new QuadBackgroundComponent(playerColor.getColor());
Texture gradientTexture = app.getAssetManager().loadTexture("Textures/gradient.png");
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(() -> {
private void handleDiceRoll() {
ifTopDialog(() -> {
if (!canRollDice) return;
canRollDice = false;
if (endTurnButton != null) endTurnButton.setEnabled(true);
startDiceAnimation();
app.getGameLogic().send(new RollDice());
app.getGameLogic().playSound(Sound.BUTTON);
new ChoosePartner(app).open();
}));
return tradeButton;
});
}
private Button createPropertyMenuButton(PlayerColor playerColor) {
propertyMenuButton = new Button("", new ElementId("button-toolbar2"));
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 createTradeButton(ColorRGBA playerColor) {
return createActionButton(playerColor, "icons/icon-handeln.png", 100, () -> new ChoosePartner(app).open());
}
private Button createEndTurnButton(PlayerColor playerColor) {
// Erstelle den Button
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
// Setze den Hintergrund
QuadBackgroundComponent background = new QuadBackgroundComponent(ColorRGBA.Gray); // Standardgrau
Texture gradientTexture = app.getAssetManager().loadTexture("Textures/gradient.png"); // Lade Gradient-Textur
if (gradientTexture != null) {
background.setTexture(gradientTexture); // Füge die Textur hinzu, wenn verfügbar
} else {
System.err.println("Gradient texture not found for EndTurn button!");
private Button createPropertyMenuButton(ColorRGBA playerColor) {
return createActionButton(playerColor, "icons/icon-gebaude.png", 75, () -> new BuildingAdminMenu(app).open());
}
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);
private Button createEndTurnButton(ColorRGBA playerColor) {
return createActionButton(playerColor, "icons/icon-zugbeenden.png", 75, () -> handleEndTurn());
}
// 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());
private Button createActionButton(ColorRGBA color, String iconPath, int iconSize, Runnable action) {
Button button = new Button("", new ElementId("button-toolbar2"));
button.setPreferredSize(new Vector3f(150, 50, 0));
button.setBackground(createButtonBackground(color));
// Überprüfe den Kontostand des Spielers
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(); // Öffne den Bankrott-Dialog
new Bankrupt(app).open();
bankruptPopUp = true;
} else {
bankruptPopUp = false;
app.getGameLogic().send(new EndTurn()); // Sende EndTurn-Nachricht
receivedEvent(new ButtonStatusEvent(false)); // Aktualisiere die Button-Statusanzeige
app.getGameLogic().send(new EndTurn());
receivedEvent(new ButtonStatusEvent(false));
}
}));
// Debug-Log hinzufügen
System.out.println("End Turn Button created successfully.");
return endTurnButton;
}
private void startDiceAnimation() {
long startTime = System.currentTimeMillis();
new Thread(() -> {
try {
animateDice(startTime);
@ -406,31 +250,22 @@ public class Toolbar extends Dialog implements GameEventListener {
}).start();
}
/**
* Animates the dice roll by cycling through dice images.
*/
private void animateDice(long startTime) throws InterruptedException {
int[] currentFace = {1};
while (System.currentTimeMillis() - startTime < 2000) { // Animation duration
while (System.currentTimeMillis() - startTime < 2000) {
currentFace[0] = (currentFace[0] % 6) + 1;
updateDiceIcons(currentFace[0]);
Thread.sleep(100);
}
}
String rotatingImage1 = diceToString(currentFace[0]);
String rotatingImage2 = diceToString((currentFace[0] % 6) + 1);
private void updateDiceIcons(int face) {
app.enqueue(() -> {
setDiceIcon(imageLabel, rotatingImage1);
setDiceIcon(imageLabel2, rotatingImage2);
setDiceIcon(imageLabel, diceToString(face));
setDiceIcon(imageLabel2, diceToString((face % 6) + 1));
});
Thread.sleep(100); // Time between frame updates
}
}
/**
* Displays the final dice result after animation.
*
* @param event the dice roll event containing the result
*/
private void showFinalDiceResult(DiceRollEvent event) {
app.enqueue(() -> {
setDiceIcon(imageLabel, diceToString(event.a()));
@ -440,131 +275,88 @@ public class Toolbar extends Dialog implements GameEventListener {
private void setDiceIcon(Label label, String 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);
}
private String diceToString(int i) {
switch (i) {
case 1: return "Pictures/dice/one.png";
case 2: return "Pictures/dice/two.png";
case 3: return "Pictures/dice/three.png";
case 4: return "Pictures/dice/four.png";
case 5: return "Pictures/dice/five.png";
case 6: return "Pictures/dice/six.png";
default: throw new IllegalArgumentException("Invalid dice number: " + i);
}
return "Pictures/dice/" + switch (i) {
case 1 -> "one";
case 2 -> "two";
case 3 -> "three";
case 4 -> "four";
case 5 -> "five";
case 6 -> "six";
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
public void receivedEvent(DiceRollEvent event) {
latestDiceRollEvent = event;
}
/**
* Updates the player view with the latest account and overview data.
*
* @param event the update event for the player view
*/
@Override
public void receivedEvent(UpdatePlayerView event) {
playerHandler = app.getGameLogic().getPlayerHandler();
System.out.println("Update Player View");
refreshPlayerView();
}
private void refreshPlayerView() {
accountContainer.clearChildren();
overviewContainer.clearChildren();
accountContainer.addChild(new Label("Kontostand", new ElementId("label-toolbar")));
accountContainer.addChild(new Label(
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);
addAccountDetails();
addOverviewDetails();
accountContainer.setBackground(null);
overviewContainer.setBackground(null);
}
private void addAccountDetails() {
Player currentPlayer = playerHandler.getPlayerById(app.getId());
accountContainer.addChild(new Label("Kontostand", new ElementId("label-toolbar")));
accountContainer.addChild(new Label(currentPlayer.getAccountBalance() + " EUR", new ElementId("label-account")));
accountContainer.addChild(new Label("Gulag Karten", new ElementId("label-toolbar")));
accountContainer.addChild(new Label(String.valueOf(currentPlayer.getNumJailCard()), new ElementId("label-account")));
}
private void addOverviewDetails() {
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
playerLabel.setColor(Player.getColor(player.getId()).getColor());
overviewContainer.addChild(playerLabel);
}
}
overviewContainer.setBackground(null);
}
/**
* Updates the enabled status of toolbar buttons based on the event.
*
* @param event the button status event
*/
@Override
public void receivedEvent(ButtonStatusEvent event) {
boolean enabled = event.buttonsEnabled();
if (diceButton != null) {
diceButton.setEnabled(enabled);
}
if (tradeButton != null) {
tradeButton.setEnabled(enabled);
}
if (propertyMenuButton != null) {
propertyMenuButton.setEnabled(enabled);
}
if (endTurnButton != null) {
endTurnButton.setEnabled(false);
}
canRollDice = enabled;
if (tradeButton != null) tradeButton.setEnabled(enabled);
if (propertyMenuButton != null) propertyMenuButton.setEnabled(enabled);
if (endTurnButton != null) endTurnButton.setEnabled(false);
}
/**
* Closes the toolbar and detaches it from the GUI.
*/
@Override
public void close() {
app.getGuiNode().detachChild(toolbarContainer);
super.close();
}
/**
* Opens the settings menu when the escape key is pressed.
*/
@Override
public void escape() {
new SettingsMenu(app).open();
}
/**
* Updates the toolbar by refreshing player information.
*/
@Override
public void update() {
receivedEvent(new UpdatePlayerView());
refreshPlayerView();
super.update();
}
}

View File

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