From 15663f6147c0810cc69ec8286ef67e7589928c16 Mon Sep 17 00:00:00 2001 From: TsubakiLoL <2789646812@qq.com> Date: Fri, 1 Nov 2024 23:23:07 +0800 Subject: [PATCH] add --- autoload/database/database.gd | 39 +++++++++- autoload/global/global.gd | 3 + json/item.json | 12 +++ scene/class/door.gd | 21 +++++- scene/class/e_interaction_item.gd | 22 ++++++ scene/class/item_class.gd | 48 ++++++++++++ scene/map/map_test_0.tscn | 22 ++---- scene/map/map_test_1.tscn | 19 +---- scene/test/atk.gd | 1 + scene/test/character.gd | 3 + scene/test/character.tscn | 18 +---- scene/test/other_character.tscn | 2 +- scene/test/run.gd | 1 - scene/test/self_character.gd | 23 ++++-- scene/test/test_door.tscn | 18 +++++ scene/test/test_main.gd | 71 +++++++++++++++--- scene/test/test_main.tscn | 9 ++- scene/tool_button/tool_button.gd | 21 ++++++ scene/tool_button/tool_button.tscn | 18 +++++ scene/trade_interaction_item/trade.gd | 15 ++++ scene/trade_interaction_item/trade.tscn | 25 +++++++ scene/trader_board/trade_item_card.gd | 15 ++++ scene/trader_board/trade_item_card.tscn | 99 +++++++++++++++++++++++++ scene/trader_board/trader_board.gd | 28 +++++++ scene/trader_board/trader_board.tscn | 76 +++++++++++++++++++ tool/state_machine/state.gd | 2 +- 26 files changed, 563 insertions(+), 68 deletions(-) create mode 100644 json/item.json create mode 100644 scene/class/e_interaction_item.gd create mode 100644 scene/class/item_class.gd create mode 100644 scene/test/test_door.tscn create mode 100644 scene/tool_button/tool_button.gd create mode 100644 scene/tool_button/tool_button.tscn create mode 100644 scene/trade_interaction_item/trade.gd create mode 100644 scene/trade_interaction_item/trade.tscn create mode 100644 scene/trader_board/trade_item_card.gd create mode 100644 scene/trader_board/trade_item_card.tscn create mode 100644 scene/trader_board/trader_board.gd create mode 100644 scene/trader_board/trader_board.tscn diff --git a/autoload/database/database.gd b/autoload/database/database.gd index c291160..2305136 100644 --- a/autoload/database/database.gd +++ b/autoload/database/database.gd @@ -1,5 +1,9 @@ extends Node + + + + #不同族群单位之间的初始好感度 #下面意思为测试族群1对2具有初始负面好感 #相反2对1具有正面好感 @@ -58,7 +62,8 @@ static var other_unit_data={ "hp":100, "atk":10, - "position":[0,0] + "position":[0,0], + "bag":[] } @@ -83,3 +88,35 @@ func get_map_data(id:String): return map_data[id] else: return null + + +#获取预先添加的物品默认数据 +static var pre_item_add_data:Dictionary={"num":1}: + get(): + return pre_item_add_data.duplicate(true) +#预处理物品数据 +static func pre_process_item_data(origin_data:Dictionary): + var new_res=origin_data + var pre_item_data=pre_item_add_data + #如数据中没有默认数据则填入默认数据 + for i in new_res.keys(): + for j in pre_item_data.keys(): + if not new_res[i].has(j): + new_res[i][j]=new_res[j] + return new_res + +#物品数据 + +@export var item_data:Dictionary=preload("res://json/item.json").data + + +#获取- 新 -的物品单例,默认数量为1 +func get_item(id:String,num:int=1)->BagItem: + + if item_data.has(id): + var itd=item_data[id] + itd["num"]=num + return BagItem.new(itd) + + else: + return BagItem.new({}) diff --git a/autoload/global/global.gd b/autoload/global/global.gd index a45cbe5..86e22c9 100644 --- a/autoload/global/global.gd +++ b/autoload/global/global.gd @@ -1,4 +1,7 @@ extends Node + +var main_scene:MainScene + #保存ID对应角色实例的字典 var unit_instance_dic:Dictionary={ diff --git a/json/item.json b/json/item.json new file mode 100644 index 0000000..475a7fe --- /dev/null +++ b/json/item.json @@ -0,0 +1,12 @@ +{ + + + "item_test_01":{ + "name":"测试物品1", + "introduction":"测试物品1的介绍" + }, + "item_test_02":{ + "name":"测试物品2", + "introduction":"测试物品2的介绍" + } +} diff --git a/scene/class/door.gd b/scene/class/door.gd index bc166fe..88b8d91 100644 --- a/scene/class/door.gd +++ b/scene/class/door.gd @@ -1,7 +1,24 @@ -extends Area2D +extends EInteractionItem class_name Door @export var map_id:String - @export var map_born_pos:int=0 + +func E_pressed(): + if Global.main_scene!=null and is_instance_valid(Global.main_scene): + Global.main_scene.change_map(map_id,map_born_pos) + + + pass + +func _on_highlight(): + $Sprite2D2.modulate=Color.GREEN + + pass + +func _exit_highlight(): + $Sprite2D2.modulate=Color.WHITE + + + pass diff --git a/scene/class/e_interaction_item.gd b/scene/class/e_interaction_item.gd new file mode 100644 index 0000000..e2c7b50 --- /dev/null +++ b/scene/class/e_interaction_item.gd @@ -0,0 +1,22 @@ +extends Area2D +##地图中使用E键进行交互的基类 +class_name EInteractionItem + + + +##交互使用的函数 +func E_pressed(): + + + pass +##高光反应抽象函数 +func _on_highlight(): + + + pass + +##去除高光抽象函数 +func _exit_highlight(): + + + pass diff --git a/scene/class/item_class.gd b/scene/class/item_class.gd new file mode 100644 index 0000000..9e33759 --- /dev/null +++ b/scene/class/item_class.gd @@ -0,0 +1,48 @@ +class_name BagItem +#物品数据 +var data:Dictionary={ + +} +##物品名字 +var item_name:String: + set(val): + data["name"]=val + item_name=val + get(): + if data.has("name"): + return str(data["name"]) + else: + return "无效数据" +##物品类型 +var item_type:int: + set(val): + data["type"]=val + item_type=val + get(): + if data.has("type"): + return int(data["type"]) + else: + return -1 +##物品介绍 +var item_introduction:String: + set(val): + data["introduction"]=val + item_introduction=val + get(): + if data.has("introduction"): + return str(data["introduction"]) + else: + return "无数据" +#数量 +var num:int: + set(val): + data["num"]=val + num=val + get(): + if data.has("num"): + return int(data["num"]) + else: + return -1 + +func _init(item_data:Dictionary) -> void: + self.data=item_data diff --git a/scene/map/map_test_0.tscn b/scene/map/map_test_0.tscn index d4f1dd6..4dfe41f 100644 --- a/scene/map/map_test_0.tscn +++ b/scene/map/map_test_0.tscn @@ -1,10 +1,10 @@ -[gd_scene load_steps=11 format=4 uid="uid://bt05onvfl6ael"] +[gd_scene load_steps=10 format=4 uid="uid://bt05onvfl6ael"] [ext_resource type="Script" path="res://scene/map/map_test_0.gd" id="1_mkv6t"] [ext_resource type="Texture2D" uid="uid://dxtu12mw7fsq8" path="res://res/image/test/tile.png" id="2_k3cp7"] [ext_resource type="PackedScene" uid="uid://b6jyxox72yxjc" path="res://scene/mark/character_marker_2d.tscn" id="3_v1al5"] -[ext_resource type="Script" path="res://scene/class/door.gd" id="4_61dsd"] -[ext_resource type="Texture2D" uid="uid://csk8u15wepd1w" path="res://icon.svg" id="5_b01gw"] +[ext_resource type="PackedScene" uid="uid://dbs4jk1ljeq1o" path="res://scene/test/test_door.tscn" id="4_gs5kc"] +[ext_resource type="PackedScene" uid="uid://2wkc3dlcfrnj" path="res://scene/trade_interaction_item/trade.tscn" id="6_fl6uv"] [ext_resource type="Script" path="res://scene/class/born_mark.gd" id="6_qu6gr"] [sub_resource type="NavigationPolygon" id="NavigationPolygon_tjudi"] @@ -27,9 +27,6 @@ physics_layer_0/collision_layer = 1 navigation_layer_0/layers = 1 sources/0 = SubResource("TileSetAtlasSource_j4j8n") -[sub_resource type="CircleShape2D" id="CircleShape2D_1hdps"] -radius = 76.99 - [node name="map_test_0" type="Node2D" node_paths=PackedStringArray("map_born_mark")] script = ExtResource("1_mkv6t") map_born_mark = [NodePath("BornMark")] @@ -57,17 +54,12 @@ position = Vector2(359, -417) unit_id = "test3" unit_data_from_id = "test_character_base" -[node name="Door" type="Area2D" parent="."] -position = Vector2(1079, 609) -script = ExtResource("4_61dsd") +[node name="test_door" parent="." instance=ExtResource("4_gs5kc")] map_id = "map_1" -[node name="Sprite2D" type="Sprite2D" parent="Door"] -texture = ExtResource("5_b01gw") - -[node name="CollisionShape2D" type="CollisionShape2D" parent="Door"] -shape = SubResource("CircleShape2D_1hdps") - [node name="BornMark" type="Marker2D" parent="."] position = Vector2(-1043, -488) script = ExtResource("6_qu6gr") + +[node name="Trade" parent="." instance=ExtResource("6_fl6uv")] +position = Vector2(943, 339) diff --git a/scene/map/map_test_1.tscn b/scene/map/map_test_1.tscn index 19e2230..f65b5f2 100644 --- a/scene/map/map_test_1.tscn +++ b/scene/map/map_test_1.tscn @@ -1,10 +1,9 @@ -[gd_scene load_steps=11 format=4 uid="uid://cgbmwgp5kxn43"] +[gd_scene load_steps=9 format=4 uid="uid://cgbmwgp5kxn43"] [ext_resource type="Script" path="res://scene/map/map_test_0.gd" id="1_476af"] [ext_resource type="Texture2D" uid="uid://dxtu12mw7fsq8" path="res://res/image/test/tile.png" id="2_3qa44"] [ext_resource type="PackedScene" uid="uid://b6jyxox72yxjc" path="res://scene/mark/character_marker_2d.tscn" id="3_yk4q8"] -[ext_resource type="Script" path="res://scene/class/door.gd" id="4_fof6u"] -[ext_resource type="Texture2D" uid="uid://csk8u15wepd1w" path="res://icon.svg" id="5_cp4uj"] +[ext_resource type="PackedScene" uid="uid://dbs4jk1ljeq1o" path="res://scene/test/test_door.tscn" id="4_tyh53"] [ext_resource type="Script" path="res://scene/class/born_mark.gd" id="6_jfam2"] [sub_resource type="NavigationPolygon" id="NavigationPolygon_tjudi"] @@ -27,9 +26,6 @@ physics_layer_0/collision_layer = 1 navigation_layer_0/layers = 1 sources/0 = SubResource("TileSetAtlasSource_j4j8n") -[sub_resource type="CircleShape2D" id="CircleShape2D_jekr0"] -radius = 76.99 - [node name="map_test_1" type="Node2D" node_paths=PackedStringArray("map_born_mark")] script = ExtResource("1_476af") map_born_mark = [NodePath("BornMark")] @@ -52,16 +48,7 @@ position = Vector2(842, 32) unit_id = "test2" unit_data_from_id = "test_character_base" -[node name="Door" type="Area2D" parent="."] -position = Vector2(1079, 609) -script = ExtResource("4_fof6u") -map_id = "map_0" - -[node name="Sprite2D" type="Sprite2D" parent="Door"] -texture = ExtResource("5_cp4uj") - -[node name="CollisionShape2D" type="CollisionShape2D" parent="Door"] -shape = SubResource("CircleShape2D_jekr0") +[node name="test_door" parent="." instance=ExtResource("4_tyh53")] [node name="BornMark" type="Marker2D" parent="."] position = Vector2(-1043, -488) diff --git a/scene/test/atk.gd b/scene/test/atk.gd index 18c3306..7aa14ff 100644 --- a/scene/test/atk.gd +++ b/scene/test/atk.gd @@ -3,6 +3,7 @@ var target func enter_state(n): if n is Unit: target=n + get_player().set_target(n.global_position) get_player().attack() pass func update_state(delta): diff --git a/scene/test/character.gd b/scene/test/character.gd index b4c6bd1..8e27e8c 100644 --- a/scene/test/character.gd +++ b/scene/test/character.gd @@ -12,9 +12,12 @@ var action_emoji:Dictionary={ "饥饿":"🍽︎", "好吃":"😋" } +#角色数据 @export var unit_data:Dictionary={ } +##背包数据 +@export var bag_data:Array=[] #允许的状态队列 var state_value_array:Array=["hungry","fatigue","rage","tensity","panic","pressure","hp_max","hp","atk"] #设置状态值 diff --git a/scene/test/character.tscn b/scene/test/character.tscn index a5b957d..0ce2c7a 100644 --- a/scene/test/character.tscn +++ b/scene/test/character.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=18 format=3 uid="uid://cf2g2urxaukxb"] +[gd_scene load_steps=17 format=3 uid="uid://cf2g2urxaukxb"] [ext_resource type="Script" path="res://scene/test/self_character.gd" id="1_d0trv"] [ext_resource type="Script" path="res://scene/test/state_machine.gd" id="2_v5m4x"] @@ -9,9 +9,6 @@ [sub_resource type="CircleShape2D" id="CircleShape2D_740ny"] -[sub_resource type="RectangleShape2D" id="RectangleShape2D_7uxj5"] -size = Vector2(100, 108) - [sub_resource type="Animation" id="Animation_tov45"] length = 0.001 tracks/0/type = "value" @@ -72,12 +69,12 @@ radius = 104.12 script = ExtResource("1_d0trv") unit_id = "player" unit_type = "player" -unit_data_from_id = "test_character_base" +unit_data_from_id = "test_character_ranged" agent = NodePath("agent") state_machine = NodePath("state_machine") rotate = NodePath("rotate") touch_area = NodePath("touch_area") -attack_area = NodePath("rotate/attack_area") +attack_area = NodePath("") [node name="agent" type="NavigationAgent2D" parent="."] path_postprocessing = 1 @@ -107,12 +104,7 @@ script = ExtResource("4_c7f2w") script = ExtResource("5_ol236") [node name="rotate" type="Node2D" parent="."] - -[node name="attack_area" type="Area2D" parent="rotate"] - -[node name="CollisionShape2D" type="CollisionShape2D" parent="rotate/attack_area"] -position = Vector2(50, 1) -shape = SubResource("RectangleShape2D_7uxj5") +unique_name_in_owner = true [node name="Sprite2D" type="Sprite2D" parent="."] visible = false @@ -165,5 +157,3 @@ unique_name_in_owner = true shape = SubResource("CircleShape2D_rhh7a") [connection signal="state_value_changed" from="." to="." method="_on_state_value_changed"] -[connection signal="area_entered" from="touch_area" to="." method="_on_touch_area_area_entered"] -[connection signal="area_exited" from="touch_area" to="." method="_on_touch_area_area_exited"] diff --git a/scene/test/other_character.tscn b/scene/test/other_character.tscn index 3aba6a6..3e94668 100644 --- a/scene/test/other_character.tscn +++ b/scene/test/other_character.tscn @@ -138,7 +138,7 @@ texture_under = SubResource("GradientTexture1D_ioncu") texture_progress = SubResource("GradientTexture1D_6t72h") [node name="BeehaveTree" parent="." node_paths=PackedStringArray("blackboard", "actor") instance=ExtResource("3_5u10o")] -blackboard = NodePath("@Node@17289") +blackboard = NodePath("@Node@231388") actor = NodePath("..") [connection signal="state_value_changed" from="." to="." method="_on_state_value_changed"] diff --git a/scene/test/run.gd b/scene/test/run.gd index 65d4592..7f21897 100644 --- a/scene/test/run.gd +++ b/scene/test/run.gd @@ -22,7 +22,6 @@ func update_state_phy(delta): get_player().stop_move() return get_player().set_target_pos(target.global_position) - return if get_player().is_move_finished(): diff --git a/scene/test/self_character.gd b/scene/test/self_character.gd index 10e9144..94049c2 100644 --- a/scene/test/self_character.gd +++ b/scene/test/self_character.gd @@ -15,24 +15,35 @@ func _on_state_value_changed(state_value_name: String, value: Variant) -> void: pass # Replace with function body. - +var e_interaction_item:EInteractionItem var door_area:Door func _on_touch_area_area_entered(area: Area2D) -> void: if area is Door: door_area=area + %door.show() + if area is EInteractionItem: + if e_interaction_item!=null: + e_interaction_item._exit_highlight() + e_interaction_item=area + + %door.show() pass # Replace with function body. func _on_touch_area_area_exited(area: Area2D) -> void: - if area is Door: - door_area=null - %door.hide() + if area is EInteractionItem: + if e_interaction_item==area: + e_interaction_item._exit_highlight() + e_interaction_item=null pass # Replace with function body. func is_door_availible(): return door_area!=null -func get_door(): +func get_e_interaction_item(): - return door_area + return e_interaction_item +func e_pressed(): + if e_interaction_item!=null: + e_interaction_item.E_pressed() diff --git a/scene/test/test_door.tscn b/scene/test/test_door.tscn new file mode 100644 index 0000000..966e411 --- /dev/null +++ b/scene/test/test_door.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=4 format=3 uid="uid://dbs4jk1ljeq1o"] + +[ext_resource type="Script" path="res://scene/class/door.gd" id="1_6ss0j"] +[ext_resource type="Texture2D" uid="uid://csk8u15wepd1w" path="res://icon.svg" id="2_50bys"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_munxd"] +radius = 76.99 + +[node name="test_door" type="Area2D"] +position = Vector2(1079, 609) +script = ExtResource("1_6ss0j") +map_id = "map_0" + +[node name="Sprite2D2" type="Sprite2D" parent="."] +texture = ExtResource("2_50bys") + +[node name="CollisionShape2D2" type="CollisionShape2D" parent="."] +shape = SubResource("CircleShape2D_munxd") diff --git a/scene/test/test_main.gd b/scene/test/test_main.gd index c39d5c6..5479eea 100644 --- a/scene/test/test_main.gd +++ b/scene/test/test_main.gd @@ -1,17 +1,36 @@ extends Node2D +class_name MainScene @export var player: SelfUnit + + + func _physics_process(delta: float) -> void: %mouse_finder.position=get_global_mouse_position() var now_map:map +var now_e_interacetion_item func _on_control_gui_input(event: InputEvent) -> void: if event.is_action_pressed("mouse_right"): if player: player.sent_message("move",player.get_global_mouse_position()) - - + #if event is InputEventMouseMotion: + #var item=%mouse_finder.get_overlapping_areas() + #if item.size()!=0: + #var target=get_closest_node(player,item,EInteractionItem) + #if target is EInteractionItem: + #if now_e_interacetion_item!=target: + #if is_instance_valid(now_e_interacetion_item): + #now_e_interacetion_item._exit_highlight() + #if is_instance_valid(target): + #target._on_highlight() + #now_e_interacetion_item=target + #else: + #if now_e_interacetion_item!=null and is_instance_valid(now_e_interacetion_item): + #now_e_interacetion_item._exit_highlight() + #now_e_interacetion_item=null if event.is_action_pressed("mouse_left"): + #投放单位,用于测试 if %put_check.button_pressed: var id=%LineEdit.text var type=selected_item @@ -23,6 +42,10 @@ func _on_control_gui_input(event: InputEvent) -> void: new_cb.second_timer_time_out() return + if now_e_interacetion_item!=null: + if player!=null and is_instance_valid(player) and player.is_unit_instance_in_touch_area(now_e_interacetion_item): + now_e_interacetion_item.E_pressed() + return var arr=%mouse_finder.get_overlapping_bodies() print(arr) if arr.size()==0: @@ -35,27 +58,35 @@ func _on_control_gui_input(event: InputEvent) -> void: pass pass # Replace with function body. -func _input(event: InputEvent) -> void: - print(event) - if event.is_action_pressed("e") and player!=null and player.is_door_availible(): - print("检测到切换请求") - var door:Door =player.get_door() - change_map(door.map_id) +#func _input(event: InputEvent) -> void: + #print(event) + # + #if event.is_action_pressed("e") and player!=null and player.is_door_availible() and $CanvasLayer/Control.has_focus(): + #print("检测到切换请求") + #var e=player.get_e_interaction_item() + #if e is EInteractionItem: + #e.E_pressed() + func get_closest_node(self_node:Node2D,array:Array,target_class): if array.size()==0: return null - var length=999999999 + var length=null var node=null for i in range(0,array.size()): print(is_instance_of(i,target_class)) if is_instance_of(array[i],target_class) and array[i]!=self_node: var l=(array[i].global_position-self_node.global_position).length() - if l void: + #同步主场景 + Global.main_scene=self var all_types=Database.get_all_unit_type() if all_types.size()>0: selected_item=all_types[0] @@ -92,6 +123,7 @@ func change_map(map_id:String,ind:int=0): var new_map_tscn=Database.get_map_data(map_id) if new_map_tscn==null: return + var new_map=load(new_map_tscn).instantiate() as map new_map.map_id=map_id add_child(new_map) @@ -131,3 +163,22 @@ func _on_change_scene_0_pressed() -> void: func _on_change_scene_1_pressed() -> void: change_map("map_1") pass # Replace with function body. + + +func _on_mouse_finder_area_entered(area: Area2D) -> void: + if area is EInteractionItem: + if now_e_interacetion_item!=null and is_instance_valid(now_e_interacetion_item): + now_e_interacetion_item._exit_highlight() + now_e_interacetion_item=area + area._on_highlight() + pass # Replace with function body. + + +func _on_mouse_finder_area_exited(area: Area2D) -> void: + if area==now_e_interacetion_item: + now_e_interacetion_item._exit_highlight() + now_e_interacetion_item=null + pass # Replace with function body. + +func show_trader_board(item_array:Array[BagItem],bind:Unit=null): + %trader_board.open(item_array,bind) diff --git a/scene/test/test_main.tscn b/scene/test/test_main.tscn index 37caf8f..a99a46e 100644 --- a/scene/test/test_main.tscn +++ b/scene/test/test_main.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=4 format=3 uid="uid://1wl1fl3qtxc"] +[gd_scene load_steps=5 format=3 uid="uid://1wl1fl3qtxc"] [ext_resource type="Script" path="res://scene/test/test_main.gd" id="1_aimp4"] +[ext_resource type="PackedScene" uid="uid://bv85dh88ovwo4" path="res://scene/trader_board/trader_board.tscn" id="2_8ymm5"] [ext_resource type="PackedScene" uid="uid://cf2g2urxaukxb" path="res://scene/test/character.tscn" id="2_nvm7o"] [sub_resource type="CircleShape2D" id="CircleShape2D_shajf"] @@ -62,6 +63,10 @@ text = "切换到场景0" layout_mode = 2 text = "切换到场景1" +[node name="trader_board" parent="CanvasLayer" instance=ExtResource("2_8ymm5")] +unique_name_in_owner = true +visible = false + [node name="mouse_finder" type="Area2D" parent="."] unique_name_in_owner = true @@ -78,3 +83,5 @@ y_sort_enabled = true [connection signal="timeout" from="CanvasLayer/Control/HBoxContainer/cacul_num_number" to="." method="_on_cacul_num_number_timeout"] [connection signal="pressed" from="CanvasLayer/Control/HBoxContainer/change_scene_0" to="." method="_on_change_scene_0_pressed"] [connection signal="pressed" from="CanvasLayer/Control/HBoxContainer/change_scene_1" to="." method="_on_change_scene_1_pressed"] +[connection signal="area_entered" from="mouse_finder" to="." method="_on_mouse_finder_area_entered"] +[connection signal="area_exited" from="mouse_finder" to="." method="_on_mouse_finder_area_exited"] diff --git a/scene/tool_button/tool_button.gd b/scene/tool_button/tool_button.gd new file mode 100644 index 0000000..1b40ed1 --- /dev/null +++ b/scene/tool_button/tool_button.gd @@ -0,0 +1,21 @@ +extends Button +class_name ToolButton + +func on_button_down() -> void: + get_parent().modulate=Color(0.5,0.5,0.5,1) + pass # Replace with function body. +func on_button_up() -> void: + get_parent().modulate=Color(1,1,1,1) + pass # Replace with function body.ion body. +static func static_on_button_down(canvas:CanvasItem) -> void: + canvas.modulate=Color(0.5,0.5,0.5,1) + pass # Replace with function body. +static func static_on_button_up(canvas:CanvasItem) -> void: + canvas.modulate=Color(1,1,1,1) + pass # Replace with function body.ion body. +func disable(is_disable:bool): + disabled=is_disable + if is_disable: + get_parent().modulate=Color(0.5,0.5,0.5,1) + else: + get_parent().modulate=Color(1,1,1,1) diff --git a/scene/tool_button/tool_button.tscn b/scene/tool_button/tool_button.tscn new file mode 100644 index 0000000..a820c6c --- /dev/null +++ b/scene/tool_button/tool_button.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=2 format=3 uid="uid://bdlo2wn4qnygv"] + +[ext_resource type="Script" path="res://scene/tool_button/tool_button.gd" id="1_rfp4a"] + +[node name="ToolButton" type="Button"] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 +focus_mode = 0 +flat = true +script = ExtResource("1_rfp4a") + +[connection signal="button_down" from="." to="." method="on_button_down"] +[connection signal="button_up" from="." to="." method="on_button_up"] diff --git a/scene/trade_interaction_item/trade.gd b/scene/trade_interaction_item/trade.gd new file mode 100644 index 0000000..740b3b4 --- /dev/null +++ b/scene/trade_interaction_item/trade.gd @@ -0,0 +1,15 @@ +extends EInteractionItem + + +func E_pressed(): + Global.main_scene.show_trader_board([Database.get_item("item_test_01"),Database.get_item("item_test_02")]) +func _on_highlight(): + $Sprite2D2.modulate=Color.GREEN + + pass + +func _exit_highlight(): + $Sprite2D2.modulate=Color.WHITE + + + pass diff --git a/scene/trade_interaction_item/trade.tscn b/scene/trade_interaction_item/trade.tscn new file mode 100644 index 0000000..f8ab71d --- /dev/null +++ b/scene/trade_interaction_item/trade.tscn @@ -0,0 +1,25 @@ +[gd_scene load_steps=4 format=3 uid="uid://2wkc3dlcfrnj"] + +[ext_resource type="Script" path="res://scene/trade_interaction_item/trade.gd" id="1_fma1q"] +[ext_resource type="Texture2D" uid="uid://csk8u15wepd1w" path="res://icon.svg" id="2_e6gt3"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_v7nqc"] +radius = 76.99 + +[node name="Trade" type="Area2D"] +script = ExtResource("1_fma1q") + +[node name="Sprite2D2" type="Sprite2D" parent="."] +texture = ExtResource("2_e6gt3") + +[node name="CollisionShape2D2" type="CollisionShape2D" parent="."] +shape = SubResource("CircleShape2D_v7nqc") + +[node name="Label" type="Label" parent="."] +offset_left = -44.0 +offset_top = -29.0 +offset_right = 40.0 +offset_bottom = 23.0 +text = "商店" +horizontal_alignment = 1 +vertical_alignment = 1 diff --git a/scene/trader_board/trade_item_card.gd b/scene/trader_board/trade_item_card.gd new file mode 100644 index 0000000..9de1409 --- /dev/null +++ b/scene/trader_board/trade_item_card.gd @@ -0,0 +1,15 @@ +extends MarginContainer + + +signal click() +var item:BagItem +func set_item(_item:BagItem): + item=_item + %name.text=item.item_name + %introduction.text=item.item_introduction + %num.text="x"+str(item.num) + + + + + pass diff --git a/scene/trader_board/trade_item_card.tscn b/scene/trader_board/trade_item_card.tscn new file mode 100644 index 0000000..02eb6a8 --- /dev/null +++ b/scene/trader_board/trade_item_card.tscn @@ -0,0 +1,99 @@ +[gd_scene load_steps=7 format=3 uid="uid://d0hg61m4hdwmy"] + +[ext_resource type="PackedScene" uid="uid://bdlo2wn4qnygv" path="res://scene/tool_button/tool_button.tscn" id="1_25x5k"] +[ext_resource type="Script" path="res://scene/trader_board/trade_item_card.gd" id="1_mghgm"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_g7xwf"] +bg_color = Color(0.252028, 0.252028, 0.252028, 1) +corner_radius_top_left = 10 +corner_radius_top_right = 10 +corner_radius_bottom_right = 10 +corner_radius_bottom_left = 10 + +[sub_resource type="LabelSettings" id="LabelSettings_42akb"] +font_size = 30 + +[sub_resource type="LabelSettings" id="LabelSettings_4efih"] +font_size = 20 + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_bgbyt"] +corner_radius_top_left = 10 +corner_radius_top_right = 10 +corner_radius_bottom_right = 10 +corner_radius_bottom_left = 10 + +[node name="TradeItemCard" type="MarginContainer"] +custom_minimum_size = Vector2(250, 0) +anchors_preset = 9 +anchor_bottom = 1.0 +offset_right = 250.0 +grow_vertical = 2 +script = ExtResource("1_mghgm") + +[node name="Panel" type="Panel" parent="."] +layout_mode = 2 +theme_override_styles/panel = SubResource("StyleBoxFlat_g7xwf") + +[node name="MarginContainer" type="MarginContainer" parent="Panel"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_right = 10 +theme_override_constants/margin_bottom = 10 + +[node name="VB" type="VBoxContainer" parent="Panel/MarginContainer"] +layout_mode = 2 + +[node name="name" type="Label" parent="Panel/MarginContainer/VB"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 0 +text = "物品名字" +label_settings = SubResource("LabelSettings_42akb") +vertical_alignment = 1 + +[node name="introduction" type="Label" parent="Panel/MarginContainer/VB"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 +text = "物品介绍" +label_settings = SubResource("LabelSettings_4efih") +autowrap_mode = 3 + +[node name="num" type="Label" parent="Panel/MarginContainer/VB"] +unique_name_in_owner = true +layout_mode = 2 +text = "数量" +vertical_alignment = 1 + +[node name="price" type="Label" parent="Panel/MarginContainer/VB"] +unique_name_in_owner = true +layout_mode = 2 +text = "价格" +vertical_alignment = 1 + +[node name="Panel" type="Panel" parent="Panel/MarginContainer/VB"] +custom_minimum_size = Vector2(0, 50) +layout_mode = 2 +theme_override_styles/panel = SubResource("StyleBoxFlat_bgbyt") + +[node name="Label" type="Label" parent="Panel/MarginContainer/VB/Panel"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +text = "购买" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="ToolButton" parent="Panel/MarginContainer/VB/Panel" instance=ExtResource("1_25x5k")] +layout_mode = 1 diff --git a/scene/trader_board/trader_board.gd b/scene/trader_board/trader_board.gd new file mode 100644 index 0000000..5035d07 --- /dev/null +++ b/scene/trader_board/trader_board.gd @@ -0,0 +1,28 @@ +extends Control + +#绑定到的角色 +var bind_character:Unit + +#卡片场景 +const TRADE_ITEM_CARD = preload("res://scene/trader_board/trade_item_card.tscn") + +#缓存的物品数据 +var item_array_cache:Array[BagItem] +#打开界面并绑定到特定角色 +func open(item_array:Array[BagItem],bind:Unit=null): + for i in %trade_card_add_pos.get_children(): + i.queue_free() + item_array_cache=item_array + for i in item_array: + var new_card=TRADE_ITEM_CARD.instantiate() + %trade_card_add_pos.add_child(new_card) + new_card.set_item(i) + show() + + + +#func _ready() -> void: + #open([Database.get_item("item_test_01"),Database.get_item("item_test_02")]) +func _on_exit_pressed() -> void: + hide() + pass # Replace with function body. diff --git a/scene/trader_board/trader_board.tscn b/scene/trader_board/trader_board.tscn new file mode 100644 index 0000000..163a367 --- /dev/null +++ b/scene/trader_board/trader_board.tscn @@ -0,0 +1,76 @@ +[gd_scene load_steps=5 format=3 uid="uid://bv85dh88ovwo4"] + +[ext_resource type="Script" path="res://scene/trader_board/trader_board.gd" id="1_24lvp"] +[ext_resource type="PackedScene" uid="uid://bdlo2wn4qnygv" path="res://scene/tool_button/tool_button.tscn" id="1_ofd53"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_h5kjg"] +corner_radius_top_left = 10 +corner_radius_top_right = 10 +corner_radius_bottom_right = 10 +corner_radius_bottom_left = 10 + +[sub_resource type="LabelSettings" id="LabelSettings_a02so"] +font_size = 30 + +[node name="trader_board" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_24lvp") + +[node name="Panel" type="Panel" parent="."] +layout_mode = 0 +anchor_left = 0.015625 +anchor_top = 0.0416667 +anchor_right = 0.976563 +anchor_bottom = 0.947531 +theme_override_styles/panel = SubResource("StyleBoxFlat_h5kjg") +metadata/_edit_use_anchors_ = true + +[node name="Label" type="Label" parent="Panel"] +layout_mode = 1 +anchors_preset = 1 +anchor_left = 1.0 +anchor_right = 1.0 +offset_left = -44.0 +offset_top = 10.0 +offset_right = -4.0 +offset_bottom = 33.0 +grow_horizontal = 0 +text = "❌" +label_settings = SubResource("LabelSettings_a02so") +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="exit" parent="Panel/Label" instance=ExtResource("1_ofd53")] +layout_mode = 1 + +[node name="Panel" type="Panel" parent="Panel"] +layout_mode = 1 +anchors_preset = -1 +anchor_left = 0.0546522 +anchor_top = 0.0826235 +anchor_right = 0.945348 +anchor_bottom = 0.917377 +grow_horizontal = 2 +grow_vertical = 2 +metadata/_edit_use_anchors_ = true + +[node name="ScrollContainer" type="ScrollContainer" parent="Panel/Panel"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +vertical_scroll_mode = 0 + +[node name="trade_card_add_pos" type="HBoxContainer" parent="Panel/Panel/ScrollContainer"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_vertical = 3 + +[connection signal="pressed" from="Panel/Label/exit" to="." method="_on_exit_pressed"] diff --git a/tool/state_machine/state.gd b/tool/state_machine/state.gd index 517612b..055e897 100644 --- a/tool/state_machine/state.gd +++ b/tool/state_machine/state.gd @@ -28,7 +28,7 @@ func is_in_list(n)->bool: ##将状态节点切换为n,并调用对应的init stable方法和exit stable方法,传入s func change_state(n:String,s): var change_to=get_node(n) - if change_to&&is_in_list(change_to)&&state_now!=change_to: + if change_to&&is_in_list(change_to): state_now.exit_state() state_now=change_to state_now.enter_state(s)