mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-21 23:34:06 +00:00
Settings load/save
This commit is contained in:
parent
e86dda79b7
commit
1e38945f63
5 changed files with 68 additions and 3 deletions
|
|
@ -31,9 +31,15 @@ layout_mode = 2
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_vertical = 4
|
size_flags_vertical = 4
|
||||||
theme = ExtResource("1_il8fq")
|
theme = ExtResource("1_il8fq")
|
||||||
text = "Back"
|
text = "Save"
|
||||||
icon = ExtResource("2_4kao5")
|
icon = ExtResource("2_4kao5")
|
||||||
|
|
||||||
|
[node name="Reset" type="Button" parent="HBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_vertical = 4
|
||||||
|
theme = ExtResource("1_il8fq")
|
||||||
|
text = "Discard"
|
||||||
|
|
||||||
[node name="MusicRoomName" type="Label" parent="HBoxContainer"]
|
[node name="MusicRoomName" type="Label" parent="HBoxContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Options"
|
text = "Options"
|
||||||
|
|
@ -59,7 +65,7 @@ theme = ExtResource("1_il8fq")
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="ScrollContainer/HBoxContainer/HFlowContainer"]
|
[node name="Label" type="Label" parent="ScrollContainer/HBoxContainer/HFlowContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Note: The options currently do nothing"
|
text = "Note: The options currently do something"
|
||||||
|
|
||||||
[node name="Resolution" type="VBoxContainer" parent="ScrollContainer/HBoxContainer/HFlowContainer"]
|
[node name="Resolution" type="VBoxContainer" parent="ScrollContainer/HBoxContainer/HFlowContainer"]
|
||||||
visible = false
|
visible = false
|
||||||
|
|
@ -130,3 +136,4 @@ layout_mode = 2
|
||||||
AudioBusName = &"Effects"
|
AudioBusName = &"Effects"
|
||||||
|
|
||||||
[connection signal="pressed" from="HBoxContainer/BackButton" to="." method="_on_back_button_pressed"]
|
[connection signal="pressed" from="HBoxContainer/BackButton" to="." method="_on_back_button_pressed"]
|
||||||
|
[connection signal="pressed" from="HBoxContainer/Reset" to="." method="_on_discard_button_pressed"]
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,12 @@ public partial class AudioSlider : HSlider
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_audioBusIndex = AudioServer.GetBusIndex(AudioBusName);
|
_audioBusIndex = AudioServer.GetBusIndex(AudioBusName);
|
||||||
|
|
||||||
|
CallDeferred(MethodName.InitializeDeferred);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitializeDeferred()
|
||||||
|
{
|
||||||
this.Value = AudioServer.GetBusVolumeLinear(_audioBusIndex);
|
this.Value = AudioServer.GetBusVolumeLinear(_audioBusIndex);
|
||||||
|
|
||||||
this.ValueChanged += MusicVolumeSliderOnValueChanged;
|
this.ValueChanged += MusicVolumeSliderOnValueChanged;
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ public partial class IntroLogos : CanvasLayer
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
|
OptionsMenu.LoadSettings();
|
||||||
_ = AutoTransition();
|
_ = AutoTransition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ public partial class MenuBase : Control
|
||||||
[Signal]
|
[Signal]
|
||||||
public delegate void MenuClosedEventHandler();
|
public delegate void MenuClosedEventHandler();
|
||||||
|
|
||||||
protected void _on_back_button_pressed()
|
protected virtual void _on_back_button_pressed()
|
||||||
{
|
{
|
||||||
this.QueueFree();
|
this.QueueFree();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,23 @@ public partial class OptionsMenu : MenuBase
|
||||||
[Export] public CheckBox FullScreenToggle { get; private set; }
|
[Export] public CheckBox FullScreenToggle { get; private set; }
|
||||||
|
|
||||||
//[Export] public HSlider MusicVolumeSlider { 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()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
|
LoadSettings();
|
||||||
foreach (var resolution in Resolutions)
|
foreach (var resolution in Resolutions)
|
||||||
{
|
{
|
||||||
ResolutionsList.AddItem($"{resolution.X}x{resolution.Y}");
|
ResolutionsList.AddItem($"{resolution.X}x{resolution.Y}");
|
||||||
|
|
@ -70,4 +84,41 @@ public partial class OptionsMenu : MenuBase
|
||||||
GD.Print($"Selected index: {index} {Resolutions[(int)index]}");
|
GD.Print($"Selected index: {index} {Resolutions[(int)index]}");
|
||||||
DisplayServer.WindowSetSize(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