added documentation for LobbyMenu

This commit is contained in:
Yvonne Schmidt 2024-12-02 07:23:25 +01:00
parent acb5c75379
commit c83f7de30c

View File

@ -31,19 +31,47 @@ import pp.monopoly.notification.Sound;
import java.util.Set; import java.util.Set;
/**
* Represents the lobby menu in the Monopoly application.
* <p>
* Provides functionality for player configuration, including input for starting capital,
* player name, and figure selection, as well as options to ready up or exit the game.
* </p>
*/
public class LobbyMenu extends Dialog { public class LobbyMenu extends Dialog {
/** Reference to the Monopoly application instance. */
private final MonopolyApp app; private final MonopolyApp app;
/** Main container for the lobby menu UI. */
private final Container menuContainer; private final Container menuContainer;
/** Background geometry for the menu. */
private Geometry background; private Geometry background;
/** Colored circle displayed between input fields and dropdown menus. */
private Geometry circle; private Geometry circle;
/** Container for the lower-left section of the menu. */
private Container lowerLeftMenu; private Container lowerLeftMenu;
/** Container for the lower-right section of the menu. */
private Container lowerRightMenu; private Container lowerRightMenu;
/** Text field for entering the player's name. */
private TextField playerInputField; private TextField playerInputField;
/** Text field for entering the starting capital. */
private TextField startingCapital = new TextField("15000"); private TextField startingCapital = new TextField("15000");
/** Selected player figure. */
private String figure; private String figure;
/**
* Constructs the lobby menu for player configuration.
*
* @param app the Monopoly application instance
*/
public LobbyMenu(MonopolyApp app) { public LobbyMenu(MonopolyApp app) {
super(app.getDialogManager()); super(app.getDialogManager());
this.app = app; this.app = app;
@ -193,7 +221,7 @@ public class LobbyMenu extends Dialog {
/** /**
* Lädt das Hintergrundbild und fügt es als geometrische Ebene hinzu. * Adds a background image to the lobby menu.
*/ */
private void addBackgroundImage() { private void addBackgroundImage() {
Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/lobby.png"); Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/lobby.png");
@ -207,6 +235,11 @@ public class LobbyMenu extends Dialog {
app.getGuiNode().attachChild(background); app.getGuiNode().attachChild(background);
} }
/**
* Creates a circle graphic element for the menu.
*
* @return the created circle geometry
*/
private Geometry createCircle() { private Geometry createCircle() {
Sphere sphere = new Sphere(90,90,60.0f); Sphere sphere = new Sphere(90,90,60.0f);
@ -220,6 +253,11 @@ public class LobbyMenu extends Dialog {
return circleGeometry; return circleGeometry;
} }
/**
* Maps the player's ID to a corresponding color.
*
* @return the color associated with the player's ID
*/
private ColorRGBA idToColor() { private ColorRGBA idToColor() {
switch (app.getId()+1) { switch (app.getId()+1) {
case 1: return PlayerColor.CYAN.getColor(); case 1: return PlayerColor.CYAN.getColor();
@ -235,19 +273,25 @@ public class LobbyMenu extends Dialog {
} }
/** /**
* Schaltet den "Bereit"-Status um. * Toggles the player's ready state and sends the configuration to the server.
*/ */
private void toggleReady() { private void toggleReady() {
app.getGameLogic().send(new PlayerReady(true, playerInputField.getText(), figure, Integer.parseInt(startingCapital.getText()))); app.getGameLogic().send(new PlayerReady(true, playerInputField.getText(), figure, Integer.parseInt(startingCapital.getText())));
} }
/**
* 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();
} }
/** /**
* Adds a custom action listener to the Selector. * Adds a custom action listener to a dropdown selector.
*
* @param selector the selector to add the listener to
* @param listener the action to perform when a selection changes
*/ */
private void addSelectionActionListener(Selector<String> selector, SelectionActionListener<String> listener) { private void addSelectionActionListener(Selector<String> selector, SelectionActionListener<String> listener) {
VersionedReference<Set<Integer>> selectionRef = selector.getSelectionModel().createReference(); VersionedReference<Set<Integer>> selectionRef = selector.getSelectionModel().createReference();
@ -282,7 +326,9 @@ public class LobbyMenu extends Dialog {
} }
/** /**
* Callback for when the dropdown selection changes. * Updates the selected figure based on the dropdown menu selection.
*
* @param selected the selected figure
*/ */
private void onDropdownSelectionChanged(String selected) { private void onDropdownSelectionChanged(String selected) {
app.getGameLogic().playSound(Sound.BUTTON); app.getGameLogic().playSound(Sound.BUTTON);
@ -311,10 +357,17 @@ public class LobbyMenu extends Dialog {
} }
/** /**
* Functional interface for a selection action listener. * Functional interface for handling selection changes in dropdown menus.
*
* @param <T> the type of the selection
*/ */
@FunctionalInterface @FunctionalInterface
private interface SelectionActionListener<T> { private interface SelectionActionListener<T> {
/**
* Triggered when the selection changes.
*
* @param selection the new selection
*/
void onSelectionChanged(T selection); void onSelectionChanged(T selection);
} }
} }