2024-12-27 07:56:45 +00:00
|
|
|
extends Control
|
|
|
|
|
|
|
|
@onready var label = %RichTextLabel as RichTextLabel
|
|
|
|
|
|
|
|
var pending_bbcode = []
|
|
|
|
var tweening := false
|
|
|
|
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
label.clear()
|
|
|
|
modulate = Color(1, 1, 1, 0)
|
|
|
|
# test notification in editor
|
2025-01-08 00:51:09 +00:00
|
|
|
# if GlobalConfig.DEBUG:
|
|
|
|
# call_deferred("test")
|
2024-12-27 07:56:45 +00:00
|
|
|
|
|
|
|
|
2025-01-08 00:51:09 +00:00
|
|
|
# func test():
|
|
|
|
# # append_dialog("吕萍", "Hello, 2! very very long message, very very loooonnnggggggg!")
|
|
|
|
# append_note("Hello, 3!")
|
|
|
|
# # append_note("Hello, blue!", "blue", 1)
|
|
|
|
# append_dialog("车夫", "你好!", "green")
|
|
|
|
# pass
|
2024-12-27 07:56:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
func append_note(note: String, note_color := "white", duration := 2.5) -> void:
|
|
|
|
pending_bbcode.append(
|
2024-12-30 13:19:10 +00:00
|
|
|
["[center][color=" + note_color + "]" + note + "[/color][/center]", duration, false]
|
2024-12-27 07:56:45 +00:00
|
|
|
)
|
|
|
|
_show()
|
|
|
|
|
|
|
|
|
|
|
|
func append_dialog(
|
|
|
|
character: String,
|
|
|
|
content: String,
|
|
|
|
character_color := "orange",
|
|
|
|
content_color := "white",
|
|
|
|
duration := 2.5
|
|
|
|
) -> void:
|
2024-12-30 13:19:10 +00:00
|
|
|
# remove non-dialog notifications
|
|
|
|
for _i in range(pending_bbcode.size()):
|
|
|
|
var triple = pending_bbcode.pop_front()
|
|
|
|
if not triple[2]:
|
|
|
|
continue
|
|
|
|
pending_bbcode.append(triple)
|
2024-12-27 07:56:45 +00:00
|
|
|
pending_bbcode.append(
|
|
|
|
[
|
|
|
|
(
|
|
|
|
"[center][color="
|
|
|
|
+ character_color
|
|
|
|
+ "][b]"
|
|
|
|
+ character
|
|
|
|
+ ":[/b][/color][color="
|
|
|
|
+ content_color
|
|
|
|
+ "]"
|
|
|
|
+ content
|
|
|
|
+ "[/color][/center]"
|
|
|
|
),
|
2024-12-30 13:19:10 +00:00
|
|
|
duration,
|
|
|
|
true
|
2024-12-27 07:56:45 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
_show()
|
|
|
|
|
|
|
|
|
|
|
|
func _show() -> void:
|
|
|
|
if not tweening and pending_bbcode.size() > 0:
|
2024-12-30 13:19:10 +00:00
|
|
|
var triple = pending_bbcode.pop_front()
|
|
|
|
label.parse_bbcode(triple[0])
|
|
|
|
if triple[2]:
|
|
|
|
label.add_theme_color_override("font_shadow_color", Color(0.2, 0.2, 0.2, 0.6))
|
|
|
|
else:
|
|
|
|
label.remove_theme_color_override("font_shadow_color")
|
2024-12-27 07:56:45 +00:00
|
|
|
tweening = true
|
|
|
|
var tween = create_tween()
|
|
|
|
# 0.5s to show the notification
|
|
|
|
tween.tween_property(self, "modulate:a", 1, 0.2).set_trans(Tween.TRANS_CUBIC)
|
|
|
|
# keep the notification
|
2024-12-30 13:19:10 +00:00
|
|
|
tween.tween_interval(max(triple[1] - 0.4, 0))
|
2024-12-27 07:56:45 +00:00
|
|
|
# 0.5s to hide the notification
|
|
|
|
tween.tween_property(self, "modulate:a", 0, 0.2).set_trans(Tween.TRANS_CUBIC)
|
|
|
|
# callback
|
|
|
|
tween.tween_callback(_check_next)
|
|
|
|
|
2024-12-30 13:19:10 +00:00
|
|
|
|
2024-12-27 07:56:45 +00:00
|
|
|
func _check_next():
|
|
|
|
tweening = false
|
2024-12-30 13:19:10 +00:00
|
|
|
_show()
|