mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-01-18 18:23:44 +01:00
added selector and selection display to TakeMortage
This commit is contained in:
parent
d08a172227
commit
e05ad71fff
@ -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)));
|
||||
|
||||
|
@ -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<Set<Integer>> selectionRef;
|
||||
private Selector<String> propertySelector;
|
||||
private Set<String> 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<BuildingProperty> 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<BuildingProperty> 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<BuildingProperty> 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<String> propertyOptions = new VersionedList<>();
|
||||
List<BuildingProperty> 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<BuildingProperty> 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<String> 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.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user