extends Node2D
@export var max_x = 100
@export var max_y = 100
var selected = false
func _on_area_2d_input_event(viewport, event, shape_idx):
	if event.is_action_pressed("select") && Global.drag_mode:
		selected = true
func _process(delta):
	queue_redraw()
	if Global.search_mode && !%FocusMind.visible:
		%FocusMind.visible = true
	elif !Global.search_mode && %FocusMind.visible:
		%FocusMind.visible = false
	
	if Input.is_action_just_released("select"):
		selected = false
	if selected:
		if get_global_mouse_position().x < (global_position.x + max_x) and get_global_mouse_position().x > (global_position.x - max_x):
			$main.global_position.x = get_global_mouse_position().x
		if get_global_mouse_position().y < (global_position.y + max_y) and get_global_mouse_position().y > (global_position.y - max_y):
			$main.global_position.y = get_global_mouse_position().y
		#position = get_global_mouse_position()
func _draw():
	if selected:
		draw_rect(Rect2(-max_x, -max_y, max_x*2, max_y*2), Color(Color.BLACK, 0.1))
		draw_rect(Rect2(-5, -5, 10, 10), Color(Color.WHITE, 1))
		draw_line(Vector2.ZERO, $main.position, Color(Color.WHITE, 0.3), 3.0)