about summary refs log tree commit diff stats
path: root/client/Archipelago/minimap.gd
diff options
context:
space:
mode:
Diffstat (limited to 'client/Archipelago/minimap.gd')
-rw-r--r--client/Archipelago/minimap.gd93
1 files changed, 93 insertions, 0 deletions
diff --git a/client/Archipelago/minimap.gd b/client/Archipelago/minimap.gd new file mode 100644 index 0000000..2702bb1 --- /dev/null +++ b/client/Archipelago/minimap.gd
@@ -0,0 +1,93 @@
1extends CanvasLayer
2
3var player
4var camera
5var label
6var map_bounds = null
7
8
9func _ready():
10 player = get_tree().get_root().get_node("scene/player")
11
12 var svc = SubViewportContainer.new()
13 svc.anchor_left = 1.0
14 svc.anchor_top = 1.0
15 svc.anchor_right = 1.0
16 svc.anchor_bottom = 1.0
17 svc.offset_left = -320.0
18 svc.offset_top = -320.0
19 svc.offset_right = -64.0
20 svc.offset_bottom = -64.0
21 add_child(svc)
22
23 var sv = SubViewport.new()
24 sv.size = Vector2i(256, 256)
25 svc.add_child(sv)
26
27 camera = Camera3D.new()
28 camera.position.y = 5
29 camera.rotation_degrees.x = -90
30 camera.projection = Camera3D.PROJECTION_ORTHOGONAL
31 camera.size = 128.0
32 camera.far = 10
33 sv.add_child(camera)
34
35 label = Label.new()
36 label.theme = preload("res://assets/themes/baseUI.tres")
37 label.add_theme_font_size_override("font_size", 32)
38 label.text = "@"
39 add_child(label)
40
41 var gridmap = get_tree().get_root().get_node("scene/GridMap")
42 if gridmap != null:
43 var cell_left = 0
44 var cell_top = 0
45 var cell_right = 0
46 var cell_bottom = 0
47
48 for pos in gridmap.get_used_cells():
49 if pos.x < cell_left:
50 cell_left = pos.x
51 if pos.x > cell_right:
52 cell_right = pos.x
53 if pos.z < cell_top:
54 cell_top = pos.z
55 if pos.z > cell_bottom:
56 cell_bottom = pos.z
57
58 var local_tl = gridmap.map_to_local(Vector3i(cell_left, 0, cell_top))
59 var local_br = gridmap.map_to_local(Vector3i(cell_right, 0, cell_bottom))
60 var global_tl = gridmap.to_global(local_tl)
61 var global_br = gridmap.to_global(local_br)
62 map_bounds = [
63 min(global_tl.x, global_br.x) + 64,
64 max(global_tl.x, global_br.x) - 64,
65 min(global_tl.z, global_br.z) + 64,
66 max(global_tl.z, global_br.z) - 64
67 ]
68
69 if map_bounds[1] < map_bounds[0]:
70 map_bounds[0] = (map_bounds[0] + map_bounds[1]) / 2
71 map_bounds[1] = map_bounds[0]
72
73 if map_bounds[3] < map_bounds[2]:
74 map_bounds[2] = (map_bounds[2] + map_bounds[3]) / 2
75 map_bounds[3] = map_bounds[2]
76
77 if map_bounds == null:
78 label.position.x = 1712.0
79 label.position.y = 872.0
80 #label.offset_right = 1743.0
81 #label.offset_bottom = 907.0
82
83
84func _process(_delta):
85 if map_bounds == null:
86 camera.position.x = player.position.x
87 camera.position.z = player.position.z
88 else:
89 camera.position.x = clamp(player.position.x, map_bounds[0], map_bounds[1])
90 camera.position.z = clamp(player.position.z, map_bounds[2], map_bounds[3])
91
92 label.position.x = 1600 + (player.position.x - camera.position.x) * 2 + 128 - 16
93 label.position.y = 760 + (player.position.z - camera.position.z) * 2 + 128 - 16