mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-01-18 22:56:15 +01:00
rent popup fixed
This commit is contained in:
parent
b87b3f054b
commit
89d5185c91
@ -16,7 +16,7 @@ import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.notification.Sound;
|
||||
|
||||
/**
|
||||
* Rent is a popup that is triggered when a player enters a field that does not belong himself and is owned by another player
|
||||
* Rent popup is triggered when a player enters a field owned by another player and needs to pay rent.
|
||||
*/
|
||||
public class Rent extends Dialog {
|
||||
private final MonopolyApp app;
|
||||
@ -28,93 +28,122 @@ public class Rent extends Dialog {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
|
||||
// Halbtransparentes Overlay hinzufügen
|
||||
// Create the overlay
|
||||
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
|
||||
// Create and position the background container
|
||||
backgroundContainer = createBackgroundContainer();
|
||||
app.getGuiNode().attachChild(backgroundContainer);
|
||||
|
||||
|
||||
|
||||
// Hauptcontainer für die Warnung
|
||||
rentContainer = new Container();
|
||||
rentContainer.setBackground(new QuadBackgroundComponent(ColorRGBA.Gray));
|
||||
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 !", 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 must Spieler "+ playerName + " "+ amount+" 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.addClickCommands(s -> ifTopDialog(() -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
close();
|
||||
}));
|
||||
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,
|
||||
10
|
||||
);
|
||||
|
||||
// Zentriere das Popup
|
||||
backgroundContainer.setLocalTranslation(
|
||||
(app.getCamera().getWidth() - rentContainer.getPreferredSize().x - padding) / 2,
|
||||
(app.getCamera().getHeight() + rentContainer.getPreferredSize().y+ padding) / 2,
|
||||
10
|
||||
);
|
||||
|
||||
// Create and position the rent container
|
||||
rentContainer = createRentContainer(playerName, amount);
|
||||
app.getGuiNode().attachChild(rentContainer);
|
||||
|
||||
centerContainers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt einen halbtransparenten Hintergrund für das Menü.
|
||||
* Creates a semi-transparent overlay background.
|
||||
*
|
||||
* @return Geometrie des Overlays
|
||||
* @return the overlay geometry
|
||||
*/
|
||||
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.setColor("Color", new ColorRGBA(0, 0, 0, 0.5f)); // Semi-transparent black
|
||||
material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
|
||||
overlay.setMaterial(material);
|
||||
overlay.setLocalTranslation(0, 0, 10);
|
||||
overlay.setLocalTranslation(0, 0, 0);
|
||||
return overlay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schließt das Menü und entfernt die GUI-Elemente.
|
||||
* Creates the background container with styling.
|
||||
*
|
||||
* @return the styled background container
|
||||
*/
|
||||
private Container createBackgroundContainer() {
|
||||
Container container = new Container();
|
||||
container.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Light gray background
|
||||
return container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the main rent container with title, text, and button.
|
||||
*
|
||||
* @param playerName the name of the player to whom the rent is owed
|
||||
* @param amount the rent amount
|
||||
* @return the rent container
|
||||
*/
|
||||
private Container createRentContainer(String playerName, int amount) {
|
||||
Container container = new Container();
|
||||
container.setBackground(new QuadBackgroundComponent(ColorRGBA.Gray));
|
||||
container.setPreferredSize(new Vector3f(550, 250, 10));
|
||||
|
||||
// Title
|
||||
Label title = container.addChild(new Label("Miete!", new ElementId("label-Bold")));
|
||||
title.setFontSize(48);
|
||||
title.setColor(ColorRGBA.Black);
|
||||
|
||||
// Rent message
|
||||
Container textContainer = container.addChild(new Container());
|
||||
textContainer.addChild(new Label("Du musst Spieler " + playerName + " " + amount + " EUR Miete zahlen",
|
||||
new ElementId("label-Text")));
|
||||
textContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||
textContainer.setPreferredSize(container.getPreferredSize().addLocal(-250, -200, 0));
|
||||
|
||||
// Payment button
|
||||
Button payButton = container.addChild(new Button("Überweisen", new ElementId("button")));
|
||||
payButton.setFontSize(32);
|
||||
payButton.addClickCommands(s -> ifTopDialog( () -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
close();
|
||||
|
||||
}));
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Centers the rent and background containers on the screen.
|
||||
*/
|
||||
private void centerContainers() {
|
||||
float padding = 10;
|
||||
|
||||
// Center rent container
|
||||
rentContainer.setLocalTranslation(
|
||||
(app.getCamera().getWidth() - rentContainer.getPreferredSize().x) / 2,
|
||||
(app.getCamera().getHeight() + rentContainer.getPreferredSize().y) / 2,
|
||||
8
|
||||
);
|
||||
|
||||
// Center background container with padding
|
||||
backgroundContainer.setPreferredSize(rentContainer.getPreferredSize().addLocal(padding, padding, 0));
|
||||
backgroundContainer.setLocalTranslation(
|
||||
(app.getCamera().getWidth() - backgroundContainer.getPreferredSize().x) / 2,
|
||||
(app.getCamera().getHeight() + backgroundContainer.getPreferredSize().y) / 2,
|
||||
7
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the popup and removes GUI elements.
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
app.getGuiNode().detachChild(rentContainer);
|
||||
app.getGuiNode().detachChild(backgroundContainer);
|
||||
app.getGuiNode().detachChild(overlayBackground);
|
||||
super.close();
|
||||
app.getGuiNode().detachChild(rentContainer); // Entferne das Menü
|
||||
app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand
|
||||
app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the escape action to close the dialog.
|
||||
*/
|
||||
@Override
|
||||
public void escape() {
|
||||
close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user