mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2024-12-01 11:09:44 +01:00
can now dynamically update toolbar view
This commit is contained in:
parent
c71e8b1e8e
commit
174958c6b1
@ -1,14 +1,15 @@
|
||||
|
||||
package pp.monopoly.client.gui;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.jme3.font.BitmapText;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector2f;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.simsilica.lemur.*;
|
||||
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;
|
||||
@ -24,6 +25,7 @@ import pp.monopoly.message.client.RollDice;
|
||||
import pp.monopoly.notification.DiceRollEvent;
|
||||
import pp.monopoly.notification.GameEventListener;
|
||||
import pp.monopoly.notification.Sound;
|
||||
import pp.monopoly.notification.UpdatePlayerView;
|
||||
|
||||
/**
|
||||
* Toolbar Klasse, die am unteren Rand der Szene angezeigt wird.
|
||||
@ -66,25 +68,10 @@ public class Toolbar extends Dialog implements GameEventListener{
|
||||
|
||||
// Menü-Container: Ein Nested-Container für Kontostand und "Meine Gulag Frei Karten"
|
||||
accountContainer = toolbarContainer.addChild(new Container());
|
||||
accountContainer.addChild(new Label("Kontostand", new ElementId("label-Bold")));
|
||||
accountContainer.addChild(new Label(playerHandler.getPlayerById(app.getId()).getAccountBalance() + " EUR", new ElementId("label-Text")));
|
||||
accountContainer.addChild(new Label("Gulag Frei Karten", new ElementId("label-Bold")));
|
||||
accountContainer.addChild(new Label(playerHandler.getPlayerById(app.getId()).getNumJailCard()+"", new ElementId("label-Text")));
|
||||
accountContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||
|
||||
// Menü-Container: Ein Container für Übersicht
|
||||
overviewContainer = toolbarContainer.addChild(new Container());
|
||||
overviewContainer.addChild(new Label("Übersicht", new ElementId("label-Bold")));
|
||||
|
||||
for (Player player : playerHandler.getPlayers()) {
|
||||
if (player.getId() != app.getId()) { // Skip the current player (host)
|
||||
overviewContainer.addChild(new Label(
|
||||
player.getName() + ": " + player.getAccountBalance() + " EUR",
|
||||
new ElementId("label-Text")
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
receivedEvent(new UpdatePlayerView());
|
||||
|
||||
|
||||
overviewContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||
@ -206,6 +193,40 @@ public class Toolbar extends Dialog implements GameEventListener{
|
||||
updateDiceImages(event.a(), event.b());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedEvent(UpdatePlayerView event) {
|
||||
// Clear existing accountContainer and overviewContainer content
|
||||
accountContainer.clearChildren();
|
||||
overviewContainer.clearChildren();
|
||||
|
||||
// Update accountContainer
|
||||
accountContainer.addChild(new Label("Kontostand", new ElementId("label-Bold")));
|
||||
accountContainer.addChild(new Label(
|
||||
playerHandler.getPlayerById(app.getId()).getAccountBalance() + " EUR",
|
||||
new ElementId("label-Text")
|
||||
));
|
||||
accountContainer.addChild(new Label("Gulag Karten", new ElementId("label-Bold")));
|
||||
accountContainer.addChild(new Label(
|
||||
playerHandler.getPlayerById(app.getId()).getNumJailCard() + "",
|
||||
new ElementId("label-Text")
|
||||
));
|
||||
accountContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||
|
||||
// Update overviewContainer
|
||||
overviewContainer.addChild(new Label("Übersicht", new ElementId("label-Bold")));
|
||||
for (Player player : playerHandler.getPlayers()) {
|
||||
if (player.getId() != app.getId()) { // Skip the current player
|
||||
overviewContainer.addChild(new Label(
|
||||
player.getName() + ": " + player.getAccountBalance() + " EUR",
|
||||
new ElementId("label-Text")
|
||||
));
|
||||
}
|
||||
}
|
||||
overviewContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||
System.out.println("pdate");
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void updateDiceImages(int a, int b) {
|
||||
//TODO dice toll animation
|
||||
|
@ -46,5 +46,17 @@ public interface GameEventListener {
|
||||
*/
|
||||
default void receivedEvent(ClientStateEvent event) { /* do nothing */ }
|
||||
|
||||
/**
|
||||
* Indicates that the dice result has changed.
|
||||
*
|
||||
* @param event the received event
|
||||
*/
|
||||
default void receivedEvent(DiceRollEvent event) { /*Do nothing */}
|
||||
|
||||
/**
|
||||
* Indicates that the players assets have changed.
|
||||
*
|
||||
* @param event the received event
|
||||
*/
|
||||
default void receivedEvent(UpdatePlayerView event) { /*Do nothing */}
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
package pp.monopoly.notification;
|
||||
|
||||
public record UpdatePlayerView() implements GameEvent{
|
||||
/**
|
||||
* Notifies the game event listener of this event.
|
||||
*
|
||||
* @param listener the game event listener
|
||||
*/
|
||||
@Override
|
||||
public void notifyListener(GameEventListener listener) {
|
||||
listener.receivedEvent(this);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user