CreateGame fertig für feinschliff (Icon test)

This commit is contained in:
Luca Puderbach 2024-11-15 06:25:21 +01:00
parent ed87a6167d
commit c31f924d77
3 changed files with 84 additions and 47 deletions

View File

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

View File

@ -1,70 +1,106 @@
package pp.monopoly.client.gui; package pp.monopoly.client.gui;
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.Insets3f;
import com.simsilica.lemur.Label; import com.simsilica.lemur.Label;
import com.simsilica.lemur.TextField; import com.simsilica.lemur.TextField;
import com.simsilica.lemur.component.SpringGridLayout; import com.simsilica.lemur.component.SpringGridLayout;
import com.simsilica.lemur.style.ElementId;
import pp.monopoly.client.MonopolyApp; import pp.monopoly.client.MonopolyApp;
import pp.monopoly.client.StartMenu;
/**
* CreateGameMenu class represents the menu for creating a new game.
*/
public class CreateGameMenu { public class CreateGameMenu {
private final MonopolyApp app; private final MonopolyApp app;
private final Container createGameContainer; private final Container menuContainer;
private Geometry background;
public CreateGameMenu(MonopolyApp app) { public CreateGameMenu(MonopolyApp app) {
this.app = app; this.app = app;
// Hauptcontainer für das Menü mit Innenabstand // Hintergrundbild laden und hinzufügen
createGameContainer = new Container(); addBackgroundImage();
createGameContainer.setInsets(new Insets3f(10, 10, 10, 10));
// Setzt den Titel des Menüs // Hauptcontainer für das Menü
Label title = createGameContainer.addChild(new Label("Neues Spiel", new ElementId("title"))); 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 // Titel
TextField inputField1 = createGameContainer.addChild(new TextField("Host")); Label title = menuContainer.addChild(new Label("Neues Spiel"));
TextField inputField2 = createGameContainer.addChild(new TextField("Port")); title.setFontSize(48);
// Erstellt einen Container mit einem Rasterlayout, um die Buttons nebeneinander anzuordnen // Eingabefelder-Container
Container buttonContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y)); Container inputContainer = menuContainer.addChild(new Container(new SpringGridLayout(Axis.Y, Axis.X)));
buttonContainer.setInsets(new Insets3f(5, 5, 5, 5)); // Abstand zwischen den Buttons und dem Rand 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 inputContainer.addChild(new Label("Server-Adresse:"));
Button button1 = buttonContainer.addChild(new Button("1")); TextField playerNameField = inputContainer.addChild(new TextField("localhost"));
button1.setInsets(new Insets3f(5, 5, 5, 5)); playerNameField.setPreferredWidth(400); // Breite des Textfelds
Button button2 = buttonContainer.addChild(new Button("2")); inputContainer.addChild(new Label("Port:"));
button2.setInsets(new Insets3f(5, 5, 5, 5)); TextField serverAddressField = inputContainer.addChild(new TextField("42069"));
serverAddressField.setPreferredWidth(400); // Breite des Textfelds
Button button3 = buttonContainer.addChild(new Button("3")); // Button-Container
button3.setInsets(new Insets3f(5, 5, 5, 5)); 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 // "Abbrechen"-Button
createGameContainer.addChild(buttonContainer); Button cancelButton = buttonContainer.addChild(new Button("Abbrechen"));
cancelButton.setPreferredSize(new Vector3f(120, 40, 0));
cancelButton.addClickCommands(source -> goBackToStartMenu());
// Setzt die Breite des Hauptcontainers // "Spiel hosten"-Button
createGameContainer.setPreferredSize(new Vector3f(600, 400, 0)); 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 // "Beitreten"-Button
createGameContainer.setLocalTranslation( Button joinButton = buttonContainer.addChild(new Button("Beitreten"));
(app.getCamera().getWidth() - createGameContainer.getPreferredSize().x) / 2, joinButton.setPreferredSize(new Vector3f(120, 40, 0));
(app.getCamera().getHeight() + createGameContainer.getPreferredSize().y) / 2, // joinButton.addClickCommands(source -> joinGame()); // Placeholder for joining logic
0
// 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(menuContainer);
app.getGuiNode().attachChild(createGameContainer);
} }
/** /**
* Schließt das CreateGameMenu. * Lädt das Hintergrundbild und fügt es als geometrische Ebene hinzu.
*/ */
public void close() { private void addBackgroundImage() {
app.getGuiNode().detachChild(createGameContainer); 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);
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB