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

This commit is contained in:
Yvonne Schmidt 2024-11-26 00:10:52 +01:00
commit 41127565fc
7 changed files with 31 additions and 70 deletions

View File

@ -15,13 +15,13 @@ import pp.monopoly.client.MonopolyApp;
import pp.monopoly.client.gui.SettingsMenu;
import pp.monopoly.model.fields.BoardManager;
import pp.monopoly.model.fields.BuildingProperty;
import pp.monopoly.notification.Sound;
/**
* SettingsMenu ist ein Overlay-Menü, das durch ESC aufgerufen werden kann.
*/
public class BuyCard extends Dialog {
private final MonopolyApp app;
private final Geometry overlayBackground;
private final Container buyCardContainer;
private final Container backgroundContainer;
@ -34,22 +34,18 @@ public class BuyCard extends Dialog {
//Generate the corresponfing field
BuildingProperty field = (BuildingProperty) new BoardManager().getFieldAtIndex(index);
// Halbtransparentes Overlay hinzufügen
overlayBackground = createOverlayBackground();
app.getGuiNode().attachChild(overlayBackground);
// Create the background container
backgroundContainer = new Container();
backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background
app.getGuiNode().attachChild(backgroundContainer);
attachChild(backgroundContainer);
// Hauptcontainer für die Gebäudekarte
buyCardContainer = new Container();
buyCardContainer.setBackground(new QuadBackgroundComponent(field.getColor().getColor()));
Label settingsTitle = buyCardContainer.addChild(new Label( field.getName(), new ElementId("settings-title")));
settingsTitle.setFontSize(48);
Label title = buyCardContainer.addChild(new Label( field.getName(), new ElementId("label-Bold")));
title.setBackground(new QuadBackgroundComponent(field.getColor().getColor()));
title.setFontSize(48);
// Text, der auf der Karte steht
// Die Preise werden dynamisch dem BoardManager entnommen
@ -70,9 +66,17 @@ public class BuyCard extends Dialog {
// Beenden-Button
Button quitButton = buyCardContainer.addChild(new Button("Beenden", new ElementId("button")));
quitButton.setFontSize(32);
quitButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON);
close();
}));
// Kaufen-Button
Button buyButton = buyCardContainer.addChild(new Button("Kaufen", new ElementId("button")));
buyButton.setFontSize(32);
buyButton.addClickCommands(s -> ifTopDialog( () -> {
app.getGameLogic().playSound(Sound.BUTTON);
//TODO send buy property request
}));
float padding = 10; // Padding around the settingsContainer for the background
backgroundContainer.setPreferredSize(buyCardContainer.getPreferredSize().addLocal(padding, padding, 0));
@ -94,22 +98,6 @@ public class BuyCard extends Dialog {
app.getGuiNode().attachChild(buyCardContainer);
}
/**
* Erstellt einen halbtransparenten Hintergrund für das Menü.
*
* @return Geometrie des Overlays
*/
private Geometry createOverlayBackground() {
Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight());
Geometry overlay = new Geometry("Overlay", quad);
Material material = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
material.setColor("Color", new ColorRGBA(0, 0, 0, 0.5f)); // Halbtransparent
material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
overlay.setMaterial(material);
overlay.setLocalTranslation(0, 0, 0);
return overlay;
}
/**
* Schließt das Menü und entfernt die GUI-Elemente.
*/
@ -117,7 +105,6 @@ public class BuyCard extends Dialog {
public void close() {
app.getGuiNode().detachChild(buyCardContainer); // Entferne das Menü
app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand
app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay
super.close();
}

View File

@ -6,6 +6,7 @@ import java.util.ArrayList;
import java.util.List;
import pp.monopoly.game.server.Player;
import pp.monopoly.game.server.PlayerHandler;
import pp.monopoly.message.client.ClientMessage;
import pp.monopoly.message.server.BuyPropertyResponse;
import pp.monopoly.message.server.DiceResult;
@ -52,7 +53,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
/** The current state of the client game logic. */
private ClientState state = new LobbyState(this);
private List<Player> players;
private PlayerHandler playerHandler;
private BoardManager boardManager = new BoardManager();
@ -94,8 +95,8 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
state.entry();
}
public List<Player> getPlayers() {
return players;
public PlayerHandler getPlayerHandler() {
return playerHandler;
}
/**
@ -255,7 +256,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
*/
@Override
public void received(GameStart msg) {
players = msg.getPlayers();
playerHandler = msg.getPlayerHandler();
setState(new WaitForTurnState(this));
}

View File

@ -40,8 +40,8 @@ public class Player implements FieldVisitor<Void>{
private int getOutOfJailCard;
private int fieldID;
private DiceResult rollResult;
private final PlayerHandler handler;
private PlayerState state = new LobbyState();
private transient final PlayerHandler handler;
private transient PlayerState state = new LobbyState();
/**
* Default constructor for serialization purposes.

View File

@ -1,6 +1,5 @@
package pp.monopoly.game.server;
import java.util.LinkedList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
@ -18,7 +17,7 @@ import pp.monopoly.model.LimitedLinkedList;
public class PlayerHandler {
private List<Player> players = new LimitedLinkedList<>(6);
private Set<Player> readyPlayers = new HashSet<>();
private ServerGameLogic logic;
private transient ServerGameLogic logic;
private Player hostPlayer;
private Player extra = null;

View File

@ -204,7 +204,7 @@ public class ServerGameLogic implements ClientInterpreter {
if(playerHandler.allPlayersReady()) {
playerHandler.setStartBalance(startMoney);
for (Player p : playerHandler.getPlayers()) {
send(p, new GameStart(playerHandler.getPlayers()));
send(p, new GameStart(playerHandler));
}
playerHandler.randomOrder();
send(playerHandler.getPlayerAtIndex(0), new NextPlayerTurn());

View File

@ -1,27 +1,25 @@
package pp.monopoly.message.server;
import java.util.List;
import com.jme3.network.serializing.Serializable;
import pp.monopoly.game.server.Player;
import pp.monopoly.game.server.PlayerHandler;
@Serializable
public class GameStart extends ServerMessage{
private List<Player> players;
private PlayerHandler playerHandler;
/**
* Default constructor for serialization purposes.
*/
private GameStart() { /* empty */ }
public GameStart(List<Player> players) {
this.players = players;
public GameStart(PlayerHandler playerHandler) {
this.playerHandler = playerHandler;
}
public List<Player> getPlayers() {
return players;
public PlayerHandler getPlayerHandler() {
return playerHandler;
}
@Override

View File

@ -43,18 +43,6 @@ import pp.monopoly.message.server.ServerMessage;
import pp.monopoly.model.Figure;
import pp.monopoly.model.IntPoint;
import pp.monopoly.model.LimitedLinkedList;
import pp.monopoly.model.fields.BuildingProperty;
import pp.monopoly.model.fields.EventField;
import pp.monopoly.model.fields.Field;
import pp.monopoly.model.fields.FieldColor;
import pp.monopoly.model.fields.FineField;
import pp.monopoly.model.fields.FoodField;
import pp.monopoly.model.fields.GateField;
import pp.monopoly.model.fields.GoField;
import pp.monopoly.model.fields.GulagField;
import pp.monopoly.model.fields.PropertyField;
import pp.monopoly.model.fields.TestStreckeField;
import pp.monopoly.model.fields.WacheField;
/**
* Server implementing the visitor pattern as MessageReceiver for ClientMessages
@ -141,19 +129,7 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
Serializer.registerClass(NextPlayerTurn.class);
Serializer.registerClass(Player.class);
Serializer.registerClass(Figure.class);
// Serializer.registerClass(PlayerHandler.class);
// Serializer.registerClass(BuildingProperty.class);
// Serializer.registerClass(EventField.class);
// Serializer.registerClass(Field.class);
// // Serializer.registerClass(FieldColor.class);
// Serializer.registerClass(FineField.class);
// Serializer.registerClass(FoodField.class);
// Serializer.registerClass(GateField.class);
// Serializer.registerClass(GoField.class);
// Serializer.registerClass(GulagField.class);
// Serializer.registerClass(PropertyField.class);
// Serializer.registerClass(TestStreckeField.class);
// Serializer.registerClass(WacheField.class);
Serializer.registerClass(PlayerHandler.class);
}
private void registerListeners() {