finished PropertyOverviewMenu

This commit is contained in:
Yvonne Schmidt 2024-11-28 21:55:44 +01:00
parent e000dcfc51
commit 12e859edd5
3 changed files with 147 additions and 21 deletions

View File

@ -81,6 +81,7 @@ public class BuildingAdminMenu extends Dialog {
overviewButton.setPreferredSize(new Vector3f(200, 50, 0)); overviewButton.setPreferredSize(new Vector3f(200, 50, 0));
overviewButton.addClickCommands(s -> ifTopDialog(() -> { overviewButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON); app.getGameLogic().playSound(Sound.BUTTON);
new PropertyOverviewMenu(app).open();
})); }));
overviewColumn.addChild(overviewButton); overviewColumn.addChild(overviewButton);

View File

@ -12,8 +12,16 @@ 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.game.server.Player;
import pp.monopoly.model.fields.BoardManager;
import pp.monopoly.model.fields.BuildingProperty;
import pp.monopoly.model.fields.Field;
import pp.monopoly.model.fields.FoodField;
import pp.monopoly.model.fields.GateField;
import pp.monopoly.model.fields.PropertyField;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
@ -35,6 +43,10 @@ public class PropertyOverviewMenu extends Dialog {
super(app.getDialogManager()); super(app.getDialogManager());
this.app = app; this.app = app;
// Assign 10 random buildings to the player
//TODO Aufruf für Demo löschen
assignRandomPropertiesToPlayer();
// Make the menu fullscreen // Make the menu fullscreen
Vector3f screenSize = new Vector3f(app.getCamera().getWidth(), app.getCamera().getHeight(), 0); Vector3f screenSize = new Vector3f(app.getCamera().getWidth(), app.getCamera().getHeight(), 0);
@ -50,15 +62,13 @@ public class PropertyOverviewMenu extends Dialog {
// Central display container (to hold the "Gebäude" cards) // Central display container (to hold the "Gebäude" cards)
displayContainer = mainContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y, FillMode.Even, FillMode.None))); // Horizontal layout displayContainer = mainContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y, FillMode.Even, FillMode.None))); // Horizontal layout
displayContainer.setPreferredSize(new Vector3f(screenSize.x - 300, 550, 0)); // Take up the remaining width displayContainer.setPreferredSize(new Vector3f(screenSize.x - 300, 550, 0)); // Take up the remaining width
displayContainer.setBackground(new QuadBackgroundComponent(ColorRGBA.Gray)); displayContainer.setBackground(new QuadBackgroundComponent(ColorRGBA.White));
displayContainer.setLocalTranslation(0, 0, 11); displayContainer.setLocalTranslation(0, 0, 11);
// Add some placeholder "Gebäude" cards to the display container // Add some placeholder "Gebäude" cards to the display container
cards = new ArrayList<>(); cards = new ArrayList<>();
for (int i = 0; i < 10; i++) { populatePlayerProperties();
Container card = createGebäudeCard("Gebäude " + (i + 1), 320, 28);
cards.add(card); // Keep track of cards for scrolling
}
// Initially add only visible cards to the displayContainer // Initially add only visible cards to the displayContainer
refreshVisibleCards(0); refreshVisibleCards(0);
@ -85,23 +95,114 @@ public class PropertyOverviewMenu extends Dialog {
/** /**
* Creates a "Gebäude" card container with the given information. * Fetches the player's properties and populates them into the cards list.
*
* @param title The title of the card (e.g., "Gebäude 1").
* @param propertyValue The property value.
* @param rent The rent amount.
* @return A styled container representing a "Gebäude" card.
*/ */
private Container createGebäudeCard(String title, int propertyValue, int rent) { private void populatePlayerProperties() {
Container card = new Container(); // Fetch the current player
card.setPreferredSize(new Vector3f(150, 200, 2)); // Increase width and height for better visibility Player currentPlayer = app.getGameLogic().getPlayerHandler().getPlayers().get(0);
card.setBackground(new QuadBackgroundComponent(ColorRGBA.Gray));
card.addChild(new Label(title, new ElementId("card-label"))).setFontSize(14); // Iterate through the player's properties
card.addChild(new Label("Grundstückswert: €" + propertyValue, new ElementId("card-label"))).setFontSize(12); for (PropertyField property : currentPlayer.getProperties()) {
card.addChild(new Label("Miete allein: €" + rent, new ElementId("card-label"))).setFontSize(12); if (property instanceof BuildingProperty) {
card.addChild(new Label("1 Haus: €50", new ElementId("card-label"))).setFontSize(12); BuildingProperty building = (BuildingProperty) property;
card.addChild(new Label("Hypothekenwert: €160", new ElementId("card-label"))).setFontSize(12); cards.add(createBuildingCard(building));
} else if (property instanceof FoodField) {
FoodField foodField = (FoodField) property;
cards.add(createFoodFieldCard(foodField));
} else if (property instanceof GateField) {
GateField gateField = (GateField) property;
cards.add(createGateFieldCard(gateField));
}
}
}
/**
* Creates a card for BuildingProperty with detailed rent and cost information.
*/
private Container createBuildingCard(BuildingProperty field) {
Container card = new Container();
card.setPreferredSize(new Vector3f(200, 300, 2)); // Match the size of the BuildingPropertyCard
card.setBackground(new QuadBackgroundComponent(field.getColor().getColor()));
card.setInsets(new Insets3f(5, 5, 5, 5)); // Add 5-pixel inset
card.addChild(new Label(field.getName(), new ElementId("label-Bold"))).setFontSize(25);
// Add property details
Container propertyValuesContainer = card.addChild(new Container());
propertyValuesContainer.addChild(new Label("Grundstückswert: €" + field.getPrice(), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))); // Leerzeile
propertyValuesContainer.addChild(new Label("Miete allein: €" + field.getAllRent().get(0), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("- mit 1 Haus: €" + field.getAllRent().get(1), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("- mit 2 Häuser: €" + field.getAllRent().get(2), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("- mit 3 Häuser: €" + field.getAllRent().get(3), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("- mit 4 Häuser: €" + field.getAllRent().get(4), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("- mit 1 Hotel: €" + field.getAllRent().get(5), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("- 1 Haus kostet: €" + field.getHousePrice(), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))); // Leerzeile
propertyValuesContainer.addChild(new Label("Hypothek: €" + field.getHypo(), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
return card;
}
/**
* Creates a card for FoodField with dynamic pricing and rent details.
*/
private Container createFoodFieldCard(FoodField field) {
Container card = new Container();
card.setPreferredSize(new Vector3f(200, 300, 2)); // Adjust card size
card.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.1f, 0.1f, 0.1f, 0.9f))); // Dark background for card
card.setInsets(new Insets3f(5, 5, 5, 5)); // Add 5-pixel inset
// Title Section
Label title = card.addChild(new Label(field.getName(), new ElementId("label-Bold")));
title.setFontSize(30);
title.setColor(ColorRGBA.White); // Ensure readability on dark background
// Property Values Section
Container propertyValuesContainer = card.addChild(new Container());
propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); // Grey background
propertyValuesContainer.addChild(new Label("Preis: €" + field.getPrice(), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))); // Leerzeile
propertyValuesContainer.addChild(new Label("Wenn man Besitzer des", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label(field.getName() + " ist,", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("so ist die Miete", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("40x Würfelwert.", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))); // Leerzeile
propertyValuesContainer.addChild(new Label("Besitzer beider", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("Restaurants zahlt", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("100x Würfelwert.", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))); // Leerzeile
propertyValuesContainer.addChild(new Label("Hypothek: €" + field.getHypo(), new ElementId("label-Text"))).setFontSize(14);
return card;
}
/**
* Creates a card for GateField with rent details for owning multiple gates.
*/
private Container createGateFieldCard(GateField field) {
Container card = new Container();
card.setPreferredSize(new Vector3f(200, 300, 2)); // Adjust card size
card.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Light grey background
card.setInsets(new Insets3f(5, 5, 5, 5)); // Add 5-pixel inset
// Title Section
Label title = card.addChild(new Label(field.getName(), new ElementId("label-Bold")));
title.setFontSize(30);
title.setColor(ColorRGBA.Black);
// Property Values Section
Container propertyValuesContainer = card.addChild(new Container());
propertyValuesContainer.addChild(new Label("Preis: €" + field.getPrice(), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))); // Leerzeile
propertyValuesContainer.addChild(new Label("1 Bahnhof: €250", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("2 Bahnhöfe: €500", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("3 Bahnhöfe: €1000", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("4 Bahnhöfe: €2000", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))); // Leerzeile
propertyValuesContainer.addChild(new Label("Hypothek: €" + field.getHypo(), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); // Dark grey background
return card; return card;
} }
@ -119,6 +220,7 @@ public class PropertyOverviewMenu extends Dialog {
} }
} }
/** /**
* Custom listener for slider value changes. * Custom listener for slider value changes.
*/ */
@ -145,4 +247,27 @@ public class PropertyOverviewMenu extends Dialog {
app.getGuiNode().detachChild(mainContainer); app.getGuiNode().detachChild(mainContainer);
super.close(); super.close();
} }
//TODO Demo Funktion nach implementierung löschen
private void assignRandomPropertiesToPlayer() {
// Get the board from the BoardManager
BoardManager boardManager = app.getGameLogic().getBoardManager();
List<Field> fields = boardManager.getBoard();
// Filter for BuildingProperty, FoodField, and GateField
List<PropertyField> propertyFields = new ArrayList<>();
for (Field field : fields) {
if (field instanceof PropertyField) {
propertyFields.add((PropertyField) field);
}
}
// Shuffle and select up to 10 properties (mix of BuildingProperty, FoodField, GateField)
Collections.shuffle(propertyFields);
List<PropertyField> randomProperties = propertyFields.subList(0, Math.min(10, propertyFields.size()));
// Assign the properties to the current player
Player currentPlayer = app.getGameLogic().getPlayerHandler().getPlayers().get(0);
currentPlayer.getProperties().clear();
currentPlayer.getProperties().addAll(randomProperties);
}
} }

View File

@ -132,7 +132,7 @@ public class Toolbar extends Dialog implements GameEventListener {
propertyMenuButton.setFontSize(30); propertyMenuButton.setFontSize(30);
propertyMenuButton.addClickCommands(s -> ifTopDialog(() -> { propertyMenuButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON); app.getGameLogic().playSound(Sound.BUTTON);
new PropertyOverviewMenu(app).open(); new BuildingAdminMenu(app).open();
})); }));
return propertyMenuButton; return propertyMenuButton;
} }