Files
better-genshin-impact/BetterGenshinImpact/ViewModel/Pages/CommonSettingsPageViewModel.cs
mfkvfhpdx 4760752e70 在调度器里面的任务之前,增加月卡处理,解决4点如果未进入任务会卡住的问题。增加了日志分析小怪详细。解决日志分析兜底结束日期不生效的问题。 (#1433)
* 修改调度器任务和部分独立任务失去焦点时,强制切换回游戏窗口,如果用常规的方式无法激活窗口,则第10次会尝试最小化所有窗口后激活游戏。

* 去除未引入的类引用

* 修正战斗结束后,大概率打开队伍界面的问题

* 修复有些电脑上因未知原因,战斗0秒打断

* 把失焦激活放入了设置-通用设置-其他设置中,默认关闭。暂停恢复时,重置移动的起始时间,防止因暂停而导致超时放弃任务。

* 在调度器里面的任务之前,增加月卡处理,解决4点如果未进入任务会卡住的问题。增加了日志分析小怪详细。解决日志分析兜底结束日期不生效的问题。

* 在设置=》其他设置中 增加调度器任务传送过程中自动领取探索奖励功能配置。

* 调整自动派遣后恢复原任务的逻辑

* 自动领取派遣奖励时,跳过异常,防止整个配置组任务被打断。

* 把打开大地图方法从TpTask中抽出为公共方法,自动领取派遣代码调整到了调度器中。

* 去除了未使用的引用

* 暂停恢复逻辑增加恢复中条件和非空判断

* 增加了临时暂停自动拾取的逻辑(RunnerContext.AutoPickTriggerStopCount 为0时不限制,大于0时停止,多次暂停会累加该值,每次恢复-1),支持嵌套情况的暂停,在自动派遣(和结束后5秒)或暂停调度器任务时,同时暂停自动拾取功能。

* 调整暂停拾取方法

* 调整个日志输出

* 路径追踪复苏时,暂停拾取
2025-04-26 21:47:57 +08:00

263 lines
8.0 KiB
C#

using System;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.Core.Recognition.OCR;
using BetterGenshinImpact.Core.Script;
using BetterGenshinImpact.GameTask;
using BetterGenshinImpact.GameTask.AutoTrackPath;
using BetterGenshinImpact.GameTask.Common.Element.Assets;
using BetterGenshinImpact.Helpers;
using BetterGenshinImpact.Service.Interface;
using BetterGenshinImpact.Service.Notification;
using BetterGenshinImpact.View.Converters;
using BetterGenshinImpact.View.Pages;
using BetterGenshinImpact.View.Windows;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging.Messages;
using Microsoft.Extensions.Localization;
using Microsoft.Win32;
using Wpf.Ui;
namespace BetterGenshinImpact.ViewModel.Pages;
public partial class CommonSettingsPageViewModel : ViewModel
{
private readonly INavigationService _navigationService;
private readonly NotificationService _notificationService;
private readonly TpConfig _tpConfig = TaskContext.Instance().Config.TpConfig;
private string _selectedArea = string.Empty;
private string _selectedCountry = string.Empty;
[ObservableProperty]
private List<string> _adventurersGuildCountry = ["无","枫丹", "稻妻", "璃月", "蒙德"];
public CommonSettingsPageViewModel(IConfigService configService, INavigationService navigationService,
NotificationService notificationService)
{
Config = configService.Get();
_navigationService = navigationService;
_notificationService = notificationService;
InitializeCountries();
}
public AllConfig Config { get; set; }
public ObservableCollection<string> CountryList { get; } = new();
public ObservableCollection<string> Areas { get; } = new();
[ObservableProperty]
private FrozenDictionary<string, string> _languageDict = new string[] { "zh-Hans", "zh-Hant", "en", "fr" }
.ToFrozenDictionary(
c => c,
c =>
{
CultureInfo.CurrentUICulture = new CultureInfo(c);
var stringLocalizer = App.GetService<IStringLocalizer<CultureInfoNameToKVPConverter>>() ?? throw new NullReferenceException();
return stringLocalizer["简体中文"].ToString();
}
);
public string SelectedCountry
{
get => _selectedCountry;
set
{
if (SetProperty(ref _selectedCountry, value))
{
UpdateAreas(value);
SelectedArea = Areas.FirstOrDefault() ?? string.Empty;
}
}
}
public string SelectedArea
{
get => _selectedArea;
set
{
if (SetProperty(ref _selectedArea, value))
{
UpdateRevivePoint(SelectedCountry, SelectedArea);
}
}
}
private void InitializeCountries()
{
var countries = MapLazyAssets.Instance.GoddessPositions.Values
.OrderBy(g => int.TryParse(g.Id, out var id) ? id : int.MaxValue)
.GroupBy(g => g.Country)
.Select(grp => grp.Key);
CountryList.Clear();
foreach (var country in countries)
{
if (!string.IsNullOrEmpty(country))
{
CountryList.Add(country);
}
}
_selectedCountry = _tpConfig.ReviveStatueOfTheSevenCountry;
UpdateAreas(SelectedCountry);
_selectedArea = _tpConfig.ReviveStatueOfTheSevenArea;
UpdateRevivePoint(SelectedCountry, SelectedArea);
}
private void UpdateAreas(string country)
{
Areas.Clear();
SelectedArea = string.Empty;
if (string.IsNullOrEmpty(country)) return;
var areas = MapLazyAssets.Instance.GoddessPositions.Values
.Where(g => g.Country == country)
.OrderBy(g => int.TryParse(g.Id, out var id) ? id : int.MaxValue)
.GroupBy(g => g.Area)
.Select(grp => grp.Key);
foreach (var area in areas)
{
if (!string.IsNullOrEmpty(area))
{
Areas.Add(area);
}
}
}
// 当国家或区域改变时更新坐标
private void UpdateRevivePoint(string country, string area)
{
if (string.IsNullOrEmpty(country) || string.IsNullOrEmpty(area)) return;
var goddess = MapLazyAssets.Instance.GoddessPositions.Values
.FirstOrDefault(g => g.Country == country && g.Area == area);
if (goddess == null) return;
_tpConfig.ReviveStatueOfTheSevenCountry = country;
_tpConfig.ReviveStatueOfTheSevenArea = area;
_tpConfig.ReviveStatueOfTheSevenPointX = goddess.X;
_tpConfig.ReviveStatueOfTheSevenPointY = goddess.Y;
_tpConfig.ReviveStatueOfTheSeven = goddess;
}
[RelayCommand]
public void OnRefreshMaskSettings()
{
WeakReferenceMessenger.Default.Send(
new PropertyChangedMessage<object>(this, "RefreshSettings", new object(), "重新计算控件位置"));
}
[RelayCommand]
private void OnSwitchMaskEnabled()
{
// if (Config.MaskWindowConfig.MaskEnabled)
// {
// MaskWindow.Instance().Show();
// }
// else
// {
// MaskWindow.Instance().Hide();
// }
}
[RelayCommand]
public void OnGoToHotKeyPage()
{
_navigationService.Navigate(typeof(HotKeyPage));
}
[RelayCommand]
public void OnSwitchTakenScreenshotEnabled()
{
}
[RelayCommand]
public void OnGoToFolder()
{
var path = Global.Absolute(@"log\screenshot\");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
Process.Start("explorer.exe", path);
}
[RelayCommand]
public void OnGoToLogFolder()
{
var path = Global.Absolute(@"log");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
Process.Start("explorer.exe", path);
}
[RelayCommand]
private void ImportLocalScriptsRepoZip()
{
Directory.CreateDirectory(ScriptRepoUpdater.ReposPath);
var dialog = new OpenFileDialog
{
Filter = "Zip Files (*.zip)|*.zip",
Multiselect = false
};
if (dialog.ShowDialog() == true)
{
var zipPath = dialog.FileName;
// 删除旧文件夹
if (Directory.Exists(ScriptRepoUpdater.CenterRepoPath))
{
DirectoryHelper.DeleteReadOnlyDirectory(ScriptRepoUpdater.CenterRepoPath);
}
ZipFile.ExtractToDirectory(zipPath, ScriptRepoUpdater.ReposPath, true);
if (Directory.Exists(ScriptRepoUpdater.CenterRepoPath))
{
MessageBox.Information("脚本仓库离线包导入成功!");
}
else
{
MessageBox.Error("脚本仓库离线包导入失败,不正确的脚本仓库离线包内容!");
DirectoryHelper.DeleteReadOnlyDirectory(ScriptRepoUpdater.ReposPath);
}
}
}
[RelayCommand]
private void OpenAboutWindow()
{
var aboutWindow = new AboutWindow();
aboutWindow.Owner = Application.Current.MainWindow;
aboutWindow.ShowDialog();
}
[RelayCommand]
private void OpenKeyBindingsWindow()
{
var keyBindingsWindow = KeyBindingsWindow.Instance;
keyBindingsWindow.Owner = Application.Current.MainWindow;
keyBindingsWindow.ShowDialog();
}
[RelayCommand]
private async Task OnGameLangSelectionChanged(KeyValuePair<string, string> type)
{
await OcrFactory.ChangeCulture(type.Key);
}
}