2025-12-17 16:19:08 -07:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Avalonia.Controls;
|
|
|
|
|
using Avalonia.Interactivity;
|
|
|
|
|
using UnifiedFarmLauncher.Services;
|
|
|
|
|
using UnifiedFarmLauncher.ViewModels;
|
|
|
|
|
|
|
|
|
|
namespace UnifiedFarmLauncher.Views
|
|
|
|
|
{
|
|
|
|
|
public partial class GlobalSettingsWindow : Window
|
|
|
|
|
{
|
|
|
|
|
private readonly GlobalSettingsViewModel _viewModel;
|
|
|
|
|
private bool _result;
|
|
|
|
|
|
|
|
|
|
public GlobalSettingsWindow()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
var configService = new ConfigService();
|
|
|
|
|
_viewModel = new GlobalSettingsViewModel(configService);
|
|
|
|
|
DataContext = _viewModel;
|
|
|
|
|
SetupEventHandlers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitializeComponent()
|
|
|
|
|
{
|
|
|
|
|
Avalonia.Markup.Xaml.AvaloniaXamlLoader.Load(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetupEventHandlers()
|
|
|
|
|
{
|
|
|
|
|
this.FindControl<Button>("OkButton")!.Click += OkButton_Click;
|
|
|
|
|
this.FindControl<Button>("CancelButton")!.Click += CancelButton_Click;
|
2025-12-17 16:23:40 -07:00
|
|
|
this.FindControl<Button>("ToggleRenderKeyButton")!.Click += ToggleRenderKeyButton_Click;
|
2025-12-17 16:19:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OkButton_Click(object? sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_viewModel.Save();
|
|
|
|
|
_result = true;
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
catch (System.Exception ex)
|
|
|
|
|
{
|
|
|
|
|
// Could show error message here
|
|
|
|
|
System.Diagnostics.Debug.WriteLine($"Failed to save global settings: {ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CancelButton_Click(object? sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_result = false;
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-17 16:23:40 -07:00
|
|
|
private void ToggleRenderKeyButton_Click(object? sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var textBox = this.FindControl<Avalonia.Controls.TextBox>("SheepItRenderKeyTextBox");
|
|
|
|
|
if (textBox != null)
|
|
|
|
|
{
|
|
|
|
|
_viewModel.IsRenderKeyVisible = !_viewModel.IsRenderKeyVisible;
|
|
|
|
|
textBox.PasswordChar = _viewModel.IsRenderKeyVisible ? '\0' : '*';
|
|
|
|
|
var button = sender as Button;
|
|
|
|
|
if (button != null)
|
|
|
|
|
{
|
|
|
|
|
button.Content = _viewModel.IsRenderKeyVisible ? "🙈" : "👁";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-17 16:19:08 -07:00
|
|
|
public async Task<bool> ShowDialogAsync(Window parent)
|
|
|
|
|
{
|
|
|
|
|
await base.ShowDialog(parent);
|
|
|
|
|
return _result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|