Compare commits
23
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7fbde10cc0 | ||
|
|
2562567715 | ||
|
|
5e6e18ca96 | ||
|
|
a4db8b4a90 | ||
|
|
43bbb409f8 | ||
|
|
29cbdd7ab2 | ||
|
|
1845475018 | ||
|
|
54e9a01a9d | ||
|
|
cc3d8fc2ef | ||
|
|
b1efd2d3f7 | ||
|
|
833638a758 | ||
|
|
99f4f1da20 | ||
|
|
368fc6eca6 | ||
|
|
bea9164c2b | ||
|
|
236c725710 | ||
|
|
3012b6de46 | ||
|
|
112f49c7d8 | ||
|
|
6d1f3d832e | ||
|
|
3a754632f8 | ||
|
|
0ee13aded4 | ||
|
|
e4e6953949 | ||
|
|
468a54e037 | ||
|
|
bb0709229f |
No files matched your search
@@ -11,7 +11,9 @@
|
||||
<ui:ControlsDictionary />
|
||||
<vio:ControlsDictionary />
|
||||
<ResourceDictionary Source="/View/Controls/WpfUi/FaFontIconStyle.xaml" />
|
||||
<ResourceDictionary Source="/View/Controls/Drawer/DrawerStyles.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<FontFamily x:Key="TextThemeFontFamily">/Assets/Fonts/MiSans-Regular.ttf#MiSans</FontFamily>
|
||||
<FontFamily x:Key="DigitalThemeFontFamily">/Assets/Fonts/deluge-led.ttf#Deluge LED</FontFamily>
|
||||
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<AssemblyName>BetterGI</AssemblyName>
|
||||
<Version>0.45.2-alpha.1</Version>
|
||||
<Version>0.45.3-alpha.1</Version>
|
||||
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
|
||||
@@ -48,6 +48,7 @@
|
||||
<PackageReference Include="DeviceId.Windows" Version="6.9.0" />
|
||||
<PackageReference Include="DeviceId.Windows.Wmi" Version="6.9.0" />
|
||||
<PackageReference Include="Emoji.Wpf" Version="0.3.4" />
|
||||
<PackageReference Include="LibGit2Sharp" Version="0.31.0" />
|
||||
<PackageReference Include="Meziantou.Framework.Win32.CredentialManager" Version="1.7.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.4" />
|
||||
|
||||
@@ -74,7 +74,13 @@ public partial class AllConfig : ObservableObject
|
||||
|
||||
[ObservableProperty]
|
||||
private List<ValueTuple<string, int, string, string>> _nextScheduledTask = [];
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 连续执行任务时,从此任务开始执行
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public string NextScriptGroupName { get; set; }= string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 一条龙选中使用的配置
|
||||
/// </summary>
|
||||
|
||||
@@ -111,12 +111,12 @@ public partial class OneDragonFlowConfig : ObservableObject
|
||||
[ObservableProperty]
|
||||
private string _completionAction = string.Empty;
|
||||
|
||||
// 通过当天是哪一天来返回配置
|
||||
// 通过当天(4点起始)是哪一天来返回配置
|
||||
public (string partyName, string domainName, string sundaySelectedValue) GetDomainConfig()
|
||||
{
|
||||
if (WeeklyDomainEnabled)
|
||||
{
|
||||
var dayOfWeek = DateTime.Now.DayOfWeek;
|
||||
var dayOfWeek = (DateTime.Now.Hour >= 4 ? DateTime.Today : DateTime.Today.AddDays(-1)).DayOfWeek;
|
||||
return dayOfWeek switch
|
||||
{
|
||||
DayOfWeek.Monday => (MondayPartyName, MondayDomainName,SundaySelectedValue),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.DirectoryServices.ActiveDirectory;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Config;
|
||||
@@ -13,7 +14,25 @@ public partial class OtherConfig : ObservableObject
|
||||
//自动领取派遣任务城市
|
||||
[ObservableProperty]
|
||||
private string _autoFetchDispatchAdventurersGuildCountry = "无";
|
||||
[ObservableProperty]
|
||||
private AutoRestart _autoRestartConfig = new();
|
||||
public partial class AutoRestart : ObservableObject
|
||||
{
|
||||
[ObservableProperty]
|
||||
private bool _enabled = false;
|
||||
|
||||
//调度器任务连续异常退出几次任务自动重启
|
||||
[ObservableProperty]
|
||||
private int _failureCount = 5;
|
||||
|
||||
//是否同时重启游戏,需开启首页启动配置:同时启动原神、自动进入游戏,此配置才会生效
|
||||
[ObservableProperty]
|
||||
private bool _restartGameTogether = false;
|
||||
|
||||
}
|
||||
|
||||
//public partial class OtherConfig : ObservableObject
|
||||
|
||||
/// <summary>
|
||||
/// 游戏语言名称
|
||||
/// </summary>
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using BetterGenshinImpact.Service;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Text.Json;
|
||||
|
||||
using BetterGenshinImpact.Service;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Newtonsoft.Json;
|
||||
using JsonSerializer = System.Text.Json.JsonSerializer;
|
||||
namespace BetterGenshinImpact.Core.Script.Group;
|
||||
|
||||
/// <summary>
|
||||
@@ -24,6 +23,14 @@ public partial class ScriptGroup : ObservableObject
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<ScriptGroupProject> _projects = [];
|
||||
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public bool NextFlag
|
||||
{
|
||||
get => _nextFlag;
|
||||
set => SetProperty(ref _nextFlag, value);
|
||||
}
|
||||
private bool _nextFlag;
|
||||
|
||||
public ScriptGroup()
|
||||
{
|
||||
Projects.CollectionChanged += ProjectsCollectionChanged;
|
||||
@@ -41,7 +48,7 @@ public partial class ScriptGroup : ObservableObject
|
||||
|
||||
public static ScriptGroup FromJson(string json)
|
||||
{
|
||||
var group = Newtonsoft.Json.JsonConvert.DeserializeObject<ScriptGroup>(json) ?? throw new Exception("解析配置组JSON配置失败");
|
||||
var group = JsonConvert.DeserializeObject<ScriptGroup>(json) ?? throw new Exception("解析配置组JSON配置失败");
|
||||
ResetGroupInfo(group);
|
||||
return group;
|
||||
}
|
||||
|
||||
@@ -72,12 +72,29 @@ public partial class ScriptGroupProject : ObservableObject
|
||||
[JsonIgnore]
|
||||
public ScriptGroup? GroupInfo { get; set; }
|
||||
|
||||
private bool? _nextFlag = false;
|
||||
private bool? _skipFlag = false;
|
||||
|
||||
/// <summary>
|
||||
/// 下一个从此执行标志
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
[ObservableProperty]
|
||||
public bool? _nextFlag = false;
|
||||
public bool? NextFlag
|
||||
{
|
||||
get => _nextFlag;
|
||||
set => SetProperty(ref _nextFlag, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 直接跳过标志
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public bool? SkipFlag
|
||||
{
|
||||
get => _skipFlag;
|
||||
set => SetProperty(ref _skipFlag, value);
|
||||
}
|
||||
|
||||
|
||||
[ObservableProperty]
|
||||
private bool? _allowJsNotification = true;
|
||||
|
||||
@@ -17,6 +17,8 @@ using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using BetterGenshinImpact.View.Windows;
|
||||
using LibGit2Sharp;
|
||||
using Vanara.PInvoke;
|
||||
using Wpf.Ui.Violeta.Controls;
|
||||
|
||||
@@ -34,15 +36,15 @@ public class ScriptRepoUpdater : Singleton<ScriptRepoUpdater>
|
||||
// 仓储临时目录 用于下载与解压
|
||||
public static readonly string ReposTempPath = Path.Combine(ReposPath, "Temp");
|
||||
|
||||
// 中央仓库信息地址
|
||||
public static readonly List<string> CenterRepoInfoUrls =
|
||||
[
|
||||
"https://raw.githubusercontent.com/babalae/bettergi-scripts-list/refs/heads/main/repo.json",
|
||||
"https://r2-script.bettergi.com/github_mirror/repo.json",
|
||||
];
|
||||
// // 中央仓库信息地址
|
||||
// public static readonly List<string> CenterRepoInfoUrls =
|
||||
// [
|
||||
// "https://raw.githubusercontent.com/babalae/bettergi-scripts-list/refs/heads/main/repo.json",
|
||||
// "https://r2-script.bettergi.com/github_mirror/repo.json",
|
||||
// ];
|
||||
|
||||
// 中央仓库解压后文件夹名
|
||||
public static readonly string CenterRepoUnzipName = "bettergi-scripts-list-main";
|
||||
public static readonly string CenterRepoUnzipName = "bettergi-scripts-list-git";
|
||||
|
||||
public static readonly string CenterRepoPath = Path.Combine(ReposPath, CenterRepoUnzipName);
|
||||
|
||||
@@ -56,103 +58,211 @@ public class ScriptRepoUpdater : Singleton<ScriptRepoUpdater>
|
||||
|
||||
private WebpageWindow? _webWindow;
|
||||
|
||||
public void AutoUpdate()
|
||||
// [Obsolete]
|
||||
// public void AutoUpdate()
|
||||
// {
|
||||
// var scriptConfig = TaskContext.Instance().Config.ScriptConfig;
|
||||
//
|
||||
// if (!Directory.Exists(ReposPath))
|
||||
// {
|
||||
// Directory.CreateDirectory(ReposPath);
|
||||
// }
|
||||
//
|
||||
// // 判断更新周期是否到达
|
||||
// if (DateTime.Now - scriptConfig.LastUpdateScriptRepoTime >=
|
||||
// TimeSpan.FromDays(scriptConfig.AutoUpdateScriptRepoPeriod))
|
||||
// {
|
||||
// // 更新仓库
|
||||
// Task.Run(async () =>
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// var (repoPath, updated) = await UpdateCenterRepo();
|
||||
// Debug.WriteLine($"脚本仓库更新完成,路径:{repoPath}");
|
||||
// scriptConfig.LastUpdateScriptRepoTime = DateTime.Now;
|
||||
// if (updated)
|
||||
// {
|
||||
// scriptConfig.ScriptRepoHintDotVisible = true;
|
||||
// }
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// _logger.LogDebug(e, $"脚本仓库更新失败:{e.Message}");
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
public async Task<(string, bool)> UpdateCenterRepoByGit(string repoUrl)
|
||||
{
|
||||
var scriptConfig = TaskContext.Instance().Config.ScriptConfig;
|
||||
|
||||
if (!Directory.Exists(ReposPath))
|
||||
if (string.IsNullOrEmpty(repoUrl))
|
||||
{
|
||||
Directory.CreateDirectory(ReposPath);
|
||||
throw new ArgumentException("仓库URL不能为空", nameof(repoUrl));
|
||||
}
|
||||
|
||||
// 判断更新周期是否到达
|
||||
if (DateTime.Now - scriptConfig.LastUpdateScriptRepoTime >= TimeSpan.FromDays(scriptConfig.AutoUpdateScriptRepoPeriod))
|
||||
{
|
||||
// 更新仓库
|
||||
Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var (repoPath, updated) = await UpdateCenterRepo();
|
||||
Debug.WriteLine($"脚本仓库更新完成,路径:{repoPath}");
|
||||
scriptConfig.LastUpdateScriptRepoTime = DateTime.Now;
|
||||
if (updated)
|
||||
{
|
||||
scriptConfig.ScriptRepoHintDotVisible = true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogDebug(e, $"脚本仓库更新失败:{e.Message}");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<(string, bool)> UpdateCenterRepo()
|
||||
{
|
||||
// 测速并获取信息
|
||||
var (fastUrl, jsonString) = await ProxySpeedTester.GetFastestUrlAsync(CenterRepoInfoUrls);
|
||||
if (string.IsNullOrEmpty(jsonString))
|
||||
{
|
||||
throw new Exception("从互联网下载最新的仓库信息失败");
|
||||
}
|
||||
|
||||
var (time, url, file) = ParseJson(jsonString);
|
||||
|
||||
var repoPath = Path.Combine(ReposPath, "bettergi-scripts-list-git");
|
||||
var updated = false;
|
||||
|
||||
// 检查仓库是否存在,不存在则下载
|
||||
var needDownload = false;
|
||||
if (Directory.Exists(CenterRepoPath))
|
||||
await Task.Run(() =>
|
||||
{
|
||||
var p = Directory.GetFiles(CenterRepoPath, "repo.json", SearchOption.AllDirectories).FirstOrDefault();
|
||||
if (p is null)
|
||||
try
|
||||
{
|
||||
needDownload = true;
|
||||
if (!Directory.Exists(repoPath))
|
||||
{
|
||||
// 如果仓库不存在,执行浅克隆操作
|
||||
_logger.LogInformation($"浅克隆仓库: {repoUrl} 到 {repoPath}");
|
||||
|
||||
// 使用浅克隆选项
|
||||
var options = new CloneOptions
|
||||
{
|
||||
Checkout = true,
|
||||
IsBare = false,
|
||||
RecurseSubmodules = false, // 不递归克隆子模块
|
||||
};
|
||||
options.FetchOptions.Depth = 1; // 浅克隆,只获取最新的提交
|
||||
// 克隆仓库
|
||||
Repository.Clone(repoUrl, repoPath, options);
|
||||
updated = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 仓库已经存在,执行拉取更新
|
||||
using var repo = new Repository(repoPath);
|
||||
|
||||
// 检查远程URL是否需要更新
|
||||
var origin = repo.Network.Remotes["origin"];
|
||||
if (origin.Url != repoUrl)
|
||||
{
|
||||
// 远程URL已更改,需要更新
|
||||
_logger.LogInformation($"更新远程URL: 从 {origin.Url} 到 {repoUrl}");
|
||||
repo.Network.Remotes.Update("origin", r => r.Url = repoUrl);
|
||||
}
|
||||
|
||||
// 获取远程分支信息
|
||||
var remote = repo.Network.Remotes["origin"];
|
||||
var refSpecs = remote.FetchRefSpecs.Select(x => x.Specification);
|
||||
|
||||
// 使用浅拉取选项
|
||||
// var fetchOptions = new FetchOptions
|
||||
// {
|
||||
// Depth = 1 // 浅拉取,只获取最新的提交
|
||||
// };
|
||||
|
||||
Commands.Fetch(repo, remote.Name, refSpecs, null, "拉取最新更新");
|
||||
|
||||
// 获取当前分支
|
||||
var branch = repo.Branches["main"] ?? repo.Branches["master"];
|
||||
if (branch == null)
|
||||
{
|
||||
throw new Exception("未找到main或master分支");
|
||||
}
|
||||
|
||||
// 如果是本地分支,需要设置上游分支
|
||||
if (!branch.IsRemote)
|
||||
{
|
||||
var trackingBranch = repo.Branches[$"origin/{branch.FriendlyName}"];
|
||||
if (trackingBranch != null && branch.TrackedBranch == null)
|
||||
{
|
||||
branch = repo.Branches.Update(branch,
|
||||
b => b.TrackedBranch = trackingBranch.CanonicalName);
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否有更新
|
||||
var currentCommitSha = repo.Head.Tip.Sha;
|
||||
|
||||
// 合并或重置到最新
|
||||
if (branch.TrackedBranch != null)
|
||||
{
|
||||
var trackingBranch = branch.TrackedBranch;
|
||||
var mergeResult = Commands.Pull(
|
||||
repo,
|
||||
new Signature("BetterGI", "[email protected]", DateTimeOffset.Now),
|
||||
new PullOptions());
|
||||
|
||||
// 检查是否有更新
|
||||
updated = currentCommitSha != repo.Head.Tip.Sha;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
needDownload = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Git仓库更新失败");
|
||||
throw;
|
||||
}
|
||||
});
|
||||
|
||||
if (needDownload)
|
||||
{
|
||||
await DownloadRepoAndUnzip(url);
|
||||
updated = true;
|
||||
}
|
||||
|
||||
// 搜索本地的 repo.json
|
||||
var localRepoJsonPath = Directory.GetFiles(CenterRepoPath, file, SearchOption.AllDirectories).FirstOrDefault();
|
||||
if (localRepoJsonPath is null)
|
||||
{
|
||||
throw new Exception("本地仓库缺少 repo.json");
|
||||
}
|
||||
|
||||
var (time2, url2, file2) = ParseJson(await File.ReadAllTextAsync(localRepoJsonPath));
|
||||
|
||||
// 检查是否需要更新
|
||||
if (long.Parse(time) > long.Parse(time2))
|
||||
{
|
||||
await DownloadRepoAndUnzip(url2);
|
||||
updated = true;
|
||||
}
|
||||
|
||||
// 获取与 localRepoJsonPath 同名(无扩展名)的文件夹路径
|
||||
var folderName = Path.GetFileNameWithoutExtension(localRepoJsonPath);
|
||||
var folderPath = Path.Combine(Path.GetDirectoryName(localRepoJsonPath)!, folderName);
|
||||
if (!Directory.Exists(folderPath))
|
||||
{
|
||||
throw new Exception("本地仓库文件夹不存在");
|
||||
}
|
||||
|
||||
return (folderPath, updated);
|
||||
return (repoPath, updated);
|
||||
}
|
||||
|
||||
|
||||
// [Obsolete]
|
||||
// public async Task<(string, bool)> UpdateCenterRepo()
|
||||
// {
|
||||
// // 测速并获取信息
|
||||
// var (fastUrl, jsonString) = await ProxySpeedTester.GetFastestUrlAsync(CenterRepoInfoUrls);
|
||||
// if (string.IsNullOrEmpty(jsonString))
|
||||
// {
|
||||
// throw new Exception("从互联网下载最新的仓库信息失败");
|
||||
// }
|
||||
//
|
||||
// var (time, url, file) = ParseJson(jsonString);
|
||||
//
|
||||
// var updated = false;
|
||||
//
|
||||
// // 检查仓库是否存在,不存在则下载
|
||||
// var needDownload = false;
|
||||
// if (Directory.Exists(CenterRepoPath))
|
||||
// {
|
||||
// var p = Directory.GetFiles(CenterRepoPath, "repo.json", SearchOption.AllDirectories).FirstOrDefault();
|
||||
// if (p is null)
|
||||
// {
|
||||
// needDownload = true;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// needDownload = true;
|
||||
// }
|
||||
//
|
||||
// if (needDownload)
|
||||
// {
|
||||
// await DownloadRepoAndUnzip(url);
|
||||
// updated = true;
|
||||
// }
|
||||
//
|
||||
// // 搜索本地的 repo.json
|
||||
// var localRepoJsonPath = Directory.GetFiles(CenterRepoPath, file, SearchOption.AllDirectories).FirstOrDefault();
|
||||
// if (localRepoJsonPath is null)
|
||||
// {
|
||||
// throw new Exception("本地仓库缺少 repo.json");
|
||||
// }
|
||||
//
|
||||
// var (time2, url2, file2) = ParseJson(await File.ReadAllTextAsync(localRepoJsonPath));
|
||||
//
|
||||
// // 检查是否需要更新
|
||||
// if (long.Parse(time) > long.Parse(time2))
|
||||
// {
|
||||
// await DownloadRepoAndUnzip(url2);
|
||||
// updated = true;
|
||||
// }
|
||||
//
|
||||
// // 获取与 localRepoJsonPath 同名(无扩展名)的文件夹路径
|
||||
// var folderName = Path.GetFileNameWithoutExtension(localRepoJsonPath);
|
||||
// var folderPath = Path.Combine(Path.GetDirectoryName(localRepoJsonPath)!, folderName);
|
||||
// if (!Directory.Exists(folderPath))
|
||||
// {
|
||||
// throw new Exception("本地仓库文件夹不存在");
|
||||
// }
|
||||
//
|
||||
// return (folderPath, updated);
|
||||
// }
|
||||
|
||||
public string FindCenterRepoPath()
|
||||
{
|
||||
var localRepoJsonPath = Directory.GetFiles(CenterRepoPath, "repo.json", SearchOption.AllDirectories).FirstOrDefault();
|
||||
var localRepoJsonPath = Directory.GetFiles(CenterRepoPath, "repo.json", SearchOption.AllDirectories)
|
||||
.FirstOrDefault();
|
||||
if (localRepoJsonPath is null)
|
||||
{
|
||||
throw new Exception("本地仓库缺少 repo.json");
|
||||
@@ -197,7 +307,9 @@ public class ScriptRepoUpdater : Singleton<ScriptRepoUpdater>
|
||||
|
||||
// 获取文件名
|
||||
var contentDisposition = res.Content.Headers.ContentDisposition;
|
||||
var fileName = contentDisposition is { FileName: not null } ? contentDisposition.FileName.Trim('"') : "temp.zip";
|
||||
var fileName = contentDisposition is { FileName: not null }
|
||||
? contentDisposition.FileName.Trim('"')
|
||||
: "temp.zip";
|
||||
|
||||
// 创建临时目录
|
||||
if (!Directory.Exists(ReposTempPath))
|
||||
@@ -250,7 +362,8 @@ public class ScriptRepoUpdater : Singleton<ScriptRepoUpdater>
|
||||
var uiMessageBox = new Wpf.Ui.Controls.MessageBox
|
||||
{
|
||||
Title = "脚本订阅",
|
||||
Content = $"检测到{(formClipboard ? "剪切板上存在" : "")}脚本订阅链接,解析后需要导入的脚本为:{pathJson}。\n是否导入并覆盖此文件或者文件夹下的脚本?",
|
||||
Content =
|
||||
$"检测到{(formClipboard ? "剪切板上存在" : "")}脚本订阅链接,解析后需要导入的脚本为:{pathJson}。\n是否导入并覆盖此文件或者文件夹下的脚本?",
|
||||
CloseButtonText = "关闭",
|
||||
PrimaryButtonText = "确认导入",
|
||||
Owner = Application.Current.MainWindow,
|
||||
@@ -322,28 +435,13 @@ public class ScriptRepoUpdater : Singleton<ScriptRepoUpdater>
|
||||
scriptConfig.SubscribedScriptPaths.AddRange(paths);
|
||||
|
||||
Toast.Information("获取最新仓库信息中...");
|
||||
|
||||
// 更新仓库
|
||||
|
||||
string repoPath;
|
||||
try
|
||||
{
|
||||
(repoPath, _) = await Task.Run(UpdateCenterRepo);
|
||||
repoPath = FindCenterRepoPath();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Toast.Warning("获取最新仓库信息失败,尝试使用本地已有仓库信息");
|
||||
try
|
||||
{
|
||||
repoPath = FindCenterRepoPath();
|
||||
}
|
||||
catch
|
||||
{
|
||||
await MessageBox.ErrorAsync("本地无仓库信息,请至少成功更新一次脚本仓库信息!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(repoPath))
|
||||
catch
|
||||
{
|
||||
await MessageBox.ErrorAsync("本地无仓库信息,请至少成功更新一次脚本仓库信息!");
|
||||
return;
|
||||
@@ -474,10 +572,13 @@ public class ScriptRepoUpdater : Singleton<ScriptRepoUpdater>
|
||||
}
|
||||
|
||||
// 使用路径分隔符分割路径
|
||||
string[] parts = path.Split(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] parts = path.Split(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar },
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
// 返回第一个文件夹和剩余路径
|
||||
return parts.Length > 0 ? (parts[0], string.Join(Path.DirectorySeparatorChar, parts.Skip(1))) : (string.Empty, string.Empty);
|
||||
return parts.Length > 0
|
||||
? (parts[0], string.Join(Path.DirectorySeparatorChar, parts.Skip(1)))
|
||||
: (string.Empty, string.Empty);
|
||||
}
|
||||
|
||||
public void OpenLocalRepoInWebView()
|
||||
@@ -493,7 +594,8 @@ public class ScriptRepoUpdater : Singleton<ScriptRepoUpdater>
|
||||
_webWindow.Closed += (s, e) => _webWindow = null;
|
||||
_webWindow.Panel!.DownloadFolderPath = MapPathingViewModel.PathJsonPath;
|
||||
_webWindow.NavigateToFile(Global.Absolute(@"Assets\Web\ScriptRepo\index.html"));
|
||||
_webWindow.Panel!.OnWebViewInitializedAction = () => _webWindow.Panel!.WebView.CoreWebView2.AddHostObjectToScript("repoWebBridge", new RepoWebBridge());
|
||||
_webWindow.Panel!.OnWebViewInitializedAction = () =>
|
||||
_webWindow.Panel!.WebView.CoreWebView2.AddHostObjectToScript("repoWebBridge", new RepoWebBridge());
|
||||
_webWindow.Show();
|
||||
}
|
||||
else
|
||||
@@ -502,6 +604,12 @@ public class ScriptRepoUpdater : Singleton<ScriptRepoUpdater>
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenScriptRepoWindow()
|
||||
{
|
||||
var scriptRepoWindow = new ScriptRepoWindow { Owner = Application.Current.MainWindow };
|
||||
scriptRepoWindow.ShowDialog();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理带有 icon.ico 和 desktop.ini 的文件夹
|
||||
/// </summary>
|
||||
|
||||
@@ -20,15 +20,6 @@ public class RepoWebBridge
|
||||
{
|
||||
public async Task<string> GetRepoJson()
|
||||
{
|
||||
try
|
||||
{
|
||||
await ScriptRepoUpdater.Instance.UpdateCenterRepo();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Toast.Warning($"更新仓库信息失败:{e.Message}");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists(ScriptRepoUpdater.CenterRepoPath))
|
||||
|
||||
@@ -280,7 +280,7 @@ public class AutoDomainTask : ISoloTask
|
||||
else if ("塞西莉亚苗圃".Equals(_taskParam.DomainName))
|
||||
{
|
||||
Simulation.SendInput.SimulateAction(GIActions.MoveForward, KeyType.KeyDown);
|
||||
Thread.Sleep(2300);
|
||||
Thread.Sleep(2500);
|
||||
Simulation.SendInput.SimulateAction(GIActions.MoveForward, KeyType.KeyUp);
|
||||
}
|
||||
else if ("太山府".Equals(_taskParam.DomainName))
|
||||
|
||||
@@ -12,6 +12,11 @@ public class AvatarMacro
|
||||
public string ScriptContent4 { get; set; } = string.Empty;
|
||||
public string ScriptContent5 { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 角色当前使用的战斗宏编号 (1-5),如果为0则使用默认宏1
|
||||
/// </summary>
|
||||
public int MacroPriority { get; set; } = 0;
|
||||
|
||||
public string GetScriptContent(int index)
|
||||
{
|
||||
return index switch
|
||||
@@ -25,9 +30,34 @@ public class AvatarMacro
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 验证宏优先级是否有效
|
||||
/// </summary>
|
||||
/// <returns>如果优先级有效返回true,否则返回false</returns>
|
||||
public bool IsValidMacroPriority()
|
||||
{
|
||||
return MacroPriority >= 0 && MacroPriority <= 5;
|
||||
}
|
||||
|
||||
public string GetScriptContent()
|
||||
{
|
||||
return GetScriptContent(TaskContext.Instance().Config.MacroConfig.CombatMacroPriority);
|
||||
// 验证宏优先级的有效性
|
||||
if (!IsValidMacroPriority())
|
||||
{
|
||||
MacroPriority = 0; // 重置为默认值
|
||||
}
|
||||
|
||||
// 如果角色设置了自己的宏优先级,使用角色的;否则使用全局配置
|
||||
var priority = MacroPriority > 0 ? MacroPriority :
|
||||
TaskContext.Instance().Config.MacroConfig.CombatMacroPriority;
|
||||
|
||||
// 确保最终优先级在有效范围内
|
||||
if (priority < 1 || priority > 5)
|
||||
{
|
||||
priority = 1; // 默认使用宏1
|
||||
}
|
||||
|
||||
return GetScriptContent(priority);
|
||||
}
|
||||
|
||||
public List<CombatCommand>? LoadCommands()
|
||||
|
||||
@@ -27,7 +27,7 @@ public class OneKeyFightTask : Singleton<OneKeyFightTask>
|
||||
private Task? _fightTask;
|
||||
|
||||
private bool _isKeyDown = false;
|
||||
private int activeMacroPriority = -1;
|
||||
private int _activeMacroPriority = -1;
|
||||
private DateTime _lastUpdateTime = DateTime.MinValue;
|
||||
|
||||
private CombatScenes? _currentCombatScenes;
|
||||
@@ -40,10 +40,10 @@ public class OneKeyFightTask : Singleton<OneKeyFightTask>
|
||||
}
|
||||
|
||||
_isKeyDown = true;
|
||||
if (activeMacroPriority != TaskContext.Instance().Config.MacroConfig.CombatMacroPriority ||
|
||||
if (_activeMacroPriority != TaskContext.Instance().Config.MacroConfig.CombatMacroPriority ||
|
||||
IsAvatarMacrosEdited())
|
||||
{
|
||||
activeMacroPriority = TaskContext.Instance().Config.MacroConfig.CombatMacroPriority;
|
||||
_activeMacroPriority = TaskContext.Instance().Config.MacroConfig.CombatMacroPriority;
|
||||
_avatarMacros = LoadAvatarMacros();
|
||||
Logger.LogInformation("加载一键宏配置完成");
|
||||
}
|
||||
@@ -187,7 +187,7 @@ public class OneKeyFightTask : Singleton<OneKeyFightTask>
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogWarning("→ {Name}配置[{Priority}]为空,请先配置一键宏", activeAvatar.Name, activeMacroPriority);
|
||||
Logger.LogWarning("→ {Name}配置[{Priority}]为空,请先配置一键宏", activeAvatar.Name, _activeMacroPriority);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -684,7 +684,7 @@ public class PathExecutor
|
||||
var screen = CaptureToRectArea();
|
||||
var position = await GetPosition(screen, waypoint);
|
||||
var targetOrientation = Navigation.GetTargetOrientation(waypoint, position);
|
||||
Logger.LogInformation("朝向点,位置({x2},{y2})", $"{waypoint.GameX:F1}", $"{waypoint.GameY:F1}");
|
||||
Logger.LogDebug("朝向点,位置({x2},{y2})", $"{waypoint.GameX:F1}", $"{waypoint.GameY:F1}");
|
||||
await _rotateTask.WaitUntilRotatedTo(targetOrientation, 2);
|
||||
await Delay(500, ct);
|
||||
}
|
||||
@@ -699,7 +699,7 @@ public class PathExecutor
|
||||
var screen = CaptureToRectArea();
|
||||
var (position, additionalTimeInMs) = await GetPositionAndTime(screen, waypoint);
|
||||
var targetOrientation = Navigation.GetTargetOrientation(waypoint, position);
|
||||
Logger.LogInformation("粗略接近途经点,位置({x2},{y2})", $"{waypoint.GameX:F1}", $"{waypoint.GameY:F1}");
|
||||
Logger.LogDebug("粗略接近途经点,位置({x2},{y2})", $"{waypoint.GameX:F1}", $"{waypoint.GameY:F1}");
|
||||
await _rotateTask.WaitUntilRotatedTo(targetOrientation, 5);
|
||||
moveToStartTime = DateTime.UtcNow;
|
||||
var lastPositionRecord = DateTime.UtcNow;
|
||||
@@ -743,7 +743,7 @@ public class PathExecutor
|
||||
Debug.WriteLine($"接近目标点中,距离为{distance}");
|
||||
if (distance < 4)
|
||||
{
|
||||
Logger.LogInformation("到达路径点附近");
|
||||
Logger.LogDebug("到达路径点附近");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -943,7 +943,7 @@ public class PathExecutor
|
||||
ImageRegion screen;
|
||||
Point2f position;
|
||||
int targetOrientation;
|
||||
Logger.LogInformation("精确接近目标点,位置({x2},{y2})", $"{waypoint.GameX:F1}", $"{waypoint.GameY:F1}");
|
||||
Logger.LogDebug("精确接近目标点,位置({x2},{y2})", $"{waypoint.GameX:F1}", $"{waypoint.GameY:F1}");
|
||||
|
||||
var stepsTaken = 0;
|
||||
while (!ct.IsCancellationRequested)
|
||||
@@ -962,7 +962,7 @@ public class PathExecutor
|
||||
position = await GetPosition(screen, waypoint);
|
||||
if (Navigation.GetDistance(waypoint, position) < 2)
|
||||
{
|
||||
Logger.LogInformation("已到达路径点");
|
||||
Logger.LogDebug("已到达路径点");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1189,7 +1189,7 @@ public class PathExecutor
|
||||
preTime = DateTime.Now;
|
||||
}
|
||||
|
||||
//Logger.LogInformation("识别到路径:"+position.X+","+position.Y);
|
||||
//Logger.LogDebug("识别到路径:"+position.X+","+position.Y);
|
||||
return (position,time);
|
||||
}
|
||||
|
||||
|
||||
@@ -527,7 +527,7 @@ public class TpTask(CancellationToken ct)
|
||||
// 非常接近目标点,不再进一步调整
|
||||
if (mouseDistance < _tpConfig.Tolerance)
|
||||
{
|
||||
Logger.LogInformation("移动 {I} 次鼠标后,已经接近目标点,不再移动地图。", iteration + 1);
|
||||
Logger.LogDebug("移动 {I} 次鼠标后,已经接近目标点,不再移动地图。", iteration + 1);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,9 +53,9 @@ public class SwitchPartyTask
|
||||
|
||||
// 考虑加载时间 2s,共检查 2.5s,如果失败则抛出异常
|
||||
|
||||
for (int i = 0; i < 3; i++) // 检查 3 次
|
||||
for (int i = 0; i < 10; i++) // 检查 3 次
|
||||
{
|
||||
await Delay(850, ct);
|
||||
await Delay(600, ct);
|
||||
using var raCheck = CaptureToRectArea();
|
||||
if (Bv.IsInPartyViewUi(raCheck))
|
||||
{
|
||||
@@ -68,11 +68,6 @@ public class SwitchPartyTask
|
||||
{
|
||||
break; // 页面已打开,跳出循环
|
||||
}
|
||||
|
||||
if (attempt < maxAttempts)
|
||||
{
|
||||
Logger.LogWarning("尝试打开队伍配置页面失败,正在重试...");
|
||||
}
|
||||
}
|
||||
|
||||
if (!isOpened)
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BetterGenshinImpact.GameTask.AutoFight.Model;
|
||||
using BetterGenshinImpact.Model;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.GameTask.AutoFight.Model;
|
||||
using BetterGenshinImpact.GameTask.AutoPathing.Suspend;
|
||||
using BetterGenshinImpact.GameTask.Common.Job;
|
||||
using OpenCvSharp;
|
||||
using Wpf.Ui.Controls;
|
||||
using BetterGenshinImpact.Model;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using static BetterGenshinImpact.GameTask.Common.TaskControl;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask;
|
||||
@@ -23,6 +21,8 @@ public class RunnerContext : Singleton<RunnerContext>
|
||||
/// </summary>
|
||||
public bool IsContinuousRunGroup { get; set; }
|
||||
|
||||
public TaskProgress.TaskProgress? taskProgress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 暂停逻辑
|
||||
/// </summary>
|
||||
@@ -112,6 +112,7 @@ public class RunnerContext : Singleton<RunnerContext>
|
||||
isAutoFetchDispatch = false;
|
||||
SuspendableDictionary.Clear();
|
||||
AutoPickTriggerStopCount = 0;
|
||||
taskProgress = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -185,7 +185,25 @@ public class SystemControl
|
||||
|
||||
ActivateWindow(TaskContext.Instance().GameHandle);
|
||||
}
|
||||
public static void RestartApplication(string[] newArgs)
|
||||
{
|
||||
// 获取当前程序路径
|
||||
string exePath = Process.GetCurrentProcess().MainModule.FileName;
|
||||
|
||||
// 构建参数字符串
|
||||
string arguments = string.Join(" ", [..newArgs,"--no-single"]);
|
||||
|
||||
// 启动新进程
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = exePath,
|
||||
Arguments = arguments,
|
||||
UseShellExecute = false
|
||||
});
|
||||
|
||||
// 关闭当前程序
|
||||
Environment.Exit(0);
|
||||
}
|
||||
public static void FocusWindow(nint hWnd)
|
||||
{
|
||||
if (User32.IsWindow(hWnd))
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using BetterGenshinImpact.Service;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.TaskProgress;
|
||||
|
||||
public partial class TaskProgress : ObservableObject
|
||||
{
|
||||
|
||||
[ObservableProperty] private List<string> _scriptGroupNames = new();
|
||||
|
||||
[ObservableProperty] private string? _lastScriptGroupName;
|
||||
[ObservableProperty] private ScriptGroupProjectInfo? _lastSuccessScriptGroupProjectInfo;
|
||||
[ObservableProperty] private string? _currentScriptGroupName;
|
||||
[ObservableProperty] private ScriptGroupProjectInfo? _currentScriptGroupProjectInfo;
|
||||
[ObservableProperty] private string _name = DateTime.Now.ToString("yyyyMMddHHmmss");
|
||||
[ObservableProperty] private DateTime _startTime = DateTime.Now;
|
||||
[ObservableProperty] private DateTime? _endTime = null;
|
||||
[ObservableProperty] private List<ScriptGroupProjectInfo>? _history = new();
|
||||
[ObservableProperty] private bool _loop = false;
|
||||
//记录完成了几圈
|
||||
[ObservableProperty] private int _loopCount = 0;
|
||||
private int _consecutiveFailureCount = 0;
|
||||
|
||||
private Progress? _next;
|
||||
/// <summary>
|
||||
/// 连续失败次数
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public int ConsecutiveFailureCount
|
||||
{
|
||||
get => _consecutiveFailureCount;
|
||||
set => SetProperty(ref _consecutiveFailureCount, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 进度信息,如果next不为空,则从next执行
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public Progress? Next
|
||||
{
|
||||
get => _next;
|
||||
set => SetProperty(ref _next, value);
|
||||
}
|
||||
public partial class Progress : ObservableObject
|
||||
{
|
||||
[ObservableProperty] private string _groupName = string.Empty;
|
||||
[ObservableProperty] private int _index = 0;
|
||||
[ObservableProperty] private string _projectName = string.Empty;
|
||||
[ObservableProperty] private string _folderName = string.Empty;
|
||||
}
|
||||
public partial class ScriptGroupProjectInfo : ObservableObject
|
||||
{
|
||||
[ObservableProperty] private string _groupName = string.Empty;
|
||||
[ObservableProperty] private bool _taskEnd = false;
|
||||
[ObservableProperty] private int _index = 0;
|
||||
[ObservableProperty] private string _name = string.Empty;
|
||||
[ObservableProperty] private string _folderName = string.Empty;
|
||||
[ObservableProperty] private DateTime _startTime = DateTime.Now;
|
||||
[ObservableProperty] private DateTime? _endTime = null;
|
||||
//状态 1 成功 2 失败
|
||||
[ObservableProperty] private int _status = 1;
|
||||
}
|
||||
public string ToJson()
|
||||
{
|
||||
return JsonSerializer.Serialize(this, ConfigService.JsonOptions);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.Core.Script.Group;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace BetterGenshinImpact.GameTask.TaskProgress;
|
||||
|
||||
public class TaskProgressManager
|
||||
{
|
||||
private static readonly string _configDir = Global.Absolute(@"log\task_progress");
|
||||
public static ILogger Logger { get; } = App.GetLogger<TaskProgressManager>();
|
||||
public static void SaveTaskProgress(TaskProgress taskProgress)
|
||||
{
|
||||
// 如果目录不存在,则创建
|
||||
if (!Directory.Exists(_configDir))
|
||||
{
|
||||
Directory.CreateDirectory(_configDir);
|
||||
}
|
||||
|
||||
var file = Path.Combine(_configDir, $"{taskProgress.Name}.json");
|
||||
File.WriteAllText(file, taskProgress.ToJson());
|
||||
}
|
||||
|
||||
public static List<TaskProgress> LoadAllTaskProgress()
|
||||
{
|
||||
// 确保目录存在
|
||||
if (!Directory.Exists(_configDir))
|
||||
{
|
||||
Directory.CreateDirectory(_configDir);
|
||||
}
|
||||
|
||||
var result = new List<TaskProgress>();
|
||||
var now = DateTime.Now;
|
||||
|
||||
// 匹配全数字文件名,形如:20250531081114.json
|
||||
var regex = new Regex(@"^\d{14}\.json$");
|
||||
var fileList = Directory.GetFiles(_configDir, "*.json")
|
||||
.Where(file => regex.IsMatch(Path.GetFileName(file))) // 筛选纯数字 JSON
|
||||
.Select(file => new FileInfo(file))
|
||||
.OrderByDescending(fi => fi.LastWriteTime) // 最后修改时间倒序
|
||||
.ToList();
|
||||
|
||||
foreach (var file in fileList.ToArray())
|
||||
{
|
||||
var fileName = file.Name;
|
||||
|
||||
// 跳过非纯数字文件名
|
||||
// if (!regex.IsMatch(fileName)) continue;
|
||||
|
||||
var lastWrite = file.LastWriteTime;
|
||||
|
||||
// 删除3天前未修改的文件
|
||||
if ((now - lastWrite).TotalDays > 3)
|
||||
{
|
||||
try
|
||||
{
|
||||
file.Delete();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogInformation($"删除文件失败:{file} - {ex.Message}");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var json = File.ReadAllText(file.FullName);
|
||||
var progress = JsonConvert.DeserializeObject<TaskProgress>(json);
|
||||
if (progress != null && progress.EndTime == null)
|
||||
result.Add(progress);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogInformation($"读取文件失败:{file} - {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void GenerNextProjectInfo(
|
||||
TaskProgress taskProgress,
|
||||
List<ScriptGroup> scriptGroups)
|
||||
{
|
||||
var currentGroupIndex = 0;
|
||||
var currentProjectIndex = -1;
|
||||
/*if (taskProgress.LastSuccessScriptGroupProjectInfo == null)
|
||||
return ;*/
|
||||
|
||||
if (taskProgress.LastScriptGroupName!=null)
|
||||
{
|
||||
currentGroupIndex = scriptGroups.FindIndex(g => g.Name == taskProgress.LastScriptGroupName);
|
||||
if (currentGroupIndex == -1)
|
||||
return ;
|
||||
}
|
||||
|
||||
var currentGroup = scriptGroups[currentGroupIndex];
|
||||
var isLastInGroup = false;
|
||||
if (taskProgress.LastSuccessScriptGroupProjectInfo!=null)
|
||||
{
|
||||
|
||||
var currentProjectInfo = taskProgress.LastSuccessScriptGroupProjectInfo;
|
||||
|
||||
currentProjectIndex = currentGroup.Projects.ToList().FindIndex(p =>
|
||||
p.Name == currentProjectInfo.Name &&
|
||||
p.FolderName == currentProjectInfo.FolderName);
|
||||
|
||||
if (currentProjectIndex == -1)
|
||||
return ;
|
||||
|
||||
isLastInGroup = currentProjectIndex == currentGroup.Projects.Count - 1;
|
||||
}
|
||||
|
||||
//bool isIncomplete = currentProjectInfo.EndTime == null;
|
||||
|
||||
if (isLastInGroup)
|
||||
{
|
||||
// 向后查找下一个非空组
|
||||
for (int i = currentGroupIndex + 1; i < scriptGroups.Count; i++)
|
||||
{
|
||||
var group = scriptGroups[i];
|
||||
if (group.Projects != null && group.Projects.Any())
|
||||
{
|
||||
var project = group.Projects.First();
|
||||
|
||||
taskProgress.Next=new TaskProgress.Progress
|
||||
{
|
||||
GroupName = group.Name,
|
||||
Index = 0,
|
||||
ProjectName = project.Name,
|
||||
FolderName = project.FolderName
|
||||
};
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 循环从开头查找直到当前组之前
|
||||
if (taskProgress.Loop)
|
||||
{
|
||||
for (int i = 0; i < currentGroupIndex; i++)
|
||||
{
|
||||
var group = scriptGroups[i];
|
||||
if (group.Projects != null && group.Projects.Any())
|
||||
{
|
||||
var project = group.Projects.First();
|
||||
taskProgress.Next = new TaskProgress.Progress
|
||||
{
|
||||
GroupName = group.Name,
|
||||
Index = 0,
|
||||
ProjectName = project.Name,
|
||||
FolderName = project.FolderName
|
||||
};
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ;
|
||||
}
|
||||
else
|
||||
{
|
||||
//取成功执行的下一个任务
|
||||
currentProjectIndex++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 返回当前项目
|
||||
var currentProject = currentGroup.Projects[currentProjectIndex];
|
||||
taskProgress.Next = new TaskProgress.Progress
|
||||
{
|
||||
GroupName = currentGroup.Name,
|
||||
Index = currentProjectIndex,
|
||||
ProjectName = currentProject.Name,
|
||||
FolderName = currentProject.FolderName
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -158,7 +158,10 @@ internal static class RuntimeExtension
|
||||
|
||||
public static IHostBuilder UseSingleInstance(this IHostBuilder self, string instanceName, Action<bool> callback = null!)
|
||||
{
|
||||
RuntimeHelper.CheckSingleInstance(instanceName, callback);
|
||||
if (!Environment.GetCommandLineArgs().Contains("--no-single"))
|
||||
{
|
||||
RuntimeHelper.CheckSingleInstance(instanceName, callback);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Wpf.Ui;
|
||||
|
||||
namespace BetterGenshinImpact.Service;
|
||||
@@ -49,8 +51,13 @@ public class ApplicationHostService(IServiceProvider serviceProvider) : IHostedS
|
||||
_navigationWindow!.ShowWindow();
|
||||
//
|
||||
var args = Environment.GetCommandLineArgs();
|
||||
|
||||
if (args.Length > 1)
|
||||
{
|
||||
|
||||
//无论如何,先跳到主页,否则在通过参数的任务在执行完之前,不会加载快捷键
|
||||
_ = _navigationWindow.Navigate(typeof(HomePage));
|
||||
|
||||
if (args[1].Contains("startOneDragon"))
|
||||
{
|
||||
|
||||
@@ -70,6 +77,19 @@ public class ApplicationHostService(IServiceProvider serviceProvider) : IHostedS
|
||||
var scheduler = App.GetService<ScriptControlViewModel>();
|
||||
scheduler?.OnStartMultiScriptGroupWithNamesAsync(names);
|
||||
}
|
||||
}else if (args[1].Trim().Equals("--TaskProgress", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
|
||||
// 通过命令行参数启动「调度组」 => 跳转到调度器配置页。
|
||||
_ = _navigationWindow.Navigate(typeof(ScriptControlPage));
|
||||
if (args.Length > 1)
|
||||
{
|
||||
// 获取调度组
|
||||
var names = args.Skip(2).ToArray().Select(x => x.Trim()).ToArray();
|
||||
// 启动调度器
|
||||
var scheduler = App.GetService<ScriptControlViewModel>();
|
||||
scheduler?.OnStartMultiScriptTaskProgressAsync(names);
|
||||
}
|
||||
}
|
||||
else if (args[1].Contains("start"))
|
||||
{
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
using BetterGenshinImpact.Core.Script.Group;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.Core.Script.Group;
|
||||
using BetterGenshinImpact.GameTask.TaskProgress;
|
||||
|
||||
namespace BetterGenshinImpact.Service.Interface;
|
||||
|
||||
public interface IScriptService
|
||||
{
|
||||
Task RunMulti(IEnumerable<ScriptGroupProject> projectList, string? groupName = null);
|
||||
Task RunMulti(IEnumerable<ScriptGroupProject> projectList, string? groupName = null,TaskProgress? taskProgress = null);
|
||||
}
|
||||
@@ -1,23 +1,25 @@
|
||||
using BetterGenshinImpact.Core.Script;
|
||||
using BetterGenshinImpact.Core.Script.Group;
|
||||
using BetterGenshinImpact.Core.Script.Project;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
|
||||
using BetterGenshinImpact.Service.Interface;
|
||||
using BetterGenshinImpact.ViewModel.Pages;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BetterGenshinImpact.Core.Script;
|
||||
using BetterGenshinImpact.Core.Script.Dependence;
|
||||
using BetterGenshinImpact.Core.Script.Group;
|
||||
using BetterGenshinImpact.Core.Script.Project;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using BetterGenshinImpact.GameTask.Common.BgiVision;
|
||||
using BetterGenshinImpact.GameTask.Common.Job;
|
||||
using BetterGenshinImpact.GameTask.TaskProgress;
|
||||
using BetterGenshinImpact.Service.Interface;
|
||||
using BetterGenshinImpact.Service.Notification;
|
||||
using BetterGenshinImpact.Service.Notification.Model.Enum;
|
||||
using BetterGenshinImpact.ViewModel.Pages;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace BetterGenshinImpact.Service;
|
||||
|
||||
@@ -45,6 +47,7 @@ public partial class ScriptService : IScriptService
|
||||
}
|
||||
public bool ShouldSkipTask(ScriptGroupProject project)
|
||||
{
|
||||
|
||||
if (project.GroupInfo is { Config.PathingConfig.Enabled: true } )
|
||||
{
|
||||
if (IsCurrentHourEqual(project.GroupInfo.Config.PathingConfig.SkipDuring))
|
||||
@@ -72,11 +75,18 @@ public partial class ScriptService : IScriptService
|
||||
}
|
||||
return false; // 不跳过
|
||||
}
|
||||
public async Task RunMulti(IEnumerable<ScriptGroupProject> projectList, string? groupName = null)
|
||||
public async Task RunMulti(IEnumerable<ScriptGroupProject> projectList, string? groupName = null,TaskProgress? taskProgress = null)
|
||||
{
|
||||
groupName ??= "默认";
|
||||
|
||||
var list = ReloadScriptProjects(projectList);
|
||||
|
||||
//恢复临时的跳过标志
|
||||
foreach (var scriptGroupProject in projectList)
|
||||
{
|
||||
scriptGroupProject.SkipFlag = false;
|
||||
}
|
||||
|
||||
|
||||
// // 针对JS 脚本,检查是否包含定时器操作
|
||||
// var jsProjects = ExtractJsProjects(list);
|
||||
@@ -107,9 +117,23 @@ public partial class ScriptService : IScriptService
|
||||
.RunThreadAsync(async () =>
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
|
||||
int projectIndex = -1;
|
||||
foreach (var project in list)
|
||||
{
|
||||
projectIndex++;
|
||||
if (taskProgress != null && taskProgress.Next != null)
|
||||
{
|
||||
if (taskProgress.Next.Index>projectIndex)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
taskProgress.Next = null;
|
||||
}
|
||||
|
||||
if (project is {SkipFlag:true})
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (ShouldSkipTask(project))
|
||||
{
|
||||
continue;
|
||||
@@ -134,6 +158,18 @@ public partial class ScriptService : IScriptService
|
||||
fisrt = false;
|
||||
Notify.Event(NotificationEvent.GroupStart).Success($"配置组{groupName}启动");
|
||||
}
|
||||
|
||||
if (taskProgress!=null)
|
||||
{
|
||||
taskProgress.CurrentScriptGroupProjectInfo = new TaskProgress.ScriptGroupProjectInfo
|
||||
{
|
||||
Name = project.Name,
|
||||
FolderName = project.FolderName
|
||||
,Index = projectIndex
|
||||
,GroupName = taskProgress?.CurrentScriptGroupName ?? ""
|
||||
};
|
||||
TaskProgressManager.SaveTaskProgress(taskProgress);
|
||||
}
|
||||
for (var i = 0; i < project.RunNum; i++)
|
||||
{
|
||||
try
|
||||
@@ -145,6 +181,7 @@ public partial class ScriptService : IScriptService
|
||||
|
||||
stopwatch.Reset();
|
||||
stopwatch.Start();
|
||||
|
||||
await ExecuteProject(project);
|
||||
|
||||
//多次执行时及时中断
|
||||
@@ -166,6 +203,10 @@ public partial class ScriptService : IScriptService
|
||||
{
|
||||
_logger.LogDebug(e, "执行脚本时发生异常");
|
||||
_logger.LogError("执行脚本时发生异常: {Msg}", e.Message);
|
||||
if (taskProgress!=null && taskProgress.CurrentScriptGroupProjectInfo!=null )
|
||||
{
|
||||
taskProgress.CurrentScriptGroupProjectInfo.Status = 2;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -179,6 +220,48 @@ public partial class ScriptService : IScriptService
|
||||
|
||||
await Task.Delay(2000);
|
||||
}
|
||||
|
||||
if (taskProgress != null)
|
||||
{
|
||||
if (taskProgress.CurrentScriptGroupProjectInfo!=null )
|
||||
{
|
||||
taskProgress.CurrentScriptGroupProjectInfo.TaskEnd = true;
|
||||
taskProgress.CurrentScriptGroupProjectInfo.EndTime = DateTime.Now;
|
||||
if (taskProgress.CurrentScriptGroupProjectInfo.Status == 1)
|
||||
{
|
||||
taskProgress.ConsecutiveFailureCount = 0;
|
||||
taskProgress.LastSuccessScriptGroupProjectInfo =
|
||||
taskProgress.CurrentScriptGroupProjectInfo;
|
||||
taskProgress.LastScriptGroupName =taskProgress.CurrentScriptGroupName;
|
||||
}
|
||||
//累计连续失败次数
|
||||
if (taskProgress.CurrentScriptGroupProjectInfo.Status == 2)
|
||||
{
|
||||
taskProgress.ConsecutiveFailureCount++;
|
||||
}
|
||||
|
||||
taskProgress?.History?.Add(taskProgress.CurrentScriptGroupProjectInfo);
|
||||
TaskProgressManager.SaveTaskProgress(taskProgress);
|
||||
}
|
||||
|
||||
//异常达到一次次数,重启bgi
|
||||
var autoconfig = TaskContext.Instance().Config.OtherConfig.AutoRestartConfig;
|
||||
if (autoconfig.Enabled && taskProgress.ConsecutiveFailureCount >= autoconfig.FailureCount)
|
||||
{
|
||||
_logger.LogInformation("调度器任务出现未预期的异常,自动重启bgi");
|
||||
Notify.Event(NotificationEvent.GroupEnd).Error("调度器任务出现未预期的异常,自动重启bgi");
|
||||
if (autoconfig.RestartGameTogether
|
||||
&& TaskContext.Instance().Config.GenshinStartConfig.LinkedStartEnabled
|
||||
&& TaskContext.Instance().Config.GenshinStartConfig.AutoEnterGameEnabled)
|
||||
{
|
||||
SystemControl.CloseGame();
|
||||
Thread.Sleep(2000);
|
||||
}
|
||||
|
||||
SystemControl.RestartApplication(["--TaskProgress",taskProgress.Name]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -195,7 +278,11 @@ public partial class ScriptService : IScriptService
|
||||
Notify.Event(NotificationEvent.GroupEnd).Success($"配置组{groupName}结束");
|
||||
}
|
||||
|
||||
|
||||
if (taskProgress != null)
|
||||
{
|
||||
taskProgress.Next = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private List<ScriptGroupProject> ReloadScriptProjects(IEnumerable<ScriptGroupProject> projectList)
|
||||
@@ -242,6 +329,7 @@ public partial class ScriptService : IScriptService
|
||||
target.JsScriptSettingsObject = source.JsScriptSettingsObject;
|
||||
target.GroupInfo = source.GroupInfo;
|
||||
target.AllowJsNotification = source.AllowJsNotification;
|
||||
target.SkipFlag = source.SkipFlag;
|
||||
}
|
||||
|
||||
// private List<ScriptProject> ExtractJsProjects(List<ScriptGroupProject> list)
|
||||
@@ -323,6 +411,8 @@ public partial class ScriptService : IScriptService
|
||||
{
|
||||
await Task.Delay(200);
|
||||
var first = true;
|
||||
var sw = Stopwatch.StartNew();
|
||||
var loseFocusCount = 0;
|
||||
while (true)
|
||||
{
|
||||
if (!homePageViewModel.TaskDispatcherEnabled || !TaskContext.Instance().IsInitialized)
|
||||
@@ -340,10 +430,31 @@ public partial class ScriptService : IScriptService
|
||||
{
|
||||
first = false;
|
||||
TaskControl.Logger.LogInformation("当前不在游戏主界面,等待进入主界面后执行任务...");
|
||||
TaskControl.Logger.LogInformation("如果你已经在游戏内的其他界面,请自行退出当前界面(ESC),使当前任务能够继续运行!");
|
||||
TaskControl.Logger.LogInformation("如果你已经在游戏内的其他界面,请自行退出当前界面(ESC),或是30秒后将程序将自动尝试到入主界面,使当前任务能够继续运行!");
|
||||
}
|
||||
|
||||
await Task.Delay(500);
|
||||
if (sw.Elapsed.TotalSeconds >= 30)
|
||||
{
|
||||
//防止自启动游戏后因为一些原因失焦,导致一直卡住
|
||||
if (!SystemControl.IsGenshinImpactActiveByProcess())
|
||||
{
|
||||
loseFocusCount++;
|
||||
if (loseFocusCount>50 && loseFocusCount<100)
|
||||
{
|
||||
SystemControl.MinimizeAndActivateWindow(TaskContext.Instance().GameHandle);
|
||||
}
|
||||
SystemControl.ActivateWindow();
|
||||
}
|
||||
|
||||
//自启动游戏,如果鼠标在游戏外面,将无法自动开门,这里尝试移动到游戏界面
|
||||
if (sw.Elapsed.TotalSeconds < 200)
|
||||
{
|
||||
GlobalMethod.MoveMouseTo(300, 300);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,389 +1,516 @@
|
||||
[
|
||||
{
|
||||
"name": "荧",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "空",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "神里绫华",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "琴",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "丽莎",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "芭芭拉",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "凯亚",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "迪卢克",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "雷泽",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "安柏",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "温迪",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "香菱",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "北斗",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "行秋",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "魈",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "凝光",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "可莉",
|
||||
"scriptContent1": "keydown(w),wait(0.08),attack(0.05),keyup(w),wait(0.2)",
|
||||
"scriptContent2": "mousedown(left),mouseup(left),wait(0.09),charge(0.519),wait(0.09),charge(0.519),wait(0.09)"
|
||||
"scriptContent2": "mousedown(left),mouseup(left),wait(0.09),charge(0.519),wait(0.09),charge(0.519),wait(0.09)",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "钟离",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "菲谢尔",
|
||||
"scriptContent1": "mousedown(left),wait(0.001),mouseup(left),wait(0.3),mousedown(left),wait(0.001),mouseup(left),wait(0.2),keydown(r),wait(0.02),keyup(r),wait(0.1),keydown(r),wait(0.02),keyup(r),wait(0.04)"
|
||||
"scriptContent1": "mousedown(left),wait(0.001),mouseup(left),wait(0.3),mousedown(left),wait(0.001),mouseup(left),wait(0.2),keydown(r),wait(0.02),keyup(r),wait(0.1),keydown(r),wait(0.02),keyup(r),wait(0.04)",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "班尼特",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "达达利亚",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "诺艾尔",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "七七",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "重云",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "甘雨",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "阿贝多",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "迪奥娜",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "莫娜",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "刻晴",
|
||||
"scriptContent1": "mousedown(left),wait(0.350),mouseup(left),wait(0.100)",
|
||||
"scriptContent2": "keydown(e),wait(0.085),keyup(e),wait(0.667),keydown(q),wait(0.081),keyup(q),wait(2.388),keydown(e),wait(0.085),keyup(e)"
|
||||
"scriptContent2": "keydown(e),wait(0.085),keyup(e),wait(0.667),keydown(q),wait(0.081),keyup(q),wait(2.388),keydown(e),wait(0.085),keyup(e)",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "砂糖",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "辛焱",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "罗莎莉亚",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "胡桃",
|
||||
"scriptContent1": "charge(0.3),wait(0.1),dash,wait(0.1),charge(0.3),wait(0.1),dash,wait(0.1),charge(0.3),wait(0.1),j,wait(0.52)"
|
||||
"scriptContent1": "charge(0.3),wait(0.1),dash,wait(0.1),charge(0.3),wait(0.1),dash,wait(0.1),charge(0.3),wait(0.1),j,wait(0.52)",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "枫原万叶",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "烟绯",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "宵宫",
|
||||
"scriptContent1": "e,wait(0.8),attack(1)",
|
||||
"scriptContent2": "mousedown(left),wait(0.001),mouseup(left),wait(0.218),mousedown(left),wait(0.001),mouseup(left),wait(0.219),mousedown(left),wait(0.25),mouseup(left),wait(0.206)"
|
||||
"scriptContent2": "mousedown(left),wait(0.001),mouseup(left),wait(0.218),mousedown(left),wait(0.001),mouseup(left),wait(0.219),mousedown(left),wait(0.25),mouseup(left),wait(0.206)",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "托马",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "优菈",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "雷电将军",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "早柚",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "珊瑚宫心海",
|
||||
"scriptContent1": "mousedown(left),wait(0.005),mouseup(left),wait(0.005),mousedown(left),wait(0.005),mouseup(left),wait(0.425),keydown(w),wait(0.225),keyup(w),wait(0.05)"
|
||||
"scriptContent1": "mousedown(left),wait(0.005),mouseup(left),wait(0.005),mousedown(left),wait(0.005),mouseup(left),wait(0.425),keydown(w),wait(0.225),keyup(w),wait(0.05)",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "五郎",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "九条裟罗",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "荒泷一斗",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "八重神子",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "鹿野院平藏",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "夜兰",
|
||||
"scriptContent1": "mousedown(left),wait(0.550),mouseup(left)"
|
||||
"scriptContent1": "mousedown(left),wait(0.550),mouseup(left)",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "绮良良",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "埃洛伊",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "申鹤",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "云堇",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "久岐忍",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "神里绫人",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "柯莱",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "多莉",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "提纳里",
|
||||
"scriptContent1": "keydown(r),wait(0.005),keyup(r),wait(0.25),mousedown(left),wait(0.05),mouseup(left),wait(0.8),mousedown(left),wait(0.05),mouseup(left),wait(0.8),mousedown(left),wait(0.05),mouseup(left),wait(0.05),keydown(r),wait(0.005),keyup(r)"
|
||||
"scriptContent1": "keydown(r),wait(0.005),keyup(r),wait(0.25),mousedown(left),wait(0.05),mouseup(left),wait(0.8),mousedown(left),wait(0.05),mouseup(left),wait(0.8),mousedown(left),wait(0.05),mouseup(left),wait(0.05),keydown(r),wait(0.005),keyup(r)",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "妮露",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "赛诺",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "坎蒂丝",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "纳西妲",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "莱依拉",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "流浪者",
|
||||
"scriptContent1": "e,wait(0.3),charge(0.71),wait(0.101),charge(0.69),wait(0.09),charge(0.702),wait(0.101),charge(0.703),wait(0.102),charge(0.698),wait(0.099),charge(0.703),wait(0.098),charge(0.703),wait(0.101),charge(0.704),wait(0.099),charge(0.701),wait(0.101),charge(0.701),wait(0.101),charge(0.702),wait(0.103),charge(0.704),wait(0.103),charge(0.704)"
|
||||
"scriptContent1": "e,wait(0.3),charge(0.71),wait(0.101),charge(0.69),wait(0.09),charge(0.702),wait(0.101),charge(0.703),wait(0.102),charge(0.698),wait(0.099),charge(0.703),wait(0.098),charge(0.703),wait(0.101),charge(0.704),wait(0.099),charge(0.701),wait(0.101),charge(0.701),wait(0.101),charge(0.702),wait(0.103),charge(0.704),wait(0.103),charge(0.704)",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "珐露珊",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "瑶瑶",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "艾尔海森",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "迪希雅",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "米卡",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "卡维",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "白术",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "琳妮特",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "林尼",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "菲米尼",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "莱欧斯利",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "那维莱特",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "夏洛蒂",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "芙宁娜",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "夏沃蕾",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "娜维娅",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "嘉明",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "闲云",
|
||||
"scriptContent1": ""
|
||||
},
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "千织",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "希格雯",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "阿蕾奇诺",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "赛索斯",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "克洛琳德",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "艾梅莉埃",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "卡齐娜",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "基尼奇",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "玛拉妮",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "希诺宁",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "恰斯卡",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "欧洛伦",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "玛薇卡",
|
||||
"scriptContent1": "keydown(space),keyup(space),wait(0.08),keydown(space),keyup(space),wait(0.08),keydown(space),keyup(space),wait(1.3)"
|
||||
"scriptContent1": "keydown(space),keyup(space),wait(0.08),keydown(space),keyup(space),wait(0.08),keydown(space),keyup(space),wait(1.3)",
|
||||
"scriptContent2": "mousedown(left),wait(0.3),mouseup(left),wait(0.6),mousedown(right),wait(0.08),mouseup(right),wait(0.02),mousedown(left),wait(0.15),mouseup(left),wait(0.05)",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "茜特菈莉",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "蓝砚",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "梦见月瑞希",
|
||||
"scriptContent1": ""
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "伊安珊",
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "瓦雷莎",
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "爱可菲",
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "伊法",
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "丝柯克",
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
},
|
||||
{
|
||||
"name": "塔利雅",
|
||||
"scriptContent1": "",
|
||||
"macroPriority": 0
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,410 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Animation;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace BetterGenshinImpact.View.Controls.Drawer;
|
||||
|
||||
public class CustomDrawer : ContentControl
|
||||
{
|
||||
#region 依赖属性
|
||||
|
||||
public static readonly DependencyProperty IsOpenProperty =
|
||||
DependencyProperty.Register(nameof(IsOpen), typeof(bool), typeof(CustomDrawer),
|
||||
new PropertyMetadata(false, OnIsOpenChanged));
|
||||
|
||||
public static readonly DependencyProperty DrawerPositionProperty =
|
||||
DependencyProperty.Register(nameof(DrawerPosition), typeof(DrawerPosition), typeof(CustomDrawer),
|
||||
new PropertyMetadata(DrawerPosition.Right, OnDrawerPositionChanged));
|
||||
|
||||
public static readonly DependencyProperty OpenWidthProperty =
|
||||
DependencyProperty.Register(nameof(OpenWidth), typeof(double), typeof(CustomDrawer),
|
||||
new PropertyMetadata(400.0));
|
||||
|
||||
public static readonly DependencyProperty OpenHeightProperty =
|
||||
DependencyProperty.Register(nameof(OpenHeight), typeof(double), typeof(CustomDrawer),
|
||||
new PropertyMetadata(300.0));
|
||||
|
||||
public static readonly DependencyProperty AnimationDurationProperty =
|
||||
DependencyProperty.Register(nameof(AnimationDuration), typeof(TimeSpan), typeof(CustomDrawer),
|
||||
new PropertyMetadata(TimeSpan.FromMilliseconds(200)));
|
||||
|
||||
public static readonly DependencyProperty BackgroundOpacityProperty =
|
||||
DependencyProperty.Register(nameof(BackgroundOpacity), typeof(double), typeof(CustomDrawer),
|
||||
new PropertyMetadata(0.6));
|
||||
|
||||
public static readonly DependencyProperty DrawerBackgroundProperty =
|
||||
DependencyProperty.Register(nameof(DrawerBackground), typeof(Brush), typeof(CustomDrawer),
|
||||
new PropertyMetadata(Brushes.Black));
|
||||
|
||||
#endregion
|
||||
|
||||
#region 事件
|
||||
|
||||
/// <summary>
|
||||
/// 抽屉打开后触发的事件
|
||||
/// </summary>
|
||||
public event EventHandler Opened;
|
||||
|
||||
/// <summary>
|
||||
/// 抽屉关闭前触发的事件,可以取消关闭操作
|
||||
/// </summary>
|
||||
public event CancelEventHandler Closing;
|
||||
|
||||
/// <summary>
|
||||
/// 引发 Opened 事件
|
||||
/// </summary>
|
||||
protected virtual void OnOpened()
|
||||
{
|
||||
Opened?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 引发 Closing 事件
|
||||
/// </summary>
|
||||
/// <returns>如果取消关闭,则返回 true;否则返回 false</returns>
|
||||
protected virtual bool OnClosing()
|
||||
{
|
||||
if (Closing != null)
|
||||
{
|
||||
CancelEventArgs args = new CancelEventArgs();
|
||||
Closing(this, args);
|
||||
return args.Cancel;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 属性
|
||||
|
||||
public bool IsOpen
|
||||
{
|
||||
get => (bool)GetValue(IsOpenProperty);
|
||||
set => SetValue(IsOpenProperty, value);
|
||||
}
|
||||
|
||||
public DrawerPosition DrawerPosition
|
||||
{
|
||||
get => (DrawerPosition)GetValue(DrawerPositionProperty);
|
||||
set => SetValue(DrawerPositionProperty, value);
|
||||
}
|
||||
|
||||
public double OpenWidth
|
||||
{
|
||||
get => (double)GetValue(OpenWidthProperty);
|
||||
set => SetValue(OpenWidthProperty, value);
|
||||
}
|
||||
|
||||
public double OpenHeight
|
||||
{
|
||||
get => (double)GetValue(OpenHeightProperty);
|
||||
set => SetValue(OpenHeightProperty, value);
|
||||
}
|
||||
|
||||
public TimeSpan AnimationDuration
|
||||
{
|
||||
get => (TimeSpan)GetValue(AnimationDurationProperty);
|
||||
set => SetValue(AnimationDurationProperty, value);
|
||||
}
|
||||
|
||||
public double BackgroundOpacity
|
||||
{
|
||||
get => (double)GetValue(BackgroundOpacityProperty);
|
||||
set => SetValue(BackgroundOpacityProperty, value);
|
||||
}
|
||||
|
||||
public Brush DrawerBackground
|
||||
{
|
||||
get => (Brush)GetValue(DrawerBackgroundProperty);
|
||||
set => SetValue(DrawerBackgroundProperty, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Border _backgroundOverlay;
|
||||
private Border _drawerContainer;
|
||||
private Grid _mainGrid;
|
||||
|
||||
static CustomDrawer()
|
||||
{
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomDrawer),
|
||||
new FrameworkPropertyMetadata(typeof(CustomDrawer)));
|
||||
}
|
||||
|
||||
public CustomDrawer()
|
||||
{
|
||||
this.Loaded += CustomDrawer_Loaded;
|
||||
}
|
||||
|
||||
public override void OnApplyTemplate()
|
||||
{
|
||||
base.OnApplyTemplate();
|
||||
|
||||
_mainGrid = GetTemplateChild("PART_MainGrid") as Grid;
|
||||
_backgroundOverlay = GetTemplateChild("PART_BackgroundOverlay") as Border;
|
||||
_drawerContainer = GetTemplateChild("PART_DrawerContainer") as Border;
|
||||
|
||||
if (_backgroundOverlay != null)
|
||||
{
|
||||
_backgroundOverlay.MouseDown += BackgroundOverlay_MouseDown;
|
||||
}
|
||||
|
||||
UpdateDrawerPosition();
|
||||
UpdateOpenState(false);
|
||||
}
|
||||
|
||||
private void CustomDrawer_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
UpdateOpenState(false);
|
||||
}
|
||||
|
||||
private void BackgroundOverlay_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
||||
{
|
||||
CloseDrawer();
|
||||
}
|
||||
|
||||
private static void OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is CustomDrawer drawer)
|
||||
{
|
||||
bool newValue = (bool)e.NewValue;
|
||||
bool oldValue = (bool)e.OldValue;
|
||||
|
||||
// 如果是从打开到关闭状态,需要触发关闭前事件
|
||||
if (oldValue && !newValue)
|
||||
{
|
||||
bool cancel = drawer.OnClosing();
|
||||
if (cancel)
|
||||
{
|
||||
// 如果取消关闭,则恢复 IsOpen 为 true
|
||||
drawer.IsOpen = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 更新抽屉状态(动画)
|
||||
drawer.UpdateOpenState(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnDrawerPositionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is CustomDrawer drawer)
|
||||
{
|
||||
drawer.UpdateDrawerPosition();
|
||||
drawer.UpdateOpenState(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateDrawerPosition()
|
||||
{
|
||||
if (_drawerContainer == null) return;
|
||||
|
||||
switch (DrawerPosition)
|
||||
{
|
||||
case DrawerPosition.Left:
|
||||
_drawerContainer.HorizontalAlignment = HorizontalAlignment.Left;
|
||||
_drawerContainer.VerticalAlignment = VerticalAlignment.Stretch;
|
||||
_drawerContainer.Width = OpenWidth;
|
||||
_drawerContainer.Height = double.NaN;
|
||||
break;
|
||||
case DrawerPosition.Right:
|
||||
_drawerContainer.HorizontalAlignment = HorizontalAlignment.Right;
|
||||
_drawerContainer.VerticalAlignment = VerticalAlignment.Stretch;
|
||||
_drawerContainer.Width = OpenWidth;
|
||||
_drawerContainer.Height = double.NaN;
|
||||
break;
|
||||
case DrawerPosition.Top:
|
||||
_drawerContainer.HorizontalAlignment = HorizontalAlignment.Stretch;
|
||||
_drawerContainer.VerticalAlignment = VerticalAlignment.Top;
|
||||
_drawerContainer.Width = double.NaN;
|
||||
_drawerContainer.Height = OpenHeight;
|
||||
break;
|
||||
case DrawerPosition.Bottom:
|
||||
_drawerContainer.HorizontalAlignment = HorizontalAlignment.Stretch;
|
||||
_drawerContainer.VerticalAlignment = VerticalAlignment.Bottom;
|
||||
_drawerContainer.Width = double.NaN;
|
||||
_drawerContainer.Height = OpenHeight;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateOpenState(bool animate)
|
||||
{
|
||||
if (_drawerContainer == null || _backgroundOverlay == null) return;
|
||||
|
||||
_backgroundOverlay.IsHitTestVisible = IsOpen;
|
||||
|
||||
_drawerContainer.Opacity = 1;
|
||||
|
||||
if (IsOpen)
|
||||
{
|
||||
Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
// 每次更新状态时重新应用宽高
|
||||
switch (DrawerPosition)
|
||||
{
|
||||
case DrawerPosition.Left:
|
||||
case DrawerPosition.Right:
|
||||
_drawerContainer.Width = OpenWidth;
|
||||
_drawerContainer.Height = double.NaN;
|
||||
break;
|
||||
case DrawerPosition.Top:
|
||||
case DrawerPosition.Bottom:
|
||||
_drawerContainer.Width = double.NaN;
|
||||
_drawerContainer.Height = OpenHeight;
|
||||
break;
|
||||
}
|
||||
|
||||
if (animate)
|
||||
{
|
||||
// 动画背景遮罩
|
||||
DoubleAnimation backgroundAnimation = new DoubleAnimation
|
||||
{
|
||||
To = IsOpen ? BackgroundOpacity : 0,
|
||||
Duration = AnimationDuration
|
||||
};
|
||||
_backgroundOverlay.BeginAnimation(OpacityProperty, backgroundAnimation);
|
||||
|
||||
// 确保RenderTransform已设置
|
||||
if (_drawerContainer.RenderTransform == null || !(_drawerContainer.RenderTransform is TranslateTransform))
|
||||
{
|
||||
_drawerContainer.RenderTransform = new TranslateTransform();
|
||||
}
|
||||
|
||||
TranslateTransform transform = (TranslateTransform)_drawerContainer.RenderTransform;
|
||||
|
||||
// 动画抽屉
|
||||
DoubleAnimation drawerAnimation = new DoubleAnimation
|
||||
{
|
||||
Duration = AnimationDuration,
|
||||
// 弹性动画效果
|
||||
// EasingFunction = IsOpen
|
||||
// ? new BackEase { EasingMode = EasingMode.EaseOut, Amplitude = 0.3 }
|
||||
// : new ExponentialEase { EasingMode = EasingMode.EaseIn, Exponent = 6 }
|
||||
};
|
||||
|
||||
// 如果是打开操作,在动画完成时触发Opened事件
|
||||
if (IsOpen)
|
||||
{
|
||||
drawerAnimation.Completed += (s, e) => OnOpened();
|
||||
}
|
||||
|
||||
switch (DrawerPosition)
|
||||
{
|
||||
case DrawerPosition.Left:
|
||||
// 打开时,先设置初始位置
|
||||
if (IsOpen)
|
||||
{
|
||||
transform.X = -OpenWidth;
|
||||
}
|
||||
|
||||
drawerAnimation.To = IsOpen ? 0 : -OpenWidth;
|
||||
transform.BeginAnimation(TranslateTransform.XProperty, drawerAnimation);
|
||||
break;
|
||||
case DrawerPosition.Right:
|
||||
// 打开时,先设置初始位置
|
||||
if (IsOpen)
|
||||
{
|
||||
transform.X = OpenWidth;
|
||||
}
|
||||
|
||||
drawerAnimation.To = IsOpen ? 0 : OpenWidth;
|
||||
transform.BeginAnimation(TranslateTransform.XProperty, drawerAnimation);
|
||||
break;
|
||||
case DrawerPosition.Top:
|
||||
// 打开时,先设置初始位置
|
||||
if (IsOpen)
|
||||
{
|
||||
transform.Y = -OpenHeight;
|
||||
}
|
||||
|
||||
drawerAnimation.To = IsOpen ? 0 : -OpenHeight;
|
||||
transform.BeginAnimation(TranslateTransform.YProperty, drawerAnimation);
|
||||
break;
|
||||
case DrawerPosition.Bottom:
|
||||
// 打开时,先设置初始位置
|
||||
if (IsOpen)
|
||||
{
|
||||
transform.Y = OpenHeight;
|
||||
}
|
||||
|
||||
drawerAnimation.To = IsOpen ? 0 : OpenHeight;
|
||||
transform.BeginAnimation(TranslateTransform.YProperty, drawerAnimation);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!IsOpen)
|
||||
{
|
||||
drawerAnimation.Completed += (s, e) =>
|
||||
{
|
||||
if (!IsOpen)
|
||||
{
|
||||
Visibility = Visibility.Collapsed;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 无动画直接设置
|
||||
_backgroundOverlay.Opacity = IsOpen ? BackgroundOpacity : 0;
|
||||
|
||||
TranslateTransform transform = new TranslateTransform();
|
||||
_drawerContainer.RenderTransform = transform;
|
||||
|
||||
switch (DrawerPosition)
|
||||
{
|
||||
case DrawerPosition.Left:
|
||||
transform.X = IsOpen ? 0 : -OpenWidth;
|
||||
break;
|
||||
case DrawerPosition.Right:
|
||||
transform.X = IsOpen ? 0 : OpenWidth;
|
||||
break;
|
||||
case DrawerPosition.Top:
|
||||
transform.Y = IsOpen ? 0 : -OpenHeight;
|
||||
break;
|
||||
case DrawerPosition.Bottom:
|
||||
transform.Y = IsOpen ? 0 : OpenHeight;
|
||||
break;
|
||||
}
|
||||
|
||||
Visibility = IsOpen ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
// 如果是无动画模式且正在打开,立即触发Opened事件
|
||||
if (IsOpen)
|
||||
{
|
||||
OnOpened();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭抽屉的方法,会触发 Closing 事件并可能被取消
|
||||
/// </summary>
|
||||
/// <returns>如果成功关闭返回 true,如果被取消返回 false</returns>
|
||||
public bool CloseDrawer()
|
||||
{
|
||||
if (!IsOpen)
|
||||
return true;
|
||||
|
||||
if (OnClosing())
|
||||
return false;
|
||||
|
||||
IsOpen = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public enum DrawerPosition
|
||||
{
|
||||
Left,
|
||||
Right,
|
||||
Top,
|
||||
Bottom
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:drawer="clr-namespace:BetterGenshinImpact.View.Controls.Drawer">
|
||||
|
||||
<Style TargetType="{x:Type drawer:CustomDrawer}">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type drawer:CustomDrawer}">
|
||||
<Grid x:Name="PART_MainGrid">
|
||||
<Border x:Name="PART_BackgroundOverlay"
|
||||
Background="Black"
|
||||
Opacity="0"/>
|
||||
<Border x:Name="PART_DrawerContainer"
|
||||
Background="{TemplateBinding DrawerBackground}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="0"
|
||||
Effect="{DynamicResource ControlElevationBorderShadow}">
|
||||
<ContentPresenter Margin="{TemplateBinding Padding}"/>
|
||||
</Border>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
@@ -0,0 +1,71 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace BetterGenshinImpact.View.Controls.Drawer;
|
||||
|
||||
public partial class DrawerViewModel : ObservableObject
|
||||
{
|
||||
[ObservableProperty]
|
||||
private bool _isDrawerOpen;
|
||||
|
||||
[ObservableProperty]
|
||||
private object? _drawerContent;
|
||||
|
||||
[ObservableProperty]
|
||||
private DrawerPosition _drawerPosition = DrawerPosition.Right;
|
||||
|
||||
[ObservableProperty]
|
||||
private double _drawerWidth = 400;
|
||||
|
||||
[ObservableProperty]
|
||||
private double _drawerHeight = 300;
|
||||
|
||||
[ObservableProperty]
|
||||
private RelayCommand _onDrawerOpenedCommand;
|
||||
|
||||
[ObservableProperty]
|
||||
private RelayCommand<CancelEventArgs> _onDrawerClosingCommand;
|
||||
|
||||
public void setDrawerOpenedAction(Action action)
|
||||
{
|
||||
OnDrawerOpenedCommand = new RelayCommand(action!);
|
||||
}
|
||||
|
||||
public void SetDrawerClosingAction(Action<CancelEventArgs> action)
|
||||
{
|
||||
OnDrawerClosingCommand = new RelayCommand<CancelEventArgs>(action!);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void OpenDrawer(object content)
|
||||
{
|
||||
DrawerContent = content;
|
||||
IsDrawerOpen = true;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void CloseDrawer()
|
||||
{
|
||||
IsDrawerOpen = false;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void ToggleDrawer(object? content = null)
|
||||
{
|
||||
if (IsDrawerOpen)
|
||||
{
|
||||
CloseDrawer();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (content != null)
|
||||
{
|
||||
DrawerContent = content;
|
||||
}
|
||||
IsDrawerOpen = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,13 @@ using Microsoft.Web.WebView2.Wpf;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Security.AccessControl;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
|
||||
namespace BetterGenshinImpact.View.Controls.Webview;
|
||||
|
||||
@@ -23,6 +25,8 @@ public class WebpagePanel : UserControl
|
||||
public string? DownloadFolderPath { get; set; }
|
||||
|
||||
public Action? OnWebViewInitializedAction { get; set; }
|
||||
|
||||
public Action<CoreWebView2NavigationCompletedEventArgs>? OnNavigationCompletedAction { get; set; }
|
||||
|
||||
public WebpagePanel()
|
||||
{
|
||||
@@ -45,10 +49,37 @@ public class WebpagePanel : UserControl
|
||||
};
|
||||
_webView.CoreWebView2InitializationCompleted += WebView_CoreWebView2InitializationCompleted;
|
||||
_webView.NavigationStarting += NavigationStarting_CancelNavigation;
|
||||
_webView.NavigationCompleted += WebView_NavigationCompleted;
|
||||
|
||||
Content = _webView;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// public WebpagePanel(WebView2 webView2)
|
||||
// {
|
||||
// if (!IsWebView2Available())
|
||||
// {
|
||||
// Content = CreateDownloadButton();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// EnsureWebView2DataFolder();
|
||||
// _webView = webView2;
|
||||
// webView2.CreationProperties = new CoreWebView2CreationProperties
|
||||
// {
|
||||
// UserDataFolder = Path.Combine(new FileInfo(Environment.ProcessPath!).DirectoryName!, @"WebView2Data\\"),
|
||||
// };
|
||||
// webView2.CoreWebView2InitializationCompleted += WebView_CoreWebView2InitializationCompleted;
|
||||
// webView2.NavigationStarting += NavigationStarting_CancelNavigation;
|
||||
// Content = webView2;
|
||||
// }
|
||||
// }
|
||||
private void WebView_NavigationCompleted(object? sender, CoreWebView2NavigationCompletedEventArgs e)
|
||||
{
|
||||
// 调用外部设置的导航完成 Action
|
||||
OnNavigationCompletedAction?.Invoke(e);
|
||||
}
|
||||
|
||||
private void WebView_CoreWebView2InitializationCompleted(object? sender, CoreWebView2InitializationCompletedEventArgs e)
|
||||
{
|
||||
if (e.IsSuccess)
|
||||
@@ -143,6 +174,15 @@ public class WebpagePanel : UserControl
|
||||
}));
|
||||
}
|
||||
|
||||
public void NavigateToMd(string md, string backgroundColor = "#2b2b2b")
|
||||
{
|
||||
md = WebUtility.HtmlEncode(md);
|
||||
string md2Html = ResourceHelper.GetString($"pack://application:,,,/Assets/Strings/md2html.html",
|
||||
Encoding.UTF8);
|
||||
var html = md2Html.Replace("{{content}}", md).Replace("#202020", backgroundColor);
|
||||
NavigateToHtml(html);
|
||||
}
|
||||
|
||||
private void NavigationStarting_CancelNavigation(object? sender, CoreWebView2NavigationStartingEventArgs e)
|
||||
{
|
||||
if (e.Uri.StartsWith("data:")) // when using NavigateToString
|
||||
|
||||
@@ -990,6 +990,104 @@
|
||||
Margin="0,0,36,0"
|
||||
IsChecked="{Binding Config.OtherConfig.RestoreFocusOnLostEnabled, Mode=TwoWay}" />-->
|
||||
</Grid>
|
||||
<ui:CardExpander Margin="0,0,0,12"
|
||||
ContentPadding="0"
|
||||
Icon="{ui:SymbolIcon SquareHintSparkles24}">
|
||||
<ui:CardExpander.Header>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<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}"
|
||||
Text="当调度器任务异常抛出未预期错误时,累计一定次数后,自动重启bgi,以恢复功能。"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:ToggleSwitch Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,24,0"
|
||||
IsChecked="{Binding Config.OtherConfig.AutoRestartConfig.Enabled, Mode=TwoWay}" />
|
||||
<b:Interaction.Triggers>
|
||||
<b:EventTrigger EventName="Unchecked">
|
||||
<b:InvokeCommandAction Command="{Binding SwitchMaskEnabledCommand}" />
|
||||
</b:EventTrigger>
|
||||
<b:EventTrigger EventName="Checked">
|
||||
<b:InvokeCommandAction Command="{Binding SwitchMaskEnabledCommand}" />
|
||||
</b:EventTrigger>
|
||||
</b:Interaction.Triggers>
|
||||
</Grid>
|
||||
</ui:CardExpander.Header>
|
||||
<StackPanel>
|
||||
<Grid Margin="16">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<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}"
|
||||
Text="当运行调度器任务时,异常导致任务失败的计数,当达到计数时会重启bgi。"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBox Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
MinWidth="90"
|
||||
Margin="0,0,36,0"
|
||||
Text="{Binding Config.OtherConfig.AutoRestartConfig.FailureCount, Mode=TwoWay,
|
||||
ValidatesOnNotifyDataErrors=True}" />
|
||||
</Grid>
|
||||
<Grid Margin="16">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<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">
|
||||
重启bgi时,同时重启游戏,需开启首页启动配置:同时启动原神、自动进入游戏,此配置才会生效。
|
||||
</ui:TextBlock>
|
||||
|
||||
<ui:ToggleSwitch Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,36,0"
|
||||
IsChecked="{Binding Config.OtherConfig.AutoRestartConfig.RestartGameTogether, Mode=TwoWay}">
|
||||
</ui:ToggleSwitch>
|
||||
</Grid>
|
||||
|
||||
</StackPanel>
|
||||
</ui:CardExpander>
|
||||
|
||||
</StackPanel>
|
||||
</ui:CardExpander>
|
||||
<!-- 地图 -->
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
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"
|
||||
xmlns:drawer="clr-namespace:BetterGenshinImpact.View.Controls.Drawer"
|
||||
d:DataContext="{d:DesignInstance Type=pages:JsListViewModel}"
|
||||
d:DesignHeight="600"
|
||||
d:DesignWidth="800"
|
||||
@@ -22,82 +23,93 @@
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid Margin="42,16,42,12">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Margin="0,0,0,8"
|
||||
FontTypography="BodyStrong"
|
||||
Text="自定义 Javascript 脚本(实验功能)" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Margin="0,0,0,8"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
TextWrapping="Wrap">
|
||||
可以通过 Javascript 调用 BetterGI 在原神中的各项能力。请在调度器中使用!<Hyperlink Command="{Binding GoToJsScriptUrlCommand}" Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}">
|
||||
点击查看 Javascript 脚本使用与编写教程
|
||||
</Hyperlink>
|
||||
</ui:TextBlock>
|
||||
<Grid>
|
||||
<Grid Margin="42,16,42,12">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal">
|
||||
<ui:Button Command="{Binding OpenScriptsFolderCommand}"
|
||||
Content="打开脚本目录"
|
||||
Icon="{ui:SymbolIcon FolderOpen24}" />
|
||||
<Separator Width="10" Opacity="0" />
|
||||
<ui:Button Command="{Binding OpenLocalScriptRepoCommand}" Icon="{ui:SymbolIcon Archive24}">
|
||||
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
||||
<ui:TextBlock>脚本仓库</ui:TextBlock>
|
||||
<ui:InfoBadge Margin="0,-8,-14,0"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Severity="Attention"
|
||||
Style="{DynamicResource DotInfoBadgeStyle}"
|
||||
Visibility="{Binding Config.ScriptConfig.ScriptRepoHintDotVisible, Converter={StaticResource BooleanToVisibilityConverter}}" />
|
||||
</Grid>
|
||||
</ui:Button>
|
||||
</StackPanel>
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Margin="0,0,0,8"
|
||||
FontTypography="BodyStrong"
|
||||
Text="自定义 Javascript 脚本(实验功能)" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Margin="0,0,0,8"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
TextWrapping="Wrap">
|
||||
可以通过 Javascript 调用 BetterGI 在原神中的各项能力。请在调度器中使用!
|
||||
<Hyperlink Command="{Binding GoToJsScriptUrlCommand}"
|
||||
Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}">
|
||||
点击查看 Javascript 脚本使用与编写教程
|
||||
</Hyperlink>
|
||||
</ui:TextBlock>
|
||||
|
||||
<Separator Grid.Row="3"
|
||||
Height="10"
|
||||
Opacity="0" />
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal">
|
||||
<ui:Button Command="{Binding OpenScriptsFolderCommand}"
|
||||
Content="打开脚本目录"
|
||||
Icon="{ui:SymbolIcon FolderOpen24}" />
|
||||
<Separator Width="10" Opacity="0" />
|
||||
<ui:Button Command="{Binding OpenLocalScriptRepoCommand}" Icon="{ui:SymbolIcon Archive24}">
|
||||
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
||||
<ui:TextBlock>脚本仓库</ui:TextBlock>
|
||||
<ui:InfoBadge Margin="0,-8,-14,0"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Severity="Attention"
|
||||
Style="{DynamicResource DotInfoBadgeStyle}"
|
||||
Visibility="{Binding Config.ScriptConfig.ScriptRepoHintDotVisible, Converter={StaticResource BooleanToVisibilityConverter}}" />
|
||||
</Grid>
|
||||
</ui:Button>
|
||||
</StackPanel>
|
||||
|
||||
<Grid Grid.Row="4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="80" />
|
||||
<!-- <ColumnDefinition Width="120" /> -->
|
||||
<ColumnDefinition Width="20" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid x:Name="Col1" Grid.Column="0" />
|
||||
<Grid x:Name="Col2" Grid.Column="1" />
|
||||
<Grid x:Name="Col3" Grid.Column="2" />
|
||||
<Grid x:Name="Col4" Grid.Column="3" />
|
||||
<!-- <Grid x:Name="Col5" Grid.Column="4" /> -->
|
||||
</Grid>
|
||||
<ui:ListView Grid.Row="5"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
ItemsSource="{Binding ScriptItems}"
|
||||
SelectionMode="Single">
|
||||
<ListView.View>
|
||||
<GridView ColumnHeaderContainerStyle="{StaticResource GridViewColumnHeaderDarkStyle}">
|
||||
<GridViewColumn Width="{Binding ElementName=Col1, Path=ActualWidth}"
|
||||
DisplayMemberBinding="{Binding FolderName}"
|
||||
Header="目录" />
|
||||
<GridViewColumn Width="{Binding ElementName=Col2, Path=ActualWidth}"
|
||||
DisplayMemberBinding="{Binding Manifest.Name}"
|
||||
Header="名称" />
|
||||
<GridViewColumn Width="{Binding ElementName=Col3, Path=ActualWidth}"
|
||||
DisplayMemberBinding="{Binding Manifest.Version}"
|
||||
Header="版本" />
|
||||
<!--<GridViewColumn Width="{Binding ElementName=Col4, Path=ActualWidth}" Header="操作">
|
||||
<Separator Grid.Row="3"
|
||||
Height="10"
|
||||
Opacity="0" />
|
||||
|
||||
<Grid Grid.Row="4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="80" />
|
||||
<!-- <ColumnDefinition Width="120" /> -->
|
||||
<ColumnDefinition Width="20" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid x:Name="Col1" Grid.Column="0" />
|
||||
<Grid x:Name="Col2" Grid.Column="1" />
|
||||
<Grid x:Name="Col3" Grid.Column="2" />
|
||||
<Grid x:Name="Col4" Grid.Column="3" />
|
||||
<!-- <Grid x:Name="Col5" Grid.Column="4" /> -->
|
||||
</Grid>
|
||||
<ui:ListView Grid.Row="5"
|
||||
x:Name="ScriptsListView"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
ItemsSource="{Binding ScriptItems}"
|
||||
SelectionMode="Single">
|
||||
<b:Interaction.Triggers>
|
||||
<b:EventTrigger EventName="SelectionChanged">
|
||||
<b:InvokeCommandAction Command="{Binding OpenScriptDetailDrawerCommand}"
|
||||
CommandParameter="{Binding ElementName=ScriptsListView, Path=SelectedItem}" />
|
||||
</b:EventTrigger>
|
||||
</b:Interaction.Triggers>
|
||||
<ListView.View>
|
||||
<GridView ColumnHeaderContainerStyle="{StaticResource GridViewColumnHeaderDarkStyle}">
|
||||
<GridViewColumn Width="{Binding ElementName=Col1, Path=ActualWidth}"
|
||||
DisplayMemberBinding="{Binding FolderName}"
|
||||
Header="目录" />
|
||||
<GridViewColumn Width="{Binding ElementName=Col2, Path=ActualWidth}"
|
||||
DisplayMemberBinding="{Binding Manifest.Name}"
|
||||
Header="名称" />
|
||||
<GridViewColumn Width="{Binding ElementName=Col3, Path=ActualWidth}"
|
||||
DisplayMemberBinding="{Binding Manifest.Version}"
|
||||
Header="版本" />
|
||||
<!--<GridViewColumn Width="{Binding ElementName=Col4, Path=ActualWidth}" Header="操作">
|
||||
<GridViewColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
@@ -110,34 +122,55 @@
|
||||
</DataTemplate>
|
||||
</GridViewColumn.CellTemplate>
|
||||
</GridViewColumn>-->
|
||||
</GridView>
|
||||
</ListView.View>
|
||||
<ListBox.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Command="{Binding OpenScriptProjectFolderCommand}"
|
||||
CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItem}"
|
||||
Header="打开目录" />
|
||||
<MenuItem Command="{Binding StartRunCommand}"
|
||||
CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItem}"
|
||||
Header="执行脚本" />
|
||||
<MenuItem Command="{Binding RefreshCommand}"
|
||||
CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItem}"
|
||||
Header="刷新" />
|
||||
</ContextMenu>
|
||||
</ListBox.ContextMenu>
|
||||
<ListView.Style>
|
||||
<Style TargetType="{x:Type ListView}">
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
</Style>
|
||||
</ListView.Style>
|
||||
<ListView.ItemContainerStyle>
|
||||
<Style BasedOn="{StaticResource ListViewItemStyle}" TargetType="ui:ListViewItem">
|
||||
<Setter Property="ToolTip" Value="{Binding Manifest.Description}" />
|
||||
<Setter Property="ToolTipService.InitialShowDelay" Value="0" />
|
||||
<Setter Property="ToolTipService.ShowDuration" Value="60000" />
|
||||
</Style>
|
||||
</ListView.ItemContainerStyle>
|
||||
</ui:ListView>
|
||||
</GridView>
|
||||
</ListView.View>
|
||||
<ListBox.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Command="{Binding OpenScriptProjectFolderCommand}"
|
||||
CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItem}"
|
||||
Header="打开目录" />
|
||||
<MenuItem Command="{Binding StartRunCommand}"
|
||||
CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItem}"
|
||||
Header="执行脚本" />
|
||||
<MenuItem Command="{Binding RefreshCommand}"
|
||||
CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItem}"
|
||||
Header="刷新" />
|
||||
</ContextMenu>
|
||||
</ListBox.ContextMenu>
|
||||
<ListView.Style>
|
||||
<Style TargetType="{x:Type ListView}">
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
</Style>
|
||||
</ListView.Style>
|
||||
<ListView.ItemContainerStyle>
|
||||
<Style BasedOn="{StaticResource ListViewItemStyle}" TargetType="ui:ListViewItem">
|
||||
<Setter Property="ToolTip" Value="{Binding Manifest.Description}" />
|
||||
<Setter Property="ToolTipService.InitialShowDelay" Value="0" />
|
||||
<Setter Property="ToolTipService.ShowDuration" Value="60000" />
|
||||
</Style>
|
||||
</ListView.ItemContainerStyle>
|
||||
</ui:ListView>
|
||||
</Grid>
|
||||
<!-- 抽屉控件 -->
|
||||
<drawer:CustomDrawer
|
||||
IsOpen="{Binding DrawerVm.IsDrawerOpen, Mode=TwoWay}"
|
||||
DrawerPosition="{Binding DrawerVm.DrawerPosition}"
|
||||
OpenWidth="{Binding DrawerVm.DrawerWidth}"
|
||||
OpenHeight="{Binding DrawerVm.DrawerHeight}"
|
||||
DrawerBackground="{DynamicResource ControlFillColorDefaultBrush}"
|
||||
Content="{Binding DrawerVm.DrawerContent}"
|
||||
Panel.ZIndex="100">
|
||||
<b:Interaction.Triggers>
|
||||
<b:EventTrigger EventName="Opened">
|
||||
<b:InvokeCommandAction Command="{Binding DrawerVm.OnDrawerOpenedCommand}"
|
||||
PassEventArgsToCommand="True"/>
|
||||
</b:EventTrigger>
|
||||
<b:EventTrigger EventName="Closing">
|
||||
<b:InvokeCommandAction Command="{Binding DrawerVm.OnDrawerClosingCommand}"
|
||||
PassEventArgsToCommand="True"/>
|
||||
</b:EventTrigger>
|
||||
</b:Interaction.Triggers>
|
||||
</drawer:CustomDrawer>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -120,21 +120,37 @@
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
FontTypography="Body"
|
||||
Text="角色选择使用的战斗宏编号"
|
||||
Text="默认战斗宏编号"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="用于修改当前配置文件中哪个战斗宏是优先使用的(1~5)"
|
||||
Text="当角色的 macroPriority 设置为0时,使用此默认宏编号(1~5)"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:NumberBox Grid.Row="0"
|
||||
<ui:TextBox Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
MinWidth="90"
|
||||
Margin="0,0,36,0"
|
||||
Maximum="5"
|
||||
Minimum="1"
|
||||
ValidationMode="InvalidInputOverwritten"
|
||||
Value="{Binding Config.MacroConfig.CombatMacroPriority, Mode=TwoWay}" />
|
||||
Text="{Binding Config.MacroConfig.CombatMacroPriority, Mode=TwoWay}" />
|
||||
</Grid>
|
||||
<Grid Margin="16">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
FontTypography="Body"
|
||||
Text="角色个性化宏编号设置"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="上方宏配置支持为每个角色单独设置宏编号。在角色宏配置中设置 macroPriority 字段(1-5),设置为0则使用上面的默认战斗宏编号。"
|
||||
TextWrapping="Wrap" />
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</ui:CardExpander>
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
xmlns:pages="clr-namespace:BetterGenshinImpact.ViewModel.Pages"
|
||||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
|
||||
xmlns:vio="http://schemas.lepo.co/wpfui/2022/xaml/violeta"
|
||||
xmlns:drawer="clr-namespace:BetterGenshinImpact.View.Controls.Drawer"
|
||||
d:DataContext="{d:DesignInstance Type=pages:MapPathingViewModel}"
|
||||
d:DesignHeight="600"
|
||||
d:DesignWidth="800"
|
||||
@@ -25,102 +26,135 @@
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<Grid Margin="42,16,42,12">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid>
|
||||
<Grid Margin="42,16,42,12">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Margin="0,0,0,8"
|
||||
FontTypography="BodyStrong"
|
||||
Text="地图追踪(实验功能)" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Margin="0,0,0,8"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
TextWrapping="Wrap">
|
||||
可以实现自动采集、自动挖矿、自动锄地等功能。请在调度器中使用!<Hyperlink Command="{Binding GoToPathingUrlCommand}" Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}">
|
||||
点击查看地图追踪与录制使用教程
|
||||
</Hyperlink>
|
||||
</ui:TextBlock>
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Margin="0,0,0,8"
|
||||
FontTypography="BodyStrong"
|
||||
Text="地图追踪(实验功能)" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Margin="0,0,0,8"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
TextWrapping="Wrap">
|
||||
可以实现自动采集、自动挖矿、自动锄地等功能。请在调度器中使用!
|
||||
<Hyperlink Command="{Binding GoToPathingUrlCommand}"
|
||||
Foreground="{ui:ThemeResource TextFillColorSecondaryBrush}">
|
||||
点击查看地图追踪与录制使用教程
|
||||
</Hyperlink>
|
||||
</ui:TextBlock>
|
||||
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal">
|
||||
<ui:Button Command="{Binding OpenScriptsFolderCommand}"
|
||||
Content="打开任务目录"
|
||||
Icon="{ui:SymbolIcon FolderOpen24}" />
|
||||
<ui:Button Margin="10,0,0,0"
|
||||
Command="{Binding OpenLocalScriptRepoCommand}"
|
||||
Icon="{ui:SymbolIcon Archive24}">
|
||||
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
||||
<ui:TextBlock>脚本仓库</ui:TextBlock>
|
||||
<ui:InfoBadge Margin="0,-8,-14,0"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Severity="Attention"
|
||||
Style="{DynamicResource DotInfoBadgeStyle}"
|
||||
Visibility="{Binding Config.ScriptConfig.ScriptRepoHintDotVisible, Converter={StaticResource BooleanToVisibilityConverter}}" />
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal">
|
||||
<ui:Button Command="{Binding OpenScriptsFolderCommand}"
|
||||
Content="打开任务目录"
|
||||
Icon="{ui:SymbolIcon FolderOpen24}" />
|
||||
<ui:Button Margin="10,0,0,0"
|
||||
Command="{Binding OpenLocalScriptRepoCommand}"
|
||||
Icon="{ui:SymbolIcon Archive24}">
|
||||
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
||||
<ui:TextBlock>脚本仓库</ui:TextBlock>
|
||||
<ui:InfoBadge Margin="0,-8,-14,0"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Severity="Attention"
|
||||
Style="{DynamicResource DotInfoBadgeStyle}"
|
||||
Visibility="{Binding Config.ScriptConfig.ScriptRepoHintDotVisible, Converter={StaticResource BooleanToVisibilityConverter}}" />
|
||||
</Grid>
|
||||
</ui:Button>
|
||||
<ui:Button Margin="10,0,0,0"
|
||||
Command="{Binding OpenSettingsCommand}"
|
||||
Content="设置"
|
||||
Icon="{ui:SymbolIcon Settings24}" />
|
||||
<ui:Button Margin="10,0,0,0"
|
||||
Command="{Binding OpenDevToolsCommand}"
|
||||
Content="开发者工具" />
|
||||
</StackPanel>
|
||||
|
||||
<Separator Grid.Row="3"
|
||||
Height="10"
|
||||
Opacity="0" />
|
||||
|
||||
<ui:Border Grid.Row="5"
|
||||
Background="{DynamicResource CardBackground}"
|
||||
BorderBrush="{DynamicResource CardBorderBrush}"
|
||||
BorderThickness="1"
|
||||
CornerRadius="{DynamicResource ControlCornerRadius}">
|
||||
<Grid Margin="4">
|
||||
<ui:Grid ColumnDefinitions="*,10" Visibility="Hidden">
|
||||
<Grid x:Name="TreeColumnStar" Grid.Column="0" />
|
||||
</ui:Grid>
|
||||
<ui:TreeListView BorderThickness="0"
|
||||
ItemsSource="{Binding TreeList}"
|
||||
SelectedItem="{Binding SelectNode, Mode=TwoWay}">
|
||||
<b:Interaction.Triggers>
|
||||
<b:EventTrigger EventName="SelectedItemChanged">
|
||||
<b:InvokeCommandAction Command="{Binding OpenPathingDetailCommand}"
|
||||
CommandParameter="{Binding SelectNode}" />
|
||||
</b:EventTrigger>
|
||||
</b:Interaction.Triggers>
|
||||
<ui:TreeListView.Columns>
|
||||
<GridViewColumnCollection>
|
||||
<ui:GridViewColumn Width="{Binding ActualWidth, ElementName=TreeColumnStar}"
|
||||
Header="名称">
|
||||
<ui:GridViewColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<ui:TreeRowExpander>
|
||||
<ui:TreeRowExpander.Content>
|
||||
<ui:StackPanel Margin="8,0,0,0"
|
||||
Orientation="Horizontal"
|
||||
Spacing="8">
|
||||
<Image Height="16"
|
||||
Source="{Binding IconFilePath, Converter={x:Static vio:PathToIconConverter.Instance}}" />
|
||||
<TextBlock VerticalAlignment="Center" Text="{Binding FileName}" />
|
||||
</ui:StackPanel>
|
||||
</ui:TreeRowExpander.Content>
|
||||
</ui:TreeRowExpander>
|
||||
</DataTemplate>
|
||||
</ui:GridViewColumn.CellTemplate>
|
||||
</ui:GridViewColumn>
|
||||
</GridViewColumnCollection>
|
||||
</ui:TreeListView.Columns>
|
||||
<ui:TreeListView.ItemTemplate>
|
||||
<HierarchicalDataTemplate ItemsSource="{Binding Children}" />
|
||||
</ui:TreeListView.ItemTemplate>
|
||||
<ui:TreeListView.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Command="{Binding StartCommand}" Header="执行任务" />
|
||||
<MenuItem Command="{Binding RefreshCommand}" Header="刷新" />
|
||||
</ContextMenu>
|
||||
</ui:TreeListView.ContextMenu>
|
||||
</ui:TreeListView>
|
||||
</Grid>
|
||||
</ui:Button>
|
||||
<ui:Button Margin="10,0,0,0"
|
||||
Command="{Binding OpenSettingsCommand}"
|
||||
Content="设置"
|
||||
Icon="{ui:SymbolIcon Settings24}" />
|
||||
<ui:Button Margin="10,0,0,0"
|
||||
Command="{Binding OpenDevToolsCommand}"
|
||||
Content="开发者工具" />
|
||||
</StackPanel>
|
||||
</ui:Border>
|
||||
</Grid>
|
||||
|
||||
<Separator Grid.Row="3"
|
||||
Height="10"
|
||||
Opacity="0" />
|
||||
|
||||
<ui:Border Grid.Row="5"
|
||||
Background="{DynamicResource CardBackground}"
|
||||
BorderBrush="{DynamicResource CardBorderBrush}"
|
||||
BorderThickness="1"
|
||||
CornerRadius="{DynamicResource ControlCornerRadius}">
|
||||
<Grid Margin="4">
|
||||
<ui:Grid ColumnDefinitions="*,10" Visibility="Hidden">
|
||||
<Grid x:Name="TreeColumnStar" Grid.Column="0" />
|
||||
</ui:Grid>
|
||||
<ui:TreeListView BorderThickness="0"
|
||||
ItemsSource="{Binding TreeList}"
|
||||
SelectedItem="{Binding SelectNode, Mode=TwoWay}">
|
||||
<ui:TreeListView.Columns>
|
||||
<GridViewColumnCollection>
|
||||
<ui:GridViewColumn Width="{Binding ActualWidth, ElementName=TreeColumnStar}" Header="名称">
|
||||
<ui:GridViewColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<ui:TreeRowExpander>
|
||||
<ui:TreeRowExpander.Content>
|
||||
<ui:StackPanel Margin="8,0,0,0"
|
||||
Orientation="Horizontal"
|
||||
Spacing="8">
|
||||
<Image Height="16" Source="{Binding IconFilePath, Converter={x:Static vio:PathToIconConverter.Instance}}" />
|
||||
<TextBlock VerticalAlignment="Center" Text="{Binding FileName}" />
|
||||
</ui:StackPanel>
|
||||
</ui:TreeRowExpander.Content>
|
||||
</ui:TreeRowExpander>
|
||||
</DataTemplate>
|
||||
</ui:GridViewColumn.CellTemplate>
|
||||
</ui:GridViewColumn>
|
||||
</GridViewColumnCollection>
|
||||
</ui:TreeListView.Columns>
|
||||
<ui:TreeListView.ItemTemplate>
|
||||
<HierarchicalDataTemplate ItemsSource="{Binding Children}" />
|
||||
</ui:TreeListView.ItemTemplate>
|
||||
<ui:TreeListView.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Command="{Binding StartCommand}" Header="执行任务" />
|
||||
<MenuItem Command="{Binding RefreshCommand}" Header="刷新" />
|
||||
</ContextMenu>
|
||||
</ui:TreeListView.ContextMenu>
|
||||
</ui:TreeListView>
|
||||
</Grid>
|
||||
</ui:Border>
|
||||
<!-- 添加抽屉控件 -->
|
||||
<drawer:CustomDrawer
|
||||
IsOpen="{Binding DrawerVm.IsDrawerOpen, Mode=TwoWay}"
|
||||
DrawerPosition="{Binding DrawerVm.DrawerPosition}"
|
||||
OpenWidth="{Binding DrawerVm.DrawerWidth}"
|
||||
OpenHeight="{Binding DrawerVm.DrawerHeight}"
|
||||
DrawerBackground="{DynamicResource ControlFillColorDefaultBrush}"
|
||||
Content="{Binding DrawerVm.DrawerContent}"
|
||||
Panel.ZIndex="100">
|
||||
<b:Interaction.Triggers>
|
||||
<b:EventTrigger EventName="Opened">
|
||||
<b:InvokeCommandAction Command="{Binding DrawerVm.OnDrawerOpenedCommand}"
|
||||
PassEventArgsToCommand="True" />
|
||||
</b:EventTrigger>
|
||||
<b:EventTrigger EventName="Closing">
|
||||
<b:InvokeCommandAction Command="{Binding DrawerVm.OnDrawerClosingCommand}"
|
||||
PassEventArgsToCommand="True" />
|
||||
</b:EventTrigger>
|
||||
</b:Interaction.Triggers>
|
||||
</drawer:CustomDrawer>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -341,7 +341,7 @@
|
||||
Text="自动秘境" />
|
||||
|
||||
|
||||
<ui:CardExpander Margin="0,0,0,12" ContentPadding="0">
|
||||
<ui:CardExpander Margin="0,0,0,12" ContentPadding="0" IsExpanded="{Binding SelectedConfig.WeeklyDomainEnabled, Converter={StaticResource InverseBooleanConverter}, Mode=TwoWay}">
|
||||
<ui:CardExpander.Icon>
|
||||
<ui:FontIcon Glyph="" Style="{StaticResource FaFontIconStyle}" />
|
||||
</ui:CardExpander.Icon>
|
||||
@@ -470,8 +470,7 @@
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</ui:CardExpander>
|
||||
|
||||
<ui:CardExpander Margin="0,0,0,12" ContentPadding="0">
|
||||
<ui:CardExpander Margin="0,0,0,12" ContentPadding="0" IsExpanded="{Binding SelectedConfig.WeeklyDomainEnabled, Mode=TwoWay}">
|
||||
<ui:CardExpander.Icon>
|
||||
<ui:FontIcon Glyph="" Style="{StaticResource FaFontIconStyle}" />
|
||||
</ui:CardExpander.Icon>
|
||||
@@ -493,10 +492,8 @@
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
Text="启用后,每日刷取配置将会失效"
|
||||
TextWrapping="Wrap">
|
||||
</ui:TextBlock>
|
||||
|
||||
Text="启用后,每日刷取配置将会失效。"
|
||||
TextWrapping="Wrap" />
|
||||
<ui:ToggleSwitch Grid.Row="0"
|
||||
Grid.RowSpan="2"
|
||||
Grid.Column="1"
|
||||
@@ -505,6 +502,25 @@
|
||||
</Grid>
|
||||
</ui:CardExpander.Header>
|
||||
<StackPanel>
|
||||
<Grid Margin="52,16,16,8">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
FontTypography="Body"
|
||||
Text=""
|
||||
TextWrapping="Wrap">
|
||||
新的一天开始于 4:00
|
||||
</ui:TextBlock>
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
TextWrapping="Wrap">
|
||||
周一 4:00 至周二 3:59 执行周一配置,以此类推。
|
||||
</ui:TextBlock>
|
||||
</Grid>
|
||||
<Grid Margin="16">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
@@ -513,7 +529,7 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Margin="35,0,0,0"
|
||||
Margin="38,0,0,0"
|
||||
HorizontalAlignment="Center"
|
||||
Text="周一"
|
||||
VerticalAlignment="Center" />
|
||||
@@ -542,7 +558,7 @@
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
FontTypography="Body"
|
||||
Margin="35,0,0,0"
|
||||
Margin="38,0,0,0"
|
||||
HorizontalAlignment="Center"
|
||||
Text="周二"
|
||||
VerticalAlignment="Center" />
|
||||
@@ -570,7 +586,7 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Margin="35,0,0,0"
|
||||
Margin="38,0,0,0"
|
||||
HorizontalAlignment="Center"
|
||||
Text="周三"
|
||||
VerticalAlignment="Center" />
|
||||
@@ -599,7 +615,7 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Margin="35,0,0,0"
|
||||
Margin="38,0,0,0"
|
||||
HorizontalAlignment="Center"
|
||||
Text="周四"
|
||||
VerticalAlignment="Center" />
|
||||
@@ -628,7 +644,7 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Margin="35,0,0,0"
|
||||
Margin="38,0,0,0"
|
||||
HorizontalAlignment="Center"
|
||||
Text="周五"
|
||||
VerticalAlignment="Center" />
|
||||
@@ -658,7 +674,7 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Margin="35,0,0,0"
|
||||
Margin="38,0,0,0"
|
||||
HorizontalAlignment="Center"
|
||||
Text="周六"
|
||||
VerticalAlignment="Center" />
|
||||
@@ -692,7 +708,7 @@
|
||||
</Grid.RowDefinitions>
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Margin="35,0,0,0"
|
||||
Margin="38,0,0,0"
|
||||
HorizontalAlignment="Center"
|
||||
Text="周日"
|
||||
VerticalAlignment="Center" />
|
||||
|
||||
@@ -55,7 +55,18 @@
|
||||
SelectionMode="Single">
|
||||
<ui:ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Margin="8,4" Text="{Binding Name, Mode=OneWay}" />
|
||||
<TextBlock Margin="8,4" Text="{Binding Name, Mode=OneWay}" >
|
||||
<TextBlock.Style>
|
||||
<Style TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="White" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding NextFlag}" Value="True">
|
||||
<Setter Property="Foreground" Value="Green" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</TextBlock.Style>
|
||||
</TextBlock>
|
||||
</DataTemplate>
|
||||
</ui:ListView.ItemTemplate>
|
||||
<ui:ListView.ContextMenu>
|
||||
@@ -70,14 +81,30 @@
|
||||
<MenuItem Command="{Binding CopyScriptGroupCommand}"
|
||||
CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItem}"
|
||||
Header="复制组" />
|
||||
<MenuItem Command="{Binding AddScriptGroupNextFlagCommand}"
|
||||
CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItem}"
|
||||
Header="连续任务从此开始执行" />
|
||||
</ContextMenu>
|
||||
</ui:ListView.ContextMenu>
|
||||
</ui:ListView>
|
||||
<ui:Button Grid.Row="2"
|
||||
Margin="0,2,0,2"
|
||||
HorizontalAlignment="Stretch"
|
||||
Command="{Binding StartMultiScriptGroupCommand}"
|
||||
Content="连续执行" />
|
||||
<Grid Grid.Row="2">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<ui:Button Grid.Row="0"
|
||||
Margin="2"
|
||||
HorizontalAlignment="Stretch"
|
||||
Command="{Binding StartMultiScriptGroupCommand}"
|
||||
Content="连续执行" />
|
||||
|
||||
<ui:Button Grid.Row="1"
|
||||
Margin="2"
|
||||
HorizontalAlignment="Stretch"
|
||||
Command="{Binding ContinueMultiScriptGroupCommand}"
|
||||
Content="继续执行" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
<ui:FluentWindow x:Class="BetterGenshinImpact.View.Windows.ScriptRepoWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:BetterGenshinImpact.View.Windows"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
|
||||
xmlns:vio="http://schemas.lepo.co/wpfui/2022/xaml/violeta"
|
||||
xmlns:emoji="clr-namespace:Emoji.Wpf;assembly=Emoji.Wpf"
|
||||
Title="脚本仓库"
|
||||
Width = "350"
|
||||
MinWidth="350"
|
||||
MinHeight="50"
|
||||
SizeToContent="Height"
|
||||
Background="#202020"
|
||||
ExtendsContentIntoTitleBar="True"
|
||||
FontFamily="{DynamicResource TextThemeFontFamily}"
|
||||
WindowBackdropType="None"
|
||||
WindowStartupLocation="CenterOwner"
|
||||
mc:Ignorable="d">
|
||||
<Grid>
|
||||
<ui:Grid Margin="0,48,0,0">
|
||||
<Border Grid.Column="2"
|
||||
Margin="6"
|
||||
Background="{ui:ThemeResource CardBackgroundFillColorDefaultBrush}"
|
||||
BorderBrush="{ui:ThemeResource CardStrokeColorDefaultBrush}"
|
||||
BorderThickness="1,1,1,1"
|
||||
CornerRadius="8">
|
||||
<Grid Margin="8">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- 第一行:更新渠道 -->
|
||||
<StackPanel Grid.Row="0"
|
||||
Orientation="Horizontal"
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,0,0,12">
|
||||
<ui:TextBlock
|
||||
Foreground="{ui:ThemeResource TextFillColorPrimaryBrush}"
|
||||
VerticalAlignment="Center"
|
||||
Margin="0,0,8,0"
|
||||
Text="更新渠道:" />
|
||||
<ComboBox
|
||||
Width="160"
|
||||
ItemsSource="{Binding RepoChannels}"
|
||||
DisplayMemberPath="Name"
|
||||
SelectedItem="{Binding SelectedRepoChannel}"
|
||||
VerticalAlignment="Center"/>
|
||||
|
||||
|
||||
</StackPanel>
|
||||
|
||||
<!-- 第二行:脚本仓库 -->
|
||||
<StackPanel Grid.Row="1"
|
||||
Orientation="Horizontal" >
|
||||
<ui:Button
|
||||
Icon="{ui:SymbolIcon CloudSync24}"
|
||||
Content="更新仓库"
|
||||
Margin="0,0,8,0"
|
||||
Command="{Binding UpdateRepoCommand}" />
|
||||
<ui:Button
|
||||
Icon="{ui:SymbolIcon ArrowReset24}"
|
||||
Content="重置仓库"
|
||||
Margin="0,0,8,0"
|
||||
Command="{Binding ResetRepoCommand}" />
|
||||
<ui:Button
|
||||
Icon="{ui:SymbolIcon BookStar24}"
|
||||
Appearance="Primary"
|
||||
Content="打开仓库"
|
||||
Command="{Binding OpenLocalScriptRepoCommand}" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Border>
|
||||
</ui:Grid>
|
||||
|
||||
<ui:TitleBar Title="{Binding Title}"
|
||||
ShowMaximize="False"
|
||||
ShowMinimize="False">
|
||||
<ui:TitleBar.Icon>
|
||||
<ui:ImageIcon Source="pack://application:,,,/Assets/Images/logo.png" />
|
||||
</ui:TitleBar.Icon>
|
||||
</ui:TitleBar>
|
||||
</Grid>
|
||||
</ui:FluentWindow>
|
||||
@@ -0,0 +1,126 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.Core.Script;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
using Wpf.Ui.Violeta.Controls;
|
||||
|
||||
namespace BetterGenshinImpact.View.Windows;
|
||||
|
||||
[ObservableObject]
|
||||
public partial class ScriptRepoWindow
|
||||
{
|
||||
// 更新渠道类
|
||||
public class RepoChannel
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Url { get; set; }
|
||||
|
||||
public RepoChannel(string name, string url)
|
||||
{
|
||||
Name = name;
|
||||
Url = url;
|
||||
}
|
||||
}
|
||||
|
||||
// 渠道列表
|
||||
private ObservableCollection<RepoChannel> _repoChannels;
|
||||
public ObservableCollection<RepoChannel> RepoChannels => _repoChannels;
|
||||
|
||||
// 选中的渠道
|
||||
[ObservableProperty] private RepoChannel _selectedRepoChannel;
|
||||
|
||||
public ScriptRepoWindow()
|
||||
{
|
||||
InitializeRepoChannels();
|
||||
InitializeComponent();
|
||||
DataContext = this;
|
||||
}
|
||||
|
||||
private void InitializeRepoChannels()
|
||||
{
|
||||
_repoChannels = new ObservableCollection<RepoChannel>
|
||||
{
|
||||
new RepoChannel("CNB", "https://cnb.cool/bettergi/bettergi-scripts-list"),
|
||||
new RepoChannel("GitCode", "https://gitcode.com/huiyadanli/bettergi-scripts-list"),
|
||||
new RepoChannel("Gitee", "https://gitee.com/babalae/bettergi-scripts-list"),
|
||||
new RepoChannel("GitHub", "https://github.com/babalae/bettergi-scripts-list"),
|
||||
};
|
||||
SelectedRepoChannel = _repoChannels[0];
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task UpdateRepo()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 使用选定渠道的URL进行更新
|
||||
string repoUrl = SelectedRepoChannel.Url;
|
||||
|
||||
// 显示更新中提示
|
||||
Toast.Information("正在更新脚本仓库...");
|
||||
|
||||
// 执行更新
|
||||
var (repoPath, updated) = await ScriptRepoUpdater.Instance.UpdateCenterRepoByGit(repoUrl);
|
||||
|
||||
// 更新结果提示
|
||||
if (updated)
|
||||
{
|
||||
Toast.Success("脚本仓库更新成功,有新内容");
|
||||
}
|
||||
else
|
||||
{
|
||||
Toast.Success("脚本仓库已是最新");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Toast.Error($"更新失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void OpenLocalScriptRepo()
|
||||
{
|
||||
TaskContext.Instance().Config.ScriptConfig.ScriptRepoHintDotVisible = false;
|
||||
ScriptRepoUpdater.Instance.OpenLocalRepoInWebView();
|
||||
Close();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task ResetRepo()
|
||||
{
|
||||
// 添加确认对话框
|
||||
var result = await MessageBox.ShowAsync(
|
||||
"确定要重置脚本仓库吗?无法正常更新时候可以使用本功能,重置后请重新更新脚本仓库。",
|
||||
"确认重置",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Warning);
|
||||
|
||||
if (result == MessageBoxResult.Yes)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Directory.Exists(ScriptRepoUpdater.CenterRepoPath))
|
||||
{
|
||||
DirectoryHelper.DeleteReadOnlyDirectory(ScriptRepoUpdater.CenterRepoPath);
|
||||
Toast.Success("脚本仓库已重置,请重新更新脚本仓库。");
|
||||
}
|
||||
else
|
||||
{
|
||||
Toast.Information("脚本仓库不存在,无需重置");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Toast.Error($"重置失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -149,7 +149,7 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
|
||||
}
|
||||
|
||||
// 更新仓库
|
||||
ScriptRepoUpdater.Instance.AutoUpdate();
|
||||
// ScriptRepoUpdater.Instance.AutoUpdate();
|
||||
|
||||
// 清理临时目录
|
||||
TempManager.CleanUp();
|
||||
|
||||
@@ -9,15 +9,25 @@ using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
using BetterGenshinImpact.View.Controls.Drawer;
|
||||
using BetterGenshinImpact.View.Controls.Webview;
|
||||
using BetterGenshinImpact.ViewModel.Message;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Microsoft.Web.WebView2.Wpf;
|
||||
using Wpf.Ui;
|
||||
using Wpf.Ui.Controls;
|
||||
using Wpf.Ui.Violeta.Controls;
|
||||
using Button = Wpf.Ui.Controls.Button;
|
||||
using StackPanel = Wpf.Ui.Controls.StackPanel;
|
||||
using TextBlock = Wpf.Ui.Controls.TextBlock;
|
||||
using TextBox = Wpf.Ui.Controls.TextBox;
|
||||
|
||||
namespace BetterGenshinImpact.ViewModel.Pages;
|
||||
|
||||
@@ -26,13 +36,21 @@ public partial class JsListViewModel : ViewModel
|
||||
private readonly ILogger<JsListViewModel> _logger = App.GetLogger<JsListViewModel>();
|
||||
private readonly string scriptPath = Global.ScriptPath();
|
||||
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<ScriptProject> _scriptItems = [];
|
||||
[ObservableProperty] private ObservableCollection<ScriptProject> _scriptItems = [];
|
||||
|
||||
private readonly IScriptService _scriptService;
|
||||
|
||||
public AllConfig Config { get; set; }
|
||||
|
||||
public DrawerViewModel DrawerVm { get; } = new DrawerViewModel();
|
||||
|
||||
private WebView2? _webView2;
|
||||
|
||||
private WebpagePanel? _mdWebpagePanel;
|
||||
|
||||
private TaskCompletionSource<bool>? _navigationCompletionSource;
|
||||
private const int NavigationTimeoutMs = 10000; // 10秒超时
|
||||
|
||||
public JsListViewModel(IScriptService scriptService, IConfigService configService)
|
||||
{
|
||||
_scriptService = scriptService;
|
||||
@@ -114,13 +132,214 @@ public partial class JsListViewModel : ViewModel
|
||||
[RelayCommand]
|
||||
public void OnGoToJsScriptUrl()
|
||||
{
|
||||
Process.Start(new ProcessStartInfo("https://bettergi.com/feats/autos/jsscript.html") { UseShellExecute = true });
|
||||
Process.Start(new ProcessStartInfo("https://bettergi.com/feats/autos/jsscript.html")
|
||||
{ UseShellExecute = true });
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void OnOpenLocalScriptRepo()
|
||||
{
|
||||
Config.ScriptConfig.ScriptRepoHintDotVisible = false;
|
||||
ScriptRepoUpdater.Instance.OpenLocalRepoInWebView();
|
||||
ScriptRepoUpdater.Instance.OpenScriptRepoWindow();
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void OpenScriptDetailDrawer(object? scriptItem)
|
||||
{
|
||||
if (scriptItem == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (scriptItem is ScriptProject scriptProject)
|
||||
{
|
||||
// 检查是否存在README.md或其他md文件
|
||||
var mdFilePath = FindMdFilePath(scriptProject);
|
||||
|
||||
// 设置抽屉位置和大小
|
||||
DrawerVm.DrawerPosition = DrawerPosition.Right;
|
||||
|
||||
if (!string.IsNullOrEmpty(mdFilePath))
|
||||
{
|
||||
DrawerVm.DrawerWidth = 450;
|
||||
// 注册抽屉关闭前事件
|
||||
DrawerVm.SetDrawerClosingAction(args =>
|
||||
{
|
||||
if (_mdWebpagePanel != null)
|
||||
{
|
||||
_mdWebpagePanel.Visibility = Visibility.Hidden;
|
||||
}
|
||||
});
|
||||
DrawerVm.setDrawerOpenedAction(async () =>
|
||||
{
|
||||
if (_mdWebpagePanel != null)
|
||||
{
|
||||
// 等待导航完成或超时
|
||||
try
|
||||
{
|
||||
await WaitForNavigationCompletedWithTimeout();
|
||||
_mdWebpagePanel.Visibility = Visibility.Visible;
|
||||
_mdWebpagePanel.WebView.Focus();
|
||||
Debug.WriteLine("Navigation completed successfully");
|
||||
// 导航成功完成后执行其他操作
|
||||
}
|
||||
catch (TimeoutException)
|
||||
{
|
||||
Toast.Error("Markdown内容加载超时");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawerVm.SetDrawerClosingAction(_ => { });
|
||||
DrawerVm.setDrawerOpenedAction(() => { });
|
||||
DrawerVm.DrawerWidth = 300;
|
||||
}
|
||||
|
||||
// 创建要在抽屉中显示的内容
|
||||
var content = CreateScriptDetailContent(scriptProject, mdFilePath);
|
||||
|
||||
// 打开抽屉
|
||||
DrawerVm.OpenDrawer(content);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task WaitForNavigationCompletedWithTimeout()
|
||||
{
|
||||
var completedTask = await Task.WhenAny(
|
||||
_navigationCompletionSource!.Task,
|
||||
Task.Delay(NavigationTimeoutMs)
|
||||
);
|
||||
|
||||
if (completedTask != _navigationCompletionSource.Task)
|
||||
{
|
||||
throw new TimeoutException("Navigation did not complete within the timeout period");
|
||||
}
|
||||
}
|
||||
|
||||
private object CreateScriptDetailContent(ScriptProject scriptProject, string? mdFilePath)
|
||||
{
|
||||
// 创建显示脚本详情的控件
|
||||
var border = new Border
|
||||
{
|
||||
Background = new SolidColorBrush(Color.FromRgb(0x2B, 0x2B, 0x2B)),
|
||||
Padding = new Thickness(20)
|
||||
};
|
||||
var panel = new StackPanel();
|
||||
border.Child = panel;
|
||||
|
||||
// 假设scriptItem是你的脚本对象,根据实际类型进行调整
|
||||
panel.Children.Add(new TextBlock
|
||||
{
|
||||
Text = scriptProject.Manifest.Name,
|
||||
FontSize = 20,
|
||||
FontWeight = FontWeights.Bold,
|
||||
Margin = new Thickness(0, 0, 0, 10)
|
||||
});
|
||||
|
||||
|
||||
// 如果找到md文件,使用WebpagePanel显示
|
||||
if (!string.IsNullOrEmpty(mdFilePath))
|
||||
{
|
||||
// 使用Grid作为容器来实现填充效果
|
||||
var grid = new Grid
|
||||
{
|
||||
Margin = new Thickness(0, 0, 0, 15)
|
||||
};
|
||||
|
||||
_mdWebpagePanel = new WebpagePanel
|
||||
{
|
||||
Margin = new Thickness(0),
|
||||
Visibility = Visibility.Hidden,
|
||||
VerticalAlignment = VerticalAlignment.Stretch,
|
||||
HorizontalAlignment = HorizontalAlignment.Stretch
|
||||
};
|
||||
|
||||
_navigationCompletionSource = new TaskCompletionSource<bool>();
|
||||
_mdWebpagePanel.OnNavigationCompletedAction = (_) =>
|
||||
{
|
||||
// 导航完成时设置任务结果
|
||||
_navigationCompletionSource.TrySetResult(true);
|
||||
};
|
||||
_mdWebpagePanel.NavigateToMd(File.ReadAllText(mdFilePath));
|
||||
|
||||
grid.Children.Add(_mdWebpagePanel);
|
||||
panel.Children.Add(grid);
|
||||
|
||||
// 设置Grid高度以占满剩余空间
|
||||
panel.SizeChanged += (sender, args) =>
|
||||
{
|
||||
// 计算其他元素使用的高度
|
||||
double otherElementsHeight = 0;
|
||||
foreach (var child in panel.Children)
|
||||
{
|
||||
if (child != grid)
|
||||
{
|
||||
var frameworkElement = child as FrameworkElement;
|
||||
if (frameworkElement != null)
|
||||
{
|
||||
otherElementsHeight += frameworkElement.ActualHeight + frameworkElement.Margin.Top + frameworkElement.Margin.Bottom;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 设置Grid高度为剩余空间
|
||||
grid.Height = Math.Max(400, panel.ActualHeight - otherElementsHeight - 15); // 设置最小高度为400
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
panel.Children.Add(new TextBlock
|
||||
{
|
||||
Text = $"版本: {scriptProject.Manifest.Version}",
|
||||
Margin = new Thickness(0, 5, 0, 5)
|
||||
});
|
||||
|
||||
panel.Children.Add(new TextBlock
|
||||
{
|
||||
Text = scriptProject.Manifest.Description,
|
||||
TextWrapping = TextWrapping.Wrap,
|
||||
Margin = new Thickness(0, 5, 0, 15)
|
||||
});
|
||||
}
|
||||
|
||||
// 添加操作按钮
|
||||
// var buttonPanel = new StackPanel { Orientation = Orientation.Horizontal };
|
||||
//
|
||||
// var runButton = new Button
|
||||
// {
|
||||
// Content = "执行脚本",
|
||||
// Margin = new Thickness(0, 0, 10, 0)
|
||||
// };
|
||||
// runButton.Click += async (s, e) => await OnStartRun(script);
|
||||
// buttonPanel.Children.Add(runButton);
|
||||
//
|
||||
// var openFolderButton = new Button { Content = "打开目录" };
|
||||
// openFolderButton.Click += (s, e) => OnOpenScriptProjectFolder(script);
|
||||
// buttonPanel.Children.Add(openFolderButton);
|
||||
|
||||
// panel.Children.Add(buttonPanel);
|
||||
|
||||
|
||||
return border;
|
||||
}
|
||||
|
||||
private static string? FindMdFilePath(ScriptProject script)
|
||||
{
|
||||
string[] possibleMdFiles = { "README.md", "readme.md" };
|
||||
string mdFilePath = null;
|
||||
|
||||
foreach (var mdFile in possibleMdFiles)
|
||||
{
|
||||
string fullPath = Path.Combine(script.ProjectPath, mdFile);
|
||||
if (File.Exists(fullPath))
|
||||
{
|
||||
mdFilePath = fullPath;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return mdFilePath;
|
||||
}
|
||||
}
|
||||
@@ -231,6 +231,6 @@ public partial class KeyMouseRecordPageViewModel : ViewModel
|
||||
public void OnOpenLocalScriptRepo()
|
||||
{
|
||||
Config.ScriptConfig.ScriptRepoHintDotVisible = false;
|
||||
ScriptRepoUpdater.Instance.OpenLocalRepoInWebView();
|
||||
ScriptRepoUpdater.Instance.OpenScriptRepoWindow();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using System;
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
using BetterGenshinImpact.Core.Script.Group;
|
||||
using BetterGenshinImpact.Core.Script.Project;
|
||||
using BetterGenshinImpact.GameTask.AutoPathing;
|
||||
@@ -21,6 +22,14 @@ using Wpf.Ui.Violeta.Controls;
|
||||
using BetterGenshinImpact.View.Pages.View;
|
||||
using BetterGenshinImpact.ViewModel.Pages.View;
|
||||
using Wpf.Ui.Violeta.Win32;
|
||||
using BetterGenshinImpact.View.Controls.Drawer;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.ComponentModel;
|
||||
using BetterGenshinImpact.View.Controls.Webview;
|
||||
using Microsoft.Web.WebView2.Wpf;
|
||||
using BetterGenshinImpact.Helpers;
|
||||
|
||||
namespace BetterGenshinImpact.ViewModel.Pages;
|
||||
|
||||
@@ -39,6 +48,15 @@ public partial class MapPathingViewModel : ViewModel
|
||||
private readonly IScriptService _scriptService;
|
||||
|
||||
public AllConfig Config { get; set; }
|
||||
|
||||
// 添加抽屉ViewModel
|
||||
public DrawerViewModel DrawerVm { get; } = new DrawerViewModel();
|
||||
|
||||
// 添加WebView2相关成员变量
|
||||
private WebView2? _webView2;
|
||||
private WebpagePanel? _mdWebpagePanel;
|
||||
private TaskCompletionSource<bool>? _navigationCompletionSource;
|
||||
private const int NavigationTimeoutMs = 10000; // 10秒超时
|
||||
|
||||
/// <inheritdoc/>
|
||||
public MapPathingViewModel(IScriptService scriptService, IConfigService configService)
|
||||
@@ -57,20 +75,28 @@ public partial class MapPathingViewModel : ViewModel
|
||||
// 循环写入 root.Children
|
||||
foreach (var item in root.Children)
|
||||
{
|
||||
// 补充图标
|
||||
if (!string.IsNullOrEmpty(item.FilePath) && File.Exists(Path.Combine(item.FilePath, "icon.ico")))
|
||||
{
|
||||
item.IconFilePath = Path.Combine(item.FilePath, "icon.ico");
|
||||
}
|
||||
else
|
||||
{
|
||||
item.IconFilePath = item.FilePath;
|
||||
}
|
||||
|
||||
SetIconForNodeAndChildren(item);
|
||||
TreeList.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetIconForNodeAndChildren(FileTreeNode<PathingTask> node)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(node.FilePath) && File.Exists(Path.Combine(node.FilePath, "icon.ico")))
|
||||
{
|
||||
node.IconFilePath = Path.Combine(node.FilePath, "icon.ico");
|
||||
}
|
||||
else
|
||||
{
|
||||
node.IconFilePath = node.FilePath;
|
||||
}
|
||||
|
||||
foreach (var child in node.Children)
|
||||
{
|
||||
SetIconForNodeAndChildren(child);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnNavigatedTo()
|
||||
{
|
||||
InitScriptListViewData();
|
||||
@@ -171,6 +197,222 @@ public partial class MapPathingViewModel : ViewModel
|
||||
public void OnOpenLocalScriptRepo()
|
||||
{
|
||||
Config.ScriptConfig.ScriptRepoHintDotVisible = false;
|
||||
ScriptRepoUpdater.Instance.OpenLocalRepoInWebView();
|
||||
ScriptRepoUpdater.Instance.OpenScriptRepoWindow();
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void OnOpenPathingDetail()
|
||||
{
|
||||
var item = SelectNode;
|
||||
if (item == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果是目录,检查是否存在README.md
|
||||
string? mdFilePath = null;
|
||||
if (item.IsDirectory && !string.IsNullOrEmpty(item.FilePath))
|
||||
{
|
||||
mdFilePath = FindMdFilePath(item.FilePath);
|
||||
}
|
||||
|
||||
// 设置抽屉位置和大小
|
||||
DrawerVm.DrawerPosition = DrawerPosition.Right;
|
||||
|
||||
if (!string.IsNullOrEmpty(mdFilePath))
|
||||
{
|
||||
DrawerVm.DrawerWidth = 450;
|
||||
// 注册抽屉关闭前事件
|
||||
DrawerVm.SetDrawerClosingAction(args =>
|
||||
{
|
||||
if (_mdWebpagePanel != null)
|
||||
{
|
||||
_mdWebpagePanel.Visibility = Visibility.Hidden;
|
||||
}
|
||||
});
|
||||
DrawerVm.setDrawerOpenedAction(async () =>
|
||||
{
|
||||
if (_mdWebpagePanel != null)
|
||||
{
|
||||
// 等待导航完成或超时
|
||||
try
|
||||
{
|
||||
await WaitForNavigationCompletedWithTimeout();
|
||||
_mdWebpagePanel.Visibility = Visibility.Visible;
|
||||
_mdWebpagePanel.WebView.Focus();
|
||||
Debug.WriteLine("Navigation completed successfully");
|
||||
}
|
||||
catch (TimeoutException)
|
||||
{
|
||||
Toast.Error("Markdown内容加载超时");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawerVm.DrawerWidth = 350;
|
||||
DrawerVm.SetDrawerClosingAction(_ => { });
|
||||
DrawerVm.setDrawerOpenedAction(() => { });
|
||||
}
|
||||
|
||||
// 创建要在抽屉中显示的内容
|
||||
var content = CreatePathingDetailContent(item, mdFilePath);
|
||||
|
||||
// 打开抽屉
|
||||
if (content != null)
|
||||
{
|
||||
DrawerVm.OpenDrawer(content);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task WaitForNavigationCompletedWithTimeout()
|
||||
{
|
||||
var completedTask = await Task.WhenAny(
|
||||
_navigationCompletionSource!.Task,
|
||||
Task.Delay(NavigationTimeoutMs)
|
||||
);
|
||||
|
||||
if (completedTask != _navigationCompletionSource.Task)
|
||||
{
|
||||
throw new TimeoutException("Navigation did not complete within the timeout period");
|
||||
}
|
||||
}
|
||||
|
||||
private string? FindMdFilePath(string dirPath)
|
||||
{
|
||||
string[] possibleMdFiles = { "README.md", "readme.md" };
|
||||
|
||||
foreach (var mdFile in possibleMdFiles)
|
||||
{
|
||||
string fullPath = Path.Combine(dirPath, mdFile);
|
||||
if (File.Exists(fullPath))
|
||||
{
|
||||
return fullPath;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private object? CreatePathingDetailContent(FileTreeNode<PathingTask> node, string? mdFilePath = null)
|
||||
{
|
||||
// 创建显示路径任务详情的控件
|
||||
var border = new Border
|
||||
{
|
||||
Background = new SolidColorBrush(Color.FromRgb(0x2B, 0x2B, 0x2B)),
|
||||
Padding = new Thickness(20)
|
||||
};
|
||||
|
||||
var panel = new StackPanel();
|
||||
border.Child = panel;
|
||||
|
||||
// 添加标题
|
||||
panel.Children.Add(new TextBlock
|
||||
{
|
||||
Text = node.FileName,
|
||||
FontSize = 20,
|
||||
FontWeight = FontWeights.Bold,
|
||||
Margin = new Thickness(0, 0, 0, 10)
|
||||
});
|
||||
|
||||
// 如果找到md文件,使用WebpagePanel显示
|
||||
if (!string.IsNullOrEmpty(mdFilePath))
|
||||
{
|
||||
// 使用Grid作为容器来实现填充效果
|
||||
var grid = new Grid
|
||||
{
|
||||
Margin = new Thickness(0, 0, 0, 15)
|
||||
};
|
||||
|
||||
_mdWebpagePanel = new WebpagePanel
|
||||
{
|
||||
Margin = new Thickness(0),
|
||||
Visibility = Visibility.Hidden,
|
||||
VerticalAlignment = VerticalAlignment.Stretch,
|
||||
HorizontalAlignment = HorizontalAlignment.Stretch
|
||||
};
|
||||
|
||||
_navigationCompletionSource = new TaskCompletionSource<bool>();
|
||||
_mdWebpagePanel.OnNavigationCompletedAction = (_) =>
|
||||
{
|
||||
// 导航完成时设置任务结果
|
||||
_navigationCompletionSource.TrySetResult(true);
|
||||
};
|
||||
_mdWebpagePanel.NavigateToMd(File.ReadAllText(mdFilePath));
|
||||
|
||||
grid.Children.Add(_mdWebpagePanel);
|
||||
panel.Children.Add(grid);
|
||||
|
||||
// 设置Grid高度以占满剩余空间
|
||||
panel.SizeChanged += (sender, args) =>
|
||||
{
|
||||
// 计算其他元素使用的高度
|
||||
double otherElementsHeight = 0;
|
||||
foreach (var child in panel.Children)
|
||||
{
|
||||
if (child != grid)
|
||||
{
|
||||
var frameworkElement = child as FrameworkElement;
|
||||
if (frameworkElement != null)
|
||||
{
|
||||
otherElementsHeight += frameworkElement.ActualHeight + frameworkElement.Margin.Top + frameworkElement.Margin.Bottom;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 设置Grid高度为剩余空间
|
||||
grid.Height = Math.Max(400, panel.ActualHeight - otherElementsHeight - 15); // 设置最小高度为400
|
||||
};
|
||||
}
|
||||
else if (!node.IsDirectory && !string.IsNullOrEmpty(node.FilePath))
|
||||
{
|
||||
// 如果是文件而不是目录,显示更多详情
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(node.Value?.Info.Description))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
panel.Children.Add(new TextBlock
|
||||
{
|
||||
Text = $"{node.Value?.Info.Description}",
|
||||
TextWrapping = TextWrapping.Wrap,
|
||||
Margin = new Thickness(0, 5, 0, 5)
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
panel.Children.Add(new TextBlock
|
||||
{
|
||||
Text = $"读取文件信息时出错: {ex.Message}",
|
||||
TextWrapping = TextWrapping.Wrap,
|
||||
Margin = new Thickness(0, 5, 0, 5)
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 显示目录信息
|
||||
panel.Children.Add(new TextBlock
|
||||
{
|
||||
Text = "这是一个目录,包含多个地图追踪任务。",
|
||||
TextWrapping = TextWrapping.Wrap,
|
||||
Margin = new Thickness(0, 5, 0, 15)
|
||||
});
|
||||
|
||||
// 添加子项信息
|
||||
if (node.Children.Count > 0)
|
||||
{
|
||||
panel.Children.Add(new TextBlock
|
||||
{
|
||||
Text = $"包含 {node.Children.Count} 个子项",
|
||||
Margin = new Thickness(0, 5, 0, 5)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return border;
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ using BetterGenshinImpact.Core.Script.Project;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
using BetterGenshinImpact.GameTask.AutoPathing.Model;
|
||||
using BetterGenshinImpact.GameTask.LogParse;
|
||||
using BetterGenshinImpact.GameTask.TaskProgress;
|
||||
using BetterGenshinImpact.Helpers.Ui;
|
||||
using BetterGenshinImpact.Model;
|
||||
using BetterGenshinImpact.Service.Interface;
|
||||
@@ -36,6 +37,7 @@ using Wpf.Ui.Violeta.Controls;
|
||||
using StackPanel = Wpf.Ui.Controls.StackPanel;
|
||||
using TextBox = Wpf.Ui.Controls.TextBox;
|
||||
using Button = Wpf.Ui.Controls.Button;
|
||||
using MessageBoxButton = System.Windows.MessageBoxButton;
|
||||
using MessageBoxResult = Wpf.Ui.Controls.MessageBoxResult;
|
||||
using TextBlock = Wpf.Ui.Controls.TextBlock;
|
||||
|
||||
@@ -105,7 +107,7 @@ public partial class ScriptControlViewModel : ViewModel
|
||||
private void ClearTasks()
|
||||
{
|
||||
// 确认?
|
||||
var result = MessageBox.Show("是否清空所有任务?", "清空任务", System.Windows.MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
var result = MessageBox.Show("是否清空所有任务?", "清空任务", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
if (result != System.Windows.MessageBoxResult.Yes)
|
||||
{
|
||||
return;
|
||||
@@ -449,7 +451,7 @@ public partial class ScriptControlViewModel : ViewModel
|
||||
public void OnOpenLocalScriptRepo()
|
||||
{
|
||||
TaskContext.Instance().Config.ScriptConfig.ScriptRepoHintDotVisible = false;
|
||||
ScriptRepoUpdater.Instance.OpenLocalRepoInWebView();
|
||||
ScriptRepoUpdater.Instance.OpenScriptRepoWindow();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
@@ -510,6 +512,21 @@ public partial class ScriptControlViewModel : ViewModel
|
||||
if (SelectedScriptGroup != null) WriteScriptGroup(SelectedScriptGroup);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void AddScriptGroupNextFlag(ScriptGroup? item)
|
||||
{
|
||||
foreach (var scriptGroup in ScriptGroups)
|
||||
{
|
||||
scriptGroup.NextFlag = false;
|
||||
}
|
||||
|
||||
if (item!=null)
|
||||
{
|
||||
item.NextFlag = true;
|
||||
TaskContext.Instance().Config.NextScriptGroupName = item.Name;
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void OnCopyScriptGroup(ScriptGroup? item)
|
||||
{
|
||||
@@ -577,6 +594,10 @@ public partial class ScriptControlViewModel : ViewModel
|
||||
{
|
||||
File.Move(Path.Combine(ScriptGroupPath, $"{item.Name}.json"), Path.Combine(ScriptGroupPath, $"{str}.json"));
|
||||
item.Name = str;
|
||||
if (item.NextFlag)
|
||||
{
|
||||
TaskContext.Instance().Config.NextScriptGroupName = item.Name;
|
||||
}
|
||||
WriteScriptGroup(item);
|
||||
}
|
||||
}
|
||||
@@ -1124,6 +1145,22 @@ public partial class ScriptControlViewModel : ViewModel
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetTaskContextNextFlag(ScriptGroup group)
|
||||
{
|
||||
var nst = TaskContext.Instance().Config.NextScheduledTask.Find(item => item.Item1 == group.Name);
|
||||
foreach (var item in group.Projects)
|
||||
{
|
||||
item.NextFlag = false;
|
||||
if (nst != default)
|
||||
{
|
||||
if (nst.Item2 == item.Index && nst.Item3 == item.FolderName && nst.Item4 == item.Name)
|
||||
{
|
||||
item.NextFlag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ReadScriptGroup()
|
||||
{
|
||||
try
|
||||
@@ -1142,21 +1179,11 @@ public partial class ScriptControlViewModel : ViewModel
|
||||
{
|
||||
var json = File.ReadAllText(file);
|
||||
var group = ScriptGroup.FromJson(json);
|
||||
|
||||
|
||||
var nst = TaskContext.Instance().Config.NextScheduledTask.Find(item => item.Item1 == group.Name);
|
||||
foreach (var item in group.Projects)
|
||||
SetTaskContextNextFlag(group);
|
||||
if (group.Name == TaskContext.Instance().Config.NextScriptGroupName)
|
||||
{
|
||||
item.NextFlag = false;
|
||||
if (nst != default)
|
||||
{
|
||||
if (nst.Item2 == item.Index && nst.Item3 == item.FolderName && nst.Item4 == item.Name)
|
||||
{
|
||||
item.NextFlag = true;
|
||||
}
|
||||
}
|
||||
group.NextFlag = true;
|
||||
}
|
||||
|
||||
groups.Add(group);
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -1239,7 +1266,15 @@ public partial class ScriptControlViewModel : ViewModel
|
||||
}
|
||||
|
||||
RunnerContext.Instance.Reset();
|
||||
await _scriptService.RunMulti(GetNextProjects(SelectedScriptGroup), SelectedScriptGroup.Name);
|
||||
|
||||
TaskProgress taskProgress = new()
|
||||
{
|
||||
ScriptGroupNames = [SelectedScriptGroup.Name]
|
||||
};
|
||||
RunnerContext.Instance.taskProgress = taskProgress;
|
||||
taskProgress.CurrentScriptGroupName = SelectedScriptGroup.Name;
|
||||
TaskProgressManager.SaveTaskProgress(taskProgress);
|
||||
await _scriptService.RunMulti(GetNextProjects(SelectedScriptGroup), SelectedScriptGroup.Name,taskProgress);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
@@ -1282,49 +1317,219 @@ public partial class ScriptControlViewModel : ViewModel
|
||||
WriteScriptGroup(SelectedScriptGroup);
|
||||
}
|
||||
|
||||
public static List<ScriptGroupProject> GetNextProjects(ScriptGroup group)
|
||||
public static List<ScriptGroup> GetNextScriptGroups(List<ScriptGroup> groups)
|
||||
{
|
||||
List<ScriptGroupProject> ls = new List<ScriptGroupProject>();
|
||||
bool start = false;
|
||||
foreach (var item in group.Projects)
|
||||
if (groups.Where(g => g.NextFlag).Count() > 0)
|
||||
{
|
||||
if (item.NextFlag ?? false)
|
||||
List<ScriptGroup> ng = new();
|
||||
bool start = false;
|
||||
foreach (var group in groups)
|
||||
{
|
||||
start = true;
|
||||
}
|
||||
|
||||
if (start)
|
||||
{
|
||||
ls.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
if (!start)
|
||||
{
|
||||
ls.AddRange(group.Projects);
|
||||
}
|
||||
|
||||
//拿出来后清空,和置状态
|
||||
if (start)
|
||||
{
|
||||
List<ValueTuple<string, int, string, string>> nextScheduledTask = TaskContext.Instance().Config.NextScheduledTask;
|
||||
foreach (var item in nextScheduledTask)
|
||||
{
|
||||
if (item.Item1 == group.Name)
|
||||
if (group.NextFlag)
|
||||
{
|
||||
nextScheduledTask.Remove(item);
|
||||
break;
|
||||
start = true;
|
||||
group.NextFlag = false;
|
||||
TaskContext.Instance().Config.NextScriptGroupName = String.Empty;
|
||||
}
|
||||
|
||||
if (start)
|
||||
{
|
||||
ng.Add(group);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in group.Projects)
|
||||
{
|
||||
item.NextFlag = false;
|
||||
}
|
||||
return ng;
|
||||
}
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
return ls;
|
||||
public static List<ScriptGroupProject> GetNextProjects(ScriptGroup group)
|
||||
{
|
||||
SetTaskContextNextFlag(group);
|
||||
List<ScriptGroupProject> ls = new List<ScriptGroupProject>();
|
||||
if (group.Projects.Where(g=>g.NextFlag ?? false).Count() > 0)
|
||||
{
|
||||
bool start = false;
|
||||
foreach (var item in group.Projects)
|
||||
{
|
||||
if (item.NextFlag ?? false)
|
||||
{
|
||||
start = true;
|
||||
}
|
||||
|
||||
if (!start)
|
||||
{
|
||||
item.SkipFlag = true;
|
||||
}
|
||||
ls.Add(item);
|
||||
}
|
||||
|
||||
if (!start)
|
||||
{
|
||||
ls.AddRange(group.Projects);
|
||||
}
|
||||
|
||||
//拿出来后清空,和置状态
|
||||
if (start)
|
||||
{
|
||||
List<ValueTuple<string, int, string, string>> nextScheduledTask = TaskContext.Instance().Config.NextScheduledTask;
|
||||
foreach (var item in nextScheduledTask)
|
||||
{
|
||||
if (item.Item1 == group.Name)
|
||||
{
|
||||
nextScheduledTask.Remove(item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in group.Projects)
|
||||
{
|
||||
item.NextFlag = false;
|
||||
}
|
||||
}
|
||||
|
||||
return ls;
|
||||
}
|
||||
|
||||
return group.Projects.Select(g=>g).ToList();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public async Task OnContinueMultiScriptGroupAsync()
|
||||
{
|
||||
// 创建一个 StackPanel 来包含全选按钮和所有配置组的 CheckBox
|
||||
|
||||
// 创建一个 StackPanel 来包含全选按钮和所有配置组的 CheckBox
|
||||
var stackPanel = new StackPanel();
|
||||
|
||||
|
||||
// 添加分割线
|
||||
var separator = new Separator
|
||||
{
|
||||
Margin = new Thickness(0, 4, 0, 4)
|
||||
};
|
||||
stackPanel.Children.Add(separator);
|
||||
|
||||
List<TaskProgress> taskProgresses = TaskProgressManager.LoadAllTaskProgress();
|
||||
var checkBox = new ComboBox();;
|
||||
stackPanel.Children.Add(checkBox);
|
||||
ObservableCollection<KeyValuePair<string, string>> kvs=new ObservableCollection<KeyValuePair<string, string>>();
|
||||
foreach (var taskProgress in taskProgresses)
|
||||
{
|
||||
var name = taskProgress.Name+"_"+taskProgress.CurrentScriptGroupName+"_";
|
||||
if (taskProgress.Loop)
|
||||
{
|
||||
name += "循环("+taskProgress.LoopCount+")_";
|
||||
}
|
||||
if (taskProgress.CurrentScriptGroupProjectInfo!=null)
|
||||
{
|
||||
name = name +taskProgress.CurrentScriptGroupProjectInfo.Index+ "_" + taskProgress.CurrentScriptGroupProjectInfo.Name;
|
||||
}
|
||||
kvs.Add(new KeyValuePair<string, string>(taskProgress.Name,name));
|
||||
}
|
||||
|
||||
checkBox.SelectedValuePath = "Key";
|
||||
checkBox.DisplayMemberPath = "Value";
|
||||
checkBox.ItemsSource = kvs;
|
||||
checkBox.SelectedIndex = 0;
|
||||
//SelectedValuePath="Key"
|
||||
// DisplayMemberPath="Value"
|
||||
var uiMessageBox = new Wpf.Ui.Controls.MessageBox
|
||||
{
|
||||
Title = "选择需要继续执行的进度记录",
|
||||
Content = new ScrollViewer
|
||||
{
|
||||
Content = stackPanel,
|
||||
VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
|
||||
Height = 300 // 设置固定高度
|
||||
,Width = 600
|
||||
},
|
||||
CloseButtonText = "关闭",
|
||||
PrimaryButtonText = "确认执行",
|
||||
Owner = Application.Current.MainWindow,
|
||||
WindowStartupLocation = WindowStartupLocation.CenterOwner,
|
||||
};
|
||||
|
||||
var result = await uiMessageBox.ShowDialogAsync();
|
||||
if (result == MessageBoxResult.Primary)
|
||||
{
|
||||
|
||||
/*var selectedGroups = checkBoxes
|
||||
.Where(kv => kv.Value.IsChecked == true)
|
||||
.Select(kv => kv.Key)
|
||||
.ToList();*/
|
||||
Object val = checkBox.SelectedValue;
|
||||
if (val == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
await OnContinueTaskProgressAsync(Convert.ToString(val), taskProgresses);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public async Task OnContinueTaskProgressAsync(string name,List<TaskProgress>? taskProgresses = null)
|
||||
{
|
||||
if (taskProgresses == null)
|
||||
{
|
||||
taskProgresses = TaskProgressManager.LoadAllTaskProgress();
|
||||
}
|
||||
TaskProgress? taskProgress = null;
|
||||
if (name == "latest")
|
||||
{
|
||||
if (taskProgresses.Count > 0)
|
||||
{
|
||||
taskProgress = taskProgresses[0];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
taskProgress=taskProgresses.FirstOrDefault(t=>t.Name == name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (taskProgress!=null)
|
||||
{
|
||||
//await StartGroups(selectedGroups);
|
||||
//taskProgress.Next
|
||||
var sg = ScriptGroups.ToList().Where(sg => taskProgress.ScriptGroupNames.Contains(sg.Name)).ToList();
|
||||
TaskProgressManager.GenerNextProjectInfo(taskProgress,sg);
|
||||
if (taskProgress.Next==null)
|
||||
{
|
||||
_logger.LogWarning("无法定位到下一个要执行的项目:next为空("+taskProgress.Name+")");
|
||||
}
|
||||
else
|
||||
{
|
||||
await StartGroups(sg,taskProgress);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("无法定位到下一个要执行的项目:taskProgress为空");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task OnStartMultiScriptTaskProgressAsync(params string[] names)
|
||||
{
|
||||
if (ScriptGroups.Count == 0)
|
||||
{
|
||||
ReadScriptGroup();
|
||||
}
|
||||
|
||||
string taskProgressName;
|
||||
if (names == null || names.Length == 0)
|
||||
{
|
||||
taskProgressName = "latest";
|
||||
}
|
||||
else
|
||||
{
|
||||
taskProgressName = names[0];
|
||||
}
|
||||
|
||||
await OnContinueTaskProgressAsync(taskProgressName);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
@@ -1334,6 +1539,13 @@ public partial class ScriptControlViewModel : ViewModel
|
||||
var stackPanel = new StackPanel();
|
||||
var checkBoxes = new Dictionary<ScriptGroup, CheckBox>();
|
||||
|
||||
|
||||
var loopCheckBox = new CheckBox
|
||||
{
|
||||
Content = "循环",
|
||||
};
|
||||
|
||||
|
||||
// 创建全选按钮
|
||||
var selectAllCheckBox = new CheckBox
|
||||
{
|
||||
@@ -1353,6 +1565,7 @@ public partial class ScriptControlViewModel : ViewModel
|
||||
checkBox.IsChecked = false;
|
||||
}
|
||||
};
|
||||
stackPanel.Children.Add(loopCheckBox);
|
||||
stackPanel.Children.Add(selectAllCheckBox);
|
||||
// 添加分割线
|
||||
var separator = new Separator
|
||||
@@ -1396,7 +1609,7 @@ public partial class ScriptControlViewModel : ViewModel
|
||||
.Select(kv => kv.Key)
|
||||
.ToList();
|
||||
|
||||
await StartGroups(selectedGroups);
|
||||
await StartGroups(selectedGroups,null,loopCheckBox.IsChecked ?? false);;
|
||||
}
|
||||
}
|
||||
public async Task OnStartMultiScriptGroupWithNamesAsync(params string[] names)
|
||||
@@ -1429,17 +1642,56 @@ public partial class ScriptControlViewModel : ViewModel
|
||||
}
|
||||
}
|
||||
|
||||
public async Task StartGroups(List<ScriptGroup> scriptGroups)
|
||||
public async Task StartGroups(List<ScriptGroup> scriptGroups,TaskProgress? taskProgress = null,bool loop = false)
|
||||
{
|
||||
_logger.LogInformation("开始连续执行选中配置组:{Names}", string.Join(",", scriptGroups.Select(x => x.Name)));
|
||||
try
|
||||
{
|
||||
RunnerContext.Instance.IsContinuousRunGroup = true;
|
||||
foreach (var scriptGroup in scriptGroups)
|
||||
if (taskProgress == null)
|
||||
{
|
||||
await _scriptService.RunMulti(GetNextProjects(scriptGroup), scriptGroup.Name);
|
||||
taskProgress = new()
|
||||
{
|
||||
ScriptGroupNames = scriptGroups.Select(x => x.Name).ToList()
|
||||
,Loop = loop
|
||||
};
|
||||
}
|
||||
|
||||
RunnerContext.Instance.taskProgress = taskProgress;
|
||||
var sg = GetNextScriptGroups(scriptGroups);
|
||||
foreach (var scriptGroup in sg)
|
||||
{
|
||||
if (taskProgress.Next!=null)
|
||||
{
|
||||
if (scriptGroup.Name!=taskProgress.Next.GroupName)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
taskProgress.CurrentScriptGroupName = scriptGroup.Name;
|
||||
TaskProgressManager.SaveTaskProgress(taskProgress);
|
||||
await _scriptService.RunMulti(GetNextProjects(scriptGroup), scriptGroup.Name,taskProgress);
|
||||
await Task.Delay(2000);
|
||||
}
|
||||
|
||||
taskProgress.LoopCount++;
|
||||
if (taskProgress is { Loop: true })
|
||||
{
|
||||
taskProgress.LastScriptGroupName = null;
|
||||
taskProgress.LastSuccessScriptGroupProjectInfo = null;
|
||||
taskProgress.Next = null;
|
||||
await StartGroups(scriptGroups, taskProgress);
|
||||
}
|
||||
else
|
||||
{
|
||||
//只有最后一次成功才算
|
||||
if (taskProgress.ConsecutiveFailureCount == 0)
|
||||
{
|
||||
taskProgress.EndTime = DateTime.Now;
|
||||
TaskProgressManager.SaveTaskProgress(taskProgress);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -1449,5 +1701,7 @@ public partial class ScriptControlViewModel : ViewModel
|
||||
{
|
||||
RunnerContext.Instance.Reset();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ public partial class AutoFightViewModel : ObservableObject, IViewModel
|
||||
public void OnOpenLocalScriptRepo()
|
||||
{
|
||||
Config.ScriptConfig.ScriptRepoHintDotVisible = false;
|
||||
ScriptRepoUpdater.Instance.OpenLocalRepoInWebView();
|
||||
ScriptRepoUpdater.Instance.OpenScriptRepoWindow();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
|
||||
Reference in new issue
Block a user