Skip to content

Commit

Permalink
Allow using the input action for choices
Browse files Browse the repository at this point in the history
  • Loading branch information
Jowan-Spooner committed Oct 26, 2024
1 parent db9ee2d commit e5e46ce
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
14 changes: 13 additions & 1 deletion addons/dialogic/Modules/Choice/subsystem_choices.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand Down
12 changes: 9 additions & 3 deletions addons/dialogic/Modules/Core/subsystem_input.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -88,23 +89,27 @@ func handle_input() -> void:
return

dialogic_action.emit()
input_was_mouse_input = false


## Unhandled Input is used for all NON-Mouse based inputs.
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()


## Input is used for all mouse based inputs.
## 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()


Expand All @@ -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:
Expand Down

0 comments on commit e5e46ce

Please sign in to comment.