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 06:49:13 +01:00
commit 2b772199b0
4 changed files with 146 additions and 50 deletions

View File

@ -85,7 +85,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
setupInput();
setupGui();
// Erst jetzt StartMenu erstellen, nachdem GuiGlobals initialisiert ist
// Initialisiere das Startmenü
StartMenu.createStartMenu(this);
}
@ -103,6 +103,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
inputManager.addListener(escapeListener, "ESC");
}
private void handleEscape(boolean isPressed) {
if (isPressed) {
if (isSettingsMenuOpen && settingsMenu != null) {

View File

@ -1,70 +1,106 @@
package pp.monopoly.client.gui;
import com.jme3.material.Material;
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.Container;
import com.simsilica.lemur.Insets3f;
import com.simsilica.lemur.Label;
import com.simsilica.lemur.TextField;
import com.simsilica.lemur.component.SpringGridLayout;
import com.simsilica.lemur.style.ElementId;
import pp.monopoly.client.MonopolyApp;
import pp.monopoly.client.StartMenu;
/**
* CreateGameMenu class represents the menu for creating a new game.
*/
public class CreateGameMenu {
private final MonopolyApp app;
private final Container createGameContainer;
private final Container menuContainer;
private Geometry background;
public CreateGameMenu(MonopolyApp app) {
this.app = app;
// Hauptcontainer für das Menü mit Innenabstand
createGameContainer = new Container();
createGameContainer.setInsets(new Insets3f(10, 10, 10, 10));
// Hintergrundbild laden und hinzufügen
addBackgroundImage();
// Setzt den Titel des Menüs
Label title = createGameContainer.addChild(new Label("Neues Spiel", new ElementId("title")));
// Hauptcontainer für das Menü
menuContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X));
menuContainer.setPreferredSize(new Vector3f(600, 400, 0)); // Feste Größe des Containers
// Fügt zwei Eingabefelder unter dem Titel hinzu
TextField inputField1 = createGameContainer.addChild(new TextField("Eingabefeld 1"));
TextField inputField2 = createGameContainer.addChild(new TextField("Eingabefeld 2"));
// Titel
Label title = menuContainer.addChild(new Label("Neues Spiel"));
title.setFontSize(48);
// 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
// Eingabefelder-Container
Container inputContainer = menuContainer.addChild(new Container(new SpringGridLayout(Axis.Y, Axis.X)));
inputContainer.setPreferredSize(new Vector3f(200, 150, 0)); // Eingabefelder nicht ganz so breit
inputContainer.setLocalTranslation(20, 0, 0); // Abstand vom 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));
inputContainer.addChild(new Label("Server-Adresse:"));
TextField playerNameField = inputContainer.addChild(new TextField("localhost"));
playerNameField.setPreferredWidth(400); // Breite des Textfelds
Button button2 = buttonContainer.addChild(new Button("2"));
button2.setInsets(new Insets3f(5, 5, 5, 5));
inputContainer.addChild(new Label("Port:"));
TextField serverAddressField = inputContainer.addChild(new TextField("42069"));
serverAddressField.setPreferredWidth(400); // Breite des Textfelds
Button button3 = buttonContainer.addChild(new Button("3"));
button3.setInsets(new Insets3f(5, 5, 5, 5));
// Button-Container
Container buttonContainer = menuContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
buttonContainer.setPreferredSize(new Vector3f(400, 50, 0));
buttonContainer.setLocalTranslation(20, 0, 0); // Abstand vom Rand
// Fügt den Button-Container zum Hauptcontainer hinzu
createGameContainer.addChild(buttonContainer);
// "Abbrechen"-Button
Button cancelButton = buttonContainer.addChild(new Button("Abbrechen"));
cancelButton.setPreferredSize(new Vector3f(120, 40, 0));
cancelButton.addClickCommands(source -> goBackToStartMenu());
// Setzt die Breite des Hauptcontainers
createGameContainer.setPreferredSize(new Vector3f(600, 400, 0));
// "Spiel hosten"-Button
Button hostButton = buttonContainer.addChild(new Button("Spiel hosten"));
hostButton.setPreferredSize(new Vector3f(120, 40, 0));
// hostButton.addClickCommands(source -> hostGame()); // Placeholder for hosting logic
// Zentriert den Container auf dem Bildschirm
createGameContainer.setLocalTranslation(
(app.getCamera().getWidth() - createGameContainer.getPreferredSize().x) / 2,
(app.getCamera().getHeight() + createGameContainer.getPreferredSize().y) / 2,
0
// "Beitreten"-Button
Button joinButton = buttonContainer.addChild(new Button("Beitreten"));
joinButton.setPreferredSize(new Vector3f(120, 40, 0));
// joinButton.addClickCommands(source -> joinGame()); // Placeholder for joining logic
// Zentrierung des Containers
menuContainer.setLocalTranslation(
(app.getCamera().getWidth() - menuContainer.getPreferredSize().x) / 2,
(app.getCamera().getHeight() + menuContainer.getPreferredSize().y) / 2,
1 // Höhere Z-Ebene für den Vordergrund
);
// Fügt das Menü zum GUI-Knoten der App hinzu
app.getGuiNode().attachChild(createGameContainer);
app.getGuiNode().attachChild(menuContainer);
}
/**
* Schließt das CreateGameMenu.
* Lädt das Hintergrundbild und fügt es als geometrische Ebene hinzu.
*/
public void close() {
app.getGuiNode().detachChild(createGameContainer);
private void addBackgroundImage() {
Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/unibw-Bib2.png");
Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight());
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); // Hintergrundebene
app.getGuiNode().attachChild(background);
}
/**
* Geht zum Startmenü zurück, wenn "Abbrechen" angeklickt wird.
*/
private void goBackToStartMenu() {
app.getGuiNode().detachChild(menuContainer);
app.getGuiNode().detachChild(background); // Entfernt das Hintergrundbild
StartMenu.createStartMenu(app);
}
}

View File

@ -1,6 +1,10 @@
package pp.monopoly.client.gui;
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;
@ -15,15 +19,23 @@ import pp.monopoly.client.MonopolyApp;
public class SettingsMenu extends Dialog {
private final MonopolyApp app;
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();
settingsContainer = new Container();
// Hintergrundfarbe für das Container-Element setzen, um es undurchsichtig zu machen
settingsContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.1f, 0.1f, 0.1f, 1f))); // Dunkelgrauer, undurchsichtiger Hintergrund
settingsContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.1f, 0.1f, 0.1f, 0.8f))); // Teiltransparent, falls gewünscht
// Titel "Einstellungen"
Label settingsTitle = settingsContainer.addChild(new Label("Einstellungen", new ElementId("settings-title")));
@ -64,15 +76,62 @@ public class SettingsMenu extends Dialog {
settingsContainer.setLocalTranslation(
(app.getCamera().getWidth() - settingsContainer.getPreferredSize().x) / 2,
(app.getCamera().getHeight() + settingsContainer.getPreferredSize().y) / 2,
0
1 // Höhere Z-Ebene für den Vordergrund
);
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");
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);
}
@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.setSettingsMenuOpen(false);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB