Class CharacterSelectScene
java.lang.Object
application.CharacterSelectScene
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
FieldsModifier and TypeFieldDescriptionprivate final doubleWidth of the selection arrow.private final doubleY position of the arrow.private javafx.scene.media.MediaPlayerBackground music player.private javafx.scene.layout.StackPaneContainer for the confirm buttons at the bottom.private final doubleSpacing between characters.private final doubleWidth 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.ButtonConfirm button for P1.private javafx.scene.control.ButtonConfirm button for P2.private javafx.scene.layout.VBoxBox displaying the stat info of the currently highlighted character.private javafx.scene.text.TextStat text inside the info box.private booleanWhether it is currently P1's turn to select.private javafx.scene.layout.StackPaneRoot layout for this screen.private BiConsumer<String, String> Callback invoked when both players have confirmed their characters; receives P1's and P2's classes.private javafx.scene.layout.PaneWrapper pane for P1's selection arrow.private intIndex of the character currently selected by P1 (0-3).private javafx.scene.layout.PaneWrapper pane for P2's selection arrow.private intIndex of the character currently selected by P2 (0-3).private javafx.scene.layout.BorderPaneMain layout.private javafx.scene.SceneMain JavaFX Scene for this screen. -
Constructor Summary
ConstructorsConstructorDescriptionCreates the character selection screen with all UI components and sets up keyboard/mouse listeners. -
Method Summary
Modifier and TypeMethodDescriptionprivate javafx.scene.layout.PanecreateArrowWrapper(String path) Creates an arrow wrapper with a floating animation.private javafx.scene.layout.StackPaneCreates the bottom Confirm button section; initially shows P1's button and switches to P2's after P1 confirms.private javafx.scene.layout.PaneCreates the center section displaying all 4 character images, selection arrows, and the stat info box.private javafx.scene.control.ButtoncreateImageButton(String imagePath) Creates an image-based button with a hover effect.private javafx.scene.layout.HBoxCreates the top header section showing the "Choose your character" image.javafx.scene.media.MediaPlayerReturns the BGM MediaPlayer for stopping before switching screens.javafx.scene.ScenegetScene()Returns the Scene for this screen.private voidhighlightSelectedCharacter(int activeIndex) Enlarges the highlighted character and dims the others, and updates the info box.voidsetOnGameStart(BiConsumer<String, String> handler) Sets the callback to be invoked when both players have confirmed their characters.private voidSets up keyboard listeners and character-confirmation logic.voidupdateArrowPositions(int p1Index, int p2Index, boolean isP2Turn) Moves the arrows to the selected indices and highlights the pointed-to character.
-
Field Details
-
CHAR_WIDTH
private final double CHAR_WIDTHWidth of each character image.- See Also:
-
CHAR_SPACING
private final double CHAR_SPACINGSpacing between characters.- See Also:
-
ARROW_WIDTH
private final double ARROW_WIDTHWidth of the selection arrow.- See Also:
-
ARROW_Y_POS
private final double ARROW_Y_POSY position of the arrow.- See Also:
-
scene
private javafx.scene.Scene sceneMain JavaFX Scene for this screen. -
mainRoot
private javafx.scene.layout.StackPane mainRootRoot layout for this screen. -
rootPane
private javafx.scene.layout.BorderPane rootPaneMain layout. -
characterClasses
Class names for all 4 characters. -
characterInfos
Stat descriptions for each character shown in the info box. -
characterImageViews
private javafx.scene.image.ImageView[] characterImageViewsImageViews for all 4 character images. -
p1ArrowWrapper
private javafx.scene.layout.Pane p1ArrowWrapperWrapper pane for P1's selection arrow. -
p2ArrowWrapper
private javafx.scene.layout.Pane p2ArrowWrapperWrapper pane for P2's selection arrow. -
confirmP1Btn
private javafx.scene.control.Button confirmP1BtnConfirm button for P1. -
confirmP2Btn
private javafx.scene.control.Button confirmP2BtnConfirm button for P2. -
bottomButtonContainer
private javafx.scene.layout.StackPane bottomButtonContainerContainer for the confirm buttons at the bottom. -
bgmPlayer
private javafx.scene.media.MediaPlayer bgmPlayerBackground music player. -
onGameStartHandler
Callback invoked when both players have confirmed their characters; receives P1's and P2's classes. -
infoBox
private javafx.scene.layout.VBox infoBoxBox displaying the stat info of the currently highlighted character. -
infoText
private javafx.scene.text.Text infoTextStat text inside the info box. -
isP1Turn
private boolean isP1TurnWhether it is currently P1's turn to select. -
p1SelectedIndex
private int p1SelectedIndexIndex of the character currently selected by P1 (0-3). -
p2SelectedIndex
private int p2SelectedIndexIndex 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
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
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
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
-