2020-10-13 13:04:12 +02:00
|
|
|
extends Node2D
|
|
|
|
|
2020-10-13 14:16:36 +02:00
|
|
|
var hovered = false
|
2020-10-13 13:04:12 +02:00
|
|
|
var dragged = false
|
|
|
|
var drag_offset
|
2020-10-13 17:08:37 +02:00
|
|
|
export var arg_number = 0
|
|
|
|
export var command = "" setget set_command
|
|
|
|
var _first_argument = null
|
|
|
|
var _home_position = null
|
|
|
|
|
2020-10-13 13:04:12 +02:00
|
|
|
|
|
|
|
func _ready():
|
|
|
|
set_process_unhandled_input(true)
|
2020-10-13 17:08:37 +02:00
|
|
|
_home_position = position
|
2020-10-13 13:04:12 +02:00
|
|
|
|
|
|
|
func _process(delta):
|
|
|
|
if dragged:
|
|
|
|
var mousepos = get_viewport().get_mouse_position()
|
|
|
|
position = mousepos - drag_offset
|
|
|
|
|
|
|
|
func _unhandled_input(event):
|
|
|
|
if event is InputEventMouseButton:
|
2020-10-13 14:16:36 +02:00
|
|
|
if event.button_index == BUTTON_LEFT and event.pressed and hovered:
|
2020-10-13 13:04:12 +02:00
|
|
|
dragged = true
|
2020-10-13 14:16:36 +02:00
|
|
|
game.dragged_object = self
|
2020-10-13 13:04:12 +02:00
|
|
|
drag_offset = get_viewport().get_mouse_position() - global_position
|
2020-10-13 14:16:36 +02:00
|
|
|
get_tree().set_input_as_handled()
|
|
|
|
modulate.a = 0.5
|
2020-10-13 17:08:37 +02:00
|
|
|
elif event.button_index == BUTTON_LEFT and !event.pressed and dragged:
|
2020-10-13 13:04:12 +02:00
|
|
|
dragged = false
|
2020-10-13 14:16:36 +02:00
|
|
|
game.dragged_object = null
|
|
|
|
modulate.a = 1
|
2020-10-13 17:29:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
if get_viewport().get_mouse_position().y < get_viewport().size.y/2:
|
|
|
|
if arg_number == 0 :
|
|
|
|
$"../Terminal".send_command($Label.text)
|
|
|
|
buuurn()
|
|
|
|
else:
|
|
|
|
move_back()
|
|
|
|
else:
|
|
|
|
_home_position = get_viewport().get_mouse_position() + drag_offset
|
2020-10-13 14:16:36 +02:00
|
|
|
|
|
|
|
func _mouse_entered():
|
|
|
|
hovered = true
|
|
|
|
|
|
|
|
func _mouse_exited():
|
|
|
|
hovered = false
|
2020-10-13 17:08:37 +02:00
|
|
|
|
|
|
|
func set_command(new_command):
|
|
|
|
command = new_command
|
|
|
|
$Label.text = self.command
|
|
|
|
|
|
|
|
func move_back():
|
|
|
|
position = _home_position
|
2020-10-13 17:29:24 +02:00
|
|
|
|
|
|
|
func buuurn():
|
|
|
|
queue_free()
|
|
|
|
$"..".draw_rand_card()
|
2020-10-13 14:16:36 +02:00
|
|
|
|
|
|
|
func dropped_on(other):
|
|
|
|
#print("I have been dropped on "+str(other.id))
|
2020-10-13 17:08:37 +02:00
|
|
|
var full_command = ""
|
|
|
|
match arg_number:
|
|
|
|
1:
|
|
|
|
full_command = $Label.text + " " + other.id
|
|
|
|
$"../Terminal".send_command(full_command)
|
2020-10-13 17:29:24 +02:00
|
|
|
buuurn()
|
2020-10-13 17:08:37 +02:00
|
|
|
2:
|
|
|
|
if _first_argument:
|
|
|
|
full_command = $Label.text + " " + _first_argument + " " + other.id
|
|
|
|
$"../Terminal".send_command(full_command)
|
2020-10-13 17:29:24 +02:00
|
|
|
buuurn()
|
2020-10-13 17:08:37 +02:00
|
|
|
else:
|
|
|
|
_first_argument = other.id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|