Skip to content

Commit 90f5c15

Browse files
authored
Merge pull request dialogic-godot#2735 from salianifo/wait-subsystem
Fix Wait Event not pausing when Dialogic is paused
2 parents b3f20d8 + ce82e40 commit 90f5c15

5 files changed

Lines changed: 71 additions & 29 deletions

File tree

addons/dialogic/Core/DialogicGameHandler.gd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ var VAR := preload("res://addons/dialogic/Modules/Variable/subsystem_variables.g
148148
var Voice := preload("res://addons/dialogic/Modules/Voice/subsystem_voice.gd").new():
149149
get: return get_subsystem("Voice")
150150

151+
var Wait := preload("res://addons/dialogic/Modules/Wait/subsystem_wait.gd").new():
152+
get: return get_subsystem("Wait")
153+
151154
#endregion
152155

153156

addons/dialogic/Modules/Wait/event_wait.gd

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,12 @@ extends DialogicEvent
1414
## If true the wait can be skipped with user input
1515
@export var skippable := false
1616

17-
var _tween: Tween
18-
1917

2018
#region EXECUTE
2119
################################################################################
2220

2321
func _execute() -> void:
24-
var final_wait_time := time
25-
26-
if dialogic.Inputs.auto_skip.enabled:
27-
var time_per_event: float = dialogic.Inputs.auto_skip.time_per_event
28-
final_wait_time = min(time, time_per_event)
29-
30-
dialogic.current_state = dialogic.States.WAITING
31-
32-
if hide_text and dialogic.has_subsystem("Text"):
33-
dialogic.Text.update_dialog_text('', true)
34-
dialogic.Text.hide_textbox()
35-
36-
_tween = dialogic.get_tree().create_tween()
37-
if DialogicUtil.is_physics_timer():
38-
_tween.set_process_mode(Tween.TWEEN_PROCESS_PHYSICS)
39-
_tween.tween_callback(_on_finish).set_delay(final_wait_time)
40-
41-
if skippable:
42-
dialogic.Inputs.dialogic_action.connect(_on_finish)
43-
44-
45-
func _on_finish() -> void:
46-
if is_instance_valid(_tween):
47-
_tween.kill()
48-
49-
if skippable:
50-
dialogic.Inputs.dialogic_action.disconnect(_on_finish)
22+
await dialogic.Wait.update_wait(time, hide_text, skippable)
5123

5224
if dialogic.Animations.is_animating():
5325
dialogic.Animations.stop_animation()

addons/dialogic/Modules/Wait/index.gd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ extends DialogicIndexer
44

55
func _get_events() -> Array:
66
return [this_folder.path_join('event_wait.gd')]
7+
8+
9+
func _get_subsystems() -> Array:
10+
return [{'name':'Wait', 'script':this_folder.path_join('subsystem_wait.gd')}]
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
extends DialogicSubsystem
2+
3+
## Subsystem that manages wait events.
4+
5+
signal timeout
6+
7+
var _timer: Timer = Timer.new()
8+
9+
10+
#region STATE
11+
####################################################################################################
12+
13+
func clear_game_state(clear_flag:=Dialogic.ClearFlags.FULL_CLEAR) -> void:
14+
_timer.stop()
15+
16+
17+
func pause() -> void:
18+
_timer.paused = true
19+
20+
21+
func resume() -> void:
22+
_timer.paused = false
23+
24+
#endregion
25+
26+
27+
#region MAIN METHODS
28+
####################################################################################################
29+
30+
func _ready() -> void:
31+
_timer.one_shot = true
32+
if DialogicUtil.is_physics_timer():
33+
_timer.process_callback = Timer.TIMER_PROCESS_PHYSICS
34+
add_child(_timer)
35+
_timer.timeout.connect(timeout.emit)
36+
37+
38+
func update_wait(time: float, hide_text: bool, skippable: bool) -> void:
39+
var final_wait_time := time
40+
41+
if dialogic.Inputs.auto_skip.enabled:
42+
var time_per_event: float = dialogic.Inputs.auto_skip.time_per_event
43+
final_wait_time = min(time, time_per_event)
44+
45+
dialogic.current_state = dialogic.States.WAITING
46+
47+
if hide_text and dialogic.has_subsystem("Text"):
48+
dialogic.Text.update_dialog_text('', true)
49+
dialogic.Text.hide_textbox()
50+
51+
_timer.start(final_wait_time)
52+
53+
if skippable:
54+
dialogic.Inputs.dialogic_action.connect(timeout.emit)
55+
56+
await timeout
57+
_timer.stop()
58+
59+
if skippable:
60+
dialogic.Inputs.dialogic_action.disconnect(timeout.emit)
61+
62+
#endregion
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://db2kljpe5lv1x

0 commit comments

Comments
 (0)