Anzeige Spielerfarbe + Figur Pos

This commit is contained in:
Luca Puderbach 2024-11-29 07:22:46 +01:00
parent cfce176c82
commit cfae369fd3
2 changed files with 63 additions and 18 deletions

View File

@ -96,12 +96,17 @@ public class TestWorld implements GameEventListener{
Player player = players.get(i);
try {
// Lade das 3D-Modell der Spielfigur
com.jme3.scene.Spatial model = app.getAssetManager().loadModel("Models/" + player.getFigure().getType() + ".j3O");
com.jme3.scene.Spatial model = app.getAssetManager().loadModel("Models/" + player.getFigure().getType() + "/" + player.getFigure().getType() + ".j3o");
model.setLocalScale(0.5f); // Skaliere das Modell
model.setLocalTranslation(0, 0, -i * 2); // Positioniere die Figur auf dem Startfeld
// Positioniere die Figur unten rechts
float startX = 9.1f; // X-Koordinate für die Ecke unten rechts
float startZ = -9.1f; // Z-Koordinate für die Ecke unten rechts
float spacing = 0.4f; // Abstand zwischen den Figuren
model.setLocalTranslation(startX, 0, startZ - (i * spacing)); // Position anpassen
app.getRootNode().attachChild(model);
System.out.println("Figur für Spieler " + player.getId() + " hinzugefügt.");
System.out.println("Figur für Spieler " + player.getId() + " positioniert bei (" + startX + ", 0, " + (startZ - (i * spacing)) + ")");
} catch (Exception e) {
System.err.println("Fehler beim Laden des Modells für Spieler " + player.getId() + ": " + e.getMessage());
}

View File

@ -15,10 +15,15 @@ import com.simsilica.lemur.style.ElementId;
import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp;
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.*;
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;
public class Toolbar extends Dialog implements GameEventListener {
@ -49,28 +54,53 @@ public class Toolbar extends Dialog implements GameEventListener {
}
private Container createToolbarContainer() {
// Erstelle den Hauptcontainer
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));
// Create account and overview containers
// Spielerfarbe abrufen
Player currentPlayer = playerHandler.getPlayerById(app.getId());
ColorRGBA playerColor = convertPlayerColor(currentPlayer.getColor());
// Füge einen farbigen Balken hinzu
Container playerColorBar = new Container();
playerColorBar.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 40, 0)); // Höhe des Balkens auf 10 festlegen
playerColorBar.setBackground(new QuadBackgroundComponent(playerColor));
playerColorBar.setLocalTranslation(0, 200, 1); // Positioniere ihn an der oberen Kante der Toolbar
container.attachChild(playerColorBar);
// Übersicht und Konto
accountContainer = container.addChild(new Container());
overviewContainer = container.addChild(new Container());
receivedEvent(new UpdatePlayerView());
// Dice section
receivedEvent(new UpdatePlayerView()); // Initiale Aktualisierung
// Würfel-Bereich
container.addChild(createDiceSection());
// Action menu
// Aktionsmenü
Container menuContainer = container.addChild(new Container());
menuContainer.addChild(createTradeButton());
menuContainer.addChild(createPropertyMenuButton());
menuContainer.addChild(createEndTurnButton());
menuContainer.setBackground(createBackground());
return container;
}
private ColorRGBA convertPlayerColor(PlayerColor color) {
switch (color) {
case CYAN: return new ColorRGBA(0f, 1f, 1f, 1f); // Cyan
case YELLOW: return ColorRGBA.Yellow;
case RED: return ColorRGBA.Red;
case PINK: return new ColorRGBA(1f, 0.75f, 0.8f, 1f); // Pink
case GREEN: return ColorRGBA.Green;
case PURPLE: return new ColorRGBA(0.5f, 0f, 0.5f, 1f); // Purple
default: return ColorRGBA.Gray; // Fallback
}
}
private Container createDiceSection() {
Container diceContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
diceContainer.addChild(createDiceDisplay());
@ -171,7 +201,7 @@ public class Toolbar extends Dialog implements GameEventListener {
private void animateDice(long startTime) throws InterruptedException {
int[] currentFace = {1};
while (System.currentTimeMillis() - startTime < 2500) { // Animation duration
while (System.currentTimeMillis() - startTime < 2000) { // Animation duration
currentFace[0] = (currentFace[0] % 6) + 1;
String rotatingImage1 = diceToString(currentFace[0]);
@ -238,10 +268,20 @@ public class Toolbar extends Dialog implements GameEventListener {
overviewContainer.addChild(new Label("Übersicht", new ElementId("label-Bold")));
for (Player player : playerHandler.getPlayers()) {
if (player.getId() != app.getId()) {
overviewContainer.addChild(new Label(
player.getName() + ": " + player.getAccountBalance() + " EUR",
new ElementId("label-Text")
));
// Spielerfarbe abrufen
ColorRGBA playerColor = convertPlayerColor(player.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(createBackground());