From 45442dd549dcb4ed8e530a64f068ad4463e878d1 Mon Sep 17 00:00:00 2001 From: bleeptrack Date: Tue, 10 Nov 2020 12:14:45 +0100 Subject: [PATCH] Shader as Target Highlights --- scenes/drop_area.gd | 10 ++++++++-- scenes/drop_area.tscn | 24 +++++++++++++++++++----- scenes/file_browser_item.tscn | 16 +++++++++++++--- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/scenes/drop_area.gd b/scenes/drop_area.gd index e90df3a..0abe499 100644 --- a/scenes/drop_area.gd +++ b/scenes/drop_area.gd @@ -16,12 +16,18 @@ func _input(event): if event is InputEventMouseButton: if event.button_index == BUTTON_LEFT and !event.pressed and hovered: if highlighted and game.dragged_object: - game.dragged_object.dropped_on($"..") + game.dragged_object.dropped_on(get_parent_with_type()) func _set_highlighted(new_highlighted): highlighted = new_highlighted $Highlight.visible = highlighted + +func get_parent_with_type(): + var parent = get_parent() + while(!parent.get("type")): + parent = parent.get_parent() + return parent func highlight(type): - if get_parent().type == type: + if get_parent_with_type().type == type: _set_highlighted(true) diff --git a/scenes/drop_area.tscn b/scenes/drop_area.tscn index 7b81dee..6185c75 100644 --- a/scenes/drop_area.tscn +++ b/scenes/drop_area.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://scenes/drop_area.gd" type="Script" id=1] [ext_resource path="res://nodes/blob.svg" type="Texture" id=2] @@ -6,11 +6,24 @@ [sub_resource type="CircleShape2D" id=1] radius = 23.5871 +[sub_resource type="Shader" id=2] +code = "shader_type canvas_item; + +void fragment() { + vec2 center = vec2(0.5, 0.5); + float d = distance(UV, center); + COLOR = vec4(0.4, 0.65, 1, smoothstep(0.5,0.2,d)); +} +" +custom_defines = "" + +[sub_resource type="ShaderMaterial" id=3] +shader = SubResource( 2 ) + [node name="DropArea" type="Node2D" groups=[ "drop_areas", ]] position = Vector2( -0.197731, 0.0673599 ) -z_index = 2 script = ExtResource( 1 ) [node name="Area2D" type="Area2D" parent="."] @@ -24,9 +37,10 @@ shape = SubResource( 1 ) [node name="Highlight" type="Node2D" parent="."] [node name="Sprite" type="Sprite" parent="Highlight"] -modulate = Color( 0.847059, 0.788235, 0.996078, 0.533333 ) -position = Vector2( 0.177797, -0.65835 ) -scale = Vector2( 1.23678, 1.23678 ) +modulate = Color( 1, 1, 1, 0.643137 ) +material = SubResource( 3 ) +position = Vector2( -0.102825, -0.377726 ) +scale = Vector2( 2.25501, 2.25501 ) texture = ExtResource( 2 ) [connection signal="area_entered" from="Area2D" to="." method="_mouse_entered"] [connection signal="area_exited" from="Area2D" to="." method="_mouse_exited"] diff --git a/scenes/file_browser_item.tscn b/scenes/file_browser_item.tscn index 8ebe23c..4644d35 100644 --- a/scenes/file_browser_item.tscn +++ b/scenes/file_browser_item.tscn @@ -17,6 +17,19 @@ __meta__ = { "_edit_use_anchors_": false } +[node name="Control" type="Control" parent="."] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="DropArea" parent="Control" instance=ExtResource( 4 )] +show_behind_parent = false +position = Vector2( 0, 0 ) + [node name="VBoxContainer" type="VBoxContainer" parent="."] anchor_right = 1.0 anchor_bottom = 1.0 @@ -80,6 +93,3 @@ custom_fonts/font = ExtResource( 2 ) text = "filename" align = 1 autowrap = true - -[node name="DropArea" parent="." instance=ExtResource( 4 )] -position = Vector2( 88.6643, 48.5029 )