java.lang.Object
javafx.application.Application
it.polimi.ingsw.am13.client.view.gui.ViewGUI
- All Implemented Interfaces:
View
This class is the JavaFX application, and it implements the View interface.
It initializes the stage when it is called by ClientMain.
Then, every time a show method is called, it changes the scene by using the corresponding fxml file if it is
necessary, and it calls the corresponding method on the controller.
-
Nested Class Summary
Nested classes/interfaces inherited from class javafx.application.Application
javafx.application.Application.Parameters
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ViewGUIController
Controller currently activeprivate static final boolean
private ViewGUIControllerInit
Controller of 'Init' scene, where the player must complete the initialization part of the gameprivate String
IP address of the serverprivate boolean
This variable if the client is connected via socket, false otherwiseprivate ViewGUIControllerJoinedRoom
Controller of 'JoinedRoom' scene, where player can wait for the room to get full or can leave the roomprivate ViewGUIControllerMatch
Controller of 'Match' scene, where player can actually play the most of the gameprivate NetworkHandler
The network handler which is used to communicate with the serverprivate int
Port of the serverprivate ViewGUIControllerRooms
Controller of the 'Rooms' scene, where the rooms are listed and the user can create/join/reconnect to a roomprivate static final int
private static final int
private javafx.stage.Stage
The stage on which the application is displayedprivate GameState
The representation of the state of the gameprivate PlayerLobby
The player corresponding to a specific instance ofViewGUI
.private ViewGUIControllerWinner
Controller of 'Winner' scene, where the final points and the winner are shownFields inherited from class javafx.application.Application
STYLESHEET_CASPIAN, STYLESHEET_MODENA
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate <T extends ViewGUIController>
TcreateScene
(Class<T> controllerClass, String fxmlName) Utility function to load the FXML file for a scene of the game and load its controllervoid
Force closing the app.static void
void
setNetworkHandler
(NetworkHandler networkHandler) Calls the corresponding method on viewGUIControllervoid
showChatMessage
(PlayerLobby sender, List<PlayerLobby> receivers) Shows a chat messagevoid
It displays that a player chose his personal objective, by calling the corresponding method onViewGUIController
void
It calls the corresponding method onViewGUIController
.void
Shows a generic exception in the view (specific exception could be handled in different ways, also depending on the phase or the state of game)void
Shows the game entering the final phase (last turns before adding extra points)void
It shows the game entering the turn-based phase, by changing the scene and calling the corresponding method onViewGUIController
void
It shows the game moving on to the next turn by calling the corresponding method onViewGUIController
void
showPickedCard
(PlayerLobby player) It shows a player picking a card, by calling the corresponding method onViewGUIController
void
showPlayedCard
(PlayerLobby player, Coordinates coord) Shows a player placing one of their hand cards on the field, by calling the corresponding method onViewGUIController
void
showPlayedStarter
(PlayerLobby player) It displays that a player chose the side for his starter card, by calling the corresponding method onViewGUIController
void
showPlayerDisconnected
(PlayerLobby player) It shows that a player disconnected from the game by calling the corresponding method onViewGUIController
.void
showPlayerJoinedRoom
(PlayerLobby player) If thisPlayer is null, it sets it, changes the scene to the joined room scene and calls getRooms.void
showPlayerLeftRoom
(PlayerLobby player) If the player who left the room is thisPlayer, it switches the scene to the rooms' scene.void
showPlayerReconnected
(PlayerLobby player) It shows that a player reconnected to the game by calling the corresponding method onViewGUIController
.void
Shows the list of rooms returned by the server, which the player can join/reconnect to.void
showStartGame
(GameState state, Chat chat) It switches the scene to the init scene, where each player can choose the side of his starter card and his personal objective.void
showStartGameReconnected
(GameState state, PlayerLobby thisPlayer, Chat chat) It sets state and thisPlayer.void
showStartupScreen
(boolean isSocket, String ip, int port) It calls the corresponding method on the controller.void
It shows the updated points after the turn-based phase is finished by calling the corresponding method onViewGUIController
void
It shows the winner by calling the corresponding method onViewGUIController
.void
start
(javafx.stage.Stage stage) This method is executed when this application is launched byClientMain
.private void
switchToScene
(ViewGUIController controller) Switches a scene, showing another scene based on the associated controller.Methods inherited from class javafx.application.Application
getHostServices, getParameters, getUserAgentStylesheet, init, launch, launch, notifyPreloader, setUserAgentStylesheet, stop
-
Field Details
-
FULLSCREEN_MODE
private static final boolean FULLSCREEN_MODE- See Also:
-
sceneWidth
private static final int sceneWidth- See Also:
-
sceneHeight
private static final int sceneHeight- See Also:
-
roomsController
Controller of the 'Rooms' scene, where the rooms are listed and the user can create/join/reconnect to a room -
joinedRoomController
Controller of 'JoinedRoom' scene, where player can wait for the room to get full or can leave the room -
initController
Controller of 'Init' scene, where the player must complete the initialization part of the game -
matchController
Controller of 'Match' scene, where player can actually play the most of the game -
winnerController
Controller of 'Winner' scene, where the final points and the winner are shown -
currentController
Controller currently active -
stage
private javafx.stage.Stage stageThe stage on which the application is displayed -
networkHandler
The network handler which is used to communicate with the server -
state
The representation of the state of the game -
thisPlayer
The player corresponding to a specific instance ofViewGUI
. It is initialized as null, set whenever a room is joined or created, and set to null whenever they leave a room. -
isSocket
private boolean isSocketThis variable if the client is connected via socket, false otherwise -
ip
IP address of the server -
port
private int portPort of the server
-
-
Constructor Details
-
ViewGUI
public ViewGUI()
-
-
Method Details
-
start
This method is executed when this application is launched byClientMain
. It sets the stage, and it loads the first scene, which is the one where players can see, join, create, reconnect to rooms. It also calls the getRooms method on the networkHandler.- Specified by:
start
in classjavafx.application.Application
- Parameters:
stage
- the stage of this application (which will never be changed throughout the execution)- Throws:
Exception
- if loading the scene fails
-
createScene
private <T extends ViewGUIController> T createScene(Class<T> controllerClass, String fxmlName) throws IOException Utility function to load the FXML file for a scene of the game and load its controller- Type Parameters:
T
- Class type of the controller, specified as parameter- Parameters:
controllerClass
- Class of the controller associated to the scenefxmlName
- Name of the FXML file for the scene- Returns:
- Controller loaded to handle the scene
- Throws:
IOException
- ???
-
switchToScene
Switches a scene, showing another scene based on the associated controller. It effectively shows the scene, sets the scene title, and sets the parametersthisPlayer
andstate
The current controller is updated, too.- Parameters:
controller
- Controller associated to the scene to switch to
-
setNetworkHandler
Calls the corresponding method on viewGUIController- Specified by:
setNetworkHandler
in interfaceView
- Parameters:
networkHandler
- Handler of the network
-
showStartupScreen
It calls the corresponding method on the controller.- Specified by:
showStartupScreen
in interfaceView
- Parameters:
isSocket
- true if the connection is via socketip
- of the connectionport
- of the connection
-
showException
Shows a generic exception in the view (specific exception could be handled in different ways, also depending on the phase or the state of game)- Specified by:
showException
in interfaceView
- Parameters:
e
- Exception to be shown
-
showRooms
Shows the list of rooms returned by the server, which the player can join/reconnect to. It is called every time a player creates, leaves or joins a room, in order to keep the view up to date. If it is called after this player has joined a room, it is used to initialise the table of players inside the room with this player and all the other players who joined the room before. -
showPlayerJoinedRoom
If thisPlayer is null, it sets it, changes the scene to the joined room scene and calls getRooms. Otherwise, it calls the corresponding method in viewGUIController.- Specified by:
showPlayerJoinedRoom
in interfaceView
- Parameters:
player
- Player who joined the room
-
showPlayerLeftRoom
If the player who left the room is thisPlayer, it switches the scene to the rooms' scene. Otherwise, it calls the getRooms method so that the rooms are updated.- Specified by:
showPlayerLeftRoom
in interfaceView
- Parameters:
player
- Player who left the room
-
showStartGame
It switches the scene to the init scene, where each player can choose the side of his starter card and his personal objective. Then it calls the corresponding method in theViewGUIController
.- Specified by:
showStartGame
in interfaceView
- Parameters:
state
- Reference to the game's state which is kept up to date
-
showStartGameReconnected
It sets state and thisPlayer. Then, depending on theGameStatus
, it calls the appropriate show method.- Specified by:
showStartGameReconnected
in interfaceView
- Parameters:
state
- GameState of the started matchthisPlayer
- Player linked to this client which is reconnecting to the match
-
showPlayedStarter
It displays that a player chose the side for his starter card, by calling the corresponding method onViewGUIController
- Specified by:
showPlayedStarter
in interfaceView
- Parameters:
player
- Player who played their starter card
-
showChosenPersonalObjective
It displays that a player chose his personal objective, by calling the corresponding method onViewGUIController
- Specified by:
showChosenPersonalObjective
in interfaceView
- Parameters:
player
- Player who chose their personal objective card
-
showInGame
public void showInGame()It shows the game entering the turn-based phase, by changing the scene and calling the corresponding method onViewGUIController
- Specified by:
showInGame
in interfaceView
-
showPlayedCard
Shows a player placing one of their hand cards on the field, by calling the corresponding method onViewGUIController
- Specified by:
showPlayedCard
in interfaceView
- Parameters:
player
- Player who placed the card on fieldcoord
- Coordinates of the field where the card has been placed
-
showPickedCard
It shows a player picking a card, by calling the corresponding method onViewGUIController
- Specified by:
showPickedCard
in interfaceView
- Parameters:
player
- Player who picked a card
-
showNextTurn
public void showNextTurn()It shows the game moving on to the next turn by calling the corresponding method onViewGUIController
- Specified by:
showNextTurn
in interfaceView
-
showFinalPhase
public void showFinalPhase()Description copied from interface:View
Shows the game entering the final phase (last turns before adding extra points)- Specified by:
showFinalPhase
in interfaceView
-
showUpdatePoints
public void showUpdatePoints()It shows the updated points after the turn-based phase is finished by calling the corresponding method onViewGUIController
- Specified by:
showUpdatePoints
in interfaceView
-
showWinner
public void showWinner()It shows the winner by calling the corresponding method onViewGUIController
. It also calls showUpdatePoints() if it has not already been called (which might happen if thisPlayer won because he was the only one connected for the defined time).- Specified by:
showWinner
in interfaceView
-
showEndGame
public void showEndGame()It calls the corresponding method onViewGUIController
.- Specified by:
showEndGame
in interfaceView
-
showPlayerDisconnected
It shows that a player disconnected from the game by calling the corresponding method onViewGUIController
.- Specified by:
showPlayerDisconnected
in interfaceView
- Parameters:
player
- Player who disconnected
-
showPlayerReconnected
It shows that a player reconnected to the game by calling the corresponding method onViewGUIController
.- Specified by:
showPlayerReconnected
in interfaceView
- Parameters:
player
- Player who reconnected
-
showChatMessage
Shows a chat message- Specified by:
showChatMessage
in interfaceView
- Parameters:
sender
- of the messagereceivers
- of the message
-
forceCloseApp
public void forceCloseApp()Force closing the app. It should be used to end the app for anomalous reasons- Specified by:
forceCloseApp
in interfaceView
-
main
-