mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-07 16:05:54 +00:00
Settings load/save
This commit is contained in:
parent
e86dda79b7
commit
1e38945f63
5 changed files with 68 additions and 3 deletions
|
|
@ -21,9 +21,23 @@ public partial class OptionsMenu : MenuBase
|
|||
[Export] public CheckBox FullScreenToggle { get; private set; }
|
||||
|
||||
//[Export] public HSlider MusicVolumeSlider { get; private set; }
|
||||
|
||||
protected override void _on_back_button_pressed()
|
||||
{
|
||||
SaveSettings();
|
||||
|
||||
base._on_back_button_pressed();
|
||||
}
|
||||
|
||||
protected void _on_discard_button_pressed()
|
||||
{
|
||||
LoadSettings();
|
||||
base._on_back_button_pressed();
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
LoadSettings();
|
||||
foreach (var resolution in Resolutions)
|
||||
{
|
||||
ResolutionsList.AddItem($"{resolution.X}x{resolution.Y}");
|
||||
|
|
@ -70,4 +84,41 @@ public partial class OptionsMenu : MenuBase
|
|||
GD.Print($"Selected index: {index} {Resolutions[(int)index]}");
|
||||
DisplayServer.WindowSetSize(Resolutions[(int)index]);
|
||||
}
|
||||
|
||||
private void SaveSettings()
|
||||
{
|
||||
var config = new ConfigFile();
|
||||
|
||||
config.SetValue("Screen","FullScreenMode", (int)DisplayServer.WindowGetMode());
|
||||
config.SetValue("Screen", "VSyncMode", (int)DisplayServer.WindowGetVsyncMode());
|
||||
|
||||
config.SetValue("Audio", "Master", AudioServer.GetBusVolumeLinear(AudioServer.GetBusIndex("Master")));
|
||||
config.SetValue("Audio", "Music", AudioServer.GetBusVolumeLinear(AudioServer.GetBusIndex("Music")));
|
||||
config.SetValue("Audio", "Effects", AudioServer.GetBusVolumeLinear(AudioServer.GetBusIndex("Effects")));
|
||||
|
||||
config.Save("user://Settings.cfg");
|
||||
}
|
||||
|
||||
public static void LoadSettings()
|
||||
{
|
||||
var config = new ConfigFile();
|
||||
Error err = config.Load("user://Settings.cfg");
|
||||
|
||||
// If the file didn't load, ignore it.
|
||||
if (err != Error.Ok)
|
||||
{
|
||||
GD.PrintErr($"Error loading settings: {err}");
|
||||
return;
|
||||
}
|
||||
|
||||
DisplayServer.WindowSetMode((DisplayServer.WindowMode) config.GetValue("Screen", "FullScreenMode", (int)DisplayServer.WindowGetMode()).AsInt32());
|
||||
|
||||
DisplayServer.WindowSetVsyncMode((DisplayServer.VSyncMode)config.GetValue("Screen", "VSyncMode", (int)DisplayServer.WindowGetVsyncMode()).AsInt32());
|
||||
|
||||
AudioServer.SetBusVolumeLinear(AudioServer.GetBusIndex("Master"), config.GetValue("Audio", "Master", AudioServer.GetBusVolumeLinear(AudioServer.GetBusIndex("Master"))).AsSingle());
|
||||
|
||||
AudioServer.SetBusVolumeLinear(AudioServer.GetBusIndex("Effects"), config.GetValue("Audio", "Effects", AudioServer.GetBusVolumeLinear(AudioServer.GetBusIndex("Effects"))).AsSingle());
|
||||
|
||||
AudioServer.SetBusVolumeLinear(AudioServer.GetBusIndex("Music"), config.GetValue("Audio", "Music", AudioServer.GetBusVolumeLinear(AudioServer.GetBusIndex("Music"))).AsSingle());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue