2026-01-24 15:43:53 +08:00
|
|
|
@tool
|
|
|
|
|
extends PanelContainer
|
|
|
|
|
class_name TipBox
|
|
|
|
|
|
2026-01-25 21:40:26 +08:00
|
|
|
enum MessageType {
|
|
|
|
|
INFO,
|
|
|
|
|
WARNING,
|
|
|
|
|
ERROR,
|
2026-01-25 21:43:53 +08:00
|
|
|
CONGRATULATION,
|
2026-01-25 21:40:26 +08:00
|
|
|
}
|
|
|
|
|
|
2026-01-24 15:43:53 +08:00
|
|
|
@export var text: String = "nothing"
|
2026-01-25 21:40:26 +08:00
|
|
|
@export var messageType: MessageType = MessageType.INFO
|
|
|
|
|
@export var colorMap = {
|
2026-01-25 21:43:53 +08:00
|
|
|
MessageType.INFO: Color.BLACK,
|
|
|
|
|
MessageType.WARNING: Color.BLACK,
|
|
|
|
|
MessageType.ERROR: Color.BLACK,
|
|
|
|
|
MessageType.CONGRATULATION: Color.BLACK,
|
2026-01-25 21:40:26 +08:00
|
|
|
}
|
2026-01-24 15:43:53 +08:00
|
|
|
|
2026-01-24 20:07:06 +08:00
|
|
|
@onready var label: RichTextLabel = $%label
|
2026-01-24 15:43:53 +08:00
|
|
|
@onready var animator: AnimationPlayer = $%animator
|
|
|
|
|
|
|
|
|
|
func _ready():
|
2026-01-24 15:54:42 +08:00
|
|
|
label.text = text
|
|
|
|
|
animator.play("show")
|
2026-01-25 21:40:26 +08:00
|
|
|
var styleBox = get_theme_stylebox("panel").duplicate() as StyleBoxFlat
|
|
|
|
|
styleBox.bg_color = colorMap[messageType]
|
|
|
|
|
add_theme_stylebox_override("panel", styleBox)
|
2026-01-24 15:43:53 +08:00
|
|
|
func _process(_delta):
|
2026-01-24 15:54:42 +08:00
|
|
|
label.text = text
|
2026-01-24 15:43:53 +08:00
|
|
|
|
|
|
|
|
func destroy():
|
2026-05-05 07:04:32 +08:00
|
|
|
if animator.is_playing(): return
|
2026-01-24 15:54:42 +08:00
|
|
|
animator.play("hide")
|
|
|
|
|
await animator.animation_finished
|
|
|
|
|
queue_free()
|
2026-01-24 15:43:53 +08:00
|
|
|
|
2026-01-25 21:40:26 +08:00
|
|
|
static func create(applyText: String, applyMessageType: MessageType = MessageType.INFO) -> TipBox:
|
2026-01-24 15:54:42 +08:00
|
|
|
var box = ComponentManager.getUIComponent("TipBox").instantiate()
|
|
|
|
|
box.text = applyText
|
2026-01-25 21:40:26 +08:00
|
|
|
box.messageType = applyMessageType
|
2026-01-24 15:54:42 +08:00
|
|
|
return box
|