This commit was started by copying `addons/escoria-ui-9verbs` as the basis for `addons/escoria-ui-keyboard-9verbs`. It was then amended to wire up keyboard shortcuts for each verb using the new `register_custom_input_handler()` API. Note that `addons/escoria-ui-keyboard-9verbs/input_map.gd` introduces one action per verb and provides a `add_actions_to_input_map()` function to add the actions to the `InputMap`. The `_process_input()` function in `game.gd` is responsible for mapping each action to the appropriate call to `verbs_menu.on_action_selected()`.
33 lines
812 B
GDScript
33 lines
812 B
GDScript
extends Control
|
|
|
|
"""
|
|
This script is out of Escoria's scope. It controls the UI reaction to an
|
|
UI event (eg right click) to change the cursor accordingly.
|
|
"""
|
|
|
|
var selected_action
|
|
|
|
func _ready():
|
|
for but in get_children():
|
|
but.connect("pressed", self, "on_action_selected", [but.name])
|
|
but.toggle_mode = true
|
|
|
|
func on_action_selected(action: String):
|
|
if escoria.inputs_manager.input_mode != escoria.inputs_manager.INPUT_ALL:
|
|
unselect_actions()
|
|
return
|
|
|
|
escoria.action_manager.set_current_action(action)
|
|
|
|
for but in get_children():
|
|
but.set_pressed(but.get_name() == action)
|
|
|
|
func unselect_actions():
|
|
for but in get_children():
|
|
but.set_pressed(false)
|
|
|
|
func set_by_name(action_name: String):
|
|
selected_action = action_name
|
|
for but in get_children():
|
|
but.set_pressed(but.get_name() == action_name)
|