added selection display

This commit is contained in:
Yvonne Schmidt 2024-12-01 23:22:19 +01:00
parent 3b729c9a04
commit 5522be228b

View File

@ -6,8 +6,8 @@ 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.Selector; import com.simsilica.lemur.Selector;
import com.simsilica.lemur.TextField;
import com.simsilica.lemur.component.QuadBackgroundComponent; import com.simsilica.lemur.component.QuadBackgroundComponent;
import com.simsilica.lemur.component.SpringGridLayout; import com.simsilica.lemur.component.SpringGridLayout;
import com.simsilica.lemur.core.VersionedList; import com.simsilica.lemur.core.VersionedList;
@ -19,9 +19,9 @@ 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.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -36,6 +36,8 @@ public class BuyHouse extends Dialog {
private VersionedReference<Set<Integer>> selectionRef; private VersionedReference<Set<Integer>> selectionRef;
private Selector<String> propertySelector; private Selector<String> propertySelector;
private BuildingProperty selectedProperty; private BuildingProperty selectedProperty;
private TextField selectionDisplay; // TextField to display selections
private final List<String> selectedProperties = new ArrayList<>();
public BuyHouse(MonopolyApp app) { public BuyHouse(MonopolyApp app) {
super(app.getDialogManager()); super(app.getDialogManager());
@ -134,22 +136,23 @@ public class BuyHouse extends Dialog {
} }
propertySelector = new Selector<>(propertyOptions, "glass"); propertySelector = new Selector<>(propertyOptions, "glass");
dropdownContainer.setBackground(new QuadBackgroundComponent(ColorRGBA.Orange));
dropdownContainer.addChild(propertySelector); 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
// Set initial selection // Set initial selection
if (!propertyOptions.isEmpty()) { if (!propertyOptions.isEmpty()) {
onDropdownSelectionChanged(propertyOptions.get(0), playerProperties); onDropdownSelectionChanged(propertyOptions.get(0), playerProperties);
} }
// Track selection changes
selectionRef = propertySelector.getSelectionModel().createReference();
return dropdownContainer; return dropdownContainer;
} }
/** /**
* Retrieves the list of properties owned by the current player. * Retrieves the list of properties owned by the current player.
* *
@ -184,10 +187,37 @@ public class BuyHouse extends Dialog {
.orElse(null); .orElse(null);
if (selectedProperty != null) { if (selectedProperty != null) {
System.out.println("Selected property: " + selectedProperty.getName()); // Add property to the selected list if not already added
if (!selectedProperties.contains(selectedProperty.getName())) {
selectedProperties.add(selectedProperty.getName());
}
// Update the selection display text field
updateSelectionDisplay();
} }
} }
/**
* Updates the selection display text field with the selected properties.
*/
private void updateSelectionDisplay() {
if (selectionDisplay != null) {
String selections = String.join("|", selectedProperties);
selectionDisplay.setText(selections);
}
}
@Override
public void update(float tpf) {
if (selectionRef.update()) {
String selected = propertySelector.getSelectionModel().getObject().toString();
if (selected != null) {
onDropdownSelectionChanged(selected, getPlayerProperties());
}
}
}
@Override @Override
public void close() { public void close() {
app.getGuiNode().detachChild(buyHouseContainer); app.getGuiNode().detachChild(buyHouseContainer);