Merge remote-tracking branch 'origin/gui' into gui

# Conflicts:
#	Projekte/monopoly/client/src/main/java/pp/monopoly/client/StartMenu.java
This commit is contained in:
Yvonne Schmidt 2024-11-15 05:12:39 +01:00
commit 0d86ba0ca9
11 changed files with 231 additions and 330 deletions

View File

@ -1,85 +1,83 @@
// Styling of Lemur components // Styling of Lemur components
// For documentation, see // For documentation, see:
// https://github.com/jMonkeyEngine-Contributions/Lemur/wiki/Styling // https://github.com/jMonkeyEngine-Contributions/Lemur/wiki/Styling
import com.simsilica.lemur.Button import com.simsilica.lemur.*
import com.simsilica.lemur.Button.ButtonAction
import com.simsilica.lemur.Command
import com.simsilica.lemur.HAlignment
import com.simsilica.lemur.Insets3f
import com.simsilica.lemur.component.QuadBackgroundComponent
import com.simsilica.lemur.component.TbtQuadBackgroundComponent
// Farben und allgemeine Stile
def bgColor = color(1, 1, 1, 1) def bgColor = color(1, 1, 1, 1)
def buttonEnabledColor = color(0.8, 0.9, 1, 1) def buttonEnabledColor = color(0.8, 0.9, 1, 1)
def buttonDisabledColor = color(0.8, 0.9, 1, 0.2) def buttonDisabledColor = color(0.8, 0.9, 1, 0.2)
//def buttonBgColor = color(0, 0.75, 0.75, 1)
def sliderColor = color(0.6, 0.8, 0.8, 1) def sliderColor = color(0.6, 0.8, 0.8, 1)
def sliderBgColor = color(0.5, 0.75, 0.75, 1) def sliderBgColor = color(0.5, 0.75, 0.75, 1)
def gradientColor = color(0.5, 0.75, 0.85, 0.5) def gradientColor = color(0.5, 0.75, 0.85, 0.5)
def tabbuttonEnabledColor = color(0.4, 0.45, 0.5, 1) def tabbuttonEnabledColor = color(0.4, 0.45, 0.5, 1)
def playButtonBorderColor = color(1, 0.6, 0, 1) // For "Spielen" button
def playButtonBorderColor = color(1, 0.6, 0, 1) // Orange border for "Spielen" button // Hintergrundverläufe
def playButtonTextColor = color(0, 0, 0, 1) // Black text color for "Spielen" button
def buttonBgColor = color(1, 1, 1, 1) // White background for "Spiel beenden" and "Einstellungen" buttons
def buttonTextColor = color(0, 0, 0, 1) // Black text color for "Spiel beenden" and "Einstellungen" buttons
def borderColor = color(0, 0, 0, 1) // Black border for "Spiel beenden" and "Einstellungen"
def gradient = TbtQuadBackgroundComponent.create( def gradient = TbtQuadBackgroundComponent.create(
texture(name: "/com/simsilica/lemur/icons/bordered-gradient.png", texture(name: "/com/simsilica/lemur/icons/bordered-gradient.png", generateMips: false),
generateMips: false), 1, 1, 1, 126, 126, 1f, false)
1, 1, 1, 126, 126,
1f, false)
def doubleGradient = new QuadBackgroundComponent(gradientColor) def doubleGradient = new QuadBackgroundComponent(gradientColor)
doubleGradient.texture = texture(name: "/com/simsilica/lemur/icons/double-gradient-128.png", doubleGradient.texture = texture(name: "/com/simsilica/lemur/icons/double-gradient-128.png", generateMips: false)
generateMips: false)
// Hauptstil für die Schriftart
selector("pp") { selector("pp") {
font = font("Interface/Fonts/Metropolis/Metropolis-Regular-32.fnt") font = font("Interface/Fonts/Metropolis/Metropolis-Regular-32.fnt")
} }
selector("label", "pp") { // Titel für "Einstellungen"
insets = new Insets3f(2, 2, 2, 2) selector("settings-title", "pp") {
color = buttonEnabledColor color = color(1, 1, 1, 1)
} fontSize = 48
selector("header", "pp") {
font = font("Interface/Fonts/Metropolis/Metropolis-Bold-42.fnt")
insets = new Insets3f(2, 2, 2, 2)
color = color(1, 0.5, 0, 1)
textHAlignment = HAlignment.Center textHAlignment = HAlignment.Center
insets = new Insets3f(5, 5, 5, 5)
} }
// Container Stil
selector("container", "pp") { selector("container", "pp") {
background = gradient.clone() background = gradient.clone()
background.setColor(bgColor) background.setColor(bgColor)
} }
// Slider Stil
selector("slider", "pp") { selector("slider", "pp") {
background = gradient.clone() insets = new Insets3f(5, 10, 5, 10) // Abstand
background.setColor(bgColor) background = new QuadBackgroundComponent(sliderBgColor)
} }
selector("play-button", "pp") { // Slider-Thumb Stil
color = playButtonTextColor // Black text color selector("slider.thumb.button", "pp") {
background = new QuadBackgroundComponent(playButtonBorderColor) // Orange border background text = "[]" // Symbol für den Thumb
insets = new Insets3f(15, 25, 15, 25) // Padding for larger button size color = sliderColor
background.setMargin(5, 5) // Thin border effect around the background color insets = new Insets3f(2, 2, 2, 2)
fontSize = 36 // Larger font size for prominence
} }
// Slider links/rechts Buttons
selector("slider.left.button", "pp") {
text = "-"
color = sliderColor
background = doubleGradient.clone()
insets = new Insets3f(5, 5, 5, 5)
}
selector("slider.right.button", "pp") {
text = "+"
color = sliderColor
background = doubleGradient.clone()
insets = new Insets3f(5, 5, 5, 5)
}
// Style für alle Buttons im Menü
selector("menu-button", "pp") { selector("menu-button", "pp") {
color = buttonTextColor // Black text color color = color(0, 0, 0, 1) // Schwarzer Text
background = new QuadBackgroundComponent(buttonBgColor) // White background background = new QuadBackgroundComponent(bgColor)
insets = new Insets3f(10, 20, 10, 20) // Padding insets = new Insets3f(10, 20, 10, 20)
background.setMargin(1, 1) // Thin black border fontSize = 24
background.setColor(borderColor) // Set black border color
fontSize = 24 // Standard font size
} }
// Standard Button Commands (Animationseffekt)
def pressedCommand = new Command<Button>() { def pressedCommand = new Command<Button>() {
void execute(Button source) { void execute(Button source) {
if (source.isPressed()) if (source.isPressed())
@ -98,30 +96,6 @@ def enabledCommand = new Command<Button>() {
} }
} }
def repeatCommand = new Command<Button>() {
private long startTime
private long lastClick
void execute(Button source) {
// Only do the repeating click while the mouse is
// over the button (and pressed of course)
if (source.isPressed() && source.isHighlightOn()) {
long elapsedTime = System.currentTimeMillis() - startTime
// After half a second pause, click 8 times a second
if (elapsedTime > 500 && elapsedTime > lastClick + 125) {
source.click()
// Try to quantize the last click time to prevent drift
lastClick = ((elapsedTime - 500) / 125) * 125 + 500
}
}
else {
startTime = System.currentTimeMillis()
lastClick = 0
}
}
}
def stdButtonCommands = [ def stdButtonCommands = [
(ButtonAction.Down) : [pressedCommand], (ButtonAction.Down) : [pressedCommand],
(ButtonAction.Up) : [pressedCommand], (ButtonAction.Up) : [pressedCommand],
@ -129,98 +103,9 @@ def stdButtonCommands = [
(ButtonAction.Disabled): [enabledCommand] (ButtonAction.Disabled): [enabledCommand]
] ]
def sliderButtonCommands = [
(ButtonAction.Hover): [repeatCommand]
]
selector("title", "pp") {
color = color(0.8, 0.9, 1, 0.85f)
highlightColor = color(1, 0.8, 1, 0.85f)
shadowColor = color(0, 0, 0, 0.75f)
shadowOffset = vec3(2, -2, -1)
background = new QuadBackgroundComponent(color(0.5, 0.75, 0.85, 1))
background.texture = texture(name: "/com/simsilica/lemur/icons/double-gradient-128.png",
generateMips: false)
insets = new Insets3f(2, 2, 2, 2)
buttonCommands = stdButtonCommands
}
selector("button", "pp") { selector("button", "pp") {
background = gradient.clone() background = gradient.clone()
color = buttonEnabledColor color = buttonEnabledColor
background.setColor(buttonBgColor)
insets = new Insets3f(2, 2, 2, 2) insets = new Insets3f(2, 2, 2, 2)
buttonCommands = stdButtonCommands
}
selector("slider", "pp") {
insets = new Insets3f(1, 3, 1, 2)
}
selector("slider", "button", "pp") {
background = doubleGradient.clone()
//background.setColor(sliderBgColor)
insets = new Insets3f(0, 0, 0, 0)
}
selector("slider.thumb.button", "pp") {
text = "[]"
color = sliderColor
}
selector("slider.left.button", "pp") {
text = "-"
background = doubleGradient.clone()
//background.setColor(sliderBgColor)
background.setMargin(5, 0)
color = sliderColor
buttonCommands = sliderButtonCommands
}
selector("slider.right.button", "pp") {
text = "+"
background = doubleGradient.clone()
//background.setColor(sliderBgColor)
background.setMargin(4, 0)
color = sliderColor
buttonCommands = sliderButtonCommands
}
selector("slider.up.button", "pp") {
buttonCommands = sliderButtonCommands
}
selector("slider.down.button", "pp") {
buttonCommands = sliderButtonCommands
}
selector("checkbox", "pp") {
color = buttonEnabledColor
}
selector("rollup", "pp") {
background = gradient.clone()
background.setColor(bgColor)
}
selector("tabbedPanel", "pp") {
activationColor = buttonEnabledColor
}
selector("tabbedPanel.container", "pp") {
background = null
}
selector("tab.button", "pp") {
background = gradient.clone()
background.setColor(bgColor)
color = tabbuttonEnabledColor
insets = new Insets3f(4, 2, 0, 2)
buttonCommands = stdButtonCommands buttonCommands = stdButtonCommands
} }

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,12 +28,14 @@ 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;
private boolean isSettingsMenuOpen = false;
public static void main(String[] args) { public static void main(String[] args) {
new MonopolyApp().start(); new MonopolyApp().start();
} }
@ -65,15 +68,24 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
return settings; return settings;
} }
public boolean isSettingsMenuOpen() {
return isSettingsMenuOpen;
}
public void setSettingsMenuOpen(boolean isOpen) {
this.isSettingsMenuOpen = isOpen;
}
@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();
setupGui(); setupGui();
// Erst jetzt StartMenu erstellen, nachdem GuiGlobals initialisiert ist
StartMenu.createStartMenu(this); StartMenu.createStartMenu(this);
} }
@ -91,9 +103,17 @@ 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 (isSettingsMenuOpen && settingsMenu != null) {
settingsMenu.close();
setSettingsMenuOpen(false);
} else {
settingsMenu = new SettingsMenu(this);
settingsMenu.open();
setSettingsMenuOpen(true);
}
}
} }
void setInfoText(String text) { void setInfoText(String text) {

View File

@ -1,17 +1,20 @@
package pp.monopoly.client; package pp.monopoly.client;
import com.jme3.material.Material;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Quad;
import com.jme3.texture.Texture;
import com.simsilica.lemur.Axis; import com.simsilica.lemur.Axis;
import com.simsilica.lemur.Button; import com.simsilica.lemur.Button;
import com.simsilica.lemur.Container; import com.simsilica.lemur.Container;
import com.simsilica.lemur.Label; import com.simsilica.lemur.Label;
import com.simsilica.lemur.component.SpringGridLayout; import com.simsilica.lemur.component.SpringGridLayout;
import pp.dialog.Dialog; import pp.dialog.Dialog;
import pp.monopoly.client.gui.CreateGameMenu; import pp.monopoly.client.gui.CreateGameMenu;
import pp.monopoly.client.gui.SettingsMenu; import pp.monopoly.client.gui.SettingsMenu;
/** /**
* Constructs the startup menu dialog for the Monopoly application. * Constructs the startup menu dialog for the Monopoly application.
*/ */
@ -33,73 +36,73 @@ public class StartMenu extends Dialog {
* opening settings, and quitting the application. * opening settings, and quitting the application.
*/ */
public static void createStartMenu(MonopolyApp app) { public static void createStartMenu(MonopolyApp app) {
int screenWidth = app.getContext().getSettings().getWidth(); int screenWidth = app.getContext().getSettings().getWidth();
int screenHeight = app.getContext().getSettings().getHeight(); int screenHeight = app.getContext().getSettings().getHeight();
// Center container for header and play button // Set up the background image
Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/unibw-Bib2.png");
Quad quad = new Quad(screenWidth, screenHeight);
Geometry background = new Geometry("Background", quad);
Material backgroundMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
backgroundMaterial.setTexture("ColorMap", backgroundImage);
background.setMaterial(backgroundMaterial);
background.setLocalTranslation(0, 0, -1); // Ensure it is behind other GUI elements
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));
centerMenu.setLocalTranslation(new Vector3f(300, 300, 0)); // Position in the center of the screen Label titleLabel = new Label("Hauptmenü");
titleLabel.setFontSize(48);
centerMenu.addChild(titleLabel);
// Title of the main menu Button startButton = new Button("Spielen");
centerMenu.addChild(new Label("Hauptmenü"));
// "Spielen" button - centered
Button startButton = centerMenu.addChild(new Button("Spielen"));
startButton.addClickCommands(source -> startGame(app)); startButton.addClickCommands(source -> startGame(app));
centerMenu.addChild(startButton);
// Position the center container in the middle of the screen // Position the center container in the middle of the screen
centerMenu.setLocalTranslation(new Vector3f(screenWidth / 2f - centerMenu.getPreferredSize().x / 2f, centerMenu.setLocalTranslation(new Vector3f(
screenHeight / 2f + centerMenu.getPreferredSize().y / 2f, screenWidth / 2f - centerMenu.getPreferredSize().x / 2f,
0)); screenHeight / 2f + centerMenu.getPreferredSize().y / 2f,
0));
// Attach the center container to the GUI node
app.getGuiNode().attachChild(centerMenu); app.getGuiNode().attachChild(centerMenu);
// Lower-left container for "Spiel beenden" button // Lower-left container for "Spiel beenden" button
Container lowerLeftMenu = new Container(); Container lowerLeftMenu = new Container();
lowerLeftMenu.setLocalTranslation(new Vector3f(50, 50, 0)); // Position in the lower-left corner lowerLeftMenu.setLocalTranslation(new Vector3f(50, 50, 0));
Button quitButton = new Button("Spiel beenden");
// "Spiel beenden" button - lower left corner
Button quitButton = lowerLeftMenu.addChild(new Button("Spiel beenden"));
quitButton.addClickCommands(source -> quitGame()); quitButton.addClickCommands(source -> quitGame());
lowerLeftMenu.addChild(quitButton);
// Attach the lower-left container to the GUI node
app.getGuiNode().attachChild(lowerLeftMenu); app.getGuiNode().attachChild(lowerLeftMenu);
// Lower-right container for "Einstellungen" button // Lower-right container for "Einstellungen" button
Container lowerRightMenu = new Container(); Container lowerRightMenu = new Container();
lowerRightMenu.setLocalTranslation(new Vector3f(screenWidth - 150, 50, 0)); // Position in the lower-right corner lowerRightMenu.setLocalTranslation(new Vector3f(screenWidth - 150, 50, 0));
Button settingsButton = new Button("Einstellungen");
// "Einstellungen" button - lower right corner
Button settingsButton = lowerRightMenu.addChild(new Button("Einstellungen"));
settingsButton.addClickCommands(source -> openSettings(app)); settingsButton.addClickCommands(source -> openSettings(app));
lowerRightMenu.addChild(settingsButton);
// Attach the lower-right container to the GUI node
app.getGuiNode().attachChild(lowerRightMenu); app.getGuiNode().attachChild(lowerRightMenu);
} }
/** /**
* Starts the game by transitioning to the CreateGameMenu. * Starts the game by transitioning to the CreateGameMenu.
*/ */
private static void startGame(MonopolyApp app) { private static void startGame(MonopolyApp app) {
app.getGuiNode().detachAllChildren(); // Schließt das Startmenü app.getGuiNode().detachAllChildren();
CreateGameMenu createGameMenu = new CreateGameMenu(app); new CreateGameMenu(app);
// Code zur Anzeige des CreateGameMenu, eventuell zusätzliche Initialisierung
} }
/** /**
* Opens the settings menu. * Opens the settings menu.
*/ */
private static void openSettings(MonopolyApp app) { private static void openSettings(MonopolyApp app) {
app.getGuiNode().detachAllChildren(); // Schließt das Startmenü app.getGuiNode().detachAllChildren();
SettingsMenu settingsMenu = new SettingsMenu(app); new SettingsMenu(app);
// Code zur Anzeige des SettingsMenu
} }
/** /**
* Quits the game application. * Quits the game application.
*/ */
private static void quitGame() { private static void quitGame() {
System.exit(0); // Beendet die Anwendung System.exit(0);
} }
} }

