77 lines
4.7 KiB
GDScript
77 lines
4.7 KiB
GDScript
extends Control
|
|
|
|
const Style := preload("res://scripts/ui/ui_style.gd")
|
|
const CATEGORIES := [
|
|
{"id":"clarity", "label":"Clarity"}, {"id":"medical_accuracy", "label":"Medical accuracy"},
|
|
{"id":"case_progression_scoring", "label":"Case progression / scoring"}, {"id":"formatting_media", "label":"Formatting / media"},
|
|
{"id":"technical_issue", "label":"Technical issue"}, {"id":"other", "label":"Other"}
|
|
]
|
|
var group: ButtonGroup
|
|
var details: TextEdit
|
|
var count: Label
|
|
var error: Label
|
|
var submit: Button
|
|
var form: VBoxContainer
|
|
var success: VBoxContainer
|
|
var attempt_id := ""
|
|
var panel: PanelContainer
|
|
|
|
func _ready() -> void:
|
|
visible = false; top_level = true; mouse_filter = Control.MOUSE_FILTER_STOP; set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
var dim := ColorRect.new(); dim.color = Color(0,0,0,0.7); dim.set_anchors_preset(Control.PRESET_FULL_RECT); add_child(dim)
|
|
var center := CenterContainer.new(); center.set_anchors_preset(Control.PRESET_FULL_RECT); add_child(center)
|
|
panel = PanelContainer.new(); panel.custom_minimum_size = Vector2(680, 560); panel.add_theme_stylebox_override("panel", Style.panel_box(Style.SURFACE_DARK, Style.RED)); center.add_child(panel)
|
|
var root := VBoxContainer.new(); root.add_theme_constant_override("separation", 12); panel.add_child(root)
|
|
var title := Label.new(); title.text = "Report CCS case"; Style.set_label(title, 25, Style.TEXT); root.add_child(title)
|
|
form = VBoxContainer.new(); form.add_theme_constant_override("separation", 10); root.add_child(form)
|
|
group = ButtonGroup.new(); group.allow_unpress = false
|
|
var grid := GridContainer.new(); grid.columns = 2; form.add_child(grid)
|
|
for category in CATEGORIES:
|
|
var option := CheckBox.new(); option.text = category.label; option.set_meta("category", category.id); option.button_group = group; option.toggled.connect(func(_value): _refresh()); grid.add_child(option)
|
|
var header := HBoxContainer.new(); form.add_child(header)
|
|
var prompt := Label.new(); prompt.text = "Details"; prompt.size_flags_horizontal = Control.SIZE_EXPAND_FILL; header.add_child(prompt)
|
|
count = Label.new(); header.add_child(count)
|
|
details = TextEdit.new(); details.placeholder_text = "Describe what should be reviewed."; details.custom_minimum_size = Vector2(0, 190); details.wrap_mode = TextEdit.LINE_WRAPPING_BOUNDARY; details.text_changed.connect(_refresh); form.add_child(details)
|
|
error = Label.new(); Style.set_label(error, 14, Style.RED); form.add_child(error)
|
|
var actions := HBoxContainer.new(); form.add_child(actions)
|
|
var cancel := Button.new(); cancel.text = "Cancel"; cancel.pressed.connect(hide_dialog); actions.add_child(cancel)
|
|
submit = Button.new(); submit.text = "Submit report"; submit.size_flags_horizontal = Control.SIZE_EXPAND_FILL; Style.style_primary_button(submit); submit.pressed.connect(_submit); actions.add_child(submit)
|
|
success = VBoxContainer.new(); success.visible = false; root.add_child(success)
|
|
var success_label := Label.new(); success_label.text = "Report submitted\nThank you for helping improve this case."; success_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER; Style.set_label(success_label, 22, Style.LIME); success.add_child(success_label)
|
|
var close := Button.new(); close.text = "Close"; close.pressed.connect(hide_dialog); success.add_child(close)
|
|
CCSService.report_submitted.connect(_submitted); CCSService.report_failed.connect(_failed)
|
|
resized.connect(_refresh_size)
|
|
_refresh()
|
|
_refresh_size()
|
|
|
|
func show_for(value: String) -> void:
|
|
attempt_id = value; details.text = ""; error.text = ""; form.visible = true; success.visible = false
|
|
for button in group.get_buttons(): button.button_pressed = false
|
|
visible = true; move_to_front(); _refresh()
|
|
|
|
func hide_dialog() -> void:
|
|
visible = false
|
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
|
if visible and event.is_action_pressed("ui_cancel"): hide_dialog(); get_viewport().set_input_as_handled()
|
|
|
|
func _refresh_size() -> void:
|
|
if panel != null: panel.custom_minimum_size = Vector2(minf(680.0, maxf(300.0, size.x - 32.0)), minf(560.0, maxf(420.0, size.y - 32.0)))
|
|
|
|
func _refresh() -> void:
|
|
var length := details.text.strip_edges().length() if details != null else 0
|
|
if count != null: count.text = "%d / 2000" % length
|
|
if submit != null: submit.disabled = group.get_pressed_button() == null or length < 10 or length > 2000
|
|
|
|
func _submit() -> void:
|
|
var selected := group.get_pressed_button();
|
|
if selected == null: return
|
|
submit.disabled = true; submit.text = "Submitting..."
|
|
CCSService.submit_report(attempt_id, str(selected.get_meta("category", "")), details.text.strip_edges())
|
|
|
|
func _submitted(_id: String) -> void:
|
|
submit.text = "Submit report"; form.visible = false; success.visible = true
|
|
|
|
func _failed(message: String) -> void:
|
|
submit.text = "Submit report"; error.text = message; _refresh()
|