Class CharacterSelectScene

java.lang.Object
application.CharacterSelectScene

public class CharacterSelectScene extends Object
Character selection screen for both players. P1 selects first and confirms with Enter, then P2 selects. Supports both keyboard (A/D to move, Enter to confirm) and mouse click.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final double
    Width of the selection arrow.
    private final double
    Y position of the arrow.
    private javafx.scene.media.MediaPlayer
    Background music player.
    private javafx.scene.layout.StackPane
    Container for the confirm buttons at the bottom.
    private final double
    Spacing between characters.
    private final double
    Width of each character image.
    private final String[]
    Class names for all 4 characters.
    private javafx.scene.image.ImageView[]
    ImageViews for all 4 character images.
    private final String[]
    Stat descriptions for each character shown in the info box.
    private javafx.scene.control.Button
    Confirm button for P1.
    private javafx.scene.control.Button
    Confirm button for P2.
    private javafx.scene.layout.VBox
    Box displaying the stat info of the currently highlighted character.
    private javafx.scene.text.Text
    Stat text inside the info box.
    private boolean
    Whether it is currently P1's turn to select.
    private javafx.scene.layout.StackPane
    Root layout for this screen.
    Callback invoked when both players have confirmed their characters; receives P1's and P2's classes.
    private javafx.scene.layout.Pane
    Wrapper pane for P1's selection arrow.
    private int
    Index of the character currently selected by P1 (0-3).
    private javafx.scene.layout.Pane
    Wrapper pane for P2's selection arrow.
    private int
    Index of the character currently selected by P2 (0-3).
    private javafx.scene.layout.BorderPane
    Main layout.
    private javafx.scene.Scene
    Main JavaFX Scene for this screen.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates the character selection screen with all UI components and sets up keyboard/mouse listeners.
  • Method Summary

    Modifier and Type
    Method
    Description
    private javafx.scene.layout.Pane
    Creates an arrow wrapper with a floating animation.
    private javafx.scene.layout.StackPane
    Creates the bottom Confirm button section; initially shows P1's button and switches to P2's after P1 confirms.
    private javafx.scene.layout.Pane
    Creates the center section displaying all 4 character images, selection arrows, and the stat info box.
    private javafx.scene.control.Button
    Creates an image-based button with a hover effect.
    private javafx.scene.layout.HBox
    Creates the top header section showing the "Choose your character" image.
    javafx.scene.media.MediaPlayer
    Returns the BGM MediaPlayer for stopping before switching screens.
    javafx.scene.Scene
    Returns the Scene for this screen.
    private void
    highlightSelectedCharacter(int activeIndex)
    Enlarges the highlighted character and dims the others, and updates the info box.
    void
    Sets the callback to be invoked when both players have confirmed their characters.
    private void
    Sets up keyboard listeners and character-confirmation logic.
    void
    updateArrowPositions(int p1Index, int p2Index, boolean isP2Turn)
    Moves the arrows to the selected indices and highlights the pointed-to character.

    Methods inherited from class java.lang.Object

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

    • CHAR_WIDTH

      private final double CHAR_WIDTH
      Width of each character image.
      See Also:
    • CHAR_SPACING

      private final double CHAR_SPACING
      Spacing between characters.
      See Also:
    • ARROW_WIDTH

      private final double ARROW_WIDTH
      Width of the selection arrow.
      See Also:
    • ARROW_Y_POS

      private final double ARROW_Y_POS
      Y position of the arrow.
      See Also:
    • scene

      private javafx.scene.Scene scene
      Main JavaFX Scene for this screen.
    • mainRoot

      private javafx.scene.layout.StackPane mainRoot
      Root layout for this screen.
    • rootPane

      private javafx.scene.layout.BorderPane rootPane
      Main layout.
    • characterClasses

      private final String[] characterClasses
      Class names for all 4 characters.
    • characterInfos

      private final String[] characterInfos
      Stat descriptions for each character shown in the info box.
    • characterImageViews

      private javafx.scene.image.ImageView[] characterImageViews
      ImageViews for all 4 character images.
    • p1ArrowWrapper

      private javafx.scene.layout.Pane p1ArrowWrapper
      Wrapper pane for P1's selection arrow.
    • p2ArrowWrapper

      private javafx.scene.layout.Pane p2ArrowWrapper
      Wrapper pane for P2's selection arrow.
    • confirmP1Btn

      private javafx.scene.control.Button confirmP1Btn
      Confirm button for P1.
    • confirmP2Btn

      private javafx.scene.control.Button confirmP2Btn
      Confirm button for P2.
    • bottomButtonContainer

      private javafx.scene.layout.StackPane bottomButtonContainer
      Container for the confirm buttons at the bottom.
    • bgmPlayer

      private javafx.scene.media.MediaPlayer bgmPlayer
      Background music player.
    • onGameStartHandler

      private BiConsumer<String,String> onGameStartHandler
      Callback invoked when both players have confirmed their characters; receives P1's and P2's classes.
    • infoBox

      private javafx.scene.layout.VBox infoBox
      Box displaying the stat info of the currently highlighted character.
    • infoText

      private javafx.scene.text.Text infoText
      Stat text inside the info box.
    • isP1Turn

      private boolean isP1Turn
      Whether it is currently P1's turn to select.
    • p1SelectedIndex

      private int p1SelectedIndex
      Index of the character currently selected by P1 (0-3).
    • p2SelectedIndex

      private int p2SelectedIndex
      Index of the character currently selected by P2 (0-3).
  • Constructor Details

    • CharacterSelectScene

      public CharacterSelectScene()
      Creates the character selection screen with all UI components and sets up keyboard/mouse listeners.
  • Method Details

    • createTopChoose

      private javafx.scene.layout.HBox createTopChoose()
      Creates the top header section showing the "Choose your character" image.
      Returns:
      The header as an HBox
    • createCenterCharacters

      private javafx.scene.layout.Pane createCenterCharacters()
      Creates the center section displaying all 4 character images, selection arrows, and the stat info box.
      Returns:
      The center section as a Pane
    • createArrowWrapper

      private javafx.scene.layout.Pane createArrowWrapper(String path)
      Creates an arrow wrapper with a floating animation.
      Parameters:
      path - Path to the arrow image (P1 or P2)
      Returns:
      A Pane containing the floating arrow
    • createBottomButtons

      private javafx.scene.layout.StackPane createBottomButtons()
      Creates the bottom Confirm button section; initially shows P1's button and switches to P2's after P1 confirms.
      Returns:
      A StackPane containing both confirm buttons
    • createImageButton

      private javafx.scene.control.Button createImageButton(String imagePath)
      Creates an image-based button with a hover effect.
      Parameters:
      imagePath - Path to the button image
      Returns:
      A Button using an image instead of text
    • updateArrowPositions

      public void updateArrowPositions(int p1Index, int p2Index, boolean isP2Turn)
      Moves the arrows to the selected indices and highlights the pointed-to character.
      Parameters:
      p1Index - Index selected by P1 (0-3)
      p2Index - Index selected by P2 (0-3)
      isP2Turn - Whether it is P2's turn (if so, P2's arrow is also shown)
    • highlightSelectedCharacter

      private void highlightSelectedCharacter(int activeIndex)
      Enlarges the highlighted character and dims the others, and updates the info box.
      Parameters:
      activeIndex - Index of the currently highlighted character
    • setupController

      private void setupController()
      Sets up keyboard listeners and character-confirmation logic. P1 uses A/D to move and Enter to confirm; P2 uses the same keys in turn. When P2 confirms, onGameStartHandler is called with both players' classes.
    • getScene

      public javafx.scene.Scene getScene()
      Returns the Scene for this screen.
      Returns:
      The character selection Scene
    • getBgmPlayer

      public javafx.scene.media.MediaPlayer getBgmPlayer()
      Returns the BGM MediaPlayer for stopping before switching screens.
      Returns:
      The BGM MediaPlayer
    • setOnGameStart

      public void setOnGameStart(BiConsumer<String,String> handler)
      Sets the callback to be invoked when both players have confirmed their characters.
      Parameters:
      handler - BiConsumer that receives P1's class and P2's class respectively