Compare commits

...

8 Commits

Author SHA1 Message Date
Yvonne Schmidt
1376da3ba6 added documentation 2024-12-08 19:00:08 +01:00
Yvonne Schmidt
fb280101a5 Merge remote-tracking branch 'origin/gui' into gui 2024-12-08 18:40:48 +01:00
Yvonne Schmidt
844495ebbb modified toolbar 2024-12-08 18:40:28 +01:00
Johannes Schmelz
e14f6bbef7 Merge branch 'gui' of https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02 into gui 2024-12-08 18:38:15 +01:00
Johannes Schmelz
4839ddd497 clean up and doc 2024-12-08 18:38:06 +01:00
Yvonne Schmidt
b901323e2f added color changes for buttons 2024-12-08 18:30:18 +01:00
Yvonne Schmidt
640665fd29 fixed layering issue 2024-12-08 18:29:14 +01:00
Johannes Schmelz
ba8791d9fe update Toolbar view 2024-12-08 18:08:16 +01:00
5 changed files with 214 additions and 21 deletions

View File

@ -13,6 +13,8 @@ import com.simsilica.lemur.HAlignment
import com.simsilica.lemur.Insets3f
import com.simsilica.lemur.component.QuadBackgroundComponent
import com.simsilica.lemur.component.TbtQuadBackgroundComponent
import pp.monopoly.client.MonopolyApp
import pp.monopoly.game.server.Player
def bgColor = color(1, 1, 1, 1)
def buttonEnabledColor = color(0, 0, 0, 1)
@ -343,22 +345,23 @@ selector("selector.item.label", "hover") {
background = new QuadBackgroundComponent(new ColorRGBA(0.2f, 0.6f, 1.0f, 0.9f)) // Highlighted background
}
def enabledCommandToolbar = new Command<Button>() {
MonopolyApp app // Pass the app instance to access player details
void execute(Button source) {
if (source.isEnabled()){
source.setColor(ColorRGBA.White)
def orangeBackground = new QuadBackgroundComponent(color(1, 1, 0, 1)); // Orange background
source.setBackground(orangeBackground);
} else{
source.setColor(ColorRGBA.White)
def grayBackground = new QuadBackgroundComponent(ColorRGBA.Gray); // Gray background
// Get the current player's color
Player currentPlayer = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId());
ColorRGBA playerColor = Player.getColor(currentPlayer.getId()).getColor();
if (source.isEnabled()) {
source.setColor(ColorRGBA.White);
def playerBackground = new QuadBackgroundComponent(playerColor); // Use player's color
source.setBackground(playerBackground);
} else {
source.setColor(ColorRGBA.White);
def grayBackground = new QuadBackgroundComponent(ColorRGBA.Gray); // Use gray when disabled
source.setBackground(grayBackground);
}
}
}

View File

