Skip to content

Commit a1aae81

Browse files
Big signal update (#1502)
Added many signals to all the subsystems. Most of these just give one info dictionary argument. While this is initally not as nice as giving named arguments, it means we can way more easily provide mode information in the future without breaking any code. Added signals: - Voice: voiceline_started, voiceline_finished, voiceline_stopped - Variable: variable_changed, variable_was_set - TextInput: input_confirmed, input_shown - Text: text_finished, speaker_updated, textbox_visibility_changed - Style: style_changed - Jump: switched_timeline, jumped_to_label, returned_from_jump - Choices: choice_selected, choices_shown - Portraits: character_joined, character_left, character_portrait_changed, character_moved, position_changed - Background: background_changed - Audio: music_started, sound_started Also: - removed the voice timer from the voice subsystem - fixed typo in Jump.resume_from_last_jump()
1 parent 3c2845e commit a1aae81

File tree

14 files changed

+132
-73
lines changed

14 files changed

+132
-73
lines changed

addons/dialogic/Events/Audio/subsystem_audio.gd

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ extends DialogicSubsystem
22

33
## Subsystem that manages music and sounds.
44

5+
signal music_started(info:Dictionary)
6+
signal sound_started(info:Dictionary)
7+
58
var base_music_player := AudioStreamPlayer.new()
69
var base_sound_player := AudioStreamPlayer.new()
710

@@ -43,7 +46,7 @@ func _ready() -> void:
4346
## Updates the background music. Will fade out previous music.
4447
func update_music(path:String = '', volume:float = 0.0, audio_bus:String = "Master", fade_time:float = 0.0, loop:bool = true) -> void:
4548
dialogic.current_state_info['music'] = {'path':path, 'volume':volume, 'audio_bus':audio_bus, 'loop':loop}
46-
49+
music_started.emit(dialogic.current_state_info['music'])
4750
var fader: Tween = null
4851
if base_music_player.playing or !path.is_empty():
4952
fader = create_tween()
@@ -77,6 +80,7 @@ func update_music(path:String = '', volume:float = 0.0, audio_bus:String = "Mast
7780
## Plays a given sound file.
7881
func play_sound(path:String, volume:float = 0.0, audio_bus:String = "Master", loop :bool= false) -> void:
7982
if base_sound_player != null and !path.is_empty():
83+
sound_started.emit({'path':path, 'volume':volume, 'audio_bus':audio_bus, 'loop':loop})
8084
var new_sound_node := base_sound_player.duplicate()
8185
new_sound_node.name = "Sound"
8286
new_sound_node.stream = load(path)

addons/dialogic/Events/Background/subsystem_backgrounds.gd

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ extends DialogicSubsystem
22

33
## Subsystem for managing backgrounds.
44

5-
var default_background_scene = load(get_script().resource_path.get_base_dir().path_join('default_background.tscn'))
5+
signal background_changed(info:Dictionary)
6+
7+
8+
var default_background_scene :PackedScene = load(get_script().resource_path.get_base_dir().path_join('default_background.tscn'))
69
####################################################################################################
710
## STATE
811
####################################################################################################
@@ -29,6 +32,7 @@ func load_game_state():
2932
## To do so implement [_should_do_background_update()] on the custom background scene.
3033
## Then [_update_background()] will be called directly on that previous scene.
3134
func update_background(scene:String = '', argument:String = '', fade_time:float = 0.0) -> void:
35+
var info := {'scene':scene, 'argument':argument, 'fade_time':fade_time, 'same_scene':false}
3236
for node in get_tree().get_nodes_in_group('dialogic_background_holders'):
3337
if node.visible:
3438
var bg_set: bool = false
@@ -38,6 +42,7 @@ func update_background(scene:String = '', argument:String = '', fade_time:float
3842
if old_bg.has_method('_update_background'):
3943
old_bg._update_background(argument, fade_time)
4044
bg_set = true
45+
info['same_scene'] = true
4146
if !bg_set:
4247
# remove previous backgrounds
4348
for old_bg in node.get_children():
@@ -70,8 +75,9 @@ func update_background(scene:String = '', argument:String = '', fade_time:float
7075

7176
elif "modulate" in new_node:
7277
new_node.modulate = Color.TRANSPARENT
73-
var tween = new_node.create_tween()
78+
var tween := new_node.create_tween()
7479
tween.tween_property(new_node, "modulate", Color.WHITE, fade_time)
7580

7681
dialogic.current_state_info['background_scene'] = scene
7782
dialogic.current_state_info['background_argument'] = argument
83+
background_changed.emit(info)

addons/dialogic/Events/Character/subsystem_portraits.gd

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@ extends DialogicSubsystem
22

33
## Subsystem that manages portraits and portrait positions.
44

5+
signal character_joined(info:Dictionary)
6+
signal character_left(info:Dictionary)
7+
signal character_portrait_changed(info:Dictionary)
8+
signal character_moved(info:Dictionary)
9+
signal position_changed(info:Dictionary)
10+
11+
512
## The default portrait scene.
6-
var default_portrait_scene = load(get_script().resource_path.get_base_dir().path_join('default_portrait.tscn'))
13+
var default_portrait_scene :PackedScene = load(get_script().resource_path.get_base_dir().path_join('default_portrait.tscn'))
714

815
## A reference to the current [DialogicNode_PortraitHolder].
916
var _portrait_holder_reference: Node = null
@@ -44,7 +51,6 @@ func resume() -> void:
4451

4552
## Joins a character and then calls change_portrait().
4653
func add_portrait(character:DialogicCharacter, portrait:String, position_idx:int, mirrored: bool = false, z_index: int = 0, extra_data:String = "") -> Node:
47-
var character_node = null
4854

4955
if portrait.is_empty():
5056
portrait = character.default_portrait
@@ -59,7 +65,7 @@ func add_portrait(character:DialogicCharacter, portrait:String, position_idx:in
5965
printerr("[DialogicError] Character ",character.display_name, " has no default portrait to use.")
6066
return null
6167

62-
character_node = Node2D.new()
68+
var character_node := Node2D.new()
6369
character_node.name = character.get_character_name()
6470
character_node.set_meta('character', character)
6571
character_node.z_index = z_index
@@ -81,6 +87,10 @@ func add_portrait(character:DialogicCharacter, portrait:String, position_idx:in
8187
change_portrait_extradata(character, extra_data)
8288
change_portrait_z_index(character, z_index)
8389

90+
var info := {'character':character}
91+
info.merge(dialogic.current_state_info['portraits'][character.resource_path])
92+
character_joined.emit(info)
93+
8494
return character_node
8595

8696

@@ -97,19 +107,23 @@ func change_portrait(character:DialogicCharacter, portrait:String, update_transf
97107
print_debug('[Dialogic] Change to not-existing portrait will be ignored!')
98108
return
99109

110+
var info := {'character':character, 'portrait':portrait, 'same_scene':false}
111+
100112
var char_node :Node = dialogic.current_state_info.portraits[character.resource_path].node
101113

102114
# path to the scene to use
103115
var scene_path :String = character.portraits[portrait].get('scene', '')
104116

105-
var portrait_node = null
117+
var portrait_node : Node = null
106118

107119
# check if the scene is the same as the currently loaded scene
108120
if (char_node.get_child_count() and
109121
character.portraits[dialogic.current_state_info['portraits'][character.resource_path]['portrait']].get('scene', '') == scene_path and
110122
# also check if the scene supports changing to the given portrait
111123
(!char_node.get_child(0).has_method('_should_do_portrait_update') or char_node.get_child(0)._should_do_portrait_update(character, portrait))):
112124
portrait_node = char_node.get_child(0)
125+
info['same_scene'] = true
126+
113127
else:
114128
# remove previous portrait
115129
if char_node.get_child_count():
@@ -118,13 +132,14 @@ func change_portrait(character:DialogicCharacter, portrait:String, update_transf
118132
if scene_path.is_empty():
119133
portrait_node = default_portrait_scene.instantiate()
120134
else:
121-
var p = load(scene_path)
135+
var p :PackedScene = load(scene_path)
122136
if p:
123137
portrait_node = p.instantiate()
124138
else:
125139
push_error('Dialogic: Portrait node "' + str(scene_path) + '" for character [' + character.display_name + '] could not be loaded. Your portrait might not show up on the screen.')
126140

127141
dialogic.current_state_info['portraits'][character.resource_path]['portrait'] = portrait
142+
character_portrait_changed.emit(info)
128143

129144
if portrait_node:
130145
for property in character.portraits[portrait].get('export_overrides', {}).keys():
@@ -194,13 +209,13 @@ func animate_portrait(character:DialogicCharacter, animation_path:String, length
194209
print_debug('[DialogicError] Cannot animate portrait of null/not joined character.')
195210
return null
196211

197-
var char_node = dialogic.current_state_info['portraits'][character.resource_path].node
212+
var char_node :Node = dialogic.current_state_info['portraits'][character.resource_path].node
198213

199214
if dialogic.current_state_info['portraits'][character.resource_path].get('animation_node', null):
200215
if is_instance_valid(dialogic.current_state_info['portraits'][character.resource_path].animation_node):
201216
dialogic.current_state_info['portraits'][character.resource_path].animation_node.queue_free()
202-
var anim_script = load(animation_path)
203-
var anim_node = Node.new()
217+
var anim_script :Script = load(animation_path)
218+
var anim_node := Node.new()
204219
anim_node.set_script(anim_script)
205220
anim_node = (anim_node as DialogicAnimation)
206221
anim_node.node = char_node
@@ -235,11 +250,11 @@ func move_portrait(character:DialogicCharacter, position_idx:int, time:float = 0
235250
remove_portrait(character)
236251
return
237252

238-
239253
char_node.position = global_pos-char_node.get_parent().global_position
240254
update_portrait_transform(character, time)
241255

242256
dialogic.current_state_info.portraits[character.resource_path].position_index = position_idx
257+
character_moved.emit({'character':character, 'position_index':position_idx, 'time':time})
243258

244259

245260
func change_portrait_z_index(character:DialogicCharacter, z_index:int, update_zindex:= true) -> void:
@@ -249,6 +264,7 @@ func change_portrait_z_index(character:DialogicCharacter, z_index:int, update_zi
249264

250265

251266
func remove_portrait(character:DialogicCharacter) -> void:
267+
character_left.emit({'character':character})
252268
dialogic.current_state_info['portraits'][character.resource_path].node.queue_free()
253269
dialogic.current_state_info['portraits'].erase(character.resource_path)
254270

@@ -266,18 +282,20 @@ func add_portrait_position(position_index: int, position:Vector2) -> void:
266282
new_position.origin_anchor = example_position.origin_anchor
267283
new_position.position_index = position_index
268284
new_position.position = position-new_position._get_origin_position()
285+
position_changed.emit({'change':'added', 'container_node':new_position, 'position_index':position_index})
269286

270287

271288
func move_portrait_position(position_index: int, vector:Vector2, relative:bool = false, time:float = 0.0) -> void:
272-
for portrait_position in get_tree().get_nodes_in_group('dialogic_portrait_container'):
273-
if portrait_position.is_visible_in_tree() and portrait_position.position_index == position_index:
274-
if !portrait_position.has_meta('default_position'):
275-
portrait_position.set_meta('default_position', portrait_position.position)
276-
var tween := portrait_position.create_tween()
289+
for portrait_container in get_tree().get_nodes_in_group('dialogic_portrait_container'):
290+
if portrait_container.is_visible_in_tree() and portrait_container.position_index == position_index:
291+
if !portrait_container.has_meta('default_position'):
292+
portrait_container.set_meta('default_position', portrait_container.position)
293+
var tween := portrait_container.create_tween()
277294
if !relative:
278-
tween.tween_property(portrait_position, 'position', vector, time)
295+
tween.tween_property(portrait_container, 'position', vector, time)
279296
else:
280-
tween.tween_property(portrait_position, 'position', vector, time).as_relative()
297+
tween.tween_property(portrait_container, 'position', vector, time).as_relative()
298+
position_changed.emit({'change':'moved', 'container_node':portrait_container, 'position_index':position_index})
281299
return
282300

283301
# If this is reached, no position could be found. If the position is absolute, we will add it.

addons/dialogic/Events/Choice/subsystem_choices.gd

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ extends DialogicSubsystem
22

33
## Subsystem that manages showing and activating of choices.
44

5+
signal choice_selected(info:Dictionary)
6+
signal choices_shown(info:Dictionary)
7+
8+
59
## Used to block choices from being clicked for a couple of seconds (if delay is set in settings).
6-
var choice_blocker = Timer.new()
10+
var choice_blocker := Timer.new()
711

812
var last_question_info := {}
913

@@ -29,8 +33,8 @@ func clear_game_state():
2933
func hide_all_choices() -> void:
3034
for node in get_tree().get_nodes_in_group('dialogic_choice_button'):
3135
node.hide()
32-
if node.is_connected('button_up', self.choice_selected):
33-
node.disconnect('button_up', self.choice_selected)
36+
if node.is_connected('button_up', _on_ChoiceButton_choice_selected):
37+
node.disconnect('button_up', _on_ChoiceButton_choice_selected)
3438

3539

3640
## Lists all current choices and shows buttons.
@@ -59,7 +63,7 @@ func show_current_choices() -> void:
5963
show_choice(button_idx, choice_event.get_property_translated('text'), true, choice_index)
6064
last_question_info['choices'].append(choice_event.get_property_translated('text'))
6165
button_idx += 1
62-
66+
choices_shown.emit(last_question_info)
6367
choice_blocker.start(float(DialogicUtil.get_project_setting('dialogic/choices/delay', 0.2)))
6468

6569

@@ -87,29 +91,22 @@ func show_choice(button_index:int, text:String, enabled:bool, event_index:int) -
8791
node.shortcut = shortcut
8892

8993
node.disabled = not enabled
90-
node.button_up.connect(choice_selected.bind(event_index))
94+
node.button_up.connect(_on_ChoiceButton_choice_selected.bind(event_index,
95+
{'button_index':button_index, 'text':text, 'enabled':enabled, 'event_index':event_index}))
9196

9297
if node.choice_index > 0:
9398
idx = node.choice_index
9499
idx += 1
95100

96-
####################################################################################################
97-
## HELPERS
98-
####################################################################################################
99-
func choice_selected(event_index:int) -> void:
101+
102+
func _on_ChoiceButton_choice_selected(event_index:int, choice_info:={}) -> void:
100103
if Dialogic.paused or not choice_blocker.is_stopped():
101104
return
105+
choice_selected.emit(choice_info)
102106
hide_all_choices()
103107
dialogic.current_state = dialogic.states.IDLE
104108
dialogic.handle_event(event_index)
105-
106-
## QUESTION/CHOICES
107-
func is_question(index:int) -> bool:
108-
if dialogic.current_timeline_events[index] is DialogicTextEvent:
109-
if len(dialogic.current_timeline_events)-1 != index:
110-
if dialogic.current_timeline_events[index+1] is DialogicChoiceEvent:
111-
return true
112-
return false
109+
113110

114111
func get_current_choice_indexes() -> Array:
115112
var choices := []
@@ -133,3 +130,15 @@ func get_current_choice_indexes() -> Array:
133130
if dialogic.current_timeline_events[evt_idx] is DialogicEndBranchEvent:
134131
ignore -= 1
135132
return choices
133+
134+
####################################################################################################
135+
## HELPERS
136+
####################################################################################################
137+
138+
func is_question(index:int) -> bool:
139+
if dialogic.current_timeline_events[index] is DialogicTextEvent:
140+
if len(dialogic.current_timeline_events)-1 != index:
141+
if dialogic.current_timeline_events[index+1] is DialogicChoiceEvent:
142+
return true
143+
return false
144+

addons/dialogic/Events/Jump/event_jump.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func _execute() -> void:
3939
if return_after:
4040
dialogic.Jump.push_to_jump_stack()
4141
if timeline and timeline != dialogic.current_timeline:
42+
dialogic.Jump.switched_timeline.emit({'previous_timeline':dialogic.current_timeline, 'timeline':timeline, 'label':label_name})
4243
dialogic.start_timeline(timeline, label_name)
4344
else:
4445
if label_name:

addons/dialogic/Events/Jump/subsystem_jump.gd

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ extends DialogicSubsystem
22

33
## Subsystem that holds methods for jumping to specific labels, or return to the previous jump.
44

5+
signal switched_timeline(info:Dictionary)
6+
signal jumped_to_label(info:Dictionary)
7+
signal returned_from_jump(info:Dictionary)
58

69
####################################################################################################
710
## STATE
@@ -34,17 +37,20 @@ func jump_to_label(label:String) -> void:
3437
if event is DialogicLabelEvent and event.name == label:
3538
break
3639
dialogic.current_event_idx = idx
40+
jumped_to_label.emit({'timeline':dialogic.current_timeline, 'label':label})
3741

3842

3943
func push_to_jump_stack() -> void:
4044
dialogic.current_state_info['jump_stack'].push_back({'timeline':dialogic.current_timeline, 'index':dialogic.current_event_idx})
4145

4246

43-
func resume_from_latst_jump() -> void:
47+
func resume_from_last_jump() -> void:
48+
var sub_timeline : DialogicTimeline = dialogic.current_timeline
4449
dialogic.start_timeline(
4550
dialogic.current_state_info['jump_stack'][-1].timeline,
4651
dialogic.current_state_info['jump_stack'][-1].index+1)
4752
dialogic.current_state_info['jump_stack'].pop_back()
53+
returned_from_jump.emit({'sub_timeline':sub_timeline, 'label':dialogic.current_timeline.get_event(dialogic.current_event_idx-1).name})
4854

4955

5056
func is_jump_stack_empty():

addons/dialogic/Events/Style/subsystem_styles.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ extends DialogicSubsystem
22

33
## Subsystem that manages showing and hiding style nodes.
44

5+
signal style_changed(info:Dictionary)
56

67
####################################################################################################
78
## STATE
@@ -36,3 +37,4 @@ func change_style(style_name:String) -> void:
3637
for style_node in get_tree().get_nodes_in_group('dialogic_styles'):
3738
if style_node.style_name == last_style:
3839
style_node.show()
40+
style_changed.emit({'style_name':style_name})

addons/dialogic/Events/Text/default_input_handler.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func _ready() -> void:
2929
autoadvance_timer.timeout.connect(_on_autoadvance_timer_timeout)
3030

3131

32-
func _on_text_finished() -> void:
32+
func _on_text_finished(info:Dictionary) -> void:
3333
if Dialogic.Text.should_autoadvance():
3434
autoadvance_timer.start(Dialogic.Text.get_autoadvance_time())
3535

0 commit comments

Comments
 (0)