This commit is contained in:
Johannes Schmelz 2024-12-02 06:53:35 +01:00
commit a73384c436
9 changed files with 201 additions and 35 deletions

View File

@ -15,7 +15,7 @@ import com.jme3.audio.AudioData;
import com.jme3.audio.AudioNode; import com.jme3.audio.AudioNode;
/** /**
* Handles the background music beeing played. Is able to start and stop the music. Set the Volume of the Audio. * Handles the background music being played. Is able to start and stop the music. Set the Volume of the Audio.
*/ */
public class GameMusic extends AbstractAppState{ public class GameMusic extends AbstractAppState{
private static final Logger LOGGER = System.getLogger(GameMusic.class.getName()); private static final Logger LOGGER = System.getLogger(GameMusic.class.getName());

View File

@ -27,9 +27,25 @@ import static pp.util.PreferencesUtils.getPreferences;
* An application state that plays sounds. * An application state that plays sounds.
*/ */
public class GameSound extends AbstractAppState implements GameEventListener { public class GameSound extends AbstractAppState implements GameEventListener {
/**
* Logger instance for logging messages related to GameSound.
*/
private static final Logger LOGGER = System.getLogger(GameSound.class.getName()); private static final Logger LOGGER = System.getLogger(GameSound.class.getName());
/**
* Preferences instance for managing GameSound-related settings.
*/
private static final Preferences PREFERENCES = getPreferences(GameSound.class); private static final Preferences PREFERENCES = getPreferences(GameSound.class);
/**
* Preference key for enabling or disabling GameSound.
*/
private static final String ENABLED_PREF = "enabled"; //NON-NLS private static final String ENABLED_PREF = "enabled"; //NON-NLS
/**
* Preference key for storing the volume level of GameSound.
*/
private static final String VOLUME_PREF = "volume"; //NON-NLS private static final String VOLUME_PREF = "volume"; //NON-NLS
private AudioNode passStartSound; private AudioNode passStartSound;
@ -223,6 +239,11 @@ public class GameSound extends AbstractAppState implements GameEventListener {
PREFERENCES.putFloat(VOLUME_PREF, vol); PREFERENCES.putFloat(VOLUME_PREF, vol);
} }
/**
* Overrides {@link SoundEvent#notifyListener(GameEventListener)}
* @param event the received event
*/
@Override @Override
public void receivedEvent(SoundEvent event) { public void receivedEvent(SoundEvent event) {
switch (event.sound()) { switch (event.sound()) {

View File

@ -48,7 +48,7 @@ import pp.monopoly.notification.InfoTextEvent;
import pp.monopoly.notification.Sound; import pp.monopoly.notification.Sound;
/** /**
* The main class for the Battleship client application. * The main class for the Monopoly client application.
* It manages the initialization, input setup, GUI setup, and game states for the client. * It manages the initialization, input setup, GUI setup, and game states for the client.
*/ */
public class MonopolyApp extends SimpleApplication implements MonopolyClient, GameEventListener { public class MonopolyApp extends SimpleApplication implements MonopolyClient, GameEventListener {
@ -153,7 +153,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
} }
/** /**
* Starts the Battleship application. * Starts the Monopoly application.
* *
* @param args Command-line arguments for launching the application. * @param args Command-line arguments for launching the application.
*/ */
@ -220,9 +220,9 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
} }
/** /**
* Returns the current configuration settings for the Battleship client. * Returns the current configuration settings for the Monopoly client.
* *
* @return The {@link BattleshipClientConfig} instance. //TODO Fehler im Kommentar * @return The {@link pp.monopoly.game.client.MonopolyClientConfig} instance.
*/ */
@Override @Override
public MonopolyAppConfig getConfig() { public MonopolyAppConfig getConfig() {
@ -276,7 +276,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
} }
//logik zum wechselnden erscheinen und verschwinden beim drücken von B //TODO süäter entfernen //logik zum wechselnden erscheinen und verschwinden beim drücken von B //TODO später entfernen
private void handleB(boolean isPressed) { private void handleB(boolean isPressed) {
if (isPressed) { if (isPressed) {
Dialog tmp = new GulagInfo(this, 3); Dialog tmp = new GulagInfo(this, 3);
@ -482,10 +482,24 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
.open(); .open();
} }
/**
* Disconnects the current server connection.
*
* This method delegates the disconnection operation to the `disconnect` method of the
* `serverConnection` object.
*
*/
public void disconnect() { public void disconnect() {
serverConnection.disconnect(); serverConnection.disconnect();
} }
/**
* Retrieves the unique identifier associated with the server connection.
*
* Checks if a Server is connected and returns {@Code 0} if there is no connection
*
* @return the ID of the connected Server instance.
*/
public int getId() { public int getId() {
if (serverConnection != null && serverConnection instanceof NetworkSupport) return ((NetworkSupport) serverConnection).getId(); if (serverConnection != null && serverConnection instanceof NetworkSupport) return ((NetworkSupport) serverConnection).getId();
return 0; return 0;

View File

@ -43,7 +43,6 @@ public class PropertyOverviewMenu extends Dialog {
super(app.getDialogManager()); super(app.getDialogManager());
this.app = app; this.app = app;
// Make the menu fullscreen // Make the menu fullscreen
Vector3f screenSize = new Vector3f(app.getCamera().getWidth(), app.getCamera().getHeight(), 0); 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. * 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 { private class SliderValueChangeListener extends AbstractControl {
@Override @Override
@ -240,6 +241,14 @@ public class PropertyOverviewMenu extends Dialog {
refreshVisibleCards(sliderValue); 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 @Override
protected void controlRender(RenderManager renderManager, ViewPort viewPort) { protected void controlRender(RenderManager renderManager, ViewPort viewPort) {
// No rendering logic needed // No rendering logic needed

View File

@ -24,15 +24,30 @@ import pp.monopoly.notification.Sound;
import static pp.util.PreferencesUtils.getPreferences; import static pp.util.PreferencesUtils.getPreferences;
/** /**
* The Menu class represents the main menu in the Battleship game application. * The Menu class represents the main menu in the Monopoly game application.
* It extends the Dialog class and provides functionalities for loading, saving, * It extends the Dialog class and provides functionalities for Volume adjustment, Sound adjustment,
* returning to the game, and quitting the application. * returning to the game, and quitting the application.
*/ */
public class SettingsMenu extends Dialog { 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 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; private final MonopolyApp app;
/**
* Slider control for adjusting the music volume.
*/
private final VolumeSlider musicSlider; private final VolumeSlider musicSlider;
/**
* Slider control for adjusting the sound effects volume.
*/
private final SoundSlider soundSlider; private final SoundSlider soundSlider;
/** /**

View File

@ -5,7 +5,14 @@ import pp.monopoly.client.GameSound;
public class SoundSlider extends Slider { public class SoundSlider extends Slider {
/**
* Manages sound effects for the game.
*/
private final pp.monopoly.client.GameSound sound; private final pp.monopoly.client.GameSound sound;
/**
* Volume level for the game sounds.
*/
private double vol; 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() { public void update() {
if (vol != getModel().getPercent()) { if (vol != getModel().getPercent()) {

View File

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

View File

@ -25,23 +25,93 @@ import pp.monopoly.notification.GameEventListener;
import pp.monopoly.notification.Sound; import pp.monopoly.notification.Sound;
import pp.monopoly.notification.UpdatePlayerView; 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 { public class Toolbar extends Dialog implements GameEventListener {
/**
* Reference to the Monopoly application instance.
*/
private final MonopolyApp app; private final MonopolyApp app;
/**
* The main container for the toolbar interface.
*/
private final Container toolbarContainer; private final Container toolbarContainer;
/**
* Container for displaying an overview of other players.
*/
private Container overviewContainer; private Container overviewContainer;
/**
* Container for displaying account-related information.
*/
private Container accountContainer; private Container accountContainer;
/**
* Handles player-related data and actions.
*/
private PlayerHandler playerHandler; private PlayerHandler playerHandler;
/**
* Label for the first dice display.
*/
private Label imageLabel; private Label imageLabel;
/**
* Label for the second dice display.
*/
private Label imageLabel2; private Label imageLabel2;
/**
* Button for rolling the dice.
*/
private Button diceButton; private Button diceButton;
/**
* Button for initiating trades.
*/
private Button tradeButton; private Button tradeButton;
/**
* Button for accessing the property menu.
*/
private Button propertyMenuButton; private Button propertyMenuButton;
/**
* Button for ending the player's turn.
*/
private Button endTurnButton; private Button endTurnButton;
/**
* Flag indicating if dice animation is ongoing.
*/
private volatile boolean animatingDice = false; private volatile boolean animatingDice = false;
/**
* Stores the most recent dice roll event.
*/
private volatile DiceRollEvent latestDiceRollEvent = null; 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) { public Toolbar(MonopolyApp app) {
super(app.getDialogManager()); super(app.getDialogManager());
this.app = app; this.app = app;
@ -216,7 +286,10 @@ public class Toolbar extends Dialog implements GameEventListener {
} }
}).start(); }).start();
} }
/**
* Animates the dice roll by cycling through dice images.
*/
private void animateDice(long startTime) throws InterruptedException { private void animateDice(long startTime) throws InterruptedException {
int[] currentFace = {1}; int[] currentFace = {1};
while (System.currentTimeMillis() - startTime < 2000) { // Animation duration while (System.currentTimeMillis() - startTime < 2000) { // Animation duration
@ -233,7 +306,12 @@ public class Toolbar extends Dialog implements GameEventListener {
Thread.sleep(100); // Time between frame updates Thread.sleep(100); // Time between frame updates
} }
} }
/**
* Displays the final dice result after animation.
*
* @param event the dice roll event containing the result
*/
private void showFinalDiceResult(DiceRollEvent event) { private void showFinalDiceResult(DiceRollEvent event) {
app.enqueue(() -> { app.enqueue(() -> {
setDiceIcon(imageLabel, diceToString(event.a())); 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 @Override
public void receivedEvent(DiceRollEvent event) { public void receivedEvent(DiceRollEvent event) {
latestDiceRollEvent = event; latestDiceRollEvent = event;
} }
/**
* Updates the player view with the latest account and overview data.
*
* @param event the update event for the player view
*/
@Override @Override
public void receivedEvent(UpdatePlayerView event) { public void receivedEvent(UpdatePlayerView event) {
playerHandler = app.getGameLogic().getPlayerHandler(); playerHandler = app.getGameLogic().getPlayerHandler();
@ -306,6 +394,11 @@ public class Toolbar extends Dialog implements GameEventListener {
overviewContainer.setBackground(null); overviewContainer.setBackground(null);
} }
/**
* Updates the enabled status of toolbar buttons based on the event.
*
* @param event the button status event
*/
@Override @Override
public void receivedEvent(ButtonStatusEvent event) { public void receivedEvent(ButtonStatusEvent event) {
boolean enabled = event.buttonsEnabled(); boolean enabled = event.buttonsEnabled();
@ -315,17 +408,26 @@ public class Toolbar extends Dialog implements GameEventListener {
endTurnButton.setEnabled(enabled); endTurnButton.setEnabled(enabled);
} }
/**
* Closes the toolbar and detaches it from the GUI.
*/
@Override @Override
public void close() { public void close() {
app.getGuiNode().detachChild(toolbarContainer); app.getGuiNode().detachChild(toolbarContainer);
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();
} }
/**
* Updates the toolbar by refreshing player information.
*/
@Override @Override
public void update() { public void update() {
receivedEvent(new UpdatePlayerView()); 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() { public void update() {
if (vol != getModel().getPercent()) { if (vol != getModel().getPercent()) {