From f67810b2883852aca8ca98f42eddbf8c7fe50171 Mon Sep 17 00:00:00 2001 From: Yvonne Schmidt Date: Mon, 25 Nov 2024 21:29:54 +0100 Subject: [PATCH 1/2] fixed toolbar buttons --- .../pp/monopoly/client/gui/ChoosePartner.java | 6 ++--- .../java/pp/monopoly/client/gui/Toolbar.java | 25 ++++++++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java index c0c3596..0de8a3a 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java @@ -34,13 +34,13 @@ public class ChoosePartner extends Dialog { new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f)); menuContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X)); - menuContainer.setPreferredSize(new Vector3f(1000, 600, 0)); // Fixed size of the container + menuContainer.setPreferredSize(new Vector3f(1000, 600, 5)); // Fixed size of the container menuContainer.setBackground(translucentWhiteBackground); // Create a smaller horizontal container for the label, input field, and spacers Container horizontalContainer = menuContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y))); horizontalContainer.setPreferredSize(new Vector3f(600, 40, 0)); // Adjust container size - horizontalContainer.setBackground(null); + horizontalContainer.setBackground(translucentWhiteBackground); Label title = horizontalContainer.addChild(new Label("Wähle deinen Handelspartner:", new ElementId("label-Bold"))); title.setFontSize(40); @@ -57,7 +57,7 @@ public class ChoosePartner extends Dialog { Material backgroundMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); backgroundMaterial.setTexture("ColorMap", backgroundImage); background.setMaterial(backgroundMaterial); - background.setLocalTranslation(0, 0, -1); // Hintergrundebene + background.setLocalTranslation(0, 0, 4); // Hintergrundebene app.getGuiNode().attachChild(background); } diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java index 68e2b9d..da1b1a1 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java @@ -165,26 +165,27 @@ public class Toolbar extends Dialog { return tradebutton; } - private Button addEndTurnButton() { - Button endTurnButton = new Button("Grundstücke"); - endTurnButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons - endTurnButton.addClickCommands(s -> ifTopDialog(() -> { - app.getGameLogic().playSound(Sound.BUTTON); - //TODO open property dialog - })); - return endTurnButton; - } - private Button addPropertyMenuButton() { - Button propertyMenuButton = new Button("Zug beenden"); + Button propertyMenuButton = new Button("Grundstücke"); + propertyMenuButton.setFontSize(30.0f); propertyMenuButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons propertyMenuButton.addClickCommands(s -> ifTopDialog(() -> { app.getGameLogic().playSound(Sound.BUTTON); - //TODO send end turn + //TODO open property dialog })); return propertyMenuButton; } + private Button addEndTurnButton() { + Button endTurnButton = new Button("Zug beenden"); + endTurnButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons + endTurnButton.addClickCommands(s -> ifTopDialog(() -> { + app.getGameLogic().playSound(Sound.BUTTON); + //TODO send end turn + })); + return endTurnButton; + } + /** * Erstellt die Anzeige für die aktuelle Position. * From 269aceaf1abd59ce4182b8ca67ecdfe7628198d4 Mon Sep 17 00:00:00 2001 From: Yvonne Schmidt Date: Tue, 26 Nov 2024 00:11:01 +0100 Subject: [PATCH 2/2] added ChoosePartner menu --- .../pp/monopoly/client/gui/ChoosePartner.java | 154 +++++++++++++++--- .../pp/monopoly/client/gui/LobbyMenu.java | 6 + 2 files changed, 140 insertions(+), 20 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java index 0de8a3a..0b2bfd7 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java @@ -1,5 +1,7 @@ package pp.monopoly.client.gui; +import com.jme3.app.Application; +import com.jme3.app.state.BaseAppState; import com.jme3.material.Material; import com.jme3.math.ColorRGBA; import com.jme3.math.Vector3f; @@ -7,63 +9,175 @@ 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.Selector; import com.simsilica.lemur.TextField; import com.simsilica.lemur.component.QuadBackgroundComponent; import com.simsilica.lemur.component.SpringGridLayout; +import com.simsilica.lemur.core.VersionedList; +import com.simsilica.lemur.core.VersionedReference; import com.simsilica.lemur.style.ElementId; import pp.dialog.Dialog; import pp.monopoly.client.MonopolyApp; +import pp.monopoly.notification.Sound; +import java.util.Set; public class ChoosePartner extends Dialog { - private final MonopolyApp app; - private final Container menuContainer; - private Geometry background; - + private Selector playerSelector; + private final Button cancelButton = new Button("Abbrechen"); + private final Button confirmButton = new Button("Bestätigen"); + private final Container mainContainer; + private Container lowerLeftMenu; + private Container lowerRightMenu; + QuadBackgroundComponent translucentWhiteBackground = + new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f)); + /** + * Constructs the ChoosePartner dialog. + * + * @param app The Monopoly application instance. + */ public ChoosePartner(MonopolyApp app) { super(app.getDialogManager()); this.app = app; - // Hintergrundbild laden und hinzufügen + + // Background Image addBackgroundImage(); - QuadBackgroundComponent translucentWhiteBackground = - new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f)); + // Main container for the UI components + mainContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X)); + mainContainer.setPreferredSize(new Vector3f(1000, 600, 0)); + mainContainer.setBackground(translucentWhiteBackground); - menuContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X)); - menuContainer.setPreferredSize(new Vector3f(1000, 600, 5)); // Fixed size of the container - menuContainer.setBackground(translucentWhiteBackground); + // Add title with background + Label headerLabel = mainContainer.addChild(new Label("Wähle deinen Handelspartner:", new ElementId("header"))); + headerLabel.setFontSize(40); + headerLabel.setBackground(translucentWhiteBackground); - // Create a smaller horizontal container for the label, input field, and spacers - Container horizontalContainer = menuContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y))); - horizontalContainer.setPreferredSize(new Vector3f(600, 40, 0)); // Adjust container size - horizontalContainer.setBackground(translucentWhiteBackground); + // Dropdown for player selection + mainContainer.addChild(createDropdown()); - Label title = horizontalContainer.addChild(new Label("Wähle deinen Handelspartner:", new ElementId("label-Bold"))); - title.setFontSize(40); + // Add buttons + mainContainer.addChild(createButtonContainer()); + // Attach main container to GUI node + app.getGuiNode().attachChild(mainContainer); + mainContainer.setLocalTranslation( + (app.getCamera().getWidth() - mainContainer.getPreferredSize().x) / 2, + (app.getCamera().getHeight() + mainContainer.getPreferredSize().y) / 2, + 0 + ); } /** - * Lädt das Hintergrundbild und fügt es als geometrische Ebene hinzu. + * Creates the dropdown menu for selecting a partner. + * + * @return The dropdown container. + */ + private Container createDropdown() { + Container dropdownContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X)); + dropdownContainer.setPreferredSize(new Vector3f(100, 80, 0)); + dropdownContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black))); + + VersionedList playerOptions = new VersionedList<>(); + playerOptions.add("Spieler 1"); + playerOptions.add("Spieler 2"); + playerOptions.add("Spieler 3"); + playerOptions.add("Spieler 4"); + + playerSelector = new Selector<>(playerOptions, "glass"); + dropdownContainer.addChild(playerSelector); + Vector3f dimens = dropdownContainer.getPreferredSize(); + Vector3f dimens2 = playerSelector.getPopupContainer().getPreferredSize(); + dimens2.setX( dimens.getX() ); + playerSelector.getPopupContainer().setPreferredSize(new Vector3f(200,200,5)); + + return dropdownContainer; + } + + /** + * Creates the button container with cancel and confirm buttons. + * + * @return The button container. + */ + private Container createButtonContainer() { + Container buttonContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y)); + buttonContainer.setBackground(translucentWhiteBackground); + + // "Abbrechen" button + lowerLeftMenu = new Container(); + cancelButton.setPreferredSize(new Vector3f(200, 60, 0)); + cancelButton.setFontSize(30); + cancelButton.addClickCommands(s -> ifTopDialog(() -> { + app.getGameLogic().playSound(Sound.BUTTON); + this.close(); + new Toolbar(app).open(); + })); + lowerLeftMenu.addChild(cancelButton); + + // Position the container near the bottom-left corner + lowerLeftMenu.setLocalTranslation(new Vector3f(120, 170, 3)); // Adjust X and Y to align with the bottom-left corner + app.getGuiNode().attachChild(lowerLeftMenu); + + + // "Bestätigen" button + lowerRightMenu = new Container(); + confirmButton.setPreferredSize(new Vector3f(200, 60, 0)); + confirmButton.setFontSize(30); + confirmButton.addClickCommands(s -> ifTopDialog(() -> { + app.getGameLogic().playSound(Sound.BUTTON); + String selectedPlayer = playerSelector.getSelectedItem(); + System.out.println("Selected player: " + selectedPlayer); + this.close(); + // TODO: Open trade menu or next step + })); + lowerRightMenu.addChild(confirmButton); + + // Position the container near the bottom-right corner + lowerRightMenu.setLocalTranslation(new Vector3f(app.getCamera().getWidth() - 320, 170, 3)); // X: 220px from the right, Y: 50px above the bottom + app.getGuiNode().attachChild(lowerRightMenu); + + + return buttonContainer; + } + + /** + * Adds a background image to the dialog. */ 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); + 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, 4); // Hintergrundebene - + background.setLocalTranslation(0, 0, -1); // Position behind other GUI elements app.getGuiNode().attachChild(background); } + /** + * Handles the escape action for the dialog. + */ @Override public void escape() { new SettingsMenu(app).open(); } + + /** + * Updates the dialog periodically, called by the dialog manager. + * + * @param delta The time elapsed since the last update. + */ + @Override + public void update(float delta) { + // Periodic updates (if needed) can be implemented here + } } + + + diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/LobbyMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/LobbyMenu.java index 9e60d9f..a592ac5 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/LobbyMenu.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/LobbyMenu.java @@ -88,6 +88,7 @@ public class LobbyMenu extends Dialog { // Dropdowns and Labels Container dropdownContainer = menuContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y))); + dropdownContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black))); dropdownContainer.setPreferredSize(new Vector3f(800, 200, 0)); dropdownContainer.setBackground(null); dropdownContainer.setInsets(new Insets3f(10, 0, 0, 0)); @@ -122,6 +123,11 @@ public class LobbyMenu extends Dialog { figureDropdown.setBackground(new QuadBackgroundComponent(ColorRGBA.DarkGray)); figureDropdown.setPreferredSize(new Vector3f(100, 20, 0)); figureDropdownContainer.addChild(figureDropdown); + Vector3f dimens = dropdownContainer.getPreferredSize(); + Vector3f dimens2 = figureDropdown.getPopupContainer().getPreferredSize(); + dimens2.setX( dimens.getX() ); + figureDropdown.getPopupContainer().setPreferredSize(new Vector3f(200,200,5)); + addSelectionActionListener(figureDropdown, this::onDropdownSelectionChanged);