Files
better-genshin-impact/BetterGenshinImpact/ViewModel/Pages/MapPathingViewModel.cs
辉鸭蛋 a06f0fcdb2 auto pathing: fix not releasing the mouse and keyboard when stopping tasks
更新日志和黑名单

移除 `PathExecutor.cs` 中的无用引用,重构 `Pathing` 方法,添加 `InitializePathing` 和 `ConvertWaypoints` 方法,提取传送点处理逻辑到 `HandleTeleportWaypoint` 方法。修改 `TpTask.cs` 中的日志格式为浮点数格式。将 `TaskRunner.cs` 中的 `FireAndForgetAsync` 方法重命名为 `RunThreadAsync`,并在 `ScriptService.cs` 中相应替换调用。为 `DpiHelper.cs` 中的 `ScaleY` 属性添加注释。更新 `pick_black_lists.json`,添加新的黑名单项 `"摆放巧像"`。在 `MapPathingViewModel.cs` 中添加 `_mapViewer` 字段,并在 `OnOpenMapViewer` 方法中使用。
2024-09-09 21:57:48 +08:00

115 lines
3.0 KiB
C#

using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.Core.Script;
using BetterGenshinImpact.Core.Script.Project;
using BetterGenshinImpact.GameTask;
using BetterGenshinImpact.GameTask.AutoPathing;
using BetterGenshinImpact.GameTask.AutoPathing.Model;
using BetterGenshinImpact.GameTask.Model.Enum;
using BetterGenshinImpact.View.Windows;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Wpf.Ui.Controls;
using Wpf.Ui.Violeta.Controls;
namespace BetterGenshinImpact.ViewModel.Pages;
public partial class MapPathingViewModel : ObservableObject, INavigationAware, IViewModel
{
private readonly ILogger<MapPathingViewModel> _logger = App.GetLogger<MapPathingViewModel>();
public static readonly string PathJsonPath = Global.Absolute(@"User\AutoPathing");
[ObservableProperty]
private ObservableCollection<PathingTask> _pathItems = [];
private MapViewer? _mapViewer;
private void InitScriptListViewData()
{
_pathItems.Clear();
var fileInfos = LoadScriptFolder(PathJsonPath);
foreach (var f in fileInfos)
{
try
{
_pathItems.Add(PathingTask.BuildFromFilePath(f.FullName));
}
catch (Exception e)
{
Toast.Warning($"地图追踪任务 {f.Name} 载入失败:{e.Message}");
}
}
}
private IEnumerable<FileInfo> LoadScriptFolder(string folder)
{
if (!Directory.Exists(folder))
{
Directory.CreateDirectory(folder);
}
var files = Directory.GetFiles(folder, "*.*",
SearchOption.AllDirectories);
return files.Select(file => new FileInfo(file)).ToList();
}
public void OnNavigatedTo()
{
InitScriptListViewData();
}
public void OnNavigatedFrom()
{
}
[RelayCommand]
public void OnOpenScriptsFolder()
{
if (!Directory.Exists(PathJsonPath))
{
Directory.CreateDirectory(PathJsonPath);
}
Process.Start("explorer.exe", PathJsonPath);
}
[RelayCommand]
public void OnOpenScriptProjectFolder(ScriptProject? item)
{
if (item == null)
{
return;
}
Process.Start("explorer.exe", item.ProjectPath);
}
[RelayCommand]
public void OnStart(PathingTask? item)
{
if (item == null)
{
return;
}
new TaskRunner(DispatcherTimerOperationEnum.UseCacheImageWithTriggerEmpty)
.FireAndForget(async () =>
{
TaskTriggerDispatcher.Instance().AddTrigger("AutoPick", null);
await new PathExecutor(CancellationContext.Instance.Cts).Pathing(item);
});
}
[RelayCommand]
public void OnOpenMapViewer()
{
_mapViewer ??= new MapViewer();
_mapViewer.Show();
}
}