1
1
mirror of https://github.com/Rundll86/Dog-Lynx-And-HCN.git synced 2026-05-31 00:11:54 +08:00

feat(FieldShow): 添加实体视图转换功能及新字段

为FieldShow组件添加useViewCast参数和entity引用,支持通过视图转换函数动态计算显示值
新增DROPPED_ITEM_GRAVITY相关字段到FieldStore
调整ItemDropped状态机的物品移动速度计算参数
This commit is contained in:
2025-08-29 07:54:00 +08:00
parent b03508a2e1
commit efa2912ae5
4 changed files with 25 additions and 6 deletions
+9 -1
View File
@@ -5,11 +5,17 @@ class_name FieldShow
@export var field: FieldStore.Entity = FieldStore.Entity.MAX_HEALTH
@export var value: float = 0
@export var showSign: bool = true
@export var entity: EntityBase = null
@export var useViewCast: bool = false
@onready var nameLabel: Label = $"%name"
@onready var valueLabel: Label = $"%value"
func _ready():
if useViewCast:
var caster = FieldStore.entityViewCastMap.get(field)
if caster:
value = caster.call(entity, value)
nameLabel.text = FieldStore.entityMap[field]
var formattedValue: String
var dataType = FieldStore.entityMapType[field]
@@ -21,9 +27,11 @@ func _ready():
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:
static func create(newField: FieldStore.Entity, newValue: float, newShowSign: bool, newEntity: EntityBase, newUseViewCast: bool) -> FieldShow:
var fieldShow = preload("res://components/UI/FieldShow.tscn").instantiate()
fieldShow.field = newField
fieldShow.value = newValue
fieldShow.showSign = newShowSign
fieldShow.entity = newEntity
fieldShow.useViewCast = newUseViewCast
return fieldShow
+1 -1
View File
@@ -21,7 +21,7 @@ func _physics_process(_delta):
linear_velocity = Vector2.ZERO
else:
var direction = (targetPlayer.position - position).normalized()
var speed = 4000.0 / ((targetPlayer.position - position).length() ** (1 / 3.0))
var speed = 5000.0 / ((targetPlayer.position - position).length() ** (1 / 3.0))
apply_central_force(direction * speed)
if position.distance_to(targetPlayer.position) < 60:
targetPlayer.collectItem(item, stackCount)
+1 -1
View File
@@ -39,7 +39,7 @@ func _physics_process(_delta):
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))
fields.add_child(FieldShow.create(i, player.fields[i], false, player, true))
fieldsAnimator.play("show")
if Input.is_action_just_released("showFields"):
fieldsAnimator.play("hide")