1
1
mirror of https://github.com/Rundll86/Dog-Lynx-And-HCN.git synced 2026-07-10 03:52:53 +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="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"] [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="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="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="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"] [node name="UI" type="CanvasLayer"]
process_mode = 3 process_mode = 3
@@ -81,10 +82,13 @@ offset_right = 97.0
offset_bottom = 14.0 offset_bottom = 14.0
theme_override_styles/panel = ExtResource("6_8m0pt") 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 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) custom_minimum_size = Vector2(16, 16)
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 4 size_flags_horizontal = 4
@@ -92,8 +96,25 @@ size_flags_vertical = 4
texture = ExtResource("7_2om12") texture = ExtResource("7_2om12")
expand_mode = 1 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 unique_name_in_owner = true
layout_mode = 2 layout_mode = 2
theme = ExtResource("5_widd7") 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"] [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"] [node name="ColorBar" type="Control"]
layout_mode = 3 layout_mode = 3
anchors_preset = 0 anchors_preset = 0
offset_right = 100.0 offset_right = 100.0
offset_bottom = 10.0 offset_bottom = 10.0
script = ExtResource("1_a106p") script = ExtResource("1_a106p")
backColor = Color(0, 0, 0, 0.5) backBox = SubResource("StyleBoxFlat_kf2fc")
middleColor = Color(1, 0, 0, 0.5) middleBox = SubResource("StyleBoxFlat_gkydp")
frontColor = Color(1, 1, 1, 1) frontBox = SubResource("StyleBoxFlat_x7p33")
speed1 = 0.9
speed2 = 0.05 speed2 = 0.05
+2 -2
View File
@@ -4,8 +4,8 @@ class_name BossBar
@onready var nameLabel: Label = $"%name" @onready var nameLabel: Label = $"%name"
@onready var valueLabel: Label = $"%value" @onready var valueLabel: Label = $"%value"
func _process(delta): func _physics_process(delta):
super._process(delta) super._physics_process(delta)
if is_instance_valid(entity): if is_instance_valid(entity):
nameLabel.text = entity.displayName nameLabel.text = entity.displayName
valueLabel.text = "%.2f" % (entity.health / entity.fields[FieldStore.Entity.MAX_HEALTH] * 100) 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 = [] var instances = []
for i in range(count): for i in range(count):
var instance: BulletBase = bullet.instantiate() var instance: BulletBase = bullet.instantiate()
if launchBy.energy < instance.needEnergy: if launchBy.useEnergy(instance.needEnergy):
continue instance.launcher = launchBy
launchBy.energy -= instance.needEnergy instance.position = spawnPosition
instance.launcher = launchBy instance.rotation = spawnRotation + deg_to_rad(randf_range(-launchBy.fields.get(FieldStore.Entity.OFFSET_SHOOT), launchBy.fields.get(FieldStore.Entity.OFFSET_SHOOT)))
instance.position = spawnPosition if addToWorld:
instance.rotation = spawnRotation + deg_to_rad(randf_range(-launchBy.fields.get(FieldStore.Entity.OFFSET_SHOOT), launchBy.fields.get(FieldStore.Entity.OFFSET_SHOOT))) WorldManager.rootNode.add_child(instance)
if addToWorld: instances.append(instance)
WorldManager.rootNode.add_child(instance)
instances.append(instance)
return len(instances) return len(instances)
+8 -8
View File
@@ -5,10 +5,10 @@ class_name ColorBar
@export var minValue: float = 0 @export var minValue: float = 0
@export var maxValue: float = 100 @export var maxValue: float = 100
@export var currentValue: float = 50 @export var currentValue: float = 50
@export var backColor: Color @export var backBox: StyleBox
@export var middleColor: Color @export var middleBox: StyleBox
@export var frontColor: Color @export var frontBox: StyleBox
@export var speed1: float = 0.9 @export var speed1: float = 0.8
@export var speed2: float = 0.01 @export var speed2: float = 0.01
var middleValue = 0 var middleValue = 0
@@ -25,10 +25,10 @@ func _ready():
middleValue = currentValue middleValue = currentValue
frontValue = currentValue frontValue = currentValue
func _draw(): func _draw():
draw_rect(Rect2(0, 0, size.x, size.y), backColor) draw_style_box(backBox, Rect2(0, 0, size.x, size.y))
draw_rect(Rect2(0, 0, size.x * getPercent(middleValue), size.y), middleColor) draw_style_box(middleBox, Rect2(0, 0, size.x * getPercent(middleValue), size.y))
draw_rect(Rect2(0, 0, size.x * getPercent(frontValue), size.y), frontColor) draw_style_box(frontBox, Rect2(0, 0, size.x * getPercent(frontValue), size.y))
func _process(_delta: float) -> void: func _physics_process(_delta: float) -> void:
middleValue = lerpf(middleValue, currentValue, speed1 if forwardDirection > 0 else speed2) middleValue = lerpf(middleValue, currentValue, speed1 if forwardDirection > 0 else speed2)
frontValue = lerpf(frontValue, currentValue, speed1 if forwardDirection < 0 else speed2) frontValue = lerpf(frontValue, currentValue, speed1 if forwardDirection < 0 else speed2)
queue_redraw() queue_redraw()
+8 -2
View File
@@ -18,7 +18,8 @@ var fields = {
FieldStore.Entity.EXTRA_BULLET_COUNT: 0, FieldStore.Entity.EXTRA_BULLET_COUNT: 0,
FieldStore.Entity.DROP_APPLE_RATE: 0, FieldStore.Entity.DROP_APPLE_RATE: 0,
FieldStore.Entity.FEED_COUNT_SHOW: 3, 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 = { var inventory = {
ItemStore.ItemType.BASEBALL: 100, ItemStore.ItemType.BASEBALL: 100,
@@ -70,7 +71,7 @@ func _ready():
currentFocusedBoss = get_tree().get_nodes_in_group("players")[0] currentFocusedBoss = get_tree().get_nodes_in_group("players")[0]
func _process(_delta): func _process(_delta):
health = clamp(health, 0, fields.get(FieldStore.Entity.MAX_HEALTH)) 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: for i in inventory:
inventory[i] = clamp(inventory[i], 0, inventoryMax[i]) inventory[i] = clamp(inventory[i], 0, inventoryMax[i])
func _physics_process(_delta: float) -> void: func _physics_process(_delta: float) -> void:
@@ -117,6 +118,11 @@ func takeDamage(bullet: BulletBase, crit: bool):
tryDie(bullet) tryDie(bullet)
func storeEnergy(value: float): func storeEnergy(value: float):
energy += value * fields.get(FieldStore.Entity.ENERGY_MULTIPILER) energy += value * fields.get(FieldStore.Entity.ENERGY_MULTIPILER)
func useEnergy(value: float):
var state = energy >= value
if state:
energy -= value
return state
func isCooldowned(): func isCooldowned():
return Time.get_ticks_msec() - lastAttack >= cooldownUnit / fields.get(FieldStore.Entity.ATTACK_SPEED) return Time.get_ticks_msec() - lastAttack >= cooldownUnit / fields.get(FieldStore.Entity.ATTACK_SPEED)
func startCooldown(): func startCooldown():
+1 -1
View File
@@ -5,7 +5,7 @@ class_name EntityStateBar
@onready var healthBar: ColorBar = $"%health" @onready var healthBar: ColorBar = $"%health"
func _process(_delta): func _physics_process(_delta):
if is_instance_valid(entity): if is_instance_valid(entity):
healthBar.maxValue = entity.fields.get(FieldStore.Entity.MAX_HEALTH) healthBar.maxValue = entity.fields.get(FieldStore.Entity.MAX_HEALTH)
healthBar.setCurrent(entity.health) healthBar.setCurrent(entity.health)
+3
View File
@@ -6,6 +6,7 @@ class_name UIState
@onready var apple = $"%apple" @onready var apple = $"%apple"
@onready var items = $"%items" @onready var items = $"%items"
@onready var energy = $"%energy" @onready var energy = $"%energy"
@onready var energyPercent: ColorBar = $"%percent"
static var player: EntityBase = null static var player: EntityBase = null
static var bossbar: EntityStateBar static var bossbar: EntityStateBar
@@ -20,6 +21,8 @@ func _process(_delta):
func _physics_process(_delta): func _physics_process(_delta):
if is_instance_valid(player): if is_instance_valid(player):
energy.text = "%.1f"%player.energy energy.text = "%.1f"%player.energy
energyPercent.maxValue = player.fields.get(FieldStore.Entity.MAX_ENERGY)
energyPercent.setCurrent(player.energy)
for i in items.get_children(): for i in items.get_children():
var item = i as ItemShow var item = i as ItemShow
item.count = player.inventory.get(item.type) item.count = player.inventory.get(item.type)
+7 -4
View File
@@ -23,10 +23,11 @@ enum Entity {
EXTRA_BULLET_COUNT, EXTRA_BULLET_COUNT,
DROP_APPLE_RATE, DROP_APPLE_RATE,
FEED_COUNT_SHOW, FEED_COUNT_SHOW,
FEED_COUNT_CAN_MADE FEED_COUNT_CAN_MADE,
MAX_ENERGY
} }
static var entityMap = { static var entityMap = {
Entity.MAX_HEALTH: "最大生命值", Entity.MAX_HEALTH: "生命上限",
Entity.DAMAGE_MULTIPILER: "伤害倍率", Entity.DAMAGE_MULTIPILER: "伤害倍率",
Entity.MOVEMENT_SPEED: "移动速度", Entity.MOVEMENT_SPEED: "移动速度",
Entity.ATTACK_SPEED: "攻击速度", Entity.ATTACK_SPEED: "攻击速度",
@@ -42,7 +43,8 @@ static var entityMap = {
Entity.EXTRA_BULLET_COUNT: "额外子弹", Entity.EXTRA_BULLET_COUNT: "额外子弹",
Entity.DROP_APPLE_RATE: "苹果掉落率", Entity.DROP_APPLE_RATE: "苹果掉落率",
Entity.FEED_COUNT_SHOW: "可选饲料数量", Entity.FEED_COUNT_SHOW: "可选饲料数量",
Entity.FEED_COUNT_CAN_MADE: "可制作饲料数量" Entity.FEED_COUNT_CAN_MADE: "可制作饲料数量",
Entity.MAX_ENERGY: "能量上限"
} }
static var entityMapType = { static var entityMapType = {
Entity.MAX_HEALTH: DataType.VALUE, Entity.MAX_HEALTH: DataType.VALUE,
@@ -61,7 +63,8 @@ static var entityMapType = {
Entity.EXTRA_BULLET_COUNT: DataType.VALUE, Entity.EXTRA_BULLET_COUNT: DataType.VALUE,
Entity.DROP_APPLE_RATE: DataType.PERCENT, Entity.DROP_APPLE_RATE: DataType.PERCENT,
Entity.FEED_COUNT_SHOW: DataType.VALUE, 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 = { static var entityApplier = {
Entity.MAX_HEALTH: func(entity, value): 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"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_2jby4"]
content_margin_left = 5.0 content_margin_left = 5.0
@@ -78,6 +78,22 @@ corner_radius_top_right = 5
corner_radius_bottom_right = 5 corner_radius_bottom_right = 5
corner_radius_bottom_left = 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] [resource]
Button/font_sizes/font_size = 14 Button/font_sizes/font_size = 14
Button/styles/disabled = SubResource("StyleBoxFlat_2jby4") 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/hover_pressed = SubResource("StyleBoxFlat_mt3v0")
Button/styles/normal = SubResource("StyleBoxFlat_3nqwh") Button/styles/normal = SubResource("StyleBoxFlat_3nqwh")
Button/styles/pressed = SubResource("StyleBoxFlat_iekfp") Button/styles/pressed = SubResource("StyleBoxFlat_iekfp")
ProgressBar/styles/background = SubResource("StyleBoxFlat_a507o")
ProgressBar/styles/fill = SubResource("StyleBoxFlat_ef7vq")