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 7724bd9..16640fe 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 @@ -25,7 +25,7 @@ import com.simsilica.lemur.style.ElementId; import pp.dialog.Dialog; import pp.monopoly.client.MonopolyApp; -import pp.monopoly.game.server.PlayerColor; +import pp.monopoly.game.server.Player; import pp.monopoly.message.client.PlayerReady; import pp.monopoly.notification.Sound; @@ -67,6 +67,9 @@ public class LobbyMenu extends Dialog { /** Selected player figure. */ private String figure; + private VersionedReference> selectionRef; + private Selector figureDropdown; + /** * Constructs the lobby menu for player configuration. * @@ -142,7 +145,7 @@ public class LobbyMenu extends Dialog { figureDropdownContainer.setBackground(null); VersionedList figures = new VersionedList<>(); - figures.add("Laptop"); + figures.add("Computer"); figures.add("Flugzeug"); figures.add("Jägermeister"); figures.add("Katze"); @@ -150,8 +153,7 @@ public class LobbyMenu extends Dialog { figures.add("Handyholster"); - - Selector figureDropdown = new Selector<>(figures, "glass"); + figureDropdown = new Selector<>(figures, "glass"); figureDropdown.setBackground(new QuadBackgroundComponent(ColorRGBA.DarkGray)); figureDropdown.setPreferredSize(new Vector3f(100, 20, 0)); figureDropdownContainer.addChild(figureDropdown); @@ -159,10 +161,12 @@ public class LobbyMenu extends Dialog { Vector3f dimens2 = figureDropdown.getPopupContainer().getPreferredSize(); dimens2.setX( dimens.getX() ); figureDropdown.getPopupContainer().setPreferredSize(new Vector3f(200,200,5)); - figureDropdown.getSelectionModel().setSelection(0); - figure = "Laptop"; - addSelectionActionListener(figureDropdown, this::onDropdownSelectionChanged); + // Create selection ref for updating + selectionRef = figureDropdown.getSelectionModel().createReference(); + // Set default + figureDropdown.getSelectionModel().setSelection(0); + onDropdownSelectionChanged(figureDropdown); Container buttonContainer = menuContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y))); buttonContainer.setPreferredSize(new Vector3f(100, 40, 0)); @@ -216,6 +220,7 @@ public class LobbyMenu extends Dialog { 1 // Höhere Z-Ebene für den Vordergrund ); + app.getGuiNode().attachChild(menuContainer); } @@ -247,31 +252,12 @@ public class LobbyMenu extends Dialog { // Create a material with a solid color Material material = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); - material.setColor("Color", idToColor()); // Set the desired color + material.setColor("Color", Player.getColor(app.getId()).getColor()); // Set the desired color circleGeometry.setMaterial(material); return circleGeometry; } - /** - * Maps the player's ID to a corresponding color. - * - * @return the color associated with the player's ID - */ - private ColorRGBA idToColor() { - switch (app.getId()+1) { - case 1: return PlayerColor.CYAN.getColor(); - case 2: return PlayerColor.YELLOW.getColor(); - case 3: return PlayerColor.RED.getColor(); - case 4: return PlayerColor.PINK.getColor(); - case 5: return PlayerColor.GREEN.getColor(); - case 6: return PlayerColor.PURPLE.getColor(); - - default: - return null; - } - } - /** * Toggles the player's ready state and sends the configuration to the server. */ @@ -287,42 +273,11 @@ public class LobbyMenu extends Dialog { new SettingsMenu(app).open(); } - /** - * Adds a custom action listener to a dropdown selector. - * - * @param selector the selector to add the listener to - * @param listener the action to perform when a selection changes - */ - 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(); - listener.onSelectionChanged(selected); - } - } - - @Override - protected void initialize(Application app) { - } - - @Override - protected void cleanup(Application app) { - } - - @Override - protected void onEnable() { - - } - - @Override - protected void onDisable() { - - } - }); + @Override + public void update(float tpf) { + if (selectionRef.update()) { + onDropdownSelectionChanged(figureDropdown); + } } /** @@ -330,30 +285,20 @@ public class LobbyMenu extends Dialog { * * @param selected the selected figure */ - private void onDropdownSelectionChanged(String selected) { + private void onDropdownSelectionChanged(Selector selector) { app.getGameLogic().playSound(Sound.BUTTON); - switch (selected) { - case "[0]": - figure = "Computer"; - break; - case "[1]": - figure = "Flugzeug"; - break; - case "[2]": + switch (selector.getSelectedItem()) { + case "Jägermeister": figure = "Jaegermeister"; break; - case "[3]": - figure = "Katze"; - break; - case "[4]": - figure = "OOP"; - break; - case "[5]": + case "Handyholster": figure = "Holster"; break; default: - break; + figure = selector.getSelectedItem(); + break; } + System.out.println("FIGUR:::::"+figure); } /** 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 2190873..89b44d2 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 @@ -133,7 +133,7 @@ public class Toolbar extends Dialog implements GameEventListener { // Spielerfarbe abrufen Player currentPlayer = playerHandler.getPlayerById(app.getId()); - ColorRGBA playerColor = currentPlayer.getColor().getColor(); + ColorRGBA playerColor = Player.getColor(currentPlayer.getId()).getColor(); // Oberer Balken Container playerColorBar = new Container(); @@ -381,7 +381,7 @@ public class Toolbar extends Dialog implements GameEventListener { for (Player player : playerHandler.getPlayers()) { if (player.getId() != app.getId()) { // Spielerfarbe abrufen - ColorRGBA playerColor = (player.getColor().getColor()); + ColorRGBA playerColor = (Player.getColor(player.getId()).getColor()); // Label für den Spieler erstellen Label playerLabel = new Label( diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/Player.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/Player.java index 95f99b1..b8c2209 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/Player.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/Player.java @@ -90,7 +90,7 @@ public class Player implements FieldVisitor{ return figure; } - public PlayerColor getColor() { + public static PlayerColor getColor(int id) { switch ((id%6)+1) { case 1: return PlayerColor.CYAN; case 2: return PlayerColor.YELLOW; diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerColor.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerColor.java index 3d38ed6..8bb23d6 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerColor.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerColor.java @@ -6,22 +6,24 @@ import com.jme3.math.ColorRGBA; * Enum representing six distinct colors for players in the game. */ public enum PlayerColor { - CYAN(new ColorRGBA(1 / 255f, 190 / 255f, 254 / 255f, 1)), - YELLOW(new ColorRGBA(255 / 255f, 255 / 255f, 0 / 255f, 1)), - RED(new ColorRGBA(255 / 255f, 0 / 255f, 0 / 255f, 1)), - PINK(new ColorRGBA(255 / 255f, 77 / 255f, 166 / 255f, 1)), - GREEN(new ColorRGBA(0 / 255f, 204 / 255f, 0 / 255f, 1)), - PURPLE(new ColorRGBA(143 / 255f, 0 / 255f, 255 / 255f, 1)); + CYAN(new ColorRGBA(1 / 255f, 190 / 255f, 254 / 255f, 1), "Cyan"), + YELLOW(new ColorRGBA(255 / 255f, 255 / 255f, 0 / 255f, 1), "Gelb"), + RED(new ColorRGBA(255 / 255f, 0 / 255f, 0 / 255f, 1), "Rot"), + PINK(new ColorRGBA(255 / 255f, 77 / 255f, 166 / 255f, 1), "Pink"), + GREEN(new ColorRGBA(0 / 255f, 204 / 255f, 0 / 255f, 1), "Grün"), + PURPLE(new ColorRGBA(143 / 255f, 0 / 255f, 255 / 255f, 1), "Lila"); private final ColorRGBA color; + private final String colorName; /** * Constructs a PlayerColor with the specified ColorRGBA value. * * @param color the ColorRGBA value associated with the player color */ - PlayerColor(ColorRGBA color) { + PlayerColor(ColorRGBA color, String colorName) { this.color = color; + this.colorName = colorName; } /** @@ -32,4 +34,13 @@ public enum PlayerColor { public ColorRGBA getColor() { return color; } + + /** + * Gets the Name of the Color + * + * @return a String with re corresponing name + */ + public String getColorName() { + return colorName; + } }