diff --git a/BetterGenshinImpact/View/Controls/TwoStateButton.cs b/BetterGenshinImpact/View/Controls/TwoStateButton.cs new file mode 100644 index 00000000..ff6378a1 --- /dev/null +++ b/BetterGenshinImpact/View/Controls/TwoStateButton.cs @@ -0,0 +1,103 @@ +using System.Windows; +using System.Windows.Input; +using Wpf.Ui.Controls; + +namespace BetterGenshinImpact.View.Controls; + +public class TwoStateButton : Button +{ + public TwoStateButton() + { + if (TryFindResource(typeof(Button)) is Style style) + { + Style = style; + } + + Loaded += OnLoaded; + } + + private void OnLoaded(object sender, RoutedEventArgs e) + { + UpdateButton(); + } + + private static void OnIsCheckedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is TwoStateButton button) + { + button.UpdateButton(); + } + } + + private static readonly DependencyProperty IsCheckedProperty = DependencyProperty.Register(nameof(IsChecked), typeof(bool), typeof(TwoStateButton), new PropertyMetadata(false, OnIsCheckedChanged)); + + public bool IsChecked + { + get => (bool)GetValue(IsCheckedProperty); + set => SetValue(IsCheckedProperty, value); + } + + private static readonly DependencyProperty EnableContentProperty = DependencyProperty.Register(nameof(EnableContent), typeof(object), typeof(TwoStateButton), new PropertyMetadata("启动")); + + public object EnableContent + { + get => (string)GetValue(EnableContentProperty); + set => SetValue(EnableContentProperty, value); + } + + private static readonly DependencyProperty EnableIconProperty = DependencyProperty.Register(nameof(EnableIcon), typeof(IconElement), typeof(TwoStateButton), new PropertyMetadata(null)); + + public IconElement EnableIcon + { + get => (IconElement)GetValue(EnableIconProperty); + set => SetValue(EnableIconProperty, value); + } + + private static readonly DependencyProperty EnableCommandProperty = DependencyProperty.Register(nameof(EnableCommand), typeof(ICommand), typeof(TwoStateButton), new PropertyMetadata(null)); + + public ICommand EnableCommand + { + get => (ICommand)GetValue(EnableCommandProperty); + set => SetValue(EnableCommandProperty, value); + } + + private static readonly DependencyProperty DisableContentProperty = DependencyProperty.Register(nameof(DisableContent), typeof(object), typeof(TwoStateButton), new PropertyMetadata("停止")); + + public object DisableContent + { + get => (string)GetValue(DisableContentProperty); + set => SetValue(DisableContentProperty, value); + } + + private static readonly DependencyProperty DisableIconProperty = DependencyProperty.Register(nameof(DisableIcon), typeof(IconElement), typeof(TwoStateButton), new PropertyMetadata(null)); + + public IconElement DisableIcon + { + get => (IconElement)GetValue(DisableIconProperty); + set => SetValue(DisableIconProperty, value); + } + + private static readonly DependencyProperty DisableCommandProperty = DependencyProperty.Register(nameof(DisableCommand), typeof(ICommand), typeof(TwoStateButton), new PropertyMetadata(null)); + + public ICommand DisableCommand + { + get => (ICommand)GetValue(DisableCommandProperty); + set => SetValue(DisableCommandProperty, value); + } + + private void UpdateButton() + { + if (IsChecked) + { + Command = DisableCommand; + Content = DisableContent; + Icon = DisableIcon; + } + else + { + Command = EnableCommand; + Content = EnableContent; + Icon = EnableIcon; + } + } +} \ No newline at end of file diff --git a/BetterGenshinImpact/View/Pages/HomePage.xaml b/BetterGenshinImpact/View/Pages/HomePage.xaml index 4d89a677..4535bb76 100644 --- a/BetterGenshinImpact/View/Pages/HomePage.xaml +++ b/BetterGenshinImpact/View/Pages/HomePage.xaml @@ -2,8 +2,8 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:b="http://schemas.microsoft.com/xaml/behaviors" + xmlns:controls="clr-namespace:BetterGenshinImpact.View.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:local="clr-namespace:BetterGenshinImpact.View.Pages" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:pages="clr-namespace:BetterGenshinImpact.ViewModel.Pages" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" @@ -95,14 +95,21 @@ Grid.Column="1" Margin="0,0,24,0" Orientation="Horizontal"> - - + + + + + + + + + diff --git a/BetterGenshinImpact/View/Pages/TaskSettingsPage.xaml b/BetterGenshinImpact/View/Pages/TaskSettingsPage.xaml index 85388868..ec109448 100644 --- a/BetterGenshinImpact/View/Pages/TaskSettingsPage.xaml +++ b/BetterGenshinImpact/View/Pages/TaskSettingsPage.xaml @@ -2,9 +2,9 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:b="http://schemas.microsoft.com/xaml/behaviors" + xmlns:controls="clr-namespace:BetterGenshinImpact.View.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:helpers="clr-namespace:BetterGenshinImpact.Helpers" - xmlns:local="clr-namespace:BetterGenshinImpact.View.Pages" xmlns:markup="clr-namespace:BetterGenshinImpact.Markup" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:pages="clr-namespace:BetterGenshinImpact.ViewModel.Pages" @@ -23,32 +23,32 @@ - - - - - - - - - - - 停止下方独立任务的运行 - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -78,12 +78,15 @@ 点击查看使用教程 - + @@ -178,12 +181,15 @@ 点击查看使用教程 - + @@ -346,12 +352,15 @@ 点击查看使用教程 - + @@ -504,12 +513,15 @@ 点击查看使用教程 - + diff --git a/BetterGenshinImpact/ViewModel/Pages/TaskSettingsPageViewModel.cs b/BetterGenshinImpact/ViewModel/Pages/TaskSettingsPageViewModel.cs index b0e12f83..26614580 100644 --- a/BetterGenshinImpact/ViewModel/Pages/TaskSettingsPageViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Pages/TaskSettingsPageViewModel.cs @@ -37,15 +37,19 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw private static readonly object _locker = new(); [ObservableProperty] private string[] _strategyList; + [ObservableProperty] private bool _switchAutoGeniusInvokationEnabled; [ObservableProperty] private string _switchAutoGeniusInvokationButtonText = "启动"; [ObservableProperty] private int _autoWoodRoundNum; [ObservableProperty] private int _autoWoodDailyMaxCount = 2000; + [ObservableProperty] private bool _switchAutoWoodEnabled; [ObservableProperty] private string _switchAutoWoodButtonText = "启动"; [ObservableProperty] private string[] _combatStrategyList; [ObservableProperty] private int _autoDomainRoundNum; + [ObservableProperty] private bool _switchAutoDomainEnabled; [ObservableProperty] private string _switchAutoDomainButtonText = "启动"; + [ObservableProperty] private bool _switchAutoFightEnabled; [ObservableProperty] private string _switchAutoFightButtonText = "启动"; [ObservableProperty] private string _switchAutoTrackButtonText = "启动"; [ObservableProperty] private string _switchAutoTrackPathButtonText = "启动"; @@ -88,6 +92,10 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw private async Task OnStopSoloTask() { CancellationContext.Instance.Cancel(); + SwitchAutoGeniusInvokationEnabled = false; + SwitchAutoWoodEnabled = false; + SwitchAutoDomainEnabled = false; + SwitchAutoFightEnabled = false; await Task.Delay(800); } @@ -139,8 +147,10 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw var content = await File.ReadAllTextAsync(path); + SwitchAutoGeniusInvokationEnabled = true; await new TaskRunner(DispatcherTimerOperationEnum.UseSelfCaptureImage) .RunSoloTaskAsync(new AutoGeniusInvokationTask(new GeniusInvokationTaskParam(content))); + SwitchAutoGeniusInvokationEnabled = false; } [RelayCommand] @@ -152,8 +162,10 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw [RelayCommand] public async Task OnSwitchAutoWood() { + SwitchAutoWoodEnabled = true; await new TaskRunner(DispatcherTimerOperationEnum.UseSelfCaptureImage) .RunSoloTaskAsync(new AutoWoodTask(new WoodTaskParam(AutoWoodRoundNum, AutoWoodDailyMaxCount))); + SwitchAutoWoodEnabled = false; } [RelayCommand] @@ -176,8 +188,10 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw PickDropsAfterFightEnabled = Config.AutoFightConfig.PickDropsAfterFightEnabled }; + SwitchAutoFightEnabled = true; await new TaskRunner(DispatcherTimerOperationEnum.UseCacheImageWithTrigger) .RunSoloTaskAsync(new AutoFightTask(param)); + SwitchAutoFightEnabled = false; } [RelayCommand] @@ -193,8 +207,10 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw { return; } + SwitchAutoDomainEnabled = true; await new TaskRunner(DispatcherTimerOperationEnum.UseCacheImage) .RunSoloTaskAsync(new AutoDomainTask(new AutoDomainParam(AutoDomainRoundNum, path))); + SwitchAutoDomainEnabled = false; } private bool GetFightStrategy(out string path)