Updated dialogic

This commit is contained in:
MaddoScientisto 2026-01-05 16:00:41 +01:00
commit cbb82512ee
483 changed files with 5743 additions and 2177 deletions

View file

@ -9,7 +9,12 @@ extends Control
@onready var name_label_box: PanelContainer = (%NameLabelPanel as PanelContainer)
@onready var name_label_holder: HBoxContainer = $DialogText/NameLabelPositioner
var node_to_point_at: Node = null
var node_to_point_at: Node = null:
set(val):
node_to_point_at = val
base_position = get_speaker_canvas_position() + base_direction * safe_zone
position = base_position
var current_character: DialogicCharacter = null
var max_width := 300
@ -36,13 +41,14 @@ func _ready() -> void:
func reset() -> void:
set_process(false)
scale = Vector2.ZERO
modulate.a = 0.0
tail.points = []
bubble_rect = Rect2(0,0,2,2)
base_position = get_speaker_canvas_position()
base_position = get_speaker_canvas_position() + base_direction * safe_zone
position = base_position
@ -106,7 +112,7 @@ func close() -> void:
func _on_dialog_text_started_revealing_text() -> void:
_resize_bubble(get_base_content_size(), true)
_resize_bubble(await get_base_content_size(), true)
func _resize_bubble(content_size:Vector2, popup:=false) -> void:
@ -137,25 +143,43 @@ func _on_question_shown(info:Dictionary) -> void:
if !is_visible_in_tree():
return
await get_tree().process_frame
# Avoid choice_container's flickering(because some ticks will happen in
# `await get_base_content_size()` which will make choice_container exist
# at its old position for several tens of milliseconds).
choice_container.modulate.a = 0
var content_size := get_base_content_size()
var content_size := await get_base_content_size()
content_size.y += choice_container.size.y
content_size.x = max(content_size.x, choice_container.size.x)
_resize_bubble(content_size)
# Now, choice_container has changed to its new position, so we can make it
# actually show up.
choice_container.modulate.a = 1
func get_base_content_size() -> Vector2:
var font: Font = text.get_theme_font(&"normal_font")
return font.get_multiline_string_size(
var text_width = font.get_multiline_string_size(
text.get_parsed_text(),
HORIZONTAL_ALIGNMENT_LEFT,
max_width,
text.get_theme_font_size(&"normal_font_size")
)
).x
# Let text use content's width, and let text auto shrink height to its content.
text.size = Vector2(text_width, 0)
await get_tree().process_frame
# Don't know why text.size.y != content's height,
# so we re-set text.size.y to 0 to let text shrink to its content again.
# Finally works this time.
text.size.y = 0
await get_tree().process_frame
return text.size
func add_choice_container(node:Container, alignment:=FlowContainer.ALIGNMENT_BEGIN) -> void:
func add_choice_container(node:Container, alignment:=FlowContainer.ALIGNMENT_BEGIN, choices_button_path:="", maximum_choices:=5) -> void:
if choice_container:
choice_container.get_parent().remove_child(choice_container)
choice_container.queue_free()
@ -168,9 +192,21 @@ func add_choice_container(node:Container, alignment:=FlowContainer.ALIGNMENT_BEG
if node is HFlowContainer:
(node as HFlowContainer).alignment = alignment
var choices_button: PackedScene = null
if not choices_button_path.is_empty():
if ResourceLoader.exists(choices_button_path):
choices_button = (load(choices_button_path) as PackedScene)
else:
printerr("[Dialogic] Unable to load custom choice button from ", choices_button_path)
for i:int in range(5):
choice_container.add_child(DialogicNode_ChoiceButton.new())
for i:int in range(maximum_choices):
var new_button : DialogicNode_ChoiceButton
if choices_button == null:
new_button = DialogicNode_ChoiceButton.new()
else:
new_button = (choices_button.instantiate() as DialogicNode_ChoiceButton)
choice_container.add_child(new_button)
if node is HFlowContainer:
continue
match alignment:
@ -200,3 +236,11 @@ func get_speaker_canvas_position() -> Vector2:
if node_to_point_at is CanvasItem:
base_position = (node_to_point_at as CanvasItem).get_global_transform_with_canvas().origin
return base_position
## Changes the property of mouse filter of the bubble and its children (text and label).
func change_mouse_filter(mouse_filter: Control.MouseFilter) -> void:
mouse_filter = mouse_filter
text.mouse_filter = mouse_filter
name_label_box.mouse_filter = mouse_filter
name_label_holder.mouse_filter = mouse_filter