mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-08-03 18:14:18 +02:00
Compare commits
7 Commits
fed8a3fd2d
...
logic
Author | SHA1 | Date | |
---|---|---|---|
|
4703afd656 | ||
|
d26c29b561 | ||
|
4279d130dd | ||
|
fc5315d35a | ||
|
c7c2d95aed | ||
|
84e68d9fa8 | ||
|
465aef567e |
@@ -1,5 +1,6 @@
|
|||||||
// Styling of Lemur components
|
// Styling of Lemur components
|
||||||
// For documentation, see:
|
// For documentation, see:
|
||||||
|
// For documentation, see:
|
||||||
// https://github.com/jMonkeyEngine-Contributions/Lemur/wiki/Styling
|
// https://github.com/jMonkeyEngine-Contributions/Lemur/wiki/Styling
|
||||||
|
|
||||||
import com.jme3.math.ColorRGBA
|
import com.jme3.math.ColorRGBA
|
||||||
@@ -11,7 +12,6 @@ import com.simsilica.lemur.Command
|
|||||||
import com.simsilica.lemur.HAlignment
|
import com.simsilica.lemur.HAlignment
|
||||||
import com.simsilica.lemur.Insets3f
|
import com.simsilica.lemur.Insets3f
|
||||||
import com.simsilica.lemur.component.QuadBackgroundComponent
|
import com.simsilica.lemur.component.QuadBackgroundComponent
|
||||||
import com.simsilica.lemur.component.TbtQuadBackgroundComponent
|
|
||||||
|
|
||||||
def bgColor = color(1, 1, 1, 1)
|
def bgColor = color(1, 1, 1, 1)
|
||||||
def buttonEnabledColor = color(0, 0, 0, 1)
|
def buttonEnabledColor = color(0, 0, 0, 1)
|
||||||
@@ -19,7 +19,7 @@ def buttonDisabledColor = color(0.8, 0.9, 1, 0.2)
|
|||||||
def buttonBgColor = color(1, 1, 1, 1)
|
def buttonBgColor = color(1, 1, 1, 1)
|
||||||
def sliderColor = color(0.6, 0.8, 0.8, 1)
|
def sliderColor = color(0.6, 0.8, 0.8, 1)
|
||||||
def sliderBgColor = color(0.5, 0.75, 0.75, 1)
|
def sliderBgColor = color(0.5, 0.75, 0.75, 1)
|
||||||
def gradientColor = color(0.5, 0.75, 0.85, 0.5)
|
def gradientColor = color(1, 1, 1, 1)
|
||||||
def tabbuttonEnabledColor = color(0.4, 0.45, 0.5, 1)
|
def tabbuttonEnabledColor = color(0.4, 0.45, 0.5, 1)
|
||||||
def solidWhiteBackground = new QuadBackgroundComponent(new ColorRGBA(1, 1, 1, 1))
|
def solidWhiteBackground = new QuadBackgroundComponent(new ColorRGBA(1, 1, 1, 1))
|
||||||
def greyBackground = new QuadBackgroundComponent(new ColorRGBA(0.1f, 0.1f, 0.1f, 1.0f));
|
def greyBackground = new QuadBackgroundComponent(new ColorRGBA(0.1f, 0.1f, 0.1f, 1.0f));
|
||||||
@@ -30,10 +30,8 @@ def lightGrey = color(0.6, 0.6, 0.6, 1.0)
|
|||||||
|
|
||||||
|
|
||||||
def gradient = TbtQuadBackgroundComponent.create(
|
def gradient = TbtQuadBackgroundComponent.create(
|
||||||
texture(name: "/com/simsilica/lemur/icons/bordered-gradient.png",
|
texture(name: "/com/simsilica/lemur/icons/bordered-gradient.png", generateMips: false),
|
||||||
generateMips: false),
|
1, 1, 1, 126, 126, 1f, false)
|
||||||
1, 1, 1, 126, 126,
|
|
||||||
1f, false)
|
|
||||||
|
|
||||||
def doubleGradient = new QuadBackgroundComponent(gradientColor)
|
def doubleGradient = new QuadBackgroundComponent(gradientColor)
|
||||||
doubleGradient.texture = texture(name: "/com/simsilica/lemur/icons/double-gradient-128.png",
|
doubleGradient.texture = texture(name: "/com/simsilica/lemur/icons/double-gradient-128.png",
|
||||||
@@ -79,6 +77,7 @@ selector("header", "pp") {
|
|||||||
textVAlignment = VAlignment.Center
|
textVAlignment = VAlignment.Center
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Container Stil
|
||||||
selector("container", "pp") {
|
selector("container", "pp") {
|
||||||
background = solidWhiteBackground.clone()
|
background = solidWhiteBackground.clone()
|
||||||
background.setColor(bgColor)
|
background.setColor(bgColor)
|
||||||
@@ -91,8 +90,8 @@ selector("toolbar") {
|
|||||||
|
|
||||||
}
|
}
|
||||||
selector("slider", "pp") {
|
selector("slider", "pp") {
|
||||||
background = gradient.clone()
|
insets = new Insets3f(5, 10, 5, 10) // Abstand
|
||||||
background.setColor(bgColor)
|
background = new QuadBackgroundComponent(sliderBgColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
def pressedCommand = new Command<Button>() {
|
def pressedCommand = new Command<Button>() {
|
||||||
@@ -113,30 +112,6 @@ def enabledCommand = new Command<Button>() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def repeatCommand = new Command<Button>() {
|
|
||||||
private long startTime
|
|
||||||
private long lastClick
|
|
||||||
|
|
||||||
void execute(Button source) {
|
|
||||||
// Only do the repeating click while the mouse is
|
|
||||||
// over the button (and pressed of course)
|
|
||||||
if (source.isPressed() && source.isHighlightOn()) {
|
|
||||||
long elapsedTime = System.currentTimeMillis() - startTime
|
|
||||||
// After half a second pause, click 8 times a second
|
|
||||||
if (elapsedTime > 500 && elapsedTime > lastClick + 125) {
|
|
||||||
source.click()
|
|
||||||
|
|
||||||
// Try to quantize the last click time to prevent drift
|
|
||||||
lastClick = ((elapsedTime - 500) / 125) * 125 + 500
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
startTime = System.currentTimeMillis()
|
|
||||||
lastClick = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def stdButtonCommands = [
|
def stdButtonCommands = [
|
||||||
(ButtonAction.Down) : [pressedCommand],
|
(ButtonAction.Down) : [pressedCommand],
|
||||||
(ButtonAction.Up) : [pressedCommand],
|
(ButtonAction.Up) : [pressedCommand],
|
||||||
|
@@ -1,110 +0,0 @@
|
|||||||
////////////////////////////////////////
|
|
||||||
// Programming project code
|
|
||||||
// UniBw M, 2022, 2023, 2024
|
|
||||||
// www.unibw.de/inf2
|
|
||||||
// (c) Mark Minas (mark.minas@unibw.de)
|
|
||||||
////////////////////////////////////////
|
|
||||||
|
|
||||||
package pp.monopoly.client;
|
|
||||||
|
|
||||||
import com.jme3.input.controls.ActionListener;
|
|
||||||
import com.jme3.scene.Node;
|
|
||||||
import com.jme3.system.AppSettings;
|
|
||||||
import pp.monopoly.client.MonopolyAppState;
|
|
||||||
import pp.monopoly.client.gui.TestWorld;
|
|
||||||
import pp.monopoly.model.IntPoint;
|
|
||||||
|
|
||||||
import java.lang.System.Logger;
|
|
||||||
import java.lang.System.Logger.Level;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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() {
|
|
||||||
testWorld = new TestWorld(getApp());
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,30 +1,26 @@
|
|||||||
////////////////////////////////////////
|
|
||||||
// Programming project code
|
|
||||||
// UniBw M, 2022, 2023, 2024
|
|
||||||
// www.unibw.de/inf2
|
|
||||||
// (c) Mark Minas (mark.minas@unibw.de)
|
|
||||||
////////////////////////////////////////
|
|
||||||
|
|
||||||
package pp.monopoly.client;
|
package pp.monopoly.client;
|
||||||
|
|
||||||
import java.lang.System.Logger;
|
import java.lang.System.Logger;
|
||||||
import java.lang.System.Logger.Level;
|
import java.lang.System.Logger.Level;
|
||||||
import java.util.prefs.Preferences;
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
|
import java.lang.System.Logger;
|
||||||
|
import java.lang.System.Logger.Level;
|
||||||
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
import com.jme3.app.Application;
|
import com.jme3.app.Application;
|
||||||
import com.jme3.app.state.AbstractAppState;
|
import com.jme3.app.state.AbstractAppState;
|
||||||
import com.jme3.app.state.AppStateManager;
|
import com.jme3.app.state.AppStateManager;
|
||||||
import com.jme3.asset.AssetLoadException;
|
|
||||||
import com.jme3.asset.AssetNotFoundException;
|
|
||||||
import com.jme3.audio.AudioData;
|
import com.jme3.audio.AudioData;
|
||||||
import com.jme3.audio.AudioNode;
|
import com.jme3.audio.AudioNode;
|
||||||
|
|
||||||
|
|
||||||
import pp.monopoly.notification.GameEventListener;
|
import pp.monopoly.notification.GameEventListener;
|
||||||
import pp.monopoly.notification.SoundEvent;
|
import pp.monopoly.notification.SoundEvent;
|
||||||
import static pp.util.PreferencesUtils.getPreferences;
|
import static pp.util.PreferencesUtils.getPreferences;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An application state that plays sounds.
|
* An application state that plays sounds based on game events.
|
||||||
*/
|
*/
|
||||||
public class GameSound extends AbstractAppState implements GameEventListener {
|
public class GameSound extends AbstractAppState implements GameEventListener {
|
||||||
private static final Logger LOGGER = System.getLogger(GameSound.class.getName());
|
private static final Logger LOGGER = System.getLogger(GameSound.class.getName());
|
||||||
@@ -71,7 +67,6 @@ public class GameSound extends AbstractAppState implements GameEventListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the enabled state of this AppState.
|
* Sets the enabled state of this AppState.
|
||||||
* Overrides {@link com.jme3.app.state.AbstractAppState#setEnabled(boolean)}
|
|
||||||
*
|
*
|
||||||
* @param enabled {@code true} to enable the AppState, {@code false} to disable it.
|
* @param enabled {@code true} to enable the AppState, {@code false} to disable it.
|
||||||
*/
|
*/
|
||||||
@@ -79,16 +74,15 @@ public class GameSound extends AbstractAppState implements GameEventListener {
|
|||||||
public void setEnabled(boolean enabled) {
|
public void setEnabled(boolean enabled) {
|
||||||
if (isEnabled() == enabled) return;
|
if (isEnabled() == enabled) return;
|
||||||
super.setEnabled(enabled);
|
super.setEnabled(enabled);
|
||||||
LOGGER.log(Level.INFO, "Sound enabled: {0}", enabled); //NON-NLS
|
LOGGER.log(Level.INFO, "Sound enabled: {0}", enabled);
|
||||||
PREFERENCES.putBoolean(ENABLED_PREF, enabled);
|
PREFERENCES.putBoolean(ENABLED_PREF, enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the sound effects for the game.
|
* Initializes the sound effects for the game and stores the application reference.
|
||||||
* Overrides {@link AbstractAppState#initialize(AppStateManager, Application)}
|
|
||||||
*
|
*
|
||||||
* @param stateManager The state manager
|
* @param stateManager The state manager
|
||||||
* @param app The application
|
* @param app The application instance
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void initialize(AppStateManager stateManager, Application app) {
|
public void initialize(AppStateManager stateManager, Application app) {
|
||||||
@@ -109,18 +103,16 @@ public class GameSound extends AbstractAppState implements GameEventListener {
|
|||||||
/**
|
/**
|
||||||
* Loads a sound from the specified file.
|
* Loads a sound from the specified file.
|
||||||
*
|
*
|
||||||
* @param app The application
|
|
||||||
* @param name The name of the sound file.
|
* @param name The name of the sound file.
|
||||||
* @return The loaded AudioNode.
|
* @return The loaded AudioNode.
|
||||||
*/
|
*/
|
||||||
private AudioNode loadSound(Application app, String name) {
|
private AudioNode loadSound(String name) {
|
||||||
try {
|
try {
|
||||||
final AudioNode sound = new AudioNode(app.getAssetManager(), name, AudioData.DataType.Buffer);
|
AudioNode sound = new AudioNode(app.getAssetManager(), name, AudioData.DataType.Buffer);
|
||||||
sound.setLooping(false);
|
sound.setLooping(false);
|
||||||
sound.setPositional(false);
|
sound.setPositional(false);
|
||||||
return sound;
|
return sound;
|
||||||
}
|
} catch (Exception ex) {
|
||||||
catch (AssetLoadException | AssetNotFoundException ex) {
|
|
||||||
LOGGER.log(Level.ERROR, ex.getMessage(), ex);
|
LOGGER.log(Level.ERROR, ex.getMessage(), ex);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -239,4 +231,4 @@ public class GameSound extends AbstractAppState implements GameEventListener {
|
|||||||
case BUTTON -> button();
|
case BUTTON -> button();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}//heloo
|
||||||
|
@@ -18,6 +18,7 @@ import com.jme3.input.controls.ActionListener;
|
|||||||
import com.jme3.input.controls.KeyTrigger;
|
import com.jme3.input.controls.KeyTrigger;
|
||||||
import com.jme3.input.controls.MouseButtonTrigger;
|
import com.jme3.input.controls.MouseButtonTrigger;
|
||||||
import com.jme3.system.AppSettings;
|
import com.jme3.system.AppSettings;
|
||||||
|
import com.jme3.texture.Texture;
|
||||||
import com.simsilica.lemur.GuiGlobals;
|
import com.simsilica.lemur.GuiGlobals;
|
||||||
import com.simsilica.lemur.Label;
|
import com.simsilica.lemur.Label;
|
||||||
import com.simsilica.lemur.style.BaseStyles;
|
import com.simsilica.lemur.style.BaseStyles;
|
||||||
@@ -221,7 +222,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
|||||||
/**
|
/**
|
||||||
* Returns the current configuration settings for the Battleship client.
|
* Returns the current configuration settings for the Battleship client.
|
||||||
*
|
*
|
||||||
* @return The {@link BattleshipClientConfig} instance. //TODO Fehler im Kommentar
|
* @return The {@link BattleshipClientConfig} instance.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public MonopolyAppConfig getConfig() {
|
public MonopolyAppConfig getConfig() {
|
||||||
@@ -279,7 +280,19 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
|||||||
private void handleB(boolean isPressed) {
|
private void handleB(boolean isPressed) {
|
||||||
if (isPressed) {
|
if (isPressed) {
|
||||||
Dialog tmp = new BuyCard(this);
|
Dialog tmp = new BuyCard(this);
|
||||||
tmp.open();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,7 +321,6 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
|||||||
|
|
||||||
attachGameSound();
|
attachGameSound();
|
||||||
attachGameMusic();
|
attachGameMusic();
|
||||||
stateManager.attach(new GameAppState());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -432,7 +444,6 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void receivedEvent(ClientStateEvent event) {
|
public void receivedEvent(ClientStateEvent event) {
|
||||||
stateManager.getState(GameAppState.class).setEnabled(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -493,9 +504,4 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
|||||||
public void disconnect() {
|
public void disconnect() {
|
||||||
serverConnection.disconnect();
|
serverConnection.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
if (serverConnection != null && serverConnection instanceof NetworkSupport) return ((NetworkSupport) serverConnection).getId();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -3,8 +3,10 @@ package pp.monopoly.client.gui;
|
|||||||
import com.jme3.scene.Node;
|
import com.jme3.scene.Node;
|
||||||
import com.jme3.scene.Spatial;
|
import com.jme3.scene.Spatial;
|
||||||
|
|
||||||
|
|
||||||
import pp.monopoly.model.Board;
|
import pp.monopoly.model.Board;
|
||||||
import pp.monopoly.model.Item;
|
import pp.monopoly.model.Item;
|
||||||
|
import pp.monopoly.model.Item;
|
||||||
import pp.monopoly.model.Visitor;
|
import pp.monopoly.model.Visitor;
|
||||||
import pp.monopoly.notification.GameEventListener;
|
import pp.monopoly.notification.GameEventListener;
|
||||||
import pp.monopoly.notification.ItemAddedEvent;
|
import pp.monopoly.notification.ItemAddedEvent;
|
||||||
@@ -24,10 +26,14 @@ abstract class BoardSynchronizer extends ModelViewSynchronizer<Item> implements
|
|||||||
*
|
*
|
||||||
* @param board the game board to synchronize
|
* @param board the game board to synchronize
|
||||||
* @param root the root node to which the view representations of the board items are attached
|
* @param root the root node to which the view representations of the board items are attached
|
||||||
|
* @param board the game board to synchronize
|
||||||
|
* @param root the root node to which the view representations of the board items are attached
|
||||||
*/
|
*/
|
||||||
|
protected BoardSynchronizer(Board board, Node root) {
|
||||||
protected BoardSynchronizer(Board board, Node root) {
|
protected BoardSynchronizer(Board board, Node root) {
|
||||||
super(root);
|
super(root);
|
||||||
this.board = board;
|
this.board = board;
|
||||||
|
this.board = board;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,6 +48,7 @@ abstract class BoardSynchronizer extends ModelViewSynchronizer<Item> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Adds the existing items from the board to the view during initialization.
|
||||||
* Adds the existing items from the board to the view during initialization.
|
* Adds the existing items from the board to the view during initialization.
|
||||||
*/
|
*/
|
||||||
protected void addExisting() {
|
protected void addExisting() {
|
||||||
@@ -49,26 +56,36 @@ abstract class BoardSynchronizer extends ModelViewSynchronizer<Item> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Handles the event when an item is removed from the board.
|
||||||
* Handles the event when an item is removed from the board.
|
* Handles the event when an item is removed from the board.
|
||||||
*
|
*
|
||||||
* @param event the event indicating that an item has been removed from the board
|
* @param event the event indicating that an item has been removed from the board
|
||||||
|
* @param event the event indicating that an item has been removed from the board
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void receivedEvent(ItemRemovedEvent event) {
|
public void receivedEvent(ItemRemovedEvent event) {
|
||||||
if (board == event.getBoard()) {
|
if (board == event.getBoard()) {
|
||||||
delete(event.getItem());
|
delete(event.getItem());
|
||||||
}
|
}
|
||||||
|
if (board == event.getBoard()) {
|
||||||
|
delete(event.getItem());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Handles the event when an item is added to the board.
|
||||||
* Handles the event when an item is added to the board.
|
* Handles the event when an item is added to the board.
|
||||||
*
|
*
|
||||||
* @param event the event indicating that an item has been added to the board
|
* @param event the event indicating that an item has been added to the board
|
||||||
|
* @param event the event indicating that an item has been added to the board
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void receivedEvent(ItemAddedEvent event) {
|
public void receivedEvent(ItemAddedEvent event) {
|
||||||
if (board == event.getBoard()) {
|
if (board == event.getBoard()) {
|
||||||
add(event.getItem());
|
add(event.getItem());
|
||||||
}
|
}
|
||||||
|
if (board == event.getBoard()) {
|
||||||
|
add(event.getItem());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,173 +0,0 @@
|
|||||||
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);
|
|
||||||
}));
|
|
||||||
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,9 +1,5 @@
|
|||||||
package pp.monopoly.client.gui;
|
package pp.monopoly.client.gui;
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import com.jme3.app.Application;
|
|
||||||
import com.jme3.app.state.BaseAppState;
|
|
||||||
import com.jme3.material.Material;
|
import com.jme3.material.Material;
|
||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
@@ -11,149 +7,48 @@ import com.jme3.scene.Geometry;
|
|||||||
import com.jme3.scene.shape.Quad;
|
import com.jme3.scene.shape.Quad;
|
||||||
import com.jme3.texture.Texture;
|
import com.jme3.texture.Texture;
|
||||||
import com.simsilica.lemur.Axis;
|
import com.simsilica.lemur.Axis;
|
||||||
import com.simsilica.lemur.Button;
|
|
||||||
import com.simsilica.lemur.Container;
|
import com.simsilica.lemur.Container;
|
||||||
import com.simsilica.lemur.Label;
|
import com.simsilica.lemur.Label;
|
||||||
import com.simsilica.lemur.Selector;
|
import com.simsilica.lemur.TextField;
|
||||||
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
||||||
import com.simsilica.lemur.component.SpringGridLayout;
|
import com.simsilica.lemur.component.SpringGridLayout;
|
||||||
import com.simsilica.lemur.core.VersionedList;
|
|
||||||
import com.simsilica.lemur.core.VersionedReference;
|
|
||||||
import com.simsilica.lemur.style.ElementId;
|
import com.simsilica.lemur.style.ElementId;
|
||||||
import pp.dialog.Dialog;
|
import pp.dialog.Dialog;
|
||||||
import pp.monopoly.client.MonopolyApp;
|
import pp.monopoly.client.MonopolyApp;
|
||||||
import pp.monopoly.game.server.Player;
|
|
||||||
import pp.monopoly.model.TradeHandler;
|
|
||||||
import pp.monopoly.notification.Sound;
|
|
||||||
|
|
||||||
public class ChoosePartner extends Dialog {
|
public class ChoosePartner extends Dialog {
|
||||||
private final MonopolyApp app;
|
|
||||||
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;
|
|
||||||
QuadBackgroundComponent translucentWhiteBackground =
|
|
||||||
new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f));
|
|
||||||
|
|
||||||
/**
|
private final MonopolyApp app;
|
||||||
* Constructs the ChoosePartner dialog.
|
private final Container menuContainer;
|
||||||
*
|
private Geometry background;
|
||||||
* @param app The Monopoly application instance.
|
|
||||||
*/
|
|
||||||
public ChoosePartner(MonopolyApp app) {
|
public ChoosePartner(MonopolyApp app) {
|
||||||
super(app.getDialogManager());
|
super(app.getDialogManager());
|
||||||
this.app = app;
|
this.app = app;
|
||||||
tradeHandler = new TradeHandler(app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()));
|
|
||||||
|
|
||||||
// Background Image
|
// Hintergrundbild laden und hinzufügen
|
||||||
addBackgroundImage();
|
addBackgroundImage();
|
||||||
|
|
||||||
// Main container for the UI components
|
QuadBackgroundComponent translucentWhiteBackground =
|
||||||
mainContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X));
|
new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f));
|
||||||
mainContainer.setPreferredSize(new Vector3f(1000, 600, 0));
|
|
||||||
mainContainer.setBackground(translucentWhiteBackground);
|
|
||||||
|
|
||||||
// Add title with background
|
menuContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X));
|
||||||
Label headerLabel = mainContainer.addChild(new Label("Wähle deinen Handelspartner:", new ElementId("label-Bold")));
|
menuContainer.setPreferredSize(new Vector3f(1000, 600, 0)); // Fixed size of the container
|
||||||
headerLabel.setFontSize(40);
|
menuContainer.setBackground(translucentWhiteBackground);
|
||||||
headerLabel.setBackground(new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f)));
|
|
||||||
|
|
||||||
// Dropdown for player selection
|
// Create a smaller horizontal container for the label, input field, and spacers
|
||||||
mainContainer.addChild(createDropdown());
|
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);
|
||||||
|
|
||||||
// Add buttons
|
Label title = horizontalContainer.addChild(new Label("Wähle deinen Handelspartner:", new ElementId("label-Bold")));
|
||||||
mainContainer.addChild(createButtonContainer());
|
title.setFontSize(40);
|
||||||
|
|
||||||
addSelectionActionListener(playerSelector, this::onDropdownSelectionChanged);
|
|
||||||
|
|
||||||
// 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
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the dropdown menu for selecting a partner.
|
* Lädt das Hintergrundbild und fügt es als geometrische Ebene hinzu.
|
||||||
*
|
|
||||||
* @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);
|
|
||||||
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).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() {
|
private void addBackgroundImage() {
|
||||||
Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/unibw-Bib2.png");
|
Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/unibw-Bib2.png");
|
||||||
@@ -162,100 +57,8 @@ public class ChoosePartner extends Dialog {
|
|||||||
Material backgroundMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
Material backgroundMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
||||||
backgroundMaterial.setTexture("ColorMap", backgroundImage);
|
backgroundMaterial.setTexture("ColorMap", backgroundImage);
|
||||||
background.setMaterial(backgroundMaterial);
|
background.setMaterial(backgroundMaterial);
|
||||||
background.setLocalTranslation(0, 0, 3); // Position behind other GUI elements
|
background.setLocalTranslation(0, 0, -1); // Hintergrundebene
|
||||||
|
|
||||||
app.getGuiNode().attachChild(background);
|
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) {
|
|
||||||
// Periodic updates (if needed) can be implemented here
|
|
||||||
}
|
|
||||||
|
|
||||||
@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();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a custom action listener to the Selector.
|
|
||||||
*/
|
|
||||||
private void addSelectionActionListener(Selector<String> selector, SelectionActionListener<String> listener) {
|
|
||||||
VersionedReference<Set<Integer>> selectionRef = selector.getSelectionModel().createReference();
|
|
||||||
|
|
||||||
app.getStateManager().attach(new BaseAppState() {
|
|
||||||
@Override
|
|
||||||
public void update(float tpf) {
|
|
||||||
if (selectionRef.update()) {
|
|
||||||
String selected = selectionRef.get().toString();
|
|
||||||
listener.onSelectionChanged(selected);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void initialize(Application app) {
|
|
||||||
update(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void cleanup(Application app) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onEnable() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDisable() {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback for when the dropdown selection changes.
|
|
||||||
*/
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Functional interface for a selection action listener.
|
|
||||||
*/
|
|
||||||
@FunctionalInterface
|
|
||||||
private interface SelectionActionListener<T> {
|
|
||||||
void onSelectionChanged(T selection);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -66,7 +66,7 @@ public class CreateGameMenu extends Dialog {
|
|||||||
|
|
||||||
final MonopolyApp app = network.getApp();
|
final MonopolyApp app = network.getApp();
|
||||||
|
|
||||||
int screenWidth = app.getContext().getSettings().getWidth();
|
int screenWidth = app.getContext().getSettings().getWidth();
|
||||||
int screenHeight = app.getContext().getSettings().getHeight();
|
int screenHeight = app.getContext().getSettings().getHeight();
|
||||||
|
|
||||||
// Set up the background image
|
// Set up the background image
|
||||||
|
@@ -25,7 +25,6 @@ import com.simsilica.lemur.style.ElementId;
|
|||||||
|
|
||||||
import pp.dialog.Dialog;
|
import pp.dialog.Dialog;
|
||||||
import pp.monopoly.client.MonopolyApp;
|
import pp.monopoly.client.MonopolyApp;
|
||||||
import pp.monopoly.game.server.PlayerColor;
|
|
||||||
import pp.monopoly.message.client.PlayerReady;
|
import pp.monopoly.message.client.PlayerReady;
|
||||||
import pp.monopoly.notification.Sound;
|
import pp.monopoly.notification.Sound;
|
||||||
|
|
||||||
@@ -40,7 +39,7 @@ public class LobbyMenu extends Dialog {
|
|||||||
private Container lowerLeftMenu;
|
private Container lowerLeftMenu;
|
||||||
private Container lowerRightMenu;
|
private Container lowerRightMenu;
|
||||||
|
|
||||||
private TextField playerInputField;
|
private TextField playerInputField = new TextField("Spieler 1");
|
||||||
private TextField startingCapital = new TextField("15000");
|
private TextField startingCapital = new TextField("15000");
|
||||||
private String figure;
|
private String figure;
|
||||||
|
|
||||||
@@ -48,7 +47,6 @@ public class LobbyMenu extends Dialog {
|
|||||||
super(app.getDialogManager());
|
super(app.getDialogManager());
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
|
||||||
playerInputField = new TextField("Spieler "+(app.getId()+1));
|
|
||||||
// Hintergrundbild laden und hinzufügen
|
// Hintergrundbild laden und hinzufügen
|
||||||
addBackgroundImage();
|
addBackgroundImage();
|
||||||
|
|
||||||
@@ -90,7 +88,6 @@ public class LobbyMenu extends Dialog {
|
|||||||
|
|
||||||
// Dropdowns and Labels
|
// Dropdowns and Labels
|
||||||
Container dropdownContainer = menuContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
|
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.setPreferredSize(new Vector3f(800, 200, 0));
|
||||||
dropdownContainer.setBackground(null);
|
dropdownContainer.setBackground(null);
|
||||||
dropdownContainer.setInsets(new Insets3f(10, 0, 0, 0));
|
dropdownContainer.setInsets(new Insets3f(10, 0, 0, 0));
|
||||||
@@ -121,18 +118,10 @@ public class LobbyMenu extends Dialog {
|
|||||||
figures.add("OOP");
|
figures.add("OOP");
|
||||||
figures.add("Handyholster");
|
figures.add("Handyholster");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Selector<String> figureDropdown = new Selector<>(figures, "glass");
|
Selector<String> figureDropdown = new Selector<>(figures, "glass");
|
||||||
figureDropdown.setBackground(new QuadBackgroundComponent(ColorRGBA.DarkGray));
|
figureDropdown.setBackground(new QuadBackgroundComponent(ColorRGBA.DarkGray));
|
||||||
figureDropdown.setPreferredSize(new Vector3f(100, 20, 0));
|
figureDropdown.setPreferredSize(new Vector3f(100, 20, 0));
|
||||||
figureDropdownContainer.addChild(figureDropdown);
|
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);
|
addSelectionActionListener(figureDropdown, this::onDropdownSelectionChanged);
|
||||||
|
|
||||||
@@ -164,7 +153,6 @@ public class LobbyMenu extends Dialog {
|
|||||||
readyButton.addClickCommands(s -> ifTopDialog(() -> {
|
readyButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||||
toggleReady();
|
toggleReady();
|
||||||
app.getGameLogic().playSound(Sound.BUTTON);
|
app.getGameLogic().playSound(Sound.BUTTON);
|
||||||
readyButton.setBackground(new QuadBackgroundComponent(ColorRGBA.DarkGray));
|
|
||||||
}));
|
}));
|
||||||
lowerRightMenu.addChild(readyButton);
|
lowerRightMenu.addChild(readyButton);
|
||||||
|
|
||||||
@@ -173,7 +161,7 @@ public class LobbyMenu extends Dialog {
|
|||||||
app.getGuiNode().attachChild(lowerRightMenu);
|
app.getGuiNode().attachChild(lowerRightMenu);
|
||||||
|
|
||||||
// Add a colored circle between the input field and the dropdown menu
|
// Add a colored circle between the input field and the dropdown menu
|
||||||
circle = createCircle(); // 50 is the diameter, Red is the color
|
circle = createCircle( ColorRGBA.Red); // 50 is the diameter, Red is the color
|
||||||
circle.setLocalTranslation(new Vector3f(
|
circle.setLocalTranslation(new Vector3f(
|
||||||
(app.getCamera().getWidth()) / 2, // Center horizontally
|
(app.getCamera().getWidth()) / 2, // Center horizontally
|
||||||
(app.getCamera().getHeight() / 2) - 90, // Adjust Y position
|
(app.getCamera().getHeight() / 2) - 90, // Adjust Y position
|
||||||
@@ -207,33 +195,19 @@ public class LobbyMenu extends Dialog {
|
|||||||
app.getGuiNode().attachChild(background);
|
app.getGuiNode().attachChild(background);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Geometry createCircle() {
|
private Geometry createCircle(ColorRGBA color) {
|
||||||
|
|
||||||
Sphere sphere = new Sphere(90,90,60.0f);
|
Sphere sphere = new Sphere(90,90,60.0f);
|
||||||
Geometry circleGeometry = new Geometry("Circle", sphere);
|
Geometry circleGeometry = new Geometry("Circle", sphere);
|
||||||
|
|
||||||
// Create a material with a solid color
|
// Create a material with a solid color
|
||||||
Material material = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
Material material = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
||||||
material.setColor("Color", idToColor()); // Set the desired color
|
material.setColor("Color", color); // Set the desired color
|
||||||
circleGeometry.setMaterial(material);
|
circleGeometry.setMaterial(material);
|
||||||
|
|
||||||
return circleGeometry;
|
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.
|
* Schaltet den "Bereit"-Status um.
|
||||||
*/
|
*/
|
||||||
@@ -257,6 +231,7 @@ public class LobbyMenu extends Dialog {
|
|||||||
public void update(float tpf) {
|
public void update(float tpf) {
|
||||||
if (selectionRef.update()) {
|
if (selectionRef.update()) {
|
||||||
String selected = selectionRef.get().toString();
|
String selected = selectionRef.get().toString();
|
||||||
|
System.out.println(selected);
|
||||||
listener.onSelectionChanged(selected);
|
listener.onSelectionChanged(selected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -285,6 +260,7 @@ public class LobbyMenu extends Dialog {
|
|||||||
* Callback for when the dropdown selection changes.
|
* Callback for when the dropdown selection changes.
|
||||||
*/
|
*/
|
||||||
private void onDropdownSelectionChanged(String selected) {
|
private void onDropdownSelectionChanged(String selected) {
|
||||||
|
System.out.println("Selected: " + selected);
|
||||||
app.getGameLogic().playSound(Sound.BUTTON);
|
app.getGameLogic().playSound(Sound.BUTTON);
|
||||||
switch (selected) {
|
switch (selected) {
|
||||||
case "[0]":
|
case "[0]":
|
||||||
|
@@ -6,12 +6,17 @@ import com.jme3.scene.Geometry;
|
|||||||
import com.jme3.scene.shape.Quad;
|
import com.jme3.scene.shape.Quad;
|
||||||
import com.jme3.texture.Texture;
|
import com.jme3.texture.Texture;
|
||||||
import com.simsilica.lemur.Axis;
|
import com.simsilica.lemur.Axis;
|
||||||
|
import com.simsilica.lemur.Axis;
|
||||||
import com.simsilica.lemur.Button;
|
import com.simsilica.lemur.Button;
|
||||||
import com.simsilica.lemur.Container;
|
import com.simsilica.lemur.Container;
|
||||||
import com.simsilica.lemur.HAlignment;
|
import com.simsilica.lemur.HAlignment;
|
||||||
|
import com.simsilica.lemur.Container;
|
||||||
|
import com.simsilica.lemur.HAlignment;
|
||||||
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
||||||
import com.simsilica.lemur.component.SpringGridLayout;
|
import com.simsilica.lemur.component.SpringGridLayout;
|
||||||
|
|
||||||
|
import com.simsilica.lemur.component.SpringGridLayout;
|
||||||
|
|
||||||
import pp.dialog.Dialog;
|
import pp.dialog.Dialog;
|
||||||
import pp.monopoly.client.MonopolyApp;
|
import pp.monopoly.client.MonopolyApp;
|
||||||
import pp.monopoly.notification.Sound;
|
import pp.monopoly.notification.Sound;
|
||||||
@@ -20,10 +25,12 @@ import pp.monopoly.notification.Sound;
|
|||||||
* Constructs the startup menu dialog for the Monopoly application.
|
* Constructs the startup menu dialog for the Monopoly application.
|
||||||
import pp.monopoly.client.gui.GameMenu;
|
import pp.monopoly.client.gui.GameMenu;
|
||||||
*/
|
*/
|
||||||
|
*/
|
||||||
public class StartMenu extends Dialog {
|
public class StartMenu extends Dialog {
|
||||||
private final MonopolyApp app;
|
private final MonopolyApp app;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Constructs the Startup Menu dialog for the Monopoly application.
|
||||||
* Constructs the Startup Menu dialog for the Monopoly application.
|
* Constructs the Startup Menu dialog for the Monopoly application.
|
||||||
*
|
*
|
||||||
* @param app the MonopolyApp instance
|
* @param app the MonopolyApp instance
|
||||||
@@ -41,8 +48,10 @@ public class StartMenu extends Dialog {
|
|||||||
Geometry background = new Geometry("Background", quad);
|
Geometry background = new Geometry("Background", quad);
|
||||||
Material backgroundMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
Material backgroundMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
||||||
backgroundMaterial.setTexture("ColorMap", backgroundImage);
|
backgroundMaterial.setTexture("ColorMap", backgroundImage);
|
||||||
|
backgroundMaterial.setTexture("ColorMap", backgroundImage);
|
||||||
background.setMaterial(backgroundMaterial);
|
background.setMaterial(backgroundMaterial);
|
||||||
background.setLocalTranslation(0, 0, -1); // Ensure it is behind other GUI elements
|
background.setLocalTranslation(0, 0, -1); // Ensure it is behind other GUI elements
|
||||||
|
background.setLocalTranslation(0, 0, -1); // Ensure it is behind other GUI elements
|
||||||
app.getGuiNode().attachChild(background);
|
app.getGuiNode().attachChild(background);
|
||||||
|
|
||||||
// Center container for title and play button
|
// Center container for title and play button
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
package pp.monopoly.client.gui;
|
package pp.monopoly.client.gui;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import com.jme3.material.Material;
|
import com.jme3.material.Material;
|
||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
@@ -10,20 +12,15 @@ import com.jme3.scene.shape.Box;
|
|||||||
import com.jme3.texture.Texture;
|
import com.jme3.texture.Texture;
|
||||||
|
|
||||||
import pp.monopoly.client.MonopolyApp;
|
import pp.monopoly.client.MonopolyApp;
|
||||||
import pp.monopoly.client.gui.popups.EventCard;
|
|
||||||
import pp.monopoly.notification.DiceRollEvent;
|
|
||||||
import pp.monopoly.notification.EventCardEvent;
|
|
||||||
import pp.monopoly.notification.GameEventListener;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TestWorld zeigt eine einfache Szene mit einem texturierten Quadrat.
|
* TestWorld zeigt eine einfache Szene mit einem texturierten Quadrat.
|
||||||
* Die Kamera wird durch den CameraController gesteuert.
|
* Die Kamera wird durch den CameraController gesteuert.
|
||||||
*/
|
*/
|
||||||
public class TestWorld implements GameEventListener{
|
public class TestWorld {
|
||||||
|
|
||||||
private final MonopolyApp app;
|
private final MonopolyApp app;
|
||||||
private CameraController cameraController; // Steuert die Kamera
|
private CameraController cameraController; // Steuert die Kamera
|
||||||
private Toolbar toolbar;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Konstruktor für TestWorld.
|
* Konstruktor für TestWorld.
|
||||||
@@ -32,7 +29,6 @@ public class TestWorld implements GameEventListener{
|
|||||||
*/
|
*/
|
||||||
public TestWorld(MonopolyApp app) {
|
public TestWorld(MonopolyApp app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
app.getGameLogic().addListener(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,8 +51,7 @@ public class TestWorld implements GameEventListener{
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Füge die Toolbar hinzu
|
// Füge die Toolbar hinzu
|
||||||
toolbar = new Toolbar(app);
|
new Toolbar(app).open();
|
||||||
toolbar.open();
|
|
||||||
|
|
||||||
cameraController.setPosition(0);
|
cameraController.setPosition(0);
|
||||||
}
|
}
|
||||||
@@ -96,9 +91,4 @@ public class TestWorld implements GameEventListener{
|
|||||||
|
|
||||||
app.getRootNode().attachChild(geom);
|
app.getRootNode().attachChild(geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void receivedEvent(EventCardEvent event) {
|
|
||||||
new EventCard(app, event.description()).open();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,80 @@
|
|||||||
|
package pp.monopoly.client.gui;
|
||||||
|
|
||||||
|
import com.jme3.app.SimpleApplication;
|
||||||
|
import com.jme3.material.Material;
|
||||||
|
import com.jme3.math.Vector3f;
|
||||||
|
import com.jme3.scene.Geometry;
|
||||||
|
import com.jme3.scene.shape.Box;
|
||||||
|
import com.jme3.texture.Texture;
|
||||||
|
import com.jme3.system.JmeCanvasContext;
|
||||||
|
import com.jme3.system.AppSettings;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
|
||||||
|
public class TestWorldWithMenu extends SimpleApplication {
|
||||||
|
|
||||||
|
public static void createAndShowGUI() {
|
||||||
|
// Create JFrame
|
||||||
|
JFrame frame = new JFrame("Test World with Menu");
|
||||||
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
frame.setLayout(new BorderLayout());
|
||||||
|
frame.setSize(800, 600);
|
||||||
|
|
||||||
|
// Create Menu Bar
|
||||||
|
JMenuBar menuBar = new JMenuBar();
|
||||||
|
JMenu fileMenu = new JMenu("File");
|
||||||
|
JMenuItem exitItem = new JMenuItem(new AbstractAction("Exit") {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
fileMenu.add(exitItem);
|
||||||
|
menuBar.add(fileMenu);
|
||||||
|
frame.setJMenuBar(menuBar);
|
||||||
|
|
||||||
|
// Create Canvas for jMonkey
|
||||||
|
AppSettings settings = new AppSettings(true);
|
||||||
|
settings.setWidth(800);
|
||||||
|
settings.setHeight(600);
|
||||||
|
|
||||||
|
TestWorldWithMenu app = new TestWorldWithMenu();
|
||||||
|
app.setSettings(settings);
|
||||||
|
app.createCanvas(); // Create a canvas for embedding
|
||||||
|
JmeCanvasContext ctx = (JmeCanvasContext) app.getContext();
|
||||||
|
ctx.setSystemListener(app);
|
||||||
|
Canvas canvas = ctx.getCanvas();
|
||||||
|
canvas.setSize(800, 600);
|
||||||
|
|
||||||
|
// Add the canvas to JFrame
|
||||||
|
frame.add(canvas, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
// Show the frame
|
||||||
|
frame.setVisible(true);
|
||||||
|
|
||||||
|
// Start the jMonkeyEngine application
|
||||||
|
app.startCanvas();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void simpleInitApp() {
|
||||||
|
// Erstelle ein Quadrat
|
||||||
|
Box box = new Box(1, 0.01f, 1); // Dünnes Quadrat für die Textur
|
||||||
|
Geometry geom = new Geometry("Box", box);
|
||||||
|
|
||||||
|
// Setze das Material mit Textur
|
||||||
|
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
|
||||||
|
Texture texture = assetManager.loadTexture("Pictures/board.png"); // Replace with the path to your image
|
||||||
|
mat.setTexture("ColorMap", texture);
|
||||||
|
geom.setMaterial(mat);
|
||||||
|
|
||||||
|
// Füge das Quadrat zur Szene hinzu
|
||||||
|
rootNode.attachChild(geom);
|
||||||
|
|
||||||
|
// Setze die Kameraposition, um das Quadrat zu fokussieren
|
||||||
|
cam.setLocation(new Vector3f(0, 0, 3)); // Kamera auf der Z-Achse, nah am Quadrat
|
||||||
|
cam.lookAt(geom.getLocalTranslation(), Vector3f.UNIT_Y);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,9 @@
|
|||||||
|
|
||||||
package pp.monopoly.client.gui;
|
package pp.monopoly.client.gui;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import com.jme3.font.BitmapText;
|
||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
import com.jme3.math.Vector2f;
|
import com.jme3.math.Vector2f;
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
@@ -7,252 +11,277 @@ import com.simsilica.lemur.*;
|
|||||||
import com.simsilica.lemur.component.IconComponent;
|
import com.simsilica.lemur.component.IconComponent;
|
||||||
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
||||||
import com.simsilica.lemur.component.SpringGridLayout;
|
import com.simsilica.lemur.component.SpringGridLayout;
|
||||||
|
|
||||||
import com.simsilica.lemur.style.ElementId;
|
import com.simsilica.lemur.style.ElementId;
|
||||||
|
|
||||||
import pp.dialog.Dialog;
|
import pp.dialog.Dialog;
|
||||||
import pp.monopoly.client.MonopolyApp;
|
import pp.monopoly.client.MonopolyApp;
|
||||||
import pp.monopoly.game.server.Player;
|
|
||||||
import pp.monopoly.game.server.PlayerHandler;
|
|
||||||
import pp.monopoly.message.client.EndTurn;
|
|
||||||
import pp.monopoly.message.client.RollDice;
|
|
||||||
import pp.monopoly.notification.DiceRollEvent;
|
|
||||||
import pp.monopoly.notification.GameEventListener;
|
|
||||||
import pp.monopoly.notification.Sound;
|
import pp.monopoly.notification.Sound;
|
||||||
import pp.monopoly.notification.UpdatePlayerView;
|
|
||||||
|
|
||||||
public class Toolbar extends Dialog implements GameEventListener {
|
/**
|
||||||
|
* Toolbar Klasse, die am unteren Rand der Szene angezeigt wird.
|
||||||
|
* Die Buttons bewegen den Würfel auf dem Spielfeld.
|
||||||
|
*/
|
||||||
|
public class Toolbar extends Dialog {
|
||||||
|
|
||||||
private final MonopolyApp app;
|
private final MonopolyApp app;
|
||||||
private final Container toolbarContainer;
|
private final Container toolbarContainer;
|
||||||
private Label imageLabel;
|
private final BitmapText positionText; // Anzeige für die aktuelle Position
|
||||||
private Label imageLabel2;
|
private final float boardLimit = 0.95f; // Grenzen des Bretts
|
||||||
private Container overviewContainer;
|
private final float stepSize = 0.18f; // Schrittgröße pro Bewegung
|
||||||
private Container accountContainer;
|
private int currentPosition = 0; // Aktuelle Position auf dem Spielfeld
|
||||||
private PlayerHandler playerHandler;
|
private final int positionsPerSide = 10; // Anzahl der Positionen pro Seite
|
||||||
private volatile boolean animatingDice = false;
|
private final Random random = new Random(); // Zufallsgenerator für den Würfelwurf
|
||||||
private volatile DiceRollEvent latestDiceRollEvent = null;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Konstruktor für die Toolbar.
|
||||||
|
*
|
||||||
|
* @param app Die Hauptanwendung (MonopolyApp)
|
||||||
|
*/
|
||||||
public Toolbar(MonopolyApp app) {
|
public Toolbar(MonopolyApp app) {
|
||||||
super(app.getDialogManager());
|
super(app.getDialogManager());
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
|
||||||
app.getGameLogic().addListener(this);
|
|
||||||
playerHandler = app.getGameLogic().getPlayerHandler();
|
|
||||||
|
|
||||||
// Erstelle die Toolbar
|
// Erstelle die Toolbar
|
||||||
toolbarContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y), "toolbar");
|
toolbarContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y), "toolbar");
|
||||||
toolbarContainer.setLocalTranslation(0, 200, 0);
|
|
||||||
toolbarContainer.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 200, 0));
|
|
||||||
|
|
||||||
// Account- und Übersichtskontainer
|
// Setze die Position am unteren Rand und die Breite
|
||||||
accountContainer = toolbarContainer.addChild(new Container());
|
toolbarContainer.setLocalTranslation(
|
||||||
overviewContainer = toolbarContainer.addChild(new Container());
|
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
|
||||||
|
|
||||||
receivedEvent(new UpdatePlayerView());
|
|
||||||
|
|
||||||
|
// Füge Buttons zur Toolbar hinzu
|
||||||
|
//initializeButtons();
|
||||||
|
|
||||||
|
|
||||||
|
// 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)));
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// 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)));
|
overviewContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||||
|
|
||||||
// Würfelbereich
|
// Menü-Container: Ein Container für Würfel
|
||||||
Container diceContainer = toolbarContainer.addChild(new Container());
|
Container diceContainer = toolbarContainer.addChild(new Container());
|
||||||
diceContainer.setLayout(new SpringGridLayout(Axis.X, Axis.Y));
|
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));
|
Container horizontalContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
|
||||||
horizontalContainer.setPreferredSize(new Vector3f(200, 150, 0));
|
horizontalContainer.setPreferredSize(new Vector3f(200, 150, 0)); // Adjust size as needed
|
||||||
|
|
||||||
// Linker Würfel
|
// Create the first container (leftContainer)
|
||||||
Container leftContainer = new Container();
|
Container leftContainer = new Container();
|
||||||
leftContainer.setPreferredSize(new Vector3f(100, 150, 0));
|
leftContainer.setPreferredSize(new Vector3f(100, 150, 0)); // Adjust size as needed
|
||||||
imageLabel = new Label("");
|
|
||||||
IconComponent icon = new IconComponent("Pictures/dice/one.png");
|
Label imageLabel = new Label("");
|
||||||
icon.setIconSize(new Vector2f(100, 100));
|
IconComponent icon = new IconComponent("Pictures/dice/one.png"); // Icon mit Textur erstellen
|
||||||
|
icon.setIconSize(new Vector2f(100,100)); // Skalierung des Bildes
|
||||||
imageLabel.setIcon(icon);
|
imageLabel.setIcon(icon);
|
||||||
|
|
||||||
// Rechter Würfel
|
Label imageLabel2 = new Label("");
|
||||||
Container rightContainer = new Container();
|
IconComponent icon2 = new IconComponent("Pictures/dice/two.png"); // Icon mit Textur erstellen
|
||||||
rightContainer.setPreferredSize(new Vector3f(100, 150, 0));
|
icon2.setIconSize(new Vector2f(100,100)); // Skalierung des Bildes
|
||||||
imageLabel2 = new Label("");
|
|
||||||
IconComponent icon2 = new IconComponent("Pictures/dice/two.png");
|
|
||||||
icon2.setIconSize(new Vector2f(100, 100));
|
|
||||||
imageLabel2.setIcon(icon2);
|
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);
|
leftContainer.addChild(imageLabel);
|
||||||
rightContainer.addChild(imageLabel2);
|
rightContainer.addChild(imageLabel2);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Add leftContainer and rightContainer to the horizontal container
|
||||||
horizontalContainer.addChild(leftContainer);
|
horizontalContainer.addChild(leftContainer);
|
||||||
horizontalContainer.addChild(rightContainer);
|
horizontalContainer.addChild(rightContainer);
|
||||||
|
|
||||||
|
// Add the horizontalContainer to the diceContainer (top section)
|
||||||
diceContainer.addChild(horizontalContainer);
|
diceContainer.addChild(horizontalContainer);
|
||||||
|
|
||||||
// Würfeln-Button
|
// Add the Würfeln button directly below the horizontalContainer
|
||||||
Button diceButton = new Button("Würfeln");
|
Button diceButton = new Button("Würfeln");
|
||||||
diceButton.setPreferredSize(new Vector3f(200, 50, 0));
|
diceButton.setPreferredSize(new Vector3f(200, 50, 0)); // Full width for Würfeln button
|
||||||
diceButton.addClickCommands(s -> ifTopDialog(() -> {
|
diceButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||||
startDiceAnimation();
|
rollDice();
|
||||||
app.getGameLogic().send(new RollDice());
|
|
||||||
app.getGameLogic().playSound(Sound.BUTTON);
|
app.getGameLogic().playSound(Sound.BUTTON);
|
||||||
}));
|
}));
|
||||||
diceContainer.addChild(diceButton);
|
diceContainer.addChild(diceButton);
|
||||||
|
|
||||||
// Menü-Container für weitere Aktionen
|
|
||||||
|
|
||||||
|
|
||||||
|
// Menü-Container: Ein Nested-Container für Handeln, Grundstücke und Zug beenden
|
||||||
Container menuContainer = toolbarContainer.addChild(new Container());
|
Container menuContainer = toolbarContainer.addChild(new Container());
|
||||||
menuContainer.addChild(addTradeMenuButton());
|
menuContainer.addChild(new Button("Handeln"));
|
||||||
menuContainer.addChild(addPropertyMenuButton());
|
menuContainer.addChild(new Button("Grundstücke"));
|
||||||
menuContainer.addChild(addEndTurnButton());
|
menuContainer.addChild(new Button("Zug beenden"));
|
||||||
menuContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
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);
|
app.getGuiNode().attachChild(toolbarContainer);
|
||||||
|
|
||||||
|
// Erstelle die Position-Anzeige
|
||||||
|
positionText = createPositionDisplay();
|
||||||
|
updatePositionDisplay(); // Initialisiere die Anzeige mit der Startposition
|
||||||
}
|
}
|
||||||
|
|
||||||
private Button addTradeMenuButton() {
|
/**
|
||||||
Button tradeButton = new Button("Handeln");
|
* Initialisiert die Buttons in der Toolbar.
|
||||||
tradeButton.setPreferredSize(new Vector3f(150, 50, 0));
|
*/
|
||||||
tradeButton.addClickCommands(s -> ifTopDialog(() -> {
|
private void initializeButtons() {
|
||||||
|
addTradeMenuButton(); // Bewegung nach vorne
|
||||||
|
addEndTurnButton(); // Bewegung nach hinten
|
||||||
|
addDiceRollButton(); // Würfel-Button
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 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);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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();
|
||||||
app.getGameLogic().playSound(Sound.BUTTON);
|
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();
|
new ChoosePartner(app).open();
|
||||||
}));
|
|
||||||
return tradeButton;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Button addPropertyMenuButton() {
|
|
||||||
Button propertyMenuButton = new Button("Grundstücke");
|
|
||||||
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 addEndTurnButton() {
|
|
||||||
Button endTurnButton = new Button("Zug beenden");
|
|
||||||
endTurnButton.setPreferredSize(new Vector3f(150, 50, 0));
|
|
||||||
endTurnButton.addClickCommands(s -> ifTopDialog(() -> {
|
|
||||||
app.getGameLogic().playSound(Sound.BUTTON);
|
|
||||||
app.getGameLogic().send(new EndTurn());
|
|
||||||
}));
|
|
||||||
return endTurnButton;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startDiceAnimation() {
|
|
||||||
animatingDice = true;
|
|
||||||
|
|
||||||
// Starte die Animation und speichere die Startzeit
|
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
|
|
||||||
Thread diceAnimation = new Thread(() -> {
|
|
||||||
int[] currentFace = {1};
|
|
||||||
try {
|
|
||||||
while (System.currentTimeMillis() - startTime < 2500) { // 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;
|
|
||||||
|
|
||||||
// Zeige das finale Ergebnis
|
|
||||||
if (latestDiceRollEvent != null) {
|
|
||||||
showFinalDiceResult(latestDiceRollEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
System.err.println("Würfelanimation unterbrochen: " + e.getMessage());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
diceAnimation.start();
|
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 showFinalDiceResult(DiceRollEvent event) {
|
private void addPropertyMenuButton() {
|
||||||
int diceRoll1 = event.a();
|
Button diceButton = new Button("Zug beenden");
|
||||||
int diceRoll2 = event.b();
|
diceButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons
|
||||||
|
diceButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||||
String finalImage1 = diceToString(diceRoll1);
|
rollDice();
|
||||||
String finalImage2 = diceToString(diceRoll2);
|
app.getGameLogic().playSound(Sound.BUTTON);
|
||||||
|
}));
|
||||||
IconComponent finalIcon1 = new IconComponent(finalImage1);
|
toolbarContainer.addChild(diceButton);
|
||||||
finalIcon1.setIconSize(new Vector2f(100, 100));
|
|
||||||
app.enqueue(() -> imageLabel.setIcon(finalIcon1));
|
|
||||||
|
|
||||||
IconComponent finalIcon2 = new IconComponent(finalImage2);
|
|
||||||
finalIcon2.setIconSize(new Vector2f(100, 100));
|
|
||||||
app.enqueue(() -> imageLabel2.setIcon(finalIcon2));
|
|
||||||
|
|
||||||
app.getGameLogic().playSound(Sound.BUTTON);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public void receivedEvent(DiceRollEvent event) {
|
* Simuliert einen Würfelwurf und bewegt die Figur entsprechend.
|
||||||
latestDiceRollEvent = event; // Speichere das Event
|
*/
|
||||||
|
private void rollDice() {
|
||||||
|
int diceRoll = random.nextInt(6) + 1; // Zahl zwischen 1 und 6
|
||||||
|
System.out.println("Gewürfelt: " + diceRoll);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public void receivedEvent(UpdatePlayerView event) {
|
* Berechnet die neue Position des Würfels basierend auf der aktuellen Brettseite und Position.
|
||||||
playerHandler = app.getGameLogic().getPlayerHandler();
|
*
|
||||||
System.err.println("Update Player View");
|
* @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
|
||||||
|
|
||||||
// Clear existing accountContainer and overviewContainer content
|
switch (side) {
|
||||||
accountContainer.clearChildren();
|
case 0: // Unten (positive x-Achse)
|
||||||
overviewContainer.clearChildren();
|
return new Vector3f(-boardLimit + offset * stepSize, 0.1f, -boardLimit + 0.05f);
|
||||||
|
case 1: // Rechts (positive z-Achse)
|
||||||
accountContainer.addChild(new Label("Kontostand", new ElementId("label-Bold")));
|
return new Vector3f(boardLimit - 0.05f, 0.1f, -boardLimit + offset * stepSize);
|
||||||
accountContainer.addChild(new Label(
|
case 2: // Oben (negative x-Achse)
|
||||||
playerHandler.getPlayerById(app.getId()).getAccountBalance() + " EUR",
|
return new Vector3f(boardLimit - offset * stepSize, 0.1f, boardLimit - 0.05f);
|
||||||
new ElementId("label-Text")
|
case 3: // Links (negative z-Achse)
|
||||||
));
|
return new Vector3f(-boardLimit + 0.05f, 0.1f, boardLimit - offset * stepSize);
|
||||||
accountContainer.addChild(new Label("Gulag Karten", new ElementId("label-Bold")));
|
|
||||||
accountContainer.addChild(new Label(
|
|
||||||
playerHandler.getPlayerById(app.getId()).getNumJailCard() + "",
|
|
||||||
new ElementId("label-Text")
|
|
||||||
));
|
|
||||||
accountContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
|
||||||
|
|
||||||
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(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
|
||||||
}
|
|
||||||
|
|
||||||
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:
|
default:
|
||||||
throw new IllegalArgumentException("Invalid dice number: " + i);
|
throw new IllegalArgumentException("Ungültige Position: " + position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aktualisiert die Anzeige für die aktuelle Position.
|
||||||
|
*/
|
||||||
|
private void updatePositionDisplay() {
|
||||||
|
positionText.setText("Feld-ID: " + currentPosition);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
app.getGuiNode().detachChild(toolbarContainer);
|
app.getGuiNode().detachChild(toolbarContainer);
|
||||||
|
app.getGuiNode().detachChild(positionText);
|
||||||
super.close();
|
super.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,382 +0,0 @@
|
|||||||
package pp.monopoly.client.gui;
|
|
||||||
|
|
||||||
import com.jme3.app.Application;
|
|
||||||
import com.jme3.app.state.BaseAppState;
|
|
||||||
import com.jme3.material.Material;
|
|
||||||
import com.jme3.math.ColorRGBA;
|
|
||||||
import com.jme3.math.Vector3f;
|
|
||||||
import com.jme3.scene.Geometry;
|
|
||||||
import com.jme3.scene.shape.Quad;
|
|
||||||
import com.jme3.texture.Texture;
|
|
||||||
import com.simsilica.lemur.*;
|
|
||||||
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
|
||||||
import com.simsilica.lemur.component.SpringGridLayout;
|
|
||||||
import com.simsilica.lemur.core.VersionedList;
|
|
||||||
import com.simsilica.lemur.core.VersionedReference;
|
|
||||||
import com.simsilica.lemur.style.ElementId;
|
|
||||||
import com.simsilica.lemur.text.DocumentModel;
|
|
||||||
import pp.dialog.Dialog;
|
|
||||||
import pp.monopoly.client.MonopolyApp;
|
|
||||||
import pp.monopoly.notification.Sound;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class TradeMenu extends Dialog {
|
|
||||||
private final MonopolyApp app;
|
|
||||||
private final Container mainContainer;
|
|
||||||
private Selector<String> leftBuildingSelector, leftCurrencySelector, leftSpecialCardSelector;
|
|
||||||
private Selector<String> rightBuildingSelector, rightCurrencySelector, rightSpecialCardSelector;
|
|
||||||
private final Button cancelButton = new Button("Abbrechen");
|
|
||||||
private final Button tradeButton = new Button("Handeln");
|
|
||||||
private Container lowerLeftMenu, lowerRightMenu;
|
|
||||||
private TextField leftSelectionsField;
|
|
||||||
private TextField rightSelectionsField;
|
|
||||||
private TextField leftCurrencyInput;
|
|
||||||
private TextField rightCurrencyInput;
|
|
||||||
|
|
||||||
QuadBackgroundComponent translucentWhiteBackground =
|
|
||||||
new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.White));
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs the TradeMenu dialog.
|
|
||||||
*
|
|
||||||
* @param app The Monopoly application instance.
|
|
||||||
*/
|
|
||||||
public TradeMenu(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(1200, 800, 0));
|
|
||||||
mainContainer.setBackground(translucentWhiteBackground);
|
|
||||||
|
|
||||||
// Add header container
|
|
||||||
mainContainer.addChild(createHeaderContainer());
|
|
||||||
// Add main content (three columns: left, middle, right)
|
|
||||||
mainContainer.addChild(createMainContent());
|
|
||||||
|
|
||||||
// Attach main container to GUI node
|
|
||||||
app.getGuiNode().attachChild(mainContainer);
|
|
||||||
mainContainer.setLocalTranslation(
|
|
||||||
(app.getCamera().getWidth() - mainContainer.getPreferredSize().x) / 2,
|
|
||||||
(app.getCamera().getHeight() + mainContainer.getPreferredSize().y) / 2,
|
|
||||||
7
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a container for the header with a fixed size.
|
|
||||||
*
|
|
||||||
* @return The header container.
|
|
||||||
*/
|
|
||||||
private Container createHeaderContainer() {
|
|
||||||
// Create a container for the header
|
|
||||||
Container headerContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
|
|
||||||
headerContainer.setPreferredSize(new Vector3f(200, 100, 0)); // Set fixed width and height
|
|
||||||
|
|
||||||
// Add the header label
|
|
||||||
Label headerLabel = headerContainer.addChild(new Label("Handelsmenü", new ElementId("label-Bold")));
|
|
||||||
headerLabel.setFontSize(50); // Adjust font size as needed
|
|
||||||
headerLabel.setInsets(new Insets3f(10, 10, 10, 10)); // Add padding around the label
|
|
||||||
headerLabel.setBackground(new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f))); // Optional background
|
|
||||||
|
|
||||||
return headerContainer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the main content layout (left, middle, right columns).
|
|
||||||
*
|
|
||||||
* @return The main content container.
|
|
||||||
*/
|
|
||||||
private Container createMainContent() {
|
|
||||||
Container mainContent = new Container(new SpringGridLayout(Axis.X, Axis.Y));
|
|
||||||
mainContent.setPreferredSize(new Vector3f(1200, 700, 0));
|
|
||||||
|
|
||||||
// Left Column
|
|
||||||
mainContent.addChild(createTradeColumn("Wähle Handelsobjekt:", true));
|
|
||||||
|
|
||||||
// Middle Section
|
|
||||||
Container middleSection = mainContent.addChild(new Container(new SpringGridLayout(Axis.Y, Axis.X)));
|
|
||||||
middleSection.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8f, 0.8f, 0.8f, 1.0f)));
|
|
||||||
|
|
||||||
// Add combined label
|
|
||||||
Label middleLabel = middleSection.addChild(new Label("Gebäude: Währung: Sonderkarten:"));
|
|
||||||
middleLabel.setFontSize(24); // Adjust font size as needed
|
|
||||||
middleLabel.setInsets(new Insets3f(5, 5, 5, 5)); // Add padding around the label
|
|
||||||
|
|
||||||
// Add the Quellobjekte TextField
|
|
||||||
leftSelectionsField = middleSection.addChild(new TextField(""));
|
|
||||||
leftSelectionsField.setPreferredSize(new Vector3f(600, 50, 0)); // Larger width to fit the split sections
|
|
||||||
|
|
||||||
addCustomSelectionListener(leftBuildingSelector, newSelection -> updateSelectionsField(leftSelectionsField, leftBuildingSelector, leftCurrencyInput, leftSpecialCardSelector));
|
|
||||||
addCustomSelectionListener(leftSpecialCardSelector, newSelection -> updateSelectionsField(leftSelectionsField, leftBuildingSelector, leftCurrencyInput, leftSpecialCardSelector));
|
|
||||||
// Add change listener for the currency input
|
|
||||||
monitorTextFieldChanges(leftCurrencyInput, () -> updateSelectionsField(leftSelectionsField, leftBuildingSelector, leftCurrencyInput, leftSpecialCardSelector));
|
|
||||||
|
|
||||||
Label arrows = middleSection.addChild(new Label("⇅"));
|
|
||||||
arrows.setFontSize(40);
|
|
||||||
|
|
||||||
// Right Column
|
|
||||||
mainContent.addChild(createTradeColumn("Wähle Zielobjekt:", false));
|
|
||||||
|
|
||||||
|
|
||||||
// Add combined label
|
|
||||||
middleLabel = middleSection.addChild(new Label("Gebäude: Währung: Sonderkarten:"));
|
|
||||||
middleLabel.setFontSize(24); // Adjust font size as needed
|
|
||||||
middleLabel.setInsets(new Insets3f(5, 5, 5, 5)); // Add padding around the label
|
|
||||||
|
|
||||||
// Add the Zielobjekte TextField
|
|
||||||
rightSelectionsField = middleSection.addChild(new TextField(""));
|
|
||||||
rightSelectionsField.setPreferredSize(new Vector3f(600, 50, 0));
|
|
||||||
|
|
||||||
addCustomSelectionListener(rightBuildingSelector, newSelection -> updateSelectionsField(rightSelectionsField, rightBuildingSelector, rightCurrencyInput, rightSpecialCardSelector));
|
|
||||||
addCustomSelectionListener(rightSpecialCardSelector, newSelection -> updateSelectionsField(rightSelectionsField, rightBuildingSelector, rightCurrencyInput, rightSpecialCardSelector));
|
|
||||||
|
|
||||||
// Add change listener for the currency input
|
|
||||||
monitorTextFieldChanges(rightCurrencyInput, () -> updateSelectionsField(rightSelectionsField, rightBuildingSelector, rightCurrencyInput, rightSpecialCardSelector));
|
|
||||||
|
|
||||||
|
|
||||||
// "Bestätigen" button
|
|
||||||
lowerRightMenu = new Container();
|
|
||||||
tradeButton.setPreferredSize(new Vector3f(200, 60, 0));
|
|
||||||
tradeButton.setFontSize(30);
|
|
||||||
tradeButton.addClickCommands(s -> ifTopDialog(() -> {
|
|
||||||
app.getGameLogic().playSound(Sound.BUTTON);
|
|
||||||
close();
|
|
||||||
new TradeMenu(app).open();
|
|
||||||
}));
|
|
||||||
lowerRightMenu.addChild(tradeButton);
|
|
||||||
|
|
||||||
// Position the container near the bottom-right corner
|
|
||||||
lowerRightMenu.setLocalTranslation(new Vector3f(app.getCamera().getWidth() - 680, 100, 8)); // X: 220px from the right, Y: 50px above the bottom
|
|
||||||
app.getGuiNode().attachChild(lowerRightMenu);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Label spacer = middleSection.addChild(new Label("")); // Spacer
|
|
||||||
spacer.setPreferredSize(new Vector3f(1, 50, 0));
|
|
||||||
|
|
||||||
return mainContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a column for trade objects (left or right side).
|
|
||||||
*
|
|
||||||
* @param label The label for the column.
|
|
||||||
* @param isLeft Whether this column is the left side.
|
|
||||||
* @return The column container.
|
|
||||||
*/
|
|
||||||
private Container createTradeColumn(String label, boolean isLeft) {
|
|
||||||
Container column = new Container(new SpringGridLayout(Axis.Y, Axis.X));
|
|
||||||
column.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.White)));
|
|
||||||
|
|
||||||
Label columnLabel = column.addChild(new Label(label));
|
|
||||||
columnLabel.setFontSize(24);
|
|
||||||
columnLabel.setBackground(translucentWhiteBackground);
|
|
||||||
|
|
||||||
// Add dropdowns
|
|
||||||
column.addChild(new Label("Gebäude:"));
|
|
||||||
Selector<String> buildingSelector = column.addChild(new Selector<>(getSampleItems(),"glass"));
|
|
||||||
buildingSelector.setInsets(new Insets3f(5, 10, 5, 10));
|
|
||||||
buildingSelector.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black)));
|
|
||||||
|
|
||||||
column.addChild(new Label("Währung:"));
|
|
||||||
TextField currencyInput = column.addChild(new TextField(""));
|
|
||||||
currencyInput.setInsets(new Insets3f(5, 10, 5, 10));
|
|
||||||
currencyInput.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black)));
|
|
||||||
|
|
||||||
column.addChild(new Label("Sonderkarten:"));
|
|
||||||
Selector<String> specialCardSelector = column.addChild(new Selector<>(getSampleItems(),"glass"));
|
|
||||||
specialCardSelector.setInsets(new Insets3f(5, 10, 5, 10));
|
|
||||||
specialCardSelector.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black)));
|
|
||||||
|
|
||||||
|
|
||||||
// Assign selectors to corresponding fields
|
|
||||||
if (isLeft) {
|
|
||||||
leftBuildingSelector = buildingSelector;
|
|
||||||
leftSpecialCardSelector = specialCardSelector;
|
|
||||||
leftCurrencyInput = currencyInput;
|
|
||||||
|
|
||||||
// "Abbrechen" button
|
|
||||||
lowerLeftMenu = new Container();
|
|
||||||
cancelButton.setPreferredSize(new Vector3f(200, 60, 0));
|
|
||||||
cancelButton.setFontSize(30);
|
|
||||||
cancelButton.addClickCommands(s -> ifTopDialog(() -> {
|
|
||||||
app.getGameLogic().playSound(Sound.BUTTON);
|
|
||||||
this.close();
|
|
||||||
}));
|
|
||||||
lowerLeftMenu.addChild(cancelButton);
|
|
||||||
|
|
||||||
// Position the container near the bottom-left corner
|
|
||||||
lowerLeftMenu.setLocalTranslation(new Vector3f(50, 100, 8)); // Adjust X and Y to align with the bottom-left corner
|
|
||||||
app.getGuiNode().attachChild(lowerLeftMenu);
|
|
||||||
|
|
||||||
Label spacer = column.addChild(new Label("")); // Spacer
|
|
||||||
spacer.setPreferredSize(new Vector3f(1, 130, 0));
|
|
||||||
|
|
||||||
} else {
|
|
||||||
rightBuildingSelector = buildingSelector;
|
|
||||||
rightSpecialCardSelector = specialCardSelector;
|
|
||||||
rightCurrencyInput = currencyInput;
|
|
||||||
|
|
||||||
Label spacer = column.addChild(new Label("")); // Spacer
|
|
||||||
spacer.setPreferredSize(new Vector3f(1, 130, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
return column;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides sample dropdown items.
|
|
||||||
*/
|
|
||||||
private VersionedList<String> getSampleItems() {
|
|
||||||
VersionedList<String> items = new VersionedList<>();
|
|
||||||
items.add("Option 1");
|
|
||||||
items.add("Option 2");
|
|
||||||
items.add("Option 3");
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a background image to the dialog.
|
|
||||||
*/
|
|
||||||
private void addBackgroundImage() {
|
|
||||||
Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/unibw-Bib2.png");
|
|
||||||
Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight());
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String truncateText(String text, int maxLength) {
|
|
||||||
return text.length() > maxLength ? text.substring(0, maxLength) + "..." : text;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateSelectionsField(TextField selectionsField, Selector<String> buildingSelector, TextField currencyInput, Selector<String> specialCardSelector) {
|
|
||||||
// Get selections from the building selector
|
|
||||||
String buildingSelections = buildingSelector != null && buildingSelector.getSelectedItem() != null
|
|
||||||
? buildingSelector.getSelectedItem().trim()
|
|
||||||
: "";
|
|
||||||
|
|
||||||
// Get text from the currency input
|
|
||||||
String currencySelections = currencyInput != null
|
|
||||||
? currencyInput.getText().trim()
|
|
||||||
: "";
|
|
||||||
|
|
||||||
// Get selections from the special card selector
|
|
||||||
String specialCardSelections = specialCardSelector != null && specialCardSelector.getSelectedItem() != null
|
|
||||||
? specialCardSelector.getSelectedItem().trim()
|
|
||||||
: "";
|
|
||||||
// Build the combined text without adding unnecessary spaces
|
|
||||||
StringBuilder combinedText = new StringBuilder();
|
|
||||||
|
|
||||||
if (!buildingSelections.isEmpty()) {
|
|
||||||
combinedText.append(buildingSelections);
|
|
||||||
}
|
|
||||||
if (!currencySelections.isEmpty()) {
|
|
||||||
if (combinedText.length() > 0) {
|
|
||||||
combinedText.append(" | "); // Add a separator if there's already text
|
|
||||||
}
|
|
||||||
combinedText.append(currencySelections);
|
|
||||||
}
|
|
||||||
if (!specialCardSelections.isEmpty()) {
|
|
||||||
if (combinedText.length() > 0) {
|
|
||||||
combinedText.append(" | "); // Add a separator if there's already text
|
|
||||||
}
|
|
||||||
combinedText.append(specialCardSelections);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the content of the TextField
|
|
||||||
selectionsField.setText(combinedText.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles the escape action for the dialog.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void escape() {
|
|
||||||
new SettingsMenu(app).open();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the dialog periodically, called by the dialog manager.
|
|
||||||
*
|
|
||||||
* @param delta The time elapsed since the last update.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void update(float delta) {
|
|
||||||
// Periodic updates (if needed) can be implemented here
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Functional interface for a selection action listener.
|
|
||||||
*/
|
|
||||||
@FunctionalInterface
|
|
||||||
private interface SelectionActionListener<T> {
|
|
||||||
void onSelectionChanged(T selection);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Adds a custom action listener to the Selector.
|
|
||||||
*/
|
|
||||||
private void addCustomSelectionListener(Selector<String> selector, SelectionActionListener<String> listener) {
|
|
||||||
VersionedReference<Set<Integer>> selectionRef = selector.getSelectionModel().createReference();
|
|
||||||
|
|
||||||
app.getStateManager().attach(new BaseAppState() {
|
|
||||||
@Override
|
|
||||||
public void update(float tpf) {
|
|
||||||
if (selectionRef.update()) {
|
|
||||||
String selected = selector.getSelectedItem();
|
|
||||||
listener.onSelectionChanged(selected);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void initialize(Application app) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void cleanup(Application app) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onEnable() {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDisable() {}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void monitorTextFieldChanges(TextField textField, Runnable onChange) {
|
|
||||||
VersionedReference<DocumentModel> ref = textField.getDocumentModel().createReference();
|
|
||||||
|
|
||||||
app.getStateManager().attach(new BaseAppState() {
|
|
||||||
@Override
|
|
||||||
public void update(float tpf) {
|
|
||||||
if (ref.update()) {
|
|
||||||
onChange.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void initialize(Application app) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void cleanup(Application app) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onEnable() {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDisable() {}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,504 +0,0 @@
|
|||||||
/*
|
|
||||||
* $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
@@ -1,135 +0,0 @@
|
|||||||
/*
|
|
||||||
* $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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@@ -1,6 +1,10 @@
|
|||||||
package pp.monopoly.client.gui.popups;
|
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.ColorRGBA;
|
||||||
|
import com.jme3.scene.Geometry;
|
||||||
|
import com.jme3.scene.shape.Quad;
|
||||||
import com.simsilica.lemur.Button;
|
import com.simsilica.lemur.Button;
|
||||||
import com.simsilica.lemur.Container;
|
import com.simsilica.lemur.Container;
|
||||||
import com.simsilica.lemur.Label;
|
import com.simsilica.lemur.Label;
|
||||||
@@ -9,40 +13,43 @@ import com.simsilica.lemur.style.ElementId;
|
|||||||
import pp.dialog.Dialog;
|
import pp.dialog.Dialog;
|
||||||
import pp.monopoly.client.MonopolyApp;
|
import pp.monopoly.client.MonopolyApp;
|
||||||
import pp.monopoly.client.gui.SettingsMenu;
|
import pp.monopoly.client.gui.SettingsMenu;
|
||||||
import pp.monopoly.message.client.BuyPropertyRequest;
|
|
||||||
import pp.monopoly.model.fields.BoardManager;
|
import pp.monopoly.model.fields.BoardManager;
|
||||||
import pp.monopoly.model.fields.BuildingProperty;
|
import pp.monopoly.model.fields.BuildingProperty;
|
||||||
import pp.monopoly.notification.Sound;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SettingsMenu ist ein Overlay-Menü, das durch ESC aufgerufen werden kann.
|
* SettingsMenu ist ein Overlay-Menü, das durch ESC aufgerufen werden kann.
|
||||||
*/
|
*/
|
||||||
public class BuyCard extends Dialog {
|
public class BuyCard extends Dialog {
|
||||||
private final MonopolyApp app;
|
private final MonopolyApp app;
|
||||||
|
private final Geometry overlayBackground;
|
||||||
private final Container buyCardContainer;
|
private final Container buyCardContainer;
|
||||||
private final Container backgroundContainer;
|
private final Container backgroundContainer;
|
||||||
|
|
||||||
|
private int index = 37;
|
||||||
|
|
||||||
public BuyCard(MonopolyApp app) {
|
public BuyCard(MonopolyApp app) {
|
||||||
super(app.getDialogManager());
|
super(app.getDialogManager());
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
|
||||||
//Generate the corresponfing field
|
//Generate the corresponfing field
|
||||||
int index = app.getGameLogic().getPlayerHandler().getPlayers().get(0).getFieldID();
|
|
||||||
BuildingProperty field = (BuildingProperty) new BoardManager().getFieldAtIndex(index);
|
BuildingProperty field = (BuildingProperty) new BoardManager().getFieldAtIndex(index);
|
||||||
|
|
||||||
|
// Halbtransparentes Overlay hinzufügen
|
||||||
|
overlayBackground = createOverlayBackground();
|
||||||
|
app.getGuiNode().attachChild(overlayBackground);
|
||||||
|
|
||||||
// Create the background container
|
// Create the background container
|
||||||
backgroundContainer = new Container();
|
backgroundContainer = new Container();
|
||||||
backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background
|
backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background
|
||||||
attachChild(backgroundContainer);
|
app.getGuiNode().attachChild(backgroundContainer);
|
||||||
|
|
||||||
// Hauptcontainer für die Gebäudekarte
|
// Hauptcontainer für die Gebäudekarte
|
||||||
buyCardContainer = new Container();
|
buyCardContainer = new Container();
|
||||||
|
buyCardContainer.setBackground(new QuadBackgroundComponent(field.getColor().getColor()));
|
||||||
|
|
||||||
Label title = buyCardContainer.addChild(new Label( field.getName(), new ElementId("label-Bold")));
|
|
||||||
title.setBackground(new QuadBackgroundComponent(field.getColor().getColor()));
|
Label settingsTitle = buyCardContainer.addChild(new Label( field.getName(), new ElementId("settings-title")));
|
||||||
title.setFontSize(48);
|
settingsTitle.setFontSize(48);
|
||||||
|
|
||||||
// Text, der auf der Karte steht
|
// Text, der auf der Karte steht
|
||||||
// Die Preise werden dynamisch dem BoardManager entnommen
|
// Die Preise werden dynamisch dem BoardManager entnommen
|
||||||
@@ -63,17 +70,9 @@ public class BuyCard extends Dialog {
|
|||||||
// Beenden-Button
|
// Beenden-Button
|
||||||
Button quitButton = buyCardContainer.addChild(new Button("Beenden", new ElementId("button")));
|
Button quitButton = buyCardContainer.addChild(new Button("Beenden", new ElementId("button")));
|
||||||
quitButton.setFontSize(32);
|
quitButton.setFontSize(32);
|
||||||
quitButton.addClickCommands(s -> ifTopDialog(() -> {
|
|
||||||
app.getGameLogic().playSound(Sound.BUTTON);
|
|
||||||
close();
|
|
||||||
}));
|
|
||||||
// Kaufen-Button
|
// Kaufen-Button
|
||||||
Button buyButton = buyCardContainer.addChild(new Button("Kaufen", new ElementId("button")));
|
Button buyButton = buyCardContainer.addChild(new Button("Kaufen", new ElementId("button")));
|
||||||
buyButton.setFontSize(32);
|
buyButton.setFontSize(32);
|
||||||
buyButton.addClickCommands(s -> ifTopDialog( () -> {
|
|
||||||
app.getGameLogic().playSound(Sound.BUTTON);
|
|
||||||
app.getGameLogic().send(new BuyPropertyRequest());
|
|
||||||
}));
|
|
||||||
|
|
||||||
float padding = 10; // Padding around the settingsContainer for the background
|
float padding = 10; // Padding around the settingsContainer for the background
|
||||||
backgroundContainer.setPreferredSize(buyCardContainer.getPreferredSize().addLocal(padding, padding, 0));
|
backgroundContainer.setPreferredSize(buyCardContainer.getPreferredSize().addLocal(padding, padding, 0));
|
||||||
@@ -95,6 +94,22 @@ public class BuyCard extends Dialog {
|
|||||||
app.getGuiNode().attachChild(buyCardContainer);
|
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.
|
* Schließt das Menü und entfernt die GUI-Elemente.
|
||||||
*/
|
*/
|
||||||
@@ -102,6 +117,7 @@ public class BuyCard extends Dialog {
|
|||||||
public void close() {
|
public void close() {
|
||||||
app.getGuiNode().detachChild(buyCardContainer); // Entferne das Menü
|
app.getGuiNode().detachChild(buyCardContainer); // Entferne das Menü
|
||||||
app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand
|
app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand
|
||||||
|
app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay
|
||||||
super.close();
|
super.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -14,6 +14,8 @@ import com.simsilica.lemur.style.ElementId;
|
|||||||
import pp.dialog.Dialog;
|
import pp.dialog.Dialog;
|
||||||
import pp.monopoly.client.MonopolyApp;
|
import pp.monopoly.client.MonopolyApp;
|
||||||
import pp.monopoly.client.gui.SettingsMenu;
|
import pp.monopoly.client.gui.SettingsMenu;
|
||||||
|
import pp.monopoly.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.
|
* SettingsMenu ist ein Overlay-Menü, das durch ESC aufgerufen werden kann.
|
||||||
*/
|
*/
|
||||||
@@ -22,13 +24,14 @@ public class EventCard extends Dialog {
|
|||||||
private final Geometry overlayBackground;
|
private final Geometry overlayBackground;
|
||||||
private final Container eventCardContainer;
|
private final Container eventCardContainer;
|
||||||
private final Container backgroundContainer;
|
private final Container backgroundContainer;
|
||||||
private final String description;
|
|
||||||
|
|
||||||
|
|
||||||
public EventCard(MonopolyApp app, String description) {
|
public EventCard(MonopolyApp app) {
|
||||||
super(app.getDialogManager());
|
super(app.getDialogManager());
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.description = description;
|
|
||||||
|
//Generate the corresponfing field
|
||||||
|
Card card = new DeckHelper().drawCard(); // TODO nimmt die Karten gerade unabhängig aus dem DeckHelper
|
||||||
|
|
||||||
// Halbtransparentes Overlay hinzufügen
|
// Halbtransparentes Overlay hinzufügen
|
||||||
overlayBackground = createOverlayBackground();
|
overlayBackground = createOverlayBackground();
|
||||||
@@ -53,7 +56,7 @@ public class EventCard extends Dialog {
|
|||||||
// Text, der auf der Karte steht
|
// Text, der auf der Karte steht
|
||||||
// Die Preise werden dynamisch dem BoardManager entnommen
|
// Die Preise werden dynamisch dem BoardManager entnommen
|
||||||
Container propertyValuesContainer = eventCardContainer.addChild(new Container());
|
Container propertyValuesContainer = eventCardContainer.addChild(new Container());
|
||||||
propertyValuesContainer.addChild(new Label(description, new ElementId("label-Text")));
|
propertyValuesContainer.addChild(new Label(card.getDescription(), new ElementId("label-Text")));
|
||||||
propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||||
propertyValuesContainer.setPreferredSize(new Vector3f(300,200,10));
|
propertyValuesContainer.setPreferredSize(new Vector3f(300,200,10));
|
||||||
|
|
||||||
@@ -62,6 +65,11 @@ public class EventCard extends Dialog {
|
|||||||
quitButton.setFontSize(32);
|
quitButton.setFontSize(32);
|
||||||
quitButton.addClickCommands(source -> close());
|
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
|
float padding = 10; // Padding around the settingsContainer for the background
|
||||||
backgroundContainer.setPreferredSize(eventCardContainer.getPreferredSize().addLocal(padding, padding, 0));
|
backgroundContainer.setPreferredSize(eventCardContainer.getPreferredSize().addLocal(padding, padding, 0));
|
||||||
|
|
||||||
@@ -111,6 +119,6 @@ public class EventCard extends Dialog {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void escape() {
|
public void escape() {
|
||||||
close();
|
new SettingsMenu(app).open();
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -5,7 +5,6 @@ import com.jme3.material.RenderState.BlendMode;
|
|||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
import com.jme3.scene.Geometry;
|
import com.jme3.scene.Geometry;
|
||||||
import com.jme3.scene.shape.Quad;
|
import com.jme3.scene.shape.Quad;
|
||||||
import com.simsilica.lemur.Button;
|
|
||||||
import com.simsilica.lemur.Container;
|
import com.simsilica.lemur.Container;
|
||||||
import com.simsilica.lemur.Label;
|
import com.simsilica.lemur.Label;
|
||||||
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
||||||
@@ -14,9 +13,7 @@ import com.simsilica.lemur.style.ElementId;
|
|||||||
import pp.dialog.Dialog;
|
import pp.dialog.Dialog;
|
||||||
import pp.monopoly.client.MonopolyApp;
|
import pp.monopoly.client.MonopolyApp;
|
||||||
import pp.monopoly.client.gui.SettingsMenu;
|
import pp.monopoly.client.gui.SettingsMenu;
|
||||||
import pp.monopoly.message.client.BuyPropertyRequest;
|
|
||||||
import pp.monopoly.model.fields.FoodField;
|
import pp.monopoly.model.fields.FoodField;
|
||||||
import pp.monopoly.notification.Sound;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FoodFieldCard erstellt die Geböudekarte vom Brandl und der Truppenküche
|
* FoodFieldCard erstellt die Geböudekarte vom Brandl und der Truppenküche
|
||||||
@@ -26,13 +23,13 @@ public class FoodFieldCard extends Dialog {
|
|||||||
private final Geometry overlayBackground;
|
private final Geometry overlayBackground;
|
||||||
private final Container foodFieldContainer;
|
private final Container foodFieldContainer;
|
||||||
private final Container backgroundContainer;
|
private final Container backgroundContainer;
|
||||||
|
private int index = 12;
|
||||||
|
|
||||||
public FoodFieldCard(MonopolyApp app) {
|
public FoodFieldCard(MonopolyApp app) {
|
||||||
super(app.getDialogManager());
|
super(app.getDialogManager());
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
|
||||||
//Generate the corresponfing field
|
//Generate the corresponfing field
|
||||||
int index = app.getGameLogic().getPlayerHandler().getPlayers().get(0).getFieldID();
|
|
||||||
FoodField field = (FoodField) app.getGameLogic().getBoardManager().getFieldAtIndex(index);
|
FoodField field = (FoodField) app.getGameLogic().getBoardManager().getFieldAtIndex(index);
|
||||||
|
|
||||||
// Halbtransparentes Overlay hinzufügen
|
// Halbtransparentes Overlay hinzufügen
|
||||||
@@ -71,24 +68,22 @@ public class FoodFieldCard extends Dialog {
|
|||||||
propertyValuesContainer.addChild(new Label("„Hypothek: " + field.getHypo() + " EUR", new ElementId("label-Text")));
|
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)));
|
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
|
// Beenden-Button
|
||||||
Button quitButton = foodFieldContainer.addChild(new Button("Beenden", new ElementId("button")));
|
Button quitButton = foodFieldContainer.addChild(new Button("Beenden", new ElementId("button")));
|
||||||
quitButton.setFontSize(32);
|
quitButton.setFontSize(32);
|
||||||
quitButton.addClickCommands(s -> ifTopDialog(() -> {
|
|
||||||
app.getGameLogic().playSound(Sound.BUTTON);
|
|
||||||
close();
|
|
||||||
}));
|
|
||||||
// Kaufen-Button
|
// Kaufen-Button
|
||||||
Button buyButton = foodFieldContainer.addChild(new Button("Kaufen", new ElementId("button")));
|
Button buyButton = foodFieldContainer.addChild(new Button("Kaufen", new ElementId("button")));
|
||||||
buyButton.setFontSize(32);
|
buyButton.setFontSize(32);
|
||||||
buyButton.addClickCommands(s -> ifTopDialog( () -> {
|
*/
|
||||||
app.getGameLogic().playSound(Sound.BUTTON);
|
|
||||||
app.getGameLogic().send(new BuyPropertyRequest());
|
|
||||||
}));
|
|
||||||
|
|
||||||
float padding = 10; // Padding around the settingsContainer for the background
|
float padding = 10; // Padding around the settingsContainer for the background
|
||||||
backgroundContainer.setPreferredSize(foodFieldContainer.getPreferredSize().addLocal(padding, padding, 0));
|
backgroundContainer.setPreferredSize(foodFieldContainer.getPreferredSize().addLocal(padding, padding, 0));
|
||||||
|
|
||||||
|
|
||||||
// Zentriere das Menü
|
// Zentriere das Menü
|
||||||
foodFieldContainer.setLocalTranslation(
|
foodFieldContainer.setLocalTranslation(
|
||||||
(app.getCamera().getWidth() - foodFieldContainer.getPreferredSize().x) / 2,
|
(app.getCamera().getWidth() - foodFieldContainer.getPreferredSize().x) / 2,
|
||||||
@@ -132,6 +127,10 @@ public class FoodFieldCard extends Dialog {
|
|||||||
super.close();
|
super.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setIndex(int index) {
|
||||||
|
this.index = index;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void escape() {
|
public void escape() {
|
||||||
new SettingsMenu(app).open();
|
new SettingsMenu(app).open();
|
||||||
|
@@ -5,7 +5,6 @@ import com.jme3.material.RenderState.BlendMode;
|
|||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
import com.jme3.scene.Geometry;
|
import com.jme3.scene.Geometry;
|
||||||
import com.jme3.scene.shape.Quad;
|
import com.jme3.scene.shape.Quad;
|
||||||
import com.simsilica.lemur.Button;
|
|
||||||
import com.simsilica.lemur.Container;
|
import com.simsilica.lemur.Container;
|
||||||
import com.simsilica.lemur.Label;
|
import com.simsilica.lemur.Label;
|
||||||
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
||||||
@@ -13,9 +12,7 @@ import com.simsilica.lemur.style.ElementId;
|
|||||||
import pp.dialog.Dialog;
|
import pp.dialog.Dialog;
|
||||||
import pp.monopoly.client.MonopolyApp;
|
import pp.monopoly.client.MonopolyApp;
|
||||||
import pp.monopoly.client.gui.SettingsMenu;
|
import pp.monopoly.client.gui.SettingsMenu;
|
||||||
import pp.monopoly.message.client.BuyPropertyRequest;
|
|
||||||
import pp.monopoly.model.fields.GateField;
|
import pp.monopoly.model.fields.GateField;
|
||||||
import pp.monopoly.notification.Sound;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SettingsMenu ist ein Overlay-Menü, das durch ESC aufgerufen werden kann.
|
* SettingsMenu ist ein Overlay-Menü, das durch ESC aufgerufen werden kann.
|
||||||
@@ -25,13 +22,13 @@ public class GateFieldCard extends Dialog {
|
|||||||
private final Geometry overlayBackground;
|
private final Geometry overlayBackground;
|
||||||
private final Container gateFieldContainer;
|
private final Container gateFieldContainer;
|
||||||
private final Container backgroundContainer;
|
private final Container backgroundContainer;
|
||||||
|
private int index = 5;
|
||||||
|
|
||||||
public GateFieldCard(MonopolyApp app) {
|
public GateFieldCard(MonopolyApp app) {
|
||||||
super(app.getDialogManager());
|
super(app.getDialogManager());
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
|
||||||
//Generate the corresponfing field
|
//Generate the corresponfing field
|
||||||
int index = app.getGameLogic().getPlayerHandler().getPlayers().get(0).getFieldID();
|
|
||||||
GateField field = (GateField) app.getGameLogic().getBoardManager().getFieldAtIndex(index);
|
GateField field = (GateField) app.getGameLogic().getBoardManager().getFieldAtIndex(index);
|
||||||
|
|
||||||
// Halbtransparentes Overlay hinzufügen
|
// Halbtransparentes Overlay hinzufügen
|
||||||
@@ -66,21 +63,16 @@ public class GateFieldCard extends Dialog {
|
|||||||
propertyValuesContainer.addChild(new Label("„Hypothek: " + field.getHypo() + " EUR", new ElementId("label-Text")));
|
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)));
|
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
|
// Beenden-Button
|
||||||
Button quitButton = gateFieldContainer.addChild(new Button("Beenden", new ElementId("button")));
|
Button quitButton = foodFieldContainer.addChild(new Button("Beenden", new ElementId("button")));
|
||||||
quitButton.setFontSize(32);
|
quitButton.setFontSize(32);
|
||||||
quitButton.addClickCommands(s -> ifTopDialog(() -> {
|
|
||||||
app.getGameLogic().playSound(Sound.BUTTON);
|
|
||||||
close();
|
|
||||||
}));
|
|
||||||
// Kaufen-Button
|
// Kaufen-Button
|
||||||
Button buyButton = gateFieldContainer.addChild(new Button("Kaufen", new ElementId("button")));
|
Button buyButton = foodFieldContainer.addChild(new Button("Kaufen", new ElementId("button")));
|
||||||
buyButton.setFontSize(32);
|
buyButton.setFontSize(32);
|
||||||
buyButton.addClickCommands(s -> ifTopDialog(() -> {
|
*/
|
||||||
app.getGameLogic().playSound(Sound.BUTTON);
|
|
||||||
app.getGameLogic().send(new BuyPropertyRequest());
|
|
||||||
close();
|
|
||||||
}));
|
|
||||||
|
|
||||||
float padding = 10; // Padding around the settingsContainer for the background
|
float padding = 10; // Padding around the settingsContainer for the background
|
||||||
backgroundContainer.setPreferredSize(gateFieldContainer.getPreferredSize().addLocal(padding, padding, 0));
|
backgroundContainer.setPreferredSize(gateFieldContainer.getPreferredSize().addLocal(padding, padding, 0));
|
||||||
@@ -129,6 +121,10 @@ public class GateFieldCard extends Dialog {
|
|||||||
super.close();
|
super.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setIndex(int index) {
|
||||||
|
this.index = index;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void escape() {
|
public void escape() {
|
||||||
new SettingsMenu(app).open();
|
new SettingsMenu(app).open();
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 169 KiB |
Binary file not shown.
Before Width: | Height: | Size: 171 KiB |
Binary file not shown.
Before Width: | Height: | Size: 183 KiB |
Binary file not shown.
Before Width: | Height: | Size: 207 KiB |
Binary file not shown.
Before Width: | Height: | Size: 105 KiB |
Binary file not shown.
Before 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.
|
* The width of the game map in terms of grid units.
|
||||||
*/
|
*/
|
||||||
@Property("map.width")
|
@Property("map.width")
|
||||||
private int mapWidth = 10;
|
private int mapWidth = 12;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The height of the game map in terms of grid units.
|
* The height of the game map in terms of grid units.
|
||||||
*/
|
*/
|
||||||
@Property("map.height")
|
@Property("map.height")
|
||||||
private int mapHeight = 10;
|
private int mapHeight = 12;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance of {@code MonopolyConfig} with default settings.
|
* Creates an instance of {@code MonopolyConfig} with default settings.
|
||||||
|
@@ -6,7 +6,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import pp.monopoly.game.server.Player;
|
import pp.monopoly.game.server.Player;
|
||||||
import pp.monopoly.game.server.PlayerHandler;
|
|
||||||
import pp.monopoly.message.client.ClientMessage;
|
import pp.monopoly.message.client.ClientMessage;
|
||||||
import pp.monopoly.message.server.BuyPropertyResponse;
|
import pp.monopoly.message.server.BuyPropertyResponse;
|
||||||
import pp.monopoly.message.server.DiceResult;
|
import pp.monopoly.message.server.DiceResult;
|
||||||
@@ -25,15 +24,12 @@ import pp.monopoly.model.Board;
|
|||||||
import pp.monopoly.model.IntPoint;
|
import pp.monopoly.model.IntPoint;
|
||||||
import pp.monopoly.model.fields.BoardManager;
|
import pp.monopoly.model.fields.BoardManager;
|
||||||
import pp.monopoly.notification.ClientStateEvent;
|
import pp.monopoly.notification.ClientStateEvent;
|
||||||
import pp.monopoly.notification.DiceRollEvent;
|
|
||||||
import pp.monopoly.notification.EventCardEvent;
|
|
||||||
import pp.monopoly.notification.GameEvent;
|
import pp.monopoly.notification.GameEvent;
|
||||||
import pp.monopoly.notification.GameEventBroker;
|
import pp.monopoly.notification.GameEventBroker;
|
||||||
import pp.monopoly.notification.GameEventListener;
|
import pp.monopoly.notification.GameEventListener;
|
||||||
import pp.monopoly.notification.InfoTextEvent;
|
import pp.monopoly.notification.InfoTextEvent;
|
||||||
import pp.monopoly.notification.Sound;
|
import pp.monopoly.notification.Sound;
|
||||||
import pp.monopoly.notification.SoundEvent;
|
import pp.monopoly.notification.SoundEvent;
|
||||||
import pp.monopoly.notification.UpdatePlayerView;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controls the client-side game logic for Monopoly.
|
* Controls the client-side game logic for Monopoly.
|
||||||
@@ -56,7 +52,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
/** The current state of the client game logic. */
|
/** The current state of the client game logic. */
|
||||||
private ClientState state = new LobbyState(this);
|
private ClientState state = new LobbyState(this);
|
||||||
|
|
||||||
private PlayerHandler playerHandler;
|
private List<Player> players;
|
||||||
|
|
||||||
private BoardManager boardManager = new BoardManager();
|
private BoardManager boardManager = new BoardManager();
|
||||||
|
|
||||||
@@ -98,8 +94,8 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
state.entry();
|
state.entry();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerHandler getPlayerHandler() {
|
public List<Player> getPlayers() {
|
||||||
return playerHandler;
|
return players;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -148,6 +144,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
LOGGER.log(Level.ERROR, "trying to send {0} with sender==null", msg); //NON-NLS
|
LOGGER.log(Level.ERROR, "trying to send {0} with sender==null", msg); //NON-NLS
|
||||||
} else {
|
} else {
|
||||||
clientSender.send(msg);
|
clientSender.send(msg);
|
||||||
|
System.out.println("Message gesendet");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,10 +199,10 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
@Override
|
@Override
|
||||||
public void received(BuyPropertyResponse msg) {
|
public void received(BuyPropertyResponse msg) {
|
||||||
if (msg.isSuccessful()) {
|
if (msg.isSuccessful()) {
|
||||||
|
setInfoText("You successfully bought " + msg.getPropertyName() + "!");
|
||||||
playSound(Sound.MONEY_LOST);
|
playSound(Sound.MONEY_LOST);
|
||||||
} else {
|
} else {
|
||||||
|
setInfoText("Unable to buy " + msg.getPropertyName() + ". Reason: " + msg.getReason());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,8 +213,9 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void received(DiceResult msg) {
|
public void received(DiceResult msg) {
|
||||||
|
setInfoText("You rolled a " + msg.calcTotal() + "!");
|
||||||
|
//Set the dice images
|
||||||
playSound(Sound.DICE_ROLL);
|
playSound(Sound.DICE_ROLL);
|
||||||
notifyListeners(new DiceRollEvent(msg.getRollResult().get(0), msg.getRollResult().get(1)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -227,8 +225,9 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void received(EventDrawCard msg) {
|
public void received(EventDrawCard msg) {
|
||||||
|
setInfoText("Event card drawn: " + msg.getCardDescription());
|
||||||
|
// Kartenlogik
|
||||||
playSound(Sound.EVENT_CARD);
|
playSound(Sound.EVENT_CARD);
|
||||||
notifyListeners(new EventCardEvent(msg.getCardDescription()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -239,11 +238,11 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
@Override
|
@Override
|
||||||
public void received(GameOver msg) {
|
public void received(GameOver msg) {
|
||||||
if (msg.isWinner()) {
|
if (msg.isWinner()) {
|
||||||
|
setInfoText("Congratulations! You have won the game!");
|
||||||
//Winner popup
|
//Winner popup
|
||||||
playSound(Sound.WINNER);
|
playSound(Sound.WINNER);
|
||||||
} else {
|
} else {
|
||||||
|
setInfoText("Game over. Better luck next time!");
|
||||||
// Looser popup
|
// Looser popup
|
||||||
playSound(Sound.LOSER);
|
playSound(Sound.LOSER);
|
||||||
}
|
}
|
||||||
@@ -256,9 +255,9 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void received(GameStart msg) {
|
public void received(GameStart msg) {
|
||||||
playerHandler = msg.getPlayerHandler();
|
players = msg.getPlayers();
|
||||||
|
setInfoText("The game has started! Good luck!");
|
||||||
setState(new WaitForTurnState(this));
|
setState(new WaitForTurnState(this));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -269,10 +268,10 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
@Override
|
@Override
|
||||||
public void received(JailEvent msg) {
|
public void received(JailEvent msg) {
|
||||||
if (msg.isGoingToJail()) {
|
if (msg.isGoingToJail()) {
|
||||||
|
setInfoText("You are sent to jail!");
|
||||||
playSound(Sound.GULAG);
|
playSound(Sound.GULAG);
|
||||||
} else {
|
} else {
|
||||||
|
setInfoText("You are out of jail!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,8 +282,8 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void received(PlayerStatusUpdate msg) {
|
public void received(PlayerStatusUpdate msg) {
|
||||||
playerHandler = msg.getPlayerHandler();
|
|
||||||
notifyListeners(new UpdatePlayerView());
|
setInfoText("Player " + msg.getPlayerName() + " status updated: " + msg.getStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -294,7 +293,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void received(TimeOutWarning msg) {
|
public void received(TimeOutWarning msg) {
|
||||||
|
setInfoText("Warning! Time is running out. You have " + msg.getRemainingTime() + " seconds left.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -304,7 +303,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void received(ViewAssetsResponse msg) {
|
public void received(ViewAssetsResponse msg) {
|
||||||
|
setInfoText("Your current assets are being displayed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -315,10 +314,10 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
@Override
|
@Override
|
||||||
public void received(TradeReply msg) {
|
public void received(TradeReply msg) {
|
||||||
if (msg.getTradeHandler().getStatus()) {
|
if (msg.getTradeHandler().getStatus()) {
|
||||||
|
setInfoText("Trade accepted by " + msg.getTradeHandler().getReceiver().getName() + ".");
|
||||||
playSound(Sound.TRADE_ACCEPTED);
|
playSound(Sound.TRADE_ACCEPTED);
|
||||||
} else {
|
} else {
|
||||||
|
setInfoText("Trade rejected by " + msg.getTradeHandler().getReceiver().getName() + ".");
|
||||||
playSound(Sound.TRADE_REJECTED);
|
playSound(Sound.TRADE_REJECTED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -330,7 +329,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void received(TradeRequest msg) {
|
public void received(TradeRequest msg) {
|
||||||
|
setInfoText("Trade offer received from " + msg.getTradeHandler().getSender().getName());
|
||||||
// playSound(Sound.TRADE_REQUEST); no sound effect
|
// playSound(Sound.TRADE_REQUEST); no sound effect
|
||||||
// notifyListeners();
|
// notifyListeners();
|
||||||
}
|
}
|
||||||
@@ -342,7 +341,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void received(NextPlayerTurn msg) {
|
public void received(NextPlayerTurn msg) {
|
||||||
|
setInfoText("It's your turn!");
|
||||||
setState(new ActiveState(this));
|
setState(new ActiveState(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,15 +7,12 @@
|
|||||||
|
|
||||||
package pp.monopoly.game.server;
|
package pp.monopoly.game.server;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
import com.jme3.network.serializing.Serializable;
|
||||||
|
|
||||||
import pp.monopoly.message.server.DiceResult;
|
import pp.monopoly.message.server.DiceResult;
|
||||||
import pp.monopoly.message.server.EventDrawCard;
|
|
||||||
import pp.monopoly.message.server.PlayerStatusUpdate;
|
|
||||||
import pp.monopoly.model.FieldVisitor;
|
import pp.monopoly.model.FieldVisitor;
|
||||||
import pp.monopoly.model.Figure;
|
import pp.monopoly.model.Figure;
|
||||||
import pp.monopoly.model.card.Card;
|
import pp.monopoly.model.card.Card;
|
||||||
@@ -39,12 +36,12 @@ public class Player implements FieldVisitor<Void>{
|
|||||||
private String name;
|
private String name;
|
||||||
private int accountBalance = 15000;
|
private int accountBalance = 15000;
|
||||||
private Figure figure;
|
private Figure figure;
|
||||||
private List<PropertyField> properties = new ArrayList<>();
|
private List<PropertyField> properties;
|
||||||
private int getOutOfJailCard;
|
private int getOutOfJailCard;
|
||||||
private int fieldID;
|
private int fieldID;
|
||||||
private DiceResult rollResult;
|
private DiceResult rollResult;
|
||||||
private transient final PlayerHandler handler;
|
private final PlayerHandler handler;
|
||||||
private transient PlayerState state = new LobbyState();
|
private PlayerState state = new LobbyState();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor for serialization purposes.
|
* Default constructor for serialization purposes.
|
||||||
@@ -82,12 +79,12 @@ public class Player implements FieldVisitor<Void>{
|
|||||||
|
|
||||||
public PlayerColor getColor() {
|
public PlayerColor getColor() {
|
||||||
switch ((id%6)+1) {
|
switch ((id%6)+1) {
|
||||||
case 1: return PlayerColor.CYAN;
|
case 1: return PlayerColor.BLUE;
|
||||||
case 2: return PlayerColor.YELLOW;
|
case 2: return PlayerColor.GREEN_DARK;
|
||||||
case 3: return PlayerColor.RED;
|
case 3: return PlayerColor.GREEN_LIGHT;
|
||||||
case 4: return PlayerColor.PINK;
|
case 4: return PlayerColor.PINK;
|
||||||
case 5: return PlayerColor.GREEN;
|
case 5: return PlayerColor.RED;
|
||||||
case 6: return PlayerColor.PURPLE;
|
case 6: return PlayerColor.YELLOW;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
@@ -322,9 +319,7 @@ public class Player implements FieldVisitor<Void>{
|
|||||||
@Override
|
@Override
|
||||||
public Void visit(EventField field) {
|
public Void visit(EventField field) {
|
||||||
Card c = getHandler().getLogic().getDeckHelper().drawCard();
|
Card c = getHandler().getLogic().getDeckHelper().drawCard();
|
||||||
getHandler().getLogic().getDeckHelper().visit(c, this); //Logic
|
getHandler().getLogic().getDeckHelper().visit(c, this);
|
||||||
getHandler().getLogic().send(this, new EventDrawCard(c.getDescription())); // Card notification
|
|
||||||
getHandler().getLogic().send(this, new PlayerStatusUpdate(getHandler())); //update view
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -413,10 +408,6 @@ public class Player implements FieldVisitor<Void>{
|
|||||||
return state.rollDice();
|
return state.rollDice();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void visitEvent() {
|
|
||||||
getHandler().getLogic().getBoardManager().getFieldAtIndex(36).accept(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A interface representing the PlayerStates
|
* A interface representing the PlayerStates
|
||||||
*/
|
*/
|
||||||
@@ -448,7 +439,7 @@ public class Player implements FieldVisitor<Void>{
|
|||||||
@Override
|
@Override
|
||||||
public DiceResult rollDice() {
|
public DiceResult rollDice() {
|
||||||
List<Integer> roll = List.of(Dice.rollDice(), Dice.rollDice());
|
List<Integer> roll = List.of(Dice.rollDice(), Dice.rollDice());
|
||||||
rollResult = new DiceResult(roll.get(0), roll.get(1));
|
rollResult = new DiceResult(roll);
|
||||||
return rollResult;
|
return rollResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -500,7 +491,7 @@ public class Player implements FieldVisitor<Void>{
|
|||||||
@Override
|
@Override
|
||||||
public DiceResult rollDice() {
|
public DiceResult rollDice() {
|
||||||
List<Integer> roll = List.of(Dice.rollDice(), Dice.rollDice());
|
List<Integer> roll = List.of(Dice.rollDice(), Dice.rollDice());
|
||||||
rollResult = new DiceResult(roll.get(0), roll.get(1));
|
rollResult = new DiceResult(roll);
|
||||||
if (rollResult.isDoublets()) {
|
if (rollResult.isDoublets()) {
|
||||||
state = new ActiveState();
|
state = new ActiveState();
|
||||||
} else if (DoubletsCounter == 0) {
|
} else if (DoubletsCounter == 0) {
|
||||||
@@ -528,7 +519,7 @@ public class Player implements FieldVisitor<Void>{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DiceResult rollDice() {
|
public DiceResult rollDice() {
|
||||||
return null;
|
throw new UnsupportedOperationException("not allowed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -6,12 +6,12 @@ import com.jme3.math.ColorRGBA;
|
|||||||
* Enum representing six distinct colors for players in the game.
|
* Enum representing six distinct colors for players in the game.
|
||||||
*/
|
*/
|
||||||
public enum PlayerColor {
|
public enum PlayerColor {
|
||||||
CYAN(new ColorRGBA(1 / 255f, 190 / 255f, 254 / 255f, 1)),
|
GREEN_LIGHT(new ColorRGBA(0 / 255f, 204 / 255f, 0 / 255f, 1)), // Hex: 00cc00
|
||||||
YELLOW(new ColorRGBA(255 / 255f, 255 / 255f, 0 / 255f, 1)),
|
RED(new ColorRGBA(255 / 255f, 0 / 255f, 0 / 255f, 1)), // Hex: ff0000
|
||||||
RED(new ColorRGBA(255 / 255f, 0 / 255f, 0 / 255f, 1)),
|
BLUE(new ColorRGBA(0 / 255f, 0 / 255f, 204 / 255f, 1)), // Hex: 0000cc
|
||||||
PINK(new ColorRGBA(255 / 255f, 77 / 255f, 166 / 255f, 1)),
|
PINK(new ColorRGBA(255 / 255f, 77 / 255f, 166 / 255f, 1)), // Hex: ff4da6
|
||||||
GREEN(new ColorRGBA(0 / 255f, 204 / 255f, 0 / 255f, 1)),
|
GREEN_DARK(new ColorRGBA(0 / 255f, 102 / 255f, 0 / 255f, 1)), // Hex: 006600
|
||||||
PURPLE(new ColorRGBA(143 / 255f, 0 / 255f, 255 / 255f, 1));
|
YELLOW(new ColorRGBA(255 / 255f, 255 / 255f, 0 / 255f, 1)); // Hex: ffff00
|
||||||
|
|
||||||
private final ColorRGBA color;
|
private final ColorRGBA color;
|
||||||
|
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
package pp.monopoly.game.server;
|
package pp.monopoly.game.server;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -16,9 +16,10 @@ import pp.monopoly.model.LimitedLinkedList;
|
|||||||
*/
|
*/
|
||||||
@Serializable
|
@Serializable
|
||||||
public class PlayerHandler {
|
public class PlayerHandler {
|
||||||
private List<Player> players = new LinkedList<>();
|
private List<Player> players = new LimitedLinkedList<>(6);
|
||||||
private Set<Player> readyPlayers = new HashSet<>();
|
private Set<Player> readyPlayers = new HashSet<>();
|
||||||
private transient ServerGameLogic logic;
|
private ServerGameLogic logic;
|
||||||
|
private Player hostPlayer;
|
||||||
private Player extra = null;
|
private Player extra = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,6 +55,14 @@ public class PlayerHandler {
|
|||||||
players.addAll(players);
|
players.addAll(players);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the host player
|
||||||
|
* @return the host player
|
||||||
|
*/
|
||||||
|
public Player getHostPlayer() {
|
||||||
|
return hostPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the number of players
|
* Return the number of players
|
||||||
* @return number of players in the game
|
* @return number of players in the game
|
||||||
@@ -105,6 +114,9 @@ public class PlayerHandler {
|
|||||||
throw new IllegalArgumentException("Player already registered");
|
throw new IllegalArgumentException("Player already registered");
|
||||||
}
|
}
|
||||||
players.add(player);
|
players.add(player);
|
||||||
|
if(hostPlayer == null) {
|
||||||
|
hostPlayer = player;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -132,6 +132,7 @@ public class ServerGameLogic implements ClientInterpreter {
|
|||||||
|
|
||||||
playerHandler.addPlayer(player);
|
playerHandler.addPlayer(player);
|
||||||
LOGGER.log(Level.DEBUG, "Player added: {0}", player.getId());
|
LOGGER.log(Level.DEBUG, "Player added: {0}", player.getId());
|
||||||
|
System.out.println("Anzahl Spieler verbunden:"+ playerHandler.getPlayerCount());
|
||||||
|
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
@@ -174,7 +175,7 @@ public class ServerGameLogic implements ClientInterpreter {
|
|||||||
LOGGER.log(Level.DEBUG, "Ending turn for player {0}", player.getName());
|
LOGGER.log(Level.DEBUG, "Ending turn for player {0}", player.getName());
|
||||||
Player next = playerHandler.nextPlayer();
|
Player next = playerHandler.nextPlayer();
|
||||||
next.setActive();
|
next.setActive();
|
||||||
send(next, new NextPlayerTurn());
|
send(next, new NextPlayerTurn(next));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -188,7 +189,7 @@ public class ServerGameLogic implements ClientInterpreter {
|
|||||||
@Override
|
@Override
|
||||||
public void received(PlayerReady msg, int from) {
|
public void received(PlayerReady msg, int from) {
|
||||||
Player player = playerHandler.getPlayerById(from);
|
Player player = playerHandler.getPlayerById(from);
|
||||||
if(player.getId() == 0) {
|
if(player == playerHandler.getHostPlayer()) {
|
||||||
startMoney = msg.getStartMoney();
|
startMoney = msg.getStartMoney();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,10 +204,10 @@ public class ServerGameLogic implements ClientInterpreter {
|
|||||||
if(playerHandler.allPlayersReady()) {
|
if(playerHandler.allPlayersReady()) {
|
||||||
playerHandler.setStartBalance(startMoney);
|
playerHandler.setStartBalance(startMoney);
|
||||||
for (Player p : playerHandler.getPlayers()) {
|
for (Player p : playerHandler.getPlayers()) {
|
||||||
send(p, new GameStart(playerHandler));
|
send(p, new GameStart(playerHandler.getPlayers()));
|
||||||
}
|
}
|
||||||
playerHandler.randomOrder();
|
playerHandler.randomOrder();
|
||||||
send(playerHandler.getPlayerAtIndex(0), new NextPlayerTurn());
|
send(playerHandler.getPlayerAtIndex(0), new NextPlayerTurn(playerHandler.getPlayerAtIndex(0)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,7 +220,7 @@ public class ServerGameLogic implements ClientInterpreter {
|
|||||||
@Override
|
@Override
|
||||||
public void received(RollDice msg, int from) {
|
public void received(RollDice msg, int from) {
|
||||||
Player player = playerHandler.getPlayerById(from);
|
Player player = playerHandler.getPlayerById(from);
|
||||||
if (player != null) {
|
if (player != null && state == ServerState.INGAME) {
|
||||||
send(player, player.rollDice());
|
send(player, player.rollDice());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,14 +7,30 @@ import com.jme3.network.serializing.Serializable;
|
|||||||
*/
|
*/
|
||||||
@Serializable
|
@Serializable
|
||||||
public class BuyPropertyRequest extends ClientMessage{
|
public class BuyPropertyRequest extends ClientMessage{
|
||||||
|
private int propertyId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor for serialization purposes.
|
||||||
|
*/
|
||||||
|
private BuyPropertyRequest() { /* empty */ }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a BuyPropertyRequest with the specified property ID.
|
* Constructs a BuyPropertyRequest with the specified property ID.
|
||||||
*
|
*
|
||||||
* @param propertyId the ID of the property to buy
|
* @param propertyId the ID of the property to buy
|
||||||
*/
|
*/
|
||||||
public BuyPropertyRequest() {}
|
public BuyPropertyRequest(int propertyId) {
|
||||||
|
this.propertyId = propertyId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the ID of the property to buy.
|
||||||
|
*
|
||||||
|
* @return the property ID
|
||||||
|
*/
|
||||||
|
public int getPropertyId() {
|
||||||
|
return propertyId;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(ClientInterpreter interpreter, int from) {
|
public void accept(ClientInterpreter interpreter, int from) {
|
||||||
|
@@ -11,7 +11,7 @@ public class RollDice extends ClientMessage{
|
|||||||
/**
|
/**
|
||||||
* Default constructor for serialization purposes.
|
* Default constructor for serialization purposes.
|
||||||
*/
|
*/
|
||||||
public RollDice() { /* empty */ }
|
private RollDice() { /* empty */ }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(ClientInterpreter interpreter, int from) {
|
public void accept(ClientInterpreter interpreter, int from) {
|
||||||
|
@@ -7,24 +7,19 @@ import com.jme3.network.serializing.Serializable;
|
|||||||
@Serializable
|
@Serializable
|
||||||
public class DiceResult extends ServerMessage{
|
public class DiceResult extends ServerMessage{
|
||||||
|
|
||||||
private final int a;
|
private List<Integer> rollResult;
|
||||||
private final int b;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor for serialization purposes.
|
* Default constructor for serialization purposes.
|
||||||
*/
|
*/
|
||||||
private DiceResult() {
|
private DiceResult() { /* empty */ }
|
||||||
a = 1;
|
|
||||||
b = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DiceResult(int a, int b) {
|
public DiceResult(List<Integer> rollResult) {
|
||||||
this.a = a;
|
this.rollResult = rollResult;
|
||||||
this.b = b;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Integer> getRollResult() {
|
public List<Integer> getRollResult() {
|
||||||
return List.of(a,b);
|
return rollResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -39,10 +34,10 @@ public class DiceResult extends ServerMessage{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDoublets() {
|
public boolean isDoublets() {
|
||||||
return a == b;
|
return rollResult.get(0) == rollResult.get(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int calcTotal() {
|
public int calcTotal() {
|
||||||
return a+b;
|
return rollResult.get(0)+rollResult.get(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,25 +1,27 @@
|
|||||||
package pp.monopoly.message.server;
|
package pp.monopoly.message.server;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
import com.jme3.network.serializing.Serializable;
|
||||||
|
|
||||||
import pp.monopoly.game.server.PlayerHandler;
|
import pp.monopoly.game.server.Player;
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
public class GameStart extends ServerMessage{
|
public class GameStart extends ServerMessage{
|
||||||
|
|
||||||
private PlayerHandler playerHandler;
|
private List<Player> players;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor for serialization purposes.
|
* Default constructor for serialization purposes.
|
||||||
*/
|
*/
|
||||||
private GameStart() { /* empty */ }
|
private GameStart() { /* empty */ }
|
||||||
|
|
||||||
public GameStart(PlayerHandler playerHandler) {
|
public GameStart(List<Player> players) {
|
||||||
this.playerHandler = playerHandler;
|
this.players = players;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerHandler getPlayerHandler() {
|
public List<Player> getPlayers() {
|
||||||
return playerHandler;
|
return players;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -2,13 +2,20 @@ package pp.monopoly.message.server;
|
|||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
import com.jme3.network.serializing.Serializable;
|
||||||
|
|
||||||
|
import pp.monopoly.game.server.Player;
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
public class NextPlayerTurn extends ServerMessage{
|
public class NextPlayerTurn extends ServerMessage{
|
||||||
|
|
||||||
|
private Player player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor for serialization purposes.
|
* Default constructor for serialization purposes.
|
||||||
*/
|
*/
|
||||||
public NextPlayerTurn() {
|
private NextPlayerTurn() { /* empty */ }
|
||||||
|
|
||||||
|
public NextPlayerTurn(Player player) {
|
||||||
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -21,4 +28,9 @@ public class NextPlayerTurn extends ServerMessage{
|
|||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
|
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -2,24 +2,36 @@ package pp.monopoly.message.server;
|
|||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
import com.jme3.network.serializing.Serializable;
|
||||||
|
|
||||||
import pp.monopoly.game.server.PlayerHandler;
|
import pp.monopoly.game.server.PlayerColor;
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
public class PlayerStatusUpdate extends ServerMessage{
|
public class PlayerStatusUpdate extends ServerMessage{
|
||||||
|
|
||||||
private PlayerHandler playerHandler;
|
private String playerName;
|
||||||
|
private String status;
|
||||||
|
private PlayerColor color;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor for serialization purposes.
|
* Default constructor for serialization purposes.
|
||||||
*/
|
*/
|
||||||
private PlayerStatusUpdate() { /* empty */ }
|
private PlayerStatusUpdate() { /* empty */ }
|
||||||
|
|
||||||
public PlayerStatusUpdate(PlayerHandler playerHandler) {
|
public PlayerStatusUpdate(String playerName, String status, PlayerColor color) {
|
||||||
this.playerHandler = playerHandler;
|
this.playerName = playerName;
|
||||||
|
this.status = status;
|
||||||
|
this.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerHandler getPlayerHandler() {
|
public String getPlayerName() {
|
||||||
return playerHandler;
|
return playerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerColor getColor() {
|
||||||
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -12,13 +12,13 @@ import java.util.List;
|
|||||||
public class TradeHandler {
|
public class TradeHandler {
|
||||||
|
|
||||||
private final Player sender;
|
private final Player sender;
|
||||||
private Player receiver;
|
private final Player receiver;
|
||||||
private int offeredAmount;
|
private final int offeredAmount;
|
||||||
private List<PropertyField> offeredProperties;
|
private final List<PropertyField> offeredProperties;
|
||||||
private int offeredJailCards;
|
private final int offeredJailCards;
|
||||||
private int requestedAmount;
|
private final int requestedAmount;
|
||||||
private List<PropertyField> requestedProperties;
|
private final List<PropertyField> requestedProperties;
|
||||||
private int requestedJailCards;
|
private final int requestedJailCards;
|
||||||
private Boolean status = null;
|
private Boolean status = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,22 +45,6 @@ public class TradeHandler {
|
|||||||
this.requestedJailCards = requestedJailCards;
|
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() {
|
public int getOfferedAmount() {
|
||||||
return offeredAmount;
|
return offeredAmount;
|
||||||
}
|
}
|
||||||
@@ -104,10 +88,10 @@ public class TradeHandler {
|
|||||||
*/
|
*/
|
||||||
public boolean initiateTrade() {
|
public boolean initiateTrade() {
|
||||||
if (!validateTrade()) {
|
if (!validateTrade()) {
|
||||||
|
System.out.println("Trade offer is invalid.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
System.out.println("Trade initiated by " + sender.getName() + " to " + receiver.getName());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,14 +122,14 @@ public class TradeHandler {
|
|||||||
transferJailCards(sender, receiver, offeredJailCards);
|
transferJailCards(sender, receiver, offeredJailCards);
|
||||||
transferJailCards(receiver, sender, requestedJailCards);
|
transferJailCards(receiver, sender, requestedJailCards);
|
||||||
|
|
||||||
|
System.out.println("Trade completed between " + sender.getName() + " and " + receiver.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rejects the trade.
|
* Rejects the trade.
|
||||||
*/
|
*/
|
||||||
public void rejectTrade() {
|
public void rejectTrade() {
|
||||||
|
System.out.println(receiver.getName() + " rejected the trade.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -156,13 +140,13 @@ public class TradeHandler {
|
|||||||
private boolean validateTrade() {
|
private boolean validateTrade() {
|
||||||
// Validate sender's ability to offer money
|
// Validate sender's ability to offer money
|
||||||
if (sender.getAccountBalance() < offeredAmount) {
|
if (sender.getAccountBalance() < offeredAmount) {
|
||||||
|
System.out.println("Sender does not have enough money to offer.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate receiver's ability to fulfill the requested amount
|
// Validate receiver's ability to fulfill the requested amount
|
||||||
if (receiver.getAccountBalance() < requestedAmount) {
|
if (receiver.getAccountBalance() < requestedAmount) {
|
||||||
|
System.out.println("Receiver does not have enough money to fulfill the request.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +154,7 @@ public class TradeHandler {
|
|||||||
if (offeredProperties != null) {
|
if (offeredProperties != null) {
|
||||||
for (PropertyField property : offeredProperties) {
|
for (PropertyField property : offeredProperties) {
|
||||||
if (!sender.getProperties().contains(property)) {
|
if (!sender.getProperties().contains(property)) {
|
||||||
|
System.out.println("Sender does not own property: " + property.getName());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -178,7 +162,7 @@ public class TradeHandler {
|
|||||||
if (requestedProperties != null) {
|
if (requestedProperties != null) {
|
||||||
for (PropertyField property : requestedProperties) {
|
for (PropertyField property : requestedProperties) {
|
||||||
if (!receiver.getProperties().contains(property)) {
|
if (!receiver.getProperties().contains(property)) {
|
||||||
|
System.out.println("Receiver does not own property: " + property.getName());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -186,11 +170,11 @@ public class TradeHandler {
|
|||||||
|
|
||||||
// Validate jail cards
|
// Validate jail cards
|
||||||
if (sender.getNumJailCard() < offeredJailCards) {
|
if (sender.getNumJailCard() < offeredJailCards) {
|
||||||
|
System.out.println("Sender does not have enough jail cards to offer.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (receiver.getNumJailCard() < requestedJailCards) {
|
if (receiver.getNumJailCard() < requestedJailCards) {
|
||||||
|
System.out.println("Receiver does not have enough jail cards to fulfill the request.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,7 +192,7 @@ public class TradeHandler {
|
|||||||
from.sellProperty(property);
|
from.sellProperty(property);
|
||||||
to.buyProperty(property);
|
to.buyProperty(property);
|
||||||
property.setOwner(to);
|
property.setOwner(to);
|
||||||
|
System.out.println("Property " + property.getName() + " transferred from " + from.getName() + " to " + to.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -223,34 +207,6 @@ public class TradeHandler {
|
|||||||
from.removeJailCard();
|
from.removeJailCard();
|
||||||
to.addJailCard();
|
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,40 +16,38 @@ public class DeckHelper{
|
|||||||
|
|
||||||
public DeckHelper() {
|
public DeckHelper() {
|
||||||
cards = new LinkedList<Card>();
|
cards = new LinkedList<Card>();
|
||||||
cards.add(new Card("Du wurdest mit einem Dienst KFZ geblitzt. Zahle: 800 EUR", "dienst-kfz-blitzer"));
|
cards.add(new Card("Du wurdest mit einem Dienst KFZ geblitzt. Zahle: 800€", "dienst-kfz-blitzer"));
|
||||||
cards.add(new Card("Die erste Spoparty steht bevor. Ziehe vor zum 23er.", "spoparty"));
|
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-1"));
|
||||||
cards.add(new Card("Du kommst aus dem Gulak frei.", "gulak-frei-2"));
|
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("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("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 EUR ein.", "namensschild-truppenkueche"));
|
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 EUR", "spendierhosen-unibar"));
|
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 in der Prüfungsphase krank. Gehe 3 Felder zurück.", "pruefungsphase-krank"));
|
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("Ziehe vor bis zum nächsten Monatsgehalt.", "naechstes-monatsgehalt"));
|
||||||
cards.add(new Card("Du hast ein Antreten verschlafen. Zahle: 500 EUR", "antreten-verschlafen-1"));
|
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 EUR", "maibock-organisiert"));
|
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 EUR und jedes Hotel: 2800 EUR", "inventur-haeuser-hotels"));
|
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("Es gab keine Mozzarella Bällchen mehr für Thoma. Alle Spieler ziehen vor auf Gym.", "dienstsport-gym"));
|
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("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("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("Das Jahresabschlussantreten steht an. Ziehe vor bis Schwimmhalle.", "jahresabschlussantreten"));
|
||||||
cards.add(new Card("Du wurdest beim Verkaufen von Versicherungen erwischt. Zahle: 4000 EUR", "verkaufen-versicherungen"));
|
cards.add(new Card("Du wurdest beim Verkaufen von Versicherungen erwischt. Zahle: 4000€", "verkaufen-versicherungen"));
|
||||||
cards.add(new Card("Du musstest einen Rückstuferantrag stellen. Setze eine Runde aus.", "rueckstuferantrag"));
|
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 EUR und gehe zurück zu SanZ.", "hausfeier-sturz"));
|
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 EUR", "befoerderung"));
|
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 EUR und setze eine Runde aus.", "dienstreise-lourd"));
|
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("Du warst fleißig Blutspenden und erhältst einen Tag Sonderurlaub. Du bist nochmal an der Reihe.", "blutspenden-sonderurlaub"));
|
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("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 EUR", "lob-chef"));
|
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 EUR", "spo-testen"));
|
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 wurdest von Kranz geexmattet. Gehe zurück zu Prüfungsamt.", "kranz-exmatrikulation"));
|
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("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 EUR", "vp-einstandsparty"));
|
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 EUR", "party-gewinn"));
|
cards.add(new Card("Du hast eine Party veranstaltet und dick Gewinn gemacht. Ziehe ein: 1500€", "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("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 EUR", "jodel-eispenis"));
|
cards.add(new Card("Dein Jodel eines Eispenis mit Unterhodenbeleuchtung geht viral. Ziehe ein: 1000€", "jodel-eispenis"));
|
||||||
|
|
||||||
shuffle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void visit(Card card, Player player) {
|
public void visit(Card card, Player player) {
|
||||||
@@ -205,7 +203,7 @@ public class DeckHelper{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void namensschildTruppenkueche(Player player) {
|
private void namensschildTruppenkueche(Player player) {
|
||||||
//TODO 10 existiert nicht mehr
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
private void spendierhosenUnibar(Player player) {
|
private void spendierhosenUnibar(Player player) {
|
||||||
|
@@ -3,11 +3,8 @@ package pp.monopoly.model.fields;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
|
||||||
|
|
||||||
import pp.monopoly.game.server.Player;
|
import pp.monopoly.game.server.Player;
|
||||||
|
|
||||||
@Serializable
|
|
||||||
public class BuildingProperty extends PropertyField {
|
public class BuildingProperty extends PropertyField {
|
||||||
|
|
||||||
private int houses;
|
private int houses;
|
||||||
@@ -20,12 +17,6 @@ public class BuildingProperty extends PropertyField {
|
|||||||
private final int rentFactor4 = 55;
|
private final int rentFactor4 = 55;
|
||||||
private final int rentFactorHotel = 70;
|
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) {
|
BuildingProperty(String name, int id, int price, int rent, int housePrice, FieldColor color) {
|
||||||
super(name, id, price, rent);
|
super(name, id, price, rent);
|
||||||
this.housePrice = housePrice;
|
this.housePrice = housePrice;
|
||||||
|
@@ -1,18 +1,11 @@
|
|||||||
package pp.monopoly.model.fields;
|
package pp.monopoly.model.fields;
|
||||||
|
|
||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
|
||||||
|
|
||||||
import pp.monopoly.game.server.Player;
|
import pp.monopoly.game.server.Player;
|
||||||
|
|
||||||
@Serializable
|
|
||||||
public class EventField extends Field{
|
public class EventField extends Field{
|
||||||
|
|
||||||
private EventField() {
|
public EventField(String name, int id) {
|
||||||
super("", 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
EventField(String name, int id) {
|
|
||||||
super(name, id);
|
super(name, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,19 +1,11 @@
|
|||||||
package pp.monopoly.model.fields;
|
package pp.monopoly.model.fields;
|
||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
|
||||||
|
|
||||||
import pp.monopoly.game.server.Player;
|
import pp.monopoly.game.server.Player;
|
||||||
|
|
||||||
@Serializable
|
abstract class Field {
|
||||||
public abstract class Field {
|
|
||||||
protected final String name;
|
protected final String name;
|
||||||
protected final int id;
|
protected final int id;
|
||||||
|
|
||||||
private Field() {
|
|
||||||
this.name = "";
|
|
||||||
this.id = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Field(String name, int id) {
|
protected Field(String name, int id) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.id= id;
|
this.id= id;
|
||||||
|
@@ -1,12 +1,10 @@
|
|||||||
package pp.monopoly.model.fields;
|
package pp.monopoly.model.fields;
|
||||||
|
|
||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
import com.jme3.network.serializing.Serializable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enum representing eight distinct colors for properties in the game.
|
* Enum representing eight distinct colors for properties in the game.
|
||||||
*/
|
*/
|
||||||
// @Serializable
|
|
||||||
public enum FieldColor {
|
public enum FieldColor {
|
||||||
BROWN(new ColorRGBA(148 / 255f, 86 / 255f, 57 / 255f, 1)),
|
BROWN(new ColorRGBA(148 / 255f, 86 / 255f, 57 / 255f, 1)),
|
||||||
GREEN(new ColorRGBA(30 / 255f, 179 / 255f, 90 / 255f, 1)),
|
GREEN(new ColorRGBA(30 / 255f, 179 / 255f, 90 / 255f, 1)),
|
||||||
@@ -19,10 +17,6 @@ public enum FieldColor {
|
|||||||
|
|
||||||
private final ColorRGBA color;
|
private final ColorRGBA color;
|
||||||
|
|
||||||
private FieldColor() {
|
|
||||||
this.color = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a FieldColor with the specified ColorRGBA value.
|
* Constructs a FieldColor with the specified ColorRGBA value.
|
||||||
*
|
*
|
||||||
|
@@ -1,19 +1,11 @@
|
|||||||
package pp.monopoly.model.fields;
|
package pp.monopoly.model.fields;
|
||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
|
||||||
|
|
||||||
import pp.monopoly.game.server.Player;
|
import pp.monopoly.game.server.Player;
|
||||||
|
|
||||||
@Serializable
|
|
||||||
public class FineField extends Field{
|
public class FineField extends Field{
|
||||||
|
|
||||||
private final int fine;
|
private final int fine;
|
||||||
|
|
||||||
private FineField() {
|
|
||||||
super("", 0);
|
|
||||||
this.fine = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
FineField(String name, int id, int fine) {
|
FineField(String name, int id, int fine) {
|
||||||
super(name, id);
|
super(name, id);
|
||||||
this.fine = fine;
|
this.fine = fine;
|
||||||
|
@@ -1,17 +1,10 @@
|
|||||||
package pp.monopoly.model.fields;
|
package pp.monopoly.model.fields;
|
||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
|
||||||
|
|
||||||
import pp.monopoly.game.server.Player;
|
import pp.monopoly.game.server.Player;
|
||||||
|
|
||||||
@Serializable
|
|
||||||
public class FoodField extends PropertyField {
|
public class FoodField extends PropertyField {
|
||||||
|
|
||||||
private FoodField() {
|
public FoodField(String name, int id) {
|
||||||
super("", 0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
FoodField(String name, int id) {
|
|
||||||
super(name, id, 1500,0);
|
super(name, id, 1500,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,14 +1,8 @@
|
|||||||
package pp.monopoly.model.fields;
|
package pp.monopoly.model.fields;
|
||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
|
||||||
|
|
||||||
import pp.monopoly.game.server.Player;
|
import pp.monopoly.game.server.Player;
|
||||||
@Serializable
|
|
||||||
public class GateField extends PropertyField{
|
|
||||||
|
|
||||||
private GateField() {
|
public class GateField extends PropertyField{
|
||||||
super("", 0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
GateField(String name, int id) {
|
GateField(String name, int id) {
|
||||||
super(name, id, 2000, 25);
|
super(name, id, 2000, 25);
|
||||||
|
@@ -1,12 +1,10 @@
|
|||||||
package pp.monopoly.model.fields;
|
package pp.monopoly.model.fields;
|
||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
|
||||||
|
|
||||||
import pp.monopoly.game.server.Player;
|
import pp.monopoly.game.server.Player;
|
||||||
@Serializable
|
|
||||||
public class GoField extends Field{
|
public class GoField extends Field{
|
||||||
|
|
||||||
GoField() {
|
public GoField() {
|
||||||
super("Monatsgehalt", 0);
|
super("Monatsgehalt", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,9 +1,7 @@
|
|||||||
package pp.monopoly.model.fields;
|
package pp.monopoly.model.fields;
|
||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
|
||||||
|
|
||||||
import pp.monopoly.game.server.Player;
|
import pp.monopoly.game.server.Player;
|
||||||
@Serializable
|
|
||||||
public class GulagField extends Field{
|
public class GulagField extends Field{
|
||||||
|
|
||||||
private int bailCost = 500;
|
private int bailCost = 500;
|
||||||
|
@@ -1,14 +1,11 @@
|
|||||||
package pp.monopoly.model.fields;
|
package pp.monopoly.model.fields;
|
||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
|
||||||
|
|
||||||
import pp.monopoly.game.server.Player;
|
import pp.monopoly.game.server.Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an abstract property field in the Monopoly game.
|
* Represents an abstract property field in the Monopoly game.
|
||||||
* Contains attributes related to ownership, price, rent, and mortgage status.
|
* Contains attributes related to ownership, price, rent, and mortgage status.
|
||||||
*/
|
*/
|
||||||
@Serializable
|
|
||||||
public abstract class PropertyField extends Field {
|
public abstract class PropertyField extends Field {
|
||||||
|
|
||||||
private final int price;
|
private final int price;
|
||||||
@@ -16,12 +13,6 @@ public abstract class PropertyField extends Field {
|
|||||||
private Player owner;
|
private Player owner;
|
||||||
private boolean mortgaged = false;
|
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.
|
* Constructs a PropertyField with the specified name, ID, price, and rent.
|
||||||
*
|
*
|
||||||
|
@@ -1,10 +1,7 @@
|
|||||||
package pp.monopoly.model.fields;
|
package pp.monopoly.model.fields;
|
||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
|
||||||
|
|
||||||
import pp.monopoly.game.server.Player;
|
import pp.monopoly.game.server.Player;
|
||||||
|
|
||||||
@Serializable
|
|
||||||
public class TestStreckeField extends Field{
|
public class TestStreckeField extends Field{
|
||||||
private int money;
|
private int money;
|
||||||
|
|
||||||
|
@@ -1,13 +1,10 @@
|
|||||||
package pp.monopoly.model.fields;
|
package pp.monopoly.model.fields;
|
||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
|
||||||
|
|
||||||
import pp.monopoly.game.server.Player;
|
import pp.monopoly.game.server.Player;
|
||||||
|
|
||||||
@Serializable
|
|
||||||
public class WacheField extends Field{
|
public class WacheField extends Field{
|
||||||
|
|
||||||
WacheField() {
|
public WacheField() {
|
||||||
super("Wache", 30);
|
super("Wache", 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,10 +0,0 @@
|
|||||||
package pp.monopoly.notification;
|
|
||||||
|
|
||||||
public record DiceRollEvent(int a, int b) implements GameEvent{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void notifyListener(GameEventListener listener) {
|
|
||||||
listener.receivedEvent(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,10 +0,0 @@
|
|||||||
package pp.monopoly.notification;
|
|
||||||
|
|
||||||
public record EventCardEvent(String description) implements GameEvent{
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void notifyListener(GameEventListener listener) {
|
|
||||||
listener.receivedEvent(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -45,25 +45,4 @@ public interface GameEventListener {
|
|||||||
* @param event the received event
|
* @param event the received event
|
||||||
*/
|
*/
|
||||||
default void receivedEvent(ClientStateEvent event) { /* do nothing */ }
|
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 */}
|
|
||||||
}
|
}
|
||||||
|
@@ -1,26 +1,25 @@
|
|||||||
////////////////////////////////////////
|
|
||||||
// Programming project code
|
|
||||||
// UniBw M, 2022, 2023, 2024
|
|
||||||
// www.unibw.de/inf2
|
|
||||||
// (c) Mark Minas (mark.minas@unibw.de)
|
|
||||||
////////////////////////////////////////
|
|
||||||
|
|
||||||
package pp.monopoly.notification;
|
package pp.monopoly.notification;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event when an item is added to a map.
|
* Event when a sound needs to be played.
|
||||||
*
|
*
|
||||||
* @param sound the sound to be played
|
* @param soundFileName the sound file to be played
|
||||||
*/
|
*/
|
||||||
public record SoundEvent(Sound sound) implements GameEvent {
|
public class SoundEvent implements GameEvent {
|
||||||
|
private final String soundFileName;
|
||||||
|
|
||||||
|
public SoundEvent(Sound sound) {
|
||||||
|
this.soundFileName = sound.getFileName(); // Angenommen, Sound hat eine Methode getFileName()
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSoundFileName() {
|
||||||
|
return soundFileName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Notifies the game event listener of this event.
|
|
||||||
*
|
|
||||||
* @param listener the game event listener
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void notifyListener(GameEventListener listener) {
|
public void notifyListener(GameEventListener listener) {
|
||||||
listener.receivedEvent(this);
|
listener.receivedEvent(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,13 +0,0 @@
|
|||||||
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
|
monopoly.name=Monopoly
|
||||||
button.play=Spiel starten
|
button.play=Start Game
|
||||||
button.ready=Bereit
|
button.ready=Ready
|
||||||
button.rotate=Drehen
|
button.rotate=Rotate
|
||||||
server.connection.failed=Fehler beim Herstellen einer Serververbindung.
|
server.connection.failed=Failed to establish a server connection.
|
||||||
its.your.turn=Du bist am Zug! Klicke auf das Feld des Gegners, um zu schießen...
|
its.your.turn=It's your turn! Click on the opponent's field to shoot...
|
||||||
lost.connection.to.server=Verbindung zum Server verloren. Das Spiel wurde beendet.
|
lost.connection.to.server=Lost connection to server. The game terminated.
|
||||||
place.ships.in.your.map=Platziere Schiffe auf deiner Karte.
|
place.ships.in.your.map=Place ships in your map.
|
||||||
wait.for.an.opponent=Warte auf einen Gegner!
|
wait.for.an.opponent=Wait for an opponent!
|
||||||
wait.for.opponent=Warte auf deinen Gegner!
|
wait.for.opponent=Wait for your opponent!
|
||||||
confirm.leaving=Möchtest du das Spiel wirklich beenden?
|
confirm.leaving=Would you really like to leave the game?
|
||||||
you.lost.the.game=Du hast das Spiel verloren!
|
you.lost.the.game=You lost the game!
|
||||||
you.won.the.game=Du hast das Spiel gewonnen!
|
you.won.the.game=You won the game!
|
||||||
button.yes=Ja
|
button.yes=Yes
|
||||||
button.no=Nein
|
button.no=No
|
||||||
button.ok=Ok
|
button.ok=Ok
|
||||||
button.connect=Verbinden
|
button.connect=Connect
|
||||||
button.cancel=Abbrechen
|
button.cancel=Cancel
|
||||||
server.dialog=Server
|
server.dialog=Server
|
||||||
host.name=Host
|
host.name=Host
|
||||||
port.number=Port
|
port.number=Port
|
||||||
wait.its.not.your.turn=Warte, es ist nicht dein Zug!!
|
wait.its.not.your.turn=Wait, it's not your turn!!
|
||||||
menu.quit=Spiel beenden
|
menu.quit=Quit game
|
||||||
menu.return-to-game=Zum Spiel zurückkehren
|
menu.return-to-game=Return to game
|
||||||
menu.sound-enabled=Ton eingeschaltet
|
menu.sound-enabled=Sound switched on
|
||||||
menu.background-sound-enabled=Hintergrundmusik eingeschaltet
|
menu.background-sound-enabled=Background music switched on
|
||||||
menu.map.load=Karte aus Datei laden...
|
menu.map.load=Load map from file...
|
||||||
menu.map.save=Karte in Datei speichern...
|
menu.map.save=Save map in file...
|
||||||
label.file=Datei:
|
label.file=File:
|
||||||
label.connecting=Verbinde...
|
label.connecting=Connecting...
|
||||||
dialog.error=Fehler
|
dialog.error=Error
|
||||||
dialog.question=Frage
|
dialog.question=Question
|
||||||
port.must.be.integer=Port muss eine ganze Zahl sein
|
port.must.be.integer=Port must be an integer number
|
||||||
map.doesnt.fit=Die Karte passt nicht zu diesem Spiel
|
map.doesnt.fit=The map doesn't fit to this game
|
||||||
client.server-start=Server starten
|
client.server-start=Start server
|
||||||
|
@@ -37,11 +37,8 @@ import pp.monopoly.message.client.RollDice;
|
|||||||
import pp.monopoly.message.client.TradeOffer;
|
import pp.monopoly.message.client.TradeOffer;
|
||||||
import pp.monopoly.message.client.TradeResponse;
|
import pp.monopoly.message.client.TradeResponse;
|
||||||
import pp.monopoly.message.client.ViewAssetsRequest;
|
import pp.monopoly.message.client.ViewAssetsRequest;
|
||||||
import pp.monopoly.message.server.DiceResult;
|
|
||||||
import pp.monopoly.message.server.EventDrawCard;
|
|
||||||
import pp.monopoly.message.server.GameStart;
|
import pp.monopoly.message.server.GameStart;
|
||||||
import pp.monopoly.message.server.NextPlayerTurn;
|
import pp.monopoly.message.server.NextPlayerTurn;
|
||||||
import pp.monopoly.message.server.PlayerStatusUpdate;
|
|
||||||
import pp.monopoly.message.server.ServerMessage;
|
import pp.monopoly.message.server.ServerMessage;
|
||||||
import pp.monopoly.model.Figure;
|
import pp.monopoly.model.Figure;
|
||||||
import pp.monopoly.model.IntPoint;
|
import pp.monopoly.model.IntPoint;
|
||||||
@@ -133,9 +130,6 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
|||||||
Serializer.registerClass(Player.class);
|
Serializer.registerClass(Player.class);
|
||||||
Serializer.registerClass(Figure.class);
|
Serializer.registerClass(Figure.class);
|
||||||
Serializer.registerClass(PlayerHandler.class);
|
Serializer.registerClass(PlayerHandler.class);
|
||||||
Serializer.registerClass(DiceResult.class);
|
|
||||||
Serializer.registerClass(EventDrawCard.class);
|
|
||||||
Serializer.registerClass(PlayerStatusUpdate.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerListeners() {
|
private void registerListeners() {
|
||||||
@@ -151,6 +145,7 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void messageReceived(HostedConnection source, Message message) {
|
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
|
LOGGER.log(Level.INFO, "message received from {0}: {1}", source.getId(), message); //NON-NLS
|
||||||
if (message instanceof ClientMessage clientMessage)
|
if (message instanceof ClientMessage clientMessage)
|
||||||
pendingMessages.add(new ReceivedMessage(clientMessage, source.getId()));
|
pendingMessages.add(new ReceivedMessage(clientMessage, source.getId()));
|
||||||
@@ -160,6 +155,7 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
|||||||
public void connectionAdded(Server server, HostedConnection hostedConnection) {
|
public void connectionAdded(Server server, HostedConnection hostedConnection) {
|
||||||
LOGGER.log(Level.INFO, "New connection established: {0}", hostedConnection); //NON-NLS
|
LOGGER.log(Level.INFO, "New connection established: {0}", hostedConnection); //NON-NLS
|
||||||
logic.addPlayer(hostedConnection.getId());
|
logic.addPlayer(hostedConnection.getId());
|
||||||
|
System.out.println("Spieler verbunden: ID = " + hostedConnection.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user