diff --git a/Projekte/jme-common/src/main/resources/Interface/Lemur/pp-styles.groovy b/Projekte/jme-common/src/main/resources/Interface/Lemur/pp-styles.groovy index 394b2a2..7bac65e 100644 --- a/Projekte/jme-common/src/main/resources/Interface/Lemur/pp-styles.groovy +++ b/Projekte/jme-common/src/main/resources/Interface/Lemur/pp-styles.groovy @@ -258,3 +258,30 @@ selector("menu-button", "pp") { buttonCommands = stdButtonCommands } +// Style for Selector text +selector("selector.item.label") { + color = color(0, 0, 0, 1) // Black text + fontSize = 16 // Optional: Adjust the text size if needed + textHAlignment = HAlignment.Left // Optional: Align text to the left + insets = new Insets3f(2, 2, 2, 2) // Optional: Add padding around text +} +// Style the popup container background +selector("selector.popup") { + background = new QuadBackgroundComponent(new ColorRGBA(1, 1, 1, 0.8f)) // Translucent white background + insets = new Insets3f(5, 5, 5, 5) // Padding inside the popup container +} + +// Style the text of dropdown options +selector("selector.item.label") { + color = color(0, 0, 0, 1) // Black text + fontSize = 16 // Optional: Adjust font size + textHAlignment = HAlignment.Left // Align text to the left + insets = new Insets3f(2, 5, 2, 5) // Add padding for each option +} + +// Style the hover state of dropdown options +selector("selector.item.label", "hover") { + color = color(1, 1, 1, 1) // White text when hovered + background = new QuadBackgroundComponent(new ColorRGBA(0.2f, 0.6f, 1.0f, 0.9f)) // Highlighted background +} + 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 2912fb2..5d01e5e 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 @@ -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; @@ -16,14 +18,19 @@ 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.monopoly.client.MonopolyApp; +import java.util.Set; + public class LobbyMenu { private final MonopolyApp app; private final Container menuContainer; private Geometry background; + private final Selector dropdown; public LobbyMenu(MonopolyApp app) { this.app = app; @@ -41,15 +48,15 @@ public class LobbyMenu { menuContainer.setPreferredSize(new Vector3f(1000, 600, 0)); // Fixed size of the container menuContainer.setBackground(translucentWhiteBackground); - // Create a smaller horizontal container for the label, input field, and spacers + // 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, 50, 0)); // Adjust container size horizontalContainer.setBackground(null); - Label title = horizontalContainer.addChild(new Label("Startkapital:",new ElementId("label-Bold"))); + Label title = horizontalContainer.addChild(new Label("Startkapital:", new ElementId("label-Bold"))); title.setFontSize(48); - // Add a spacer between the title and the input field + // Add a spacer between the title and the input field Label spacerBeforeInput = horizontalContainer.addChild(new Label("")); // Invisible spacer spacerBeforeInput.setPreferredSize(new Vector3f(20, 1, 0)); // Width of the spacer @@ -59,7 +66,7 @@ public class LobbyMenu { startingCapital.setPreferredSize(new Vector3f(150, 50, 0)); startingCapital.setInsets(new Insets3f(5, 10, 5, 10)); // Add padding around the text inside the field - // Add a spacer after the input field + // Add a spacer after the input field Label spacerAfterInput = horizontalContainer.addChild(new Label("")); // Invisible spacer spacerAfterInput.setPreferredSize(new Vector3f(20, 1, 0)); // Width of the spacer @@ -76,20 +83,20 @@ public class LobbyMenu { playerListContainer.setBackground(null); Label playersLabel = playerListContainer.addChild(new Label("Noch keine Spieler verbunden.")); // Beispieltext - // Dropdown menu for game options - Selector dropdown = new Selector<>(); - for (int i = 1; i <= 10; i++) { // Generate 10 options - dropdown.getModel().add("Option " + i); - } + VersionedList items = new VersionedList<>(); + items.add("Alpha"); + items.add("Beta"); + items.add("Gamma"); + items.add("Back"); - menuContainer.addChild(new Label("Game Options:")); // Add a label for clarity + dropdown = new Selector<>(items); + dropdown.setBackground(new QuadBackgroundComponent(ColorRGBA.Black)); menuContainer.addChild(dropdown); - // Adjust the dropdown's popup container size if necessary - Vector3f dimens = menuContainer.getPreferredSize(); - Vector3f dimens2 = dropdown.getPopupContainer().getPreferredSize(); - dimens2.setX(dimens.getX()); - dropdown.getPopupContainer().setPreferredSize(dimens2); + // Add the custom action listener + addSelectionActionListener(dropdown, this::onDropdownSelectionChanged); + + // Buttons Container buttonContainer = menuContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y))); @@ -146,4 +153,71 @@ public class LobbyMenu { app.getGuiNode().detachChild(background); // Entfernt das Hintergrundbild new CreateGameMenu(app); } + + /** + * Adds a custom action listener to the Selector. + */ + private void addSelectionActionListener(Selector selector, SelectionActionListener listener) { + VersionedReference> selectionRef = selector.getSelectionModel().createReference(); + + app.getStateManager().attach(new BaseAppState() { + @Override + public void update(float tpf) { + if (selectionRef.update()) { + String selected = selectionRef.get().toString(); + System.out.println(selected); + listener.onSelectionChanged(selected); + } + } + + @Override + protected void initialize(Application app) { + } + + @Override + protected void cleanup(Application app) { + } + + @Override + protected void onEnable() { + + } + + @Override + protected void onDisable() { + + } + }); + } + + /** + * Callback for when the dropdown selection changes. + */ + private void onDropdownSelectionChanged(String selected) { + System.out.println("Selected: " + selected); + switch (selected) { + case "[0]": + System.out.println("Alpha selected"); + break; + case "[1]": + System.out.println("Beta selected"); + break; + case "[2]": + System.out.println("Gamma selected"); + break; + case "[3]": + goBackToCreateGame(); + break; + default: + System.out.println("Unknown selection"); + } + } + + /** + * Functional interface for a selection action listener. + */ + @FunctionalInterface + private interface SelectionActionListener { + void onSelectionChanged(T selection); + } } diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/SelectionListener.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/SelectionListener.java new file mode 100644 index 0000000..e668df5 --- /dev/null +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/SelectionListener.java @@ -0,0 +1,49 @@ +package pp.monopoly.client.gui.popups; + +/* + * $Id$ + * + * Copyright (c) 2013-2013 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +import com.jme3.scene.Spatial; + + +/** + * Notified when the current selection changes. + * + * @author Paul Speed + */ +public interface SelectionListener { + + public void selectionChanged( Spatial selection, Spatial previous ); +}