From 8993e56a79f9e9176c194d20e9d3fe9744be4492 Mon Sep 17 00:00:00 2001 From: Zapzoop0099 Date: Sat, 30 Jan 2021 18:44:05 +0530 Subject: [PATCH 01/18] Container task running good --- .../resources/interact/interact.tres | 3 + .../resources/interacttask/interacttask.tres | 3 + src/assets/autoload/uimanager.gd | 9 +- .../classes/ui/base/margincontainerbase.gd | 30 +++++++ src/assets/items/item.gd | 11 ++- src/assets/main/maps.gd | 5 ++ src/assets/maps/test/Container.gd | 45 ++++++++++ src/assets/maps/test/test.tscn | 52 +++++++++--- .../ui/tasks/container/Textures/Container.png | 3 + .../container/Textures/Container.png.import | 34 ++++++++ src/assets/ui/tasks/container/container.gd | 83 +++++++++++++++++++ src/assets/ui/tasks/container/container.tscn | 56 +++++++++++++ src/assets/ui/tasks/container/itemslot.gd | 35 ++++++++ src/assets/ui/tasks/container/itemslot.tscn | 31 +++++++ .../ui/tasks/container/itemslotbackend.gd | 37 +++++++++ src/assets/ui/uicontroller/uicontroller.gd | 16 ++++ src/project.godot | 6 ++ 17 files changed, 445 insertions(+), 14 deletions(-) create mode 100644 src/assets/common/classes/ui/base/margincontainerbase.gd create mode 100644 src/assets/maps/test/Container.gd create mode 100644 src/assets/ui/tasks/container/Textures/Container.png create mode 100644 src/assets/ui/tasks/container/Textures/Container.png.import create mode 100644 src/assets/ui/tasks/container/container.gd create mode 100644 src/assets/ui/tasks/container/container.tscn create mode 100644 src/assets/ui/tasks/container/itemslot.gd create mode 100644 src/assets/ui/tasks/container/itemslot.tscn create mode 100644 src/assets/ui/tasks/container/itemslotbackend.gd diff --git a/src/addons/opensusinteraction/resources/interact/interact.tres b/src/addons/opensusinteraction/resources/interact/interact.tres index 30c3965d..f5c03024 100644 --- a/src/addons/opensusinteraction/resources/interact/interact.tres +++ b/src/addons/opensusinteraction/resources/interact/interact.tres @@ -33,8 +33,11 @@ resource_local_to_scene = true resource_name = "InteractTask" script = ExtResource( 5 ) task_text = "" +random_numbers = 0 +task_id = -1 ui_resource = SubResource( 2 ) outputs/toggle_map_interactions = false +is_task_global = false [resource] resource_local_to_scene = true diff --git a/src/addons/opensusinteraction/resources/interacttask/interacttask.tres b/src/addons/opensusinteraction/resources/interacttask/interacttask.tres index 67ea357d..4a9b2980 100644 --- a/src/addons/opensusinteraction/resources/interacttask/interacttask.tres +++ b/src/addons/opensusinteraction/resources/interacttask/interacttask.tres @@ -20,5 +20,8 @@ resource_local_to_scene = true resource_name = "InteractTask" script = ExtResource( 1 ) task_text = "" +random_numbers = 0 +task_id = -1 ui_resource = SubResource( 1 ) outputs/toggle_map_interactions = false +is_task_global = false diff --git a/src/assets/autoload/uimanager.gd b/src/assets/autoload/uimanager.gd index 5b59baad..687c6c54 100644 --- a/src/assets/autoload/uimanager.gd +++ b/src/assets/autoload/uimanager.gd @@ -17,7 +17,8 @@ var ui_list: Dictionary = { "appearance_editor": {"scene": preload("res://assets/ui/submenus/appearance_editor/appearance_editor.tscn")}, #task UI - "clockset": {"scene": preload("res://assets/ui/tasks/clockset/clockset.tscn")} + "clockset": {"scene": preload("res://assets/ui/tasks/clockset/clockset.tscn")}, + "container":{"scene": preload("res://assets/ui/tasks/container/container.tscn")} } var current_ui: Control @@ -35,6 +36,7 @@ signal close_ui(ui_name, free) signal instance_ui(ui_name, ui_data) signal update_ui(ui_name, ui_data) signal free_ui(ui_name) +signal pre_ins(ui_name) signal close_all_ui() func _ready(): @@ -83,6 +85,11 @@ func free_ui(ui_name: String): push_error("free_ui() called with invalid ui name " + ui_name) emit_signal("free_ui", ui_name) +func pre_ins(ui_name:String): + if not ui_list.keys().has(ui_name): + push_error("pre_ins() called with invalid ui name " + ui_name) + emit_signal("pre_ins", ui_name) + func close_all_ui(free: bool = false): emit_signal("close_all_ui", free) diff --git a/src/assets/common/classes/ui/base/margincontainerbase.gd b/src/assets/common/classes/ui/base/margincontainerbase.gd new file mode 100644 index 00000000..7a4be0e0 --- /dev/null +++ b/src/assets/common/classes/ui/base/margincontainerbase.gd @@ -0,0 +1,30 @@ +extends MarginContainer + +class_name MarginContainerBase + +export (String) var menu_name + +export (bool) var disable_movement + +var ui_data: Dictionary = {} + +func _init(): + connect("visibility_changed", self, "_on_visibility_changed") + +#called by ui system +func base_open(): + show() + +#called by self or ui system +func base_close(): + hide() + +# warning-ignore:unused_argument + +func _on_visibility_changed(): + if not disable_movement: + return + if visible: + UIManager.ui_opened(menu_name) + else: + UIManager.ui_closed(menu_name) diff --git a/src/assets/items/item.gd b/src/assets/items/item.gd index 053a5bac..40ba298b 100644 --- a/src/assets/items/item.gd +++ b/src/assets/items/item.gd @@ -11,10 +11,11 @@ var can_pickup_with_mouse: bool var holding_player: Player var being_held: bool var being_picked_up: bool +var item_location:NodePath #The location of the item +var item_from_container:bool #Checks item is from container or not -func _ready() -> void: - $ItemAnimator.play("hover") +func _ready() -> void: # Wait another frame for map to finish setting up yield(get_tree(), "idle_frame") # print("(items.gd/_ready)") @@ -34,7 +35,11 @@ func picked_up() -> void: """Item is picked up.""" set_collision_layer_bit(4, false) being_held = true - map_items.remove_child(self) + if item_from_container: + var path = get_tree().get_root().get_node(item_location) + path.remove_child(self) + else: + map_items.remove_child(self) holding_player.item_handler.add_child(self) position = Vector2.ZERO diff --git a/src/assets/main/maps.gd b/src/assets/main/maps.gd index 2792e0a7..31d5346b 100644 --- a/src/assets/main/maps.gd +++ b/src/assets/main/maps.gd @@ -68,6 +68,8 @@ func switchMap(newMap: String) -> void: # actual current map to position 0 manually. move_child(mapClone, 0) emit_signal("spawn", getSpawnPoints()) + if newMap == "Test": + init_all_tasks() func instance_map(map_name: String) -> Node: # print("instancing map ", map_name) @@ -107,3 +109,6 @@ func load_map_info_resources() -> Array: if not res is MapInfo: resources.erase(res) return resources + +func init_all_tasks(): + UIManager.pre_ins("container") diff --git a/src/assets/maps/test/Container.gd b/src/assets/maps/test/Container.gd new file mode 100644 index 00000000..4993c55a --- /dev/null +++ b/src/assets/maps/test/Container.gd @@ -0,0 +1,45 @@ +extends Area2D + +#export(Resource) var interact_resource +var pressed:bool = false +var interacting:bool = false +var interactor:Dictionary +#TODO:Add a shader + + +func _ready(): + #interact_resource.init_resource(self) + pass + +func reset() -> void: #Resets the node + interacting = false + pressed = false + interactor.clear() + +func register(body) -> void:#Register a body + interactor[body.id] = body.get_path() + interactor["bool"] = true + return + +func _input(event):#Checks that the player presses the key is in interacting dic + if event.is_action_pressed("interact") and interactor.keys().has(Network.get_my_id()): + interacting = true + pressed = true + UIManager.open_ui("container", interactor) + #interact(interactor) + +func _on_Container_body_entered(_body):#Check wether the body is player or not and record the player + for bodies in get_overlapping_bodies(): + if bodies.is_in_group("players"): + if interactor.empty(): + register(bodies) + else: + return + + +func _on_Container_body_exited(_body):#Closes the ui + UIManager.close_ui("container") + reset() + +#func interact(interactor):#The main func to pass data +# interact_resource.interact(self,interactor) diff --git a/src/assets/maps/test/test.tscn b/src/assets/maps/test/test.tscn index 5b8089b8..4e7f4c30 100644 --- a/src/assets/maps/test/test.tscn +++ b/src/assets/maps/test/test.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=38 format=2] +[gd_scene load_steps=41 format=2] [ext_resource path="res://assets/common/textures/icons/spawnpad.png" type="Texture" id=1] [ext_resource path="res://assets/maps/common/dynamic/testdoor/testdoor.tscn" type="PackedScene" id=2] @@ -11,9 +11,11 @@ [ext_resource path="res://addons/opensusinteraction/resources/interact/interact.gd" type="Script" id=9] [ext_resource path="res://addons/opensusinteraction/resources/interactmap/interactmap.gd" type="Script" id=10] [ext_resource path="res://addons/opensusinteraction/resources/interactui/interactui.gd" type="Script" id=11] +[ext_resource path="res://assets/maps/test/Container.gd" type="Script" id=12] [ext_resource path="res://assets/items/battery.tscn" type="PackedScene" id=13] [ext_resource path="res://assets/items/wrench.tscn" type="PackedScene" id=14] [ext_resource path="res://assets/maps/map.gd" type="Script" id=15] +[ext_resource path="res://assets/player/textures/characters/black/black-proto-1.png" type="Texture" id=16] [sub_resource type="Resource" id=1] resource_local_to_scene = true @@ -33,8 +35,9 @@ ui_name = "" ui_data = { } +action = 0 advanced/reinstance = false -advanced/only_instance = false +advanced/free_on_close = false [sub_resource type="Resource" id=3] resource_local_to_scene = true @@ -55,8 +58,9 @@ ui_name = "" ui_data = { } +action = 0 advanced/reinstance = false -advanced/only_instance = false +advanced/free_on_close = false [sub_resource type="Resource" id=5] resource_local_to_scene = true @@ -94,8 +98,9 @@ ui_name = "clockset" ui_data = { } +action = 0 advanced/reinstance = false -advanced/only_instance = false +advanced/free_on_close = false [sub_resource type="Resource" id=9] resource_local_to_scene = true @@ -115,8 +120,9 @@ ui_name = "" ui_data = { } +action = 0 advanced/reinstance = false -advanced/only_instance = false +advanced/free_on_close = false [sub_resource type="Resource" id=11] resource_local_to_scene = true @@ -133,8 +139,9 @@ ui_name = "clockset" ui_data = { } +action = 0 advanced/reinstance = false -advanced/only_instance = false +advanced/free_on_close = false [sub_resource type="Resource" id=13] resource_local_to_scene = true @@ -152,8 +159,9 @@ ui_name = "" ui_data = { } +action = 0 advanced/reinstance = false -advanced/only_instance = false +advanced/free_on_close = false [sub_resource type="Resource" id=15] resource_local_to_scene = true @@ -172,8 +180,9 @@ ui_name = "chatbox" ui_data = { } +action = 0 advanced/reinstance = false -advanced/only_instance = false +advanced/free_on_close = false [sub_resource type="Resource" id=17] resource_local_to_scene = true @@ -209,8 +218,9 @@ ui_name = "clockset" ui_data = { } +action = 0 advanced/reinstance = false -advanced/only_instance = false +advanced/free_on_close = false [sub_resource type="Resource" id=21] resource_local_to_scene = true @@ -230,8 +240,9 @@ ui_name = "" ui_data = { } +action = 0 advanced/reinstance = false -advanced/only_instance = false +advanced/free_on_close = false [sub_resource type="Resource" id=23] resource_local_to_scene = true @@ -241,6 +252,9 @@ task_resource = SubResource( 21 ) ui_resource = SubResource( 22 ) map_resource = SubResource( 18 ) +[sub_resource type="RectangleShape2D" id=24] +extents = Vector2( 24, 24 ) + [node name="test" type="YSort"] script = ExtResource( 15 ) @@ -454,6 +468,24 @@ position = Vector2( 155.052, -40.363 ) material = null position = Vector2( -96.3763, 93.3395 ) +[node name="Tasks" type="YSort" parent="Interactive"] + +[node name="Containers" type="YSort" parent="Interactive/Tasks"] + +[node name="Container" type="Area2D" parent="Interactive/Tasks/Containers"] +position = Vector2( 232, 56 ) +script = ExtResource( 12 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Interactive/Tasks/Containers/Container"] +shape = SubResource( 24 ) + +[node name="Sprite" type="Sprite" parent="Interactive/Tasks/Containers/Container"] +position = Vector2( 0, 3.8147e-06 ) +scale = Vector2( 0.625, 0.625 ) +texture = ExtResource( 16 ) + [node name="Props" type="YSort" parent="."] [node name="Corpses" type="YSort" parent="Props"] +[connection signal="body_entered" from="Interactive/Tasks/Containers/Container" to="Interactive/Tasks/Containers/Container" method="_on_Container_body_entered"] +[connection signal="body_exited" from="Interactive/Tasks/Containers/Container" to="Interactive/Tasks/Containers/Container" method="_on_Container_body_exited"] diff --git a/src/assets/ui/tasks/container/Textures/Container.png b/src/assets/ui/tasks/container/Textures/Container.png new file mode 100644 index 00000000..1ccd3ffd --- /dev/null +++ b/src/assets/ui/tasks/container/Textures/Container.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f9ee4cda50a6ef92514e07738a47d1157665114243346e6c358d313833130d5d +size 5831 diff --git a/src/assets/ui/tasks/container/Textures/Container.png.import b/src/assets/ui/tasks/container/Textures/Container.png.import new file mode 100644 index 00000000..9ffee9ec --- /dev/null +++ b/src/assets/ui/tasks/container/Textures/Container.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/Container.png-879c764ee37a9377f78340a313b4b235.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/ui/tasks/container/Textures/Container.png" +dest_files=[ "res://.import/Container.png-879c764ee37a9377f78340a313b4b235.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/src/assets/ui/tasks/container/container.gd b/src/assets/ui/tasks/container/container.gd new file mode 100644 index 00000000..e49adedf --- /dev/null +++ b/src/assets/ui/tasks/container/container.gd @@ -0,0 +1,83 @@ +extends MarginContainerBase + +onready var grid = $background/conatainergrid + +const slot_scene = preload("res://assets/ui/tasks/container/itemslot.tscn") + +var pressed:bool= false + +export(int) var slots +#var slots_data:Array + +func _ready(): +#When the first player interacts then called this func to all others so everyone get the same scene set + if grid.get_child(0) == null: + rpc_id(1,"set_slot_server") +#Connects with GameManager to record game transition + GameManager.connect('state_changed', self, '_on_state_changed') + + +func _process(_delta):#Called every frame to check interaction status + if ui_data.has("bool"): + rpc_id(1, "pass_data_server", ui_data) + +func _on_closebutton_pressed():#Resets the data which is passed + UIManager.close_ui("container") + rpc_id(1, "reset_server") + +puppetsync func set_slot(): + #Place where the scene is built + for num in range(0, slots): + var slot = slot_scene.instance() + slot.set_name(str(num)) + slot.index = num + slot.get_child(0).frontend = slot + grid.add_child(slot) + +puppetsync func pass_data(data:Dictionary):#Pass data to child + for slot in grid.get_children(): + slot.ui_data = data + +func erase_data():#Erase data from child + for slot in grid.get_children(): + slot.ui_data.clear() + +puppetsync func erase_child():#erases all child + for child in grid.get_children(): + child.queue_free() + +puppetsync func reset():#Clears all the data + erase_data() + ui_data.clear() + +# +func _on_state_changed(_old_state, new_state) -> void:#resets the task when state changes + match new_state: + GameManager.State.Normal: + if grid.get_child(0) == null: + rpc_id(1,"set_slot_server") + GameManager.State.Lobby: + rpc_id(1, "erase_child_server") + rpc_id(1, "reset_server") + +remotesync func set_slot_server(): + if not get_tree().is_network_server(): + return + rpc("set_slot") + +remotesync func pass_data_server(data:Dictionary): + if not get_tree().is_network_server(): + return + rpc("pass_data", data) + +remotesync func reset_server(): + if not get_tree().is_network_server(): + return + rpc("reset") +remotesync func erase_child_server(): + if not get_tree().is_network_server(): + return + rpc("erase_child") + + + diff --git a/src/assets/ui/tasks/container/container.tscn b/src/assets/ui/tasks/container/container.tscn new file mode 100644 index 00000000..e287629b --- /dev/null +++ b/src/assets/ui/tasks/container/container.tscn @@ -0,0 +1,56 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://assets/ui/tasks/container/container.gd" type="Script" id=1] +[ext_resource path="res://assets/ui/tasks/container/Textures/Container.png" type="Texture" id=2] + +[node name="conatiner" type="MarginContainer"] +margin_left = 128.0 +margin_top = 48.0 +margin_right = 859.0 +margin_bottom = 587.0 +script = ExtResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} +slots = 8 + +[node name="background" type="TextureRect" parent="."] +margin_right = 731.0 +margin_bottom = 539.0 +texture = ExtResource( 2 ) + +[node name="upperoverlay" type="Control" parent="background"] +margin_right = 728.0 +margin_bottom = 32.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="name" type="Label" parent="background/upperoverlay"] +margin_right = 680.0 +margin_bottom = 24.0 +text = "Container" +align = 1 + +[node name="closebutton" type="Button" parent="background/upperoverlay"] +margin_left = 704.0 +margin_right = 728.0 +margin_bottom = 28.0 +text = "X" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="conatainergrid" type="GridContainer" parent="background"] +margin_left = 32.0 +margin_top = 112.0 +margin_right = 696.0 +margin_bottom = 492.0 +custom_constants/vseparation = 200 +custom_constants/hseparation = 92 +columns = 4 +__meta__ = { +"_edit_use_anchors_": false +} +[connection signal="mouse_entered" from="." to="." method="_on_conatiner_mouse_entered"] +[connection signal="pressed" from="background/upperoverlay/closebutton" to="." method="_on_closebutton_pressed"] diff --git a/src/assets/ui/tasks/container/itemslot.gd b/src/assets/ui/tasks/container/itemslot.gd new file mode 100644 index 00000000..d48092fc --- /dev/null +++ b/src/assets/ui/tasks/container/itemslot.gd @@ -0,0 +1,35 @@ +extends MarginContainerBase + +var mouse_entered:bool +var index:int + +#TODO: Set a randomizer + +signal input_received(ui_data, index) + +func _ready(): + pass + + +func _on_itemslot_mouse_entered(): + if get_child_count() == 1: + return + else: + get_child(1).animator.play("hover") + get_child(1).can_pickup_with_mouse = true + mouse_entered = true + + +func _on_itemslot_mouse_exited(): + if get_child_count() == 1: + return + else: + get_child(1).animator.play("idle") + get_child(1).can_pickup_with_mouse = false + mouse_entered = false + + +func _on_itemslot_gui_input(event): + if event is InputEventMouseButton and event.pressed and event.button_index == BUTTON_LEFT and mouse_entered == true: + if get_child(1) != null: + emit_signal("input_received", ui_data, index) diff --git a/src/assets/ui/tasks/container/itemslot.tscn b/src/assets/ui/tasks/container/itemslot.tscn new file mode 100644 index 00000000..7445b108 --- /dev/null +++ b/src/assets/ui/tasks/container/itemslot.tscn @@ -0,0 +1,31 @@ +[gd_scene load_steps=6 format=2] + +[ext_resource path="res://assets/ui/tasks/container/itemslot.gd" type="Script" id=1] +[ext_resource path="res://assets/common/shaders/outline.shader" type="Shader" id=2] +[ext_resource path="res://assets/items/battery.tscn" type="PackedScene" id=3] +[ext_resource path="res://assets/ui/tasks/container/itemslotbackend.gd" type="Script" id=4] + +[sub_resource type="ShaderMaterial" id=1] +resource_local_to_scene = true +shader = ExtResource( 2 ) +shader_param/line_color = Color( 1, 1, 0, 0 ) +shader_param/line_thickness = 5.0 + +[node name="itemslot" type="MarginContainer"] +margin_right = 128.0 +margin_bottom = 128.0 +rect_min_size = Vector2( 90, 90 ) +script = ExtResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Backend" type="Node" parent="."] +script = ExtResource( 4 ) + +[node name="Battery" parent="." instance=ExtResource( 3 )] +material = SubResource( 1 ) +position = Vector2( 64, 64 ) +[connection signal="gui_input" from="." to="." method="_on_itemslot_gui_input"] +[connection signal="mouse_entered" from="." to="." method="_on_itemslot_mouse_entered"] +[connection signal="mouse_exited" from="." to="." method="_on_itemslot_mouse_exited"] diff --git a/src/assets/ui/tasks/container/itemslotbackend.gd b/src/assets/ui/tasks/container/itemslotbackend.gd new file mode 100644 index 00000000..9c6278cb --- /dev/null +++ b/src/assets/ui/tasks/container/itemslotbackend.gd @@ -0,0 +1,37 @@ +extends Node + +var frontend = null + +func _ready(): + frontend.connect("input_received", self, "on_input_received") + +func set_in_hand(ui_data_pass, index:int):#This the crucial function + if not frontend.index == index: + return + else: + var item = frontend.get_child(1) + #By only this the item from the itemslot get transferredd to hand + for key in ui_data_pass.keys(): + if typeof(key) == TYPE_INT:#Filters the ui_data + var player = ui_data_pass[key] + get_tree().get_root().get_node(player).item_handler._test_pickup(item) + +puppetsync func set_path():#Give the item its location so it cna remove itself and add to other location + var item = frontend.get_child(1) + var self_path = get_parent().get_path() + print(get_parent().get_path()) + print(item.get_path()) + item.item_location = self_path + item.item_from_container = true + +func on_input_received(ui_data:Dictionary, index:int): + rpc_id(1, "set_server") + set_in_hand(ui_data,index) + +remotesync func set_server(): + if not get_tree().is_network_server(): + return + var id: int = get_tree().get_rpc_sender_id() + if not Network.peers.has(id): + return + rpc("set_path") diff --git a/src/assets/ui/uicontroller/uicontroller.gd b/src/assets/ui/uicontroller/uicontroller.gd index 523bef2e..3f4ec2f9 100644 --- a/src/assets/ui/uicontroller/uicontroller.gd +++ b/src/assets/ui/uicontroller/uicontroller.gd @@ -23,6 +23,9 @@ func _ready(): UIManager.connect("free_ui", self, "free_ui") # warning-ignore:return_value_discarded UIManager.connect("close_all_ui", self, "close_all_ui") +# warning-ignore:return_value_discarded + UIManager.connect("pre_ins", self, "pre_ins") + var err = config.load("user://settings.cfg") if err == OK: $ColorblindRect.material.set_shader_param( @@ -127,3 +130,16 @@ func get_child_node_names() -> Array: for i in get_children(): name_list.append(i.name) return name_list + +func pre_ins(ui_name: String): + update_instanced_uis() + if not ui_list.keys().has(ui_name): + return + var new_ui = ui_list[ui_name].scene.instance() + new_ui.name = ui_name + instanced_uis[ui_name] = new_ui + add_child(new_ui) + if new_ui.has_method("base_close"): + new_ui.base_close() + if new_ui.has_method("close"): + new_ui.close() diff --git a/src/project.godot b/src/project.godot index 6abeb4a8..b98af940 100644 --- a/src/project.godot +++ b/src/project.godot @@ -44,6 +44,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://assets/common/classes/resources/mapinfo/mapinfo.gd" }, { +"base": "MarginContainer", +"class": "MarginContainerBase", +"language": "GDScript", +"path": "res://assets/common/classes/ui/base/margincontainerbase.gd" +}, { "base": "KinematicBody2D", "class": "Player", "language": "GDScript", @@ -92,6 +97,7 @@ _global_script_class_icons={ "Item": "", "ItemHandler": "", "MapInfo": "", +"MarginContainerBase": "", "Player": "", "PoolManager": "", "PopupBase": "", From 8d62ec3c1f97e7b5d43569f25027e9c3cf4b2735 Mon Sep 17 00:00:00 2001 From: Zapzoop0099 Date: Sat, 30 Jan 2021 19:15:20 +0530 Subject: [PATCH 02/18] Removed test debug messages --- src/assets/ui/tasks/container/itemslotbackend.gd | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/assets/ui/tasks/container/itemslotbackend.gd b/src/assets/ui/tasks/container/itemslotbackend.gd index 9c6278cb..e5543461 100644 --- a/src/assets/ui/tasks/container/itemslotbackend.gd +++ b/src/assets/ui/tasks/container/itemslotbackend.gd @@ -19,8 +19,6 @@ func set_in_hand(ui_data_pass, index:int):#This the crucial function puppetsync func set_path():#Give the item its location so it cna remove itself and add to other location var item = frontend.get_child(1) var self_path = get_parent().get_path() - print(get_parent().get_path()) - print(item.get_path()) item.item_location = self_path item.item_from_container = true From 04185c2006b58a9e7a841ab0ad72e1c0bfcc6c02 Mon Sep 17 00:00:00 2001 From: Zapzoop0099 Date: Thu, 4 Feb 2021 15:28:21 +0530 Subject: [PATCH 03/18] Fixed both bugs proposed by damjan94 and NiceMicro --- src/assets/items/item.gd | 3 +- src/assets/maps/test/Container.gd | 45 ----------- src/assets/maps/test/container_area.gd | 80 +++++++++++++++++++ src/assets/maps/test/test.tscn | 3 +- src/assets/player/item_handler.gd | 3 + src/assets/player/player.gd | 8 +- src/assets/ui/tasks/container/container.gd | 10 ++- src/assets/ui/tasks/container/container.tscn | 1 - .../ui/tasks/container/itemslotbackend.gd | 2 + 9 files changed, 101 insertions(+), 54 deletions(-) delete mode 100644 src/assets/maps/test/Container.gd create mode 100644 src/assets/maps/test/container_area.gd diff --git a/src/assets/items/item.gd b/src/assets/items/item.gd index 40ba298b..597dd5b8 100644 --- a/src/assets/items/item.gd +++ b/src/assets/items/item.gd @@ -14,7 +14,6 @@ var being_picked_up: bool var item_location:NodePath #The location of the item var item_from_container:bool #Checks item is from container or not - func _ready() -> void: # Wait another frame for map to finish setting up yield(get_tree(), "idle_frame") @@ -55,6 +54,8 @@ func dropped() -> void: global_position = holding_player.global_position - map_items.global_position being_held = false holding_player = null + if item_from_container: + item_from_container = false set_collision_layer_bit(4, true) func _on_MouseArea_mouse_entered() -> void: diff --git a/src/assets/maps/test/Container.gd b/src/assets/maps/test/Container.gd deleted file mode 100644 index 4993c55a..00000000 --- a/src/assets/maps/test/Container.gd +++ /dev/null @@ -1,45 +0,0 @@ -extends Area2D - -#export(Resource) var interact_resource -var pressed:bool = false -var interacting:bool = false -var interactor:Dictionary -#TODO:Add a shader - - -func _ready(): - #interact_resource.init_resource(self) - pass - -func reset() -> void: #Resets the node - interacting = false - pressed = false - interactor.clear() - -func register(body) -> void:#Register a body - interactor[body.id] = body.get_path() - interactor["bool"] = true - return - -func _input(event):#Checks that the player presses the key is in interacting dic - if event.is_action_pressed("interact") and interactor.keys().has(Network.get_my_id()): - interacting = true - pressed = true - UIManager.open_ui("container", interactor) - #interact(interactor) - -func _on_Container_body_entered(_body):#Check wether the body is player or not and record the player - for bodies in get_overlapping_bodies(): - if bodies.is_in_group("players"): - if interactor.empty(): - register(bodies) - else: - return - - -func _on_Container_body_exited(_body):#Closes the ui - UIManager.close_ui("container") - reset() - -#func interact(interactor):#The main func to pass data -# interact_resource.interact(self,interactor) diff --git a/src/assets/maps/test/container_area.gd b/src/assets/maps/test/container_area.gd new file mode 100644 index 00000000..6a0b1a4b --- /dev/null +++ b/src/assets/maps/test/container_area.gd @@ -0,0 +1,80 @@ +extends Area2D + +#export(Resource) var interact_resource +var interacting:bool = false +var interactor:Dictionary +var player +#TODO:Add a shader + + +func _ready(): + #interact_resource.init_resource(self) + pass + +func reset() -> void: #Resets the node + interacting = false + interactor.clear() + +func register(body) -> void:#Register a body + interactor[body.id] = body.get_path() + interactor["bool"] = true + return + +func _input(event):#Checks that the player presses the key is in interacting dic + if event.is_action_pressed("interact") and interactor.keys().has(Network.get_my_id()) and interacting: + print("true _input") + UIManager.open_ui("container", interactor) + player.can_pickup = false + #interact(interactor) + +func _on_Container_body_entered(_body):#Check wether the body is player or not and record the player + for bodies in get_overlapping_bodies(): + if bodies.is_in_group("players"): + if can_interact(): + player = bodies + register(bodies) + + +func _on_Container_body_exited(body):#Closes the ui + if body.is_in_group("players"): + body.can_pickup = true + UIManager.close_ui("container") + reset() + +#func interact(interactor):#The main func to pass data +# interact_resource.interact(self,interactor) + +func can_interact() -> bool: + if not interactor.empty(): + interacting = false + return false + else: + interacting = true + return true + #if body.item_handler.has_item() and body.item_handler._target_item != null: + # body.item_handler.drop_item_external() + # body.item_handler._target_item.can_pickup_with_mouse = false + # interacting = true + # return true + #if body.item_handler.has_item() and body.item_handler._target_item == null and body.item_handler.pickup_enabled == false: + # interacting = false + # return false + + ################################# + #if interactor.empty() and body.item_handler._target_item != null: + # interacting =true + # body.item_handler._target_item.can_pickup_with_mouse = false + # return true + #elif interactor.empty() and body.item_handler._target_item == null: + # interacting = true +# return true + + #if interactor.empty() and body.item_handler._target_item == null and body.item_handler.pickup_enabled == false and body.item_handler.has_item() or body.item_handler.has_item() == false: + # interacting = true + # return true + #elif interactor.empty() and body.item_handler._target_item != null and body.item_handler.pickup_enabled == false and body.item_handler.has_item() or body.item_handler.has_item() == false: + # interacting = false + # return false + #else: + # interacting = false + # return false diff --git a/src/assets/maps/test/test.tscn b/src/assets/maps/test/test.tscn index 4e7f4c30..41c810d7 100644 --- a/src/assets/maps/test/test.tscn +++ b/src/assets/maps/test/test.tscn @@ -11,12 +11,13 @@ [ext_resource path="res://addons/opensusinteraction/resources/interact/interact.gd" type="Script" id=9] [ext_resource path="res://addons/opensusinteraction/resources/interactmap/interactmap.gd" type="Script" id=10] [ext_resource path="res://addons/opensusinteraction/resources/interactui/interactui.gd" type="Script" id=11] -[ext_resource path="res://assets/maps/test/Container.gd" type="Script" id=12] +[ext_resource path="res://assets/maps/test/container_area.gd" type="Script" id=12] [ext_resource path="res://assets/items/battery.tscn" type="PackedScene" id=13] [ext_resource path="res://assets/items/wrench.tscn" type="PackedScene" id=14] [ext_resource path="res://assets/maps/map.gd" type="Script" id=15] [ext_resource path="res://assets/player/textures/characters/black/black-proto-1.png" type="Texture" id=16] + [sub_resource type="Resource" id=1] resource_local_to_scene = true resource_name = "InteractMap" diff --git a/src/assets/player/item_handler.gd b/src/assets/player/item_handler.gd index 90e0bed0..590d548c 100644 --- a/src/assets/player/item_handler.gd +++ b/src/assets/player/item_handler.gd @@ -134,3 +134,6 @@ func _on_Player_dead() -> void: _target_item.get_node("SpritePosition/ItemSprite").material.set_shader_param("line_color", Color.transparent) in_pickup_range = [] _target_item = null + +func drop_item_external(): + emit_signal("main_player_dropped_item") diff --git a/src/assets/player/player.gd b/src/assets/player/player.gd index e2f551bf..93a1cefc 100644 --- a/src/assets/player/player.gd +++ b/src/assets/player/player.gd @@ -44,6 +44,7 @@ var last_received_input: int = 0 # velocities for movement prediciton. The values are stored as Arrays of # movement and previous velocity. var input_queue: Array = [] +var can_pickup = true func _ready(): # Reparent ItemHandler to Skeleton Node2D @@ -77,8 +78,11 @@ func _ready(): customizePlayer(id) func _input(event: InputEvent) -> void: - # Item Handler does not receive input as a child of a Viewport - item_handler._input(event) + if can_pickup == true: + # Item Handler does not receive input as a child of a Viewport + item_handler._input(event) + else: + return func setName(newName): ourname = newName diff --git a/src/assets/ui/tasks/container/container.gd b/src/assets/ui/tasks/container/container.gd index e49adedf..edc56d94 100644 --- a/src/assets/ui/tasks/container/container.gd +++ b/src/assets/ui/tasks/container/container.gd @@ -4,8 +4,6 @@ onready var grid = $background/conatainergrid const slot_scene = preload("res://assets/ui/tasks/container/itemslot.tscn") -var pressed:bool= false - export(int) var slots #var slots_data:Array @@ -14,14 +12,18 @@ func _ready(): if grid.get_child(0) == null: rpc_id(1,"set_slot_server") #Connects with GameManager to record game transition +# warning-ignore:return_value_discarded GameManager.connect('state_changed', self, '_on_state_changed') - func _process(_delta):#Called every frame to check interaction status - if ui_data.has("bool"): + if not ui_data.empty(): rpc_id(1, "pass_data_server", ui_data) func _on_closebutton_pressed():#Resets the data which is passed + for key in ui_data.keys(): + if typeof(key) == TYPE_INT: + var player = ui_data[key] + get_tree().get_root().get_node(player).can_pickup = true UIManager.close_ui("container") rpc_id(1, "reset_server") diff --git a/src/assets/ui/tasks/container/container.tscn b/src/assets/ui/tasks/container/container.tscn index e287629b..b40c83af 100644 --- a/src/assets/ui/tasks/container/container.tscn +++ b/src/assets/ui/tasks/container/container.tscn @@ -52,5 +52,4 @@ columns = 4 __meta__ = { "_edit_use_anchors_": false } -[connection signal="mouse_entered" from="." to="." method="_on_conatiner_mouse_entered"] [connection signal="pressed" from="background/upperoverlay/closebutton" to="." method="_on_closebutton_pressed"] diff --git a/src/assets/ui/tasks/container/itemslotbackend.gd b/src/assets/ui/tasks/container/itemslotbackend.gd index e5543461..6e0c3c0d 100644 --- a/src/assets/ui/tasks/container/itemslotbackend.gd +++ b/src/assets/ui/tasks/container/itemslotbackend.gd @@ -14,6 +14,8 @@ func set_in_hand(ui_data_pass, index:int):#This the crucial function for key in ui_data_pass.keys(): if typeof(key) == TYPE_INT:#Filters the ui_data var player = ui_data_pass[key] + if get_tree().get_root().get_node(player).item_handler.get_child_count() > 0: + get_tree().get_root().get_node(player).item_handler.drop_item_external() get_tree().get_root().get_node(player).item_handler._test_pickup(item) puppetsync func set_path():#Give the item its location so it cna remove itself and add to other location From 68548dba5ab5ce24983271e0b211b5ace8f6a361 Mon Sep 17 00:00:00 2001 From: Zapzoop0099 Date: Sat, 6 Feb 2021 22:09:53 +0530 Subject: [PATCH 04/18] implemented rest of the changes --- src/assets/autoload/uimanager.gd | 6 ++-- src/assets/main/maps.gd | 2 +- src/assets/maps/test/container_area.gd | 32 ++----------------- src/assets/player/item_handler.gd | 3 -- src/assets/ui/tasks/container/container.gd | 26 +++++++-------- src/assets/ui/tasks/container/itemslot.gd | 5 --- .../ui/tasks/container/itemslotbackend.gd | 14 ++++---- src/assets/ui/uicontroller/uicontroller.gd | 16 +++------- 8 files changed, 30 insertions(+), 74 deletions(-) diff --git a/src/assets/autoload/uimanager.gd b/src/assets/autoload/uimanager.gd index 20f56075..94e7410a 100644 --- a/src/assets/autoload/uimanager.gd +++ b/src/assets/autoload/uimanager.gd @@ -36,7 +36,7 @@ signal close_ui(ui_name, free) signal instance_ui(ui_name, ui_data) signal update_ui(ui_name, ui_data) signal free_ui(ui_name) -signal pre_ins(ui_name) +signal pre_instance(ui_name) signal close_all_ui() func _ready(): @@ -87,10 +87,10 @@ func free_ui(ui_name: String): push_error("free_ui() called with invalid ui name " + ui_name) emit_signal("free_ui", ui_name) -func pre_ins(ui_name:String): +func pre_instance(ui_name:String): if not ui_list.keys().has(ui_name): push_error("pre_ins() called with invalid ui name " + ui_name) - emit_signal("pre_ins", ui_name) + emit_signal("pre_instance", ui_name) func close_all_ui(free: bool = false): emit_signal("close_all_ui", free) diff --git a/src/assets/main/maps.gd b/src/assets/main/maps.gd index 31d5346b..042cee99 100644 --- a/src/assets/main/maps.gd +++ b/src/assets/main/maps.gd @@ -111,4 +111,4 @@ func load_map_info_resources() -> Array: return resources func init_all_tasks(): - UIManager.pre_ins("container") + UIManager.pre_instance("container") diff --git a/src/assets/maps/test/container_area.gd b/src/assets/maps/test/container_area.gd index 6a0b1a4b..2ce2e1f3 100644 --- a/src/assets/maps/test/container_area.gd +++ b/src/assets/maps/test/container_area.gd @@ -3,7 +3,7 @@ extends Area2D #export(Resource) var interact_resource var interacting:bool = false var interactor:Dictionary -var player +var player = null #TODO:Add a shader @@ -13,16 +13,15 @@ func _ready(): func reset() -> void: #Resets the node interacting = false + player = null interactor.clear() func register(body) -> void:#Register a body interactor[body.id] = body.get_path() - interactor["bool"] = true return func _input(event):#Checks that the player presses the key is in interacting dic if event.is_action_pressed("interact") and interactor.keys().has(Network.get_my_id()) and interacting: - print("true _input") UIManager.open_ui("container", interactor) player.can_pickup = false #interact(interactor) @@ -51,30 +50,3 @@ func can_interact() -> bool: else: interacting = true return true - #if body.item_handler.has_item() and body.item_handler._target_item != null: - # body.item_handler.drop_item_external() - # body.item_handler._target_item.can_pickup_with_mouse = false - # interacting = true - # return true - #if body.item_handler.has_item() and body.item_handler._target_item == null and body.item_handler.pickup_enabled == false: - # interacting = false - # return false - - ################################# - #if interactor.empty() and body.item_handler._target_item != null: - # interacting =true - # body.item_handler._target_item.can_pickup_with_mouse = false - # return true - #elif interactor.empty() and body.item_handler._target_item == null: - # interacting = true -# return true - - #if interactor.empty() and body.item_handler._target_item == null and body.item_handler.pickup_enabled == false and body.item_handler.has_item() or body.item_handler.has_item() == false: - # interacting = true - # return true - #elif interactor.empty() and body.item_handler._target_item != null and body.item_handler.pickup_enabled == false and body.item_handler.has_item() or body.item_handler.has_item() == false: - # interacting = false - # return false - #else: - # interacting = false - # return false diff --git a/src/assets/player/item_handler.gd b/src/assets/player/item_handler.gd index 590d548c..90e0bed0 100644 --- a/src/assets/player/item_handler.gd +++ b/src/assets/player/item_handler.gd @@ -134,6 +134,3 @@ func _on_Player_dead() -> void: _target_item.get_node("SpritePosition/ItemSprite").material.set_shader_param("line_color", Color.transparent) in_pickup_range = [] _target_item = null - -func drop_item_external(): - emit_signal("main_player_dropped_item") diff --git a/src/assets/ui/tasks/container/container.gd b/src/assets/ui/tasks/container/container.gd index edc56d94..c4792347 100644 --- a/src/assets/ui/tasks/container/container.gd +++ b/src/assets/ui/tasks/container/container.gd @@ -5,7 +5,6 @@ onready var grid = $background/conatainergrid const slot_scene = preload("res://assets/ui/tasks/container/itemslot.tscn") export(int) var slots -#var slots_data:Array func _ready(): #When the first player interacts then called this func to all others so everyone get the same scene set @@ -27,7 +26,7 @@ func _on_closebutton_pressed():#Resets the data which is passed UIManager.close_ui("container") rpc_id(1, "reset_server") -puppetsync func set_slot(): +puppetsync func set_slot() -> void: #Place where the scene is built for num in range(0, slots): var slot = slot_scene.instance() @@ -36,50 +35,49 @@ puppetsync func set_slot(): slot.get_child(0).frontend = slot grid.add_child(slot) -puppetsync func pass_data(data:Dictionary):#Pass data to child +puppetsync func pass_data(data:Dictionary) -> void:#Pass data to child for slot in grid.get_children(): slot.ui_data = data -func erase_data():#Erase data from child +func erase_data() -> void:#Erase data from child for slot in grid.get_children(): slot.ui_data.clear() -puppetsync func erase_child():#erases all child +puppetsync func erase_children() -> void:#erases all child for child in grid.get_children(): child.queue_free() -puppetsync func reset():#Clears all the data +puppetsync func reset() -> void:#Clears all the data erase_data() ui_data.clear() - -# + func _on_state_changed(_old_state, new_state) -> void:#resets the task when state changes match new_state: GameManager.State.Normal: if grid.get_child(0) == null: rpc_id(1,"set_slot_server") GameManager.State.Lobby: - rpc_id(1, "erase_child_server") + rpc_id(1, "erase_children_server") rpc_id(1, "reset_server") -remotesync func set_slot_server(): +remotesync func set_slot_server() -> void: if not get_tree().is_network_server(): return rpc("set_slot") -remotesync func pass_data_server(data:Dictionary): +remotesync func pass_data_server(data:Dictionary) -> void: if not get_tree().is_network_server(): return rpc("pass_data", data) -remotesync func reset_server(): +remotesync func reset_server() -> void: if not get_tree().is_network_server(): return rpc("reset") -remotesync func erase_child_server(): +remotesync func erase_children_server() -> void: if not get_tree().is_network_server(): return - rpc("erase_child") + rpc("erase_children") diff --git a/src/assets/ui/tasks/container/itemslot.gd b/src/assets/ui/tasks/container/itemslot.gd index d48092fc..f1f01efc 100644 --- a/src/assets/ui/tasks/container/itemslot.gd +++ b/src/assets/ui/tasks/container/itemslot.gd @@ -3,14 +3,11 @@ extends MarginContainerBase var mouse_entered:bool var index:int -#TODO: Set a randomizer - signal input_received(ui_data, index) func _ready(): pass - func _on_itemslot_mouse_entered(): if get_child_count() == 1: return @@ -19,7 +16,6 @@ func _on_itemslot_mouse_entered(): get_child(1).can_pickup_with_mouse = true mouse_entered = true - func _on_itemslot_mouse_exited(): if get_child_count() == 1: return @@ -28,7 +24,6 @@ func _on_itemslot_mouse_exited(): get_child(1).can_pickup_with_mouse = false mouse_entered = false - func _on_itemslot_gui_input(event): if event is InputEventMouseButton and event.pressed and event.button_index == BUTTON_LEFT and mouse_entered == true: if get_child(1) != null: diff --git a/src/assets/ui/tasks/container/itemslotbackend.gd b/src/assets/ui/tasks/container/itemslotbackend.gd index 6e0c3c0d..24d291b7 100644 --- a/src/assets/ui/tasks/container/itemslotbackend.gd +++ b/src/assets/ui/tasks/container/itemslotbackend.gd @@ -2,33 +2,33 @@ extends Node var frontend = null +#TODO: Set a randomizer + func _ready(): frontend.connect("input_received", self, "on_input_received") -func set_in_hand(ui_data_pass, index:int):#This the crucial function +func set_in_hand(ui_data_pass, index:int) -> void:#This the crucial function if not frontend.index == index: return else: var item = frontend.get_child(1) - #By only this the item from the itemslot get transferredd to hand + #By only this the item from the itemslot get transferred to hand for key in ui_data_pass.keys(): if typeof(key) == TYPE_INT:#Filters the ui_data var player = ui_data_pass[key] - if get_tree().get_root().get_node(player).item_handler.get_child_count() > 0: - get_tree().get_root().get_node(player).item_handler.drop_item_external() get_tree().get_root().get_node(player).item_handler._test_pickup(item) -puppetsync func set_path():#Give the item its location so it cna remove itself and add to other location +puppetsync func set_path() -> void:#Give the item its location so it can remove itself and add to other location var item = frontend.get_child(1) var self_path = get_parent().get_path() item.item_location = self_path item.item_from_container = true -func on_input_received(ui_data:Dictionary, index:int): +func on_input_received(ui_data:Dictionary, index:int) -> void: rpc_id(1, "set_server") set_in_hand(ui_data,index) -remotesync func set_server(): +remotesync func set_server() -> void: if not get_tree().is_network_server(): return var id: int = get_tree().get_rpc_sender_id() diff --git a/src/assets/ui/uicontroller/uicontroller.gd b/src/assets/ui/uicontroller/uicontroller.gd index 3f4ec2f9..50a526a6 100644 --- a/src/assets/ui/uicontroller/uicontroller.gd +++ b/src/assets/ui/uicontroller/uicontroller.gd @@ -24,7 +24,7 @@ func _ready(): # warning-ignore:return_value_discarded UIManager.connect("close_all_ui", self, "close_all_ui") # warning-ignore:return_value_discarded - UIManager.connect("pre_ins", self, "pre_ins") + UIManager.connect("pre_instance", self, "pre_instance") var err = config.load("user://settings.cfg") if err == OK: @@ -131,15 +131,9 @@ func get_child_node_names() -> Array: name_list.append(i.name) return name_list -func pre_ins(ui_name: String): +func pre_instance(ui_name: String):#Make the ui to be in active state when a game is started update_instanced_uis() - if not ui_list.keys().has(ui_name): + if instanced_uis.keys().has(ui_name): return - var new_ui = ui_list[ui_name].scene.instance() - new_ui.name = ui_name - instanced_uis[ui_name] = new_ui - add_child(new_ui) - if new_ui.has_method("base_close"): - new_ui.base_close() - if new_ui.has_method("close"): - new_ui.close() + instance_ui(ui_name) + close_ui(ui_name) From 8d235b3f7834a8979883b577b56ef3a644fac40f Mon Sep 17 00:00:00 2001 From: nicemicro Date: Wed, 10 Feb 2021 18:56:23 +0900 Subject: [PATCH 05/18] added the chemical cabinet and UI opening using the interaction resource --- src/assets/maps/test/test.tscn | 68 ++++++++++++++++++- .../maps/test/textures/chemicals-cabinet.png | 3 + .../textures/chemicals-cabinet.png.import | 34 ++++++++++ 3 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 src/assets/maps/test/textures/chemicals-cabinet.png create mode 100644 src/assets/maps/test/textures/chemicals-cabinet.png.import diff --git a/src/assets/maps/test/test.tscn b/src/assets/maps/test/test.tscn index 41c810d7..d1b84d77 100644 --- a/src/assets/maps/test/test.tscn +++ b/src/assets/maps/test/test.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=41 format=2] +[gd_scene load_steps=47 format=2] [ext_resource path="res://assets/common/textures/icons/spawnpad.png" type="Texture" id=1] [ext_resource path="res://assets/maps/common/dynamic/testdoor/testdoor.tscn" type="PackedScene" id=2] @@ -16,7 +16,7 @@ [ext_resource path="res://assets/items/wrench.tscn" type="PackedScene" id=14] [ext_resource path="res://assets/maps/map.gd" type="Script" id=15] [ext_resource path="res://assets/player/textures/characters/black/black-proto-1.png" type="Texture" id=16] - +[ext_resource path="res://assets/maps/test/textures/chemicals-cabinet.png" type="Texture" id=17] [sub_resource type="Resource" id=1] resource_local_to_scene = true @@ -256,6 +256,60 @@ map_resource = SubResource( 18 ) [sub_resource type="RectangleShape2D" id=24] extents = Vector2( 24, 24 ) +[sub_resource type="Resource" id=25] +resource_local_to_scene = true +resource_name = "InteractMap" +script = ExtResource( 10 ) +interact_with = NodePath("") +interact_data = { + +} +advanced/network_sync = false + +[sub_resource type="Resource" id=26] +resource_local_to_scene = true +resource_name = "InteractUI" +script = ExtResource( 11 ) +ui_name = "container" +ui_data = { + +} +action = 0 +advanced/reinstance = false +advanced/free_on_close = false + +[sub_resource type="Resource" id=27] +resource_local_to_scene = true +resource_name = "InteractTask" +script = ExtResource( 8 ) +task_text = "Chemicals Cabinet" +random_numbers = 2 +task_id = -1 +ui_resource = SubResource( 26 ) +outputs/toggle_map_interactions = false +is_task_global = true + +[sub_resource type="Resource" id=28] +resource_local_to_scene = true +resource_name = "InteractUI" +script = ExtResource( 11 ) +ui_name = "" +ui_data = { + +} +action = 0 +advanced/reinstance = false +advanced/free_on_close = false + +[sub_resource type="Resource" id=29] +resource_local_to_scene = true +resource_name = "Interact" +script = ExtResource( 9 ) +interact_type = 0 +task_resource = SubResource( 27 ) +ui_resource = SubResource( 28 ) +map_resource = SubResource( 25 ) + [node name="test" type="YSort"] script = ExtResource( 15 ) @@ -485,6 +539,16 @@ position = Vector2( 0, 3.8147e-06 ) scale = Vector2( 0.625, 0.625 ) texture = ExtResource( 16 ) +[node name="ChemicalCabinet" parent="Interactive/Tasks" instance=ExtResource( 5 )] +position = Vector2( 235, -155 ) +interact_resource = SubResource( 29 ) +display_text = "chemicals" + +[node name="Sprite" type="Sprite" parent="Interactive/Tasks/ChemicalCabinet"] +position = Vector2( 0, -35 ) +scale = Vector2( 0.07, 0.07 ) +texture = ExtResource( 17 ) + [node name="Props" type="YSort" parent="."] [node name="Corpses" type="YSort" parent="Props"] diff --git a/src/assets/maps/test/textures/chemicals-cabinet.png b/src/assets/maps/test/textures/chemicals-cabinet.png new file mode 100644 index 00000000..a5dc6c3a --- /dev/null +++ b/src/assets/maps/test/textures/chemicals-cabinet.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:123dd793397b2928b11fd2e17f97ebc91ab41a8cb827dc1eb0f93cef25c72ff7 +size 95069 diff --git a/src/assets/maps/test/textures/chemicals-cabinet.png.import b/src/assets/maps/test/textures/chemicals-cabinet.png.import new file mode 100644 index 00000000..a514ec83 --- /dev/null +++ b/src/assets/maps/test/textures/chemicals-cabinet.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/chemicals-cabinet.png-bb5d6bb3670a6d68311a67228ccf64cf.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/maps/test/textures/chemicals-cabinet.png" +dest_files=[ "res://.import/chemicals-cabinet.png-bb5d6bb3670a6d68311a67228ccf64cf.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 From 409bc6efefb59c4a73d5528ece4a22b359c8d3f5 Mon Sep 17 00:00:00 2001 From: Zapzoop0099 Date: Sat, 27 Feb 2021 13:22:38 +0530 Subject: [PATCH 06/18] Fixed merge mistakes --- src/assets/maps/test/test.tscn | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/assets/maps/test/test.tscn b/src/assets/maps/test/test.tscn index feb56c2e..354981ab 100644 --- a/src/assets/maps/test/test.tscn +++ b/src/assets/maps/test/test.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=35 format=2] +[gd_scene load_steps=36 format=2] [ext_resource path="res://assets/common/textures/icons/spawnpad.png" type="Texture" id=1] [ext_resource path="res://assets/maps/common/dynamic/testdoor/testdoor.tscn" type="PackedScene" id=2] @@ -16,7 +16,8 @@ [ext_resource path="res://assets/items/wrench.tscn" type="PackedScene" id=14] [ext_resource path="res://assets/maps/map.gd" type="Script" id=15] [ext_resource path="res://assets/maps/test/tasks/clockset/interactpointclockset.tres" type="Resource" id=16] -[ext_resource path="res://assets/maps/test/textures/chemicals-cabinet.png" type="Texture" id=17] +[ext_resource path="res://assets/maps/test/container_area.gd" type="Script" id=18] +[ext_resource path="res://assets/maps/test/textures/chemicals-cabinet.png" type="Texture" id=19] [sub_resource type="Resource" id=1] resource_local_to_scene = true @@ -132,7 +133,7 @@ ui_resource = SubResource( 10 ) map_resource = SubResource( 7 ) [sub_resource type="RectangleShape2D" id=12] -extents = Vector2( 24, 24 ) +extents = Vector2( 48, 48 ) [sub_resource type="Resource" id=13] resource_local_to_scene = true @@ -405,16 +406,18 @@ position = Vector2( -96.3763, 93.3395 ) [node name="Containers" type="YSort" parent="Interactive/Tasks"] [node name="Container" type="Area2D" parent="Interactive/Tasks/Containers"] -position = Vector2( 232, 56 ) -script = ExtResource( 12 ) +position = Vector2( 224, 56 ) +script = ExtResource( 18 ) + +[node name="Sprite" type="Sprite" parent="Interactive/Tasks/Containers/Container"] +position = Vector2( -8, 0 ) +scale = Vector2( 0.1, 0.1 ) +texture = ExtResource( 19 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="Interactive/Tasks/Containers/Container"] +position = Vector2( -8, 0 ) shape = SubResource( 12 ) -[node name="Sprite" type="Sprite" parent="Interactive/Tasks/Containers/Container"] -position = Vector2( 0, 3.8147e-06 ) -scale = Vector2( 0.625, 0.625 ) - [node name="ChemicalCabinet" parent="Interactive/Tasks" instance=ExtResource( 5 )] position = Vector2( 235, -155 ) interact_resource = SubResource( 17 ) @@ -423,7 +426,7 @@ display_text = "chemicals" [node name="Sprite" type="Sprite" parent="Interactive/Tasks/ChemicalCabinet"] position = Vector2( 0, -35 ) scale = Vector2( 0.07, 0.07 ) -texture = ExtResource( 17 ) +texture = ExtResource( 19 ) [node name="Props" type="YSort" parent="."] From 35308450ceb6293b367c20d688707b5b4bda12fa Mon Sep 17 00:00:00 2001 From: Zapzoop0099 Date: Sun, 28 Feb 2021 09:10:43 +0530 Subject: [PATCH 07/18] Custom task resource --- .../resources/interact/interact.tres | 4 +-- .../resources/interacttask/interacttask.gd | 2 +- src/assets/maps/test/container_area.gd | 11 ++++---- src/assets/maps/test/test.tscn | 4 ++- .../tasks/container/containerinteracttask.gd | 13 ++++++++++ .../container/containerinteracttask.tres | 25 +++++++++++++++++++ 6 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 src/assets/ui/tasks/container/containerinteracttask.gd create mode 100644 src/assets/ui/tasks/container/containerinteracttask.tres diff --git a/src/addons/opensusinteraction/resources/interact/interact.tres b/src/addons/opensusinteraction/resources/interact/interact.tres index db49393b..41dd2e67 100644 --- a/src/addons/opensusinteraction/resources/interact/interact.tres +++ b/src/addons/opensusinteraction/resources/interact/interact.tres @@ -20,7 +20,7 @@ advanced/network_sync = false resource_local_to_scene = true resource_name = "InteractUI" script = ExtResource( 4 ) -ui_name = "" +ui_name = "container" ui_data = { } @@ -32,7 +32,7 @@ advanced/free_on_close = false resource_local_to_scene = true resource_name = "InteractTask" script = ExtResource( 5 ) -task_text = "" +task_text = "container" ui_resource = SubResource( 2 ) outputs/toggle_map_interactions = false outputs/output_map_interactions = [ ] diff --git a/src/addons/opensusinteraction/resources/interacttask/interacttask.gd b/src/addons/opensusinteraction/resources/interacttask/interacttask.gd index 0f6e2df8..b04851b6 100644 --- a/src/addons/opensusinteraction/resources/interacttask/interacttask.gd +++ b/src/addons/opensusinteraction/resources/interacttask/interacttask.gd @@ -414,7 +414,7 @@ func is_task_completed(player_id: int) -> bool: return get_task_state(player_id) == TaskManager.task_state.COMPLETED func get_task_state(player_id: int) -> int: - player_id = normalize_player_id(player_id) + player_id= normalize_player_id(player_id) if not is_player_assigned(player_id): #this player has not been assigned this task return TaskManager.task_state.INVALID diff --git a/src/assets/maps/test/container_area.gd b/src/assets/maps/test/container_area.gd index 2ce2e1f3..46a4c7de 100644 --- a/src/assets/maps/test/container_area.gd +++ b/src/assets/maps/test/container_area.gd @@ -1,6 +1,6 @@ extends Area2D -#export(Resource) var interact_resource +export(Resource) var interact_resource var interacting:bool = false var interactor:Dictionary var player = null @@ -8,7 +8,7 @@ var player = null func _ready(): - #interact_resource.init_resource(self) + interact_resource.init_resource(self) pass func reset() -> void: #Resets the node @@ -22,9 +22,8 @@ func register(body) -> void:#Register a body func _input(event):#Checks that the player presses the key is in interacting dic if event.is_action_pressed("interact") and interactor.keys().has(Network.get_my_id()) and interacting: - UIManager.open_ui("container", interactor) player.can_pickup = false - #interact(interactor) + interact(interactor) func _on_Container_body_entered(_body):#Check wether the body is player or not and record the player for bodies in get_overlapping_bodies(): @@ -40,8 +39,8 @@ func _on_Container_body_exited(body):#Closes the ui UIManager.close_ui("container") reset() -#func interact(interactor):#The main func to pass data -# interact_resource.interact(self,interactor) +func interact(interactor):#The main func to pass data + interact_resource.interact(self,interactor) func can_interact() -> bool: if not interactor.empty(): diff --git a/src/assets/maps/test/test.tscn b/src/assets/maps/test/test.tscn index 354981ab..5768a05f 100644 --- a/src/assets/maps/test/test.tscn +++ b/src/assets/maps/test/test.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=36 format=2] +[gd_scene load_steps=37 format=2] [ext_resource path="res://assets/common/textures/icons/spawnpad.png" type="Texture" id=1] [ext_resource path="res://assets/maps/common/dynamic/testdoor/testdoor.tscn" type="PackedScene" id=2] @@ -16,6 +16,7 @@ [ext_resource path="res://assets/items/wrench.tscn" type="PackedScene" id=14] [ext_resource path="res://assets/maps/map.gd" type="Script" id=15] [ext_resource path="res://assets/maps/test/tasks/clockset/interactpointclockset.tres" type="Resource" id=16] +[ext_resource path="res://assets/ui/tasks/container/containerinteracttask.tres" type="Resource" id=17] [ext_resource path="res://assets/maps/test/container_area.gd" type="Script" id=18] [ext_resource path="res://assets/maps/test/textures/chemicals-cabinet.png" type="Texture" id=19] @@ -408,6 +409,7 @@ position = Vector2( -96.3763, 93.3395 ) [node name="Container" type="Area2D" parent="Interactive/Tasks/Containers"] position = Vector2( 224, 56 ) script = ExtResource( 18 ) +interact_resource = ExtResource( 17 ) [node name="Sprite" type="Sprite" parent="Interactive/Tasks/Containers/Container"] position = Vector2( -8, 0 ) diff --git a/src/assets/ui/tasks/container/containerinteracttask.gd b/src/assets/ui/tasks/container/containerinteracttask.gd new file mode 100644 index 00000000..b3479f6f --- /dev/null +++ b/src/assets/ui/tasks/container/containerinteracttask.gd @@ -0,0 +1,13 @@ +tool +extends InteractTask + + + + +func _ready(): + pass + +func _interact(_from: Node = null, _interact_data: Dictionary = {}): + var dic = Helpers.merge_dicts(_interact_data, get_task_data()) + ui_res.interact(_from, dic) + return false diff --git a/src/assets/ui/tasks/container/containerinteracttask.tres b/src/assets/ui/tasks/container/containerinteracttask.tres new file mode 100644 index 00000000..a884190d --- /dev/null +++ b/src/assets/ui/tasks/container/containerinteracttask.tres @@ -0,0 +1,25 @@ +[gd_resource type="Resource" load_steps=4 format=2] + +[ext_resource path="res://assets/ui/tasks/container/containerinteracttask.gd" type="Script" id=1] +[ext_resource path="res://addons/opensusinteraction/resources/interactui/interactui.gd" type="Script" id=2] + +[sub_resource type="Resource" id=1] +resource_local_to_scene = true +resource_name = "InteractUI" +script = ExtResource( 2 ) +ui_name = "container" +ui_data = { + +} +action = 0 +advanced/reinstance = false +advanced/free_on_close = false + +[resource] +resource_local_to_scene = true +script = ExtResource( 1 ) +task_text = "Container" +ui_resource = SubResource( 1 ) +outputs/toggle_map_interactions = false +outputs/output_map_interactions = [ ] +is_task_global = true From a8b3f170e533c280bfa39cec22eb040707af4ce9 Mon Sep 17 00:00:00 2001 From: Zapzoop0099 Date: Tue, 2 Mar 2021 11:31:15 +0530 Subject: [PATCH 08/18] Sync work --- .../resources/interactui/interactui.tres | 4 +- .../classes/ui/base/margincontainerbase.gd | 8 +- src/assets/maps/test/container_area.gd | 10 +-- src/assets/maps/test/test.tscn | 7 +- .../Resource/containerinteracttask.gd | 79 +++++++++++++++++++ .../containerintercattask.tres} | 8 +- src/assets/ui/tasks/container/container.gd | 69 +++++----------- src/assets/ui/tasks/container/container.tscn | 2 +- .../tasks/container/containerinteracttask.gd | 13 --- src/project.godot | 4 + 10 files changed, 122 insertions(+), 82 deletions(-) create mode 100644 src/assets/ui/tasks/container/Resource/containerinteracttask.gd rename src/assets/ui/tasks/container/{containerinteracttask.tres => Resource/containerintercattask.tres} (79%) delete mode 100644 src/assets/ui/tasks/container/containerinteracttask.gd diff --git a/src/addons/opensusinteraction/resources/interactui/interactui.tres b/src/addons/opensusinteraction/resources/interactui/interactui.tres index 6e0b03f9..4dbb680c 100644 --- a/src/addons/opensusinteraction/resources/interactui/interactui.tres +++ b/src/addons/opensusinteraction/resources/interactui/interactui.tres @@ -6,10 +6,10 @@ resource_local_to_scene = true resource_name = "InteractUI" script = ExtResource( 1 ) -ui_name = "" +ui_name = "container" ui_data = { } -action = 0 +action = 3 advanced/reinstance = false advanced/free_on_close = false diff --git a/src/assets/common/classes/ui/base/margincontainerbase.gd b/src/assets/common/classes/ui/base/margincontainerbase.gd index 7a4be0e0..dd23d19f 100644 --- a/src/assets/common/classes/ui/base/margincontainerbase.gd +++ b/src/assets/common/classes/ui/base/margincontainerbase.gd @@ -9,8 +9,8 @@ export (bool) var disable_movement var ui_data: Dictionary = {} func _init(): +# warning-ignore:return_value_discarded connect("visibility_changed", self, "_on_visibility_changed") - #called by ui system func base_open(): show() @@ -19,7 +19,7 @@ func base_open(): func base_close(): hide() -# warning-ignore:unused_argument + func _on_visibility_changed(): if not disable_movement: @@ -28,3 +28,7 @@ func _on_visibility_changed(): UIManager.ui_opened(menu_name) else: UIManager.ui_closed(menu_name) + +func get_res() -> Resource: + var res = TaskManager.get_task_resource(ui_data[TaskManager.TASK_ID_KEY]) + return res diff --git a/src/assets/maps/test/container_area.gd b/src/assets/maps/test/container_area.gd index 46a4c7de..d198298b 100644 --- a/src/assets/maps/test/container_area.gd +++ b/src/assets/maps/test/container_area.gd @@ -9,7 +9,7 @@ var player = null func _ready(): interact_resource.init_resource(self) - pass + interact_resource.update(self, {},interact_resource.actions.UPDATE) func reset() -> void: #Resets the node interacting = false @@ -23,7 +23,7 @@ func register(body) -> void:#Register a body func _input(event):#Checks that the player presses the key is in interacting dic if event.is_action_pressed("interact") and interactor.keys().has(Network.get_my_id()) and interacting: player.can_pickup = false - interact(interactor) + interact(interactor, interact_resource.actions.OPEN) func _on_Container_body_entered(_body):#Check wether the body is player or not and record the player for bodies in get_overlapping_bodies(): @@ -36,11 +36,11 @@ func _on_Container_body_entered(_body):#Check wether the body is player or not a func _on_Container_body_exited(body):#Closes the ui if body.is_in_group("players"): body.can_pickup = true - UIManager.close_ui("container") + interact({},interact_resource.actions.CLOSE) reset() -func interact(interactor):#The main func to pass data - interact_resource.interact(self,interactor) +func interact(ui_data:Dictionary = {}, value = interact_resource.actions.OPEN): + interact_resource.interact(self,ui_data, value) func can_interact() -> bool: if not interactor.empty(): diff --git a/src/assets/maps/test/test.tscn b/src/assets/maps/test/test.tscn index 5768a05f..118f900c 100644 --- a/src/assets/maps/test/test.tscn +++ b/src/assets/maps/test/test.tscn @@ -16,7 +16,7 @@ [ext_resource path="res://assets/items/wrench.tscn" type="PackedScene" id=14] [ext_resource path="res://assets/maps/map.gd" type="Script" id=15] [ext_resource path="res://assets/maps/test/tasks/clockset/interactpointclockset.tres" type="Resource" id=16] -[ext_resource path="res://assets/ui/tasks/container/containerinteracttask.tres" type="Resource" id=17] +[ext_resource path="res://assets/ui/tasks/container/Resource/containerintercattask.tres" type="Resource" id=17] [ext_resource path="res://assets/maps/test/container_area.gd" type="Script" id=18] [ext_resource path="res://assets/maps/test/textures/chemicals-cabinet.png" type="Texture" id=19] @@ -138,7 +138,6 @@ extents = Vector2( 48, 48 ) [sub_resource type="Resource" id=13] resource_local_to_scene = true -resource_name = "InteractMap" script = ExtResource( 10 ) interact_with = NodePath("") interact_data = { @@ -148,7 +147,6 @@ advanced/network_sync = false [sub_resource type="Resource" id=14] resource_local_to_scene = true -resource_name = "InteractUI" script = ExtResource( 11 ) ui_name = "container" ui_data = { @@ -160,7 +158,6 @@ advanced/free_on_close = false [sub_resource type="Resource" id=15] resource_local_to_scene = true -resource_name = "InteractTask" script = ExtResource( 8 ) task_text = "Chemicals Cabinet" ui_resource = SubResource( 14 ) @@ -170,7 +167,6 @@ is_task_global = true [sub_resource type="Resource" id=16] resource_local_to_scene = true -resource_name = "InteractUI" script = ExtResource( 11 ) ui_name = "" ui_data = { @@ -182,7 +178,6 @@ advanced/free_on_close = false [sub_resource type="Resource" id=17] resource_local_to_scene = true -resource_name = "Interact" script = ExtResource( 9 ) interact_type = 0 task_resource = SubResource( 15 ) diff --git a/src/assets/ui/tasks/container/Resource/containerinteracttask.gd b/src/assets/ui/tasks/container/Resource/containerinteracttask.gd new file mode 100644 index 00000000..b8027023 --- /dev/null +++ b/src/assets/ui/tasks/container/Resource/containerinteracttask.gd @@ -0,0 +1,79 @@ +tool +extends InteractTask + +enum actions {OPEN, INSTANCE, UPDATE, CLOSE} + +signal set_scene +signal erase_children + +func _init(): + add_networked_func("_server_set_scene", MultiplayerAPI.RPC_MODE_MASTER) + add_networked_func("_client_set_scene", MultiplayerAPI.RPC_MODE_PUPPET) + add_networked_func("_server_erase_children", MultiplayerAPI.RPC_MODE_MASTER) + add_networked_func("_client_erase_children", MultiplayerAPI.RPC_MODE_PUPPET) + + GameManager.connect("state_changed",self,"_on_state_changed") + +func set_action(value): + match value: + actions.OPEN: + ui_res.action = actions.OPEN + actions.INSTANCE: + ui_res.action = actions.INSTANCE + actions.UPDATE: + ui_res.action = actions.UPDATE + actions.CLOSE: + ui_res.action = actions.CLOSE + +func interact(_from: Node = null, _interact_data: Dictionary = {}, value = actions.OPEN): + if attached_to == null and _from != null: + attached_to = _from + if attached_to == null: + push_error("InteractTask resource trying to be used with no defined node") + if not is_player_assigned(Network.get_my_id()): + print("false1") + return + if is_task_completed(Network.get_my_id()): + print("false2") + return + + var dic = Helpers.merge_dicts(_interact_data, get_task_data()) + set_action(value) + print(dic) + ui_res.interact(_from, dic) + +func update(_from, data, value): + print("get interaction") + interact(_from, data, value) + print("next is sync") + sync_task() + + +func _sync_task(): + print("set_server") + #call("_server_set_scene", []) + task_rpc("_server_set_scene",[]) + + + +func _server_set_scene(_arr): + emit_signal("set_scene") + print("client one next") + task_rpc("_client_set_scene", []) + +func _server_erase_children(_dic): + emit_signal("erase_children") + task_rpc("_client_erase_children", []) + +func _client_set_scene(_dic): + print("emitted") + emit_signal("set_scene") + +func _client_erase_children(_dic): + emit_signal("erase_children") + + +func _on_state_changed(_old_state, new_state) -> void:#resets the task when state changes + match new_state: + GameManager.State.Lobby: + task_rpc("_server_erase_children", []) diff --git a/src/assets/ui/tasks/container/containerinteracttask.tres b/src/assets/ui/tasks/container/Resource/containerintercattask.tres similarity index 79% rename from src/assets/ui/tasks/container/containerinteracttask.tres rename to src/assets/ui/tasks/container/Resource/containerintercattask.tres index a884190d..49a04235 100644 --- a/src/assets/ui/tasks/container/containerinteracttask.tres +++ b/src/assets/ui/tasks/container/Resource/containerintercattask.tres @@ -1,12 +1,12 @@ [gd_resource type="Resource" load_steps=4 format=2] -[ext_resource path="res://assets/ui/tasks/container/containerinteracttask.gd" type="Script" id=1] -[ext_resource path="res://addons/opensusinteraction/resources/interactui/interactui.gd" type="Script" id=2] +[ext_resource path="res://addons/opensusinteraction/resources/interactui/interactui.gd" type="Script" id=1] +[ext_resource path="res://assets/ui/tasks/container/Resource/containerinteracttask.gd" type="Script" id=2] [sub_resource type="Resource" id=1] resource_local_to_scene = true resource_name = "InteractUI" -script = ExtResource( 2 ) +script = ExtResource( 1 ) ui_name = "container" ui_data = { @@ -17,7 +17,7 @@ advanced/free_on_close = false [resource] resource_local_to_scene = true -script = ExtResource( 1 ) +script = ExtResource( 2 ) task_text = "Container" ui_resource = SubResource( 1 ) outputs/toggle_map_interactions = false diff --git a/src/assets/ui/tasks/container/container.gd b/src/assets/ui/tasks/container/container.gd index c4792347..81be9be7 100644 --- a/src/assets/ui/tasks/container/container.gd +++ b/src/assets/ui/tasks/container/container.gd @@ -8,25 +8,19 @@ export(int) var slots func _ready(): #When the first player interacts then called this func to all others so everyone get the same scene set - if grid.get_child(0) == null: - rpc_id(1,"set_slot_server") #Connects with GameManager to record game transition # warning-ignore:return_value_discarded - GameManager.connect('state_changed', self, '_on_state_changed') - -func _process(_delta):#Called every frame to check interaction status - if not ui_data.empty(): - rpc_id(1, "pass_data_server", ui_data) +# GameManager.connect('state_changed', self, '_on_state_changed') + pass func _on_closebutton_pressed():#Resets the data which is passed for key in ui_data.keys(): if typeof(key) == TYPE_INT: var player = ui_data[key] get_tree().get_root().get_node(player).can_pickup = true - UIManager.close_ui("container") - rpc_id(1, "reset_server") + interact({},get_res().actions.CLOSE) -puppetsync func set_slot() -> void: +func _on_set_scene() -> void: #Place where the scene is built for num in range(0, slots): var slot = slot_scene.instance() @@ -35,49 +29,26 @@ puppetsync func set_slot() -> void: slot.get_child(0).frontend = slot grid.add_child(slot) -puppetsync func pass_data(data:Dictionary) -> void:#Pass data to child - for slot in grid.get_children(): - slot.ui_data = data - -func erase_data() -> void:#Erase data from child - for slot in grid.get_children(): - slot.ui_data.clear() - -puppetsync func erase_children() -> void:#erases all child +func _on_erase_children() -> void:#erases all child for child in grid.get_children(): child.queue_free() -puppetsync func reset() -> void:#Clears all the data - erase_data() - ui_data.clear() +#func _on_state_changed(_old_state, new_state) -> void:#resets the task when state changes +# match new_state: +# GameManager.State.Normal: +# if grid.get_child(0) == null: +# rpc_id(1,"set_slot_server") +# GameManager.State.Lobby: +# rpc_id(1, "erase_children_server") +# rpc_id(1, "reset_server") -func _on_state_changed(_old_state, new_state) -> void:#resets the task when state changes - match new_state: - GameManager.State.Normal: - if grid.get_child(0) == null: - rpc_id(1,"set_slot_server") - GameManager.State.Lobby: - rpc_id(1, "erase_children_server") - rpc_id(1, "reset_server") - -remotesync func set_slot_server() -> void: - if not get_tree().is_network_server(): - return - rpc("set_slot") - -remotesync func pass_data_server(data:Dictionary) -> void: - if not get_tree().is_network_server(): - return - rpc("pass_data", data) - -remotesync func reset_server() -> void: - if not get_tree().is_network_server(): - return - rpc("reset") -remotesync func erase_children_server() -> void: - if not get_tree().is_network_server(): - return - rpc("erase_children") +func interact(data:Dictionary = {}, value = get_res().actions.OPEN): + get_res().interact(self,{}, value) +func update(): +# warning-ignore:return_value_discarded + print("uupdate got recieve") + get_res().connect("set_scene", self, "_on_set_scene") + get_res().connect("erase_children", self, "_on_erase_children") diff --git a/src/assets/ui/tasks/container/container.tscn b/src/assets/ui/tasks/container/container.tscn index b40c83af..8264daad 100644 --- a/src/assets/ui/tasks/container/container.tscn +++ b/src/assets/ui/tasks/container/container.tscn @@ -3,7 +3,7 @@ [ext_resource path="res://assets/ui/tasks/container/container.gd" type="Script" id=1] [ext_resource path="res://assets/ui/tasks/container/Textures/Container.png" type="Texture" id=2] -[node name="conatiner" type="MarginContainer"] +[node name="container" type="MarginContainer"] margin_left = 128.0 margin_top = 48.0 margin_right = 859.0 diff --git a/src/assets/ui/tasks/container/containerinteracttask.gd b/src/assets/ui/tasks/container/containerinteracttask.gd deleted file mode 100644 index b3479f6f..00000000 --- a/src/assets/ui/tasks/container/containerinteracttask.gd +++ /dev/null @@ -1,13 +0,0 @@ -tool -extends InteractTask - - - - -func _ready(): - pass - -func _interact(_from: Node = null, _interact_data: Dictionary = {}): - var dic = Helpers.merge_dicts(_interact_data, get_task_data()) - ui_res.interact(_from, dic) - return false diff --git a/src/project.godot b/src/project.godot index 3c553492..4ef6e6a7 100644 --- a/src/project.godot +++ b/src/project.godot @@ -223,6 +223,10 @@ pointing/emulate_touch_from_mouse=true translations=PoolStringArray( "res://locale/de.po", "res://locale/el.po", "res://locale/en.po", "res://locale/es.po", "res://locale/fr.po", "res://locale/hu.po", "res://locale/ko.po", "res://locale/ro.po", "res://locale/sr.po", "res://locale/sv.po" ) locale_filter=[ 0, [ ] ] +[network] + +limits/debugger_stdout/max_chars_per_second=70000 + [rendering] quality/driver/driver_name="GLES2" From 8996940205b295f073c4cf706d4f0c918f2ee1d9 Mon Sep 17 00:00:00 2001 From: nicemicro Date: Tue, 2 Mar 2021 21:47:37 +0900 Subject: [PATCH 09/18] renaming files --- .../resource}/containerinteracttask.gd | 0 .../resource}/containerintercattask.tres | 2 +- src/assets/maps/test/test.tscn | 54 ++----------------- src/assets/ui/tasks/container/container.tscn | 4 +- .../Container.png => textures/container.png} | 0 .../container.png.import} | 6 +-- 6 files changed, 10 insertions(+), 56 deletions(-) rename src/assets/{ui/tasks/container/Resource => maps/test/tasks/container/resource}/containerinteracttask.gd (100%) rename src/assets/{ui/tasks/container/Resource => maps/test/tasks/container/resource}/containerintercattask.tres (84%) rename src/assets/ui/tasks/container/{Textures/Container.png => textures/container.png} (100%) rename src/assets/ui/tasks/container/{Textures/Container.png.import => textures/container.png.import} (68%) diff --git a/src/assets/ui/tasks/container/Resource/containerinteracttask.gd b/src/assets/maps/test/tasks/container/resource/containerinteracttask.gd similarity index 100% rename from src/assets/ui/tasks/container/Resource/containerinteracttask.gd rename to src/assets/maps/test/tasks/container/resource/containerinteracttask.gd diff --git a/src/assets/ui/tasks/container/Resource/containerintercattask.tres b/src/assets/maps/test/tasks/container/resource/containerintercattask.tres similarity index 84% rename from src/assets/ui/tasks/container/Resource/containerintercattask.tres rename to src/assets/maps/test/tasks/container/resource/containerintercattask.tres index 49a04235..220fcf9d 100644 --- a/src/assets/ui/tasks/container/Resource/containerintercattask.tres +++ b/src/assets/maps/test/tasks/container/resource/containerintercattask.tres @@ -1,7 +1,7 @@ [gd_resource type="Resource" load_steps=4 format=2] [ext_resource path="res://addons/opensusinteraction/resources/interactui/interactui.gd" type="Script" id=1] -[ext_resource path="res://assets/ui/tasks/container/Resource/containerinteracttask.gd" type="Script" id=2] +[ext_resource path="res://assets/maps/test/tasks/container/resource/containerinteracttask.gd" type="Script" id=2] [sub_resource type="Resource" id=1] resource_local_to_scene = true diff --git a/src/assets/maps/test/test.tscn b/src/assets/maps/test/test.tscn index 118f900c..84193cc7 100644 --- a/src/assets/maps/test/test.tscn +++ b/src/assets/maps/test/test.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=37 format=2] +[gd_scene load_steps=32 format=2] [ext_resource path="res://assets/common/textures/icons/spawnpad.png" type="Texture" id=1] [ext_resource path="res://assets/maps/common/dynamic/testdoor/testdoor.tscn" type="PackedScene" id=2] @@ -16,7 +16,7 @@ [ext_resource path="res://assets/items/wrench.tscn" type="PackedScene" id=14] [ext_resource path="res://assets/maps/map.gd" type="Script" id=15] [ext_resource path="res://assets/maps/test/tasks/clockset/interactpointclockset.tres" type="Resource" id=16] -[ext_resource path="res://assets/ui/tasks/container/Resource/containerintercattask.tres" type="Resource" id=17] +[ext_resource path="res://assets/maps/test/tasks/container/resource/containerintercattask.tres" type="Resource" id=17] [ext_resource path="res://assets/maps/test/container_area.gd" type="Script" id=18] [ext_resource path="res://assets/maps/test/textures/chemicals-cabinet.png" type="Texture" id=19] @@ -136,54 +136,6 @@ map_resource = SubResource( 7 ) [sub_resource type="RectangleShape2D" id=12] extents = Vector2( 48, 48 ) -[sub_resource type="Resource" id=13] -resource_local_to_scene = true -script = ExtResource( 10 ) -interact_with = NodePath("") -interact_data = { - -} -advanced/network_sync = false - -[sub_resource type="Resource" id=14] -resource_local_to_scene = true -script = ExtResource( 11 ) -ui_name = "container" -ui_data = { - -} -action = 0 -advanced/reinstance = false -advanced/free_on_close = false - -[sub_resource type="Resource" id=15] -resource_local_to_scene = true -script = ExtResource( 8 ) -task_text = "Chemicals Cabinet" -ui_resource = SubResource( 14 ) -outputs/toggle_map_interactions = false -outputs/output_map_interactions = [ ] -is_task_global = true - -[sub_resource type="Resource" id=16] -resource_local_to_scene = true -script = ExtResource( 11 ) -ui_name = "" -ui_data = { - -} -action = 0 -advanced/reinstance = false -advanced/free_on_close = false - -[sub_resource type="Resource" id=17] -resource_local_to_scene = true -script = ExtResource( 9 ) -interact_type = 0 -task_resource = SubResource( 15 ) -ui_resource = SubResource( 16 ) -map_resource = SubResource( 13 ) - [node name="test" type="YSort"] script = ExtResource( 15 ) @@ -417,7 +369,7 @@ shape = SubResource( 12 ) [node name="ChemicalCabinet" parent="Interactive/Tasks" instance=ExtResource( 5 )] position = Vector2( 235, -155 ) -interact_resource = SubResource( 17 ) +interact_resource = ExtResource( 17 ) display_text = "chemicals" [node name="Sprite" type="Sprite" parent="Interactive/Tasks/ChemicalCabinet"] diff --git a/src/assets/ui/tasks/container/container.tscn b/src/assets/ui/tasks/container/container.tscn index 8264daad..69691fc7 100644 --- a/src/assets/ui/tasks/container/container.tscn +++ b/src/assets/ui/tasks/container/container.tscn @@ -1,7 +1,9 @@ [gd_scene load_steps=3 format=2] [ext_resource path="res://assets/ui/tasks/container/container.gd" type="Script" id=1] -[ext_resource path="res://assets/ui/tasks/container/Textures/Container.png" type="Texture" id=2] +[ext_resource path="res://assets/ui/tasks/container/textures/container.png" type="Texture" id=2] + + [node name="container" type="MarginContainer"] margin_left = 128.0 diff --git a/src/assets/ui/tasks/container/Textures/Container.png b/src/assets/ui/tasks/container/textures/container.png similarity index 100% rename from src/assets/ui/tasks/container/Textures/Container.png rename to src/assets/ui/tasks/container/textures/container.png diff --git a/src/assets/ui/tasks/container/Textures/Container.png.import b/src/assets/ui/tasks/container/textures/container.png.import similarity index 68% rename from src/assets/ui/tasks/container/Textures/Container.png.import rename to src/assets/ui/tasks/container/textures/container.png.import index 9ffee9ec..34be2326 100644 --- a/src/assets/ui/tasks/container/Textures/Container.png.import +++ b/src/assets/ui/tasks/container/textures/container.png.import @@ -2,15 +2,15 @@ importer="texture" type="StreamTexture" -path="res://.import/Container.png-879c764ee37a9377f78340a313b4b235.stex" +path="res://.import/container.png-420ee352d5a0e234d6ec764ff7051749.stex" metadata={ "vram_texture": false } [deps] -source_file="res://assets/ui/tasks/container/Textures/Container.png" -dest_files=[ "res://.import/Container.png-879c764ee37a9377f78340a313b4b235.stex" ] +source_file="res://assets/ui/tasks/container/textures/container.png" +dest_files=[ "res://.import/container.png-420ee352d5a0e234d6ec764ff7051749.stex" ] [params] From ca16166c7da67bcc1df92586267c9323e16779c8 Mon Sep 17 00:00:00 2001 From: Zapzoop0099 Date: Wed, 3 Mar 2021 15:01:33 +0530 Subject: [PATCH 10/18] Fixed sync state --- .../common/classes/ui/base/margincontainerbase.gd | 3 --- src/assets/maps/test/container_area.gd | 1 + .../tasks/container/Resource/containerinteracttask.gd | 11 +++++------ src/assets/ui/tasks/container/container.gd | 7 +++++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/assets/common/classes/ui/base/margincontainerbase.gd b/src/assets/common/classes/ui/base/margincontainerbase.gd index dd23d19f..575b132c 100644 --- a/src/assets/common/classes/ui/base/margincontainerbase.gd +++ b/src/assets/common/classes/ui/base/margincontainerbase.gd @@ -29,6 +29,3 @@ func _on_visibility_changed(): else: UIManager.ui_closed(menu_name) -func get_res() -> Resource: - var res = TaskManager.get_task_resource(ui_data[TaskManager.TASK_ID_KEY]) - return res diff --git a/src/assets/maps/test/container_area.gd b/src/assets/maps/test/container_area.gd index d198298b..fc9e6bf7 100644 --- a/src/assets/maps/test/container_area.gd +++ b/src/assets/maps/test/container_area.gd @@ -9,6 +9,7 @@ var player = null func _ready(): interact_resource.init_resource(self) + yield(get_tree(), "idle_frame") interact_resource.update(self, {},interact_resource.actions.UPDATE) func reset() -> void: #Resets the node diff --git a/src/assets/ui/tasks/container/Resource/containerinteracttask.gd b/src/assets/ui/tasks/container/Resource/containerinteracttask.gd index b8027023..88baef33 100644 --- a/src/assets/ui/tasks/container/Resource/containerinteracttask.gd +++ b/src/assets/ui/tasks/container/Resource/containerinteracttask.gd @@ -31,28 +31,26 @@ func interact(_from: Node = null, _interact_data: Dictionary = {}, value = actio if attached_to == null: push_error("InteractTask resource trying to be used with no defined node") if not is_player_assigned(Network.get_my_id()): - print("false1") return if is_task_completed(Network.get_my_id()): - print("false2") return var dic = Helpers.merge_dicts(_interact_data, get_task_data()) set_action(value) - print(dic) ui_res.interact(_from, dic) func update(_from, data, value): print("get interaction") - interact(_from, data, value) + set_action(value) + ui_res.interact(_from,task_data) print("next is sync") sync_task() func _sync_task(): print("set_server") - #call("_server_set_scene", []) - task_rpc("_server_set_scene",[]) + + task_rpc("_server_set_scene",["_no_var"]) @@ -77,3 +75,4 @@ func _on_state_changed(_old_state, new_state) -> void:#resets the task when stat match new_state: GameManager.State.Lobby: task_rpc("_server_erase_children", []) + diff --git a/src/assets/ui/tasks/container/container.gd b/src/assets/ui/tasks/container/container.gd index 81be9be7..5fa9f454 100644 --- a/src/assets/ui/tasks/container/container.gd +++ b/src/assets/ui/tasks/container/container.gd @@ -41,14 +41,17 @@ func _on_erase_children() -> void:#erases all child # GameManager.State.Lobby: # rpc_id(1, "erase_children_server") # rpc_id(1, "reset_server") +func get_res() -> Resource: + var res = TaskManager.get_task_resource(ui_data[TaskManager.TASK_ID_KEY]) + return res func interact(data:Dictionary = {}, value = get_res().actions.OPEN): - get_res().interact(self,{}, value) + get_res().interact(self,data, value) func update(): # warning-ignore:return_value_discarded - print("uupdate got recieve") + get_res().connect("set_scene", self, "_on_set_scene") get_res().connect("erase_children", self, "_on_erase_children") From 3d35c41d85abae21c19b9f7dcc260f7419c3f553 Mon Sep 17 00:00:00 2001 From: Zapzoop0099 Date: Wed, 3 Mar 2021 16:31:05 +0530 Subject: [PATCH 11/18] Some basic item_holding_dic added --- .../resource/containerinteracttask.gd | 26 ++++++++++++++----- src/assets/ui/tasks/container/container.gd | 23 ++++++++++++++-- src/assets/ui/tasks/container/itemslot.gd | 4 ++- src/assets/ui/tasks/container/itemslot.tscn | 14 +--------- .../ui/tasks/container/itemslotbackend.gd | 3 ++- 5 files changed, 47 insertions(+), 23 deletions(-) diff --git a/src/assets/maps/test/tasks/container/resource/containerinteracttask.gd b/src/assets/maps/test/tasks/container/resource/containerinteracttask.gd index 88baef33..7611e797 100644 --- a/src/assets/maps/test/tasks/container/resource/containerinteracttask.gd +++ b/src/assets/maps/test/tasks/container/resource/containerinteracttask.gd @@ -6,6 +6,9 @@ enum actions {OPEN, INSTANCE, UPDATE, CLOSE} signal set_scene signal erase_children +var slots_info:Dictionary = {} +var items_to_hold:Array = ["battery","wrench"] + func _init(): add_networked_func("_server_set_scene", MultiplayerAPI.RPC_MODE_MASTER) add_networked_func("_client_set_scene", MultiplayerAPI.RPC_MODE_PUPPET) @@ -49,19 +52,16 @@ func update(_from, data, value): func _sync_task(): print("set_server") - task_rpc("_server_set_scene",["_no_var"]) - - func _server_set_scene(_arr): emit_signal("set_scene") print("client one next") - task_rpc("_client_set_scene", []) + task_rpc("_client_set_scene", ["_no_var"]) func _server_erase_children(_dic): emit_signal("erase_children") - task_rpc("_client_erase_children", []) + task_rpc("_client_erase_children", ["_no_var"]) func _client_set_scene(_dic): print("emitted") @@ -74,5 +74,19 @@ func _client_erase_children(_dic): func _on_state_changed(_old_state, new_state) -> void:#resets the task when state changes match new_state: GameManager.State.Lobby: - task_rpc("_server_erase_children", []) + task_rpc("_server_erase_children", ["no_var"]) +func give_item(index): + print("slot index") + print(slots_info) + print("index1") + print(index) + + for slot_index in slots_info.keys(): + if not index == slot_index: + return + else: + for slot in slot_index: + var item_holding = slot_index[slot] + print(item_holding) + diff --git a/src/assets/ui/tasks/container/container.gd b/src/assets/ui/tasks/container/container.gd index 5fa9f454..aa32147a 100644 --- a/src/assets/ui/tasks/container/container.gd +++ b/src/assets/ui/tasks/container/container.gd @@ -4,6 +4,13 @@ onready var grid = $background/conatainergrid const slot_scene = preload("res://assets/ui/tasks/container/itemslot.tscn") +var available_items:Dictionary = { + "battery":{"scene":preload("res://assets/items/battery.tscn")}, + "wrench":{"scene":preload("res://assets/items/wrench.tscn")} +} + +var slots_in_grid:Dictionary={} + export(int) var slots func _ready(): @@ -24,10 +31,13 @@ func _on_set_scene() -> void: #Place where the scene is built for num in range(0, slots): var slot = slot_scene.instance() - slot.set_name(str(num)) slot.index = num - slot.get_child(0).frontend = slot + slot.container = self grid.add_child(slot) + var item_to_instance = Helpers.pick_random(available_items.keys()) + position_and_add_child(slot, randomizer(item_to_instance)) + slots_in_grid[slot.index] = {slot:item_to_instance} + get_res().slots_info = slots_in_grid func _on_erase_children() -> void:#erases all child for child in grid.get_children(): @@ -55,3 +65,12 @@ func update(): get_res().connect("set_scene", self, "_on_set_scene") get_res().connect("erase_children", self, "_on_erase_children") +func randomizer(item): + for items in available_items.keys(): + if item == items: + var item_as_child = available_items[item].scene.instance() + return item_as_child + +func position_and_add_child(slot, item): + item.position += Vector2(64,64) + slot.add_child(item) diff --git a/src/assets/ui/tasks/container/itemslot.gd b/src/assets/ui/tasks/container/itemslot.gd index f1f01efc..ad926a1b 100644 --- a/src/assets/ui/tasks/container/itemslot.gd +++ b/src/assets/ui/tasks/container/itemslot.gd @@ -2,6 +2,8 @@ extends MarginContainerBase var mouse_entered:bool var index:int +var container = get_owner() + signal input_received(ui_data, index) @@ -27,4 +29,4 @@ func _on_itemslot_mouse_exited(): func _on_itemslot_gui_input(event): if event is InputEventMouseButton and event.pressed and event.button_index == BUTTON_LEFT and mouse_entered == true: if get_child(1) != null: - emit_signal("input_received", ui_data, index) + container.get_res().give_item(index) diff --git a/src/assets/ui/tasks/container/itemslot.tscn b/src/assets/ui/tasks/container/itemslot.tscn index 7445b108..6369181c 100644 --- a/src/assets/ui/tasks/container/itemslot.tscn +++ b/src/assets/ui/tasks/container/itemslot.tscn @@ -1,16 +1,8 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://assets/ui/tasks/container/itemslot.gd" type="Script" id=1] -[ext_resource path="res://assets/common/shaders/outline.shader" type="Shader" id=2] -[ext_resource path="res://assets/items/battery.tscn" type="PackedScene" id=3] [ext_resource path="res://assets/ui/tasks/container/itemslotbackend.gd" type="Script" id=4] -[sub_resource type="ShaderMaterial" id=1] -resource_local_to_scene = true -shader = ExtResource( 2 ) -shader_param/line_color = Color( 1, 1, 0, 0 ) -shader_param/line_thickness = 5.0 - [node name="itemslot" type="MarginContainer"] margin_right = 128.0 margin_bottom = 128.0 @@ -22,10 +14,6 @@ __meta__ = { [node name="Backend" type="Node" parent="."] script = ExtResource( 4 ) - -[node name="Battery" parent="." instance=ExtResource( 3 )] -material = SubResource( 1 ) -position = Vector2( 64, 64 ) [connection signal="gui_input" from="." to="." method="_on_itemslot_gui_input"] [connection signal="mouse_entered" from="." to="." method="_on_itemslot_mouse_entered"] [connection signal="mouse_exited" from="." to="." method="_on_itemslot_mouse_exited"] diff --git a/src/assets/ui/tasks/container/itemslotbackend.gd b/src/assets/ui/tasks/container/itemslotbackend.gd index 24d291b7..e3053956 100644 --- a/src/assets/ui/tasks/container/itemslotbackend.gd +++ b/src/assets/ui/tasks/container/itemslotbackend.gd @@ -5,7 +5,8 @@ var frontend = null #TODO: Set a randomizer func _ready(): - frontend.connect("input_received", self, "on_input_received") + pass +# frontend.connect("input_received", self, "on_input_received") func set_in_hand(ui_data_pass, index:int) -> void:#This the crucial function if not frontend.index == index: From 63a890d62c9a41a9309909e3c0766f3ccbd46505 Mon Sep 17 00:00:00 2001 From: nicemicro Date: Fri, 5 Mar 2021 21:15:01 +0900 Subject: [PATCH 12/18] added new items for the chemical cabinet --- src/assets/items/battery.tscn | 30 +++++++---- src/assets/items/large-liquid-bottle.tscn | 50 +++++++++++++++++++ src/assets/items/powder-bottle.tscn | 50 +++++++++++++++++++ src/assets/items/small-liquid-bottle.tscn | 50 +++++++++++++++++++ .../items/textures/large-liquid-bottle.png | 3 ++ .../textures/large-liquid-bottle.png.import | 34 +++++++++++++ src/assets/items/textures/powder-bottle.png | 3 ++ .../items/textures/powder-bottle.png.import | 34 +++++++++++++ .../items/textures/small-liquid-bottle.png | 3 ++ .../textures/small-liquid-bottle.png.import | 34 +++++++++++++ 10 files changed, 280 insertions(+), 11 deletions(-) create mode 100644 src/assets/items/large-liquid-bottle.tscn create mode 100644 src/assets/items/powder-bottle.tscn create mode 100644 src/assets/items/small-liquid-bottle.tscn create mode 100644 src/assets/items/textures/large-liquid-bottle.png create mode 100644 src/assets/items/textures/large-liquid-bottle.png.import create mode 100644 src/assets/items/textures/powder-bottle.png create mode 100644 src/assets/items/textures/powder-bottle.png.import create mode 100644 src/assets/items/textures/small-liquid-bottle.png create mode 100644 src/assets/items/textures/small-liquid-bottle.png.import diff --git a/src/assets/items/battery.tscn b/src/assets/items/battery.tscn index aa221682..3a07d9d7 100644 --- a/src/assets/items/battery.tscn +++ b/src/assets/items/battery.tscn @@ -1,12 +1,19 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=10 format=2] [ext_resource path="res://assets/items/item.tscn" type="PackedScene" id=1] [ext_resource path="res://assets/items/textures/battery.png" type="Texture" id=2] +[ext_resource path="res://assets/common/shaders/items.shader" type="Shader" id=3] -[sub_resource type="RectangleShape2D" id=6] +[sub_resource type="ShaderMaterial" id=1] +resource_local_to_scene = true +shader = ExtResource( 3 ) +shader_param/line_color = Color( 1, 1, 1, 1 ) +shader_param/line_thickness = 5.0 + +[sub_resource type="RectangleShape2D" id=2] extents = Vector2( 9.5, 4.4 ) -[sub_resource type="Shader" id=2] +[sub_resource type="Shader" id=3] resource_local_to_scene = true code = "shader_type canvas_item; @@ -34,13 +41,13 @@ void fragment() COLOR = mix(color, outlined_result, outlined_result.a); }" -[sub_resource type="ShaderMaterial" id=3] +[sub_resource type="ShaderMaterial" id=4] resource_local_to_scene = true -shader = SubResource( 2 ) +shader = SubResource( 3 ) shader_param/line_color = Color( 1, 1, 0, 0 ) shader_param/line_thickness = 5.0 -[sub_resource type="SpriteFrames" id=4] +[sub_resource type="SpriteFrames" id=5] animations = [ { "frames": [ ExtResource( 2 ) ], "loop": true, @@ -48,27 +55,28 @@ animations = [ { "speed": 5.0 } ] -[sub_resource type="CapsuleShape2D" id=5] +[sub_resource type="CapsuleShape2D" id=6] radius = 8.0 height = 12.0 [node name="Battery" instance=ExtResource( 1 )] +material = SubResource( 1 ) position = Vector2( -0.0936432, 0 ) [node name="ItemCollision" parent="." index="0"] rotation = 2.35619 -shape = SubResource( 6 ) +shape = SubResource( 2 ) [node name="SpritePosition" parent="." index="2"] position = Vector2( 0, 0 ) [node name="ItemSprite" parent="SpritePosition" index="0"] -material = SubResource( 3 ) +material = SubResource( 4 ) rotation = 2.35619 scale = Vector2( 0.1, 0.1 ) -frames = SubResource( 4 ) +frames = SubResource( 5 ) offset = Vector2( 0, 0 ) [node name="MouseCollision" parent="SpritePosition/MouseArea" index="0"] rotation = 0.785398 -shape = SubResource( 5 ) +shape = SubResource( 6 ) diff --git a/src/assets/items/large-liquid-bottle.tscn b/src/assets/items/large-liquid-bottle.tscn new file mode 100644 index 00000000..22259826 --- /dev/null +++ b/src/assets/items/large-liquid-bottle.tscn @@ -0,0 +1,50 @@ +[gd_scene load_steps=9 format=2] + +[ext_resource path="res://assets/items/item.tscn" type="PackedScene" id=1] +[ext_resource path="res://assets/common/shaders/items.shader" type="Shader" id=2] +[ext_resource path="res://assets/items/textures/large-liquid-bottle.png" type="Texture" id=3] + +[sub_resource type="ShaderMaterial" id=1] +resource_local_to_scene = true +shader = ExtResource( 2 ) +shader_param/line_color = Color( 1, 1, 1, 1 ) +shader_param/line_thickness = 5.0 + +[sub_resource type="CapsuleShape2D" id=2] +radius = 11.5 +height = 19.5 + +[sub_resource type="ShaderMaterial" id=3] +resource_local_to_scene = true +shader = ExtResource( 2 ) +shader_param/line_color = Color( 1, 1, 0, 0 ) +shader_param/line_thickness = 5.0 + +[sub_resource type="SpriteFrames" id=4] +animations = [ { +"frames": [ ExtResource( 3 ) ], +"loop": true, +"name": "default", +"speed": 5.0 +} ] + +[sub_resource type="CapsuleShape2D" id=5] +radius = 15.625 +height = 19.25 + +[node name="LargeLiquidBottle" instance=ExtResource( 1 )] +material = SubResource( 1 ) + +[node name="ItemCollision" parent="." index="0"] +position = Vector2( 0, 11 ) +shape = SubResource( 2 ) + +[node name="ItemSprite" parent="SpritePosition" index="0"] +material = SubResource( 3 ) +position = Vector2( 0, 12 ) +scale = Vector2( 0.15, 0.15 ) +frames = SubResource( 4 ) + +[node name="MouseCollision" parent="SpritePosition/MouseArea" index="0"] +position = Vector2( 0, 8 ) +shape = SubResource( 5 ) diff --git a/src/assets/items/powder-bottle.tscn b/src/assets/items/powder-bottle.tscn new file mode 100644 index 00000000..6bd0bf7a --- /dev/null +++ b/src/assets/items/powder-bottle.tscn @@ -0,0 +1,50 @@ +[gd_scene load_steps=9 format=2] + +[ext_resource path="res://assets/items/item.tscn" type="PackedScene" id=1] +[ext_resource path="res://assets/common/shaders/items.shader" type="Shader" id=2] +[ext_resource path="res://assets/items/textures/powder-bottle.png" type="Texture" id=3] + +[sub_resource type="ShaderMaterial" id=1] +resource_local_to_scene = true +shader = ExtResource( 2 ) +shader_param/line_color = Color( 1, 1, 1, 1 ) +shader_param/line_thickness = 5.0 + +[sub_resource type="CapsuleShape2D" id=4] +radius = 6.0 +height = 11.0 + +[sub_resource type="ShaderMaterial" id=2] +resource_local_to_scene = true +shader = ExtResource( 2 ) +shader_param/line_color = Color( 1, 1, 0, 0 ) +shader_param/line_thickness = 5.0 + +[sub_resource type="SpriteFrames" id=3] +animations = [ { +"frames": [ ExtResource( 3 ) ], +"loop": true, +"name": "default", +"speed": 5.0 +} ] + +[sub_resource type="CapsuleShape2D" id=5] +radius = 7.5 +height = 18.0 + +[node name="PowderBottle" instance=ExtResource( 1 )] +material = SubResource( 1 ) + +[node name="ItemCollision" parent="." index="0"] +position = Vector2( 0, 5 ) +shape = SubResource( 4 ) + +[node name="ItemSprite" parent="SpritePosition" index="0"] +material = SubResource( 2 ) +position = Vector2( 0, 5 ) +scale = Vector2( 0.15, 0.15 ) +frames = SubResource( 3 ) + +[node name="MouseCollision" parent="SpritePosition/MouseArea" index="0"] +position = Vector2( 0, 3 ) +shape = SubResource( 5 ) diff --git a/src/assets/items/small-liquid-bottle.tscn b/src/assets/items/small-liquid-bottle.tscn new file mode 100644 index 00000000..0f229ae6 --- /dev/null +++ b/src/assets/items/small-liquid-bottle.tscn @@ -0,0 +1,50 @@ +[gd_scene load_steps=9 format=2] + +[ext_resource path="res://assets/items/item.tscn" type="PackedScene" id=1] +[ext_resource path="res://assets/common/shaders/items.shader" type="Shader" id=2] +[ext_resource path="res://assets/items/textures/small-liquid-bottle.png" type="Texture" id=3] + +[sub_resource type="ShaderMaterial" id=1] +resource_local_to_scene = true +shader = ExtResource( 2 ) +shader_param/line_color = Color( 1, 1, 1, 1 ) +shader_param/line_thickness = 5.0 + +[sub_resource type="CapsuleShape2D" id=2] +radius = 7.375 +height = 12.75 + +[sub_resource type="ShaderMaterial" id=3] +resource_local_to_scene = true +shader = ExtResource( 2 ) +shader_param/line_color = Color( 1, 1, 0, 0 ) +shader_param/line_thickness = 5.0 + +[sub_resource type="SpriteFrames" id=4] +animations = [ { +"frames": [ ExtResource( 3 ) ], +"loop": true, +"name": "default", +"speed": 5.0 +} ] + +[sub_resource type="CapsuleShape2D" id=5] +radius = 9.625 +height = 15.25 + +[node name="SmallLiquidBottle" instance=ExtResource( 1 )] +material = SubResource( 1 ) + +[node name="ItemCollision" parent="." index="0"] +position = Vector2( 0, 6 ) +shape = SubResource( 2 ) + +[node name="ItemSprite" parent="SpritePosition" index="0"] +material = SubResource( 3 ) +position = Vector2( 0, 7 ) +scale = Vector2( 0.15, 0.15 ) +frames = SubResource( 4 ) + +[node name="MouseCollision" parent="SpritePosition/MouseArea" index="0"] +position = Vector2( 0, 4 ) +shape = SubResource( 5 ) diff --git a/src/assets/items/textures/large-liquid-bottle.png b/src/assets/items/textures/large-liquid-bottle.png new file mode 100644 index 00000000..c8c17b2a --- /dev/null +++ b/src/assets/items/textures/large-liquid-bottle.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a010b1f2d160537a05a37b4561770269957656aa462efaa2134cf44fa00558e7 +size 17170 diff --git a/src/assets/items/textures/large-liquid-bottle.png.import b/src/assets/items/textures/large-liquid-bottle.png.import new file mode 100644 index 00000000..34be1251 --- /dev/null +++ b/src/assets/items/textures/large-liquid-bottle.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/large-liquid-bottle.png-b85e83d54ea8d53b5b9adb6d794e82da.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/items/textures/large-liquid-bottle.png" +dest_files=[ "res://.import/large-liquid-bottle.png-b85e83d54ea8d53b5b9adb6d794e82da.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/src/assets/items/textures/powder-bottle.png b/src/assets/items/textures/powder-bottle.png new file mode 100644 index 00000000..e42866ae --- /dev/null +++ b/src/assets/items/textures/powder-bottle.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:837ff4a5621db49c0c7c95b6b997665a7138ff87acafd477d1e79f407ebf151c +size 7643 diff --git a/src/assets/items/textures/powder-bottle.png.import b/src/assets/items/textures/powder-bottle.png.import new file mode 100644 index 00000000..2d5e4d70 --- /dev/null +++ b/src/assets/items/textures/powder-bottle.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/powder-bottle.png-788d1d4ba26c8d8cc9bff4f661a7ce70.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/items/textures/powder-bottle.png" +dest_files=[ "res://.import/powder-bottle.png-788d1d4ba26c8d8cc9bff4f661a7ce70.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/src/assets/items/textures/small-liquid-bottle.png b/src/assets/items/textures/small-liquid-bottle.png new file mode 100644 index 00000000..74ea7139 --- /dev/null +++ b/src/assets/items/textures/small-liquid-bottle.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e928f9388f1b880a1c00f97eeabcccdcfe76373c6c1a3144145c5e9b9220bbc4 +size 9927 diff --git a/src/assets/items/textures/small-liquid-bottle.png.import b/src/assets/items/textures/small-liquid-bottle.png.import new file mode 100644 index 00000000..777f0484 --- /dev/null +++ b/src/assets/items/textures/small-liquid-bottle.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/small-liquid-bottle.png-b1f28f3dcc2545a6f9fd766619ca48ea.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/items/textures/small-liquid-bottle.png" +dest_files=[ "res://.import/small-liquid-bottle.png-b1f28f3dcc2545a6f9fd766619ca48ea.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 From b1ec4d57da8faaa738e730de52e78f7639e7dd8d Mon Sep 17 00:00:00 2001 From: Zapzoop0099 Date: Fri, 5 Mar 2021 20:11:52 +0530 Subject: [PATCH 13/18] Interaction done --- .../resources/interacttask/interacttask.tres | 18 +++++-- .../interactpoint/interactpoint.gd | 3 +- .../mapnodescripts}/container_area.gd | 0 .../mapnodescripts/spawnpositionofitem.gd | 53 +++++++++++++++++++ .../resource/containerinteracttask.gd | 40 ++++++-------- .../resource/containerintercattask.tres | 20 +++++-- src/assets/maps/test/test.tscn | 22 ++++---- src/assets/ui/tasks/container/container.gd | 7 ++- src/assets/ui/tasks/container/container.tscn | 2 - src/assets/ui/tasks/container/itemslot.gd | 3 +- 10 files changed, 119 insertions(+), 49 deletions(-) rename src/assets/maps/test/{ => tasks/container/mapnodescripts}/container_area.gd (100%) create mode 100644 src/assets/maps/test/tasks/container/mapnodescripts/spawnpositionofitem.gd diff --git a/src/addons/opensusinteraction/resources/interacttask/interacttask.tres b/src/addons/opensusinteraction/resources/interacttask/interacttask.tres index a69905cb..1786c1ec 100644 --- a/src/addons/opensusinteraction/resources/interacttask/interacttask.tres +++ b/src/addons/opensusinteraction/resources/interacttask/interacttask.tres @@ -1,11 +1,21 @@ -[gd_resource type="Resource" load_steps=4 format=2] +[gd_resource type="Resource" load_steps=6 format=2] [ext_resource path="res://addons/opensusinteraction/resources/interacttask/interacttask.gd" type="Script" id=1] [ext_resource path="res://addons/opensusinteraction/resources/interactui/interactui.gd" type="Script" id=2] +[ext_resource path="res://addons/opensusinteraction/resources/interactmap/interactmap.gd" type="Script" id=3] [sub_resource type="Resource" id=1] resource_local_to_scene = true -resource_name = "InteractUI" +resource_name = "InteractMap" +script = ExtResource( 3 ) +interact_with = NodePath("") +interact_data = { + +} +advanced/network_sync = false + +[sub_resource type="Resource" id=2] +resource_local_to_scene = true script = ExtResource( 2 ) ui_name = "" ui_data = { @@ -20,7 +30,7 @@ resource_local_to_scene = true resource_name = "InteractTask" script = ExtResource( 1 ) task_text = "" -ui_resource = SubResource( 1 ) +ui_resource = SubResource( 2 ) outputs/toggle_map_interactions = false -outputs/output_map_interactions = [ ] +outputs/output_map_interactions = [ SubResource( 1 ) ] is_task_global = false diff --git a/src/assets/maps/common/interactables/interactpoint/interactpoint.gd b/src/assets/maps/common/interactables/interactpoint/interactpoint.gd index 959293d5..b0b4da6d 100644 --- a/src/assets/maps/common/interactables/interactpoint/interactpoint.gd +++ b/src/assets/maps/common/interactables/interactpoint/interactpoint.gd @@ -6,7 +6,8 @@ export(String) var display_text var interact_data: Dictionary = {} setget , get_interact_data func _ready(): - interact_resource.init_resource(self) + pass + #interact_resource.init_resource(self) func get_interact_data(): #var interact_resource: Interact = interact diff --git a/src/assets/maps/test/container_area.gd b/src/assets/maps/test/tasks/container/mapnodescripts/container_area.gd similarity index 100% rename from src/assets/maps/test/container_area.gd rename to src/assets/maps/test/tasks/container/mapnodescripts/container_area.gd diff --git a/src/assets/maps/test/tasks/container/mapnodescripts/spawnpositionofitem.gd b/src/assets/maps/test/tasks/container/mapnodescripts/spawnpositionofitem.gd new file mode 100644 index 00000000..8323e43d --- /dev/null +++ b/src/assets/maps/test/tasks/container/mapnodescripts/spawnpositionofitem.gd @@ -0,0 +1,53 @@ +extends Node2D + +onready var map_items: Node2D +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" +var available_items:Dictionary = { + "battery":{"scene":preload("res://assets/items/battery.tscn")}, + "wrench":{"scene":preload("res://assets/items/wrench.tscn")} +} +var total_items:Array=[] +var data = null +# Called when the node enters the scene tree for the first time. +func _ready(): + MapManager.connect("interacted_with", self, "on_interacted_with") + yield(get_tree(), "idle_frame") + update_total_items() + map_items = MapManager.get_current_map().items + +func on_interacted_with(interactNode, from, interact_data): + if interactNode != self: + return + print(interact_data) + data = interact_data + print(data) + add_item(interact_data["item_instanced"]) + + +func add_item(item_instanced): + for items in available_items.keys(): + if item_instanced == items: + var item_as_child = available_items[item_instanced].scene.instance() + + map_items.add_child(item_as_child) + get_tree().get_root().get_node(get_player()).item_handler._test_pickup(item_as_child) + + +func update_total_items(): + for items in available_items.keys(): + total_items.append(items) + +func do_match(value): + for items in total_items: + match items: + value: + add_item(items) + return true + +func get_player(): + for key in data.keys(): + if typeof(key) == TYPE_INT:#Filters the ui_data + var player = data[key] + return player diff --git a/src/assets/maps/test/tasks/container/resource/containerinteracttask.gd b/src/assets/maps/test/tasks/container/resource/containerinteracttask.gd index 7611e797..4fafafa1 100644 --- a/src/assets/maps/test/tasks/container/resource/containerinteracttask.gd +++ b/src/assets/maps/test/tasks/container/resource/containerinteracttask.gd @@ -8,6 +8,7 @@ signal erase_children var slots_info:Dictionary = {} var items_to_hold:Array = ["battery","wrench"] +var data = null func _init(): add_networked_func("_server_set_scene", MultiplayerAPI.RPC_MODE_MASTER) @@ -37,26 +38,22 @@ func interact(_from: Node = null, _interact_data: Dictionary = {}, value = actio return if is_task_completed(Network.get_my_id()): return - - var dic = Helpers.merge_dicts(_interact_data, get_task_data()) + data = _interact_data + var merged_dic = Helpers.merge_dicts(_interact_data, get_task_data()) set_action(value) - ui_res.interact(_from, dic) + ui_res.interact(_from, merged_dic) -func update(_from, data, value): - print("get interaction") +func update(_from, _data, value): set_action(value) ui_res.interact(_from,task_data) - print("next is sync") sync_task() func _sync_task(): - print("set_server") task_rpc("_server_set_scene",["_no_var"]) func _server_set_scene(_arr): emit_signal("set_scene") - print("client one next") task_rpc("_client_set_scene", ["_no_var"]) func _server_erase_children(_dic): @@ -64,7 +61,6 @@ func _server_erase_children(_dic): task_rpc("_client_erase_children", ["_no_var"]) func _client_set_scene(_dic): - print("emitted") emit_signal("set_scene") func _client_erase_children(_dic): @@ -76,17 +72,15 @@ func _on_state_changed(_old_state, new_state) -> void:#resets the task when stat GameManager.State.Lobby: task_rpc("_server_erase_children", ["no_var"]) -func give_item(index): - print("slot index") - print(slots_info) - print("index1") - print(index) - - for slot_index in slots_info.keys(): - if not index == slot_index: - return - else: - for slot in slot_index: - var item_holding = slot_index[slot] - print(item_holding) - +func generate_interact_data(slot_index): + var interact_data:Dictionary = {} + for index in slots_info.keys(): + if index == slot_index: + interact_data = slots_info[index].duplicate() + send_interact_data(interact_data) + +func send_interact_data(interact_data): + var merged_dic = Helpers.merge_dicts(interact_data, data) + if map_outputs_on: + for resource in map_outputs: + resource.interact(attached_to, merged_dic) diff --git a/src/assets/maps/test/tasks/container/resource/containerintercattask.tres b/src/assets/maps/test/tasks/container/resource/containerintercattask.tres index 220fcf9d..f490391b 100644 --- a/src/assets/maps/test/tasks/container/resource/containerintercattask.tres +++ b/src/assets/maps/test/tasks/container/resource/containerintercattask.tres @@ -1,11 +1,21 @@ -[gd_resource type="Resource" load_steps=4 format=2] +[gd_resource type="Resource" load_steps=6 format=2] [ext_resource path="res://addons/opensusinteraction/resources/interactui/interactui.gd" type="Script" id=1] [ext_resource path="res://assets/maps/test/tasks/container/resource/containerinteracttask.gd" type="Script" id=2] +[ext_resource path="res://addons/opensusinteraction/resources/interactmap/interactmap.gd" type="Script" id=3] [sub_resource type="Resource" id=1] resource_local_to_scene = true -resource_name = "InteractUI" +resource_name = "InteractMap" +script = ExtResource( 3 ) +interact_with = NodePath("Node2D") +interact_data = { + +} +advanced/network_sync = false + +[sub_resource type="Resource" id=2] +resource_local_to_scene = true script = ExtResource( 1 ) ui_name = "container" ui_data = { @@ -19,7 +29,7 @@ advanced/free_on_close = false resource_local_to_scene = true script = ExtResource( 2 ) task_text = "Container" -ui_resource = SubResource( 1 ) -outputs/toggle_map_interactions = false -outputs/output_map_interactions = [ ] +ui_resource = SubResource( 2 ) +outputs/toggle_map_interactions = true +outputs/output_map_interactions = [ SubResource( 1 ) ] is_task_global = true diff --git a/src/assets/maps/test/test.tscn b/src/assets/maps/test/test.tscn index 84193cc7..1a296670 100644 --- a/src/assets/maps/test/test.tscn +++ b/src/assets/maps/test/test.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=32 format=2] +[gd_scene load_steps=34 format=2] [ext_resource path="res://assets/common/textures/icons/spawnpad.png" type="Texture" id=1] [ext_resource path="res://assets/maps/common/dynamic/testdoor/testdoor.tscn" type="PackedScene" id=2] @@ -17,8 +17,10 @@ [ext_resource path="res://assets/maps/map.gd" type="Script" id=15] [ext_resource path="res://assets/maps/test/tasks/clockset/interactpointclockset.tres" type="Resource" id=16] [ext_resource path="res://assets/maps/test/tasks/container/resource/containerintercattask.tres" type="Resource" id=17] -[ext_resource path="res://assets/maps/test/container_area.gd" type="Script" id=18] +[ext_resource path="res://assets/maps/test/tasks/container/mapnodescripts/container_area.gd" type="Script" id=18] [ext_resource path="res://assets/maps/test/textures/chemicals-cabinet.png" type="Texture" id=19] +[ext_resource path="res://assets/player/textures/characters/black/black-proto-1.png" type="Texture" id=20] +[ext_resource path="res://assets/maps/test/tasks/container/mapnodescripts/spawnpositionofitem.gd" type="Script" id=21] [sub_resource type="Resource" id=1] resource_local_to_scene = true @@ -354,19 +356,21 @@ position = Vector2( -96.3763, 93.3395 ) [node name="Containers" type="YSort" parent="Interactive/Tasks"] [node name="Container" type="Area2D" parent="Interactive/Tasks/Containers"] -position = Vector2( 224, 56 ) +position = Vector2( 208, 80 ) script = ExtResource( 18 ) interact_resource = ExtResource( 17 ) -[node name="Sprite" type="Sprite" parent="Interactive/Tasks/Containers/Container"] -position = Vector2( -8, 0 ) -scale = Vector2( 0.1, 0.1 ) -texture = ExtResource( 19 ) - [node name="CollisionShape2D" type="CollisionShape2D" parent="Interactive/Tasks/Containers/Container"] -position = Vector2( -8, 0 ) shape = SubResource( 12 ) +[node name="Sprite" type="Sprite" parent="Interactive/Tasks/Containers/Container"] +position = Vector2( -7.62939e-06, 0 ) +scale = Vector2( 0.9625, 0.9625 ) +texture = ExtResource( 20 ) + +[node name="Node2D" type="Node2D" parent="Interactive/Tasks/Containers/Container"] +script = ExtResource( 21 ) + [node name="ChemicalCabinet" parent="Interactive/Tasks" instance=ExtResource( 5 )] position = Vector2( 235, -155 ) interact_resource = ExtResource( 17 ) diff --git a/src/assets/ui/tasks/container/container.gd b/src/assets/ui/tasks/container/container.gd index aa32147a..841e0ef0 100644 --- a/src/assets/ui/tasks/container/container.gd +++ b/src/assets/ui/tasks/container/container.gd @@ -35,8 +35,8 @@ func _on_set_scene() -> void: slot.container = self grid.add_child(slot) var item_to_instance = Helpers.pick_random(available_items.keys()) - position_and_add_child(slot, randomizer(item_to_instance)) - slots_in_grid[slot.index] = {slot:item_to_instance} + set_position_and_add_child(slot, randomizer(item_to_instance)) + slots_in_grid[slot.index] = {"slot":slot,"item_instanced":item_to_instance} get_res().slots_info = slots_in_grid func _on_erase_children() -> void:#erases all child @@ -61,7 +61,6 @@ func interact(data:Dictionary = {}, value = get_res().actions.OPEN): func update(): # warning-ignore:return_value_discarded - get_res().connect("set_scene", self, "_on_set_scene") get_res().connect("erase_children", self, "_on_erase_children") @@ -71,6 +70,6 @@ func randomizer(item): var item_as_child = available_items[item].scene.instance() return item_as_child -func position_and_add_child(slot, item): +func set_position_and_add_child(slot, item): item.position += Vector2(64,64) slot.add_child(item) diff --git a/src/assets/ui/tasks/container/container.tscn b/src/assets/ui/tasks/container/container.tscn index 69691fc7..8687fd3c 100644 --- a/src/assets/ui/tasks/container/container.tscn +++ b/src/assets/ui/tasks/container/container.tscn @@ -3,8 +3,6 @@ [ext_resource path="res://assets/ui/tasks/container/container.gd" type="Script" id=1] [ext_resource path="res://assets/ui/tasks/container/textures/container.png" type="Texture" id=2] - - [node name="container" type="MarginContainer"] margin_left = 128.0 margin_top = 48.0 diff --git a/src/assets/ui/tasks/container/itemslot.gd b/src/assets/ui/tasks/container/itemslot.gd index ad926a1b..20a2c6eb 100644 --- a/src/assets/ui/tasks/container/itemslot.gd +++ b/src/assets/ui/tasks/container/itemslot.gd @@ -29,4 +29,5 @@ func _on_itemslot_mouse_exited(): func _on_itemslot_gui_input(event): if event is InputEventMouseButton and event.pressed and event.button_index == BUTTON_LEFT and mouse_entered == true: if get_child(1) != null: - container.get_res().give_item(index) + container.get_res().generate_interact_data(index) + #get_child(1).queue_free() From fc83e0602166d0cebf350e83a05e26e31ef80822 Mon Sep 17 00:00:00 2001 From: Zapzoop0099 Date: Sat, 6 Mar 2021 17:07:32 +0530 Subject: [PATCH 14/18] Basic stacking of items --- .../mapnodescripts/spawnpositionofitem.gd | 30 ++++++++-------- src/assets/ui/tasks/container/container.gd | 30 +++++++++++++--- src/assets/ui/tasks/container/itemslot.gd | 35 ++++++++++-------- src/assets/ui/tasks/container/itemslot.tscn | 36 +++++++++++++------ 4 files changed, 87 insertions(+), 44 deletions(-) diff --git a/src/assets/maps/test/tasks/container/mapnodescripts/spawnpositionofitem.gd b/src/assets/maps/test/tasks/container/mapnodescripts/spawnpositionofitem.gd index 8323e43d..b0c96944 100644 --- a/src/assets/maps/test/tasks/container/mapnodescripts/spawnpositionofitem.gd +++ b/src/assets/maps/test/tasks/container/mapnodescripts/spawnpositionofitem.gd @@ -6,7 +6,10 @@ onready var map_items: Node2D # var b = "text" var available_items:Dictionary = { "battery":{"scene":preload("res://assets/items/battery.tscn")}, - "wrench":{"scene":preload("res://assets/items/wrench.tscn")} + "wrench":{"scene":preload("res://assets/items/wrench.tscn")}, + "large-liquid-bottle":{"scene":preload("res://assets/items/large-liquid-bottle.tscn")}, + "powder-bottle":{"scene":preload("res://assets/items/powder-bottle.tscn")}, + "small-liquid-bottle":{"scene":preload("res://assets/items/small-liquid-bottle.tscn")} } var total_items:Array=[] var data = null @@ -20,17 +23,16 @@ func _ready(): func on_interacted_with(interactNode, from, interact_data): if interactNode != self: return - print(interact_data) - data = interact_data + data = interact_data.duplicate() print(data) - add_item(interact_data["item_instanced"]) + add_item(interact_data["item_instanced"],interact_data["number_of_item"]) -func add_item(item_instanced): +func add_item(item_instanced, number): for items in available_items.keys(): - if item_instanced == items: + if item_instanced == items and int(number) != 0: var item_as_child = available_items[item_instanced].scene.instance() - + update_data() map_items.add_child(item_as_child) get_tree().get_root().get_node(get_player()).item_handler._test_pickup(item_as_child) @@ -39,15 +41,15 @@ func update_total_items(): for items in available_items.keys(): total_items.append(items) -func do_match(value): - for items in total_items: - match items: - value: - add_item(items) - return true - func get_player(): for key in data.keys(): if typeof(key) == TYPE_INT:#Filters the ui_data var player = data[key] return player + +func update_data(): + var dic_to_change = data.duplicate() + var number = int(dic_to_change["number_of_item"]) + dic_to_change["number_of_item"] = str(number - 1) + data = dic_to_change + #print(data) diff --git a/src/assets/ui/tasks/container/container.gd b/src/assets/ui/tasks/container/container.gd index 841e0ef0..3e090c9e 100644 --- a/src/assets/ui/tasks/container/container.gd +++ b/src/assets/ui/tasks/container/container.gd @@ -6,9 +6,12 @@ const slot_scene = preload("res://assets/ui/tasks/container/itemslot.tscn") var available_items:Dictionary = { "battery":{"scene":preload("res://assets/items/battery.tscn")}, - "wrench":{"scene":preload("res://assets/items/wrench.tscn")} + "wrench":{"scene":preload("res://assets/items/wrench.tscn")}, + "large-liquid-bottle":{"scene":preload("res://assets/items/large-liquid-bottle.tscn")}, + "powder-bottle":{"scene":preload("res://assets/items/powder-bottle.tscn")}, + "small-liquid-bottle":{"scene":preload("res://assets/items/small-liquid-bottle.tscn")} } - +var current_item_instanced:Array = [] var slots_in_grid:Dictionary={} export(int) var slots @@ -34,9 +37,11 @@ func _on_set_scene() -> void: slot.index = num slot.container = self grid.add_child(slot) - var item_to_instance = Helpers.pick_random(available_items.keys()) - set_position_and_add_child(slot, randomizer(item_to_instance)) - slots_in_grid[slot.index] = {"slot":slot,"item_instanced":item_to_instance} + var item_to_instance = place_item(slot) + if item_to_instance == null: + break + var number_of_item = set_amount(slot) + slots_in_grid[slot.index] = {"slot":slot,"item_instanced":item_to_instance,"number_of_item":number_of_item} get_res().slots_info = slots_in_grid func _on_erase_children() -> void:#erases all child @@ -73,3 +78,18 @@ func randomizer(item): func set_position_and_add_child(slot, item): item.position += Vector2(64,64) slot.add_child(item) + + +func set_amount(slot): + var number_of_item = Helpers.pick_random(range(0,11)) + slot.amount.text = str(number_of_item) + return number_of_item + +func place_item(slot): + var item_to_instance = Helpers.pick_random(available_items.keys()) + if current_item_instanced.has(item_to_instance): + return null + else: + current_item_instanced.append(item_to_instance) + set_position_and_add_child(slot, randomizer(item_to_instance)) + return item_to_instance diff --git a/src/assets/ui/tasks/container/itemslot.gd b/src/assets/ui/tasks/container/itemslot.gd index 20a2c6eb..fc8a3002 100644 --- a/src/assets/ui/tasks/container/itemslot.gd +++ b/src/assets/ui/tasks/container/itemslot.gd @@ -1,33 +1,38 @@ extends MarginContainerBase +onready var amount = $Control/Label +onready var itemslot = self + var mouse_entered:bool var index:int -var container = get_owner() - +var container signal input_received(ui_data, index) func _ready(): pass + + +func _on_Control_gui_input(event): + if event is InputEventMouseButton and event.pressed and event.button_index == BUTTON_LEFT and mouse_entered == true: + if itemslot.get_child(1) != null: + container.get_res().generate_interact_data(index) -func _on_itemslot_mouse_entered(): - if get_child_count() == 1: + +func _on_Control_mouse_entered(): + if itemslot.get_child_count() == 1: return else: - get_child(1).animator.play("hover") - get_child(1).can_pickup_with_mouse = true + itemslot.get_child(1).animator.play("hover") + itemslot.get_child(1).can_pickup_with_mouse = true mouse_entered = true -func _on_itemslot_mouse_exited(): - if get_child_count() == 1: + +func _on_Control_mouse_exited(): + if itemslot.get_child_count() == 1: return else: - get_child(1).animator.play("idle") - get_child(1).can_pickup_with_mouse = false + itemslot.get_child(1).animator.play("idle") + itemslot.get_child(1).can_pickup_with_mouse = false mouse_entered = false -func _on_itemslot_gui_input(event): - if event is InputEventMouseButton and event.pressed and event.button_index == BUTTON_LEFT and mouse_entered == true: - if get_child(1) != null: - container.get_res().generate_interact_data(index) - #get_child(1).queue_free() diff --git a/src/assets/ui/tasks/container/itemslot.tscn b/src/assets/ui/tasks/container/itemslot.tscn index 6369181c..1f134eb3 100644 --- a/src/assets/ui/tasks/container/itemslot.tscn +++ b/src/assets/ui/tasks/container/itemslot.tscn @@ -1,19 +1,35 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=2 format=2] [ext_resource path="res://assets/ui/tasks/container/itemslot.gd" type="Script" id=1] -[ext_resource path="res://assets/ui/tasks/container/itemslotbackend.gd" type="Script" id=4] [node name="itemslot" type="MarginContainer"] -margin_right = 128.0 -margin_bottom = 128.0 +anchor_left = 0.102 +anchor_top = 0.173 +anchor_right = 0.125 +anchor_bottom = 0.213 +margin_left = -104.448 +margin_top = -103.8 +margin_bottom = 0.199989 rect_min_size = Vector2( 90, 90 ) script = ExtResource( 1 ) __meta__ = { -"_edit_use_anchors_": false +"_edit_use_anchors_": true } -[node name="Backend" type="Node" parent="."] -script = ExtResource( 4 ) -[connection signal="gui_input" from="." to="." method="_on_itemslot_gui_input"] -[connection signal="mouse_entered" from="." to="." method="_on_itemslot_mouse_entered"] -[connection signal="mouse_exited" from="." to="." method="_on_itemslot_mouse_exited"] +[node name="Control" type="Control" parent="."] +margin_right = 128.0 +margin_bottom = 128.0 + +[node name="Label" type="Label" parent="Control"] +margin_left = 96.0 +margin_top = 96.0 +margin_right = 120.0 +margin_bottom = 118.0 +text = "8" +align = 2 +__meta__ = { +"_edit_use_anchors_": false +} +[connection signal="gui_input" from="Control" to="." method="_on_Control_gui_input"] +[connection signal="mouse_entered" from="Control" to="." method="_on_Control_mouse_entered"] +[connection signal="mouse_exited" from="Control" to="." method="_on_Control_mouse_exited"] From 6d4f1839afb2199c719fd30a1cc7d4b6bc08b5db Mon Sep 17 00:00:00 2001 From: nicemicro Date: Sat, 20 Mar 2021 00:50:00 +0900 Subject: [PATCH 15/18] added new items --- src/assets/items/beaker-empty.tscn | 52 +++++++++++++++++++ src/assets/items/flask-empty.tscn | 50 ++++++++++++++++++ src/assets/items/gas-burner.tscn | 50 ++++++++++++++++++ src/assets/items/iron-tripod.tscn | 50 ++++++++++++++++++ src/assets/items/textures/beaker-empty.png | 3 ++ .../items/textures/beaker-empty.png.import | 34 ++++++++++++ src/assets/items/textures/flask-empty.png | 3 ++ .../items/textures/flask-empty.png.import | 34 ++++++++++++ src/assets/items/textures/gas_burner.png | 3 ++ .../items/textures/gas_burner.png.import | 34 ++++++++++++ src/assets/items/textures/iron_tripod.png | 3 ++ .../items/textures/iron_tripod.png.import | 34 ++++++++++++ 12 files changed, 350 insertions(+) create mode 100644 src/assets/items/beaker-empty.tscn create mode 100644 src/assets/items/flask-empty.tscn create mode 100644 src/assets/items/gas-burner.tscn create mode 100644 src/assets/items/iron-tripod.tscn create mode 100644 src/assets/items/textures/beaker-empty.png create mode 100644 src/assets/items/textures/beaker-empty.png.import create mode 100644 src/assets/items/textures/flask-empty.png create mode 100644 src/assets/items/textures/flask-empty.png.import create mode 100644 src/assets/items/textures/gas_burner.png create mode 100644 src/assets/items/textures/gas_burner.png.import create mode 100644 src/assets/items/textures/iron_tripod.png create mode 100644 src/assets/items/textures/iron_tripod.png.import diff --git a/src/assets/items/beaker-empty.tscn b/src/assets/items/beaker-empty.tscn new file mode 100644 index 00000000..b98a7bee --- /dev/null +++ b/src/assets/items/beaker-empty.tscn @@ -0,0 +1,52 @@ +[gd_scene load_steps=9 format=2] + +[ext_resource path="res://assets/items/item.tscn" type="PackedScene" id=1] +[ext_resource path="res://assets/common/shaders/items.shader" type="Shader" id=2] +[ext_resource path="res://assets/items/textures/beaker-empty.png" type="Texture" id=3] + +[sub_resource type="ShaderMaterial" id=1] +resource_local_to_scene = true +shader = ExtResource( 2 ) +shader_param/line_color = Color( 1, 1, 1, 1 ) +shader_param/line_thickness = 5.0 + +[sub_resource type="CapsuleShape2D" id=2] +radius = 11.125 +height = 4.872 + +[sub_resource type="ShaderMaterial" id=3] +resource_local_to_scene = true +shader = ExtResource( 2 ) +shader_param/line_color = Color( 1, 1, 0, 0 ) +shader_param/line_thickness = 5.0 + +[sub_resource type="SpriteFrames" id=4] +animations = [ { +"frames": [ ExtResource( 3 ) ], +"loop": true, +"name": "default", +"speed": 5.0 +} ] + +[sub_resource type="CapsuleShape2D" id=5] +radius = 13.125 +height = 7.5 + +[node name="BeakerEmpty" instance=ExtResource( 1 )] +material = SubResource( 1 ) +position = Vector2( 0, 0.436 ) + +[node name="ItemCollision" parent="." index="0"] +position = Vector2( 3.5, 10 ) +shape = SubResource( 2 ) + +[node name="ItemSprite" parent="SpritePosition" index="0"] +material = SubResource( 3 ) +position = Vector2( 4, 8 ) +scale = Vector2( 0.15, 0.15 ) +frames = SubResource( 4 ) +offset = Vector2( 0, 0 ) + +[node name="MouseCollision" parent="SpritePosition/MouseArea" index="0"] +position = Vector2( 3, 6 ) +shape = SubResource( 5 ) diff --git a/src/assets/items/flask-empty.tscn b/src/assets/items/flask-empty.tscn new file mode 100644 index 00000000..cc228e8c --- /dev/null +++ b/src/assets/items/flask-empty.tscn @@ -0,0 +1,50 @@ +[gd_scene load_steps=9 format=2] + +[ext_resource path="res://assets/items/item.tscn" type="PackedScene" id=1] +[ext_resource path="res://assets/common/shaders/items.shader" type="Shader" id=2] +[ext_resource path="res://assets/items/textures/flask-empty.png" type="Texture" id=3] + +[sub_resource type="ShaderMaterial" id=1] +resource_local_to_scene = true +shader = ExtResource( 2 ) +shader_param/line_color = Color( 1, 1, 1, 1 ) +shader_param/line_thickness = 5.0 + +[sub_resource type="CapsuleShape2D" id=2] +radius = 8.98537 +height = 5.18001 + +[sub_resource type="ShaderMaterial" id=3] +resource_local_to_scene = true +shader = ExtResource( 2 ) +shader_param/line_color = Color( 1, 1, 0, 0 ) +shader_param/line_thickness = 5.0 + +[sub_resource type="SpriteFrames" id=4] +animations = [ { +"frames": [ ExtResource( 3 ) ], +"loop": true, +"name": "default", +"speed": 5.0 +} ] + +[sub_resource type="CapsuleShape2D" id=5] +radius = 10.8208 +height = 6.84969 + +[node name="FlaskEmpty" instance=ExtResource( 1 )] +material = SubResource( 1 ) + +[node name="ItemCollision" parent="." index="0"] +position = Vector2( 0, 7 ) +shape = SubResource( 2 ) + +[node name="ItemSprite" parent="SpritePosition" index="0"] +material = SubResource( 3 ) +position = Vector2( 0, 8 ) +scale = Vector2( 0.15, 0.15 ) +frames = SubResource( 4 ) + +[node name="MouseCollision" parent="SpritePosition/MouseArea" index="0"] +position = Vector2( 0, 5 ) +shape = SubResource( 5 ) diff --git a/src/assets/items/gas-burner.tscn b/src/assets/items/gas-burner.tscn new file mode 100644 index 00000000..aaffee62 --- /dev/null +++ b/src/assets/items/gas-burner.tscn @@ -0,0 +1,50 @@ +[gd_scene load_steps=9 format=2] + +[ext_resource path="res://assets/items/item.tscn" type="PackedScene" id=1] +[ext_resource path="res://assets/common/shaders/items.shader" type="Shader" id=2] +[ext_resource path="res://assets/items/textures/gas_burner.png" type="Texture" id=3] + +[sub_resource type="ShaderMaterial" id=1] +resource_local_to_scene = true +shader = ExtResource( 2 ) +shader_param/line_color = Color( 1, 1, 1, 1 ) +shader_param/line_thickness = 5.0 + +[sub_resource type="CapsuleShape2D" id=2] +radius = 9.32964 +height = 3.54026 + +[sub_resource type="ShaderMaterial" id=3] +resource_local_to_scene = true +shader = ExtResource( 2 ) +shader_param/line_color = Color( 1, 1, 0, 0 ) +shader_param/line_thickness = 5.0 + +[sub_resource type="SpriteFrames" id=4] +animations = [ { +"frames": [ ExtResource( 3 ) ], +"loop": true, +"name": "default", +"speed": 5.0 +} ] + +[sub_resource type="CapsuleShape2D" id=5] +radius = 8.77283 +height = 2.09932 + +[node name="GasBurner" instance=ExtResource( 1 )] +material = SubResource( 1 ) + +[node name="ItemCollision" parent="." index="0"] +position = Vector2( 0, 7 ) +shape = SubResource( 2 ) + +[node name="ItemSprite" parent="SpritePosition" index="0"] +material = SubResource( 3 ) +position = Vector2( 0, 8 ) +scale = Vector2( 0.15, 0.15 ) +frames = SubResource( 4 ) + +[node name="MouseCollision" parent="SpritePosition/MouseArea" index="0"] +position = Vector2( 0, 4.5 ) +shape = SubResource( 5 ) diff --git a/src/assets/items/iron-tripod.tscn b/src/assets/items/iron-tripod.tscn new file mode 100644 index 00000000..f9d5c9e4 --- /dev/null +++ b/src/assets/items/iron-tripod.tscn @@ -0,0 +1,50 @@ +[gd_scene load_steps=9 format=2] + +[ext_resource path="res://assets/items/item.tscn" type="PackedScene" id=1] +[ext_resource path="res://assets/common/shaders/items.shader" type="Shader" id=2] +[ext_resource path="res://assets/items/textures/iron_tripod.png" type="Texture" id=3] + +[sub_resource type="ShaderMaterial" id=1] +resource_local_to_scene = true +shader = ExtResource( 2 ) +shader_param/line_color = Color( 1, 1, 1, 1 ) +shader_param/line_thickness = 5.0 + +[sub_resource type="CapsuleShape2D" id=2] +radius = 13.7841 +height = 5.99475 + +[sub_resource type="ShaderMaterial" id=3] +resource_local_to_scene = true +shader = ExtResource( 2 ) +shader_param/line_color = Color( 1, 1, 0, 0 ) +shader_param/line_thickness = 5.0 + +[sub_resource type="SpriteFrames" id=4] +animations = [ { +"frames": [ ExtResource( 3 ) ], +"loop": true, +"name": "default", +"speed": 5.0 +} ] + +[sub_resource type="CapsuleShape2D" id=5] +radius = 15.7887 +height = 9.22651 + +[node name="IronTripod" instance=ExtResource( 1 )] +material = SubResource( 1 ) + +[node name="ItemCollision" parent="." index="0"] +position = Vector2( 0, 9 ) +shape = SubResource( 2 ) + +[node name="ItemSprite" parent="SpritePosition" index="0"] +material = SubResource( 3 ) +position = Vector2( 0, 8 ) +scale = Vector2( 0.15, 0.15 ) +frames = SubResource( 4 ) + +[node name="MouseCollision" parent="SpritePosition/MouseArea" index="0"] +position = Vector2( 0, 5 ) +shape = SubResource( 5 ) diff --git a/src/assets/items/textures/beaker-empty.png b/src/assets/items/textures/beaker-empty.png new file mode 100644 index 00000000..39efdefd --- /dev/null +++ b/src/assets/items/textures/beaker-empty.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:72d3adcd6558b937e57e0dbbc370ee48eec12d944b6fdae7ef6aca73fd5598ed +size 8673 diff --git a/src/assets/items/textures/beaker-empty.png.import b/src/assets/items/textures/beaker-empty.png.import new file mode 100644 index 00000000..7c891a48 --- /dev/null +++ b/src/assets/items/textures/beaker-empty.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/beaker-empty.png-38544917ebf9cfa0f5ac641aef007203.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/items/textures/beaker-empty.png" +dest_files=[ "res://.import/beaker-empty.png-38544917ebf9cfa0f5ac641aef007203.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/src/assets/items/textures/flask-empty.png b/src/assets/items/textures/flask-empty.png new file mode 100644 index 00000000..c5034d0e --- /dev/null +++ b/src/assets/items/textures/flask-empty.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f5e67ded5740bc1cb0668d3e71f7f0f1e55699b5bc6a1376c68b41c686b047d1 +size 5212 diff --git a/src/assets/items/textures/flask-empty.png.import b/src/assets/items/textures/flask-empty.png.import new file mode 100644 index 00000000..f910c144 --- /dev/null +++ b/src/assets/items/textures/flask-empty.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/flask-empty.png-8d12cce29361badcc5e51061e3784dd9.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/items/textures/flask-empty.png" +dest_files=[ "res://.import/flask-empty.png-8d12cce29361badcc5e51061e3784dd9.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/src/assets/items/textures/gas_burner.png b/src/assets/items/textures/gas_burner.png new file mode 100644 index 00000000..6da7210f --- /dev/null +++ b/src/assets/items/textures/gas_burner.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:519b60821576e61aa93376a0a45e9cb039be4f4a81f5652203e1035f51ded8b9 +size 7450 diff --git a/src/assets/items/textures/gas_burner.png.import b/src/assets/items/textures/gas_burner.png.import new file mode 100644 index 00000000..7bcb8bf2 --- /dev/null +++ b/src/assets/items/textures/gas_burner.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/gas_burner.png-0a110d252f0d01b0f2ea1cad77a7fbae.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/items/textures/gas_burner.png" +dest_files=[ "res://.import/gas_burner.png-0a110d252f0d01b0f2ea1cad77a7fbae.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/src/assets/items/textures/iron_tripod.png b/src/assets/items/textures/iron_tripod.png new file mode 100644 index 00000000..d46dd2d7 --- /dev/null +++ b/src/assets/items/textures/iron_tripod.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:750c42f0b1eb8bdd51adca94d5cf0ffd9d74a97b66396642059fa2f183a7160c +size 4437 diff --git a/src/assets/items/textures/iron_tripod.png.import b/src/assets/items/textures/iron_tripod.png.import new file mode 100644 index 00000000..ad1b8649 --- /dev/null +++ b/src/assets/items/textures/iron_tripod.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/iron_tripod.png-ba36b18d4bbc63c12198090560d3e65c.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/items/textures/iron_tripod.png" +dest_files=[ "res://.import/iron_tripod.png-ba36b18d4bbc63c12198090560d3e65c.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 From 5233618b9e9e58287b88fda8a4d721b486d3c35f Mon Sep 17 00:00:00 2001 From: Zapzoop0099 Date: Sun, 28 Mar 2021 11:50:31 +0530 Subject: [PATCH 16/18] Basic scene setup --- src/assets/items/beaker-empty.tscn | 4 + src/assets/items/flask-empty.tscn | 4 + src/assets/items/gas-burner.tscn | 4 + src/assets/items/iron-tripod.tscn | 4 + src/assets/items/large-liquid-bottle.tscn | 6 +- src/assets/items/powder-bottle.tscn | 18 +++-- src/assets/items/small-liquid-bottle.tscn | 6 +- src/assets/ui/tasks/container/container.gd | 85 +++++++++++++++----- src/assets/ui/tasks/container/container.tscn | 9 +-- src/assets/ui/tasks/container/itemslot.gd | 21 +++-- src/assets/ui/tasks/container/itemslot.tscn | 20 +---- 11 files changed, 115 insertions(+), 66 deletions(-) diff --git a/src/assets/items/beaker-empty.tscn b/src/assets/items/beaker-empty.tscn index b98a7bee..28c25231 100644 --- a/src/assets/items/beaker-empty.tscn +++ b/src/assets/items/beaker-empty.tscn @@ -37,6 +37,7 @@ material = SubResource( 1 ) position = Vector2( 0, 0.436 ) [node name="ItemCollision" parent="." index="0"] +visible = false position = Vector2( 3.5, 10 ) shape = SubResource( 2 ) @@ -47,6 +48,9 @@ scale = Vector2( 0.15, 0.15 ) frames = SubResource( 4 ) offset = Vector2( 0, 0 ) +[node name="MouseArea" parent="SpritePosition" index="1"] +visible = false + [node name="MouseCollision" parent="SpritePosition/MouseArea" index="0"] position = Vector2( 3, 6 ) shape = SubResource( 5 ) diff --git a/src/assets/items/flask-empty.tscn b/src/assets/items/flask-empty.tscn index cc228e8c..7e4d19f8 100644 --- a/src/assets/items/flask-empty.tscn +++ b/src/assets/items/flask-empty.tscn @@ -36,6 +36,7 @@ height = 6.84969 material = SubResource( 1 ) [node name="ItemCollision" parent="." index="0"] +visible = false position = Vector2( 0, 7 ) shape = SubResource( 2 ) @@ -45,6 +46,9 @@ position = Vector2( 0, 8 ) scale = Vector2( 0.15, 0.15 ) frames = SubResource( 4 ) +[node name="MouseArea" parent="SpritePosition" index="1"] +visible = false + [node name="MouseCollision" parent="SpritePosition/MouseArea" index="0"] position = Vector2( 0, 5 ) shape = SubResource( 5 ) diff --git a/src/assets/items/gas-burner.tscn b/src/assets/items/gas-burner.tscn index aaffee62..b2aa3c27 100644 --- a/src/assets/items/gas-burner.tscn +++ b/src/assets/items/gas-burner.tscn @@ -36,6 +36,7 @@ height = 2.09932 material = SubResource( 1 ) [node name="ItemCollision" parent="." index="0"] +visible = false position = Vector2( 0, 7 ) shape = SubResource( 2 ) @@ -45,6 +46,9 @@ position = Vector2( 0, 8 ) scale = Vector2( 0.15, 0.15 ) frames = SubResource( 4 ) +[node name="MouseArea" parent="SpritePosition" index="1"] +visible = false + [node name="MouseCollision" parent="SpritePosition/MouseArea" index="0"] position = Vector2( 0, 4.5 ) shape = SubResource( 5 ) diff --git a/src/assets/items/iron-tripod.tscn b/src/assets/items/iron-tripod.tscn index f9d5c9e4..3b096df7 100644 --- a/src/assets/items/iron-tripod.tscn +++ b/src/assets/items/iron-tripod.tscn @@ -36,6 +36,7 @@ height = 9.22651 material = SubResource( 1 ) [node name="ItemCollision" parent="." index="0"] +visible = false position = Vector2( 0, 9 ) shape = SubResource( 2 ) @@ -45,6 +46,9 @@ position = Vector2( 0, 8 ) scale = Vector2( 0.15, 0.15 ) frames = SubResource( 4 ) +[node name="MouseArea" parent="SpritePosition" index="1"] +visible = false + [node name="MouseCollision" parent="SpritePosition/MouseArea" index="0"] position = Vector2( 0, 5 ) shape = SubResource( 5 ) diff --git a/src/assets/items/large-liquid-bottle.tscn b/src/assets/items/large-liquid-bottle.tscn index 22259826..30a2e1ff 100644 --- a/src/assets/items/large-liquid-bottle.tscn +++ b/src/assets/items/large-liquid-bottle.tscn @@ -22,7 +22,7 @@ shader_param/line_thickness = 5.0 [sub_resource type="SpriteFrames" id=4] animations = [ { -"frames": [ ExtResource( 3 ) ], +"frames": [ ExtResource( 3 ), null ], "loop": true, "name": "default", "speed": 5.0 @@ -36,6 +36,7 @@ height = 19.25 material = SubResource( 1 ) [node name="ItemCollision" parent="." index="0"] +visible = false position = Vector2( 0, 11 ) shape = SubResource( 2 ) @@ -45,6 +46,9 @@ position = Vector2( 0, 12 ) scale = Vector2( 0.15, 0.15 ) frames = SubResource( 4 ) +[node name="MouseArea" parent="SpritePosition" index="1"] +visible = false + [node name="MouseCollision" parent="SpritePosition/MouseArea" index="0"] position = Vector2( 0, 8 ) shape = SubResource( 5 ) diff --git a/src/assets/items/powder-bottle.tscn b/src/assets/items/powder-bottle.tscn index 6bd0bf7a..2aeac9bb 100644 --- a/src/assets/items/powder-bottle.tscn +++ b/src/assets/items/powder-bottle.tscn @@ -10,19 +10,19 @@ shader = ExtResource( 2 ) shader_param/line_color = Color( 1, 1, 1, 1 ) shader_param/line_thickness = 5.0 -[sub_resource type="CapsuleShape2D" id=4] +[sub_resource type="CapsuleShape2D" id=2] radius = 6.0 height = 11.0 -[sub_resource type="ShaderMaterial" id=2] +[sub_resource type="ShaderMaterial" id=3] resource_local_to_scene = true shader = ExtResource( 2 ) shader_param/line_color = Color( 1, 1, 0, 0 ) shader_param/line_thickness = 5.0 -[sub_resource type="SpriteFrames" id=3] +[sub_resource type="SpriteFrames" id=4] animations = [ { -"frames": [ ExtResource( 3 ) ], +"frames": [ ExtResource( 3 ), null ], "loop": true, "name": "default", "speed": 5.0 @@ -36,14 +36,18 @@ height = 18.0 material = SubResource( 1 ) [node name="ItemCollision" parent="." index="0"] +visible = false position = Vector2( 0, 5 ) -shape = SubResource( 4 ) +shape = SubResource( 2 ) [node name="ItemSprite" parent="SpritePosition" index="0"] -material = SubResource( 2 ) +material = SubResource( 3 ) position = Vector2( 0, 5 ) scale = Vector2( 0.15, 0.15 ) -frames = SubResource( 3 ) +frames = SubResource( 4 ) + +[node name="MouseArea" parent="SpritePosition" index="1"] +visible = false [node name="MouseCollision" parent="SpritePosition/MouseArea" index="0"] position = Vector2( 0, 3 ) diff --git a/src/assets/items/small-liquid-bottle.tscn b/src/assets/items/small-liquid-bottle.tscn index 0f229ae6..9a89f5a9 100644 --- a/src/assets/items/small-liquid-bottle.tscn +++ b/src/assets/items/small-liquid-bottle.tscn @@ -22,7 +22,7 @@ shader_param/line_thickness = 5.0 [sub_resource type="SpriteFrames" id=4] animations = [ { -"frames": [ ExtResource( 3 ) ], +"frames": [ ExtResource( 3 ), null ], "loop": true, "name": "default", "speed": 5.0 @@ -36,6 +36,7 @@ height = 15.25 material = SubResource( 1 ) [node name="ItemCollision" parent="." index="0"] +visible = false position = Vector2( 0, 6 ) shape = SubResource( 2 ) @@ -45,6 +46,9 @@ position = Vector2( 0, 7 ) scale = Vector2( 0.15, 0.15 ) frames = SubResource( 4 ) +[node name="MouseArea" parent="SpritePosition" index="1"] +visible = false + [node name="MouseCollision" parent="SpritePosition/MouseArea" index="0"] position = Vector2( 0, 4 ) shape = SubResource( 5 ) diff --git a/src/assets/ui/tasks/container/container.gd b/src/assets/ui/tasks/container/container.gd index 3e090c9e..1d7b9462 100644 --- a/src/assets/ui/tasks/container/container.gd +++ b/src/assets/ui/tasks/container/container.gd @@ -5,11 +5,9 @@ onready var grid = $background/conatainergrid const slot_scene = preload("res://assets/ui/tasks/container/itemslot.tscn") var available_items:Dictionary = { - "battery":{"scene":preload("res://assets/items/battery.tscn")}, - "wrench":{"scene":preload("res://assets/items/wrench.tscn")}, - "large-liquid-bottle":{"scene":preload("res://assets/items/large-liquid-bottle.tscn")}, - "powder-bottle":{"scene":preload("res://assets/items/powder-bottle.tscn")}, - "small-liquid-bottle":{"scene":preload("res://assets/items/small-liquid-bottle.tscn")} + "large-liquid-bottle":{"scene":preload("res://assets/items/large-liquid-bottle.tscn"),"position":Vector2(40,56),"shift":8,"scale":Vector2(1.5,1.5)}, + "powder-bottle":{"scene":preload("res://assets/items/powder-bottle.tscn"),"position":Vector2(40,80),"shift":8,"scale":Vector2(2,2)}, + "small-liquid-bottle":{"scene":preload("res://assets/items/small-liquid-bottle.tscn"),"position":Vector2(40,64),"shift":8,"scale":Vector2(2,2)} } var current_item_instanced:Array = [] var slots_in_grid:Dictionary={} @@ -31,17 +29,19 @@ func _on_closebutton_pressed():#Resets the data which is passed interact({},get_res().actions.CLOSE) func _on_set_scene() -> void: + print("called") #Place where the scene is built for num in range(0, slots): var slot = slot_scene.instance() slot.index = num slot.container = self - grid.add_child(slot) - var item_to_instance = place_item(slot) - if item_to_instance == null: - break - var number_of_item = set_amount(slot) - slots_in_grid[slot.index] = {"slot":slot,"item_instanced":item_to_instance,"number_of_item":number_of_item} + if can_set_up_items(slot): + grid.add_child(slot) +# var item_to_instance = place_item(slot) +# if item_to_instance == null: +# break +# var number_of_item = set_amount(slot) +# slots_in_grid[slot.index] = {"slot":slot,"item_instanced":item_to_instance,"number_of_item":number_of_item} get_res().slots_info = slots_in_grid func _on_erase_children() -> void:#erases all child @@ -69,27 +69,68 @@ func update(): get_res().connect("set_scene", self, "_on_set_scene") get_res().connect("erase_children", self, "_on_erase_children") -func randomizer(item): - for items in available_items.keys(): - if item == items: - var item_as_child = available_items[item].scene.instance() - return item_as_child +#func randomizer(item,number_of_item): +# var item_as_child +# for items in available_items.keys(): +# if item == items: +# for item in range(0, number_of_item): +# item_as_child = available_items[item].scene.instance() +# return item_as_child -func set_position_and_add_child(slot, item): - item.position += Vector2(64,64) - slot.add_child(item) +#func set_position_and_add_child(slot, item): +# item.position += Vector2(64,64) +# slot.add_child(item) func set_amount(slot): var number_of_item = Helpers.pick_random(range(0,11)) - slot.amount.text = str(number_of_item) return number_of_item -func place_item(slot): +func random_item(slot): var item_to_instance = Helpers.pick_random(available_items.keys()) if current_item_instanced.has(item_to_instance): return null else: current_item_instanced.append(item_to_instance) - set_position_and_add_child(slot, randomizer(item_to_instance)) return item_to_instance + +func can_set_up_items(slot) -> bool: + var item_as_child + var item_to_instanced = random_item(slot) + if item_to_instanced == null: + return false + print(item_to_instanced) + var number_of_item = set_amount(slot) + + if not available_items.keys().has(item_to_instanced): + return false + + for item_count in range(0,number_of_item): + item_as_child = available_items[item_to_instanced].scene.instance() + slot.add_child(item_as_child) + slot.move_child(item_as_child,0) + set_item_position(item_to_instanced,item_as_child,item_count,number_of_item) + slots_in_grid[slot.index] = {"slot":slot,"item_instanced":item_to_instanced,"number_of_item":number_of_item} + return true + #set_position_and_add_child(slot, randomizer(item_to_instanced,number_of_item)) + +func set_item_position(item_name,item,item_count,number_of_item): + var item_scale = available_items[item_name].scale + item.set_scale(item_scale) + item.position += available_items[item_name].position + if not item_count != 0: + return + var item_shift = available_items[item_name].shift + var position = item.position + position.x += item_count * item_shift + position.y -= item_count * item_shift + item.position = position + #var item_shift = available_items[item_name].shift + #print(item.position) + #var position = item.position + #position.x += item_shift + #position.y -= item_shift + #print(position) + #item.position = position + + diff --git a/src/assets/ui/tasks/container/container.tscn b/src/assets/ui/tasks/container/container.tscn index 8687fd3c..9f2eb683 100644 --- a/src/assets/ui/tasks/container/container.tscn +++ b/src/assets/ui/tasks/container/container.tscn @@ -42,11 +42,10 @@ __meta__ = { } [node name="conatainergrid" type="GridContainer" parent="background"] -margin_left = 32.0 -margin_top = 112.0 -margin_right = 696.0 -margin_bottom = 492.0 -custom_constants/vseparation = 200 +margin_top = 160.0 +margin_right = 728.0 +margin_bottom = 544.0 +custom_constants/vseparation = 175 custom_constants/hseparation = 92 columns = 4 __meta__ = { diff --git a/src/assets/ui/tasks/container/itemslot.gd b/src/assets/ui/tasks/container/itemslot.gd index fc8a3002..d687ae68 100644 --- a/src/assets/ui/tasks/container/itemslot.gd +++ b/src/assets/ui/tasks/container/itemslot.gd @@ -7,32 +7,29 @@ var mouse_entered:bool var index:int var container -signal input_received(ui_data, index) - func _ready(): pass func _on_Control_gui_input(event): if event is InputEventMouseButton and event.pressed and event.button_index == BUTTON_LEFT and mouse_entered == true: - if itemslot.get_child(1) != null: + if itemslot.get_child(0) != null: container.get_res().generate_interact_data(index) -func _on_Control_mouse_entered(): - if itemslot.get_child_count() == 1: +func _on_itemslot_mouse_entered(): + if itemslot.get_child_count() == 0: return else: - itemslot.get_child(1).animator.play("hover") - itemslot.get_child(1).can_pickup_with_mouse = true + itemslot.get_child(get_child_count() - 1).animator.play("hover") + itemslot.get_child(get_child_count() - 1).can_pickup_with_mouse = true mouse_entered = true -func _on_Control_mouse_exited(): - if itemslot.get_child_count() == 1: +func _on_itemslot_mouse_exited(): + if itemslot.get_child_count() == 0: return else: - itemslot.get_child(1).animator.play("idle") - itemslot.get_child(1).can_pickup_with_mouse = false + itemslot.get_child(get_child_count() - 1).animator.play("idle") + itemslot.get_child(get_child_count() - 1).can_pickup_with_mouse = false mouse_entered = false - diff --git a/src/assets/ui/tasks/container/itemslot.tscn b/src/assets/ui/tasks/container/itemslot.tscn index 1f134eb3..df000718 100644 --- a/src/assets/ui/tasks/container/itemslot.tscn +++ b/src/assets/ui/tasks/container/itemslot.tscn @@ -15,21 +15,5 @@ script = ExtResource( 1 ) __meta__ = { "_edit_use_anchors_": true } - -[node name="Control" type="Control" parent="."] -margin_right = 128.0 -margin_bottom = 128.0 - -[node name="Label" type="Label" parent="Control"] -margin_left = 96.0 -margin_top = 96.0 -margin_right = 120.0 -margin_bottom = 118.0 -text = "8" -align = 2 -__meta__ = { -"_edit_use_anchors_": false -} -[connection signal="gui_input" from="Control" to="." method="_on_Control_gui_input"] -[connection signal="mouse_entered" from="Control" to="." method="_on_Control_mouse_entered"] -[connection signal="mouse_exited" from="Control" to="." method="_on_Control_mouse_exited"] +[connection signal="mouse_entered" from="." to="." method="_on_itemslot_mouse_entered"] +[connection signal="mouse_exited" from="." to="." method="_on_itemslot_mouse_exited"] From 885e2624a41a061ca1c7f7652667f50bfa6558a4 Mon Sep 17 00:00:00 2001 From: Zapzoop0099 Date: Sun, 28 Mar 2021 22:49:54 +0530 Subject: [PATCH 17/18] Cleanup --- src/assets/autoload/taskmanager.gd | 6 ++ src/assets/autoload/uimanager.gd | 8 +- src/assets/main/maps.gd | 4 +- .../mapnodescripts/spawnpositionofitem.gd | 14 +-- .../resource/containerinteracttask.gd | 67 ++++++++++++-- src/assets/ui/tasks/container/container.gd | 91 ++----------------- src/assets/ui/uicontroller/uicontroller.gd | 1 + 7 files changed, 85 insertions(+), 106 deletions(-) diff --git a/src/assets/autoload/taskmanager.gd b/src/assets/autoload/taskmanager.gd index 37cbc8d4..7cfe4450 100644 --- a/src/assets/autoload/taskmanager.gd +++ b/src/assets/autoload/taskmanager.gd @@ -22,6 +22,12 @@ var player_tasks: Dictionary = {} #format: {: {name: , type: , state: , resource: , assigned_players: []} var task_dict: Dictionary = {} +var available_items:Dictionary = { + "large-liquid-bottle":{"scene":preload("res://assets/items/large-liquid-bottle.tscn"),"position":Vector2(40,56),"shift":8,"scale":Vector2(1.5,1.5)}, + "powder-bottle":{"scene":preload("res://assets/items/powder-bottle.tscn"),"position":Vector2(40,80),"shift":8,"scale":Vector2(2,2)}, + "small-liquid-bottle":{"scene":preload("res://assets/items/small-liquid-bottle.tscn"),"position":Vector2(40,64),"shift":8,"scale":Vector2(2,2)} +} + var node_path_resource: Dictionary = {} const PLAYER_ID_KEY = "player_id" diff --git a/src/assets/autoload/uimanager.gd b/src/assets/autoload/uimanager.gd index 94e7410a..2d1d6123 100644 --- a/src/assets/autoload/uimanager.gd +++ b/src/assets/autoload/uimanager.gd @@ -123,9 +123,13 @@ func state_changed(old_state, new_state): func state_changed_priority(old_state, new_state, priority): if priority != 0: return - if new_state == GameManager.State.Normal: + match new_state: + GameManager.State.Normal: # needs to call _on_ready to connect signals, before roles are assigned - open_ui("rolescreen") + open_ui("rolescreen") + pre_instance("container") + GameManager.State.Lobby: + free_ui("container") func in_ui() -> bool: return not open_uis.empty() diff --git a/src/assets/main/maps.gd b/src/assets/main/maps.gd index 042cee99..a76912d9 100644 --- a/src/assets/main/maps.gd +++ b/src/assets/main/maps.gd @@ -68,8 +68,8 @@ func switchMap(newMap: String) -> void: # actual current map to position 0 manually. move_child(mapClone, 0) emit_signal("spawn", getSpawnPoints()) - if newMap == "Test": - init_all_tasks() + #if newMap == "Test": + # init_all_tasks() func instance_map(map_name: String) -> Node: # print("instancing map ", map_name) diff --git a/src/assets/maps/test/tasks/container/mapnodescripts/spawnpositionofitem.gd b/src/assets/maps/test/tasks/container/mapnodescripts/spawnpositionofitem.gd index b0c96944..fc8ef764 100644 --- a/src/assets/maps/test/tasks/container/mapnodescripts/spawnpositionofitem.gd +++ b/src/assets/maps/test/tasks/container/mapnodescripts/spawnpositionofitem.gd @@ -1,19 +1,11 @@ extends Node2D onready var map_items: Node2D -# Declare member variables here. Examples: -# var a = 2 -# var b = "text" -var available_items:Dictionary = { - "battery":{"scene":preload("res://assets/items/battery.tscn")}, - "wrench":{"scene":preload("res://assets/items/wrench.tscn")}, - "large-liquid-bottle":{"scene":preload("res://assets/items/large-liquid-bottle.tscn")}, - "powder-bottle":{"scene":preload("res://assets/items/powder-bottle.tscn")}, - "small-liquid-bottle":{"scene":preload("res://assets/items/small-liquid-bottle.tscn")} -} + +var available_items:Dictionary = TaskManager.available_items var total_items:Array=[] var data = null -# Called when the node enters the scene tree for the first time. + func _ready(): MapManager.connect("interacted_with", self, "on_interacted_with") yield(get_tree(), "idle_frame") diff --git a/src/assets/maps/test/tasks/container/resource/containerinteracttask.gd b/src/assets/maps/test/tasks/container/resource/containerinteracttask.gd index 4fafafa1..bdeb823c 100644 --- a/src/assets/maps/test/tasks/container/resource/containerinteracttask.gd +++ b/src/assets/maps/test/tasks/container/resource/containerinteracttask.gd @@ -7,7 +7,11 @@ signal set_scene signal erase_children var slots_info:Dictionary = {} +var available_items:Dictionary = TaskManager.available_items + +var current_item_instanced:Array = [] var items_to_hold:Array = ["battery","wrench"] + var data = null func _init(): @@ -50,27 +54,71 @@ func update(_from, _data, value): func _sync_task(): - task_rpc("_server_set_scene",["_no_var"]) + task_rpc("_server_set_scene") -func _server_set_scene(_arr): +func _server_set_scene(): emit_signal("set_scene") - task_rpc("_client_set_scene", ["_no_var"]) + task_rpc("_client_set_scene") -func _server_erase_children(_dic): +func _server_erase_children(): emit_signal("erase_children") - task_rpc("_client_erase_children", ["_no_var"]) + task_rpc("_client_erase_children") -func _client_set_scene(_dic): +func _client_set_scene(): emit_signal("set_scene") -func _client_erase_children(_dic): +func _client_erase_children(): emit_signal("erase_children") - func _on_state_changed(_old_state, new_state) -> void:#resets the task when state changes match new_state: GameManager.State.Lobby: - task_rpc("_server_erase_children", ["no_var"]) + task_rpc("_server_erase_children") + + +func set_amount(slot): + var number_of_item = Helpers.pick_random(range(0,5)) + return number_of_item + +func random_item(slot): + var item_to_instance = Helpers.pick_random(available_items.keys()) + if current_item_instanced.has(item_to_instance): + return null + else: + current_item_instanced.append(item_to_instance) + return item_to_instance + +func can_set_up_items(slot) -> bool: + var item_as_child + var item_to_instanced = random_item(slot) + if item_to_instanced == null: + return false + print(item_to_instanced) + var number_of_item = set_amount(slot) + + if not available_items.keys().has(item_to_instanced): + return false + + for item_count in range(0,number_of_item): + item_as_child = available_items[item_to_instanced].scene.instance() + slot.add_child(item_as_child) + slot.move_child(item_as_child,0) + set_item_position(item_to_instanced,item_as_child,item_count,number_of_item) + slots_info[slot.index] = {"slot":slot,"item_instanced":item_to_instanced,"number_of_item":number_of_item} + return true + #set_position_and_add_child(slot, randomizer(item_to_instanced,number_of_item)) + +func set_item_position(item_name,item,item_count,number_of_item): + var item_scale = available_items[item_name].scale + item.set_scale(item_scale) + item.position += available_items[item_name].position + if not item_count != 0: + return + var item_shift = available_items[item_name].shift + var position = item.position + position.x += item_count * item_shift + position.y -= item_count * item_shift + item.position = position func generate_interact_data(slot_index): var interact_data:Dictionary = {} @@ -84,3 +132,4 @@ func send_interact_data(interact_data): if map_outputs_on: for resource in map_outputs: resource.interact(attached_to, merged_dic) + diff --git a/src/assets/ui/tasks/container/container.gd b/src/assets/ui/tasks/container/container.gd index 1d7b9462..8f96da7b 100644 --- a/src/assets/ui/tasks/container/container.gd +++ b/src/assets/ui/tasks/container/container.gd @@ -4,12 +4,6 @@ onready var grid = $background/conatainergrid const slot_scene = preload("res://assets/ui/tasks/container/itemslot.tscn") -var available_items:Dictionary = { - "large-liquid-bottle":{"scene":preload("res://assets/items/large-liquid-bottle.tscn"),"position":Vector2(40,56),"shift":8,"scale":Vector2(1.5,1.5)}, - "powder-bottle":{"scene":preload("res://assets/items/powder-bottle.tscn"),"position":Vector2(40,80),"shift":8,"scale":Vector2(2,2)}, - "small-liquid-bottle":{"scene":preload("res://assets/items/small-liquid-bottle.tscn"),"position":Vector2(40,64),"shift":8,"scale":Vector2(2,2)} -} -var current_item_instanced:Array = [] var slots_in_grid:Dictionary={} export(int) var slots @@ -21,41 +15,26 @@ func _ready(): # GameManager.connect('state_changed', self, '_on_state_changed') pass -func _on_closebutton_pressed():#Resets the data which is passed - for key in ui_data.keys(): - if typeof(key) == TYPE_INT: - var player = ui_data[key] - get_tree().get_root().get_node(player).can_pickup = true - interact({},get_res().actions.CLOSE) - func _on_set_scene() -> void: - print("called") #Place where the scene is built for num in range(0, slots): var slot = slot_scene.instance() slot.index = num slot.container = self - if can_set_up_items(slot): + if get_res().can_set_up_items(slot): grid.add_child(slot) -# var item_to_instance = place_item(slot) -# if item_to_instance == null: -# break -# var number_of_item = set_amount(slot) -# slots_in_grid[slot.index] = {"slot":slot,"item_instanced":item_to_instance,"number_of_item":number_of_item} - get_res().slots_info = slots_in_grid + +func _on_closebutton_pressed():#Resets the data which is passed + for key in ui_data.keys(): + if typeof(key) == TYPE_INT: + var player = ui_data[key] + get_tree().get_root().get_node(player).can_pickup = true + interact({},get_res().actions.CLOSE) func _on_erase_children() -> void:#erases all child for child in grid.get_children(): child.queue_free() -#func _on_state_changed(_old_state, new_state) -> void:#resets the task when state changes -# match new_state: -# GameManager.State.Normal: -# if grid.get_child(0) == null: -# rpc_id(1,"set_slot_server") -# GameManager.State.Lobby: -# rpc_id(1, "erase_children_server") -# rpc_id(1, "reset_server") func get_res() -> Resource: var res = TaskManager.get_task_resource(ui_data[TaskManager.TASK_ID_KEY]) return res @@ -65,6 +44,7 @@ func interact(data:Dictionary = {}, value = get_res().actions.OPEN): get_res().interact(self,data, value) func update(): + print("updated") # warning-ignore:return_value_discarded get_res().connect("set_scene", self, "_on_set_scene") get_res().connect("erase_children", self, "_on_erase_children") @@ -81,56 +61,3 @@ func update(): # item.position += Vector2(64,64) # slot.add_child(item) - -func set_amount(slot): - var number_of_item = Helpers.pick_random(range(0,11)) - return number_of_item - -func random_item(slot): - var item_to_instance = Helpers.pick_random(available_items.keys()) - if current_item_instanced.has(item_to_instance): - return null - else: - current_item_instanced.append(item_to_instance) - return item_to_instance - -func can_set_up_items(slot) -> bool: - var item_as_child - var item_to_instanced = random_item(slot) - if item_to_instanced == null: - return false - print(item_to_instanced) - var number_of_item = set_amount(slot) - - if not available_items.keys().has(item_to_instanced): - return false - - for item_count in range(0,number_of_item): - item_as_child = available_items[item_to_instanced].scene.instance() - slot.add_child(item_as_child) - slot.move_child(item_as_child,0) - set_item_position(item_to_instanced,item_as_child,item_count,number_of_item) - slots_in_grid[slot.index] = {"slot":slot,"item_instanced":item_to_instanced,"number_of_item":number_of_item} - return true - #set_position_and_add_child(slot, randomizer(item_to_instanced,number_of_item)) - -func set_item_position(item_name,item,item_count,number_of_item): - var item_scale = available_items[item_name].scale - item.set_scale(item_scale) - item.position += available_items[item_name].position - if not item_count != 0: - return - var item_shift = available_items[item_name].shift - var position = item.position - position.x += item_count * item_shift - position.y -= item_count * item_shift - item.position = position - #var item_shift = available_items[item_name].shift - #print(item.position) - #var position = item.position - #position.x += item_shift - #position.y -= item_shift - #print(position) - #item.position = position - - diff --git a/src/assets/ui/uicontroller/uicontroller.gd b/src/assets/ui/uicontroller/uicontroller.gd index 50a526a6..f3767bd8 100644 --- a/src/assets/ui/uicontroller/uicontroller.gd +++ b/src/assets/ui/uicontroller/uicontroller.gd @@ -135,5 +135,6 @@ func pre_instance(ui_name: String):#Make the ui to be in active state when a gam update_instanced_uis() if instanced_uis.keys().has(ui_name): return + print(instanced_uis) instance_ui(ui_name) close_ui(ui_name) From e58b129673070889e0e9c31be7a24cbccf83c629 Mon Sep 17 00:00:00 2001 From: Zapzoop0099 Date: Tue, 30 Mar 2021 13:30:02 +0530 Subject: [PATCH 18/18] Working Container --- .../mapnodescripts/spawnpositionofitem.gd | 14 ++----- .../resource/containerinteracttask.gd | 39 +++++++++++++++---- src/assets/ui/tasks/container/itemslot.gd | 13 +++---- src/assets/ui/tasks/container/itemslot.tscn | 1 + .../ui/tasks/container/itemslotbackend.gd | 38 ------------------ 5 files changed, 42 insertions(+), 63 deletions(-) delete mode 100644 src/assets/ui/tasks/container/itemslotbackend.gd diff --git a/src/assets/maps/test/tasks/container/mapnodescripts/spawnpositionofitem.gd b/src/assets/maps/test/tasks/container/mapnodescripts/spawnpositionofitem.gd index fc8ef764..fe463c20 100644 --- a/src/assets/maps/test/tasks/container/mapnodescripts/spawnpositionofitem.gd +++ b/src/assets/maps/test/tasks/container/mapnodescripts/spawnpositionofitem.gd @@ -16,15 +16,13 @@ func on_interacted_with(interactNode, from, interact_data): if interactNode != self: return data = interact_data.duplicate() - print(data) - add_item(interact_data["item_instanced"],interact_data["number_of_item"]) + add_item(data["item_instanced"]) -func add_item(item_instanced, number): +func add_item(item_instanced): for items in available_items.keys(): - if item_instanced == items and int(number) != 0: + if item_instanced == items: var item_as_child = available_items[item_instanced].scene.instance() - update_data() map_items.add_child(item_as_child) get_tree().get_root().get_node(get_player()).item_handler._test_pickup(item_as_child) @@ -39,9 +37,3 @@ func get_player(): var player = data[key] return player -func update_data(): - var dic_to_change = data.duplicate() - var number = int(dic_to_change["number_of_item"]) - dic_to_change["number_of_item"] = str(number - 1) - data = dic_to_change - #print(data) diff --git a/src/assets/maps/test/tasks/container/resource/containerinteracttask.gd b/src/assets/maps/test/tasks/container/resource/containerinteracttask.gd index bdeb823c..3ed59acc 100644 --- a/src/assets/maps/test/tasks/container/resource/containerinteracttask.gd +++ b/src/assets/maps/test/tasks/container/resource/containerinteracttask.gd @@ -12,7 +12,8 @@ var available_items:Dictionary = TaskManager.available_items var current_item_instanced:Array = [] var items_to_hold:Array = ["battery","wrench"] -var data = null +var player_data = null +var interact_data:Dictionary = {} func _init(): add_networked_func("_server_set_scene", MultiplayerAPI.RPC_MODE_MASTER) @@ -42,7 +43,7 @@ func interact(_from: Node = null, _interact_data: Dictionary = {}, value = actio return if is_task_completed(Network.get_my_id()): return - data = _interact_data + player_data = _interact_data var merged_dic = Helpers.merge_dicts(_interact_data, get_task_data()) set_action(value) ui_res.interact(_from, merged_dic) @@ -121,15 +122,39 @@ func set_item_position(item_name,item,item_count,number_of_item): item.position = position func generate_interact_data(slot_index): - var interact_data:Dictionary = {} for index in slots_info.keys(): if index == slot_index: interact_data = slots_info[index].duplicate() - send_interact_data(interact_data) + send_interact_data(filter_data()) + update_scene() -func send_interact_data(interact_data): - var merged_dic = Helpers.merge_dicts(interact_data, data) +func send_interact_data(interact_data:Dictionary={}): + var merged_dic = Helpers.merge_dicts(interact_data, player_data) if map_outputs_on: for resource in map_outputs: resource.interact(attached_to, merged_dic) - + +func filter_data(): + var number = interact_data["number_of_item"] + if number == 0: + return + + var key_to_remove=["number_of_item","slot"] + var filtered_data:Dictionary = interact_data.duplicate() + + for key in key_to_remove: + filtered_data.erase(key_to_remove) + + return filtered_data + +func update_scene(): + var updated_data = interact_data.duplicate() + var number = int(updated_data["number_of_item"]) + updated_data["number_of_item"] = str(number - 1) + interact_data = updated_data + update_slot() + +func update_slot(): + var slot = interact_data["slot"] + slot.get_child(0).queue_free() + diff --git a/src/assets/ui/tasks/container/itemslot.gd b/src/assets/ui/tasks/container/itemslot.gd index d687ae68..a21a6220 100644 --- a/src/assets/ui/tasks/container/itemslot.gd +++ b/src/assets/ui/tasks/container/itemslot.gd @@ -9,13 +9,6 @@ var container func _ready(): pass - - -func _on_Control_gui_input(event): - if event is InputEventMouseButton and event.pressed and event.button_index == BUTTON_LEFT and mouse_entered == true: - if itemslot.get_child(0) != null: - container.get_res().generate_interact_data(index) - func _on_itemslot_mouse_entered(): if itemslot.get_child_count() == 0: @@ -33,3 +26,9 @@ func _on_itemslot_mouse_exited(): itemslot.get_child(get_child_count() - 1).animator.play("idle") itemslot.get_child(get_child_count() - 1).can_pickup_with_mouse = false mouse_entered = false + + +func _on_itemslot_gui_input(event): + if event is InputEventMouseButton and event.pressed and event.button_index == BUTTON_LEFT and mouse_entered == true: + if itemslot.get_child(0) != null: + container.get_res().generate_interact_data(index) diff --git a/src/assets/ui/tasks/container/itemslot.tscn b/src/assets/ui/tasks/container/itemslot.tscn index df000718..4ddc8491 100644 --- a/src/assets/ui/tasks/container/itemslot.tscn +++ b/src/assets/ui/tasks/container/itemslot.tscn @@ -15,5 +15,6 @@ script = ExtResource( 1 ) __meta__ = { "_edit_use_anchors_": true } +[connection signal="gui_input" from="." to="." method="_on_itemslot_gui_input"] [connection signal="mouse_entered" from="." to="." method="_on_itemslot_mouse_entered"] [connection signal="mouse_exited" from="." to="." method="_on_itemslot_mouse_exited"] diff --git a/src/assets/ui/tasks/container/itemslotbackend.gd b/src/assets/ui/tasks/container/itemslotbackend.gd deleted file mode 100644 index e3053956..00000000 --- a/src/assets/ui/tasks/container/itemslotbackend.gd +++ /dev/null @@ -1,38 +0,0 @@ -extends Node - -var frontend = null - -#TODO: Set a randomizer - -func _ready(): - pass -# frontend.connect("input_received", self, "on_input_received") - -func set_in_hand(ui_data_pass, index:int) -> void:#This the crucial function - if not frontend.index == index: - return - else: - var item = frontend.get_child(1) - #By only this the item from the itemslot get transferred to hand - for key in ui_data_pass.keys(): - if typeof(key) == TYPE_INT:#Filters the ui_data - var player = ui_data_pass[key] - get_tree().get_root().get_node(player).item_handler._test_pickup(item) - -puppetsync func set_path() -> void:#Give the item its location so it can remove itself and add to other location - var item = frontend.get_child(1) - var self_path = get_parent().get_path() - item.item_location = self_path - item.item_from_container = true - -func on_input_received(ui_data:Dictionary, index:int) -> void: - rpc_id(1, "set_server") - set_in_hand(ui_data,index) - -remotesync func set_server() -> void: - if not get_tree().is_network_server(): - return - var id: int = get_tree().get_rpc_sender_id() - if not Network.peers.has(id): - return - rpc("set_path")