completed BuildingAdminMenu

This commit is contained in:
Yvonne Schmidt 2024-11-27 00:17:04 +01:00
parent 8d087a8e84
commit cb9888af7a
2 changed files with 85 additions and 107 deletions

View File

@ -1,7 +1,11 @@
package pp.monopoly.client.gui; package pp.monopoly.client.gui;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Quad;
import com.jme3.texture.Texture;
import com.simsilica.lemur.*; import com.simsilica.lemur.*;
import com.simsilica.lemur.component.QuadBackgroundComponent; import com.simsilica.lemur.component.QuadBackgroundComponent;
import com.simsilica.lemur.component.SpringGridLayout; import com.simsilica.lemur.component.SpringGridLayout;
@ -10,15 +14,10 @@ import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp; import pp.monopoly.client.MonopolyApp;
import pp.monopoly.notification.Sound; import pp.monopoly.notification.Sound;
/**
* Represents a dialog for managing properties in the Monopoly game.
* Allows users to view properties, build, demolish, and manage mortgages.
*/
public class BuildingAdminMenu extends Dialog { public class BuildingAdminMenu extends Dialog {
private final MonopolyApp app; private final MonopolyApp app;
private final Container mainContainer;
// Buttons private final Container mainContainer;
private final Button backButton = new Button("Zurück"); private final Button backButton = new Button("Zurück");
private final Button buildButton = new Button("Bauen"); private final Button buildButton = new Button("Bauen");
private final Button demolishButton = new Button("Abriss"); private final Button demolishButton = new Button("Abriss");
@ -26,156 +25,135 @@ public class BuildingAdminMenu extends Dialog {
private final Button payMortgageButton = new Button("Hypothek bezahlen"); private final Button payMortgageButton = new Button("Hypothek bezahlen");
private final Button overviewButton = new Button("Übersicht"); private final Button overviewButton = new Button("Übersicht");
/**
* Constructs the BuildingAdminMenu dialog.
*
* @param app The Monopoly application instance.
*/
public BuildingAdminMenu(MonopolyApp app) { public BuildingAdminMenu(MonopolyApp app) {
super(app.getDialogManager()); super(app.getDialogManager());
this.app = app; this.app = app;
// Configure the main container // Background Image
addBackgroundImage();
// Main container for the UI components
mainContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X)); mainContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X));
mainContainer.setPreferredSize(new Vector3f(app.getCamera().getWidth(), app.getCamera().getHeight(), 0)); mainContainer.setPreferredSize(new Vector3f(800, 600, 0));
mainContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(1, 1, 1, 0.7f))); // Translucent white background mainContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(1, 1, 1, 0.7f))); // Translucent white background
// Add the header // Add header
addHeader("Grundstücke Verwalten"); mainContainer.addChild(createHeaderContainer());
// Add content
// Add content (Overview, Build, and Mortgage columns) mainContainer.addChild(createContent());
addContent(); // Attach main container to GUI node
// Attach main container to the GUI node
app.getGuiNode().attachChild(mainContainer); app.getGuiNode().attachChild(mainContainer);
mainContainer.setLocalTranslation(0, app.getCamera().getHeight(), 7); // Full screen mainContainer.setLocalTranslation(
(app.getCamera().getWidth() - mainContainer.getPreferredSize().x) / 2,
(app.getCamera().getHeight() + mainContainer.getPreferredSize().y) / 2,
7
);
} }
/** /**
* Adds the header section to the main container. * Creates the header container.
* *
* @param title The title text for the header. * @return The header container.
*/ */
private void addHeader(String title) { private Container createHeaderContainer() {
Container headerContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y)); Container headerContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
headerContainer.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 100, 0)); headerContainer.setPreferredSize(new Vector3f(800, 100, 0));
Label headerLabel = headerContainer.addChild(new Label(title, new ElementId("header"))); Label headerLabel = headerContainer.addChild(new Label("Grundstücke Verwalten", new ElementId("header")));
headerLabel.setFontSize(40); headerLabel.setFontSize(45);
headerLabel.setInsets(new Insets3f(10, 10, 10, 10)); headerLabel.setInsets(new Insets3f(10, 10, 10, 10));
mainContainer.addChild(headerContainer); return headerContainer;
} }
/** /**
* Adds the main content, organized into columns for Overview, Build, and Mortgage management. * Creates the main content container with columns for Overview, Build, and Mortgage.
*
* @return The content container.
*/ */
private void addContent() { private Container createContent() {
Container contentContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y)); Container contentContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
contentContainer.setPreferredSize(new Vector3f(app.getCamera().getWidth(), app.getCamera().getHeight() - 100, 0)); contentContainer.setPreferredSize(new Vector3f(800, 500, 0));
// Overview Column // Overview Column
Container overviewColumn = new Container(new SpringGridLayout(Axis.Y, Axis.X)); Container overviewColumn = new Container(new SpringGridLayout(Axis.Y, Axis.X));
overviewColumn.addChild(new Label("Übersicht:")).setFontSize(24); overviewColumn.addChild(new Label("Übersicht:")).setFontSize(30);
overviewColumn.addChild(createButtonContainer(overviewButton, "Übersicht", () -> {
overviewButton.setPreferredSize(new Vector3f(200, 50, 0));
overviewButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON); app.getGameLogic().playSound(Sound.BUTTON);
handleOverview();
})); }));
overviewColumn.addChild(createButtonContainer(backButton, "Zurück", () -> { overviewColumn.addChild(overviewButton);
// Back Button
backButton.setPreferredSize(new Vector3f(200, 50, 0));
backButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON); app.getGameLogic().playSound(Sound.BUTTON);
handleBack(); this.close();
})); }));
overviewColumn.addChild(backButton);
contentContainer.addChild(overviewColumn);
// Build Column // Build Column
Container buildColumn = new Container(new SpringGridLayout(Axis.Y, Axis.X)); Container buildColumn = new Container(new SpringGridLayout(Axis.Y, Axis.X));
buildColumn.addChild(new Label("Bauen:")).setFontSize(24); buildColumn.addChild(new Label("Bauen:")).setFontSize(30);
buildColumn.addChild(createButtonContainer(buildButton, "Bauen", () -> {
buildButton.setPreferredSize(new Vector3f(200, 50, 0));
buildButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON); app.getGameLogic().playSound(Sound.BUTTON);
handleBuild();
})); }));
buildColumn.addChild(createButtonContainer(demolishButton, "Abriss", () -> { buildColumn.addChild(buildButton);
demolishButton.setPreferredSize(new Vector3f(200, 50, 0));
demolishButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON); app.getGameLogic().playSound(Sound.BUTTON);
handleDemolish();
})); }));
buildColumn.addChild(demolishButton);
contentContainer.addChild(buildColumn);
// Mortgage Column // Mortgage Column
Container mortgageColumn = new Container(new SpringGridLayout(Axis.Y, Axis.X)); Container mortgageColumn = new Container(new SpringGridLayout(Axis.Y, Axis.X));
mortgageColumn.addChild(new Label("Hypotheken:")).setFontSize(24); mortgageColumn.addChild(new Label("Hypotheken:")).setFontSize(30);
mortgageColumn.addChild(createButtonContainer(takeMortgageButton, "Hypothek aufnehmen", () -> {
app.getGameLogic().playSound(Sound.BUTTON);
handleTakeMortgage();
}));
mortgageColumn.addChild(createButtonContainer(payMortgageButton, "Hypothek bezahlen", () -> {
app.getGameLogic().playSound(Sound.BUTTON);
handlePayMortgage();
}));
takeMortgageButton.setPreferredSize(new Vector3f(200, 50, 0));
takeMortgageButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON);
}));
mortgageColumn.addChild(takeMortgageButton);
payMortgageButton.setPreferredSize(new Vector3f(200, 50, 0));
payMortgageButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON);
}));
mortgageColumn.addChild(payMortgageButton);
// Add all columns to the content container
contentContainer.addChild(overviewColumn);
contentContainer.addChild(buildColumn);
contentContainer.addChild(mortgageColumn); contentContainer.addChild(mortgageColumn);
return contentContainer;
mainContainer.addChild(contentContainer);
} }
/** /**
* Creates a button within a dedicated container. * Adds a background image to the dialog.
*
* @param button The button to configure.
* @param label The button label.
* @param action The action to perform when the button is clicked.
* @return The container containing the button.
*/ */
private Container createButtonContainer(Button button, String label, Runnable action) { private void addBackgroundImage() {
Container buttonContainer = new Container(); Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/unibw-Bib2.png");
button.setText(label); Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight());
button.setPreferredSize(new Vector3f(200, 60, 0)); Geometry background = new Geometry("Background", quad);
button.setFontSize(30); // Larger font size for better visibility Material backgroundMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
button.addClickCommands(source -> ifTopDialog(action)); backgroundMaterial.setTexture("ColorMap", backgroundImage);
buttonContainer.setPreferredSize(new Vector3f(200, 60, 0)); // Ensuring container matches button size background.setMaterial(backgroundMaterial);
buttonContainer.addChild(button); background.setLocalTranslation(0, 0, 6); // Position behind other GUI elements
return buttonContainer; app.getGuiNode().attachChild(background);
}
/**
* Handles the "Bauen" action.
*/
private void handleBuild() {
// Implement build logic
}
/**
* Handles the "Abriss" action.
*/
private void handleDemolish() {
// Implement demolish logic
}
/**
* Handles the "Hypothek aufnehmen" action.
*/
private void handleTakeMortgage() {
// Implement take mortgage logic
}
/**
* Handles the "Hypothek bezahlen" action.
*/
private void handlePayMortgage() {
// Implement pay mortgage logic
}
/**
* Handles the "Übersicht" action.
*/
private void handleOverview() {
// Implement overview logic
} }
/** /**
* Handles the "Zurück" action. * Handles the "Zurück" action.
*/ */
private void handleBack() { private void handleBack() {
app.getGameLogic().playSound(Sound.BUTTON);
close(); close();
} }
@ -188,4 +166,4 @@ public class BuildingAdminMenu extends Dialog {
public void update(float delta) { public void update(float delta) {
// Periodic updates if necessary // Periodic updates if necessary
} }
} }

View File

@ -66,7 +66,7 @@ public class CreateGameMenu extends Dialog {
final MonopolyApp app = network.getApp(); final MonopolyApp app = network.getApp();
int screenWidth = app.getContext().getSettings().getWidth(); int screenWidth = app.getContext().getSettings().getWidth();
int screenHeight = app.getContext().getSettings().getHeight(); int screenHeight = app.getContext().getSettings().getHeight();
// Set up the background image // Set up the background image