Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(StateMachine): add state_added signal, more robust signal emission, and tests #387

Merged
merged 27 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4d4bac1
fix(StateMachine): add state_added signal, more robust signal emissio…
ShadowApex Aug 16, 2024
ef4712a
fix(StateMachine): refactor menus to use more robust state switching
ShadowApex Aug 16, 2024
9ab7220
fix(Dracula Theme): use correct quick bar panel style
ShadowApex Aug 17, 2024
e343e48
fix(Focus): add option to disable focus wrapping
ShadowApex Aug 17, 2024
e7f5b2d
feat(State Machine Watcher): add node to watch state machine changes
ShadowApex Aug 17, 2024
696738c
feat(Behvaior Node): add base class for behavior nodes
ShadowApex Aug 17, 2024
6a75f73
feat(Tab Setter): add behavior node to set tab index
ShadowApex Aug 17, 2024
1747f59
feat(Text Setter): add behavior node to set label text
ShadowApex Aug 17, 2024
cc9bdb8
fix(State Updater): add configuration warnings if state machine is no…
ShadowApex Aug 17, 2024
f1bef89
fix(Themes): add ThemeUtils class with method to get effective theme
ShadowApex Aug 17, 2024
1b93b7f
chore(Icons): add resource icons for behaviors
ShadowApex Aug 17, 2024
89d20cc
fix(Theme): themes will now be properly set on UI components
ShadowApex Aug 17, 2024
c5296e2
refactor(Menus): update all menus to use new state machine pattern
ShadowApex Aug 17, 2024
3f07584
fix(In Game State): clear and push states depending on in-game
ShadowApex Aug 18, 2024
9117b61
fix(Running Game Card): update to use new states
ShadowApex Aug 18, 2024
6f1855f
fix(Overlay): Un game overlay buttons no longer close the menu.
pastaq Aug 18, 2024
bc94b4f
fix(Focus) Fix focus on some menus
pastaq Aug 20, 2024
2df90bf
fix(Plugin Store Card): update focus and handle back input
ShadowApex Aug 21, 2024
a0533bf
fix(Plugin Settings): fix focus on expanding cards for plugin settings
ShadowApex Aug 21, 2024
175ae61
fix(OSK): Fix the OSK.
pastaq Aug 23, 2024
ebd0186
fix(Expandable Card): don't close card on OSK focus
ShadowApex Aug 23, 2024
68be14d
feat(Blur): add settings option to disable/enable blur when overlay i…
ShadowApex Aug 23, 2024
4503656
fix(Input): handle X button for search
ShadowApex Aug 23, 2024
1d8ad2c
fix(Input): handle left/right triggers for keyboard shifting
ShadowApex Aug 23, 2024
3140e2a
fix(Overlay Mode): Get overlay mode working with new state machines.
pastaq Aug 23, 2024
986b1e6
fix(Disks Menu): Refactor disks menu to work with the new focus methods.
pastaq Aug 23, 2024
c289117
chore(Various): minor fixes from code review
ShadowApex Aug 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ $(EXPORT_TEMPLATE):

.PHONY: debug
debug: $(IMPORT_DIR) ## Run the project in debug mode in gamescope
$(GAMESCOPE) --xwayland-count 2 -- \
$(GAMESCOPE) -e --xwayland-count 2 -- \
$(GODOT) --path $(PWD) --remote-debug tcp://127.0.0.1:6007 \
--position 320,140 res://entrypoint.tscn

