aboutsummaryrefslogtreecommitdiff
path: root/client/menu/settings/input/input_manager.gd
diff options
context:
space:
mode:
Diffstat (limited to 'client/menu/settings/input/input_manager.gd')
-rw-r--r--client/menu/settings/input/input_manager.gd36
1 files changed, 35 insertions, 1 deletions
diff --git a/client/menu/settings/input/input_manager.gd b/client/menu/settings/input/input_manager.gd
index d216884b..640410d0 100644
--- a/client/menu/settings/input/input_manager.gd
+++ b/client/menu/settings/input/input_manager.gd
@@ -16,8 +16,15 @@
#
extends Node
+enum EventType {
+ KEYBOARD,
+ JOYPAD,
+ TOUCH,
+ OTHER
+}
+
var default_input_map = {}
-var input_map
+var input_map: Dictionary
func _init():
default_input_map = get_input_map()
@@ -31,6 +38,12 @@ func get_input_map() -> Dictionary:
kb[a] = input_events
return kb
+func get_events(action_name: String) -> Array:
+ if not input_map.has(action_name):
+ push_error("Tried to get action %s in input map which does not exist" % action_name)
+ return []
+ return input_map[action_name]
+
func input_map_to_settings(map: Dictionary) -> Array:
var entries := []
for k in map.keys():
@@ -68,3 +81,24 @@ func apply_input_map(new_input_map: Dictionary):
func reset_input_map():
Global.set_setting("input_map", default_input_map.duplicate())
apply_input_map(Global.get_setting("input_map"))
+
+func get_event_type(input_event: InputEvent) -> EventType:
+ if input_event is InputEventKey or input_event is InputEventMouseButton:
+ return EventType.KEYBOARD
+ elif input_event is InputEventJoypadButton or input_event is InputEventJoypadMotion:
+ return EventType.JOYPAD
+ elif input_event is InputEventScreenTouch or input_event is InputEventScreenDrag:
+ return EventType.TOUCH
+ return EventType.OTHER
+
+func display_input_event(input_event: InputEvent) -> String:
+ if input_event is InputEventKey:
+ return tr("c.settings.input.keyboard") % OS.get_keycode_string(input_event.physical_keycode)
+ elif input_event is InputEventMouseButton:
+ return tr("c.settings.input.mouse_button") % input_event.button_index
+ elif input_event is InputEventJoypadButton:
+ return tr("c.settings.input.joypad") % input_event.button_index
+ elif input_event is InputEventJoypadMotion:
+ return tr("c.settings.input.joypad_axis") % [input_event.axis]
+ else:
+ return tr("c.settings.input.other_event")