First commit 🎉

This commit is contained in:
Tony Bark 2025-07-17 01:49:18 -04:00
commit 43ea213f9b
728 changed files with 37080 additions and 0 deletions

View file

@ -0,0 +1,165 @@
@tool
@icon('res://addons/popochiu/icons/dialog.png')
class_name PopochiuDialog
extends Resource
## A class for branching dialogs. The dialog options can be used to trigger events.
## The identifier of the object used in scripts.
@export var script_name := ''
## The array of [PopochiuDialogOption] to show on screen when the dialog is running.
@export var options: Array[PopochiuDialogOption] = [] : set = set_options
#region Virtual ####################################################################################
## Called when the dialog starts. [b]You have to use an [code]await[/code] in this method in order
## to make the dialog to work properly[/b].
## [i]Virtual[/i].
func _on_start() -> void:
pass
## Called when the [param opt] dialog option is clicked. The [member PopochiuDialogOption.id] in
## [param opt] can be used to check which was the selected option.
## [i]Virtual[/i].
func _option_selected(opt: PopochiuDialogOption) -> void:
pass
## Called when the game is saved.
## [i]Virtual[/i].
func _on_save() -> Dictionary:
return {}
## Called when the game is loaded. The structure of [param data] is the same returned by
## [method _on_save].
## [i]Virtual[/i].
func _on_load(_data: Dictionary) -> void:
pass
#endregion
#region Public #####################################################################################
## Starts this dialog, then [method _on_start] is called.[br][br]
## [i]This method is intended to be used inside a [method Popochiu.queue] of instructions.[/i]
func queue_start() -> Callable:
return func (): await start()
## Starts this dialog, then [method _on_start] is called.
func start() -> void:
if PopochiuUtils.d.current_dialog == self:
return
# Start this dialog
PopochiuUtils.d.current_dialog = self
await _start()
## Stops the dialog (which makes the menu with the options to disappear).[br][br]
## [i]This method is intended to be used inside a [method Popochiu.queue] of instructions.[/i]
func queue_stop() -> Callable:
return func (): await stop()
## Stops the dialog (which makes the menu with the options to disappear).
func stop() -> void:
PopochiuUtils.d.finish_dialog()
## Enables each [PopochiuDialogOption] which [member PopochiuDialogOption.id] matches each of the
## values in the [param ids] array.
func turn_on_options(ids: Array) -> void:
for id in ids:
var opt: PopochiuDialogOption = get_option(id)
if opt: opt.turn_on()
## Disables each [PopochiuDialogOption] which [member PopochiuDialogOption.id] matches each of the
## values in the [param ids] array.
func turn_off_options(ids: Array) -> void:
for id in ids:
var opt: PopochiuDialogOption = get_option(id)
if opt: opt.turn_off()
## Disables [b]forever[/b] each [PopochiuDialogOption] which [member PopochiuDialogOption.id]
## matches each of the values in the [param ids] array.
func turn_off_forever_options(ids: Array) -> void:
for id in ids:
var opt: PopochiuDialogOption = get_option(id)
if opt: opt.turn_off_forever()
## Use this to save custom data when saving the game. The returned [Dictionary] must contain only
## JSON supported types: [bool], [int], [float], [String].
func on_save() -> Dictionary:
return _on_save()
## Called when the game is loaded. [param data] will have the same structure you defined for the
## returned [Dictionary] by [method _on_save].
func on_load(data: Dictionary) -> void:
_on_load(data)
## Returns the dilog option which [member PopochiuDialogOption.id] matches [param opt_id].
func get_option(opt_id: String) -> PopochiuDialogOption:
for o in options:
if (o as PopochiuDialogOption).id == opt_id:
return o
return null
#endregion
#region SetGet #####################################################################################
func set_options(value: Array[PopochiuDialogOption]) -> void:
options = value
for idx in value.size():
if not value[idx]:
var new_opt: PopochiuDialogOption = PopochiuDialogOption.new()
var id := 'Opt%d' % options.size()
new_opt.id = id
new_opt.text = 'Option %d' % options.size()
options[idx] = new_opt
#endregion
#region Private ####################################################################################
func _start() -> void:
PopochiuUtils.g.block()
PopochiuUtils.d.dialog_started.emit(self)
await _on_start()
_show_options()
await PopochiuUtils.d.dialog_finished
PopochiuUtils.g.unblock()
PopochiuUtils.d.option_selected.disconnect(_on_option_selected)
func _show_options() -> void:
if not PopochiuUtils.d.active: return
PopochiuUtils.d.dialog_options_requested.emit(options)
if not PopochiuUtils.d.option_selected.is_connected(_on_option_selected):
PopochiuUtils.d.option_selected.connect(_on_option_selected)
func _on_option_selected(opt: PopochiuDialogOption) -> void:
opt.used = true
opt.used_times += 1
PopochiuUtils.d.selected_option = opt
_option_selected(opt)
#endregion

View file

@ -0,0 +1 @@
uid://osh8vbx7f1ah

View file

@ -0,0 +1,67 @@
@tool
class_name PopochiuDialogOption
extends Resource
## Each of the options in a [PopochiuDialog].
## The identifier of the option. Use it when scripting.
@export var id := "" : set = set_id
## The text to show on screen for the option.
@export var text := ""
## The icon to show on screen for the option.
#@export var icon: Texture = null
## Whether this option is visible.
@export var visible := true
## Whether this option is disabled. If [code]true[/code], the option won´t be rendered.
@export var disabled := false
## Whether this option should be [b]always[/b] rendered as not previously selected.
@export var always_on := false
## Stores the same value of the [member id] property.
var script_name := ""
## Whether the option was already been selected. If [code]true[/code], then the option's
## [member text] will be shown different in the options menu, so players know they already clicked
## the option.
var used := false
## The number of times this options has been clicked.
var used_times := 0
#region Virtual ####################################################################################
## Called when the option is selected.
## [i]Virtual[/i].
func _on_selected() -> void:
pass
#endregion
#region Public #####################################################################################
## Makes the option visible. Won´t work if the option is [member disabled].
func turn_on() -> void:
if disabled: return
visible = true
used = false
## Makes the option invisible.
func turn_off() -> void:
visible = false
## Disables the option by making [member disable] [code]true[/code].
func turn_off_forever() -> void:
disabled = true
#endregion
#region SetGet #####################################################################################
func set_id(value: String) -> void:
id = value
script_name = id
resource_name = id
#endregion

View file

@ -0,0 +1 @@
uid://cclk5bj1l4p4p