mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-05-28 06:51:54 +08:00
feat(UI): 为提示框添加类型支持并改进样式
- 新增MessageType枚举定义提示类型(INFO/WARNING/ERROR) - 根据不同类型显示不同颜色样式 - 修改所有调用showTip的地方使用新的类型参数 - 移除自动销毁时间参数,统一使用固定显示时长
This commit is contained in:
@@ -3,12 +3,12 @@
|
|||||||
[ext_resource type="Script" uid="uid://c1gqcwr6say6f" path="res://scripts/Statemachine/TipBox.gd" id="1_7vuk3"]
|
[ext_resource type="Script" uid="uid://c1gqcwr6say6f" path="res://scripts/Statemachine/TipBox.gd" id="1_7vuk3"]
|
||||||
[ext_resource type="Theme" uid="uid://bje5cd08dyok7" path="res://themes/bigTextAndBold.tres" id="2_5pngc"]
|
[ext_resource type="Theme" uid="uid://bje5cd08dyok7" path="res://themes/bigTextAndBold.tres" id="2_5pngc"]
|
||||||
|
|
||||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_nooq4"]
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_5pngc"]
|
||||||
content_margin_left = 10.0
|
content_margin_left = 10.0
|
||||||
content_margin_top = 5.0
|
content_margin_top = 5.0
|
||||||
content_margin_right = 10.0
|
content_margin_right = 10.0
|
||||||
content_margin_bottom = 5.0
|
content_margin_bottom = 5.0
|
||||||
bg_color = Color(1, 0, 0, 1)
|
bg_color = Color(0, 0, 1, 1)
|
||||||
corner_radius_top_right = 100
|
corner_radius_top_right = 100
|
||||||
corner_radius_bottom_right = 100
|
corner_radius_bottom_right = 100
|
||||||
|
|
||||||
@@ -104,8 +104,13 @@ _data = {
|
|||||||
[node name="TipBox" type="PanelContainer"]
|
[node name="TipBox" type="PanelContainer"]
|
||||||
offset_right = 79.0
|
offset_right = 79.0
|
||||||
offset_bottom = 34.0
|
offset_bottom = 34.0
|
||||||
theme_override_styles/panel = SubResource("StyleBoxFlat_nooq4")
|
theme_override_styles/panel = SubResource("StyleBoxFlat_5pngc")
|
||||||
script = ExtResource("1_7vuk3")
|
script = ExtResource("1_7vuk3")
|
||||||
|
colorMap = {
|
||||||
|
0: Color(0, 0.5265789, 1, 1),
|
||||||
|
1: Color(1, 0.48120707, 0, 1),
|
||||||
|
2: Color(1, 0, 0, 1)
|
||||||
|
}
|
||||||
|
|
||||||
[node name="label" type="RichTextLabel" parent="."]
|
[node name="label" type="RichTextLabel" parent="."]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ static func next(waves: Array):
|
|||||||
wave = instance_from_id(wave.get_instance_id())
|
wave = instance_from_id(wave.get_instance_id())
|
||||||
EntityBase.generate(ComponentManager.getCharacter(wave.entity), wave.entityPosition, true, wave.isBoss)
|
EntityBase.generate(ComponentManager.getCharacter(wave.entity), wave.entityPosition, true, wave.isBoss)
|
||||||
current += 1
|
current += 1
|
||||||
UIState.showTip("第%d波开始!" % current, 500)
|
UIState.showTip("第%d波开始!" % current, TipBox.MessageType.INFO)
|
||||||
showNextBossReminder()
|
showNextBossReminder()
|
||||||
static func showNextBossReminder():
|
static func showNextBossReminder():
|
||||||
var nextBossInfo = getNextBossInfo()
|
var nextBossInfo = getNextBossInfo()
|
||||||
@@ -117,7 +117,7 @@ static func showNextBossReminder():
|
|||||||
var bossName = nextBossInfo[0]
|
var bossName = nextBossInfo[0]
|
||||||
var wavesLeft = nextBossInfo[1]
|
var wavesLeft = nextBossInfo[1]
|
||||||
if wavesLeft > 0:
|
if wavesLeft > 0:
|
||||||
UIState.showTip("Boss [b]%s[/b] 将在[b]%d[/b]波后到来!" % [bossName, wavesLeft], 500)
|
UIState.showTip("Boss [b]%s[/b] 将在[b]%d[/b]波后到来!" % [bossName, wavesLeft], TipBox.MessageType.WARNING)
|
||||||
|
|
||||||
static func startWith(wave: int):
|
static func startWith(wave: int):
|
||||||
return wave - 1
|
return wave - 1
|
||||||
|
|||||||
@@ -369,9 +369,9 @@ func tryDie(by: BulletBase = null):
|
|||||||
await die()
|
await die()
|
||||||
died.emit()
|
died.emit()
|
||||||
if isBoss:
|
if isBoss:
|
||||||
UIState.showTip("[b]%s[/b] 已被打败!" % displayName, 500)
|
UIState.showTip("[b]%s[/b] 已被打败!" % displayName, TipBox.MessageType.INFO)
|
||||||
elif isPlayer():
|
elif isPlayer():
|
||||||
UIState.showTip("[b]%s[/b] 似了😭。" % displayName, 500)
|
UIState.showTip("[b]%s[/b] 似了😭。" % displayName, TipBox.MessageType.ERROR)
|
||||||
queue_free()
|
queue_free()
|
||||||
func tryHeal(count: float):
|
func tryHeal(count: float):
|
||||||
playSound("heal")
|
playSound("heal")
|
||||||
|
|||||||
@@ -2,7 +2,19 @@
|
|||||||
extends PanelContainer
|
extends PanelContainer
|
||||||
class_name TipBox
|
class_name TipBox
|
||||||
|
|
||||||
|
enum MessageType {
|
||||||
|
INFO,
|
||||||
|
WARNING,
|
||||||
|
ERROR,
|
||||||
|
}
|
||||||
|
|
||||||
@export var text: String = "nothing"
|
@export var text: String = "nothing"
|
||||||
|
@export var messageType: MessageType = MessageType.INFO
|
||||||
|
@export var colorMap = {
|
||||||
|
MessageType.INFO: Color.BLUE,
|
||||||
|
MessageType.WARNING: Color.ORANGE,
|
||||||
|
MessageType.ERROR: Color.RED,
|
||||||
|
}
|
||||||
|
|
||||||
@onready var label: RichTextLabel = $%label
|
@onready var label: RichTextLabel = $%label
|
||||||
@onready var animator: AnimationPlayer = $%animator
|
@onready var animator: AnimationPlayer = $%animator
|
||||||
@@ -10,6 +22,9 @@ class_name TipBox
|
|||||||
func _ready():
|
func _ready():
|
||||||
label.text = text
|
label.text = text
|
||||||
animator.play("show")
|
animator.play("show")
|
||||||
|
var styleBox = get_theme_stylebox("panel").duplicate() as StyleBoxFlat
|
||||||
|
styleBox.bg_color = colorMap[messageType]
|
||||||
|
add_theme_stylebox_override("panel", styleBox)
|
||||||
func _process(_delta):
|
func _process(_delta):
|
||||||
label.text = text
|
label.text = text
|
||||||
|
|
||||||
@@ -18,7 +33,8 @@ func destroy():
|
|||||||
await animator.animation_finished
|
await animator.animation_finished
|
||||||
queue_free()
|
queue_free()
|
||||||
|
|
||||||
static func create(applyText: String) -> TipBox:
|
static func create(applyText: String, applyMessageType: MessageType = MessageType.INFO) -> TipBox:
|
||||||
var box = ComponentManager.getUIComponent("TipBox").instantiate()
|
var box = ComponentManager.getUIComponent("TipBox").instantiate()
|
||||||
box.text = applyText
|
box.text = applyText
|
||||||
|
box.messageType = applyMessageType
|
||||||
return box
|
return box
|
||||||
|
|||||||
@@ -74,11 +74,8 @@ static func setPanel(targetName: String = "", args: Array = []):
|
|||||||
panel.hidePanel()
|
panel.hidePanel()
|
||||||
static func closeCurrentPanel():
|
static func closeCurrentPanel():
|
||||||
setPanel()
|
setPanel()
|
||||||
static func showTip(text: String, destroyAfter: float = -1):
|
static func showTip(text: String, messageType: TipBox.MessageType = TipBox.MessageType.INFO):
|
||||||
var box = TipBox.create(text)
|
var box = TipBox.create(text, messageType)
|
||||||
tips.add_child(box)
|
tips.add_child(box)
|
||||||
if destroyAfter > 0:
|
await TickTool.millseconds(500 * len(text))
|
||||||
await TickTool.millseconds(destroyAfter * len(text))
|
box.destroy()
|
||||||
box.destroy()
|
|
||||||
else:
|
|
||||||
return box
|
|
||||||
|
|||||||
Reference in New Issue
Block a user