added selector to SellHouse

This commit is contained in:
Yvonne Schmidt 2024-11-29 05:16:33 +01:00
parent 94ba9f0af2
commit 7d9af0c4c7

View File

@ -4,17 +4,26 @@ import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.simsilica.lemur.Button;
import com.simsilica.lemur.Checkbox;
import com.simsilica.lemur.Container;
import com.simsilica.lemur.Label;
import com.simsilica.lemur.ListBox;
import com.simsilica.lemur.component.IconComponent;
import com.simsilica.lemur.component.QuadBackgroundComponent;
import com.simsilica.lemur.core.VersionedList;
import com.simsilica.lemur.style.ElementId;
import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp;
import pp.monopoly.client.gui.SettingsMenu;
import pp.monopoly.game.server.Player;
import pp.monopoly.message.client.BuyPropertyResponse;
import pp.monopoly.model.fields.BoardManager;
import pp.monopoly.model.fields.BuildingProperty;
import pp.monopoly.notification.Sound;
import java.util.List;
import java.util.stream.Collectors;
/**
* SettingsMenu ist ein Overlay-Menü, das durch ESC aufgerufen werden kann.
*/
@ -39,6 +48,7 @@ public class SellHouse extends Dialog {
// Hauptcontainer für die Gebäudekarte
sellhouseContainer = new Container();
sellhouseContainer.setPreferredSize(new Vector3f(800, 600, 0));
Label title = sellhouseContainer.addChild(new Label( "Gebäude Abreißen", new ElementId("label-Bold"))); //TODO ggf die Buttons Sprachabhängig von den Properties machen
@ -54,11 +64,65 @@ public class SellHouse extends Dialog {
upContainer.addChild(new Label("„Grundstück wählen:", new ElementId("label-Text"))); //TODO hier überall die entsprechenden Variablen einfügen
upContainer.addChild(new Label("", new ElementId("label-Text")));// Leerzeile
upContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
middleContainer.setPreferredSize(new Vector3f(100, 150, 0));
middleContainer.setBackground(new QuadBackgroundComponent(ColorRGBA.Red));
middleContainer.addChild(new Label("Dies ist ein Container", new ElementId("label-Text")));
middleContainer.addChild(new Label("", new ElementId("label-Text")));
middleContainer.addChild(new Label("Hier kann der Slider und die Checkbocen eingefügt werden", new ElementId("label-Text")));
middleContainer.setBackground(new QuadBackgroundComponent(ColorRGBA.Orange));
/*
// Create a VersionedList for the ListBox model
VersionedList<String> checkboxListModel = new VersionedList<>();
for (int i = 1; i <= 10; i++) {
checkboxListModel.add("Option " + i); // Add items to the list
}
// Create a ListBox with the "glass" style and the model
ListBox<String> checkboxListBox = new ListBox<>(checkboxListModel, "glass");
checkboxListBox.setPreferredSize(new Vector3f(300, 200, 0)); // Adjust size as needed
// Add the ListBox to the middle container
middleContainer.addChild(checkboxListBox);
// If you need separate checkboxes (optional), render them separately
for (String option : checkboxListModel) {
Checkbox checkbox = new Checkbox(option);
checkbox.setFontSize(16); // Optional: adjust font size
middleContainer.addChild(checkbox); // Add it to the middle container
}
// Add the ListBox to the middle container
middleContainer.addChild(checkboxListBox); */
// Create a VersionedList for the ListBox model
VersionedList<BuildingProperty> listModel = new VersionedList<>();
// Retrieve current player and their properties
Player currentPlayer = app.getGameLogic().getPlayerHandler().getPlayers().get(0);
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);
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")));
@ -76,10 +140,16 @@ public class SellHouse extends Dialog {
confirmButton.setFontSize(32);
confirmButton.addClickCommands(s -> ifTopDialog( () -> {
app.getGameLogic().playSound(Sound.BUTTON);
//TODO
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
}
}));
float padding = 10; // Padding around the settingsContainer for the background
backgroundContainer.setPreferredSize(sellhouseContainer.getPreferredSize().addLocal(padding, padding, 0));