2024-12-23 01:29:31 +00:00
|
|
|
extends Control
|
|
|
|
|
2025-01-24 14:19:17 +00:00
|
|
|
@onready var top_right_label := %RichTextLabel as RichTextLabel
|
|
|
|
@onready var top_center_label := %CenterLabel as Label
|
2024-12-24 01:16:06 +00:00
|
|
|
|
|
|
|
var pending_notifications = []
|
2025-01-24 14:19:17 +00:00
|
|
|
var tweening_top_left := false
|
2024-12-24 01:16:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
2025-01-24 14:19:17 +00:00
|
|
|
top_right_label.modulate.a = 0
|
|
|
|
top_center_label.modulate.a = 0
|
2024-12-24 01:16:06 +00:00
|
|
|
|
|
|
|
|
2025-01-24 14:19:17 +00:00
|
|
|
# # test notification in editor
|
|
|
|
# if GlobalConfig.DEBUG:
|
|
|
|
# call_deferred("test")
|
|
|
|
|
|
|
|
# func test():
|
|
|
|
# # return
|
|
|
|
# show_center_notification(tr("ui_press_e"))
|
|
|
|
# # show_center_notification(tr("ui_press_b"))
|
|
|
|
# # show_center_notification(tr("ui_press_shift"))
|
|
|
|
# #show_notification("Hello, 1!", 42)
|
|
|
|
# #show_notification("Hello, 2! very very long message, very very loooonnnggggggg!", 2)
|
|
|
|
# #show_notification("Hello, 3!", 24)
|
|
|
|
# show_notification(tr("ui_saved_all"), 1)
|
|
|
|
|
|
|
|
|
|
|
|
func show_center_notification(msg, duration := 3.0):
|
|
|
|
if not top_center_label:
|
|
|
|
return
|
|
|
|
top_center_label.text = msg
|
|
|
|
var tween = create_tween()
|
|
|
|
tween.tween_property(top_center_label, "modulate:a", 1, 0.4)
|
|
|
|
tween.tween_interval(max(0.1, duration - .8))
|
|
|
|
tween.tween_property(top_center_label, "modulate:a", 0, 0.4)
|
2024-12-24 01:16:06 +00:00
|
|
|
|
2024-12-23 01:29:31 +00:00
|
|
|
|
|
|
|
func show_notification(msg, number):
|
2025-01-24 14:19:17 +00:00
|
|
|
if not top_right_label:
|
2024-12-27 13:32:12 +00:00
|
|
|
return
|
2025-01-24 14:19:17 +00:00
|
|
|
if tweening_top_left:
|
2024-12-24 01:16:06 +00:00
|
|
|
pending_notifications.append([msg, number])
|
|
|
|
else:
|
2025-01-24 14:19:17 +00:00
|
|
|
top_right_label.text = msg
|
|
|
|
tweening_top_left = true
|
2024-12-24 01:16:06 +00:00
|
|
|
var tween = create_tween()
|
|
|
|
# 0.5s to show the notification
|
2025-01-24 14:19:17 +00:00
|
|
|
tween.tween_property(top_right_label, "modulate:a", 1, 0.5).set_trans(Tween.TRANS_CUBIC)
|
2024-12-24 01:16:06 +00:00
|
|
|
# keep the notification
|
|
|
|
if pending_notifications.size() > 0:
|
|
|
|
tween.tween_interval(2)
|
|
|
|
else:
|
|
|
|
tween.tween_interval(3)
|
|
|
|
# 0.5s to hide the notification
|
2025-01-24 14:19:17 +00:00
|
|
|
tween.tween_property(top_right_label, "modulate:a", 0, 0.5).set_trans(Tween.TRANS_CUBIC)
|
2024-12-24 01:16:06 +00:00
|
|
|
# callback
|
2025-01-24 14:19:17 +00:00
|
|
|
tween.tween_callback(_check_next)
|
2024-12-24 01:16:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _check_next():
|
2025-01-24 14:19:17 +00:00
|
|
|
tweening_top_left = false
|
2024-12-24 01:16:06 +00:00
|
|
|
if pending_notifications.size() > 0:
|
|
|
|
var n = pending_notifications.pop_front()
|
|
|
|
show_notification(n[0], n[1])
|