2020-10-13 14:16:36 +02:00
|
|
|
extends Node2D
|
|
|
|
|
|
|
|
var hovered = false
|
2020-11-03 12:39:40 +01:00
|
|
|
var highlighted = false setget _set_highlighted
|
2020-10-13 14:16:36 +02:00
|
|
|
|
|
|
|
func _ready():
|
2020-11-03 14:39:54 +01:00
|
|
|
_set_highlighted(false)
|
2020-10-13 14:16:36 +02:00
|
|
|
|
2020-11-07 13:59:47 +01:00
|
|
|
func _mouse_entered(_area):
|
2020-10-13 14:16:36 +02:00
|
|
|
hovered = true
|
|
|
|
|
2020-11-07 13:59:47 +01:00
|
|
|
func _mouse_exited(_area):
|
2020-10-13 14:16:36 +02:00
|
|
|
hovered = false
|
|
|
|
|
|
|
|
func _input(event):
|
|
|
|
if event is InputEventMouseButton:
|
|
|
|
if event.button_index == BUTTON_LEFT and !event.pressed and hovered:
|
2020-11-03 13:08:07 +01:00
|
|
|
if highlighted and game.dragged_object:
|
2020-11-10 12:14:45 +01:00
|
|
|
game.dragged_object.dropped_on(get_parent_with_type())
|
2020-11-03 12:39:40 +01:00
|
|
|
|
|
|
|
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
|
2020-11-03 12:39:40 +01:00
|
|
|
|
|
|
|
func highlight(type):
|
2020-11-10 12:14:45 +01:00
|
|
|
if get_parent_with_type().type == type:
|
2020-11-03 12:39:40 +01:00
|
|
|
_set_highlighted(true)
|