diff --git a/DungeonShooting_Godot/prefab/role/Player.tscn b/DungeonShooting_Godot/prefab/role/Player.tscn index 0440d22..abab257 100644 --- a/DungeonShooting_Godot/prefab/role/Player.tscn +++ b/DungeonShooting_Godot/prefab/role/Player.tscn @@ -8,6 +8,3 @@ collision_layer = 8 script = ExtResource( 2 ) GunPrefab = ExtResource( 4 ) - -[node name="AnimatedSprite" parent="." index="1"] -frame = 1 diff --git a/DungeonShooting_Godot/prefab/ui/RoomUI.tscn b/DungeonShooting_Godot/prefab/ui/RoomUI.tscn index 9441d00..228cf92 100644 --- a/DungeonShooting_Godot/prefab/ui/RoomUI.tscn +++ b/DungeonShooting_Godot/prefab/ui/RoomUI.tscn @@ -1,24 +1,15 @@ -[gd_scene load_steps=18 format=2] +[gd_scene load_steps=11 format=2] [ext_resource path="res://src/ui/RoomUI.cs" type="Script" id=1] [ext_resource path="res://resource/sprite/ui/mapBar.png" type="Texture" id=2] -[ext_resource path="res://resource/sprite/ui/keyboard/e.png" type="Texture" id=3] +[ext_resource path="res://prefab/ui/bar/ReloadBar.tscn" type="PackedScene" id=3] [ext_resource path="res://resource/sprite/ui/healthBar.png" type="Texture" id=4] [ext_resource path="res://resource/sprite/gun/gun4.png" type="Texture" id=5] [ext_resource path="res://resource/sprite/ui/hpBar.png" type="Texture" id=6] [ext_resource path="res://resource/sprite/ui/shieldBar.png" type="Texture" id=7] [ext_resource path="res://resource/sprite/ui/hpSlot.png" type="Texture" id=8] [ext_resource path="res://resource/sprite/ui/shieldSlot.png" type="Texture" id=9] -[ext_resource path="res://resource/sprite/ui/icon/icon_bullet.png" type="Texture" id=10] -[ext_resource path="res://resource/font/cn_font_4.tres" type="DynamicFont" id=11] -[ext_resource path="res://src/ui/InteractiveTipBar.cs" type="Script" id=12] -[ext_resource path="res://resource/sprite/ui/font_bg.png" type="Texture" id=13] -[ext_resource path="res://resource/sprite/ui/reloadBar.png" type="Texture" id=14] -[ext_resource path="res://resource/sprite/ui/reloadBarBlock.png" type="Texture" id=15] -[ext_resource path="res://src/ui/ReloadBar.cs" type="Script" id=16] - -[sub_resource type="Gradient" id=1] -colors = PoolColorArray( 0.4, 0.498039, 1, 1, 0.4, 0.498039, 1, 0.313726 ) +[ext_resource path="res://prefab/ui/bar/InteractiveTipBar.tscn" type="PackedScene" id=10] [node name="RoomUI" type="Control"] anchor_right = 1.0 @@ -111,47 +102,6 @@ [node name="GlobalNode" type="Node" parent="."] -[node name="InteractiveTipBar" type="Node2D" parent="GlobalNode"] -visible = false -z_index = 10 -script = ExtResource( 12 ) +[node name="InteractiveTipBar" parent="GlobalNode" instance=ExtResource( 10 )] -[node name="Bg" type="Sprite" parent="GlobalNode/InteractiveTipBar"] -position = Vector2( 14, -17 ) -scale = Vector2( 28, 7 ) -texture = ExtResource( 13 ) - -[node name="Icon" type="Sprite" parent="GlobalNode/InteractiveTipBar"] -position = Vector2( 0, -32 ) -texture = ExtResource( 10 ) - -[node name="Message" type="Label" parent="GlobalNode/InteractiveTipBar"] -margin_left = -18.0 -margin_top = -27.0 -margin_right = 18.0 -margin_bottom = -15.0 -custom_colors/font_color = Color( 0, 0, 0, 1 ) -custom_fonts/font = ExtResource( 11 ) -text = "111111" -align = 1 -valign = 1 - -[node name="InteractiveIcon" type="Sprite" parent="GlobalNode/InteractiveTipBar"] -visible = false -position = Vector2( 0, -30 ) -texture = ExtResource( 3 ) - -[node name="Line2D" type="Line2D" parent="GlobalNode/InteractiveTipBar"] -points = PoolVector2Array( 0, -17, 0, 0 ) -width = 1.0 -gradient = SubResource( 1 ) - -[node name="ReloadBar" type="Sprite" parent="GlobalNode"] -visible = false -position = Vector2( 0, -26 ) -texture = ExtResource( 14 ) -script = ExtResource( 16 ) - -[node name="ReloadBarBlock" type="Sprite" parent="GlobalNode/ReloadBar"] -position = Vector2( -13, 0 ) -texture = ExtResource( 15 ) +[node name="ReloadBar" parent="GlobalNode" instance=ExtResource( 3 )] diff --git a/DungeonShooting_Godot/prefab/ui/bar/InteractiveTipBar.tscn b/DungeonShooting_Godot/prefab/ui/bar/InteractiveTipBar.tscn new file mode 100644 index 0000000..23ee05f --- /dev/null +++ b/DungeonShooting_Godot/prefab/ui/bar/InteractiveTipBar.tscn @@ -0,0 +1,45 @@ +[gd_scene load_steps=7 format=2] + +[ext_resource path="res://src/ui/InteractiveTipBar.cs" type="Script" id=1] +[ext_resource path="res://resource/sprite/ui/keyboard/e.png" type="Texture" id=2] +[ext_resource path="res://resource/sprite/ui/icon/icon_bullet.png" type="Texture" id=3] +[ext_resource path="res://resource/sprite/ui/font_bg.png" type="Texture" id=4] +[ext_resource path="res://resource/font/cn_font_4.tres" type="DynamicFont" id=5] + +[sub_resource type="Gradient" id=1] +colors = PoolColorArray( 0.4, 0.498039, 1, 1, 0.4, 0.498039, 1, 0.313726 ) + +[node name="InteractiveTipBar" type="Node2D"] +visible = false +z_index = 10 +script = ExtResource( 1 ) + +[node name="Bg" type="Sprite" parent="."] +position = Vector2( 14, -17 ) +scale = Vector2( 28, 7 ) +texture = ExtResource( 4 ) + +[node name="Icon" type="Sprite" parent="."] +position = Vector2( 0, -32 ) +texture = ExtResource( 3 ) + +[node name="Message" type="Label" parent="."] +margin_left = -18.0 +margin_top = -27.0 +margin_right = 18.0 +margin_bottom = -15.0 +custom_colors/font_color = Color( 0, 0, 0, 1 ) +custom_fonts/font = ExtResource( 5 ) +text = "111111" +align = 1 +valign = 1 + +[node name="InteractiveIcon" type="Sprite" parent="."] +visible = false +position = Vector2( 0, -30 ) +texture = ExtResource( 2 ) + +[node name="Line2D" type="Line2D" parent="."] +points = PoolVector2Array( 0, -17, 0, 0 ) +width = 1.0 +gradient = SubResource( 1 ) diff --git a/DungeonShooting_Godot/prefab/ui/bar/ReloadBar.tscn b/DungeonShooting_Godot/prefab/ui/bar/ReloadBar.tscn new file mode 100644 index 0000000..d34b274 --- /dev/null +++ b/DungeonShooting_Godot/prefab/ui/bar/ReloadBar.tscn @@ -0,0 +1,15 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://src/ui/ReloadBar.cs" type="Script" id=1] +[ext_resource path="res://resource/sprite/ui/reloadBarBlock.png" type="Texture" id=2] +[ext_resource path="res://resource/sprite/ui/reloadBar.png" type="Texture" id=3] + +[node name="ReloadBar" type="Sprite"] +visible = false +position = Vector2( 0, -26 ) +texture = ExtResource( 3 ) +script = ExtResource( 1 ) + +[node name="ReloadBarBlock" type="Sprite" parent="."] +position = Vector2( -13, 0 ) +texture = ExtResource( 2 ) diff --git a/DungeonShooting_Godot/src/role/Player.cs b/DungeonShooting_Godot/src/role/Player.cs index c57f4ea..fdb4bd7 100644 --- a/DungeonShooting_Godot/src/role/Player.cs +++ b/DungeonShooting_Godot/src/role/Player.cs @@ -117,6 +117,15 @@ } //刷新显示的弹药剩余量 RefreshGunAmmunition(); + + if (Holster.ActiveGun != null && Holster.ActiveGun.Reloading) + { + RoomUI.Current.ReloadBar.ShowBar(GlobalPosition); + } + else + { + RoomUI.Current.ReloadBar.HideBar(); + } } public override void _PhysicsProcess(float delta) diff --git a/DungeonShooting_Godot/src/ui/ReloadBar.cs b/DungeonShooting_Godot/src/ui/ReloadBar.cs index 829cf27..f6b64ad 100644 --- a/DungeonShooting_Godot/src/ui/ReloadBar.cs +++ b/DungeonShooting_Godot/src/ui/ReloadBar.cs @@ -2,5 +2,22 @@ public class ReloadBar : Sprite { - + private Sprite block; + + public override void _Ready() + { + block = GetNode("ReloadBarBlock"); + } + + public void HideBar() + { + Visible = false; + } + + public void ShowBar(Vector2 position) + { + Visible = true; + GlobalPosition = position; + } + } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/ui/RoomUI.cs b/DungeonShooting_Godot/src/ui/RoomUI.cs index bda6251..42a57e3 100644 --- a/DungeonShooting_Godot/src/ui/RoomUI.cs +++ b/DungeonShooting_Godot/src/ui/RoomUI.cs @@ -29,6 +29,10 @@ /// 互动提示组件 /// public InteractiveTipBar InteractiveTipBar { get; private set; } + /// + /// 换弹进度组件 + /// + public ReloadBar ReloadBar { get; private set; } private NinePatchRect hpSlot; private NinePatchRect shieldSlot; @@ -55,10 +59,14 @@ InteractiveTipBar = GetNode("GlobalNode/InteractiveTipBar"); InteractiveTipBar.Visible = false; + ReloadBar = GetNode("GlobalNode/ReloadBar"); + ReloadBar.Visible = false; + //将 GlobalNode 节点下的 ui 节点放入全局坐标中 var tempNode = GetNode("GlobalNode"); var root = GetTree().CurrentScene; - for (int i = 0; i < tempNode.GetChildCount(); i++) + var count = tempNode.GetChildCount(); + for (int i = count - 1; i >= 0; i--) { var node = tempNode.GetChild(i); tempNode.RemoveChild(node); diff --git a/DungeonShooting_Godot/src/weapon/gun/Gun.cs b/DungeonShooting_Godot/src/weapon/gun/Gun.cs index 6b09d86..d8b63b5 100644 --- a/DungeonShooting_Godot/src/weapon/gun/Gun.cs +++ b/DungeonShooting_Godot/src/weapon/gun/Gun.cs @@ -88,6 +88,10 @@ /// 换弹计时器 /// public float ReloadTimer { get; private set; } = 0; + /// + /// 换弹进度 (0 - 1) + /// + public float ReloadProgress => ReloadTimer / Attribute.ReloadTime; //是否按下 private bool triggerFlag = false; @@ -331,7 +335,7 @@ if (Reloading) { //换弹中 - GD.Print("换弹中..." + (ReloadTimer / Attribute.ReloadTime)); + GD.Print("换弹中..." + ReloadProgress); } else if (CurrAmmo <= 0) {