From 91e4df747843f9219f580d9b0c5a8b328d2c3474 Mon Sep 17 00:00:00 2001 From: Simon Wilkening Date: Fri, 22 Nov 2024 05:23:52 +0100 Subject: [PATCH] =?UTF-8?q?B-Taste=20um=20Karte=20Kaufen=20Popup=20zu=20?= =?UTF-8?q?=C3=B6ffnen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/pp/monopoly/client/MonopolyApp.java | 36 +++++ .../monopoly/client/gui/CreateGameMenu.java | 10 ++ .../monopoly/client/gui/popups/BuyCard.java | 134 ++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyCard.java diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java index 4adde8d..e454bb9 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java @@ -18,6 +18,7 @@ import pp.dialog.DialogManager; import pp.graphics.Draw; import pp.monopoly.client.gui.SettingsMenu; import pp.monopoly.client.gui.TestWorld; +import pp.monopoly.client.gui.popups.BuyCard; import pp.monopoly.game.client.ClientGameLogic; import pp.monopoly.game.client.MonopolyClient; import pp.monopoly.game.client.ServerConnection; @@ -42,6 +43,11 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga private MonopolyServer monopolyServer; private NetworkSupport networkSupport; + + private BuyCard buyCard; + private boolean isBuyCardPopupOpen = false; + private final ActionListener BListener = (name, isPressed, tpf) -> handleB(isPressed); + /** * Path to the styles script for GUI elements. */ @@ -114,6 +120,9 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga inputManager.setCursorVisible(true); inputManager.addMapping("ESC", new KeyTrigger(KeyInput.KEY_ESCAPE)); inputManager.addListener(escapeListener, "ESC"); + + inputManager.addMapping("B", new KeyTrigger(KeyInput.KEY_B)); + inputManager.addListener(BListener, "B"); } private void handleEscape(boolean isPressed) { @@ -134,6 +143,25 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga } } + //logik zum wechselnden erscheinen und verschwinden beim drücken von B + private void handleB(boolean isPressed) { + if (isPressed) { + if (buyCard != null && isBuyCardPopupOpen) { + // Schließe das SettingsMenu + System.out.println("Schließe BuyCardPopup..."); + buyCard.close(); + buyCard = null; + setBuyCardPopupOpen(false); + } else { + // Öffne das SettingsMenu + System.out.println("Öffne BuyCardPopup..."); + buyCard = new BuyCard(this); + buyCard.open(); + setBuyCardPopupOpen(true); + } + } + } + private void blockInputs() { if (!inputBlocked) { System.out.println("Blockiere Eingaben..."); @@ -196,6 +224,10 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga this.isSettingsMenuOpen = isOpen; } + public void setBuyCardPopupOpen(boolean isOpen) { + this.isBuyCardPopupOpen = isOpen; + } + @Override public void simpleUpdate(float tpf) { if (testWorld != null) { @@ -209,6 +241,10 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga testWorld.initializeScene(); // Initialisiere die Szene } + public void startBuyCard() { + + } + public void returnToMenu() { guiNode.detachAllChildren(); // Entferne die GUI StartMenu.createStartMenu(this); // Zeige das Startmenü erneut diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/CreateGameMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/CreateGameMenu.java index 90e5bf0..3efc117 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/CreateGameMenu.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/CreateGameMenu.java @@ -110,6 +110,16 @@ public class CreateGameMenu { } }, "OpenTestWorld"); + app.getInputManager().addMapping("OpenBuyCard", new com.jme3.input.controls.KeyTrigger(com.jme3.input.KeyInput.KEY_B)); + app.getInputManager().addListener(new com.jme3.input.controls.ActionListener() { + @Override + public void onAction(String name, boolean isPressed, float tpf) { + if (name.equals("OpenBuyCard") && isPressed) { + app.startBuyCard(); // Öffnet die TestWorld + } + } + }, "OpenBuyCard"); + app.getGuiNode().attachChild(menuContainer); } diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyCard.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyCard.java new file mode 100644 index 0000000..8453e87 --- /dev/null +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyCard.java @@ -0,0 +1,134 @@ +package pp.monopoly.client.gui.popups; + +import com.jme3.material.Material; +import com.jme3.material.RenderState.BlendMode; +import com.jme3.math.ColorRGBA; +import com.jme3.math.Vector3f; +import com.jme3.scene.Geometry; +import com.jme3.scene.shape.Quad; +import com.simsilica.lemur.*; +import com.simsilica.lemur.component.QuadBackgroundComponent; +import com.simsilica.lemur.style.ElementId; +import pp.dialog.Dialog; +import pp.monopoly.client.MonopolyApp; + +/** + * SettingsMenu ist ein Overlay-Menü, das durch ESC aufgerufen werden kann. + */ +public class BuyCard extends Dialog { + private final MonopolyApp app; + private final Geometry overlayBackground; + private final Container settingsContainer; + private final Container backgroundContainer; + + public BuyCard(MonopolyApp app) { + super(app.getDialogManager()); + this.app = app; + + // Halbtransparentes Overlay hinzufügen + overlayBackground = createOverlayBackground(); + app.getGuiNode().attachChild(overlayBackground); + + // Create the background container + backgroundContainer = new Container(); + backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background + app.getGuiNode().attachChild(backgroundContainer); + + // Hauptcontainer für das Menü + settingsContainer = new Container(); + settingsContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.1f, 0.1f, 0.1f, 0.9f))); + + + + // Titel + Label settingsTitle = settingsContainer.addChild(new Label("Gebäude XX", new ElementId("settings-title"))); //TODO Dynamische Gebäudezahl einfügen + settingsTitle.setFontSize(48); + + // Effekt-Sound: Slider und Checkbox + Container propertyValuesContainer = settingsContainer.addChild(new Container()); + propertyValuesContainer.addChild(new Label("„Preis: XXXX", new ElementId("label-Text")));//TODO Variable hier einsetzen + propertyValuesContainer.addChild(new Label("„Miete: XXXX", new ElementId("label-Text")));//TODO Variable hier einsetzen + propertyValuesContainer.addChild(new Label("„Hypothek: XXXX", new ElementId("label-Text")));//TODO Variable hier einsetzen + propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); + + /*Selector dropdown = new Selector<>(); + backgroundMusicContainer.addChild(dropdown); + + Vector3f dimens = settingsContainer.getPreferredSize(); + Vector3f dimens2 = dropdown.getPopupContainer().getPreferredSize(); + dimens2.setX(dimens.getX()); + dropdown.getPopupContainer().setPreferredSize(dimens2);*/ + // Create the dropdown menu + Selector dropdown = new Selector<>(); + + // Generate and add numbered examples to the dropdown + for (int i = 1; i <= 10; i++) { // Generate 10 examples + dropdown.getModel().add("Example " + i); + } + + + + // Adjust the dropdown's popup container size if necessary + Vector3f dimens = settingsContainer.getPreferredSize(); + Vector3f dimens2 = dropdown.getPopupContainer().getPreferredSize(); + dimens2.setX(dimens.getX()); + dropdown.getPopupContainer().setPreferredSize(dimens2); + // Beenden-Button + Button quitButton = settingsContainer.addChild(new Button("Beenden", new ElementId("button"))); + quitButton.setFontSize(32); + // Kaufen-Button + Button buyButton = settingsContainer.addChild(new Button("Kaufen", new ElementId("button"))); + buyButton.setFontSize(32); + + float padding = 10; // Padding around the settingsContainer for the background + backgroundContainer.setPreferredSize(settingsContainer.getPreferredSize().addLocal(padding, padding, 0)); + + + // Zentriere das Menü + settingsContainer.setLocalTranslation( + (app.getCamera().getWidth() - settingsContainer.getPreferredSize().x) / 2, + (app.getCamera().getHeight() + settingsContainer.getPreferredSize().y) / 2, + 4 + ); + + backgroundContainer.setLocalTranslation( + (app.getCamera().getWidth() - settingsContainer.getPreferredSize().x - padding) / 2, + (app.getCamera().getHeight() + settingsContainer.getPreferredSize().y+ padding) / 2, + 3 + ); + + app.getGuiNode().attachChild(settingsContainer); + } + + /** + * Erstellt einen halbtransparenten Hintergrund für das Menü. + * + * @return Geometrie des Overlays + */ + private Geometry createOverlayBackground() { + Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight()); + Geometry overlay = new Geometry("Overlay", quad); + Material material = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); + material.setColor("Color", new ColorRGBA(0, 0, 0, 0.5f)); // Halbtransparent + material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); + overlay.setMaterial(material); + overlay.setLocalTranslation(0, 0, 0); + return overlay; + } + + /** + * Schließt das Menü und entfernt die GUI-Elemente. + */ + @Override + public void close() { + System.out.println("Schließe SettingsMenu..."); // Debugging-Ausgabe + app.getGuiNode().detachChild(settingsContainer); // Entferne das Menü + app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand + app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay + app.setSettingsMenuOpen(false); // Menü als geschlossen markieren + app.unblockInputs(); // Eingaben wieder aktivieren + System.out.println("SettingsMenu geschlossen."); // Debugging-Ausgabe + } + + +}