This commit is contained in:
Luca Puderbach
2024-11-29 04:41:14 +01:00
28 changed files with 1148 additions and 702 deletions

View File

@@ -38,11 +38,6 @@ import static pp.monopoly.Resources.lookup;
import pp.monopoly.client.gui.SettingsMenu;
import pp.monopoly.client.gui.StartMenu;
import pp.monopoly.client.gui.TestWorld;
import pp.monopoly.client.gui.popups.BuildingPropertyCard;
import pp.monopoly.client.gui.popups.BuyCard;
import pp.monopoly.client.gui.popups.EventCard;
import pp.monopoly.client.gui.popups.FoodFieldCard;
import pp.monopoly.client.gui.popups.GateFieldCard;
import pp.monopoly.game.client.ClientGameLogic;
import pp.monopoly.game.client.MonopolyClient;
import pp.monopoly.game.client.ServerConnection;
@@ -133,6 +128,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
private FoodFieldCard foodField;
private GateFieldCard gateField;
private BuyCard buyCard;
private LooserPopUp looserpopup;
private boolean isBuyCardPopupOpen = false;
private final ActionListener BListener = (name, isPressed, tpf) -> handleB(isPressed);
private TestWorld testWorld;
@@ -276,7 +272,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
//logik zum wechselnden erscheinen und verschwinden beim drücken von B //TODO süäter entfernen
private void handleB(boolean isPressed) {
if (isPressed) {
Dialog tmp = new BuyCard(this);
Dialog tmp = new SellHouse(this);
tmp.open();
}
}

View File

@@ -81,6 +81,7 @@ public class BuildingAdminMenu extends Dialog {
overviewButton.setPreferredSize(new Vector3f(200, 50, 0));
overviewButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON);
new PropertyOverviewMenu(app).open();
}));
overviewColumn.addChild(overviewButton);

View File

@@ -2,27 +2,23 @@ package pp.monopoly.client.gui;
import java.util.Set;
import com.jme3.app.Application;
import com.jme3.app.state.BaseAppState;
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.Axis;
import com.simsilica.lemur.Button;
import com.simsilica.lemur.Container;
import com.simsilica.lemur.Label;
import com.simsilica.lemur.Selector;
import com.simsilica.lemur.*;
import com.simsilica.lemur.component.QuadBackgroundComponent;
import com.simsilica.lemur.component.SpringGridLayout;
import com.simsilica.lemur.core.VersionedList;
import com.simsilica.lemur.core.VersionedReference;
import com.simsilica.lemur.style.ElementId;
import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp;
import pp.monopoly.game.server.Player;
import pp.monopoly.message.client.ViewAssetsRequest;
import pp.monopoly.model.TradeHandler;
import pp.monopoly.notification.Sound;
@@ -36,6 +32,9 @@ public class ChoosePartner extends Dialog {
private Container lowerRightMenu;
private Geometry background;
private TradeHandler tradeHandler;
private VersionedReference<Set<Integer>> selectionRef; // Reference to track selector changes
private String lastSelected = ""; // To keep track of the last selected value
QuadBackgroundComponent translucentWhiteBackground =
new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f));
@@ -48,6 +47,7 @@ public class ChoosePartner extends Dialog {
super(app.getDialogManager());
this.app = app;
tradeHandler = new TradeHandler(app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()));
app.getGameLogic().send(new ViewAssetsRequest());
// Background Image
addBackgroundImage();
@@ -68,8 +68,6 @@ public class ChoosePartner extends Dialog {
// Add buttons
mainContainer.addChild(createButtonContainer());
addSelectionActionListener(playerSelector, this::onDropdownSelectionChanged);
// Attach main container to GUI node
app.getGuiNode().attachChild(mainContainer);
mainContainer.setLocalTranslation(
@@ -77,6 +75,9 @@ public class ChoosePartner extends Dialog {
(app.getCamera().getHeight() + mainContainer.getPreferredSize().y) / 2,
4
);
// Initialize selection reference for tracking changes
selectionRef = playerSelector.getSelectionModel().createReference();
}
/**
@@ -93,7 +94,7 @@ public class ChoosePartner extends Dialog {
for (Player player : app.getGameLogic().getPlayerHandler().getPlayers()) {
if (player.getId() != app.getId()) {
playerOptions.add(player.getName() + " (ID: "+player.getId()+")");
playerOptions.add(player.getName() + " (ID: " + player.getId() + ")");
}
}
@@ -101,10 +102,14 @@ public class ChoosePartner extends Dialog {
dropdownContainer.addChild(playerSelector);
Vector3f dimens = dropdownContainer.getPreferredSize();
Vector3f dimens2 = playerSelector.getPopupContainer().getPreferredSize();
dimens2.setX( dimens.getX() );
playerSelector.getPopupContainer().setPreferredSize(new Vector3f(200,200,3));
playerSelector.setLocalTranslation(0,0,5);
onDropdownSelectionChanged(playerOptions.get(0));
dimens2.setX(dimens.getX());
playerSelector.getPopupContainer().setPreferredSize(new Vector3f(200, 200, 3));
playerSelector.setLocalTranslation(0, 0, 5);
// Set initial selection
if (!playerOptions.isEmpty()) {
onDropdownSelectionChanged(playerOptions.get(0));
}
return dropdownContainer;
}
@@ -132,7 +137,6 @@ public class ChoosePartner extends Dialog {
lowerLeftMenu.setLocalTranslation(new Vector3f(120, 170, 5)); // Adjust X and Y to align with the bottom-left corner
app.getGuiNode().attachChild(lowerLeftMenu);
// "Bestätigen" button
lowerRightMenu = new Container();
confirmButton.setPreferredSize(new Vector3f(200, 60, 0));
@@ -140,7 +144,7 @@ public class ChoosePartner extends Dialog {
confirmButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON);
close();
new TradeMenu(app).open();
new TradeMenu(app, tradeHandler).open();
}));
lowerRightMenu.addChild(confirmButton);
@@ -148,7 +152,6 @@ public class ChoosePartner extends Dialog {
lowerRightMenu.setLocalTranslation(new Vector3f(app.getCamera().getWidth() - 320, 170, 5)); // X: 220px from the right, Y: 50px above the bottom
app.getGuiNode().attachChild(lowerRightMenu);
return buttonContainer;
}
@@ -181,7 +184,14 @@ public class ChoosePartner extends Dialog {
*/
@Override
public void update(float delta) {
// Periodic updates (if needed) can be implemented here
// Check if the selection has changed
if (selectionRef.update()) {
String selected = playerSelector.getSelectedItem();
if (!selected.equals(lastSelected)) {
lastSelected = selected;
onDropdownSelectionChanged(selected);
}
}
}
@Override
@@ -194,42 +204,6 @@ public class ChoosePartner extends Dialog {
super.close();
}
/**
* Adds a custom action listener to the Selector.
*/
private void addSelectionActionListener(Selector<String> selector, SelectionActionListener<String> listener) {
VersionedReference<Set<Integer>> selectionRef = selector.getSelectionModel().createReference();
app.getStateManager().attach(new BaseAppState() {
@Override
public void update(float tpf) {
if (selectionRef.update()) {
String selected = selectionRef.get().toString();
listener.onSelectionChanged(selected);
}
}
@Override
protected void initialize(Application app) {
update(1);
}
@Override
protected void cleanup(Application app) {
}
@Override
protected void onEnable() {
}
@Override
protected void onDisable() {
}
});
}
/**
* Callback for when the dropdown selection changes.
*/
@@ -239,23 +213,12 @@ public class ChoosePartner extends Dialog {
int idEnd = selected.indexOf(")", idStart); // Find end of the ID
String idStr = selected.substring(idStart, idEnd); // Extract the ID as a string
int playerId = Integer.parseInt(idStr); // Convert the ID to an integer
// Find the player by ID
Player selectedPlayer = app.getGameLogic().getPlayerHandler().getPlayerById(playerId);
if (selectedPlayer != null) {
tradeHandler.setReceiver(selectedPlayer); // Set the receiver in TradeHandler
}
}
/**
* Functional interface for a selection action listener.
*/
@FunctionalInterface
private interface SelectionActionListener<T> {
void onSelectionChanged(T selection);
}
}

