Files
step3/scripts/ui/progress_profile.gd
T

82 lines
2.4 KiB
GDScript

extends VBoxContainer
const Style := preload("res://scripts/ui/ui_style.gd")
var main: Control
var profile_text: RichTextLabel
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 to Menu"
back.pressed.connect(func(): main.show_screen("menu"))
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)
add_child(row)
func on_show(_payload: Variant = null) -> void:
var profile := ProfileService.get_profile()
var xp_into := ProgressionService.xp_into_level(int(profile["xp"]))
var text := "[b]Level %d[/b]\n%d total XP (%d/%d to next level)\nCurrent streak: %d\nBest streak: %d\n\n[b]Badges[/b]\n" % [
profile["level"],
profile["xp"],
xp_into,
ProgressionService.XP_PER_LEVEL,
profile["current_streak"],
profile["best_streak"]
]
if profile["badges"].is_empty():
text += "No badges yet.\n"
else:
for badge in profile["badges"]:
text += "- %s\n" % badge
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, +%d XP\n" % [
block.get("timestamp", ""),
block.get("system", ""),
block.get("correct", 0),
block.get("total", 0),
block.get("xp_earned", 0)
]
profile_text.text = text