added documentation for TakeMortage

This commit is contained in:
Yvonne Schmidt 2024-12-02 08:54:49 +01:00
parent 4917208818
commit 531a3e263c

View File

@ -29,20 +29,43 @@ import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* TakeMortage is a popup which appears when a player clicks on the "TakeMortage"-button in the BuildingAdminMenu * TakeMortage is a popup that appears when a player clicks on the "Take Mortage" button
* in the BuildingAdminMenu.
* <p>
* This popup allows the player to select properties and take a mortgage on them
* to gain financial benefit during gameplay.
* </p>
*/ */
public class TakeMortage extends Dialog { public class TakeMortage extends Dialog {
/** Reference to the Monopoly application instance. */
private final MonopolyApp app; private final MonopolyApp app;
/** Main container for the TakeMortage dialog UI. */
private final Container takeMortageContainer; private final Container takeMortageContainer;
/** Background container providing a styled border around the main dialog. */
private final Container backgroundContainer; private final Container backgroundContainer;
private TextField selectionDisplay; // TextField to display selections
/** Text field to display selected properties. */
private TextField selectionDisplay;
/** Reference to track selection changes in the property selector. */
private VersionedReference<Set<Integer>> selectionRef; private VersionedReference<Set<Integer>> selectionRef;
/** Dropdown selector for displaying available properties. */
private Selector<String> propertySelector; private Selector<String> propertySelector;
/** Set of properties selected for mortgaging. */
private Set<String> selectedProperties = new HashSet<>(); private Set<String> selectedProperties = new HashSet<>();
/** Label to display the total mortgage amount. */
private Label cost = new Label("0", new ElementId("label-Text")); private Label cost = new Label("0", new ElementId("label-Text"));
/**
* Constructs a new TakeMortage dialog.
*
* @param app The MonopolyApp instance.
*/
public TakeMortage(MonopolyApp app) { public TakeMortage(MonopolyApp app) {
super(app.getDialogManager()); super(app.getDialogManager());
this.app = app; this.app = app;
@ -122,7 +145,7 @@ public class TakeMortage extends Dialog {
/** /**
* Creates a dropdown menu for selecting a property. * Creates a dropdown menu for selecting a property.
* *
* @return The dropdown container. * @return The dropdown container with property options.
*/ */
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));
@ -155,10 +178,14 @@ public class TakeMortage 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.
* <p>
* Only properties that are not currently mortgaged are included.
* </p>
* *
* @return List of PropertyField objects owned by the player. * @return List of eligible PropertyField objects owned by the player.
*/ */
private List<PropertyField> getPlayerProperties() { private List<PropertyField> getPlayerProperties() {
Player self = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()); Player self = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId());
@ -171,6 +198,11 @@ public class TakeMortage extends Dialog {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
/**
* Updates the dialog UI, tracking changes in the property selection.
*
* @param delta Time since the last update.
*/
@Override @Override
public void update(float delta) { public void update(float delta) {
if(selectionRef.update()) { if(selectionRef.update()) {
@ -179,7 +211,9 @@ public class TakeMortage extends Dialog {
} }
/** /**
* Handles property selection changes. * Handles changes to the property selection.
*
* @param playerProperties The dropdown menu's selection state.
*/ */
private void onDropdownSelectionChanged(Selector<String> playerProperties) { private void onDropdownSelectionChanged(Selector<String> playerProperties) {
String selected = playerProperties.getSelectedItem(); String selected = playerProperties.getSelectedItem();
@ -202,7 +236,7 @@ public class TakeMortage extends Dialog {
} }
/** /**
* Schließt das Menü und entfernt die GUI-Elemente. * Closes the dialog and removes GUI elements from the screen.
*/ */
@Override @Override
public void close() { public void close() {
@ -211,6 +245,9 @@ public class TakeMortage extends Dialog {
super.close(); super.close();
} }
/**
* Handles the escape action to close the dialog.
*/
@Override @Override
public void escape() { public void escape() {
new SettingsMenu(app).open(); new SettingsMenu(app).open();