View File

@@ -0,0 +1,244 @@
package pp.monopoly.client.gui;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.control.AbstractControl;
import com.simsilica.lemur.*;
import com.simsilica.lemur.component.QuadBackgroundComponent;
import com.simsilica.lemur.component.SpringGridLayout;
import com.simsilica.lemur.style.ElementId;
import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp;
import pp.monopoly.game.server.Player;
import pp.monopoly.model.fields.BuildingProperty;
import pp.monopoly.model.fields.FoodField;
import pp.monopoly.model.fields.GateField;
import pp.monopoly.model.fields.PropertyField;
import java.util.ArrayList;
import java.util.List;
/**
* PropertyOverviewMenu is a dialog for displaying the player's properties in the game.
*/
public class PropertyOverviewMenu extends Dialog {
private final MonopolyApp app;
private final Container mainContainer;
private final Container displayContainer;
private final Slider horizontalSlider;
private final List<Container> cards;
/**
* Constructs the PropertyOverviewMenu dialog.
*
* @param app The Monopoly application instance.
*/
public PropertyOverviewMenu(MonopolyApp app) {
super(app.getDialogManager());
this.app = app;
// Make the menu fullscreen
Vector3f screenSize = new Vector3f(app.getCamera().getWidth(), app.getCamera().getHeight(), 0);
// Main container for the menu layout
mainContainer = new Container();
mainContainer.setPreferredSize(screenSize); // Make fullscreen
mainContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.8f))); // Semi-transparent background
// Header label
Label headerLabel = mainContainer.addChild(new Label("Meine Grundstücke", new ElementId("header")));
headerLabel.setFontSize(40);
// Central display container (to hold the "Gebäude" cards)
displayContainer = mainContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y, FillMode.Even, FillMode.None))); // Horizontal layout
displayContainer.setPreferredSize(new Vector3f(screenSize.x - 300, 550, 0)); // Take up the remaining width
displayContainer.setBackground(new QuadBackgroundComponent(ColorRGBA.White));
displayContainer.setLocalTranslation(0, 0, 11);
// Add some placeholder "Gebäude" cards to the display container
cards = new ArrayList<>();
populatePlayerProperties();
// Initially add only visible cards to the displayContainer
refreshVisibleCards(0);
// Horizontal slider for scrolling through cards
horizontalSlider = mainContainer.addChild(new Slider(Axis.X));
horizontalSlider.setPreferredSize(new Vector3f(screenSize.x - 300, 20, 5));
horizontalSlider.setModel(new DefaultRangedValueModel(0, Math.max(0, cards.size() - 5), 0));
horizontalSlider.addControl(new SliderValueChangeListener());
// Add the "Zurück" button at the bottom
Button backButton = mainContainer.addChild(new Button("Zurück", new ElementId("button")));
backButton.setPreferredSize(new Vector3f(200, 60, 0));
backButton.addClickCommands(source -> this.close());
// Attach the main container to the GUI node
app.getGuiNode().attachChild(mainContainer);
mainContainer.setLocalTranslation(
0,
app.getCamera().getHeight(), // Align to the top
10
);
}
/**
* Fetches the player's properties and populates them into the cards list.
*/
private void populatePlayerProperties() {
// Fetch the current player
Player currentPlayer = app.getGameLogic().getPlayerHandler().getPlayers().get(0);
// Iterate through the player's properties
for (PropertyField property : currentPlayer.getPropertyFields()) {
if (property instanceof BuildingProperty) {
BuildingProperty building = (BuildingProperty) property;
cards.add(createBuildingCard(building));
} else if (property instanceof FoodField) {
FoodField foodField = (FoodField) property;
cards.add(createFoodFieldCard(foodField));
} else if (property instanceof GateField) {
GateField gateField = (GateField) property;
cards.add(createGateFieldCard(gateField));
}
}
}
/**
* Creates a card for BuildingProperty with detailed rent and cost information.
*/
private Container createBuildingCard(BuildingProperty field) {
Container card = new Container();
card.setPreferredSize(new Vector3f(200, 300, 2)); // Match the size of the BuildingPropertyCard
card.setBackground(new QuadBackgroundComponent(field.getColor().getColor()));
card.setInsets(new Insets3f(5, 5, 5, 5)); // Add 5-pixel inset
card.addChild(new Label(field.getName(), new ElementId("label-Bold"))).setFontSize(25);
// Add property details
Container propertyValuesContainer = card.addChild(new Container());
propertyValuesContainer.addChild(new Label("Grundstückswert: €" + field.getPrice(), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))); // Leerzeile
propertyValuesContainer.addChild(new Label("Miete allein: €" + field.getAllRent().get(0), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("- mit 1 Haus: €" + field.getAllRent().get(1), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("- mit 2 Häuser: €" + field.getAllRent().get(2), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("- mit 3 Häuser: €" + field.getAllRent().get(3), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("- mit 4 Häuser: €" + field.getAllRent().get(4), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("- mit 1 Hotel: €" + field.getAllRent().get(5), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("- 1 Haus kostet: €" + field.getHousePrice(), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))); // Leerzeile
propertyValuesContainer.addChild(new Label("Hypothek: €" + field.getHypo(), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
return card;
}
/**
* Creates a card for FoodField with dynamic pricing and rent details.
*/
private Container createFoodFieldCard(FoodField field) {
Container card = new Container();
card.setPreferredSize(new Vector3f(200, 300, 2)); // Adjust card size
card.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.1f, 0.1f, 0.1f, 0.9f))); // Dark background for card
card.setInsets(new Insets3f(5, 5, 5, 5)); // Add 5-pixel inset
// Title Section
Label title = card.addChild(new Label(field.getName(), new ElementId("label-Bold")));
title.setFontSize(30);
title.setColor(ColorRGBA.White); // Ensure readability on dark background
// Property Values Section
Container propertyValuesContainer = card.addChild(new Container());
propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); // Grey background
propertyValuesContainer.addChild(new Label("Preis: €" + field.getPrice(), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))); // Leerzeile
propertyValuesContainer.addChild(new Label("Wenn man Besitzer des", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label(field.getName() + " ist,", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("so ist die Miete", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("40x Würfelwert.", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))); // Leerzeile
propertyValuesContainer.addChild(new Label("Besitzer beider", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("Restaurants zahlt", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("100x Würfelwert.", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))); // Leerzeile
propertyValuesContainer.addChild(new Label("Hypothek: €" + field.getHypo(), new ElementId("label-Text"))).setFontSize(14);
return card;
}
/**
* Creates a card for GateField with rent details for owning multiple gates.
*/
private Container createGateFieldCard(GateField field) {
Container card = new Container();
card.setPreferredSize(new Vector3f(200, 300, 2)); // Adjust card size
card.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Light grey background
card.setInsets(new Insets3f(5, 5, 5, 5)); // Add 5-pixel inset
// Title Section
Label title = card.addChild(new Label(field.getName(), new ElementId("label-Bold")));
title.setFontSize(30);
title.setColor(ColorRGBA.Black);
// Property Values Section
Container propertyValuesContainer = card.addChild(new Container());
propertyValuesContainer.addChild(new Label("Preis: €" + field.getPrice(), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))); // Leerzeile
propertyValuesContainer.addChild(new Label("1 Bahnhof: €250", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("2 Bahnhöfe: €500", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("3 Bahnhöfe: €1000", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("4 Bahnhöfe: €2000", new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text"))); // Leerzeile
propertyValuesContainer.addChild(new Label("Hypothek: €" + field.getHypo(), new ElementId("label-Text"))).setFontSize(14);
propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); // Dark grey background
return card;
}
/**
* Updates the visible cards in the displayContainer based on the slider value.
*
* @param startIndex The starting index of the visible cards.
*/
private void refreshVisibleCards(int startIndex) {
displayContainer.clearChildren(); // Remove all current children
int maxVisible = 5; // Number of cards to display at once
for (int i = startIndex; i < startIndex + maxVisible && i < cards.size(); i++) {
displayContainer.addChild(cards.get(i));
}
}
/**
* Custom listener for slider value changes.
*/
private class SliderValueChangeListener extends AbstractControl {
@Override
protected void controlUpdate(float tpf) {
// Get the slider's current value and refresh visible cards
int sliderValue = (int) ((Slider) getSpatial()).getModel().getValue();
refreshVisibleCards(sliderValue);
}
@Override
protected void controlRender(RenderManager renderManager, ViewPort viewPort) {
// No rendering logic needed
}
}
/**
* Closes the dialog and detaches it from the GUI node.
*/
@Override
public void close() {
app.getGuiNode().detachChild(mainContainer);
super.close();
}
}

View File

@@ -3,7 +3,19 @@ package pp.monopoly.client.gui;
import java.util.List;
import pp.monopoly.client.MonopolyApp;
import pp.monopoly.client.gui.popups.BuyCard;
import pp.monopoly.client.gui.popups.EventCard;
import pp.monopoly.client.gui.popups.FoodFieldCard;
import pp.monopoly.client.gui.popups.GateFieldCard;
import pp.monopoly.game.server.Player;
import pp.monopoly.model.fields.BuildingProperty;
import pp.monopoly.model.fields.FoodField;
import pp.monopoly.model.fields.GateField;
import pp.monopoly.model.fields.PropertyField;
import pp.monopoly.notification.DiceRollEvent;
import pp.monopoly.notification.EventCardEvent;
import pp.monopoly.notification.GameEventListener;
import pp.monopoly.notification.PopUpEvent;
/**
* TestWorld zeigt eine einfache Szene mit Spielfeld und Spielfiguren.
@@ -113,4 +125,23 @@ public class TestWorld {
cameraController.update(tpf); // Aktualisiere die Kameraposition
}
}
@Override
public void receivedEvent(PopUpEvent event) {
System.err.println("Trigger ?");
// if (event.desc() == "BuyCard") {
int field = app.getGameLogic().getPlayerHandler().getPlayers().get(0).getFieldID();
Object fieldObject = app.getGameLogic().getBoardManager().getFieldAtIndex(field);
if (fieldObject instanceof BuildingProperty) {
new BuyCard(app).open();
} else if (fieldObject instanceof GateField){
new GateFieldCard(app).open();
} else if (fieldObject instanceof FoodField) {
new FoodFieldCard(app).open();
}
}
}

View File

@@ -18,20 +18,22 @@ 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.DiceRollEvent;
import pp.monopoly.notification.GameEventListener;
import pp.monopoly.notification.Sound;
import pp.monopoly.notification.UpdatePlayerView;
import pp.monopoly.notification.*;
public class Toolbar extends Dialog implements GameEventListener {
private final MonopolyApp app;
private final Container toolbarContainer;
private Label imageLabel;
private Label imageLabel2;
private Container overviewContainer;
private Container accountContainer;
private PlayerHandler playerHandler;
private Label imageLabel;
private Label imageLabel2;
private Button diceButton;
private Button tradeButton;
private Button propertyMenuButton;
private Button endTurnButton;
private volatile boolean animatingDice = false;
private volatile DiceRollEvent latestDiceRollEvent = null;
@@ -40,73 +42,82 @@ public class Toolbar extends Dialog implements GameEventListener {
this.app = app;
app.getGameLogic().addListener(this);
playerHandler = app.getGameLogic().getPlayerHandler();
this.playerHandler = app.getGameLogic().getPlayerHandler();
// Erstelle die Toolbar
toolbarContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y), "toolbar");
toolbarContainer.setLocalTranslation(0, 200, 0);
toolbarContainer.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 200, 0));
toolbarContainer = createToolbarContainer();
app.getGuiNode().attachChild(toolbarContainer);
}
// Account- und Übersichtskontainer
accountContainer = toolbarContainer.addChild(new Container());
overviewContainer = toolbarContainer.addChild(new Container());
private Container createToolbarContainer() {
Container container = new Container(new SpringGridLayout(Axis.X, Axis.Y), "toolbar");
container.setLocalTranslation(0, 200, 0);
container.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 200, 0));
// Create account and overview containers
accountContainer = container.addChild(new Container());
overviewContainer = container.addChild(new Container());
receivedEvent(new UpdatePlayerView());
overviewContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
// Dice section
container.addChild(createDiceSection());
// Würfelbereich
Container diceContainer = toolbarContainer.addChild(new Container());
diceContainer.setLayout(new SpringGridLayout(Axis.X, Axis.Y));
// Action menu
Container menuContainer = container.addChild(new Container());
menuContainer.addChild(createTradeButton());
menuContainer.addChild(createPropertyMenuButton());
menuContainer.addChild(createEndTurnButton());
menuContainer.setBackground(createBackground());
Container horizontalContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
horizontalContainer.setPreferredSize(new Vector3f(200, 150, 0));
return container;
}
// Linker Würfel
Container leftContainer = new Container();
leftContainer.setPreferredSize(new Vector3f(100, 150, 0));
imageLabel = new Label("");
IconComponent icon = new IconComponent("Pictures/dice/one.png");
icon.setIconSize(new Vector2f(100, 100));
imageLabel.setIcon(icon);
private Container createDiceSection() {
Container diceContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
diceContainer.addChild(createDiceDisplay());
// Rechter Würfel
Container rightContainer = new Container();
rightContainer.setPreferredSize(new Vector3f(100, 150, 0));
imageLabel2 = new Label("");
IconComponent icon2 = new IconComponent("Pictures/dice/two.png");
icon2.setIconSize(new Vector2f(100, 100));
imageLabel2.setIcon(icon2);
leftContainer.addChild(imageLabel);
rightContainer.addChild(imageLabel2);
horizontalContainer.addChild(leftContainer);
horizontalContainer.addChild(rightContainer);
diceContainer.addChild(horizontalContainer);
// Würfeln-Button
Button diceButton = new Button("Würfeln");
diceButton = new Button("Würfeln", new ElementId("button-toolbar"));
diceButton.setPreferredSize(new Vector3f(200, 50, 0));
diceButton.addClickCommands(s -> ifTopDialog(() -> {
diceButton.setEnabled(false);
startDiceAnimation();
app.getGameLogic().send(new RollDice());
app.getGameLogic().playSound(Sound.BUTTON);
}));
diceContainer.addChild(diceButton);
// Menü-Container für weitere Aktionen
Container menuContainer = toolbarContainer.addChild(new Container());
menuContainer.addChild(addTradeMenuButton());
menuContainer.addChild(addPropertyMenuButton());
menuContainer.addChild(addEndTurnButton());
menuContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
app.getGuiNode().attachChild(toolbarContainer);
return diceContainer;
}
private Button addTradeMenuButton() {
Button tradeButton = new Button("Handeln");
private Container createDiceDisplay() {
Container horizontalContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
horizontalContainer.setPreferredSize(new Vector3f(200, 150, 0));
imageLabel = createDiceLabel("Pictures/dice/one.png");
imageLabel2 = createDiceLabel("Pictures/dice/two.png");
horizontalContainer.addChild(createDiceContainer(imageLabel));
horizontalContainer.addChild(createDiceContainer(imageLabel2));
return horizontalContainer;
}
private Label createDiceLabel(String iconPath) {
Label label = new Label("");
IconComponent icon = new IconComponent(iconPath);
icon.setIconSize(new Vector2f(100, 100));
label.setIcon(icon);
return label;
}
private Container createDiceContainer(Label label) {
Container container = new Container();
container.setPreferredSize(new Vector3f(100, 150, 0));
container.addChild(label);
return container;
}
private Button createTradeButton() {
tradeButton = new Button("Handeln", new ElementId("button-toolbar"));
tradeButton.setPreferredSize(new Vector3f(150, 50, 0));
tradeButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON);
@@ -115,8 +126,8 @@ public class Toolbar extends Dialog implements GameEventListener {
return tradeButton;
}
private Button addPropertyMenuButton() {
Button propertyMenuButton = new Button("Grundstücke");
private Button createPropertyMenuButton() {
propertyMenuButton = new Button("Grundstücke", new ElementId("button-toolbar"));
propertyMenuButton.setPreferredSize(new Vector3f(150, 50, 0));
propertyMenuButton.setFontSize(30);
propertyMenuButton.addClickCommands(s -> ifTopDialog(() -> {
@@ -126,20 +137,23 @@ public class Toolbar extends Dialog implements GameEventListener {
return propertyMenuButton;
}
private Button addEndTurnButton() {
Button endTurnButton = new Button("Zug beenden");
private Button createEndTurnButton() {
endTurnButton = new Button("Zug beenden", new ElementId("button-toolbar"));
endTurnButton.setPreferredSize(new Vector3f(150, 50, 0));
endTurnButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON);
app.getGameLogic().send(new EndTurn());
receivedEvent(new ButtonStatusEvent(false));
}));
return endTurnButton;
}
private QuadBackgroundComponent createBackground() {
return new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f));
}
private void startDiceAnimation() {
animatingDice = true;
// Starte die Animation und speichere die Startzeit
long startTime = System.currentTimeMillis();
Thread diceAnimation = new Thread(() -> {
@@ -165,48 +179,66 @@ public class Toolbar extends Dialog implements GameEventListener {
// Animation beenden
animatingDice = false;
// Zeige das finale Ergebnis
if (latestDiceRollEvent != null) {
showFinalDiceResult(latestDiceRollEvent);
}
} catch (InterruptedException e) {
System.err.println("Würfelanimation unterbrochen: " + e.getMessage());
System.err.println("Dice animation interrupted: " + e.getMessage());
}
});
diceAnimation.start();
}).start();
}
private void animateDice(long startTime) throws InterruptedException {
int[] currentFace = {1};
while (System.currentTimeMillis() - startTime < 2500) { // Animation duration
currentFace[0] = (currentFace[0] % 6) + 1;
String rotatingImage1 = diceToString(currentFace[0]);
String rotatingImage2 = diceToString((currentFace[0] % 6) + 1);
app.enqueue(() -> {
setDiceIcon(imageLabel, rotatingImage1);
setDiceIcon(imageLabel2, rotatingImage2);
});
Thread.sleep(100); // Time between frame updates
}
}
private void showFinalDiceResult(DiceRollEvent event) {
int diceRoll1 = event.a();
int diceRoll2 = event.b();
app.enqueue(() -> {
setDiceIcon(imageLabel, diceToString(event.a()));
setDiceIcon(imageLabel2, diceToString(event.b()));
app.getGameLogic().playSound(Sound.BUTTON);
});
}
private void setDiceIcon(Label label, String imagePath) {
IconComponent icon = new IconComponent(imagePath);
icon.setIconSize(new Vector2f(80, 80)); // Set consistent dice size
label.setIcon(icon);
}
String finalImage1 = diceToString(diceRoll1);
String finalImage2 = diceToString(diceRoll2);
IconComponent finalIcon1 = new IconComponent(finalImage1);
finalIcon1.setIconSize(new Vector2f(100, 100));
app.enqueue(() -> imageLabel.setIcon(finalIcon1));
IconComponent finalIcon2 = new IconComponent(finalImage2);
finalIcon2.setIconSize(new Vector2f(100, 100));
app.enqueue(() -> imageLabel2.setIcon(finalIcon2));
app.getGameLogic().playSound(Sound.BUTTON);
private String diceToString(int i) {
switch (i) {
case 1: return "Pictures/dice/one.png";
case 2: return "Pictures/dice/two.png";
case 3: return "Pictures/dice/three.png";
case 4: return "Pictures/dice/four.png";
case 5: return "Pictures/dice/five.png";
case 6: return "Pictures/dice/six.png";
default: throw new IllegalArgumentException("Invalid dice number: " + i);
}
}
@Override
public void receivedEvent(DiceRollEvent event) {
latestDiceRollEvent = event; // Speichere das Event
latestDiceRollEvent = event;
}
@Override
public void receivedEvent(UpdatePlayerView event) {
playerHandler = app.getGameLogic().getPlayerHandler();
System.err.println("Update Player View");
// Clear existing accountContainer and overviewContainer content
accountContainer.clearChildren();
overviewContainer.clearChildren();
@@ -220,7 +252,7 @@ public class Toolbar extends Dialog implements GameEventListener {
playerHandler.getPlayerById(app.getId()).getNumJailCard() + "",
new ElementId("label-Text")
));
accountContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
accountContainer.setBackground(createBackground());
overviewContainer.addChild(new Label("Übersicht", new ElementId("label-Bold")));
for (Player player : playerHandler.getPlayers()) {
@@ -231,26 +263,16 @@ public class Toolbar extends Dialog implements GameEventListener {
));
}
}
overviewContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
overviewContainer.setBackground(createBackground());
}
private String diceToString(int i) {
switch (i) {
case 1:
return "Pictures/dice/one.png";
case 2:
return "Pictures/dice/two.png";
case 3:
return "Pictures/dice/three.png";
case 4:
return "Pictures/dice/four.png";
case 5:
return "Pictures/dice/five.png";
case 6:
return "Pictures/dice/six.png";
default:
throw new IllegalArgumentException("Invalid dice number: " + i);
}
@Override
public void receivedEvent(ButtonStatusEvent event) {
boolean enabled = event.buttonsEnabled();
diceButton.setEnabled(enabled);
tradeButton.setEnabled(enabled);
propertyMenuButton.setEnabled(enabled);
endTurnButton.setEnabled(enabled);
}
@Override

View File

@@ -1,7 +1,8 @@
package pp.monopoly.client.gui;
import static java.lang.Math.min;
import com.jme3.app.Application;
import com.jme3.app.state.BaseAppState;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
@@ -12,55 +13,218 @@ import com.simsilica.lemur.*;
import com.simsilica.lemur.component.QuadBackgroundComponent;
import com.simsilica.lemur.component.SpringGridLayout;
import com.simsilica.lemur.core.VersionedList;
import com.simsilica.lemur.core.VersionedReference;
import com.simsilica.lemur.style.ElementId;
import com.simsilica.lemur.text.DocumentModel;
import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp;
import pp.monopoly.model.TradeHandler;
import pp.monopoly.model.fields.PropertyField;
import pp.monopoly.notification.Sound;
import java.util.Set;
public class TradeMenu extends Dialog {
private final MonopolyApp app;
private final TradeHandler tradeHandler;
private final Container mainContainer;
private Selector<String> leftBuildingSelector, leftCurrencySelector, leftSpecialCardSelector;
private Selector<String> rightBuildingSelector, rightCurrencySelector, rightSpecialCardSelector;
private final Button cancelButton = new Button("Abbrechen");
private final Button tradeButton = new Button("Handeln");
private Container lowerLeftMenu, lowerRightMenu;
private TextField leftSelectionsField;
private TextField rightSelectionsField;
private TextField leftCurrencyInput;
private TextField rightCurrencyInput;
private Selector<String> leftBuildingSelector, leftSpecialCardSelector;
private Selector<String> rightBuildingSelector, rightSpecialCardSelector;
private TextField leftSelectionsField, rightSelectionsField;
private TextField leftCurrencyInput, rightCurrencyInput;
QuadBackgroundComponent translucentWhiteBackground =
new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.White));
private static final ColorRGBA TRANSLUCENT_WHITE = new ColorRGBA(1, 1, 1, 0.5f);
/**
* Constructs the TradeMenu dialog.
*
* @param app The Monopoly application instance.
*/
public TradeMenu(MonopolyApp app) {
public TradeMenu(MonopolyApp app, TradeHandler tradeHandler) {
super(app.getDialogManager());
this.app = app;
this.tradeHandler = tradeHandler;
// Background Image
addBackgroundImage();
// Main container for the UI components
mainContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X));
mainContainer.setPreferredSize(new Vector3f(1200, 800, 0));
mainContainer.setBackground(translucentWhiteBackground);
// Add header container
mainContainer.addChild(createHeaderContainer());
// Add main content (three columns: left, middle, right)
mainContainer.addChild(createMainContent());
// Attach main container to GUI node
mainContainer = createMainContainer();
app.getGuiNode().attachChild(mainContainer);
positionMainContainer();
}
private Container createMainContainer() {
Container container = new Container(new SpringGridLayout(Axis.Y, Axis.X));
container.setPreferredSize(new Vector3f(1200, 800, 0));
container.setBackground(new QuadBackgroundComponent(TRANSLUCENT_WHITE));
container.addChild(createHeader());
container.addChild(createMainContent());
return container;
}
private Label createHeader() {
Label header = new Label("Handelsmenü", new ElementId("label-Bold"));
header.setFontSize(50);
header.setInsets(new Insets3f(10, 10, 10, 10));
header.setBackground(new QuadBackgroundComponent(TRANSLUCENT_WHITE));
return header;
}
private Container createMainContent() {
Container mainContent = new Container(new SpringGridLayout(Axis.X, Axis.Y));
mainContent.setPreferredSize(new Vector3f(1200, 700, 0));
mainContent.addChild(createTradeColumn("Wähle Handelsobjekt:", true));
mainContent.addChild(createMiddleSection());
mainContent.addChild(createTradeColumn("Wähle Zielobjekt:", false));
Container buttons = mainContent.addChild(new Container(new SpringGridLayout()));
Button cancel = new Button("Abbrechen");
cancel.addClickCommands(s-> ifTopDialog( () -> {
close();
app.getGameLogic().playSound(Sound.BUTTON);
}));
Button trade = new Button("Handeln");
trade.addClickCommands(s-> ifTopDialog( () -> {
close();
app.getGameLogic().playSound(Sound.BUTTON);
}));
buttons.addChild(cancel);
buttons.addChild(trade);
return mainContent;
}
private Container createTradeColumn(String label, boolean isLeft) {
Container column = new Container(new SpringGridLayout(Axis.Y, Axis.X));
column.setBackground(new QuadBackgroundComponent(ColorRGBA.White));
Label columnLabel = column.addChild(new Label(label));
columnLabel.setFontSize(24);
columnLabel.setBackground(new QuadBackgroundComponent(TRANSLUCENT_WHITE));
column.addChild(new Label("Gebäude:"));
Selector<String> buildingSelector = createPropertySelector(isLeft);
column.addChild(buildingSelector);
column.addChild(new Label("Währung:"));
TextField currencyInput = createCurrencyInput();
column.addChild(currencyInput);
column.addChild(new Label("Sonderkarten:"));
Selector<String> specialCardSelector = createSpecialCardSelector();
styleSelector(specialCardSelector);
column.addChild(specialCardSelector);
assignSelectors(buildingSelector, specialCardSelector, currencyInput, isLeft);
return column;
}
private Selector<String> createPropertySelector(boolean isLeft) {
VersionedList<String> properties = new VersionedList<>();
for (PropertyField field : getPropertyFields(isLeft)) {
properties.add(field.getName());
}
Selector<String> selector = new Selector<>(properties, "glass");
styleSelector(selector);
return selector;
}
private Selector<String> createSpecialCardSelector() {
VersionedList<String> numbers = new VersionedList<>();
for (int i = 0; i <= app.getGameLogic().getPlayerHandler().getPlayerById(tradeHandler.getReceiver().getId()).getNumJailCard(); i++) {
numbers.add(i+"");
}
Selector<String> selector = new Selector<>(numbers, "glass");
styleSelector(selector);
return selector;
}
private Iterable<PropertyField> getPropertyFields(boolean isLeft) {
return app.getGameLogic()
.getBoardManager()
.getPropertyFields(app.getGameLogic()
.getPlayerHandler()
.getPlayerById(isLeft ? tradeHandler.getReceiver().getId() : tradeHandler.getSender().getId())
.getProperties());
}
private TextField createCurrencyInput() {
TextField currencyInput = new TextField("");
styleTextField(currencyInput);
return currencyInput;
}
/**
* Creates the middle section with selection fields and arrows.
*
* @return The middle section container.
*/
private Container createMiddleSection() {
Container middleSection = new Container(new SpringGridLayout(Axis.Y, Axis.X));
middleSection.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8f, 0.8f, 0.8f, 1.0f)));
// Add combined label for the top
Label middleLabelTop = middleSection.addChild(new Label("Gebäude: Währung: Sonderkarten:"));
middleLabelTop.setFontSize(24);
middleLabelTop.setInsets(new Insets3f(5, 5, 5, 5));
// Add the left selection field (Quellobjekte)
leftSelectionsField = middleSection.addChild(new TextField(""));
leftSelectionsField.setPreferredSize(new Vector3f(600, 50, 0));
// Add arrows
Label arrows = middleSection.addChild(new Label(""));
arrows.setFontSize(40);
// Add the right selection field (Zielobjekte)
rightSelectionsField = middleSection.addChild(new TextField(""));
rightSelectionsField.setPreferredSize(new Vector3f(600, 50, 0));
// Add combined label for the bottom
Label middleLabelBottom = middleSection.addChild(new Label("Gebäude: Währung: Sonderkarten:"));
middleLabelBottom.setFontSize(24);
middleLabelBottom.setInsets(new Insets3f(5, 5, 5, 5));
// Spacer
Label spacer = middleSection.addChild(new Label(""));
spacer.setPreferredSize(new Vector3f(1, 50, 0));
return middleSection;
}
private TextField createSelectionsField(Container parent, boolean isLeft) {
TextField field = new TextField("");
field.setPreferredSize(new Vector3f(600, 50, 0));
parent.addChild(field);
return field;
}
private Label createArrowLabel() {
Label arrowLabel = new Label("");
arrowLabel.setFontSize(40);
return arrowLabel;
}
private void styleSelector(Selector<String> selector) {
selector.setInsets(new Insets3f(5, 10, 5, 10));
selector.setBackground(new QuadBackgroundComponent(ColorRGBA.Black));
}
private void styleTextField(TextField textField) {
textField.setInsets(new Insets3f(5, 10, 5, 10));
textField.setBackground(new QuadBackgroundComponent(ColorRGBA.Black));
}
private void assignSelectors(Selector<String> buildingSelector, Selector<String> specialCardSelector, TextField currencyInput, boolean isLeft) {
if (isLeft) {
leftBuildingSelector = buildingSelector;
leftSpecialCardSelector = specialCardSelector;
leftCurrencyInput = currencyInput;
} else {
rightBuildingSelector = buildingSelector;
rightSpecialCardSelector = specialCardSelector;
rightCurrencyInput = currencyInput;
}
}
private void positionMainContainer() {
mainContainer.setLocalTranslation(
(app.getCamera().getWidth() - mainContainer.getPreferredSize().x) / 2,
(app.getCamera().getHeight() + mainContainer.getPreferredSize().y) / 2,
@@ -68,183 +232,6 @@ public class TradeMenu extends Dialog {
);
}
/**
* Creates a container for the header with a fixed size.
*
* @return The header container.
*/
private Container createHeaderContainer() {
// Create a container for the header
Container headerContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
headerContainer.setPreferredSize(new Vector3f(200, 100, 0)); // Set fixed width and height
// Add the header label
Label headerLabel = headerContainer.addChild(new Label("Handelsmenü", new ElementId("label-Bold")));
headerLabel.setFontSize(50); // Adjust font size as needed
headerLabel.setInsets(new Insets3f(10, 10, 10, 10)); // Add padding around the label
headerLabel.setBackground(new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f))); // Optional background
return headerContainer;
}
/**
* Creates the main content layout (left, middle, right columns).
*
* @return The main content container.
*/
private Container createMainContent() {
Container mainContent = new Container(new SpringGridLayout(Axis.X, Axis.Y));
mainContent.setPreferredSize(new Vector3f(1200, 700, 0));
// Left Column
mainContent.addChild(createTradeColumn("Wähle Handelsobjekt:", true));
// Middle Section
Container middleSection = mainContent.addChild(new Container(new SpringGridLayout(Axis.Y, Axis.X)));
middleSection.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8f, 0.8f, 0.8f, 1.0f)));
// Add combined label
Label middleLabel = middleSection.addChild(new Label("Gebäude: Währung: Sonderkarten:"));
middleLabel.setFontSize(24); // Adjust font size as needed
middleLabel.setInsets(new Insets3f(5, 5, 5, 5)); // Add padding around the label
// Add the Quellobjekte TextField
leftSelectionsField = middleSection.addChild(new TextField(""));
leftSelectionsField.setPreferredSize(new Vector3f(600, 50, 0)); // Larger width to fit the split sections
addCustomSelectionListener(leftBuildingSelector, newSelection -> updateSelectionsField(leftSelectionsField, leftBuildingSelector, leftCurrencyInput, leftSpecialCardSelector));
addCustomSelectionListener(leftSpecialCardSelector, newSelection -> updateSelectionsField(leftSelectionsField, leftBuildingSelector, leftCurrencyInput, leftSpecialCardSelector));
// Add change listener for the currency input
monitorTextFieldChanges(leftCurrencyInput, () -> updateSelectionsField(leftSelectionsField, leftBuildingSelector, leftCurrencyInput, leftSpecialCardSelector));
Label arrows = middleSection.addChild(new Label(""));
arrows.setFontSize(40);
// Right Column
mainContent.addChild(createTradeColumn("Wähle Zielobjekt:", false));
// Add combined label
middleLabel = middleSection.addChild(new Label("Gebäude: Währung: Sonderkarten:"));
middleLabel.setFontSize(24); // Adjust font size as needed
middleLabel.setInsets(new Insets3f(5, 5, 5, 5)); // Add padding around the label
// Add the Zielobjekte TextField
rightSelectionsField = middleSection.addChild(new TextField(""));
rightSelectionsField.setPreferredSize(new Vector3f(600, 50, 0));
addCustomSelectionListener(rightBuildingSelector, newSelection -> updateSelectionsField(rightSelectionsField, rightBuildingSelector, rightCurrencyInput, rightSpecialCardSelector));
addCustomSelectionListener(rightSpecialCardSelector, newSelection -> updateSelectionsField(rightSelectionsField, rightBuildingSelector, rightCurrencyInput, rightSpecialCardSelector));
// Add change listener for the currency input
monitorTextFieldChanges(rightCurrencyInput, () -> updateSelectionsField(rightSelectionsField, rightBuildingSelector, rightCurrencyInput, rightSpecialCardSelector));
// "Bestätigen" button
lowerRightMenu = new Container();
tradeButton.setPreferredSize(new Vector3f(200, 60, 0));
tradeButton.setFontSize(30);
tradeButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON);
close();
new TradeMenu(app).open();
}));
lowerRightMenu.addChild(tradeButton);
// Position the container near the bottom-right corner
lowerRightMenu.setLocalTranslation(new Vector3f(app.getCamera().getWidth() - 680, 100, 8)); // X: 220px from the right, Y: 50px above the bottom
app.getGuiNode().attachChild(lowerRightMenu);
Label spacer = middleSection.addChild(new Label("")); // Spacer
spacer.setPreferredSize(new Vector3f(1, 50, 0));
return mainContent;
}
/**
* Creates a column for trade objects (left or right side).
*
* @param label The label for the column.
* @param isLeft Whether this column is the left side.
* @return The column container.
*/
private Container createTradeColumn(String label, boolean isLeft) {
Container column = new Container(new SpringGridLayout(Axis.Y, Axis.X));
column.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.White)));
Label columnLabel = column.addChild(new Label(label));
columnLabel.setFontSize(24);
columnLabel.setBackground(translucentWhiteBackground);
// Add dropdowns
column.addChild(new Label("Gebäude:"));
Selector<String> buildingSelector = column.addChild(new Selector<>(getSampleItems(),"glass"));
buildingSelector.setInsets(new Insets3f(5, 10, 5, 10));
buildingSelector.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black)));
column.addChild(new Label("Währung:"));
TextField currencyInput = column.addChild(new TextField(""));
currencyInput.setInsets(new Insets3f(5, 10, 5, 10));
currencyInput.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black)));
column.addChild(new Label("Sonderkarten:"));
Selector<String> specialCardSelector = column.addChild(new Selector<>(getSampleItems(),"glass"));
specialCardSelector.setInsets(new Insets3f(5, 10, 5, 10));
specialCardSelector.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black)));
// Assign selectors to corresponding fields
if (isLeft) {
leftBuildingSelector = buildingSelector;
leftSpecialCardSelector = specialCardSelector;
leftCurrencyInput = currencyInput;
// "Abbrechen" button
lowerLeftMenu = new Container();
cancelButton.setPreferredSize(new Vector3f(200, 60, 0));
cancelButton.setFontSize(30);
cancelButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON);
this.close();
}));
lowerLeftMenu.addChild(cancelButton);
// Position the container near the bottom-left corner
lowerLeftMenu.setLocalTranslation(new Vector3f(50, 100, 8)); // Adjust X and Y to align with the bottom-left corner
app.getGuiNode().attachChild(lowerLeftMenu);
Label spacer = column.addChild(new Label("")); // Spacer
spacer.setPreferredSize(new Vector3f(1, 130, 0));
} else {
rightBuildingSelector = buildingSelector;
rightSpecialCardSelector = specialCardSelector;
rightCurrencyInput = currencyInput;
Label spacer = column.addChild(new Label("")); // Spacer
spacer.setPreferredSize(new Vector3f(1, 130, 0));
}
return column;
}
/**
* Provides sample dropdown items.
*/
private VersionedList<String> getSampleItems() {
VersionedList<String> items = new VersionedList<>();
items.add("Option 1");
items.add("Option 2");
items.add("Option 3");
return items;
}
/**
* Adds a background image to the dialog.
*/
private void addBackgroundImage() {
Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/unibw-Bib2.png");
Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight());
@@ -252,131 +239,18 @@ public class TradeMenu extends Dialog {
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
background.setLocalTranslation(0, 0, 6);
app.getGuiNode().attachChild(background);
}
private String truncateText(String text, int maxLength) {
return text.length() > maxLength ? text.substring(0, maxLength) + "..." : text;
}
private void updateSelectionsField(TextField selectionsField, Selector<String> buildingSelector, TextField currencyInput, Selector<String> specialCardSelector) {
// Get selections from the building selector
String buildingSelections = buildingSelector != null && buildingSelector.getSelectedItem() != null
? buildingSelector.getSelectedItem().trim()
: "";
// Get text from the currency input
String currencySelections = currencyInput != null
? currencyInput.getText().trim()
: "";
// Get selections from the special card selector
String specialCardSelections = specialCardSelector != null && specialCardSelector.getSelectedItem() != null
? specialCardSelector.getSelectedItem().trim()
: "";
// Build the combined text without adding unnecessary spaces
StringBuilder combinedText = new StringBuilder();
if (!buildingSelections.isEmpty()) {
combinedText.append(buildingSelections);
}
if (!currencySelections.isEmpty()) {
if (combinedText.length() > 0) {
combinedText.append(" | "); // Add a separator if there's already text
}
combinedText.append(currencySelections);
}
if (!specialCardSelections.isEmpty()) {
if (combinedText.length() > 0) {
combinedText.append(" | "); // Add a separator if there's already text
}
combinedText.append(specialCardSelections);
}
// Update the content of the TextField
selectionsField.setText(combinedText.toString());
}
/**
* Handles the escape action for the dialog.
*/
@Override
public void escape() {
new SettingsMenu(app).open();
}
/**
* Updates the dialog periodically, called by the dialog manager.
*
* @param delta The time elapsed since the last update.
*/
@Override
public void update(float delta) {
// Periodic updates (if needed) can be implemented here
public void close() {
app.getGuiNode().detachChild(mainContainer);
super.close();
}
/**
* Functional interface for a selection action listener.
*/
@FunctionalInterface
private interface SelectionActionListener<T> {
void onSelectionChanged(T selection);
}
/**
* Adds a custom action listener to the Selector.
*/
private void addCustomSelectionListener(Selector<String> selector, SelectionActionListener<String> listener) {
VersionedReference<Set<Integer>> selectionRef = selector.getSelectionModel().createReference();
app.getStateManager().attach(new BaseAppState() {
@Override
public void update(float tpf) {
if (selectionRef.update()) {
String selected = selector.getSelectedItem();
listener.onSelectionChanged(selected);
}
}
@Override
protected void initialize(Application app) {}
@Override
protected void cleanup(Application app) {}
@Override
protected void onEnable() {}
@Override
protected void onDisable() {}
});
}
private void monitorTextFieldChanges(TextField textField, Runnable onChange) {
VersionedReference<DocumentModel> ref = textField.getDocumentModel().createReference();
app.getStateManager().attach(new BaseAppState() {
@Override
public void update(float tpf) {
if (ref.update()) {
onChange.run();
}
}
@Override
protected void initialize(Application app) {}
@Override
protected void cleanup(Application app) {}
@Override
protected void onEnable() {}
@Override
protected void onDisable() {}
});
}
}

