mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2024-11-24 23:59:44 +01:00
tmp settings menu fix
This commit is contained in:
parent
6a34dab00c
commit
fb28f3fefc
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,7 +161,7 @@ public class StartMenu extends Dialog {
|
||||
*/
|
||||
private static void startGame(MonopolyApp app) {
|
||||
app.getGuiNode().detachAllChildren();
|
||||
app.getServerConnection().connect();
|
||||
// app.getServerConnection().connect();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
/**
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user