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

View File

@ -71,6 +71,11 @@ selector("label-Text", "pp") {
color = buttonEnabledColor color = buttonEnabledColor
} }
selector("card-label", "pp") {
insets = new Insets3f(2, 2, 2, 2)
color = ColorRGBA.Black
}
selector("header", "pp") { selector("header", "pp") {
font = font("Interface/Fonts/Metropolis/Metropolis-Bold-42.fnt") font = font("Interface/Fonts/Metropolis/Metropolis-Bold-42.fnt")
insets = new Insets3f(2, 2, 2, 2) insets = new Insets3f(2, 2, 2, 2)
@ -292,3 +297,44 @@ selector("selector.item.label", "hover") {
background = new QuadBackgroundComponent(new ColorRGBA(0.2f, 0.6f, 1.0f, 0.9f)) // Highlighted background background = new QuadBackgroundComponent(new ColorRGBA(0.2f, 0.6f, 1.0f, 0.9f)) // Highlighted background
} }
def enabledCommandToolbar = new Command<Button>() {
void execute(Button source) {
if (source.isEnabled()){
source.setColor(ColorRGBA.White)
def orangeBackground = new QuadBackgroundComponent(color(1, 0.5, 0, 1)); // Orange background
source.setBackground(orangeBackground);
} else{
source.setColor(ColorRGBA.White)
def grayBackground = new QuadBackgroundComponent(ColorRGBA.Gray); // Gray background
source.setBackground(grayBackground);
}
}
}
def stdButtonCommandsToolbar = [
(ButtonAction.Down) : [pressedCommand],
(ButtonAction.Up) : [pressedCommand],
(ButtonAction.Enabled) : [enabledCommandToolbar],
(ButtonAction.Disabled): [enabledCommandToolbar]
]
selector("button-toolbar", "pp") {
def outerBackground = new QuadBackgroundComponent(color(1, 0.5, 0, 1)) // Orange border
def innerBackground = new QuadBackgroundComponent(buttonBgColor) // Inner button background
// Apply the outer border as the main background
background = outerBackground
// Use insets to create a margin/padding effect for the inner background
insets = new Insets3f(3, 3, 3, 3) // Adjust the border thickness
textHAlignment = HAlignment.Center
textVAlignment = VAlignment.Center
buttonCommands = stdButtonCommandsToolbar
}

View File

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

View File

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

View File

@ -2,27 +2,23 @@ package pp.monopoly.client.gui;
import java.util.Set; import java.util.Set;
import com.jme3.app.Application;
import com.jme3.app.state.BaseAppState;
import com.jme3.material.Material; import com.jme3.material.Material;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry; import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Quad; import com.jme3.scene.shape.Quad;
import com.jme3.texture.Texture; import com.jme3.texture.Texture;
import com.simsilica.lemur.Axis; import com.simsilica.lemur.*;
import com.simsilica.lemur.Button;
import com.simsilica.lemur.Container;
import com.simsilica.lemur.Label;
import com.simsilica.lemur.Selector;
import com.simsilica.lemur.component.QuadBackgroundComponent; import com.simsilica.lemur.component.QuadBackgroundComponent;
import com.simsilica.lemur.component.SpringGridLayout; import com.simsilica.lemur.component.SpringGridLayout;
import com.simsilica.lemur.core.VersionedList; import com.simsilica.lemur.core.VersionedList;
import com.simsilica.lemur.core.VersionedReference; import com.simsilica.lemur.core.VersionedReference;
import com.simsilica.lemur.style.ElementId; import com.simsilica.lemur.style.ElementId;
import pp.dialog.Dialog; import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp; import pp.monopoly.client.MonopolyApp;
import pp.monopoly.game.server.Player; import pp.monopoly.game.server.Player;
import pp.monopoly.message.client.ViewAssetsRequest;
import pp.monopoly.model.TradeHandler; import pp.monopoly.model.TradeHandler;
import pp.monopoly.notification.Sound; import pp.monopoly.notification.Sound;
@ -36,6 +32,9 @@ public class ChoosePartner extends Dialog {
private Container lowerRightMenu; private Container lowerRightMenu;
private Geometry background; private Geometry background;
private TradeHandler tradeHandler; 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 = QuadBackgroundComponent translucentWhiteBackground =
new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f)); new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f));
@ -48,6 +47,7 @@ public class ChoosePartner extends Dialog {
super(app.getDialogManager()); super(app.getDialogManager());
this.app = app; this.app = app;
tradeHandler = new TradeHandler(app.getGameLogic().getPlayerHandler().getPlayerById(app.getId())); tradeHandler = new TradeHandler(app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()));
app.getGameLogic().send(new ViewAssetsRequest());
// Background Image // Background Image
addBackgroundImage(); addBackgroundImage();
@ -68,8 +68,6 @@ public class ChoosePartner extends Dialog {
// Add buttons // Add buttons
mainContainer.addChild(createButtonContainer()); mainContainer.addChild(createButtonContainer());
addSelectionActionListener(playerSelector, this::onDropdownSelectionChanged);
// Attach main container to GUI node // Attach main container to GUI node
app.getGuiNode().attachChild(mainContainer); app.getGuiNode().attachChild(mainContainer);
mainContainer.setLocalTranslation( mainContainer.setLocalTranslation(
@ -77,6 +75,9 @@ public class ChoosePartner extends Dialog {
(app.getCamera().getHeight() + mainContainer.getPreferredSize().y) / 2, (app.getCamera().getHeight() + mainContainer.getPreferredSize().y) / 2,
4 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()) { for (Player player : app.getGameLogic().getPlayerHandler().getPlayers()) {
if (player.getId() != app.getId()) { 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); dropdownContainer.addChild(playerSelector);
Vector3f dimens = dropdownContainer.getPreferredSize(); Vector3f dimens = dropdownContainer.getPreferredSize();
Vector3f dimens2 = playerSelector.getPopupContainer().getPreferredSize(); Vector3f dimens2 = playerSelector.getPopupContainer().getPreferredSize();
dimens2.setX( dimens.getX() ); dimens2.setX(dimens.getX());
playerSelector.getPopupContainer().setPreferredSize(new Vector3f(200,200,3)); playerSelector.getPopupContainer().setPreferredSize(new Vector3f(200, 200, 3));
playerSelector.setLocalTranslation(0,0,5); playerSelector.setLocalTranslation(0, 0, 5);
onDropdownSelectionChanged(playerOptions.get(0));
// Set initial selection
if (!playerOptions.isEmpty()) {
onDropdownSelectionChanged(playerOptions.get(0));
}
return dropdownContainer; 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 lowerLeftMenu.setLocalTranslation(new Vector3f(120, 170, 5)); // Adjust X and Y to align with the bottom-left corner
app.getGuiNode().attachChild(lowerLeftMenu); app.getGuiNode().attachChild(lowerLeftMenu);
// "Bestätigen" button // "Bestätigen" button
lowerRightMenu = new Container(); lowerRightMenu = new Container();
confirmButton.setPreferredSize(new Vector3f(200, 60, 0)); confirmButton.setPreferredSize(new Vector3f(200, 60, 0));
@ -140,7 +144,7 @@ public class ChoosePartner extends Dialog {
confirmButton.addClickCommands(s -> ifTopDialog(() -> { confirmButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON); app.getGameLogic().playSound(Sound.BUTTON);
close(); close();
new TradeMenu(app).open(); new TradeMenu(app, tradeHandler).open();
})); }));
lowerRightMenu.addChild(confirmButton); 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 lowerRightMenu.setLocalTranslation(new Vector3f(app.getCamera().getWidth() - 320, 170, 5)); // X: 220px from the right, Y: 50px above the bottom
app.getGuiNode().attachChild(lowerRightMenu); app.getGuiNode().attachChild(lowerRightMenu);
return buttonContainer; return buttonContainer;
} }
@ -181,7 +184,14 @@ public class ChoosePartner extends Dialog {
*/ */
@Override @Override
public void update(float delta) { 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 @Override
@ -194,42 +204,6 @@ public class ChoosePartner extends Dialog {
super.close(); 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. * 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 int idEnd = selected.indexOf(")", idStart); // Find end of the ID
String idStr = selected.substring(idStart, idEnd); // Extract the ID as a string String idStr = selected.substring(idStart, idEnd); // Extract the ID as a string
int playerId = Integer.parseInt(idStr); // Convert the ID to an integer int playerId = Integer.parseInt(idStr); // Convert the ID to an integer
// Find the player by ID // Find the player by ID
Player selectedPlayer = app.getGameLogic().getPlayerHandler().getPlayerById(playerId); Player selectedPlayer = app.getGameLogic().getPlayerHandler().getPlayerById(playerId);
if (selectedPlayer != null) { if (selectedPlayer != null) {
tradeHandler.setReceiver(selectedPlayer); // Set the receiver in TradeHandler 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 java.util.List;
import pp.monopoly.client.MonopolyApp; 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.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. * TestWorld zeigt eine einfache Szene mit Spielfeld und Spielfiguren.
@ -113,4 +125,23 @@ public class TestWorld {
cameraController.update(tpf); // Aktualisiere die Kameraposition 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.game.server.PlayerHandler;
import pp.monopoly.message.client.EndTurn; import pp.monopoly.message.client.EndTurn;
import pp.monopoly.message.client.RollDice; import pp.monopoly.message.client.RollDice;
import pp.monopoly.notification.DiceRollEvent; import pp.monopoly.notification.*;
import pp.monopoly.notification.GameEventListener;
import pp.monopoly.notification.Sound;
import pp.monopoly.notification.UpdatePlayerView;
public class Toolbar extends Dialog implements GameEventListener { public class Toolbar extends Dialog implements GameEventListener {
private final MonopolyApp app; private final MonopolyApp app;
private final Container toolbarContainer; private final Container toolbarContainer;
private Label imageLabel;
private Label imageLabel2;
private Container overviewContainer; private Container overviewContainer;
private Container accountContainer; private Container accountContainer;
private PlayerHandler playerHandler; 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 boolean animatingDice = false;
private volatile DiceRollEvent latestDiceRollEvent = null; private volatile DiceRollEvent latestDiceRollEvent = null;
@ -40,73 +42,82 @@ public class Toolbar extends Dialog implements GameEventListener {
this.app = app; this.app = app;
app.getGameLogic().addListener(this); app.getGameLogic().addListener(this);
playerHandler = app.getGameLogic().getPlayerHandler(); this.playerHandler = app.getGameLogic().getPlayerHandler();
// Erstelle die Toolbar toolbarContainer = createToolbarContainer();
toolbarContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y), "toolbar"); app.getGuiNode().attachChild(toolbarContainer);
toolbarContainer.setLocalTranslation(0, 200, 0); }
toolbarContainer.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 200, 0));
// Account- und Übersichtskontainer private Container createToolbarContainer() {
accountContainer = toolbarContainer.addChild(new Container()); Container container = new Container(new SpringGridLayout(Axis.X, Axis.Y), "toolbar");
overviewContainer = toolbarContainer.addChild(new Container()); 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()); receivedEvent(new UpdatePlayerView());
overviewContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); // Dice section
container.addChild(createDiceSection());
// Würfelbereich // Action menu
Container diceContainer = toolbarContainer.addChild(new Container()); Container menuContainer = container.addChild(new Container());
diceContainer.setLayout(new SpringGridLayout(Axis.X, Axis.Y)); menuContainer.addChild(createTradeButton());
menuContainer.addChild(createPropertyMenuButton());
menuContainer.addChild(createEndTurnButton());
menuContainer.setBackground(createBackground());
Container horizontalContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y)); return container;
horizontalContainer.setPreferredSize(new Vector3f(200, 150, 0)); }
// Linker Würfel private Container createDiceSection() {
Container leftContainer = new Container(); Container diceContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
leftContainer.setPreferredSize(new Vector3f(100, 150, 0)); diceContainer.addChild(createDiceDisplay());
imageLabel = new Label("");
IconComponent icon = new IconComponent("Pictures/dice/one.png");
icon.setIconSize(new Vector2f(100, 100));
imageLabel.setIcon(icon);
// Rechter Würfel diceButton = new Button("Würfeln", new ElementId("button-toolbar"));
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.setPreferredSize(new Vector3f(200, 50, 0)); diceButton.setPreferredSize(new Vector3f(200, 50, 0));
diceButton.addClickCommands(s -> ifTopDialog(() -> { diceButton.addClickCommands(s -> ifTopDialog(() -> {
diceButton.setEnabled(false);
startDiceAnimation(); startDiceAnimation();
app.getGameLogic().send(new RollDice()); app.getGameLogic().send(new RollDice());
app.getGameLogic().playSound(Sound.BUTTON); app.getGameLogic().playSound(Sound.BUTTON);
})); }));
diceContainer.addChild(diceButton); diceContainer.addChild(diceButton);
// Menü-Container für weitere Aktionen return diceContainer;
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);
} }
private Button addTradeMenuButton() { private Container createDiceDisplay() {
Button tradeButton = new Button("Handeln"); 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.setPreferredSize(new Vector3f(150, 50, 0));
tradeButton.addClickCommands(s -> ifTopDialog(() -> { tradeButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON); app.getGameLogic().playSound(Sound.BUTTON);
@ -115,8 +126,8 @@ public class Toolbar extends Dialog implements GameEventListener {
return tradeButton; return tradeButton;
} }
private Button addPropertyMenuButton() { private Button createPropertyMenuButton() {
Button propertyMenuButton = new Button("Grundstücke"); propertyMenuButton = new Button("Grundstücke", new ElementId("button-toolbar"));
propertyMenuButton.setPreferredSize(new Vector3f(150, 50, 0)); propertyMenuButton.setPreferredSize(new Vector3f(150, 50, 0));
propertyMenuButton.setFontSize(30); propertyMenuButton.setFontSize(30);
propertyMenuButton.addClickCommands(s -> ifTopDialog(() -> { propertyMenuButton.addClickCommands(s -> ifTopDialog(() -> {
@ -126,20 +137,23 @@ public class Toolbar extends Dialog implements GameEventListener {
return propertyMenuButton; return propertyMenuButton;
} }
private Button addEndTurnButton() { private Button createEndTurnButton() {
Button endTurnButton = new Button("Zug beenden"); endTurnButton = new Button("Zug beenden", new ElementId("button-toolbar"));
endTurnButton.setPreferredSize(new Vector3f(150, 50, 0)); endTurnButton.setPreferredSize(new Vector3f(150, 50, 0));
endTurnButton.addClickCommands(s -> ifTopDialog(() -> { endTurnButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON); app.getGameLogic().playSound(Sound.BUTTON);
app.getGameLogic().send(new EndTurn()); app.getGameLogic().send(new EndTurn());
receivedEvent(new ButtonStatusEvent(false));
})); }));
return endTurnButton; return endTurnButton;
} }
private QuadBackgroundComponent createBackground() {
return new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f));
}
private void startDiceAnimation() { private void startDiceAnimation() {
animatingDice = true; animatingDice = true;
// Starte die Animation und speichere die Startzeit
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
Thread diceAnimation = new Thread(() -> { Thread diceAnimation = new Thread(() -> {
@ -165,48 +179,66 @@ public class Toolbar extends Dialog implements GameEventListener {
// Animation beenden // Animation beenden
animatingDice = false; animatingDice = false;
// Zeige das finale Ergebnis
if (latestDiceRollEvent != null) { if (latestDiceRollEvent != null) {
showFinalDiceResult(latestDiceRollEvent); showFinalDiceResult(latestDiceRollEvent);
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
System.err.println("Würfelanimation unterbrochen: " + e.getMessage()); System.err.println("Dice animation interrupted: " + e.getMessage());
} }
}); }).start();
diceAnimation.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) { private void showFinalDiceResult(DiceRollEvent event) {
int diceRoll1 = event.a(); app.enqueue(() -> {
int diceRoll2 = event.b(); 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); private String diceToString(int i) {
String finalImage2 = diceToString(diceRoll2); switch (i) {
case 1: return "Pictures/dice/one.png";
IconComponent finalIcon1 = new IconComponent(finalImage1); case 2: return "Pictures/dice/two.png";
finalIcon1.setIconSize(new Vector2f(100, 100)); case 3: return "Pictures/dice/three.png";
app.enqueue(() -> imageLabel.setIcon(finalIcon1)); case 4: return "Pictures/dice/four.png";
case 5: return "Pictures/dice/five.png";
IconComponent finalIcon2 = new IconComponent(finalImage2); case 6: return "Pictures/dice/six.png";
finalIcon2.setIconSize(new Vector2f(100, 100)); default: throw new IllegalArgumentException("Invalid dice number: " + i);
app.enqueue(() -> imageLabel2.setIcon(finalIcon2)); }
app.getGameLogic().playSound(Sound.BUTTON);
} }
@Override @Override
public void receivedEvent(DiceRollEvent event) { public void receivedEvent(DiceRollEvent event) {
latestDiceRollEvent = event; // Speichere das Event latestDiceRollEvent = event;
} }
@Override @Override
public void receivedEvent(UpdatePlayerView event) { public void receivedEvent(UpdatePlayerView event) {
playerHandler = app.getGameLogic().getPlayerHandler();
System.err.println("Update Player View");
// Clear existing accountContainer and overviewContainer content
accountContainer.clearChildren(); accountContainer.clearChildren();
overviewContainer.clearChildren(); overviewContainer.clearChildren();
@ -220,7 +252,7 @@ public class Toolbar extends Dialog implements GameEventListener {
playerHandler.getPlayerById(app.getId()).getNumJailCard() + "", playerHandler.getPlayerById(app.getId()).getNumJailCard() + "",
new ElementId("label-Text") 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"))); overviewContainer.addChild(new Label("Übersicht", new ElementId("label-Bold")));
for (Player player : playerHandler.getPlayers()) { 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) { @Override
switch (i) { public void receivedEvent(ButtonStatusEvent event) {
case 1: boolean enabled = event.buttonsEnabled();
return "Pictures/dice/one.png"; diceButton.setEnabled(enabled);
case 2: tradeButton.setEnabled(enabled);
return "Pictures/dice/two.png"; propertyMenuButton.setEnabled(enabled);
case 3: endTurnButton.setEnabled(enabled);
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 @Override

View File

@ -1,7 +1,8 @@
package pp.monopoly.client.gui; package pp.monopoly.client.gui;
import static java.lang.Math.min;
import com.jme3.app.Application; import com.jme3.app.Application;
import com.jme3.app.state.BaseAppState;
import com.jme3.material.Material; import com.jme3.material.Material;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
@ -12,55 +13,218 @@ import com.simsilica.lemur.*;
import com.simsilica.lemur.component.QuadBackgroundComponent; import com.simsilica.lemur.component.QuadBackgroundComponent;
import com.simsilica.lemur.component.SpringGridLayout; import com.simsilica.lemur.component.SpringGridLayout;
import com.simsilica.lemur.core.VersionedList; import com.simsilica.lemur.core.VersionedList;
import com.simsilica.lemur.core.VersionedReference;
import com.simsilica.lemur.style.ElementId; import com.simsilica.lemur.style.ElementId;
import com.simsilica.lemur.text.DocumentModel;
import pp.dialog.Dialog; import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp; import pp.monopoly.client.MonopolyApp;
import pp.monopoly.model.TradeHandler;
import pp.monopoly.model.fields.PropertyField;
import pp.monopoly.notification.Sound; import pp.monopoly.notification.Sound;
import java.util.Set;
public class TradeMenu extends Dialog { public class TradeMenu extends Dialog {
private final MonopolyApp app; private final MonopolyApp app;
private final TradeHandler tradeHandler;
private final Container mainContainer; private final Container mainContainer;
private Selector<String> leftBuildingSelector, leftCurrencySelector, leftSpecialCardSelector; private Selector<String> leftBuildingSelector, leftSpecialCardSelector;
private Selector<String> rightBuildingSelector, rightCurrencySelector, rightSpecialCardSelector; private Selector<String> rightBuildingSelector, rightSpecialCardSelector;
private final Button cancelButton = new Button("Abbrechen"); private TextField leftSelectionsField, rightSelectionsField;
private final Button tradeButton = new Button("Handeln"); private TextField leftCurrencyInput, rightCurrencyInput;
private Container lowerLeftMenu, lowerRightMenu;
private TextField leftSelectionsField;
private TextField rightSelectionsField;
private TextField leftCurrencyInput;
private TextField rightCurrencyInput;
QuadBackgroundComponent translucentWhiteBackground = private static final ColorRGBA TRANSLUCENT_WHITE = new ColorRGBA(1, 1, 1, 0.5f);
new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.White));
/** public TradeMenu(MonopolyApp app, TradeHandler tradeHandler) {
* Constructs the TradeMenu dialog.
*
* @param app The Monopoly application instance.
*/
public TradeMenu(MonopolyApp app) {
super(app.getDialogManager()); super(app.getDialogManager());
this.app = app; this.app = app;
this.tradeHandler = tradeHandler;
// Background Image
addBackgroundImage(); addBackgroundImage();
// Main container for the UI components mainContainer = createMainContainer();
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
app.getGuiNode().attachChild(mainContainer); 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( mainContainer.setLocalTranslation(
(app.getCamera().getWidth() - mainContainer.getPreferredSize().x) / 2, (app.getCamera().getWidth() - mainContainer.getPreferredSize().x) / 2,
(app.getCamera().getHeight() + mainContainer.getPreferredSize().y) / 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() { private void addBackgroundImage() {
Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/unibw-Bib2.png"); Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/unibw-Bib2.png");
Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight()); 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"); Material backgroundMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
backgroundMaterial.setTexture("ColorMap", backgroundImage); backgroundMaterial.setTexture("ColorMap", backgroundImage);
background.setMaterial(backgroundMaterial); background.setMaterial(backgroundMaterial);
background.setLocalTranslation(0, 0, 6); // Position behind other GUI elements background.setLocalTranslation(0, 0, 6);
app.getGuiNode().attachChild(background); 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 @Override
public void escape() { public void escape() {
new SettingsMenu(app).open(); new SettingsMenu(app).open();
} }
/**
* Updates the dialog periodically, called by the dialog manager.
*
* @param delta The time elapsed since the last update.
*/
@Override @Override
public void update(float delta) { public void close() {
// Periodic updates (if needed) can be implemented here 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.dialog.Dialog;
import pp.monopoly.client.MonopolyApp; import pp.monopoly.client.MonopolyApp;
import pp.monopoly.client.gui.SettingsMenu; 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.BoardManager;
import pp.monopoly.model.fields.BuildingProperty; import pp.monopoly.model.fields.BuildingProperty;
import pp.monopoly.notification.Sound; import pp.monopoly.notification.Sound;
@ -28,7 +28,7 @@ public class BuyCard extends Dialog {
this.app = app; this.app = app;
//Generate the corresponfing field //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); BuildingProperty field = (BuildingProperty) new BoardManager().getFieldAtIndex(index);
// Create the background container // Create the background container
@ -64,6 +64,7 @@ public class BuyCard extends Dialog {
Button quitButton = buyCardContainer.addChild(new Button("Beenden", new ElementId("button"))); Button quitButton = buyCardContainer.addChild(new Button("Beenden", new ElementId("button")));
quitButton.setFontSize(32); quitButton.setFontSize(32);
quitButton.addClickCommands(s -> ifTopDialog(() -> { quitButton.addClickCommands(s -> ifTopDialog(() -> {
System.err.println("Button does something?");
app.getGameLogic().playSound(Sound.BUTTON); app.getGameLogic().playSound(Sound.BUTTON);
close(); close();
})); }));
@ -72,7 +73,8 @@ public class BuyCard extends Dialog {
buyButton.setFontSize(32); buyButton.setFontSize(32);
buyButton.addClickCommands(s -> ifTopDialog( () -> { buyButton.addClickCommands(s -> ifTopDialog( () -> {
app.getGameLogic().playSound(Sound.BUTTON); 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 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.dialog.Dialog;
import pp.monopoly.client.MonopolyApp; import pp.monopoly.client.MonopolyApp;
import pp.monopoly.client.gui.SettingsMenu; 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.model.fields.FoodField;
import pp.monopoly.notification.Sound; import pp.monopoly.notification.Sound;
@ -83,7 +83,7 @@ public class FoodFieldCard extends Dialog {
buyButton.setFontSize(32); buyButton.setFontSize(32);
buyButton.addClickCommands(s -> ifTopDialog( () -> { buyButton.addClickCommands(s -> ifTopDialog( () -> {
app.getGameLogic().playSound(Sound.BUTTON); 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 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.dialog.Dialog;
import pp.monopoly.client.MonopolyApp; import pp.monopoly.client.MonopolyApp;
import pp.monopoly.client.gui.SettingsMenu; 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.model.fields.GateField;
import pp.monopoly.notification.Sound; import pp.monopoly.notification.Sound;
@ -78,7 +78,7 @@ public class GateFieldCard extends Dialog {
buyButton.setFontSize(32); buyButton.setFontSize(32);
buyButton.addClickCommands(s -> ifTopDialog(() -> { buyButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON); app.getGameLogic().playSound(Sound.BUTTON);
app.getGameLogic().send(new BuyPropertyRequest()); app.getGameLogic().send(new BuyPropertyResponse());
close(); 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();
}
}

View File

@ -5,10 +5,9 @@ import java.lang.System.Logger.Level;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import pp.monopoly.game.server.Player;
import pp.monopoly.game.server.PlayerHandler; import pp.monopoly.game.server.PlayerHandler;
import pp.monopoly.message.client.ClientMessage; import pp.monopoly.message.client.ClientMessage;
import pp.monopoly.message.server.BuyPropertyResponse; import pp.monopoly.message.server.BuyPropertyRequest;
import pp.monopoly.message.server.DiceResult; import pp.monopoly.message.server.DiceResult;
import pp.monopoly.message.server.EventDrawCard; import pp.monopoly.message.server.EventDrawCard;
import pp.monopoly.message.server.GameOver; import pp.monopoly.message.server.GameOver;
@ -26,11 +25,13 @@ import pp.monopoly.model.IntPoint;
import pp.monopoly.model.fields.BoardManager; import pp.monopoly.model.fields.BoardManager;
import pp.monopoly.notification.ClientStateEvent; import pp.monopoly.notification.ClientStateEvent;
import pp.monopoly.notification.DiceRollEvent; import pp.monopoly.notification.DiceRollEvent;
import pp.monopoly.notification.ButtonStatusEvent;
import pp.monopoly.notification.EventCardEvent; import pp.monopoly.notification.EventCardEvent;
import pp.monopoly.notification.GameEvent; import pp.monopoly.notification.GameEvent;
import pp.monopoly.notification.GameEventBroker; import pp.monopoly.notification.GameEventBroker;
import pp.monopoly.notification.GameEventListener; import pp.monopoly.notification.GameEventListener;
import pp.monopoly.notification.InfoTextEvent; import pp.monopoly.notification.InfoTextEvent;
import pp.monopoly.notification.PopUpEvent;
import pp.monopoly.notification.Sound; import pp.monopoly.notification.Sound;
import pp.monopoly.notification.SoundEvent; import pp.monopoly.notification.SoundEvent;
import pp.monopoly.notification.UpdatePlayerView; import pp.monopoly.notification.UpdatePlayerView;
@ -60,6 +61,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
private BoardManager boardManager = new BoardManager(); private BoardManager boardManager = new BoardManager();
/** /**
* Constructs a ClientGameLogic with the specified sender object. * Constructs a ClientGameLogic with the specified sender object.
* *
@ -194,21 +196,6 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
state.update(delta); state.update(delta);
} }
/**
* Handles the response for buying a property.
*
* @param msg the message containing the buy property response
*/
@Override
public void received(BuyPropertyResponse msg) {
if (msg.isSuccessful()) {
playSound(Sound.MONEY_LOST);
} else {
}
}
/** /**
* Handles the result of a dice roll. * Handles the result of a dice roll.
* *
@ -258,7 +245,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
public void received(GameStart msg) { public void received(GameStart msg) {
playerHandler = msg.getPlayerHandler(); playerHandler = msg.getPlayerHandler();
setState(new WaitForTurnState(this)); setState(new WaitForTurnState(this));
notifyListeners(new ButtonStatusEvent(false));
} }
/** /**
@ -304,7 +291,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
*/ */
@Override @Override
public void received(ViewAssetsResponse msg) { public void received(ViewAssetsResponse msg) {
boardManager = msg.getboard();
} }
/** /**
@ -330,9 +317,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
*/ */
@Override @Override
public void received(TradeRequest msg) { public void received(TradeRequest msg) {
// playSound(Sound.TRADE_REQUEST); no sound effect
// notifyListeners();
} }
/** /**
@ -342,7 +327,12 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
*/ */
@Override @Override
public void received(NextPlayerTurn msg) { public void received(NextPlayerTurn msg) {
notifyListeners(new ButtonStatusEvent(true));
setState(new ActiveState(this)); setState(new ActiveState(this));
} }
@Override
public void received(BuyPropertyRequest msg) {
notifyListeners(new PopUpEvent());
}
} }

View File

@ -13,8 +13,10 @@ import java.util.Random;
import com.jme3.network.serializing.Serializable; import com.jme3.network.serializing.Serializable;
import pp.monopoly.message.server.BuyPropertyRequest;
import pp.monopoly.message.server.DiceResult; import pp.monopoly.message.server.DiceResult;
import pp.monopoly.message.server.EventDrawCard; import pp.monopoly.message.server.EventDrawCard;
import pp.monopoly.message.server.NextPlayerTurn;
import pp.monopoly.message.server.PlayerStatusUpdate; import pp.monopoly.message.server.PlayerStatusUpdate;
import pp.monopoly.model.FieldVisitor; import pp.monopoly.model.FieldVisitor;
import pp.monopoly.model.Figure; import pp.monopoly.model.Figure;
@ -39,12 +41,14 @@ public class Player implements FieldVisitor<Void>{
private String name; private String name;
private int accountBalance = 15000; private int accountBalance = 15000;
private Figure figure; private Figure figure;
private List<PropertyField> properties = new ArrayList<>(); private List<Integer> properties = new ArrayList<>();
private int getOutOfJailCard; private int getOutOfJailCard;
private int fieldID; private int fieldID;
private DiceResult rollResult; private DiceResult rollResult;
private transient final PlayerHandler handler; private transient final PlayerHandler handler;
private transient PlayerState state = new LobbyState(); private transient PlayerState state = new WaitForTurnState();
private int doubletscounter = 0;
private boolean mayRollDice = false;
/** /**
* Default constructor for serialization purposes. * Default constructor for serialization purposes.
@ -131,6 +135,8 @@ public class Player implements FieldVisitor<Void>{
} }
void setActive() { void setActive() {
state = new ActiveState(); state = new ActiveState();
doubletscounter = 0;
mayRollDice = true;
} }
boolean finishTurn() { boolean finishTurn() {
@ -161,20 +167,37 @@ public class Player implements FieldVisitor<Void>{
*/ */
public int movePos(int position){ public int movePos(int position){
fieldID = fieldID+position; fieldID = fieldID+position;
System.out.println("Aktuelle Position" +fieldID);
System.err.println("Würfelergebniss"+ rollResult.calcTotal());
if(fieldID >= 40) { if(fieldID >= 40) {
fieldID = fieldID%40; fieldID = fieldID%40;
earnMoney(2000); earnMoney(2000);
} }
figure.moveTo(fieldID); figure.moveTo(fieldID);
getHandler().getLogic().send(this, new PlayerStatusUpdate(handler));
handler.getLogic().getBoardManager().getFieldAtIndex(fieldID).accept(this);
return fieldID; return fieldID;
} }
/**
* Sets the player to the specified Position on the board
* @param position the position to move to
* @return the new position
*/
public int setPosition(int position){
if(position < 40 && position > 0) {
fieldID = position;
figure.moveTo(fieldID);
handler.getLogic().getBoardManager().getFieldAtIndex(fieldID).accept(this);
}
return fieldID;
}
/** /**
* Gets all the properties owned by this player * Gets all the properties owned by this player
* @return List of all properties owned by this player * @return List of all properties owned by this player
*/ */
public List<PropertyField> getProperties() { public List<Integer> getProperties() {
return properties; return properties;
} }
@ -185,7 +208,7 @@ public class Player implements FieldVisitor<Void>{
*/ */
public void buyProperty(PropertyField property) { public void buyProperty(PropertyField property) {
if (property.getOwner() == null && accountBalance >= property.getPrice()) { if (property.getOwner() == null && accountBalance >= property.getPrice()) {
properties.add(property); properties.add(property.getId());
property.setOwner(this); property.setOwner(this);
pay(property.getPrice()); pay(property.getPrice());
} }
@ -284,30 +307,41 @@ public class Player implements FieldVisitor<Void>{
@Override @Override
public Void visit(BuildingProperty field) { public Void visit(BuildingProperty field) {
int rent = field.calcRent(); if(field.getOwner() == null) {
getHandler().getLogic().send(this, new BuyPropertyRequest());
field.getOwner().earnMoney(rent); } else if (field.getOwner() != this){
pay(rent); int rent = field.calcRent();
field.getOwner().earnMoney(rent);
pay(rent);
}
return null; return null;
} }
@Override @Override
public Void visit(FoodField field) { public Void visit(FoodField field) {
int factor = 4; if(field.getOwner() == null) {
if (field.getOwner().getNumProp(field) == 2) { getHandler().getLogic().send(this, new BuyPropertyRequest());
factor = 10; } else {
int factor = 4;
if (field.getOwner().getNumProp(field) == 2) {
factor = 10;
}
field.getOwner().earnMoney(rollResult.calcTotal()*factor);
pay(rollResult.calcTotal()*factor);
} }
field.getOwner().earnMoney(rollResult.calcTotal()*factor);
pay(rollResult.calcTotal()*factor);
return null; return null;
} }
@Override @Override
public Void visit(GateField field) { public Void visit(GateField field) {
int rent = field.calcRent() * field.getOwner().getNumProp(field); if(field.getOwner() == null) {
getHandler().getLogic().send(this, new BuyPropertyRequest());
} else {
int rent = field.calcRent() * field.getOwner().getNumProp(field);
field.getOwner().earnMoney(rent); field.getOwner().earnMoney(rent);
pay(rent); pay(rent);
}
return null; return null;
} }
@ -334,15 +368,13 @@ public class Player implements FieldVisitor<Void>{
@Override @Override
public Void visit(WacheField field) { public Void visit(WacheField field) {
movePos(10); setPosition(10);
return null; return null;
} }
@Override @Override
public Void visit(GoField field) { public Void visit(GoField field) {
earnMoney(2000); earnMoney(2000);
GulagField res = (GulagField) handler.getLogic().getBoardManager().getFieldAtIndex(10);
res.accept(this);
return null; return null;
} }
@ -355,6 +387,16 @@ public class Player implements FieldVisitor<Void>{
return null; return null;
} }
public List<PropertyField> getPropertyFields() {
List<PropertyField> properties = new ArrayList<>();
for (Integer i : this.properties) {
properties.add((PropertyField)getHandler().getLogic().getBoardManager().getFieldAtIndex(i));
}
return properties;
}
/** /**
* Return the number of Properties of the speciefied fild type * Return the number of Properties of the speciefied fild type
* @param field the type of field to search for * @param field the type of field to search for
@ -362,7 +404,9 @@ public class Player implements FieldVisitor<Void>{
*/ */
public int getNumProp(PropertyField field) { public int getNumProp(PropertyField field) {
int count = 0; int count = 0;
for (PropertyField propertyField : properties) { if (properties.isEmpty()) return 0;
for (PropertyField propertyField : getPropertyFields()) {
if (propertyField.getClass() == field.getClass()) { if (propertyField.getClass() == field.getClass()) {
count++; count++;
} }
@ -373,7 +417,7 @@ public class Player implements FieldVisitor<Void>{
public int getNumHouses() { public int getNumHouses() {
int total = 0; int total = 0;
for (PropertyField field : properties) { for (PropertyField field : getPropertyFields()) {
if (field.getClass() == BuildingProperty.class) { if (field.getClass() == BuildingProperty.class) {
total += ((BuildingProperty) field).getHouses(); total += ((BuildingProperty) field).getHouses();
} }
@ -383,7 +427,7 @@ public class Player implements FieldVisitor<Void>{
public int getNumHotels() { public int getNumHotels() {
int total = 0; int total = 0;
for (PropertyField field : properties) { for (PropertyField field : getPropertyFields()) {
if (field.getClass() == BuildingProperty.class) { if (field.getClass() == BuildingProperty.class) {
total += ((BuildingProperty) field).getHotel(); total += ((BuildingProperty) field).getHotel();
} }
@ -414,11 +458,21 @@ public class Player implements FieldVisitor<Void>{
* @return a List of two integers representing the dice roll results * @return a List of two integers representing the dice roll results
*/ */
DiceResult rollDice() { DiceResult rollDice() {
return state.rollDice(); if (mayRollDice) {
} state.rollDice();
}
private void visitEvent() { if (rollResult.isDoublets()) {
getHandler().getLogic().getBoardManager().getFieldAtIndex(36).accept(this); doubletscounter++;
mayRollDice = true;
getHandler().getLogic().send(this, new NextPlayerTurn());
setName(name);
if (doubletscounter >= 3) {
setPosition(10);
}
} else {
mayRollDice = false;
}
return rollResult;
} }
/** /**
@ -453,6 +507,8 @@ public class Player implements FieldVisitor<Void>{
public DiceResult rollDice() { public DiceResult rollDice() {
List<Integer> roll = List.of(Dice.rollDice(), Dice.rollDice()); List<Integer> roll = List.of(Dice.rollDice(), Dice.rollDice());
rollResult = new DiceResult(roll.get(0), roll.get(1)); rollResult = new DiceResult(roll.get(0), roll.get(1));
System.out.println(rollResult.calcTotal());
move(rollResult.calcTotal());
return rollResult; return rollResult;
} }
@ -468,31 +524,6 @@ public class Player implements FieldVisitor<Void>{
} }
/**
* A class to represent the Lobby PlayerState
* Set when in Lobby
*/
private class LobbyState implements PlayerState{
@Override
public DiceResult rollDice() {
//do nothing
return null;
}
@Override
public void payBail() {
//do nothing
}
@Override
public void useJailCard() {
// do nothing
}
}
/** /**
* A class to represent the Jailed PlayerState * A class to represent the Jailed PlayerState
* Set when in Gulag * Set when in Gulag

View File

@ -4,7 +4,7 @@ import java.lang.System.Logger;
import java.lang.System.Logger.Level; import java.lang.System.Logger.Level;
import pp.monopoly.MonopolyConfig; import pp.monopoly.MonopolyConfig;
import pp.monopoly.message.client.BuyPropertyRequest; import pp.monopoly.message.client.BuyPropertyResponse;
import pp.monopoly.message.client.ClientInterpreter; import pp.monopoly.message.client.ClientInterpreter;
import pp.monopoly.message.client.EndTurn; import pp.monopoly.message.client.EndTurn;
import pp.monopoly.message.client.PlayerReady; import pp.monopoly.message.client.PlayerReady;
@ -19,7 +19,6 @@ import pp.monopoly.message.server.ServerMessage;
import pp.monopoly.message.server.TradeReply; import pp.monopoly.message.server.TradeReply;
import pp.monopoly.message.server.TradeRequest; import pp.monopoly.message.server.TradeRequest;
import pp.monopoly.message.server.ViewAssetsResponse; import pp.monopoly.message.server.ViewAssetsResponse;
import pp.monopoly.model.Board;
import pp.monopoly.model.Figure; import pp.monopoly.model.Figure;
import pp.monopoly.model.Rotation; import pp.monopoly.model.Rotation;
import pp.monopoly.model.card.DeckHelper; import pp.monopoly.model.card.DeckHelper;
@ -144,19 +143,14 @@ public class ServerGameLogic implements ClientInterpreter {
* @param from the connection ID of the player who sent the request * @param from the connection ID of the player who sent the request
*/ */
@Override @Override
public void received(BuyPropertyRequest msg, int from) { public void received(BuyPropertyResponse msg, int from) {
Player player = playerHandler.getPlayerById(from); Player player = playerHandler.getPlayerById(from);
if (player != null && state == ServerState.INGAME) { if (player != null) {
PropertyField property = (PropertyField) boardManager.getFieldAtIndex(player.move(0)); // Assuming player position for property PropertyField property = (PropertyField) boardManager.getFieldAtIndex(player.getFieldID()); // Assuming player position for property
if (property.getOwner() == null && player.getAccountBalance() >= property.getPrice()) { player.buyProperty(property);
player.buyProperty(property); System.out.println("Properties:" +player.getProperties().toString());
property.setOwner(player); LOGGER.log(Level.INFO, "Player {0} bought property {1}", player.getName(), property.getName());
player.earnMoney(-property.getPrice());
LOGGER.log(Level.INFO, "Player {0} bought property {1}", player.getName(), property.getName());
} else {
LOGGER.log(Level.WARNING, "Player {0} cannot buy property {1}", player.getName(), property.getName());
}
} }
} }
@ -169,12 +163,14 @@ public class ServerGameLogic implements ClientInterpreter {
@Override @Override
public void received(EndTurn msg, int from) { public void received(EndTurn msg, int from) {
Player player = playerHandler.getPlayerById(from); Player player = playerHandler.getPlayerById(from);
if (player != null && state == ServerState.INGAME) { if (player != null && player == playerHandler.getPlayerAtIndex(0)) {
if (player.finishTurn()) { if (player.finishTurn()) {
LOGGER.log(Level.DEBUG, "Ending turn for player {0}", player.getName()); LOGGER.log(Level.DEBUG, "Ending turn for player {0}", player.getName());
Player next = playerHandler.nextPlayer(); Player next = playerHandler.nextPlayer();
next.setActive(); next.setActive();
send(next, new NextPlayerTurn()); send(next, new NextPlayerTurn());
send(next, new PlayerStatusUpdate(playerHandler));
send(player, new PlayerStatusUpdate(playerHandler));
} }
} }
} }
@ -267,11 +263,12 @@ public class ServerGameLogic implements ClientInterpreter {
@Override @Override
public void received(ViewAssetsRequest msg, int from) { public void received(ViewAssetsRequest msg, int from) {
Player sender = playerHandler.getPlayerById(from); Player sender = playerHandler.getPlayerById(from);
Player player = msg.getPlayer(); if (sender != null) {
if (sender != null && player != null) { LOGGER.log(Level.DEBUG, "Processing ViewAssetsRequest for player {0}", sender.getName());
LOGGER.log(Level.DEBUG, "Processing ViewAssetsRequest for player {0}", sender.getName()); send(sender, new ViewAssetsResponse(boardManager));
for (Player player : playerHandler.getPlayers()) {
send(sender, new ViewAssetsResponse(boardManager, player.getProperties(), player.getAccountBalance(), player.getNumJailCard())); send(player, new PlayerStatusUpdate(playerHandler));
}
} }
} }

View File

@ -6,14 +6,14 @@ import com.jme3.network.serializing.Serializable;
* Represents a request from a player to buy a property. * Represents a request from a player to buy a property.
*/ */
@Serializable @Serializable
public class BuyPropertyRequest extends ClientMessage{ public class BuyPropertyResponse extends ClientMessage{
/** /**
* Constructs a BuyPropertyRequest with the specified property ID. * Constructs a BuyPropertyRequest with the specified property ID.
* *
* @param propertyId the ID of the property to buy * @param propertyId the ID of the property to buy
*/ */
public BuyPropertyRequest() {} public BuyPropertyResponse() {}
@Override @Override

View File

@ -17,7 +17,7 @@ public interface ClientInterpreter {
* @param msg the BuyPropertyRequest to be processed * @param msg the BuyPropertyRequest to be processed
* @param from the connection ID from which the message was received * @param from the connection ID from which the message was received
*/ */
void received(BuyPropertyRequest msg, int from); void received(BuyPropertyResponse msg, int from);
/** /**
* Processes a received EndTurn. * Processes a received EndTurn.

View File

@ -2,23 +2,13 @@ package pp.monopoly.message.client;
import com.jme3.network.serializing.Serializable; import com.jme3.network.serializing.Serializable;
import pp.monopoly.game.server.Player;
/** /**
* Represents a request from a player to view their assets. * Represents a request from a player to view their assets.
*/ */
@Serializable @Serializable
public class ViewAssetsRequest extends ClientMessage{ public class ViewAssetsRequest extends ClientMessage{
private Player player; public ViewAssetsRequest() {
/**
* Default constructor for serialization purposes.
*/
private ViewAssetsRequest() { /* empty */ }
public ViewAssetsRequest(Player player) {
this.player = player;
} }
@Override @Override
@ -26,8 +16,4 @@ public class ViewAssetsRequest extends ClientMessage{
interpreter.received(this, from); interpreter.received(this, from);
} }
public Player getPlayer() {
return player;
}
} }

View File

@ -0,0 +1,21 @@
package pp.monopoly.message.server;
import com.jme3.network.serializing.Serializable;
@Serializable
public class BuyPropertyRequest extends ServerMessage{
public BuyPropertyRequest(){}
@Override
public void accept(ServerInterpreter interpreter) {
interpreter.received(this);
}
@Override
public String getInfoTextKey() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
}
}

View File

@ -1,47 +0,0 @@
package pp.monopoly.message.server;
import com.jme3.network.serializing.Serializable;
/**
* Represents the server's response to a player's request to buy a property.
*/
@Serializable
public class BuyPropertyResponse extends ServerMessage{
private boolean successful;
private String propertyName;
private String reason; // Reason for failure, if any
/**
* Default constructor for serialization purposes.
*/
private BuyPropertyResponse() { /* empty */ }
public BuyPropertyResponse(boolean successful, String propertyName, String reason) {
this.successful = successful;
this.propertyName = propertyName;
this.reason = reason;
}
public boolean isSuccessful() {
return successful;
}
public String getPropertyName() {
return propertyName;
}
public String getReason() {
return reason;
}
@Override
public void accept(ServerInterpreter interpreter) {
interpreter.received(this);
}
@Override
public String getInfoTextKey() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
}
}

View File

@ -13,13 +13,6 @@ package pp.monopoly.message.server;
*/ */
public interface ServerInterpreter { public interface ServerInterpreter {
/**
* Handles a BuyPropertyResponse message received from the server.
*
* @param msg the BuyPropertyResponse message received
*/
void received(BuyPropertyResponse msg);
/** /**
* Handles a DiceResult message received from the server. * Handles a DiceResult message received from the server.
* *
@ -96,4 +89,11 @@ public interface ServerInterpreter {
* @param msg the NextPlayerTurn message received * @param msg the NextPlayerTurn message received
*/ */
void received(NextPlayerTurn msg); void received(NextPlayerTurn msg);
/**
* Handles a NextPlayerTurn message received from the server.
*
* @param msg the NextPlayerTurn message received
*/
void received(BuyPropertyRequest msg);
} }

View File

@ -1,11 +1,9 @@
package pp.monopoly.message.server; package pp.monopoly.message.server;
import java.util.List;
import com.jme3.network.serializing.Serializable; import com.jme3.network.serializing.Serializable;
import pp.monopoly.model.fields.BoardManager; import pp.monopoly.model.fields.BoardManager;
import pp.monopoly.model.fields.PropertyField;
/** /**
* Represents a response containing the player's assets. * Represents a response containing the player's assets.
@ -13,10 +11,7 @@ import pp.monopoly.model.fields.PropertyField;
@Serializable @Serializable
public class ViewAssetsResponse extends ServerMessage{ public class ViewAssetsResponse extends ServerMessage{
private List<PropertyField> properties;
private BoardManager board; private BoardManager board;
private int accountBalance;
private int jailCards;
/** /**
* Default constructor for serialization purposes. * Default constructor for serialization purposes.
@ -29,11 +24,8 @@ public class ViewAssetsResponse extends ServerMessage{
* @param properties a List of PropertyField objects representing the player's properties * @param properties a List of PropertyField objects representing the player's properties
* @param accountBalance the player's current account balance * @param accountBalance the player's current account balance
*/ */
public ViewAssetsResponse(BoardManager board, List<PropertyField> properties, int accountBalance, int jailCards) { public ViewAssetsResponse(BoardManager board) {
this.board = board; this.board = board;
this.properties = properties;
this.accountBalance = accountBalance;
this.jailCards = jailCards;
} }
@Override @Override
@ -47,18 +39,6 @@ public class ViewAssetsResponse extends ServerMessage{
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'"); throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
} }
public List<PropertyField> getProperties() {
return properties;
}
public int getAccountBalance() {
return accountBalance;
}
public int getJailCards() {
return jailCards;
}
public BoardManager getboard() { public BoardManager getboard() {
return board; return board;
} }

View File

@ -4,9 +4,12 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import com.jme3.network.serializing.Serializable;
/** /**
* Simple Manager class responsible for managing the GameBoard of Monopoly * Simple Manager class responsible for managing the GameBoard of Monopoly
*/ */
@Serializable
public class BoardManager { public class BoardManager {
private List<Field> board; private List<Field> board;
@ -92,4 +95,12 @@ public class BoardManager {
public List<Field> getBoard() { public List<Field> getBoard() {
return board; return board;
} }
public List<PropertyField> getPropertyFields(List<Integer> source) {
List<PropertyField> properties = new ArrayList<>();
for (Integer i : source) {
properties.add((PropertyField)getFieldAtIndex(i));
}
return properties;
}
} }

View File

@ -0,0 +1,13 @@
package pp.monopoly.notification;
public record ButtonStatusEvent(boolean buttonsEnabled) 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);
}
}

View File

@ -66,4 +66,18 @@ public interface GameEventListener {
* @param event the received event * @param event the received event
*/ */
default void receivedEvent(EventCardEvent event) { /*Do nothing */} default void receivedEvent(EventCardEvent event) { /*Do nothing */}
/**
* Indicates that all buttons in the toolbar should be disabled
*
* @param event the received event
*/
default void receivedEvent(ButtonStatusEvent event) { /*Do nothing */}
/**
* Indicates that all buttons in the toolbar should be disabled
*
* @param event the received event
*/
default void receivedEvent(PopUpEvent event) { /*Do nothing */}
} }

View File

@ -0,0 +1,10 @@
package pp.monopoly.notification;
public record PopUpEvent() implements GameEvent{
@Override
public void notifyListener(GameEventListener listener) {
listener.receivedEvent(this);
}
}

View File

@ -29,7 +29,7 @@ import pp.monopoly.game.server.Player;
import pp.monopoly.game.server.PlayerHandler; import pp.monopoly.game.server.PlayerHandler;
import pp.monopoly.game.server.ServerGameLogic; import pp.monopoly.game.server.ServerGameLogic;
import pp.monopoly.game.server.ServerSender; import pp.monopoly.game.server.ServerSender;
import pp.monopoly.message.client.BuyPropertyRequest; import pp.monopoly.message.client.BuyPropertyResponse;
import pp.monopoly.message.client.ClientMessage; import pp.monopoly.message.client.ClientMessage;
import pp.monopoly.message.client.EndTurn; import pp.monopoly.message.client.EndTurn;
import pp.monopoly.message.client.PlayerReady; import pp.monopoly.message.client.PlayerReady;
@ -37,15 +37,29 @@ import pp.monopoly.message.client.RollDice;
import pp.monopoly.message.client.TradeOffer; import pp.monopoly.message.client.TradeOffer;
import pp.monopoly.message.client.TradeResponse; import pp.monopoly.message.client.TradeResponse;
import pp.monopoly.message.client.ViewAssetsRequest; import pp.monopoly.message.client.ViewAssetsRequest;
import pp.monopoly.message.server.BuyPropertyRequest;
import pp.monopoly.message.server.DiceResult; import pp.monopoly.message.server.DiceResult;
import pp.monopoly.message.server.EventDrawCard; import pp.monopoly.message.server.EventDrawCard;
import pp.monopoly.message.server.GameStart; import pp.monopoly.message.server.GameStart;
import pp.monopoly.message.server.NextPlayerTurn; import pp.monopoly.message.server.NextPlayerTurn;
import pp.monopoly.message.server.PlayerStatusUpdate; import pp.monopoly.message.server.PlayerStatusUpdate;
import pp.monopoly.message.server.ServerMessage; import pp.monopoly.message.server.ServerMessage;
import pp.monopoly.message.server.ViewAssetsResponse;
import pp.monopoly.model.Figure; import pp.monopoly.model.Figure;
import pp.monopoly.model.IntPoint; import pp.monopoly.model.IntPoint;
import pp.monopoly.model.LimitedLinkedList; import pp.monopoly.model.LimitedLinkedList;
import pp.monopoly.model.fields.BoardManager;
import pp.monopoly.model.fields.BuildingProperty;
import pp.monopoly.model.fields.EventField;
import pp.monopoly.model.fields.Field;
import pp.monopoly.model.fields.FineField;
import pp.monopoly.model.fields.FoodField;
import pp.monopoly.model.fields.GateField;
import pp.monopoly.model.fields.GoField;
import pp.monopoly.model.fields.GulagField;
import pp.monopoly.model.fields.PropertyField;
import pp.monopoly.model.fields.TestStreckeField;
import pp.monopoly.model.fields.WacheField;
/** /**
* Server implementing the visitor pattern as MessageReceiver for ClientMessages * Server implementing the visitor pattern as MessageReceiver for ClientMessages
@ -120,6 +134,7 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
private void initializeSerializables() { private void initializeSerializables() {
Serializer.registerClass(IntPoint.class); Serializer.registerClass(IntPoint.class);
Serializer.registerClass(BuyPropertyResponse.class);
Serializer.registerClass(BuyPropertyRequest.class); Serializer.registerClass(BuyPropertyRequest.class);
Serializer.registerClass(EndTurn.class); Serializer.registerClass(EndTurn.class);
Serializer.registerClass(PlayerReady.class); Serializer.registerClass(PlayerReady.class);
@ -127,6 +142,7 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
Serializer.registerClass(TradeOffer.class); Serializer.registerClass(TradeOffer.class);
Serializer.registerClass(TradeResponse.class); Serializer.registerClass(TradeResponse.class);
Serializer.registerClass(ViewAssetsRequest.class); Serializer.registerClass(ViewAssetsRequest.class);
Serializer.registerClass(ViewAssetsResponse.class);
Serializer.registerClass(GameStart.class); Serializer.registerClass(GameStart.class);
Serializer.registerClass(LimitedLinkedList.class); Serializer.registerClass(LimitedLinkedList.class);
Serializer.registerClass(NextPlayerTurn.class); Serializer.registerClass(NextPlayerTurn.class);
@ -136,10 +152,22 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
Serializer.registerClass(DiceResult.class); Serializer.registerClass(DiceResult.class);
Serializer.registerClass(EventDrawCard.class); Serializer.registerClass(EventDrawCard.class);
Serializer.registerClass(PlayerStatusUpdate.class); Serializer.registerClass(PlayerStatusUpdate.class);
Serializer.registerClass(BoardManager.class);
Serializer.registerClass(Field.class);
Serializer.registerClass(PropertyField.class);
Serializer.registerClass(BuildingProperty.class);
Serializer.registerClass(FoodField.class);
Serializer.registerClass(GateField.class);
Serializer.registerClass(WacheField.class);
Serializer.registerClass(GoField.class);
Serializer.registerClass(TestStreckeField.class);
Serializer.registerClass(EventField.class);
Serializer.registerClass(GulagField.class);
Serializer.registerClass(FineField.class);
} }
private void registerListeners() { private void registerListeners() {
myServer.addMessageListener(this, BuyPropertyRequest.class); myServer.addMessageListener(this, BuyPropertyResponse.class);
myServer.addMessageListener(this, EndTurn.class); myServer.addMessageListener(this, EndTurn.class);
myServer.addMessageListener(this, PlayerReady.class); myServer.addMessageListener(this, PlayerReady.class);
myServer.addMessageListener(this, RollDice.class); myServer.addMessageListener(this, RollDice.class);