@@ -2,7 +2,6 @@ extends Control
22
33const USER_TEMPLATES := "user://data/gamepad/templates"
44const USER_PROFILES := "user://data/gamepad/profiles"
5- const GLOBAL_PROFILE_PATH := "user://data/gamepad/profiles/global.json"
65
76var change_input_state := preload ("res://assets/state/states/gamepad_change_input.tres" ) as State
87var gamepad_state := load ("res://assets/state/states/gamepad_settings.tres" ) as State
@@ -74,8 +73,16 @@ func _ready() -> void:
7473 # Load the default profile
7574 var profile_path = settings_manager .get_value ("input" , "gamepad_profile" , "" )
7675 self .profile_gamepad = settings_manager .get_value ("input" , "gamepad_profile_target" , "" )
77- for composite_device in input_plumber .get_composite_devices ():
78- _set_gamepad_profile (composite_device , profile_path )
76+ if not self .profile_gamepad :
77+ # Set the current profile_gamepad type to the currently configured CompositeDevice target gamepad
78+ var targets = gamepad .get_target_devices ()
79+ for target in targets :
80+ var target_dbus_path : String = target .get ("dbus_path" )
81+ if not target_dbus_path .contains ("target/gamepad" ):
82+ continue
83+ self .profile_gamepad = target .get ("device_type" )
84+ break
85+ _set_gamepad_profile (gamepad , profile_path )
7986
8087 # Grab focus when the mapper exits
8188 var on_state_changed := func (_from : State , to : State ):
@@ -131,7 +138,7 @@ func _on_state_entered(_from: State) -> void:
131138
132139 # Set the gamepad name label
133140 gamepad_label .text = self .gamepad .name
134-
141+
135142 # Populate the menu with the source inputs for the given gamepad
136143 populate_mappings_for (self .gamepad )
137144
@@ -146,17 +153,31 @@ func _on_state_entered(_from: State) -> void:
146153 if not self .library_item :
147154 self .library_item = launch_manager .get_current_app_library_item ()
148155
156+ # Set the current profile_gamepad type to the currently configured CompositeDevice target gamepad
157+ var targets = gamepad .get_target_devices ()
158+ for target in targets :
159+ var target_dbus_path : String = target .get ("dbus_path" )
160+ if not target_dbus_path .contains ("target/gamepad" ):
161+ continue
162+ self .profile_gamepad = target .get ("device_type" )
163+ break
164+
149165 # If no library item was set with the state, then configure the OGUI profile
150166 var profile_path : String
151167 if not self .library_item :
152168 self .profile_label .text = "Global"
153169 profile_path = settings_manager .get_value ("input" , "gamepad_profile" , input_manager .get_default_global_profile_path ()) as String
170+ # Check if we have a profile target, otherwise use the currently set one
171+ self .profile_gamepad = settings_manager .get_value ("input" , "gamepad_profile_target" , self .profile_gamepad )
154172 else :
155173 self .profile_label .text = self .library_item .name
156174 profile_path = settings_manager .get_library_value (self .library_item , "gamepad_profile" , "" ) as String
157- self .profile_gamepad = settings_manager .get_library_value (self .library_item , "gamepad_profile_target" , "" ) as String
175+ # Check if we have a profile target, otherwise use the currently set one
176+ self .profile_gamepad = settings_manager .get_library_value (self .library_item , "gamepad_profile_target" , self .profile_gamepad ) as String
158177
159178 self .profile = _load_profile (profile_path )
179+ logger .debug ("Set profile target gamepad to " + self .profile_gamepad )
180+
160181 _update_mapping_elements ()
161182
162183 # Clear focus
@@ -196,7 +217,7 @@ func populate_mappings_for(gamepad: CompositeDevice) -> void:
196217 # Sort the capabilities
197218 capabilities = InputPlumberEvent .sort_capabilities (capabilities )
198219 capabilities .reverse ()
199- logger .debug ("Found capabilities for gamepad : " + str (capabilities ))
220+ logger .debug ("Found capabilities for " + gamepad_name + " : " + str (capabilities ))
200221
201222 # Delete any old UI elements
202223 for child in container .get_children ():
@@ -390,9 +411,10 @@ func _add_group_for_capability(gamepad_name: String, capability: String, parent:
390411
391412## Syncs the UI to the given profile
392413func _update_mapping_elements () -> void :
393- if not profile :
414+ if not self . profile :
394415 return
395- profile_label .text = profile .name
416+
417+ self .profile_label .text = self .profile .name
396418
397419 # Update the dropdown based on the profile's target gamepad type
398420 if not self .profile_gamepad .is_empty ():
@@ -634,7 +656,7 @@ func _save_profile() -> void:
634656 logger .debug ("No library item loaded to associate profile with" )
635657 # Save the profile
636658 @warning_ignore ("confusable_local_declaration" )
637- var path := GLOBAL_PROFILE_PATH
659+ var path := input_manager . get_default_global_profile_path ()
638660 if profile .save (path ) != OK :
639661 logger .error ("Failed to save global gamepad profile to: " + path )
640662 notify .text = "Failed to save global gamepad profile"
@@ -646,8 +668,8 @@ func _save_profile() -> void:
646668 settings_manager .set_value ("input" , "gamepad_profile" , path )
647669 settings_manager .set_value ("input" , "gamepad_profile_target" , self .profile_gamepad )
648670
649- for gamepad in input_plumber .get_composite_devices ():
650- _set_gamepad_profile (gamepad , path )
671+ for device : CompositeDevice in input_plumber .get_composite_devices ():
672+ _set_gamepad_profile (device , path )
651673
652674 logger .debug ("Saved global gamepad profile to: " + path )
653675 notify .text = "Global gamepad profile saved"
0 commit comments