| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using Avalonia.Controls;
- using SlamCross.Models;
- namespace SlamCross.Views;
- public partial class SettingsWindow : Window
- {
- private readonly AppSettings _settings;
- public SettingsWindow(AppSettings settings)
- {
- _settings = settings;
- InitializeComponent();
- LoadSettings();
- }
- private void LoadSettings()
- {
- Set<CheckBox>("StartEnabled", b => b.IsChecked = _settings.StartEnabled);
- Set<CheckBox>("StartMinimized",b => b.IsChecked = _settings.StartMinimized);
- Set<CheckBox>("HoldToPlay", b => b.IsChecked = _settings.HoldToPlay);
- Set<CheckBox>("LogError", b => b.IsChecked = _settings.LogError);
- Set<CheckBox>("WriteTags", b => b.IsChecked = _settings.WriteTags);
- Set<CheckBox>("OverrideFolders",b => b.IsChecked = _settings.OverrideFolders);
- Set<TextBox>("RelayKeyBox", b => b.Text = _settings.RelayKey);
- Set<TextBox>("SteamAppsBox", b => b.Text = _settings.SteamAppsOverride);
- Set<TextBox>("UserDataBox", b => b.Text = _settings.UserDataOverride);
- UpdateOverrideVisibility();
- }
- private void OverrideChanged(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
- => UpdateOverrideVisibility();
- private void UpdateOverrideVisibility()
- {
- var visible = this.FindControl<CheckBox>("OverrideFolders")?.IsChecked == true;
- if (this.FindControl<Grid>("OverridePanel") is Grid panel)
- panel.IsVisible = visible;
- }
- private void Save_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
- {
- _settings.StartEnabled = Get<CheckBox>("StartEnabled")?.IsChecked == true;
- _settings.StartMinimized = Get<CheckBox>("StartMinimized")?.IsChecked == true;
- _settings.HoldToPlay = Get<CheckBox>("HoldToPlay")?.IsChecked == true;
- _settings.LogError = Get<CheckBox>("LogError")?.IsChecked == true;
- _settings.WriteTags = Get<CheckBox>("WriteTags")?.IsChecked == true;
- _settings.OverrideFolders= Get<CheckBox>("OverrideFolders")?.IsChecked == true;
- var relay = Get<TextBox>("RelayKeyBox")?.Text?.Trim();
- if (!string.IsNullOrEmpty(relay) && !relay.Equals(_settings.PlayKey, System.StringComparison.OrdinalIgnoreCase))
- _settings.RelayKey = relay;
- _settings.SteamAppsOverride = Get<TextBox>("SteamAppsBox")?.Text?.Trim() ?? "";
- _settings.UserDataOverride = Get<TextBox>("UserDataBox")?.Text?.Trim() ?? "";
- Close();
- }
- private void Close_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e) => Close();
- private T? Get<T>(string name) where T : Control => this.FindControl<T>(name);
- private void Set<T>(string name, System.Action<T> action) where T : Control
- {
- if (this.FindControl<T>(name) is T ctrl) action(ctrl);
- }
- }
|