tmp settings menu fix

This commit is contained in:
Johannes Schmelz 2024-11-24 19:02:56 +01:00
parent 6a34dab00c
commit fb28f3fefc
12 changed files with 83 additions and 165 deletions

View File

@ -18,10 +18,11 @@ import com.simsilica.lemur.style.ElementId;
import static pp.battleship.Resources.lookup; import static pp.battleship.Resources.lookup;
import pp.battleship.client.gui.GameMusic; import pp.battleship.client.gui.GameMusic;
import pp.battleship.client.gui.VolumeSlider;
import pp.dialog.Dialog; import pp.dialog.Dialog;
import pp.dialog.StateCheckboxModel; import pp.dialog.StateCheckboxModel;
import pp.dialog.TextInputDialog; import pp.dialog.TextInputDialog;
import pp.monopoly.client.gui.VolumeSlider;
import static pp.util.PreferencesUtils.getPreferences; import static pp.util.PreferencesUtils.getPreferences;
/** /**

View File

@ -1,51 +0,0 @@
////////////////////////////////////////
// Programming project code
// UniBw M, 2022, 2023, 2024
// www.unibw.de/inf2
// (c) Mark Minas (mark.minas@unibw.de)
////////////////////////////////////////
package pp.monopoly.client;
import java.util.prefs.Preferences;
import pp.dialog.Dialog;
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,
* returning to the game, and quitting the application.
*/
class Menu extends Dialog {
private static final Preferences PREFERENCES = getPreferences(Menu.class);
private static final String LAST_PATH = "last.file.path";
private final MonopolyApp app;
/**
* Constructs the Menu dialog for the Battleship application.
*
* @param app the BattleshipApp instance
*/
public Menu(MonopolyApp app) {
super(app.getDialogManager());
this.app = app;
}
/**
* Updates the state of the load and save buttons based on the game logic.
*/
@Override
public void update() {
}
/**
* As an escape action, this method closes the menu if it is the top dialog.
*/
@Override
public void escape() {
close();
}
}

View File

