Resolve merge conflicts

This commit is contained in:
Luca Puderbach 2024-11-18 04:42:30 +01:00
parent 5189c74058
commit af4b4243ea
10 changed files with 139 additions and 241 deletions

View File

@ -55,55 +55,6 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
setSettings(makeSettings());
}
/**
* Creates and configures application settings from the client configuration.
*
* @return A configured {@link AppSettings} object.
*/
private AppSettings makeSettings() {
final AppSettings settings = new AppSettings(true);
settings.setTitle(lookup("monopoly.name"));
settings.setResolution(config.getResolutionWidth(), config.getResolutionHeight());
settings.setFullscreen(config.fullScreen());
settings.setUseRetinaFrameBuffer(config.useRetinaFrameBuffer());
settings.setGammaCorrection(config.useGammaCorrection());
return settings;
}
/**
* Factory method for creating a server connection based on the current
* client configuration.
*
* @return A {@link ServerConnection} instance, which could be a real or mock server.
*/
private ServerConnection makeServerConnection() {
return new NetworkSupport(this);
}
/**
* Returns the dialog manager responsible for managing in-game dialogs.
*
* @return The {@link DialogManager} instance.
*/
public DialogManager getDialogManager() {
return dialogManager;
}
/**
* Returns the game logic handler for the client.
*
* @return The {@link ClientGameLogic} instance.
*/
@Override
public ClientGameLogic getGameLogic() {
return logic;
}
/**
* Returns the current configuration settings for the Monopoly client.
*
* @return The {@link MonopolyClientConfig} instance.
*/
@Override
public MonopolyAppConfig getConfig() {
return config;

View File

@ -1,10 +1,3 @@
////////////////////////////////////////
// Programming project code
// UniBw M, 2022, 2023, 2024
// www.unibw.de/inf2
// (c) Mark Minas (mark.minas@unibw.de)
////////////////////////////////////////
package pp.monopoly.client;
import com.jme3.math.ColorRGBA;

View File

@ -142,4 +142,5 @@ class NetworkDialog extends SimpleDialog {
network.getApp().errorDialog("Verbindung zum Server fehlgeschlagen.");
network.getApp().setInfoText(e.getLocalizedMessage());
}
}

View File

