2024-01-28 11:58:35 +00:00
|
|
|
class_name OptionsManager extends Node
|
|
|
|
|
2024-04-05 10:52:30 +01:00
|
|
|
@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]
|
|
|
|
}
|
|
|
|
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]
|
|
|
|
}
|
|
|
|
|
2024-01-28 11:58:35 +00:00
|
|
|
@export var ui_windowed : CanvasItem
|
|
|
|
@export var ui_fullscreen : CanvasItem
|
2024-04-05 10:52:30 +01:00
|
|
|
@export var ui_deviceController : CanvasItem
|
|
|
|
@export var ui_deviceMouse : CanvasItem
|
2024-01-28 11:58:35 +00:00
|
|
|
@export var button_windowed : ButtonClass
|
|
|
|
@export var button_fullscreen : ButtonClass
|
|
|
|
@export var menu : MenuManager
|
|
|
|
@export var ui_volume : Label
|
2024-04-10 19:19:04 +01:00
|
|
|
@export var checkmark_colorblind : Checkmark
|
2024-04-05 10:52:30 +01:00
|
|
|
|
|
|
|
const savePath := "user://buckshotroulette_options_12.shell"
|
2024-01-28 11:58:35 +00:00
|
|
|
var data = {}
|
2024-04-05 10:52:30 +01:00
|
|
|
var data_inputmap = {}
|
|
|
|
var setting_inputmap_keyboard = {}
|
|
|
|
var setting_inputmap_controller = {}
|
2024-01-28 11:58:35 +00:00
|
|
|
var setting_volume = 1
|
|
|
|
var setting_windowed = false
|
2024-04-05 10:52:30 +01:00
|
|
|
var setting_language = "EN"
|
|
|
|
var setting_controllerEnabled = false
|
2024-04-10 19:19:04 +01:00
|
|
|
var setting_colorblind = false
|
2024-04-13 15:32:57 +01:00
|
|
|
var setting_music_enabled = true
|
2024-01-28 11:58:35 +00:00
|
|
|
|
|
|
|
func _ready():
|
2024-10-28 16:42:34 +00:00
|
|
|
print("your version %s does not match this %s version" % [900, 400])
|
2024-01-28 11:58:35 +00:00
|
|
|
LoadSettings()
|
2024-04-05 10:52:30 +01:00
|
|
|
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()
|
2024-01-28 11:58:35 +00:00
|
|
|
|
2024-04-10 19:19:04 +01:00
|
|
|
func Printout():
|
|
|
|
print("user current version: ", GlobalVariables.currentVersion)
|
2024-04-13 15:32:57 +01:00
|
|
|
print("user current hotfix: ", GlobalVariables.currentVersion_hotfix)
|
2024-04-10 19:19:04 +01:00
|
|
|
|
2024-01-28 11:58:35 +00:00
|
|
|
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()
|
2024-04-05 10:52:30 +01:00
|
|
|
"controller enable":
|
|
|
|
setting_controllerEnabled = true
|
|
|
|
ApplySettings_controller()
|
|
|
|
"controller disable":
|
|
|
|
setting_controllerEnabled = false
|
|
|
|
ApplySettings_controller()
|
2024-01-28 11:58:35 +00:00
|
|
|
"windowed":
|
|
|
|
setting_windowed = true
|
|
|
|
ApplySettings_window()
|
|
|
|
"fullscreen":
|
|
|
|
setting_windowed = false
|
|
|
|
ApplySettings_window()
|
2024-04-05 10:52:30 +01:00
|
|
|
|
2024-01-28 11:58:35 +00:00
|
|
|
if (alias != "increase" && alias != "decrease"): menu.ResetButtons()
|
2024-04-05 10:52:30 +01:00
|
|
|
|
2024-04-10 19:19:04 +01:00
|
|
|
func ToggleColorblind():
|
|
|
|
setting_colorblind = !setting_colorblind
|
|
|
|
checkmark_colorblind.UpdateCheckmark(setting_colorblind)
|
|
|
|
ApplySettings_colorblind()
|
2024-04-05 10:52:30 +01:00
|
|
|
|
|
|
|
func AdjustLanguage(alias : String):
|
|
|
|
setting_language = alias
|
|
|
|
ApplySettings_language()
|
|
|
|
menu.ResetButtons()
|
|
|
|
|
2024-01-28 11:58:35 +00:00
|
|
|
func ApplySettings_volume():
|
|
|
|
AudioServer.set_bus_volume_db(0, linear_to_db(setting_volume))
|
|
|
|
UpdateDisplay()
|
|
|
|
pass
|
|
|
|
|
2024-04-13 15:32:57 +01:00
|
|
|
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
|
2024-10-29 08:00:41 +00:00
|
|
|
AudioServer.set_bus_mute(1, !setting_music_enabled)
|
|
|
|
AudioServer.set_bus_mute(2, !setting_music_enabled)
|
2024-04-13 15:32:57 +01:00
|
|
|
AudioServer.get_property_list()
|
|
|
|
GlobalVariables.music_enabled = setting_music_enabled
|
|
|
|
|
2024-01-28 11:58:35 +00:00
|
|
|
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
|
2024-04-05 10:52:30 +01:00
|
|
|
button_fullscreen.mainActive = true
|
2024-01-28 11:58:35 +00:00
|
|
|
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
|
2024-04-05 10:52:30 +01:00
|
|
|
button_windowed.mainActive = true
|
2024-01-28 11:58:35 +00:00
|
|
|
pass
|
|
|
|
|
2024-04-05 10:52:30 +01:00
|
|
|
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])
|
|
|
|
}
|
|
|
|
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])
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2024-04-10 19:19:04 +01:00
|
|
|
func ApplySettings_colorblind():
|
|
|
|
GlobalVariables.colorblind = setting_colorblind
|
|
|
|
|
2024-01-28 11:58:35 +00:00
|
|
|
func SaveSettings():
|
|
|
|
data = {
|
|
|
|
#"has_read_introduction": roundManager.playerData.hasReadIntroduction,
|
|
|
|
"setting_volume": setting_volume,
|
2024-04-05 10:52:30 +01:00
|
|
|
"setting_windowed": setting_windowed,
|
|
|
|
"setting_language" : setting_language,
|
|
|
|
"setting_controllerEnabled" : setting_controllerEnabled,
|
|
|
|
"setting_inputmap_keyboard": setting_inputmap_keyboard,
|
2024-04-10 19:19:04 +01:00
|
|
|
"setting_inputmap_controller": setting_inputmap_controller,
|
2024-04-13 15:32:57 +01:00
|
|
|
"setting_colorblind": setting_colorblind,
|
|
|
|
"setting_music_enabled": setting_music_enabled
|
2024-01-28 11:58:35 +00:00
|
|
|
}
|
2024-04-10 19:19:04 +01:00
|
|
|
print("attempting to save settings")
|
2024-01-28 11:58:35 +00:00
|
|
|
var file = FileAccess.open(savePath, FileAccess.WRITE)
|
|
|
|
file.store_var(data)
|
|
|
|
file.close()
|
2024-04-10 19:19:04 +01:00
|
|
|
print("file closed")
|
2024-01-28 11:58:35 +00:00
|
|
|
|
2024-04-05 10:52:30 +01:00
|
|
|
var receivedFile = false
|
2024-01-28 11:58:35 +00:00
|
|
|
func LoadSettings():
|
|
|
|
if (FileAccess.file_exists(savePath)):
|
2024-04-10 19:19:04 +01:00
|
|
|
print("settings file found, attempting to load settings: ")
|
|
|
|
print("")
|
2024-01-28 11:58:35 +00:00
|
|
|
var file = FileAccess.open(savePath, FileAccess.READ)
|
|
|
|
data = file.get_var()
|
|
|
|
setting_volume = data.setting_volume
|
|
|
|
setting_windowed = data.setting_windowed
|
2024-04-05 10:52:30 +01:00
|
|
|
setting_language = data.setting_language
|
|
|
|
setting_controllerEnabled = data.setting_controllerEnabled
|
|
|
|
setting_inputmap_keyboard = data.setting_inputmap_keyboard
|
|
|
|
setting_inputmap_controller = data.setting_inputmap_controller
|
2024-04-10 19:19:04 +01:00
|
|
|
if (data.has('setting_colorblind')):
|
|
|
|
setting_colorblind = data.setting_colorblind
|
|
|
|
if (checkmark_colorblind != null): checkmark_colorblind.UpdateCheckmark(setting_colorblind)
|
2024-04-13 15:32:57 +01:00
|
|
|
if (data.has('setting_music_enabled')):
|
|
|
|
setting_music_enabled = data.setting_music_enabled
|
2024-01-28 11:58:35 +00:00
|
|
|
file.close()
|
2024-04-10 19:19:04 +01:00
|
|
|
print("---------------------------------")
|
|
|
|
print("user settings: ", data)
|
|
|
|
print("---------------------------------")
|
|
|
|
print("settings file closed")
|
2024-04-05 10:52:30 +01:00
|
|
|
setting = true
|
2024-04-13 15:32:57 +01:00
|
|
|
ApplySettings_music()
|
2024-01-28 11:58:35 +00:00
|
|
|
ApplySettings_volume()
|
|
|
|
ApplySettings_window()
|
2024-04-05 10:52:30 +01:00
|
|
|
ApplySettings_language()
|
|
|
|
ApplySettings_controller()
|
|
|
|
ApplySettings_inputmap()
|
2024-04-10 19:19:04 +01:00
|
|
|
ApplySettings_colorblind()
|
2024-04-05 10:52:30 +01:00
|
|
|
receivedFile = true
|
2024-04-10 19:19:04 +01:00
|
|
|
else: print("user does not have settings file")
|