From aedcb3dde51132da247d9976a67448ae00eb3e5d Mon Sep 17 00:00:00 2001 From: huiyadanli Date: Fri, 9 Feb 2024 13:05:14 +0800 Subject: [PATCH] optimize --- BetterGenshinImpact/BetterGenshinImpact.csproj | 2 +- BetterGenshinImpact/Core/Config/AllConfig.cs | 12 +++++------- .../Core/Config/MaskWindowConfig.cs | 2 +- .../GameTask/AutoSkip/Assets/AutoSkipAssets.cs | 8 +++++--- .../GameTask/TaskTriggerDispatcher.cs | 16 +++++++++++++++- .../ViewModel/Pages/HotKeyPageViewModel.cs | 3 ++- 6 files changed, 29 insertions(+), 14 deletions(-) diff --git a/BetterGenshinImpact/BetterGenshinImpact.csproj b/BetterGenshinImpact/BetterGenshinImpact.csproj index e6379089..dad05c3c 100644 --- a/BetterGenshinImpact/BetterGenshinImpact.csproj +++ b/BetterGenshinImpact/BetterGenshinImpact.csproj @@ -63,7 +63,7 @@ - Always + Never Code diff --git a/BetterGenshinImpact/Core/Config/AllConfig.cs b/BetterGenshinImpact/Core/Config/AllConfig.cs index d434b689..daa44000 100644 --- a/BetterGenshinImpact/Core/Config/AllConfig.cs +++ b/BetterGenshinImpact/Core/Config/AllConfig.cs @@ -1,18 +1,16 @@ using BetterGenshinImpact.GameTask; +using BetterGenshinImpact.GameTask.AutoDomain; +using BetterGenshinImpact.GameTask.AutoFight; using BetterGenshinImpact.GameTask.AutoFishing; +using BetterGenshinImpact.GameTask.AutoGeniusInvokation; using BetterGenshinImpact.GameTask.AutoPick; using BetterGenshinImpact.GameTask.AutoSkip; +using BetterGenshinImpact.GameTask.AutoWood; +using BetterGenshinImpact.GameTask.QuickTeleport; using CommunityToolkit.Mvvm.ComponentModel; using Fischless.GameCapture; using System; -using System.Collections.ObjectModel; using System.Text.Json.Serialization; -using BetterGenshinImpact.GameTask.AutoDomain; -using BetterGenshinImpact.GameTask.AutoFight; -using BetterGenshinImpact.Model; -using BetterGenshinImpact.GameTask.AutoGeniusInvokation; -using BetterGenshinImpact.GameTask.AutoWood; -using BetterGenshinImpact.GameTask.QuickTeleport; namespace BetterGenshinImpact.Core.Config { diff --git a/BetterGenshinImpact/Core/Config/MaskWindowConfig.cs b/BetterGenshinImpact/Core/Config/MaskWindowConfig.cs index 7fe15bdc..61a201fd 100644 --- a/BetterGenshinImpact/Core/Config/MaskWindowConfig.cs +++ b/BetterGenshinImpact/Core/Config/MaskWindowConfig.cs @@ -50,7 +50,7 @@ namespace BetterGenshinImpact.Core.Config /// /// 1080p下UID遮盖的位置与大小 /// - public Rect UidCoverRect { get; set; } = new(1695, 1052, 168, 22); + public Rect UidCoverRect { get; set; } = new(1690, 1052, 173, 22); /// /// 方位提示是否启用 diff --git a/BetterGenshinImpact/GameTask/AutoSkip/Assets/AutoSkipAssets.cs b/BetterGenshinImpact/GameTask/AutoSkip/Assets/AutoSkipAssets.cs index aefd3e96..7c6b6a11 100644 --- a/BetterGenshinImpact/GameTask/AutoSkip/Assets/AutoSkipAssets.cs +++ b/BetterGenshinImpact/GameTask/AutoSkip/Assets/AutoSkipAssets.cs @@ -58,12 +58,14 @@ public class AutoSkipAssets DrawOnWindow = true }.InitTemplate(); + + var optionRect = new Rect(info.CaptureAreaRect.Width / 2, 0, info.CaptureAreaRect.Width - info.CaptureAreaRect.Width / 2 - info.CaptureAreaRect.Width / 6, info.CaptureAreaRect.Height); OptionIconRo = new RecognitionObject { Name = "OptionIcon", RecognitionType = RecognitionTypes.TemplateMatch, TemplateImageMat = GameTaskManager.LoadAssetImage("AutoSkip", "icon_option.png"), - RegionOfInterest = new Rect(info.CaptureAreaRect.Width / 2, 0, info.CaptureAreaRect.Width - info.CaptureAreaRect.Width / 2, info.CaptureAreaRect.Height), + RegionOfInterest = optionRect, DrawOnWindow = false }.InitTemplate(); DailyRewardIconRo = new RecognitionObject @@ -71,7 +73,7 @@ public class AutoSkipAssets Name = "DailyRewardIcon", RecognitionType = RecognitionTypes.TemplateMatch, TemplateImageMat = GameTaskManager.LoadAssetImage("AutoSkip", "icon_daily_reward.png"), - RegionOfInterest = new Rect(info.CaptureAreaRect.Width / 2, 0, info.CaptureAreaRect.Width - info.CaptureAreaRect.Width / 2, info.CaptureAreaRect.Height), + RegionOfInterest = optionRect, DrawOnWindow = false }.InitTemplate(); ExploreIconRo = new RecognitionObject @@ -79,7 +81,7 @@ public class AutoSkipAssets Name = "ExploreIcon", RecognitionType = RecognitionTypes.TemplateMatch, TemplateImageMat = GameTaskManager.LoadAssetImage("AutoSkip", "icon_explore.png"), - RegionOfInterest = new Rect(info.CaptureAreaRect.Width / 2, 0, info.CaptureAreaRect.Width - info.CaptureAreaRect.Width / 2, info.CaptureAreaRect.Height), + RegionOfInterest = optionRect, DrawOnWindow = false }.InitTemplate(); diff --git a/BetterGenshinImpact/GameTask/TaskTriggerDispatcher.cs b/BetterGenshinImpact/GameTask/TaskTriggerDispatcher.cs index a048d9af..99a32cff 100644 --- a/BetterGenshinImpact/GameTask/TaskTriggerDispatcher.cs +++ b/BetterGenshinImpact/GameTask/TaskTriggerDispatcher.cs @@ -20,7 +20,10 @@ using BetterGenshinImpact.Core.Config; using Vanara.PInvoke; using System.IO; using System.Drawing.Imaging; +using OpenCvSharp; +using OpenCvSharp.Extensions; using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrackBar; +using Point = OpenCvSharp.Point; namespace BetterGenshinImpact.GameTask { @@ -426,7 +429,18 @@ namespace BetterGenshinImpact.GameTask var name = $@"{DateTime.Now:yyyyMMddHHmmssffff}.png"; var savePath = Global.Absolute($@"log\screenshot\{name}"); - bitmap.Save(savePath, ImageFormat.Png); + if (TaskContext.Instance().Config.CommonConfig.ScreenshotUidCoverEnabled) + { + var mat = bitmap.ToMat(); + var rect = TaskContext.Instance().Config.MaskWindowConfig.UidCoverRect; + mat.Rectangle(rect, Scalar.White, -1); + Cv2.ImWrite(savePath, mat); + } + else + { + bitmap.Save(savePath, ImageFormat.Png); + } + _logger.LogInformation("截图已保存: {Name}", name); } catch (Exception e) diff --git a/BetterGenshinImpact/ViewModel/Pages/HotKeyPageViewModel.cs b/BetterGenshinImpact/ViewModel/Pages/HotKeyPageViewModel.cs index 8d0847f6..0d5af17a 100644 --- a/BetterGenshinImpact/ViewModel/Pages/HotKeyPageViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Pages/HotKeyPageViewModel.cs @@ -6,6 +6,7 @@ using CommunityToolkit.Mvvm.ComponentModel; using System.Collections.ObjectModel; using System.Diagnostics; using System.Reflection; +using System.Threading; using BetterGenshinImpact.Helpers.Extensions; using Microsoft.Extensions.Logging; using HotKeySettingModel = BetterGenshinImpact.Model.HotKeySettingModel; @@ -182,7 +183,7 @@ public partial class HotKeyPageViewModel : ObservableObject nameof(Config.HotKeyConfig.QuickTeleportTickHotkey), Config.HotKeyConfig.QuickTeleportTickHotkey, Config.HotKeyConfig.QuickTeleportTickHotkeyType, - (_, _) => { }, + (_, _) => { Thread.Sleep(100); }, true ); HotKeySettingModels.Add(quickTeleportTickHotKeySettingModel);