idk richtext stuff
This commit is contained in:
@@ -86,7 +86,7 @@ func _enter_tree():
|
||||
_parse_input_actions()
|
||||
|
||||
func _exit_tree():
|
||||
Mapper.queue_free()
|
||||
Mapper = null
|
||||
|
||||
func _parse_input_actions():
|
||||
_custom_input_actions.clear()
|
||||
@@ -189,10 +189,13 @@ func refresh():
|
||||
func get_joypad_type(controller: int = _last_controller) -> ControllerSettings.Devices:
|
||||
return Mapper._get_joypad_type(controller, _settings.joypad_fallback)
|
||||
|
||||
func parse_path(path: String, input_type = _last_input_type, last_controller = _last_controller) -> Texture:
|
||||
func get_last_input_type() -> InputType:
|
||||
return _last_input_type
|
||||
|
||||
func parse_path(path: String, input_type = _last_input_type, last_controller = _last_controller, forced_controller_icon_style = ControllerSettings.Devices.NONE) -> Texture:
|
||||
if typeof(input_type) == TYPE_NIL:
|
||||
return null
|
||||
var root_paths := _expand_path(path, input_type, last_controller)
|
||||
var root_paths := _expand_path(path, input_type, last_controller, forced_controller_icon_style)
|
||||
for root_path in root_paths:
|
||||
if _load_icon(root_path):
|
||||
continue
|
||||
@@ -228,6 +231,7 @@ func parse_event_modifiers(event: InputEvent) -> Array[Texture]:
|
||||
for icon_path in _expand_path(modifier, InputType.KEYBOARD_MOUSE, -1):
|
||||
if _load_icon(icon_path) == OK:
|
||||
icons.push_back(_cached_icons[icon_path])
|
||||
break
|
||||
|
||||
return icons
|
||||
|
||||
@@ -270,7 +274,7 @@ func get_matching_event(path: String, input_type: InputType = _last_input_type,
|
||||
else:
|
||||
events = InputMap.action_get_events(path)
|
||||
|
||||
var fallback = null
|
||||
var fallbacks = []
|
||||
for event in events:
|
||||
if not is_instance_valid(event): continue
|
||||
|
||||
@@ -283,13 +287,15 @@ func get_matching_event(path: String, input_type: InputType = _last_input_type,
|
||||
# Use the first device specific mapping if there is one.
|
||||
if event.device == controller:
|
||||
return event
|
||||
# Otherwise use the first "all devices" mapping.
|
||||
elif fallback == null and event.device < 0:
|
||||
fallback = event
|
||||
# Otherwise, we create a fallback prioritizing events with 'ALL_DEVICE'
|
||||
if event.device < 0: # All-device event
|
||||
fallbacks.push_front(event)
|
||||
else:
|
||||
fallbacks.push_back(event)
|
||||
|
||||
return fallback
|
||||
return fallbacks[0] if not fallbacks.is_empty() else null
|
||||
|
||||
func _expand_path(path: String, input_type: int, controller: int) -> Array:
|
||||
func _expand_path(path: String, input_type: int, controller: int, forced_controller_icon_style = ControllerSettings.Devices.NONE) -> Array:
|
||||
var paths := []
|
||||
var base_paths := [
|
||||
_settings.custom_asset_dir + "/",
|
||||
@@ -298,20 +304,20 @@ func _expand_path(path: String, input_type: int, controller: int) -> Array:
|
||||
for base_path in base_paths:
|
||||
if base_path.is_empty():
|
||||
continue
|
||||
base_path += _convert_path_to_asset_file(path, input_type, controller)
|
||||
base_path += _convert_path_to_asset_file(path, input_type, controller, forced_controller_icon_style)
|
||||
|
||||
paths.push_back(base_path + "." + _base_extension)
|
||||
return paths
|
||||
|
||||
func _convert_path_to_asset_file(path: String, input_type: int, controller: int) -> String:
|
||||
func _convert_path_to_asset_file(path: String, input_type: int, controller: int, forced_controller_icon_style = ControllerSettings.Devices.NONE) -> String:
|
||||
match get_path_type(path):
|
||||
PathType.INPUT_ACTION:
|
||||
var event := get_matching_event(path, input_type, controller)
|
||||
if event:
|
||||
return _convert_event_to_path(event)
|
||||
return _convert_event_to_path(event, controller, forced_controller_icon_style)
|
||||
return path
|
||||
PathType.JOYPAD_PATH:
|
||||
return Mapper._convert_joypad_path(path, controller, _settings.joypad_fallback)
|
||||
return Mapper._convert_joypad_path(path, controller, _settings.joypad_fallback, forced_controller_icon_style)
|
||||
PathType.SPECIFIC_PATH, _:
|
||||
return path
|
||||
|
||||
@@ -372,7 +378,7 @@ func _convert_asset_file_to_tts(path: String) -> String:
|
||||
_:
|
||||
return path
|
||||
|
||||
func _convert_event_to_path(event: InputEvent):
|
||||
func _convert_event_to_path(event: InputEvent, controller: int = _last_controller, forced_controller_icon_style = ControllerSettings.Devices.NONE):
|
||||
if event is InputEventKey:
|
||||
# If this is a physical key, convert to localized scancode
|
||||
if event.keycode == 0:
|
||||
@@ -381,9 +387,9 @@ func _convert_event_to_path(event: InputEvent):
|
||||
elif event is InputEventMouseButton:
|
||||
return _convert_mouse_button_to_path(event.button_index)
|
||||
elif event is InputEventJoypadButton:
|
||||
return _convert_joypad_button_to_path(event.button_index, event.device)
|
||||
return _convert_joypad_button_to_path(event.button_index, controller, forced_controller_icon_style)
|
||||
elif event is InputEventJoypadMotion:
|
||||
return _convert_joypad_motion_to_path(event.axis, event.device)
|
||||
return _convert_joypad_motion_to_path(event.axis, controller, forced_controller_icon_style)
|
||||
|
||||
func _convert_key_to_path(scancode: int):
|
||||
match scancode:
|
||||
@@ -615,7 +621,7 @@ func _convert_mouse_button_to_path(button_index: int):
|
||||
_:
|
||||
return "mouse/sample"
|
||||
|
||||
func _convert_joypad_button_to_path(button_index: int, controller: int):
|
||||
func _convert_joypad_button_to_path(button_index: int, controller: int, forced_controller_icon_style = ControllerSettings.Devices.NONE):
|
||||
var path
|
||||
match button_index:
|
||||
JOY_BUTTON_A:
|
||||
@@ -652,9 +658,9 @@ func _convert_joypad_button_to_path(button_index: int, controller: int):
|
||||
path = "joypad/share"
|
||||
_:
|
||||
return ""
|
||||
return Mapper._convert_joypad_path(path, controller, _settings.joypad_fallback)
|
||||
return Mapper._convert_joypad_path(path, controller, _settings.joypad_fallback, forced_controller_icon_style)
|
||||
|
||||
func _convert_joypad_motion_to_path(axis: int, controller: int):
|
||||
func _convert_joypad_motion_to_path(axis: int, controller: int, forced_controller_icon_style = ControllerSettings.Devices.NONE):
|
||||
var path : String
|
||||
match axis:
|
||||
JOY_AXIS_LEFT_X, JOY_AXIS_LEFT_Y:
|
||||
@@ -667,7 +673,7 @@ func _convert_joypad_motion_to_path(axis: int, controller: int):
|
||||
path = "joypad/rt"
|
||||
_:
|
||||
return ""
|
||||
return Mapper._convert_joypad_path(path, controller, _settings.joypad_fallback)
|
||||
return Mapper._convert_joypad_path(path, controller, _settings.joypad_fallback, forced_controller_icon_style)
|
||||
|
||||
func _load_icon(path: String) -> int:
|
||||
if _cached_icons.has(path): return OK
|
||||
|
Reference in New Issue
Block a user