mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-08-03 10:37:11 +02:00
Compare commits
195 Commits
logic
...
1ccdea0c87
Author | SHA1 | Date | |
---|---|---|---|
|
1ccdea0c87 | ||
|
7d9af0c4c7 | ||
|
a1247cdae5 | ||
|
5696192cce | ||
|
91826b730f | ||
|
48b1cf817a | ||
|
94ba9f0af2 | ||
|
333f27a016 | ||
|
b67379a6c3 | ||
|
1e6188cf24 | ||
|
12e859edd5 | ||
|
e000dcfc51 | ||
|
e7a06159bb | ||
|
c900b6384d | ||
|
970a0ae254 | ||
|
5e0ac0abc7 | ||
|
bcd6711965 | ||
|
bb63a4df9f | ||
|
b4d7349583 | ||
|
fed8a3fd2d | ||
|
bc6e7174ec | ||
|
075f98883a | ||
|
c9df3a6176 | ||
|
b2d2a79b00 | ||
|
26d8283930 | ||
|
4079c0a32c | ||
|
6d72a94fe4 | ||
|
227a7a027f | ||
|
9e595b92ba | ||
|
c346058631 | ||
|
f2678ea33d | ||
|
45a43d6998 | ||
|
cb9888af7a | ||
|
93b183254f | ||
|
e92b305a56 | ||
|
5b0628da15 | ||
|
8d087a8e84 | ||
|
1715926c1c | ||
|
c8b69efca2 | ||
|
7f6011720c | ||
|
bdc5f0269f | ||
|
a6054e825e | ||
|
156e76fe0a | ||
|
89587a4c78 | ||
|
29cc73e83b | ||
|
e56cdb1dcb | ||
|
9107a08011 | ||
|
0242587a5f | ||
|
3ce27023c2 | ||
|
174958c6b1 | ||
|
c71e8b1e8e | ||
|
ada067a2a0 | ||
|
f4c4f6bc93 | ||
|
6eeb6fd209 | ||
|
efba3c496a | ||
|
27a0ab52e6 | ||
|
d6ce859fcd | ||
|
e5f69c9536 | ||
|
d8a2225038 | ||
|
7b91a679f5 | ||
|
840658b590 | ||
|
c5e7ef855e | ||
|
170227c97f | ||
|
379803278b | ||
|
3956d8efa7 | ||
|
269aceaf1a | ||
|
41127565fc | ||
|
0e405d2f90 | ||
|
f67810b288 | ||
|
4095d9e79d | ||
|
547a4c2353 | ||
|
9120e4d53c | ||
|
1a62b76104 | ||
|
cc7f277bef | ||
|
274df8dfd1 | ||
|
0c2b266f5e | ||
|
16b4dbae18 | ||
|
88409dcc99 | ||
|
5cacff39b7 | ||
|
093723a9d0 | ||
|
dfdbcdc9f3 | ||
|
bd725e2dc4 | ||
|
dd9d9144dd | ||
|
1a429e4bb6 | ||
|
ad6fb5e926 | ||
|
72cb7049ba | ||
|
2e42f3afac | ||
|
8474c9f5bc | ||
|
b7ed03f7e8 | ||
|
a44b6b5e4c | ||
|
5268f75e17 | ||
|
687d1621fc | ||
|
a6944aa6e3 | ||
|
b8365c76a1 | ||
|
19216cc174 | ||
|
c6a23b9b8e | ||
|
c0f42fb1eb | ||
|
160873e2cc | ||
|
8df859bbef | ||
|
e30d10a85d | ||
|
bafc3f1db6 | ||
|
03571fcf74 | ||
|
e7a6802488 | ||
|
a6e6b5e158 | ||
|
74c3d925e6 | ||
|
f67fa4d7f0 | ||
|
225a8c0e08 | ||
|
9a6ce27fe1 | ||
|
437114704a | ||
|
9b4cac4e56 | ||
|
e780513b35 | ||
|
d582c59a7d | ||
|
7d2c85f617 | ||
|
4a882bc4ac | ||
|
3c4eac1fcd | ||
|
75d5a15bdb | ||
|
17f121f7d1 | ||
|
a66c570b51 | ||
|
e1e7f2eaf6 | ||
|
46d2dce372 | ||
|
c39f1f6d4c | ||
|
738b04f2d9 | ||
|
ecba1c3135 | ||
|
748226f4ed | ||
|
f658f53ba9 | ||
|
4a8304ee4f | ||
|
7fe9604338 | ||
|
7f09a6dae8 | ||
|
270129bc97 | ||
|
62ec6f6bef | ||
|
b24c14900c | ||
|
44c55ce3a6 | ||
|
895bea048c | ||
|
885ab5bdc9 | ||
|
c6355b2c09 | ||
|
ada6bf3f24 | ||
|
db471ac679 | ||
|
84059c4085 | ||
|
09b363f943 | ||
|
fd347c7780 | ||
|
b38a34efa5 | ||
|
10e24cf30e | ||
|
3369057afb | ||
|
7ada56e215 | ||
|
373b9e6d53 | ||
|
3de31de9f7 | ||
|
7252259ab3 | ||
|
f33c673a05 | ||
|
65a7958b66 | ||
|
91e4df7478 | ||
|
399606d9a0 | ||
|
559afcaffd | ||
|
15f5f91ddb | ||
|
067a8063a5 | ||
|
35e367ba24 | ||
|
fe68d991fc | ||
|
88dc633e8e | ||
|
0b9cbb0f5f | ||
|
c3a33b4402 | ||
|
e12f00aad6 | ||
|
47bac0185f | ||
|
dafe1dab2a | ||
|
8ba4ea2819 | ||
|
f6f708fd5b | ||
|
1203077aed | ||
|
ddbf79c928 | ||
|
aa47dd579f | ||
|
cdce478d77 | ||
|
f11f4a59f1 | ||
|
d631e8df1e | ||
|
af80d40700 | ||
|
3a6f8a945a | ||
|
bb9727d54a | ||
|
7da8b3e545 | ||
|
b6968df451 | ||
|
aa986fb948 | ||
|
6e63de6e99 | ||
|
962ecd08fa | ||
|
580a26b3ea | ||
|
0cda6b5fa0 | ||
|
cc8c3795b8 | ||
|
3c21165efb | ||
|
818fdf4670 | ||
|
b7d679b492 | ||
|
a42093df23 | ||
|
6157db51da | ||
|
843052989b | ||
|
8e01fa3192 | ||
|
e2126a7ea7 | ||
|
0b46d14650 | ||
|
9e28deedf7 | ||
|
9c0172b413 | ||
|
2933d022aa | ||
|
bdefb7193e | ||
|
69b68a6975 |
@@ -71,6 +71,11 @@ selector("label-Text", "pp") {
|
||||
color = buttonEnabledColor
|
||||
}
|
||||
|
||||
selector("card-label", "pp") {
|
||||
insets = new Insets3f(2, 2, 2, 2)
|
||||
color = ColorRGBA.Black
|
||||
}
|
||||
|
||||
selector("header", "pp") {
|
||||
font = font("Interface/Fonts/Metropolis/Metropolis-Bold-42.fnt")
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
|
@@ -0,0 +1,115 @@
|
||||
////////////////////////////////////////
|
||||
// Programming project code
|
||||
// UniBw M, 2022, 2023, 2024
|
||||
// www.unibw.de/inf2
|
||||
// (c) Mark Minas (mark.minas@unibw.de)
|
||||
////////////////////////////////////////
|
||||
|
||||
package pp.monopoly.client;
|
||||
|
||||
import java.lang.System.Logger;
|
||||
import java.util.List;
|
||||
|
||||
import com.jme3.input.controls.ActionListener;
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.system.AppSettings;
|
||||
|
||||
import pp.monopoly.client.gui.TestWorld;
|
||||
import pp.monopoly.game.server.Player;
|
||||
|
||||
/**
|
||||
* Represents the state responsible for managing the battle interface within the Battleship game.
|
||||
* This state handles the display and interaction of the battle map, including the opponent's map.
|
||||
* It manages GUI components, input events, and the layout of the interface when this state is enabled.
|
||||
*/
|
||||
public class GameAppState extends MonopolyAppState {
|
||||
private static final Logger LOGGER = System.getLogger(MonopolyAppState.class.getName());
|
||||
private static final float DEPTH = 0f;
|
||||
private static final float GAP = 20f;
|
||||
|
||||
/**
|
||||
* A listener for handling click events in the battle interface.
|
||||
* When a click is detected, it triggers the corresponding actions on the opponent's map.
|
||||
*/
|
||||
private final ActionListener clickListener = (name, isPressed, tpf) -> click(isPressed);
|
||||
|
||||
/**
|
||||
* The root node for all GUI components in the battle state.
|
||||
*/
|
||||
private final Node battleNode = new Node("Game"); //NON-NLS
|
||||
|
||||
/**
|
||||
* A view representing the opponent's map in the GUI.
|
||||
*/
|
||||
private TestWorld testWorld;
|
||||
|
||||
/**
|
||||
* Enables the battle state by initializing, laying out, and adding GUI components.
|
||||
* Attaches the components to the GUI node and registers input listeners.
|
||||
*/
|
||||
@Override
|
||||
protected void enableState() {
|
||||
battleNode.detachAllChildren();
|
||||
initializeGuiComponents();
|
||||
layoutGuiComponents();
|
||||
addGuiComponents();
|
||||
getApp().getGuiNode().attachChild(battleNode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the battle state by removing GUI components and unregistering input listeners.
|
||||
* Also handles cleanup of resources, such as the opponent's map view.
|
||||
*/
|
||||
@Override
|
||||
protected void disableState() {
|
||||
getApp().getGuiNode().detachChild(battleNode);
|
||||
getApp().getInputManager().removeListener(clickListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the GUI components used in the battle state.
|
||||
* Creates the opponent's map view and adds a grid overlay to it.
|
||||
*/
|
||||
private void initializeGuiComponents() {
|
||||
// Abrufen der Spielerliste aus der ClientGameLogic
|
||||
List<Player> players = getApp().getGameLogic().getPlayerHandler().getPlayers();
|
||||
|
||||
// Initialisiere TestWorld mit Spielern
|
||||
testWorld = new TestWorld(getApp(), players);
|
||||
testWorld.initializeScene();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds the initialized GUI components to the battle node.
|
||||
* Currently, it attaches the opponent's map view to the node.
|
||||
*/
|
||||
private void addGuiComponents() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Lays out the GUI components within the window, positioning them appropriately.
|
||||
* The opponent's map view is positioned based on the window's dimensions and a specified gap.
|
||||
*/
|
||||
private void layoutGuiComponents() {
|
||||
final AppSettings s = getApp().getContext().getSettings();
|
||||
final float windowWidth = s.getWidth();
|
||||
final float windowHeight = s.getHeight();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles click events in the battle interface. If the event indicates a click (not a release),
|
||||
* it translates the cursor position to the model's coordinate system and triggers the game logic
|
||||
* for interacting with the opponent's map.
|
||||
*
|
||||
* @param isPressed whether the mouse button is currently pressed (true) or released (false)
|
||||
*/
|
||||
private void click(boolean isPressed) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float tpf) {
|
||||
testWorld.update(tpf);
|
||||
super.update(tpf);
|
||||
}
|
||||
}
|
@@ -7,6 +7,15 @@
|
||||
|
||||
package pp.monopoly.client;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.logging.LogManager;
|
||||
|
||||
import com.jme3.app.DebugKeysAppState;
|
||||
import com.jme3.app.SimpleApplication;
|
||||
import com.jme3.app.StatsAppState;
|
||||
@@ -19,38 +28,24 @@ import com.jme3.input.controls.KeyTrigger;
|
||||
import com.jme3.input.controls.MouseButtonTrigger;
|
||||
import com.jme3.system.AppSettings;
|
||||
import com.simsilica.lemur.GuiGlobals;
|
||||
import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.style.BaseStyles;
|
||||
import pp.monopoly.game.client.MonopolyClient;
|
||||
|
||||
import pp.dialog.Dialog;
|
||||
import pp.dialog.DialogBuilder;
|
||||
import pp.dialog.DialogManager;
|
||||
import pp.graphics.Draw;
|
||||
import static pp.monopoly.Resources.lookup;
|
||||
import pp.monopoly.client.gui.SettingsMenu;
|
||||
import pp.monopoly.client.gui.StartMenu;
|
||||
import pp.monopoly.client.gui.TestWorld;
|
||||
import pp.monopoly.client.gui.popups.BuildingPropertyCard;
|
||||
import pp.monopoly.client.gui.popups.BuyCard;
|
||||
import pp.monopoly.client.gui.popups.EventCard;
|
||||
import pp.monopoly.client.gui.popups.FoodFieldCard;
|
||||
import pp.monopoly.client.gui.popups.GateFieldCard;
|
||||
import pp.monopoly.client.gui.popups.*;
|
||||
import pp.monopoly.game.client.ClientGameLogic;
|
||||
import pp.monopoly.game.client.MonopolyClient;
|
||||
import pp.monopoly.game.client.ServerConnection;
|
||||
import pp.monopoly.notification.ClientStateEvent;
|
||||
import pp.monopoly.notification.GameEventListener;
|
||||
import pp.monopoly.notification.InfoTextEvent;
|
||||
import pp.monopoly.notification.Sound;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.dialog.DialogBuilder;
|
||||
import pp.dialog.DialogManager;
|
||||
import pp.graphics.Draw;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.logging.LogManager;
|
||||
|
||||
import static pp.monopoly.Resources.lookup;
|
||||
|
||||
/**
|
||||
* The main class for the Battleship client application.
|
||||
@@ -134,9 +129,10 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
||||
private FoodFieldCard foodField;
|
||||
private GateFieldCard gateField;
|
||||
private BuyCard buyCard;
|
||||
private LooserPopUp looserpopup;
|
||||
private Bankrupt bankrupt;
|
||||
private boolean isBuyCardPopupOpen = false;
|
||||
private final ActionListener BListener = (name, isPressed, tpf) -> handleB(isPressed);
|
||||
private final ActionListener TListener = (name, isPressed, tpf) -> handleT(isPressed);
|
||||
private TestWorld testWorld;
|
||||
|
||||
static {
|
||||
@@ -221,7 +217,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
||||
/**
|
||||
* Returns the current configuration settings for the Battleship client.
|
||||
*
|
||||
* @return The {@link BattleshipClientConfig} instance.
|
||||
* @return The {@link BattleshipClientConfig} instance. //TODO Fehler im Kommentar
|
||||
*/
|
||||
@Override
|
||||
public MonopolyAppConfig getConfig() {
|
||||
@@ -272,36 +268,18 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
||||
inputManager.addMapping("B", new KeyTrigger(KeyInput.KEY_B));
|
||||
inputManager.addListener(BListener, "B");
|
||||
inputManager.addMapping("T", new KeyTrigger(KeyInput.KEY_T));
|
||||
inputManager.addListener(TListener, "T");
|
||||
|
||||
}
|
||||
|
||||
//logik zum wechselnden erscheinen und verschwinden beim drücken von B //TODO süäter entfernen
|
||||
private void handleB(boolean isPressed) {
|
||||
if (isPressed) {
|
||||
Dialog tmp = new BuyCard(this);
|
||||
if (eventCard != null && isBuyCardPopupOpen) {
|
||||
// Schließe das SettingsMenu
|
||||
System.out.println("Schließe BuyCardPopup...");
|
||||
eventCard.close();
|
||||
eventCard = null;
|
||||
tmp.open();
|
||||
} else {
|
||||
// Öffne das SettingsMenu
|
||||
System.out.println("Öffne BuyCardPopup...");
|
||||
eventCard = new EventCard(this);
|
||||
eventCard.open();
|
||||
dialogManager.close(tmp);
|
||||
}
|
||||
Dialog tmp = new Bankrupt(this);
|
||||
tmp.open();
|
||||
}
|
||||
}
|
||||
|
||||
//logik zum wechselnden erscheinen und verschwinden beim drücken von B //TODO süäter entfernen
|
||||
private void handleT(boolean isPressed) {
|
||||
if (isPressed) {
|
||||
testWorld = new TestWorld(this);
|
||||
testWorld.initializeScene();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -320,6 +298,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
||||
|
||||
attachGameSound();
|
||||
attachGameMusic();
|
||||
stateManager.attach(new GameAppState());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -443,6 +422,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
||||
*/
|
||||
@Override
|
||||
public void receivedEvent(ClientStateEvent event) {
|
||||
stateManager.getState(GameAppState.class).setEnabled(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -503,4 +483,9 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
||||
public void disconnect() {
|
||||
serverConnection.disconnect();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
if (serverConnection != null && serverConnection instanceof NetworkSupport) return ((NetworkSupport) serverConnection).getId();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,174 @@
|
||||
package pp.monopoly.client.gui;
|
||||
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.shape.Quad;
|
||||
import com.jme3.texture.Texture;
|
||||
import com.simsilica.lemur.*;
|
||||
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
||||
import com.simsilica.lemur.component.SpringGridLayout;
|
||||
import com.simsilica.lemur.style.ElementId;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.notification.Sound;
|
||||
|
||||
public class BuildingAdminMenu extends Dialog {
|
||||
private final MonopolyApp app;
|
||||
|
||||
private final Container mainContainer;
|
||||
private final Button backButton = new Button("Zurück");
|
||||
private final Button buildButton = new Button("Bauen");
|
||||
private final Button demolishButton = new Button("Abriss");
|
||||
private final Button takeMortgageButton = new Button("Hypothek aufnehmen");
|
||||
private final Button payMortgageButton = new Button("Hypothek bezahlen");
|
||||
private final Button overviewButton = new Button("Übersicht");
|
||||
|
||||
public BuildingAdminMenu(MonopolyApp app) {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
|
||||
// Background Image
|
||||
addBackgroundImage();
|
||||
|
||||
// Main container for the UI components
|
||||
mainContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X));
|
||||
mainContainer.setPreferredSize(new Vector3f(800, 600, 0));
|
||||
mainContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(1, 1, 1, 0.7f))); // Translucent white background
|
||||
|
||||
// Add header
|
||||
mainContainer.addChild(createHeaderContainer());
|
||||
// Add content
|
||||
mainContainer.addChild(createContent());
|
||||
// Attach main container to GUI node
|
||||
app.getGuiNode().attachChild(mainContainer);
|
||||
mainContainer.setLocalTranslation(
|
||||
(app.getCamera().getWidth() - mainContainer.getPreferredSize().x) / 2,
|
||||
(app.getCamera().getHeight() + mainContainer.getPreferredSize().y) / 2,
|
||||
7
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the header container.
|
||||
*
|
||||
* @return The header container.
|
||||
*/
|
||||
private Container createHeaderContainer() {
|
||||
Container headerContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
|
||||
headerContainer.setPreferredSize(new Vector3f(800, 100, 0));
|
||||
Label headerLabel = headerContainer.addChild(new Label("Grundstücke Verwalten", new ElementId("header")));
|
||||
headerLabel.setFontSize(45);
|
||||
headerLabel.setInsets(new Insets3f(10, 10, 10, 10));
|
||||
return headerContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the main content container with columns for Overview, Build, and Mortgage.
|
||||
*
|
||||
* @return The content container.
|
||||
*/
|
||||
private Container createContent() {
|
||||
Container contentContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
|
||||
contentContainer.setPreferredSize(new Vector3f(800, 500, 0));
|
||||
|
||||
// Overview Column
|
||||
Container overviewColumn = new Container(new SpringGridLayout(Axis.Y, Axis.X));
|
||||
overviewColumn.addChild(new Label("Übersicht:")).setFontSize(30);
|
||||
|
||||
//Building Overview Button
|
||||
overviewButton.setPreferredSize(new Vector3f(200, 50, 0));
|
||||
overviewButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
new PropertyOverviewMenu(app).open();
|
||||
}));
|
||||
overviewColumn.addChild(overviewButton);
|
||||
|
||||
// Back Button
|
||||
backButton.setPreferredSize(new Vector3f(200, 50, 0));
|
||||
backButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
this.close();
|
||||
}));
|
||||
overviewColumn.addChild(backButton);
|
||||
|
||||
contentContainer.addChild(overviewColumn);
|
||||
|
||||
|
||||
// Build Column
|
||||
Container buildColumn = new Container(new SpringGridLayout(Axis.Y, Axis.X));
|
||||
buildColumn.addChild(new Label("Bauen:")).setFontSize(30);
|
||||
|
||||
// Build Houses Button
|
||||
buildButton.setPreferredSize(new Vector3f(200, 50, 0));
|
||||
buildButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
}));
|
||||
buildColumn.addChild(buildButton);
|
||||
|
||||
//Demolish Houses Button
|
||||
demolishButton.setPreferredSize(new Vector3f(200, 50, 0));
|
||||
demolishButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
}));
|
||||
buildColumn.addChild(demolishButton);
|
||||
|
||||
contentContainer.addChild(buildColumn);
|
||||
|
||||
|
||||
// Mortgage Column
|
||||
Container mortgageColumn = new Container(new SpringGridLayout(Axis.Y, Axis.X));
|
||||
mortgageColumn.addChild(new Label("Hypotheken:")).setFontSize(30);
|
||||
|
||||
// Lend Mortgage Button
|
||||
takeMortgageButton.setPreferredSize(new Vector3f(200, 50, 0));
|
||||
takeMortgageButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
}));
|
||||
mortgageColumn.addChild(takeMortgageButton);
|
||||
|
||||
//Repay Mortgage Button
|
||||
payMortgageButton.setPreferredSize(new Vector3f(200, 50, 0));
|
||||
payMortgageButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
}));
|
||||
mortgageColumn.addChild(payMortgageButton);
|
||||
|
||||
contentContainer.addChild(mortgageColumn);
|
||||
|
||||
return contentContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a background image to the dialog.
|
||||
*/
|
||||
private void addBackgroundImage() {
|
||||
Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/unibw-Bib2.png");
|
||||
Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight());
|
||||
Geometry background = new Geometry("Background", quad);
|
||||
Material backgroundMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
backgroundMaterial.setTexture("ColorMap", backgroundImage);
|
||||
background.setMaterial(backgroundMaterial);
|
||||
background.setLocalTranslation(0, 0, 6); // Position behind other GUI elements
|
||||
app.getGuiNode().attachChild(background);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the "Zurück" action.
|
||||
*/
|
||||
private void handleBack() {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void escape() {
|
||||
handleBack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float delta) {
|
||||
// Periodic updates if necessary
|
||||
}
|
||||
}
|
@@ -1,54 +1,162 @@
|
||||
package pp.monopoly.client.gui;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.shape.Quad;
|
||||
import com.jme3.texture.Texture;
|
||||
import com.simsilica.lemur.Axis;
|
||||
import com.simsilica.lemur.Container;
|
||||
import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.TextField;
|
||||
import com.simsilica.lemur.*;
|
||||
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
||||
import com.simsilica.lemur.component.SpringGridLayout;
|
||||
import com.simsilica.lemur.core.VersionedList;
|
||||
import com.simsilica.lemur.core.VersionedReference;
|
||||
import com.simsilica.lemur.style.ElementId;
|
||||
|
||||
import pp.dialog.Dialog;
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.game.server.Player;
|
||||
import pp.monopoly.message.client.ViewAssetsRequest;
|
||||
import pp.monopoly.model.TradeHandler;
|
||||
import pp.monopoly.notification.Sound;
|
||||
|
||||
public class ChoosePartner extends Dialog {
|
||||
|
||||
private final MonopolyApp app;
|
||||
private final Container menuContainer;
|
||||
private Selector<String> playerSelector;
|
||||
private final Button cancelButton = new Button("Abbrechen");
|
||||
private final Button confirmButton = new Button("Bestätigen");
|
||||
private final Container mainContainer;
|
||||
private Container lowerLeftMenu;
|
||||
private Container lowerRightMenu;
|
||||
private Geometry background;
|
||||
private TradeHandler tradeHandler;
|
||||
private VersionedReference<Set<Integer>> selectionRef; // Reference to track selector changes
|
||||
private String lastSelected = ""; // To keep track of the last selected value
|
||||
|
||||
QuadBackgroundComponent translucentWhiteBackground =
|
||||
new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f));
|
||||
|
||||
/**
|
||||
* Constructs the ChoosePartner dialog.
|
||||
*
|
||||
* @param app The Monopoly application instance.
|
||||
*/
|
||||
public ChoosePartner(MonopolyApp app) {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
tradeHandler = new TradeHandler(app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()));
|
||||
app.getGameLogic().send(new ViewAssetsRequest());
|
||||
|
||||
// Hintergrundbild laden und hinzufügen
|
||||
// Background Image
|
||||
addBackgroundImage();
|
||||
|
||||
QuadBackgroundComponent translucentWhiteBackground =
|
||||
new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f));
|
||||
// Main container for the UI components
|
||||
mainContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X));
|
||||
mainContainer.setPreferredSize(new Vector3f(1000, 600, 0));
|
||||
mainContainer.setBackground(translucentWhiteBackground);
|
||||
|
||||
menuContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X));
|
||||
menuContainer.setPreferredSize(new Vector3f(1000, 600, 0)); // Fixed size of the container
|
||||
menuContainer.setBackground(translucentWhiteBackground);
|
||||
// Add title with background
|
||||
Label headerLabel = mainContainer.addChild(new Label("Wähle deinen Handelspartner:", new ElementId("label-Bold")));
|
||||
headerLabel.setFontSize(40);
|
||||
headerLabel.setBackground(new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f)));
|
||||
|
||||
// Create a smaller horizontal container for the label, input field, and spacers
|
||||
Container horizontalContainer = menuContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
|
||||
horizontalContainer.setPreferredSize(new Vector3f(600, 40, 0)); // Adjust container size
|
||||
horizontalContainer.setBackground(null);
|
||||
// Dropdown for player selection
|
||||
mainContainer.addChild(createDropdown());
|
||||
|
||||
Label title = horizontalContainer.addChild(new Label("Wähle deinen Handelspartner:", new ElementId("label-Bold")));
|
||||
title.setFontSize(40);
|
||||
// Add buttons
|
||||
mainContainer.addChild(createButtonContainer());
|
||||
|
||||
// Attach main container to GUI node
|
||||
app.getGuiNode().attachChild(mainContainer);
|
||||
mainContainer.setLocalTranslation(
|
||||
(app.getCamera().getWidth() - mainContainer.getPreferredSize().x) / 2,
|
||||
(app.getCamera().getHeight() + mainContainer.getPreferredSize().y) / 2,
|
||||
4
|
||||
);
|
||||
|
||||
// Initialize selection reference for tracking changes
|
||||
selectionRef = playerSelector.getSelectionModel().createReference();
|
||||
}
|
||||
|
||||
/**
|
||||
* Lädt das Hintergrundbild und fügt es als geometrische Ebene hinzu.
|
||||
* Creates the dropdown menu for selecting a partner.
|
||||
*
|
||||
* @return The dropdown container.
|
||||
*/
|
||||
private Container createDropdown() {
|
||||
Container dropdownContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X));
|
||||
dropdownContainer.setPreferredSize(new Vector3f(100, 80, 0));
|
||||
dropdownContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black)));
|
||||
|
||||
VersionedList<String> playerOptions = new VersionedList<>();
|
||||
|
||||
for (Player player : app.getGameLogic().getPlayerHandler().getPlayers()) {
|
||||
if (player.getId() != app.getId()) {
|
||||
playerOptions.add(player.getName() + " (ID: " + player.getId() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
playerSelector = new Selector<>(playerOptions, "glass");
|
||||
dropdownContainer.addChild(playerSelector);
|
||||
Vector3f dimens = dropdownContainer.getPreferredSize();
|
||||
Vector3f dimens2 = playerSelector.getPopupContainer().getPreferredSize();
|
||||
dimens2.setX(dimens.getX());
|
||||
playerSelector.getPopupContainer().setPreferredSize(new Vector3f(200, 200, 3));
|
||||
playerSelector.setLocalTranslation(0, 0, 5);
|
||||
|
||||
// Set initial selection
|
||||
if (!playerOptions.isEmpty()) {
|
||||
onDropdownSelectionChanged(playerOptions.get(0));
|
||||
}
|
||||
|
||||
return dropdownContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the button container with cancel and confirm buttons.
|
||||
*
|
||||
* @return The button container.
|
||||
*/
|
||||
private Container createButtonContainer() {
|
||||
Container buttonContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
|
||||
buttonContainer.setBackground(translucentWhiteBackground);
|
||||
|
||||
// "Abbrechen" button
|
||||
lowerLeftMenu = new Container();
|
||||
cancelButton.setPreferredSize(new Vector3f(200, 60, 0));
|
||||
cancelButton.setFontSize(30);
|
||||
cancelButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
close();
|
||||
}));
|
||||
lowerLeftMenu.addChild(cancelButton);
|
||||
|
||||
// Position the container near 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);
|
||||
|
||||
// "Bestätigen" button
|
||||
lowerRightMenu = new Container();
|
||||
confirmButton.setPreferredSize(new Vector3f(200, 60, 0));
|
||||
confirmButton.setFontSize(30);
|
||||
confirmButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
close();
|
||||
new TradeMenu(app, tradeHandler).open();
|
||||
}));
|
||||
lowerRightMenu.addChild(confirmButton);
|
||||
|
||||
// Position the container near the bottom-right corner
|
||||
lowerRightMenu.setLocalTranslation(new Vector3f(app.getCamera().getWidth() - 320, 170, 5)); // X: 220px from the right, Y: 50px above the bottom
|
||||
app.getGuiNode().attachChild(lowerRightMenu);
|
||||
|
||||
return buttonContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a background image to the dialog.
|
||||
*/
|
||||
private void addBackgroundImage() {
|
||||
Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/unibw-Bib2.png");
|
||||
@@ -57,8 +165,60 @@ public class ChoosePartner extends Dialog {
|
||||
Material backgroundMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
backgroundMaterial.setTexture("ColorMap", backgroundImage);
|
||||
background.setMaterial(backgroundMaterial);
|
||||
background.setLocalTranslation(0, 0, -1); // Hintergrundebene
|
||||
|
||||
background.setLocalTranslation(0, 0, 3); // Position behind other GUI elements
|
||||
app.getGuiNode().attachChild(background);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the escape action for the dialog.
|
||||
*/
|
||||
@Override
|
||||
public void escape() {
|
||||
new SettingsMenu(app).open();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the dialog periodically, called by the dialog manager.
|
||||
*
|
||||
* @param delta The time elapsed since the last update.
|
||||
*/
|
||||
@Override
|
||||
public void update(float delta) {
|
||||
// Check if the selection has changed
|
||||
if (selectionRef.update()) {
|
||||
String selected = playerSelector.getSelectedItem();
|
||||
if (!selected.equals(lastSelected)) {
|
||||
lastSelected = selected;
|
||||
onDropdownSelectionChanged(selected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
app.getGuiNode().detachChild(playerSelector);
|
||||
app.getGuiNode().detachChild(lowerLeftMenu);
|
||||
app.getGuiNode().detachChild(lowerRightMenu);
|
||||
app.getGuiNode().detachChild(mainContainer);
|
||||
app.getGuiNode().detachChild(background);
|
||||
super.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for when the dropdown selection changes.
|
||||
*/
|
||||
private void onDropdownSelectionChanged(String selected) {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
int idStart = selected.indexOf("(ID: ") + 5; // Find start 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
|
||||
int playerId = Integer.parseInt(idStr); // Convert the ID to an integer
|
||||
|
||||
// Find the player by ID
|
||||
Player selectedPlayer = app.getGameLogic().getPlayerHandler().getPlayerById(playerId);
|
||||
|
||||
if (selectedPlayer != null) {
|
||||
tradeHandler.setReceiver(selectedPlayer); // Set the receiver in TradeHandler
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -66,7 +66,7 @@ public class CreateGameMenu extends Dialog {
|
||||
|
||||
final MonopolyApp app = network.getApp();
|
||||
|
||||
int screenWidth = app.getContext().getSettings().getWidth();
|
||||
int screenWidth = app.getContext().getSettings().getWidth();
|
||||
int screenHeight = app.getContext().getSettings().getHeight();
|
||||
|
||||
// Set up the background image
|
||||
|
@@ -25,6 +25,7 @@ import com.simsilica.lemur.style.ElementId;
|
||||
|
||||
import pp.dialog.Dialog;
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.game.server.PlayerColor;
|
||||
import pp.monopoly.message.client.PlayerReady;
|
||||
import pp.monopoly.notification.Sound;
|
||||
|
||||
@@ -39,7 +40,7 @@ public class LobbyMenu extends Dialog {
|
||||
private Container lowerLeftMenu;
|
||||
private Container lowerRightMenu;
|
||||
|
||||
private TextField playerInputField = new TextField("Spieler 1");
|
||||
private TextField playerInputField;
|
||||
private TextField startingCapital = new TextField("15000");
|
||||
private String figure;
|
||||
|
||||
@@ -47,6 +48,7 @@ public class LobbyMenu extends Dialog {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
|
||||
playerInputField = new TextField("Spieler "+(app.getId()+1));
|
||||
// Hintergrundbild laden und hinzufügen
|
||||
addBackgroundImage();
|
||||
|
||||
@@ -88,6 +90,7 @@ public class LobbyMenu extends Dialog {
|
||||
|
||||
// Dropdowns and Labels
|
||||
Container dropdownContainer = menuContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
|
||||
dropdownContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black)));
|
||||
dropdownContainer.setPreferredSize(new Vector3f(800, 200, 0));
|
||||
dropdownContainer.setBackground(null);
|
||||
dropdownContainer.setInsets(new Insets3f(10, 0, 0, 0));
|
||||
@@ -118,10 +121,18 @@ public class LobbyMenu extends Dialog {
|
||||
figures.add("OOP");
|
||||
figures.add("Handyholster");
|
||||
|
||||
|
||||
|
||||
Selector<String> figureDropdown = new Selector<>(figures, "glass");
|
||||
figureDropdown.setBackground(new QuadBackgroundComponent(ColorRGBA.DarkGray));
|
||||
figureDropdown.setPreferredSize(new Vector3f(100, 20, 0));
|
||||
figureDropdownContainer.addChild(figureDropdown);
|
||||
Vector3f dimens = dropdownContainer.getPreferredSize();
|
||||
Vector3f dimens2 = figureDropdown.getPopupContainer().getPreferredSize();
|
||||
dimens2.setX( dimens.getX() );
|
||||
figureDropdown.getPopupContainer().setPreferredSize(new Vector3f(200,200,5));
|
||||
figureDropdown.getSelectionModel().setSelection(0);
|
||||
figure = "Laptop";
|
||||
|
||||
addSelectionActionListener(figureDropdown, this::onDropdownSelectionChanged);
|
||||
|
||||
@@ -153,6 +164,7 @@ public class LobbyMenu extends Dialog {
|
||||
readyButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
toggleReady();
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
readyButton.setBackground(new QuadBackgroundComponent(ColorRGBA.DarkGray));
|
||||
}));
|
||||
lowerRightMenu.addChild(readyButton);
|
||||
|
||||
@@ -161,7 +173,7 @@ public class LobbyMenu extends Dialog {
|
||||
app.getGuiNode().attachChild(lowerRightMenu);
|
||||
|
||||
// Add a colored circle between the input field and the dropdown menu
|
||||
circle = createCircle( ColorRGBA.Red); // 50 is the diameter, Red is the color
|
||||
circle = createCircle(); // 50 is the diameter, Red is the color
|
||||
circle.setLocalTranslation(new Vector3f(
|
||||
(app.getCamera().getWidth()) / 2, // Center horizontally
|
||||
(app.getCamera().getHeight() / 2) - 90, // Adjust Y position
|
||||
@@ -195,19 +207,33 @@ public class LobbyMenu extends Dialog {
|
||||
app.getGuiNode().attachChild(background);
|
||||
}
|
||||
|
||||
private Geometry createCircle(ColorRGBA color) {
|
||||
private Geometry createCircle() {
|
||||
|
||||
Sphere sphere = new Sphere(90,90,60.0f);
|
||||
Geometry circleGeometry = new Geometry("Circle", sphere);
|
||||
|
||||
// Create a material with a solid color
|
||||
Material material = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
material.setColor("Color", color); // Set the desired color
|
||||
material.setColor("Color", idToColor()); // Set the desired color
|
||||
circleGeometry.setMaterial(material);
|
||||
|
||||
return circleGeometry;
|
||||
}
|
||||
|
||||
private ColorRGBA idToColor() {
|
||||
switch (app.getId()+1) {
|
||||
case 1: return PlayerColor.CYAN.getColor();
|
||||
case 2: return PlayerColor.YELLOW.getColor();
|
||||
case 3: return PlayerColor.RED.getColor();
|
||||
case 4: return PlayerColor.PINK.getColor();
|
||||
case 5: return PlayerColor.GREEN.getColor();
|
||||
case 6: return PlayerColor.PURPLE.getColor();
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Schaltet den "Bereit"-Status um.
|
||||
*/
|
||||
@@ -231,7 +257,6 @@ public class LobbyMenu extends Dialog {
|
||||
public void update(float tpf) {
|
||||
if (selectionRef.update()) {
|
||||
String selected = selectionRef.get().toString();
|
||||
System.out.println(selected);
|
||||
listener.onSelectionChanged(selected);
|
||||
}
|
||||
}
|
||||
@@ -260,7 +285,6 @@ public class LobbyMenu extends Dialog {
|
||||
* Callback for when the dropdown selection changes.
|
||||
*/
|
||||
private void onDropdownSelectionChanged(String selected) {
|
||||
System.out.println("Selected: " + selected);
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
switch (selected) {
|
||||
case "[0]":
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
@@ -1,94 +1,147 @@
|
||||
package pp.monopoly.client.gui;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.shape.Box;
|
||||
import com.jme3.texture.Texture;
|
||||
import java.util.List;
|
||||
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.client.gui.popups.BuyCard;
|
||||
import pp.monopoly.client.gui.popups.EventCard;
|
||||
import pp.monopoly.client.gui.popups.FoodFieldCard;
|
||||
import pp.monopoly.client.gui.popups.GateFieldCard;
|
||||
import pp.monopoly.game.server.Player;
|
||||
import pp.monopoly.model.fields.BuildingProperty;
|
||||
import pp.monopoly.model.fields.FoodField;
|
||||
import pp.monopoly.model.fields.GateField;
|
||||
import pp.monopoly.model.fields.PropertyField;
|
||||
import pp.monopoly.notification.DiceRollEvent;
|
||||
import pp.monopoly.notification.EventCardEvent;
|
||||
import pp.monopoly.notification.GameEventListener;
|
||||
import pp.monopoly.notification.PopUpEvent;
|
||||
|
||||
/**
|
||||
* TestWorld zeigt eine einfache Szene mit einem texturierten Quadrat.
|
||||
* Die Kamera wird durch den CameraController gesteuert.
|
||||
* TestWorld zeigt eine einfache Szene mit Spielfeld und Spielfiguren.
|
||||
*/
|
||||
public class TestWorld {
|
||||
|
||||
private final MonopolyApp app;
|
||||
private CameraController cameraController; // Steuert die Kamera
|
||||
private final List<Player> players; // Liste der Spieler, bereits aus GameStart geladen
|
||||
private CameraController cameraController;
|
||||
|
||||
/**
|
||||
* Konstruktor für TestWorld.
|
||||
* Konstruktor für die TestWorld.
|
||||
*
|
||||
* @param app Die Hauptanwendung (MonopolyApp)
|
||||
* @param app Die Hauptanwendung
|
||||
* @param players Die Liste der Spieler mit ihren Figuren
|
||||
*/
|
||||
public TestWorld(MonopolyApp app) {
|
||||
public TestWorld(MonopolyApp app, List<Player> players) {
|
||||
this.app = app;
|
||||
this.players = players;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialisiert die Szene und startet die Kamerabewegung.
|
||||
* Initialisiert die Szene mit Spielfeld und Figuren.
|
||||
*/
|
||||
public void initializeScene() {
|
||||
app.getGuiNode().detachAllChildren(); // Entferne GUI
|
||||
app.getRootNode().detachAllChildren(); // Entferne andere Szenenobjekte
|
||||
// Entferne bestehende Inhalte
|
||||
app.getGuiNode().detachAllChildren();
|
||||
app.getRootNode().detachAllChildren();
|
||||
|
||||
setSkyColor(); // Setze den Himmel auf hellblau
|
||||
createBoard(); // Erstelle das Spielfeld
|
||||
System.out.println("Szene initialisiert.");
|
||||
|
||||
// Erstelle den CameraController
|
||||
cameraController = new CameraController(
|
||||
app.getCamera(), // Die Kamera der App
|
||||
Vector3f.ZERO, // Fokus auf die Mitte des Spielfelds
|
||||
4, // Radius des Kreises
|
||||
15, // Höhe der Kamera
|
||||
0 // Geschwindigkeit der Bewegung
|
||||
);
|
||||
|
||||
// Füge die Toolbar hinzu
|
||||
new Toolbar(app).open();
|
||||
|
||||
cameraController.setPosition(0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Aktualisiert die Kameraposition.
|
||||
*
|
||||
* @param tpf Zeit pro Frame
|
||||
*/
|
||||
public void update(float tpf) {
|
||||
if (cameraController != null) {
|
||||
cameraController.update(tpf);
|
||||
}
|
||||
// Initialisiere Szene
|
||||
setSkyColor();
|
||||
createBoard();
|
||||
createPlayerFigures(); // Lädt Figuren aus der bereits vorhandenen Liste
|
||||
setupCamera();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt die Hintergrundfarbe der Szene auf hellblau.
|
||||
*/
|
||||
private void setSkyColor() {
|
||||
app.getViewPort().setBackgroundColor(new ColorRGBA(0.5f, 0.7f, 1.0f, 1.0f)); // Hellblauer Himmel
|
||||
app.getViewPort().setBackgroundColor(new com.jme3.math.ColorRGBA(0.5f, 0.7f, 1.0f, 1.0f));
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstelle das Spielfeld.
|
||||
* Erstellt das Spielfeld und fügt es zur Szene hinzu.
|
||||
*/
|
||||
private void createBoard() {
|
||||
// Erstelle ein Quadrat
|
||||
Box box = new Box(10, 0.1f, 10); // Dünnes Quadrat für die Textur
|
||||
Geometry geom = new Geometry("Board", box);
|
||||
try {
|
||||
// Erstelle das Spielfeld als flaches Rechteck
|
||||
com.jme3.scene.shape.Box box = new com.jme3.scene.shape.Box(10, 0.1f, 10); // Breite, Höhe, Tiefe
|
||||
com.jme3.scene.Geometry geom = new com.jme3.scene.Geometry("Board", box);
|
||||
|
||||
// Setze das Material mit Textur
|
||||
Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
Texture texture = app.getAssetManager().loadTexture("Pictures/board2.png");
|
||||
mat.setTexture("ColorMap", texture);
|
||||
geom.setMaterial(mat);
|
||||
// Lade und setze das Material mit der Textur
|
||||
com.jme3.material.Material mat = new com.jme3.material.Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
com.jme3.texture.Texture texture = app.getAssetManager().loadTexture("Pictures/board2.png");
|
||||
mat.setTexture("ColorMap", texture);
|
||||
geom.setMaterial(mat);
|
||||
|
||||
app.getRootNode().attachChild(geom);
|
||||
// Positioniere das Spielfeld in der Szene
|
||||
geom.setLocalTranslation(0, -0.1f, 0); // Direkt auf der Grundebene
|
||||
app.getRootNode().attachChild(geom);
|
||||
|
||||
System.out.println("Spielbrett erfolgreich erstellt und hinzugefügt.");
|
||||
} catch (Exception e) {
|
||||
System.err.println("Fehler beim Erstellen des Spielfelds: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt die Spielfiguren basierend auf der bereits bekannten Spielerliste.
|
||||
*/
|
||||
private void createPlayerFigures() {
|
||||
for (int i = 0; i < players.size(); i++) {
|
||||
Player player = players.get(i);
|
||||
try {
|
||||
// Lade das 3D-Modell der Spielfigur
|
||||
com.jme3.scene.Spatial model = app.getAssetManager().loadModel("Models/" + player.getFigure().getType() + ".j3O");
|
||||
model.setLocalScale(0.5f); // Skaliere das Modell
|
||||
model.setLocalTranslation(0, 0, -i * 2); // Positioniere die Figur auf dem Startfeld
|
||||
|
||||
app.getRootNode().attachChild(model);
|
||||
System.out.println("Figur für Spieler " + player.getId() + " hinzugefügt.");
|
||||
} catch (Exception e) {
|
||||
System.err.println("Fehler beim Laden des Modells für Spieler " + player.getId() + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Richtet die Kamera auf das Spielfeld aus.
|
||||
*/
|
||||
private void setupCamera() {
|
||||
app.getCamera().setLocation(new com.jme3.math.Vector3f(0, 20, 20)); // Über dem Spielfeld
|
||||
app.getCamera().lookAt(new com.jme3.math.Vector3f(0, 0, 0), com.jme3.math.Vector3f.UNIT_Y); // Fokus auf Spielfeldmitte
|
||||
System.out.println("Kamera eingerichtet.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Wird bei jedem Frame aufgerufen, um die Szene zu aktualisieren.
|
||||
*
|
||||
* @param tpf Zeit seit dem letzten Frame in Sekunden
|
||||
*/
|
||||
public void update(float tpf) {
|
||||
if (cameraController != null) {
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,287 +1,283 @@
|
||||
|
||||
package pp.monopoly.client.gui;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import com.jme3.font.BitmapText;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector2f;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.simsilica.lemur.*;
|
||||
import com.simsilica.lemur.Axis;
|
||||
import com.simsilica.lemur.Button;
|
||||
import com.simsilica.lemur.Container;
|
||||
import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.component.IconComponent;
|
||||
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.notification.Sound;
|
||||
import pp.monopoly.game.server.Player;
|
||||
import pp.monopoly.game.server.PlayerHandler;
|
||||
import pp.monopoly.message.client.EndTurn;
|
||||
import pp.monopoly.message.client.RollDice;
|
||||
import pp.monopoly.notification.*;
|
||||
|
||||
/**
|
||||
* Toolbar Klasse, die am unteren Rand der Szene angezeigt wird.
|
||||
* Die Buttons bewegen den Würfel auf dem Spielfeld.
|
||||
*/
|
||||
public class Toolbar extends Dialog {
|
||||
public class Toolbar extends Dialog implements GameEventListener {
|
||||
|
||||
private final MonopolyApp app;
|
||||
private final Container toolbarContainer;
|
||||
private final BitmapText positionText; // Anzeige für die aktuelle Position
|
||||
private final float boardLimit = 0.95f; // Grenzen des Bretts
|
||||
private final float stepSize = 0.18f; // Schrittgröße pro Bewegung
|
||||
private int currentPosition = 0; // Aktuelle Position auf dem Spielfeld
|
||||
private final int positionsPerSide = 10; // Anzahl der Positionen pro Seite
|
||||
private final Random random = new Random(); // Zufallsgenerator für den Würfelwurf
|
||||
private Container overviewContainer;
|
||||
private Container accountContainer;
|
||||
private PlayerHandler playerHandler;
|
||||
private Label imageLabel;
|
||||
private Label imageLabel2;
|
||||
private Button diceButton;
|
||||
private Button tradeButton;
|
||||
private Button propertyMenuButton;
|
||||
private Button endTurnButton;
|
||||
|
||||
private volatile boolean animatingDice = false;
|
||||
private volatile DiceRollEvent latestDiceRollEvent = null;
|
||||
|
||||
/**
|
||||
* Konstruktor für die Toolbar.
|
||||
*
|
||||
* @param app Die Hauptanwendung (MonopolyApp)
|
||||
*/
|
||||
public Toolbar(MonopolyApp app) {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
|
||||
// Erstelle die Toolbar
|
||||
toolbarContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y), "toolbar");
|
||||
app.getGameLogic().addListener(this);
|
||||
this.playerHandler = app.getGameLogic().getPlayerHandler();
|
||||
|
||||
// Setze die Position am unteren Rand und die Breite
|
||||
toolbarContainer.setLocalTranslation(
|
||||
0, // Links bündig
|
||||
200, // Höhe über dem unteren Rand
|
||||
0 // Z-Ebene
|
||||
);
|
||||
toolbarContainer.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 200, 0)); // Volle Breite
|
||||
toolbarContainer = createToolbarContainer();
|
||||
app.getGuiNode().attachChild(toolbarContainer);
|
||||
}
|
||||
|
||||
private Container createToolbarContainer() {
|
||||
Container container = new Container(new SpringGridLayout(Axis.X, Axis.Y), "toolbar");
|
||||
container.setLocalTranslation(0, 200, 0);
|
||||
container.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 200, 0));
|
||||
|
||||
// Füge Buttons zur Toolbar hinzu
|
||||
//initializeButtons();
|
||||
// Create account and overview containers
|
||||
accountContainer = container.addChild(new Container());
|
||||
overviewContainer = container.addChild(new Container());
|
||||
receivedEvent(new UpdatePlayerView());
|
||||
|
||||
// Dice section
|
||||
container.addChild(createDiceSection());
|
||||
|
||||
// Menü-Container: Ein Nested-Container für Kontostand und "Meine Gulag Frei Karten"
|
||||
Container accountContainer = toolbarContainer.addChild(new Container());
|
||||
accountContainer.addChild(new Label("Kontostand", new ElementId("label-Bold")));
|
||||
accountContainer.addChild(new Label("6666€", new ElementId("label-Text"))); //TODO Variable hier einsetzen
|
||||
accountContainer.addChild(new Label("Gulag Frei Karten", new ElementId("label-Bold")));
|
||||
accountContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||
// Action menu
|
||||
Container menuContainer = container.addChild(new Container());
|
||||
menuContainer.addChild(createTradeButton());
|
||||
menuContainer.addChild(createPropertyMenuButton());
|
||||
menuContainer.addChild(createEndTurnButton());
|
||||
menuContainer.setBackground(createBackground());
|
||||
|
||||
// Add a spacer between accountContainer and overviewContainer
|
||||
Panel spacer = new Panel(); // Create an empty panel as a spacer
|
||||
spacer.setPreferredSize(new Vector3f(5, 0, 0)); // Adjust the width as needed
|
||||
spacer.setBackground(null);
|
||||
toolbarContainer.addChild(spacer);
|
||||
return container;
|
||||
}
|
||||
|
||||
// Menü-Container: Ein Container für Übersicht
|
||||
Container overviewContainer = toolbarContainer.addChild(new Container());
|
||||
overviewContainer.addChild(new Label("Übersicht", new ElementId("label-Bold")));
|
||||
overviewContainer.addChild(new Label("„Spieler 1“: 1244€", new ElementId("label-Text")));//TODO Variable hier einsetzen
|
||||
overviewContainer.addChild(new Label("„Spieler 2“: 1244€", new ElementId("label-Text")));//TODO Variable hier einsetzen
|
||||
overviewContainer.addChild(new Label("„Spieler 3“: 1244€", new ElementId("label-Text")));//TODO Variable hier einsetzen
|
||||
overviewContainer.addChild(new Label("„Spieler 4“: 1244€", new ElementId("label-Text")));//TODO Variable hier einsetzen
|
||||
overviewContainer.addChild(new Label("„Spieler 5“: 1244€", new ElementId("label-Text")));//TODO Variable hier einsetzen
|
||||
overviewContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||
private Container createDiceSection() {
|
||||
Container diceContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
|
||||
diceContainer.addChild(createDiceDisplay());
|
||||
|
||||
// Menü-Container: Ein Container für Würfel
|
||||
Container diceContainer = toolbarContainer.addChild(new Container());
|
||||
diceContainer.setLayout(new SpringGridLayout(Axis.X, Axis.Y));
|
||||
|
||||
// Create a horizontal container to align leftContainer and rightContainer side by side
|
||||
Container horizontalContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
|
||||
horizontalContainer.setPreferredSize(new Vector3f(200, 150, 0)); // Adjust size as needed
|
||||
|
||||
// Create the first container (leftContainer)
|
||||
Container leftContainer = new Container();
|
||||
leftContainer.setPreferredSize(new Vector3f(100, 150, 0)); // Adjust size as needed
|
||||
|
||||
Label imageLabel = new Label("");
|
||||
IconComponent icon = new IconComponent("Pictures/dice/one.png"); // Icon mit Textur erstellen
|
||||
icon.setIconSize(new Vector2f(100,100)); // Skalierung des Bildes
|
||||
imageLabel.setIcon(icon);
|
||||
|
||||
Label imageLabel2 = new Label("");
|
||||
IconComponent icon2 = new IconComponent("Pictures/dice/two.png"); // Icon mit Textur erstellen
|
||||
icon2.setIconSize(new Vector2f(100,100)); // Skalierung des Bildes
|
||||
imageLabel2.setIcon(icon2);
|
||||
|
||||
// Create the second container (rightContainer)
|
||||
Container rightContainer = new Container();
|
||||
rightContainer.setPreferredSize(new Vector3f(100, 150, 0)); // Adjust size as needed
|
||||
leftContainer.setBackground(null);
|
||||
rightContainer.setBackground(null);
|
||||
diceContainer.setBackground(null);
|
||||
horizontalContainer.setBackground(null);
|
||||
|
||||
imageLabel.setTextVAlignment(VAlignment.Center);
|
||||
imageLabel.setTextHAlignment(HAlignment.Center);
|
||||
imageLabel2.setTextVAlignment(VAlignment.Center);
|
||||
imageLabel2.setTextHAlignment(HAlignment.Center);
|
||||
|
||||
leftContainer.addChild(imageLabel);
|
||||
rightContainer.addChild(imageLabel2);
|
||||
|
||||
|
||||
|
||||
// Add leftContainer and rightContainer to the horizontal container
|
||||
horizontalContainer.addChild(leftContainer);
|
||||
horizontalContainer.addChild(rightContainer);
|
||||
|
||||
// Add the horizontalContainer to the diceContainer (top section)
|
||||
diceContainer.addChild(horizontalContainer);
|
||||
|
||||
// Add the Würfeln button directly below the horizontalContainer
|
||||
Button diceButton = new Button("Würfeln");
|
||||
diceButton.setPreferredSize(new Vector3f(200, 50, 0)); // Full width for Würfeln button
|
||||
diceButton = new Button("Würfeln", new ElementId("button-toolbar"));
|
||||
diceButton.setPreferredSize(new Vector3f(200, 50, 0));
|
||||
diceButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
rollDice();
|
||||
diceButton.setEnabled(false);
|
||||
startDiceAnimation();
|
||||
app.getGameLogic().send(new RollDice());
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
}));
|
||||
diceContainer.addChild(diceButton);
|
||||
|
||||
|
||||
|
||||
|
||||
// Menü-Container: Ein Nested-Container für Handeln, Grundstücke und Zug beenden
|
||||
Container menuContainer = toolbarContainer.addChild(new Container());
|
||||
menuContainer.addChild(new Button("Handeln"));
|
||||
menuContainer.addChild(new Button("Grundstücke"));
|
||||
menuContainer.addChild(new Button("Zug beenden"));
|
||||
menuContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||
|
||||
// Füge die Toolbar zur GUI hinzu
|
||||
app.getGuiNode().attachChild(toolbarContainer);
|
||||
|
||||
// Erstelle die Position-Anzeige
|
||||
positionText = createPositionDisplay();
|
||||
updatePositionDisplay(); // Initialisiere die Anzeige mit der Startposition
|
||||
return diceContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialisiert die Buttons in der Toolbar.
|
||||
*/
|
||||
private void initializeButtons() {
|
||||
addTradeMenuButton(); // Bewegung nach vorne
|
||||
addEndTurnButton(); // Bewegung nach hinten
|
||||
addDiceRollButton(); // Würfel-Button
|
||||
private Container createDiceDisplay() {
|
||||
Container horizontalContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
|
||||
horizontalContainer.setPreferredSize(new Vector3f(200, 150, 0));
|
||||
|
||||
imageLabel = createDiceLabel("Pictures/dice/one.png");
|
||||
imageLabel2 = createDiceLabel("Pictures/dice/two.png");
|
||||
|
||||
horizontalContainer.addChild(createDiceContainer(imageLabel));
|
||||
horizontalContainer.addChild(createDiceContainer(imageLabel2));
|
||||
|
||||
return horizontalContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fügt einen Button mit einer Bewegung hinzu.
|
||||
*
|
||||
* @param label Der Text des Buttons
|
||||
* @param step Schrittweite (+1 für vorwärts, -1 für rückwärts)
|
||||
*/
|
||||
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 void addButton(String label, int step) {
|
||||
Button button = new Button(label);
|
||||
button.setPreferredSize(new Vector3f(150, 50, 0)); // Größe der Buttons
|
||||
button.addClickCommands(source -> moveCube(step));
|
||||
toolbarContainer.addChild(button);
|
||||
}*/
|
||||
private Container createDiceContainer(Label label) {
|
||||
Container container = new Container();
|
||||
container.setPreferredSize(new Vector3f(100, 150, 0));
|
||||
container.addChild(label);
|
||||
return container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fügt den Würfel-Button hinzu, der die Figur entsprechend der gewürfelten Zahl bewegt.
|
||||
*/
|
||||
private Button addDiceRollButton() {
|
||||
Button diceButton = new Button("Würfeln");
|
||||
diceButton.setPreferredSize(new Vector3f(50, 20, 0));
|
||||
diceButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
rollDice();
|
||||
private Button createTradeButton() {
|
||||
tradeButton = new Button("Handeln", new ElementId("button-toolbar"));
|
||||
tradeButton.setPreferredSize(new Vector3f(150, 50, 0));
|
||||
tradeButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
}));
|
||||
toolbarContainer.addChild(diceButton);
|
||||
return diceButton;
|
||||
}
|
||||
|
||||
private void addTradeMenuButton() {
|
||||
Button diceButton = new Button("Handeln");
|
||||
diceButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons
|
||||
diceButton.addClickCommands(s -> {
|
||||
rollDice();
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
this.close();
|
||||
System.out.println("test");
|
||||
new ChoosePartner(app).open();
|
||||
}));
|
||||
return tradeButton;
|
||||
}
|
||||
|
||||
private Button createPropertyMenuButton() {
|
||||
propertyMenuButton = new Button("Grundstücke", new ElementId("button-toolbar"));
|
||||
propertyMenuButton.setPreferredSize(new Vector3f(150, 50, 0));
|
||||
propertyMenuButton.setFontSize(30);
|
||||
propertyMenuButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
new BuildingAdminMenu(app).open();
|
||||
}));
|
||||
return propertyMenuButton;
|
||||
}
|
||||
|
||||
private Button createEndTurnButton() {
|
||||
endTurnButton = new Button("Zug beenden", new ElementId("button-toolbar"));
|
||||
endTurnButton.setPreferredSize(new Vector3f(150, 50, 0));
|
||||
endTurnButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
app.getGameLogic().send(new EndTurn());
|
||||
receivedEvent(new ButtonStatusEvent(false));
|
||||
}));
|
||||
return endTurnButton;
|
||||
}
|
||||
|
||||
private QuadBackgroundComponent createBackground() {
|
||||
return new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f));
|
||||
}
|
||||
|
||||
private void startDiceAnimation() {
|
||||
animatingDice = true;
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
Thread diceAnimation = new Thread(() -> {
|
||||
int[] currentFace = {1};
|
||||
try {
|
||||
while (System.currentTimeMillis() - startTime < 2000) { // Animation läuft für 4 Sekunden
|
||||
currentFace[0] = (currentFace[0] % 6) + 1;
|
||||
|
||||
String rotatingImage1 = diceToString(currentFace[0]);
|
||||
String rotatingImage2 = diceToString((currentFace[0] % 6) + 1);
|
||||
|
||||
IconComponent newIcon1 = new IconComponent(rotatingImage1);
|
||||
newIcon1.setIconSize(new Vector2f(100, 100));
|
||||
app.enqueue(() -> imageLabel.setIcon(newIcon1));
|
||||
|
||||
IconComponent newIcon2 = new IconComponent(rotatingImage2);
|
||||
newIcon2.setIconSize(new Vector2f(100, 100));
|
||||
app.enqueue(() -> imageLabel2.setIcon(newIcon2));
|
||||
|
||||
// Warte 100 ms, bevor die Bilder wechseln
|
||||
Thread.sleep(100);
|
||||
}
|
||||
|
||||
// Animation beenden
|
||||
animatingDice = false;
|
||||
if (latestDiceRollEvent != null) {
|
||||
showFinalDiceResult(latestDiceRollEvent);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
System.err.println("Dice animation interrupted: " + e.getMessage());
|
||||
}
|
||||
}).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) {
|
||||
app.enqueue(() -> {
|
||||
setDiceIcon(imageLabel, diceToString(event.a()));
|
||||
setDiceIcon(imageLabel2, diceToString(event.b()));
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
});
|
||||
toolbarContainer.addChild(diceButton);
|
||||
}// TODO Funktion der Buttons Überarbeiten und prüfen
|
||||
|
||||
private void addEndTurnButton() {
|
||||
Button diceButton = new Button("Grundstücke");
|
||||
diceButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons
|
||||
diceButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
rollDice();
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
}));
|
||||
toolbarContainer.addChild(diceButton);
|
||||
}
|
||||
|
||||
private void addPropertyMenuButton() {
|
||||
Button diceButton = new Button("Zug beenden");
|
||||
diceButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons
|
||||
diceButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
rollDice();
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
}));
|
||||
toolbarContainer.addChild(diceButton);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Simuliert einen Würfelwurf und bewegt die Figur entsprechend.
|
||||
*/
|
||||
private void rollDice() {
|
||||
int diceRoll = random.nextInt(6) + 1; // Zahl zwischen 1 und 6
|
||||
System.out.println("Gewürfelt: " + diceRoll);
|
||||
}
|
||||
|
||||
/**
|
||||
* Berechnet die neue Position des Würfels basierend auf der aktuellen Brettseite und Position.
|
||||
*
|
||||
* @param position Aktuelle Position auf dem Spielfeld
|
||||
* @return Die berechnete Position als Vector3f
|
||||
*/
|
||||
private Vector3f calculatePosition(int position) {
|
||||
int side = position / positionsPerSide; // Seite des Bretts (0 = unten, 1 = rechts, 2 = oben, 3 = links)
|
||||
int offset = position % positionsPerSide; // Position auf der aktuellen Seite
|
||||
|
||||
switch (side) {
|
||||
case 0: // Unten (positive x-Achse)
|
||||
return new Vector3f(-boardLimit + offset * stepSize, 0.1f, -boardLimit + 0.05f);
|
||||
case 1: // Rechts (positive z-Achse)
|
||||
return new Vector3f(boardLimit - 0.05f, 0.1f, -boardLimit + offset * stepSize);
|
||||
case 2: // Oben (negative x-Achse)
|
||||
return new Vector3f(boardLimit - offset * stepSize, 0.1f, boardLimit - 0.05f);
|
||||
case 3: // Links (negative z-Achse)
|
||||
return new Vector3f(-boardLimit + 0.05f, 0.1f, boardLimit - offset * stepSize);
|
||||
default:
|
||||
throw new IllegalArgumentException("Ungültige Position: " + position);
|
||||
private String diceToString(int i) {
|
||||
switch (i) {
|
||||
case 1: return "Pictures/dice/one.png";
|
||||
case 2: return "Pictures/dice/two.png";
|
||||
case 3: return "Pictures/dice/three.png";
|
||||
case 4: return "Pictures/dice/four.png";
|
||||
case 5: return "Pictures/dice/five.png";
|
||||
case 6: return "Pictures/dice/six.png";
|
||||
default: throw new IllegalArgumentException("Invalid dice number: " + i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt die Anzeige für die aktuelle Position.
|
||||
*
|
||||
* @return Das BitmapText-Objekt für die Anzeige
|
||||
*/
|
||||
private BitmapText createPositionDisplay() {
|
||||
BitmapText text = new BitmapText(app.getAssetManager().loadFont("Interface/Fonts/Default.fnt"), false);
|
||||
text.setSize(20); // Schriftgröße
|
||||
text.setLocalTranslation(10, app.getCamera().getHeight() - 10, 0); // Oben links
|
||||
app.getGuiNode().attachChild(text);
|
||||
return text;
|
||||
@Override
|
||||
public void receivedEvent(DiceRollEvent event) {
|
||||
latestDiceRollEvent = event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktualisiert die Anzeige für die aktuelle Position.
|
||||
*/
|
||||
private void updatePositionDisplay() {
|
||||
positionText.setText("Feld-ID: " + currentPosition);
|
||||
@Override
|
||||
public void receivedEvent(UpdatePlayerView event) {
|
||||
accountContainer.clearChildren();
|
||||
overviewContainer.clearChildren();
|
||||
|
||||
accountContainer.addChild(new Label("Kontostand", new ElementId("label-Bold")));
|
||||
accountContainer.addChild(new Label(
|
||||
playerHandler.getPlayerById(app.getId()).getAccountBalance() + " EUR",
|
||||
new ElementId("label-Text")
|
||||
));
|
||||
accountContainer.addChild(new Label("Gulag Karten", new ElementId("label-Bold")));
|
||||
accountContainer.addChild(new Label(
|
||||
playerHandler.getPlayerById(app.getId()).getNumJailCard() + "",
|
||||
new ElementId("label-Text")
|
||||
));
|
||||
accountContainer.setBackground(createBackground());
|
||||
|
||||
overviewContainer.addChild(new Label("Übersicht", new ElementId("label-Bold")));
|
||||
for (Player player : playerHandler.getPlayers()) {
|
||||
if (player.getId() != app.getId()) {
|
||||
overviewContainer.addChild(new Label(
|
||||
player.getName() + ": " + player.getAccountBalance() + " EUR",
|
||||
new ElementId("label-Text")
|
||||
));
|
||||
}
|
||||
}
|
||||
overviewContainer.setBackground(createBackground());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedEvent(ButtonStatusEvent event) {
|
||||
boolean enabled = event.buttonsEnabled();
|
||||
diceButton.setEnabled(enabled);
|
||||
tradeButton.setEnabled(enabled);
|
||||
propertyMenuButton.setEnabled(enabled);
|
||||
endTurnButton.setEnabled(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
app.getGuiNode().detachChild(toolbarContainer);
|
||||
app.getGuiNode().detachChild(positionText);
|
||||
super.close();
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,256 @@
|
||||
package pp.monopoly.client.gui;
|
||||
|
||||
import static java.lang.Math.min;
|
||||
|
||||
import com.jme3.app.Application;
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.shape.Quad;
|
||||
import com.jme3.texture.Texture;
|
||||
import com.simsilica.lemur.*;
|
||||
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
||||
import com.simsilica.lemur.component.SpringGridLayout;
|
||||
import com.simsilica.lemur.core.VersionedList;
|
||||
import com.simsilica.lemur.style.ElementId;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.model.TradeHandler;
|
||||
import pp.monopoly.model.fields.PropertyField;
|
||||
import pp.monopoly.notification.Sound;
|
||||
|
||||
public class TradeMenu extends Dialog {
|
||||
private final MonopolyApp app;
|
||||
private final TradeHandler tradeHandler;
|
||||
|
||||
private final Container mainContainer;
|
||||
private Selector<String> leftBuildingSelector, leftSpecialCardSelector;
|
||||
private Selector<String> rightBuildingSelector, rightSpecialCardSelector;
|
||||
private TextField leftSelectionsField, rightSelectionsField;
|
||||
private TextField leftCurrencyInput, rightCurrencyInput;
|
||||
|
||||
private static final ColorRGBA TRANSLUCENT_WHITE = new ColorRGBA(1, 1, 1, 0.5f);
|
||||
|
||||
public TradeMenu(MonopolyApp app, TradeHandler tradeHandler) {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
this.tradeHandler = tradeHandler;
|
||||
|
||||
addBackgroundImage();
|
||||
|
||||
mainContainer = createMainContainer();
|
||||
app.getGuiNode().attachChild(mainContainer);
|
||||
positionMainContainer();
|
||||
}
|
||||
|
||||
private Container createMainContainer() {
|
||||
Container container = new Container(new SpringGridLayout(Axis.Y, Axis.X));
|
||||
container.setPreferredSize(new Vector3f(1200, 800, 0));
|
||||
container.setBackground(new QuadBackgroundComponent(TRANSLUCENT_WHITE));
|
||||
|
||||
container.addChild(createHeader());
|
||||
container.addChild(createMainContent());
|
||||
return container;
|
||||
}
|
||||
|
||||
private Label createHeader() {
|
||||
Label header = new Label("Handelsmenü", new ElementId("label-Bold"));
|
||||
header.setFontSize(50);
|
||||
header.setInsets(new Insets3f(10, 10, 10, 10));
|
||||
header.setBackground(new QuadBackgroundComponent(TRANSLUCENT_WHITE));
|
||||
return header;
|
||||
}
|
||||
|
||||
private Container createMainContent() {
|
||||
Container mainContent = new Container(new SpringGridLayout(Axis.X, Axis.Y));
|
||||
mainContent.setPreferredSize(new Vector3f(1200, 700, 0));
|
||||
|
||||
mainContent.addChild(createTradeColumn("Wähle Handelsobjekt:", true));
|
||||
mainContent.addChild(createMiddleSection());
|
||||
mainContent.addChild(createTradeColumn("Wähle Zielobjekt:", false));
|
||||
|
||||
Container buttons = mainContent.addChild(new Container(new SpringGridLayout()));
|
||||
Button cancel = new Button("Abbrechen");
|
||||
cancel.addClickCommands(s-> ifTopDialog( () -> {
|
||||
close();
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
}));
|
||||
|
||||
Button trade = new Button("Handeln");
|
||||
trade.addClickCommands(s-> ifTopDialog( () -> {
|
||||
close();
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
}));
|
||||
|
||||
buttons.addChild(cancel);
|
||||
buttons.addChild(trade);
|
||||
|
||||
return mainContent;
|
||||
}
|
||||
|
||||
private Container createTradeColumn(String label, boolean isLeft) {
|
||||
Container column = new Container(new SpringGridLayout(Axis.Y, Axis.X));
|
||||
column.setBackground(new QuadBackgroundComponent(ColorRGBA.White));
|
||||
|
||||
Label columnLabel = column.addChild(new Label(label));
|
||||
columnLabel.setFontSize(24);
|
||||
columnLabel.setBackground(new QuadBackgroundComponent(TRANSLUCENT_WHITE));
|
||||
|
||||
column.addChild(new Label("Gebäude:"));
|
||||
Selector<String> buildingSelector = createPropertySelector(isLeft);
|
||||
column.addChild(buildingSelector);
|
||||
|
||||
column.addChild(new Label("Währung:"));
|
||||
TextField currencyInput = createCurrencyInput();
|
||||
column.addChild(currencyInput);
|
||||
|
||||
column.addChild(new Label("Sonderkarten:"));
|
||||
Selector<String> specialCardSelector = createSpecialCardSelector();
|
||||
styleSelector(specialCardSelector);
|
||||
column.addChild(specialCardSelector);
|
||||
|
||||
assignSelectors(buildingSelector, specialCardSelector, currencyInput, isLeft);
|
||||
return column;
|
||||
}
|
||||
|
||||
private Selector<String> createPropertySelector(boolean isLeft) {
|
||||
VersionedList<String> properties = new VersionedList<>();
|
||||
for (PropertyField field : getPropertyFields(isLeft)) {
|
||||
properties.add(field.getName());
|
||||
}
|
||||
Selector<String> selector = new Selector<>(properties, "glass");
|
||||
styleSelector(selector);
|
||||
return selector;
|
||||
}
|
||||
|
||||
private Selector<String> createSpecialCardSelector() {
|
||||
VersionedList<String> numbers = new VersionedList<>();
|
||||
for (int i = 0; i <= app.getGameLogic().getPlayerHandler().getPlayerById(tradeHandler.getReceiver().getId()).getNumJailCard(); i++) {
|
||||
numbers.add(i+"");
|
||||
}
|
||||
Selector<String> selector = new Selector<>(numbers, "glass");
|
||||
styleSelector(selector);
|
||||
return selector;
|
||||
}
|
||||
|
||||
private Iterable<PropertyField> getPropertyFields(boolean isLeft) {
|
||||
return app.getGameLogic()
|
||||
.getBoardManager()
|
||||
.getPropertyFields(app.getGameLogic()
|
||||
.getPlayerHandler()
|
||||
.getPlayerById(isLeft ? tradeHandler.getReceiver().getId() : tradeHandler.getSender().getId())
|
||||
.getProperties());
|
||||
}
|
||||
|
||||
private TextField createCurrencyInput() {
|
||||
TextField currencyInput = new TextField("");
|
||||
styleTextField(currencyInput);
|
||||
return currencyInput;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the middle section with selection fields and arrows.
|
||||
*
|
||||
* @return The middle section container.
|
||||
*/
|
||||
private Container createMiddleSection() {
|
||||
Container middleSection = new Container(new SpringGridLayout(Axis.Y, Axis.X));
|
||||
middleSection.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8f, 0.8f, 0.8f, 1.0f)));
|
||||
|
||||
// Add combined label for the top
|
||||
Label middleLabelTop = middleSection.addChild(new Label("Gebäude: Währung: Sonderkarten:"));
|
||||
middleLabelTop.setFontSize(24);
|
||||
middleLabelTop.setInsets(new Insets3f(5, 5, 5, 5));
|
||||
|
||||
// Add the left selection field (Quellobjekte)
|
||||
leftSelectionsField = middleSection.addChild(new TextField(""));
|
||||
leftSelectionsField.setPreferredSize(new Vector3f(600, 50, 0));
|
||||
|
||||
// Add arrows
|
||||
Label arrows = middleSection.addChild(new Label("⇅"));
|
||||
arrows.setFontSize(40);
|
||||
|
||||
// Add the right selection field (Zielobjekte)
|
||||
rightSelectionsField = middleSection.addChild(new TextField(""));
|
||||
rightSelectionsField.setPreferredSize(new Vector3f(600, 50, 0));
|
||||
|
||||
// Add combined label for the bottom
|
||||
Label middleLabelBottom = middleSection.addChild(new Label("Gebäude: Währung: Sonderkarten:"));
|
||||
middleLabelBottom.setFontSize(24);
|
||||
middleLabelBottom.setInsets(new Insets3f(5, 5, 5, 5));
|
||||
|
||||
// Spacer
|
||||
Label spacer = middleSection.addChild(new Label(""));
|
||||
spacer.setPreferredSize(new Vector3f(1, 50, 0));
|
||||
|
||||
return middleSection;
|
||||
}
|
||||
|
||||
|
||||
private TextField createSelectionsField(Container parent, boolean isLeft) {
|
||||
TextField field = new TextField("");
|
||||
field.setPreferredSize(new Vector3f(600, 50, 0));
|
||||
parent.addChild(field);
|
||||
|
||||
return field;
|
||||
}
|
||||
|
||||
private Label createArrowLabel() {
|
||||
Label arrowLabel = new Label("⇅");
|
||||
arrowLabel.setFontSize(40);
|
||||
return arrowLabel;
|
||||
}
|
||||
|
||||
private void styleSelector(Selector<String> selector) {
|
||||
selector.setInsets(new Insets3f(5, 10, 5, 10));
|
||||
selector.setBackground(new QuadBackgroundComponent(ColorRGBA.Black));
|
||||
}
|
||||
|
||||
private void styleTextField(TextField textField) {
|
||||
textField.setInsets(new Insets3f(5, 10, 5, 10));
|
||||
textField.setBackground(new QuadBackgroundComponent(ColorRGBA.Black));
|
||||
}
|
||||
|
||||
private void assignSelectors(Selector<String> buildingSelector, Selector<String> specialCardSelector, TextField currencyInput, boolean isLeft) {
|
||||
if (isLeft) {
|
||||
leftBuildingSelector = buildingSelector;
|
||||
leftSpecialCardSelector = specialCardSelector;
|
||||
leftCurrencyInput = currencyInput;
|
||||
} else {
|
||||
rightBuildingSelector = buildingSelector;
|
||||
rightSpecialCardSelector = specialCardSelector;
|
||||
rightCurrencyInput = currencyInput;
|
||||
}
|
||||
}
|
||||
|
||||
private void positionMainContainer() {
|
||||
mainContainer.setLocalTranslation(
|
||||
(app.getCamera().getWidth() - mainContainer.getPreferredSize().x) / 2,
|
||||
(app.getCamera().getHeight() + mainContainer.getPreferredSize().y) / 2,
|
||||
7
|
||||
);
|
||||
}
|
||||
|
||||
private void addBackgroundImage() {
|
||||
Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/unibw-Bib2.png");
|
||||
Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight());
|
||||
Geometry background = new Geometry("Background", quad);
|
||||
Material backgroundMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
backgroundMaterial.setTexture("ColorMap", backgroundImage);
|
||||
background.setMaterial(backgroundMaterial);
|
||||
background.setLocalTranslation(0, 0, 6);
|
||||
app.getGuiNode().attachChild(background);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void escape() {
|
||||
new SettingsMenu(app).open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
app.getGuiNode().detachChild(mainContainer);
|
||||
super.close();
|
||||
}
|
||||
}
|
@@ -0,0 +1,504 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2014, Simsilica, LLC
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package pp.monopoly.client.gui.hslider;
|
||||
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.scene.Spatial;
|
||||
import com.simsilica.lemur.Axis;
|
||||
import com.simsilica.lemur.Button;
|
||||
import com.simsilica.lemur.FillMode;
|
||||
import com.simsilica.lemur.GuiGlobals;
|
||||
import com.simsilica.lemur.HAlignment;
|
||||
import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.Panel;
|
||||
import com.simsilica.lemur.TextField;
|
||||
import com.simsilica.lemur.component.SpringGridLayout;
|
||||
import com.simsilica.lemur.core.GuiControl;
|
||||
import com.simsilica.lemur.core.VersionedReference;
|
||||
import com.simsilica.lemur.grid.GridModel;
|
||||
import com.simsilica.lemur.style.Attributes;
|
||||
import com.simsilica.lemur.style.ElementId;
|
||||
import com.simsilica.lemur.style.StyleDefaults;
|
||||
import com.simsilica.lemur.style.Styles;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Paul Speed
|
||||
*/
|
||||
public class GridPanel extends Panel {
|
||||
|
||||
public static final String ELEMENT_ID = "grid";
|
||||
|
||||
private GridModel<Panel> model;
|
||||
private VersionedReference<GridModel<Panel>> modelRef;
|
||||
private SpringGridLayout layout;
|
||||
private int visibleRows = 5;
|
||||
private int visibleColumns = 5;
|
||||
private int row = 0;
|
||||
private int column = 0;
|
||||
private Float alpha; // for setting to new children
|
||||
private Float[] columnwidths = null;
|
||||
private Float[] rowheight = null;
|
||||
private boolean widthsupdate = false;
|
||||
private HAlignment [] columnHalignement = null;
|
||||
|
||||
|
||||
|
||||
public GridPanel(GridModel<Panel> model ) {
|
||||
this(true, model, new ElementId(ELEMENT_ID), null);
|
||||
}
|
||||
|
||||
public GridPanel(GridModel<Panel> model, String style ) {
|
||||
this(true, model, new ElementId(ELEMENT_ID), style);
|
||||
}
|
||||
|
||||
public GridPanel(GridModel<Panel> model, ElementId elementId, String style ) {
|
||||
this(true, model, elementId, style);
|
||||
}
|
||||
|
||||
protected GridPanel(boolean applyStyles, GridModel<Panel> model,
|
||||
ElementId elementId, String style ) {
|
||||
super(false, elementId, style);
|
||||
|
||||
this.layout = new SpringGridLayout(Axis.Y, Axis.X,
|
||||
FillMode.ForcedEven,
|
||||
FillMode.ForcedEven);
|
||||
getControl(GuiControl.class).setLayout(layout);
|
||||
|
||||
if( applyStyles ) {
|
||||
Styles styles = GuiGlobals.getInstance().getStyles();
|
||||
styles.applyStyles(this, elementId, style);
|
||||
}
|
||||
|
||||
setModel(model);
|
||||
}
|
||||
// change the layout if necessary
|
||||
public void setLayout(SpringGridLayout lay) {
|
||||
this.layout = lay;
|
||||
getControl(GuiControl.class).getLayout().clearChildren();
|
||||
getControl(GuiControl.class).setLayout(layout);
|
||||
|
||||
this.modelRef = null;
|
||||
if( this.model != null ) {
|
||||
this.modelRef = model.createReference();
|
||||
refreshGrid();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@StyleDefaults(ELEMENT_ID)
|
||||
public static void initializeDefaultStyles( Attributes attrs ) {
|
||||
}
|
||||
|
||||
public void setModel( GridModel<Panel> model ) {
|
||||
|
||||
if( this.model == model ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if( this.model != null ) {
|
||||
// Clear the old panel
|
||||
getControl(GuiControl.class).getLayout().clearChildren();
|
||||
this.modelRef = null;
|
||||
}
|
||||
|
||||
this.model = model;
|
||||
|
||||
if( this.model != null ) {
|
||||
this.modelRef = model.createReference();
|
||||
refreshGrid();
|
||||
}
|
||||
}
|
||||
|
||||
public GridModel<Panel> getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public void setRow( int row ) {
|
||||
setLocation(row, column);
|
||||
}
|
||||
|
||||
public int getRow() {
|
||||
return row;
|
||||
}
|
||||
|
||||
public void setColumn( int column ) {
|
||||
setLocation(row, column);
|
||||
}
|
||||
|
||||
public int getColumn() {
|
||||
return column;
|
||||
}
|
||||
|
||||
public Panel getCell( int r, int c ) {
|
||||
r = r - row;
|
||||
c = c - column;
|
||||
if( r < 0 || c < 0 || r >= visibleRows || c >= visibleColumns ) {
|
||||
return null;
|
||||
}
|
||||
return (Panel)layout.getChild(r, c);
|
||||
}
|
||||
|
||||
public void setLocation( int row, int column ) {
|
||||
if( this.row == row && this.column == column ) {
|
||||
return;
|
||||
}
|
||||
this.row = row;
|
||||
this.column = column;
|
||||
refreshGrid();
|
||||
}
|
||||
|
||||
public void setVisibleSize( int rows, int columns ) {
|
||||
this.visibleRows = rows;
|
||||
this.visibleColumns = columns;
|
||||
getControl(GuiControl.class).getLayout().clearChildren();
|
||||
refreshGrid();
|
||||
}
|
||||
|
||||
public void setVisibleRows( int rows ) {
|
||||
setVisibleSize(rows, visibleColumns);
|
||||
}
|
||||
|
||||
public int getVisibleRows() {
|
||||
return visibleRows;
|
||||
}
|
||||
|
||||
public void setVisibleColumns( int columns ) {
|
||||
setVisibleSize(visibleRows, columns);
|
||||
}
|
||||
|
||||
public int getVisibleColumns() {
|
||||
return visibleColumns;
|
||||
}
|
||||
|
||||
public void setAlpha( float alpha, boolean recursive ) {
|
||||
this.alpha = alpha;
|
||||
super.setAlpha(alpha, recursive);
|
||||
}
|
||||
|
||||
protected void refreshGrid() {
|
||||
widthsupdate = false;
|
||||
|
||||
if( model == null ) {
|
||||
getControl(GuiControl.class).getLayout().clearChildren();
|
||||
return;
|
||||
}
|
||||
|
||||
for( int r = row; r < row + visibleRows; r++ ) {
|
||||
for( int c = column; c < column + visibleColumns; c++ ) {
|
||||
Node existing = layout.getChild(r-row, c-column);
|
||||
if( r < 0 || r >= model.getRowCount() || c < 0 || c >= model.getColumnCount() ) {
|
||||
// Out of bounds
|
||||
layout.addChild(null, r-row, c-column);
|
||||
} else {
|
||||
Panel child = model.getCell(r, c, (Panel)existing);
|
||||
|
||||
// we check if there is a size for either rowheight or columnwidth stored
|
||||
Float ytemp = null;
|
||||
Float xtemp = null;
|
||||
|
||||
if (columnwidths !=null) {
|
||||
if (columnwidths.length > c) {
|
||||
if (columnwidths[c] != null) xtemp = columnwidths[c];
|
||||
}
|
||||
}
|
||||
|
||||
if (rowheight != null) {
|
||||
if (rowheight.length > r) {
|
||||
if (rowheight[r] !=null) ytemp = rowheight[r];
|
||||
}
|
||||
}
|
||||
// and only if, we set the preferred size
|
||||
if (ytemp !=null || xtemp != null) {
|
||||
child.setPreferredSize(null);
|
||||
if (xtemp != null) child.setPreferredSize(child.getPreferredSize().clone().setX(xtemp));
|
||||
if (ytemp !=null) child.setPreferredSize(child.getPreferredSize().clone().setY(ytemp));
|
||||
}
|
||||
|
||||
if (columnHalignement != null) {
|
||||
if (columnHalignement.length > c) {
|
||||
if (columnHalignement[c] != null) {
|
||||
// we only set the alignement for "text" elements attached to the listbox
|
||||
// for others e.g. progressbar etc. we should call the element and do the changes there
|
||||
if (child instanceof Button) ((Button) child).setTextHAlignment(columnHalignement[c]);
|
||||
if (child instanceof Label) ((Label) child).setTextHAlignment(columnHalignement[c]);
|
||||
if (child instanceof TextField)
|
||||
((TextField) child).setTextHAlignment(columnHalignement[c]);
|
||||
} else if (child instanceof Button) ((Button) child).setTextHAlignment(HAlignment.Left);
|
||||
} else if (child instanceof Button) ((Button) child).setTextHAlignment(HAlignment.Left);
|
||||
} else if (child instanceof Button) ((Button) child).setTextHAlignment(HAlignment.Left);
|
||||
|
||||
if( child != existing ) {
|
||||
// Make sure new children pick up the alpha of the container
|
||||
if( alpha != null && alpha != 1 ) {
|
||||
child.setAlpha(alpha);
|
||||
}
|
||||
|
||||
layout.addChild(child, r-row, c-column);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLogicalState( float tpf ) {
|
||||
super.updateLogicalState(tpf);
|
||||
|
||||
if( modelRef.update() ) {
|
||||
refreshGrid();
|
||||
}
|
||||
|
||||
if (widthsupdate) refreshGrid();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getName() + "[elementId=" + getElementId() + "]";
|
||||
}
|
||||
|
||||
|
||||
public Float[] getColumnwidths() {
|
||||
return columnwidths;
|
||||
}
|
||||
|
||||
public Float[] getRowheights() {
|
||||
return rowheight;
|
||||
}
|
||||
|
||||
|
||||
public void setRowheight(Float rowheight, int rownumber_starting_with_0){
|
||||
// adds or replaces a columnwidth
|
||||
if (rownumber_starting_with_0 < 0) return;
|
||||
int size = rownumber_starting_with_0+1;
|
||||
if (this.rowheight != null) {
|
||||
size = Math.max(size, this.rowheight.length);
|
||||
}
|
||||
preparegridsizes(size,false);
|
||||
setcheckedsize(rowheight,rownumber_starting_with_0,true,true);
|
||||
}
|
||||
|
||||
public void setColumnwidths(Float columnwidth, int columnnumber_starting_with_0) {
|
||||
// adds or replaces a columnwidth
|
||||
if (columnnumber_starting_with_0 <0) return;
|
||||
int size = columnnumber_starting_with_0+1;
|
||||
if (this.columnwidths != null) {
|
||||
size = Math.max(size, this.columnwidths.length);
|
||||
}
|
||||
preparegridsizes(size,true);
|
||||
setcheckedsize(columnwidth,columnnumber_starting_with_0,true,false);
|
||||
}
|
||||
|
||||
|
||||
public void setRowheight (Float[] rowheights_or_null) {
|
||||
// replaces the given rowheights and only keep the number of rows given
|
||||
setRowheight(rowheights_or_null,true);
|
||||
}
|
||||
|
||||
public void setColumnwidths (Float[] columnwidths_or_null) {
|
||||
// replaces the given columnwidths and only keep the number of columns given
|
||||
setColumnwidths(columnwidths_or_null,true);
|
||||
}
|
||||
|
||||
|
||||
public void setRowheight(Float[] rowheights_or_null, boolean write_null_values) {
|
||||
// replaces the given rowheights and only keep the number of rows given
|
||||
// null values either overwrite or will be ignored
|
||||
Integer tmp = null;
|
||||
if (rowheights_or_null != null) tmp = rowheights_or_null.length;
|
||||
if (preparegridsizes(tmp,false)) {
|
||||
for (int i = 0; i <tmp;i++) {
|
||||
setcheckedsize(rowheights_or_null[i],i,write_null_values,true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setColumnwidths(Float[] columnwidths_or_null, boolean write_null_values) {
|
||||
// replaces the given columnwidths_or_null and only keep the number of columns given
|
||||
// null values either overwrite or will be ignored
|
||||
Integer tmp = null;
|
||||
if (columnwidths_or_null != null) tmp = columnwidths_or_null.length;
|
||||
if (preparegridsizes(tmp,true)) {
|
||||
for (int i = 0; i <tmp;i++) {
|
||||
setcheckedsize(columnwidths_or_null[i],i,write_null_values,false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean preparegridsizes(Integer givenfieldsize, boolean width) {
|
||||
// prepares and adjust the size of the field(s) that hold columnwidth or rowheights
|
||||
if (givenfieldsize == null) {
|
||||
if (width) { //either columns or rows will be set null
|
||||
columnwidths =null;
|
||||
} else {
|
||||
rowheight = null;
|
||||
}
|
||||
for (Spatial p: this.getChildren()) {
|
||||
Panel x = (Panel) p;
|
||||
x.setPreferredSize(null); //we set all sizes to 0 as we will recalculate them with next update
|
||||
}
|
||||
widthsupdate = true;
|
||||
return false; // no more activity needed
|
||||
} else {
|
||||
Float[] tmp;
|
||||
tmp = new Float[givenfieldsize];
|
||||
if (width) {
|
||||
if (columnwidths == null) {
|
||||
columnwidths = tmp;
|
||||
return true;
|
||||
}
|
||||
int i = 0;
|
||||
for (Float z:columnwidths) {
|
||||
tmp[i] =z;
|
||||
i++;
|
||||
if (i>= givenfieldsize) break;
|
||||
}
|
||||
columnwidths = tmp; // we get what we have
|
||||
} else {
|
||||
if (rowheight == null) {
|
||||
rowheight = tmp;
|
||||
return true;
|
||||
}
|
||||
int i = 0;
|
||||
for (Float z:rowheight) {
|
||||
tmp[i] =z;
|
||||
i++;
|
||||
if (i>= givenfieldsize) break;
|
||||
}
|
||||
rowheight = tmp; // we get what we have
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void setcheckedsize(Float size, int row_or_column, boolean override, boolean i_am_a_row) {
|
||||
if (override || (size !=null)) {
|
||||
if (i_am_a_row) {
|
||||
rowheight[row_or_column] = size;
|
||||
} else {
|
||||
columnwidths[row_or_column] = size;
|
||||
}
|
||||
widthsupdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// public void setRowheight(Float rowheight_or_null){
|
||||
// if (rowheight_or_null<=0) return;
|
||||
// this.rowheight = rowheight_or_null;
|
||||
// widthsupdate = true;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void setHalignements(HAlignment[] hals) {
|
||||
setHalignements(hals,false);
|
||||
}
|
||||
|
||||
public void setHalignements(HAlignment[] hals, boolean overridestandard) {
|
||||
if (checkexistinghal(hals)) {
|
||||
int i =0;
|
||||
for (HAlignment z:hals) {
|
||||
setHalignementchecked(z,i,overridestandard);
|
||||
i++;
|
||||
if (i>=columnHalignement.length) return; // we ignore given HAlignement that is out of column bound
|
||||
}
|
||||
if (!overridestandard ) return;
|
||||
for (int u = i; u<columnHalignement.length;u++) {
|
||||
setHalignementchecked(null,u,overridestandard); // override existing HAlignements
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setHalignements(HAlignment hal, int column) {
|
||||
checkexistinghal(new HAlignment[]{HAlignment.Center});
|
||||
if (column < columnHalignement.length) setHalignementchecked(hal,column,true);
|
||||
}
|
||||
|
||||
private void setHalignementchecked(HAlignment hal, int column,boolean override) {
|
||||
if (override || (hal !=null)) {
|
||||
columnHalignement[column] = hal;
|
||||
widthsupdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkexistinghal(HAlignment[] givenfield) {
|
||||
// delete the given Halignements
|
||||
if (givenfield == null) {
|
||||
columnHalignement =null;
|
||||
for (Spatial p: this.getChildren()) {
|
||||
Button x = (Button)((Panel) p);
|
||||
x.setTextHAlignment(HAlignment.Left); //standard HAlignement
|
||||
}
|
||||
widthsupdate = true;
|
||||
return false;
|
||||
}
|
||||
// or prepare if we have no columnHalignement yet
|
||||
HAlignment[] tmp;
|
||||
if (columnHalignement == null) {
|
||||
tmp = new HAlignment[model.getColumnCount()];
|
||||
columnHalignement = tmp;
|
||||
} else {
|
||||
if (!(columnHalignement.length ==model.getColumnCount() )) {
|
||||
tmp = new HAlignment[model.getColumnCount()];
|
||||
int i = 0;
|
||||
for (HAlignment z:columnHalignement) {
|
||||
tmp[i] =z;
|
||||
i++;
|
||||
if (i>=model.getColumnCount()) break;
|
||||
}
|
||||
columnHalignement = tmp;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public HAlignment[] getColumnHalignement() {
|
||||
return columnHalignement;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (c) 2014, Simsilica, LLC
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package pp.monopoly.client.gui.hslider;
|
||||
|
||||
import java.util.AbstractList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.simsilica.lemur.core.VersionedObject;
|
||||
import com.simsilica.lemur.core.VersionedReference;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Paul Speed
|
||||
*/
|
||||
public class VersionedList<T> extends AbstractList<T>
|
||||
implements VersionedObject<List<T>> {
|
||||
private long version = 0;
|
||||
private List<T> list;
|
||||
|
||||
protected VersionedList(List<T> items, boolean copy ) {
|
||||
if( copy ) {
|
||||
list = new ArrayList<T>();
|
||||
list.addAll(items);
|
||||
} else {
|
||||
this.list = items;
|
||||
}
|
||||
}
|
||||
|
||||
public VersionedList() {
|
||||
this(new ArrayList<T>(), false);
|
||||
}
|
||||
|
||||
public VersionedList(List<T> items ) {
|
||||
this(items, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a list in a VersionedList instead of copying it.
|
||||
* This is useful for cases where a VersionedList is required
|
||||
* but strict versioning is not, for example, passing a static list
|
||||
* to a ListBox. Changes to the wrapped list obviously don't
|
||||
* trigger version changes in the wrapper. Only changes through
|
||||
* the wrapper will increment the version.
|
||||
*/
|
||||
public static <T> VersionedList<T> wrap( List<T> list ) {
|
||||
return new VersionedList<T>(list, false);
|
||||
}
|
||||
|
||||
public void incrementVersion() { // changed this to public
|
||||
version++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<T> getObject() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VersionedReference<List<T>> createReference() {
|
||||
return new VersionedReference<List<T>>(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get( int i ) {
|
||||
return list.get(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T set( int i, T val ) {
|
||||
T result = list.set(i, val);
|
||||
incrementVersion();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add( int i, T val ) {
|
||||
list.add(i, val);
|
||||
incrementVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T remove( int i ) {
|
||||
T result = list.remove(i);
|
||||
incrementVersion();
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,119 @@
|
||||
package pp.monopoly.client.gui.popups;
|
||||
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.material.RenderState.BlendMode;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.shape.Quad;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Bankrupt ist ein Overlay-Menü, welches aufgerufen werden kann, wenn man mit einem negativen Kontostand den Zug beenden möchte. // TODO welche menü-Klasse
|
||||
*/
|
||||
public class Bankrupt extends Dialog {
|
||||
private final MonopolyApp app;
|
||||
private final Geometry overlayBackground;
|
||||
private final Container bankruptContainer;
|
||||
private final Container backgroundContainer;
|
||||
|
||||
|
||||
|
||||
public Bankrupt(MonopolyApp app) {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
|
||||
|
||||
// Halbtransparentes Overlay hinzufügen
|
||||
overlayBackground = createOverlayBackground();
|
||||
app.getGuiNode().attachChild(overlayBackground);
|
||||
|
||||
// Create the background container
|
||||
backgroundContainer = new Container();
|
||||
backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background
|
||||
app.getGuiNode().attachChild(backgroundContainer);
|
||||
|
||||
|
||||
// Hauptcontainer für die Gebäudekarte
|
||||
bankruptContainer = new Container();
|
||||
bankruptContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f)));
|
||||
bankruptContainer.setPreferredSize(new Vector3f(550,250,10));
|
||||
|
||||
float padding = 10; // Padding around the settingsContainer for the background
|
||||
backgroundContainer.setPreferredSize(bankruptContainer.getPreferredSize().addLocal(padding, padding, 0));
|
||||
|
||||
// Titel
|
||||
// Die Namen werden dynamisch dem BoardManager entnommen
|
||||
Label gateFieldTitle = bankruptContainer.addChild(new Label("Vorsicht !", new ElementId("settings-title"))); //TODO Dicke Schrift
|
||||
gateFieldTitle.setFontSize(48);
|
||||
gateFieldTitle.setColor(ColorRGBA.Black);
|
||||
|
||||
// Text, der auf der Karte steht
|
||||
// Die Preise werden dynamisch dem BoardManager entnommen
|
||||
Container Container = bankruptContainer.addChild(new Container());
|
||||
Container.addChild(new Label("Du hast noch einen negativen Kontostand. Wenn du jetzt deinen Zug beendest, gehst du Bankrott und verlierst das Spiel!", new ElementId("label-Text")));
|
||||
Container.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||
Container.setPreferredSize(bankruptContainer.getPreferredSize().addLocal(-250,-200,0));
|
||||
|
||||
// Beenden-Button
|
||||
Button quitButton = bankruptContainer.addChild(new Button("Bestätigen", new ElementId("button")));
|
||||
quitButton.setFontSize(32);
|
||||
quitButton.addClickCommands(source -> close());
|
||||
|
||||
|
||||
// Zentriere das Menü
|
||||
bankruptContainer.setLocalTranslation(
|
||||
(app.getCamera().getWidth() - bankruptContainer.getPreferredSize().x) / 2,
|
||||
(app.getCamera().getHeight() + bankruptContainer.getPreferredSize().y) / 2,
|
||||
8
|
||||
);
|
||||
|
||||
|
||||
backgroundContainer.setLocalTranslation(
|
||||
(app.getCamera().getWidth() - bankruptContainer.getPreferredSize().x - padding) / 2,
|
||||
(app.getCamera().getHeight() + bankruptContainer.getPreferredSize().y+ padding) / 2,
|
||||
7
|
||||
);
|
||||
|
||||
app.getGuiNode().attachChild(bankruptContainer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt einen halbtransparenten Hintergrund für das Menü.
|
||||
*
|
||||
* @return Geometrie des Overlays
|
||||
*/
|
||||
private Geometry createOverlayBackground() {
|
||||
Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight());
|
||||
Geometry overlay = new Geometry("Overlay", quad);
|
||||
Material material = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
material.setColor("Color", new ColorRGBA(0, 0, 0, 0.5f)); // Halbtransparent
|
||||
material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
|
||||
overlay.setMaterial(material);
|
||||
overlay.setLocalTranslation(0, 0, 0);
|
||||
return overlay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schließt das Menü und entfernt die GUI-Elemente.
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
app.getGuiNode().detachChild(bankruptContainer); // Entferne das Menü
|
||||
app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand
|
||||
app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay
|
||||
super.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void escape() {
|
||||
close();
|
||||
}
|
||||
|
||||
}
|
@@ -1,10 +1,6 @@
|
||||
package pp.monopoly.client.gui.popups;
|
||||
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.material.RenderState.BlendMode;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.shape.Quad;
|
||||
import com.simsilica.lemur.Button;
|
||||
import com.simsilica.lemur.Container;
|
||||
import com.simsilica.lemur.Label;
|
||||
@@ -13,43 +9,40 @@ 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.model.fields.BoardManager;
|
||||
import pp.monopoly.model.fields.BuildingProperty;
|
||||
import pp.monopoly.notification.Sound;
|
||||
|
||||
/**
|
||||
* SettingsMenu ist ein Overlay-Menü, das durch ESC aufgerufen werden kann.
|
||||
*/
|
||||
public class BuyCard extends Dialog {
|
||||
private final MonopolyApp app;
|
||||
private final Geometry overlayBackground;
|
||||
private final Container buyCardContainer;
|
||||
private final Container backgroundContainer;
|
||||
|
||||
private int index = 37;
|
||||
|
||||
|
||||
public BuyCard(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);
|
||||
|
||||
// Halbtransparentes Overlay hinzufügen
|
||||
overlayBackground = createOverlayBackground();
|
||||
app.getGuiNode().attachChild(overlayBackground);
|
||||
|
||||
// Create the background container
|
||||
backgroundContainer = new Container();
|
||||
backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background
|
||||
app.getGuiNode().attachChild(backgroundContainer);
|
||||
attachChild(backgroundContainer);
|
||||
|
||||
// Hauptcontainer für die Gebäudekarte
|
||||
buyCardContainer = new Container();
|
||||
buyCardContainer.setBackground(new QuadBackgroundComponent(field.getColor().getColor()));
|
||||
|
||||
|
||||
Label settingsTitle = buyCardContainer.addChild(new Label( field.getName(), new ElementId("settings-title")));
|
||||
settingsTitle.setFontSize(48);
|
||||
|
||||
|
||||
Label title = buyCardContainer.addChild(new Label( field.getName(), new ElementId("label-Bold")));
|
||||
title.setBackground(new QuadBackgroundComponent(field.getColor().getColor()));
|
||||
title.setFontSize(48);
|
||||
|
||||
// Text, der auf der Karte steht
|
||||
// Die Preise werden dynamisch dem BoardManager entnommen
|
||||
@@ -70,9 +63,19 @@ public class BuyCard extends Dialog {
|
||||
// Beenden-Button
|
||||
Button quitButton = buyCardContainer.addChild(new Button("Beenden", new ElementId("button")));
|
||||
quitButton.setFontSize(32);
|
||||
quitButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
System.err.println("Button does something?");
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
close();
|
||||
}));
|
||||
// Kaufen-Button
|
||||
Button buyButton = buyCardContainer.addChild(new Button("Kaufen", new ElementId("button")));
|
||||
buyButton.setFontSize(32);
|
||||
buyButton.addClickCommands(s -> ifTopDialog( () -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
close();
|
||||
app.getGameLogic().send(new BuyPropertyResponse());
|
||||
}));
|
||||
|
||||
float padding = 10; // Padding around the settingsContainer for the background
|
||||
backgroundContainer.setPreferredSize(buyCardContainer.getPreferredSize().addLocal(padding, padding, 0));
|
||||
@@ -94,22 +97,6 @@ public class BuyCard extends Dialog {
|
||||
app.getGuiNode().attachChild(buyCardContainer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt einen halbtransparenten Hintergrund für das Menü.
|
||||
*
|
||||
* @return Geometrie des Overlays
|
||||
*/
|
||||
private Geometry createOverlayBackground() {
|
||||
Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight());
|
||||
Geometry overlay = new Geometry("Overlay", quad);
|
||||
Material material = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
material.setColor("Color", new ColorRGBA(0, 0, 0, 0.5f)); // Halbtransparent
|
||||
material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
|
||||
overlay.setMaterial(material);
|
||||
overlay.setLocalTranslation(0, 0, 0);
|
||||
return overlay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schließt das Menü und entfernt die GUI-Elemente.
|
||||
*/
|
||||
@@ -117,7 +104,6 @@ public class BuyCard extends Dialog {
|
||||
public void close() {
|
||||
app.getGuiNode().detachChild(buyCardContainer); // Entferne das Menü
|
||||
app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand
|
||||
app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay
|
||||
super.close();
|
||||
}
|
||||
|
||||
|
@@ -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( () -> { //TODO Buttonfunktion prüfen
|
||||
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();
|
||||
}
|
||||
}
|
@@ -14,8 +14,6 @@ import com.simsilica.lemur.style.ElementId;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.client.gui.SettingsMenu;
|
||||
import pp.monopoly.model.card.Card; // TODO für den Import der Queue notwendig
|
||||
import pp.monopoly.model.card.DeckHelper;
|
||||
/**
|
||||
* SettingsMenu ist ein Overlay-Menü, das durch ESC aufgerufen werden kann.
|
||||
*/
|
||||
@@ -24,14 +22,13 @@ public class EventCard extends Dialog {
|
||||
private final Geometry overlayBackground;
|
||||
private final Container eventCardContainer;
|
||||
private final Container backgroundContainer;
|
||||
private final String description;
|
||||
|
||||
|
||||
public EventCard(MonopolyApp app) {
|
||||
public EventCard(MonopolyApp app, String description) {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
|
||||
//Generate the corresponfing field
|
||||
Card card = new DeckHelper().drawCard(); // TODO nimmt die Karten gerade unabhängig aus dem DeckHelper
|
||||
this.description = description;
|
||||
|
||||
// Halbtransparentes Overlay hinzufügen
|
||||
overlayBackground = createOverlayBackground();
|
||||
@@ -56,7 +53,7 @@ public class EventCard extends Dialog {
|
||||
// Text, der auf der Karte steht
|
||||
// Die Preise werden dynamisch dem BoardManager entnommen
|
||||
Container propertyValuesContainer = eventCardContainer.addChild(new Container());
|
||||
propertyValuesContainer.addChild(new Label(card.getDescription(), new ElementId("label-Text")));
|
||||
propertyValuesContainer.addChild(new Label(description, new ElementId("label-Text")));
|
||||
propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||
propertyValuesContainer.setPreferredSize(new Vector3f(300,200,10));
|
||||
|
||||
@@ -65,11 +62,6 @@ public class EventCard extends Dialog {
|
||||
quitButton.setFontSize(32);
|
||||
quitButton.addClickCommands(source -> close());
|
||||
|
||||
|
||||
// TODO Kaufen-Button wird nicht mehr benötigt, prüfen ob weg kann
|
||||
//Button buyButton = buyCardContainer.addChild(new Button("Kaufen", new ElementId("button")));
|
||||
//buyButton.setFontSize(32);
|
||||
|
||||
float padding = 10; // Padding around the settingsContainer for the background
|
||||
backgroundContainer.setPreferredSize(eventCardContainer.getPreferredSize().addLocal(padding, padding, 0));
|
||||
|
||||
@@ -119,6 +111,6 @@ public class EventCard extends Dialog {
|
||||
|
||||
@Override
|
||||
public void escape() {
|
||||
new SettingsMenu(app).open();
|
||||
close();
|
||||
}
|
||||
}
|
@@ -5,6 +5,7 @@ import com.jme3.material.RenderState.BlendMode;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.shape.Quad;
|
||||
import com.simsilica.lemur.Button;
|
||||
import com.simsilica.lemur.Container;
|
||||
import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
||||
@@ -13,7 +14,9 @@ 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.model.fields.FoodField;
|
||||
import pp.monopoly.notification.Sound;
|
||||
|
||||
/**
|
||||
* FoodFieldCard erstellt die Geböudekarte vom Brandl und der Truppenküche
|
||||
@@ -23,13 +26,13 @@ public class FoodFieldCard extends Dialog {
|
||||
private final Geometry overlayBackground;
|
||||
private final Container foodFieldContainer;
|
||||
private final Container backgroundContainer;
|
||||
private int index = 12;
|
||||
|
||||
public FoodFieldCard(MonopolyApp app) {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
|
||||
//Generate the corresponfing field
|
||||
int index = app.getGameLogic().getPlayerHandler().getPlayers().get(0).getFieldID();
|
||||
FoodField field = (FoodField) app.getGameLogic().getBoardManager().getFieldAtIndex(index);
|
||||
|
||||
// Halbtransparentes Overlay hinzufügen
|
||||
@@ -68,22 +71,24 @@ public class FoodFieldCard extends Dialog {
|
||||
propertyValuesContainer.addChild(new Label("„Hypothek: " + field.getHypo() + " EUR", new ElementId("label-Text")));
|
||||
propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||
|
||||
|
||||
//TODO eventuell diese Stelle löschen, da nur die BuyCard Kaufen und beenden hat
|
||||
|
||||
/*
|
||||
// Beenden-Button
|
||||
Button quitButton = foodFieldContainer.addChild(new Button("Beenden", new ElementId("button")));
|
||||
quitButton.setFontSize(32);
|
||||
quitButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
close();
|
||||
}));
|
||||
// Kaufen-Button
|
||||
Button buyButton = foodFieldContainer.addChild(new Button("Kaufen", new ElementId("button")));
|
||||
buyButton.setFontSize(32);
|
||||
*/
|
||||
buyButton.addClickCommands(s -> ifTopDialog( () -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
app.getGameLogic().send(new BuyPropertyResponse());
|
||||
}));
|
||||
|
||||
float padding = 10; // Padding around the settingsContainer for the background
|
||||
backgroundContainer.setPreferredSize(foodFieldContainer.getPreferredSize().addLocal(padding, padding, 0));
|
||||
|
||||
|
||||
// Zentriere das Menü
|
||||
foodFieldContainer.setLocalTranslation(
|
||||
(app.getCamera().getWidth() - foodFieldContainer.getPreferredSize().x) / 2,
|
||||
@@ -127,10 +132,6 @@ public class FoodFieldCard extends Dialog {
|
||||
super.close();
|
||||
}
|
||||
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void escape() {
|
||||
new SettingsMenu(app).open();
|
||||
|
@@ -5,6 +5,7 @@ import com.jme3.material.RenderState.BlendMode;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.shape.Quad;
|
||||
import com.simsilica.lemur.Button;
|
||||
import com.simsilica.lemur.Container;
|
||||
import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
||||
@@ -12,7 +13,9 @@ 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.model.fields.GateField;
|
||||
import pp.monopoly.notification.Sound;
|
||||
|
||||
/**
|
||||
* SettingsMenu ist ein Overlay-Menü, das durch ESC aufgerufen werden kann.
|
||||
@@ -22,13 +25,13 @@ public class GateFieldCard extends Dialog {
|
||||
private final Geometry overlayBackground;
|
||||
private final Container gateFieldContainer;
|
||||
private final Container backgroundContainer;
|
||||
private int index = 5;
|
||||
|
||||
public GateFieldCard(MonopolyApp app) {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
|
||||
//Generate the corresponfing field
|
||||
int index = app.getGameLogic().getPlayerHandler().getPlayers().get(0).getFieldID();
|
||||
GateField field = (GateField) app.getGameLogic().getBoardManager().getFieldAtIndex(index);
|
||||
|
||||
// Halbtransparentes Overlay hinzufügen
|
||||
@@ -63,16 +66,21 @@ public class GateFieldCard extends Dialog {
|
||||
propertyValuesContainer.addChild(new Label("„Hypothek: " + field.getHypo() + " EUR", new ElementId("label-Text")));
|
||||
propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||
|
||||
//TODO eventuell diese Stelle löschen, da nur die BuyCard Kaufen und beenden hat
|
||||
|
||||
/*
|
||||
// Beenden-Button
|
||||
Button quitButton = foodFieldContainer.addChild(new Button("Beenden", new ElementId("button")));
|
||||
Button quitButton = gateFieldContainer.addChild(new Button("Beenden", new ElementId("button")));
|
||||
quitButton.setFontSize(32);
|
||||
quitButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
close();
|
||||
}));
|
||||
// Kaufen-Button
|
||||
Button buyButton = foodFieldContainer.addChild(new Button("Kaufen", new ElementId("button")));
|
||||
Button buyButton = gateFieldContainer.addChild(new Button("Kaufen", new ElementId("button")));
|
||||
buyButton.setFontSize(32);
|
||||
*/
|
||||
buyButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
app.getGameLogic().send(new BuyPropertyResponse());
|
||||
close();
|
||||
}));
|
||||
|
||||
float padding = 10; // Padding around the settingsContainer for the background
|
||||
backgroundContainer.setPreferredSize(gateFieldContainer.getPreferredSize().addLocal(padding, padding, 0));
|
||||
@@ -121,10 +129,6 @@ public class GateFieldCard extends Dialog {
|
||||
super.close();
|
||||
}
|
||||
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void escape() {
|
||||
new SettingsMenu(app).open();
|
||||
|
@@ -0,0 +1,187 @@
|
||||
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.Checkbox;
|
||||
import com.simsilica.lemur.Container;
|
||||
import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.ListBox;
|
||||
import com.simsilica.lemur.component.IconComponent;
|
||||
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
||||
import com.simsilica.lemur.core.VersionedList;
|
||||
import com.simsilica.lemur.style.ElementId;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.client.gui.SettingsMenu;
|
||||
import pp.monopoly.game.server.Player;
|
||||
import pp.monopoly.message.client.BuyPropertyResponse;
|
||||
import pp.monopoly.model.fields.BoardManager;
|
||||
import pp.monopoly.model.fields.BuildingProperty;
|
||||
import pp.monopoly.notification.Sound;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
sellhouseContainer.setPreferredSize(new Vector3f(800, 600, 0));
|
||||
|
||||
|
||||
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.Orange));
|
||||
/*
|
||||
// Create a VersionedList for the ListBox model
|
||||
VersionedList<String> checkboxListModel = new VersionedList<>();
|
||||
for (int i = 1; i <= 10; i++) {
|
||||
checkboxListModel.add("Option " + i); // Add items to the list
|
||||
}
|
||||
|
||||
// Create a ListBox with the "glass" style and the model
|
||||
ListBox<String> checkboxListBox = new ListBox<>(checkboxListModel, "glass");
|
||||
checkboxListBox.setPreferredSize(new Vector3f(300, 200, 0)); // Adjust size as needed
|
||||
|
||||
// Add the ListBox to the middle container
|
||||
middleContainer.addChild(checkboxListBox);
|
||||
|
||||
// If you need separate checkboxes (optional), render them separately
|
||||
for (String option : checkboxListModel) {
|
||||
Checkbox checkbox = new Checkbox(option);
|
||||
checkbox.setFontSize(16); // Optional: adjust font size
|
||||
middleContainer.addChild(checkbox); // Add it to the middle container
|
||||
}
|
||||
// Add the ListBox to the middle container
|
||||
middleContainer.addChild(checkboxListBox); */
|
||||
|
||||
// Create a VersionedList for the ListBox model
|
||||
VersionedList<BuildingProperty> listModel = new VersionedList<>();
|
||||
|
||||
// Retrieve current player and their properties
|
||||
Player currentPlayer = app.getGameLogic().getPlayerHandler().getPlayers().get(0);
|
||||
BoardManager boardManager = app.getGameLogic().getBoardManager();
|
||||
|
||||
List<BuildingProperty> playerProperties = boardManager.getPropertyFields(
|
||||
currentPlayer.getProperties()).stream()
|
||||
.filter(property -> property instanceof BuildingProperty)
|
||||
.map(property -> (BuildingProperty) property)
|
||||
.filter(property -> property.getHouses() > 0 || property.getHotel() == 1)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// Populate the list model
|
||||
listModel.addAll(playerProperties);
|
||||
|
||||
// Create a ListBox with the "glass" style and the model
|
||||
ListBox<BuildingProperty> listBox = new ListBox<>(listModel, "glass");
|
||||
listBox.setPreferredSize(new Vector3f(300, 200, 0)); // Adjust size as needed
|
||||
|
||||
// Add selection listener
|
||||
listBox.addClickCommands(item -> {
|
||||
BuildingProperty selected = listBox.getSelectedItem(); // Correct method to retrieve the selected item
|
||||
if (selected != null) {
|
||||
System.out.println("Selected property: " + selected.getName());
|
||||
}
|
||||
});
|
||||
|
||||
// Add the ListBox to the middle container
|
||||
middleContainer.addChild(listBox);
|
||||
|
||||
|
||||
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);
|
||||
BuildingProperty selected = listBox.getSelectedItem();
|
||||
if (selected != null) {
|
||||
System.out.println("Confirmed property: " + selected.getName());
|
||||
// Send the "alter building" message to the server
|
||||
//app.getGameLogic().sendMessage(new AlterBuildingMessage(selected.getId(), false)); TODO Message an Server
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
@@ -0,0 +1,122 @@
|
||||
package pp.monopoly.client.gui.popups;
|
||||
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.material.RenderState.BlendMode;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.shape.Quad;
|
||||
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.notification.Sound;
|
||||
import static pp.monopoly.Resources.lookup;
|
||||
|
||||
/**
|
||||
* TimeOut ist ein Overlay-Menü, welches aufgerufen wird, wenn die Verbindung zum Server unterbrochen wurde.
|
||||
*/
|
||||
public class TimeOut extends Dialog {
|
||||
private final MonopolyApp app;
|
||||
private final Geometry overlayBackground;
|
||||
private final Container timeOutContainer;
|
||||
private final Container backgroundContainer;
|
||||
|
||||
|
||||
|
||||
public TimeOut(MonopolyApp app) {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
|
||||
|
||||
// Halbtransparentes Overlay hinzufügen
|
||||
overlayBackground = createOverlayBackground();
|
||||
app.getGuiNode().attachChild(overlayBackground);
|
||||
|
||||
// Create the background container
|
||||
backgroundContainer = new Container();
|
||||
backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background
|
||||
app.getGuiNode().attachChild(backgroundContainer);
|
||||
|
||||
|
||||
|
||||
// Hauptcontainer für die Gebäudekarte
|
||||
timeOutContainer = new Container();
|
||||
timeOutContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f)));
|
||||
timeOutContainer.setPreferredSize(new Vector3f(550,250,10));
|
||||
|
||||
float padding = 10; // Padding around the settingsContainer for the background
|
||||
backgroundContainer.setPreferredSize(timeOutContainer.getPreferredSize().addLocal(padding, padding, 0));
|
||||
|
||||
// Titel
|
||||
// Die Namen werden dynamisch dem BoardManager entnommen
|
||||
Label gateFieldTitle = timeOutContainer.addChild(new Label("Vorsicht !", new ElementId("settings-title"))); //TODO dicke Schrift
|
||||
gateFieldTitle.setFontSize(48);
|
||||
gateFieldTitle.setColor(ColorRGBA.Black);
|
||||
|
||||
// Text, der auf der Karte steht
|
||||
// Die Preise werden dynamisch dem BoardManager entnommen
|
||||
Container propertyValuesContainer = timeOutContainer.addChild(new Container());
|
||||
propertyValuesContainer.addChild(new Label("Du hast die Verbindung verloren und kannst nichts dagegen machen. Akzeptiere einfach, dass du verloren hast!", new ElementId("label-Text")));
|
||||
propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||
propertyValuesContainer.setPreferredSize(timeOutContainer.getPreferredSize().addLocal(-250,-200,0));
|
||||
|
||||
// Beenden-Button
|
||||
Button quitButton = timeOutContainer.addChild(new Button("Bestätigen", new ElementId("button")));
|
||||
quitButton.setFontSize(32);
|
||||
quitButton.addClickCommands(source -> close());
|
||||
|
||||
|
||||
// Zentriere das Menü
|
||||
timeOutContainer.setLocalTranslation(
|
||||
(app.getCamera().getWidth() - timeOutContainer.getPreferredSize().x) / 2,
|
||||
(app.getCamera().getHeight() + timeOutContainer.getPreferredSize().y) / 2,
|
||||
8
|
||||
);
|
||||
|
||||
|
||||
backgroundContainer.setLocalTranslation(
|
||||
(app.getCamera().getWidth() - timeOutContainer.getPreferredSize().x - padding) / 2,
|
||||
(app.getCamera().getHeight() + timeOutContainer.getPreferredSize().y+ padding) / 2,
|
||||
7
|
||||
);
|
||||
|
||||
app.getGuiNode().attachChild(timeOutContainer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt einen halbtransparenten Hintergrund für das Menü.
|
||||
*
|
||||
* @return Geometrie des Overlays
|
||||
*/
|
||||
private Geometry createOverlayBackground() {
|
||||
Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight());
|
||||
Geometry overlay = new Geometry("Overlay", quad);
|
||||
Material material = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
material.setColor("Color", new ColorRGBA(0, 0, 0, 0.5f)); // Halbtransparent
|
||||
material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
|
||||
overlay.setMaterial(material);
|
||||
overlay.setLocalTranslation(0, 0, 0);
|
||||
return overlay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schließt das Menü und entfernt die GUI-Elemente.
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
app.getGuiNode().detachChild(timeOutContainer); // Entferne das Menü
|
||||
app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand
|
||||
app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay
|
||||
super.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void escape() {
|
||||
close();
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Projekte/monopoly/client/src/main/resources/Pictures/dice/1.png
Normal file
BIN
Projekte/monopoly/client/src/main/resources/Pictures/dice/1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 169 KiB |
BIN
Projekte/monopoly/client/src/main/resources/Pictures/dice/2.png
Normal file
BIN
Projekte/monopoly/client/src/main/resources/Pictures/dice/2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 171 KiB |
BIN
Projekte/monopoly/client/src/main/resources/Pictures/dice/3.png
Normal file
BIN
Projekte/monopoly/client/src/main/resources/Pictures/dice/3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 183 KiB |
BIN
Projekte/monopoly/client/src/main/resources/Pictures/dice/4.png
Normal file
BIN
Projekte/monopoly/client/src/main/resources/Pictures/dice/4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 207 KiB |
BIN
Projekte/monopoly/client/src/main/resources/Pictures/dice/5.png
Normal file
BIN
Projekte/monopoly/client/src/main/resources/Pictures/dice/5.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 105 KiB |
BIN
Projekte/monopoly/client/src/main/resources/Pictures/dice/6.png
Normal file
BIN
Projekte/monopoly/client/src/main/resources/Pictures/dice/6.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 228 KiB |
@@ -34,13 +34,13 @@ public class MonopolyConfig extends Config {
|
||||
* The width of the game map in terms of grid units.
|
||||
*/
|
||||
@Property("map.width")
|
||||
private int mapWidth = 12;
|
||||
private int mapWidth = 10;
|
||||
|
||||
/**
|
||||
* The height of the game map in terms of grid units.
|
||||
*/
|
||||
@Property("map.height")
|
||||
private int mapHeight = 12;
|
||||
private int mapHeight = 10;
|
||||
|
||||
/**
|
||||
* Creates an instance of {@code MonopolyConfig} with default settings.
|
||||
|
@@ -5,9 +5,9 @@ import java.lang.System.Logger.Level;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import pp.monopoly.game.server.Player;
|
||||
import pp.monopoly.game.server.PlayerHandler;
|
||||
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.EventDrawCard;
|
||||
import pp.monopoly.message.server.GameOver;
|
||||
@@ -24,12 +24,17 @@ import pp.monopoly.model.Board;
|
||||
import pp.monopoly.model.IntPoint;
|
||||
import pp.monopoly.model.fields.BoardManager;
|
||||
import pp.monopoly.notification.ClientStateEvent;
|
||||
import pp.monopoly.notification.DiceRollEvent;
|
||||
import pp.monopoly.notification.ButtonStatusEvent;
|
||||
import pp.monopoly.notification.EventCardEvent;
|
||||
import pp.monopoly.notification.GameEvent;
|
||||
import pp.monopoly.notification.GameEventBroker;
|
||||
import pp.monopoly.notification.GameEventListener;
|
||||
import pp.monopoly.notification.InfoTextEvent;
|
||||
import pp.monopoly.notification.PopUpEvent;
|
||||
import pp.monopoly.notification.Sound;
|
||||
import pp.monopoly.notification.SoundEvent;
|
||||
import pp.monopoly.notification.UpdatePlayerView;
|
||||
|
||||
/**
|
||||
* Controls the client-side game logic for Monopoly.
|
||||
@@ -52,10 +57,11 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
/** The current state of the client game logic. */
|
||||
private ClientState state = new LobbyState(this);
|
||||
|
||||
private List<Player> players;
|
||||
private PlayerHandler playerHandler;
|
||||
|
||||
private BoardManager boardManager = new BoardManager();
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a ClientGameLogic with the specified sender object.
|
||||
*
|
||||
@@ -94,8 +100,8 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
state.entry();
|
||||
}
|
||||
|
||||
public List<Player> getPlayers() {
|
||||
return players;
|
||||
public PlayerHandler getPlayerHandler() {
|
||||
return playerHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,7 +150,6 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
LOGGER.log(Level.ERROR, "trying to send {0} with sender==null", msg); //NON-NLS
|
||||
} else {
|
||||
clientSender.send(msg);
|
||||
System.out.println("Message gesendet");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,21 +196,6 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
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()) {
|
||||
setInfoText("You successfully bought " + msg.getPropertyName() + "!");
|
||||
playSound(Sound.MONEY_LOST);
|
||||
} else {
|
||||
setInfoText("Unable to buy " + msg.getPropertyName() + ". Reason: " + msg.getReason());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the result of a dice roll.
|
||||
*
|
||||
@@ -213,9 +203,8 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
*/
|
||||
@Override
|
||||
public void received(DiceResult msg) {
|
||||
setInfoText("You rolled a " + msg.calcTotal() + "!");
|
||||
//Set the dice images
|
||||
playSound(Sound.DICE_ROLL);
|
||||
notifyListeners(new DiceRollEvent(msg.getRollResult().get(0), msg.getRollResult().get(1)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -225,9 +214,8 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
*/
|
||||
@Override
|
||||
public void received(EventDrawCard msg) {
|
||||
setInfoText("Event card drawn: " + msg.getCardDescription());
|
||||
// Kartenlogik
|
||||
playSound(Sound.EVENT_CARD);
|
||||
notifyListeners(new EventCardEvent(msg.getCardDescription()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -238,11 +226,11 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
@Override
|
||||
public void received(GameOver msg) {
|
||||
if (msg.isWinner()) {
|
||||
setInfoText("Congratulations! You have won the game!");
|
||||
|
||||
//Winner popup
|
||||
playSound(Sound.WINNER);
|
||||
} else {
|
||||
setInfoText("Game over. Better luck next time!");
|
||||
|
||||
// Looser popup
|
||||
playSound(Sound.LOSER);
|
||||
}
|
||||
@@ -255,9 +243,9 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
*/
|
||||
@Override
|
||||
public void received(GameStart msg) {
|
||||
players = msg.getPlayers();
|
||||
setInfoText("The game has started! Good luck!");
|
||||
playerHandler = msg.getPlayerHandler();
|
||||
setState(new WaitForTurnState(this));
|
||||
notifyListeners(new ButtonStatusEvent(false));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -268,10 +256,10 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
@Override
|
||||
public void received(JailEvent msg) {
|
||||
if (msg.isGoingToJail()) {
|
||||
setInfoText("You are sent to jail!");
|
||||
|
||||
playSound(Sound.GULAG);
|
||||
} else {
|
||||
setInfoText("You are out of jail!");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,8 +270,8 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
*/
|
||||
@Override
|
||||
public void received(PlayerStatusUpdate msg) {
|
||||
|
||||
setInfoText("Player " + msg.getPlayerName() + " status updated: " + msg.getStatus());
|
||||
playerHandler = msg.getPlayerHandler();
|
||||
notifyListeners(new UpdatePlayerView());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -293,7 +281,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
*/
|
||||
@Override
|
||||
public void received(TimeOutWarning msg) {
|
||||
setInfoText("Warning! Time is running out. You have " + msg.getRemainingTime() + " seconds left.");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -303,7 +291,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
*/
|
||||
@Override
|
||||
public void received(ViewAssetsResponse msg) {
|
||||
setInfoText("Your current assets are being displayed.");
|
||||
boardManager = msg.getboard();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -314,10 +302,10 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
@Override
|
||||
public void received(TradeReply msg) {
|
||||
if (msg.getTradeHandler().getStatus()) {
|
||||
setInfoText("Trade accepted by " + msg.getTradeHandler().getReceiver().getName() + ".");
|
||||
|
||||
playSound(Sound.TRADE_ACCEPTED);
|
||||
} else {
|
||||
setInfoText("Trade rejected by " + msg.getTradeHandler().getReceiver().getName() + ".");
|
||||
|
||||
playSound(Sound.TRADE_REJECTED);
|
||||
}
|
||||
}
|
||||
@@ -329,9 +317,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
*/
|
||||
@Override
|
||||
public void received(TradeRequest msg) {
|
||||
setInfoText("Trade offer received from " + msg.getTradeHandler().getSender().getName());
|
||||
// playSound(Sound.TRADE_REQUEST); no sound effect
|
||||
// notifyListeners();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -341,7 +327,12 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
*/
|
||||
@Override
|
||||
public void received(NextPlayerTurn msg) {
|
||||
setInfoText("It's your turn!");
|
||||
notifyListeners(new ButtonStatusEvent(true));
|
||||
setState(new ActiveState(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(BuyPropertyRequest msg) {
|
||||
notifyListeners(new PopUpEvent());
|
||||
}
|
||||
}
|
||||
|
@@ -7,12 +7,17 @@
|
||||
|
||||
package pp.monopoly.game.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.message.server.BuyPropertyRequest;
|
||||
import pp.monopoly.message.server.DiceResult;
|
||||
import pp.monopoly.message.server.EventDrawCard;
|
||||
import pp.monopoly.message.server.NextPlayerTurn;
|
||||
import pp.monopoly.message.server.PlayerStatusUpdate;
|
||||
import pp.monopoly.model.FieldVisitor;
|
||||
import pp.monopoly.model.Figure;
|
||||
import pp.monopoly.model.card.Card;
|
||||
@@ -36,12 +41,14 @@ public class Player implements FieldVisitor<Void>{
|
||||
private String name;
|
||||
private int accountBalance = 15000;
|
||||
private Figure figure;
|
||||
private List<PropertyField> properties;
|
||||
private List<Integer> properties = new ArrayList<>();
|
||||
private int getOutOfJailCard;
|
||||
private int fieldID;
|
||||
private DiceResult rollResult;
|
||||
private final PlayerHandler handler;
|
||||
private PlayerState state = new LobbyState();
|
||||
private transient final PlayerHandler handler;
|
||||
private transient PlayerState state = new WaitForTurnState();
|
||||
private int doubletscounter = 0;
|
||||
private boolean mayRollDice = false;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
@@ -76,15 +83,19 @@ public class Player implements FieldVisitor<Void>{
|
||||
public void setFigure(Figure figure) {
|
||||
this.figure = figure;
|
||||
}
|
||||
|
||||
public Figure getFigure(){
|
||||
return figure;
|
||||
}
|
||||
|
||||
public PlayerColor getColor() {
|
||||
switch ((id%6)+1) {
|
||||
case 1: return PlayerColor.BLUE;
|
||||
case 2: return PlayerColor.GREEN_DARK;
|
||||
case 3: return PlayerColor.GREEN_LIGHT;
|
||||
case 1: return PlayerColor.CYAN;
|
||||
case 2: return PlayerColor.YELLOW;
|
||||
case 3: return PlayerColor.RED;
|
||||
case 4: return PlayerColor.PINK;
|
||||
case 5: return PlayerColor.RED;
|
||||
case 6: return PlayerColor.YELLOW;
|
||||
case 5: return PlayerColor.GREEN;
|
||||
case 6: return PlayerColor.PURPLE;
|
||||
|
||||
default:
|
||||
return null;
|
||||
@@ -124,6 +135,8 @@ public class Player implements FieldVisitor<Void>{
|
||||
}
|
||||
void setActive() {
|
||||
state = new ActiveState();
|
||||
doubletscounter = 0;
|
||||
mayRollDice = true;
|
||||
}
|
||||
|
||||
boolean finishTurn() {
|
||||
@@ -154,20 +167,37 @@ public class Player implements FieldVisitor<Void>{
|
||||
*/
|
||||
public int movePos(int position){
|
||||
fieldID = fieldID+position;
|
||||
System.out.println("Aktuelle Position" +fieldID);
|
||||
System.err.println("Würfelergebniss"+ rollResult.calcTotal());
|
||||
if(fieldID >= 40) {
|
||||
fieldID = fieldID%40;
|
||||
earnMoney(2000);
|
||||
}
|
||||
figure.moveTo(fieldID);
|
||||
getHandler().getLogic().send(this, new PlayerStatusUpdate(handler));
|
||||
handler.getLogic().getBoardManager().getFieldAtIndex(fieldID).accept(this);
|
||||
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
|
||||
* @return List of all properties owned by this player
|
||||
*/
|
||||
public List<PropertyField> getProperties() {
|
||||
public List<Integer> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
@@ -178,7 +208,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
*/
|
||||
public void buyProperty(PropertyField property) {
|
||||
if (property.getOwner() == null && accountBalance >= property.getPrice()) {
|
||||
properties.add(property);
|
||||
properties.add(property.getId());
|
||||
property.setOwner(this);
|
||||
pay(property.getPrice());
|
||||
}
|
||||
@@ -277,30 +307,41 @@ public class Player implements FieldVisitor<Void>{
|
||||
|
||||
@Override
|
||||
public Void visit(BuildingProperty field) {
|
||||
int rent = field.calcRent();
|
||||
|
||||
field.getOwner().earnMoney(rent);
|
||||
pay(rent);
|
||||
if(field.getOwner() == null) {
|
||||
getHandler().getLogic().send(this, new BuyPropertyRequest());
|
||||
} else if (field.getOwner() != this){
|
||||
int rent = field.calcRent();
|
||||
field.getOwner().earnMoney(rent);
|
||||
pay(rent);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(FoodField field) {
|
||||
int factor = 4;
|
||||
if (field.getOwner().getNumProp(field) == 2) {
|
||||
factor = 10;
|
||||
if(field.getOwner() == null) {
|
||||
getHandler().getLogic().send(this, new BuyPropertyRequest());
|
||||
} 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
pay(rent);
|
||||
field.getOwner().earnMoney(rent);
|
||||
pay(rent);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -319,21 +360,21 @@ public class Player implements FieldVisitor<Void>{
|
||||
@Override
|
||||
public Void visit(EventField field) {
|
||||
Card c = getHandler().getLogic().getDeckHelper().drawCard();
|
||||
getHandler().getLogic().getDeckHelper().visit(c, this);
|
||||
getHandler().getLogic().getDeckHelper().visit(c, this); //Logic
|
||||
getHandler().getLogic().send(this, new EventDrawCard(c.getDescription())); // Card notification
|
||||
getHandler().getLogic().send(this, new PlayerStatusUpdate(getHandler())); //update view
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(WacheField field) {
|
||||
movePos(10);
|
||||
setPosition(10);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(GoField field) {
|
||||
earnMoney(2000);
|
||||
GulagField res = (GulagField) handler.getLogic().getBoardManager().getFieldAtIndex(10);
|
||||
res.accept(this);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -346,6 +387,16 @@ public class Player implements FieldVisitor<Void>{
|
||||
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
|
||||
* @param field the type of field to search for
|
||||
@@ -353,7 +404,9 @@ public class Player implements FieldVisitor<Void>{
|
||||
*/
|
||||
public int getNumProp(PropertyField field) {
|
||||
int count = 0;
|
||||
for (PropertyField propertyField : properties) {
|
||||
if (properties.isEmpty()) return 0;
|
||||
|
||||
for (PropertyField propertyField : getPropertyFields()) {
|
||||
if (propertyField.getClass() == field.getClass()) {
|
||||
count++;
|
||||
}
|
||||
@@ -364,7 +417,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
|
||||
public int getNumHouses() {
|
||||
int total = 0;
|
||||
for (PropertyField field : properties) {
|
||||
for (PropertyField field : getPropertyFields()) {
|
||||
if (field.getClass() == BuildingProperty.class) {
|
||||
total += ((BuildingProperty) field).getHouses();
|
||||
}
|
||||
@@ -374,7 +427,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
|
||||
public int getNumHotels() {
|
||||
int total = 0;
|
||||
for (PropertyField field : properties) {
|
||||
for (PropertyField field : getPropertyFields()) {
|
||||
if (field.getClass() == BuildingProperty.class) {
|
||||
total += ((BuildingProperty) field).getHotel();
|
||||
}
|
||||
@@ -405,7 +458,21 @@ public class Player implements FieldVisitor<Void>{
|
||||
* @return a List of two integers representing the dice roll results
|
||||
*/
|
||||
DiceResult rollDice() {
|
||||
return state.rollDice();
|
||||
if (mayRollDice) {
|
||||
state.rollDice();
|
||||
}
|
||||
if (rollResult.isDoublets()) {
|
||||
doubletscounter++;
|
||||
mayRollDice = true;
|
||||
getHandler().getLogic().send(this, new NextPlayerTurn());
|
||||
setName(name);
|
||||
if (doubletscounter >= 3) {
|
||||
setPosition(10);
|
||||
}
|
||||
} else {
|
||||
mayRollDice = false;
|
||||
}
|
||||
return rollResult;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -439,7 +506,9 @@ public class Player implements FieldVisitor<Void>{
|
||||
@Override
|
||||
public DiceResult rollDice() {
|
||||
List<Integer> roll = List.of(Dice.rollDice(), Dice.rollDice());
|
||||
rollResult = new DiceResult(roll);
|
||||
rollResult = new DiceResult(roll.get(0), roll.get(1));
|
||||
System.out.println(rollResult.calcTotal());
|
||||
move(rollResult.calcTotal());
|
||||
return rollResult;
|
||||
}
|
||||
|
||||
@@ -455,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
|
||||
* Set when in Gulag
|
||||
@@ -491,7 +535,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
@Override
|
||||
public DiceResult rollDice() {
|
||||
List<Integer> roll = List.of(Dice.rollDice(), Dice.rollDice());
|
||||
rollResult = new DiceResult(roll);
|
||||
rollResult = new DiceResult(roll.get(0), roll.get(1));
|
||||
if (rollResult.isDoublets()) {
|
||||
state = new ActiveState();
|
||||
} else if (DoubletsCounter == 0) {
|
||||
@@ -519,7 +563,7 @@ public class Player implements FieldVisitor<Void>{
|
||||
|
||||
@Override
|
||||
public DiceResult rollDice() {
|
||||
throw new UnsupportedOperationException("not allowed");
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -531,4 +575,8 @@ public class Player implements FieldVisitor<Void>{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Player{name=" + name + ", figure=" + figure + "}";
|
||||
}
|
||||
}
|
||||
|
@@ -6,12 +6,12 @@ import com.jme3.math.ColorRGBA;
|
||||
* Enum representing six distinct colors for players in the game.
|
||||
*/
|
||||
public enum PlayerColor {
|
||||
GREEN_LIGHT(new ColorRGBA(0 / 255f, 204 / 255f, 0 / 255f, 1)), // Hex: 00cc00
|
||||
RED(new ColorRGBA(255 / 255f, 0 / 255f, 0 / 255f, 1)), // Hex: ff0000
|
||||
BLUE(new ColorRGBA(0 / 255f, 0 / 255f, 204 / 255f, 1)), // Hex: 0000cc
|
||||
PINK(new ColorRGBA(255 / 255f, 77 / 255f, 166 / 255f, 1)), // Hex: ff4da6
|
||||
GREEN_DARK(new ColorRGBA(0 / 255f, 102 / 255f, 0 / 255f, 1)), // Hex: 006600
|
||||
YELLOW(new ColorRGBA(255 / 255f, 255 / 255f, 0 / 255f, 1)); // Hex: ffff00
|
||||
CYAN(new ColorRGBA(1 / 255f, 190 / 255f, 254 / 255f, 1)),
|
||||
YELLOW(new ColorRGBA(255 / 255f, 255 / 255f, 0 / 255f, 1)),
|
||||
RED(new ColorRGBA(255 / 255f, 0 / 255f, 0 / 255f, 1)),
|
||||
PINK(new ColorRGBA(255 / 255f, 77 / 255f, 166 / 255f, 1)),
|
||||
GREEN(new ColorRGBA(0 / 255f, 204 / 255f, 0 / 255f, 1)),
|
||||
PURPLE(new ColorRGBA(143 / 255f, 0 / 255f, 255 / 255f, 1));
|
||||
|
||||
private final ColorRGBA color;
|
||||
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package pp.monopoly.game.server;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
@@ -16,10 +16,9 @@ import pp.monopoly.model.LimitedLinkedList;
|
||||
*/
|
||||
@Serializable
|
||||
public class PlayerHandler {
|
||||
private List<Player> players = new LimitedLinkedList<>(6);
|
||||
private List<Player> players = new LinkedList<>();
|
||||
private Set<Player> readyPlayers = new HashSet<>();
|
||||
private ServerGameLogic logic;
|
||||
private Player hostPlayer;
|
||||
private transient ServerGameLogic logic;
|
||||
private Player extra = null;
|
||||
|
||||
/**
|
||||
@@ -55,14 +54,6 @@ public class PlayerHandler {
|
||||
players.addAll(players);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the host player
|
||||
* @return the host player
|
||||
*/
|
||||
public Player getHostPlayer() {
|
||||
return hostPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of players
|
||||
* @return number of players in the game
|
||||
@@ -114,9 +105,6 @@ public class PlayerHandler {
|
||||
throw new IllegalArgumentException("Player already registered");
|
||||
}
|
||||
players.add(player);
|
||||
if(hostPlayer == null) {
|
||||
hostPlayer = player;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -4,7 +4,7 @@ import java.lang.System.Logger;
|
||||
import java.lang.System.Logger.Level;
|
||||
|
||||
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.EndTurn;
|
||||
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.TradeRequest;
|
||||
import pp.monopoly.message.server.ViewAssetsResponse;
|
||||
import pp.monopoly.model.Board;
|
||||
import pp.monopoly.model.Figure;
|
||||
import pp.monopoly.model.Rotation;
|
||||
import pp.monopoly.model.card.DeckHelper;
|
||||
@@ -132,7 +131,6 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
|
||||
playerHandler.addPlayer(player);
|
||||
LOGGER.log(Level.DEBUG, "Player added: {0}", player.getId());
|
||||
System.out.println("Anzahl Spieler verbunden:"+ playerHandler.getPlayerCount());
|
||||
|
||||
return player;
|
||||
}
|
||||
@@ -145,19 +143,14 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
* @param from the connection ID of the player who sent the request
|
||||
*/
|
||||
@Override
|
||||
public void received(BuyPropertyRequest msg, int from) {
|
||||
public void received(BuyPropertyResponse msg, int from) {
|
||||
Player player = playerHandler.getPlayerById(from);
|
||||
if (player != null && state == ServerState.INGAME) {
|
||||
PropertyField property = (PropertyField) boardManager.getFieldAtIndex(player.move(0)); // Assuming player position for property
|
||||
if (player != null) {
|
||||
PropertyField property = (PropertyField) boardManager.getFieldAtIndex(player.getFieldID()); // Assuming player position for property
|
||||
|
||||
if (property.getOwner() == null && player.getAccountBalance() >= property.getPrice()) {
|
||||
player.buyProperty(property);
|
||||
property.setOwner(player);
|
||||
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());
|
||||
}
|
||||
player.buyProperty(property);
|
||||
System.out.println("Properties:" +player.getProperties().toString());
|
||||
LOGGER.log(Level.INFO, "Player {0} bought property {1}", player.getName(), property.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,12 +163,14 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
@Override
|
||||
public void received(EndTurn msg, int from) {
|
||||
Player player = playerHandler.getPlayerById(from);
|
||||
if (player != null && state == ServerState.INGAME) {
|
||||
if (player != null && player == playerHandler.getPlayerAtIndex(0)) {
|
||||
if (player.finishTurn()) {
|
||||
LOGGER.log(Level.DEBUG, "Ending turn for player {0}", player.getName());
|
||||
Player next = playerHandler.nextPlayer();
|
||||
next.setActive();
|
||||
send(next, new NextPlayerTurn(next));
|
||||
send(next, new NextPlayerTurn());
|
||||
send(next, new PlayerStatusUpdate(playerHandler));
|
||||
send(player, new PlayerStatusUpdate(playerHandler));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -189,7 +184,7 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
@Override
|
||||
public void received(PlayerReady msg, int from) {
|
||||
Player player = playerHandler.getPlayerById(from);
|
||||
if(player == playerHandler.getHostPlayer()) {
|
||||
if(player.getId() == 0) {
|
||||
startMoney = msg.getStartMoney();
|
||||
}
|
||||
|
||||
@@ -204,10 +199,10 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
if(playerHandler.allPlayersReady()) {
|
||||
playerHandler.setStartBalance(startMoney);
|
||||
for (Player p : playerHandler.getPlayers()) {
|
||||
send(p, new GameStart(playerHandler.getPlayers()));
|
||||
send(p, new GameStart(playerHandler));
|
||||
}
|
||||
playerHandler.randomOrder();
|
||||
send(playerHandler.getPlayerAtIndex(0), new NextPlayerTurn(playerHandler.getPlayerAtIndex(0)));
|
||||
send(playerHandler.getPlayerAtIndex(0), new NextPlayerTurn());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +215,7 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
@Override
|
||||
public void received(RollDice msg, int from) {
|
||||
Player player = playerHandler.getPlayerById(from);
|
||||
if (player != null && state == ServerState.INGAME) {
|
||||
if (player != null) {
|
||||
send(player, player.rollDice());
|
||||
}
|
||||
}
|
||||
@@ -268,11 +263,12 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
@Override
|
||||
public void received(ViewAssetsRequest msg, int from) {
|
||||
Player sender = playerHandler.getPlayerById(from);
|
||||
Player player = msg.getPlayer();
|
||||
if (sender != null && player != null) {
|
||||
LOGGER.log(Level.DEBUG, "Processing ViewAssetsRequest for player {0}", sender.getName());
|
||||
|
||||
send(sender, new ViewAssetsResponse(boardManager, player.getProperties(), player.getAccountBalance(), player.getNumJailCard()));
|
||||
if (sender != null) {
|
||||
LOGGER.log(Level.DEBUG, "Processing ViewAssetsRequest for player {0}", sender.getName());
|
||||
send(sender, new ViewAssetsResponse(boardManager));
|
||||
for (Player player : playerHandler.getPlayers()) {
|
||||
send(player, new PlayerStatusUpdate(playerHandler));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,39 +0,0 @@
|
||||
package pp.monopoly.message.client;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* Represents a request from a player to buy a property.
|
||||
*/
|
||||
@Serializable
|
||||
public class BuyPropertyRequest extends ClientMessage{
|
||||
private int propertyId;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private BuyPropertyRequest() { /* empty */ }
|
||||
|
||||
/**
|
||||
* Constructs a BuyPropertyRequest with the specified property ID.
|
||||
*
|
||||
* @param propertyId the ID of the property to buy
|
||||
*/
|
||||
public BuyPropertyRequest(int propertyId) {
|
||||
this.propertyId = propertyId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ID of the property to buy.
|
||||
*
|
||||
* @return the property ID
|
||||
*/
|
||||
public int getPropertyId() {
|
||||
return propertyId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ClientInterpreter interpreter, int from) {
|
||||
interpreter.received(this, from);
|
||||
}
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
package pp.monopoly.message.client;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* Represents a request from a player to buy a property.
|
||||
*/
|
||||
@Serializable
|
||||
public class BuyPropertyResponse extends ClientMessage{
|
||||
|
||||
/**
|
||||
* Constructs a BuyPropertyRequest with the specified property ID.
|
||||
*
|
||||
* @param propertyId the ID of the property to buy
|
||||
*/
|
||||
public BuyPropertyResponse() {}
|
||||
|
||||
|
||||
@Override
|
||||
public void accept(ClientInterpreter interpreter, int from) {
|
||||
interpreter.received(this, from);
|
||||
}
|
||||
}
|
@@ -17,7 +17,7 @@ public interface ClientInterpreter {
|
||||
* @param msg the BuyPropertyRequest to be processed
|
||||
* @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.
|
||||
|
@@ -11,7 +11,7 @@ public class RollDice extends ClientMessage{
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private RollDice() { /* empty */ }
|
||||
public RollDice() { /* empty */ }
|
||||
|
||||
@Override
|
||||
public void accept(ClientInterpreter interpreter, int from) {
|
||||
|
@@ -2,23 +2,13 @@ package pp.monopoly.message.client;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.game.server.Player;
|
||||
|
||||
/**
|
||||
* Represents a request from a player to view their assets.
|
||||
*/
|
||||
@Serializable
|
||||
public class ViewAssetsRequest extends ClientMessage{
|
||||
|
||||
private Player player;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private ViewAssetsRequest() { /* empty */ }
|
||||
|
||||
public ViewAssetsRequest(Player player) {
|
||||
this.player = player;
|
||||
public ViewAssetsRequest() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -26,8 +16,4 @@ public class ViewAssetsRequest extends ClientMessage{
|
||||
interpreter.received(this, from);
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
}
|
@@ -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'");
|
||||
}
|
||||
|
||||
}
|
@@ -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'");
|
||||
}
|
||||
}
|
@@ -7,19 +7,24 @@ import com.jme3.network.serializing.Serializable;
|
||||
@Serializable
|
||||
public class DiceResult extends ServerMessage{
|
||||
|
||||
private List<Integer> rollResult;
|
||||
private final int a;
|
||||
private final int b;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private DiceResult() { /* empty */ }
|
||||
private DiceResult() {
|
||||
a = 1;
|
||||
b = 1;
|
||||
}
|
||||
|
||||
public DiceResult(List<Integer> rollResult) {
|
||||
this.rollResult = rollResult;
|
||||
public DiceResult(int a, int b) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public List<Integer> getRollResult() {
|
||||
return rollResult;
|
||||
return List.of(a,b);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -34,10 +39,10 @@ public class DiceResult extends ServerMessage{
|
||||
}
|
||||
|
||||
public boolean isDoublets() {
|
||||
return rollResult.get(0) == rollResult.get(1);
|
||||
return a == b;
|
||||
}
|
||||
|
||||
public int calcTotal() {
|
||||
return rollResult.get(0)+rollResult.get(1);
|
||||
return a+b;
|
||||
}
|
||||
}
|
||||
|
@@ -1,27 +1,25 @@
|
||||
package pp.monopoly.message.server;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.game.server.Player;
|
||||
import pp.monopoly.game.server.PlayerHandler;
|
||||
|
||||
@Serializable
|
||||
public class GameStart extends ServerMessage{
|
||||
|
||||
private List<Player> players;
|
||||
private PlayerHandler playerHandler;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private GameStart() { /* empty */ }
|
||||
|
||||
public GameStart(List<Player> players) {
|
||||
this.players = players;
|
||||
public GameStart(PlayerHandler playerHandler) {
|
||||
this.playerHandler = playerHandler;
|
||||
}
|
||||
|
||||
public List<Player> getPlayers() {
|
||||
return players;
|
||||
public PlayerHandler getPlayerHandler() {
|
||||
return playerHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -2,20 +2,13 @@ package pp.monopoly.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.game.server.Player;
|
||||
|
||||
@Serializable
|
||||
public class NextPlayerTurn extends ServerMessage{
|
||||
|
||||
private Player player;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private NextPlayerTurn() { /* empty */ }
|
||||
|
||||
public NextPlayerTurn(Player player) {
|
||||
this.player = player;
|
||||
public NextPlayerTurn() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -28,9 +21,4 @@ public class NextPlayerTurn extends ServerMessage{
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -2,36 +2,24 @@ package pp.monopoly.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.game.server.PlayerColor;
|
||||
import pp.monopoly.game.server.PlayerHandler;
|
||||
|
||||
@Serializable
|
||||
public class PlayerStatusUpdate extends ServerMessage{
|
||||
|
||||
private String playerName;
|
||||
private String status;
|
||||
private PlayerColor color;
|
||||
private PlayerHandler playerHandler;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private PlayerStatusUpdate() { /* empty */ }
|
||||
|
||||
public PlayerStatusUpdate(String playerName, String status, PlayerColor color) {
|
||||
this.playerName = playerName;
|
||||
this.status = status;
|
||||
this.color = color;
|
||||
public PlayerStatusUpdate(PlayerHandler playerHandler) {
|
||||
this.playerHandler = playerHandler;
|
||||
}
|
||||
|
||||
public String getPlayerName() {
|
||||
return playerName;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public PlayerColor getColor() {
|
||||
return color;
|
||||
public PlayerHandler getPlayerHandler() {
|
||||
return playerHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -13,13 +13,6 @@ package pp.monopoly.message.server;
|
||||
*/
|
||||
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.
|
||||
*
|
||||
@@ -96,4 +89,11 @@ public interface ServerInterpreter {
|
||||
* @param msg the NextPlayerTurn message received
|
||||
*/
|
||||
void received(NextPlayerTurn msg);
|
||||
|
||||
/**
|
||||
* Handles a NextPlayerTurn message received from the server.
|
||||
*
|
||||
* @param msg the NextPlayerTurn message received
|
||||
*/
|
||||
void received(BuyPropertyRequest msg);
|
||||
}
|
||||
|
@@ -1,11 +1,9 @@
|
||||
package pp.monopoly.message.server;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.model.fields.BoardManager;
|
||||
import pp.monopoly.model.fields.PropertyField;
|
||||
|
||||
/**
|
||||
* Represents a response containing the player's assets.
|
||||
@@ -13,10 +11,7 @@ import pp.monopoly.model.fields.PropertyField;
|
||||
@Serializable
|
||||
public class ViewAssetsResponse extends ServerMessage{
|
||||
|
||||
private List<PropertyField> properties;
|
||||
private BoardManager board;
|
||||
private int accountBalance;
|
||||
private int jailCards;
|
||||
|
||||
/**
|
||||
* 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 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.properties = properties;
|
||||
this.accountBalance = accountBalance;
|
||||
this.jailCards = jailCards;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,18 +39,6 @@ public class ViewAssetsResponse extends ServerMessage{
|
||||
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() {
|
||||
return board;
|
||||
}
|
||||
|
@@ -1,14 +1,13 @@
|
||||
package pp.monopoly.model;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
import static java.lang.Math.min;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
import static java.lang.Math.min;
|
||||
|
||||
@Serializable
|
||||
public class Figure implements Item{
|
||||
private final String type;
|
||||
@@ -313,5 +312,9 @@ public class Figure implements Item{
|
||||
public void accept(VoidVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -12,13 +12,13 @@ import java.util.List;
|
||||
public class TradeHandler {
|
||||
|
||||
private final Player sender;
|
||||
private final Player receiver;
|
||||
private final int offeredAmount;
|
||||
private final List<PropertyField> offeredProperties;
|
||||
private final int offeredJailCards;
|
||||
private final int requestedAmount;
|
||||
private final List<PropertyField> requestedProperties;
|
||||
private final int requestedJailCards;
|
||||
private Player receiver;
|
||||
private int offeredAmount;
|
||||
private List<PropertyField> offeredProperties;
|
||||
private int offeredJailCards;
|
||||
private int requestedAmount;
|
||||
private List<PropertyField> requestedProperties;
|
||||
private int requestedJailCards;
|
||||
private Boolean status = null;
|
||||
|
||||
/**
|
||||
@@ -45,6 +45,22 @@ public class TradeHandler {
|
||||
this.requestedJailCards = requestedJailCards;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a TradeHandler for a single trade instance.
|
||||
*
|
||||
* @param sender the Player initiating the trade
|
||||
* @param receiver the Player receiving the trade offer
|
||||
* @param offeredAmount the amount of money offered by the sender
|
||||
* @param offeredProperties the properties offered by the sender
|
||||
* @param offeredJailCards the jail cards offered by the sender
|
||||
* @param requestedAmount the amount of money requested from the receiver
|
||||
* @param requestedProperties the properties requested from the receiver
|
||||
* @param requestedJailCards the jail cards requested from the receiver
|
||||
*/
|
||||
public TradeHandler(Player sender) {
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
public int getOfferedAmount() {
|
||||
return offeredAmount;
|
||||
}
|
||||
@@ -88,10 +104,10 @@ public class TradeHandler {
|
||||
*/
|
||||
public boolean initiateTrade() {
|
||||
if (!validateTrade()) {
|
||||
System.out.println("Trade offer is invalid.");
|
||||
|
||||
return false;
|
||||
}
|
||||
System.out.println("Trade initiated by " + sender.getName() + " to " + receiver.getName());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -122,14 +138,14 @@ public class TradeHandler {
|
||||
transferJailCards(sender, receiver, offeredJailCards);
|
||||
transferJailCards(receiver, sender, requestedJailCards);
|
||||
|
||||
System.out.println("Trade completed between " + sender.getName() + " and " + receiver.getName());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Rejects the trade.
|
||||
*/
|
||||
public void rejectTrade() {
|
||||
System.out.println(receiver.getName() + " rejected the trade.");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,13 +156,13 @@ public class TradeHandler {
|
||||
private boolean validateTrade() {
|
||||
// Validate sender's ability to offer money
|
||||
if (sender.getAccountBalance() < offeredAmount) {
|
||||
System.out.println("Sender does not have enough money to offer.");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate receiver's ability to fulfill the requested amount
|
||||
if (receiver.getAccountBalance() < requestedAmount) {
|
||||
System.out.println("Receiver does not have enough money to fulfill the request.");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -154,7 +170,7 @@ public class TradeHandler {
|
||||
if (offeredProperties != null) {
|
||||
for (PropertyField property : offeredProperties) {
|
||||
if (!sender.getProperties().contains(property)) {
|
||||
System.out.println("Sender does not own property: " + property.getName());
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -162,7 +178,7 @@ public class TradeHandler {
|
||||
if (requestedProperties != null) {
|
||||
for (PropertyField property : requestedProperties) {
|
||||
if (!receiver.getProperties().contains(property)) {
|
||||
System.out.println("Receiver does not own property: " + property.getName());
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -170,11 +186,11 @@ public class TradeHandler {
|
||||
|
||||
// Validate jail cards
|
||||
if (sender.getNumJailCard() < offeredJailCards) {
|
||||
System.out.println("Sender does not have enough jail cards to offer.");
|
||||
|
||||
return false;
|
||||
}
|
||||
if (receiver.getNumJailCard() < requestedJailCards) {
|
||||
System.out.println("Receiver does not have enough jail cards to fulfill the request.");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -192,7 +208,7 @@ public class TradeHandler {
|
||||
from.sellProperty(property);
|
||||
to.buyProperty(property);
|
||||
property.setOwner(to);
|
||||
System.out.println("Property " + property.getName() + " transferred from " + from.getName() + " to " + to.getName());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,6 +223,34 @@ public class TradeHandler {
|
||||
from.removeJailCard();
|
||||
to.addJailCard();
|
||||
}
|
||||
System.out.println(numCards + " jail card(s) transferred from " + from.getName() + " to " + to.getName());
|
||||
|
||||
}
|
||||
|
||||
public void setOfferedAmount(int offeredAmount) {
|
||||
this.offeredAmount = offeredAmount;
|
||||
}
|
||||
|
||||
public void setOfferedJailCards(int offeredJailCards) {
|
||||
this.offeredJailCards = offeredJailCards;
|
||||
}
|
||||
|
||||
public void setOfferedProperties(List<PropertyField> offeredProperties) {
|
||||
this.offeredProperties = offeredProperties;
|
||||
}
|
||||
|
||||
public void setReceiver(Player receiver) {
|
||||
this.receiver = receiver;
|
||||
}
|
||||
|
||||
public void setRequestedAmount(int requestedAmount) {
|
||||
this.requestedAmount = requestedAmount;
|
||||
}
|
||||
|
||||
public void setRequestedJailCards(int requestedJailCards) {
|
||||
this.requestedJailCards = requestedJailCards;
|
||||
}
|
||||
|
||||
public void setRequestedProperties(List<PropertyField> requestedProperties) {
|
||||
this.requestedProperties = requestedProperties;
|
||||
}
|
||||
}
|
||||
|
@@ -16,38 +16,40 @@ public class DeckHelper{
|
||||
|
||||
public DeckHelper() {
|
||||
cards = new LinkedList<Card>();
|
||||
cards.add(new Card("Du wurdest mit einem Dienst KFZ geblitzt. Zahle: 800€", "dienst-kfz-blitzer"));
|
||||
cards.add(new Card("Du wurdest mit einem Dienst KFZ geblitzt. Zahle: 800 EUR", "dienst-kfz-blitzer"));
|
||||
cards.add(new Card("Die erste Spoparty steht bevor. Ziehe vor zum 23er.", "spoparty"));
|
||||
cards.add(new Card("Du kommst aus dem Gulak frei.", "gulak-frei-1"));
|
||||
cards.add(new Card("Du kommst aus dem Gulak frei.", "gulak-frei-2"));
|
||||
cards.add(new Card("Du hast den Dienstführerschein bestanden. Ziehe vor bis Teststrecke.", "dienstfuehrerschein"));
|
||||
cards.add(new Card("Malkmus läd zum Pubquiz ein. Rücke vor bis zum 20er.", "pubquiz"));
|
||||
cards.add(new Card("Du warst ohne Namensschild in der Truppenküche. Rücke vor zum 10er. Gehe nicht über Monatsgehalt. Ziehe keine 2000x€ ein.", "namensschild-truppenkueche"));
|
||||
cards.add(new Card("Du hast heute die Spendierhosen an und gibst eine Runde in der Unibar. Zahle jedem Spieler: 400€", "spendierhosen-unibar"));
|
||||
cards.add(new Card("Du warst ohne Namensschild in der Truppenküche. Rücke vor zum 10er. Gehe nicht über Monatsgehalt. Ziehe keine 2000x EUR ein.", "namensschild-truppenkueche"));
|
||||
cards.add(new Card("Du hast heute die Spendierhosen an und gibst eine Runde in der Unibar. Zahle jedem Spieler: 400 EUR", "spendierhosen-unibar"));
|
||||
cards.add(new Card("Du warst in der Prüfungsphase krank. Gehe 3 Felder zurück.", "pruefungsphase-krank"));
|
||||
cards.add(new Card("Ziehe vor bis zum nächsten Monatsgehalt.", "naechstes-monatsgehalt"));
|
||||
cards.add(new Card("Du hast ein Antreten verschlafen. Zahle: 500€", "antreten-verschlafen-1"));
|
||||
cards.add(new Card("Du hast den Maibock organisiert. Du erhältst: 3000€", "maibock-organisiert"));
|
||||
cards.add(new Card("Der Spieß macht eine unangekündigte Inventur. Zahle für jedes Haus: 400€ und jedes Hotel: 2800€", "inventur-haeuser-hotels"));
|
||||
cards.add(new Card("Du hast ein Antreten verschlafen. Zahle: 500 EUR", "antreten-verschlafen-1"));
|
||||
cards.add(new Card("Du hast den Maibock organisiert. Du erhältst: 3000 EUR", "maibock-organisiert"));
|
||||
cards.add(new Card("Der Spieß macht eine unangekündigte Inventur. Zahle für jedes Haus: 400 EUR und jedes Hotel: 2800 EUR", "inventur-haeuser-hotels"));
|
||||
cards.add(new Card("Es gab keine Mozzarella Bällchen mehr für Thoma. Alle Spieler ziehen vor auf Gym.", "dienstsport-gym"));
|
||||
cards.add(new Card("Auf deiner Stube wurde Schimmel gefunden. Gehe ins Gulak. Begib Dich direkt dorthin. Gehe nicht über Monatsgehalt. Ziehe nicht ein.", "schimmel-gulak"));
|
||||
cards.add(new Card("Deine Stube ist nach einer Partynacht nicht mehr bewohnbar. Du ziehst ins Gulak. Begib Dich direkt dorthin. Gehe nicht über Monatsgehalt. Ziehe nicht ein.", "partynacht-gulak"));
|
||||
cards.add(new Card("Das Jahresabschlussantreten steht an. Ziehe vor bis Schwimmhalle.", "jahresabschlussantreten"));
|
||||
cards.add(new Card("Du wurdest beim Verkaufen von Versicherungen erwischt. Zahle: 4000€", "verkaufen-versicherungen"));
|
||||
cards.add(new Card("Du wurdest beim Verkaufen von Versicherungen erwischt. Zahle: 4000 EUR", "verkaufen-versicherungen"));
|
||||
cards.add(new Card("Du musstest einen Rückstuferantrag stellen. Setze eine Runde aus.", "rueckstuferantrag"));
|
||||
cards.add(new Card("Auf einer Hausfeier bist du betrunken auf der Treppe gestürzt und dabei auf einen Kameraden gefallen. Zahle: 800€ und gehe zurück zu SanZ.", "hausfeier-sturz"));
|
||||
cards.add(new Card("Beförderung. Beim nächsten Monatsgehalt ziehst du ein: 3000€", "befoerderung"));
|
||||
cards.add(new Card("Du entscheidest dich für eine Dienstreise nach Lourd. Zahle: 1000€ und setze eine Runde aus.", "dienstreise-lourd"));
|
||||
cards.add(new Card("Auf einer Hausfeier bist du betrunken auf der Treppe gestürzt und dabei auf einen Kameraden gefallen. Zahle: 800 EUR und gehe zurück zu SanZ.", "hausfeier-sturz"));
|
||||
cards.add(new Card("Beförderung. Beim nächsten Monatsgehalt ziehst du ein: 3000 EUR", "befoerderung"));
|
||||
cards.add(new Card("Du entscheidest dich für eine Dienstreise nach Lourd. Zahle: 1000 EUR und setze eine Runde aus.", "dienstreise-lourd"));
|
||||
cards.add(new Card("Du warst fleißig Blutspenden und erhältst einen Tag Sonderurlaub. Du bist nochmal an der Reihe.", "blutspenden-sonderurlaub"));
|
||||
cards.add(new Card("Dir wurde auf dem Oktoberfest dein Geldbeutel geklaut. Gebe 10% deines Vermögens ab.", "geldbeutel-oktoberfest"));
|
||||
cards.add(new Card("Du wirst von deinem Chef für vorbildliches Verhalten gelobt. Du erhältst: 4000€", "lob-chef"));
|
||||
cards.add(new Card("Deine Bekanntschaft von letzter Nacht war eine Spo. Lasse dich testen und zahle: 200€", "spo-testen"));
|
||||
cards.add(new Card("Du wirst von deinem Chef für vorbildliches Verhalten gelobt. Du erhältst: 4000 EUR", "lob-chef"));
|
||||
cards.add(new Card("Deine Bekanntschaft von letzter Nacht war eine Spo. Lasse dich testen und zahle: 200 EUR", "spo-testen"));
|
||||
cards.add(new Card("Du wurdest von Kranz geexmattet. Gehe zurück zu Prüfungsamt.", "kranz-exmatrikulation"));
|
||||
cards.add(new Card("Die letzte Party ist ein wenig eskaliert. Setze eine Runde aus.", "party-eskaliert"));
|
||||
cards.add(new Card("Du wurdest zur VP gewählt und schmeißt eine Einstandsparty. Zahle: 800€", "vp-einstandsparty"));
|
||||
cards.add(new Card("Du hast eine Party veranstaltet und dick Gewinn gemacht. Ziehe ein: 1500€", "party-gewinn"));
|
||||
cards.add(new Card("Du wurdest zur VP gewählt und schmeißt eine Einstandsparty. Zahle: 800 EUR", "vp-einstandsparty"));
|
||||
cards.add(new Card("Du hast eine Party veranstaltet und dick Gewinn gemacht. Ziehe ein: 1500 EUR", "party-gewinn"));
|
||||
cards.add(new Card("Zur falschen Zeit am falschen Ort. Du musst einen Bergmarsch planen und setzt eine Runde aus.", "bergmarsch"));
|
||||
cards.add(new Card("Dein Jodel eines Eispenis mit Unterhodenbeleuchtung geht viral. Ziehe ein: 1000€", "jodel-eispenis"));
|
||||
cards.add(new Card("Dein Jodel eines Eispenis mit Unterhodenbeleuchtung geht viral. Ziehe ein: 1000 EUR", "jodel-eispenis"));
|
||||
|
||||
shuffle();
|
||||
}
|
||||
|
||||
public void visit(Card card, Player player) {
|
||||
@@ -203,7 +205,7 @@ public class DeckHelper{
|
||||
}
|
||||
|
||||
private void namensschildTruppenkueche(Player player) {
|
||||
//TODO
|
||||
//TODO 10 existiert nicht mehr
|
||||
}
|
||||
|
||||
private void spendierhosenUnibar(Player player) {
|
||||
|
@@ -4,9 +4,12 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* Simple Manager class responsible for managing the GameBoard of Monopoly
|
||||
*/
|
||||
@Serializable
|
||||
public class BoardManager {
|
||||
|
||||
private List<Field> board;
|
||||
@@ -92,4 +95,12 @@ public class BoardManager {
|
||||
public List<Field> getBoard() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -3,8 +3,11 @@ package pp.monopoly.model.fields;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.game.server.Player;
|
||||
|
||||
@Serializable
|
||||
public class BuildingProperty extends PropertyField {
|
||||
|
||||
private int houses;
|
||||
@@ -17,6 +20,12 @@ public class BuildingProperty extends PropertyField {
|
||||
private final int rentFactor4 = 55;
|
||||
private final int rentFactorHotel = 70;
|
||||
|
||||
private BuildingProperty(){
|
||||
super("", 0, 0, 0);
|
||||
this.housePrice = 0;
|
||||
this.color = null;
|
||||
}
|
||||
|
||||
BuildingProperty(String name, int id, int price, int rent, int housePrice, FieldColor color) {
|
||||
super(name, id, price, rent);
|
||||
this.housePrice = housePrice;
|
||||
|
@@ -1,11 +1,18 @@
|
||||
package pp.monopoly.model.fields;
|
||||
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.game.server.Player;
|
||||
|
||||
@Serializable
|
||||
public class EventField extends Field{
|
||||
|
||||
public EventField(String name, int id) {
|
||||
private EventField() {
|
||||
super("", 0);
|
||||
}
|
||||
|
||||
EventField(String name, int id) {
|
||||
super(name, id);
|
||||
}
|
||||
|
||||
|
@@ -1,11 +1,19 @@
|
||||
package pp.monopoly.model.fields;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.game.server.Player;
|
||||
|
||||
abstract class Field {
|
||||
@Serializable
|
||||
public abstract class Field {
|
||||
protected final String name;
|
||||
protected final int id;
|
||||
|
||||
private Field() {
|
||||
this.name = "";
|
||||
this.id = 0;
|
||||
}
|
||||
|
||||
protected Field(String name, int id) {
|
||||
this.name = name;
|
||||
this.id= id;
|
||||
|
@@ -1,10 +1,12 @@
|
||||
package pp.monopoly.model.fields;
|
||||
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* Enum representing eight distinct colors for properties in the game.
|
||||
*/
|
||||
// @Serializable
|
||||
public enum FieldColor {
|
||||
BROWN(new ColorRGBA(148 / 255f, 86 / 255f, 57 / 255f, 1)),
|
||||
GREEN(new ColorRGBA(30 / 255f, 179 / 255f, 90 / 255f, 1)),
|
||||
@@ -17,6 +19,10 @@ public enum FieldColor {
|
||||
|
||||
private final ColorRGBA color;
|
||||
|
||||
private FieldColor() {
|
||||
this.color = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a FieldColor with the specified ColorRGBA value.
|
||||
*
|
||||
|
@@ -1,11 +1,19 @@
|
||||
package pp.monopoly.model.fields;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.game.server.Player;
|
||||
|
||||
@Serializable
|
||||
public class FineField extends Field{
|
||||
|
||||
private final int fine;
|
||||
|
||||
private FineField() {
|
||||
super("", 0);
|
||||
this.fine = 0;
|
||||
}
|
||||
|
||||
FineField(String name, int id, int fine) {
|
||||
super(name, id);
|
||||
this.fine = fine;
|
||||
|
@@ -1,10 +1,17 @@
|
||||
package pp.monopoly.model.fields;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.game.server.Player;
|
||||
|
||||
@Serializable
|
||||
public class FoodField extends PropertyField {
|
||||
|
||||
public FoodField(String name, int id) {
|
||||
private FoodField() {
|
||||
super("", 0, 0, 0);
|
||||
}
|
||||
|
||||
FoodField(String name, int id) {
|
||||
super(name, id, 1500,0);
|
||||
}
|
||||
|
||||
|
@@ -1,9 +1,15 @@
|
||||
package pp.monopoly.model.fields;
|
||||
|
||||
import pp.monopoly.game.server.Player;
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.game.server.Player;
|
||||
@Serializable
|
||||
public class GateField extends PropertyField{
|
||||
|
||||
private GateField() {
|
||||
super("", 0, 0, 0);
|
||||
}
|
||||
|
||||
GateField(String name, int id) {
|
||||
super(name, id, 2000, 25);
|
||||
}
|
||||
|
@@ -1,10 +1,12 @@
|
||||
package pp.monopoly.model.fields;
|
||||
|
||||
import pp.monopoly.game.server.Player;
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.game.server.Player;
|
||||
@Serializable
|
||||
public class GoField extends Field{
|
||||
|
||||
public GoField() {
|
||||
GoField() {
|
||||
super("Monatsgehalt", 0);
|
||||
}
|
||||
|
||||
|
@@ -1,7 +1,9 @@
|
||||
package pp.monopoly.model.fields;
|
||||
|
||||
import pp.monopoly.game.server.Player;
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.game.server.Player;
|
||||
@Serializable
|
||||
public class GulagField extends Field{
|
||||
|
||||
private int bailCost = 500;
|
||||
|
@@ -1,11 +1,14 @@
|
||||
package pp.monopoly.model.fields;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.game.server.Player;
|
||||
|
||||
/**
|
||||
* Represents an abstract property field in the Monopoly game.
|
||||
* Contains attributes related to ownership, price, rent, and mortgage status.
|
||||
*/
|
||||
@Serializable
|
||||
public abstract class PropertyField extends Field {
|
||||
|
||||
private final int price;
|
||||
@@ -13,6 +16,12 @@ public abstract class PropertyField extends Field {
|
||||
private Player owner;
|
||||
private boolean mortgaged = false;
|
||||
|
||||
private PropertyField() {
|
||||
super("", 0);
|
||||
this.price = 0;
|
||||
this.rent = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a PropertyField with the specified name, ID, price, and rent.
|
||||
*
|
||||
|
@@ -1,7 +1,10 @@
|
||||
package pp.monopoly.model.fields;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.game.server.Player;
|
||||
|
||||
@Serializable
|
||||
public class TestStreckeField extends Field{
|
||||
private int money;
|
||||
|
||||
|
@@ -1,10 +1,13 @@
|
||||
package pp.monopoly.model.fields;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.game.server.Player;
|
||||
|
||||
@Serializable
|
||||
public class WacheField extends Field{
|
||||
|
||||
public WacheField() {
|
||||
WacheField() {
|
||||
super("Wache", 30);
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
package pp.monopoly.notification;
|
||||
|
||||
public record DiceRollEvent(int a, int b) implements GameEvent{
|
||||
|
||||
@Override
|
||||
public void notifyListener(GameEventListener listener) {
|
||||
listener.receivedEvent(this);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
package pp.monopoly.notification;
|
||||
|
||||
public record EventCardEvent(String description) implements GameEvent{
|
||||
|
||||
@Override
|
||||
public void notifyListener(GameEventListener listener) {
|
||||
listener.receivedEvent(this);
|
||||
}
|
||||
|
||||
}
|
@@ -45,4 +45,39 @@ public interface GameEventListener {
|
||||
* @param event the received event
|
||||
*/
|
||||
default void receivedEvent(ClientStateEvent event) { /* do nothing */ }
|
||||
|
||||
/**
|
||||
* Indicates that the dice result has changed.
|
||||
*
|
||||
* @param event the received event
|
||||
*/
|
||||
default void receivedEvent(DiceRollEvent event) { /*Do nothing */}
|
||||
|
||||
/**
|
||||
* Indicates that the players assets have changed.
|
||||
*
|
||||
* @param event the received event
|
||||
*/
|
||||
default void receivedEvent(UpdatePlayerView event) { /*Do nothing */}
|
||||
|
||||
/**
|
||||
* Indicates that an event card has been drawn
|
||||
*
|
||||
* @param event the received event
|
||||
*/
|
||||
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 */}
|
||||
}
|
||||
|
@@ -0,0 +1,10 @@
|
||||
package pp.monopoly.notification;
|
||||
|
||||
public record PopUpEvent() implements GameEvent{
|
||||
|
||||
@Override
|
||||
public void notifyListener(GameEventListener listener) {
|
||||
listener.receivedEvent(this);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
package pp.monopoly.notification;
|
||||
|
||||
public record UpdatePlayerView() implements GameEvent{
|
||||
/**
|
||||
* Notifies the game event listener of this event.
|
||||
*
|
||||
* @param listener the game event listener
|
||||
*/
|
||||
@Override
|
||||
public void notifyListener(GameEventListener listener) {
|
||||
listener.receivedEvent(this);
|
||||
}
|
||||
}
|
@@ -6,37 +6,37 @@
|
||||
########################################
|
||||
#
|
||||
monopoly.name=Monopoly
|
||||
button.play=Start Game
|
||||
button.ready=Ready
|
||||
button.rotate=Rotate
|
||||
server.connection.failed=Failed to establish a server connection.
|
||||
its.your.turn=It's your turn! Click on the opponent's field to shoot...
|
||||
lost.connection.to.server=Lost connection to server. The game terminated.
|
||||
place.ships.in.your.map=Place ships in your map.
|
||||
wait.for.an.opponent=Wait for an opponent!
|
||||
wait.for.opponent=Wait for your opponent!
|
||||
confirm.leaving=Would you really like to leave the game?
|
||||
you.lost.the.game=You lost the game!
|
||||
you.won.the.game=You won the game!
|
||||
button.yes=Yes
|
||||
button.no=No
|
||||
button.play=Spiel starten
|
||||
button.ready=Bereit
|
||||
button.rotate=Drehen
|
||||
server.connection.failed=Fehler beim Herstellen einer Serververbindung.
|
||||
its.your.turn=Du bist am Zug! Klicke auf das Feld des Gegners, um zu schießen...
|
||||
lost.connection.to.server=Verbindung zum Server verloren. Das Spiel wurde beendet.
|
||||
place.ships.in.your.map=Platziere Schiffe auf deiner Karte.
|
||||
wait.for.an.opponent=Warte auf einen Gegner!
|
||||
wait.for.opponent=Warte auf deinen Gegner!
|
||||
confirm.leaving=Möchtest du das Spiel wirklich beenden?
|
||||
you.lost.the.game=Du hast das Spiel verloren!
|
||||
you.won.the.game=Du hast das Spiel gewonnen!
|
||||
button.yes=Ja
|
||||
button.no=Nein
|
||||
button.ok=Ok
|
||||
button.connect=Connect
|
||||
button.cancel=Cancel
|
||||
button.connect=Verbinden
|
||||
button.cancel=Abbrechen
|
||||
server.dialog=Server
|
||||
host.name=Host
|
||||
port.number=Port
|
||||
wait.its.not.your.turn=Wait, it's not your turn!!
|
||||
menu.quit=Quit game
|
||||
menu.return-to-game=Return to game
|
||||
menu.sound-enabled=Sound switched on
|
||||
menu.background-sound-enabled=Background music switched on
|
||||
menu.map.load=Load map from file...
|
||||
menu.map.save=Save map in file...
|
||||
label.file=File:
|
||||
label.connecting=Connecting...
|
||||
dialog.error=Error
|
||||
dialog.question=Question
|
||||
port.must.be.integer=Port must be an integer number
|
||||
map.doesnt.fit=The map doesn't fit to this game
|
||||
client.server-start=Start server
|
||||
wait.its.not.your.turn=Warte, es ist nicht dein Zug!!
|
||||
menu.quit=Spiel beenden
|
||||
menu.return-to-game=Zum Spiel zurückkehren
|
||||
menu.sound-enabled=Ton eingeschaltet
|
||||
menu.background-sound-enabled=Hintergrundmusik eingeschaltet
|
||||
menu.map.load=Karte aus Datei laden...
|
||||
menu.map.save=Karte in Datei speichern...
|
||||
label.file=Datei:
|
||||
label.connecting=Verbinde...
|
||||
dialog.error=Fehler
|
||||
dialog.question=Frage
|
||||
port.must.be.integer=Port muss eine ganze Zahl sein
|
||||
map.doesnt.fit=Die Karte passt nicht zu diesem Spiel
|
||||
client.server-start=Server starten
|
||||
|
@@ -29,7 +29,7 @@ import pp.monopoly.game.server.Player;
|
||||
import pp.monopoly.game.server.PlayerHandler;
|
||||
import pp.monopoly.game.server.ServerGameLogic;
|
||||
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.EndTurn;
|
||||
import pp.monopoly.message.client.PlayerReady;
|
||||
@@ -37,12 +37,29 @@ import pp.monopoly.message.client.RollDice;
|
||||
import pp.monopoly.message.client.TradeOffer;
|
||||
import pp.monopoly.message.client.TradeResponse;
|
||||
import pp.monopoly.message.client.ViewAssetsRequest;
|
||||
import pp.monopoly.message.server.BuyPropertyRequest;
|
||||
import pp.monopoly.message.server.DiceResult;
|
||||
import pp.monopoly.message.server.EventDrawCard;
|
||||
import pp.monopoly.message.server.GameStart;
|
||||
import pp.monopoly.message.server.NextPlayerTurn;
|
||||
import pp.monopoly.message.server.PlayerStatusUpdate;
|
||||
import pp.monopoly.message.server.ServerMessage;
|
||||
import pp.monopoly.message.server.ViewAssetsResponse;
|
||||
import pp.monopoly.model.Figure;
|
||||
import pp.monopoly.model.IntPoint;
|
||||
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
|
||||
@@ -117,6 +134,7 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
||||
|
||||
private void initializeSerializables() {
|
||||
Serializer.registerClass(IntPoint.class);
|
||||
Serializer.registerClass(BuyPropertyResponse.class);
|
||||
Serializer.registerClass(BuyPropertyRequest.class);
|
||||
Serializer.registerClass(EndTurn.class);
|
||||
Serializer.registerClass(PlayerReady.class);
|
||||
@@ -124,16 +142,32 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
||||
Serializer.registerClass(TradeOffer.class);
|
||||
Serializer.registerClass(TradeResponse.class);
|
||||
Serializer.registerClass(ViewAssetsRequest.class);
|
||||
Serializer.registerClass(ViewAssetsResponse.class);
|
||||
Serializer.registerClass(GameStart.class);
|
||||
Serializer.registerClass(LimitedLinkedList.class);
|
||||
Serializer.registerClass(NextPlayerTurn.class);
|
||||
Serializer.registerClass(Player.class);
|
||||
Serializer.registerClass(Figure.class);
|
||||
Serializer.registerClass(PlayerHandler.class);
|
||||
Serializer.registerClass(DiceResult.class);
|
||||
Serializer.registerClass(EventDrawCard.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() {
|
||||
myServer.addMessageListener(this, BuyPropertyRequest.class);
|
||||
myServer.addMessageListener(this, BuyPropertyResponse.class);
|
||||
myServer.addMessageListener(this, EndTurn.class);
|
||||
myServer.addMessageListener(this, PlayerReady.class);
|
||||
myServer.addMessageListener(this, RollDice.class);
|
||||
@@ -145,7 +179,6 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
||||
|
||||
@Override
|
||||
public void messageReceived(HostedConnection source, Message message) {
|
||||
System.out.println("Message recieved");
|
||||
LOGGER.log(Level.INFO, "message received from {0}: {1}", source.getId(), message); //NON-NLS
|
||||
if (message instanceof ClientMessage clientMessage)
|
||||
pendingMessages.add(new ReceivedMessage(clientMessage, source.getId()));
|
||||
@@ -155,7 +188,6 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
||||
public void connectionAdded(Server server, HostedConnection hostedConnection) {
|
||||
LOGGER.log(Level.INFO, "New connection established: {0}", hostedConnection); //NON-NLS
|
||||
logic.addPlayer(hostedConnection.getId());
|
||||
System.out.println("Spieler verbunden: ID = " + hostedConnection.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user