# Class Gui

java.lang.Object
javafx.application.Application
it.polimi.ingsw.is25am31.view.gui.Gui

public class Gui extends javafx.application.Application
Main JavaFX application class that serves as the central controller for the GUI. Manages the lifecycle of different game screens, coordinates between various controllers, and handles the flow of game states from initial connection through final results. Implements the Application interface to initialize the JavaFX runtime.

- ## Nested Class Summary

  ### Nested classes/interfaces inherited from class javafx.application.Application

  `javafx.application.Application.Parameters`

- ## Field Summary

  ### Fields inherited from class javafx.application.Application

  `STYLESHEET_CASPIAN, STYLESHEET_MODENA`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Gui()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `ClientModel`
  `getClient()`
  Gets the ClientModel instance.
  `CrewSelectionController`
  `getCrewSelectionController()`
  Gets the CrewSelectionController.
  `CardManagerController`
  `getCurrentCardController()`
  Gets the current CardManagerController.
  `Dashboard`
  `getDashboard()`
  Gets the Dashboard controller.
  `Dashboard2`
  `getDashboard2()`
  Gets the Dashboard2 controller.
  `GameSelectorController`
  `getGameSelectorController()`
  Gets the GameSelectorController.
  `javafx.stage.Stage`
  `getSelectedTileStage()`
  Gets the selected tile stage.
  `VirtualServer`
  `getServer()`
  Gets the VirtualServer instance.
  `Stage2Controller`
  `getStage2Controller()`
  Gets the Stage2Controller.
  `javafx.stage.Stage`
  `getStage2Stage()`
  Gets the Stage2 stage.
  `javafx.scene.control.Label`
  `getTextPrompt()`
  Gets the text prompt label.
  `WaitingRoomController`
  `getWaitingRoomController()`
  Gets the WaitingRoomController instance.
  `javafx.stage.Stage`
  `getWaitingRoomStage()`
  Gets the waiting room stage.
  `void`
  `handleConnectionEstablished(ConnectionResponse response)`
  Handles the connection response from the server and updates the UI accordingly.
  `void`
  `loadCrewPhase(Ship ship, Map<Integer,Integer> positions)`
  Loads the crew placement phase scene.
  `void`
  `loadDashboard2Scene(boolean isLeader, Ship ship)`
  Loads the dashboard scene for flight phase 2.
  `void`
  `loadDashboardScene(boolean isLeader, Ship ship)`
  Loads the dashboard scene for flight phase 1.
  `void`
  `loadFinalStage(Map<Player,Integer> ranking)`
  Loads the final stage scene showing game results.
  `void`
  `loadStage2Scene()`
  Loads the Stage 2 scene (ship assembly) and selected tile view.
  `static VirtualServer`
  `server()`
  Gets the static VirtualServer instance.
  `static void`
  `setClient(VirtualView client)`
  Sets the static VirtualView client instance.
  `static void`
  `setClientModel(ClientModel client)`
  Sets the static ClientModel instance.
  `void`
  `setCrewSelectionController(CrewSelectionController controller)`
  Sets the CrewSelectionController.
  `void`
  `setCurrentCardController(CardManagerController controller)`
  Sets the current CardManagerController.
  `void`
  `setDashboard(Dashboard dashboard)`
  Sets the Dashboard controller.
  `void`
  `setDashboard2(Dashboard2 dashboard2)`
  Sets the Dashboard2 controller.
  `void`
  `setGameSelectorController(GameSelectorController controller)`
  Sets the GameSelectorController.
  `void`
  `setGuiRenderer(GuiRenderer guiRenderer)`
  Sets the GUI renderer for this instance.
  `void`
  `setSelectedTileStage(javafx.stage.Stage stage)`
  Sets the selected tile stage.
  `static void`
  `setServer(VirtualServer server)`
  Sets the static VirtualServer instance.
  `void`
  `setStage2Controller(Stage2Controller controller)`
  Sets the Stage2Controller for this GUI instance.
  `void`
  `setStage2Stage(javafx.stage.Stage stage)`
  Sets the Stage2 stage.
  `void`
  `setWaitingRoomController(WaitingRoomController controller)`
  Sets the WaitingRoomController for this GUI instance.
  `void`
  `setWaitingRoomStage(javafx.stage.Stage stage)`
  Sets the waiting room stage.
  `void`
  `showComponentImageById(int id, Component component)`
  Shows a component image in the selected tile view.
  `void`
  `showFirstPlayerSetup()`
  Shows the first player setup UI with all fields enabled.
  `void`
  `showNicknameInput()`
  Shows the nickname input field while disabling other fields.
  `void`
  `showWaitingMessage(String message)`
  Shows a waiting message and disables all input fields.
  `void`
  `start(javafx.stage.Stage stage)`
  Starts the JavaFX application by loading the game selector view.
  `void`
  `unlockNicknameField()`
  Unlocks the nickname field for input using Platform.runLater for thread safety.
  `void`
  `updateDashboard2Scene(boolean isLeader, Ship ship)`
  Updates the dashboard2 scene with new leader status and ship state.
  `void`
  `updateDashboardScene(boolean isLeader, Ship ship)`
  Updates the dashboard scene with new leader status and ship state.
  `void`
  `updateFaceUpList(List<Component> components)`
  Updates the face-up component list in Stage2Controller.
  `void`
  `updateSubDeck(List<Card> subDeck)`
  Updates the sub-deck display in Stage2Controller.
  `void`
  `updateTimerStage(int counter, int seconds)`
  Updates the timer display in the appropriate controller.

  ### Methods inherited from class javafx.application.Application

  `getHostServices, getParameters, getUserAgentStylesheet, init, launch, launch, notifyPreloader, setUserAgentStylesheet, stop`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Gui

    public Gui()

