mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-04-05 11:25:20 +08:00
103
BetterGenshinImpact/View/Controls/TwoStateButton.cs
Normal file
103
BetterGenshinImpact/View/Controls/TwoStateButton.cs
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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">
|
||||
<ui:Button Command="{Binding StartTriggerCommand}"
|
||||
Content="启动"
|
||||
Icon="{ui:SymbolIcon Play24}"
|
||||
Visibility="{Binding TaskDispatcherEnabled, Converter={StaticResource BooleanToVisibilityRevertConverter}, Mode=OneWay}" />
|
||||
<ui:Button Command="{Binding StopTriggerCommand}"
|
||||
Content="停止"
|
||||
Icon="{ui:SymbolIcon Dismiss24}"
|
||||
Visibility="{Binding TaskDispatcherEnabled, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}" />
|
||||
<controls:TwoStateButton DisableCommand="{Binding StopTriggerCommand}"
|
||||
DisableContent="停止"
|
||||
DisableIcon="{ui:SymbolIcon Dismiss24}"
|
||||
EnableCommand="{Binding StartTriggerCommand}"
|
||||
EnableContent="启动"
|
||||
EnableIcon="{ui:SymbolIcon Play24}"
|
||||
IsChecked="{Binding TaskDispatcherEnabled, Mode=OneWay}" />
|
||||
<!-- <ui:Button Command="{Binding StartTriggerCommand}" -->
|
||||
<!-- Content="启动" -->
|
||||
<!-- Icon="{ui:SymbolIcon Play24}" -->
|
||||
<!-- Visibility="{Binding TaskDispatcherEnabled, Converter={StaticResource BooleanToVisibilityRevertConverter}, Mode=OneWay}" /> -->
|
||||
<!-- <ui:Button Command="{Binding StopTriggerCommand}" -->
|
||||
<!-- Content="停止" -->
|
||||
<!-- Icon="{ui:SymbolIcon Dismiss24}" -->
|
||||
<!-- Visibility="{Binding TaskDispatcherEnabled, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}" /> -->
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</ui:CardExpander.Header>
|
||||
|
||||
@@ -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 @@
|
||||
<ui:TextBlock Margin="0,0,0,8"
|
||||
FontTypography="BodyStrong"
|
||||
Text="独立任务设置" />
|
||||
<!-- 停止任务 -->
|
||||
<ui:CardControl Margin="0,0,0,12" Icon="{ui:SymbolIcon DismissCircle24}">
|
||||
<ui:CardControl.Header>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
FontTypography="Body"
|
||||
Text="停止任务"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
TextWrapping="Wrap">
|
||||
停止下方独立任务的运行
|
||||
</ui:TextBlock>
|
||||
</Grid>
|
||||
</ui:CardControl.Header>
|
||||
<ui:Button Margin="0,0,36,0"
|
||||
Command="{Binding StopSoloTaskCommand}"
|
||||
Content="停止任务"
|
||||
Icon="{ui:SymbolIcon Dismiss24}" />
|
||||
</ui:CardControl>
|
||||
<!-- ~1~ 停止任务 @1@ -->
|
||||
<!-- <ui:CardControl Margin="0,0,0,12" Icon="{ui:SymbolIcon DismissCircle24}"> -->
|
||||
<!-- <ui:CardControl.Header> -->
|
||||
<!-- <Grid> -->
|
||||
<!-- <Grid.RowDefinitions> -->
|
||||
<!-- <RowDefinition Height="Auto" /> -->
|
||||
<!-- <RowDefinition Height="Auto" /> -->
|
||||
<!-- </Grid.RowDefinitions> -->
|
||||
<!-- <ui:TextBlock Grid.Row="0" -->
|
||||
<!-- Grid.Column="0" -->
|
||||
<!-- FontTypography="Body" -->
|
||||
<!-- Text="停止任务" -->
|
||||
<!-- TextWrapping="Wrap" /> -->
|
||||
<!-- <ui:TextBlock Grid.Row="1" -->
|
||||
<!-- Grid.Column="0" -->
|
||||
<!-- Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}" -->
|
||||
<!-- TextWrapping="Wrap"> -->
|
||||
<!-- 停止下方独立任务的运行 -->
|
||||
<!-- </ui:TextBlock> -->
|
||||
<!-- </Grid> -->
|
||||
<!-- </ui:CardControl.Header> -->
|
||||
<!-- <ui:Button Margin="0,0,36,0" -->
|
||||
<!-- Command="{Binding StopSoloTaskCommand}" -->
|
||||
<!-- Content="停止任务" -->
|
||||
<!-- Icon="{ui:SymbolIcon Dismiss24}" /> -->
|
||||
<!-- </ui:CardControl> -->
|
||||
|
||||
|
||||
<ui:CardExpander Margin="0,0,0,12" ContentPadding="0">
|
||||
@@ -78,12 +78,15 @@
|
||||
点击查看使用教程
|
||||
</Hyperlink>
|
||||
</ui:TextBlock>
|
||||
<ui:Button Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,24,0"
|
||||
Command="{Binding SwitchAutoGeniusInvokationCommand}"
|
||||
Content="{Binding SwitchAutoGeniusInvokationButtonText}" />
|
||||
<controls:TwoStateButton Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,24,0"
|
||||
DisableCommand="{Binding StopSoloTaskCommand}"
|
||||
DisableContent="停止"
|
||||
EnableCommand="{Binding SwitchAutoGeniusInvokationCommand}"
|
||||
EnableContent="{Binding SwitchAutoGeniusInvokationButtonText}"
|
||||
IsChecked="{Binding SwitchAutoGeniusInvokationEnabled}" />
|
||||
</Grid>
|
||||
</ui:CardExpander.Header>
|
||||
<StackPanel>
|
||||
@@ -178,12 +181,15 @@
|
||||
点击查看使用教程
|
||||
</Hyperlink>
|
||||
</ui:TextBlock>
|
||||
<ui:Button Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,24,0"
|
||||
Command="{Binding SwitchAutoWoodCommand}"
|
||||
Content="{Binding SwitchAutoWoodButtonText}" />
|
||||
<controls:TwoStateButton Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,24,0"
|
||||
DisableCommand="{Binding StopSoloTaskCommand}"
|
||||
DisableContent="停止"
|
||||
EnableCommand="{Binding SwitchAutoWoodCommand}"
|
||||
EnableContent="{Binding SwitchAutoWoodButtonText}"
|
||||
IsChecked="{Binding SwitchAutoWoodEnabled}" />
|
||||
</Grid>
|
||||
</ui:CardExpander.Header>
|
||||
<StackPanel>
|
||||
@@ -346,12 +352,15 @@
|
||||
点击查看使用教程
|
||||
</Hyperlink>
|
||||
</ui:TextBlock>
|
||||
<ui:Button Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,24,0"
|
||||
Command="{Binding SwitchAutoFightCommand}"
|
||||
Content="{Binding SwitchAutoFightButtonText}" />
|
||||
<controls:TwoStateButton Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,24,0"
|
||||
DisableCommand="{Binding StopSoloTaskCommand}"
|
||||
DisableContent="停止"
|
||||
EnableCommand="{Binding SwitchAutoFightCommand}"
|
||||
EnableContent="{Binding SwitchAutoFightButtonText}"
|
||||
IsChecked="{Binding SwitchAutoFightEnabled}" />
|
||||
</Grid>
|
||||
</ui:CardExpander.Header>
|
||||
<StackPanel>
|
||||
@@ -504,12 +513,15 @@
|
||||
点击查看使用教程
|
||||
</Hyperlink>
|
||||
</ui:TextBlock>
|
||||
<ui:Button Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,24,0"
|
||||
Command="{Binding SwitchAutoDomainCommand}"
|
||||
Content="{Binding SwitchAutoDomainButtonText}" />
|
||||
<controls:TwoStateButton Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,24,0"
|
||||
DisableCommand="{Binding StopSoloTaskCommand}"
|
||||
DisableContent="停止"
|
||||
EnableCommand="{Binding SwitchAutoDomainCommand}"
|
||||
EnableContent="{Binding SwitchAutoDomainButtonText}"
|
||||
IsChecked="{Binding SwitchAutoDomainEnabled}" />
|
||||
</Grid>
|
||||
</ui:CardExpander.Header>
|
||||
<StackPanel>
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user