Package edu.ntnu.idi.idatt.view.common
Class MenuView
java.lang.Object
javafx.scene.Node
javafx.scene.Parent
javafx.scene.layout.Region
javafx.scene.layout.Pane
javafx.scene.layout.VBox
edu.ntnu.idi.idatt.view.common.MenuView
- All Implemented Interfaces:
ButtonClickSubject
,javafx.css.Styleable
,javafx.event.EventTarget
- Direct Known Subclasses:
LadderGameMenuView
,LudoGameMenuView
MenuView.
Abstract base class for game menu views, providing common UI structure and functionality for player selection, board selection, and navigation controls.
It manages a list of MenuPlayerRow
s, displays board information via a
BoardStackPane
,
and handles actions like adding/removing players, importing/saving configurations, and starting
the game. This class implements ButtonClickSubject
to notify observers (typically a
MenuController
) of user interactions.
- See Also:
-
Property Summary
Properties inherited from class javafx.scene.layout.VBox
alignment, fillWidth, spacing
Properties inherited from class javafx.scene.layout.Region
background, border, cacheShape, centerShape, height, insets, maxHeight, maxWidth, minHeight, minWidth, opaqueInsets, padding, prefHeight, prefWidth, scaleShape, shape, snapToPixel, width
Properties inherited from class javafx.scene.Parent
needsLayout
Properties inherited from class javafx.scene.Node
accessibleHelp, accessibleRoleDescription, accessibleRole, accessibleText, blendMode, boundsInLocal, boundsInParent, cacheHint, cache, clip, cursor, depthTest, disabled, disable, effectiveNodeOrientation, effect, eventDispatcher, focused, focusTraversable, focusVisible, focusWithin, hover, id, inputMethodRequests, layoutBounds, layoutX, layoutY, localToParentTransform, localToSceneTransform, managed, mouseTransparent, nodeOrientation, onContextMenuRequested, onDragDetected, onDragDone, onDragDropped, onDragEntered, onDragExited, onDragOver, onInputMethodTextChanged, onKeyPressed, onKeyReleased, onKeyTyped, onMouseClicked, onMouseDragEntered, onMouseDragExited, onMouseDragged, onMouseDragOver, onMouseDragReleased, onMouseEntered, onMouseExited, onMouseMoved, onMousePressed, onMouseReleased, onRotate, onRotationFinished, onRotationStarted, onScrollFinished, onScroll, onScrollStarted, onSwipeDown, onSwipeLeft, onSwipeRight, onSwipeUp, onTouchMoved, onTouchPressed, onTouchReleased, onTouchStationary, onZoomFinished, onZoom, onZoomStarted, opacity, parent, pickOnBounds, pressed, rotate, rotationAxis, scaleX, scaleY, scaleZ, scene, style, translateX, translateY, translateZ, viewOrder, visible
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final javafx.scene.layout.HBox
protected final List
<PlayerTokenType> protected final javafx.scene.control.Label
protected javafx.scene.layout.VBox
protected javafx.scene.layout.HBox
protected final BoardStackPane
protected final javafx.scene.control.Label
protected static final org.slf4j.Logger
protected final List
<MenuPlayerRow> protected int
protected int
protected final List
<ButtonClickObserver> protected final javafx.scene.layout.VBox
protected javafx.scene.layout.VBox
protected javafx.scene.layout.HBox
protected Board
protected final javafx.scene.control.Button
Fields inherited from class javafx.scene.layout.Region
USE_COMPUTED_SIZE, USE_PREF_SIZE
Fields inherited from class javafx.scene.Node
BASELINE_OFFSET_SAME_AS_HEIGHT
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
MenuView
(BoardStackPane boardStackPane) Constructs a MenuView. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addObserver
(ButtonClickObserver observer) Adds aButtonClickObserver
to be notified of button clicks in this menu.protected void
addPlayerRow
(String defaultName, javafx.scene.paint.Color color, boolean removable, boolean isBot) Adds a newMenuPlayerRow
to the player list.protected javafx.scene.layout.VBox
Creates the board selection section of the menu, including a title, options menu (import/create), the board display/carousel, and board information (title, description).protected javafx.scene.layout.HBox
createHeaderBox
(String title) Creates the header HBox for the menu view, containing a back button and the menu title.protected javafx.scene.layout.VBox
Creates the player selection section of the menu, including a title, options menu (import/save), the list of player rows, and buttons to add new players or bots.protected void
disableStartGameButton
(String toolTipText) Disables the "Start Game" button and sets a tooltip with the provided text.protected void
Enables the "Start Game" button and removes any associated tooltip.Returns the list ofMenuPlayerRow
s currently displayed in the menu.protected void
Handles the action to navigate to the board creation screen.protected void
Handles the action to import a board from a file.protected void
Handles the action to import players from a file.protected void
Handles the action to save the current player list to a file.void
initialize
(String title, List<PlayerTokenType> allowedPlayerTokenTypes, List<String> allowedPlayerColors, int minimumPlayers, int maximumPlayers) Initializes the menu view with a title and configuration for player and board selection.void
notifyObservers
(String buttonId) Notifies all registered observers of a button click event.void
notifyObserversWithParams
(String buttonId, Map<String, Object> params) Notifies all registered observers of a button click event that includes parameters.void
removeObserver
(ButtonClickObserver observer) Removes aButtonClickObserver
from this menu.protected void
removePlayerRow
(MenuPlayerRow mainMenuPlayerRow) Removes the specifiedMenuPlayerRow
from the player list.void
setPlayers
(List<Player> players) Replaces the current player rows in the menu with new rows based on the provided list ofPlayer
s.abstract void
setSelectedBoard
(Board board) Sets the currently selected board and updates the view to display its information.void
showErrorAlert
(String headerText, String message) Displays an error alert dialog.void
showInfoAlert
(String headerText, String message) Displays an information alert dialog.protected void
Updates the visibility of add player/bot buttons and callsvalidatePlayers()
to enable/disable the start game button based on the current player configuration.protected abstract void
Validates the current player setup (e.g., number of players, unique colors/tokens) and enables/disables the start game button accordingly.Methods inherited from class javafx.scene.layout.VBox
alignmentProperty, clearConstraints, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, fillWidthProperty, getAlignment, getClassCssMetaData, getContentBias, getCssMetaData, getMargin, getSpacing, getVgrow, isFillWidth, layoutChildren, requestLayout, setAlignment, setFillWidth, setMargin, setSpacing, setVgrow, spacingProperty
Methods inherited from class javafx.scene.layout.Pane
getChildren
Methods inherited from class javafx.scene.layout.Region
backgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, computeMaxHeight, computeMaxWidth, getBackground, getBorder, getHeight, getInsets, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpaqueInsets, getPadding, getPrefHeight, getPrefWidth, getShape, getUserAgentStylesheet, getWidth, heightProperty, insetsProperty, isCacheShape, isCenterShape, isResizable, isScaleShape, isSnapToPixel, layoutInArea, layoutInArea, layoutInArea, layoutInArea, maxHeight, maxHeightProperty, maxWidth, maxWidthProperty, minHeight, minHeightProperty, minWidth, minWidthProperty, opaqueInsetsProperty, paddingProperty, positionInArea, positionInArea, prefHeight, prefHeightProperty, prefWidth, prefWidthProperty, resize, scaleShapeProperty, setBackground, setBorder, setCacheShape, setCenterShape, setHeight, setMaxHeight, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinWidth, setOpaqueInsets, setPadding, setPrefHeight, setPrefSize, setPrefWidth, setScaleShape, setShape, setSnapToPixel, setWidth, shapeProperty, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, snapToPixelProperty, widthProperty
Methods inherited from class javafx.scene.Parent
getBaselineOffset, getChildrenUnmodifiable, getManagedChildren, getStylesheets, isNeedsLayout, layout, lookup, needsLayoutProperty, queryAccessibleAttribute, requestParentLayout, setNeedsLayout, updateBounds
Methods inherited from class javafx.scene.Node
accessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, executeAccessibleAction, fireEvent, focusedProperty, focusTraversableProperty, focusVisibleProperty, focusWithinProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClip, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInitialCursor, getInitialFocusTraversable, getInputMethodRequests, getLayoutBounds, getLayoutX, getLayoutY, getLocalToParentTransform, getLocalToSceneTransform, getNodeOrientation, getOnContextMenuRequested, getOnDragDetected, getOnDragDone, getOnDragDropped, getOnDragEntered, getOnDragExited, getOnDragOver, getOnInputMethodTextChanged, getOnKeyPressed, getOnKeyReleased, getOnKeyTyped, getOnMouseClicked, getOnMouseDragEntered, getOnMouseDragExited, getOnMouseDragged, getOnMouseDragOver, getOnMouseDragReleased, getOnMouseEntered, getOnMouseExited, getOnMouseMoved, getOnMousePressed, getOnMouseReleased, getOnRotate, getOnRotationFinished, getOnRotationStarted, getOnScroll, getOnScrollFinished, getOnScrollStarted, getOnSwipeDown, getOnSwipeLeft, getOnSwipeRight, getOnSwipeUp, getOnTouchMoved, getOnTouchPressed, getOnTouchReleased, getOnTouchStationary, getOnZoom, getOnZoomFinished, getOnZoomStarted, getOpacity, getParent, getProperties, getPseudoClassStates, getRotate, getRotationAxis, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleableParent, getStyleClass, getTransforms, getTranslateX, getTranslateY, getTranslateZ, getTypeSelector, getUserData, getViewOrder, hasProperties, hoverProperty, idProperty, inputMethodRequestsProperty, intersects, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isFocusVisible, isFocusWithin, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, isVisible, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToParent, localToParent, localToParentTransformProperty, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToSceneTransformProperty, localToScreen, localToScreen, localToScreen, localToScreen, localToScreen, lookupAll, managedProperty, mouseTransparentProperty, nodeOrientationProperty, notifyAccessibleAttributeChanged, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onInputMethodTextChangedProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDragEnteredProperty, onMouseDragExitedProperty, onMouseDraggedProperty, onMouseDragOverProperty, onMouseDragReleasedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onRotateProperty, onRotationFinishedProperty, onRotationStartedProperty, onScrollFinishedProperty, onScrollProperty, onScrollStartedProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, onZoomFinishedProperty, onZoomProperty, onZoomStartedProperty, opacityProperty, parentProperty, parentToLocal, parentToLocal, parentToLocal, parentToLocal, parentToLocal, pickOnBoundsProperty, pressedProperty, pseudoClassStateChanged, relocate, removeEventFilter, removeEventHandler, requestFocus, resizeRelocate, rotateProperty, rotationAxisProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, screenToLocal, screenToLocal, screenToLocal, setAccessibleHelp, setAccessibleRole, setAccessibleRoleDescription, setAccessibleText, setBlendMode, setCache, setCacheHint, setClip, setCursor, setDepthTest, setDisable, setDisabled, setEffect, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setInputMethodRequests, setLayoutX, setLayoutY, setManaged, setMouseTransparent, setNodeOrientation, setOnContextMenuRequested, setOnDragDetected, setOnDragDone, setOnDragDropped, setOnDragEntered, setOnDragExited, setOnDragOver, setOnInputMethodTextChanged, setOnKeyPressed, setOnKeyReleased, setOnKeyTyped, setOnMouseClicked, setOnMouseDragEntered, setOnMouseDragExited, setOnMouseDragged, setOnMouseDragOver, setOnMouseDragReleased, setOnMouseEntered, setOnMouseExited, setOnMouseMoved, setOnMousePressed, setOnMouseReleased, setOnRotate, setOnRotationFinished, setOnRotationStarted, setOnScroll, setOnScrollFinished, setOnScrollStarted, setOnSwipeDown, setOnSwipeLeft, setOnSwipeRight, setOnSwipeUp, setOnTouchMoved, setOnTouchPressed, setOnTouchReleased, setOnTouchStationary, setOnZoom, setOnZoomFinished, setOnZoomStarted, setOpacity, setPickOnBounds, setPressed, setRotate, setRotationAxis, setScaleX, setScaleY, setScaleZ, setStyle, setTranslateX, setTranslateY, setTranslateZ, setUserData, setViewOrder, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, viewOrderProperty, visibleProperty
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface javafx.css.Styleable
getStyleableNode
-
Field Details
-
logger
protected static final org.slf4j.Logger logger -
observers
-
allowedPlayerTokenTypes
-
allowedPlayerColors
-
minimumPlayers
protected int minimumPlayers -
maximumPlayers
protected int maximumPlayers -
playerSelectionBox
protected javafx.scene.layout.VBox playerSelectionBox -
playerSelectionHeader
protected javafx.scene.layout.HBox playerSelectionHeader -
mainMenuPlayerRows
-
addPlayerButtonsBox
protected final javafx.scene.layout.HBox addPlayerButtonsBox -
playerListBox
protected final javafx.scene.layout.VBox playerListBox -
boardSelectionBox
protected javafx.scene.layout.VBox boardSelectionBox -
boardSelectionHeader
protected javafx.scene.layout.HBox boardSelectionHeader -
boardStackPane
-
boardTitle
protected final javafx.scene.control.Label boardTitle -
boardDescription
protected final javafx.scene.control.Label boardDescription -
startGameButton
protected final javafx.scene.control.Button startGameButton -
selectedBoard
-
-
Constructor Details
-
MenuView
Constructs a MenuView.- Parameters:
boardStackPane
- TheBoardStackPane
used to display the selected board preview.
-
-
Method Details
-
validatePlayers
protected abstract void validatePlayers()Validates the current player setup (e.g., number of players, unique colors/tokens) and enables/disables the start game button accordingly. Subclasses must implement the specific validation logic. -
setSelectedBoard
Sets the currently selected board and updates the view to display its information.- Parameters:
board
- TheBoard
to be displayed.
-
initialize
public void initialize(String title, List<PlayerTokenType> allowedPlayerTokenTypes, List<String> allowedPlayerColors, int minimumPlayers, int maximumPlayers) Initializes the menu view with a title and configuration for player and board selection.- Parameters:
title
- The title to be displayed at the top of the menu.allowedPlayerTokenTypes
- A list ofPlayerTokenType
s allowed for players.allowedPlayerColors
- A list of hex color strings allowed for players.minimumPlayers
- The minimum number of players required to start the game.maximumPlayers
- The maximum number of players allowed in the game.
-
getPlayerRows
Returns the list ofMenuPlayerRow
s currently displayed in the menu.- Returns:
- A list of player rows.
-
createHeaderBox
Creates the header HBox for the menu view, containing a back button and the menu title.- Parameters:
title
- The title text to display in the header.- Returns:
- The configured
HBox
for the header.
-
createPlayerSelectionBox
protected javafx.scene.layout.VBox createPlayerSelectionBox()Creates the player selection section of the menu, including a title, options menu (import/save), the list of player rows, and buttons to add new players or bots.- Returns:
- A
VBox
containing the player selection UI elements.
-
createBoardSelectionBox
protected javafx.scene.layout.VBox createBoardSelectionBox()Creates the board selection section of the menu, including a title, options menu (import/create), the board display/carousel, and board information (title, description).- Returns:
- A
VBox
containing the board selection UI elements.
-
setPlayers
Replaces the current player rows in the menu with new rows based on the provided list ofPlayer
s.- Parameters:
players
- The list of players to display.
-
addPlayerRow
protected void addPlayerRow(String defaultName, javafx.scene.paint.Color color, boolean removable, boolean isBot) Adds a newMenuPlayerRow
to the player list.- Parameters:
defaultName
- The default name for the new player.color
- The initial color for the new player's token.removable
- Whether the new player row can be removed.isBot
- Whether the new player is a bot.
-
removePlayerRow
Removes the specifiedMenuPlayerRow
from the player list.- Parameters:
mainMenuPlayerRow
- The player row to remove.
-
updateControls
protected void updateControls()Updates the visibility of add player/bot buttons and callsvalidatePlayers()
to enable/disable the start game button based on the current player configuration. -
disableStartGameButton
Disables the "Start Game" button and sets a tooltip with the provided text.- Parameters:
toolTipText
- The text to display in the tooltip when the button is hovered.
-
enableStartGameButton
protected void enableStartGameButton()Enables the "Start Game" button and removes any associated tooltip. -
handleSavePlayers
protected void handleSavePlayers()Handles the action to save the current player list to a file. Opens aFileChooser
and notifies observers with the selected file. -
handleImportPlayers
protected void handleImportPlayers()Handles the action to import players from a file. Opens aFileChooser
and notifies observers with the selected file. -
handleImportBoard
protected void handleImportBoard()Handles the action to import a board from a file. Opens aFileChooser
and notifies observers with the selected file. -
handleCreateBoard
protected void handleCreateBoard()Handles the action to navigate to the board creation screen. Notifies observers with the "create_board" action ID. -
showInfoAlert
Displays an information alert dialog.- Parameters:
headerText
- The header text for the alert.message
- The main message content for the alert.
-
showErrorAlert
Displays an error alert dialog.- Parameters:
headerText
- The header text for the alert.message
- The main message content for the alert.
-
addObserver
Adds aButtonClickObserver
to be notified of button clicks in this menu.- Specified by:
addObserver
in interfaceButtonClickSubject
- Parameters:
observer
- The observer to add.
-
removeObserver
Removes aButtonClickObserver
from this menu.- Specified by:
removeObserver
in interfaceButtonClickSubject
- Parameters:
observer
- The observer to remove.
-
notifyObservers
Notifies all registered observers of a button click event.- Specified by:
notifyObservers
in interfaceButtonClickSubject
- Parameters:
buttonId
- The ID of the button that was clicked.
-
notifyObserversWithParams
Notifies all registered observers of a button click event that includes parameters.- Specified by:
notifyObserversWithParams
in interfaceButtonClickSubject
- Parameters:
buttonId
- The ID of the button that was clicked.params
- A map of parameters associated with the button click.
-