-
Notifications
You must be signed in to change notification settings - Fork 1
/
OptionsManager.gd
278 lines (253 loc) · 9.98 KB
/
OptionsManager.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
class_name OptionsManager extends Node
@export var controller : ControllerManager
@export var defaultOption_language : String = "EN"
@export var defaultOption_windowed : bool
@export var defaultOption_controllerActive : bool
var defaultOption_inputmap_keyboard = {
"ui_accept": InputMap.action_get_events("ui_accept")[0],
"ui_cancel": InputMap.action_get_events("ui_cancel")[0],
"ui_left": InputMap.action_get_events("ui_left")[0],
"ui_right": InputMap.action_get_events("ui_right")[0],
"ui_up": InputMap.action_get_events("ui_up")[0],
"ui_down": InputMap.action_get_events("ui_down")[0],
"reset": InputMap.action_get_events("reset")[0],
"exit game": InputMap.action_get_events("exit game")[0],
"free look toggle": InputMap.action_get_events("free look toggle")[0],
}
var defaultOption_inputmap_controller = {
"ui_accept": InputMap.action_get_events("ui_accept")[1],
"ui_cancel": InputMap.action_get_events("ui_cancel")[1],
"ui_left": InputMap.action_get_events("ui_left")[1],
"ui_right": InputMap.action_get_events("ui_right")[1],
"ui_up": InputMap.action_get_events("ui_up")[1],
"ui_down": InputMap.action_get_events("ui_down")[1],
"reset": InputMap.action_get_events("reset")[1],
"exit game": InputMap.action_get_events("exit game")[1],
"free look toggle": InputMap.action_get_events("free look toggle")[1],
}
@export var ui_windowed : CanvasItem
@export var ui_fullscreen : CanvasItem
@export var ui_deviceController : CanvasItem
@export var ui_deviceMouse : CanvasItem
@export var button_windowed : ButtonClass
@export var button_fullscreen : ButtonClass
@export var menu : MenuManager
@export var ui_volume : Label
@export var checkmark_colorblind : Checkmark
@export var checkmark_greyscale : Checkmark
const savePath := "user://buckshotroulette_options_12.shell"
var data = {}
var data_inputmap = {}
var setting_inputmap_keyboard = {}
var setting_inputmap_controller = {}
var setting_volume = 1
var setting_windowed = false
var setting_language = "EN"
var setting_controllerEnabled = false
var setting_colorblind = false
var setting_greyscale_death = true
var setting_music_enabled = true
func _ready():
LoadSettings()
if (!receivedFile):
setting_windowed = defaultOption_windowed
setting_controllerEnabled = defaultOption_controllerActive
setting_language = defaultOption_language
setting_inputmap_keyboard = defaultOption_inputmap_keyboard
setting_inputmap_controller = defaultOption_inputmap_controller
ApplySettings_window()
ApplySettings_controller()
ApplySettings_language()
ApplySettings_inputmap()
ApplySettings_greyscaledeath()
func Printout():
print("user current version: ", GlobalVariables.currentVersion)
print("user current hotfix: ", GlobalVariables.currentVersion_hotfix)
func Adjust(alias : String):
match(alias):
"increase":
if setting_volume != 1:
setting_volume = setting_volume + 0.05
if setting_volume > 1:
setting_volume = 1
UpdateDisplay()
ApplySettings_volume()
"decrease":
if setting_volume != 0:
setting_volume = setting_volume - 0.05
if setting_volume < 0:
setting_volume = 0
UpdateDisplay()
ApplySettings_volume()
"controller enable":
setting_controllerEnabled = true
ApplySettings_controller()
"controller disable":
setting_controllerEnabled = false
ApplySettings_controller()
"windowed":
setting_windowed = true
ApplySettings_window()
"fullscreen":
setting_windowed = false
ApplySettings_window()
if (alias != "increase" && alias != "decrease"): menu.ResetButtons()
func ToggleColorblind():
setting_colorblind = !setting_colorblind
checkmark_colorblind.UpdateCheckmark(setting_colorblind)
ApplySettings_colorblind()
func ToggleGreyscaleDeath():
setting_greyscale_death = !setting_greyscale_death
checkmark_greyscale.UpdateCheckmark(setting_greyscale_death)
ApplySettings_greyscaledeath()
func AdjustLanguage(alias : String):
setting_language = alias
ApplySettings_language()
menu.ResetButtons()
func ApplySettings_volume():
AudioServer.set_bus_volume_db(0, linear_to_db(setting_volume))
UpdateDisplay()
pass
func AdjustSettings_music():
setting_music_enabled = !setting_music_enabled
ApplySettings_music()
@export var anim_vinyl : AnimationPlayer
func ApplySettings_music():
if (setting_music_enabled): anim_vinyl.speed_scale = 1
else: anim_vinyl.speed_scale = 0
AudioServer.set_bus_mute(1, !setting_music_enabled) #music
AudioServer.set_bus_mute(2, !setting_music_enabled) #music secondary
AudioServer.set_bus_mute(4, !setting_music_enabled) #music resolve
AudioServer.get_property_list()
GlobalVariables.music_enabled = setting_music_enabled
func UpdateDisplay():
ui_volume.text = str(snapped(setting_volume * 100, .01)) + "%"
func ApplySettings_window():
if (!setting_windowed):
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_EXCLUSIVE_FULLSCREEN)
ui_fullscreen.modulate.a = 1
ui_windowed.modulate.a = .5
button_fullscreen.mainActive = true
button_windowed.mainActive = true
else:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
ui_fullscreen.modulate.a = .5
ui_windowed.modulate.a = 1
button_fullscreen.mainActive = true
button_windowed.mainActive = true
pass
func ApplySettings_controller():
if (setting_controllerEnabled):
controller.SetMainControllerState(true)
ui_deviceController.modulate.a = 1
ui_deviceMouse.modulate.a = .5
GlobalVariables.controllerEnabled = true
else:
controller.SetMainControllerState(false)
ui_deviceController.modulate.a = .5
ui_deviceMouse.modulate.a = 1
GlobalVariables.controllerEnabled = false
func ParseInputMapDictionary():
setting_inputmap_keyboard = {
"ui_accept": var_to_str(InputMap.action_get_events("ui_accept")[0]),
"ui_cancel": var_to_str(InputMap.action_get_events("ui_cancel")[0]),
"ui_left": var_to_str(InputMap.action_get_events("ui_left")[0]),
"ui_right": var_to_str(InputMap.action_get_events("ui_right")[0]),
"ui_up": var_to_str(InputMap.action_get_events("ui_up")[0]),
"ui_down": var_to_str(InputMap.action_get_events("ui_down")[0]),
"reset": var_to_str(InputMap.action_get_events("reset")[0]),
"exit game": var_to_str(InputMap.action_get_events("exit game")[0]),
"free look toggle": var_to_str(InputMap.action_get_events("free look toggle")[0])
}
setting_inputmap_controller = {
"ui_accept": var_to_str(InputMap.action_get_events("ui_accept")[1]),
"ui_cancel": var_to_str(InputMap.action_get_events("ui_cancel")[1]),
"ui_left": var_to_str(InputMap.action_get_events("ui_left")[1]),
"ui_right": var_to_str(InputMap.action_get_events("ui_right")[1]),
"ui_up": var_to_str(InputMap.action_get_events("ui_up")[1]),
"ui_down": var_to_str(InputMap.action_get_events("ui_down")[1]),
"reset": var_to_str(InputMap.action_get_events("reset")[1]),
"exit game": var_to_str(InputMap.action_get_events("exit game")[1]),
"free look toggle": var_to_str(InputMap.action_get_events("free look toggle")[1])
}
func ResetControls():
setting_inputmap_keyboard = defaultOption_inputmap_keyboard
setting_inputmap_controller = defaultOption_inputmap_controller
ApplySettings_inputmap()
keyrebinding.UpdateBindList()
@export var keyrebinding : Rebinding
var setting = false
func ApplySettings_inputmap():
for key in setting_inputmap_keyboard:
var value = setting_inputmap_keyboard[key]
if (setting): value = str_to_var(value)
InputMap.action_erase_events(key)
InputMap.action_add_event(key, value)
for key in setting_inputmap_controller:
var value = setting_inputmap_controller[key]
if (setting): value = str_to_var(value)
InputMap.action_add_event(key, value)
keyrebinding.UpdateBindList()
setting = false
func ApplySettings_language():
TranslationServer.set_locale(setting_language)
func ApplySettings_colorblind():
GlobalVariables.colorblind = setting_colorblind
func ApplySettings_greyscaledeath():
GlobalVariables.greyscale_death = setting_greyscale_death
checkmark_greyscale.UpdateCheckmark(GlobalVariables.greyscale_death)
func SaveSettings():
data = {
#"has_read_introduction": roundManager.playerData.hasReadIntroduction,
"setting_volume": setting_volume,
"setting_windowed": setting_windowed,
"setting_language" : setting_language,
"setting_controllerEnabled" : setting_controllerEnabled,
"setting_inputmap_keyboard": setting_inputmap_keyboard,
"setting_inputmap_controller": setting_inputmap_controller,
"setting_colorblind": setting_colorblind,
"setting_music_enabled": setting_music_enabled,
"setting_greyscale_death": setting_greyscale_death,
}
print("attempting to save settings")
var file = FileAccess.open(savePath, FileAccess.WRITE)
file.store_var(data)
file.close()
print("file closed")
var receivedFile = false
func LoadSettings():
if (FileAccess.file_exists(savePath)):
print("settings file found, attempting to load settings: ")
print("")
var file = FileAccess.open(savePath, FileAccess.READ)
data = file.get_var()
setting_volume = data.setting_volume
setting_windowed = data.setting_windowed
setting_language = data.setting_language
setting_controllerEnabled = data.setting_controllerEnabled
setting_inputmap_keyboard = data.setting_inputmap_keyboard
setting_inputmap_controller = data.setting_inputmap_controller
if (data.has('setting_colorblind')):
setting_colorblind = data.setting_colorblind
if (checkmark_colorblind != null): checkmark_colorblind.UpdateCheckmark(setting_colorblind)
if (data.has('setting_music_enabled')):
setting_music_enabled = data.setting_music_enabled
if (data.has('setting_greyscale_death')):
setting_greyscale_death = data.setting_greyscale_death
if (checkmark_greyscale != null): checkmark_greyscale.UpdateCheckmark(setting_greyscale_death)
file.close()
print("---------------------------------")
print("user settings: ", data)
print("---------------------------------")
print("settings file closed")
setting = true
ApplySettings_music()
ApplySettings_volume()
ApplySettings_window()
ApplySettings_language()
ApplySettings_controller()
ApplySettings_inputmap()
ApplySettings_colorblind()
ApplySettings_greyscaledeath()
receivedFile = true
else: print("user does not have settings file")