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-11-24 15:26:16 +01:00
|
|
|
var dragged = false
|
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-24 15:26:16 +01:00
|
|
|
func _process(delta):
|
|
|
|
if dragged:
|
|
|
|
if get_parent().type == "file":
|
|
|
|
var diff = get_viewport().get_mouse_position() - get_parent().global_position
|
|
|
|
get_parent().move(diff)
|
|
|
|
|
2020-11-07 13:59:47 +01:00
|
|
|
func _mouse_entered(_area):
|
2020-10-13 14:16:36 +02:00
|
|
|
hovered = true
|
2020-11-10 12:42:47 +01:00
|
|
|
var tween = Tween.new()
|
|
|
|
tween.interpolate_property($Highlight/Sprite.material, "shader_param/hovered", 0, 1, 0.1, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
|
|
|
|
add_child(tween)
|
|
|
|
tween.start()
|
2020-10-13 14:16:36 +02:00
|
|
|
|
2020-11-07 13:59:47 +01:00
|
|
|
func _mouse_exited(_area):
|
2020-10-13 14:16:36 +02:00
|
|
|
hovered = false
|
2020-11-10 12:42:47 +01:00
|
|
|
var tween = Tween.new()
|
|
|
|
tween.interpolate_property($Highlight/Sprite.material, "shader_param/hovered", 1, 0, 0.1, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
|
|
|
|
add_child(tween)
|
|
|
|
tween.start()
|
2020-10-13 14:16:36 +02:00
|
|
|
|
|
|
|
func _input(event):
|
|
|
|
if event is InputEventMouseButton:
|
2020-11-24 15:26:16 +01:00
|
|
|
if event.button_index == BUTTON_LEFT and !event.pressed:
|
2020-11-24 17:34:46 +01:00
|
|
|
if dragged:
|
|
|
|
for area in get_tree().get_nodes_in_group("drop_areas"):
|
|
|
|
if area.hovered:
|
2020-11-25 13:53:07 +01:00
|
|
|
if area.highlighted:
|
|
|
|
get_parent_with_type().dropped_on(area.get_parent_with_type())
|
2020-11-24 17:34:46 +01:00
|
|
|
_turn_off_highlights()
|
|
|
|
dragged = false
|
2020-11-25 14:39:52 +01:00
|
|
|
game.dragged_object = null
|
|
|
|
elif game.dragged_object and game.dragged_object.has_method("try_play"):
|
2020-11-25 13:53:07 +01:00
|
|
|
if hovered and highlighted:
|
|
|
|
game.dragged_object.dropped_on(get_parent_with_type())
|
2020-11-24 17:34:46 +01:00
|
|
|
|
2020-11-24 15:26:16 +01:00
|
|
|
if event.button_index == BUTTON_LEFT and event.pressed and hovered:
|
2020-11-25 14:39:52 +01:00
|
|
|
if not game.dragged_object:
|
|
|
|
if get_parent().type == "file" and get_parent().item_type == "wd":
|
|
|
|
dragged = true
|
|
|
|
game.dragged_object = self
|
|
|
|
_turn_on_highlights()
|
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)
|
2020-11-24 17:34:46 +01:00
|
|
|
|
|
|
|
func _turn_on_highlights():
|
|
|
|
var parent_type = get_parent_with_type().file_browser.type
|
|
|
|
var highlight_type = "inventory"
|
|
|
|
if parent_type == "inventory":
|
|
|
|
highlight_type = "world"
|
|
|
|
|
|
|
|
for area in get_tree().get_nodes_in_group("drop_areas"):
|
|
|
|
area.highlight(highlight_type)
|
|
|
|
|
|
|
|
func _turn_off_highlights():
|
|
|
|
for area in get_tree().get_nodes_in_group("drop_areas"):
|
|
|
|
area.highlighted = false
|