@@ -70,8 +70,8 @@ func post_install() -> void:
70
70
func hide_all_choices () -> void :
71
71
for node in get_tree ().get_nodes_in_group ('dialogic_choice_button' ):
72
72
node .hide ()
73
- if node .is_connected ('button_up' , _on_choice_selected ):
74
- node .disconnect ('button_up' , _on_choice_selected )
73
+ if node .pressed . is_connected (_on_choice_selected ):
74
+ node .pressed . disconnect (_on_choice_selected )
75
75
76
76
77
77
## Collects information on all the choices of the current question.
@@ -156,7 +156,7 @@ func show_current_question(instant:=true) -> void:
156
156
var question_info := get_current_question_info ()
157
157
158
158
for choice in question_info .choices :
159
- var node : DialogicNode_ChoiceButton = get_choice_button_node (choice .button_index )
159
+ var node : DialogicNode_ChoiceButton = get_choice_button (choice .button_index )
160
160
161
161
if not node :
162
162
missing_button = true
@@ -193,8 +193,24 @@ func show_current_question(instant:=true) -> void:
193
193
printerr ("[Dialogic] The layout you are using doesn't have enough Choice Buttons for the choices you are trying to display." )
194
194
195
195
196
+ func focus_choice (button_index :int ) -> void :
197
+ var node : DialogicNode_ChoiceButton = get_choice_button (button_index )
198
+ if node :
199
+ node .grab_focus ()
200
+
201
+
202
+ func select_choice (button_index :int ) -> void :
203
+ var node : DialogicNode_ChoiceButton = get_choice_button (button_index )
204
+ if node :
205
+ node .pressed .emit ()
206
+
207
+
208
+ func select_focused_choice () -> void :
209
+ if get_viewport ().gui_get_focus_owner () is DialogicNode_ChoiceButton :
210
+ (get_viewport ().gui_get_focus_owner () as DialogicNode_ChoiceButton ).pressed .emit ()
211
+
196
212
197
- func get_choice_button_node (button_index :int ) -> DialogicNode_ChoiceButton :
213
+ func get_choice_button (button_index :int ) -> DialogicNode_ChoiceButton :
198
214
var idx := 1
199
215
for node : DialogicNode_ChoiceButton in get_tree ().get_nodes_in_group ('dialogic_choice_button' ):
200
216
if ! node .get_parent ().is_visible_in_tree ():
@@ -229,6 +245,7 @@ func _on_choice_selected(choice_info := {}) -> void:
229
245
230
246
231
247
248
+ ## Returns the indexes of the choice events related to the current question.
232
249
func get_current_choice_indexes () -> Array :
233
250
var choices := []
234
251
var evt_idx := dialogic .current_event_idx
@@ -252,9 +269,10 @@ func get_current_choice_indexes() -> Array:
252
269
return choices
253
270
254
271
272
+ ## Forward the dialogic action to the focused button
255
273
func _on_dialogic_action () -> void :
256
- if get_viewport (). gui_get_focus_owner () is DialogicNode_ChoiceButton and use_input_action and not dialogic .Inputs .input_was_mouse_input :
257
- get_viewport (). gui_get_focus_owner (). pressed . emit ()
274
+ if use_input_action and not dialogic .Inputs .input_was_mouse_input :
275
+ select_focused_choice ()
258
276
259
277
260
278
#endregion
0 commit comments