User Tools

Site Tools


docs:textdialog

A Text Dialog box that can be shown with text at the bottom of the screen. It optionally supports getting input from the player in the form of single answer multiple choice questions, multiple answer multiple choice questions, and free form input questions.

The TextDialog node is loaded as a child of the autoloaded UI node.

Usage

Creating a Frame

A Frame represents all of the information that the dialog box needs in order to render a single box worth of text. The available frames types are listed below:

  • TextFrame: Display text
  • InputFrame: Display text, and ask for freeform input
  • MultipleAnswerFrame: Display text, and present checkboxes to select from
  • MultipleChoiceFrame: Display text, and present buttons to select from
# Let's start with a a simple TextFrame
var frame1: TextFrame = TextFrame.new()
frame1.text = "This is example text."

# And make a slightly more complicated MultipleChoiceFrame
var frame2: MultipleChoiceFrame = MultipleChoiceFrame.new()
frame2.text = "This is an example question."
frame2.choices = ["How is this a question?", "Okay"]

Adding Frames and Displaying

After all of the frames have been created you can send them all to the dialog and tell it to start displaying them.

# Add the frames
UI.get_node("TextDialog")
UI.get_node("TextDialog").add_frame(frame1)
UI.get_node("TextDialog").add_frame(frame2)

# Set our settings
UI.get_node("TextDialog").pause_game = true

# Begin displaying
UI.get_node("TextDialog").display()

Signals

After the dialog is displayed you might want to continue to interact with it, such as to get the player selected inputs, or to add additional frames to the queue. The Text Dialog provides a number of useful Signals to accomplish this.

The two most useful of these are dismissed and no_more_frames. The dismissed signal is fired off when the dialog box is finished will all frames and has closed. The no_more_frames signal is fired off just before that as a last chance to add more frames to the queue before the dialog is dismissed.

Both of these signals are easily interacted with using yield.

# Yield until just the last moment
yield(UI.get_node("TextDialog"), "no_more_frames")

# Did they question the question?
if (frame2.selected_choice == "How is this a question?"):
    # Let's give them a response
    var frame3: TextFrame = TextFrame.new()
    frame3.text = "It isn't."
    UI.get_node("TextDialog").add_frame(frame2)

Class References

TextDialog

Signals

Frame related signals:

  • frame_started
    • Emitted just as a frame begins to render
    • Passes current_frame_number: int and current_frame
  • frame_ended
    • Emitted when a frame is finished and the player has asked to move on
    • Passes current_frame_number: int and current_frame
  • dismissed
    • Emitted when the dialog box is closed
  • no_more_frames
    • Emitted when the last frame in the queue is finished
    • Does one final check of queue after this signal
    • Passes self

Other signals:

  • text_drawn
    • Emitted when all of the text from the frame has been drawn
    • Passes current_frame_number: int and current_frame
  • multiple_choice_selected
    • Emitted whenever a MultipleChoiceFrame is submitted
    • Passes current_frame_number: int and current_frame
  • multiple_answer_selected
    • Emitted whenever a MultipleAnswerFrame is submitted
    • Passes current_frame_number: int and current_frame
  • input_submitted
    • Emitted whenever a InputFrame is submitted
    • Passes current_frame_number: int and current_frame
  • next_button_clicked
    • Emitted whenever a TextFrame is submitted

Properties

  • pause_game: bool
    • Determines if game will be paused while dialog is displayed
  • current_frame: int
    • Contains current frame counter
  • base_rate: float
    • Multiplied with the config_adjustment to determine how fast text is written
  • button_texture: Texture
    • Texture used for next button
  • alt_button_texture: Texture
    • Texture used to blink next button

TextFrame

Properties

  • text: String
    • Text to display

MultipleChoiceFrame

Properties

  • text: String
    • Text to display
  • choices: Array
    • Array of Strings containing choices to display
  • selected_choice: String
    • Contains the user's selected choice once selected

MultipleAnswerFrame

Properties

  • text: String
    • Text to display
  • choices: Array
    • Array of Strings containing choices to display
  • selected_choice: Array
    • Contains the user's selected choices as an Array of Strings once selected

InputFrame

Properties

  • text: String
    • Text to display
  • invalid_response_text: String
    • Text to display when asking user to retry for invalid input
  • response_text: String
    • Contains the user's input once submitted
  • validation_function: FuncRef
    • A reference to a function to be called to validate the user's input
    • Should have signature validation(response_text: String, frame: InputFrame) → bool
docs/textdialog.txt · Last modified: 2021/02/04 01:42 by 94.198.42.180