fixed buyCard color and button function

This commit is contained in:
Johannes Schmelz 2024-11-25 21:29:00 +01:00
parent 547a4c2353
commit 4095d9e79d

View File

@ -15,13 +15,13 @@ import pp.monopoly.client.MonopolyApp;
import pp.monopoly.client.gui.SettingsMenu; import pp.monopoly.client.gui.SettingsMenu;
import pp.monopoly.model.fields.BoardManager; import pp.monopoly.model.fields.BoardManager;
import pp.monopoly.model.fields.BuildingProperty; import pp.monopoly.model.fields.BuildingProperty;
import pp.monopoly.notification.Sound;
/** /**
* SettingsMenu ist ein Overlay-Menü, das durch ESC aufgerufen werden kann. * SettingsMenu ist ein Overlay-Menü, das durch ESC aufgerufen werden kann.
*/ */
public class BuyCard extends Dialog { public class BuyCard extends Dialog {
private final MonopolyApp app; private final MonopolyApp app;
private final Geometry overlayBackground;
private final Container buyCardContainer; private final Container buyCardContainer;
private final Container backgroundContainer; private final Container backgroundContainer;
@ -34,22 +34,18 @@ public class BuyCard extends Dialog {
//Generate the corresponfing field //Generate the corresponfing field
BuildingProperty field = (BuildingProperty) new BoardManager().getFieldAtIndex(index); BuildingProperty field = (BuildingProperty) new BoardManager().getFieldAtIndex(index);
// Halbtransparentes Overlay hinzufügen
overlayBackground = createOverlayBackground();
app.getGuiNode().attachChild(overlayBackground);
// Create the background container // Create the background container
backgroundContainer = new Container(); backgroundContainer = new Container();
backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background
app.getGuiNode().attachChild(backgroundContainer); attachChild(backgroundContainer);
// Hauptcontainer für die Gebäudekarte // Hauptcontainer für die Gebäudekarte
buyCardContainer = new Container(); buyCardContainer = new Container();
buyCardContainer.setBackground(new QuadBackgroundComponent(field.getColor().getColor()));
Label settingsTitle = buyCardContainer.addChild(new Label( field.getName(), new ElementId("settings-title"))); Label title = buyCardContainer.addChild(new Label( field.getName(), new ElementId("label-Bold")));
settingsTitle.setFontSize(48); title.setBackground(new QuadBackgroundComponent(field.getColor().getColor()));
title.setFontSize(48);
// Text, der auf der Karte steht // Text, der auf der Karte steht
// Die Preise werden dynamisch dem BoardManager entnommen // Die Preise werden dynamisch dem BoardManager entnommen
@ -70,9 +66,17 @@ public class BuyCard extends Dialog {
// Beenden-Button // Beenden-Button
Button quitButton = buyCardContainer.addChild(new Button("Beenden", new ElementId("button"))); Button quitButton = buyCardContainer.addChild(new Button("Beenden", new ElementId("button")));
quitButton.setFontSize(32); quitButton.setFontSize(32);
quitButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON);
close();
}));
// Kaufen-Button // Kaufen-Button
Button buyButton = buyCardContainer.addChild(new Button("Kaufen", new ElementId("button"))); Button buyButton = buyCardContainer.addChild(new Button("Kaufen", new ElementId("button")));
buyButton.setFontSize(32); buyButton.setFontSize(32);
buyButton.addClickCommands(s -> ifTopDialog( () -> {
app.getGameLogic().playSound(Sound.BUTTON);
//TODO send buy property request
}));
float padding = 10; // Padding around the settingsContainer for the background float padding = 10; // Padding around the settingsContainer for the background
backgroundContainer.setPreferredSize(buyCardContainer.getPreferredSize().addLocal(padding, padding, 0)); backgroundContainer.setPreferredSize(buyCardContainer.getPreferredSize().addLocal(padding, padding, 0));
@ -94,22 +98,6 @@ public class BuyCard extends Dialog {
app.getGuiNode().attachChild(buyCardContainer); app.getGuiNode().attachChild(buyCardContainer);
} }
/**
* 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. * Schließt das Menü und entfernt die GUI-Elemente.
*/ */
@ -117,7 +105,6 @@ public class BuyCard extends Dialog {
public void close() { public void close() {
app.getGuiNode().detachChild(buyCardContainer); // Entferne das Menü app.getGuiNode().detachChild(buyCardContainer); // Entferne das Menü
app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand
app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay
super.close(); super.close();
} }