diff --git a/BetterGenshinImpact/GameTask/MapMask/MapMaskTrigger.cs b/BetterGenshinImpact/GameTask/MapMask/MapMaskTrigger.cs index 549658e4..cd9a7f23 100644 --- a/BetterGenshinImpact/GameTask/MapMask/MapMaskTrigger.cs +++ b/BetterGenshinImpact/GameTask/MapMask/MapMaskTrigger.cs @@ -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; } diff --git a/BetterGenshinImpact/View/MaskWindow.xaml.cs b/BetterGenshinImpact/View/MaskWindow.xaml.cs index 687afe27..bc963e6c 100644 --- a/BetterGenshinImpact/View/MaskWindow.xaml.cs +++ b/BetterGenshinImpact/View/MaskWindow.xaml.cs @@ -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);