extends Area2D @export_group("Color", "color") @export var color_background: Color @export var color_border: Color var anchor: Vector2 = Vector2.ZERO var size: Vector2 = Vector2.ZERO : set(value): size = value $CollisionShape2D.position = size / 2 $CollisionShape2D.shape.size = abs(size) var is_active: bool : get(): return abs(size) > Vector2(1, 1) and Client.state is StateDefault @onready var camera: Camera = get_viewport().get_camera_2d() func _process(_delta: float) -> void: if Input.is_action_just_pressed("select"): anchor = get_global_mouse_position() global_position = anchor if Input.is_action_pressed("select"): size = get_global_mouse_position() - anchor if is_active: queue_redraw() if is_active and Input.is_action_just_released("select"): var areas = get_overlapping_areas() for area in areas: if "is_selected" in area.get_parent(): if area.get_parent().owner_id == multiplayer.get_unique_id(): area.get_parent().is_selected = true if not areas.is_empty(): Client.multi_select_finished.emit(areas) size = Vector2.ZERO queue_redraw() func _draw(): if is_active: var rect = Rect2(Vector2.ZERO, size) draw_rect(rect, color_background) draw_rect(rect, color_border, false, 1.25 / max(camera.zoom.x, camera.zoom.y)) func _on_area_entered(area: Area2D) -> void: if area.get_parent().owner_id == multiplayer.get_unique_id(): area.get_parent().is_hovered = true func _on_area_exited(area: Area2D) -> void: if area.get_parent().owner_id == multiplayer.get_unique_id(): area.get_parent().is_hovered = false