Expand Down
1 change: 1 addition & 0 deletions assets/editor-icons/fluent--brain-circuit-24-filled.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions assets/editor-icons/fluent--brain-circuit-24-filled.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://dumpjvnmyvle0"
path="res://.godot/imported/fluent--brain-circuit-24-filled.svg-deafc844fbbb2acb1300ed1eab205035.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://assets/editor-icons/fluent--brain-circuit-24-filled.svg"
dest_files=["res://.godot/imported/fluent--brain-circuit-24-filled.svg-deafc844fbbb2acb1300ed1eab205035.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
1 change: 1 addition & 0 deletions assets/editor-icons/fluent--draw-text-24-filled.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions assets/editor-icons/fluent--draw-text-24-filled.svg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://b37mlly16qbny"
path="res://.godot/imported/fluent--draw-text-24-filled.svg-62a66cb94069dc7c979f10a171be9c30.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://assets/editor-icons/fluent--draw-text-24-filled.svg"
dest_files=["res://.godot/imported/fluent--draw-text-24-filled.svg-62a66cb94069dc7c979f10a171be9c30.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
8 changes: 7 additions & 1 deletion assets/state/state_machines/global_state_machine.tres
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
[gd_resource type="Resource" script_class="StateMachine" load_steps=2 format=3 uid="uid://cr544el0cqjlm"]
[gd_resource type="Resource" script_class="StateMachine" load_steps=6 format=3 uid="uid://cr544el0cqjlm"]

[ext_resource type="Resource" uid="uid://c640rq4e1xmrn" path="res://assets/state/states/in_game.tres" id="1_dtppc"]
[ext_resource type="Script" path="res://core/systems/state/state_machine.gd" id="1_dw1uo"]
[ext_resource type="Resource" uid="uid://bmgs1ngma1523" path="res://assets/state/states/in_game_menu.tres" id="2_pg6ge"]
[ext_resource type="Resource" uid="uid://cv3vduo0ojk1u" path="res://assets/state/states/menu.tres" id="3_4n6bo"]
[ext_resource type="Resource" uid="uid://dgbe422crufa4" path="res://assets/state/states/popup.tres" id="4_j3a4g"]

[resource]
script = ExtResource("1_dw1uo")
logger_name = "GlobalStateMachine"
minimum_states = 1
allowed_states = Array[Resource("res://core/systems/state/state.gd")]([ExtResource("1_dtppc"), ExtResource("2_pg6ge"), ExtResource("3_4n6bo"), ExtResource("4_j3a4g")])
8 changes: 8 additions & 0 deletions assets/state/state_machines/menu_state_machine.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[gd_resource type="Resource" script_class="StateMachine" load_steps=2 format=3 uid="uid://bcr6c0281lb5b"]

[ext_resource type="Script" path="res://core/systems/state/state_machine.gd" id="1_18avi"]

[resource]
script = ExtResource("1_18avi")
logger_name = "MenuStateMachine"
minimum_states = 0
14 changes: 14 additions & 0 deletions assets/state/state_machines/popup_state_machine.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[gd_resource type="Resource" script_class="StateMachine" load_steps=7 format=3 uid="uid://cadriyl38ny5y"]

[ext_resource type="Resource" uid="uid://e7bbebwf7guj" path="res://assets/state/states/main_menu.tres" id="1_7fvmm"]
[ext_resource type="Resource" uid="uid://bp807nlks8eq1" path="res://assets/state/states/quick_bar_menu.tres" id="2_detpa"]
[ext_resource type="Resource" uid="uid://bw0mtk7sso8m2" path="res://assets/state/states/power_menu.tres" id="3_0mhn6"]
[ext_resource type="Resource" uid="uid://dja3m1mevv6xw" path="res://assets/state/states/osk.tres" id="4_qu5fi"]
[ext_resource type="Resource" uid="uid://db5gbdl3xgwlq" path="res://assets/state/states/help_menu.tres" id="5_5ytlq"]
[ext_resource type="Script" path="res://core/systems/state/state_machine.gd" id="6_82te1"]

[resource]
script = ExtResource("6_82te1")
logger_name = "PopupStateMachine"
minimum_states = 0
allowed_states = Array[Resource("res://core/systems/state/state.gd")]([ExtResource("1_7fvmm"), ExtResource("2_detpa"), ExtResource("3_0mhn6"), ExtResource("4_qu5fi"), ExtResource("5_5ytlq")])
8 changes: 8 additions & 0 deletions assets/state/states/menu.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[gd_resource type="Resource" script_class="State" load_steps=2 format=3 uid="uid://cv3vduo0ojk1u"]

[ext_resource type="Script" path="res://core/systems/state/state.gd" id="1_8q8t2"]

[resource]
script = ExtResource("1_8q8t2")
name = "menu"
data = {}
8 changes: 8 additions & 0 deletions assets/state/states/popup.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[gd_resource type="Resource" script_class="State" load_steps=2 format=3 uid="uid://dgbe422crufa4"]

[ext_resource type="Script" path="res://core/systems/state/state.gd" id="1_t0m3s"]

[resource]
script = ExtResource("1_t0m3s")
name = "popup"
data = {}
2 changes: 1 addition & 1 deletion assets/styles/dracula/quick_bar_panel.tres
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[gd_resource type="StyleBoxFlat" format=3 uid="uid://br2w1fnanqkfa"]

[resource]
bg_color = Color(0.0823529, 0.0862745, 0.105882, 1)
bg_color = Color(0.156863, 0.164706, 0.211765, 1)
corner_radius_bottom_left = 10
shadow_size = 5
shadow_offset = Vector2(-4, 4)
6 changes: 3 additions & 3 deletions assets/themes/card_ui-dracula.tres
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
[ext_resource type="StyleBox" uid="uid://y3qbwgrt2wai" path="res://assets/styles/dracula/settings_menu_panel.tres" id="10_rxp5w"]
[ext_resource type="StyleBox" uid="uid://dj0ysj0o6beba" path="res://assets/styles/dracula/power_menu_panel.tres" id="10_u1qhh"]
[ext_resource type="StyleBox" uid="uid://bifp73vg5vmau" path="res://assets/styles/dracula/plugin_store_card_panel.tres" id="11_83cpl"]
[ext_resource type="StyleBox" uid="uid://daavpt58e7jlj" path="res://assets/styles/darksoul/quick_bar_panel.tres" id="14_fm0xr"]
[ext_resource type="StyleBox" uid="uid://br2w1fnanqkfa" path="res://assets/styles/dracula/quick_bar_panel.tres" id="15_354e6"]
ShadowApex marked this conversation as resolved.
Show resolved Hide resolved

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_s2sy6"]
bg_color = Color(0.133333, 0.137255, 0.180392, 1)
Expand Down Expand Up @@ -112,14 +112,14 @@ MainMenu/styles/panel = ExtResource("7_n80rp")
Notification/base_type = &"PanelContainer"
Notification/styles/panel = ExtResource("9_sy73e")
Panel/styles/panel = ExtResource("2_f7nj8")
PanelContainer/styles/panel = ExtResource("2_f7nj8")
PanelContainer/styles/panel = ExtResource("4_wqh56")
PluginStoreCard/base_type = &"PanelContainer"
PluginStoreCard/styles/panel = ExtResource("11_83cpl")
PowerMenu/base_type = &"PanelContainer"
PowerMenu/styles/panel = ExtResource("10_u1qhh")
ProgressBar/styles/fill = SubResource("StyleBoxFlat_4nys6")
QuickBar/base_type = &"PanelContainer"
QuickBar/styles/panel = ExtResource("14_fm0xr")
QuickBar/styles/panel = ExtResource("15_354e6")
RoundedPanel/base_type = &"PanelContainer"
RoundedPanel/styles/panel = SubResource("StyleBoxFlat_knf7f")
SearchBar/base_type = &"PanelContainer"
Expand Down
4 changes: 2 additions & 2 deletions core/global/gamescope.gd
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func get_window_pid(window_id: int, display: XWAYLAND) -> int:
## window was found.
func get_window_id(pid: int, display: XWAYLAND) -> int:
var display_name := get_display_name(display)
logger.debug("Getting Window ID for {0} on display {1}".format([pid, display_name]))
logger.trace("Getting Window ID for {0} on display {1}".format([pid, display_name]))
var xwayland := get_xwayland(display)
if not xwayland:
return -1
Expand All @@ -270,7 +270,7 @@ func get_window_id(pid: int, display: XWAYLAND) -> int:
func get_window_ids(pid: int, display: XWAYLAND) -> PackedInt32Array:
var window_ids := PackedInt32Array()
var display_name := get_display_name(display)
logger.debug("Getting Window ID for {0} on display {1}".format([pid, display_name]))
logger.trace("Getting Window ID for {0} on display {1}".format([pid, display_name]))
var xwayland := get_xwayland(display)
if not xwayland:
return window_ids
Expand Down
44 changes: 24 additions & 20 deletions core/global/launch_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,32 @@ var _apps_by_name: Dictionary = {}
var _data_dir: String = ProjectSettings.get_setting("OpenGamepadUI/data/directory")
var _persist_path: String = "/".join([_data_dir, "launcher.json"])
var _persist_data: Dictionary = {"version": 1}
var logger := Log.get_logger("LaunchManager", Log.LEVEL.INFO)
var _ogui_window_id: int
var should_manage_overlay := true
var logger := Log.get_logger("LaunchManager", Log.LEVEL.INFO)


# Connect to Gamescope signals
func _init() -> void:
# Grab the window ID of OpenGamepadUI
_ogui_window_id = gamescope.get_window_id(PID, gamescope.XWAYLAND.OGUI)

# When window focus changes, update the current app and gamepad profile
var on_focus_changed := func(from: int, to: int):
logger.info("Window focus changed from " + str(from) + " to: " + str(to))
var last_app := _current_app
_current_app = get_running_from_window_id(to)
# If there is no _current_app then another process opened this window. Find it.
if _current_app == null:
_current_app = _detect_running_app(to)
_current_app = _detect_running_app(to)

logger.debug("Last app: " + str(last_app) + " current_app: " + str(_current_app))
app_switched.emit(last_app, _current_app)

# If the app has a gamepad profile, set it
set_app_gamepad_profile(_current_app)
if to != _ogui_window_id and _current_app:
set_app_gamepad_profile(_current_app)

# If we don't want LaunchManager to manage overlay (I.E. overlay mode), return false always.
if not should_manage_overlay:
return
# If we don't want LaunchManager to manage overlay (I.E. overlay mode), return false always.
if not should_manage_overlay:
return

gamescope.focused_window_updated.connect(on_focus_changed)

Expand All @@ -94,20 +98,19 @@ func _init() -> void:
if not should_manage_overlay:
return

logger.debug("Enabling STEAM_OVERLAY.")
var ogui_window_id = gamescope.get_window_id(PID, gamescope.XWAYLAND.OGUI)
gamescope.set_overlay(ogui_window_id, 0)

logger.debug("Enabling STEAM_OVERLAY atom")
gamescope.set_overlay(_ogui_window_id, 0)

var on_game_state_exited := func(_to: State):
# Set the gamepad profile to the global profile
set_gamepad_profile("")

# If we don't want LaunchManager to manage overlay (I.E. overlay mode), return false always.
if not should_manage_overlay:
return

logger.debug("Removing STEAM_OVERLAY.")
var ogui_window_id = gamescope.get_window_id(PID, gamescope.XWAYLAND.OGUI)
logger.debug("Disabling STEAM_OVERLAY atom")
gamescope.set_overlay(ogui_window_id, 1)

in_game_state.state_entered.connect(on_game_state_entered)
Expand All @@ -118,12 +121,12 @@ func _init() -> void:
func _load_persist_data():
# Create the data directory if it doesn't exist
DirAccess.make_dir_absolute(_data_dir)

# Create our data file if it doesn't exist
if not FileAccess.file_exists(_persist_path):
logger.debug("LaunchManager: Launcher data does not exist. Creating it.")
_save_persist_data()

# Read our persistent data and parse it
var file: FileAccess = FileAccess.open(_persist_path, FileAccess.READ)
var data: String = file.get_as_text()
Expand Down Expand Up @@ -168,12 +171,12 @@ func launch(app: LibraryLaunchItem) -> RunningApp:
env = user_env
var sandboxing_key := ".".join(["use_sandboxing", app._provider_id])
var use_sandboxing := settings_manager.get_value(section, sandboxing_key, true) as bool

# Set the display environment if one was not set.
if not "DISPLAY" in env:
env["DISPLAY"] = gamescope.get_display_name(Gamescope.XWAYLAND.GAME)
var display := env["DISPLAY"] as String

# Set the OGUI ID environment variable
env["OGUI_ID"] = app.name

Expand Down Expand Up @@ -298,6 +301,7 @@ func set_app_gamepad_profile(app: RunningApp) -> void:

## Sets the gamepad profile for the running app with the given profile
func set_gamepad_profile(path: String, target_gamepad: String = "") -> void:
logger.warn("Set gamepad profile to:", path, "With target_gamepad:", target_gamepad)
# Discover the currently set gamepad to properly add additional capabilities based on that gamepad
var profile_modifier := target_gamepad
if target_gamepad.is_empty():
Expand Down Expand Up @@ -409,7 +413,7 @@ func _remove_running(app: RunningApp):


# Checks for running apps and updates our state accordingly
func _check_running() -> void:
func check_running() -> void:
# Find the root window
var root_id := gamescope.get_root_window_id(Gamescope.XWAYLAND.GAME)
if root_id < 0:
Expand Down
2 changes: 2 additions & 0 deletions core/systems/input/back_input_handler.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
extends Node
class_name BackInputHandler

## DEPRECATED: Use [InputWatcher] with [StateUpdater] instead

## The state machine to use to update when back input is pressed
@export var state_machine: StateMachine = preload(
"res://assets/state/state_machines/global_state_machine.tres"
Expand Down
20 changes: 15 additions & 5 deletions core/systems/input/focus_group.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class_name FocusGroup
@export var focus_stack: FocusStack
## The InputEvent that will trigger focusing a parent focus group
@export var back_action := "ogui_east"
## Whether or not to wrap around focus chains
@export var wrap_focus: bool = true

@export_category("Focus Group Neighbors")
@export var focus_neighbor_bottom: FocusGroup
Expand Down Expand Up @@ -144,7 +146,7 @@ func _input(event: InputEvent) -> void:
return

# Only handle back button pressed and when the guide button is not held
if not event.is_action_pressed(back_action) or Input.is_action_pressed("ogui_guide"):
if not event.is_action_released(back_action) or Input.is_action_pressed("ogui_guide"):
return

# Only handle input if a focus stack is defined
Expand Down Expand Up @@ -421,12 +423,20 @@ func _vbox_set_focus_tree(control_children: Array[Control]) -> void:
child.focus_next = control_children[i + 1].get_path()
child.focus_neighbor_bottom = control_children[i + 1].get_path()
else:
child.focus_next = control_children[0].get_path()
child.focus_neighbor_bottom = control_children[0].get_path()
if wrap_focus:
child.focus_next = control_children[0].get_path()
child.focus_neighbor_bottom = control_children[0].get_path()
else:
child.focus_next = control_children[i].get_path()
child.focus_neighbor_bottom = control_children[i].get_path()

# Index -1
child.focus_previous = control_children[i - 1].get_path()
child.focus_neighbor_top = control_children[i - 1].get_path()
if i == 0 and not wrap_focus:
child.focus_previous = control_children[i].get_path()
child.focus_neighbor_top = control_children[i].get_path()
else:
child.focus_previous = control_children[i - 1].get_path()
child.focus_neighbor_top = control_children[i - 1].get_path()

# Block leaving the UI element unless B button is pressed.
child.focus_neighbor_left = control_children[i].get_path()
Expand Down
Loading
Loading