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

This commit is contained in:
Yvonne Schmidt 2024-11-18 23:04:43 +01:00
commit 843052989b
11 changed files with 182 additions and 52 deletions

View File

@ -0,0 +1,18 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="MonopolyApp" type="Application" factoryName="Application" singleton="false"
nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="pp.monopoly.client.MonopolyApp"/>
<module name="Projekte.monopoly.client.main"/>
<option name="VM_PARAMETERS" value="-Djava.util.logging.config.file=logging.properties"/>
<option name="WORKING_DIRECTORY" value="$MODULE_WORKING_DIR$"/>
<extension name="coverage">
<pattern>
<option name="PATTERN" value="pp.monopoly.client.*"/>
<option name="ENABLED" value="true"/>
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true"/>
</method>
</configuration>
</component>

View File

@ -0,0 +1,17 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="MonopolyServer" type="Application" factoryName="Application"
nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="pp.monopoly.server.MonopolyServer"/>
<module name="Projekte.monopoly.server.main"/>
<option name="WORKING_DIRECTORY" value="$MODULE_WORKING_DIR$"/>
<extension name="coverage">
<pattern>
<option name="PATTERN" value="pp.monopoly.server.*"/>
<option name="ENABLED" value="true"/>
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true"/>
</method>
</configuration>
</component>

View File

@ -7,22 +7,21 @@
package pp.battleship.client;
import java.io.File;
import java.io.IOException;
import java.util.prefs.Preferences;
import com.simsilica.lemur.Button;
import com.simsilica.lemur.Checkbox;
import com.simsilica.lemur.Label;
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 java.io.File;
import java.io.IOException;
import java.util.prefs.Preferences;
import static pp.battleship.Resources.lookup;
import static pp.util.PreferencesUtils.getPreferences;
/**
@ -39,7 +38,7 @@ class Menu extends Dialog {
private final VolumeSlider slider;
/**
* Constructs the Menu dialog for the Battleship application.
* Constructs the Menu dialog for the Battleship application.+
*
* @param app the BattleshipApp instance
*/

View File

@ -7,6 +7,7 @@ description = 'Monopoly Client'
dependencies {
implementation project(":jme-common")
implementation project(":monopoly:model")
implementation project(":monopoly:server")
implementation libs.jme3.desktop

View File

@ -9,8 +9,10 @@ import com.jme3.font.BitmapText;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.system.AppSettings;
import com.simsilica.lemur.GuiGlobals;
import com.simsilica.lemur.Label;
import com.simsilica.lemur.style.BaseStyles;
import pp.dialog.DialogBuilder;
@ -23,6 +25,7 @@ import pp.monopoly.game.client.MonopolyClient;
import pp.monopoly.game.client.ServerConnection;
import pp.monopoly.notification.GameEventListener;
import pp.monopoly.notification.InfoTextEvent;
import pp.monopoly.server.MonopolyServer;
public class MonopolyApp extends SimpleApplication implements MonopolyClient, GameEventListener {
private BitmapText topText;
@ -37,6 +40,8 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
private TestWorld testWorld;
private boolean isSettingsMenuOpen = false;
private boolean inputBlocked = false;
private MonopolyServer monopolyServer;
/**
* Path to the styles script for GUI elements.
*/
@ -206,4 +211,21 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
guiNode.detachAllChildren(); // Entferne die GUI
StartMenu.createStartMenu(this); // Zeige das Startmenü erneut
}
/**
* Startet den Server in einem neuen Thread.
*/
public void startServer() {
new Thread(() -> {
try {
monopolyServer = new MonopolyServer(); // Erstelle Serverinstanz
} catch (Exception e) {
e.printStackTrace();
}
}).start();
}
public MonopolyServer getMonopolyServer() {
return monopolyServer;
}
}

View File

@ -1,7 +1,6 @@
package pp.monopoly.client;
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;

View File

