Package com.csse3200.game.ui.dialoguebox
Class DialogueBox
java.lang.Object
com.csse3200.game.ui.dialoguebox.DialogueBox
Represents a chat overlay UI component that displays a series of hint messages
and allows navigation between them using forward and backward buttons.
-
Constructor Summary
ConstructorsConstructorDescriptionDialogueBox
(com.badlogic.gdx.scenes.scene2d.Stage stage) Creates a new base DialogueBox with the given hint messages.DialogueBox
(String[][] labelText) Creates a new DialogueBox with the given hint messages. -
Method Summary
Modifier and TypeMethodDescriptioncom.badlogic.gdx.scenes.scene2d.ui.TextButton
createOptionButton
(int index) Creates the optionButton.void
Creates the playButton for booting up mini-gamesvoid
dialogueBoxInitialisation
(boolean hide) void
dispose()
Removes all components of the dialogue box from the stage.com.badlogic.gdx.scenes.scene2d.ui.TextButton
Returns the TextButton instance used for the "Back" (backward) action.int
Returns the index of the current hint being displayed.int
Returns the index of the current hint line being displayed.com.badlogic.gdx.scenes.scene2d.ui.TextButton
Returns the TextButton instance used for the "Continue" (forward) action.String[][]
getHints()
Returns the array of hint messages.boolean
Returns whether the dialogueBox is visible or not.com.badlogic.gdx.scenes.scene2d.ui.Label
getLabel()
Returns the Label object used for displaying hints.com.badlogic.gdx.scenes.scene2d.ui.TextButton[]
Gets the option buttons.void
Handles the backward button click event to navigate to the previous hint.void
Handles the forward button click event to navigate to the next hint.void
handleOptionButtonClick
(int index) Handles the option button click event to navigate to the specific hint.void
Hides the dialogue box by setting all its components (background image, label, and buttons) to invisible.minigameCheck
(String text) Checks if the current text on the label contains either of the following flags at the beginning of the string.optionsCheck
(String text) Checks if the current text on the label contains either of the following flags at the beginning of the string.void
Hides or removes the "Continue" button (forward button) from the dialogue box.void
Resizes the background image for formattingvoid
Resizes and spaces the buttons based on the number of currently visible options.static void
Sets the GdxGame for any services that require it (should not be used unless necessary).void
Determines when to hide and show forward / backward buttons on clicks.void
showDialogueBox
(String[][] hints) Displays the dialogue box with the provided hint messages.
-
Constructor Details
-
DialogueBox
public DialogueBox(com.badlogic.gdx.scenes.scene2d.Stage stage) Creates a new base DialogueBox with the given hint messages. -
DialogueBox
Creates a new DialogueBox with the given hint messages.- Parameters:
labelText
- The array of hint messages to display.
-
-
Method Details
-
setGame
Sets the GdxGame for any services that require it (should not be used unless necessary). Errors if the game is set twice- Parameters:
g
- the instance of GdxGame that is running
-
dialogueBoxInitialisation
public void dialogueBoxInitialisation(boolean hide) -
resizeElements
public void resizeElements()Resizes the background image for formatting -
createPlayButton
public void createPlayButton()Creates the playButton for booting up mini-games -
createOptionButton
public com.badlogic.gdx.scenes.scene2d.ui.TextButton createOptionButton(int index) Creates the optionButton.- Parameters:
index
- the option index- Returns:
- the optionButton instance.
-
getHints
Returns the array of hint messages.- Returns:
- An array of strings containing the hint messages.
-
getCurrentHint
public int getCurrentHint()Returns the index of the current hint being displayed.- Returns:
- The index of the current hint.
-
getCurrentHintLine
public int getCurrentHintLine()Returns the index of the current hint line being displayed.- Returns:
- The index of the current hint line.
-
getLabel
public com.badlogic.gdx.scenes.scene2d.ui.Label getLabel()Returns the Label object used for displaying hints.- Returns:
- The Label instance for displaying hints.
-
handleForwardButtonClick
public void handleForwardButtonClick()Handles the forward button click event to navigate to the next hint. Updates the label text to the next hint in the array and repositions the label. -
handleBackwardButtonClick
public void handleBackwardButtonClick()Handles the backward button click event to navigate to the previous hint. Updates the label text to the previous hint in the array and repositions the label. -
resizeOptionButtons
public void resizeOptionButtons()Resizes and spaces the buttons based on the number of currently visible options. -
showAppropriateButtons
public void showAppropriateButtons()Determines when to hide and show forward / backward buttons on clicks. -
handleOptionButtonClick
public void handleOptionButtonClick(int index) Handles the option button click event to navigate to the specific hint. Updates the label text to the certain hint in the array and repositions the label. -
getOptionButtons
public com.badlogic.gdx.scenes.scene2d.ui.TextButton[] getOptionButtons()Gets the option buttons.- Returns:
- the array of option buttons.
-
minigameCheck
Checks if the current text on the label contains either of the following flags at the beginning of the string. This then shows the playButton and assigns the corresponding mini-game to be played. /ms: mini-game snake /mb: mini-game birdie dash /mu: underwater maze- Parameters:
text
- the label text to be shown in the dialogue.- Returns:
- the altered text without the flag to be shown in the dialogue box.
-
optionsCheck
Checks if the current text on the label contains either of the following flags at the beginning of the string. This then shows the option buttons. /c: indicates that this is a dialogue with options /s00: string after this is one of the options user can choose. The number is replaced with what index the option takes the user to- Parameters:
text
- the label text to be shown in the dialogue.- Returns:
- the altered text without the flag to be shown in the dialogue box.
-
hideDialogueBox
public void hideDialogueBox()Hides the dialogue box by setting all its components (background image, label, and buttons) to invisible. -
showDialogueBox
Displays the dialogue box with the provided hint messages. Sets the first hint message, shows all components (background image, label, and buttons), and resets the current hint index to 0.- Parameters:
hints
- An array of strings containing the hint messages to display.
-
removeContinueButton
public void removeContinueButton()Hides or removes the "Continue" button (forward button) from the dialogue box. -
dispose
public void dispose()Removes all components of the dialogue box from the stage. This should be called to clean up resources when the dialogue box is no longer needed. -
getForwardButton
public com.badlogic.gdx.scenes.scene2d.ui.TextButton getForwardButton()Returns the TextButton instance used for the "Continue" (forward) action.- Returns:
- The TextButton instance for the forward button.
-
getBackwardButton
public com.badlogic.gdx.scenes.scene2d.ui.TextButton getBackwardButton()Returns the TextButton instance used for the "Back" (backward) action.- Returns:
- The TextButton instance for the backward button.
-
getIsVisible
public boolean getIsVisible()Returns whether the dialogueBox is visible or not.- Returns:
- boolean representing if the dialogue box is visible.
-