-
Notifications
You must be signed in to change notification settings - Fork 2
/
Settings.gd
77 lines (52 loc) · 2.09 KB
/
Settings.gd
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
extends ColorRect
signal closed()
onready var master_bus = AudioServer.get_bus_index('Master')
onready var music_bus = AudioServer.get_bus_index('Music')
onready var sfx_bus = AudioServer.get_bus_index('SFX')
var action_after_confirm := ''
func _ready():
$master_slider.value = db2linear(AudioServer.get_bus_volume_db(master_bus))
$music_slider.value = db2linear(AudioServer.get_bus_volume_db(music_bus))
$sfx_slider.value = db2linear(AudioServer.get_bus_volume_db(sfx_bus))
$fullscreen_checkbox.pressed = OS.window_fullscreen
$master_slider.grab_focus()
func _input(_event):
if visible and Input.is_action_just_pressed("ui_cancel"):
close_screen()
func _on_master_slider_value_changed(value):
AudioServer.set_bus_volume_db(master_bus, linear2db(value))
Global.save_settings()
func _on_music_slider_value_changed(value):
AudioServer.set_bus_volume_db(music_bus, linear2db(value))
Global.save_settings()
func _on_sfx_slider_value_changed(value):
AudioServer.set_bus_volume_db(sfx_bus, linear2db(value))
Global.save_settings()
func close_screen():
get_tree().paused = false
emit_signal("closed")
get_tree().set_input_as_handled()
func _on_back_btn_pressed():
$ui_sound.play()
close_screen()
func _on_exit_btn_pressed():
action_after_confirm = 'exit'
$confirm_dialog.dialog_text = 'Are you sure you want to exit? You will permanently lose your current progress.'
$confirm_dialog.popup_centered()
func _on_fullscreen_checkbox_toggled(button_pressed):
OS.window_fullscreen = button_pressed
Global.save_settings()
func _on_new_game_btn_pressed():
action_after_confirm = 'reset'
$confirm_dialog.dialog_text = 'Are you sure you want to reset? You will permanently lose your current progress.'
$confirm_dialog.popup_centered()
func _on_confirm_dialog_confirmed():
if action_after_confirm == 'reset':
get_tree().paused = false
Global.remove_save()
if get_tree().reload_current_scene() != OK:
print('Cannot reload current scene. Run for your lives!')
elif action_after_confirm == 'exit':
var world = get_tree().get_nodes_in_group('world')[0]
Global.save_game(world)
get_tree().quit()