mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-19 02:23:01 +08:00
@@ -80,6 +80,8 @@ namespace MaaWpfGui.Constants
|
||||
public const string AutoRestartOnDrop = "Start.AutoRestartOnDrop";
|
||||
public const string StartsWithScript = "Start.StartsWithScript";
|
||||
public const string EndsWithScript = "Start.EndsWithScript";
|
||||
public const string CopilotWithScript = "Start.CopilotWithScript";
|
||||
public const string ManualStopWithScript = "Start.ManualStopWithScript";
|
||||
public const string BlockSleep = "Start.BlockSleep";
|
||||
public const string BlockSleepWithScreenOn = "Start.BlockSleepWithScreenOn";
|
||||
|
||||
|
||||
@@ -702,6 +702,18 @@ namespace MaaWpfGui.Main
|
||||
isMainTaskQueueAllCompleted = taskList.All(i => !latestMinorTaskIds.Contains(i));
|
||||
}
|
||||
|
||||
if (_latestTaskId.ContainsKey(TaskType.Copilot))
|
||||
{
|
||||
if (Instances.SettingsViewModel.CopilotWithScript)
|
||||
{
|
||||
Task.Run(() => Instances.SettingsViewModel.RunScript("EndsWithScript", showLog: false));
|
||||
if (!string.IsNullOrWhiteSpace(Instances.SettingsViewModel.EndsWithScript))
|
||||
{
|
||||
Instances.CopilotViewModel.AddLog(LocalizationHelper.GetString("EndsWithScript"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool buyWine = _latestTaskId.ContainsKey(TaskType.Mall) && Instances.SettingsViewModel.DidYouBuyWine();
|
||||
_latestTaskId.Clear();
|
||||
|
||||
|
||||
@@ -255,6 +255,8 @@
|
||||
<system:String x:Key="AdditionCommand">附加命令</system:String>
|
||||
<system:String x:Key="StartsWithScript">开始前脚本</system:String>
|
||||
<system:String x:Key="EndsWithScript">结束后脚本</system:String>
|
||||
<system:String x:Key="CopilotWithScript">自动战斗时启用上述脚本</system:String>
|
||||
<system:String x:Key="ManualStopWithScript">手动暂停时启用上述脚本</system:String>
|
||||
<system:String x:Key="BlockSleep">运行任务时阻止休眠</system:String>
|
||||
<system:String x:Key="BlockSleepWithScreenOn">阻止休眠时保持屏幕常亮</system:String>
|
||||
<system:String x:Key="ScreencapCost">截图耗时 min/avg/max(ms): {0:#,#} / {1:#,#} / {2:#,#} ({3})</system:String>
|
||||
|
||||
@@ -997,6 +997,15 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
return;
|
||||
}
|
||||
|
||||
if (Instances.SettingsViewModel.CopilotWithScript)
|
||||
{
|
||||
await Task.Run(() => Instances.SettingsViewModel.RunScript("StartsWithScript", showLog: false));
|
||||
if (!string.IsNullOrWhiteSpace(Instances.SettingsViewModel.StartsWithScript))
|
||||
{
|
||||
AddLog(LocalizationHelper.GetString("StartsWithScript"));
|
||||
}
|
||||
}
|
||||
|
||||
AddLog(LocalizationHelper.GetString("ConnectingToEmulator"));
|
||||
if (!Instances.SettingsViewModel.AdbReplaced && !Instances.SettingsViewModel.IsAdbTouchMode())
|
||||
{
|
||||
@@ -1014,6 +1023,7 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
if (errMsg.Length != 0)
|
||||
{
|
||||
AddLog(errMsg, UiLogColor.Error);
|
||||
Stop();
|
||||
}
|
||||
|
||||
UserAdditional = UserAdditional.Replace(",", ",").Replace(";", ";").Trim();
|
||||
@@ -1079,6 +1089,15 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
// ReSharper disable once UnusedMember.Global
|
||||
public void Stop()
|
||||
{
|
||||
if (Instances.SettingsViewModel.CopilotWithScript && Instances.SettingsViewModel.ManualStopWithScript)
|
||||
{
|
||||
Task.Run(() => Instances.SettingsViewModel.RunScript("EndsWithScript", showLog: false));
|
||||
if (!string.IsNullOrWhiteSpace(Instances.SettingsViewModel.EndsWithScript))
|
||||
{
|
||||
Instances.CopilotViewModel.AddLog(LocalizationHelper.GetString("EndsWithScript"));
|
||||
}
|
||||
}
|
||||
|
||||
if (!Instances.AsstProxy.AsstStop())
|
||||
{
|
||||
_logger.Warning("Failed to stop Asst");
|
||||
|
||||
@@ -771,6 +771,30 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
}
|
||||
}
|
||||
|
||||
private bool _copilotWithScript = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.CopilotWithScript, bool.FalseString));
|
||||
|
||||
public bool CopilotWithScript
|
||||
{
|
||||
get => _copilotWithScript;
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _copilotWithScript, value);
|
||||
ConfigurationHelper.SetValue(ConfigurationKeys.CopilotWithScript, value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private bool _manualStopWithScript = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.ManualStopWithScript, bool.FalseString));
|
||||
|
||||
public bool ManualStopWithScript
|
||||
{
|
||||
get => _manualStopWithScript;
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _manualStopWithScript, value);
|
||||
ConfigurationHelper.SetValue(ConfigurationKeys.ManualStopWithScript, value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private bool _blockSleep = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.BlockSleep, bool.FalseString));
|
||||
|
||||
public bool BlockSleep
|
||||
@@ -803,7 +827,7 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
set => SetAndNotify(ref _screencapCost, value);
|
||||
}
|
||||
|
||||
public void RunScript(string str)
|
||||
public void RunScript(string str, bool showLog = true)
|
||||
{
|
||||
bool enable = str switch
|
||||
{
|
||||
@@ -824,8 +848,18 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
_ => () => false,
|
||||
};
|
||||
|
||||
if (!showLog)
|
||||
{
|
||||
if (!func())
|
||||
{
|
||||
_logger.Warning("Failed to execute the script.");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Execute.OnUIThread(() => Instances.TaskQueueViewModel.AddLog(
|
||||
LocalizationHelper.GetString("StartTask") + LocalizationHelper.GetString(str)));
|
||||
LocalizationHelper.GetString("StartTask") + LocalizationHelper.GetString(str)));
|
||||
if (func())
|
||||
{
|
||||
Execute.OnUIThread(() => Instances.TaskQueueViewModel.AddLog(
|
||||
|
||||
@@ -1076,6 +1076,10 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
public void SetStopped()
|
||||
{
|
||||
SleepManagement.AllowSleep();
|
||||
if (Instances.SettingsViewModel.ManualStopWithScript)
|
||||
{
|
||||
Task.Run(() => Instances.SettingsViewModel.RunScript("EndsWithScript"));
|
||||
}
|
||||
|
||||
if (!_runningState.GetIdle() || Stopping)
|
||||
{
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel
|
||||
Grid.Row="0"
|
||||
@@ -266,11 +267,30 @@
|
||||
Drop="EndsWithScript_Drop"
|
||||
PreviewDragOver="TextBox_PreviewDragOver"
|
||||
Text="{Binding EndsWithScript}" />
|
||||
<StackPanel
|
||||
<WrapPanel
|
||||
Grid.Row="9"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="2"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center">
|
||||
<CheckBox
|
||||
Margin="10"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Content="{DynamicResource CopilotWithScript}"
|
||||
IsChecked="{Binding CopilotWithScript}" />
|
||||
<CheckBox
|
||||
Margin="10"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Content="{DynamicResource ManualStopWithScript}"
|
||||
IsChecked="{Binding ManualStopWithScript}" />
|
||||
</WrapPanel>
|
||||
<StackPanel
|
||||
Grid.Row="10"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="2"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Orientation="Horizontal">
|
||||
<CheckBox
|
||||
@@ -287,7 +307,7 @@
|
||||
Visibility="{c:Binding BlockSleep}" />
|
||||
</StackPanel>
|
||||
<controls:TextBlock
|
||||
Grid.Row="10"
|
||||
Grid.Row="11"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="2"
|
||||
HorizontalAlignment="Center"
|
||||
|
||||
Reference in New Issue
Block a user