added documentation for BuyHouse

This commit is contained in:
Yvonne Schmidt 2024-12-02 08:10:08 +01:00
parent 6f15f12b49
commit 4ac02a1a7b

View File

@ -31,16 +31,35 @@ import java.util.stream.Collectors;
* BuyHouse is a popup which appears when a player clicks on the "Buy House"-button in the BuildingAdminMenu * BuyHouse is a popup which appears when a player clicks on the "Buy House"-button in the BuildingAdminMenu
*/ */
public class BuyHouse extends Dialog { public class BuyHouse extends Dialog {
/** Reference to the Monopoly application instance. */
private final MonopolyApp app; private final MonopolyApp app;
/** Main container for the "Buy House" popup UI. */
private final Container buyHouseContainer; private final Container buyHouseContainer;
/** Background container providing a border for the popup. */
private final Container backgroundContainer; private final Container backgroundContainer;
private TextField selectionDisplay; // TextField to display selections
/** TextField to display selected properties. */
private TextField selectionDisplay;
/** Reference for tracking dropdown selection changes. */
private VersionedReference<Set<Integer>> selectionRef; private VersionedReference<Set<Integer>> selectionRef;
/** Dropdown selector for choosing properties to build houses on. */
private Selector<String> propertySelector; private Selector<String> propertySelector;
/** Set of selected properties for house purchase. */
private Set<String> selectedProperties = new HashSet<>(); private Set<String> selectedProperties = new HashSet<>();
/** Label displaying the total cost of building houses on the selected properties. */
private Label cost = new Label("0", new ElementId("label-Text")); private Label cost = new Label("0", new ElementId("label-Text"));
/**
* Constructs the "Buy House" popup.
*
* @param app the Monopoly application instance
*/
public BuyHouse(MonopolyApp app) { public BuyHouse(MonopolyApp app) {
super(app.getDialogManager()); super(app.getDialogManager());
this.app = app; this.app = app;
@ -119,9 +138,9 @@ public class BuyHouse extends Dialog {
} }
/** /**
* Creates a dropdown menu for selecting a property. * Creates a dropdown menu for selecting properties eligible for house construction.
* *
* @return The dropdown container. * @return The container holding the dropdown menu.
*/ */
private Container createPropertyDropdown() { private Container createPropertyDropdown() {
Container dropdownContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X)); Container dropdownContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X));
@ -154,10 +173,11 @@ public class BuyHouse extends Dialog {
return dropdownContainer; return dropdownContainer;
} }
/** /**
* Retrieves the list of properties owned by the current player. * Retrieves the list of properties owned by the current player that are eligible for house construction.
* *
* @return List of BuildingProperty objects owned by the player. * @return A list of {@link BuildingProperty} objects owned by the player.
*/ */
private List<BuildingProperty> getPlayerProperties() { private List<BuildingProperty> getPlayerProperties() {
Player self = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()); Player self = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId());
@ -170,6 +190,11 @@ public class BuyHouse extends Dialog {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
/**
* Periodically updates the popup, tracking selection changes in the dropdown menu.
*
* @param delta Time since the last update in seconds.
*/
@Override @Override
public void update(float delta) { public void update(float delta) {
if(selectionRef.update()) { if(selectionRef.update()) {
@ -178,7 +203,9 @@ public class BuyHouse extends Dialog {
} }
/** /**
* Handles property selection changes. * Handles property selection changes in the dropdown menu.
*
* @param playerProperties the dropdown selector for the player's properties
*/ */
private void onDropdownSelectionChanged(Selector<String> playerProperties) { private void onDropdownSelectionChanged(Selector<String> playerProperties) {
String selected = playerProperties.getSelectedItem(); String selected = playerProperties.getSelectedItem();
@ -200,6 +227,9 @@ public class BuyHouse extends Dialog {
this.cost.setText(cost+""); this.cost.setText(cost+"");
} }
/**
* Closes the popup and removes its GUI elements.
*/
@Override @Override
public void close() { public void close() {
app.getGuiNode().detachChild(buyHouseContainer); app.getGuiNode().detachChild(buyHouseContainer);
@ -207,6 +237,9 @@ public class BuyHouse extends Dialog {
super.close(); super.close();
} }
/**
* Opens the settings menu when the escape key is pressed.
*/
@Override @Override
public void escape() { public void escape() {
new SettingsMenu(app).open(); new SettingsMenu(app).open();