This commit is contained in:
TsubakiLoL 2024-11-01 23:23:07 +08:00
parent 285af6eb6c
commit 15663f6147
26 changed files with 563 additions and 68 deletions

View File

@ -1,5 +1,9 @@
extends Node extends Node
#不同族群单位之间的初始好感度 #不同族群单位之间的初始好感度
#下面意思为测试族群1对2具有初始负面好感 #下面意思为测试族群1对2具有初始负面好感
#相反2对1具有正面好感 #相反2对1具有正面好感
@ -58,7 +62,8 @@ static var other_unit_data={
"hp":100, "hp":100,
"atk":10, "atk":10,
"position":[0,0] "position":[0,0],
"bag":[]
} }
@ -83,3 +88,35 @@ func get_map_data(id:String):
return map_data[id] return map_data[id]
else: else:
return null 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({})

View File

@ -1,4 +1,7 @@
extends Node extends Node
var main_scene:MainScene
#保存ID对应角色实例的字典 #保存ID对应角色实例的字典
var unit_instance_dic:Dictionary={ var unit_instance_dic:Dictionary={

12
json/item.json Normal file
View File

@ -0,0 +1,12 @@
{
"item_test_01":{
"name":"测试物品1",
"introduction":"测试物品1的介绍"
},
"item_test_02":{
"name":"测试物品2",
"introduction":"测试物品2的介绍"
}
}

View File

@ -1,7 +1,24 @@
extends Area2D extends EInteractionItem
class_name Door class_name Door
@export var map_id:String @export var map_id:String
@export var map_born_pos:int=0 @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

View File

@ -0,0 +1,22 @@
extends Area2D
##地图中使用E键进行交互的基类
class_name EInteractionItem
##交互使用的函数
func E_pressed():
pass
##高光反应抽象函数
func _on_highlight():
pass
##去除高光抽象函数
func _exit_highlight():
pass

48
scene/class/item_class.gd Normal file
View File

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

View File

@ -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="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="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="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="PackedScene" uid="uid://dbs4jk1ljeq1o" path="res://scene/test/test_door.tscn" id="4_gs5kc"]
[ext_resource type="Texture2D" uid="uid://csk8u15wepd1w" path="res://icon.svg" id="5_b01gw"] [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"] [ext_resource type="Script" path="res://scene/class/born_mark.gd" id="6_qu6gr"]
[sub_resource type="NavigationPolygon" id="NavigationPolygon_tjudi"] [sub_resource type="NavigationPolygon" id="NavigationPolygon_tjudi"]
@ -27,9 +27,6 @@ physics_layer_0/collision_layer = 1
navigation_layer_0/layers = 1 navigation_layer_0/layers = 1
sources/0 = SubResource("TileSetAtlasSource_j4j8n") 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")] [node name="map_test_0" type="Node2D" node_paths=PackedStringArray("map_born_mark")]
script = ExtResource("1_mkv6t") script = ExtResource("1_mkv6t")
map_born_mark = [NodePath("BornMark")] map_born_mark = [NodePath("BornMark")]
@ -57,17 +54,12 @@ position = Vector2(359, -417)
unit_id = "test3" unit_id = "test3"
unit_data_from_id = "test_character_base" unit_data_from_id = "test_character_base"
[node name="Door" type="Area2D" parent="."] [node name="test_door" parent="." instance=ExtResource("4_gs5kc")]
position = Vector2(1079, 609)
script = ExtResource("4_61dsd")
map_id = "map_1" 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="."] [node name="BornMark" type="Marker2D" parent="."]
position = Vector2(-1043, -488) position = Vector2(-1043, -488)
script = ExtResource("6_qu6gr") script = ExtResource("6_qu6gr")
[node name="Trade" parent="." instance=ExtResource("6_fl6uv")]
position = Vector2(943, 339)

View File

@ -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="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="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="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="PackedScene" uid="uid://dbs4jk1ljeq1o" path="res://scene/test/test_door.tscn" id="4_tyh53"]
[ext_resource type="Texture2D" uid="uid://csk8u15wepd1w" path="res://icon.svg" id="5_cp4uj"]
[ext_resource type="Script" path="res://scene/class/born_mark.gd" id="6_jfam2"] [ext_resource type="Script" path="res://scene/class/born_mark.gd" id="6_jfam2"]
[sub_resource type="NavigationPolygon" id="NavigationPolygon_tjudi"] [sub_resource type="NavigationPolygon" id="NavigationPolygon_tjudi"]
@ -27,9 +26,6 @@ physics_layer_0/collision_layer = 1
navigation_layer_0/layers = 1 navigation_layer_0/layers = 1
sources/0 = SubResource("TileSetAtlasSource_j4j8n") 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")] [node name="map_test_1" type="Node2D" node_paths=PackedStringArray("map_born_mark")]
script = ExtResource("1_476af") script = ExtResource("1_476af")
map_born_mark = [NodePath("BornMark")] map_born_mark = [NodePath("BornMark")]
@ -52,16 +48,7 @@ position = Vector2(842, 32)
unit_id = "test2" unit_id = "test2"
unit_data_from_id = "test_character_base" unit_data_from_id = "test_character_base"
[node name="Door" type="Area2D" parent="."] [node name="test_door" parent="." instance=ExtResource("4_tyh53")]
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="BornMark" type="Marker2D" parent="."] [node name="BornMark" type="Marker2D" parent="."]
position = Vector2(-1043, -488) position = Vector2(-1043, -488)

View File

@ -3,6 +3,7 @@ var target
func enter_state(n): func enter_state(n):
if n is Unit: if n is Unit:
target=n target=n
get_player().set_target(n.global_position)
get_player().attack() get_player().attack()
pass pass
func update_state(delta): func update_state(delta):

View File

@ -12,9 +12,12 @@ var action_emoji:Dictionary={
"饥饿":"🍽︎", "饥饿":"🍽︎",
"好吃":"😋" "好吃":"😋"
} }
#角色数据
@export var unit_data: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"] var state_value_array:Array=["hungry","fatigue","rage","tensity","panic","pressure","hp_max","hp","atk"]
#设置状态值 #设置状态值

