Refactor of GUI - synchronized methods
Changed info box
This commit is contained in:
@@ -38,7 +38,6 @@ public class ClientController {
|
|||||||
public ClientController(IView view) {
|
public ClientController(IView view) {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.client = null;
|
this.client = null;
|
||||||
this.miniModel = new MiniModel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,46 +1,69 @@
|
|||||||
package it.polimi.ingsw.gc14.Model.GamePackage;
|
package it.polimi.ingsw.gc14.Model.GamePackage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the possible stages of a game.
|
* Represents the possible stages of a game.
|
||||||
*/
|
*/
|
||||||
public enum GameStages {
|
public enum GameStages {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stage in which the game is waiting for players to join.
|
* Stage in which the game is waiting for players to join.
|
||||||
*/
|
*/
|
||||||
WAITING,
|
WAITING("Waiting"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stage in which players choose their totems.
|
* Stage in which players choose their totems.
|
||||||
*/
|
*/
|
||||||
TOTEM_CHOICE,
|
TOTEM_CHOICE("Totem"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stage in which players select their action slots.
|
* Stage in which players select their action slots.
|
||||||
*/
|
*/
|
||||||
SLOT_CHOICE,
|
SLOT_CHOICE("Slot"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stage in which the mandatory actions associated with the chosen slots are resolved.
|
* Stage in which the mandatory actions associated with the chosen slots are resolved.
|
||||||
*/
|
*/
|
||||||
RES_ACTIONS,
|
RES_ACTIONS("Actions"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stage in which an optional card effect can be resolved.
|
* Stage in which an optional card effect can be resolved.
|
||||||
*/
|
*/
|
||||||
OPT_CARD_E,
|
OPT_CARD_E("Card Effect"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stage in which an event card is being resolved.
|
* Stage in which an event card is being resolved.
|
||||||
*/
|
*/
|
||||||
RES_EVENT,
|
RES_EVENT("Event"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stage in which end-of-round or end-of-game operations are processed.
|
* Stage in which end-of-round or end-of-game operations are processed.
|
||||||
*/
|
*/
|
||||||
ENDING,
|
ENDING("Ending"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stage indicating that the game has ended.
|
* Stage indicating that the game has ended.
|
||||||
*/
|
*/
|
||||||
ENDED
|
ENDED("Ended");
|
||||||
|
|
||||||
|
/** The human-readable name of this stage, used in {@link #toString()}. */
|
||||||
|
private final String displayName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a {@code GameStages} value with the given display name.
|
||||||
|
*
|
||||||
|
* @param displayName the human-readable label for this stage
|
||||||
|
*/
|
||||||
|
GameStages(String displayName) {
|
||||||
|
this.displayName = displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the human-readable name of this stage.
|
||||||
|
*
|
||||||
|
* @return the display name (e.g. {@code "Slot"} for {@code SLOT_CHOICE})
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return displayName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -46,7 +46,8 @@ public class AddPlayer extends NetworkEvent implements Serializable {
|
|||||||
//TODO
|
//TODO
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(MiniModel miniModel){
|
public boolean apply(MiniModel miniModel){
|
||||||
if(isError)
|
synchronized (miniModel) {
|
||||||
|
if (isError)
|
||||||
return false;
|
return false;
|
||||||
miniModel.setPlayers(playerList);
|
miniModel.setPlayers(playerList);
|
||||||
miniModel.setOrderLogicCard(orderLogicCard);
|
miniModel.setOrderLogicCard(orderLogicCard);
|
||||||
@@ -54,4 +55,5 @@ public class AddPlayer extends NetworkEvent implements Serializable {
|
|||||||
miniModel.setSlotPlayerMap(slotPlayerMap);
|
miniModel.setSlotPlayerMap(slotPlayerMap);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,15 +59,17 @@ public class ApplyNextRound extends NetworkEvent implements Serializable{
|
|||||||
}
|
}
|
||||||
public boolean apply(MiniModel miniModel)
|
public boolean apply(MiniModel miniModel)
|
||||||
{
|
{
|
||||||
|
synchronized (miniModel) {
|
||||||
miniModel.setSlotPlayerMap(slotPlayerMap);
|
miniModel.setSlotPlayerMap(slotPlayerMap);
|
||||||
miniModel.setOrderLogicCard(orderLogicCard);
|
miniModel.setOrderLogicCard(orderLogicCard);
|
||||||
miniModel.setCurrentState(currentState);
|
miniModel.setCurrentState(currentState);
|
||||||
miniModel.setPlayers(players);
|
miniModel.setPlayers(players);
|
||||||
miniModel.upperListTribeCards=upperListTribeCards;
|
miniModel.upperListTribeCards = upperListTribeCards;
|
||||||
miniModel.lowerListTribeCards=lowerListTribeCards;
|
miniModel.lowerListTribeCards = lowerListTribeCards;
|
||||||
miniModel.upperListBuildingCards=upperListBuildingCards;
|
miniModel.upperListBuildingCards = upperListBuildingCards;
|
||||||
miniModel.lowerListBuildingCards=lowerListBuildingCards;
|
miniModel.lowerListBuildingCards = lowerListBuildingCards;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,10 +33,10 @@ public class DisconnectedPlayer extends NetworkEvent implements Serializable{
|
|||||||
//TODO
|
//TODO
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(MiniModel miniModel){
|
public boolean apply(MiniModel miniModel){
|
||||||
if(isError)
|
synchronized (miniModel) {
|
||||||
|
if (isError)
|
||||||
return false;
|
return false;
|
||||||
if(miniModel!=null)
|
if (miniModel != null) {
|
||||||
{
|
|
||||||
miniModel.setPlayers(playerList);
|
miniModel.setPlayers(playerList);
|
||||||
miniModel.setOrderLogicCard(orderLogicCard);
|
miniModel.setOrderLogicCard(orderLogicCard);
|
||||||
miniModel.setCurrentState(currentState);
|
miniModel.setCurrentState(currentState);
|
||||||
@@ -44,6 +44,7 @@ public class DisconnectedPlayer extends NetworkEvent implements Serializable{
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ public class DrawLowerBuildingCard extends NetworkEvent implements Serializable
|
|||||||
//TODO
|
//TODO
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(MiniModel miniModel){
|
public boolean apply(MiniModel miniModel){
|
||||||
if(isError)
|
synchronized (miniModel) {
|
||||||
|
if (isError)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
miniModel.lowerListBuildingCards.remove(pos);
|
miniModel.lowerListBuildingCards.remove(pos);
|
||||||
@@ -48,7 +49,7 @@ public class DrawLowerBuildingCard extends NetworkEvent implements Serializable
|
|||||||
miniModel.setCurrentState(currentState);
|
miniModel.setCurrentState(currentState);
|
||||||
miniModel.setSlotPlayerMap(slotPlayerMap);
|
miniModel.setSlotPlayerMap(slotPlayerMap);
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ public class DrawLowerTribeCard extends NetworkEvent implements Serializable{
|
|||||||
//TODO
|
//TODO
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(MiniModel miniModel){
|
public boolean apply(MiniModel miniModel){
|
||||||
if(isError)
|
synchronized (miniModel) {
|
||||||
|
if (isError)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
miniModel.lowerListTribeCards.remove(pos);
|
miniModel.lowerListTribeCards.remove(pos);
|
||||||
@@ -47,7 +48,7 @@ public class DrawLowerTribeCard extends NetworkEvent implements Serializable{
|
|||||||
miniModel.setCurrentState(currentState);
|
miniModel.setCurrentState(currentState);
|
||||||
miniModel.setSlotPlayerMap(slotPlayerMap);
|
miniModel.setSlotPlayerMap(slotPlayerMap);
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ public class DrawUpperBuildingCard extends NetworkEvent implements Serializable
|
|||||||
//TODO
|
//TODO
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(MiniModel miniModel){
|
public boolean apply(MiniModel miniModel){
|
||||||
if(isError)
|
synchronized (miniModel) {
|
||||||
|
if (isError)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
miniModel.upperListBuildingCards.remove(pos);
|
miniModel.upperListBuildingCards.remove(pos);
|
||||||
@@ -48,6 +49,6 @@ public class DrawUpperBuildingCard extends NetworkEvent implements Serializable
|
|||||||
miniModel.setCurrentState(currentState);
|
miniModel.setCurrentState(currentState);
|
||||||
miniModel.setSlotPlayerMap(slotPlayerMap);
|
miniModel.setSlotPlayerMap(slotPlayerMap);
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ public class DrawUpperTribeCard extends NetworkEvent implements Serializable{
|
|||||||
//TODO
|
//TODO
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(MiniModel miniModel){
|
public boolean apply(MiniModel miniModel){
|
||||||
if(isError)
|
synchronized (miniModel) {
|
||||||
|
if (isError)
|
||||||
return false;
|
return false;
|
||||||
miniModel.upperListTribeCards.remove(pos);
|
miniModel.upperListTribeCards.remove(pos);
|
||||||
miniModel.setPlayers(playerList);
|
miniModel.setPlayers(playerList);
|
||||||
@@ -46,7 +47,7 @@ public class DrawUpperTribeCard extends NetworkEvent implements Serializable{
|
|||||||
miniModel.setCurrentState(currentState);
|
miniModel.setCurrentState(currentState);
|
||||||
miniModel.setSlotPlayerMap(slotPlayerMap);
|
miniModel.setSlotPlayerMap(slotPlayerMap);
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ public class EndedGame extends NetworkEvent implements Serializable{
|
|||||||
}
|
}
|
||||||
public boolean apply(MiniModel miniModel)
|
public boolean apply(MiniModel miniModel)
|
||||||
{
|
{
|
||||||
|
synchronized (miniModel) {
|
||||||
miniModel.setSlotPlayerMap(slotPlayerMap);
|
miniModel.setSlotPlayerMap(slotPlayerMap);
|
||||||
miniModel.setOrderLogicCard(orderLogicCard);
|
miniModel.setOrderLogicCard(orderLogicCard);
|
||||||
miniModel.setCurrentState(currentState);
|
miniModel.setCurrentState(currentState);
|
||||||
@@ -55,5 +56,6 @@ public class EndedGame extends NetworkEvent implements Serializable{
|
|||||||
miniModel.setStandingPlayers(players);
|
miniModel.setStandingPlayers(players);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ public class ReconnectPlayer extends NetworkEvent implements Serializable {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(MiniModel miniModel) {
|
public boolean apply(MiniModel miniModel) {
|
||||||
|
synchronized (miniModel) {
|
||||||
if (isError)
|
if (isError)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -57,4 +58,5 @@ public class ReconnectPlayer extends NetworkEvent implements Serializable {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -33,14 +33,15 @@ public class SkipTurn extends NetworkEvent implements Serializable{
|
|||||||
//TODO
|
//TODO
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(MiniModel miniModel){
|
public boolean apply(MiniModel miniModel){
|
||||||
if(isError)
|
synchronized (miniModel) {
|
||||||
|
if (isError)
|
||||||
return false;
|
return false;
|
||||||
miniModel.setPlayers(playerList);
|
miniModel.setPlayers(playerList);
|
||||||
miniModel.setOrderLogicCard(orderLogicCard);
|
miniModel.setOrderLogicCard(orderLogicCard);
|
||||||
miniModel.setCurrentState(currentState);
|
miniModel.setCurrentState(currentState);
|
||||||
miniModel.setSlotPlayerMap(slotPlayerMap);
|
miniModel.setSlotPlayerMap(slotPlayerMap);
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,14 +39,15 @@ public class SlotChoice extends NetworkEvent implements Serializable {
|
|||||||
//TODO
|
//TODO
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(MiniModel miniModel){
|
public boolean apply(MiniModel miniModel){
|
||||||
if(isError)
|
synchronized (miniModel) {
|
||||||
|
if (isError)
|
||||||
return false;
|
return false;
|
||||||
miniModel.setPlayers(playerList);
|
miniModel.setPlayers(playerList);
|
||||||
miniModel.setOrderLogicCard(orderLogicCard);
|
miniModel.setOrderLogicCard(orderLogicCard);
|
||||||
miniModel.setCurrentState(currentState);
|
miniModel.setCurrentState(currentState);
|
||||||
miniModel.setSlotPlayerMap(slotPlayerMap);
|
miniModel.setSlotPlayerMap(slotPlayerMap);
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ public class TotemChoice extends NetworkEvent implements Serializable {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(MiniModel miniModel) {
|
public boolean apply(MiniModel miniModel) {
|
||||||
|
synchronized (miniModel) {
|
||||||
if (isError)
|
if (isError)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -79,4 +80,5 @@ public class TotemChoice extends NetworkEvent implements Serializable {
|
|||||||
miniModel.setAvailableTotems(availableTotems);
|
miniModel.setAvailableTotems(availableTotems);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -40,10 +40,8 @@ public class ClientCallbackImpl extends UnicastRemoteObject implements IClientCa
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onGameInit(MiniModel model) throws RemoteException {
|
public void onGameInit(MiniModel model) throws RemoteException {
|
||||||
Platform.runLater(() -> {
|
|
||||||
clientController.setModel(model);
|
clientController.setModel(model);
|
||||||
clientController.view.render();
|
clientController.view.render();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -56,15 +54,12 @@ public class ClientCallbackImpl extends UnicastRemoteObject implements IClientCa
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onAction(NetworkEvent event) throws RemoteException {
|
public void onAction(NetworkEvent event) throws RemoteException {
|
||||||
synchronized (clientController) {
|
|
||||||
if(event.getIsError()) {
|
if(event.getIsError()) {
|
||||||
clientController.view.showError(event.toString());
|
clientController.view.showError(event.toString());
|
||||||
} else {
|
} else {
|
||||||
Platform.runLater(() -> {
|
|
||||||
event.apply(clientController.miniModel);
|
event.apply(clientController.miniModel);
|
||||||
clientController.view.render();
|
clientController.view.render();
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,8 +83,6 @@ public class GUI extends Application implements IView {
|
|||||||
showLogin();
|
showLogin();
|
||||||
stage.setTitle("Mesos");
|
stage.setTitle("Mesos");
|
||||||
primaryStage.setMaximized(true);
|
primaryStage.setMaximized(true);
|
||||||
primaryStage.setMinWidth(1583);
|
|
||||||
primaryStage.setMinHeight(734);
|
|
||||||
primaryStage.setOnCloseRequest(e -> {
|
primaryStage.setOnCloseRequest(e -> {
|
||||||
Platform.exit();
|
Platform.exit();
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
@@ -106,39 +104,24 @@ public class GUI extends Application implements IView {
|
|||||||
this.controller=controller;
|
this.controller=controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void render() {
|
||||||
public void applyAndRender(NetworkEvent event) {
|
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
if (event!=null) {
|
synchronized (miniModel) {
|
||||||
event.apply(miniModel);
|
|
||||||
}
|
|
||||||
if (controller.miniModel.currentState.getGameStage() == TOTEM_CHOICE) {
|
if (controller.miniModel.currentState.getGameStage() == TOTEM_CHOICE) {
|
||||||
primaryStage.setScene(totemScene);
|
primaryStage.setScene(totemScene);
|
||||||
controllerTotem.render();
|
controllerTotem.render();
|
||||||
} else if (controller.miniModel.currentState.getGameStage() == GameStages.ENDED) {
|
} else if (controller.miniModel.currentState.getGameStage() == ENDED) {
|
||||||
primaryStage.setScene(leaderboardScene);
|
primaryStage.setScene(leaderboardScene);
|
||||||
controllerLeaderboard.render();
|
controllerLeaderboard.render();
|
||||||
} else {
|
} else {
|
||||||
primaryStage.setScene(mainScene);
|
|
||||||
controllerMain.render(event);
|
|
||||||
controllerMain.initPopup(mainScene);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void render() {
|
|
||||||
if (controller.miniModel.currentState.getGameStage() == TOTEM_CHOICE) {
|
|
||||||
primaryStage.setScene(totemScene);
|
|
||||||
controllerTotem.render();
|
|
||||||
} else if (controller.miniModel.currentState.getGameStage() == ENDED){
|
|
||||||
primaryStage.setScene(leaderboardScene);
|
|
||||||
controllerLeaderboard.render();
|
|
||||||
}else {
|
|
||||||
primaryStage.setScene(mainScene);
|
primaryStage.setScene(mainScene);
|
||||||
controllerMain.initPopup(mainScene);
|
controllerMain.initPopup(mainScene);
|
||||||
controllerMain.render();
|
controllerMain.render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public void showMessage(String message) {
|
public void showMessage(String message) {
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ import it.polimi.ingsw.gc14.Model.Cards.TribeCard;
|
|||||||
import it.polimi.ingsw.gc14.Model.Orders.OrderPlayer;
|
import it.polimi.ingsw.gc14.Model.Orders.OrderPlayer;
|
||||||
import it.polimi.ingsw.gc14.Network.EventType;
|
import it.polimi.ingsw.gc14.Network.EventType;
|
||||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
import javafx.animation.AnimationTimer;
|
|
||||||
import javafx.animation.PauseTransition;
|
|
||||||
import javafx.animation.ScaleTransition;
|
import javafx.animation.ScaleTransition;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.beans.value.ChangeListener;
|
import javafx.beans.value.ChangeListener;
|
||||||
@@ -18,6 +16,7 @@ import javafx.fxml.FXML;
|
|||||||
import javafx.geometry.Bounds;
|
import javafx.geometry.Bounds;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.geometry.Rectangle2D;
|
||||||
import javafx.scene.Cursor;
|
import javafx.scene.Cursor;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
@@ -33,7 +32,7 @@ import javafx.scene.paint.Color;
|
|||||||
import javafx.scene.shape.*;
|
import javafx.scene.shape.*;
|
||||||
import javafx.scene.text.Font;
|
import javafx.scene.text.Font;
|
||||||
import javafx.stage.Popup;
|
import javafx.stage.Popup;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Screen;
|
||||||
import javafx.stage.Window;
|
import javafx.stage.Window;
|
||||||
import javafx.util.Duration;
|
import javafx.util.Duration;
|
||||||
|
|
||||||
@@ -41,21 +40,16 @@ import java.util.*;
|
|||||||
|
|
||||||
public class MainFXMLController {
|
public class MainFXMLController {
|
||||||
|
|
||||||
@FXML private HBox currentStateBar;
|
|
||||||
@FXML private ScrollPane playerSide;
|
@FXML private ScrollPane playerSide;
|
||||||
@FXML private HBox mainHBox;
|
@FXML private HBox mainHBox;
|
||||||
|
@FXML private ImageView backgroundImage;
|
||||||
@FXML private HBox board;
|
@FXML private HBox board;
|
||||||
@FXML private HBox upperList;
|
@FXML private HBox upperList;
|
||||||
@FXML private HBox lowerList;
|
@FXML private HBox lowerList;
|
||||||
@FXML private HBox myHand;
|
@FXML private HBox myHand;
|
||||||
@FXML private VBox sidePanel;
|
|
||||||
@FXML private HBox buttonRow;
|
|
||||||
@FXML private Button skipBtn;
|
@FXML private Button skipBtn;
|
||||||
@FXML private Button detailsBtn;
|
@FXML private Button detailsBtn;
|
||||||
@FXML private HBox info;
|
@FXML private Label infoText;
|
||||||
@FXML private Label era;
|
|
||||||
@FXML private Label round;
|
|
||||||
@FXML private Label player;
|
|
||||||
|
|
||||||
private Popup popup;
|
private Popup popup;
|
||||||
private HBox popupCards;
|
private HBox popupCards;
|
||||||
@@ -70,15 +64,14 @@ public class MainFXMLController {
|
|||||||
p -> new Image(getClass().getResourceAsStream(p)));
|
p -> new Image(getClass().getResourceAsStream(p)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setController(ClientController controller) {
|
public void setController(ClientController controller) {
|
||||||
this.controller = controller;
|
this.controller = controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
Font.loadFont(getClass().getResourceAsStream("/Fonts/InknutAntiqua-Regular.ttf"), 14);
|
Font.loadFont(getClass().getResourceAsStream("/Fonts/InknutAntiqua-Regular.ttf"), 14);
|
||||||
|
|
||||||
popup = new Popup();
|
popup = new Popup();
|
||||||
mainHBox.sceneProperty().addListener((obs, oldScene, newScene) -> {
|
mainHBox.sceneProperty().addListener((obs, oldScene, newScene) -> {
|
||||||
if (newScene != null) {
|
if (newScene != null) {
|
||||||
@@ -88,17 +81,7 @@ public class MainFXMLController {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mainHBox.layoutBoundsProperty().addListener(new ChangeListener<Bounds>() {
|
|
||||||
@Override
|
|
||||||
public void changed(ObservableValue<? extends Bounds> obs, Bounds ov, Bounds nv) {
|
|
||||||
if (nv.getWidth() > 0 && nv.getHeight() > 0 && controller != null) {
|
|
||||||
mainHBox.layoutBoundsProperty().removeListener(this);
|
|
||||||
render();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
addHoverZoom(skipBtn);
|
|
||||||
addHoverZoom(detailsBtn);
|
|
||||||
renderBackground();
|
renderBackground();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,11 +121,9 @@ public class MainFXMLController {
|
|||||||
Rectangle clip = new Rectangle();
|
Rectangle clip = new Rectangle();
|
||||||
clip.setArcWidth(20);
|
clip.setArcWidth(20);
|
||||||
clip.setArcHeight(20);
|
clip.setArcHeight(20);
|
||||||
clip.heightProperty().bind(img.fitHeightProperty());
|
|
||||||
clip.widthProperty().bind(img.fitHeightProperty().multiply(
|
|
||||||
img.getImage().getWidth() / img.getImage().getHeight()
|
|
||||||
));
|
|
||||||
img.setClip(clip);
|
img.setClip(clip);
|
||||||
|
clip.heightProperty().bind(img.layoutBoundsProperty().map(b -> b.getHeight()));
|
||||||
|
clip.widthProperty().bind(img.layoutBoundsProperty().map(b -> b.getWidth()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addHoverZoom(Node node) {
|
private void addHoverZoom(Node node) {
|
||||||
@@ -190,7 +171,7 @@ public class MainFXMLController {
|
|||||||
private StackPane createSlot(Slot slot, boolean withZoom, boolean withShadow) {
|
private StackPane createSlot(Slot slot, boolean withZoom, boolean withShadow) {
|
||||||
ImageView img = new ImageView(loadImage("/GUIImages/Fronts/card-" + slot.getSlotId() + ".png"));
|
ImageView img = new ImageView(loadImage("/GUIImages/Fronts/card-" + slot.getSlotId() + ".png"));
|
||||||
img.setPreserveRatio(true);
|
img.setPreserveRatio(true);
|
||||||
img.fitHeightProperty().bind(board.heightProperty().add(-15));
|
img.fitHeightProperty().bind(board.heightProperty().add(-15)); // TODO perchè è tutto moltiplicato per una costante ma in board facciamo -15?
|
||||||
addClip(img);
|
addClip(img);
|
||||||
StackPane wrapper = new StackPane(img);
|
StackPane wrapper = new StackPane(img);
|
||||||
|
|
||||||
@@ -200,10 +181,7 @@ public class MainFXMLController {
|
|||||||
totem.fitHeightProperty().bind(img.fitHeightProperty().multiply(0.332));
|
totem.fitHeightProperty().bind(img.fitHeightProperty().multiply(0.332));
|
||||||
totem.setPreserveRatio(true);
|
totem.setPreserveRatio(true);
|
||||||
StackPane.setAlignment(totem, Pos.TOP_LEFT);
|
StackPane.setAlignment(totem, Pos.TOP_LEFT);
|
||||||
StackPane.setMargin(totem, new Insets(0, 0, 0, 0.224 * img.getFitHeight()));
|
StackPane.setMargin(totem, new Insets(0, 0, 0, 0.224 * img.getFitHeight())); // TODO perchè margine sx incrementa con altezza e non larghezza?
|
||||||
img.fitHeightProperty().addListener((obs, ov, nv) -> {
|
|
||||||
StackPane.setMargin(totem, new Insets(0, 0, 0, 0.224 * nv.doubleValue()));
|
|
||||||
});
|
|
||||||
wrapper.getChildren().add(totem);
|
wrapper.getChildren().add(totem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,9 +266,9 @@ public class MainFXMLController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawMyHandList(ArrayList<? extends PlayableCard> cardList, HBox parent) {
|
private void drawMyHandList(ArrayList<? extends PlayableCard> cardList) {
|
||||||
if (!cardList.isEmpty()) {
|
if (!cardList.isEmpty()) {
|
||||||
StackPane img = createCard(cardList.getLast(), true, true, parent);
|
StackPane img = createCard(cardList.getLast(), true, true, myHand);
|
||||||
Label label = new Label(String.valueOf(cardList.size()));
|
Label label = new Label(String.valueOf(cardList.size()));
|
||||||
label.setTranslateY(-55);
|
label.setTranslateY(-55);
|
||||||
label.setTranslateX(10);
|
label.setTranslateX(10);
|
||||||
@@ -298,13 +276,13 @@ public class MainFXMLController {
|
|||||||
StackPane.setAlignment(label, Pos.TOP_RIGHT);
|
StackPane.setAlignment(label, Pos.TOP_RIGHT);
|
||||||
img.getChildren().add(label);
|
img.getChildren().add(label);
|
||||||
img.setOnMouseClicked(e -> openPopup(new ArrayList<>(cardList)));
|
img.setOnMouseClicked(e -> openPopup(new ArrayList<>(cardList)));
|
||||||
parent.getChildren().add(img);
|
myHand.getChildren().add(img);
|
||||||
} else {
|
} else {
|
||||||
Region placeholder = new Region();
|
Region placeholder = new Region();
|
||||||
placeholder.prefHeightProperty().bind(parent.heightProperty().multiply(0.85));
|
placeholder.prefHeightProperty().bind(myHand.heightProperty().multiply(0.85));
|
||||||
placeholder.prefWidthProperty().bind(placeholder.prefHeightProperty().multiply(0.675));
|
placeholder.prefWidthProperty().bind(placeholder.prefHeightProperty().multiply(0.675));
|
||||||
placeholder.setStyle("-fx-background-color: transparent;");
|
placeholder.setStyle("-fx-background-color: transparent;");
|
||||||
parent.getChildren().add(placeholder);
|
myHand.getChildren().add(placeholder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,8 +291,15 @@ public class MainFXMLController {
|
|||||||
VBox.setMargin(card, new Insets(15,15,15,15));
|
VBox.setMargin(card, new Insets(15,15,15,15));
|
||||||
card.getStyleClass().add("player-card");
|
card.getStyleClass().add("player-card");
|
||||||
card.setPadding(new Insets(8));
|
card.setPadding(new Insets(8));
|
||||||
addHoverZoom(card);
|
|
||||||
addShadow(card);
|
if(player.getUserName().equals(controller.miniModel.currentState.getCurrentPlayer().getUserName())) {
|
||||||
|
ScaleTransition scaleUp = new ScaleTransition(Duration.millis(150), card);
|
||||||
|
scaleUp.setToX(1.1);
|
||||||
|
scaleUp.setToY(1.1);
|
||||||
|
scaleUp.play();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Riga 1: totem + nome
|
// Riga 1: totem + nome
|
||||||
HBox headerRow = new HBox(8);
|
HBox headerRow = new HBox(8);
|
||||||
@@ -482,7 +467,6 @@ public class MainFXMLController {
|
|||||||
4, new double[]{0.142, 0.316, 0.503, 0.690},
|
4, new double[]{0.142, 0.316, 0.503, 0.690},
|
||||||
5, new double[]{0.066, 0.251, 0.433, 0.617, 0.802}
|
5, new double[]{0.066, 0.251, 0.433, 0.617, 0.802}
|
||||||
);
|
);
|
||||||
|
|
||||||
double[] positions = slotPositions.get(numPlayers);
|
double[] positions = slotPositions.get(numPlayers);
|
||||||
if (positions == null) return;
|
if (positions == null) return;
|
||||||
|
|
||||||
@@ -548,27 +532,27 @@ public class MainFXMLController {
|
|||||||
myHand.setAlignment(Pos.CENTER);
|
myHand.setAlignment(Pos.CENTER);
|
||||||
|
|
||||||
Player me = controller.miniModel.players.get(controller.myUsername);
|
Player me = controller.miniModel.players.get(controller.myUsername);
|
||||||
drawMyHandList(me.artists,myHand);
|
drawMyHandList(me.artists);
|
||||||
drawMyHandList(me.gatherers,myHand);
|
drawMyHandList(me.gatherers);
|
||||||
drawMyHandList(me.inventors,myHand);
|
drawMyHandList(me.inventors);
|
||||||
drawMyHandList(me.builders,myHand);
|
drawMyHandList(me.builders);
|
||||||
drawMyHandList(me.shamans,myHand);
|
drawMyHandList(me.shamans);
|
||||||
drawMyHandList(me.hunters,myHand);
|
drawMyHandList(me.hunters);
|
||||||
drawMyHandList(me.buildingCards,myHand);
|
drawMyHandList(me.buildingCards);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderSidePanel() {
|
private void renderSidePanel() {
|
||||||
currentStateBar.getChildren().clear();
|
infoText.setText("Round: "+Integer.toString(controller.miniModel.currentState.getRound()) + " • " + controller.miniModel.currentState.getGameStage().toString());
|
||||||
currentStateBar.getChildren().add(new Label("Round:"+controller.miniModel.currentState.getRound()));
|
|
||||||
era.setText(Integer.toString(controller.miniModel.currentState.getEra()));
|
|
||||||
round.setText(Integer.toString(controller.miniModel.currentState.getRound()));
|
|
||||||
player.setText(controller.miniModel.currentState.getCurrentPlayer().getUserName());
|
|
||||||
skipBtn.setOnAction(e -> controller.skipTurn(controller.myUsername));
|
skipBtn.setOnAction(e -> controller.skipTurn(controller.myUsername));
|
||||||
// ← VBox separato solo per i player
|
detailsBtn.setOnAction(e -> openDetailsPopup());
|
||||||
VBox playerList = new VBox(6);
|
|
||||||
|
addHoverZoom(skipBtn);
|
||||||
|
addHoverZoom(detailsBtn);
|
||||||
|
|
||||||
|
VBox playerList = new VBox();
|
||||||
playerList.setFillWidth(true);
|
playerList.setFillWidth(true);
|
||||||
for (Player p : controller.miniModel.players.values()) {
|
for (Player p : controller.miniModel.players.values()) {
|
||||||
renderPlayer(p, playerList); // ← passa playerList invece di sidePanel
|
renderPlayer(p, playerList);
|
||||||
}
|
}
|
||||||
playerSide.setContent(playerList);
|
playerSide.setContent(playerList);
|
||||||
}
|
}
|
||||||
@@ -587,7 +571,7 @@ public class MainFXMLController {
|
|||||||
);
|
);
|
||||||
|
|
||||||
popup.getContent().add(popupCards);
|
popup.getContent().add(popupCards);
|
||||||
popup.setAutoHide(false); // gestito manualmente per permettere click sulle carte
|
popup.setAutoHide(false);
|
||||||
popup.addEventHandler(Event.ANY, e -> {
|
popup.addEventHandler(Event.ANY, e -> {
|
||||||
if (popup.getScene() != null) {
|
if (popup.getScene() != null) {
|
||||||
popup.getScene().setFill(Color.TRANSPARENT);
|
popup.getScene().setFill(Color.TRANSPARENT);
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
<StackPane xmlns="http://javafx.com/javafx/21"
|
<StackPane xmlns="http://javafx.com/javafx/21"
|
||||||
xmlns:fx="http://javafx.com/fxml/1"
|
xmlns:fx="http://javafx.com/fxml/1"
|
||||||
fx:controller="it.polimi.ingsw.gc14.View.GUI.LoginFXMLController"
|
fx:controller="it.polimi.ingsw.gc14.View.GUI.LoginFXMLController"
|
||||||
prefWidth="1280" prefHeight="720"
|
|
||||||
style="-fx-background-color: #09060300;"
|
style="-fx-background-color: #09060300;"
|
||||||
stylesheets="@styles.css">
|
stylesheets="@styles.css">
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,11 @@
|
|||||||
<?import javafx.scene.control.Button?>
|
<?import javafx.scene.control.Button?>
|
||||||
<HBox fx:id="mainHBox"
|
<HBox fx:id="mainHBox"
|
||||||
maxHeight="Infinity" maxWidth="Infinity"
|
maxHeight="Infinity" maxWidth="Infinity"
|
||||||
prefHeight="1080.0" prefWidth="1920.0"
|
|
||||||
xmlns="http://javafx.com/javafx/26"
|
xmlns="http://javafx.com/javafx/26"
|
||||||
xmlns:fx="http://javafx.com/fxml/1"
|
xmlns:fx="http://javafx.com/fxml/1"
|
||||||
fx:controller="it.polimi.ingsw.gc14.View.GUI.MainFXMLController"
|
fx:controller="it.polimi.ingsw.gc14.View.GUI.MainFXMLController"
|
||||||
stylesheets="@styles.css">
|
stylesheets="@styles.css">
|
||||||
|
|
||||||
<children>
|
<children>
|
||||||
<!-- VBox sinistra: si espande per riempire tutto lo spazio disponibile -->
|
<!-- VBox sinistra: si espande per riempire tutto lo spazio disponibile -->
|
||||||
<VBox alignment="CENTER"
|
<VBox alignment="CENTER"
|
||||||
@@ -23,7 +23,6 @@
|
|||||||
<Insets top="5" right="5" bottom="5" left="5" />
|
<Insets top="5" right="5" bottom="5" left="5" />
|
||||||
</HBox.margin>
|
</HBox.margin>
|
||||||
<children>
|
<children>
|
||||||
<HBox fx:id="currentStateBar" style="-fx-background-color: #ffffff59" maxHeight="30" minHeight="30" prefHeight="30" alignment="CENTER" />
|
|
||||||
<HBox fx:id="upperList" styleClass="card-list" VBox.vgrow="ALWAYS">
|
<HBox fx:id="upperList" styleClass="card-list" VBox.vgrow="ALWAYS">
|
||||||
<VBox.margin>
|
<VBox.margin>
|
||||||
<Insets top="5" right="5" bottom="5" left="5" />
|
<Insets top="5" right="5" bottom="5" left="5" />
|
||||||
@@ -61,32 +60,13 @@
|
|||||||
<Insets bottom="10" left="10" right="10" top="10" />
|
<Insets bottom="10" left="10" right="10" top="10" />
|
||||||
</HBox.margin>
|
</HBox.margin>
|
||||||
<children>
|
<children>
|
||||||
<HBox fx:id="info" prefHeight="107.0" prefWidth="483.0" styleClass="frame">
|
<HBox fx:id="info" prefHeight="107.0" prefWidth="483.0" styleClass="frame" alignment="CENTER">
|
||||||
<children>
|
<Label fx:id="infoText" styleClass="label-medium" text="VALORE" />
|
||||||
<VBox alignment="CENTER" prefHeight="107.0" prefWidth="161.0" spacing="2">
|
|
||||||
<children>
|
|
||||||
<Label styleClass="label-medium" text="Era" />
|
|
||||||
<Label fx:id="era" styleClass="label-medium" text="VALORE" />
|
|
||||||
</children>
|
|
||||||
</VBox>
|
|
||||||
<VBox alignment="CENTER" prefHeight="107.0" prefWidth="161.0" spacing="2">
|
|
||||||
<children>
|
|
||||||
<Label styleClass="label-medium" text="Round" />
|
|
||||||
<Label fx:id="round" styleClass="label-medium" text="VALORE" />
|
|
||||||
</children>
|
|
||||||
</VBox>
|
|
||||||
<VBox alignment="CENTER" prefHeight="107.0" prefWidth="161.0" spacing="2">
|
|
||||||
<children>
|
|
||||||
<Label styleClass="label-medium" text="Player" />
|
|
||||||
<Label fx:id="player" styleClass="label-medium" text="VALORE" />
|
|
||||||
</children>
|
|
||||||
</VBox>
|
|
||||||
</children>
|
|
||||||
</HBox>
|
</HBox>
|
||||||
<HBox alignment="CENTER" fx:id="buttonRow" >
|
<HBox alignment="CENTER" fx:id="buttonRow" >
|
||||||
<HBox spacing="10">
|
<HBox spacing="10">
|
||||||
<Button fx:id="skipBtn" styleClass="action-button" text="Skip Turn"/>
|
<Button fx:id="skipBtn" styleClass="action-button" text="Skip Turn"/>
|
||||||
<Button fx:id="detailsBtn" styleClass="action-button" onAction="#openDetailsPopup" text="Ending Details"/>
|
<Button fx:id="detailsBtn" styleClass="action-button" text="Ending Details"/>
|
||||||
</HBox>
|
</HBox>
|
||||||
<VBox.margin>
|
<VBox.margin>
|
||||||
<Insets top="5" right="5" bottom="5" left="5"/>
|
<Insets top="5" right="5" bottom="5" left="5"/>
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
<StackPane xmlns="http://javafx.com/javafx/21"
|
<StackPane xmlns="http://javafx.com/javafx/21"
|
||||||
xmlns:fx="http://javafx.com/fxml/1"
|
xmlns:fx="http://javafx.com/fxml/1"
|
||||||
fx:controller="it.polimi.ingsw.gc14.View.GUI.TotemFXMLController"
|
fx:controller="it.polimi.ingsw.gc14.View.GUI.TotemFXMLController"
|
||||||
prefWidth="1280" prefHeight="720"
|
|
||||||
style="-fx-background-color: #09060300;">
|
style="-fx-background-color: #09060300;">
|
||||||
<ImageView fx:id="backgroundImage" fitWidth="1920" fitHeight="1080" preserveRatio="false">
|
<ImageView fx:id="backgroundImage" fitWidth="1920" fitHeight="1080" preserveRatio="false">
|
||||||
</ImageView>
|
</ImageView>
|
||||||
|
|||||||
Reference in New Issue
Block a user