@ -7,8 +7,15 @@ import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.scene.Spatial;
import com.jme3.texture.Texture;
import com.simsilica.lemur.*;
import com.simsilica.lemur.component.*;
import com.simsilica.lemur.Axis;
import com.simsilica.lemur.Button;
import com.simsilica.lemur.Container;
import com.simsilica.lemur.HAlignment;
import com.simsilica.lemur.Label;
import com.simsilica.lemur.VAlignment;
import com.simsilica.lemur.component.IconComponent;
import com.simsilica.lemur.component.QuadBackgroundComponent;
import com.simsilica.lemur.component.SpringGridLayout;
import com.simsilica.lemur.event.MouseEventControl;
import com.simsilica.lemur.event.MouseListener;
import com.simsilica.lemur.style.ElementId;
@ -19,7 +26,11 @@ import pp.monopoly.game.server.Player;
import pp.monopoly.game.server.PlayerHandler;
import pp.monopoly.message.client.EndTurn;
import pp.monopoly.message.client.RollDice;
import pp.monopoly.notification.*;
import pp.monopoly.notification.ButtonStatusEvent;
import pp.monopoly.notification.DiceRollEvent;
import pp.monopoly.notification.GameEventListener;
import pp.monopoly.notification.Sound;
import pp.monopoly.notification.UpdatePlayerView;
/**
* Represents the toolbar interface in the Monopoly application.
@ -27,20 +38,38 @@ import pp.monopoly.notification.*;
*/
public class Toolbar extends Dialog implements GameEventListener {
/** The Monopoly application instance*/
private final MonopolyApp app;
/** The container representing the toolbar interface */
private final Container toolbarContainer;
/** The container representing the player overview information */
private Container overviewContainer;
/** The container representing the player account information */
private Container accountContainer;
/** The player handler instance */
private PlayerHandler playerHandler;
/** The label representing the left dice */
private Label imageLabel;
/** The label representing the right dice */
private Label imageLabel2;
/** The flag to check if the dice can be rolled */
private boolean canRollDice = false;
/** The trade button */
private Button tradeButton;
/** The property menu button */
private Button propertyMenuButton;
/** The end turn button */
private Button endTurnButton;
/** The latest incoming Dice Roll Event */
private DiceRollEvent latestDiceRollEvent = null;
/** The flag to check if the bankrupt pop up is already shown */
private boolean bankruptPopUp = false;
/**
* Constructs a new {@code Toolbar} for the given {@code MonopolyApp}.
*
* @param app The {@code MonopolyApp} instance to create the toolbar for.
*/
public Toolbar(MonopolyApp app) {
super(app.getDialogManager());
this.app = app;
@ -52,6 +81,11 @@ public class Toolbar extends Dialog implements GameEventListener {
app.getGuiNode().attachChild(toolbarContainer);
}
/**
* Sets up the toolbar interface with the game controls, player information, and event handling.
*
* @return The container representing the toolbar interface.
*/
private Container setupToolbar() {
Container container = new Container(new SpringGridLayout(Axis.X, Axis.Y), "toolbar");
container.setLocalTranslation(0, 200, 0);
@ -70,13 +104,27 @@ public class Toolbar extends Dialog implements GameEventListener {
return container;
}
/**
* Sets up the borders for the toolbar interface.
*
* @param container The container representing the toolbar interface.
*/
private void setupBorders(Container container) {
addBorder(0, 205, app.getCamera().getWidth(), 5, ColorRGBA.DarkGray); // Top
addBorder(0, 5, app.getCamera().getWidth(), 10, ColorRGBA.DarkGray); // Bottom
addBorder(0, 200, 5, 210, ColorRGBA.DarkGray); // Left
addBorder(app.getCamera().getWidth() - 5, 200, 5, 210, ColorRGBA.DarkGray); // Right
addBorder(0, 200, 8, 210, ColorRGBA.DarkGray); // Left
addBorder(app.getCamera().getWidth() - 5, 200, 8, 210, ColorRGBA.DarkGray); // Right
}
/**
* Adds a border to the toolbar interface with the specified dimensions and color.
*
* @param x The x-coordinate of the border.
* @param y The y-coordinate of the border.
* @param width The width of the border.
* @param height The height of the border.
* @param color The color of the border.
*/
private void addBorder(float x, float y, float width, float height, ColorRGBA color) {
Container border = new Container();
border.setPreferredSize(new Vector3f(width, height, 0));
@ -85,6 +133,11 @@ public class Toolbar extends Dialog implements GameEventListener {
app.getGuiNode().attachChild(border);
}
/**
* Sets up the player information section of the toolbar interface.
*
* @param parentContainer The container representing the toolbar interface.
*/
private void setupPlayerInfoSection(Container parentContainer) {
Container playerInfoSection = parentContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
playerInfoSection.setPreferredSize(new Vector3f(600, 300, 0)); // Adjust size for both containers
@ -104,12 +157,22 @@ public class Toolbar extends Dialog implements GameEventListener {
refreshPlayerView();
}
/**
* Sets up the dice section of the toolbar interface.
*
* @param container The container representing the toolbar interface.
*/
private void setupDiceSection(Container container) {
Container diceContainer = container.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
diceContainer.addChild(createDiceDisplay());
diceContainer.setBackground(null);
}
/**
* Sets up the action menu of the toolbar interface.
*
* @param container The container representing the toolbar interface.
*/
private void setupActionMenu(Container container) {
Container menuContainer = container.addChild(new Container());
menuContainer.addChild(createTradeButton(getCurrentPlayerColor()));
@ -118,11 +181,21 @@ public class Toolbar extends Dialog implements GameEventListener {
menuContainer.setBackground(null);
}
/**
* Returns the color of the current player.
*
* @return The color of the current player.
*/
private ColorRGBA getCurrentPlayerColor() {
Player currentPlayer = playerHandler.getPlayerById(app.getId());
return Player.getColor(currentPlayer.getId()).getColor();
}
/**
* Creates the dice display section of the toolbar interface.
*
* @return The container representing the dice display section.
*/
private Container createDiceDisplay() {
Container horizontalContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
horizontalContainer.setPreferredSize(new Vector3f(200, 150, 0));
@ -163,6 +236,12 @@ public class Toolbar extends Dialog implements GameEventListener {
return horizontalContainer;
}
/**
* Creates a dice label with the specified icon path.
*
* @param iconPath The path to the icon image.
* @return The label representing the dice.
*/
private Label createDiceLabel(String iconPath) {
Label label = new Label("");
IconComponent icon = new IconComponent(iconPath);
@ -171,6 +250,12 @@ public class Toolbar extends Dialog implements GameEventListener {
return label;
}
/**
* Creates a dice container with the specified label.
*
* @param label The label representing the dice.
* @return The container representing the dice.
*/
private Container createDiceContainer(Label label) {
Container container = new Container();
container.setBackground(null);
@ -179,6 +264,9 @@ public class Toolbar extends Dialog implements GameEventListener {
return container;
}
/**
* Handles the dice roll event.
*/
private void handleDiceRoll() {
ifTopDialog(() -> {
if (!canRollDice) return;
@ -190,18 +278,45 @@ public class Toolbar extends Dialog implements GameEventListener {
});
}
/**
* Creates a trade button with the specified player color.
*
* @param playerColor The color of the player.
* @return The button representing the trade action.
*/
private Button createTradeButton(ColorRGBA playerColor) {
return createActionButton(playerColor, "icons/icon-handeln.png", 100, () -> new ChoosePartner(app).open());
}
/**
* Creates a property menu button with the specified player color.
*
* @param playerColor The color of the player.
* @return The button representing the property menu action.
*/
private Button createPropertyMenuButton(ColorRGBA playerColor) {
return createActionButton(playerColor, "icons/icon-gebaude.png", 75, () -> new BuildingAdminMenu(app).open());
}
/**
* Creates an end turn button with the specified player color.
*
* @param playerColor The color of the player.
* @return The button representing the end turn action.
*/
private Button createEndTurnButton(ColorRGBA playerColor) {
return createActionButton(playerColor, "icons/icon-zugbeenden.png", 75, () -> handleEndTurn());
}
/**
* Creates an action button with the specified color, icon path, icon size, and action.
*
* @param color The color of the button.
* @param iconPath The path to the icon image.
* @param iconSize The size of the icon.
* @param action The action to perform when the button is clicked.
* @return The button representing the action.
*/
private Button createActionButton(ColorRGBA color, String iconPath, int iconSize, Runnable action) {
Button button = new Button("", new ElementId("button-toolbar2"));
button.setPreferredSize(new Vector3f(150, 50, 0));
@ -217,6 +332,12 @@ public class Toolbar extends Dialog implements GameEventListener {
return button;
}
/**
* Creates a background with the specified color.
*
* @param color The color of the background.
* @return The background component.
*/
private QuadBackgroundComponent createButtonBackground(ColorRGBA color) {
QuadBackgroundComponent background = new QuadBackgroundComponent(color);
Texture gradient = app.getAssetManager().loadTexture("Textures/gradient.png");
@ -224,6 +345,9 @@ public class Toolbar extends Dialog implements GameEventListener {
return background;
}
/**
* Handles the end turn event.
*/
private void handleEndTurn() {
Player currentPlayer = playerHandler.getPlayerById(app.getId());
if (currentPlayer.getAccountBalance() < 0 && !bankruptPopUp) {
@ -236,6 +360,9 @@ public class Toolbar extends Dialog implements GameEventListener {
}
}
/**
* Starts the dice animation.
*/
private void startDiceAnimation() {
long startTime = System.currentTimeMillis();
new Thread(() -> {
@ -250,6 +377,12 @@ public class Toolbar extends Dialog implements GameEventListener {
}).start();
}
/**
* Animates the dice roll.
*
* @param startTime The start time of the animation.
* @throws InterruptedException If the animation is interrupted.
*/
private void animateDice(long startTime) throws InterruptedException {
int[] currentFace = {1};
while (System.currentTimeMillis() - startTime < 2000) {
@ -259,6 +392,11 @@ public class Toolbar extends Dialog implements GameEventListener {
}
}
/**
* Updates the dice icons with the specified face.
*
* @param face The face of the dice.
*/
private void updateDiceIcons(int face) {
app.enqueue(() -> {
setDiceIcon(imageLabel, diceToString(face));
@ -266,6 +404,11 @@ public class Toolbar extends Dialog implements GameEventListener {
});
}
/**
* Shows the final dice result.
*
* @param event The dice roll event.
*/
private void showFinalDiceResult(DiceRollEvent event) {
app.enqueue(() -> {
setDiceIcon(imageLabel, diceToString(event.a()));
@ -273,12 +416,24 @@ public class Toolbar extends Dialog implements GameEventListener {
});
}
/**
* Sets the dice icon with the specified image path.
*
* @param label The label representing the dice.
* @param imagePath The path to the icon image.
*/
private void setDiceIcon(Label label, String imagePath) {
IconComponent icon = new IconComponent(imagePath);
icon.setIconSize(new Vector2f(80, 80));
label.setIcon(icon);
}
/**
* Converts the dice number to a string representation.
*
* @param i The dice number.
* @return The string representation of the dice number.
*/
private String diceToString(int i) {
return "Pictures/dice/" + switch (i) {
case 1 -> "one";
@ -291,16 +446,30 @@ public class Toolbar extends Dialog implements GameEventListener {
} + ".png";
}
/**
* Handles dice roll events and updates the dice display.
*
* @param event the dice roll event containing dice values
*/
@Override
public void receivedEvent(DiceRollEvent event) {
latestDiceRollEvent = event;
}
/**
* Updates the player view by refreshing the player information displayed on the toolbar.
*
* @param event the update player view event
*/
@Override
public void receivedEvent(UpdatePlayerView event) {
playerHandler = app.getGameLogic().getPlayerHandler();
refreshPlayerView();
}
/**
* Refreshes the player view.
*/
private void refreshPlayerView() {
accountContainer.clearChildren();
overviewContainer.clearChildren();
@ -312,6 +481,9 @@ public class Toolbar extends Dialog implements GameEventListener {
overviewContainer.setBackground(null);
}
/**
* Adds the account details to the player view.
*/
private void addAccountDetails() {
Player currentPlayer = playerHandler.getPlayerById(app.getId());
accountContainer.addChild(new Label("Kontostand", new ElementId("label-toolbar")));
@ -320,6 +492,9 @@ public class Toolbar extends Dialog implements GameEventListener {
accountContainer.addChild(new Label(String.valueOf(currentPlayer.getNumJailCard()), new ElementId("label-account")));
}
/**
* Adds the overview details to the player view.
*/
private void addOverviewDetails() {
overviewContainer.addChild(new Label("Übersicht", new ElementId("label-toolbar")));
for (Player player : playerHandler.getPlayers()) {
@ -334,6 +509,12 @@ public class Toolbar extends Dialog implements GameEventListener {
}
}
/**
* Updates the status of toolbar buttons based on the provided button status event.
* Disables or enables buttons such as trade, property menu, and end turn based on the player's turn status.
*
* @param event the button status event indicating whether the buttons should be enabled
*/
@Override
public void receivedEvent(ButtonStatusEvent event) {
boolean enabled = event.buttonsEnabled();
@ -343,17 +524,26 @@ public class Toolbar extends Dialog implements GameEventListener {
if (endTurnButton != null) endTurnButton.setEnabled(false);
}
/**
* Closes the toolbar, detaching it from the GUI.
*/
@Override
public void close() {
app.getGuiNode().detachChild(toolbarContainer);
super.close();
}
/**
* Opens the settings menu when the escape key is pressed.
*/
@Override
public void escape() {
new SettingsMenu(app).open();
}
/**
* Updates the toolbar by refreshing player information.
*/
@Override
public void update() {
refreshPlayerView();

View File

@ -125,13 +125,13 @@ public class BuyHouse extends Dialog {
buyHouseContainer.setLocalTranslation(
(app.getCamera().getWidth() - buyHouseContainer.getPreferredSize().x) / 2,
(app.getCamera().getHeight() + buyHouseContainer.getPreferredSize().y) / 2,
9
11
);
backgroundContainer.setLocalTranslation(
(app.getCamera().getWidth() - buyHouseContainer.getPreferredSize().x - padding) / 2,
(app.getCamera().getHeight() + buyHouseContainer.getPreferredSize().y + padding) / 2,
8
10
);
app.getGuiNode().attachChild(buyHouseContainer);

View File

@ -83,14 +83,14 @@ public class EventCardPopup extends Dialog {
eventCardContainer.setLocalTranslation(
(app.getCamera().getWidth() - eventCardContainer.getPreferredSize().x) / 2,
(app.getCamera().getHeight() + eventCardContainer.getPreferredSize().y) / 2,
10
9
);
// Zentriere das Popup
backgroundContainer.setLocalTranslation(
(app.getCamera().getWidth() - eventCardContainer.getPreferredSize().x - padding) / 2,
(app.getCamera().getHeight() + eventCardContainer.getPreferredSize().y+ padding) / 2,
9
8
);
app.getGuiNode().attachChild(eventCardContainer);

Binary file not shown.

After

Width:  |  Height:  |  Size: 195 KiB