View File

@@ -9,7 +9,7 @@ import com.simsilica.lemur.style.ElementId;
import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp;
import pp.monopoly.client.gui.SettingsMenu;
import pp.monopoly.message.client.BuyPropertyRequest;
import pp.monopoly.message.client.BuyPropertyResponse;
import pp.monopoly.model.fields.BoardManager;
import pp.monopoly.model.fields.BuildingProperty;
import pp.monopoly.notification.Sound;
@@ -28,7 +28,7 @@ public class BuyCard extends Dialog {
this.app = app;
//Generate the corresponfing field
int index = app.getGameLogic().getPlayerHandler().getPlayers().get(0).getFieldID();
int index = app.getGameLogic().getPlayerHandler().getPlayers().get(0).getFieldID();;
BuildingProperty field = (BuildingProperty) new BoardManager().getFieldAtIndex(index);
// Create the background container
@@ -64,6 +64,7 @@ public class BuyCard extends Dialog {
Button quitButton = buyCardContainer.addChild(new Button("Beenden", new ElementId("button")));
quitButton.setFontSize(32);
quitButton.addClickCommands(s -> ifTopDialog(() -> {
System.err.println("Button does something?");
app.getGameLogic().playSound(Sound.BUTTON);
close();
}));
@@ -72,7 +73,8 @@ public class BuyCard extends Dialog {
buyButton.setFontSize(32);
buyButton.addClickCommands(s -> ifTopDialog( () -> {
app.getGameLogic().playSound(Sound.BUTTON);
app.getGameLogic().send(new BuyPropertyRequest());
close();
app.getGameLogic().send(new BuyPropertyResponse());
}));
float padding = 10; // Padding around the settingsContainer for the background

View File

@@ -0,0 +1,116 @@
package pp.monopoly.client.gui.popups;
import com.jme3.math.ColorRGBA;
import com.simsilica.lemur.Button;
import com.simsilica.lemur.Container;
import com.simsilica.lemur.Label;
import com.simsilica.lemur.component.QuadBackgroundComponent;
import com.simsilica.lemur.style.ElementId;
import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp;
import pp.monopoly.client.gui.SettingsMenu;
import pp.monopoly.notification.Sound;
/**
* SettingsMenu ist ein Overlay-Menü, das durch ESC aufgerufen werden kann.
*/
public class ConfirmTrade extends Dialog {
private final MonopolyApp app;
private final Container confirmTradeContainer;
private final Container backgroundContainer;
public ConfirmTrade(MonopolyApp app) {
super(app.getDialogManager());
this.app = app;
//Generate the corresponfing field
//int index = app.getGameLogic().getPlayerHandler().getPlayers().get(0).getFieldID();;
// BuildingProperty field = (BuildingProperty) new BoardManager().getFieldAtIndex(index);
// Create the background container
backgroundContainer = new Container();
backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background
attachChild(backgroundContainer);
// Hauptcontainer für die Gebäudekarte
confirmTradeContainer = new Container();
Label title = confirmTradeContainer.addChild(new Label( "Handel", new ElementId("label-Bold"))); //TODO ggf die Buttons Sprachabhängig von den Properties machen
title.setFontSize(48);
title.setColor(ColorRGBA.Black);
// Text, der auf der Karte steht
// Die Preise werden dynamisch dem BoardManager entnommen
Container propertyValuesContainer = confirmTradeContainer.addChild(new Container());
propertyValuesContainer.addChild(new Label("„Spieler XXX möchte:", new ElementId("label-Text"))); //TODO hier überall die entsprechenden Variablen einfügen
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text")));// Leerzeile
propertyValuesContainer.addChild(new Label("- XXX Gebäude", new ElementId("label-Text")));
propertyValuesContainer.addChild(new Label("- XXX EUR", new ElementId("label-Text")));
propertyValuesContainer.addChild(new Label("- XXX Sonderkaten", new ElementId("label-Text")));
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text")));// Leerzeile
propertyValuesContainer.addChild(new Label("gegen:", new ElementId("label-Text")));
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text")));// Leerzeile
propertyValuesContainer.addChild(new Label("- XXX Gebäude", new ElementId("label-Text")));
propertyValuesContainer.addChild(new Label("- XXX EUR", new ElementId("label-Text")));
propertyValuesContainer.addChild(new Label("- XXX Sonderkaten", new ElementId("label-Text")));
propertyValuesContainer.addChild(new Label("", new ElementId("label-Text")));// Leerzeile
propertyValuesContainer.addChild(new Label("tauschen, willst du das Angebot annehmen?", new ElementId("label-Text")));
propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
// Beenden-Button
Button declineButton = confirmTradeContainer.addChild(new Button("Ablehnen", new ElementId("button"))); //TODO ggf die Buttons Sprachabhängig von den Properties machen
declineButton.setFontSize(32);
declineButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON);
close();
}));
// Kaufen-Button
Button negotiateButton = confirmTradeContainer.addChild(new Button("Verhandeln", new ElementId("button"))); //TODO ggf die Buttons Sprachabhängig von den Properties machen
negotiateButton.setFontSize(32);
negotiateButton.addClickCommands(s -> ifTopDialog( () -> {
app.getGameLogic().playSound(Sound.BUTTON);
}));
// Kaufen-Button
Button confirmButton = confirmTradeContainer.addChild(new Button("Bestätigen", new ElementId("button"))); //TODO ggf die Buttons Sprachabhängig von den Properties machen
confirmButton.setFontSize(32);
confirmButton.addClickCommands(s -> ifTopDialog( () -> {
app.getGameLogic().playSound(Sound.BUTTON);
}));
float padding = 10; // Padding around the settingsContainer for the background
backgroundContainer.setPreferredSize(confirmTradeContainer.getPreferredSize().addLocal(padding, padding, 0));
// Zentriere das Menü
confirmTradeContainer.setLocalTranslation(
(app.getCamera().getWidth() - confirmTradeContainer.getPreferredSize().x) / 2,
(app.getCamera().getHeight() + confirmTradeContainer.getPreferredSize().y) / 2,
8
);
backgroundContainer.setLocalTranslation(
(app.getCamera().getWidth() - confirmTradeContainer.getPreferredSize().x - padding) / 2,
(app.getCamera().getHeight() + confirmTradeContainer.getPreferredSize().y+ padding) / 2,
7
);
app.getGuiNode().attachChild(confirmTradeContainer);
}
/**
* Schließt das Menü und entfernt die GUI-Elemente.
*/
@Override
public void close() {
app.getGuiNode().detachChild(confirmTradeContainer); // Entferne das Menü
app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand
super.close();
}
@Override
public void escape() {
new SettingsMenu(app).open();
}
}

