diff --git a/VPet-Simulator.Core/Display/MainDisplay.cs b/VPet-Simulator.Core/Display/MainDisplay.cs index 5177c9e91..48be2ef39 100644 --- a/VPet-Simulator.Core/Display/MainDisplay.cs +++ b/VPet-Simulator.Core/Display/MainDisplay.cs @@ -374,7 +374,7 @@ private void DisplayRaising(string name = null) break; case -1: rasetype = int.MinValue; - Core.Controller.RePostionActive = !Core.Controller.CheckPosition(); + Core.Controller.RePositionActive = !Core.Controller.CheckPosition(); //判断侧边隐藏 if(!MoveSideHideCheck()) { diff --git a/VPet-Simulator.Core/Display/MainLogic.cs b/VPet-Simulator.Core/Display/MainLogic.cs index 9d71568e2..9b5b199df 100644 --- a/VPet-Simulator.Core/Display/MainLogic.cs +++ b/VPet-Simulator.Core/Display/MainLogic.cs @@ -537,6 +537,10 @@ public void EventTimer_Elapsed() /// 是否成功进入侧边隐藏模式 private bool MoveSideHideCheck() { + if (Core.Controller.IfInActivateScreen() == false && Core.Controller.AutoChangeWindow == true) + { + Core.Controller.SetNowScreenActivate(); + } //判断是否靠边,如果靠边就进入侧边隐藏模式 if (Core.Controller.GetWindowsDistanceLeft() < -50 * Core.Controller.ZoomRatio) { @@ -544,6 +548,8 @@ private bool MoveSideHideCheck() if (Core.Graph.FindName(GraphType.SideHide_Left_Main) != null) { Core.Controller.MoveWindows(-Core.Controller.GetWindowsDistanceLeft() / Core.Controller.ZoomRatio - Core.Graph.GraphConfig.Data["side"][(gdbe)"left"], 0); + if (Core.Controller.GetWindowsDistanceDown() < 0) Core.Controller.MoveWindows(0, Core.Controller.GetWindowsDistanceDown() / Core.Controller.ZoomRatio - 100); + else if (Core.Controller.GetWindowsDistanceUp() < 0) Core.Controller.MoveWindows(0, -Core.Controller.GetWindowsDistanceUp() / Core.Controller.ZoomRatio); Display(GraphType.SideHide_Left_Main, AnimatType.A_Start, DisplayBLoopingForce); return true; } @@ -557,6 +563,8 @@ private bool MoveSideHideCheck() if (Core.Graph.FindName(GraphType.SideHide_Right_Main) != null) { Core.Controller.MoveWindows(Core.Controller.GetWindowsDistanceRight() / Core.Controller.ZoomRatio + 500 - Core.Graph.GraphConfig.Data["side"][(gdbe)"right"], 0); + if (Core.Controller.GetWindowsDistanceDown() < 0) Core.Controller.MoveWindows(0, Core.Controller.GetWindowsDistanceDown() / Core.Controller.ZoomRatio - 100); + else if (Core.Controller.GetWindowsDistanceUp() < 0) Core.Controller.MoveWindows(0, -Core.Controller.GetWindowsDistanceUp() / Core.Controller.ZoomRatio); Display(GraphType.SideHide_Right_Main, AnimatType.A_Start, DisplayBLoopingForce); return true; } diff --git a/VPet-Simulator.Core/Graph/GraphHelper.cs b/VPet-Simulator.Core/Graph/GraphHelper.cs index e1b81f7fc..a3d334be6 100644 --- a/VPet-Simulator.Core/Graph/GraphHelper.cs +++ b/VPet-Simulator.Core/Graph/GraphHelper.cs @@ -535,9 +535,9 @@ public void Displaying(Main m) private void StopMoving(Main m) { - if (m.Core.Controller.RePostionActive) + if (m.Core.Controller.RePositionActive) m.Core.Controller.ResetPosition(); - m.Core.Controller.RePostionActive = !m.Core.Controller.CheckPosition(); + m.Core.Controller.RePositionActive = !m.Core.Controller.CheckPosition(); m.MoveTimer.Enabled = false; m.Display(Graph, AnimatType.C_End, () => { m.Event_MoveEndInvoke(this); m.DisplayToNomal(); }); diff --git a/VPet-Simulator.Core/Handle/IController.cs b/VPet-Simulator.Core/Handle/IController.cs index 9ec7a29cd..d5af72f3a 100644 --- a/VPet-Simulator.Core/Handle/IController.cs +++ b/VPet-Simulator.Core/Handle/IController.cs @@ -28,6 +28,15 @@ public interface IController /// 获取桌宠距离下方的位置 /// double GetWindowsDistanceDown(); + /// + /// 获取桌宠所在屏幕是否为活动屏幕 + /// + /// + bool IfInActivateScreen() => true; + /// + /// 将当前屏幕设置为活动屏幕(如果桌宠在多个屏幕上则以主要屏幕为准) + /// + void SetNowScreenActivate() { } ///// ///// 窗体宽度 ///// @@ -71,6 +80,11 @@ public interface IController /// /// 是否启用边缘重新定位 /// - bool RePostionActive { get; set; } + bool RePositionActive { get; set; } + + /// + /// 是否自动切换活动屏幕 + /// + bool AutoChangeWindow => false; } } diff --git a/VPet-Simulator.Windows/Function/MWController.cs b/VPet-Simulator.Windows/Function/MWController.cs index 1b1b4e62d..e1be4692f 100644 --- a/VPet-Simulator.Windows/Function/MWController.cs +++ b/VPet-Simulator.Windows/Function/MWController.cs @@ -1,4 +1,10 @@ -using System.Drawing; +using Panuon.WPF.UI; +using System; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Windows; +using System.Windows.Forms; +using System.Windows.Interop; using VPet_Simulator.Core; namespace VPet_Simulator.Windows @@ -43,6 +49,7 @@ public Rectangle ScreenBorder IsPrimaryScreen = false; } } + public void ResetScreenBorder() { IsPrimaryScreen = true; @@ -93,6 +100,93 @@ public void MoveWindows(double X, double Y) }); } + public bool IfInActivateScreen() + { + try + { + if (mw.Dispatcher.HasShutdownStarted || mw.Dispatcher.HasShutdownFinished) return false; + if (mw.winSetting != null && mw.winSetting.Visibility == Visibility.Visible) return false; + if (mw.winBetterBuy != null && mw.winBetterBuy.Visibility == Visibility.Visible) return false; + if (mw.winWorkMenu != null && mw.winWorkMenu.Visibility == Visibility.Visible) return false; + if (mw.winMutiPlayer != null && mw.winMutiPlayer.Visibility == Visibility.Visible) return false; + } + catch { } + return mw.Dispatcher.Invoke(() => + { + + try + { + var screen = Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(mw).Handle); + var screens = Screen.AllScreens; + for (int i = 0; i < screens.Length; i++) + { + if (screens[i].DeviceName == screen.DeviceName) + { + if(i == mw.Set.GameScreenIndex) + { + return true; + } + } + } + return false; + } + catch(Exception) + { + return true; + } + }); + } + + public void SetNowScreenActivate() + { + if (!mw.IsLoaded) return; + if (mw.winSetting != null && mw.winSetting.Visibility == Visibility.Visible) return; + if (mw.winBetterBuy != null && mw.winBetterBuy.Visibility == Visibility.Visible) return; + if (mw.winWorkMenu != null && mw.winWorkMenu.Visibility == Visibility.Visible) return; + if (mw.winMutiPlayer != null && mw.winMutiPlayer.Visibility == Visibility.Visible) return; + mw.Dispatcher.Invoke(() => + { + var helper = new WindowInteropHelper(mw); + var currentScreen = Screen.FromHandle(helper.Handle); + var hwndSource = HwndSource.FromHwnd(helper.Handle); + + Rectangle logicalBounds; + + if (hwndSource?.CompositionTarget != null) + { + var dpi = hwndSource.CompositionTarget.TransformToDevice; + + logicalBounds = new Rectangle( + (int)(currentScreen.Bounds.X / dpi.M11), + (int)(currentScreen.Bounds.Y / dpi.M22), + (int)(currentScreen.Bounds.Width / dpi.M11), + (int)(currentScreen.Bounds.Height / dpi.M22) + ); + } + else + { + logicalBounds = new Rectangle( + currentScreen.Bounds.X, + currentScreen.Bounds.Y, + currentScreen.Bounds.Width, + currentScreen.Bounds.Height + ); + } + + ScreenBorder = logicalBounds; + + var screens = Screen.AllScreens; + for (int i = 0; i < screens.Length; i++) + { + if (screens[i].DeviceName == currentScreen.DeviceName) + { + mw.Set.GameScreenIndex = i; + break; + } + } + }); + } + public void ShowSetting() { mw.Topmost = false; @@ -134,7 +228,7 @@ public bool CheckPosition() => mw.Dispatcher.Invoke(() => || GetWindowsDistanceRight() < -0.25 * mw.ActualWidth && GetWindowsDistanceLeft() < System.Windows.SystemParameters.PrimaryScreenWidth ); - public bool RePostionActive { get; set; } = true; + public bool RePositionActive { get; set; } = true; public double ZoomRatio => mw.Set.ZoomLevel; @@ -144,5 +238,6 @@ public bool CheckPosition() => mw.Dispatcher.Invoke(() => public int InteractionCycle => mw.Set.InteractionCycle; + public bool AutoChangeWindow => mw.Set.AutoChangeWindow; } } diff --git a/VPet-Simulator.Windows/Function/Setting.cs b/VPet-Simulator.Windows/Function/Setting.cs index d89123bd7..6b0a1a04d 100644 --- a/VPet-Simulator.Windows/Function/Setting.cs +++ b/VPet-Simulator.Windows/Function/Setting.cs @@ -38,6 +38,7 @@ public Setting(MainWindow mw, string lps) : base(lps) enablefunction = !this["gameconfig"].GetBool("nofunction"); autobuy = this["gameconfig"].GetBool("autobuy"); autogift = this["gameconfig"].GetBool("autogift"); + autochangewindow = !this["gameconfig"].GetBool("autochangewindow"); this.mw = mw; } @@ -302,6 +303,16 @@ public bool EnableFunction this["gameconfig"].SetBool("nofunction", !value); } } + private bool autochangewindow; + public bool AutoChangeWindow + { + get => !autochangewindow; + set + { + autochangewindow = !value; + this["gameconfig"].SetBool("autochangewindow", value); + } + } /// /// 智能移动周期 (秒) /// @@ -517,6 +528,12 @@ public bool OpacityHitThrough set => this["gameconfig"].SetBool("opacityhitthrough", !value); } + public int GameScreenIndex + { + get => this["gameconfig"].GetInt("gamescreenindex", 0); + set => this["gameconfig"].SetInt("gamescreenindex", value); + } + /// /// 读写自定义游戏设置(给mod准备的接口) /// diff --git a/VPet-Simulator.Windows/MutiPlayer/MPController.cs b/VPet-Simulator.Windows/MutiPlayer/MPController.cs index 3f5c36934..29b62df32 100644 --- a/VPet-Simulator.Windows/MutiPlayer/MPController.cs +++ b/VPet-Simulator.Windows/MutiPlayer/MPController.cs @@ -1,4 +1,5 @@ -using VPet_Simulator.Core; +using System; +using VPet_Simulator.Core; namespace VPet_Simulator.Windows { @@ -99,7 +100,7 @@ public bool CheckPosition() => mp.Dispatcher.Invoke(() => || GetWindowsDistanceRight() < -0.25 * mp.ActualWidth && GetWindowsDistanceLeft() < System.Windows.SystemParameters.PrimaryScreenWidth ); - public bool RePostionActive { get; set; } = true; + public bool RePositionActive { get; set; } = true; public double ZoomRatio => mw.Set.ZoomLevel; @@ -109,5 +110,44 @@ public bool CheckPosition() => mp.Dispatcher.Invoke(() => public int InteractionCycle => mw.Set.InteractionCycle; + public bool AutoChangeWindow => mw.Set.AutoChangeWindow; + + public bool IfInActivateScreen() + { + try + { + if (mp.Dispatcher.HasShutdownStarted || mp.Dispatcher.HasShutdownFinished) return false; + } + catch { } + return mp.Dispatcher.Invoke(() => + { + + try + { + var screen = System.Windows.Forms.Screen.FromHandle(new System.Windows.Interop.WindowInteropHelper(mp).Handle); + var screens = System.Windows.Forms.Screen.AllScreens; + for (int i = 0; i < screens.Length; i++) + { + if (screens[i].DeviceName == screen.DeviceName) + { + if (i == mw.Set.GameScreenIndex) + { + return true; + } + } + } + return false; + } + catch (Exception) + { + return true; + } + }); + } + + public void SetNowScreenActivate() + { + + } } } diff --git a/VPet-Simulator.Windows/WinDesign/winGameSetting.xaml b/VPet-Simulator.Windows/WinDesign/winGameSetting.xaml index 075812df4..573e552d5 100644 --- a/VPet-Simulator.Windows/WinDesign/winGameSetting.xaml +++ b/VPet-Simulator.Windows/WinDesign/winGameSetting.xaml @@ -566,6 +566,7 @@ + @@ -658,23 +659,33 @@ + - + + -