From 54a41133943046b815e08caa7c054dbaafc0b207 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=A8=E8=90=BD=E5=9F=BA=E5=9B=B4=E8=99=BE?= <3161880837@qq.com> Date: Wed, 27 Aug 2025 20:27:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0UI=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E8=83=BD=E9=87=8F=E6=9D=A1=E5=92=8C?= =?UTF-8?q?=E9=A2=9C=E8=89=B2=E6=9D=A1=EF=BC=8C=E4=BC=98=E5=8C=96=E8=83=BD?= =?UTF-8?q?=E9=87=8F=E7=AE=A1=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Scenes/UI.tscn | 31 +++++++++++++++++++++----- components/UI/ColorBar.tscn | 30 +++++++++++++++++++++---- scripts/Statemachine/BossBar.gd | 4 ++-- scripts/Statemachine/BulletBase.gd | 16 ++++++------- scripts/Statemachine/ColorBar.gd | 16 ++++++------- scripts/Statemachine/EntityBase.gd | 10 +++++++-- scripts/Statemachine/EntityStateBar.gd | 2 +- scripts/Statemachine/UIState.gd | 3 +++ scripts/Tools/FieldStore.gd | 11 +++++---- themes/main.tres | 20 ++++++++++++++++- 10 files changed, 107 insertions(+), 36 deletions(-) diff --git a/components/Scenes/UI.tscn b/components/Scenes/UI.tscn index 0fedecb..d5a0368 100644 --- a/components/Scenes/UI.tscn +++ b/components/Scenes/UI.tscn @@ -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 diff --git a/components/UI/ColorBar.tscn b/components/UI/ColorBar.tscn index 72be9cd..54f04da 100644 --- a/components/UI/ColorBar.tscn +++ b/components/UI/ColorBar.tscn @@ -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 diff --git a/scripts/Statemachine/BossBar.gd b/scripts/Statemachine/BossBar.gd index 2e2a43c..914ac84 100644 --- a/scripts/Statemachine/BossBar.gd +++ b/scripts/Statemachine/BossBar.gd @@ -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) diff --git a/scripts/Statemachine/BulletBase.gd b/scripts/Statemachine/BulletBase.gd index 971e6c0..ea4d65a 100644 --- a/scripts/Statemachine/BulletBase.gd +++ b/scripts/Statemachine/BulletBase.gd @@ -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) diff --git a/scripts/Statemachine/ColorBar.gd b/scripts/Statemachine/ColorBar.gd index b73fb29..c026834 100644 --- a/scripts/Statemachine/ColorBar.gd +++ b/scripts/Statemachine/ColorBar.gd @@ -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() diff --git a/scripts/Statemachine/EntityBase.gd b/scripts/Statemachine/EntityBase.gd index 4975077..a7535e2 100644 --- a/scripts/Statemachine/EntityBase.gd +++ b/scripts/Statemachine/EntityBase.gd @@ -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(): diff --git a/scripts/Statemachine/EntityStateBar.gd b/scripts/Statemachine/EntityStateBar.gd index abcec42..13f54ef 100644 --- a/scripts/Statemachine/EntityStateBar.gd +++ b/scripts/Statemachine/EntityStateBar.gd @@ -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) diff --git a/scripts/Statemachine/UIState.gd b/scripts/Statemachine/UIState.gd index 29382dd..cbdb0dc 100644 --- a/scripts/Statemachine/UIState.gd +++ b/scripts/Statemachine/UIState.gd @@ -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) diff --git a/scripts/Tools/FieldStore.gd b/scripts/Tools/FieldStore.gd index 0e5de81..7c4dc66 100644 --- a/scripts/Tools/FieldStore.gd +++ b/scripts/Tools/FieldStore.gd @@ -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): diff --git a/themes/main.tres b/themes/main.tres index af5d52e..2801177 100644 --- a/themes/main.tres +++ b/themes/main.tres @@ -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")