sticker land detection + sticker mode
This commit is contained in:
parent
a4c7e49438
commit
e7729da740
3 changed files with 59 additions and 29 deletions
|
@ -7,6 +7,8 @@ class_name Sticker extends Area2D
|
|||
## all the fonctionnalities. You need to assign nodes for the stickerdetection
|
||||
## and for the sprites.
|
||||
|
||||
#region Exported variables
|
||||
@export var Sticker_mode:bool = false
|
||||
@export_group("Nodes")
|
||||
## The look of the object. If it's multiple sprites, they should be under one main sprite
|
||||
@export var WorldSprite:Sprite2D
|
||||
|
@ -22,14 +24,21 @@ class_name Sticker extends Area2D
|
|||
add_child(test)
|
||||
test.set_owner(get_tree().get_edited_scene_root())
|
||||
test = null
|
||||
#endregion
|
||||
|
||||
var meta:PackedStringArray = ["sticker"]
|
||||
var detected_solids:Array
|
||||
var detected_stickers:Array
|
||||
|
||||
|
||||
#region Functions
|
||||
|
||||
|
||||
func _init():
|
||||
collision_layer = 2
|
||||
collision_mask = 0
|
||||
collision_mask = 15
|
||||
set_meta("tags",meta)
|
||||
monitoring = false
|
||||
monitoring = true
|
||||
|
||||
func _enter_tree():
|
||||
set_meta("tags",meta)
|
||||
|
@ -41,8 +50,24 @@ func _ready():
|
|||
if (get_parent() == get_tree().root):
|
||||
printerr("stickers should always have a parent")
|
||||
breakpoint
|
||||
body_entered.connect(_on_body_entered)
|
||||
body_exited.connect(_on_body_exited)
|
||||
area_entered.connect(_on_area_entered)
|
||||
area_exited.connect(_on_area_exited)
|
||||
|
||||
|
||||
func _on_body_entered(body:Node2D):
|
||||
print("body entered",body)
|
||||
detected_solids.append(body)
|
||||
func _on_body_exited(body:Node2D):
|
||||
print("body exited",body)
|
||||
detected_solids.erase(body)
|
||||
func _on_area_entered(area:Area2D):
|
||||
print("area entered",area)
|
||||
#TODO:Filter by type
|
||||
detected_stickers.append(area)
|
||||
func _on_area_exited(area:Area2D):
|
||||
print("area exited",area)
|
||||
detected_stickers.erase(area)
|
||||
|
||||
func _process(delta):
|
||||
pass
|
||||
|
@ -51,11 +76,13 @@ func _process(delta):
|
|||
func on_released(CastResult:Array=[]):
|
||||
print(self," released")
|
||||
#TODO: Need a traceresult to know if it should stay in the stickerstate or be released in the world
|
||||
get_parent().top_level = false
|
||||
if(detected_solids.size()==0):
|
||||
get_parent().top_level = false
|
||||
disable_ChildNodes_collisions(false)
|
||||
update_ChildNodes_visibilty(true)
|
||||
Sticker_mode = false
|
||||
get_parent().reparent(MapManager.current_scene.get_child(0))
|
||||
disable_ChildNodes_collisions(false)
|
||||
update_ChildNodes_visibilty(true)
|
||||
#on_unhover() # When released behind another sticker, sometimes cursor cannot reach
|
||||
|
||||
|
||||
func on_click():
|
||||
print(self," clicked")
|
||||
|
@ -67,23 +94,27 @@ func redraw():
|
|||
WorldSprite.queue_redraw()
|
||||
|
||||
func on_hover():
|
||||
if (StickerSprite != null):
|
||||
WorldSprite.visible = false
|
||||
StickerSprite.visible = true
|
||||
elif (WorldSprite != null):
|
||||
WorldSprite.material = OutlineMat
|
||||
redraw()
|
||||
if (Sticker_mode == false):
|
||||
if (StickerSprite != null):
|
||||
WorldSprite.visible = false
|
||||
StickerSprite.visible = true
|
||||
elif (WorldSprite != null):
|
||||
WorldSprite.material = OutlineMat
|
||||
redraw()
|
||||
|
||||
|
||||
func on_unhover():
|
||||
if (StickerSprite != null):
|
||||
StickerSprite.visible = false
|
||||
if (WorldSprite != null):
|
||||
WorldSprite.material = null
|
||||
WorldSprite.visible = true
|
||||
redraw()
|
||||
if (Sticker_mode == false):
|
||||
if (StickerSprite != null):
|
||||
StickerSprite.visible = false
|
||||
if (WorldSprite != null):
|
||||
WorldSprite.material = null
|
||||
WorldSprite.visible = true
|
||||
redraw()
|
||||
|
||||
|
||||
func on_grab(_offset:Vector2=Vector2(0.0,0.0)):
|
||||
Sticker_mode = true
|
||||
get_parent().top_level = true
|
||||
get_parent().reparent(get_tree().root)
|
||||
update_ChildNodes_visibilty(false)
|
||||
|
@ -97,5 +128,6 @@ func update_ChildNodes_visibilty(_visible:bool=true):
|
|||
func disable_ChildNodes_collisions(_disable:bool=true):
|
||||
for _childNode in get_parent().get_children():
|
||||
if (_childNode != self):
|
||||
_childNode.process_mode = Node.PROCESS_MODE_DISABLED if _disable else Node.PROCESS_MODE_ALWAYS
|
||||
_childNode.process_mode = Node.PROCESS_MODE_DISABLED if _disable else Node.PROCESS_MODE_ALWAYS
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
[ext_resource type="Texture2D" uid="uid://c6acjgu8jnrkl" path="res://textures/sprites/rocks_rock1.tres" id="8_bhcew"]
|
||||
[ext_resource type="Texture2D" uid="uid://dnomlcslicb3k" path="res://textures/sprites/props_fire1.tres" id="10_2ugv3"]
|
||||
[ext_resource type="Texture2D" uid="uid://qsse8uwt06ns" path="res://textures/sprites/plants_bush2.tres" id="11_dibxq"]
|
||||
[ext_resource type="Texture2D" uid="uid://xx3dwpwk467v" path="res://textures/sprites/stickers_fire1.png" id="14_3fmba"]
|
||||
[ext_resource type="Texture2D" uid="uid://51ntd0qmjw5j" path="res://textures/sprites/props_woodbarrer.tres" id="14_n4lnm"]
|
||||
[ext_resource type="Texture2D" uid="uid://xx3dwpwk467v" path="res://textures/sprites/stickers_fire1.png" id="19_d8hr8"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_yeof8"]
|
||||
size = Vector2(202.667, 60.3336)
|
||||
|
@ -155,7 +155,6 @@ metadata/tags = PackedStringArray("sticker")
|
|||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Bush1/Sticker"]
|
||||
position = Vector2(-4.46973, -71.6294)
|
||||
rotation = 1.6
|
||||
scale = Vector2(1, 1)
|
||||
shape = SubResource("CapsuleShape2D_lfx7b")
|
||||
|
||||
[node name="Tree2" type="Sprite2D" parent="."]
|
||||
|
@ -237,7 +236,6 @@ metadata/tags = PackedStringArray("sticker")
|
|||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Tree4/Sticker"]
|
||||
position = Vector2(0, -253.27)
|
||||
rotation = 0.01
|
||||
scale = Vector2(1, 1)
|
||||
shape = SubResource("CapsuleShape2D_dqo8w")
|
||||
|
||||
[node name="Bush6" type="Sprite2D" parent="."]
|
||||
|
@ -319,7 +317,6 @@ metadata/tags = PackedStringArray("sticker")
|
|||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Bush9/Sticker"]
|
||||
position = Vector2(-4.46976, -71.6294)
|
||||
rotation = 1.6
|
||||
scale = Vector2(1, 1)
|
||||
shape = SubResource("CapsuleShape2D_lfx7b")
|
||||
|
||||
[node name="Bush8" type="Sprite2D" parent="."]
|
||||
|
@ -362,7 +359,6 @@ metadata/tags = PackedStringArray("sticker")
|
|||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Bush10/Sticker"]
|
||||
position = Vector2(0, -48.95)
|
||||
rotation = 1.5
|
||||
scale = Vector2(1, 1)
|
||||
shape = SubResource("CapsuleShape2D_b3366")
|
||||
|
||||
[node name="Rock1" type="Sprite2D" parent="."]
|
||||
|
@ -517,7 +513,7 @@ shape = SubResource("CircleShape2D_wkggp")
|
|||
[node name="FirePitSticker" type="Sprite2D" parent="FirePit"]
|
||||
visible = false
|
||||
scale = Vector2(1.8, 1.8)
|
||||
texture = ExtResource("14_3fmba")
|
||||
texture = ExtResource("19_d8hr8")
|
||||
offset = Vector2(0, -95.355)
|
||||
|
||||
[connection signal="property_list_changed" from="Bush1" to="Bush1" method="_on_property_list_changed"]
|
||||
|
|
|
@ -122,6 +122,8 @@ mouse_right={
|
|||
|
||||
2d_physics/layer_1="Player"
|
||||
2d_physics/layer_2="Stickers"
|
||||
2d_physics/layer_3="Zone"
|
||||
2d_physics/layer_4="PNJ"
|
||||
|
||||
[rendering]
|
||||
|
||||
|
|
Loading…
Reference in a new issue