@ -1,117 +1,123 @@
package pp.monopoly.client;
import com.jme3.asset.TextureKey;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
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.Button;
import com.simsilica.lemur.Insets3f;
import com.simsilica.lemur.Label;
import com.simsilica.lemur.Panel;
import com.simsilica.lemur.style.ElementId;
import com.simsilica.lemur.Container;
import com.simsilica.lemur.HAlignment;
import com.simsilica.lemur.component.QuadBackgroundComponent;
import com.jme3.math.ColorRGBA;
import com.simsilica.lemur.component.SpringGridLayout;
import pp.dialog.Dialog;
import pp.monopoly.client.gui.GameMenu;
import pp.dialog.DialogManager;
import java.util.prefs.Preferences;
import static pp.monopoly.Resources.lookup;
import static pp.util.PreferencesUtils.getPreferences;
public class StartMenu extends Dialog {
private static final Preferences PREFERENCES = getPreferences(StartMenu.class);
private final MonopolyApp app;
// Buttons for the menu
private final Button playButton = new Button(lookup("button.play"));
private final Button quitButton = new Button(lookup("menu.quit"));
private final Button settingsButton = new Button("Einstellungen", new ElementId("menu-button"));
import pp.monopoly.client.gui.CreateGameMenu;
import pp.monopoly.client.gui.SettingsMenu;
/**
* Constructs the StartMenu dialog for the Monopoly application.
* Constructs the startup menu dialog for the Monopoly application.
import pp.monopoly.client.gui.GameMenu;
*/
public class StartMenu extends Dialog {
private final MonopolyApp app;
/**
* Constructs the Startup Menu dialog for the Monopoly application.
*
* @param app the MonopolyApp instance
*/
public StartMenu(MonopolyApp app) {
super(app.getDialogManager());
this.app = app;
}
// Load and display the background image
TextureKey backgroundKey = new TextureKey("unibw-bib", false);
Texture backgroundTexture = app.getAssetManager().loadTexture(backgroundKey);
/**
* Creates and displays the Start Menu with buttons for starting the game,
* opening settings, and quitting the application.
*/
public static void createStartMenu(MonopolyApp app) {
int screenWidth = app.getContext().getSettings().getWidth();
int screenHeight = app.getContext().getSettings().getHeight();
// 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", backgroundTexture);
// Create a large Quad for the background
Quad backgroundQuad = new Quad(16, 9); // Adjust size as necessary to fill the screen
Geometry background = new Geometry("Background", backgroundQuad);
backgroundMaterial.setTexture("ColorMap", backgroundImage);
background.setMaterial(backgroundMaterial);
background.setLocalTranslation(new Vector3f(-8, -4.5f, -1)); // Position it behind the UI components
// Attach the background as the first element
background.setLocalTranslation(0, 0, -1); // Ensure it is behind other GUI elements
app.getGuiNode().attachChild(background);
// Load and display the Monopoly logo
TextureKey monopolyLogoKey = new TextureKey("log-Monopoly", false);
Texture monopolyLogoTexture = app.getAssetManager().loadTexture(monopolyLogoKey);
Material monopolyLogoMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
monopolyLogoMaterial.setTexture("ColorMap", monopolyLogoTexture);
// Center container for title and play button
Container centerMenu = new Container(new SpringGridLayout(Axis.Y, Axis.X));
Quad monopolyQuad = new Quad(5, 1.5f); // Adjust dimensions as necessary
Geometry monopolyLogo = new Geometry("MonopolyLogo", monopolyQuad);
monopolyLogo.setMaterial(monopolyLogoMaterial);
monopolyLogo.setLocalTranslation(new Vector3f(0, 5, 0)); // Position Monopoly logo at the top
Button startButton = new Button("Spielen");
startButton.setPreferredSize(new Vector3f(190, 60, 0)); // Increase button size (width, height)
startButton.setFontSize(40); // Set the font size for the button text
startButton.setTextHAlignment(HAlignment.Center); // Center the text horizontally
Panel monopolyLogoPanel = new Panel();
addChild(monopolyLogoPanel);
// Set a custom border and background color
ColorRGBA borderColor = ColorRGBA.Orange; // Example: White border
ColorRGBA backgroundColor = ColorRGBA.LightGray; // Example: light gray background
QuadBackgroundComponent backgroundColorSp = new QuadBackgroundComponent(backgroundColor);
backgroundColorSp.setMargin(2, 2); // Optional: Adjust margin for the border
backgroundColorSp.setColor(borderColor); // Set border color
startButton.setBackground(backgroundColorSp);
// Load and display the university logo
TextureKey universityLogoKey = new TextureKey("unibw-logo.png", false);
Texture universityLogoTexture = app.getAssetManager().loadTexture(universityLogoKey);
Material universityLogoMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
universityLogoMaterial.setTexture("ColorMap", universityLogoTexture);
startButton.addClickCommands(source -> startGame(app));
centerMenu.addChild(startButton);
Quad universityQuad = new Quad(4, 1); // Adjust dimensions to fit below Monopoly logo
Geometry universityLogo = new Geometry("UniversityLogo", universityQuad);
universityLogo.setMaterial(universityLogoMaterial);
universityLogo.setLocalTranslation(new Vector3f(0, 3, 0)); // Position below the Monopoly logo
// Position the center container in the middle of the screen
centerMenu.setLocalTranslation(new Vector3f(screenWidth / 2f - centerMenu.getPreferredSize().x / 2f,
screenHeight / 2f - 280 + centerMenu.getPreferredSize().y / 2f,
0));
app.getGuiNode().attachChild(centerMenu);
Panel universityLogoPanel = new Panel();
addChild(universityLogoPanel);
// Lower-left container for "Spiel beenden" button
Container lowerLeftMenu = new Container();
lowerLeftMenu.setLocalTranslation(new Vector3f(100, 90, 0));
Button quitButton = new Button("Spiel beenden");
quitButton.setPreferredSize(new Vector3f(130, 40, 0)); // Increase button size slightly (width, height)
quitButton.setFontSize(20);
quitButton.addClickCommands(source -> quitGame());
lowerLeftMenu.addChild(quitButton);
app.getGuiNode().attachChild(lowerLeftMenu);
// Button actions
playButton.addClickCommands(source -> startGame());
quitButton.addClickCommands(source -> app.closeApp());
settingsButton.addClickCommands(source -> openSettings());
addChild(monopolyLogoPanel);
addChild(universityLogoPanel);
addChild(playButton);
addChild(quitButton);
addChild(settingsButton);
// Lower-right container for "Einstellungen" button
Container lowerRightMenu = new Container();
lowerRightMenu.setLocalTranslation(new Vector3f(screenWidth - 200, 90, 0));
Button settingsButton = new Button("Einstellungen");
settingsButton.setPreferredSize(new Vector3f(130, 40, 0)); // Increase button size slightly (width, height)
settingsButton.setFontSize(20); // Increase the font size for the text
settingsButton.addClickCommands(source -> openSettings(app));
lowerRightMenu.addChild(settingsButton);
app.getGuiNode().attachChild(lowerRightMenu);
}
private void startGame() {
System.out.println("Starting game...");
/**
* Starts the game by transitioning to the CreateGameMenu.
*/
private static void startGame(MonopolyApp app) {
app.getGuiNode().detachAllChildren();
new CreateGameMenu(app);
}
private void openSettings() {
app.getDialogManager().close(this);
app.getDialogManager().open(new GameMenu(app));
/**
* Opens the settings menu.
*/
private static void openSettings(MonopolyApp app) {
app.getGuiNode().detachAllChildren();
new SettingsMenu(app);
}
@Override
public void update() {
}
@Override
public void escape() {
close();
/**
* Quits the game application.
*/
private static void quitGame() {
System.exit(0);
}
}

View File

@ -5,6 +5,7 @@ import com.jme3.math.ColorRGBA;
import com.simsilica.lemur.Button;
import com.simsilica.lemur.Label;
import com.simsilica.lemur.style.ElementId;
import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp;

View File

@ -1,10 +1,10 @@
package pp.monopoly.client.gui;
import com.jme3.material.Material;
import com.jme3.material.RenderState.BlendMode;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Quad;
import com.jme3.texture.Texture;
import com.simsilica.lemur.Button;
import com.simsilica.lemur.Checkbox;
import com.simsilica.lemur.Container;
@ -16,122 +16,80 @@ import com.simsilica.lemur.style.ElementId;
import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp;
/**
* SettingsMenu ist ein Overlay-Menü, das durch ESC aufgerufen werden kann.
*/
public class SettingsMenu extends Dialog {
private final MonopolyApp app;
private final Geometry overlayBackground;
private final Container settingsContainer;
private Geometry blockLayer;
private final Node savedGuiNodeContent = new Node("SavedGuiNodeContent");
public SettingsMenu(MonopolyApp app) {
super(app.getDialogManager());
this.app = app;
// Blockierungsebene hinzufügen
addBlockLayer();
// Hintergrundbild
addBackgroundImage();
// Halbtransparentes Overlay hinzufügen
overlayBackground = createOverlayBackground();
app.getGuiNode().attachChild(overlayBackground);
// Hauptcontainer für das Menü
settingsContainer = new Container();
settingsContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.1f, 0.1f, 0.1f, 0.9f)));
// Hintergrundfarbe für das Container-Element setzen, um es undurchsichtig zu machen
settingsContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.1f, 0.1f, 0.1f, 0.8f))); // Teiltransparent, falls gewünscht
// Titel "Einstellungen"
// Titel
Label settingsTitle = settingsContainer.addChild(new Label("Einstellungen", new ElementId("settings-title")));
settingsTitle.setFontSize(48);
settingsTitle.setColor(ColorRGBA.White);
// Effekt Sound mit Slider und Checkbox
// Effekt-Sound: Slider und Checkbox
Container effectSoundContainer = settingsContainer.addChild(new Container());
Label effectSoundLabel = effectSoundContainer.addChild(new Label("Effekt Sound", new ElementId("label")));
effectSoundLabel.setFontSize(24);
effectSoundLabel.setColor(ColorRGBA.White);
effectSoundContainer.addChild(new Label("Effekt Sound", new ElementId("label")));
effectSoundContainer.addChild(new Slider());
effectSoundContainer.addChild(new Checkbox("Aktivieren")).setChecked(true);
Slider effectSoundSlider = effectSoundContainer.addChild(new Slider());
effectSoundSlider.setPreferredSize(new com.jme3.math.Vector3f(300, 30, 0));
Checkbox effectSoundCheckbox = effectSoundContainer.addChild(new Checkbox(""));
effectSoundCheckbox.setChecked(true);
// Hintergrund Musik mit Slider und Checkbox
// Hintergrundmusik: 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);
backgroundMusicContainer.addChild(new Label("Hintergrund Musik", new ElementId("label")));
backgroundMusicContainer.addChild(new Slider());
backgroundMusicContainer.addChild(new Checkbox("Aktivieren")).setChecked(true);
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
// 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
// Zentriere das Menü
settingsContainer.setLocalTranslation(
(app.getCamera().getWidth() - settingsContainer.getPreferredSize().x) / 2,
(app.getCamera().getHeight() + settingsContainer.getPreferredSize().y) / 2,
1 // Höhere Z-Ebene für den Vordergrund
1
);
app.getGuiNode().attachChild(settingsContainer);
}
private void addBlockLayer() {
// Sichern des aktuellen GUI-Inhalts
for (var child : app.getGuiNode().getChildren()) {
savedGuiNodeContent.attachChild(child);
}
app.getGuiNode().detachAllChildren();
// Blockierungsebene erstellen und hinzufügen
blockLayer = new Geometry("BlockLayer", new Quad(app.getCamera().getWidth(), app.getCamera().getHeight()));
blockLayer.setMaterial(createTransparentMaterial());
blockLayer.setLocalTranslation(0, 0, 0); // Platzierung unterhalb des SettingsMenu
app.getGuiNode().attachChild(blockLayer);
}
private com.jme3.material.Material createTransparentMaterial() {
com.jme3.material.Material material = new com.jme3.material.Material(
app.getAssetManager(),
"Common/MatDefs/Misc/Unshaded.j3md"
);
material.setColor("Color", new ColorRGBA(0, 0, 0, 0.5f)); // Halbtransparent
material.getAdditionalRenderState().setBlendMode(com.jme3.material.RenderState.BlendMode.Alpha);
return material;
}
private void addBackgroundImage() {
Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/unibw-Bib2.png");
/**
* 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 background = new Geometry("Background", quad);
com.jme3.material.Material backgroundMaterial = new com.jme3.material.Material(
app.getAssetManager(),
"Common/MatDefs/Misc/Unshaded.j3md"
);
backgroundMaterial.setTexture("ColorMap", backgroundImage);
background.setMaterial(backgroundMaterial);
background.setLocalTranslation(0, 0, -1); // Platzierung hinter dem SettingsMenu
app.getGuiNode().attachChild(background);
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
public void close() {
// Entfernt das SettingsMenu und die Blockierungsebene
app.getGuiNode().detachChild(settingsContainer);
app.getGuiNode().detachChild(blockLayer);
// Stellt die ursprüngliche GUI wieder her
for (var child : savedGuiNodeContent.getChildren()) {
app.getGuiNode().attachChild(child);
}
savedGuiNodeContent.detachAllChildren();
app.getGuiNode().detachChild(overlayBackground);
app.setSettingsMenuOpen(false);
}
}

View File

@ -7,6 +7,13 @@
package pp.monopoly.game.client;
import java.io.File;
import java.io.IOException;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.util.ArrayList;
import java.util.List;
import pp.monopoly.message.client.ClientMessage;
import pp.monopoly.message.server.BuyPropertyResponse;
import pp.monopoly.message.server.DiceResult;
@ -21,25 +28,6 @@ import pp.monopoly.message.server.TradeReply;
import pp.monopoly.message.server.TradeRequest;
import pp.monopoly.message.server.UpdatePlayerAssets;
import pp.monopoly.message.server.ViewAssetsResponse;
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.IOException;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.util.ArrayList;
import java.util.List;
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;