From 6cdad71693d03c384f1a484c0621273d3b3e5244 Mon Sep 17 00:00:00 2001 From: Simon Wilkening Date: Fri, 29 Nov 2024 08:57:11 +0100 Subject: [PATCH] Gulag und Rent erstellt --- .../java/pp/monopoly/client/MonopolyApp.java | 2 +- .../pp/monopoly/client/gui/popups/Gulag.java | 119 +++++++++++++++++ .../pp/monopoly/client/gui/popups/Rent.java | 124 ++++++++++++++++++ 3 files changed, 244 insertions(+), 1 deletion(-) create mode 100644 Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/Gulag.java create mode 100644 Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/Rent.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 0441d01..b713c1d 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 @@ -280,7 +280,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga //logik zum wechselnden erscheinen und verschwinden beim drücken von B //TODO süäter entfernen private void handleB(boolean isPressed) { if (isPressed) { - Dialog tmp = new TimeOut(this); + Dialog tmp = new Rent(this); tmp.open(); } } diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/Gulag.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/Gulag.java new file mode 100644 index 0000000..8d28032 --- /dev/null +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/Gulag.java @@ -0,0 +1,119 @@ +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.Button; +import com.simsilica.lemur.Container; +import com.simsilica.lemur.Label; +import com.simsilica.lemur.component.QuadBackgroundComponent; +import com.simsilica.lemur.style.ElementId; +import pp.dialog.Dialog; +import pp.monopoly.client.MonopolyApp; + +/** + * Gulag is a warning popup that is triggered when a certain player enters the "Wache" field + */ +public class Gulag extends Dialog { + private final MonopolyApp app; + private final Geometry overlayBackground; + private final Container gulagContainer; + private final Container backgroundContainer; + + + + public Gulag(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 die Warnung + gulagContainer = new Container(); + gulagContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); + gulagContainer.setPreferredSize(new Vector3f(550,250,10)); + + float padding = 10; // Passt den backgroundContainer an die Größe des bankruptContainers an + backgroundContainer.setPreferredSize(gulagContainer.getPreferredSize().addLocal(padding, padding, 0)); + + // Titel + Label gateFieldTitle = gulagContainer.addChild(new Label("Du kommst ins Gulag!", new ElementId("warning-title"))); + gateFieldTitle.setFontSize(48); + gateFieldTitle.setColor(ColorRGBA.Black); + + // Text, der auf der Karte steht + /* Container textContainer = gulagContainer.addChild(new Container()); + textContainer.addChild(new Label("Du hast die Verbindung verloren und kannst nichts dagegen machen. Akzeptiere einfach, dass du verloren hast!", new ElementId("label-Text"))); + textContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); + textContainer.setPreferredSize(gulagContainer.getPreferredSize().addLocal(-250,-200,0)); + */ + + // Beenden-Button + Button quitButton = gulagContainer.addChild(new Button("Jawohl Gulag", new ElementId("button"))); + quitButton.setFontSize(32); + quitButton.addClickCommands(source -> close()); + + + // Zentriere das Popup + gulagContainer.setLocalTranslation( + (app.getCamera().getWidth() - gulagContainer.getPreferredSize().x) / 2, + (app.getCamera().getHeight() + gulagContainer.getPreferredSize().y) / 2, + 8 + ); + + // Zentriere das Popup + backgroundContainer.setLocalTranslation( + (app.getCamera().getWidth() - gulagContainer.getPreferredSize().x - padding) / 2, + (app.getCamera().getHeight() + gulagContainer.getPreferredSize().y+ padding) / 2, + 7 + ); + + app.getGuiNode().attachChild(gulagContainer); + } + + /** + * 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() { + app.getGuiNode().detachChild(gulagContainer); // Entferne das Menü + app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand + app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay + super.close(); + } + + @Override + public void escape() { + close(); + } + +} \ No newline at end of file diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/Rent.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/Rent.java new file mode 100644 index 0000000..f45d853 --- /dev/null +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/Rent.java @@ -0,0 +1,124 @@ +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.Button; +import com.simsilica.lemur.Container; +import com.simsilica.lemur.Label; +import com.simsilica.lemur.component.QuadBackgroundComponent; +import com.simsilica.lemur.style.ElementId; +import pp.dialog.Dialog; +import pp.monopoly.client.MonopolyApp; +import pp.monopoly.model.fields.BuildingProperty; + +/** + * Rent is a popup that is triggered when a player enters a field that does not belong himself and is owned by another player + */ +public class Rent extends Dialog { + private final MonopolyApp app; + private final Geometry overlayBackground; + private final Container rentContainer; + private final Container backgroundContainer; + + + private int index = 37; // TODO fixed for testing + + + + public Rent(MonopolyApp app) { + super(app.getDialogManager()); + this.app = app; + + BuildingProperty field = (BuildingProperty) app.getGameLogic().getBoardManager().getFieldAtIndex(index); + + // 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 die Warnung + rentContainer = new Container(); + rentContainer.setBackground(new QuadBackgroundComponent(field.getColor().getColor())); + rentContainer.setPreferredSize(new Vector3f(550,250,10)); + + float padding = 10; // Passt den backgroundContainer an die Größe des bankruptContainers an + backgroundContainer.setPreferredSize(rentContainer.getPreferredSize().addLocal(padding, padding, 0)); + + // Titel + Label gateFieldTitle = rentContainer.addChild(new Label( "Miete fürs "+field.getName()+" !", new ElementId("label-Bold"))); + gateFieldTitle.setFontSize(48); + gateFieldTitle.setColor(ColorRGBA.Black); + + // Text, der auf der Karte steht + Container textContainer = rentContainer.addChild(new Container()); + textContainer.addChild(new Label("Du bist auf das " + field.getName()+ " gekommen!", new ElementId("label-Text"))); + textContainer.addChild(new Label("Du must Spieler XXX XXX EUR Miete zahlen", new ElementId("label-Text"))); + textContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); + textContainer.setPreferredSize(rentContainer.getPreferredSize().addLocal(-250,-200,0)); + + // Beenden-Button + Button quitButton = rentContainer.addChild(new Button("Überweisen", new ElementId("button"))); + quitButton.setFontSize(32); + quitButton.addClickCommands(source -> close()); + + + // Zentriere das Popup + rentContainer.setLocalTranslation( + (app.getCamera().getWidth() - rentContainer.getPreferredSize().x) / 2, + (app.getCamera().getHeight() + rentContainer.getPreferredSize().y) / 2, + 8 + ); + + // Zentriere das Popup + backgroundContainer.setLocalTranslation( + (app.getCamera().getWidth() - rentContainer.getPreferredSize().x - padding) / 2, + (app.getCamera().getHeight() + rentContainer.getPreferredSize().y+ padding) / 2, + 7 + ); + + app.getGuiNode().attachChild(rentContainer); + } + + /** + * 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() { + app.getGuiNode().detachChild(rentContainer); // Entferne das Menü + app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand + app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay + super.close(); + } + + @Override + public void escape() { + close(); + } + +} \ No newline at end of file