Initial STEP 3 study game and questions API
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
extends VBoxContainer
|
||||
|
||||
const Style := preload("res://scripts/ui/ui_style.gd")
|
||||
|
||||
var main: Control
|
||||
var summary_label: Label
|
||||
var answer_list: VBoxContainer
|
||||
|
||||
func _ready() -> void:
|
||||
set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
add_theme_constant_override("separation", 14)
|
||||
|
||||
var title := Label.new()
|
||||
title.text = "Block Complete"
|
||||
Style.set_label(title, 34, Style.LIME)
|
||||
add_child(title)
|
||||
|
||||
summary_label = Label.new()
|
||||
summary_label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
Style.set_label(summary_label, 20, Style.TEXT)
|
||||
add_child(summary_label)
|
||||
|
||||
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)
|
||||
|
||||
var scroll := ScrollContainer.new()
|
||||
scroll.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
answer_list = VBoxContainer.new()
|
||||
answer_list.add_theme_constant_override("separation", 10)
|
||||
scroll.add_child(answer_list)
|
||||
panel.add_child(scroll)
|
||||
|
||||
var row := HBoxContainer.new()
|
||||
var map := Button.new()
|
||||
map.text = "Back to Map"
|
||||
map.pressed.connect(func(): main.show_screen("map"))
|
||||
row.add_child(map)
|
||||
var again := Button.new()
|
||||
again.text = "New Block"
|
||||
Style.style_primary_button(again)
|
||||
again.pressed.connect(func(): main.show_screen("setup", "All Systems"))
|
||||
row.add_child(again)
|
||||
add_child(row)
|
||||
|
||||
|
||||
func on_show(payload: Variant = null) -> void:
|
||||
var results: Dictionary = payload if typeof(payload) == TYPE_DICTIONARY else {}
|
||||
var accuracy := int(round(float(results.get("accuracy", 0.0)) * 100.0))
|
||||
summary_label.text = "%d/%d correct (%d%%) | +%d XP | Streak: %d | New badges: %s" % [
|
||||
results.get("correct", 0),
|
||||
results.get("total", 0),
|
||||
accuracy,
|
||||
results.get("xp_earned", 0),
|
||||
results.get("ending_streak", 0),
|
||||
", ".join(results.get("badges_unlocked", [])) if results.get("badges_unlocked", []).size() > 0 else "None"
|
||||
]
|
||||
|
||||
for child in answer_list.get_children():
|
||||
child.queue_free()
|
||||
|
||||
for answer in results.get("answers", []):
|
||||
var question: Dictionary = answer.get("question", {})
|
||||
var item := RichTextLabel.new()
|
||||
item.bbcode_enabled = true
|
||||
item.fit_content = true
|
||||
item.custom_minimum_size = Vector2(0, 90)
|
||||
var icon := "[color=#a6ff5f]CLEAR[/color]" if answer.get("is_correct", false) else "[color=#ff5f6d]MISS[/color]"
|
||||
item.text = "[b]%s[/b] %s\n[color=#aeb8ca]Selected: %s | Correct: %s[/color]\n%s" % [
|
||||
icon,
|
||||
question.get("lead_in", ""),
|
||||
answer.get("selected_choice_id", ""),
|
||||
question.get("correct_choice_id", ""),
|
||||
question.get("explanation", "")
|
||||
]
|
||||
answer_list.add_child(item)
|
||||
Reference in New Issue
Block a user