Files
sor/Client/origin-client/scenes/account/account_screen.gd
T

275 lines
8.6 KiB
GDScript

extends Control
## Account Management screen.
const NOTIF_ROW = preload("res://scenes/account/components/NotificationRow.tscn")
@onready var back_btn : Button = %BackBtn
@onready var display_label : Label = %DisplayLabel
@onready var op_label : Label = %OpLabel
@onready var rank_label : Label = %RankLabel
@onready var mailbox_list : VBoxContainer = %MailboxList
@onready var loading_label : Label = %LoadingLabel
@onready var empty_label : Label = %EmptyLabel
# ── Lifecycle ─────────────────────────────────────────────────────────────────
func _ready() -> void:
back_btn.pressed.connect(_on_back)
_load_profile()
_load_notifications()
# ── Profile ───────────────────────────────────────────────────────────────────
func _load_profile() -> void:
display_label.text = Auth.display_name
op_label.text = "◆ — OP"
rank_label.text = "Rank: —"
Network.request(
"account.get_profile",
{},
func(_type: String, p: Variant): _on_profile_ok(p),
func(_c: String, _m: String): pass
)
func _on_profile_ok(p: Variant) -> void:
var d := p as Dictionary
op_label.text = "◆ %d OP" % int(d.get("originPoints", 0))
rank_label.text = "Rank Score: %d" % int(d.get("rankScore", 1000))
# ── Notifications (mailbox) ──────────────────────────────────────────────────
func _load_notifications() -> void:
loading_label.visible = true
loading_label.text = "Loading…"
empty_label.visible = false
for c in mailbox_list.get_children():
c.queue_free()
Network.request(
"chat.notifications.get",
{ "unreadOnly": false },
func(_type: String, p: Variant): _on_notifications_ok(p),
func(_c: String, _m: String):
loading_label.visible = true
loading_label.text = "Failed to load mailbox."
)
func _on_notifications_ok(p: Variant) -> void:
loading_label.visible = false
var notifs : Array = (p as Dictionary).get("notifications", []) as Array
if notifs.is_empty():
empty_label.visible = true
return
for n in notifs:
var nd := n as Dictionary
var row := NOTIF_ROW.instantiate()
mailbox_list.add_child(row)
row.setup(nd)
row.open_requested.connect(_on_open_notification)
row.reply_requested.connect(_on_reply_notification)
row.delete_requested.connect(_on_delete_notification)
row.mark_read_requested.connect(_on_mark_read_notification)
func _on_mark_read_notification(notification_id: String) -> void:
if notification_id.is_empty():
return
Network.request(
"chat.notifications.read",
{ "notificationIds": [notification_id] },
func(_t: String, _p: Variant): _load_notifications(),
func(_c: String, _m: String): pass
)
func _on_delete_notification(notification_id: String) -> void:
if notification_id.is_empty():
return
Network.request(
"chat.notifications.delete",
{ "notificationIds": [notification_id] },
func(_t: String, _p: Variant): _load_notifications(),
func(_c: String, _m: String): pass
)
func _on_open_notification(notification: Dictionary) -> void:
_show_notification_dialog(notification, false)
func _on_reply_notification(notification: Dictionary) -> void:
_show_notification_dialog(notification, true)
func _show_notification_dialog(notification: Dictionary, focus_reply: bool) -> void:
var notification_id := str(notification.get("id", ""))
if not notification_id.is_empty() and notification.get("readAt", null) == null:
_on_mark_read_notification(notification_id)
var dialog := AcceptDialog.new()
dialog.title = str(notification.get("title", "Mailbox"))
dialog.ok_button_text = "Close"
dialog.min_size = Vector2(680, 520)
add_child(dialog)
var root := VBoxContainer.new()
root.size_flags_vertical = Control.SIZE_EXPAND_FILL
root.size_flags_horizontal = Control.SIZE_EXPAND_FILL
root.add_theme_constant_override("separation", 8)
dialog.add_child(root)
var body := RichTextLabel.new()
body.size_flags_vertical = Control.SIZE_EXPAND_FILL
body.bbcode_enabled = false
body.fit_content = false
body.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
body.text = str(notification.get("body", ""))
root.add_child(body)
var thread_info := _extract_bug_report_payload(notification)
var bug_report_id := str(thread_info.get("bugReportId", ""))
var divider := HSeparator.new()
root.add_child(divider)
var response_title := Label.new()
response_title.text = "Thread"
response_title.modulate = Color(0.8, 0.8, 0.9)
root.add_child(response_title)
var response_log := RichTextLabel.new()
response_log.size_flags_vertical = Control.SIZE_EXPAND_FILL
response_log.bbcode_enabled = false
response_log.fit_content = false
response_log.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
response_log.text = "Loading thread…" if not bug_report_id.is_empty() else "No support thread is attached to this message."
root.add_child(response_log)
var reply_edit := TextEdit.new()
reply_edit.custom_minimum_size = Vector2(0, 100)
reply_edit.placeholder_text = "Reply to support…"
reply_edit.visible = not bug_report_id.is_empty()
root.add_child(reply_edit)
var actions := HBoxContainer.new()
actions.add_theme_constant_override("separation", 8)
root.add_child(actions)
var send_btn := Button.new()
send_btn.text = "Send Reply"
send_btn.visible = not bug_report_id.is_empty()
actions.add_child(send_btn)
var delete_btn := Button.new()
delete_btn.text = "Delete Message"
delete_btn.modulate = Color(1.0, 0.5, 0.5)
actions.add_child(delete_btn)
if not bug_report_id.is_empty():
_load_bug_report_thread(bug_report_id, response_log)
send_btn.pressed.connect(func() -> void:
var content := reply_edit.text.strip_edges()
if content.is_empty() or bug_report_id.is_empty():
return
send_btn.disabled = true
Network.request(
"support.reply_bug_report",
{
"bugReportId": bug_report_id,
"content": content,
},
func(_t: String, _p: Variant):
reply_edit.text = ""
send_btn.disabled = false
_load_bug_report_thread(bug_report_id, response_log),
func(code: String, msg: String):
send_btn.disabled = false
response_log.text += "\n\n[Reply failed: %s] %s" % [code, msg]
)
)
delete_btn.pressed.connect(func() -> void:
_on_delete_notification(notification_id)
dialog.queue_free()
)
dialog.popup_centered()
if focus_reply and reply_edit.visible:
reply_edit.grab_focus()
func _extract_bug_report_payload(notification: Dictionary) -> Dictionary:
var payload_raw := notification.get("payloadJson", null)
if payload_raw == null:
return {}
var payload_text := str(payload_raw)
if payload_text.is_empty():
return {}
var parsed := JSON.parse_string(payload_text)
if typeof(parsed) == TYPE_DICTIONARY:
return parsed as Dictionary
return {}
func _load_bug_report_thread(bug_report_id: String, out_log: RichTextLabel) -> void:
Network.request(
"support.get_bug_report_thread",
{ "bugReportId": bug_report_id },
func(_t: String, p: Variant):
var thread := (p as Dictionary).get("thread", {}) as Dictionary
out_log.text = _format_thread_text(thread),
func(code: String, msg: String):
out_log.text = "Failed to load support thread.\n[%s] %s" % [code, msg]
)
func _format_thread_text(thread: Dictionary) -> String:
if thread.is_empty():
return "No thread data."
var lines: Array[String] = []
lines.append("Title: %s" % str(thread.get("title", "")))
lines.append("Status: %s" % str(thread.get("status", "")))
lines.append("Category: %s" % str(thread.get("category", "")))
lines.append("")
lines.append("Original report:")
lines.append(str(thread.get("description", "")))
var steps := str(thread.get("stepsToReproduce", ""))
if not steps.is_empty():
lines.append("")
lines.append("Steps to reproduce:")
lines.append(steps)
lines.append("")
lines.append("Responses:")
var responses: Array = thread.get("responses", []) as Array
if responses.is_empty():
lines.append("(No responses yet)")
else:
for r in responses:
var rd := r as Dictionary
lines.append("- %s: %s" % [
str(rd.get("authorDisplayName", "Unknown")),
str(rd.get("content", ""))
])
return "\n".join(lines)
# ── Navigation ────────────────────────────────────────────────────────────────
func _on_back() -> void:
get_tree().change_scene_to_file("res://scenes/main/MainScreen.tscn")