View File

@ -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/self_character.gd" id="1_d0trv"]
[ext_resource type="Script" path="res://scene/test/state_machine.gd" id="2_v5m4x"] [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="CircleShape2D" id="CircleShape2D_740ny"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_7uxj5"]
size = Vector2(100, 108)
[sub_resource type="Animation" id="Animation_tov45"] [sub_resource type="Animation" id="Animation_tov45"]
length = 0.001 length = 0.001
tracks/0/type = "value" tracks/0/type = "value"
@ -72,12 +69,12 @@ radius = 104.12
script = ExtResource("1_d0trv") script = ExtResource("1_d0trv")
unit_id = "player" unit_id = "player"
unit_type = "player" unit_type = "player"
unit_data_from_id = "test_character_base" unit_data_from_id = "test_character_ranged"
agent = NodePath("agent") agent = NodePath("agent")
state_machine = NodePath("state_machine") state_machine = NodePath("state_machine")
rotate = NodePath("rotate") rotate = NodePath("rotate")
touch_area = NodePath("touch_area") touch_area = NodePath("touch_area")
attack_area = NodePath("rotate/attack_area") attack_area = NodePath("")
[node name="agent" type="NavigationAgent2D" parent="."] [node name="agent" type="NavigationAgent2D" parent="."]
path_postprocessing = 1 path_postprocessing = 1
@ -107,12 +104,7 @@ script = ExtResource("4_c7f2w")
script = ExtResource("5_ol236") script = ExtResource("5_ol236")
[node name="rotate" type="Node2D" parent="."] [node name="rotate" type="Node2D" parent="."]
unique_name_in_owner = true
[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")
[node name="Sprite2D" type="Sprite2D" parent="."] [node name="Sprite2D" type="Sprite2D" parent="."]
visible = false visible = false
@ -165,5 +157,3 @@ unique_name_in_owner = true
shape = SubResource("CircleShape2D_rhh7a") shape = SubResource("CircleShape2D_rhh7a")
[connection signal="state_value_changed" from="." to="." method="_on_state_value_changed"] [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"]

View File

@ -138,7 +138,7 @@ texture_under = SubResource("GradientTexture1D_ioncu")
texture_progress = SubResource("GradientTexture1D_6t72h") texture_progress = SubResource("GradientTexture1D_6t72h")
[node name="BeehaveTree" parent="." node_paths=PackedStringArray("blackboard", "actor") instance=ExtResource("3_5u10o")] [node name="BeehaveTree" parent="." node_paths=PackedStringArray("blackboard", "actor") instance=ExtResource("3_5u10o")]
blackboard = NodePath("@Node@17289") blackboard = NodePath("@Node@231388")
actor = NodePath("..") actor = NodePath("..")
[connection signal="state_value_changed" from="." to="." method="_on_state_value_changed"] [connection signal="state_value_changed" from="." to="." method="_on_state_value_changed"]

View File

@ -22,7 +22,6 @@ func update_state_phy(delta):
get_player().stop_move() get_player().stop_move()
return return
get_player().set_target_pos(target.global_position) get_player().set_target_pos(target.global_position)
return return
if get_player().is_move_finished(): if get_player().is_move_finished():

View File

@ -15,24 +15,35 @@ func _on_state_value_changed(state_value_name: String, value: Variant) -> void:
pass # Replace with function body. pass # Replace with function body.
var e_interaction_item:EInteractionItem
var door_area:Door var door_area:Door
func _on_touch_area_area_entered(area: Area2D) -> void: func _on_touch_area_area_entered(area: Area2D) -> void:
if area is Door: if area is Door:
door_area=area 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() %door.show()
pass # Replace with function body. pass # Replace with function body.
func _on_touch_area_area_exited(area: Area2D) -> void: func _on_touch_area_area_exited(area: Area2D) -> void:
if area is Door: if area is EInteractionItem:
door_area=null if e_interaction_item==area:
%door.hide() e_interaction_item._exit_highlight()
e_interaction_item=null
pass # Replace with function body. pass # Replace with function body.
func is_door_availible(): func is_door_availible():
return door_area!=null 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()

18
scene/test/test_door.tscn Normal file
View File

@ -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")

View File

@ -1,17 +1,36 @@
extends Node2D extends Node2D
class_name MainScene
@export var player: SelfUnit @export var player: SelfUnit
func _physics_process(delta: float) -> void: func _physics_process(delta: float) -> void:
%mouse_finder.position=get_global_mouse_position() %mouse_finder.position=get_global_mouse_position()
var now_map:map var now_map:map
var now_e_interacetion_item
func _on_control_gui_input(event: InputEvent) -> void: func _on_control_gui_input(event: InputEvent) -> void:
if event.is_action_pressed("mouse_right"): if event.is_action_pressed("mouse_right"):
if player: if player:
player.sent_message("move",player.get_global_mouse_position()) 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 event.is_action_pressed("mouse_left"):
#投放单位,用于测试
if %put_check.button_pressed: if %put_check.button_pressed:
var id=%LineEdit.text var id=%LineEdit.text
var type=selected_item var type=selected_item
@ -23,6 +42,10 @@ func _on_control_gui_input(event: InputEvent) -> void:
new_cb.second_timer_time_out() new_cb.second_timer_time_out()
return 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() var arr=%mouse_finder.get_overlapping_bodies()
print(arr) print(arr)
if arr.size()==0: if arr.size()==0:
@ -35,27 +58,35 @@ func _on_control_gui_input(event: InputEvent) -> void:
pass pass
pass # Replace with function body. pass # Replace with function body.
func _input(event: InputEvent) -> void: #func _input(event: InputEvent) -> void:
print(event) #print(event)
if event.is_action_pressed("e") and player!=null and player.is_door_availible(): #
print("检测到切换请求") #if event.is_action_pressed("e") and player!=null and player.is_door_availible() and $CanvasLayer/Control.has_focus():
var door:Door =player.get_door() #print("检测到切换请求")
change_map(door.map_id) #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): func get_closest_node(self_node:Node2D,array:Array,target_class):
if array.size()==0: if array.size()==0:
return null return null
var length=999999999 var length=null
var node=null var node=null
for i in range(0,array.size()): for i in range(0,array.size()):
print(is_instance_of(i,target_class)) print(is_instance_of(i,target_class))
if is_instance_of(array[i],target_class) and array[i]!=self_node: if is_instance_of(array[i],target_class) and array[i]!=self_node:
var l=(array[i].global_position-self_node.global_position).length() var l=(array[i].global_position-self_node.global_position).length()
if l<length: if length==null:
length=l
node=array[i]
elif l<length:
length=l length=l
node=array[i] node=array[i]
return node return node
func _ready() -> void: func _ready() -> void:
#同步主场景
Global.main_scene=self
var all_types=Database.get_all_unit_type() var all_types=Database.get_all_unit_type()
if all_types.size()>0: if all_types.size()>0:
selected_item=all_types[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) var new_map_tscn=Database.get_map_data(map_id)
if new_map_tscn==null: if new_map_tscn==null:
return return
var new_map=load(new_map_tscn).instantiate() as map var new_map=load(new_map_tscn).instantiate() as map
new_map.map_id=map_id new_map.map_id=map_id
add_child(new_map) add_child(new_map)
@ -131,3 +163,22 @@ func _on_change_scene_0_pressed() -> void:
func _on_change_scene_1_pressed() -> void: func _on_change_scene_1_pressed() -> void:
change_map("map_1") change_map("map_1")
pass # Replace with function body. 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)

View File

@ -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="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"] [ext_resource type="PackedScene" uid="uid://cf2g2urxaukxb" path="res://scene/test/character.tscn" id="2_nvm7o"]
[sub_resource type="CircleShape2D" id="CircleShape2D_shajf"] [sub_resource type="CircleShape2D" id="CircleShape2D_shajf"]
@ -62,6 +63,10 @@ text = "切换到场景0"
layout_mode = 2 layout_mode = 2
text = "切换到场景1" 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="."] [node name="mouse_finder" type="Area2D" parent="."]
unique_name_in_owner = true 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="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_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="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"]

View File

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

View File

@ -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"]

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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"]

View File

@ -28,7 +28,7 @@ func is_in_list(n)->bool:
##将状态节点切换为n,并调用对应的init stable方法和exit stable方法,传入s ##将状态节点切换为n,并调用对应的init stable方法和exit stable方法,传入s
func change_state(n:String,s): func change_state(n:String,s):
var change_to=get_node(n) 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.exit_state()
state_now=change_to state_now=change_to
state_now.enter_state(s) state_now.enter_state(s)