mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-01-18 22:56:15 +01:00
replaced listbox in sellHouse with a selector
This commit is contained in:
parent
85e0c68a36
commit
79a08a0c9e
@ -17,7 +17,9 @@ import pp.monopoly.client.gui.popups.ConfirmTrade;
|
|||||||
import pp.monopoly.client.gui.popups.EventCardPopup;
|
import pp.monopoly.client.gui.popups.EventCardPopup;
|
||||||
import pp.monopoly.client.gui.popups.FoodFieldCard;
|
import pp.monopoly.client.gui.popups.FoodFieldCard;
|
||||||
import pp.monopoly.client.gui.popups.GateFieldCard;
|
import pp.monopoly.client.gui.popups.GateFieldCard;
|
||||||
|
import pp.monopoly.client.gui.popups.Gulag;
|
||||||
import pp.monopoly.client.gui.popups.LooserPopUp;
|
import pp.monopoly.client.gui.popups.LooserPopUp;
|
||||||
|
import pp.monopoly.client.gui.popups.NoMoneyWarning;
|
||||||
import pp.monopoly.client.gui.popups.TimeOut;
|
import pp.monopoly.client.gui.popups.TimeOut;
|
||||||
import pp.monopoly.client.gui.popups.WinnerPopUp;
|
import pp.monopoly.client.gui.popups.WinnerPopUp;
|
||||||
import pp.monopoly.game.server.Player;
|
import pp.monopoly.game.server.Player;
|
||||||
|
@ -2,12 +2,16 @@ package pp.monopoly.client.gui.popups;
|
|||||||
|
|
||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
|
import com.simsilica.lemur.Axis;
|
||||||
import com.simsilica.lemur.Button;
|
import com.simsilica.lemur.Button;
|
||||||
import com.simsilica.lemur.Container;
|
import com.simsilica.lemur.Container;
|
||||||
import com.simsilica.lemur.Label;
|
import com.simsilica.lemur.Label;
|
||||||
import com.simsilica.lemur.ListBox;
|
import com.simsilica.lemur.ListBox;
|
||||||
|
import com.simsilica.lemur.Selector;
|
||||||
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
||||||
|
import com.simsilica.lemur.component.SpringGridLayout;
|
||||||
import com.simsilica.lemur.core.VersionedList;
|
import com.simsilica.lemur.core.VersionedList;
|
||||||
|
import com.simsilica.lemur.core.VersionedReference;
|
||||||
import com.simsilica.lemur.style.ElementId;
|
import com.simsilica.lemur.style.ElementId;
|
||||||
import pp.dialog.Dialog;
|
import pp.dialog.Dialog;
|
||||||
import pp.monopoly.client.MonopolyApp;
|
import pp.monopoly.client.MonopolyApp;
|
||||||
@ -15,9 +19,11 @@ import pp.monopoly.client.gui.SettingsMenu;
|
|||||||
import pp.monopoly.game.server.Player;
|
import pp.monopoly.game.server.Player;
|
||||||
import pp.monopoly.model.fields.BoardManager;
|
import pp.monopoly.model.fields.BoardManager;
|
||||||
import pp.monopoly.model.fields.BuildingProperty;
|
import pp.monopoly.model.fields.BuildingProperty;
|
||||||
|
import pp.monopoly.model.fields.PropertyField;
|
||||||
import pp.monopoly.notification.Sound;
|
import pp.monopoly.notification.Sound;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,7 +33,9 @@ public class BuyHouse extends Dialog {
|
|||||||
private final MonopolyApp app;
|
private final MonopolyApp app;
|
||||||
private final Container buyHouseContainer;
|
private final Container buyHouseContainer;
|
||||||
private final Container backgroundContainer;
|
private final Container backgroundContainer;
|
||||||
|
private VersionedReference<Set<Integer>> selectionRef;
|
||||||
|
private Selector<String> propertySelector;
|
||||||
|
private BuildingProperty selectedProperty;
|
||||||
|
|
||||||
public BuyHouse(MonopolyApp app) {
|
public BuyHouse(MonopolyApp app) {
|
||||||
super(app.getDialogManager());
|
super(app.getDialogManager());
|
||||||
@ -38,100 +46,69 @@ public class BuyHouse extends Dialog {
|
|||||||
backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background
|
backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background
|
||||||
attachChild(backgroundContainer);
|
attachChild(backgroundContainer);
|
||||||
|
|
||||||
// Hauptcontainer für das Menü
|
// Main container for the menu
|
||||||
buyHouseContainer = new Container();
|
buyHouseContainer = new Container();
|
||||||
buyHouseContainer.setPreferredSize(new Vector3f(800, 600, 0));
|
buyHouseContainer.setPreferredSize(new Vector3f(800, 600, 0));
|
||||||
|
|
||||||
float padding = 10; // Passt den backgroundContainer an die Größe des sellhouseContainers an
|
float padding = 10; // Adjust backgroundContainer size to match buyHouseContainer
|
||||||
backgroundContainer.setPreferredSize(buyHouseContainer.getPreferredSize().addLocal(padding, padding, 0));
|
backgroundContainer.setPreferredSize(buyHouseContainer.getPreferredSize().addLocal(padding, padding, 0));
|
||||||
|
|
||||||
// Titel
|
// Title
|
||||||
Label title = buyHouseContainer.addChild(new Label( "Gebäude Kaufen", new ElementId("warining-Bold")));
|
Label title = buyHouseContainer.addChild(new Label("Gebäude Kaufen", new ElementId("warning-Bold")));
|
||||||
title.setFontSize(48);
|
title.setFontSize(48);
|
||||||
title.setColor(ColorRGBA.Black);
|
title.setColor(ColorRGBA.Black);
|
||||||
|
|
||||||
//Unterteilund des sellHouseContainer in drei "Untercontainer"
|
// Divide buyHouseContainer into three sub-containers
|
||||||
Container upContainer = buyHouseContainer.addChild(new Container());
|
Container upContainer = buyHouseContainer.addChild(new Container());
|
||||||
Container middleContainer = buyHouseContainer.addChild(new Container());
|
Container middleContainer = buyHouseContainer.addChild(new Container());
|
||||||
Container downContainer = buyHouseContainer.addChild(new Container());
|
Container downContainer = buyHouseContainer.addChild(new Container());
|
||||||
|
|
||||||
// Text, der auf der Karte steht
|
// Upper section text
|
||||||
upContainer.addChild(new Label("„Grundstück wählen:", new ElementId("label-Text"))); //TODO hier überall die entsprechenden Variablen einfügen
|
upContainer.addChild(new Label("„Grundstück wählen:", new ElementId("label-Text")));
|
||||||
upContainer.addChild(new Label("", new ElementId("label-Text")));// Leerzeile
|
upContainer.addChild(new Label("", new ElementId("label-Text"))); // Empty line
|
||||||
upContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
upContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||||
|
|
||||||
middleContainer.setPreferredSize(new Vector3f(100, 150, 0));
|
middleContainer.setPreferredSize(new Vector3f(100, 150, 0));
|
||||||
middleContainer.setBackground(new QuadBackgroundComponent(ColorRGBA.Orange));
|
middleContainer.setBackground(new QuadBackgroundComponent(ColorRGBA.Orange));
|
||||||
|
|
||||||
// Create a VersionedList for the ListBox model
|
// Add the property selector dropdown
|
||||||
VersionedList<BuildingProperty> listModel = new VersionedList<>();
|
middleContainer.addChild(createPropertyDropdown());
|
||||||
|
|
||||||
// Retrieve current player and their properties //TODO hier Prüfen, ob abweichungen zur SellHouse-Klasse beachtet werden müssen
|
downContainer.addChild(new Label("", new ElementId("label-Text"))); // Empty line
|
||||||
Player currentPlayer = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId());
|
downContainer.addChild(new Label("Kosten:", new ElementId("label-Text"))); // Label for cost
|
||||||
BoardManager boardManager = app.getGameLogic().getBoardManager();
|
downContainer.addChild(new Label("Hier die tatsächlichen Kosten", new ElementId("label-Text"))); // Cost details
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
|
|
||||||
downContainer.addChild(new Label("", new ElementId("label-Text")));// Leerzeile
|
|
||||||
downContainer.addChild(new Label("Kosten:", new ElementId("label-Text")));// Leerzeile
|
|
||||||
downContainer.addChild(new Label("Hier die tätsächliche Erstattung", new ElementId("label-Text")));
|
|
||||||
downContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
downContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||||
|
|
||||||
// Beenden-Button
|
// Cancel button
|
||||||
Button cancelButton = buyHouseContainer.addChild(new Button("Abbrechen", new ElementId("button")));
|
Button cancelButton = buyHouseContainer.addChild(new Button("Abbrechen", new ElementId("button")));
|
||||||
cancelButton.setFontSize(32);
|
cancelButton.setFontSize(32);
|
||||||
cancelButton.addClickCommands(s -> ifTopDialog(() -> {
|
cancelButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||||
app.getGameLogic().playSound(Sound.BUTTON);
|
app.getGameLogic().playSound(Sound.BUTTON);
|
||||||
close();
|
close();
|
||||||
}));
|
}));
|
||||||
// Kaufen-Button
|
|
||||||
|
// Confirm button
|
||||||
Button confirmButton = buyHouseContainer.addChild(new Button("Bestätigen", new ElementId("button")));
|
Button confirmButton = buyHouseContainer.addChild(new Button("Bestätigen", new ElementId("button")));
|
||||||
confirmButton.setFontSize(32);
|
confirmButton.setFontSize(32);
|
||||||
confirmButton.addClickCommands(s -> ifTopDialog( () -> {
|
confirmButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||||
app.getGameLogic().playSound(Sound.BUTTON);
|
app.getGameLogic().playSound(Sound.BUTTON);
|
||||||
BuildingProperty selected = listBox.getSelectedItem();
|
if (selectedProperty != null) {
|
||||||
if (selected != null) {
|
System.out.println("Confirmed property: " + selectedProperty.getName());
|
||||||
System.out.println("Confirmed property: " + selected.getName());
|
|
||||||
// Send the "alter building" message to the server
|
// Send the "alter building" message to the server
|
||||||
//app.getGameLogic().sendMessage(new AlterBuildingMessage(selected.getId(), false)); TODO Message an Server
|
// app.getGameLogic().sendMessage(new AlterBuildingMessage(selectedProperty.getId(), false)); // TODO
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Zentriere das Popup
|
// Center the popup
|
||||||
buyHouseContainer.setLocalTranslation(
|
buyHouseContainer.setLocalTranslation(
|
||||||
(app.getCamera().getWidth() - buyHouseContainer.getPreferredSize().x) / 2,
|
(app.getCamera().getWidth() - buyHouseContainer.getPreferredSize().x) / 2,
|
||||||
(app.getCamera().getHeight() + buyHouseContainer.getPreferredSize().y) / 2,
|
(app.getCamera().getHeight() + buyHouseContainer.getPreferredSize().y) / 2,
|
||||||
9
|
9
|
||||||
);
|
);
|
||||||
|
|
||||||
// Zentriere das Popup
|
|
||||||
backgroundContainer.setLocalTranslation(
|
backgroundContainer.setLocalTranslation(
|
||||||
(app.getCamera().getWidth() - buyHouseContainer.getPreferredSize().x - padding) / 2,
|
(app.getCamera().getWidth() - buyHouseContainer.getPreferredSize().x - padding) / 2,
|
||||||
(app.getCamera().getHeight() + buyHouseContainer.getPreferredSize().y+ padding) / 2,
|
(app.getCamera().getHeight() + buyHouseContainer.getPreferredSize().y + padding) / 2,
|
||||||
8
|
8
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -139,12 +116,82 @@ public class BuyHouse extends Dialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schließt das Menü und entfernt die GUI-Elemente.
|
* 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() + " (ID: " + property.getId() + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
propertySelector = new Selector<>(propertyOptions, "glass");
|
||||||
|
dropdownContainer.setBackground(new QuadBackgroundComponent(ColorRGBA.Orange));
|
||||||
|
dropdownContainer.addChild(propertySelector);
|
||||||
|
|
||||||
|
// Set initial selection
|
||||||
|
if (!propertyOptions.isEmpty()) {
|
||||||
|
onDropdownSelectionChanged(propertyOptions.get(0), playerProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Track selection changes
|
||||||
|
selectionRef = propertySelector.getSelectionModel().createReference();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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 currentPlayer = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId());
|
||||||
|
BoardManager boardManager = app.getGameLogic().getBoardManager();
|
||||||
|
|
||||||
|
return boardManager.getPropertyFields(currentPlayer.getProperties()).stream()
|
||||||
|
.filter(property -> property instanceof BuildingProperty)
|
||||||
|
.map(property -> (BuildingProperty) property)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles property selection changes.
|
||||||
|
*/
|
||||||
|
private void onDropdownSelectionChanged(String selected, List<BuildingProperty> playerProperties) {
|
||||||
|
app.getGameLogic().playSound(Sound.BUTTON);
|
||||||
|
|
||||||
|
// Extract the ID from the selected string
|
||||||
|
int idStart = selected.indexOf("(ID: ") + 5;
|
||||||
|
int idEnd = selected.indexOf(")", idStart);
|
||||||
|
String idStr = selected.substring(idStart, idEnd);
|
||||||
|
int propertyId = Integer.parseInt(idStr);
|
||||||
|
|
||||||
|
// Find the selected property
|
||||||
|
selectedProperty = playerProperties.stream()
|
||||||
|
.filter(property -> property.getId() == propertyId)
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
if (selectedProperty != null) {
|
||||||
|
System.out.println("Selected property: " + selectedProperty.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
app.getGuiNode().detachChild(buyHouseContainer); // Entferne das Menü
|
app.getGuiNode().detachChild(buyHouseContainer);
|
||||||
app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand
|
app.getGuiNode().detachChild(backgroundContainer);
|
||||||
super.close();
|
super.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,4 +199,4 @@ public class BuyHouse extends Dialog {
|
|||||||
public void escape() {
|
public void escape() {
|
||||||
new SettingsMenu(app).open();
|
new SettingsMenu(app).open();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user