-
Notifications
You must be signed in to change notification settings - Fork 11
Feature/settings menu populate #72
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
base: main
Are you sure you want to change the base?
Changes from all commits
0016c66
8caca9a
7f6844e
d55e8a3
186ef11
7b1b7df
3bd0582
e5e2196
a569753
7afd59f
bc98d15
3a8e5aa
ff63d0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <Project Sdk="Godot.NET.Sdk/4.6.0"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net9.0</TargetFramework> | ||
| <TargetFramework Condition=" '$(GodotTargetPlatform)' == 'windows' Or '$(OS)' == 'Windows_NT' ">net9.0-windows10.0.19041.0</TargetFramework> | ||
| <SupportedOSPlatformVersion Condition=" '$(GodotTargetPlatform)' == 'windows' Or '$(OS)' == 'Windows_NT' ">10.0.19041.0</SupportedOSPlatformVersion> | ||
| <EnableWindowsTargeting Condition=" '$(GodotTargetPlatform)' == 'windows' Or '$(OS)' == 'Windows_NT' ">true</EnableWindowsTargeting> | ||
| <EnableDynamicLoading>true</EnableDynamicLoading> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Tmds.DBus" Version="0.93.0" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Remove="addons/launch_monitors/common/bluetooth/windows/**/*.cs" Condition=" '$(GodotTargetPlatform)' != 'windows' And '$(OS)' != 'Windows_NT' " /> | ||
| </ItemGroup> | ||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,35 @@ | ||
| extends Control | ||
| # TODO - add settings menu system on future PR. | ||
|
|
||
| @onready var _settings_button: Button = $VerticalLayout/TopStrip/HBoxContainer/SettingsButton | ||
| @onready var _exit_button: Button = $VerticalLayout/TopStrip/HBoxContainer/ExitButton | ||
| @onready var _courses_button: Button = $VerticalLayout/TilesRow/CoursesTile/CoursesTextBackdrop/CoursesButton | ||
| @onready var _range_button: Button = $VerticalLayout/TilesRow/RangeTile/RangeTextBackdrop/RangeButton | ||
| @onready var _version_label: Label = $VerticalLayout/VersionLabel | ||
| @onready var _version_label: Label = $BottomInfoBar/VersionLabel | ||
| @onready var _launch_monitor_status: HBoxContainer = $BottomInfoBar/LaunchMonitorStatus | ||
| @onready var _launch_monitor_status_label: Label = $BottomInfoBar/LaunchMonitorStatus/StatusLabel | ||
| @onready var _launch_monitor_battery_label: Label = $BottomInfoBar/LaunchMonitorStatus/BatteryLabel | ||
| @onready var _launch_monitor_firmware_label: Label = $BottomInfoBar/LaunchMonitorStatus/FirmwareLabel | ||
| @onready var _settings_panel: SettingsPanel = $SettingsPanel | ||
| var _version_fall_back: String = "dev" | ||
| var _version_setting_path: String = "application/config/version" | ||
| var _version_text: String | ||
|
|
||
|
|
||
| # Called when the node enters the scene tree for the first time. | ||
| func _ready(): | ||
|
|
||
| func _ready() -> void: | ||
| _exit_button.pressed.connect(_on_exit_pressed) | ||
| _settings_button.pressed.connect(_on_settings_pressed) | ||
| _settings_button.pressed.connect(_settings_panel.show_panel) | ||
| _range_button.pressed.connect(_on_range_pressed) | ||
| _courses_button.pressed.connect(_on_courses_pressed) | ||
|
|
||
| _settings_panel.set_main_menu_button_visible(false) | ||
| _connect_launch_monitor_status_signals() | ||
|
|
||
| _update_version_label() | ||
| _update_launch_monitor_status() | ||
| SceneManager.current_scene = self | ||
|
|
||
|
|
||
| # Called every frame. 'delta' is the elapsed time since the previous frame. | ||
| func _process(_delta: float) -> void: | ||
| pass | ||
|
|
||
| func _exit_tree() -> void: | ||
| _disconnect_launch_monitor_status_signals() | ||
|
|
||
|
|
||
| func _on_range_pressed() -> void: | ||
|
|
@@ -35,16 +40,91 @@ func _on_courses_pressed() -> void: | |
| SceneManager.change_scene("res://Courses/CourseSelector/course_selector.tscn") | ||
|
|
||
|
|
||
| func _update_version_label(): | ||
| func _update_version_label() -> void: | ||
| _version_text = _version_fall_back | ||
| if (ProjectSettings.has_setting(_version_setting_path)): | ||
| var _configured_version = str(ProjectSettings.get_setting(_version_setting_path)).strip_edges() | ||
| _version_text = _configured_version; | ||
| _version_text = _configured_version | ||
|
|
||
| _version_label.text = "OSG Version %s" % _version_text | ||
|
|
||
|
|
||
| func _connect_launch_monitor_status_signals() -> void: | ||
| var refresh := _update_launch_monitor_status.unbind(1) | ||
| var launch_monitor = (LaunchMonitorManager as LaunchMonitorManagerAutoload) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the point of this line? we should be able to just refer to the autoload by name
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Defensive coding and captures typed cast, null-guard. Creates local instance as well which is usually safer than a static global init. |
||
| if launch_monitor != null: | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't need this null check here
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the cast fails, this catches it. |
||
| if not launch_monitor.status_changed.is_connected(refresh): | ||
| launch_monitor.status_changed.connect(refresh) | ||
| if not launch_monitor.battery_changed.is_connected(refresh): | ||
| launch_monitor.battery_changed.connect(refresh) | ||
| if not launch_monitor.firmware_changed.is_connected(refresh): | ||
| launch_monitor.firmware_changed.connect(refresh) | ||
|
|
||
| var global_settings = (GlobalSettingsManager as GlobalSettings) | ||
| if global_settings != null and global_settings.app_settings != null: | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't need these null checks |
||
| var app_settings: AppSettings = global_settings.app_settings | ||
| if not app_settings.launch_monitor_enabled.setting_changed.is_connected(refresh): | ||
| app_settings.launch_monitor_enabled.setting_changed.connect(refresh) | ||
| if not app_settings.launch_monitor_provider.setting_changed.is_connected(refresh): | ||
| app_settings.launch_monitor_provider.setting_changed.connect(refresh) | ||
|
|
||
|
|
||
| func _disconnect_launch_monitor_status_signals() -> void: | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the point of disconnecting all of these signals?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A lot of safety checks. Avoids dangling connections, which apparently we were having before. Avoid dup conn attempt since the pattern is now changed to instantiate on menu versus entire game. Safer to disconnect all, status firmware, battery, etc. |
||
| var refresh := _update_launch_monitor_status.unbind(1) | ||
| var launch_monitor = (LaunchMonitorManager as LaunchMonitorManagerAutoload) | ||
| if launch_monitor != null: | ||
| if launch_monitor.status_changed.is_connected(refresh): | ||
| launch_monitor.status_changed.disconnect(refresh) | ||
| if launch_monitor.battery_changed.is_connected(refresh): | ||
| launch_monitor.battery_changed.disconnect(refresh) | ||
| if launch_monitor.firmware_changed.is_connected(refresh): | ||
| launch_monitor.firmware_changed.disconnect(refresh) | ||
|
|
||
| var global_settings = (GlobalSettingsManager as GlobalSettings) | ||
| if global_settings != null and global_settings.app_settings != null: | ||
| var app_settings: AppSettings = global_settings.app_settings | ||
| if app_settings.launch_monitor_enabled.setting_changed.is_connected(refresh): | ||
| app_settings.launch_monitor_enabled.setting_changed.disconnect(refresh) | ||
| if app_settings.launch_monitor_provider.setting_changed.is_connected(refresh): | ||
| app_settings.launch_monitor_provider.setting_changed.disconnect(refresh) | ||
|
|
||
|
|
||
| func _update_launch_monitor_status() -> void: | ||
| var global_settings = (GlobalSettingsManager as GlobalSettings) | ||
| if global_settings == null or global_settings.app_settings == null: | ||
|
jeshernandez marked this conversation as resolved.
|
||
| _launch_monitor_status.visible = false | ||
| return | ||
|
|
||
| var app_settings: AppSettings = global_settings.app_settings | ||
| if not bool(app_settings.launch_monitor_enabled.value): | ||
| _launch_monitor_status.visible = false | ||
| return | ||
|
|
||
| var launch_monitor = (LaunchMonitorManager as LaunchMonitorManagerAutoload) | ||
|
jeshernandez marked this conversation as resolved.
|
||
| if launch_monitor == null: | ||
|
jeshernandez marked this conversation as resolved.
|
||
| _launch_monitor_status.visible = false | ||
| return | ||
|
|
||
| _launch_monitor_status.visible = true | ||
| var monitor_status := str(launch_monitor.status).strip_edges() | ||
| if monitor_status.begins_with("PiTrac Listening on"): | ||
| monitor_status = "" | ||
| if monitor_status != "": | ||
| _launch_monitor_status_label.text = "Status: %s" % monitor_status | ||
| else: | ||
| _launch_monitor_status_label.text = "Status: -" | ||
|
|
||
| var battery := int(launch_monitor.battery_level) | ||
| if battery >= 0: | ||
| _launch_monitor_battery_label.text = "Battery: %d%%" % battery | ||
| else: | ||
| _launch_monitor_battery_label.text = "Battery: -" | ||
|
|
||
| _version_label.text = "Version %s" % _version_text | ||
|
|
||
| func _on_settings_pressed() -> void: | ||
| pass # Replace with function body. | ||
| var firmware := str(launch_monitor.firmware).strip_edges() | ||
| if firmware != "": | ||
| _launch_monitor_firmware_label.text = "Firmware: %s" % firmware | ||
| else: | ||
| _launch_monitor_firmware_label.text = "Firmware: -" | ||
|
|
||
|
|
||
| func _on_exit_pressed() -> void: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requesting purpose statement comments for all functions. Kind of hard to parse whats really happening and whats really necessary