View File

@@ -14,7 +14,7 @@ import com.simsilica.lemur.style.ElementId;
import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp;
import pp.monopoly.client.gui.SettingsMenu;
import pp.monopoly.message.client.BuyPropertyRequest;
import pp.monopoly.message.client.BuyPropertyResponse;
import pp.monopoly.model.fields.FoodField;
import pp.monopoly.notification.Sound;
@@ -83,7 +83,7 @@ public class FoodFieldCard extends Dialog {
buyButton.setFontSize(32);
buyButton.addClickCommands(s -> ifTopDialog( () -> {
app.getGameLogic().playSound(Sound.BUTTON);
app.getGameLogic().send(new BuyPropertyRequest());
app.getGameLogic().send(new BuyPropertyResponse());
}));
float padding = 10; // Padding around the settingsContainer for the background

View File

@@ -13,7 +13,7 @@ import com.simsilica.lemur.style.ElementId;
import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp;
import pp.monopoly.client.gui.SettingsMenu;
import pp.monopoly.message.client.BuyPropertyRequest;
import pp.monopoly.message.client.BuyPropertyResponse;
import pp.monopoly.model.fields.GateField;
import pp.monopoly.notification.Sound;
@@ -78,7 +78,7 @@ public class GateFieldCard extends Dialog {
buyButton.setFontSize(32);
buyButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON);
app.getGameLogic().send(new BuyPropertyRequest());
app.getGameLogic().send(new BuyPropertyResponse());
close();
}));

