Class MainFXMLController

java.lang.Object
it.polimi.ingsw.gc14.View.GUI.MainFXMLController

public class MainFXMLController extends Object
FXML controller for the main game scene.

Renders the board (upper/lower tribe and building card rows), player stats, the player's hand, and action buttons (skip, details).

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private javafx.scene.layout.HBox
    HBox holding the board slot and order cards.
    Client controller for fetching game state and sending player actions.
    private javafx.scene.control.Button
    Button that opens the game details popup.
    private final Map<String, javafx.scene.control.Label>
    Maps each player's username to their current food-value label in the side panel.
    private final Map<String, List<javafx.scene.image.ImageView>>
    Maps each player's username to their ordered list of card-type icon ImageViews.
    private static final Map<String, javafx.scene.image.Image>
     
    private javafx.scene.control.Label
    Label showing the current round number and game stage.
    private boolean
    true when the last received event was an error response.
    private javafx.scene.layout.HBox
    HBox holding the lower tribe card row (and lower building stack).
    private javafx.scene.layout.HBox
    Root HBox containing all main scene elements.
    private javafx.scene.layout.HBox
    HBox displaying the local player's card piles.
    private final Map<String, javafx.scene.layout.VBox>
    Maps each player's username to their player-card VBox in the side panel.
    private javafx.scene.control.ScrollPane
    Scrollable container holding all player side-panel cards.
    private javafx.stage.Popup
    Shared popup used for card previews and building selection.
    private javafx.scene.layout.HBox
    HBox inside popup that holds the displayed card images.
    private final Map<String, javafx.scene.control.Label>
    Maps each player's username to their current prestige-value label in the side panel.
    private javafx.scene.control.Button
    Button that disconnects and closes the client.
    private javafx.scene.control.Button
    Button that sends a skip-turn command.
    private javafx.scene.layout.HBox
    HBox holding the upper tribe card row (and upper building stack).
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    addClip(javafx.scene.image.ImageView img)
    Binds a rounded-rectangle clip to img so its corners are cropped.
    private void
    addHoverZoom(javafx.scene.Node node)
    Scales node to 1.1× on hover and restores on exit; sets a hand cursor.
    private void
    addShadow(javafx.scene.Node node)
    Applies a drop-shadow to node that intensifies on hover.
    private javafx.scene.layout.VBox
    Builds the side-panel card widget for player with totem, stats, and card-type icons.
    private void
    Builds the full side panel from scratch, creating a player card for each connected player.
    private javafx.scene.layout.StackPane
    createCard(PlayableCard card, boolean withZoom, boolean withShadow, javafx.scene.layout.Region parent)
    Creates a StackPane for a playable card, scaling its height to a fraction of parent's scene.
    private javafx.scene.layout.StackPane
    createCardPopup(PlayableCard card, boolean withZoom, boolean withShadow)
    Creates a fixed-height StackPane card widget suitable for use inside the popup.
    private javafx.scene.layout.StackPane
    Creates a StackPane containing the order card image for a game of num players.
    private javafx.scene.layout.StackPane
    createSlot(Slot slot, boolean withZoom, boolean withShadow)
    Creates a StackPane for a board slot, optionally overlaying the occupying player's totem.
    private void
    Renders the top card of the lower building stack with a count badge; clicking opens the selection popup.
    private void
    drawMyHandList(ArrayList<? extends PlayableCard> cardList)
    Renders a single card-type pile in the hand area, or an invisible placeholder if the list is empty.
    private void
    Renders the top card of the upper building stack with a count badge; clicking opens the selection popup.
    getPlayerCards(String username, String type)
    Returns a copy of the named card collection for username.
    void
    Initializes the scene: loads fonts, sets up the popup, and registers input listeners.
    private void
    Creates and configures the shared card-preview popup container.
    private javafx.scene.image.Image
    Returns a cached Image for the given classpath path, loading it on first access.
    private void
    Shows the deck details/rules card in the popup.
    private void
    openPopup(ArrayList<? extends PlayableCard> cardList)
    Populates the popup with non-clickable card images and shows it.
    private void
    Populates the popup with clickable lower-building cards; clicking one draws it via the controller.
    private void
    Populates the popup with clickable upper-building cards; clicking one draws it via the controller.
    void
    Incrementally re-renders only the parts of the scene affected by the last network event.
    private void
    Sets the full-cover background image on the main HBox container.
    private void
    Clears the board area and orchestrates deck, order card, and slot-map rendering.
    private void
    Adds the era-specific deck back image to the board.
    private void
    Clears and rebuilds the lower tribe row with click handlers for drawing, then appends the lower building stack.
    private void
    Clears and re-renders all seven card-type piles in the local player's hand area.
    private void
    Renders the order card and overlays each player's totem at their proportional position.
    private void
    Adds a clickable slot widget for each entry in the slot-player map.
    private void
    Clears and rebuilds the upper tribe row with click handlers for drawing, then appends the upper building stack.
    void
    Injects the client controller and wires up the skip-turn button action.
    void
    setError(boolean error)
    Sets the error flag; called by GUI before delegating to render().
    private void
    Centers the popup over the current window and makes it visible.
    private void
    Updates food/prestige labels, current-player highlight, card-icon opacity, and plays error shake if needed.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • playerSide

      private javafx.scene.control.ScrollPane playerSide
      Scrollable container holding all player side-panel cards.
    • mainHBox

      private javafx.scene.layout.HBox mainHBox
      Root HBox containing all main scene elements.
    • board

      private javafx.scene.layout.HBox board
      HBox holding the board slot and order cards.
    • upperList

      private javafx.scene.layout.HBox upperList
      HBox holding the upper tribe card row (and upper building stack).
    • lowerList

      private javafx.scene.layout.HBox lowerList
      HBox holding the lower tribe card row (and lower building stack).
    • myHand

      private javafx.scene.layout.HBox myHand
      HBox displaying the local player's card piles.
    • skipBtn

      private javafx.scene.control.Button skipBtn
      Button that sends a skip-turn command.
    • detailsBtn

      private javafx.scene.control.Button detailsBtn
      Button that opens the game details popup.
    • quitBtn

      private javafx.scene.control.Button quitBtn
      Button that disconnects and closes the client.
    • infoText

      private javafx.scene.control.Label infoText
      Label showing the current round number and game stage.
    • foodLabels

      private final Map<String, javafx.scene.control.Label> foodLabels
      Maps each player's username to their current food-value label in the side panel.
    • prestigeLabels

      private final Map<String, javafx.scene.control.Label> prestigeLabels
      Maps each player's username to their current prestige-value label in the side panel.
    • playerCards

      private final Map<String, javafx.scene.layout.VBox> playerCards
      Maps each player's username to their player-card VBox in the side panel.
    • iconViews

      private final Map<String, List<javafx.scene.image.ImageView>> iconViews
      Maps each player's username to their ordered list of card-type icon ImageViews.
    • popupCards

      private javafx.scene.layout.HBox popupCards
      HBox inside popup that holds the displayed card images.
    • controller

      private ClientController controller
      Client controller for fetching game state and sending player actions.
    • isError

      private boolean isError
      true when the last received event was an error response.
    • imageCache

      private static final Map<String, javafx.scene.image.Image> imageCache
  • Constructor Details

    • MainFXMLController

      public MainFXMLController()
  • Method Details

    • setError

      public void setError(boolean error)
      Sets the error flag; called by GUI before delegating to render().
      Parameters:
      error - true if the last received event was an error response.
    • loadImage

      private javafx.scene.image.Image loadImage(String path)
      Returns a cached Image for the given classpath path, loading it on first access.
    • setController

      public void setController(ClientController controller)
      Injects the client controller and wires up the skip-turn button action.
      Parameters:
      controller - the client controller to use.
    • initialize

      public void initialize()
      Initializes the scene: loads fonts, sets up the popup, and registers input listeners.
    • render

      public void render()
      Incrementally re-renders only the parts of the scene affected by the last network event.
    • addClip

      private void addClip(javafx.scene.image.ImageView img)
      Binds a rounded-rectangle clip to img so its corners are cropped.
    • addHoverZoom

      private void addHoverZoom(javafx.scene.Node node)
      Scales node to 1.1× on hover and restores on exit; sets a hand cursor.
    • addShadow

      private void addShadow(javafx.scene.Node node)
      Applies a drop-shadow to node that intensifies on hover.
    • buildPlayerCard

      private javafx.scene.layout.VBox buildPlayerCard(Player player)
      Builds the side-panel card widget for player with totem, stats, and card-type icons.
    • createOrder

      private javafx.scene.layout.StackPane createOrder(String num)
      Creates a StackPane containing the order card image for a game of num players.
    • createSlot

      private javafx.scene.layout.StackPane createSlot(Slot slot, boolean withZoom, boolean withShadow)
      Creates a StackPane for a board slot, optionally overlaying the occupying player's totem.
    • createCard

      private javafx.scene.layout.StackPane createCard(PlayableCard card, boolean withZoom, boolean withShadow, javafx.scene.layout.Region parent)
      Creates a StackPane for a playable card, scaling its height to a fraction of parent's scene.
    • buildSidePanel

      private void buildSidePanel()
      Builds the full side panel from scratch, creating a player card for each connected player.
    • updateSidePanel

      private void updateSidePanel()
      Updates food/prestige labels, current-player highlight, card-icon opacity, and plays error shake if needed.
    • drawUpperBuilding

      private void drawUpperBuilding()
      Renders the top card of the upper building stack with a count badge; clicking opens the selection popup.
    • drawLowerBuilding

      private void drawLowerBuilding()
      Renders the top card of the lower building stack with a count badge; clicking opens the selection popup.
    • drawMyHandList

      private void drawMyHandList(ArrayList<? extends PlayableCard> cardList)
      Renders a single card-type pile in the hand area, or an invisible placeholder if the list is empty.
    • getPlayerCards

      private ArrayList<PlayableCard> getPlayerCards(String username, String type)
      Returns a copy of the named card collection for username.
    • renderUpper

      private void renderUpper()
      Clears and rebuilds the upper tribe row with click handlers for drawing, then appends the upper building stack.
    • renderLower

      private void renderLower()
      Clears and rebuilds the lower tribe row with click handlers for drawing, then appends the lower building stack.
    • renderBackground

      private void renderBackground()
      Sets the full-cover background image on the main HBox container.
    • renderBoard

      private void renderBoard()
      Clears the board area and orchestrates deck, order card, and slot-map rendering.
    • renderDeck

      private void renderDeck()
      Adds the era-specific deck back image to the board.
    • renderOrder

      private void renderOrder()
      Renders the order card and overlays each player's totem at their proportional position.
    • renderSlotMap

      private void renderSlotMap()
      Adds a clickable slot widget for each entry in the slot-player map.
    • renderMyHand

      private void renderMyHand()
      Clears and re-renders all seven card-type piles in the local player's hand area.
    • initPopup

      private void initPopup()
      Creates and configures the shared card-preview popup container.
    • showPopup

      private void showPopup()
      Centers the popup over the current window and makes it visible.
    • openPopup

      private void openPopup(ArrayList<? extends PlayableCard> cardList)
      Populates the popup with non-clickable card images and shows it.
    • openPopupUpperBuilding

      private void openPopupUpperBuilding(ArrayList<BuildingCard> cardList)
      Populates the popup with clickable upper-building cards; clicking one draws it via the controller.
    • openPopupLowerBuilding

      private void openPopupLowerBuilding(ArrayList<BuildingCard> cardList)
      Populates the popup with clickable lower-building cards; clicking one draws it via the controller.
    • openDetailsPopup

      private void openDetailsPopup()
      Shows the deck details/rules card in the popup.
    • createCardPopup

      private javafx.scene.layout.StackPane createCardPopup(PlayableCard card, boolean withZoom, boolean withShadow)
      Creates a fixed-height StackPane card widget suitable for use inside the popup.