Skip to content

Commit 4d89024

Browse files
committed
fix(Default Profiles): Seperate overlay and full session defualt profiles
1 parent def7b75 commit 4d89024

File tree

13 files changed

+137
-52
lines changed

13 files changed

+137
-52
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
"version": 1,
3+
"kind": "DeviceProfile",
4+
"name": "OpenGamepadUI Default",
5+
"mapping": [
6+
{
7+
"name": "LeftTop",
8+
"source_event": {
9+
"gamepad": {
10+
"button": "LeftTop"
11+
}
12+
},
13+
"target_events": [
14+
{
15+
"gamepad": {
16+
"button": "Guide"
17+
}
18+
},
19+
{
20+
"gamepad": {
21+
"button": "North"
22+
}
23+
}
24+
]
25+
},
26+
{
27+
"name": "RightTop",
28+
"source_event": {
29+
"gamepad": {
30+
"button": "RightTop"
31+
}
32+
},
33+
"target_events": [
34+
{
35+
"gamepad": {
36+
"button": "Guide"
37+
}
38+
},
39+
{
40+
"gamepad": {
41+
"button": "East"
42+
}
43+
}
44+
]
45+
},
46+
{
47+
"name": "Keyboard",
48+
"source_event": {
49+
"gamepad": {
50+
"button": "Keyboard"
51+
}
52+
},
53+
"target_events": [
54+
{
55+
"dbus": "ui_osk"
56+
}
57+
]
58+
},
59+
{
60+
"name": "QuickAccess2",
61+
"source_event": {
62+
"gamepad": {
63+
"button": "QuickAccess2"
64+
}
65+
},
66+
"target_events": [
67+
{
68+
"gamepad": {
69+
"button": "Guide"
70+
}
71+
},
72+
{
73+
"gamepad": {
74+
"button": "East"
75+
}
76+
}
77+
]
78+
},
79+
]
80+
}

core/global/launch_manager.gd

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ var _ogui_window_id := 0
6666
var should_manage_overlay := true
6767
var logger := Log.get_logger("LaunchManager", Log.LEVEL.INFO)
6868
var _focused_app_id := 0
69-
69+
var _input_manager: InputManager
7070

7171
# Connect to Gamescope signals
7272
func _init() -> void:
@@ -212,6 +212,11 @@ func _save_persist_data():
212212
file.flush()
213213

214214

215+
# Get access to nodes from the scene tree and other goodies
216+
func setup(input_manager: InputManager):
217+
_input_manager = input_manager
218+
219+
215220
## Launches the given application and switches to the in-game state. Returns a
216221
## [RunningApp] instance of the application.
217222
func launch(app: LibraryLaunchItem) -> RunningApp:
@@ -491,10 +496,10 @@ func set_gamepad_profile(path: String, target_gamepad: String = "") -> void:
491496
# If no profile was specified, unset the gamepad profiles
492497
if path == "":
493498
# Try check to see if there is a global gamepad setting
494-
path = settings_manager.get_value("input", "gamepad_profile", InputPlumber.DEFAULT_GLOBAL_PROFILE) as String
499+
path = settings_manager.get_value("input", "gamepad_profile", _input_manager.get_default_global_profile_path()) as String
495500
# Verify we loaded a valid profile, or fallback.
496501
if not path.ends_with(".json") or not FileAccess.file_exists(path):
497-
path = InputPlumber.DEFAULT_GLOBAL_PROFILE
502+
path = _input_manager.get_default_global_profile_path()
498503

499504
logger.info("Loading gamepad profile: " + path)
500505
if not FileAccess.file_exists(path):

core/systems/input/input_manager.gd

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,29 @@ var current_touches := 0
4242
## Will show logger events with the prefix InputManager
4343
var logger := Log.get_logger("InputManager", Log.LEVEL.INFO)
4444

45+
const PROFILES_DIR := "user://data/gamepad/profiles"
46+
47+
48+
func _init() -> void:
49+
# Ensure the default global profile exists in the user directory.
50+
var default_global_profile := get_default_global_profile_path()
51+
var default_profile := _get_default_profile_path()
52+
if FileAccess.file_exists(default_global_profile):
53+
return
54+
55+
var file := FileAccess.open(default_profile, FileAccess.READ)
56+
var content := file.get_as_text()
57+
file.close()
58+
if DirAccess.make_dir_recursive_absolute(PROFILES_DIR) != OK:
59+
var logger := Log.get_logger("InputPlumber", Log.LEVEL.DEBUG)
60+
logger.error("Failed to create gamepad profiles directory")
61+
var new_file := FileAccess.open(default_global_profile, FileAccess.WRITE)
62+
new_file.store_string(content)
63+
new_file.close()
64+
4565