@ -21,6 +21,7 @@ import com.jme3.system.AppSettings;
import com.simsilica.lemur.GuiGlobals; import com.simsilica.lemur.GuiGlobals;
import com.simsilica.lemur.style.BaseStyles; import com.simsilica.lemur.style.BaseStyles;
import pp.monopoly.game.client.MonopolyClient; import pp.monopoly.game.client.MonopolyClient;
import pp.monopoly.client.gui.SettingsMenu;
import pp.monopoly.game.client.ClientGameLogic; import pp.monopoly.game.client.ClientGameLogic;
import pp.monopoly.game.client.ServerConnection; import pp.monopoly.game.client.ServerConnection;
import pp.monopoly.notification.ClientStateEvent; import pp.monopoly.notification.ClientStateEvent;
@ -159,7 +160,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
*/ */
private AppSettings makeSettings() { private AppSettings makeSettings() {
final AppSettings settings = new AppSettings(true); final AppSettings settings = new AppSettings(true);
settings.setTitle(lookup("battleship.name")); settings.setTitle(lookup("monopoly.name"));
settings.setResolution(config.getResolutionWidth(), config.getResolutionHeight()); settings.setResolution(config.getResolutionWidth(), config.getResolutionHeight());
settings.setFullscreen(config.fullScreen()); settings.setFullscreen(config.fullScreen());
settings.setUseRetinaFrameBuffer(config.useRetinaFrameBuffer()); settings.setUseRetinaFrameBuffer(config.useRetinaFrameBuffer());
@ -217,7 +218,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
setupInput(); setupInput();
setupStates(); setupStates();
setupGui(); setupGui();
serverConnection.connect(); // serverConnection.connect();
} }
/** /**
@ -305,7 +306,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
if (dialogManager.showsDialog()) if (dialogManager.showsDialog())
dialogManager.escape(); dialogManager.escape();
else else
new Menu(this).open(); new SettingsMenu(this).open();
} }
/** /**

View File

@ -161,7 +161,7 @@ public class StartMenu extends Dialog {
*/ */
private static void startGame(MonopolyApp app) { private static void startGame(MonopolyApp app) {
app.getGuiNode().detachAllChildren(); app.getGuiNode().detachAllChildren();
app.getServerConnection().connect(); // app.getServerConnection().connect();
} }
/** /**

View File

@ -214,7 +214,7 @@ public class LobbyMenu {
app.getGuiNode().detachChild(circle); app.getGuiNode().detachChild(circle);
app.getGuiNode().detachChild(lowerLeftMenu); app.getGuiNode().detachChild(lowerLeftMenu);
app.getGuiNode().detachChild(lowerRightMenu); app.getGuiNode().detachChild(lowerRightMenu);
app.getServerConnection().connect(); // app.getServerConnection().connect();
} }
/** /**

View File

@ -1,123 +1,77 @@
////////////////////////////////////////
// Programming project code
// UniBw M, 2022, 2023, 2024
// www.unibw.de/inf2
// (c) Mark Minas (mark.minas@unibw.de)
////////////////////////////////////////
package pp.monopoly.client.gui; package pp.monopoly.client.gui;
import com.jme3.material.Material; import java.util.prefs.Preferences;
import com.jme3.material.RenderState.BlendMode;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Quad;
import com.simsilica.lemur.Button; import com.simsilica.lemur.Button;
import com.simsilica.lemur.Checkbox; import com.simsilica.lemur.Checkbox;
import com.simsilica.lemur.Container;
import com.simsilica.lemur.Label; import com.simsilica.lemur.Label;
import com.simsilica.lemur.Slider;
import com.simsilica.lemur.component.QuadBackgroundComponent;
import com.simsilica.lemur.style.ElementId; import com.simsilica.lemur.style.ElementId;
import com.simsilica.lemur.ValueRenderer;
import com.simsilica.lemur.Selector; import static pp.monopoly.Resources.lookup;
import pp.dialog.Dialog; import pp.monopoly.client.GameMusic;
import pp.monopoly.client.GameSound;
import pp.monopoly.client.MonopolyApp; import pp.monopoly.client.MonopolyApp;
import pp.dialog.Dialog;
import pp.dialog.StateCheckboxModel;
import static pp.util.PreferencesUtils.getPreferences;
/** /**
* SettingsMenu ist ein Overlay-Menü, das durch ESC aufgerufen werden kann. * The Menu class represents the main menu in the Battleship game application.
* It extends the Dialog class and provides functionalities for loading, saving,
* returning to the game, and quitting the application.
*/ */
public class SettingsMenu extends Dialog { public class SettingsMenu extends Dialog {
private static final Preferences PREFERENCES = getPreferences(SettingsMenu.class);
private static final String LAST_PATH = "last.file.path";
private final MonopolyApp app; private final MonopolyApp app;
private final Geometry overlayBackground; private final VolumeSlider slider;
private final Container settingsContainer;
private final Container backgroundContainer;
/**
* Constructs the Menu dialog for the Battleship application.
*
* @param app the MonopolyApp instance
*/
public SettingsMenu(MonopolyApp app) { public SettingsMenu(MonopolyApp app) {
super(app.getDialogManager()); super(app.getDialogManager());
this.app = app; this.app = app;
slider = new VolumeSlider(app.getStateManager().getState(GameMusic.class));
addChild(new Label(lookup("monopoly.name"), new ElementId("header"))); //NON-NLS
addChild(new Checkbox(lookup("menu.sound-enabled"), new StateCheckboxModel(app, GameSound.class)));
// Halbtransparentes Overlay hinzufügen addChild(new Checkbox(lookup("menu.background-sound-enabled"), new StateCheckboxModel(app, GameMusic.class)));
overlayBackground = createOverlayBackground();
app.getGuiNode().attachChild(overlayBackground);
// Create the background container addChild(slider);
backgroundContainer = new Container();
backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background
app.getGuiNode().attachChild(backgroundContainer);
// Hauptcontainer für das Menü addChild(new Button(lookup("menu.return-to-game"))).addClickCommands(s -> ifTopDialog(this::close));
settingsContainer = new Container(); addChild(new Button(lookup("menu.quit"))).addClickCommands(s -> ifTopDialog(app::closeApp));
settingsContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.1f, 0.1f, 0.1f, 0.9f)));
update();
// Titel
Label settingsTitle = settingsContainer.addChild(new Label("Einstellungen", new ElementId("settings-title")));
settingsTitle.setFontSize(48);
// Effekt-Sound: Slider und Checkbox
Container effectSoundContainer = settingsContainer.addChild(new Container());
effectSoundContainer.addChild(new Label("Effekt Sound", new ElementId("label")));
effectSoundContainer.addChild(new Slider());
effectSoundContainer.addChild(new Checkbox("Soundeffekte an")).setChecked(true);
effectSoundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
// Hintergrundmusik: Slider und Checkbox
Container backgroundMusicContainer = settingsContainer.addChild(new Container());
backgroundMusicContainer.addChild(new Label("Hintergrund Musik", new ElementId("label")));
backgroundMusicContainer.addChild(new Slider());
backgroundMusicContainer.addChild(new Checkbox("Musik an")).setChecked(true);
backgroundMusicContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
// Beenden-Button
Button quitButton = settingsContainer.addChild(new Button("Beenden", new ElementId("menu-button")));
quitButton.setFontSize(32);
quitButton.addClickCommands(source -> app.stop());
float padding = 10; // Padding around the settingsContainer for the background
backgroundContainer.setPreferredSize(settingsContainer.getPreferredSize().addLocal(padding, padding, 0));
// Zentriere das Menü
settingsContainer.setLocalTranslation(
(app.getCamera().getWidth() - settingsContainer.getPreferredSize().x) / 2,
(app.getCamera().getHeight() + settingsContainer.getPreferredSize().y) / 2,
4
);
backgroundContainer.setLocalTranslation(
(app.getCamera().getWidth() - settingsContainer.getPreferredSize().x - padding) / 2,
(app.getCamera().getHeight() + settingsContainer.getPreferredSize().y+ padding) / 2,
3
);
app.getGuiNode().attachChild(settingsContainer);
} }
/** /**
* Erstellt einen halbtransparenten Hintergrund für das Menü. * Updates the state of the load and save buttons based on the game logic.
*
* @return Geometrie des Overlays
*/
private Geometry createOverlayBackground() {
Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight());
Geometry overlay = new Geometry("Overlay", quad);
Material material = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
material.setColor("Color", new ColorRGBA(0, 0, 0, 0.5f)); // Halbtransparent
material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
overlay.setMaterial(material);
overlay.setLocalTranslation(0, 0, 0);
return overlay;
}
/**
* Schließt das Menü und entfernt die GUI-Elemente.
*/ */
@Override @Override
public void close() { public void update() {
System.out.println("Schließe SettingsMenu..."); // Debugging-Ausgabe
app.getGuiNode().detachChild(settingsContainer); // Entferne das Menü
app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand
app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay
app.setSettingsMenuOpen(false); // Menü als geschlossen markieren
app.unblockInputs(); // Eingaben wieder aktivieren
System.out.println("SettingsMenu geschlossen."); // Debugging-Ausgabe
} }
@Override
public void update(float delta) {
slider.update();
}
/**
* As an escape action, this method closes the menu if it is the top dialog.
*/
@Override
public void escape() {
close();
}
} }

