Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
83987a6
尝试修复靠边的多屏幕兼容问题
YIYuNCU Feb 23, 2026
378881e
修复拼写错误,添加切换主屏幕相关代码
YIYuNCU Apr 26, 2026
543a8d8
引入自动切换屏幕功能,添加设置项(未添加设置UI)
YIYuNCU Apr 26, 2026
8b8bdc3
Potential fix for pull request finding
LorisYounger Apr 29, 2026
594bb48
Potential fix for pull request finding
LorisYounger Apr 29, 2026
8cb7a48
Merge pull request #544 from LorisYounger/main
LorisYounger May 20, 2026
c1a40fb
添加自动切换屏幕功能(自动开启)
YIYuNCU May 24, 2026
a4c87c6
Merge branch 'dev-靠边检测' of https://github.com/LorisYounger/VPet into …
YIYuNCU May 24, 2026
faacf86
fix AutoChangeWindow
LorisYounger May 24, 2026
9bf10c2
Merge branch 'dev-靠边检测' of https://github.com/LorisYounger/VPet into …
LorisYounger May 24, 2026
f0aca0b
Potential fix for pull request finding
LorisYounger May 24, 2026
abcd3e6
Potential fix for pull request finding
LorisYounger May 24, 2026
c06955f
Merge branch 'dev-靠边检测' of https://github.com/LorisYounger/VPet into …
LorisYounger May 24, 2026
361e0f3
fix: add non-breaking defaults for IController screen APIs
Copilot May 24, 2026
448e9f3
Normalize left side-hide Y delta by ZoomRatio
Copilot May 27, 2026
d8e8495
修复换算问题?
YIYuNCU May 27, 2026
79594ae
修复多余变量定义
YIYuNCU May 27, 2026
11d6f2c
修复多余变量定义
YIYuNCU May 27, 2026
38e5027
修复设置无法正常读取问题
YIYuNCU May 27, 2026
5b7046b
修复错误改动
YIYuNCU May 27, 2026
6224dc3
修复屏幕下部位置优化过多的问题
YIYuNCU May 27, 2026
405d7b6
修复设置读取错误问题
YIYuNCU May 27, 2026
062bdb5
增加兼容代码
YIYuNCU May 27, 2026
ce419a1
增加兼容代码
YIYuNCU May 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VPet-Simulator.Core/Display/MainDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down
8 changes: 8 additions & 0 deletions VPet-Simulator.Core/Display/MainLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -537,13 +537,19 @@ public void EventTimer_Elapsed()
/// <returns>是否成功进入侧边隐藏模式</returns>
private bool MoveSideHideCheck()
{
if (Core.Controller.IfInActivateScreen() == false && Core.Controller.AutoChangeWindow == true)
{
Core.Controller.SetNowScreenActivate();
}
//判断是否靠边,如果靠边就进入侧边隐藏模式
if (Core.Controller.GetWindowsDistanceLeft() < -50 * Core.Controller.ZoomRatio)
{
//检查下是否有SideLoad
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;
}
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions VPet-Simulator.Core/Graph/GraphHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(); });
Expand Down
16 changes: 15 additions & 1 deletion VPet-Simulator.Core/Handle/IController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public interface IController
/// 获取桌宠距离下方的位置
/// </summary>
double GetWindowsDistanceDown();
/// <summary>
/// 获取桌宠所在屏幕是否为活动屏幕
/// </summary>
/// <returns></returns>
bool IfInActivateScreen() => true;
/// <summary>
/// 将当前屏幕设置为活动屏幕(如果桌宠在多个屏幕上则以主要屏幕为准)
/// </summary>
void SetNowScreenActivate() { }
///// <summary>
///// 窗体宽度
///// </summary>
Expand Down Expand Up @@ -71,6 +80,11 @@ public interface IController
/// <summary>
/// 是否启用边缘重新定位
/// </summary>
bool RePostionActive { get; set; }
bool RePositionActive { get; set; }

/// <summary>
/// 是否自动切换活动屏幕
/// </summary>
bool AutoChangeWindow => false;
}
}
99 changes: 97 additions & 2 deletions VPet-Simulator.Windows/Function/MWController.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -43,6 +49,7 @@ public Rectangle ScreenBorder
IsPrimaryScreen = false;
}
}