View File

@@ -0,0 +1,117 @@
package pp.monopoly.client.gui.popups;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.simsilica.lemur.Button;
import com.simsilica.lemur.Container;
import com.simsilica.lemur.Label;
import com.simsilica.lemur.component.IconComponent;
import com.simsilica.lemur.component.QuadBackgroundComponent;
import com.simsilica.lemur.style.ElementId;
import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp;
import pp.monopoly.client.gui.SettingsMenu;
import pp.monopoly.message.client.BuyPropertyResponse;
import pp.monopoly.notification.Sound;
/**
* SettingsMenu ist ein Overlay-Menü, das durch ESC aufgerufen werden kann.
*/
public class SellHouse extends Dialog {
private final MonopolyApp app;
private final Container sellhouseContainer;
private final Container backgroundContainer;
public SellHouse(MonopolyApp app) {
super(app.getDialogManager());
this.app = app;
//Generate the corresponfing field
//int index = app.getGameLogic().getPlayerHandler().getPlayers().get(0).getFieldID();;
// BuildingProperty field = (BuildingProperty) new BoardManager().getFieldAtIndex(index);
// Create the background container
backgroundContainer = new Container();
backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background
attachChild(backgroundContainer);
// Hauptcontainer für die Gebäudekarte
sellhouseContainer = new Container();
Label title = sellhouseContainer.addChild(new Label( "Gebäude Abreißen", new ElementId("label-Bold"))); //TODO ggf die Buttons Sprachabhängig von den Properties machen
title.setFontSize(48);
title.setColor(ColorRGBA.Black);
Container upContainer = sellhouseContainer.addChild(new Container());
Container middleContainer = sellhouseContainer.addChild(new Container());
Container downContainer = sellhouseContainer.addChild(new Container());
// Text, der auf der Karte steht
// Die Preise werden dynamisch dem BoardManager entnommen
upContainer.addChild(new Label("„Grundstück wählen:", new ElementId("label-Text"))); //TODO hier überall die entsprechenden Variablen einfügen
upContainer.addChild(new Label("", new ElementId("label-Text")));// Leerzeile
upContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
middleContainer.setPreferredSize(new Vector3f(100, 150, 0));
middleContainer.setBackground(new QuadBackgroundComponent(ColorRGBA.Red));
middleContainer.addChild(new Label("Dies ist ein Container", new ElementId("label-Text")));
middleContainer.addChild(new Label("", new ElementId("label-Text")));
middleContainer.addChild(new Label("Hier kann der Slider und die Checkbocen eingefügt werden", new ElementId("label-Text")));
downContainer.addChild(new Label("", new ElementId("label-Text")));// Leerzeile
downContainer.addChild(new Label("Erstattung:", new ElementId("label-Text")));// Leerzeile
downContainer.addChild(new Label("Hier die tätsächliche Erstattung", new ElementId("label-Text")));
downContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
// Beenden-Button
Button cancelButton = sellhouseContainer.addChild(new Button("Abbrechen", new ElementId("button"))); //TODO ggf die Buttons Sprachabhängig von den Properties machen
cancelButton.setFontSize(32);
cancelButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON);
close();
}));
// Kaufen-Button
Button confirmButton = sellhouseContainer.addChild(new Button("Bestätigen", new ElementId("button"))); //TODO ggf die Buttons Sprachabhängig von den Properties machen
confirmButton.setFontSize(32);
confirmButton.addClickCommands(s -> ifTopDialog( () -> {
app.getGameLogic().playSound(Sound.BUTTON);
//TODO
}));
float padding = 10; // Padding around the settingsContainer for the background
backgroundContainer.setPreferredSize(sellhouseContainer.getPreferredSize().addLocal(padding, padding, 0));
// Zentriere das Menü
sellhouseContainer.setLocalTranslation(
(app.getCamera().getWidth() - sellhouseContainer.getPreferredSize().x) / 2,
(app.getCamera().getHeight() + sellhouseContainer.getPreferredSize().y) / 2,
8
);
backgroundContainer.setLocalTranslation(
(app.getCamera().getWidth() - sellhouseContainer.getPreferredSize().x - padding) / 2,
(app.getCamera().getHeight() + sellhouseContainer.getPreferredSize().y+ padding) / 2,
7
);
app.getGuiNode().attachChild(sellhouseContainer);
}
/**
* Schließt das Menü und entfernt die GUI-Elemente.
*/
@Override
public void close() {
app.getGuiNode().detachChild(sellhouseContainer); // Entferne das Menü
app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand
super.close();
}
@Override
public void escape() {
new SettingsMenu(app).open();
}
}