mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-05-31 00:11:54 +08:00
feat(UI): 添加显示实体属性的面板和动画效果
添加新的输入动作"showFields"用于显示/隐藏实体属性面板 创建新的FieldShow组件用于显示实体属性值 为属性面板添加显示/隐藏动画效果 调整EntityBase中属性初始化的顺序
This commit is contained in:
@@ -73,9 +73,6 @@ func _ready():
|
||||
else:
|
||||
statebar = selfStatebar
|
||||
statebar.entity = self
|
||||
applyLevel()
|
||||
health = fields.get(FieldStore.Entity.MAX_HEALTH)
|
||||
energy = fields.get(FieldStore.Entity.MAX_ENERGY) * 0.5
|
||||
if isPlayer():
|
||||
statebar.levelLabels.hide()
|
||||
UIState.player = self
|
||||
@@ -99,6 +96,9 @@ func _ready():
|
||||
)
|
||||
else:
|
||||
currentFocusedBoss = get_tree().get_nodes_in_group("players")[0]
|
||||
applyLevel()
|
||||
health = fields.get(FieldStore.Entity.MAX_HEALTH)
|
||||
energy = fields.get(FieldStore.Entity.MAX_ENERGY) * 0.5
|
||||
healthChanged.connect(
|
||||
func(newHealth):
|
||||
if is_instance_valid(statebar):
|
||||
|
||||
@@ -4,6 +4,7 @@ class_name FieldShow
|
||||
|
||||
@export var field: FieldStore.Entity = FieldStore.Entity.MAX_HEALTH
|
||||
@export var value: float = 0
|
||||
@export var showSign: bool = true
|
||||
|
||||
@onready var nameLabel: Label = $"%name"
|
||||
@onready var valueLabel: Label = $"%value"
|
||||
@@ -13,9 +14,16 @@ func _ready():
|
||||
var formattedValue: String
|
||||
var dataType = FieldStore.entityMapType[field]
|
||||
if dataType == FieldStore.DataType.VALUE:
|
||||
formattedValue = MathTool.signBeforeStr(value)
|
||||
formattedValue = "%s" % (MathTool.signBeforeStr(value) if showSign else str(value))
|
||||
elif dataType == FieldStore.DataType.ANGLE:
|
||||
formattedValue = MathTool.signBeforeStr(value) + "°"
|
||||
formattedValue = "%s°" % (MathTool.signBeforeStr(value) if showSign else str(value))
|
||||
elif dataType == FieldStore.DataType.PERCENT:
|
||||
formattedValue = MathTool.signBeforeStr(float("%.1f" % (value * 100))) + "%"
|
||||
formattedValue = (MathTool.signBeforeStr(value * 100) if showSign else str(value * 100)) + "%"
|
||||
valueLabel.text = formattedValue
|
||||
|
||||
static func create(newField: FieldStore.Entity, newValue: float, newShowSign: bool) -> FieldShow:
|
||||
var fieldShow = preload("res://components/UI/FieldShow.tscn").instantiate()
|
||||
fieldShow.field = newField
|
||||
fieldShow.value = newValue
|
||||
fieldShow.showSign = newShowSign
|
||||
return fieldShow
|
||||
|
||||
@@ -7,6 +7,8 @@ class_name UIState
|
||||
@onready var items = $"%items"
|
||||
@onready var energyLabel: Label = $"%energy"
|
||||
@onready var energyMaxLabel: Label = $"%energyMax"
|
||||
@onready var fields: VBoxContainer = $"%fields"
|
||||
@onready var fieldsAnimator: AnimationPlayer = $"%fieldsAnimator"
|
||||
|
||||
static var player: EntityBase = null
|
||||
static var bossbar: EntityStateBar
|
||||
@@ -33,6 +35,14 @@ func _physics_process(_delta):
|
||||
WorldManager.rootNode.process_mode = Node.PROCESS_MODE_DISABLED
|
||||
else:
|
||||
WorldManager.rootNode.process_mode = Node.PROCESS_MODE_INHERIT
|
||||
if Input.is_action_just_pressed("showFields"):
|
||||
for i in fields.get_children():
|
||||
fields.remove_child(i)
|
||||
for i in player.fields:
|
||||
fields.add_child(FieldShow.create(i, player.fields[i], false))
|
||||
fieldsAnimator.play("show")
|
||||
if Input.is_action_just_released("showFields"):
|
||||
fieldsAnimator.play("hide")
|
||||
|
||||
static func setPanel(targetName: String = ""):
|
||||
currentPanel = null
|
||||
|
||||
@@ -10,4 +10,4 @@ static func randv2_range(offset: float):
|
||||
static func randc_from(array: Array):
|
||||
return array[randi() % array.size()]
|
||||
static func signBeforeStr(value: float):
|
||||
return ("+" if value > 0 else "-" if value < 0 else "") + str(abs(value))
|
||||
return ("+" if value > 0 else "-" if value < 0 else "") + str(abs(value))
|
||||
|
||||
Reference in New Issue
Block a user