地图遮罩开关实时生效

This commit is contained in:
辉鸭蛋
2026-02-06 02:46:09 +08:00
parent bf3957d4e8
commit b61ceae5ea
2 changed files with 25 additions and 22 deletions

View File

@@ -44,6 +44,21 @@ public class MapMaskTrigger : ITaskTrigger
public void Init()
{
IsEnabled = _config.Enabled;
// 关闭时隐藏UI
if (!IsEnabled)
{
UIDispatcherHelper.Invoke(() =>
{
if (MaskWindow.InstanceNullable() != null)
{
if (MaskWindow.Instance().DataContext is MaskWindowViewModel vm)
{
vm.IsInBigMapUi = false;
}
}
});
}
}
public void OnCapture(CaptureContent content)
@@ -61,8 +76,7 @@ public class MapMaskTrigger : ITaskTrigger
var inBigMapUi = content.CurrentGameUiCategory == GameUiCategory.BigMap || Bv.IsInBigMapUi(region);
UIDispatcherHelper.Invoke(() =>
{
var vm = MaskWindow.Instance().DataContext as MaskWindowViewModel;
if (vm != null)
if (MaskWindow.Instance().DataContext is MaskWindowViewModel vm)
{
vm.IsInBigMapUi = inBigMapUi;
}

View File

@@ -76,6 +76,11 @@ public partial class MaskWindow : Window
return _maskWindow;
}
public static MaskWindow? InstanceNullable()
{
return _maskWindow;
}
public bool IsExist()
{
@@ -298,13 +303,13 @@ public partial class MaskWindow : Window
{
var editEnabled = TaskContext.Instance().Config.MaskWindowConfig.OverlayLayoutEditEnabled;
var inBigMapUi = _viewModel?.IsInBigMapUi == true;
if (editEnabled)
{
this.SetClickThrough(false);
return;
}
this.SetClickThrough(!inBigMapUi);
}
catch
@@ -593,25 +598,9 @@ file static class MaskWindowExtension
public static void SetClickThrough(this Window window, bool isClickThrough)
{
SetClickThrough(new WindowInteropHelper(window).Handle, isClickThrough);
SetLayeredWindow(new WindowInteropHelper(window).Handle, isClickThrough);
}
private static void SetClickThrough(nint hWnd, bool isClickThrough)
{
int style = User32.GetWindowLong(hWnd, User32.WindowLongFlags.GWL_EXSTYLE);
if (isClickThrough)
{
style |= (int)User32.WindowStylesEx.WS_EX_TRANSPARENT;
}
else
{
style &= ~(int)User32.WindowStylesEx.WS_EX_TRANSPARENT;
}
_ = User32.SetWindowLong(hWnd, User32.WindowLongFlags.GWL_EXSTYLE, style);
}
public static void SetChildWindow(this Window window)
{
SetChildWindow(new WindowInteropHelper(window).Handle);