PopochiuDialog
Inherits: Resource
Description
Represents a branching dialog tree with selectable options.
Dialog options can trigger game events, be enabled or disabled at runtime, and track usage history. Override virtual methods to define dialog behavior.
Properties
| Type | Name | Default |
|---|---|---|
| Array[PopochiuDialogOption] | options | [] |
| Variant | script_name | '' |
Methods
| Return Type | Method |
|---|---|
| Array[PopochiuDialogOption] | _on_build_options(existing_options: Array[PopochiuDialogOption]) virtual |
| void | _on_load(_data: Dictionary) virtual |
| Dictionary | _on_save() virtual |
| void | _on_start() virtual |
| void | _option_selected(opt: PopochiuDialogOption) virtual |
| void | build_options() |
| PopochiuDialogOption | create_option(id: String, config: Dictionary = {}) |
| PopochiuDialogOption | get_option(opt_id: String) |
| Callable | queue_start() |
| Callable | queue_stop() |
| void | set_options(value: Array[PopochiuDialogOption]) |
| void | start() |
| void | stop() |
| void | turn_off_forever_options(ids: Array) |
| void | turn_off_options(ids: Array) |
| void | turn_on_options(ids: Array) |
Property Descriptions
options
@export var options : Array[PopochiuDialogOption] = []
- Setter:
set_options
The array of PopochiuDialogOption to show on screen when the dialog is running.
script_name
@export var script_name = ''
The identifier of the object used in scripts.
Method Descriptions
_on_build_options
func _on_build_options(existing_options: Array[PopochiuDialogOption]) -> Array[PopochiuDialogOption]
This is a virtual method. Override it in your subclass.
Called when the dialog is first accessed (before it starts).
Return an array of PopochiuDialogOptions created with create_option().
To mix creating options from code and inspector, add your options to existing_options:
existing_options.append_array([
create_option("Joke1", {
text = "What do you call a magic dog?",
}),
])
return existing_options
Overriding this function is optional. You can configure your dialog using the Inspector. Virtual.
_on_load
func _on_load(_data: Dictionary) -> void
This is a virtual method. Override it in your subclass.
Called when the game is loaded. The structure of data matches that returned by
_on_save().
Implement this to restore the custom properties you persisted in [_on_save].
_on_save
func _on_save() -> Dictionary
This is a virtual method. Override it in your subclass.
Called when the game is saved.
Implement this to persist custom properties that you added to this resource. Should return a Dictionary containing the data to be saved.
The returned Dictionary must contain only JSON-supported types: [bool], [int], [float], String.
_on_start
func _on_start() -> void
This is a virtual method. Override it in your subclass.
Called when the dialog starts.
You must use await inside this method for the dialog to work properly.
Implement this to add custom behavior (such as change the animation of a character) or update the game state when the dialog starts.
_option_selected
func _option_selected(opt: PopochiuDialogOption) -> void
This is a virtual method. Override it in your subclass.
Called when opt (one of the dialog options) is clicked. Use
id to identify which option was selected.
Implement this to add custom behavior (such as change the animation of a character, play a sound, etc.) or to update the game state when a dialog option is selected.
Instead of overriding this function, you can write functions for each option using their
snake_case
name (option id BYE2 will call _on_option_bye_2).
Virtual.
build_options
func build_options()
Called by PopochiuIDialog before returning the list of options for a dialogue. NOTE: This funciton is for internal engine use only and is not supposed to be used in game scripts.
create_option
func create_option(id: String, config: Dictionary = {}) -> PopochiuDialogOption
Call this from within _on_build_options() to populate your dialog options (instead
of using the Inspector).
Optionally use config to create the list of options in one block:
return [
create_option("OfferHelp", {
text = "What can I do for you?",
}),
create_option("Bye", {
text = "Going get you some food, hold on.",
visible = false,
}),
]
get_option
func get_option(opt_id: String) -> PopochiuDialogOption
Returns the dialog option whose id matches opt_id.
queue_start
func queue_start() -> Callable
Starts this dialog, then calls _on_start().
This method is intended to be used inside a queue() of instructions.
queue_stop
func queue_stop() -> Callable
Stops the dialog, hiding the options menu.
This method is intended to be used inside a queue() of instructions.
set_options
func set_options(value: Array[PopochiuDialogOption]) -> void
start
func start() -> void
Starts this dialog, then calls _on_start().
stop
func stop() -> void
Stops the dialog, hiding the options menu.
turn_off_forever_options
func turn_off_forever_options(ids: Array) -> void
Disables forever each PopochiuDialogOption which id
appears in the ids array.
turn_off_options
func turn_off_options(ids: Array) -> void
Disables each PopochiuDialogOption which id appears in the
ids array.
turn_on_options
func turn_on_options(ids: Array) -> void
Enables each PopochiuDialogOption which id appears in the
ids array.