2 extends DialogicLayoutBase
4 ## This layout won't do anything on its own
6 var bubbles: Array = []
7 var registered_characters: Dictionary = {}
10 @export_range(1, 25, 1) var bubble_count: int = 2
13 func _ready() -> void:
14 if Engine.is_editor_hint():
17 DialogicUtil.autoload().Text.about_to_show_text.connect(_on_dialogic_text_event)
18 $Example/CRT.position = $Example.get_viewport_rect().size/2
20 if not has_node('TextBubbleLayer'):
23 if len(bubbles) < bubble_count:
27 func register_character(character:Variant, node:Node):
28 if typeof(character) == TYPE_STRING:
29 var character_string: String = character
30 if character.begins_with("res://"):
31 character = load(character)
33 character = DialogicResourceUtil.get_character_resource(character)
35 printerr("[Dialogic] Textbubble: Tried registering character from invalid string '", character_string, "'.")
37 registered_characters[character] = node
38 if len(registered_characters) > len(bubbles) and len(bubbles) < bubble_count:
42 func _get_persistent_info() -> Dictionary:
43 return {"textbubble_registers": registered_characters}
46 func _load_persistent_info(info: Dictionary) -> void:
47 var register_info: Dictionary = info.get("textbubble_registers", {})
48 for character in register_info:
49 if is_instance_valid(register_info[character]):
50 register_character(character, register_info[character])
53 func add_bubble() -> void:
54 if not has_node('TextBubbleLayer'):
57 var new_bubble: Control = get_node("TextBubbleLayer").add_bubble()
58 bubbles.append(new_bubble)
61 func _on_dialogic_text_event(info:Dictionary):
62 var bubble_to_use: Node
63 for bubble in bubbles:
64 if bubble.current_character == info.character:
65 bubble_to_use = bubble
67 if bubble_to_use == null:
68 for bubble in bubbles:
69 if bubble.current_character == null:
70 bubble_to_use = bubble
72 if bubble_to_use == null:
73 bubble_to_use = bubbles[0]
75 var node_to_point_at: Node
76 if info.character in registered_characters:
77 node_to_point_at = registered_characters[info.character]
80 node_to_point_at = $Example/CRT/Marker
83 bubble_to_use.current_character = info.character
84 bubble_to_use.node_to_point_at = node_to_point_at
86 if has_node('TextBubbleLayer'):
87 get_node("TextBubbleLayer").bubble_apply_overrides(bubble_to_use)
90 ## Now close other bubbles
91 for bubble in bubbles:
92 if bubble != bubble_to_use:
94 bubble.current_character = null