Clear draw content when triggers disabled

This commit is contained in:
huiyadanli 2023-10-06 00:11:52 +08:00
parent 81a5819019
commit fa770efcca
4 changed files with 46 additions and 20 deletions

View File

@ -20,7 +20,7 @@ using Pen = System.Drawing.Pen;
namespace BetterGenshinImpact.GameTask.AutoFishing
{
public class AutoFishingTrigger : ITaskTrigger, IDisposable
public class AutoFishingTrigger : ITaskTrigger
{
private readonly ILogger<AutoFishingTrigger> _logger = App.GetLogger<AutoFishingTrigger>();
private readonly IOcrService _ocrService = OcrFactory.Create(OcrEngineType.WinRT);
@ -92,6 +92,8 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
}
}
/// <summary>
/// 在“开始钓鱼”按钮上方安排一个我们的“开始自动钓鱼”按钮
/// </summary>
@ -581,25 +583,25 @@ namespace BetterGenshinImpact.GameTask.AutoFishing
VisionContext.Instance().DrawContent.PutOrRemoveRectList(list);
}
/// <summary>
/// 清理画布
/// </summary>
public void ClearDraw()
{
VisionContext.Instance().DrawContent.PutOrRemoveRectList(new List<(string, RectDrawable)>
{
("FishingBarLeft", new RectDrawable(System.Windows.Rect.Empty)),
("FishingBarCur", new RectDrawable(System.Windows.Rect.Empty)),
("FishingBarRight", new RectDrawable(System.Windows.Rect.Empty))
});
VisionContext.Instance().DrawContent.RemoveRect("FishBiteTips");
VisionContext.Instance().DrawContent.RemoveRect("StartFishingButton");
WeakReferenceMessenger.Default.Send(new PropertyChangedMessage<object>(this, "RemoveButton", new object(), "开始自动钓鱼"));
}
///// <summary>
///// 清理画布
///// </summary>
//public void ClearDraw()
//{
// VisionContext.Instance().DrawContent.PutOrRemoveRectList(new List<(string, RectDrawable)>
// {
// ("FishingBarLeft", new RectDrawable(System.Windows.Rect.Empty)),
// ("FishingBarCur", new RectDrawable(System.Windows.Rect.Empty)),
// ("FishingBarRight", new RectDrawable(System.Windows.Rect.Empty))
// });
// VisionContext.Instance().DrawContent.RemoveRect("FishBiteTips");
// VisionContext.Instance().DrawContent.RemoveRect("StartFishingButton");
// WeakReferenceMessenger.Default.Send(new PropertyChangedMessage<object>(this, "RemoveButton", new object(), "开始自动钓鱼"));
//}
public void Dispose()
{
ClearDraw();
}
//public void Stop()
//{
// ClearDraw();
//}
}
}

View File

@ -1,9 +1,12 @@
using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.Core.Recognition.OpenCv;
using CommunityToolkit.Mvvm.Messaging.Messages;
using CommunityToolkit.Mvvm.Messaging;
using OpenCvSharp;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using BetterGenshinImpact.View.Drawable;
namespace BetterGenshinImpact.GameTask
{
@ -42,6 +45,9 @@ namespace BetterGenshinImpact.GameTask
{
TriggerDictionary["AutoFishing"] = new AutoFishing.AutoFishingTrigger();
}
// 清理画布
WeakReferenceMessenger.Default.Send(new PropertyChangedMessage<object>(new object(), "RemoveAllButton", new object(), ""));
VisionContext.Instance().DrawContent.ClearAll();
}
}

View File

@ -93,4 +93,15 @@ public class DrawContent
MaskWindow.Instance().Refresh();
}
}
/// <summary>
/// 清理所有绘制内容
/// </summary>
public void ClearAll()
{
RectList.Clear();
TextList.Clear();
MaskWindow.Instance().Refresh();
}
}

View File

@ -56,6 +56,13 @@ namespace BetterGenshinImpact.ViewModel
}
});
}
else if (msg.PropertyName == "RemoveAllButton")
{
UIDispatcherHelper.Invoke(() =>
{
_maskButtons.Clear();
});
}
});
}