public void ResetScreenBorder()
{
IsPrimaryScreen = true;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -144,5 +238,6 @@ public bool CheckPosition() => mw.Dispatcher.Invoke(() =>

public int InteractionCycle => mw.Set.InteractionCycle;

public bool AutoChangeWindow => mw.Set.AutoChangeWindow;
}
}
17 changes: 17 additions & 0 deletions VPet-Simulator.Windows/Function/Setting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
}
/// <summary>
/// 智能移动周期 (秒)
/// </summary>
Expand Down Expand Up @@ -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);
}

/// <summary>
/// 读写自定义游戏设置(给mod准备的接口)
/// </summary>
Expand Down
44 changes: 42 additions & 2 deletions VPet-Simulator.Windows/MutiPlayer/MPController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using VPet_Simulator.Core;
using System;
using VPet_Simulator.Core;

namespace VPet_Simulator.Windows
{
Expand Down Expand Up @@ -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;

Expand All @@ -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()
{

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
Comment on lines +148 to +151
}
}
19 changes: 15 additions & 4 deletions VPet-Simulator.Windows/WinDesign/winGameSetting.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />

</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="35" />
Expand Down Expand Up @@ -658,23 +659,33 @@
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<WrapPanel Grid.ColumnSpan="3">
<pu:Switch x:Name="AutoChangeWindowEvent" Margin="5" Background="Transparent"
BorderBrush="{DynamicResource PrimaryDark}" BoxHeight="18" BoxWidth="35"
Checked="AutoChangeWindowEvent_Checked" CheckedBackground="{DynamicResource Primary}"
CheckedBorderBrush="{DynamicResource Primary}"
CheckedToggleBrush="{DynamicResource DARKPrimaryText}" Content="{ll:Str 启用窗口自动切换}"
IsChecked="True" ToggleBrush="{DynamicResource PrimaryDark}"
ToggleShadowColor="{x:Null}" ToggleSize="14"
ToolTip="{ll:Str '启用窗口切换,桌宠将能自主切换窗口'}"
Unchecked="AutoChangeWindowEvent_Checked" Grid.Row="0" Grid.ColumnSpan="3"/>
<WrapPanel Grid.ColumnSpan="3" Grid.Column="0" Grid.Row="1">
<TextBlock Text="{ll:Str '当前移动区域:'}" />
<TextBlock x:Name="textMoveArea" Text="{ll:Str '主屏幕'}" />
</WrapPanel>

<Button x:Name="BtnSetMoveArea_Default" Grid.Row="1" Grid.Column="0" Margin="5,5,5,5"
<Button x:Name="BtnSetMoveArea_Default" Grid.Row="2" Grid.Column="0" Margin="5,5,5,5"
Padding="1" pu:ButtonHelper.CornerRadius="4"
Background="{DynamicResource SecondaryLight}"
Click="BtnSetMoveArea_Default_Click" Content="{ll:Str 重置为主屏}"
ToolTip="{ll:Str '设置桌宠只在主屏幕进行移动'}" />
<Button x:Name="BtnSetMoveArea_DetectScreen" Grid.Row="1" Grid.Column="1"
<Button x:Name="BtnSetMoveArea_DetectScreen" Grid.Row="2" Grid.Column="1"
Margin="5,5,5,5" Padding="1" pu:ButtonHelper.CornerRadius="4"
Background="{DynamicResource SecondaryLight}"
Click="BtnSetMoveArea_DetectScreen_Click" Content="{ll:Str 设为当前屏幕}"
ToolTip="{ll:Str '设置桌宠只在当前桌宠所在的屏幕范围进行移动'}" />
<Button x:Name="BtnSetMoveArea_Window" Grid.Row="1" Grid.Column="2" Margin="5,5,5,5"
<Button x:Name="BtnSetMoveArea_Window" Grid.Row="2" Grid.Column="2" Margin="5,5,5,5"
Padding="1" pu:ButtonHelper.CornerRadius="4"
Background="{DynamicResource SecondaryLight}"
Click="BtnSetMoveArea_Window_Click" Content="{ll:Str 自定移动范围}"
Expand Down
Loading
Loading