From fb28f3fefc17dbd1b704c404c9c2d8fc6e10b7cf Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Sun, 24 Nov 2024 19:02:56 +0100 Subject: [PATCH] tmp settings menu fix --- .../main/java/pp/battleship/client/Menu.java | 3 +- .../main/java/pp/monopoly/client/Menu.java | 51 ------- .../java/pp/monopoly/client/MonopolyApp.java | 7 +- .../java/pp/monopoly/client/StartMenu.java | 2 +- .../pp/monopoly/client/gui/LobbyMenu.java | 2 +- .../pp/monopoly/client/gui/SettingsMenu.java | 144 ++++++------------ .../pp/monopoly}/client/gui/VolumeSlider.java | 6 +- .../gui/popups/BuildingPropertyCard.java | 6 +- .../monopoly/client/gui/popups/BuyCard.java | 4 +- .../client/gui/popups/FoodFieldCard.java | 6 +- .../client/gui/popups/GateFieldCard.java | 6 +- .../monopoly/game/client/ClientGameLogic.java | 11 ++ 12 files changed, 83 insertions(+), 165 deletions(-) delete mode 100644 Projekte/monopoly/client/src/main/java/pp/monopoly/client/Menu.java rename Projekte/{battleship/client/src/main/java/pp/battleship => monopoly/client/src/main/java/pp/monopoly}/client/gui/VolumeSlider.java (87%) diff --git a/Projekte/battleship/client/src/main/java/pp/battleship/client/Menu.java b/Projekte/battleship/client/src/main/java/pp/battleship/client/Menu.java index 44a9a74..231776d 100644 --- a/Projekte/battleship/client/src/main/java/pp/battleship/client/Menu.java +++ b/Projekte/battleship/client/src/main/java/pp/battleship/client/Menu.java @@ -18,10 +18,11 @@ import com.simsilica.lemur.style.ElementId; import static pp.battleship.Resources.lookup; import pp.battleship.client.gui.GameMusic; -import pp.battleship.client.gui.VolumeSlider; import pp.dialog.Dialog; import pp.dialog.StateCheckboxModel; import pp.dialog.TextInputDialog; +import pp.monopoly.client.gui.VolumeSlider; + import static pp.util.PreferencesUtils.getPreferences; /** diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/Menu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/Menu.java deleted file mode 100644 index a9a22e5..0000000 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/Menu.java +++ /dev/null @@ -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(); - } -} diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java index e92f74e..9dd6a9d 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java @@ -21,6 +21,7 @@ import com.jme3.system.AppSettings; import com.simsilica.lemur.GuiGlobals; import com.simsilica.lemur.style.BaseStyles; import pp.monopoly.game.client.MonopolyClient; +import pp.monopoly.client.gui.SettingsMenu; import pp.monopoly.game.client.ClientGameLogic; import pp.monopoly.game.client.ServerConnection; import pp.monopoly.notification.ClientStateEvent; @@ -159,7 +160,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga */ private AppSettings makeSettings() { final AppSettings settings = new AppSettings(true); - settings.setTitle(lookup("battleship.name")); + settings.setTitle(lookup("monopoly.name")); settings.setResolution(config.getResolutionWidth(), config.getResolutionHeight()); settings.setFullscreen(config.fullScreen()); settings.setUseRetinaFrameBuffer(config.useRetinaFrameBuffer()); @@ -217,7 +218,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga setupInput(); setupStates(); setupGui(); - serverConnection.connect(); + // serverConnection.connect(); } /** @@ -305,7 +306,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga if (dialogManager.showsDialog()) dialogManager.escape(); else - new Menu(this).open(); + new SettingsMenu(this).open(); } /** diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/StartMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/StartMenu.java index e48efe3..2ffccb4 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/StartMenu.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/StartMenu.java @@ -161,7 +161,7 @@ public class StartMenu extends Dialog { */ private static void startGame(MonopolyApp app) { app.getGuiNode().detachAllChildren(); - app.getServerConnection().connect(); + // app.getServerConnection().connect(); } /** diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/LobbyMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/LobbyMenu.java index 03ce06e..6408bda 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/LobbyMenu.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/LobbyMenu.java @@ -214,7 +214,7 @@ public class LobbyMenu { app.getGuiNode().detachChild(circle); app.getGuiNode().detachChild(lowerLeftMenu); app.getGuiNode().detachChild(lowerRightMenu); - app.getServerConnection().connect(); + // app.getServerConnection().connect(); } /** diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/SettingsMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/SettingsMenu.java index 5fabf92..eafb833 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/SettingsMenu.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/SettingsMenu.java @@ -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; -import com.jme3.material.Material; -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 java.util.prefs.Preferences; + import com.simsilica.lemur.Button; import com.simsilica.lemur.Checkbox; -import com.simsilica.lemur.Container; 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.ValueRenderer; -import com.simsilica.lemur.Selector; -import pp.dialog.Dialog; +import static pp.monopoly.Resources.lookup; +import pp.monopoly.client.GameMusic; +import pp.monopoly.client.GameSound; 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 { + private static final Preferences PREFERENCES = getPreferences(SettingsMenu.class); + private static final String LAST_PATH = "last.file.path"; private final MonopolyApp app; - private final Geometry overlayBackground; - private final Container settingsContainer; - private final Container backgroundContainer; + private final VolumeSlider slider; + /** + * Constructs the Menu dialog for the Battleship application. + * + * @param app the MonopolyApp instance + */ public SettingsMenu(MonopolyApp app) { super(app.getDialogManager()); 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 - overlayBackground = createOverlayBackground(); - app.getGuiNode().attachChild(overlayBackground); + addChild(new Checkbox(lookup("menu.background-sound-enabled"), new StateCheckboxModel(app, GameMusic.class))); + + addChild(slider); - // Create the background container - 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ü - settingsContainer = new Container(); - settingsContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.1f, 0.1f, 0.1f, 0.9f))); - - - - // 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); + addChild(new Button(lookup("menu.return-to-game"))).addClickCommands(s -> ifTopDialog(this::close)); + addChild(new Button(lookup("menu.quit"))).addClickCommands(s -> ifTopDialog(app::closeApp)); + + update(); } /** - * Erstellt einen halbtransparenten Hintergrund für das Menü. - * - * @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. + * Updates the state of the load and save buttons based on the game logic. */ @Override - public void close() { - 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 + public void update() { } + @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(); + } } diff --git a/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/VolumeSlider.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/VolumeSlider.java similarity index 87% rename from Projekte/battleship/client/src/main/java/pp/battleship/client/gui/VolumeSlider.java rename to Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/VolumeSlider.java index aa27292..c0c8cc2 100644 --- a/Projekte/battleship/client/src/main/java/pp/battleship/client/gui/VolumeSlider.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/VolumeSlider.java @@ -1,6 +1,8 @@ -package pp.battleship.client.gui; +package pp.monopoly.client.gui; import com.simsilica.lemur.Slider; + +import pp.monopoly.client.GameMusic; /** * The VolumeSlider class represents the Volume Slider in the Menu. * 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 { - private final GameMusic music; + private final pp.monopoly.client.GameMusic music; private double vol; /** diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuildingPropertyCard.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuildingPropertyCard.java index 4fbaca0..3ddf76c 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuildingPropertyCard.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuildingPropertyCard.java @@ -30,7 +30,7 @@ public class BuildingPropertyCard extends Dialog { this.app = app; //Generate the corresponfing field - BuildingProperty field = (BuildingProperty) app.getBoardManager().getFieldAtIndex(index); + BuildingProperty field = (BuildingProperty) app.getGameLogic().getBoardManager().getFieldAtIndex(index); // Halbtransparentes Overlay hinzufügen overlayBackground = createOverlayBackground(); @@ -121,8 +121,8 @@ public class BuildingPropertyCard extends Dialog { app.getGuiNode().detachChild(buildingPropertyContainer); // 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 + // app.setSettingsMenuOpen(false); // Menü als geschlossen markieren + // app.unblockInputs(); // Eingaben wieder aktivieren System.out.println("SettingsMenu geschlossen."); // Debugging-Ausgabe } diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyCard.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyCard.java index 8cfba7f..ebeb0ee 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyCard.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyCard.java @@ -107,8 +107,8 @@ public class BuyCard extends Dialog { 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 + // app.setSettingsMenuOpen(false); // Menü als geschlossen markieren + // app.unblockInputs(); // Eingaben wieder aktivieren System.out.println("SettingsMenu geschlossen."); // Debugging-Ausgabe } diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/FoodFieldCard.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/FoodFieldCard.java index ea4fa81..c6224cb 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/FoodFieldCard.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/FoodFieldCard.java @@ -30,7 +30,7 @@ public class FoodFieldCard extends Dialog { this.app = app; //Generate the corresponfing field - FoodField field = (FoodField) app.getBoardManager().getFieldAtIndex(index); + FoodField field = (FoodField) app.getGameLogic().getBoardManager().getFieldAtIndex(index); // Halbtransparentes Overlay hinzufügen overlayBackground = createOverlayBackground(); @@ -125,8 +125,8 @@ public class FoodFieldCard extends Dialog { app.getGuiNode().detachChild(foodFieldContainer); // 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 + // app.setSettingsMenuOpen(false); // Menü als geschlossen markieren + // app.unblockInputs(); // Eingaben wieder aktivieren System.out.println("SettingsMenu geschlossen."); // Debugging-Ausgabe } diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/GateFieldCard.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/GateFieldCard.java index 30392e3..4a9597a 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/GateFieldCard.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/GateFieldCard.java @@ -28,7 +28,7 @@ public class GateFieldCard extends Dialog { this.app = app; //Generate the corresponfing field - GateField field = (GateField) app.getBoardManager().getFieldAtIndex(index); + GateField field = (GateField) app.getGameLogic().getBoardManager().getFieldAtIndex(index); // Halbtransparentes Overlay hinzufügen overlayBackground = createOverlayBackground(); @@ -118,8 +118,8 @@ public class GateFieldCard extends Dialog { app.getGuiNode().detachChild(gateFieldContainer); // 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 + // app.setSettingsMenuOpen(false); // Menü als geschlossen markieren + // app.unblockInputs(); // Eingaben wieder aktivieren System.out.println("SettingsMenu geschlossen."); // Debugging-Ausgabe } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java index ad93f0e..e6ef7e4 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java @@ -22,6 +22,7 @@ import pp.monopoly.message.server.TradeRequest; import pp.monopoly.message.server.ViewAssetsResponse; import pp.monopoly.model.Board; import pp.monopoly.model.IntPoint; +import pp.monopoly.model.fields.BoardManager; import pp.monopoly.notification.ClientStateEvent; import pp.monopoly.notification.GameEvent; import pp.monopoly.notification.GameEventBroker; @@ -53,6 +54,8 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { private PlayerHandler playerHandler; + private BoardManager boardManager = new BoardManager(); + /** * Constructs a ClientGameLogic with the specified sender object. * @@ -62,6 +65,14 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { this.clientSender = clientSender; } + /** + * Reutns the BoardManager + * @return the boardManager + */ + public BoardManager getBoardManager() { + return boardManager; + } + /** * Returns the current state of the game logic. *