summaryrefslogtreecommitdiff
path: root/Scenes/UI/Menu.gd
blob: ce45a2663e86a356d09fc55b9b90a428d51b14bd (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
extends TabContainer


@onready var audio_bus = AudioServer.get_bus_index("Master")


func _ready():
	hide()
	
	self._ready_bombs()
	self._ready_system()


func _input(event: InputEvent):
	if event.is_action_pressed("ui_menu"):
		print(Global.player.position)
		print("pressed")
		if get_tree().paused: # game is paused
			self.close_menu()
			print("was paused")
		else: # game is running
			self.open_menu()
			print("was running")
	
	if event.is_action_pressed("ui_menu_left"):
		if get_current_tab() > 0:
			set_current_tab(get_current_tab() - 1)
	if event.is_action_pressed("ui_menu_right"):
		if get_current_tab() < get_tab_count() - 1:
			set_current_tab(get_current_tab() + 1)
	
	connect("tab_changed", func(tab_id):
		if tab_id == 0:
			(func(): $Bombs/Panel/HBoxContainer/VBoxContainer/ButtonBombNormal.grab_focus()).call_deferred()
		elif tab_id == 1:
			(func(): $System/Panel/VBoxContainer/ButtonResume.grab_focus()).call_deferred()
	)


func open_menu():
	get_tree().paused = true
	show()
	
	(func(): $Bombs/Panel/HBoxContainer/VBoxContainer/ButtonBombNormal.grab_focus()).call_deferred()


func close_menu():
	hide()
	get_tree().paused = false


func get_player():
	return Global.player
	#return get_tree().get_current_scene().get_node("Player")


### Bombs ###


func _ready_bombs():
	for component in Bomb.COMPONENT_TYPE:
		var idx = Bomb.COMPONENT_TYPE[component]
		$Bombs/Panel/HBoxContainer/VBoxContainer3/BombComponents.set_item_text(idx, component.capitalize())


func _on_button_bomb_normal_pressed():
	self.get_player().BombScene = preload("res://Scenes/Entities/Bombs/Bomb__Normal.tscn")


func _on_button_bomb_breakables_pressed():
	self.get_player().BombScene = preload("res://Scenes/Entities/Bombs/Bomb__Breakables.tscn")


func _on_bomb_power_item_selected(index):
	var power = int($Bombs/Panel/HBoxContainer/VBoxContainer2/BombPower.get_item_text(index))
	self.get_player().bomb_power = power


func _on_bomb_components_multi_selected(_index, _selected):
	Global.player.bomb_components = []
	for idx in $Bombs/Panel/HBoxContainer/VBoxContainer3/BombComponents.get_selected_items():
		Global.player.bomb_components.append(idx) # same as enum idx


### System ###


func _ready_system():
	AudioServer.set_bus_volume_db(self.audio_bus, linear_to_db(0))
	$System/Panel/VBoxContainer2/SliderVolume.value = db_to_linear(AudioServer.get_bus_volume_db(self.audio_bus))


func _on_slider_volume_value_changed(value):
	AudioServer.set_bus_volume_db(self.audio_bus, linear_to_db(value))


func quit_game():
	get_tree().quit()


func _on_button_resume_pressed():
	self.close_menu()


func _on_button_quit_pressed():
	self.quit_game()