View File

@ -1,77 +1,70 @@
package pp.monopoly.client.gui; package pp.monopoly.client.gui;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.simsilica.lemur.Axis;
import com.simsilica.lemur.Button; import com.simsilica.lemur.Button;
import com.simsilica.lemur.Container; import com.simsilica.lemur.Container;
import com.simsilica.lemur.Insets3f;
import com.simsilica.lemur.Label; import com.simsilica.lemur.Label;
import com.simsilica.lemur.TextField;
import com.simsilica.lemur.component.SpringGridLayout;
import com.simsilica.lemur.style.ElementId;
import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp; import pp.monopoly.client.MonopolyApp;
import pp.monopoly.client.StartMenu;
/** public class CreateGameMenu {
* Menu for creating a new game, where players can configure settings before starting.
*/
public class CreateGameMenu extends Dialog {
private final MonopolyApp app; private final MonopolyApp app;
private final Container createGameContainer;
/**
* Constructs the CreateGameMenu dialog for the Monopoly application.
*
* @param app the MonopolyApp instance
*/
public CreateGameMenu(MonopolyApp app) { public CreateGameMenu(MonopolyApp app) {
super(app.getDialogManager());
this.app = app; this.app = app;
initializeMenu();
// Hauptcontainer für das Menü mit Innenabstand
createGameContainer = new Container();
createGameContainer.setInsets(new Insets3f(10, 10, 10, 10));
// Setzt den Titel des Menüs
Label title = createGameContainer.addChild(new Label("Neues Spiel", new ElementId("title")));
// Fügt zwei Eingabefelder unter dem Titel hinzu
TextField inputField1 = createGameContainer.addChild(new TextField("Eingabefeld 1"));
TextField inputField2 = createGameContainer.addChild(new TextField("Eingabefeld 2"));
// Erstellt einen Container mit einem Rasterlayout, um die Buttons nebeneinander anzuordnen
Container buttonContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
buttonContainer.setInsets(new Insets3f(5, 5, 5, 5)); // Abstand zwischen den Buttons und dem Rand
// Buttons hinzufügen und jeweils einen Innenabstand hinzufügen
Button button1 = buttonContainer.addChild(new Button("1"));
button1.setInsets(new Insets3f(5, 5, 5, 5));
Button button2 = buttonContainer.addChild(new Button("2"));
button2.setInsets(new Insets3f(5, 5, 5, 5));
Button button3 = buttonContainer.addChild(new Button("3"));
button3.setInsets(new Insets3f(5, 5, 5, 5));
// Fügt den Button-Container zum Hauptcontainer hinzu
createGameContainer.addChild(buttonContainer);
// Setzt die Breite des Hauptcontainers
createGameContainer.setPreferredSize(new Vector3f(600, 400, 0));
// Zentriert den Container auf dem Bildschirm
createGameContainer.setLocalTranslation(
(app.getCamera().getWidth() - createGameContainer.getPreferredSize().x) / 2,
(app.getCamera().getHeight() + createGameContainer.getPreferredSize().y) / 2,
0
);
// Fügt das Menü zum GUI-Knoten der App hinzu
app.getGuiNode().attachChild(createGameContainer);
} }
/** /**
* Sets up the Create Game Menu layout and buttons. * Schließt das CreateGameMenu.
*/ */
private void initializeMenu() { public void close() {
Container menuContainer = new Container(); app.getGuiNode().detachChild(createGameContainer);
menuContainer.setLocalTranslation(new Vector3f(300, 300, 0)); // Positionierung des Menüs
// Titel des Menüs
menuContainer.addChild(new Label("Neues Spiel erstellen"));
// Beispiel-Button für die Spieleranzahl-Einstellung
Button playerCountButton = menuContainer.addChild(new Button("Spieleranzahl einstellen"));
playerCountButton.addClickCommands(source -> setPlayerCount());
// Start-Button zum Spielbeginn
Button startGameButton = menuContainer.addChild(new Button("Spiel starten"));
startGameButton.addClickCommands(source -> startGame());
// Zurück-Button zum Startmenü
Button backButton = menuContainer.addChild(new Button("Zurück"));
backButton.addClickCommands(source -> returnToStartMenu());
app.getGuiNode().attachChild(menuContainer);
}
/**
* Placeholder for setting the player count.
*/
private void setPlayerCount() {
// Logik zum Festlegen der Spieleranzahl
System.out.println("Spieleranzahl einstellen wurde ausgewählt");
}
/**
* Placeholder for starting the game.
*/
private void startGame() {
// Logik für den Start des Spiels
System.out.println("Spiel starten wurde ausgewählt");
}
/**
* Returns to the StartMenu.
*/
private void returnToStartMenu() {
app.getGuiNode().detachAllChildren(); // Schließt das CreateGameMenu
StartMenu.createStartMenu(app); // Zeigt das Startmenü erneut an
} }
} }

