1
0
mirror of https://gitee.com/freeyz/godot-mota.git synced 2024-12-22 19:59:20 +08:00

增加怪物图鉴

This commit is contained in:
freewu32 2020-09-03 22:30:49 +08:00
parent cf3835f53f
commit 2501cb81b8
7 changed files with 241 additions and 11 deletions

View File

@ -21,6 +21,8 @@ func connect_player_properties_update():
func connect_button(): func connect_button():
$"/root/Main/HUD/BottomBackground/VBoxContainer/SaveButton".connect("pressed",self,"on_save_button_clicked") $"/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/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(): func connect_level_update():
get_level_manager().connect("level_changed",self,"on_level_changed") get_level_manager().connect("level_changed",self,"on_level_changed")
@ -60,6 +62,12 @@ func on_save_button_clicked():
func on_load_button_clicked(): func on_load_button_clicked():
get_level_manager().load_persistent(0) 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: func get_hud() -> Hud:
return $HUD as Hud return $HUD as Hud

View File

@ -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://src/levels/Level1.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/sounds/bgm.ogg" type="AudioStream" id=5] [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 ) atlas = SubResource( 6 )
region = Rect2( 0, 544, 32, 32 ) 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"] [node name="Main" type="Node2D"]
script = ExtResource( 12 ) script = ExtResource( 12 )
@ -416,27 +426,35 @@ anchor_top = 0.5
anchor_right = 0.5 anchor_right = 0.5
anchor_bottom = 0.5 anchor_bottom = 0.5
margin_left = -208.0 margin_left = -208.0
margin_top = -208.0 margin_top = -200.0
margin_right = 206.0 margin_right = 232.0
margin_bottom = 208.0 margin_bottom = 152.0
scroll_horizontal_enabled = false
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="VBoxContainer" type="VBoxContainer" parent="HUD/BookDialog/ScrollContainer"] [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_left = 1.0
anchor_top = 1.0 anchor_top = 1.0
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
margin_left = -77.9 margin_left = -103.0
margin_top = -32.0 margin_top = -49.1
margin_right = -13.9 margin_right = -15.0
margin_bottom = -10.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 ) custom_fonts/font = ExtResource( 8 )
text = "返回游戏" text = "返回游戏"
valign = 1
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }

View File

@ -31,3 +31,9 @@ func get_save_button_view() -> TextureButton:
func get_load_button_view() -> TextureButton: func get_load_button_view() -> TextureButton:
return $"BottomBackground/VBoxContainer/Loadutton" as 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

View File

@ -9,6 +9,7 @@ var monster_sprite : AnimatedSprite
func _ready(): func _ready():
monster_sprite = get_parent() monster_sprite = get_parent()
monster_info = MonsterBook.get_info_by_name(monster_sprite.animation) monster_info = MonsterBook.get_info_by_name(monster_sprite.animation)
add_to_group("monster")
# 玩家触碰回调 # 玩家触碰回调
func on_player_touched(player): func on_player_touched(player):

View File

@ -20,9 +20,12 @@ animations = [ {
"speed": 20.0 "speed": 20.0
} ] } ]
[node name="MonsterSprite" type="AnimatedSprite"] [node name="MonsterSprite" type="AnimatedSprite" groups=[
"monster",
]]
frames = ExtResource( 8 ) frames = ExtResource( 8 )
animation = "greenSlime" animation = "greenSlime"
frame = 1
playing = true playing = true
[node name="Monster" type="StaticBody2D" parent="."] [node name="Monster" type="StaticBody2D" parent="."]

View File

@ -22,3 +22,33 @@ func get_monsters_name() -> Array:
# 根据怪物名称获取怪物信息 # 根据怪物名称获取怪物信息
func get_info_by_name(name:String) -> Dictionary: func get_info_by_name(name:String) -> Dictionary:
return monster_data[name] 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()

View File

@ -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
}