4666
# Called when the node enters the scene tree for the first time.
4767
func _ready() -> void:
48-
add_to_group("InputManager")
4968
input_plumber.composite_device_added.connect(_watch_dbus_device)
5069
input_plumber.started.connect(_init_inputplumber)
5170
_init_inputplumber()
@@ -55,6 +74,13 @@ func _init_inputplumber() -> void:
5574
for device in input_plumber.get_composite_devices():
5675
_watch_dbus_device(device)
5776

77+
func _get_default_profile_path() -> String:
78+
return "res://assets/gamepad/profiles/default.json"
79+
80+
func get_default_global_profile_path() -> String:
81+
return "user://data/gamepad/profiles/global_default.json"
82+
83+
5884

5985
## Returns true if the given event is an InputPlumber event
6086
static func is_inputplumber_event(event: InputEvent) -> bool:

core/systems/input/input_manager.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[ext_resource type="Script" uid="uid://blpngehu3py28" path="res://core/systems/input/input_plumber.gd" id="2_v1kl3"]
55
[ext_resource type="InputPlumberInstance" uid="uid://e2bevy4j4rx2" path="res://core/systems/input/input_plumber.tres" id="3_eclcy"]
66

7-
[node name="InputManager" type="Node"]
7+
[node name="InputManager" type="Node" groups=["input_manager"]]
88
script = ExtResource("1_3s67x")
99

1010
[node name="InputPlumber" type="Node" parent="."]

core/systems/input/input_plumber.gd

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,12 @@ class_name InputPlumber
77
## The InputPlumberManager class is responsible for handling dbus messages to and
88
## from the InputPlumber input manager daemon.
99

10-
const DEFAULT_PROFILE := "res://assets/gamepad/profiles/default.json"
11-
const DEFAULT_GLOBAL_PROFILE := "user://data/gamepad/profiles/global_default.json"
12-
const PROFILES_DIR := "user://data/gamepad/profiles"
13-
1410
@export var instance: InputPlumberInstance = load("res://core/systems/input/input_plumber.tres")
1511

1612
# Keep a reference to dbus devices so they are not cleaned up automatically
1713
var _dbus_devices := {}
1814

1915

20-
func _init() -> void:
21-
# Ensure the default global profile exists in the user directory.
22-
if not FileAccess.file_exists(DEFAULT_GLOBAL_PROFILE):
23-
var file := FileAccess.open(DEFAULT_PROFILE, FileAccess.READ)
24-
var content := file.get_as_text()
25-
file.close()
26-
if DirAccess.make_dir_recursive_absolute(PROFILES_DIR) != OK:
27-
var logger := Log.get_logger("InputPlumber", Log.LEVEL.DEBUG)
28-
logger.error("Failed to create gamepad profiles directory")
29-
var new_file := FileAccess.open(DEFAULT_GLOBAL_PROFILE, FileAccess.WRITE)
30-
new_file.store_string(content)
31-
new_file.close()
32-
33-
3416
func _ready() -> void:
3517
# Add listeners for any new devices
3618
var on_device_added := func(device: CompositeDevice):

core/systems/input/overlay_mode_input_manager.gd

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@icon("res://assets/editor-icons/material-symbols-joystick.svg")
2-
extends Node
2+
extends InputManager
33
class_name OverlayInputManager
44

55
## Manages global input while ion overlay mode
@@ -11,33 +11,11 @@ class_name OverlayInputManager
1111
## To include this functionality, add this as a node to the root node in the
1212
## scene tree.
1313

14-
## The audio manager to use to adjust the audio when audio input events happen.
15-
var audio_manager := load("res://core/global/audio_manager.tres") as AudioManager
16-
## InputPlumber receives and sends DBus input events.
17-
var input_plumber := load("res://core/systems/input/input_plumber.tres") as InputPlumberInstance
18-
## LaunchManager provides context on the currently running app so we can switch profiles
19-
var launch_manager := load("res://core/global/launch_manager.tres") as LaunchManager
20-
## The Global State Machine
21-
var state_machine := load("res://assets/state/state_machines/global_state_machine.tres") as StateMachine
22-
## State machine to use to switch menu states in response to input events.
23-
var popup_state_machine := (
24-
preload("res://assets/state/state_machines/popup_state_machine.tres") as StateMachine
25-
)
2614
var menu_state_machine := preload("res://assets/state/state_machines/menu_state_machine.tres") as StateMachine
27-
var in_game_menu_state := preload("res://assets/state/states/in_game_menu.tres") as State
28-
var main_menu_state := preload("res://assets/state/states/main_menu.tres") as State
29-
var quick_bar_state := preload("res://assets/state/states/quick_bar_menu.tres") as State
3015
var base_state = preload("res://assets/state/states/in_game.tres") as State
3116

