Add core game retry flow and question stats
This commit is contained in:
+93
-16
@@ -6,14 +6,18 @@ var screens := {}
|
||||
var header_stats: Label
|
||||
var header_panel: PanelContainer
|
||||
var user_label: Label
|
||||
var app_menu: PanelContainer
|
||||
var menu_exit_button: Button
|
||||
var current_screen_name := ""
|
||||
|
||||
func _ready() -> void:
|
||||
Style.apply_app_theme(self)
|
||||
_build_ui()
|
||||
show_screen("menu" if AuthState.is_logged_in else "login")
|
||||
show_screen("dashboard" if AuthState.is_logged_in else "login")
|
||||
|
||||
|
||||
func show_screen(screen_name: String, payload: Variant = null) -> void:
|
||||
_close_app_menu()
|
||||
for child in $Root/Screens.get_children():
|
||||
child.visible = false
|
||||
|
||||
@@ -21,6 +25,7 @@ func show_screen(screen_name: String, payload: Variant = null) -> void:
|
||||
if screen == null:
|
||||
return
|
||||
|
||||
current_screen_name = screen_name
|
||||
screen.visible = true
|
||||
if header_panel != null:
|
||||
header_panel.visible = screen_name != "login"
|
||||
@@ -68,21 +73,6 @@ func _build_ui() -> void:
|
||||
user_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
|
||||
header.add_child(user_label)
|
||||
|
||||
var profile_button := Button.new()
|
||||
profile_button.text = "Profile"
|
||||
profile_button.pressed.connect(func(): show_screen("profile"))
|
||||
header.add_child(profile_button)
|
||||
|
||||
var map_button := Button.new()
|
||||
map_button.text = "Study Map"
|
||||
map_button.pressed.connect(func(): show_screen("map"))
|
||||
header.add_child(map_button)
|
||||
|
||||
var logout_button := Button.new()
|
||||
logout_button.text = "Log Out"
|
||||
logout_button.pressed.connect(_logout)
|
||||
header.add_child(logout_button)
|
||||
|
||||
var screens_container := MarginContainer.new()
|
||||
screens_container.name = "Screens"
|
||||
screens_container.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
@@ -104,6 +94,12 @@ func _build_ui() -> void:
|
||||
screens_container.add_child(login)
|
||||
screens["login"] = login
|
||||
|
||||
var dashboard := preload("res://scripts/ui/dashboard.gd").new()
|
||||
dashboard.name = "Dashboard"
|
||||
dashboard.main = self
|
||||
screens_container.add_child(dashboard)
|
||||
screens["dashboard"] = dashboard
|
||||
|
||||
var map := preload("res://scripts/ui/study_map.gd").new()
|
||||
map.name = "StudyMap"
|
||||
map.main = self
|
||||
@@ -137,6 +133,15 @@ func _build_ui() -> void:
|
||||
ProfileService.profile_changed.connect(_refresh_header_stats)
|
||||
AuthState.auth_changed.connect(_refresh_header_stats)
|
||||
_refresh_header_stats()
|
||||
_build_app_menu()
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if not AuthState.is_logged_in or current_screen_name == "login":
|
||||
return
|
||||
if event.is_action_pressed("ui_cancel"):
|
||||
_toggle_app_menu()
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
|
||||
func _refresh_header_stats() -> void:
|
||||
@@ -153,5 +158,77 @@ func _refresh_header_stats() -> void:
|
||||
|
||||
|
||||
func _logout() -> void:
|
||||
_close_app_menu()
|
||||
if BlockSessionService.block_started:
|
||||
BlockSessionService.finish_block()
|
||||
QuestionBankService.clear_questions()
|
||||
AuthState.clear_session()
|
||||
show_screen("login")
|
||||
|
||||
|
||||
func _build_app_menu() -> void:
|
||||
app_menu = PanelContainer.new()
|
||||
app_menu.visible = false
|
||||
app_menu.top_level = true
|
||||
app_menu.mouse_filter = Control.MOUSE_FILTER_STOP
|
||||
app_menu.custom_minimum_size = Vector2(340, 230)
|
||||
app_menu.add_theme_stylebox_override("panel", Style.panel_box(Color("172337"), Style.CYAN))
|
||||
add_child(app_menu)
|
||||
|
||||
var content := VBoxContainer.new()
|
||||
content.add_theme_constant_override("separation", 12)
|
||||
app_menu.add_child(content)
|
||||
|
||||
var title := Label.new()
|
||||
title.text = "Paused"
|
||||
title.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
Style.set_label(title, 28, Style.TEXT)
|
||||
content.add_child(title)
|
||||
|
||||
var resume := Button.new()
|
||||
resume.text = "Resume"
|
||||
resume.custom_minimum_size = Vector2(0, 48)
|
||||
Style.style_primary_button(resume)
|
||||
resume.pressed.connect(_close_app_menu)
|
||||
content.add_child(resume)
|
||||
|
||||
menu_exit_button = Button.new()
|
||||
menu_exit_button.text = "Exit Run"
|
||||
menu_exit_button.custom_minimum_size = Vector2(0, 48)
|
||||
menu_exit_button.pressed.connect(_exit_run)
|
||||
content.add_child(menu_exit_button)
|
||||
|
||||
var logout := Button.new()
|
||||
logout.text = "Log Out"
|
||||
logout.custom_minimum_size = Vector2(0, 48)
|
||||
Style.style_chip(logout, Style.RED)
|
||||
logout.pressed.connect(_logout)
|
||||
content.add_child(logout)
|
||||
|
||||
|
||||
func _toggle_app_menu() -> void:
|
||||
if app_menu == null:
|
||||
return
|
||||
if app_menu.visible:
|
||||
_close_app_menu()
|
||||
else:
|
||||
app_menu.visible = true
|
||||
app_menu.size = app_menu.custom_minimum_size
|
||||
app_menu.position = (get_viewport_rect().size - app_menu.size) * 0.5
|
||||
menu_exit_button.visible = current_screen_name == "player" and BlockSessionService.block_started
|
||||
if menu_exit_button.visible:
|
||||
Style.style_chip(menu_exit_button, Style.AMBER)
|
||||
BlockSessionService.pause_current_question_timer()
|
||||
|
||||
|
||||
func _close_app_menu() -> void:
|
||||
if app_menu != null:
|
||||
app_menu.visible = false
|
||||
BlockSessionService.resume_current_question_timer()
|
||||
|
||||
|
||||
func _exit_run() -> void:
|
||||
_close_app_menu()
|
||||
if BlockSessionService.block_started:
|
||||
BlockSessionService.finish_block()
|
||||
show_screen("dashboard")
|
||||
|
||||
Reference in New Issue
Block a user