Files
step3/scripts/ui/progress_profile.gd
T

118 lines
3.7 KiB
GDScript

extends VBoxContainer
const Style := preload("res://scripts/ui/ui_style.gd")
var main: Control
var profile_text: RichTextLabel
var reset_qbank_button: Button
var reset_qbank_pending := false
func _ready() -> void:
set_anchors_preset(Control.PRESET_FULL_RECT)
add_theme_constant_override("separation", 14)
var title := Label.new()
title.text = "Progress Profile"
Style.set_label(title, 34, Style.CYAN)
add_child(title)
var panel := PanelContainer.new()
panel.add_theme_stylebox_override("panel", Style.panel_box(Color("172337"), Color("405475")))
panel.size_flags_vertical = Control.SIZE_EXPAND_FILL
add_child(panel)
profile_text = RichTextLabel.new()
profile_text.bbcode_enabled = true
profile_text.size_flags_vertical = Control.SIZE_EXPAND_FILL
panel.add_child(profile_text)
var row := HBoxContainer.new()
var back := Button.new()
back.text = "Back"
back.pressed.connect(func(): main.show_screen("selection", "step3"))
row.add_child(back)
var reset := Button.new()
reset.text = "Reset Progress"
Style.style_chip(reset, Style.RED)
reset.pressed.connect(func():
ProfileService.reset_profile()
on_show()
)
row.add_child(reset)
var simulations := Button.new()
simulations.text = "Simulation History"
Style.style_chip(simulations, Style.CYAN)
simulations.pressed.connect(func(): main.show_screen("simulation_history"))
row.add_child(simulations)
reset_qbank_button = Button.new()
reset_qbank_button.text = "Reset QBank"
Style.style_chip(reset_qbank_button, Style.AMBER)
reset_qbank_button.pressed.connect(_on_reset_qbank_pressed)
row.add_child(reset_qbank_button)
add_child(row)
func on_show(_payload: Variant = null) -> void:
_reset_qbank_confirmation()
var profile := ProfileService.get_profile()
var text := "[b]Overall ELO %d[/b]\n%d rated questions\nCurrent streak: %d\nBest streak: %d\nToday: %d/%d questions\n\n[b]Category ELO[/b]\n" % [
QuestionBankService.overall_elo,
QuestionBankService.rated_question_count,
profile["current_streak"],
profile["best_streak"],
profile.get("daily_questions_answered", 0),
profile.get("daily_goal_questions", 10)
]
if QuestionBankService.category_elos.is_empty():
text += "No rated categories yet.\n"
else:
var categories := QuestionBankService.category_elos.keys()
categories.sort()
for category in categories:
text += "- %s: %d\n" % [category, int(QuestionBankService.category_elos[category])]
text += "\n[b]System Accuracy[/b]\n"
if profile["system_stats"].is_empty():
text += "No completed questions yet.\n"
else:
for system_name in profile["system_stats"].keys():
var stats: Dictionary = profile["system_stats"][system_name]
var seen := int(stats.get("seen", 0))
var correct := int(stats.get("correct", 0))
var accuracy := int(round(float(correct) / float(max(seen, 1)) * 100.0))
text += "- %s: %d/%d (%d%%)\n" % [system_name, correct, seen, accuracy]
text += "\n[b]Recent Blocks[/b]\n"
for block in profile["block_history"]:
text += "- %s: %s %d/%d\n" % [
block.get("timestamp", ""),
block.get("system", ""),
block.get("correct", 0),
block.get("total", 0)
]
profile_text.text = text
func _on_reset_qbank_pressed() -> void:
if not reset_qbank_pending:
reset_qbank_pending = true
reset_qbank_button.text = "Confirm Reset QBank"
Style.style_chip(reset_qbank_button, Style.RED)
return
ProfileService.reset_qbank_memory()
if BlockSessionService.core_status_message == "All available questions cleared.":
BlockSessionService.core_status_message = ""
_reset_qbank_confirmation()
on_show()
func _reset_qbank_confirmation() -> void:
reset_qbank_pending = false
if reset_qbank_button != null:
reset_qbank_button.text = "Reset QBank"
Style.style_chip(reset_qbank_button, Style.AMBER)