From e5e46ce13b284505b04d5220d72f9288ccc5ae29 Mon Sep 17 00:00:00 2001 From: Jowan-Spooner Date: Sun, 29 Sep 2024 16:26:41 +0200 Subject: [PATCH] Allow using the input action for choices --- .../dialogic/Modules/Choice/subsystem_choices.gd | 14 +++++++++++++- addons/dialogic/Modules/Core/subsystem_input.gd | 12 +++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/addons/dialogic/Modules/Choice/subsystem_choices.gd b/addons/dialogic/Modules/Choice/subsystem_choices.gd index 13d61cc5c..aa7caa9ac 100644 --- a/addons/dialogic/Modules/Choice/subsystem_choices.gd +++ b/addons/dialogic/Modules/Choice/subsystem_choices.gd @@ -19,7 +19,9 @@ var reveal_by_input := false var block_delay := 0.2 ## If true, the first (top-most) choice will be focused var autofocus_first_choice := true - +## If true the dialogic input action is used to trigger choices. +## However mouse events will be ignored no matter what. +var use_input_action := false enum FalseBehaviour {HIDE=0, DISABLE=1} ## The behaviour of choices with a false condition and else_action set to DEFAULT. @@ -54,6 +56,10 @@ func _ready() -> void: hotkey_behaviour = ProjectSettings.get_setting('dialogic/choices/hotkey_behaviour', hotkey_behaviour) default_false_behaviour = ProjectSettings.get_setting('dialogic/choices/def_false_behaviour', default_false_behaviour) + +func post_install() -> void: + dialogic.Inputs.dialogic_action.connect(_on_dialogic_action) + #endregion @@ -244,6 +250,12 @@ func get_current_choice_indexes() -> Array: evt_idx += 1 return choices + +func _on_dialogic_action() -> void: + if get_viewport().gui_get_focus_owner() is DialogicNode_ChoiceButton and use_input_action and not dialogic.Inputs.input_was_mouse_input: + get_viewport().gui_get_focus_owner().pressed.emit() + + #endregion diff --git a/addons/dialogic/Modules/Core/subsystem_input.gd b/addons/dialogic/Modules/Core/subsystem_input.gd index 1c21f695f..dec4f657a 100644 --- a/addons/dialogic/Modules/Core/subsystem_input.gd +++ b/addons/dialogic/Modules/Core/subsystem_input.gd @@ -18,6 +18,7 @@ const _SETTING_INPUT_ACTION_DEFAULT := "dialogic_default_action" var input_block_timer := Timer.new() var _auto_skip_timer_left: float = 0.0 var action_was_consumed := false +var input_was_mouse_input := false var auto_skip: DialogicAutoSkip = null var auto_advance: DialogicAutoAdvance = null @@ -88,6 +89,7 @@ func handle_input() -> void: return dialogic_action.emit() + input_was_mouse_input = false ## Unhandled Input is used for all NON-Mouse based inputs. @@ -95,6 +97,7 @@ func _unhandled_input(event:InputEvent) -> void: if is_input_pressed(event, true): if event is InputEventMouse or event is InputEventScreenTouch: return + input_was_mouse_input = false handle_input() @@ -102,9 +105,11 @@ func _unhandled_input(event:InputEvent) -> void: ## If any DialogicInputNode is present this won't do anything (because that node handles MouseInput then). func _input(event:InputEvent) -> void: if is_input_pressed(event): - if not event is InputEventMouse or get_tree().get_nodes_in_group('dialogic_input').any(func(node):return node.is_visible_in_tree()): + if not event is InputEventMouse: return - + if get_tree().get_nodes_in_group('dialogic_input').any(func(node):return node.is_visible_in_tree()): + return + input_was_mouse_input = true handle_input() @@ -117,7 +122,8 @@ func is_input_pressed(event: InputEvent, exact := false) -> bool: func handle_node_gui_input(event:InputEvent) -> void: if Input.is_action_just_pressed(ProjectSettings.get_setting(_SETTING_INPUT_ACTION, _SETTING_INPUT_ACTION_DEFAULT)): if event is InputEventMouseButton and event.pressed: - DialogicUtil.autoload().Inputs.handle_input() + input_was_mouse_input = true + handle_input() func is_input_blocked() -> bool: