added documentation

This commit is contained in:
Yvonne Schmidt 2024-12-02 05:53:52 +01:00
parent 7f58558da4
commit 0b71c2cb96
6 changed files with 160 additions and 29 deletions

View File

@ -43,7 +43,6 @@ public class PropertyOverviewMenu extends Dialog {
super(app.getDialogManager());
this.app = app;
// Make the menu fullscreen
Vector3f screenSize = new Vector3f(app.getCamera().getWidth(), app.getCamera().getHeight(), 0);
@ -231,6 +230,8 @@ public class PropertyOverviewMenu extends Dialog {
/**
* Custom listener for slider value changes.
* Extends {@link AbstractControl} to respond to updates in the slider's value and refresh
* the visible cards accordingly.
*/
private class SliderValueChangeListener extends AbstractControl {
@Override
@ -240,6 +241,14 @@ public class PropertyOverviewMenu extends Dialog {
refreshVisibleCards(sliderValue);
}
/**
* Overrides the rendering logic for the control.
* <p>
* This implementation does not require any rendering operations, so the method is left empty.
*
* @param renderManager the {@link RenderManager} handling the rendering process.
* @param viewPort the {@link ViewPort} associated with the rendering context.
*/
@Override
protected void controlRender(RenderManager renderManager, ViewPort viewPort) {
// No rendering logic needed

View File

@ -24,15 +24,30 @@ import pp.monopoly.notification.Sound;
import static pp.util.PreferencesUtils.getPreferences;
/**
* The Menu class represents the main menu in the Battleship game application.
* It extends the Dialog class and provides functionalities for loading, saving,
* The Menu class represents the main menu in the Monopoly game application.
* It extends the Dialog class and provides functionalities for Volume adjustment, Sound adjustment,
* returning to the game, and quitting the application.
*/
public class SettingsMenu extends Dialog {
/**
* Preferences instance for storing and retrieving settings specific to the SettingsMenu.
*/
private static final Preferences PREFERENCES = getPreferences(SettingsMenu.class);
private static final String LAST_PATH = "last.file.path";
/**
* Reference to the main Monopoly application instance.
*/
private final MonopolyApp app;
/**
* Slider control for adjusting the music volume.
*/
private final VolumeSlider musicSlider;
/**
* Slider control for adjusting the sound effects volume.
*/
private final SoundSlider soundSlider;
/**

View File

@ -5,7 +5,14 @@ import pp.monopoly.client.GameSound;
public class SoundSlider extends Slider {
/**
* Manages sound effects for the game.
*/
private final pp.monopoly.client.GameSound sound;
/**
* Volume level for the game sounds.
*/
private double vol;
/**
@ -20,7 +27,7 @@ public class SoundSlider extends Slider {
}
/**
* when triggered it updates the volume to the value set with the slider
* When triggered it updates the volume to the value set with the slider
*/
public void update() {
if (vol != getModel().getPercent()) {

View File

@ -18,7 +18,6 @@ import pp.monopoly.notification.Sound;
/**
* Constructs the startup menu dialog for the Monopoly application.
import pp.monopoly.client.gui.GameMenu;
*/
public class StartMenu extends Dialog {
private final MonopolyApp app;
@ -42,25 +41,24 @@ public class StartMenu extends Dialog {
Material backgroundMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
backgroundMaterial.setTexture("ColorMap", backgroundImage);
background.setMaterial(backgroundMaterial);
background.setLocalTranslation(0, 0, -1); // Ensure it is behind other GUI elements
background.setLocalTranslation(0, 0, -1);
app.getGuiNode().attachChild(background);
// Center container for title and play button
Container centerMenu = new Container(new SpringGridLayout(Axis.Y, Axis.X));
Button startButton = new Button("Spielen");
startButton.setPreferredSize(new Vector3f(190, 60, 0)); // Increase button size (width, height)
startButton.setFontSize(40); // Set the font size for the button text
startButton.setTextHAlignment(HAlignment.Center); // Center the text horizontally
startButton.setPreferredSize(new Vector3f(190, 60, 0));
startButton.setFontSize(40);
startButton.setTextHAlignment(HAlignment.Center);
startButton.addClickCommands(s -> ifTopDialog(() -> {
close();
app.getGameLogic().playSound(Sound.BUTTON);
app.connect(); // Perform the connection logic
app.connect();
}));
centerMenu.addChild(startButton);
// Position the center container in the middle of the screen
centerMenu.setLocalTranslation(new Vector3f(screenWidth / 2f - centerMenu.getPreferredSize().x / 2f,
screenHeight / 2f - 280 + centerMenu.getPreferredSize().y / 2f,
0));
@ -74,38 +72,32 @@ public class StartMenu extends Dialog {
QuadBackgroundComponent logoBackground = new QuadBackgroundComponent(logoTexture);
logoContainer.setBackground(logoBackground);
// Set the size of the container to fit the logo
float logoWidth = 512; // Adjust these values based on the logo dimensions
float logoHeight = 128; // Adjust these values based on the logo dimensions
float logoWidth = 512;
float logoHeight = 128;
logoContainer.setPreferredSize(new Vector3f(logoWidth, logoHeight, 0));
// Position the container at the center of the screen
logoContainer.setLocalTranslation(new Vector3f(
screenWidth / 2f - logoWidth / 2f,
screenHeight / 2f + 200, // Adjust this value for vertical position
screenHeight / 2f + 200,
0
));
// Attach the container to the GUI node
app.getGuiNode().attachChild(logoContainer);
// Load the Unibw logo as a texture
Texture unibwTexture = app.getAssetManager().loadTexture("Pictures/logo-unibw.png");
// Create a container for the Unibw logo
Container unibwContainer = new Container();
QuadBackgroundComponent unibwBackground = new QuadBackgroundComponent(unibwTexture);
unibwContainer.setBackground(unibwBackground);
// Set the size of the container to fit the Unibw logo
float unibwWidth = 512; // Adjust these values based on the logo dimensions
float unibwHeight = 128; // Adjust these values based on the logo dimensions
float unibwWidth = 512;
float unibwHeight = 128;
unibwContainer.setPreferredSize(new Vector3f(unibwWidth, unibwHeight, 0));
// Position the container slightly below the Monopoly logo
unibwContainer.setLocalTranslation(new Vector3f(
screenWidth / 2f - unibwWidth / 2f,
screenHeight / 2f + 100, // Adjust this value for vertical position
screenHeight / 2f + 100,
0
));
@ -113,11 +105,17 @@ public class StartMenu extends Dialog {
app.getGuiNode().attachChild(unibwContainer);
}
/**
* Opens the settings menu when the escape key is pressed.
*/
@Override
public void escape() {
new SettingsMenu(app).open();
}
/**
* Closes the startup menu and detaches all GUI elements.
*/
@Override
public void close() {
app.getGuiNode().detachAllChildren();

View File

@ -25,23 +25,93 @@ import pp.monopoly.notification.GameEventListener;
import pp.monopoly.notification.Sound;
import pp.monopoly.notification.UpdatePlayerView;
/**
* Represents the toolbar interface in the Monopoly application.
* <p>
* This class provides game controls, player information, and event handling
* for actions such as dice rolling, trading, and ending turns.
* Implements {@link GameEventListener} to respond to game events.
* </p>
*/
public class Toolbar extends Dialog implements GameEventListener {
/**
* Reference to the Monopoly application instance.
*/
private final MonopolyApp app;
/**
* The main container for the toolbar interface.
*/
private final Container toolbarContainer;
/**
* Container for displaying an overview of other players.
*/
private Container overviewContainer;
/**
* Container for displaying account-related information.
*/
private Container accountContainer;
/**
* Handles player-related data and actions.
*/
private PlayerHandler playerHandler;
/**
* Label for the first dice display.
*/
private Label imageLabel;
/**
* Label for the second dice display.
*/
private Label imageLabel2;
/**
* Button for rolling the dice.
*/
private Button diceButton;
/**
* Button for initiating trades.
*/
private Button tradeButton;
/**
* Button for accessing the property menu.
*/
private Button propertyMenuButton;
/**
* Button for ending the player's turn.
*/
private Button endTurnButton;
/**
* Flag indicating if dice animation is ongoing.
*/
private volatile boolean animatingDice = false;
/**
* Stores the most recent dice roll event.
*/
private volatile DiceRollEvent latestDiceRollEvent = null;
/**
* Constructs the toolbar for the Monopoly application.
* <p>
* Initializes the toolbar interface, adds event listeners, and sets up
* the GUI elements such as dice, buttons, and player information displays.
* </p>
*
* @param app the Monopoly application instance
*/
public Toolbar(MonopolyApp app) {
super(app.getDialogManager());
this.app = app;
@ -217,6 +287,9 @@ public class Toolbar extends Dialog implements GameEventListener {
}).start();
}
/**
* Animates the dice roll by cycling through dice images.
*/
private void animateDice(long startTime) throws InterruptedException {
int[] currentFace = {1};
while (System.currentTimeMillis() - startTime < 2000) { // Animation duration
@ -234,6 +307,11 @@ public class Toolbar extends Dialog implements GameEventListener {
}
}
/**
* Displays the final dice result after animation.
*
* @param event the dice roll event containing the result
*/
private void showFinalDiceResult(DiceRollEvent event) {
app.enqueue(() -> {
setDiceIcon(imageLabel, diceToString(event.a()));
@ -260,11 +338,21 @@ public class Toolbar extends Dialog implements GameEventListener {
}
}
/**
* Handles dice roll events by updating the dice display.
*
* @param event the dice roll event containing dice values
*/
@Override
public void receivedEvent(DiceRollEvent event) {
latestDiceRollEvent = event;
}
/**
* Updates the player view with the latest account and overview data.
*
* @param event the update event for the player view
*/
@Override
public void receivedEvent(UpdatePlayerView event) {
playerHandler = app.getGameLogic().getPlayerHandler();
@ -306,6 +394,11 @@ public class Toolbar extends Dialog implements GameEventListener {
overviewContainer.setBackground(null);
}
/**
* Updates the enabled status of toolbar buttons based on the event.
*
* @param event the button status event
*/
@Override
public void receivedEvent(ButtonStatusEvent event) {
boolean enabled = event.buttonsEnabled();
@ -315,17 +408,26 @@ public class Toolbar extends Dialog implements GameEventListener {
endTurnButton.setEnabled(enabled);
}
/**
* Closes the toolbar and detaches it from the GUI.
*/
@Override
public void close() {
app.getGuiNode().detachChild(toolbarContainer);
super.close();
}
/**
* Opens the settings menu when the escape key is pressed.
*/
@Override
public void escape() {
new SettingsMenu(app).open();
}
/**
* Updates the toolbar by refreshing player information.
*/
@Override
public void update() {
receivedEvent(new UpdatePlayerView());

View File

@ -25,7 +25,7 @@ public class VolumeSlider extends Slider {
}
/**
* when triggered it updates the volume to the value set with the slider
* When triggered it updates the volume to the value set with the slider
*/
public void update() {
if (vol != getModel().getPercent()) {