summaryrefslogtreecommitdiff
path: root/UI/LevelSelect.gd
blob: 368d338296c2531065e50e689e9b209043efc651 (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
extends Control


func _ready():
	Global.connect("level_map_updated", Callable(self, "draw"))
	draw()


func draw():
	var Cell = load("res://UI/LevelSelectCell.tscn")
	
	for idx in range(Global.Level_Map.size()): # size = 9
		var cell = Cell.instantiate()
		cell.level_idx = idx
		cell.set_rect_size(
			get_viewport_rect().size.x/3,
			get_viewport_rect().size.y/3
		)
		var column = idx % 3
		var row = idx / 3
		cell.position.x = cell.size.x*column
		cell.position.y = cell.size.y*row
		cell.connect("gui_input", Callable(self, '_button_pressed').bind(idx))
		self.add_child(cell)


func _button_pressed(event, idx):
	if event is InputEventMouseButton or event is InputEventKey:
		if event.pressed:
			Global.start_level(idx)