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

feat: 更新UI组件,添加能量条和颜色条,优化能量管理逻辑

This commit is contained in:
2025-08-27 20:27:01 +08:00
parent b4d11ee98a
commit 54a4113394
10 changed files with 107 additions and 36 deletions
+26 -5
View File
@@ -1,4 +1,4 @@
[gd_scene load_steps=9 format=3 uid="uid://dfwg750a47ggx"]
[gd_scene load_steps=10 format=3 uid="uid://dfwg750a47ggx"]
[ext_resource type="PackedScene" uid="uid://ofpg5s3j7esv" path="res://components/UI/BossBar.tscn" id="1_2pe58"]
[ext_resource type="Script" path="res://scripts/Statemachine/UIState.gd" id="1_f00a6"]
@@ -8,6 +8,7 @@
[ext_resource type="Theme" uid="uid://b6nox1qqh50ub" path="res://themes/smallText.tres" id="5_widd7"]
[ext_resource type="StyleBox" uid="uid://bsv1daadkv4eq" path="res://styleboxes/topLeftPanel.tres" id="6_8m0pt"]
[ext_resource type="Texture2D" uid="uid://k13cte17httt" path="res://resources/items/energy.svg" id="7_2om12"]
[ext_resource type="PackedScene" uid="uid://d1ulrvupa76ap" path="res://components/UI/ColorBar.tscn" id="9_44nw8"]
[node name="UI" type="CanvasLayer"]
process_mode = 3
@@ -81,10 +82,13 @@ offset_right = 97.0
offset_bottom = 14.0
theme_override_styles/panel = ExtResource("6_8m0pt")
[node name="energy" type="HBoxContainer" parent="root/energy"]
[node name="container" type="VBoxContainer" parent="root/energy"]
layout_mode = 2
[node name="icon" type="TextureRect" parent="root/energy/energy"]
[node name="energy" type="HBoxContainer" parent="root/energy/container"]
layout_mode = 2
[node name="icon" type="TextureRect" parent="root/energy/container/energy"]
custom_minimum_size = Vector2(16, 16)
layout_mode = 2
size_flags_horizontal = 4
@@ -92,8 +96,25 @@ size_flags_vertical = 4
texture = ExtResource("7_2om12")
expand_mode = 1
[node name="energy" type="Label" parent="root/energy/energy"]
[node name="energy" type="Label" parent="root/energy/container/energy"]
unique_name_in_owner = true
layout_mode = 2
theme = ExtResource("5_widd7")
text = "114514.0"
text = "50.0"
[node name="sep" type="Label" parent="root/energy/container/energy"]
layout_mode = 2
theme = ExtResource("5_widd7")
text = "/"
[node name="energyMax" type="Label" parent="root/energy/container/energy"]
unique_name_in_owner = true
layout_mode = 2
theme = ExtResource("5_widd7")
text = "100.0"
[node name="percent" parent="root/energy/container" instance=ExtResource("9_44nw8")]
unique_name_in_owner = true
custom_minimum_size = Vector2(0, 5)
layout_mode = 2
speed1 = 0.9
+26 -4
View File
@@ -1,14 +1,36 @@
[gd_scene load_steps=2 format=3 uid="uid://d1ulrvupa76ap"]
[gd_scene load_steps=5 format=3 uid="uid://d1ulrvupa76ap"]
[ext_resource type="Script" path="res://scripts/Statemachine/ColorBar.gd" id="1_a106p"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_kf2fc"]
bg_color = Color(0, 0, 0, 0.5)
corner_radius_top_left = 5
corner_radius_top_right = 5
corner_radius_bottom_right = 5
corner_radius_bottom_left = 5
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_gkydp"]
bg_color = Color(1, 0, 0, 0.5)
corner_radius_top_left = 5
corner_radius_top_right = 5
corner_radius_bottom_right = 5
corner_radius_bottom_left = 5
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_x7p33"]
bg_color = Color(1, 1, 1, 1)
corner_radius_top_left = 5
corner_radius_top_right = 5
corner_radius_bottom_right = 5
corner_radius_bottom_left = 5
[node name="ColorBar" type="Control"]
layout_mode = 3
anchors_preset = 0
offset_right = 100.0
offset_bottom = 10.0
script = ExtResource("1_a106p")
backColor = Color(0, 0, 0, 0.5)
middleColor = Color(1, 0, 0, 0.5)
frontColor = Color(1, 1, 1, 1)
backBox = SubResource("StyleBoxFlat_kf2fc")
middleBox = SubResource("StyleBoxFlat_gkydp")
frontBox = SubResource("StyleBoxFlat_x7p33")
speed1 = 0.9
speed2 = 0.05
+2 -2
View File
@@ -4,8 +4,8 @@ class_name BossBar
@onready var nameLabel: Label = $"%name"
@onready var valueLabel: Label = $"%value"
func _process(delta):
super._process(delta)
func _physics_process(delta):
super._physics_process(delta)
if is_instance_valid(entity):
nameLabel.text = entity.displayName
valueLabel.text = "%.2f" % (entity.health / entity.fields[FieldStore.Entity.MAX_HEALTH] * 100)
+7 -9
View File
@@ -86,13 +86,11 @@ static func generate(
var instances = []
for i in range(count):
var instance: BulletBase = bullet.instantiate()
if launchBy.energy < instance.needEnergy:
continue
launchBy.energy -= instance.needEnergy
instance.launcher = launchBy
instance.position = spawnPosition
instance.rotation = spawnRotation + deg_to_rad(randf_range(-launchBy.fields.get(FieldStore.Entity.OFFSET_SHOOT), launchBy.fields.get(FieldStore.Entity.OFFSET_SHOOT)))
if addToWorld:
WorldManager.rootNode.add_child(instance)
instances.append(instance)
if launchBy.useEnergy(instance.needEnergy):
instance.launcher = launchBy
instance.position = spawnPosition
instance.rotation = spawnRotation + deg_to_rad(randf_range(-launchBy.fields.get(FieldStore.Entity.OFFSET_SHOOT), launchBy.fields.get(FieldStore.Entity.OFFSET_SHOOT)))
if addToWorld:
WorldManager.rootNode.add_child(instance)
instances.append(instance)
return len(instances)
+8 -8
View File
@@ -5,10 +5,10 @@ class_name ColorBar
@export var minValue: float = 0
@export var maxValue: float = 100
@export var currentValue: float = 50
@export var backColor: Color
@export var middleColor: Color
@export var frontColor: Color
@export var speed1: float = 0.9
@export var backBox: StyleBox
@export var middleBox: StyleBox
@export var frontBox: StyleBox
@export var speed1: float = 0.8
@export var speed2: float = 0.01
var middleValue = 0
@@ -25,10 +25,10 @@ func _ready():
middleValue = currentValue
frontValue = currentValue
func _draw():
draw_rect(Rect2(0, 0, size.x, size.y), backColor)
draw_rect(Rect2(0, 0, size.x * getPercent(middleValue), size.y), middleColor)
draw_rect(Rect2(0, 0, size.x * getPercent(frontValue), size.y), frontColor)
func _process(_delta: float) -> void:
draw_style_box(backBox, Rect2(0, 0, size.x, size.y))
draw_style_box(middleBox, Rect2(0, 0, size.x * getPercent(middleValue), size.y))
draw_style_box(frontBox, Rect2(0, 0, size.x * getPercent(frontValue), size.y))
func _physics_process(_delta: float) -> void:
middleValue = lerpf(middleValue, currentValue, speed1 if forwardDirection > 0 else speed2)
frontValue = lerpf(frontValue, currentValue, speed1 if forwardDirection < 0 else speed2)
queue_redraw()
+8 -2
View File
@@ -18,7 +18,8 @@ var fields = {
FieldStore.Entity.EXTRA_BULLET_COUNT: 0,
FieldStore.Entity.DROP_APPLE_RATE: 0,
FieldStore.Entity.FEED_COUNT_SHOW: 3,
FieldStore.Entity.FEED_COUNT_CAN_MADE: 1
FieldStore.Entity.FEED_COUNT_CAN_MADE: 1,
FieldStore.Entity.MAX_ENERGY: 200,
}
var inventory = {
ItemStore.ItemType.BASEBALL: 100,
@@ -70,7 +71,7 @@ func _ready():
currentFocusedBoss = get_tree().get_nodes_in_group("players")[0]
func _process(_delta):
health = clamp(health, 0, fields.get(FieldStore.Entity.MAX_HEALTH))
energy = clamp(energy, 0, INF)
energy = clamp(energy, 0, fields.get(FieldStore.Entity.MAX_ENERGY))
for i in inventory:
inventory[i] = clamp(inventory[i], 0, inventoryMax[i])
func _physics_process(_delta: float) -> void:
@@ -117,6 +118,11 @@ func takeDamage(bullet: BulletBase, crit: bool):
tryDie(bullet)
func storeEnergy(value: float):
energy += value * fields.get(FieldStore.Entity.ENERGY_MULTIPILER)
func useEnergy(value: float):
var state = energy >= value
if state:
energy -= value
return state
func isCooldowned():
return Time.get_ticks_msec() - lastAttack >= cooldownUnit / fields.get(FieldStore.Entity.ATTACK_SPEED)
func startCooldown():
+1 -1
View File
@@ -5,7 +5,7 @@ class_name EntityStateBar
@onready var healthBar: ColorBar = $"%health"
func _process(_delta):
func _physics_process(_delta):
if is_instance_valid(entity):
healthBar.maxValue = entity.fields.get(FieldStore.Entity.MAX_HEALTH)
healthBar.setCurrent(entity.health)
+3
View File
@@ -6,6 +6,7 @@ class_name UIState
@onready var apple = $"%apple"
@onready var items = $"%items"
@onready var energy = $"%energy"
@onready var energyPercent: ColorBar = $"%percent"
static var player: EntityBase = null
static var bossbar: EntityStateBar
@@ -20,6 +21,8 @@ func _process(_delta):
func _physics_process(_delta):
if is_instance_valid(player):
energy.text = "%.1f"%player.energy
energyPercent.maxValue = player.fields.get(FieldStore.Entity.MAX_ENERGY)
energyPercent.setCurrent(player.energy)
for i in items.get_children():
var item = i as ItemShow
item.count = player.inventory.get(item.type)
+7 -4
View File
@@ -23,10 +23,11 @@ enum Entity {
EXTRA_BULLET_COUNT,
DROP_APPLE_RATE,
FEED_COUNT_SHOW,
FEED_COUNT_CAN_MADE
FEED_COUNT_CAN_MADE,
MAX_ENERGY
}
static var entityMap = {
Entity.MAX_HEALTH: "最大生命值",
Entity.MAX_HEALTH: "生命上限",
Entity.DAMAGE_MULTIPILER: "伤害倍率",
Entity.MOVEMENT_SPEED: "移动速度",
Entity.ATTACK_SPEED: "攻击速度",
@@ -42,7 +43,8 @@ static var entityMap = {
Entity.EXTRA_BULLET_COUNT: "额外子弹",
Entity.DROP_APPLE_RATE: "苹果掉落率",
Entity.FEED_COUNT_SHOW: "可选饲料数量",
Entity.FEED_COUNT_CAN_MADE: "可制作饲料数量"
Entity.FEED_COUNT_CAN_MADE: "可制作饲料数量",
Entity.MAX_ENERGY: "能量上限"
}
static var entityMapType = {
Entity.MAX_HEALTH: DataType.VALUE,
@@ -61,7 +63,8 @@ static var entityMapType = {
Entity.EXTRA_BULLET_COUNT: DataType.VALUE,
Entity.DROP_APPLE_RATE: DataType.PERCENT,
Entity.FEED_COUNT_SHOW: DataType.VALUE,
Entity.FEED_COUNT_CAN_MADE: DataType.VALUE
Entity.FEED_COUNT_CAN_MADE: DataType.VALUE,
Entity.MAX_ENERGY: DataType.VALUE
}
static var entityApplier = {
Entity.MAX_HEALTH: func(entity, value):
+19 -1
View File
@@ -1,4 +1,4 @@
[gd_resource type="Theme" load_steps=7 format=3 uid="uid://dhvs6urgf6jr5"]
[gd_resource type="Theme" load_steps=9 format=3 uid="uid://dhvs6urgf6jr5"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_2jby4"]
content_margin_left = 5.0
@@ -78,6 +78,22 @@ corner_radius_top_right = 5
corner_radius_bottom_right = 5
corner_radius_bottom_left = 5
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_a507o"]
content_margin_top = 5.0
content_margin_bottom = 0.0
bg_color = Color(0, 0, 0, 0.5)
corner_radius_top_left = 5
corner_radius_top_right = 5
corner_radius_bottom_right = 5
corner_radius_bottom_left = 5
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ef7vq"]
bg_color = Color(1, 1, 1, 1)
corner_radius_top_left = 5
corner_radius_top_right = 5
corner_radius_bottom_right = 5
corner_radius_bottom_left = 5
[resource]
Button/font_sizes/font_size = 14
Button/styles/disabled = SubResource("StyleBoxFlat_2jby4")
@@ -86,3 +102,5 @@ Button/styles/hover = SubResource("StyleBoxFlat_4j7ii")
Button/styles/hover_pressed = SubResource("StyleBoxFlat_mt3v0")
Button/styles/normal = SubResource("StyleBoxFlat_3nqwh")
Button/styles/pressed = SubResource("StyleBoxFlat_iekfp")
ProgressBar/styles/background = SubResource("StyleBoxFlat_a507o")
ProgressBar/styles/fill = SubResource("StyleBoxFlat_ef7vq")