mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-15 17:30:27 +08:00
perf: 账号切换增加是否启用勾选框 (#17280)
* perf: 账号切换增加是否启用勾选框 * rft: 改用 OnDeserialized 处理迁移
This commit is contained in:
@@ -11,13 +11,25 @@
|
||||
// but WITHOUT ANY WARRANTY
|
||||
// </copyright>
|
||||
#nullable enable
|
||||
using System.Text.Json.Serialization;
|
||||
using static MaaWpfGui.Main.AsstProxy;
|
||||
|
||||
namespace MaaWpfGui.Configuration.Single.MaaTask;
|
||||
|
||||
public class StartUpTask : BaseTask
|
||||
public class StartUpTask : BaseTask, IJsonOnDeserialized
|
||||
{
|
||||
public StartUpTask() => TaskType = TaskType.StartUp;
|
||||
|
||||
public string AccountName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether 启用账号切换。null 表示尚未迁移的旧配置,迁移后不再为 null。
|
||||
/// </summary>
|
||||
public bool? AccountSwitchEnabled { get; set; }
|
||||
|
||||
public void OnDeserialized()
|
||||
{
|
||||
// v6.14.0-b2 新增一次性配置迁移:旧配置没有这个字段(json 中不存在,反序列化后为 null),此时按是否已有账号名决定初始值
|
||||
AccountSwitchEnabled ??= !string.IsNullOrEmpty(AccountName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,12 @@ public class StartUpSettingsUserControlModel : TaskSettingsViewModel, StartUpSet
|
||||
}
|
||||
}
|
||||
|
||||
public bool AccountSwitchEnabled
|
||||
{
|
||||
get => GetTaskConfig<StartUpTask>().AccountSwitchEnabled ?? false;
|
||||
set => SetTaskConfig<StartUpTask>(t => t.AccountSwitchEnabled == value, t => t.AccountSwitchEnabled = value);
|
||||
}
|
||||
|
||||
// UI 绑定的方法
|
||||
[UsedImplicitly]
|
||||
public async void AccountSwitchManualRun()
|
||||
@@ -88,7 +94,8 @@ public class StartUpSettingsUserControlModel : TaskSettingsViewModel, StartUpSet
|
||||
|
||||
var clientType = SettingsViewModel.GameSettings.ClientType;
|
||||
var accountName = !SettingsViewModel.ConnectSettings.UseAttachWindow &&
|
||||
clientType is ClientType.Official or ClientType.Bilibili or ClientType.Txwy
|
||||
clientType is ClientType.Official or ClientType.Bilibili or ClientType.Txwy &&
|
||||
startUp.AccountSwitchEnabled is true
|
||||
? startUp.AccountName
|
||||
: string.Empty;
|
||||
|
||||
|
||||
@@ -20,39 +20,37 @@
|
||||
mc:Ignorable="d">
|
||||
<StackPanel>
|
||||
<StackPanel Visibility="{c:Binding !UseAttachWindow, Source={x:Static settings_vms:ConnectSettingsUserControlModel.Instance}}">
|
||||
<Grid Margin="0,5" Visibility="{c:Binding 'ClientType == "Official" or ClientType == "Bilibili" or ClientType == "txwy"', Source={x:Static settings_vms:GameSettingsUserControlModel.Instance}}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<StackPanel Visibility="{c:Binding 'ClientType == "Official" or ClientType == "Bilibili" or ClientType == "txwy"', Source={x:Static settings_vms:GameSettingsUserControlModel.Instance}}">
|
||||
<StackPanel
|
||||
Margin="0,5"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top"
|
||||
Orientation="Horizontal">
|
||||
<TextBlock
|
||||
Margin="8,0,0,0"
|
||||
Text="{DynamicResource AccountSwitch}"
|
||||
Visibility="Hidden" />
|
||||
<controls:TooltipBlock Margin="0,0,5,0" TooltipText="{DynamicResource AccountSwitchTip}" />
|
||||
<CheckBox Content="{DynamicResource AccountSwitch}" IsChecked="{Binding AccountSwitchEnabled}" />
|
||||
<controls:TooltipBlock TooltipText="{DynamicResource AccountSwitchTip}" />
|
||||
</StackPanel>
|
||||
<hc:TextBox
|
||||
Grid.Column="0"
|
||||
hc:BorderElement.CornerRadius="4,0,0,4"
|
||||
hc:TitleElement.Title="{DynamicResource AccountSwitch}"
|
||||
IsReadOnly="{c:Binding !Idle,
|
||||
Source={x:Static helper:Instances.SettingsViewModel}}"
|
||||
Text="{Binding AccountName, UpdateSourceTrigger=PropertyChanged}" />
|
||||
<Button
|
||||
Grid.Column="1"
|
||||
Padding="12,1,12,1"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Bottom"
|
||||
hc:BorderElement.CornerRadius="0,4,4,0"
|
||||
BorderThickness="0,1,1,1"
|
||||
Command="{s:Action AccountSwitchManualRun}"
|
||||
Content="{DynamicResource AccountSwitchManualRun}"
|
||||
IsEnabled="{c:Binding 'AccountName != ""'}" />
|
||||
</Grid>
|
||||
<Grid Margin="0,5" Visibility="{c:Binding AccountSwitchEnabled}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBox
|
||||
Grid.Column="0"
|
||||
hc:BorderElement.CornerRadius="4,0,0,4"
|
||||
IsReadOnly="{c:Binding !Idle,
|
||||
Source={x:Static helper:Instances.SettingsViewModel}}"
|
||||
Text="{Binding AccountName, UpdateSourceTrigger=PropertyChanged}" />
|
||||
<Button
|
||||
Grid.Column="1"
|
||||
Padding="12,1,12,1"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Bottom"
|
||||
hc:BorderElement.CornerRadius="0,4,4,0"
|
||||
BorderThickness="0,1,1,1"
|
||||
Command="{s:Action AccountSwitchManualRun}"
|
||||
Content="{DynamicResource AccountSwitchManualRun}"
|
||||
IsEnabled="{c:Binding 'AccountName != ""'}" />
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
|
||||
<controls:TextBlock
|
||||
Margin="0,5"
|
||||
|
||||
Reference in New Issue
Block a user