Add selectable on hover effect
All checks were successful
/ test (push) Successful in 1s

This commit is contained in:
Antonio Dell'Annunziata 2025-03-05 06:35:47 +01:00
parent 7ef763605e
commit 95be5ae355
No known key found for this signature in database
GPG key ID: 8D2BB16641F06E94
4 changed files with 116 additions and 11 deletions

View file

@ -1,7 +1,8 @@
[gd_scene load_steps=9 format=3 uid="uid://w3ntt1yh1nq7"]
[gd_scene load_steps=18 format=3 uid="uid://w3ntt1yh1nq7"]
[ext_resource type="Script" path="res://dialog.gd" id="1_0qabl"]
[ext_resource type="Script" path="res://main.gd" id="1_dp5o4"]
[ext_resource type="PackedScene" uid="uid://3oqyqft8w72m" path="res://selectable.tscn" id="3_g5hfc"]
[sub_resource type="Gradient" id="Gradient_cuqb1"]
offsets = PackedFloat32Array(0)
@ -11,25 +12,61 @@ colors = PackedColorArray(0, 0, 0, 1)
gradient = SubResource("Gradient_cuqb1")
width = 1152
[sub_resource type="Gradient" id="Gradient_i35qq"]
offsets = PackedFloat32Array(0.159011)
colors = PackedColorArray(0.344076, 0.344076, 0.344076, 1)
[sub_resource type="Gradient" id="Gradient_ukr0q"]
offsets = PackedFloat32Array(0.272085)
colors = PackedColorArray(0.202521, 0.371426, 0.429081, 1)
[sub_resource type="GradientTexture2D" id="GradientTexture2D_4lgr0"]
gradient = SubResource("Gradient_i35qq")
gradient = SubResource("Gradient_ukr0q")
width = 200
height = 400
fill_from = Vector2(0.5, 0)
fill_to = Vector2(0.5, 1)
[sub_resource type="Gradient" id="Gradient_qkope"]
offsets = PackedFloat32Array(0)
offsets = PackedFloat32Array(0.0372881)
colors = PackedColorArray(0.466181, 0.466181, 0.466181, 1)
[sub_resource type="GradientTexture1D" id="GradientTexture1D_p6qcv"]
gradient = SubResource("Gradient_qkope")
width = 1152
[sub_resource type="Gradient" id="Gradient_wb6aq"]
offsets = PackedFloat32Array(0.0372881)
colors = PackedColorArray(0.281175, 0.300745, 0.258554, 1)
[sub_resource type="GradientTexture1D" id="GradientTexture1D_ij864"]
gradient = SubResource("Gradient_wb6aq")
width = 1152
[sub_resource type="Gradient" id="Gradient_b76e3"]
offsets = PackedFloat32Array(0.0881356)
colors = PackedColorArray(0.0885599, 0.0885599, 0.0885599, 1)
[sub_resource type="GradientTexture1D" id="GradientTexture1D_soglf"]
gradient = SubResource("Gradient_b76e3")
width = 1
[sub_resource type="Gradient" id="Gradient_fq5io"]
offsets = PackedFloat32Array(0.272085)
colors = PackedColorArray(0.202521, 0.371426, 0.429081, 1)
[sub_resource type="GradientTexture2D" id="GradientTexture2D_ty4ro"]
gradient = SubResource("Gradient_fq5io")
width = 100
height = 200
fill_from = Vector2(0.5, 0)
fill_to = Vector2(0.5, 1)
[sub_resource type="Gradient" id="Gradient_ncwe7"]
offsets = PackedFloat32Array(0.282686)
colors = PackedColorArray(0.368627, 0, 0, 1)
[sub_resource type="GradientTexture2D" id="GradientTexture2D_ftstk"]
gradient = SubResource("Gradient_ncwe7")
width = 170
height = 170
[node name="Main" type="Node2D"]
script = ExtResource("1_dp5o4")
@ -85,18 +122,48 @@ text = "Bob"
[node name="Room" type="Node2D" parent="."]
[node name="RoomBackground" type="Sprite2D" parent="Room"]
[node name="RoomFloor" type="Sprite2D" parent="Room"]
position = Vector2(576, 325.25)
scale = Vector2(1.001, 652)
texture = SubResource("GradientTexture1D_p6qcv")
[node name="RoomWall" type="Sprite2D" parent="Room"]
position = Vector2(578, -71)
scale = Vector2(1.001, 652)
texture = SubResource("GradientTexture1D_ij864")
[node name="Shelves" type="Sprite2D" parent="Room"]
position = Vector2(1004, 324.5)
scale = Vector2(300, 655)
texture = SubResource("GradientTexture1D_soglf")
[node name="Undead" type="Sprite2D" parent="Room"]
position = Vector2(237, 260)
scale = Vector2(0.5, 0.5)
texture = SubResource("GradientTexture2D_4lgr0")
position = Vector2(242, 258)
texture = SubResource("GradientTexture2D_ty4ro")
[node name="Selectable" parent="Room/Undead" instance=ExtResource("3_g5hfc")]
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Room/Undead/Selectable"]
polygon = PackedVector2Array(-50, 100, -50, -100, 50, -100, 50, 100)
[node name="Label" type="Label" parent="Room/Undead"]
offset_top = 2.0
offset_right = 40.0
offset_bottom = 25.0
text = "Bob"
[node name="RitualPlace" type="Sprite2D" parent="Room"]
position = Vector2(469, 390)
texture = SubResource("GradientTexture2D_ftstk")
[node name="Selectable" parent="Room/RitualPlace" instance=ExtResource("3_g5hfc")]
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Room/RitualPlace/Selectable"]
polygon = PackedVector2Array(-85, 85, -85, -85, 85, -85, 85, 85)
[node name="Label" type="Label" parent="Room/RitualPlace"]
offset_left = -41.0
offset_top = 44.0
offset_right = 49.0
offset_bottom = 67.0
text = "Ritual place"

View file

@ -11,7 +11,7 @@ config_version=5
[application]
config/name="necra-prototypes"
run/main_scene="res://operation/prototype_dark_cut.tscn"
run/main_scene="res://main.tscn"
config/features=PackedStringArray("4.3", "GL Compatibility")
config/icon="res://operation/icon.svg"

29
selectable.gd Normal file
View file

@ -0,0 +1,29 @@
class_name Selectable
extends Area2D
var selection_sprite: Sprite2D
func _ready():
if selection_sprite: return
var parent_sprite = get_parent() as Sprite2D
selection_sprite = Sprite2D.new()
selection_sprite.texture = parent_sprite.texture.duplicate(true)
var scale_x = ((selection_sprite.texture.get_size().x + 10) / selection_sprite.texture.get_size().x)
var scale_y = ((selection_sprite.texture.get_size().y + 10) / selection_sprite.texture.get_size().y)
selection_sprite.scale = Vector2(scale_x,scale_y)
selection_sprite.show_behind_parent = true
selection_sprite.modulate = Color.BLACK
selection_sprite.visible = false
parent_sprite.call_deferred("add_child", selection_sprite)
parent_sprite.call_deferred("move_child", selection_sprite, 0)
func _on_mouse_entered():
_show_selection_outline()
func _on_mouse_exited():
_hide_selection_outline()
func _show_selection_outline():
selection_sprite.show()
func _hide_selection_outline():
selection_sprite.hide()

9
selectable.tscn Normal file
View file

@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=3 uid="uid://3oqyqft8w72m"]
[ext_resource type="Script" path="res://selectable.gd" id="1_ayyf7"]
[node name="Selectable" type="Area2D"]
script = ExtResource("1_ayyf7")
[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"]
[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"]