44 lines
1 KiB
GDScript
44 lines
1 KiB
GDScript
extends Control
|
|
|
|
|
|
var dragging: bool = false
|
|
var dragging_start_position: Vector2i = Vector2i()
|
|
|
|
@onready var dragon: Dragon = $".."
|
|
|
|
|
|
func _ready() -> void:
|
|
set_process_input(true)
|
|
|
|
|
|
func _input(event) -> void:
|
|
if event is not InputEventMouseButton:
|
|
return
|
|
if event.button_index != MOUSE_BUTTON_LEFT:
|
|
return
|
|
|
|
if event.pressed:
|
|
dragging = true
|
|
dragging_start_position = Vector2i(get_global_mouse_position())
|
|
else:
|
|
dragging = false
|
|
if _is_inside_main_window():
|
|
_destroy_dragon()
|
|
|
|
|
|
func _process(_delta) -> void:
|
|
if dragging:
|
|
dragon.position = dragon.position + Vector2i(get_global_mouse_position()) - dragging_start_position
|
|
|
|
|
|
func _is_inside_main_window() -> bool:
|
|
var id: int = get_window().get_window_id()
|
|
var window_position: Vector2i = DisplayServer.window_get_position(id)
|
|
var window_size: Vector2i = DisplayServer.window_get_size(id)
|
|
var rect: Rect2i = Rect2i(window_position, window_size)
|
|
|
|
return rect.intersects(dragon.main_window_rect)
|
|
|
|
|
|
func _destroy_dragon() -> void:
|
|
dragon.queue_free()
|