@@ -3,6 +3,8 @@ extends Object
3
3
4
4
var allow_skip := true
5
5
6
+ var allow_cancel := true
7
+
6
8
var allow_func := true
7
9
8
10
var auto := false
@@ -44,7 +46,7 @@ var actor_label : Label
44
46
45
47
var caller : Dictionary = {}
46
48
47
- ## [RichTextLabel ] node that displays the dialogue body [member Dialogue.set_current.dlg]. This element is [b]required[/b] for the dialogue to run.
49
+ ## [DialogueLabel ] node that displays the dialogue body [member Dialogue.set_current.dlg]. This is [b]required[/b] for the dialogue to run
48
50
var dialogue_label : DialogueLabel
49
51
50
52
## Current progress of the Dialogue.
@@ -95,6 +97,7 @@ func _init(parameters : Dictionary):
95
97
96
98
var constructor_property : PackedStringArray = [
97
99
"allow_skip" ,
100
+ "allow_cancel" ,
98
101
"allow_func" ,
99
102
"auto" ,
100
103
"auto_delay" ,
@@ -108,8 +111,6 @@ func _init(parameters : Dictionary):
108
111
else :
109
112
push_error ("Error constructing Stage, `%s ` does not exists" % property )
110
113
111
- Theatre .locale_changed .connect (switch_lang )
112
-
113
114
## Emitted when [Dialogue] started ([member step] == 0)
114
115
signal started
115
116
## Emitted when [Dialogue] finished ([member step] == [member step.size()])
@@ -127,19 +128,23 @@ func get_current_set() -> Dictionary:
127
128
func is_playing () -> bool :
128
129
return step >= 0
129
130
130
- ## Progress the [Dialogue] by 1 step. If [member progress_tween] is still running, [member progress_tween.stop()] and [member progress_tween_reset] will be called, and the [Dialogue] will not progressed.
131
+ ## Progress the [Dialogue] by 1 step.
131
132
func progress () -> void :
132
- if current_dialogue != null :
133
+ if current_dialogue == null :
134
+ push_warning ("No Dialogue present" )
135
+ else :
133
136
# Skip dialogue
134
137
if dialogue_label .visible_ratio < 1.0 :
135
138
if allow_skip :
136
- dialogue_label .visible_characters = current_dialogue_set ["line" ].length ()
139
+ dialogue_label .clear_render ()
140
+ dialogue_label .visible_ratio = 1.0
137
141
138
142
# Progress dialogue
139
143
else :
140
144
if step + 1 < current_dialogue_length :
145
+ dialogue_label .clear_render ()
146
+
141
147
step += 1
142
- dialogue_label .visible_characters = 0
143
148
current_dialogue_set = current_dialogue .sets [step ]
144
149
body_text_length = current_dialogue_set ["line" ].length ()
145
150
@@ -167,8 +172,7 @@ func progress() -> void:
167
172
else :
168
173
caller [f ["caller" ]].callv (f ["name" ], f ["args" ])
169
174
170
- if dialogue_label != null :
171
- dialogue_label .start_render ()
175
+ dialogue_label .start_render ()
172
176
173
177
progressed .emit (step , current_dialogue_set )
174
178
@@ -177,36 +181,46 @@ func progress() -> void:
177
181
finished .emit ()
178
182
179
183
## Stop Dialogue and resets everything
180
- func reset (keep_dialogue : bool = false ) -> void :
181
- print ("Resetting Dialogue [%s ]..." % current_dialogue .source_path )
182
- resetted .emit (step ,
183
- current_dialogue .sets [step ] if step != - 1 else \
184
- Dialogue .Parser .SETS_TEMPLATE
185
- )
184
+ func reset () -> void :
185
+ if ! allow_cancel :
186
+ print ("Resetting Dialogue is not allowed" )
187
+ else :
188
+ if current_dialogue != null :
189
+ print ("Resetting Dialogue [%s ]..." % current_dialogue .source_path )
190
+ resetted .emit (step ,
191
+ current_dialogue .sets [step ] if step != - 1 else \
192
+ Dialogue .Parser .SETS_TEMPLATE
193
+ )
186
194
187
- if ! keep_dialogue :
188
- current_dialogue = null
189
- step = - 1
195
+ step = - 1
190
196
191
- if actor_label != null :
192
- actor_label .text = ""
193
- dialogue_label .text = ""
197
+ if actor_label != null :
198
+ actor_label .text = ""
199
+
200
+ dialogue_label .clear_render ()
201
+ dialogue_label .text = ""
202
+
203
+ current_dialogue = null
194
204
195
205
## Start the [Dialogue] at step 0 or at defined preprogress parameter.
196
206
## If no parameter (or null) is passed, it will run the [member current_dialogue] if present
197
207
func start (dialogue : Dialogue = null ) -> void :
198
- if dialogue != null :
199
- current_dialogue = dialogue
200
-
201
- if current_dialogue == null :
202
- push_error ("Cannot start the Stage: `current_dialogue` is null" )
208
+ if is_playing ():
209
+ push_warning ("Theres already a running Dialogue!" )
203
210
else :
204
- print ("Starting Dialogue [%s ]..." % current_dialogue .source_path )
205
- current_dialogue_length = current_dialogue .sets .size ()
211
+ if dialogue != null :
212
+ current_dialogue = dialogue
213
+
214
+ if current_dialogue == null :
215
+ push_error ("Cannot start the Stage: `current_dialogue` is null" )
216
+ else :
217
+ print ("Starting Dialogue [%s ]..." % current_dialogue .source_path )
218
+ current_dialogue_length = current_dialogue .sets .size ()
206
219
207
- progress ()
208
- started .emit ()
220
+ progress ()
221
+ started .emit ()
209
222
223
+ # TODO
210
224
func switch_lang (lang : String = "" ) -> void :
211
225
if current_dialogue == null :
212
226
push_error ("Failed switching lang: current_dialogue is null" )
@@ -242,8 +256,7 @@ func switch_lang(lang : String = "") -> void:
242
256
if is_playing ():
243
257
current_dialogue_set = current_dialogue .sets [step ]
244
258
update_display ()
245
- if dialogue_label != null :
246
- dialogue_label .rerender ()
259
+ dialogue_label .rerender ()
247
260
248
261
func add_caller (id : String , node : Node ) -> void :
249
262
caller [id ] = node
0 commit comments