-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsWindow.axaml.cs
More file actions
64 lines (56 loc) · 1.95 KB
/
SettingsWindow.axaml.cs
File metadata and controls
64 lines (56 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using AutoClacker.ViewModels;
using AutoClacker.Services;
using AutoClacker.Models;
namespace AutoClacker;
public partial class SettingsWindow : Window
{
readonly MainViewModel _vm;
readonly Action<string>? _onTriggerKeyChanged;
Button? _trigBtn; TextBlock? _trigLbl; CheckBox? _debugCheck;
bool _capTrig;
public SettingsWindow(MainViewModel vm, Action<string>? onTriggerKeyChanged = null)
{
InitializeComponent();
_vm = vm;
_onTriggerKeyChanged = onTriggerKeyChanged;
Loaded += OnLoad;
KeyDown += OnKey;
}
void OnLoad(object? s, RoutedEventArgs e)
{
_trigBtn = this.FindControl<Button>("SetTriggerButton");
_trigLbl = this.FindControl<TextBlock>("TriggerKeyLabel");
_debugCheck = this.FindControl<CheckBox>("DebugConsoleCheckbox");
if (_trigLbl != null) _trigLbl.Text = _vm.TriggerKey;
if (_debugCheck != null) _debugCheck.IsChecked = _vm.ShowDebugConsole;
}
void OnKey(object? s, KeyEventArgs e)
{
if (_capTrig)
{
var k = e.Key.ToString();
Logger.Log($"SettingsWindow: Trigger key changed to {k}");
_vm.TriggerKey = k;
if (_trigLbl != null) _trigLbl.Text = k;
if (_trigBtn != null) _trigBtn.Content = "Set Hotkey";
_capTrig = false;
_onTriggerKeyChanged?.Invoke(k);
e.Handled = true;
}
}
void SetTriggerButton_Click(object? s, RoutedEventArgs e)
{
_capTrig = true;
if (_trigBtn != null) _trigBtn.Content = "Press any key...";
}
void DebugConsoleCheckbox_Click(object? s, RoutedEventArgs e)
{
_vm.ShowDebugConsole = _debugCheck?.IsChecked ?? false;
Logger.Log($"ShowDebugConsole set to {_vm.ShowDebugConsole}");
}
void CloseButton_Click(object? s, RoutedEventArgs e) => Close();
}