Pong/Scripts/Managers/UI/Menus/Settings.cs

51 lines
1.1 KiB
C#
Raw Normal View History

namespace Pong.Scripts.Managers.UI.Menus;
public partial class Settings : BaseMenu
{
private SettingsManager _settings;
private SpinBox _scale;
private Button _saveButton;
private bool _scaleModified;
protected override void EnterTree()
{
GetNodes();
_scale.Value = _settings.SettingsData.Scale;
}
private void OnBackButtonPressed()
{
GetTree().ChangeSceneToFile("res://Scenes/UI/Menus/MainMenu.tscn");
}
private void GetNodes()
{
_settings = GetNode<SettingsManager>("/root/SettingsManager");
_scale = GetNode<SpinBox>("ScrollContainer/InternalMainContainer/ScaleContainer/Scale");
_saveButton = GetNode<Button>("SaveButton");
_scale.ValueChanged += ScaleChanged;
}
private void ScaleChanged(double value)
{
_scaleModified = !value.Equals(_settings.SettingsData.Scale);
CheckIfModified();
}
private bool CheckIfModified()
{
var isModified = _scaleModified;
_saveButton.Disabled = !isModified;
return isModified;
}
private async void OnSaveButtonPressed()
{
if (!await _settings.SaveSettings(_settings.SettingsData with { Scale = _scale.Value })) return;
_saveButton.Disabled = true;
}
}