View File

@ -1,70 +1,78 @@
package pp.monopoly.client.gui; package pp.monopoly.client.gui;
import com.jme3.math.Vector3f; import com.jme3.math.ColorRGBA;
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.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 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();
* Sets up the layout and elements for the settings menu.
*/ // Hintergrundfarbe für das Container-Element setzen, um es undurchsichtig zu machen
private void initializeMenu() { settingsContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.1f, 0.1f, 0.1f, 1f))); // Dunkelgrauer, undurchsichtiger Hintergrund
Container settingsContainer = new Container();
settingsContainer.setLocalTranslation(new Vector3f(300, 300, 0)); // Positionierung des Menüs
// Titel des Menüs // Titel "Einstellungen"
settingsContainer.addChild(new Label("Einstellungen")); Label settingsTitle = settingsContainer.addChild(new Label("Einstellungen", new ElementId("settings-title")));
settingsTitle.setFontSize(48);
settingsTitle.setColor(ColorRGBA.White);
// Beispiel-Einstellung: Sound aktivieren/deaktivieren // Effekt Sound mit Slider und Checkbox
Checkbox soundCheckbox = settingsContainer.addChild(new Checkbox("Sound aktivieren")); Container effectSoundContainer = settingsContainer.addChild(new Container());
soundCheckbox.setChecked(GameSound.enabledInPreferences()); Label effectSoundLabel = effectSoundContainer.addChild(new Label("Effekt Sound", new ElementId("label")));
soundCheckbox.addClickCommands(source -> toggleSound(soundCheckbox.isChecked())); effectSoundLabel.setFontSize(24);
effectSoundLabel.setColor(ColorRGBA.White);
// Zurück-Button zum Startmenü Slider effectSoundSlider = effectSoundContainer.addChild(new Slider());
Button backButton = settingsContainer.addChild(new Button("Zurück")); effectSoundSlider.setPreferredSize(new com.jme3.math.Vector3f(300, 30, 0));
backButton.addClickCommands(source -> returnToStartMenu());
Checkbox effectSoundCheckbox = effectSoundContainer.addChild(new Checkbox(""));
effectSoundCheckbox.setChecked(true);
// Hintergrund Musik mit Slider und Checkbox
Container backgroundMusicContainer = settingsContainer.addChild(new Container());
Label backgroundMusicLabel = backgroundMusicContainer.addChild(new Label("Hintergrund Musik", new ElementId("label")));
backgroundMusicLabel.setFontSize(24);
backgroundMusicLabel.setColor(ColorRGBA.White);
Slider backgroundMusicSlider = backgroundMusicContainer.addChild(new Slider());
backgroundMusicSlider.setPreferredSize(new com.jme3.math.Vector3f(300, 30, 0));
Checkbox backgroundMusicCheckbox = backgroundMusicContainer.addChild(new Checkbox(""));
backgroundMusicCheckbox.setChecked(true);
// Beenden Button
Button quitButton = settingsContainer.addChild(new Button("Beenden", new ElementId("menu-button")));
quitButton.setFontSize(32);
quitButton.setColor(ColorRGBA.White);
quitButton.addClickCommands(source -> app.stop());
// Zentrieren des Containers
settingsContainer.setLocalTranslation(
(app.getCamera().getWidth() - settingsContainer.getPreferredSize().x) / 2,
(app.getCamera().getHeight() + settingsContainer.getPreferredSize().y) / 2,
0
);
app.getGuiNode().attachChild(settingsContainer); app.getGuiNode().attachChild(settingsContainer);
} }
/** @Override
* Toggles the sound setting and saves the preference. public void close() {
* app.getGuiNode().detachChild(settingsContainer);
* @param enabled true if sound should be enabled; false otherwise. app.setSettingsMenuOpen(false);
*/
private void toggleSound(boolean enabled) {
GameSound.enabledInPreferences(); // Speichert die Einstellung in den Preferences
System.out.println("Sound " + (enabled ? "aktiviert" : "deaktiviert"));
}
/**
* Returns to the StartMenu.
*/
private void returnToStartMenu() {
app.getGuiNode().detachAllChildren(); // Schließt das SettingsMenu
StartMenu.createStartMenu(app); // Zeigt das Startmenü erneut an
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 857 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 MiB

View File

@ -7,18 +7,6 @@
package pp.monopoly.game.client; package pp.monopoly.game.client;
import pp.monopoly.message.client.ClientMessage;
import pp.monopoly.message.server.ServerInterpreter;
import pp.monopoly.model.IntPoint;
import pp.monopoly.model.Board;
import pp.monopoly.notification.ClientStateEvent;
import pp.monopoly.notification.GameEvent;
import pp.monopoly.notification.GameEventBroker;
import pp.monopoly.notification.GameEventListener;
import pp.monopoly.notification.InfoTextEvent;
import pp.monopoly.notification.Sound;
import pp.monopoly.notification.SoundEvent;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.System.Logger; import java.lang.System.Logger;
@ -26,7 +14,17 @@ import java.lang.System.Logger.Level;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static java.lang.Math.max; import pp.monopoly.message.client.ClientMessage;
import pp.monopoly.message.server.ServerInterpreter;
import pp.monopoly.model.Board;
import pp.monopoly.model.IntPoint;
import pp.monopoly.notification.ClientStateEvent;
import pp.monopoly.notification.GameEvent;
import pp.monopoly.notification.GameEventBroker;
import pp.monopoly.notification.GameEventListener;
import pp.monopoly.notification.InfoTextEvent;
import pp.monopoly.notification.Sound;
import pp.monopoly.notification.SoundEvent;
/** /**
* Controls the client-side game logic for Monopoly. * Controls the client-side game logic for Monopoly.

View File

@ -7,13 +7,9 @@
package pp.monopoly.game.client; package pp.monopoly.game.client;
import pp.monopoly.MonopolyConfig;
import pp.monopoly.model.IntPoint;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.Iterator; import pp.monopoly.MonopolyConfig;
import java.util.List;
/** /**
* Class providing access to the Monopoly client configuration. * Class providing access to the Monopoly client configuration.

View File

@ -7,12 +7,6 @@
package pp.monopoly.game.server; package pp.monopoly.game.server;
import pp.monopoly.MonopolyConfig;
import pp.monopoly.message.client.ClientInterpreter;
import pp.monopoly.message.server.ServerMessage;
import pp.monopoly.model.IntPoint;
import java.lang.System.Logger; import java.lang.System.Logger;
import java.lang.System.Logger.Level; import java.lang.System.Logger.Level;
import java.util.ArrayList; import java.util.ArrayList;
@ -20,6 +14,10 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import pp.monopoly.MonopolyConfig;
import pp.monopoly.message.client.ClientInterpreter;
import pp.monopoly.message.server.ServerMessage;
/** /**
* Controls the server-side game logic for Monopoly. * Controls the server-side game logic for Monopoly.
* Manages game states, player interactions, and message handling. * Manages game states, player interactions, and message handling.

View File

@ -7,10 +7,10 @@
package pp.monopoly.model; package pp.monopoly.model;
import com.jme3.network.serializing.Serializable;
import java.util.Objects; import java.util.Objects;
import com.jme3.network.serializing.Serializable;
/** /**
* Represents a point in the two-dimensional plane with integer coordinates. * Represents a point in the two-dimensional plane with integer coordinates.
*/ */