32-
var actions_pressed := {}
33-
34-
## Will show logger events with the prefix InputManager(Overlay Mode)
35-
var logger := Log.get_logger("InputManager(Overlay Mode)", Log.LEVEL.INFO)
36-
37-
3817
# Called when the node enters the scene tree for the first time.
3918
func _ready() -> void:
40-
add_to_group("InputManager")
4119
input_plumber.composite_device_added.connect(_watch_dbus_device)
4220
input_plumber.started.connect(_init_inputplumber)
4321
_init_inputplumber()
@@ -48,6 +26,14 @@ func _init_inputplumber() -> void:
4826
_watch_dbus_device(device)
4927

5028

29+
func _get_default_profile_path() -> String:
30+
return "res://assets/gamepad/profiles/default_overlay.json"
31+
32+
33+
func get_default_global_profile_path() -> String:
34+
return "user://data/gamepad/profiles/global_default_overlay.json"
35+
36+
5137
## Queue a release event for the given action
5238
func action_release(dbus_path: String, action: String, strength: float = 1.0) -> void:
5339
Input.action_release(action)

core/systems/input/overlay_mode_input_manager.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[ext_resource type="Script" uid="uid://cwuxmp5lmsvgt" path="res://core/systems/input/overlay_mode_input_manager.gd" id="1_fvwoc"]
44
[ext_resource type="Script" uid="uid://blpngehu3py28" path="res://core/systems/input/input_plumber.gd" id="2_vf8uv"]
55

6-
[node name="InputManager" type="Node"]
6+
[node name="InputManager" type="Node" groups=["input_manager"]]
77
script = ExtResource("1_fvwoc")
88

99
[node name="InputPlumber" type="Node" parent="."]

core/systems/launcher/launcher.gd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class_name Launcher
55
@export var launch_manager := preload("res://core/global/launch_manager.tres") as LaunchManager
66

77
@onready var overlay_display = OS.get_environment("DISPLAY")
8-
8+
@onready var input_manager := get_tree().get_first_node_in_group("input_manager") as InputManager
99

1010
func _init() -> void:
1111
launch_manager._load_persist_data()
@@ -18,3 +18,6 @@ func _ready() -> void:
1818
timer.wait_time = 1
1919
timer.timeout.connect(launch_manager.check_running)
2020
add_child(timer)
21+
22+
# Give the launch manager access to the input manager
23+
launch_manager.setup(input_manager)

core/ui/card_ui/card_ui.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var overlay_window_id := 0
3333
@onready var fade_texture := $%FadeTexture as TextureRect
3434
@onready var power_timer := $%PowerTimer as Timer
3535
@onready var settings_menu := $%SettingsMenu as Control
36+
@onready var input_manager := get_tree().get_first_node_in_group("input_manager") as InputManager
3637

3738
var logger = Log.get_logger("Main", Log.LEVEL.INFO)
3839

core/ui/card_ui/gamepad/gamepad_settings.gd

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var logger := Log.get_logger("GamepadSettings", Log.LEVEL.INFO)
4040
@onready var delete_button := $%DeleteButton as CardIconButton
4141
@onready var profile_label := $%ProfileNameLabel as Label
4242
@onready var gamepad_type_dropdown := %GamepadTypeDropdown as Dropdown
43+
@onready var input_manager := get_tree().get_first_node_in_group("input_manager") as InputManager
4344

4445

4546
# Called when the node enters the scene tree for the first time.
@@ -149,7 +150,7 @@ func _on_state_entered(_from: State) -> void:
149150
var profile_path: String
150151
if not self.library_item:
151152
self.profile_label.text = "Global"
152-
profile_path = settings_manager.get_value("input", "gamepad_profile", InputPlumber.DEFAULT_GLOBAL_PROFILE) as String
153+
profile_path = settings_manager.get_value("input", "gamepad_profile", input_manager.get_default_global_profile_path()) as String
153154
else:
154155
self.profile_label.text = self.library_item.name
155156
profile_path = settings_manager.get_library_value(self.library_item, "gamepad_profile", "") as String
@@ -685,7 +686,7 @@ func _save_profile() -> void:
685686
func _load_profile(profile_path: String = "") -> InputPlumberProfile:
686687
var loaded: InputPlumberProfile
687688
if profile_path == "" or not profile_path.ends_with(".json") or not FileAccess.file_exists(profile_path):
688-
loaded = InputPlumberProfile.load(InputPlumber.DEFAULT_GLOBAL_PROFILE)
689+
loaded = InputPlumberProfile.load(input_manager.get_default_global_profile_path())
689690
if not loaded:
690691
loaded = InputPlumberProfile.new()
691692
if library_item:

0 commit comments

Comments
 (0)