From 2501cb81b8fc9aab03f73a4c926804f78c04af94 Mon Sep 17 00:00:00 2001 From: freewu32 <2217332562@qq.com> Date: Thu, 3 Sep 2020 22:30:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=80=AA=E7=89=A9=E5=9B=BE?= =?UTF-8?q?=E9=89=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Main.gd | 8 ++ Main.tscn | 38 +++++-- src/hud/HUD.gd | 6 ++ src/monster/Monster.gd | 1 + src/monster/Monster.tscn | 5 +- src/monster/MonsterBook.gd | 30 ++++++ src/monster/MonsterBookItem.tscn | 164 +++++++++++++++++++++++++++++++ 7 files changed, 241 insertions(+), 11 deletions(-) create mode 100644 src/monster/MonsterBookItem.tscn diff --git a/Main.gd b/Main.gd index 0320ee1..1f5c8c4 100644 --- a/Main.gd +++ b/Main.gd @@ -21,6 +21,8 @@ func connect_player_properties_update(): func connect_button(): $"/root/Main/HUD/BottomBackground/VBoxContainer/SaveButton".connect("pressed",self,"on_save_button_clicked") $"/root/Main/HUD/BottomBackground/VBoxContainer/LoadButton".connect("pressed",self,"on_load_button_clicked") + $"/root/Main/HUD/BottomBackground/VBoxContainer/BookButton".connect("pressed",self,"on_book_button_clicked") + get_hud().get_close_book_button_view().connect("pressed",self,"on_close_book_clicked") func connect_level_update(): get_level_manager().connect("level_changed",self,"on_level_changed") @@ -60,6 +62,12 @@ func on_save_button_clicked(): func on_load_button_clicked(): get_level_manager().load_persistent(0) +func on_book_button_clicked(): + MonsterBook.show() + +func on_close_book_clicked(): + get_hud().get_book_dialog_view().visible = false + func get_hud() -> Hud: return $HUD as Hud diff --git a/Main.tscn b/Main.tscn index 832a37d..5711258 100644 --- a/Main.tscn +++ b/Main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=23 format=2] +[gd_scene load_steps=28 format=2] [ext_resource path="res://src/levels/Level1.tscn" type="PackedScene" id=1] [ext_resource path="res://assets/sounds/bgm.ogg" type="AudioStream" id=5] @@ -64,6 +64,16 @@ region = Rect2( 0, 512, 32, 32 ) atlas = SubResource( 6 ) region = Rect2( 0, 544, 32, 32 ) +[sub_resource type="StyleBoxEmpty" id=15] + +[sub_resource type="StyleBoxEmpty" id=16] + +[sub_resource type="StyleBoxEmpty" id=17] + +[sub_resource type="StyleBoxEmpty" id=18] + +[sub_resource type="StyleBoxEmpty" id=19] + [node name="Main" type="Node2D"] script = ExtResource( 12 ) @@ -416,27 +426,35 @@ anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 margin_left = -208.0 -margin_top = -208.0 -margin_right = 206.0 -margin_bottom = 208.0 +margin_top = -200.0 +margin_right = 232.0 +margin_bottom = 152.0 +scroll_horizontal_enabled = false __meta__ = { "_edit_use_anchors_": false } [node name="VBoxContainer" type="VBoxContainer" parent="HUD/BookDialog/ScrollContainer"] +__meta__ = { +"_edit_use_anchors_": false +} -[node name="CloseBook" type="Label" parent="HUD/BookDialog"] +[node name="CloseBook" type="Button" parent="HUD/BookDialog"] anchor_left = 1.0 anchor_top = 1.0 anchor_right = 1.0 anchor_bottom = 1.0 -margin_left = -77.9 -margin_top = -32.0 -margin_right = -13.9 -margin_bottom = -10.0 +margin_left = -103.0 +margin_top = -49.1 +margin_right = -15.0 +margin_bottom = -15.1 +custom_styles/hover = SubResource( 15 ) +custom_styles/pressed = SubResource( 16 ) +custom_styles/focus = SubResource( 17 ) +custom_styles/disabled = SubResource( 18 ) +custom_styles/normal = SubResource( 19 ) custom_fonts/font = ExtResource( 8 ) text = "返回游戏" -valign = 1 __meta__ = { "_edit_use_anchors_": false } diff --git a/src/hud/HUD.gd b/src/hud/HUD.gd index 34c97d4..fa01f57 100644 --- a/src/hud/HUD.gd +++ b/src/hud/HUD.gd @@ -31,3 +31,9 @@ func get_save_button_view() -> TextureButton: func get_load_button_view() -> TextureButton: return $"BottomBackground/VBoxContainer/Loadutton" as TextureButton + +func get_book_dialog_view() -> PopupDialog: + return $"BookDialog" as PopupDialog + +func get_close_book_button_view() -> Button: + return $"BookDialog/CloseBook" as Button diff --git a/src/monster/Monster.gd b/src/monster/Monster.gd index a03927d..93c1d86 100644 --- a/src/monster/Monster.gd +++ b/src/monster/Monster.gd @@ -9,6 +9,7 @@ var monster_sprite : AnimatedSprite func _ready(): monster_sprite = get_parent() monster_info = MonsterBook.get_info_by_name(monster_sprite.animation) + add_to_group("monster") # 玩家触碰回调 func on_player_touched(player): diff --git a/src/monster/Monster.tscn b/src/monster/Monster.tscn index 6a5f8af..fddbee3 100644 --- a/src/monster/Monster.tscn +++ b/src/monster/Monster.tscn @@ -20,9 +20,12 @@ animations = [ { "speed": 20.0 } ] -[node name="MonsterSprite" type="AnimatedSprite"] +[node name="MonsterSprite" type="AnimatedSprite" groups=[ +"monster", +]] frames = ExtResource( 8 ) animation = "greenSlime" +frame = 1 playing = true [node name="Monster" type="StaticBody2D" parent="."] diff --git a/src/monster/MonsterBook.gd b/src/monster/MonsterBook.gd index a17bb15..eb3b062 100644 --- a/src/monster/MonsterBook.gd +++ b/src/monster/MonsterBook.gd @@ -22,3 +22,33 @@ func get_monsters_name() -> Array: # 根据怪物名称获取怪物信息 func get_info_by_name(name:String) -> Dictionary: return monster_data[name] + +# 显示怪物图鉴 +func show(): + var dialog : PopupDialog = $"/root/Main/HUD/BookDialog" + var container : VBoxContainer = dialog.get_node("ScrollContainer/VBoxContainer") + var monster_set = {} + for monster in get_tree().get_nodes_in_group("monster"): + if monster is AnimatedSprite: + monster_set[monster.animation] = -1 + #清理旧视图 + for child in container.get_children(): + container.remove_child(child) + #增加子项视图 + for monster_name in monster_set.keys(): + var monster_info = get_info_by_name(monster_name) + var item = load("res://src/monster/MonsterBookItem.tscn").instance() as PanelContainer + #设置图标 + item.get_node("Content/MonsterImageBackground/MonsterImage").animation = monster_name + #设置名称 + item.get_node("Content/MonsterName").text = monster_info.name + #设置血量 + item.get_node("Content/MonsterHp/HpValue").text = monster_info.hp as String + #设置攻击力 + item.get_node("Content/MonsterAtk/AtkValue").text = monster_info.atk as String + #设置防御力 + item.get_node("Content/MonsterDef/DefValue").text = monster_info.def as String + #设置金钱 + item.get_node("Content/MonsterMoney/MoneyValue").text = monster_info.money as String + container.add_child(item) + dialog.popup() diff --git a/src/monster/MonsterBookItem.tscn b/src/monster/MonsterBookItem.tscn new file mode 100644 index 0000000..f75d30b --- /dev/null +++ b/src/monster/MonsterBookItem.tscn @@ -0,0 +1,164 @@ +[gd_scene load_steps=7 format=2] + +[ext_resource path="res://src/monster/monster_spriteframes.tres" type="SpriteFrames" id=1] +[ext_resource path="res://assets/images/ground.png" type="Texture" id=2] +[ext_resource path="res://assets/fonts/Droid Sans Fallback.tres" type="DynamicFont" id=3] +[ext_resource path="res://assets/fonts/Droid Sans Fallback.ttf" type="DynamicFontData" id=4] + +[sub_resource type="StyleBoxEmpty" id=1] + +[sub_resource type="DynamicFont" id=2] +size = 12 +font_data = ExtResource( 4 ) + +[node name="MonsterBookItem" type="PanelContainer"] +margin_right = 416.0 +margin_bottom = 64.0 +rect_min_size = Vector2( 416, 64 ) +custom_styles/panel = SubResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Content" type="Control" parent="."] +margin_right = 416.0 +margin_bottom = 64.0 + +[node name="MonsterImageBackground" type="TextureRect" parent="Content"] +margin_left = 16.0 +margin_top = 16.0 +margin_right = 48.0 +margin_bottom = 48.0 +texture = ExtResource( 2 ) +expand = true +__meta__ = { +"_edit_group_": true, +"_edit_use_anchors_": false +} + +[node name="MonsterImage" type="AnimatedSprite" parent="Content/MonsterImageBackground"] +position = Vector2( 16, 16 ) +frames = ExtResource( 1 ) +animation = "greenSlime" +frame = 1 +playing = true + +[node name="MonsterName" type="Label" parent="Content"] +margin_left = 64.0 +margin_top = 16.0 +margin_right = 144.0 +margin_bottom = 48.0 +custom_fonts/font = ExtResource( 3 ) +text = "绿色史莱姆" +valign = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="MonsterHp" type="Label" parent="Content"] +margin_left = 160.0 +margin_top = 8.0 +margin_right = 196.0 +margin_bottom = 25.0 +custom_fonts/font = SubResource( 2 ) +text = "生命值" +valign = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="HpValue" type="Label" parent="Content/MonsterHp"] +anchor_top = 0.5 +anchor_bottom = 0.5 +margin_left = 48.0 +margin_top = -8.5 +margin_right = 112.0 +margin_bottom = 8.5 +custom_fonts/font = SubResource( 2 ) +text = "35" +valign = 1 +clip_text = true +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="MonsterMoney" type="Label" parent="Content"] +margin_left = 160.0 +margin_top = 40.0 +margin_right = 184.0 +margin_bottom = 57.0 +custom_fonts/font = SubResource( 2 ) +text = "金钱" +valign = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="MoneyValue" type="Label" parent="Content/MonsterMoney"] +anchor_top = 0.5 +anchor_bottom = 0.5 +margin_left = 48.0 +margin_top = -8.5 +margin_right = 112.0 +margin_bottom = 8.5 +custom_fonts/font = SubResource( 2 ) +text = "1" +valign = 1 +clip_text = true +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="MonsterAtk" type="Label" parent="Content"] +margin_left = 288.0 +margin_top = 8.0 +margin_right = 324.0 +margin_bottom = 25.0 +custom_fonts/font = SubResource( 2 ) +text = "攻击力" +valign = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="AtkValue" type="Label" parent="Content/MonsterAtk"] +anchor_top = 0.5 +anchor_bottom = 0.5 +margin_left = 48.0 +margin_top = -8.5 +margin_right = 111.0 +margin_bottom = 8.5 +custom_fonts/font = SubResource( 2 ) +text = "35" +valign = 1 +clip_text = true +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="MonsterDef" type="Label" parent="Content"] +margin_left = 288.0 +margin_top = 40.0 +margin_right = 324.0 +margin_bottom = 57.0 +custom_fonts/font = SubResource( 2 ) +text = "防御力" +valign = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="DefValue" type="Label" parent="Content/MonsterDef"] +anchor_top = 0.5 +anchor_bottom = 0.5 +margin_left = 48.0 +margin_top = -8.5 +margin_right = 111.0 +margin_bottom = 8.5 +custom_fonts/font = SubResource( 2 ) +text = "1" +valign = 1 +clip_text = true +__meta__ = { +"_edit_use_anchors_": false +}