-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
PauseMenu.gd
382 lines (303 loc) · 13.7 KB
/
PauseMenu.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
extends Control
signal color_settings_changed
const PROFILE_PANEL = preload("res://gui/profile_panel.tscn")
@onready var BlueColorButton := $Background/ColorSelect/ColorButtons/BlueButton
@onready var YellowColorButton := $Background/ColorSelect/ColorButtons/YellowButton
@onready var GreenColorButton := $Background/ColorSelect/ColorButtons/GreenButton
@onready var PurpleColorButton := $Background/ColorSelect/ColorButtons/PurpleButton
@onready var BlueColorButtonIcon := $Background/ColorSelect/ColorButtons/BlueButton/Icon
@onready var YellowColorButtonIcon := $Background/ColorSelect/ColorButtons/YellowButton/Icon
@onready var GreenColorButtonIcon := $Background/ColorSelect/ColorButtons/GreenButton/Icon
@onready var PurpleColorButtonIcon := $Background/ColorSelect/ColorButtons/PurpleButton/Icon
@onready var BlueColorButtonBG := $Background/ColorSelect/ColorButtons/BlueButton/NodeBG
@onready var YellowColorButtonBG := $Background/ColorSelect/ColorButtons/YellowButton/NodeBG
@onready var GreenColorButtonBG := $Background/ColorSelect/ColorButtons/GreenButton/NodeBG
@onready var PurpleColorButtonBG := $Background/ColorSelect/ColorButtons/PurpleButton/NodeBG
@onready var ColorPickerNode := $Background/ColorSelectPicker/PickerContainer/ColorPicker
@onready var ColorButtons := $Background/ColorSelect/ColorButtons
@onready var PauseMenu := $Background/Paused
@onready var ProfilesMenu := $Background/Profiles
@onready var OptionsMenu := $Background/Options
@onready var CreditsMenu := $Background/Credits
@onready var ColorSelectMenu := $Background/ColorSelect
@onready var ColorSelectPicker := $Background/ColorSelectPicker
@onready var ProfileList := $Background/Profiles/ProfilesScroll/ProfileUI/ProfileList
var editing_color :int = -1
var handling_profile := -1
var previous_state := &"pause"
func _ready():
$Background/AudioSettings/Buttons/MasterVolume/Slider.value = SaveData.save_handler.vget_value(["options", "mastervol"], 1.0)
$Background/AudioSettings/Buttons/SFXVolume/Slider.value = SaveData.save_handler.vget_value(["options", "sfxvol"], 1.0)
$Background/AudioSettings/Buttons/MusicVolume/Slider.value = SaveData.save_handler.vget_value(["options", "musicvol"], 0.8)
var tween := create_tween()
tween.tween_property($"../Panel", "modulate:a", 0.0, 0.2)
tween.tween_property($"../Panel", "visible", false, 0.0)
BlueColorButton.pressed.connect(open_color_picker.bind(NodeRule.COLORS.blue))
YellowColorButton.pressed.connect(open_color_picker.bind(NodeRule.COLORS.yellow))
GreenColorButton.pressed.connect(open_color_picker.bind(NodeRule.COLORS.green))
PurpleColorButton.pressed.connect(open_color_picker.bind(NodeRule.COLORS.purple))
set_gui_state(&"pause")
if not DirAccess.dir_exists_absolute("user://profiles"):
DirAccess.make_dir_absolute("user://profiles")
var profiles := DirAccess.get_directories_at("user://profiles")
if not profiles.is_empty():
for path in profiles:
var last := path.rsplit("/", false, 1)[0] as int
add_profile_panel(last)
func _process(_delta: float) -> void:
if Input.is_action_just_pressed("pause") and $"../Panel".visible == false:
SaveData.save_handler.save_profile_data()
$Background/Paused/ProfilePanel.set_profile(SaveData.save_handler.profile)
get_tree().paused = !get_tree().paused
set_gui_state(&"pause")
if get_tree().paused:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
else:
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
visible = get_tree().paused
set_preview_color(BlueColorButtonIcon, BlueColorButtonBG, NodeRule.COLORS.blue)
set_preview_color(YellowColorButtonIcon, YellowColorButtonBG, NodeRule.COLORS.yellow)
set_preview_color(GreenColorButtonIcon, GreenColorButtonBG, NodeRule.COLORS.green)
set_preview_color(PurpleColorButtonIcon, PurpleColorButtonBG, NodeRule.COLORS.purple)
func set_preview_color(preview: Control, preview_bg: Control, color: NodeRule.COLORS):
var col := SaveData.get_node_color(color)
preview_bg.modulate = col
if col.get_luminance() > 0.5:
preview.modulate = col.darkened(0.6)
else:
preview.modulate = col.lightened(0.6)
func open_color_picker(color: NodeRule.COLORS):
editing_color = color
ColorPickerNode.color = SaveData.get_node_color(color)
set_gui_state(&"color_picker")
func _on_done_pressed():
SaveData.save_handler.vsave_value(["options", "accessibility", "colors", str(editing_color)], ColorPickerNode.color)
set_gui_state("color_setting")
SaveData.save()
color_settings_changed.emit()
func _on_reset_pressed():
SaveData.save_handler.vsave_value(["options", "accessibility", "colors", str(editing_color)], NodeRule.get_default_color(editing_color as NodeRule.COLORS))
ColorPickerNode.color = NodeRule.get_default_color(editing_color as NodeRule.COLORS)
SaveData.save()
color_settings_changed.emit()
func _on_quit_pressed():
get_tree().call_group("Puzzle", "save_data")
SaveData.save()
get_tree().quit()
func set_gui_state(state: StringName):
match state:
&"pause":
previous_state = state
PauseMenu.visible = true
ProfilesMenu.visible = false
OptionsMenu.visible = false
CreditsMenu.visible = false
ColorSelectMenu.visible = false
ColorSelectPicker.visible = false
$Background/ProfileRenaming.visible = false
$Background/ViewControls.visible = false
$Background/Paused/ProfilePanel.set_profile(SaveData.save_handler.profile)
$Background/AudioSettings.visible = false
&"options":
PauseMenu.visible = false
ProfilesMenu.visible = false
OptionsMenu.visible = true
CreditsMenu.visible = false
ColorSelectMenu.visible = false
ColorSelectPicker.visible = false
$Background/ViewControls.visible = false
$Background/AudioSettings.visible = false
$Background/Options/Buttons/HoldMode.button_pressed = SaveData.save_handler.vget_value(["accessibility", "hold"], true)
$Background/Options/Buttons/FullscreenButton.button_pressed = get_window().mode == Window.MODE_FULLSCREEN
&"profiles":
previous_state = state
PauseMenu.visible = false
ProfilesMenu.visible = true
OptionsMenu.visible = false
CreditsMenu.visible = false
ColorSelectMenu.visible = false
ColorSelectPicker.visible = false
$Background/ProfileRenaming.visible = false
$Background/ProfileDeleting.visible = false
$Background/ProfileSwitching.visible = false
$Background/ViewControls.visible = false
$Background/AudioSettings.visible = false
var index := 0
for i in ProfileList.get_children():
i.set_profile(index)
index += 1
&"credits":
PauseMenu.visible = false
ProfilesMenu.visible = false
OptionsMenu.visible = false
CreditsMenu.visible = true
ColorSelectMenu.visible = false
ColorSelectPicker.visible = false
$Background/ViewControls.visible = false
&"color_setting":
PauseMenu.visible = false
ProfilesMenu.visible = false
OptionsMenu.visible = false
CreditsMenu.visible = false
ColorSelectMenu.visible = true
ColorSelectPicker.visible = false
$Background/ViewControls.visible = false
&"color_picker":
PauseMenu.visible = false
ProfilesMenu.visible = false
OptionsMenu.visible = false
CreditsMenu.visible = false
ColorSelectMenu.visible = false
ColorSelectPicker.visible = true
$Background/ViewControls.visible = false
&"profile_renaming":
OptionsMenu.visible = false
CreditsMenu.visible = false
ColorSelectMenu.visible = false
ColorSelectPicker.visible = false
$Background/ProfileRenaming.visible = true
$Background/ViewControls.visible = false
&"profile_deleting":
PauseMenu.visible = false
ProfilesMenu.visible = true
OptionsMenu.visible = false
CreditsMenu.visible = false
ColorSelectMenu.visible = false
ColorSelectPicker.visible = false
$Background/ProfileDeleting.visible = true
$Background/ViewControls.visible = false
&"profile_switching":
PauseMenu.visible = false
ProfilesMenu.visible = true
OptionsMenu.visible = false
CreditsMenu.visible = false
ColorSelectMenu.visible = false
ColorSelectPicker.visible = false
$Background/ProfileSwitching.visible = true
$Background/ViewControls.visible = false
&"viewcontrols":
PauseMenu.visible = false
ProfilesMenu.visible = false
OptionsMenu.visible = false
CreditsMenu.visible = false
ColorSelectMenu.visible = false
ColorSelectPicker.visible = false
$Background/ProfileSwitching.visible = false
$Background/ViewControls.visible = true
&"audio_controls":
PauseMenu.visible = false
ProfilesMenu.visible = false
OptionsMenu.visible = false
CreditsMenu.visible = false
ColorSelectMenu.visible = false
ColorSelectPicker.visible = false
$Background/ProfileSwitching.visible = false
$Background/ViewControls.visible = false
$Background/AudioSettings.visible = true
func _on_fullscreen_button_pressed() -> void:
get_window().mode = Window.MODE_FULLSCREEN if get_window().mode != Window.MODE_FULLSCREEN else Window.MODE_WINDOWED
SaveData.save_handler.vsave_value(["options", "fullscreen"], get_window().mode == Window.MODE_FULLSCREEN)
func _on_profile_panel_rename_request(profile: int) -> void:
set_gui_state(&"profile_renaming")
handling_profile = profile
func _on_profile_panel_delete_request(profile: int) -> void:
set_gui_state(&"profile_deleting")
handling_profile = profile
func _on_save_name_pressed() -> void:
var handler := SaveHandler.new()
handler.profile = handling_profile
handler.load_profile_data()
handler.profile_data["name"] = $Background/ProfileRenaming/PanelContainer/VBoxContainer/NameInput.text
handler.save_profile_data()
handler.free()
set_gui_state(previous_state)
func _on_discard_name_pressed() -> void:
set_gui_state(previous_state)
func _on_create_new_profile_pressed() -> void:
var new_profile_handler := SaveHandler.new()
new_profile_handler.profile = ProfileList.get_child_count()
new_profile_handler.save_profile_data()
add_profile_panel(ProfileList.get_child_count())
func add_profile_panel(p) -> void:
var new_panel := PROFILE_PANEL.instantiate()
new_panel.set_profile(p)
new_panel.rename_request.connect(_on_profile_panel_rename_request)
new_panel.delete_request.connect(_on_profile_panel_delete_request)
new_panel.switch_to_request.connect(_on_profile_panel_switch_to_request)
if p == SaveData.save_handler.profile:
new_panel.deletable = false
new_panel.switchable = false
ProfileList.add_child(new_panel)
func _on_delete_profile_pressed() -> void:
for index in ProfileList.get_child_count():
if index == SaveData.save_handler.profile and index >= handling_profile:
SaveData.save_handler.profile -= 1
var file := FileAccess.open("user://.currentprofile", FileAccess.WRITE)
file.store_string(str(SaveData.save_handler.profile))
file.close()
if index > handling_profile:
var true_index = index - 1
DirAccess.rename_absolute("user://profiles/%d" % index, "user://profiles/%d" % true_index)
elif index == handling_profile:
DirAccess.rename_absolute("user://profiles/%d" % index, "user://profiles/-1")
ProfileList.get_child(handling_profile).free()
var handler := SaveHandler.new()
handler.profile = -1
handler.delete_profile()
handler.free()
set_gui_state(&"profiles")
func _on_cancel_deletion_pressed() -> void:
set_gui_state(&"profiles")
func _on_profile_panel_switch_to_request(profile: int) -> void:
$"../Panel".visible = true
get_tree().call_group("Puzzle", "save_data")
SaveData.save()
var tween = create_tween()
tween.tween_property($"../Panel", "modulate:a", 1.0, 1.0)
tween.finished.connect(do_the_switch.bind(profile))
func do_the_switch(profile: int) -> void:
var file := FileAccess.open("user://.currentprofile", FileAccess.WRITE)
file.store_string(str(profile))
file.close()
get_tree().reload_current_scene()
SaveData.reset_all_globals()
SaveData.save_handler.profile = profile
SaveData._ready()
print("d1")
func _on_cancel_switch_pressed() -> void:
set_gui_state(&"profiles")
func _on_switch_close_pressed() -> void:
var file := FileAccess.open("user://.currentprofile", FileAccess.WRITE)
file.store_string(str(handling_profile))
file.close()
get_tree().call_group("Puzzle", "save_data")
SaveData.save()
get_tree().quit()
func _on_hold_mode_pressed() -> void:
var get_hold_mode :bool = SaveData.save_handler.vget_value(["accessibility", "hold"], true)
SaveData.save_handler.vsave_value(["accessibility", "hold"], !get_hold_mode)
func _on_resume_button_pressed() -> void:
get_tree().paused = false
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
func _on_color_presets_index_pressed(index: int) -> void:
var new_preset := "default"
match index:
1: new_preset = "protanopia"
2: new_preset = "deuteranopia"
3: new_preset = "tritanopia"
_: new_preset = "default"
SaveData.save_handler.vsave_value(["options", "accessibility", "preset"], new_preset)
SaveData.save_handler.vsave_value(["options", "accessibility", "colors", str(NodeRule.COLORS.blue)], NodeRule.get_default_color(NodeRule.COLORS.blue))
SaveData.save_handler.vsave_value(["options", "accessibility", "colors", str(NodeRule.COLORS.yellow)], NodeRule.get_default_color(NodeRule.COLORS.yellow))
SaveData.save_handler.vsave_value(["options", "accessibility", "colors", str(NodeRule.COLORS.green)], NodeRule.get_default_color(NodeRule.COLORS.green))
SaveData.save_handler.vsave_value(["options", "accessibility", "colors", str(NodeRule.COLORS.purple)], NodeRule.get_default_color(NodeRule.COLORS.purple))
color_settings_changed.emit()
func _on_master_volume_value_changed(value: float) -> void:
SaveData.save_handler.vsave_value(["options", "mastervol"], value)
AudioServer.set_bus_volume_db(0, linear_to_db(value))
func _on_sfx_volume_value_changed(value: float) -> void:
SaveData.save_handler.vsave_value(["options", "sfxvol"], value)
AudioServer.set_bus_volume_db(1, linear_to_db(value))
func _on_music_volume_value_changed(value: float) -> void:
SaveData.save_handler.vsave_value(["options", "musicvol"], value)
AudioServer.set_bus_volume_db(2, linear_to_db(value))