blob: 5e7d1c1f4c32654a4b28eeab1cf56e5e6c1ccf8a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
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: Camera2D = get_tree().get_first_node_in_group("camera")
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"):
for area in get_overlapping_areas():
if "is_selected" in area.get_parent():
if area.get_parent().owner_id == multiplayer.get_unique_id():
area.get_parent().is_selected = true
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
|