View File

@ -1,6 +1,8 @@
package pp.battleship.client.gui; package pp.monopoly.client.gui;
import com.simsilica.lemur.Slider; import com.simsilica.lemur.Slider;
import pp.monopoly.client.GameMusic;
/** /**
* The VolumeSlider class represents the Volume Slider in the Menu. * The VolumeSlider class represents the Volume Slider in the Menu.
* It extends the Slider class and provides functionalities for setting the music volume, * It extends the Slider class and provides functionalities for setting the music volume,
@ -8,7 +10,7 @@ import com.simsilica.lemur.Slider;
*/ */
public class VolumeSlider extends Slider { public class VolumeSlider extends Slider {
private final GameMusic music; private final pp.monopoly.client.GameMusic music;
private double vol; private double vol;
/** /**

View File

@ -30,7 +30,7 @@ public class BuildingPropertyCard extends Dialog {
this.app = app; this.app = app;
//Generate the corresponfing field //Generate the corresponfing field
BuildingProperty field = (BuildingProperty) app.getBoardManager().getFieldAtIndex(index); BuildingProperty field = (BuildingProperty) app.getGameLogic().getBoardManager().getFieldAtIndex(index);
// Halbtransparentes Overlay hinzufügen // Halbtransparentes Overlay hinzufügen
overlayBackground = createOverlayBackground(); overlayBackground = createOverlayBackground();
@ -121,8 +121,8 @@ public class BuildingPropertyCard extends Dialog {
app.getGuiNode().detachChild(buildingPropertyContainer); // Entferne das Menü app.getGuiNode().detachChild(buildingPropertyContainer); // Entferne das Menü
app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand
app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay
app.setSettingsMenuOpen(false); // Menü als geschlossen markieren // app.setSettingsMenuOpen(false); // Menü als geschlossen markieren
app.unblockInputs(); // Eingaben wieder aktivieren // app.unblockInputs(); // Eingaben wieder aktivieren
System.out.println("SettingsMenu geschlossen."); // Debugging-Ausgabe System.out.println("SettingsMenu geschlossen."); // Debugging-Ausgabe
} }

View File

@ -107,8 +107,8 @@ public class BuyCard extends Dialog {
app.getGuiNode().detachChild(settingsContainer); // Entferne das Menü app.getGuiNode().detachChild(settingsContainer); // Entferne das Menü
app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand
app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay
app.setSettingsMenuOpen(false); // Menü als geschlossen markieren // app.setSettingsMenuOpen(false); // Menü als geschlossen markieren
app.unblockInputs(); // Eingaben wieder aktivieren // app.unblockInputs(); // Eingaben wieder aktivieren
System.out.println("SettingsMenu geschlossen."); // Debugging-Ausgabe System.out.println("SettingsMenu geschlossen."); // Debugging-Ausgabe
} }

View File

@ -30,7 +30,7 @@ public class FoodFieldCard extends Dialog {
this.app = app; this.app = app;
//Generate the corresponfing field //Generate the corresponfing field
FoodField field = (FoodField) app.getBoardManager().getFieldAtIndex(index); FoodField field = (FoodField) app.getGameLogic().getBoardManager().getFieldAtIndex(index);
// Halbtransparentes Overlay hinzufügen // Halbtransparentes Overlay hinzufügen
overlayBackground = createOverlayBackground(); overlayBackground = createOverlayBackground();
@ -125,8 +125,8 @@ public class FoodFieldCard extends Dialog {
app.getGuiNode().detachChild(foodFieldContainer); // Entferne das Menü app.getGuiNode().detachChild(foodFieldContainer); // Entferne das Menü
app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand
app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay
app.setSettingsMenuOpen(false); // Menü als geschlossen markieren // app.setSettingsMenuOpen(false); // Menü als geschlossen markieren
app.unblockInputs(); // Eingaben wieder aktivieren // app.unblockInputs(); // Eingaben wieder aktivieren
System.out.println("SettingsMenu geschlossen."); // Debugging-Ausgabe System.out.println("SettingsMenu geschlossen."); // Debugging-Ausgabe
} }

View File

@ -28,7 +28,7 @@ public class GateFieldCard extends Dialog {
this.app = app; this.app = app;
//Generate the corresponfing field //Generate the corresponfing field
GateField field = (GateField) app.getBoardManager().getFieldAtIndex(index); GateField field = (GateField) app.getGameLogic().getBoardManager().getFieldAtIndex(index);
// Halbtransparentes Overlay hinzufügen // Halbtransparentes Overlay hinzufügen
overlayBackground = createOverlayBackground(); overlayBackground = createOverlayBackground();
@ -118,8 +118,8 @@ public class GateFieldCard extends Dialog {
app.getGuiNode().detachChild(gateFieldContainer); // Entferne das Menü app.getGuiNode().detachChild(gateFieldContainer); // Entferne das Menü
app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand
app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay
app.setSettingsMenuOpen(false); // Menü als geschlossen markieren // app.setSettingsMenuOpen(false); // Menü als geschlossen markieren
app.unblockInputs(); // Eingaben wieder aktivieren // app.unblockInputs(); // Eingaben wieder aktivieren
System.out.println("SettingsMenu geschlossen."); // Debugging-Ausgabe System.out.println("SettingsMenu geschlossen."); // Debugging-Ausgabe
} }

View File

@ -22,6 +22,7 @@ import pp.monopoly.message.server.TradeRequest;
import pp.monopoly.message.server.ViewAssetsResponse; import pp.monopoly.message.server.ViewAssetsResponse;
import pp.monopoly.model.Board; import pp.monopoly.model.Board;
import pp.monopoly.model.IntPoint; import pp.monopoly.model.IntPoint;
import pp.monopoly.model.fields.BoardManager;
import pp.monopoly.notification.ClientStateEvent; import pp.monopoly.notification.ClientStateEvent;
import pp.monopoly.notification.GameEvent; import pp.monopoly.notification.GameEvent;
import pp.monopoly.notification.GameEventBroker; import pp.monopoly.notification.GameEventBroker;
@ -53,6 +54,8 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
private PlayerHandler playerHandler; private PlayerHandler playerHandler;
private BoardManager boardManager = new BoardManager();
/** /**
* Constructs a ClientGameLogic with the specified sender object. * Constructs a ClientGameLogic with the specified sender object.
* *
@ -62,6 +65,14 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
this.clientSender = clientSender; this.clientSender = clientSender;
} }
/**
* Reutns the BoardManager
* @return the boardManager
*/
public BoardManager getBoardManager() {
return boardManager;
}
/** /**
* Returns the current state of the game logic. * Returns the current state of the game logic.
* *