diff options
| author | tpart <tpart120@proton.me> | 2024-09-17 15:55:43 +0200 | 
|---|---|---|
| committer | tpart <tpart120@proton.me> | 2024-09-17 15:56:20 +0200 | 
| commit | c953a601500eead8161baf012e338e3ea496ceaf (patch) | |
| tree | 59867880437e86d4e1b74720210c70770b50852f /client/menu/settings | |
| parent | ea5e8bad363a6e490c787b0e5f13bb6defd4c450 (diff) | |
| download | hurrycurry-c953a601500eead8161baf012e338e3ea496ceaf.tar hurrycurry-c953a601500eead8161baf012e338e3ea496ceaf.tar.bz2 hurrycurry-c953a601500eead8161baf012e338e3ea496ceaf.tar.zst  | |
Refactor hints system to use new input manager; Add input manager helper function; Fix lots of bugs; Update translations
Diffstat (limited to 'client/menu/settings')
| -rw-r--r-- | client/menu/settings/input/input_manager.gd | 36 | ||||
| -rw-r--r-- | client/menu/settings/input/input_value_node.gd | 15 | 
2 files changed, 37 insertions, 14 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") diff --git a/client/menu/settings/input/input_value_node.gd b/client/menu/settings/input/input_value_node.gd index 9f89416b..ef00c09b 100644 --- a/client/menu/settings/input/input_value_node.gd +++ b/client/menu/settings/input/input_value_node.gd @@ -34,20 +34,9 @@ func update(fix_focus: bool = false):  		c.queue_free()  	for e: InputEvent in value: -		var description: String -		 -		if e is InputEventKey: -			description = tr("%s (Keyboard)") % OS.get_keycode_string(e.physical_keycode) -		elif e is InputEventMouseButton: -			description = tr("Mouse button %s") % e.button_index -		elif e is InputEventJoypadButton: -			description = tr("%s (Joypad)") % e.button_index -		elif e is InputEventJoypadMotion: -			description = tr("Joypad axis %s") % [e.axis] -		else: -			description = tr("Other event") -		 +		var description: String = InputManager.display_input_event(e)  		var button := Button.new() +		  		button.text = description  		button.pressed.connect(erase_event.bind(e))  		actions_container.add_child(button)  |