diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/SellHouse.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/SellHouse.java index d1ea377..08d78c5 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/SellHouse.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/SellHouse.java @@ -84,7 +84,6 @@ public class SellHouse extends Dialog { downContainer.addChild(new Label("", new ElementId("label-Text")));// Leerzeile downContainer.addChild(new Label("Erstattung:", new ElementId("label-Text")));// Leerzeile - downContainer.addChild(new Label("Hier die tätsächliche Erstattung", new ElementId("label-Text"))); downContainer.addChild(cost); // Cost details downContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/TakeMortage.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/TakeMortage.java index f2c615a..3211df9 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/TakeMortage.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/TakeMortage.java @@ -2,12 +2,17 @@ package pp.monopoly.client.gui.popups; import com.jme3.math.ColorRGBA; import com.jme3.math.Vector3f; +import com.simsilica.lemur.Axis; import com.simsilica.lemur.Button; import com.simsilica.lemur.Container; import com.simsilica.lemur.Label; import com.simsilica.lemur.ListBox; +import com.simsilica.lemur.Selector; +import com.simsilica.lemur.TextField; import com.simsilica.lemur.component.QuadBackgroundComponent; +import com.simsilica.lemur.component.SpringGridLayout; import com.simsilica.lemur.core.VersionedList; +import com.simsilica.lemur.core.VersionedReference; import com.simsilica.lemur.style.ElementId; import pp.dialog.Dialog; import pp.monopoly.client.MonopolyApp; @@ -17,7 +22,9 @@ import pp.monopoly.model.fields.BoardManager; import pp.monopoly.model.fields.BuildingProperty; import pp.monopoly.notification.Sound; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; /** @@ -27,6 +34,12 @@ public class TakeMortage extends Dialog { private final MonopolyApp app; private final Container takeMortageContainer; private final Container backgroundContainer; + private TextField selectionDisplay; // TextField to display selections + private VersionedReference> selectionRef; + private Selector propertySelector; + private Set selectedProperties = new HashSet<>(); + + private Label cost = new Label("0", new ElementId("label-Text")); public TakeMortage(MonopolyApp app) { @@ -63,42 +76,11 @@ public class TakeMortage extends Dialog { middleContainer.setPreferredSize(new Vector3f(100, 150, 0)); middleContainer.setBackground(new QuadBackgroundComponent(ColorRGBA.Orange)); - // Create a VersionedList for the ListBox model - VersionedList listModel = new VersionedList<>(); - - // Retrieve current player and their properties //TODO hier Prüfen, ob abweichungen zur SellHouse-Klasse beachtet werden müssen - Player currentPlayer = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()); - BoardManager boardManager = app.getGameLogic().getBoardManager(); - - List playerProperties = boardManager.getPropertyFields( - currentPlayer.getProperties()).stream() - .filter(property -> property instanceof BuildingProperty) - .map(property -> (BuildingProperty) property) - .filter(property -> property.getHouses() > 0 || property.getHotel() == 1) - .collect(Collectors.toList()); - - // Populate the list model - listModel.addAll(playerProperties); - - // Create a ListBox with the "glass" style and the model - ListBox listBox = new ListBox<>(listModel, "glass"); - listBox.setPreferredSize(new Vector3f(300, 200, 0)); // Adjust size as needed - - // Add selection listener - listBox.addClickCommands(item -> { - BuildingProperty selected = listBox.getSelectedItem(); // Correct method to retrieve the selected item - if (selected != null) { - System.out.println("Selected property: " + selected.getName()); - } - }); - - // Add the ListBox to the middle container - middleContainer.addChild(listBox); - + middleContainer.addChild(createPropertyDropdown()); downContainer.addChild(new Label("", new ElementId("label-Text")));// Leerzeile downContainer.addChild(new Label("Erstattung:", new ElementId("label-Text")));// Leerzeile - downContainer.addChild(new Label("Hier die tätsächliche Erstattung", new ElementId("label-Text"))); + downContainer.addChild(cost); downContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); // Beenden-Button @@ -113,12 +95,8 @@ public class TakeMortage extends Dialog { confirmButton.setFontSize(32); confirmButton.addClickCommands(s -> ifTopDialog( () -> { app.getGameLogic().playSound(Sound.BUTTON); - BuildingProperty selected = listBox.getSelectedItem(); - if (selected != null) { - System.out.println("Confirmed property: " + selected.getName()); // Send the "alter building" message to the server //app.getGameLogic().sendMessage(new AlterBuildingMessage(selected.getId(), false)); TODO Message an Server - } })); // Zentriere das Popup @@ -138,6 +116,82 @@ public class TakeMortage extends Dialog { app.getGuiNode().attachChild(takeMortageContainer); } + /** + * Creates a dropdown menu for selecting a property. + * + * @return The dropdown container. + */ + private Container createPropertyDropdown() { + Container dropdownContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X)); + dropdownContainer.setPreferredSize(new Vector3f(300, 200, 0)); + dropdownContainer.setBackground(new QuadBackgroundComponent(ColorRGBA.Orange)); + + VersionedList propertyOptions = new VersionedList<>(); + List playerProperties = getPlayerProperties(); + + // Populate the dropdown with property names + for (BuildingProperty property : playerProperties) { + propertyOptions.add(property.getName()); + } + + propertySelector = new Selector<>(propertyOptions, "glass"); + dropdownContainer.addChild(propertySelector); + + // Track selection changes + selectionRef = propertySelector.getSelectionModel().createReference(); + + // Initialize the selection display here + selectionDisplay = new TextField(""); // Create TextField for displaying selections + selectionDisplay.setPreferredSize(new Vector3f(300, 30, 0)); + dropdownContainer.addChild(selectionDisplay); // Add it to the dropdown container + + return dropdownContainer; + } + /** + * Retrieves the list of properties owned by the current player. + * + * @return List of BuildingProperty objects owned by the player. + */ + private List getPlayerProperties() { + Player self = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()); + BoardManager boardManager = app.getGameLogic().getBoardManager(); + + return boardManager.getPropertyFields(self.getProperties()).stream() + .filter(property -> property instanceof BuildingProperty) + .map(property -> (BuildingProperty) property) + .collect(Collectors.toList()); + } + + @Override + public void update(float delta) { + if(selectionRef.update()) { + onDropdownSelectionChanged(propertySelector); + } + } + + /** + * Handles property selection changes. + */ + private void onDropdownSelectionChanged(Selector playerProperties) { + String selected = playerProperties.getSelectedItem(); + app.getGameLogic().playSound(Sound.BUTTON); + if (selectedProperties.contains(selected)) { + selectedProperties.remove(selected); + } else { + selectedProperties.add(selected); + } + + int cost = 0; + for (String s : selectedProperties) { + cost += ((BuildingProperty) app.getGameLogic().getBoardManager().getFieldByName(s)).getHousePrice(); + } + + String display = String.join(" | ", selectedProperties); + selectionDisplay.setText(display); + + this.cost.setText(cost+""); + } + /** * Schließt das Menü und entfernt die GUI-Elemente. */