diff --git a/InfoWindow.xaml b/InfoWindow.xaml new file mode 100644 index 0000000..4d274cf --- /dev/null +++ b/InfoWindow.xaml @@ -0,0 +1,25 @@ + + + + + + \ No newline at end of file diff --git a/InfoWindow.xaml.cs b/InfoWindow.xaml.cs new file mode 100644 index 0000000..633a3a6 --- /dev/null +++ b/InfoWindow.xaml.cs @@ -0,0 +1,23 @@ +namespace HellDivers2OneKeyStratagem; + +public partial class InfoWindow() +{ + private readonly MainWindow _mainWindow = null!; + + public InfoWindow(MainWindow mainWindow): this() + { + _mainWindow = mainWindow; + + InitializeComponent(); + } + + public void SetInfo(string info) + { + InfoLabel.Content = info; + } + + private void InfoWindow_OnClosed(object? sender, EventArgs e) + { + _mainWindow.NotifyInfoWindowClosed(); + } +} diff --git a/MainWindow.xaml b/MainWindow.xaml index c25da98..08ecb21 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -17,8 +17,9 @@ SizeToContent="WidthAndHeight" ResizeMode="CanMinimize" - Loaded="Window_Loaded" - Deactivated="Window_Deactivated"> + Initialized="MainWindow_OnInitialized" + Deactivated="Window_Deactivated" + Closed="MainWindow_OnClosed"> @@ -133,6 +134,12 @@ + + + + diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index aa757c2..339e5fc 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -1,13 +1,13 @@ -using EdgeTTS; -using iNKORE.UI.WPF.Modern.Controls; -using NAudio.Wave; -using NHotkey; -using System.Diagnostics; +using System.Diagnostics; using System.Globalization; using System.IO; using System.Windows; using System.Windows.Controls; using System.Windows.Input; +using EdgeTTS; +using iNKORE.UI.WPF.Modern.Controls; +using NAudio.Wave; +using NHotkey; using Brushes = System.Windows.Media.Brushes; using CheckBox = System.Windows.Controls.CheckBox; using HorizontalAlignment = System.Windows.HorizontalAlignment; @@ -40,10 +40,9 @@ private bool IsLoading } } - private async void Window_Loaded(object sender, RoutedEventArgs e) + private async void MainWindow_OnInitialized(object? sender, EventArgs e) { IsLoading = true; - BeginInit(); try { @@ -56,7 +55,6 @@ private async void Window_Loaded(object sender, RoutedEventArgs e) } finally { - EndInit(); IsLoading = false; } @@ -644,7 +642,9 @@ private async Task StartSpeechTrigger() _voiceCommand.CommandRecognized += (_, command) => { var failed = command.Score < Settings.VoiceConfidence; - VoiceRecognizeResultLabel.Content = $@"【{(failed ? "失败" : "成功")}】识别阈值:{command.Score:F3} 识别文字:{command.Text} 当前程序:{ActiveWindowMonitor.CurrentProcessFileName}"; + var info = $"【{(failed ? "失败" : "成功")}】识别阈值:{command.Score:F3} 识别文字:{command.Text}"; + VoiceRecognizeResultLabel.Content = info; + _infoWindow?.SetInfo(info); if (failed) return; @@ -823,6 +823,7 @@ private void RefreshAfterEnableSpeechTriggerChanged() SpeechSubSettingsContainer.Visibility = Settings.EnableSpeechTrigger ? Visibility.Visible : Visibility.Collapsed; EnableSetKeyBySpeechCheckBox.IsEnabled = Settings.EnableSpeechTrigger; StratagemsContainer.Visibility = Settings.EnableSpeechTrigger || Settings.EnableHotkeyTrigger ? Visibility.Visible : Visibility.Collapsed; + ShowSpeechInfoWindowCheckBox.Visibility = Settings.EnableSpeechTrigger ? Visibility.Visible : Visibility.Collapsed; } private void OpenSpeechRecognitionControlPanelButton_OnClick(object sender, RoutedEventArgs e) @@ -1113,4 +1114,44 @@ private void GenerateTxtButton_Click(object sender, RoutedEventArgs e) File.WriteAllText(Path.Combine(folder, stratagem.Name), stratagem.Name); GenerateVoiceMessageLabel.Content = @"txt 生成完毕"; } + + private InfoWindow? _infoWindow; + + private void ShowInfoWindow() + { + if (_infoWindow != null) + return; + + _infoWindow = new InfoWindow(this); + _infoWindow.Show(); + } + + private void HideInfoWindow() + { + _infoWindow?.Close(); + _infoWindow = null; + } + + public void NotifyInfoWindowClosed() + { + _infoWindow = null; + ShowSpeechInfoWindowCheckBox.IsChecked = false; + } + + private void ShowSpeechInfoWindowCheckBox_OnChecked(object sender, RoutedEventArgs e) + { + ShowInfoWindow(); + } + + private void ShowSpeechInfoWindowCheckBox_OnUnchecked(object sender, RoutedEventArgs e) + { + HideInfoWindow(); + } + + private async void MainWindow_OnClosed(object? sender, EventArgs e) + { + HideInfoWindow(); + HotkeyGroupManager.ClearHotkeyGroup(); + await StopSpeechTrigger(); + } }