@ -1,10 +1,11 @@
package pp.monopoly.client.gui;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import javax.swing.JOptionPane;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.network.Client;
import com.jme3.network.Network;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Quad;
import com.jme3.texture.Texture;
@ -17,6 +18,7 @@ import com.simsilica.lemur.component.SpringGridLayout;
import pp.monopoly.client.MonopolyApp;
import pp.monopoly.client.StartMenu;
import pp.monopoly.server.MonopolyServer;
/**
* CreateGameMenu class represents the menu for creating a new game.
@ -26,6 +28,7 @@ public class CreateGameMenu {
private final MonopolyApp app;
private final Container menuContainer;
private Geometry background;
private Label serverStatusLabel;
public CreateGameMenu(MonopolyApp app) {
this.app = app;
@ -64,15 +67,18 @@ public class CreateGameMenu {
cancelButton.setPreferredSize(new Vector3f(120, 40, 0));
cancelButton.addClickCommands(source -> goBackToStartMenu());
// "Spiel hosten"-Button (funktionslos)
Button hostButton = buttonContainer.addChild(new Button("Spiel hosten"));
// "Selber hosten"-Button
Button hostButton = buttonContainer.addChild(new Button("Selber hosten"));
hostButton.setPreferredSize(new Vector3f(120, 40, 0));
// Keine Funktion zugewiesen
hostButton.addClickCommands(source -> app.startServer());
// "Beitreten"-Button (ebenfalls funktionslos, falls benötigt)
// "Beitreten"-Button (vorerst funktionslos)
Button joinButton = buttonContainer.addChild(new Button("Beitreten"));
joinButton.setPreferredSize(new Vector3f(120, 40, 0));
// Keine Funktion zugewiesen
// Serverstatus-Label
serverStatusLabel = menuContainer.addChild(new Label("Serverstatus: Noch nicht gestartet"));
serverStatusLabel.setFontSize(24);
// Zentrierung des Containers
menuContainer.setLocalTranslation(
@ -81,10 +87,17 @@ public class CreateGameMenu {
1 // Höhere Z-Ebene für den Vordergrund
);
app.getGuiNode().attachChild(menuContainer);
app.getInputManager().addMapping("OpenTestWorld", new com.jme3.input.controls.KeyTrigger(com.jme3.input.KeyInput.KEY_T));
app.getInputManager().addListener(new com.jme3.input.controls.ActionListener() {
@Override
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("OpenTestWorld") && isPressed) {
app.startTestWorld(); // Öffnet die TestWorld
}
}
}, "OpenTestWorld");
// Key-Mapping für Taste "T"
setupKeyMappings();
app.getGuiNode().attachChild(menuContainer);
}
/**
@ -110,30 +123,4 @@ public class CreateGameMenu {
app.getGuiNode().detachChild(background); // Entfernt das Hintergrundbild
StartMenu.createStartMenu(app);
}
/**
* Fügt ein Key-Mapping hinzu, um die TestWorld mit der Taste "T" zu öffnen.
*/
private void setupKeyMappings() {
app.getInputManager().addMapping("OpenTestWorld", new KeyTrigger(KeyInput.KEY_T));
app.getInputManager().addListener(actionListener, "OpenTestWorld");
}
/**
* ActionListener, um auf Tastendrücke zu reagieren.
*/
private final ActionListener actionListener = (name, isPressed, tpf) -> {
if (name.equals("OpenTestWorld") && isPressed) {
openTestWorld();
}
};
/**
* Öffnet die TestWorld.
*/
private void openTestWorld() {
app.getGuiNode().detachChild(menuContainer);
app.getGuiNode().detachChild(background); // Entfernt das Hintergrundbild
app.startTestWorld(); // Öffne die TestWorld
}
}

View File

@ -0,0 +1,89 @@
package pp.monopoly.client.gui;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
public class ServerScreen {
private JFrame frame;
private JTextField inputField;
private JLabel label;
private JButton startButton;
private JButton stopButton;
public ServerScreen() {
initialize();
}
private void initialize() {
// Erstelle das Hauptfenster
frame = new JFrame("Server Placeholder"); // Setze den Titel
frame.setSize(400, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
// Eingabefeld und Label im oberen Bereich
JPanel topPanel = new JPanel();
topPanel.setLayout(new FlowLayout());
label = new JLabel("Server-Port:");
inputField = new JTextField("42069", 10);
topPanel.add(label);
topPanel.add(inputField);
// Buttons im unteren Bereich
JPanel bottomPanel = new JPanel();
bottomPanel.setLayout(new FlowLayout());
startButton = new JButton("Start Server");
stopButton = new JButton("Stop Server");
stopButton.setEnabled(false); // Stop-Button ist anfangs deaktiviert
bottomPanel.add(startButton);
bottomPanel.add(stopButton);
// Füge die Panels zum Hauptfenster hinzu
frame.add(topPanel, BorderLayout.NORTH);
frame.add(bottomPanel, BorderLayout.SOUTH);
// Aktion für Start-Button
startButton.addActionListener(e -> startServer());
// Aktion für Stop-Button
stopButton.addActionListener(e -> stopServer());
// Zeige das Fenster
frame.setVisible(true);
}
private void startServer() {
String port = inputField.getText();
try {
int portNumber = Integer.parseInt(port);
// Server-Startlogik hier einfügen
JOptionPane.showMessageDialog(frame, "Server gestartet auf Port " + portNumber);
startButton.setEnabled(false); // Deaktiviere den Start-Button
stopButton.setEnabled(true); // Aktiviere den Stop-Button
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(frame, "Ungültiger Port: " + port, "Fehler", JOptionPane.ERROR_MESSAGE);
}
}
private void stopServer() {
// Server-Stoplogik hier einfügen
JOptionPane.showMessageDialog(frame, "Server gestoppt.");
startButton.setEnabled(true); // Aktiviere den Start-Button
stopButton.setEnabled(false); // Deaktiviere den Stop-Button
}
public static void main(String[] args) {
SwingUtilities.invokeLater(ServerScreen::new);
}
}

View File

@ -57,6 +57,7 @@ public class SettingsMenu extends Dialog {
quitButton.setFontSize(32);
quitButton.addClickCommands(source -> app.stop());
// Zentriere das Menü
settingsContainer.setLocalTranslation(
(app.getCamera().getWidth() - settingsContainer.getPreferredSize().x) / 2,

View File

@ -7,13 +7,10 @@
package pp.monopoly;
import pp.util.config.Config;
import java.util.Map;
import java.util.TreeMap;
import static java.lang.Math.max;
import pp.util.config.Config;
/**
* Provides access to the configuration settings for the Monopoly game.
* <p>
@ -31,7 +28,7 @@ public class MonopolyConfig extends Config {
* The default port number for the Monopoly server.
*/
@Property("port")
private int port = 1234;
private int port = 42069;
/**
* The width of the game map in terms of grid units.

View File

@ -65,7 +65,7 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
/**
* Creates the server.
*/
MonopolyServer() {
public MonopolyServer() {
config.readFromIfExists(CONFIG_FILE);
LOGGER.log(Level.INFO, "Configuration: {0}", config); //NON-NLS
logic = new ServerGameLogic(this, config);