From 776e538ab09e936236ae8266fc48ad9b71b0b808 Mon Sep 17 00:00:00 2001 From: TsubakiLoL <2789646812@qq.com> Date: Mon, 30 Sep 2024 18:06:45 +0800 Subject: [PATCH] =?UTF-8?q?9.30=E4=B8=8B=E5=8D=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- autoload/global/script/global.gd | 58 ++++++++++++++++- class/character_tool/character_tool.gd | 39 +++++++++++- json/event.json | 30 ++++++++- json/item.json | 13 ++++ json/scene.json | 4 ++ json/script.json | 88 ++++++++++++++++---------- scene/basic_message.gd | 61 ++++++++++++++++-- scene/basic_message.tscn | 4 +- scene/game_flow.gd | 7 ++ scene/game_flow.tscn | 5 +- scene/skill_config_card_down.gd | 19 ++++-- scene/skill_config_card_down.tscn | 28 +++++--- scene/skill_config_card_up.gd | 18 ++++-- scene/skill_config_card_up.tscn | 13 +++- 14 files changed, 313 insertions(+), 74 deletions(-) diff --git a/autoload/global/script/global.gd b/autoload/global/script/global.gd index 55e06c2..569f62d 100644 --- a/autoload/global/script/global.gd +++ b/autoload/global/script/global.gd @@ -178,7 +178,18 @@ func get_all_equip_index_and_data_in_bag()->Array: data_arr.append(item[i]) res=[ind_arr,data_arr] return res - +#返回一个长度为2的数组,第一个数组存储的item中技能的index,另一个是对应的item_data +func get_all_skill_index_and_data_in_bag()->Array: + var item:Array=now_game_data["item"].duplicate(true) + var res:Array=[] + var ind_arr:Array=[] + var data_arr:Array=[] + for i in item.size(): + if is_item_a_skill(item[i]): + ind_arr.append(i) + data_arr.append(item[i]) + res=[ind_arr,data_arr] + return res #判断item是否为一个装备(暂时将武器除外) func is_item_a_equip(item_data:Dictionary)->bool: @@ -189,6 +200,17 @@ func is_item_a_equip(item_data:Dictionary)->bool: return true else: return false + +#判断item是否为一个技能 +func is_item_a_skill(item_data:Dictionary): + if not item_data.has("type"): + return false + var type:int=item_data["type"] + if type ==6: + return true + else: + return false + #改变当前角色使用的装备页 func change_character_equip_now_use(page:int): print(page) @@ -196,7 +218,23 @@ func change_character_equip_now_use(page:int): #获取当前使用装备页数 func get_character_page_now_use()->int: return CharacterTool.get_character_equip_now_use_page(now_game_data["character_data"]) - +#将角色第ind个技能卡移除,放入背包 +func remove_skill_card_ind_to_bag(ind:int): + var now_character_data:Dictionary=now_game_data["character_data"] + var left=CharacterTool.remove_skill_index(now_character_data,ind) + if left!=null: + add_item_to_bag(left) +#将背包中序列为ind的技能卡装备到角色 +func add_sill_card_from_bag_to_character(ind:int): + var item_data=now_game_data["item"][ind] + if is_item_a_skill(item_data): + var res=CharacterTool.add_skill_card(now_game_data["character_data"],item_data) + if res: + decrease_item_num_index(ind) +#获取当前角色的所有技能 +func get_now_character_skill(): + var character_data=now_game_data["character_data"] + return CharacterTool.get_character_skill_all(character_data) ##当前数据 var now_game_data:Dictionary={ "character_data":{ @@ -231,6 +269,19 @@ func delete_card(card_id:String)->bool: else: now_game_data["card_in_bag"].pop_at(ind) return true + + +var now_fight_enermy_data:Array=[] +var now_fight_friend_data:Array=[] +func fight(data:Dictionary): + if data.has("friend"): + now_fight_friend_data=data["friend"] + now_fight_enermy_data + SceneManager.change_scene_to("res://scene/fight.tscn") + pass + + + #使用卡牌,character为使用者,target为目标,card_data为使用的卡牌数据 func use_card(card_data:Dictionary,user=null,target=null): print("执行了卡牌:\n"+str(card_data)+"\n目标"+str(target)) @@ -295,7 +346,8 @@ var triger:Dictionary={ "change_choice":func(data):now_game_flow.event_panel.change_choice(data), "increase_health":func (data):now_game_data.health-=data, "end_event":func(data):now_game_flow.event_panel.hide(), - "flow_time":func (data):flow_time(data) + "flow_time":func (data):flow_time(data), + "fight":func (data):fight(data) } #使用事件触发器 func call_triger(triger_type:String,data): diff --git a/class/character_tool/character_tool.gd b/class/character_tool/character_tool.gd index 5eb7fae..cc40950 100644 --- a/class/character_tool/character_tool.gd +++ b/class/character_tool/character_tool.gd @@ -119,7 +119,7 @@ static func get_name_by_attribute_key(key:String)->String: #对角色json加载后进行预处理 static func pre_process_character_data(character_data:Dictionary)->Dictionary: var res:Dictionary=character_data.duplicate(true) - #添加三页装备为null + #_添加三页装备为null #每页顺序默认是饰品1,饰品2,饰品3,饰品4,手部1,手部2,头部,身体 #共八个 res["equip"]=[ @@ -128,7 +128,9 @@ static func pre_process_character_data(character_data:Dictionary)->Dictionary: [null,null,null,null,null,null,null,null,] ] res["now_use_equip"]=0 + #技能 res["skill"]=[] + #道具 res["prop"]=[] return res @@ -155,3 +157,38 @@ static func change_character_equip_now_use(character_data:Dictionary,page:int): #获取角色当前使用的装备页数 static func get_character_equip_now_use_page(character_data:Dictionary)->int: return int(character_data["now_use_equip"]) + +#移除第ind个技能卡,返回被移除的技能卡数据 +static func remove_skill_index(character_data:Dictionary,ind:int): + var data + if character_data.has("skill"): + var skill_arr=character_data["skill"] + if skill_arr is Array and skill_arr.size()>ind: + data=skill_arr[ind] + skill_arr.pop_at(ind) + return data +#根据id移除技能卡(仅仅移除第一个) +static func remove_skill_id(character_data:Dictionary,id:String): + var data + if character_data.has("skill"): + var skill_arr=character_data["skill"] + if skill_arr is Array: + for i in skill_arr.size(): + if skill_arr[i]["id"]==id: + data=skill_arr[i].duplicate(true) + skill_arr.pop_at(i) + break + return data +#向角色添加技能卡(bool为添加成功与否的标志,如果以后角色需要限制技能卡装备数量上限更改此处) +static func add_skill_card(character_data:Dictionary,skill_data:Dictionary)->bool: + if character_data.has("skill"): + var skill_arr=character_data["skill"] + skill_arr.append(skill_data.duplicate(true)) + return true + else: + return false +#获取角色的技能序列 +static func get_character_skill_all(character_data:Dictionary): + if character_data.has("skill"): + var skill_arr:Array=character_data["skill"] + return skill_arr.duplicate(true) diff --git a/json/event.json b/json/event.json index f9b92e0..46c1867 100644 --- a/json/event.json +++ b/json/event.json @@ -36,7 +36,7 @@ "data":"test_character" } ] - }, + }, { "name":"改变描述文本", "triger":[{ @@ -62,5 +62,31 @@ ] } ] - } + }, + "event_03":{ + "name":"测试事件3", + "texture":"test_scene", + "text":"这是一个测试战斗的事件", + "choice":[ + { + "name":"战斗", + "triger":[{ + "type":"fight", + "data":{ + "enermy":["test_character_01"], + "friend":[] + } + } + ] + }, + { + "name":"结束", + "triger":[{ + "type":"end_event", + "data":"" + }, + ] + } + ] + }, } diff --git a/json/item.json b/json/item.json index b7cb902..cf98a67 100644 --- a/json/item.json +++ b/json/item.json @@ -71,6 +71,19 @@ "price":100, "quality":0, "name":"绷带", + "introduction":"用于测试的道具,并没有什么用", + "material":{ + + } + }, + "item_07":{ + "type":6, + "allow_merge":false, + "price":100, + "quality":0, + "name":"测试技能", + "texture":"knife", + "introduction":"用于测试的技能,并没有什么用", "material":{ } diff --git a/json/scene.json b/json/scene.json index 5a62388..6734e8f 100644 --- a/json/scene.json +++ b/json/scene.json @@ -11,6 +11,10 @@ { "name":"测试场景事件", "event":"event_02" + }, + { + "name":"战斗测试", + "event":"event_03" } ], "linked_scene":[{ diff --git a/json/script.json b/json/script.json index df18ee9..027fb33 100644 --- a/json/script.json +++ b/json/script.json @@ -20,19 +20,41 @@ }, "script_002":{ - "name":"测试剧本002", - "texture":"texture_test", - "side_texture":"test_scene", + "name":"测试剧本001", + "texture":"test_scene", + "side_texture":"texture_test", "introduction":"这是一个测试剧本", - "type":0 + "type":0, + "init_date":{ + "year":1860, + "month":1, + "day":1, + }, + "finish_date":{ + "year":1860, + "month":2, + "day":1, + }, + "init_scene":"scene_01", }, "script_003":{ - "name":"测试剧本003", - "texture":"texture_test", - "side_texture":"test_scene", + "name":"测试剧本001", + "texture":"test_scene", + "side_texture":"texture_test", "introduction":"这是一个测试剧本", - "type":1 + "type":0, + "init_date":{ + "year":1860, + "month":1, + "day":1, + }, + "finish_date":{ + "year":1860, + "month":2, + "day":1, + }, + "init_scene":"scene_01", }, "script_004":{ @@ -40,31 +62,18 @@ "texture":"test_scene", "side_texture":"texture_test", "introduction":"这是一个测试剧本", - "type":1 - }, - "script_005":{ - - "name":"测试剧本001", - "texture":"texture_test", - "side_texture":"test_scene", - "introduction":"这是一个测试剧本", - "type":2 - }, - "script_006":{ - - "name":"测试剧本001", - "texture":"test_scene", - "side_texture":"texture_test", - "introduction":"这是一个测试剧本", - "type":2 - }, - "script_007":{ - - "name":"测试剧本001", - "texture":"texture_test", - "side_texture":"test_scene", - "introduction":"这是一个测试剧本", - "type":3 + "type":0, + "init_date":{ + "year":1860, + "month":1, + "day":1, + }, + "finish_date":{ + "year":1860, + "month":2, + "day":1, + }, + "init_scene":"scene_01", }, "script_008":{ @@ -72,7 +81,18 @@ "texture":"test_scene", "side_texture":"texture_test", "introduction":"这是一个测试剧本", - "type":3 + "type":0, + "init_date":{ + "year":1860, + "month":1, + "day":1, + }, + "finish_date":{ + "year":1860, + "month":2, + "day":1, + }, + "init_scene":"scene_01", }, } diff --git a/scene/basic_message.gd b/scene/basic_message.gd index 5fb19b2..df52099 100644 --- a/scene/basic_message.gd +++ b/scene/basic_message.gd @@ -5,6 +5,11 @@ const SELECTED = preload("res://res/ui/ui_005_basic_message/selected.tres") const BASIC_MES_SKIN_CARD = preload("res://scene/basic_mes_skin_card.tscn") const START_CONFIG_MES = preload("res://scene/start_config_mes.tscn") const BAG_SIDE_CARD = preload("res://scene/bag_side_card.tscn") + +const SKILL_CONFIG_CARD_DOWN = preload("res://scene/skill_config_card_down.tscn") +const SKILL_CONFIG_CARD_UP = preload("res://scene/skill_config_card_up.tscn") + + var data:Dictionary ##当前是在游戏外编辑还是在游戏内编辑 @export var is_in_game:bool=false @@ -158,9 +163,43 @@ func init_from_data(): for i in equipment_group.size(): equipment_group[i].page=now_character_use_equip_page equipment_group[i].set_data(now_use_equip_data_arr[i]) + #技能配置 + if is_in_game: + for i in %skill_config_card_up_add_pos.get_children(): + i.queue_free() + for i in %skill_config_card_down_add_pos.get_children(): + i.queue_free() + var character_skill:Array=Global.get_now_character_skill() + var bag=Global.get_all_skill_index_and_data_in_bag() + var bag_index:Array=bag[0] + var bag_skill_data:Array=bag[1] + for i in character_skill.size(): + var new_card=SKILL_CONFIG_CARD_UP.instantiate() + %skill_config_card_up_add_pos.add_child(new_card) + new_card.click.connect(card_up_click.bind(i)) + new_card.set_data(character_skill[i]) + for i in bag_skill_data.size(): + var new_card=SKILL_CONFIG_CARD_DOWN.instantiate() + %skill_config_card_down_add_pos.add_child(new_card) + new_card.click.connect(card_down_click.bind(bag_index[i])) + new_card.set_data(bag_skill_data[i]) + pass pass - +#角色装备技能被点击触发 +func card_up_click(ind:int): + + Global.remove_skill_card_ind_to_bag(ind) + fresh() + pass +#背包技能被点击触发 +func card_down_click(ind:int): + Global.add_sill_card_from_bag_to_character(ind) + + + fresh() + pass +#开局按钮被点击触发 func start_config_mes_click(mes:StartConfigMes,ind:int): now_selected_mes.state=0 mes.state=1 @@ -204,7 +243,6 @@ func selected(ind:int): func _ready() -> void: - #Global.set_now_character("test_character_01") ##向背包中添加物品 #Global.add_item_to_bag(Global.get_item_data("item_01")) #Global.add_item_to_bag(Global.get_item_data("item_02")) @@ -231,19 +269,32 @@ func _ready() -> void: #Global.add_item_to_bag(Global.get_item_data("item_03")) #Global.add_item_to_bag(Global.get_item_data("item_04")) #Global.add_item_to_bag(Global.get_item_data("item_05")) + Global.add_item_to_bag(Global.get_item_data("item_07")) + Global.add_item_to_bag(Global.get_item_data("item_07")) + Global.add_item_to_bag(Global.get_item_data("item_07")) + Global.add_item_to_bag(Global.get_item_data("item_07")) + Global.add_item_to_bag(Global.get_item_data("item_07")) + Global.add_item_to_bag(Global.get_item_data("item_07")) + if is_in_game: $VBoxContainer/TextureRect/HBoxContainer/Button6.hide() $VBoxContainer/TextureRect/HBoxContainer/Button4.show() + $VBoxContainer/TextureRect/HBoxContainer/Button5.show() else: $VBoxContainer/TextureRect/HBoxContainer/Button6.show() $VBoxContainer/TextureRect/HBoxContainer/Button4.hide() + $VBoxContainer/TextureRect/HBoxContainer/Button5.hide() pass - #data=Global.get_character_data("test_character_01") - for i in equipment_group: i.fresh.connect(fresh) - #init_from_data() + + Global.set_now_character("test_character_01") + data=Global.get_now_character_data() + init_from_data() connect_button() + + + func _on_back_button_pressed() -> void: diff --git a/scene/basic_message.tscn b/scene/basic_message.tscn index f22af0d..d3812dc 100644 --- a/scene/basic_message.tscn +++ b/scene/basic_message.tscn @@ -346,12 +346,11 @@ layout_mode = 2 size_flags_vertical = 3 size_flags_stretch_ratio = 939.0 theme_override_styles/panel = SubResource("StyleBoxEmpty_81i7t") -current_tab = 4 +current_tab = 0 clip_tabs = false tabs_visible = false [node name="basic_mes" type="MarginContainer" parent="VBoxContainer/TabContainer"] -visible = false layout_mode = 2 theme_override_constants/margin_right = 19 theme_override_constants/margin_bottom = 43 @@ -1919,6 +1918,7 @@ texture = NodePath("../TextureRect") metadata/_edit_use_anchors_ = true [node name="skill_config" type="MarginContainer" parent="VBoxContainer/TabContainer"] +visible = false layout_mode = 2 theme_override_constants/margin_left = 54 theme_override_constants/margin_top = 8 diff --git a/scene/game_flow.gd b/scene/game_flow.gd index ce26e73..ccf3050 100644 --- a/scene/game_flow.gd +++ b/scene/game_flow.gd @@ -98,3 +98,10 @@ func _on_map_pressed() -> void: map.show() pass # Replace with function body. + + +func _on_head_btn_pressed() -> void: + %basic_mes.data=Global.get_now_character_data() + %basic_mes.init_from_data() + %basic_mes.show() + pass # Replace with function body. diff --git a/scene/game_flow.tscn b/scene/game_flow.tscn index 186e383..19a0559 100644 --- a/scene/game_flow.tscn +++ b/scene/game_flow.tscn @@ -175,7 +175,7 @@ texture = ExtResource("7_xk2ne") expand_mode = 1 stretch_mode = 5 -[node name="ToolButton" parent="hbox/TextureRect" instance=ExtResource("8_q6ple")] +[node name="head_btn" parent="hbox/TextureRect" instance=ExtResource("8_q6ple")] layout_mode = 1 [node name="TextureRect2" type="TextureRect" parent="hbox"] @@ -439,7 +439,10 @@ visible = false layout_mode = 1 [node name="basic_mes" parent="." instance=ExtResource("19_xvka5")] +unique_name_in_owner = true visible = false layout_mode = 1 +is_in_game = true +[connection signal="pressed" from="hbox/TextureRect/head_btn" to="." method="_on_head_btn_pressed"] [connection signal="pressed" from="HBoxContainer/TextureRect3/map" to="." method="_on_map_pressed"] diff --git a/scene/skill_config_card_down.gd b/scene/skill_config_card_down.gd index 3dbf848..9c36a6f 100644 --- a/scene/skill_config_card_down.gd +++ b/scene/skill_config_card_down.gd @@ -1,11 +1,16 @@ extends TextureRect +signal click -# Called when the node enters the scene tree for the first time. -func _ready() -> void: +var data:Dictionary + +func set_data(_data:Dictionary): + + data=_data + %face.texture=Global.get_texture(data["texture"]) + %name.text=data["name"] + %introduction.text=data["introduction"] + +func _on_tool_button_pressed() -> void: + click.emit() pass # Replace with function body. - - -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta: float) -> void: - pass diff --git a/scene/skill_config_card_down.tscn b/scene/skill_config_card_down.tscn index 3f847ea..d1335a3 100644 --- a/scene/skill_config_card_down.tscn +++ b/scene/skill_config_card_down.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=5 format=3 uid="uid://bui33cht0ni46"] +[gd_scene load_steps=6 format=3 uid="uid://bui33cht0ni46"] [ext_resource type="Texture2D" uid="uid://c7ayf2vovekm6" path="res://res/ui/ui_009_skill_config/juxing522.png" id="1_nuikj"] [ext_resource type="Texture2D" uid="uid://dua40uesoxqlb" path="res://res/ui/ui_009_skill_config/tuceng299.png" id="2_n1i8g"] [ext_resource type="Script" path="res://scene/skill_config_card_down.gd" id="2_y5jpa"] [ext_resource type="Texture2D" uid="uid://li8e5ntlgcpg" path="res://res/ui/ui_003_select/test.png" id="3_2p0oi"] +[ext_resource type="PackedScene" uid="uid://bdlo2wn4qnygv" path="res://scene/tool/tool_button.tscn" id="5_q5g5g"] [node name="skill_config_card_down" type="TextureRect"] custom_minimum_size = Vector2(252, 336) @@ -30,7 +31,8 @@ texture = ExtResource("2_n1i8g") expand_mode = 1 stretch_mode = 5 -[node name="TextureRect" type="TextureRect" parent="TextureRect"] +[node name="face" type="TextureRect" parent="TextureRect"] +unique_name_in_owner = true layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 @@ -39,9 +41,10 @@ grow_horizontal = 2 grow_vertical = 2 texture = ExtResource("3_2p0oi") expand_mode = 1 -stretch_mode = 6 +stretch_mode = 5 -[node name="Label" type="Label" parent="."] +[node name="name" type="Label" parent="."] +unique_name_in_owner = true layout_mode = 0 anchor_left = 0.130952 anchor_top = 0.107143 @@ -56,14 +59,21 @@ horizontal_alignment = 1 vertical_alignment = 1 metadata/_edit_use_anchors_ = true -[node name="Label2" type="Label" parent="."] +[node name="introduction" type="Label" parent="."] +unique_name_in_owner = true layout_mode = 0 -offset_left = 10.0 -offset_top = 86.0 -offset_right = 243.0 -offset_bottom = 298.0 +anchor_left = 0.0396825 +anchor_top = 0.255952 +anchor_right = 0.964286 +anchor_bottom = 0.886905 theme_override_colors/font_color = Color(1, 1, 1, 1) theme_override_colors/font_shadow_color = Color(0, 0, 0, 1) theme_override_font_sizes/font_size = 21 text = "技能介绍技能介绍技能介绍技能介绍技能介绍技能介绍技能介绍技能介绍技能介绍技能介绍技能介绍技能介绍技能介绍技能介绍" autowrap_mode = 3 +metadata/_edit_use_anchors_ = true + +[node name="ToolButton" parent="." instance=ExtResource("5_q5g5g")] +layout_mode = 1 + +[connection signal="pressed" from="ToolButton" to="." method="_on_tool_button_pressed"] diff --git a/scene/skill_config_card_up.gd b/scene/skill_config_card_up.gd index 3dbf848..3100294 100644 --- a/scene/skill_config_card_up.gd +++ b/scene/skill_config_card_up.gd @@ -1,11 +1,15 @@ extends TextureRect +signal click -# Called when the node enters the scene tree for the first time. -func _ready() -> void: +var data:Dictionary + +func set_data(_data:Dictionary): + + data=_data + %face.texture=Global.get_texture(data["texture"]) + + +func _on_tool_button_pressed() -> void: + click.emit() pass # Replace with function body. - - -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta: float) -> void: - pass diff --git a/scene/skill_config_card_up.tscn b/scene/skill_config_card_up.tscn index 3216699..b499b5e 100644 --- a/scene/skill_config_card_up.tscn +++ b/scene/skill_config_card_up.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=5 format=3 uid="uid://cg3ahgbl85d65"] +[gd_scene load_steps=6 format=3 uid="uid://cg3ahgbl85d65"] [ext_resource type="Texture2D" uid="uid://c7ayf2vovekm6" path="res://res/ui/ui_009_skill_config/juxing522.png" id="1_egy6w"] [ext_resource type="Script" path="res://scene/skill_config_card_up.gd" id="2_usnbp"] [ext_resource type="Texture2D" uid="uid://dua40uesoxqlb" path="res://res/ui/ui_009_skill_config/tuceng299.png" id="2_ykdl0"] [ext_resource type="Texture2D" uid="uid://li8e5ntlgcpg" path="res://res/ui/ui_003_select/test.png" id="3_6l4j1"] +[ext_resource type="PackedScene" uid="uid://bdlo2wn4qnygv" path="res://scene/tool/tool_button.tscn" id="5_jq85w"] [node name="skill_config_card_up" type="TextureRect"] custom_minimum_size = Vector2(178, 238) @@ -30,7 +31,8 @@ texture = ExtResource("2_ykdl0") expand_mode = 1 stretch_mode = 5 -[node name="TextureRect" type="TextureRect" parent="TextureRect"] +[node name="face" type="TextureRect" parent="TextureRect"] +unique_name_in_owner = true layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 @@ -39,4 +41,9 @@ grow_horizontal = 2 grow_vertical = 2 texture = ExtResource("3_6l4j1") expand_mode = 1 -stretch_mode = 6 +stretch_mode = 5 + +[node name="ToolButton" parent="." instance=ExtResource("5_jq85w")] +layout_mode = 1 + +[connection signal="pressed" from="ToolButton" to="." method="_on_tool_button_pressed"]