diff --git a/DungeonShooting_Godot/prefab/role/Player.tscn b/DungeonShooting_Godot/prefab/role/Player.tscn index ececbbf..41d150d 100644 --- a/DungeonShooting_Godot/prefab/role/Player.tscn +++ b/DungeonShooting_Godot/prefab/role/Player.tscn @@ -1,11 +1,8 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=4 format=2] [ext_resource path="res://prefab/role/Role.tscn" type="PackedScene" id=1] [ext_resource path="res://src/role/Player.cs" type="Script" id=2] -[ext_resource path="res://resource/sprite/ui/keyboard/e.png" type="Texture" id=3] [ext_resource path="res://prefab/weapon/Gun.tscn" type="PackedScene" id=4] -[ext_resource path="res://resource/sprite/shell/shellCase.png" type="Texture" id=5] -[ext_resource path="res://resource/font/cn_font_4.tres" type="DynamicFont" id=6] [node name="Player" instance=ExtResource( 1 )] collision_layer = 8 @@ -13,36 +10,4 @@ GunPrefab = ExtResource( 4 ) [node name="AnimatedSprite" parent="." index="0"] -frame = 1 - -[node name="TipBar" type="ColorRect" parent="." index="6"] -visible = false -margin_left = -9.0 -margin_top = -24.0 -margin_right = 11.0 -margin_bottom = -18.0 -color = Color( 0.784314, 0.784314, 0.784314, 0.588235 ) - -[node name="ShellCase" type="TextureRect" parent="TipBar" index="0"] -margin_left = 1.0 -margin_top = 5.0 -margin_right = 5.0 -margin_bottom = 7.0 -rect_rotation = -90.0 -texture = ExtResource( 5 ) - -[node name="Label" type="Label" parent="TipBar" index="1"] -margin_left = 1.0 -margin_top = -2.0 -margin_right = 21.0 -margin_bottom = 9.0 -custom_colors/font_color = Color( 0, 0, 0, 1 ) -custom_fonts/font = ExtResource( 6 ) -text = "M1911" - -[node name="E" type="TextureRect" parent="TipBar" index="2"] -margin_left = 5.0 -margin_top = -12.0 -margin_right = 14.0 -margin_bottom = -1.0 -texture = ExtResource( 3 ) +frame = 3 diff --git a/DungeonShooting_Godot/prefab/ui/RoomUI.tscn b/DungeonShooting_Godot/prefab/ui/RoomUI.tscn index e3af5ff..a46592c 100644 --- a/DungeonShooting_Godot/prefab/ui/RoomUI.tscn +++ b/DungeonShooting_Godot/prefab/ui/RoomUI.tscn @@ -1,13 +1,18 @@ -[gd_scene load_steps=9 format=2] +[gd_scene load_steps=14 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://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] [node name="RoomUI" type="Control"] anchor_right = 1.0 @@ -97,3 +102,38 @@ margin_bottom = 17.0 text = "30/90" align = 1 + +[node name="GlobalNode" type="Node" parent="."] + +[node name="InteractiveTipBar" type="Node2D" parent="GlobalNode"] +z_index = 10 +script = ExtResource( 12 ) + +[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 diff --git a/DungeonShooting_Godot/resource/font/cn_font_35.tres b/DungeonShooting_Godot/resource/font/cn_font_35.tres index 16b5fe2..f4e81ad 100644 --- a/DungeonShooting_Godot/resource/font/cn_font_35.tres +++ b/DungeonShooting_Godot/resource/font/cn_font_35.tres @@ -4,7 +4,5 @@ [resource] size = 35 -use_mipmaps = true -use_filter = true extra_spacing_char = 1 font_data = ExtResource( 1 ) diff --git a/DungeonShooting_Godot/resource/font/cn_font_4.tres b/DungeonShooting_Godot/resource/font/cn_font_4.tres index 76f4221..fe24004 100644 --- a/DungeonShooting_Godot/resource/font/cn_font_4.tres +++ b/DungeonShooting_Godot/resource/font/cn_font_4.tres @@ -4,8 +4,6 @@ [resource] size = 4 -use_mipmaps = true -use_filter = true extra_spacing_top = -2 extra_spacing_bottom = -2 font_data = ExtResource( 1 ) diff --git a/DungeonShooting_Godot/resource/font/cn_font_6.tres b/DungeonShooting_Godot/resource/font/cn_font_6.tres index 5c63c44..be51965 100644 --- a/DungeonShooting_Godot/resource/font/cn_font_6.tres +++ b/DungeonShooting_Godot/resource/font/cn_font_6.tres @@ -4,6 +4,4 @@ [resource] size = 6 -use_mipmaps = true -use_filter = true font_data = ExtResource( 1 ) diff --git a/DungeonShooting_Godot/resource/sprite/ui/font_bg.png b/DungeonShooting_Godot/resource/sprite/ui/font_bg.png new file mode 100644 index 0000000..ffc8de6 --- /dev/null +++ b/DungeonShooting_Godot/resource/sprite/ui/font_bg.png Binary files differ diff --git a/DungeonShooting_Godot/resource/sprite/ui/font_bg.png.import b/DungeonShooting_Godot/resource/sprite/ui/font_bg.png.import new file mode 100644 index 0000000..bdc6bcf --- /dev/null +++ b/DungeonShooting_Godot/resource/sprite/ui/font_bg.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/font_bg.png-18c47830f9c445852c317c13c8eb1f7f.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://resource/sprite/ui/font_bg.png" +dest_files=[ "res://.import/font_bg.png-18c47830f9c445852c317c13c8eb1f7f.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/DungeonShooting_Godot/resource/sprite/ui/icon/icon_bullet.png b/DungeonShooting_Godot/resource/sprite/ui/icon/icon_bullet.png new file mode 100644 index 0000000..6afda7f --- /dev/null +++ b/DungeonShooting_Godot/resource/sprite/ui/icon/icon_bullet.png Binary files differ diff --git a/DungeonShooting_Godot/resource/sprite/ui/icon/icon_bullet.png.import b/DungeonShooting_Godot/resource/sprite/ui/icon/icon_bullet.png.import new file mode 100644 index 0000000..4f342e7 --- /dev/null +++ b/DungeonShooting_Godot/resource/sprite/ui/icon/icon_bullet.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/icon_bullet.png-c2767feaa9ebe0084fe04f619ec7ad30.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://resource/sprite/ui/icon/icon_bullet.png" +dest_files=[ "res://.import/icon_bullet.png-c2767feaa9ebe0084fe04f619ec7ad30.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/DungeonShooting_Godot/resource/sprite/ui/icon/icon_replace.png b/DungeonShooting_Godot/resource/sprite/ui/icon/icon_replace.png new file mode 100644 index 0000000..e956271 --- /dev/null +++ b/DungeonShooting_Godot/resource/sprite/ui/icon/icon_replace.png Binary files differ diff --git a/DungeonShooting_Godot/resource/sprite/ui/icon/icon_replace.png.import b/DungeonShooting_Godot/resource/sprite/ui/icon/icon_replace.png.import new file mode 100644 index 0000000..d70c2c3 --- /dev/null +++ b/DungeonShooting_Godot/resource/sprite/ui/icon/icon_replace.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/icon_replace.png-6e605c83622b5a2d459c2a9108a7d72a.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://resource/sprite/ui/icon/icon_replace.png" +dest_files=[ "res://.import/icon_replace.png-6e605c83622b5a2d459c2a9108a7d72a.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/DungeonShooting_Godot/resource/theme/mainTheme.tres b/DungeonShooting_Godot/resource/theme/mainTheme.tres index 0eae407..a2124e1 100644 --- a/DungeonShooting_Godot/resource/theme/mainTheme.tres +++ b/DungeonShooting_Godot/resource/theme/mainTheme.tres @@ -384,6 +384,8 @@ Button/colors/font_color_pressed = Color( 0.117647, 0.431373, 0.905882, 1 ) Button/colors/icon_color_hover = Color( 1.15, 1.15, 1.15, 1 ) Button/colors/icon_color_pressed = Color( 0.135294, 0.496079, 1.04176, 1 ) +Button/constants/hseparation = 2 +Button/fonts/font = null Button/styles/disabled = SubResource( 1 ) Button/styles/focus = SubResource( 2 ) Button/styles/hover = SubResource( 3 ) @@ -469,10 +471,12 @@ Editor/styles/sub_inspector_property_bg_selected9 = SubResource( 53 ) Label/colors/font_color = Color( 0.780392, 0.780392, 0.780392, 1 ) Label/colors/font_color_shadow = Color( 0, 0, 0, 0 ) +Label/colors/font_outline_modulate = Color( 1, 1, 1, 1 ) Label/constants/line_spacing = 3 Label/constants/shadow_as_outline = 0 Label/constants/shadow_offset_x = 1 Label/constants/shadow_offset_y = 1 +Label/fonts/font = null Label/styles/normal = SubResource( 54 ) LineEdit/colors/clear_button_color = Color( 0.780392, 0.780392, 0.780392, 1 ) LineEdit/colors/clear_button_color_pressed = Color( 0.117647, 0.431373, 0.905882, 1 ) diff --git a/DungeonShooting_Godot/src/props/CheckInteractiveResult.cs b/DungeonShooting_Godot/src/props/CheckInteractiveResult.cs new file mode 100644 index 0000000..07053f5 --- /dev/null +++ b/DungeonShooting_Godot/src/props/CheckInteractiveResult.cs @@ -0,0 +1,28 @@ + +/// +/// 检测互动返回的数据集 +/// +public class CheckInteractiveResult +{ + /// + /// 互动物体 + /// + public IProp Target; + /// + /// 是否可以互动 + /// + public bool CanInteractive; + /// + /// 互动提示信息 + /// + public string Message; + /// + /// 互动提示显示的图标 + /// + public string ShowIcon; + + public CheckInteractiveResult(IProp target) + { + Target = target; + } +} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/props/IProp.cs b/DungeonShooting_Godot/src/props/IProp.cs index 04f758e..960dba7 100644 --- a/DungeonShooting_Godot/src/props/IProp.cs +++ b/DungeonShooting_Godot/src/props/IProp.cs @@ -1,3 +1,4 @@ +using Godot; /// /// 道具接口 @@ -5,14 +6,19 @@ public interface IProp { /// + /// 获取道具所在的坐标 + /// + Vector2 GlobalPosition { get; } + + /// /// 返回是否能互动 /// /// 触发者 - bool CanTnteractive(Role master); + CheckInteractiveResult CheckInteractive(Role master); /// /// 与角色互动时调用 /// /// 触发者 - void Tnteractive(Role master); + void Interactive(Role master); } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/role/Player.cs b/DungeonShooting_Godot/src/role/Player.cs index aa1481e..a958225 100644 --- a/DungeonShooting_Godot/src/role/Player.cs +++ b/DungeonShooting_Godot/src/role/Player.cs @@ -16,8 +16,6 @@ /// public Vector2 Velocity = Vector2.Zero; - public Control TipBar; - /// /// 当前护盾值 /// @@ -55,8 +53,6 @@ { base._EnterTree(); RoomManager.Current.Player = this; - - TipBar = GetNode("TipBar"); } public override void _Ready() @@ -138,19 +134,19 @@ RoomUI.Current.SetMaxHp(maxHp); } - protected override void ChangeInteractiveItem() + protected override void ChangeInteractiveItem(CheckInteractiveResult result) { - if (InteractiveItem == null) + if (result == null) { - GD.Print("没有可互动的道具了"); - TipBar.Visible = false; + //隐藏互动提示 + RoomUI.Current.InteractiveTipBar.HideBar(); } else { if (InteractiveItem is Gun gun) { - GD.Print("更新可互动的道具: " + gun.Attribute.Name); - TipBar.Visible = true; + //显示互动提示 + RoomUI.Current.InteractiveTipBar.ShowBar(result.Target.GlobalPosition, result.ShowIcon, result.Message); } } } diff --git a/DungeonShooting_Godot/src/role/Role.cs b/DungeonShooting_Godot/src/role/Role.cs index 95c587f..2b6675b 100644 --- a/DungeonShooting_Godot/src/role/Role.cs +++ b/DungeonShooting_Godot/src/role/Role.cs @@ -107,10 +107,10 @@ protected abstract void OnChangeMaxHp(int maxHp); /// - /// 当可互动的物体改变时调用, 从 this.InteractiveItem 取值 + /// 当可互动的物体改变时调用, result 参数为 null 表示变为不可互动 /// - /// - protected abstract void ChangeInteractiveItem(); + /// 检测是否可互动时的返回值 + protected abstract void ChangeInteractiveItem(CheckInteractiveResult result); public override void _Ready() { @@ -141,14 +141,18 @@ else { //找到可互动的道具了 - if (!findFlag && item.CanTnteractive(this)) + if (!findFlag) { - findFlag = true; - if (InteractiveItem != item) + var result = item.CheckInteractive(this); + if (result.CanInteractive) //可以互动 { - InteractiveItem = item; - //GD.Print("--------change"); - ChangeInteractiveItem(); + findFlag = true; + if (InteractiveItem != item) + { + InteractiveItem = item; + //GD.Print("--------change"); + ChangeInteractiveItem(result); + } } } } @@ -158,7 +162,7 @@ { InteractiveItem = null; //GD.Print("--------remove1"); - ChangeInteractiveItem(); + ChangeInteractiveItem(null); } } @@ -216,7 +220,7 @@ { if (HasTnteractive()) { - InteractiveItem.Tnteractive(this); + InteractiveItem.Interactive(this); } } @@ -312,7 +316,7 @@ if (InteractiveItem == prop) { InteractiveItem = null; - ChangeInteractiveItem(); + ChangeInteractiveItem(null); } } } diff --git a/DungeonShooting_Godot/src/ui/InteractiveTipBar.cs b/DungeonShooting_Godot/src/ui/InteractiveTipBar.cs new file mode 100644 index 0000000..188b05e --- /dev/null +++ b/DungeonShooting_Godot/src/ui/InteractiveTipBar.cs @@ -0,0 +1,29 @@ +using Godot; + +public class InteractiveTipBar : Node2D +{ + + private Label Message; + private Sprite Icon; + private Sprite Bg; + + public override void _Ready() + { + Message = GetNode