Add persistent light and dark themes

This commit is contained in:
hz
2026-07-14 13:39:42 -05:00
parent 04694e4932
commit abbe6cf9f8
8 changed files with 315 additions and 26 deletions
+28
View File
@@ -9,11 +9,15 @@ var user_label: Label
var app_menu: PanelContainer
var menu_exit_button: Button
var sound_toggle: CheckButton
var theme_button: Button
var theme_service
var current_screen_name := ""
func _ready() -> void:
theme_service = get_node("/root/UIThemeService")
Style.apply_app_theme(self)
_build_ui()
theme_service.theme_changed.connect(_on_theme_changed)
resized.connect(_update_responsive_layout)
_update_responsive_layout()
show_screen("selection" if AuthState.is_logged_in else "login", "exam")
@@ -92,6 +96,14 @@ func _build_ui() -> void:
user_label.gui_input.connect(_on_user_label_gui_input)
header.add_child(user_label)
theme_button = Button.new()
theme_button.custom_minimum_size = Vector2(44, 44)
theme_button.add_theme_font_size_override("font_size", 22)
UISoundService.set_button_sound(theme_button, "toggle")
theme_button.pressed.connect(theme_service.toggle_theme)
header.add_child(theme_button)
_refresh_theme_button()
var screens_container := MarginContainer.new()
screens_container.name = "Screens"
screens_container.size_flags_vertical = Control.SIZE_EXPAND_FILL
@@ -176,6 +188,22 @@ func _refresh_header_stats() -> void:
user_label.text = AuthState.username if AuthState.is_logged_in else ""
func _on_theme_changed(is_dark_mode: bool) -> void:
Style.refresh_tree(self, not is_dark_mode)
_refresh_theme_button()
var player = screens.get("player")
if player != null and player.has_method("refresh_theme_controls"):
player.refresh_theme_controls()
func _refresh_theme_button() -> void:
if theme_button == null:
return
theme_button.text = "☀" if theme_service.is_dark_mode() else "☾"
theme_button.tooltip_text = "Switch to light mode" if theme_service.is_dark_mode() else "Switch to dark mode"
Style.style_chip(theme_button, Style.CYAN)
func _logout() -> void:
_close_app_menu()
if BlockSessionService.block_started: