oh-my-git/scenes/drop_area.gd

42 lines
1.2 KiB
GDScript3
Raw Permalink Normal View History

extends Node2D
var hovered = false
2023-09-06 16:04:23 +02:00
var highlighted = false: set = _set_highlighted
func _ready():
_set_highlighted(false)
func _mouse_entered(_area):
hovered = true
2023-09-06 16:04:23 +02:00
var tween = get_tree().create_tween()
tween.tween_property($Highlight/Sprite2D.material, "shader_param/hovered",1,0.1)
#tween.interpolate_property($Highlight/Sprite2D.material, "shader_param/hovered", 0, 1, 0.1, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
#add_child(tween)
#tween.start()
func _mouse_exited(_area):
hovered = false
2023-09-06 16:04:23 +02:00
var tween = get_tree().create_tween()
tween.tween_property($Highlight/Sprite2D.material, "shader_param/hovered", 0, 0.1)
func _input(event):
if event is InputEventMouseButton:
2023-09-06 16:04:23 +02:00
if event.button_index == MOUSE_BUTTON_LEFT and !event.pressed and hovered:
if highlighted and game.dragged_object:
2020-11-10 12:14:45 +01:00
game.dragged_object.dropped_on(get_parent_with_type())
func _set_highlighted(new_highlighted):
highlighted = new_highlighted
$Highlight.visible = highlighted
2020-11-10 12:14:45 +01:00
func get_parent_with_type():
var parent = get_parent()
while(!parent.get("type")):
parent = parent.get_parent()
return parent
func highlight(type):
2020-11-10 12:14:45 +01:00
if get_parent_with_type().type == type:
_set_highlighted(true)