- ## Method Details

  - ### setStage2Controller

    public void setStage2Controller(Stage2Controller controller)
    Sets the Stage2Controller for this GUI instance.
    Parameters:
      `controller` - the Stage2Controller to set

  - ### setWaitingRoomController

    public void setWaitingRoomController(WaitingRoomController controller)
    Sets the WaitingRoomController for this GUI instance.
    Parameters:
      `controller` - the WaitingRoomController to set

  - ### getWaitingRoomController

    public WaitingRoomController getWaitingRoomController()
    Gets the WaitingRoomController instance.
    Returns:
      the current WaitingRoomController

  - ### setServer

    public static void setServer(VirtualServer server)
    Sets the static VirtualServer instance.
    Parameters:
      `server` - the VirtualServer to set

  - ### server

    public static VirtualServer server()
    Gets the static VirtualServer instance.
    Returns:
      the current VirtualServer

  - ### setClientModel

    public static void setClientModel(ClientModel client)
    Sets the static ClientModel instance.
    Parameters:
      `client` - the ClientModel to set

  - ### setClient

    public static void setClient(VirtualView client)
    Sets the static VirtualView client instance.
    Parameters:
      `client` - the VirtualView to set

  - ### start

    public void start(javafx.stage.Stage stage) throws Exception
    Starts the JavaFX application by loading the game selector view.
    Specified by:
      `start` in class `javafx.application.Application`
    Parameters:
      `stage` - the primary stage for the application
    Throws:
      `Exception` - if the FXML file cannot be loaded

  - ### handleConnectionEstablished

    public void handleConnectionEstablished(ConnectionResponse response)
    Handles the connection response from the server and updates the UI accordingly.
    Parameters:
      `response` - the ConnectionResponse indicating the connection status

  - ### showFirstPlayerSetup

    public void showFirstPlayerSetup()
    Shows the first player setup UI with all fields enabled. Allows setting player count, game level, and nickname.

  - ### showWaitingMessage

    public void showWaitingMessage(String message)
    Shows a waiting message and disables all input fields.
    Parameters:
      `message` - the waiting message to display

  - ### showNicknameInput

    public void showNicknameInput()
    Shows the nickname input field while disabling other fields. Checks if already waiting for other players to prevent re-enabling.

  - ### getTextPrompt

    public javafx.scene.control.Label getTextPrompt()
    Gets the text prompt label.
    Returns:
      the text prompt label

  - ### setGuiRenderer

    public void setGuiRenderer(GuiRenderer guiRenderer)
    Sets the GUI renderer for this instance.
    Parameters:
      `guiRenderer` - the GuiRenderer to set

  - ### unlockNicknameField

    public void unlockNicknameField()
    Unlocks the nickname field for input using Platform.runLater for thread safety.

  - ### loadStage2Scene

    public void loadStage2Scene() throws IOException
    Loads the Stage 2 scene (ship assembly) and selected tile view.
    Throws:
      `IOException` - if FXML files cannot be loaded

  - ### showComponentImageById

    public void showComponentImageById(int id, Component component)
    Shows a component image in the selected tile view.
    Parameters:
      `id` - the component ID
      `component` - the component to display

  - ### getSelectedTileStage

    public javafx.stage.Stage getSelectedTileStage()
    Gets the selected tile stage.
    Returns:
      the selected tile stage

  - ### setSelectedTileStage

    public void setSelectedTileStage(javafx.stage.Stage stage)
    Sets the selected tile stage.
    Parameters:
      `stage` - the stage to set

  - ### getServer

    public VirtualServer getServer()
    Gets the VirtualServer instance.
    Returns:
      the current VirtualServer

  - ### getClient

    public ClientModel getClient()
    Gets the ClientModel instance.
    Returns:
      the current ClientModel

  - ### updateFaceUpList

    public void updateFaceUpList(List<Component> components)
    Updates the face-up component list in Stage2Controller.
    Parameters:
      `components` - the list of components to display

  - ### updateTimerStage

    public void updateTimerStage(int counter, int seconds)
    Updates the timer display in the appropriate controller.
    Parameters:
      `counter` - the current count
      `seconds` - the total seconds

  - ### setStage2Stage

    public void setStage2Stage(javafx.stage.Stage stage)
    Sets the Stage2 stage.
    Parameters:
      `stage` - the stage to set

  - ### getStage2Stage

    public javafx.stage.Stage getStage2Stage()
    Gets the Stage2 stage.
    Returns:
      the Stage2 stage

  - ### setWaitingRoomStage

    public void setWaitingRoomStage(javafx.stage.Stage stage)
    Sets the waiting room stage.
    Parameters:
      `stage` - the stage to set

  - ### loadCrewPhase

    public void loadCrewPhase(Ship ship, Map<Integer,Integer> positions) throws IOException
    Loads the crew placement phase scene.
    Parameters:
      `ship` - the player's ship
      `positions` - the component positions map
    Throws:
      `IOException` - if FXML file cannot be loaded

  - ### setCrewSelectionController

    public void setCrewSelectionController(CrewSelectionController controller)
    Sets the CrewSelectionController.
    Parameters:
      `controller` - the controller to set

  - ### getCrewSelectionController

    public CrewSelectionController getCrewSelectionController()
    Gets the CrewSelectionController.
    Returns:
      the current CrewSelectionController

  - ### getStage2Controller

    public Stage2Controller getStage2Controller()
    Gets the Stage2Controller.
    Returns:
      the current Stage2Controller

  - ### loadDashboardScene

    public void loadDashboardScene(boolean isLeader, Ship ship) throws IOException
    Loads the dashboard scene for flight phase 1.
    Parameters:
      `isLeader` - whether the player is the current leader
      `ship` - the player's ship
    Throws:
      `IOException` - if FXML file cannot be loaded

  - ### updateDashboardScene

    public void updateDashboardScene(boolean isLeader, Ship ship) throws IOException
    Updates the dashboard scene with new leader status and ship state.
    Parameters:
      `isLeader` - whether the player is the current leader
      `ship` - the player's ship (can be null)
    Throws:
      `IOException` - if update fails

  - ### getWaitingRoomStage

    public javafx.stage.Stage getWaitingRoomStage()
    Gets the waiting room stage.
    Returns:
      the waiting room stage

  - ### updateDashboard2Scene

    public void updateDashboard2Scene(boolean isLeader, Ship ship) throws IOException
    Updates the dashboard2 scene with new leader status and ship state.
    Parameters:
      `isLeader` - whether the player is the current leader
      `ship` - the player's ship (can be null)
    Throws:
      `IOException` - if update fails

  - ### loadDashboard2Scene

    public void loadDashboard2Scene(boolean isLeader, Ship ship) throws IOException
    Loads the dashboard scene for flight phase 2.
    Parameters:
      `isLeader` - whether the player is the current leader
      `ship` - the player's ship
    Throws:
      `IOException` - if FXML file cannot be loaded

  - ### updateSubDeck

    public void updateSubDeck(List<Card> subDeck)
    Updates the sub-deck display in Stage2Controller.
    Parameters:
      `subDeck` - the list of cards in the sub-deck

  - ### setDashboard2

    public void setDashboard2(Dashboard2 dashboard2)
    Sets the Dashboard2 controller.
    Parameters:
      `dashboard2` - the controller to set

  - ### setDashboard

    public void setDashboard(Dashboard dashboard)
    Sets the Dashboard controller.
    Parameters:
      `dashboard` - the controller to set

  - ### getDashboard2

    public Dashboard2 getDashboard2()
    Gets the Dashboard2 controller.
    Returns:
      the current Dashboard2 controller

  - ### getDashboard

    public Dashboard getDashboard()
    Gets the Dashboard controller.
    Returns:
      the current Dashboard controller

  - ### setCurrentCardController

    public void setCurrentCardController(CardManagerController controller)
    Sets the current CardManagerController.
    Parameters:
      `controller` - the controller to set

  - ### getCurrentCardController

    public CardManagerController getCurrentCardController()
    Gets the current CardManagerController.
    Returns:
      the current CardManagerController

  - ### loadFinalStage

    public void loadFinalStage(Map<Player,Integer> ranking)
    Loads the final stage scene showing game results.
    Parameters:
      `ranking` - the final ranking of all players

  - ### setGameSelectorController

    public void setGameSelectorController(GameSelectorController controller)
    Sets the GameSelectorController.
    Parameters:
      `controller` - the controller to set

  - ### getGameSelectorController

    public GameSelectorController getGameSelectorController()
    Gets the GameSelectorController.
    Returns:
      the current GameSelectorController