SettingsMenü Anpassungen

This commit is contained in:
Luca Puderbach 2024-11-15 02:31:12 +01:00
parent 12ef219064
commit 15b3902bd3
3 changed files with 34 additions and 47 deletions

View File

@ -16,6 +16,7 @@ import com.simsilica.lemur.style.BaseStyles;
import pp.dialog.DialogBuilder; import pp.dialog.DialogBuilder;
import pp.dialog.DialogManager; import pp.dialog.DialogManager;
import pp.graphics.Draw; import pp.graphics.Draw;
import pp.monopoly.client.gui.SettingsMenu;
import pp.monopoly.game.client.ClientGameLogic; import pp.monopoly.game.client.ClientGameLogic;
import pp.monopoly.game.client.MonopolyClient; import pp.monopoly.game.client.MonopolyClient;
import pp.monopoly.game.client.ServerConnection; import pp.monopoly.game.client.ServerConnection;
@ -27,10 +28,10 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
private final ServerConnection serverConnection; private final ServerConnection serverConnection;
private final ClientGameLogic logic; private final ClientGameLogic logic;
private final MonopolyAppConfig config; private final MonopolyAppConfig config;
private final ActionListener escapeListener = (name, isPressed, tpf) -> escape(isPressed); private final ActionListener escapeListener = (name, isPressed, tpf) -> handleEscape(isPressed);
private final DialogManager dialogManager = new DialogManager(this); private final DialogManager dialogManager = new DialogManager(this);
private final ExecutorService executor = Executors.newCachedThreadPool(); private final ExecutorService executor = Executors.newCachedThreadPool();
private SettingsMenu settingsMenu;
private final Draw draw; private final Draw draw;
public static void main(String[] args) { public static void main(String[] args) {
@ -67,9 +68,8 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
@Override @Override
public void simpleInitApp() { public void simpleInitApp() {
stateManager.detach(stateManager.getState(com.jme3.app.StatsAppState.class)); //FPS-Anzeige GuiGlobals.initialize(this);
GuiGlobals.initialize(this); // Lemur initialisieren BaseStyles.loadGlassStyle();
BaseStyles.loadGlassStyle(); // Beispielstil für Lemur
GuiGlobals.getInstance().getStyles().setDefaultStyle("glass"); GuiGlobals.getInstance().getStyles().setDefaultStyle("glass");
setupInput(); setupInput();
@ -91,9 +91,15 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
inputManager.addListener(escapeListener, "ESC"); inputManager.addListener(escapeListener, "ESC");
} }
private void escape(boolean isPressed) { private void handleEscape(boolean isPressed) {
if (!isPressed) return; if (isPressed) {
new StartMenu(this); if (settingsMenu != null && guiNode.hasChild(settingsMenu.getContainer())) {
settingsMenu.close();
} else {
settingsMenu = new SettingsMenu(this);
settingsMenu.open();
}
}
} }
void setInfoText(String text) { void setInfoText(String text) {

View File

@ -2,69 +2,50 @@ package pp.monopoly.client.gui;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.simsilica.lemur.Button; import com.simsilica.lemur.Button;
import com.simsilica.lemur.Checkbox;
import com.simsilica.lemur.Container; import com.simsilica.lemur.Container;
import com.simsilica.lemur.Label; import com.simsilica.lemur.Label;
import pp.dialog.Dialog; import pp.dialog.Dialog;
import pp.monopoly.client.GameSound;
import pp.monopoly.client.MonopolyApp; import pp.monopoly.client.MonopolyApp;
import pp.monopoly.client.StartMenu;
/**
* Settings menu for the Monopoly application, where users can configure preferences.
*/
public class SettingsMenu extends Dialog { public class SettingsMenu extends Dialog {
private final MonopolyApp app; private final MonopolyApp app;
private final Container settingsContainer;
/**
* Constructs the SettingsMenu dialog for the Monopoly 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;
initializeMenu(); settingsContainer = new Container();
} }
/** public void open() {
* Sets up the layout and elements for the settings menu. settingsContainer.setLocalTranslation(new Vector3f(300, 300, 0));
*/
private void initializeMenu() {
Container settingsContainer = new Container();
settingsContainer.setLocalTranslation(new Vector3f(300, 300, 0)); // Positionierung des Menüs
// Titel des Menüs // Titel des Einstellungsmenüs
settingsContainer.addChild(new Label("Einstellungen")); settingsContainer.addChild(new Label("Einstellungen"));
// Beispiel-Einstellung: Sound aktivieren/deaktivieren // Beispiel: Button zum Umschalten einer Option
Checkbox soundCheckbox = settingsContainer.addChild(new Checkbox("Sound aktivieren")); Label soundLabel = settingsContainer.addChild(new Label("Sound"));
soundCheckbox.setChecked(GameSound.enabledInPreferences()); Button toggleSoundButton = settingsContainer.addChild(new Button("An/Aus"));
soundCheckbox.addClickCommands(source -> toggleSound(soundCheckbox.isChecked())); toggleSoundButton.addClickCommands(source -> toggleSound());
// Zurück-Button zum Startmenü // Zurück-Button, um das Menü zu schließen
Button backButton = settingsContainer.addChild(new Button("Zurück")); Button backButton = settingsContainer.addChild(new Button("Zurück"));
backButton.addClickCommands(source -> returnToStartMenu()); backButton.addClickCommands(source -> close());
// Container dem GUI-Knoten hinzufügen
app.getGuiNode().attachChild(settingsContainer); app.getGuiNode().attachChild(settingsContainer);
} }
/** public void close() {
* Toggles the sound setting and saves the preference. app.getGuiNode().detachChild(settingsContainer);
*
* @param enabled true if sound should be enabled; false otherwise.
*/
private void toggleSound(boolean enabled) {
GameSound.enabledInPreferences(); // Speichert die Einstellung in den Preferences
System.out.println("Sound " + (enabled ? "aktiviert" : "deaktiviert"));
} }
/** private void toggleSound() {
* Returns to the StartMenu. System.out.println("Sound umgeschaltet!");
*/ }
private void returnToStartMenu() {
app.getGuiNode().detachAllChildren(); // Schließt das SettingsMenu public Container getContainer() {
StartMenu.createStartMenu(app); // Zeigt das Startmenü erneut an return settingsContainer;
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 857 KiB