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

85 lines
2.5 KiB
GDScript

extends PanelContainer
## Single mailbox notification row with quick actions.
signal open_requested(notification: Dictionary)
signal reply_requested(notification: Dictionary)
signal delete_requested(notification_id: String)
signal mark_read_requested(notification_id: String)
@onready var title_label : Label = %TitleLabel
@onready var body_label : Label = %BodyLabel
@onready var _vbox : VBoxContainer = $Margin/VBox
var _notification: Dictionary = {}
func _ready() -> void:
mouse_filter = Control.MOUSE_FILTER_STOP
gui_input.connect(_on_gui_input)
func setup(notification: Dictionary) -> void:
_notification = notification.duplicate(true)
var title := str(_notification.get("title", "Notification"))
var body := str(_notification.get("body", ""))
var is_unread := _notification.get("readAt", null) == null
title_label.text = title
body_label.text = body
if is_unread:
title_label.modulate = Color(0.95, 0.85, 0.30)
else:
title_label.modulate = Color(0.82, 0.82, 0.88)
_build_actions(is_unread)
func _build_actions(is_unread: bool) -> void:
for c in _vbox.get_children():
if c.name == "ActionRow":
c.queue_free()
var action_row := HBoxContainer.new()
action_row.name = "ActionRow"
action_row.add_theme_constant_override("separation", 6)
_vbox.add_child(action_row)
var open_btn := Button.new()
open_btn.text = "Open"
open_btn.flat = true
open_btn.pressed.connect(func() -> void:
open_requested.emit(_notification))
action_row.add_child(open_btn)
var notif_type := str(_notification.get("notificationType", ""))
if notif_type == "admin_response":
var reply_btn := Button.new()
reply_btn.text = "Reply"
reply_btn.flat = true
reply_btn.pressed.connect(func() -> void:
reply_requested.emit(_notification))
action_row.add_child(reply_btn)
if is_unread:
var mark_btn := Button.new()
mark_btn.text = "Mark read"
mark_btn.flat = true
mark_btn.pressed.connect(func() -> void:
mark_read_requested.emit(str(_notification.get("id", ""))))
action_row.add_child(mark_btn)
var delete_btn := Button.new()
delete_btn.text = "Delete"
delete_btn.flat = true
delete_btn.modulate = Color(1.0, 0.5, 0.5)
delete_btn.pressed.connect(func() -> void:
delete_requested.emit(str(_notification.get("id", ""))))
action_row.add_child(delete_btn)
func _on_gui_input(event: InputEvent) -> void:
if event is InputEventMouseButton:
var mb := event as InputEventMouseButton
if mb.button_index == MOUSE_BUTTON_LEFT and mb.pressed and mb.double_click:
open_requested.emit(_notification)