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;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
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.component.QuadBackgroundComponent;
import com.simsilica.lemur.component.SpringGridLayout;
@ -10,15 +14,10 @@ import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp;
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 {
private final MonopolyApp app;
private final Container mainContainer;
// Buttons
private final Container mainContainer;
private final Button backButton = new Button("Zurück");
private final Button buildButton = new Button("Bauen");
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 overviewButton = new Button("Übersicht");
/**
* Constructs the BuildingAdminMenu dialog.
*
* @param app The Monopoly application instance.
*/
public BuildingAdminMenu(MonopolyApp app) {
super(app.getDialogManager());
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.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
// Add the header
addHeader("Grundstücke Verwalten");
// Add content (Overview, Build, and Mortgage columns)
addContent();
// Attach main container to the GUI node
// Add header
mainContainer.addChild(createHeaderContainer());
// Add content
mainContainer.addChild(createContent());
// Attach main container to GUI node
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));
headerContainer.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 100, 0));
Label headerLabel = headerContainer.addChild(new Label(title, new ElementId("header")));
headerLabel.setFontSize(40);
headerContainer.setPreferredSize(new Vector3f(800, 100, 0));
Label headerLabel = headerContainer.addChild(new Label("Grundstücke Verwalten", new ElementId("header")));
headerLabel.setFontSize(45);
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));
contentContainer.setPreferredSize(new Vector3f(app.getCamera().getWidth(), app.getCamera().getHeight() - 100, 0));
contentContainer.setPreferredSize(new Vector3f(800, 500, 0));
// Overview Column
Container overviewColumn = new Container(new SpringGridLayout(Axis.Y, Axis.X));
overviewColumn.addChild(new Label("Übersicht:")).setFontSize(24);
overviewColumn.addChild(createButtonContainer(overviewButton, "Übersicht", () -> {
overviewColumn.addChild(new Label("Übersicht:")).setFontSize(30);
overviewButton.setPreferredSize(new Vector3f(200, 50, 0));
overviewButton.addClickCommands(s -> ifTopDialog(() -> {
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);
handleBack();
this.close();
}));
overviewColumn.addChild(backButton);
contentContainer.addChild(overviewColumn);
// Build Column
Container buildColumn = new Container(new SpringGridLayout(Axis.Y, Axis.X));
buildColumn.addChild(new Label("Bauen:")).setFontSize(24);
buildColumn.addChild(createButtonContainer(buildButton, "Bauen", () -> {
buildColumn.addChild(new Label("Bauen:")).setFontSize(30);
buildButton.setPreferredSize(new Vector3f(200, 50, 0));
buildButton.addClickCommands(s -> ifTopDialog(() -> {
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);
handleDemolish();
}));
buildColumn.addChild(demolishButton);
contentContainer.addChild(buildColumn);
// Mortgage Column
Container mortgageColumn = new Container(new SpringGridLayout(Axis.Y, Axis.X));
mortgageColumn.addChild(new Label("Hypotheken:")).setFontSize(24);
mortgageColumn.addChild(createButtonContainer(takeMortgageButton, "Hypothek aufnehmen", () -> {
app.getGameLogic().playSound(Sound.BUTTON);
handleTakeMortgage();
}));
mortgageColumn.addChild(createButtonContainer(payMortgageButton, "Hypothek bezahlen", () -> {
app.getGameLogic().playSound(Sound.BUTTON);
handlePayMortgage();
}));
mortgageColumn.addChild(new Label("Hypotheken:")).setFontSize(30);
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);
mainContainer.addChild(contentContainer);
return contentContainer;
}
/**
* Creates a button within a dedicated container.
*
* @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.
* Adds a background image to the dialog.
*/
private Container createButtonContainer(Button button, String label, Runnable action) {
Container buttonContainer = new Container();
button.setText(label);
button.setPreferredSize(new Vector3f(200, 60, 0));
button.setFontSize(30); // Larger font size for better visibility
button.addClickCommands(source -> ifTopDialog(action));
buttonContainer.setPreferredSize(new Vector3f(200, 60, 0)); // Ensuring container matches button size
buttonContainer.addChild(button);
return buttonContainer;
}
/**
* 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
private void addBackgroundImage() {
Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/unibw-Bib2.png");
Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight());
Geometry background = new Geometry("Background", quad);
Material backgroundMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
backgroundMaterial.setTexture("ColorMap", backgroundImage);
background.setMaterial(backgroundMaterial);
background.setLocalTranslation(0, 0, 6); // Position behind other GUI elements
app.getGuiNode().attachChild(background);
}
/**
* Handles the "Zurück" action.
*/
private void handleBack() {
app.getGameLogic().playSound(Sound.BUTTON);
close();
}

View File

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