java.lang.Object
javafx.application.Application
it.polimi.ingsw.am13.client.view.gui.ViewGUI
All Implemented Interfaces:
View

public class ViewGUI extends javafx.application.Application implements 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.
  • 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

      private ViewGUIControllerRooms roomsController
      Controller of the 'Rooms' scene, where the rooms are listed and the user can create/join/reconnect to a room
    • joinedRoomController

      private ViewGUIControllerJoinedRoom joinedRoomController
      Controller of 'JoinedRoom' scene, where player can wait for the room to get full or can leave the room
    • initController

      private ViewGUIControllerInit initController
      Controller of 'Init' scene, where the player must complete the initialization part of the game
    • matchController

      private ViewGUIControllerMatch matchController
      Controller of 'Match' scene, where player can actually play the most of the game
    • winnerController

      private ViewGUIControllerWinner winnerController
      Controller of 'Winner' scene, where the final points and the winner are shown
    • currentController

      private ViewGUIController currentController
      Controller currently active
    • stage

      private javafx.stage.Stage stage
      The stage on which the application is displayed
    • networkHandler

      private NetworkHandler networkHandler
      The network handler which is used to communicate with the server
    • state

      private GameState state
      The representation of the state of the game
    • thisPlayer

      private PlayerLobby thisPlayer
      The player corresponding to a specific instance of ViewGUI. 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 isSocket
      This variable if the client is connected via socket, false otherwise
    • ip

      private String ip
      IP address of the server
    • port

      private int port
      Port of the server
  • Constructor Details

    • ViewGUI

      public ViewGUI()
  • Method Details

    • start

      public void start(javafx.stage.Stage stage) throws Exception
      This method is executed when this application is launched by ClientMain. 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 class javafx.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 scene
      fxmlName - Name of the FXML file for the scene
      Returns:
      Controller loaded to handle the scene
      Throws:
      IOException - ???
    • switchToScene

      private void switchToScene(ViewGUIController controller)
      Switches a scene, showing another scene based on the associated controller. It effectively shows the scene, sets the scene title, and sets the parameters thisPlayer and state The current controller is updated, too.
      Parameters:
      controller - Controller associated to the scene to switch to
    • setNetworkHandler

      public void setNetworkHandler(NetworkHandler networkHandler)
      Calls the corresponding method on viewGUIController
      Specified by:
      setNetworkHandler in interface View
      Parameters:
      networkHandler - Handler of the network
    • showStartupScreen

      public void showStartupScreen(boolean isSocket, String ip, int port)
      It calls the corresponding method on the controller.
      Specified by:
      showStartupScreen in interface View
      Parameters:
      isSocket - true if the connection is via socket
      ip - of the connection
      port - of the connection
    • showException

      public void showException(Exception e)
      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 interface View
      Parameters:
      e - Exception to be shown
    • showRooms

      public void showRooms(List<RoomIF> rooms)
      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.
      Specified by:
      showRooms in interface View
      Parameters:
      rooms - List of rooms
    • showPlayerJoinedRoom

      public void showPlayerJoinedRoom(PlayerLobby player)
      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 interface View
      Parameters:
      player - Player who joined the room
    • showPlayerLeftRoom

      public void showPlayerLeftRoom(PlayerLobby player)
      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 interface View
      Parameters:
      player - Player who left the room
    • showStartGame

      public 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. Then it calls the corresponding method in the ViewGUIController.
      Specified by:
      showStartGame in interface View
      Parameters:
      state - Reference to the game's state which is kept up to date
    • showStartGameReconnected

      public void showStartGameReconnected(GameState state, PlayerLobby thisPlayer, Chat chat)
      It sets state and thisPlayer. Then, depending on the GameStatus, it calls the appropriate show method.
      Specified by:
      showStartGameReconnected in interface View
      Parameters:
      state - GameState of the started match
      thisPlayer - Player linked to this client which is reconnecting to the match
    • showPlayedStarter

      public void showPlayedStarter(PlayerLobby player)
      It displays that a player chose the side for his starter card, by calling the corresponding method on ViewGUIController
      Specified by:
      showPlayedStarter in interface View
      Parameters:
      player - Player who played their starter card
    • showChosenPersonalObjective

      public void showChosenPersonalObjective(PlayerLobby player)
      It displays that a player chose his personal objective, by calling the corresponding method on ViewGUIController
      Specified by:
      showChosenPersonalObjective in interface View
      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 on ViewGUIController
      Specified by:
      showInGame in interface View
    • showPlayedCard

      public void showPlayedCard(PlayerLobby player, Coordinates coord)
      Shows a player placing one of their hand cards on the field, by calling the corresponding method on ViewGUIController
      Specified by:
      showPlayedCard in interface View
      Parameters:
      player - Player who placed the card on field
      coord - Coordinates of the field where the card has been placed
    • showPickedCard

      public void showPickedCard(PlayerLobby player)
      It shows a player picking a card, by calling the corresponding method on ViewGUIController
      Specified by:
      showPickedCard in interface View
      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 on ViewGUIController
      Specified by:
      showNextTurn in interface View
    • 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 interface View
    • showUpdatePoints

      public void showUpdatePoints()
      It shows the updated points after the turn-based phase is finished by calling the corresponding method on ViewGUIController
      Specified by:
      showUpdatePoints in interface View
    • showWinner

      public void showWinner()
      It shows the winner by calling the corresponding method on ViewGUIController. 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 interface View
    • showEndGame

      public void showEndGame()
      It calls the corresponding method on ViewGUIController.
      Specified by:
      showEndGame in interface View
    • showPlayerDisconnected

      public void showPlayerDisconnected(PlayerLobby player)
      It shows that a player disconnected from the game by calling the corresponding method on ViewGUIController.
      Specified by:
      showPlayerDisconnected in interface View
      Parameters:
      player - Player who disconnected
    • showPlayerReconnected

      public void showPlayerReconnected(PlayerLobby player)
      It shows that a player reconnected to the game by calling the corresponding method on ViewGUIController.
      Specified by:
      showPlayerReconnected in interface View
      Parameters:
      player - Player who reconnected
    • showChatMessage

      public void showChatMessage(PlayerLobby sender, List<PlayerLobby> receivers)
      Shows a chat message
      Specified by:
      showChatMessage in interface View
      Parameters:
      sender - of the message
      receivers - 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 interface View
    • main

      public static void main(String[] args)