智能化重新归位

This commit is contained in:
ZouJin
2023-12-02 18:12:03 +08:00
parent 69c64b83ae
commit a8107a6ea8
4 changed files with 41 additions and 23 deletions

View File

@ -28,7 +28,6 @@ namespace VPet_Simulator.Core
/// </summary> /// </summary>
public void DisplayToNomal() public void DisplayToNomal()
{ {
this.Core.Controller.ResetPosition();
switch (State) switch (State)
{ {
default: default:
@ -378,6 +377,7 @@ namespace VPet_Simulator.Core
break; break;
case -1: case -1:
rasetype = int.MinValue; rasetype = int.MinValue;
Core.Controller.RePostionActive = !Core.Controller.CheckPosition();
if (string.IsNullOrEmpty(name)) if (string.IsNullOrEmpty(name))
Display(GraphType.Raised_Static, AnimatType.C_End, DisplayToNomal); Display(GraphType.Raised_Static, AnimatType.C_End, DisplayToNomal);
else else

View File

@ -485,8 +485,7 @@ namespace VPet_Simulator.Core
return; return;
} }
} }
m.MoveTimer.Enabled = false; StopMoving(m);
m.Display(Graph, AnimatType.C_End, m.DisplayToNomal);
return; return;
} }
//不是:继续右边走or停下 //不是:继续右边走or停下
@ -504,6 +503,14 @@ namespace VPet_Simulator.Core
return; return;
} }
} }
StopMoving(m);
}
private void StopMoving(Main m)
{
if (m.Core.Controller.RePostionActive)
m.Core.Controller.ResetPosition();
m.Core.Controller.RePostionActive = !m.Core.Controller.CheckPosition();
m.MoveTimer.Enabled = false; m.MoveTimer.Enabled = false;
m.Display(Graph, AnimatType.C_End, m.DisplayToNomal); m.Display(Graph, AnimatType.C_End, m.DisplayToNomal);
} }

View File

@ -54,6 +54,10 @@
/// 在边缘时重新靠边,防止被阻挡 /// 在边缘时重新靠边,防止被阻挡
/// </summary> /// </summary>
void ResetPosition(); void ResetPosition();
/// <summary>
/// 判断桌宠是否靠边
/// </summary>
bool CheckPosition();
/// <summary> /// <summary>
/// 启用计算等数据功能 /// 启用计算等数据功能
@ -63,5 +67,10 @@
/// 互动周期 /// 互动周期
/// </summary> /// </summary>
int InteractionCycle { get; } int InteractionCycle { get; }
/// <summary>
/// 是否启用边缘重新定位
/// </summary>
bool RePostionActive { get; set; }
} }
} }

View File

@ -111,30 +111,32 @@ namespace VPet_Simulator.Windows
{ {
mw.Dispatcher.Invoke(() => mw.Dispatcher.Invoke(() =>
{ {
if (RePostionActive) if (GetWindowsDistanceUp() < -0.25 * mw.Height && GetWindowsDistanceDown() < System.Windows.SystemParameters.PrimaryScreenHeight)
{ {
if (mw.Core.Controller.GetWindowsDistanceUp() < -0.25 * mw.Height && mw.Core.Controller.GetWindowsDistanceDown() < System.Windows.SystemParameters.PrimaryScreenHeight) MoveWindows(0, -GetWindowsDistanceUp() / ZoomRatio);
{ }
mw.Core.Controller.MoveWindows(0, -mw.Core.Controller.GetWindowsDistanceUp() / mw.Core.Controller.ZoomRatio); else if (GetWindowsDistanceDown() < -0.25 * mw.Height && GetWindowsDistanceUp() < System.Windows.SystemParameters.PrimaryScreenHeight)
} {
else if (mw.Core.Controller.GetWindowsDistanceDown() < -0.25 * mw.Height && mw.Core.Controller.GetWindowsDistanceUp() < System.Windows.SystemParameters.PrimaryScreenHeight) MoveWindows(0, GetWindowsDistanceDown() / ZoomRatio);
{ }
mw.Core.Controller.MoveWindows(0, mw.Core.Controller.GetWindowsDistanceDown() / mw.Core.Controller.ZoomRatio); if (GetWindowsDistanceLeft() < -0.25 * mw.Width && GetWindowsDistanceRight() < System.Windows.SystemParameters.PrimaryScreenWidth)
} {
if (mw.Core.Controller.GetWindowsDistanceLeft() < -0.25 * mw.Width && mw.Core.Controller.GetWindowsDistanceRight() < System.Windows.SystemParameters.PrimaryScreenWidth) MoveWindows(-GetWindowsDistanceLeft() / ZoomRatio, 0);
{ }
mw.Core.Controller.MoveWindows(-mw.Core.Controller.GetWindowsDistanceLeft() / mw.Core.Controller.ZoomRatio, 0); else if (GetWindowsDistanceRight() < -0.25 * mw.Width && GetWindowsDistanceLeft() < System.Windows.SystemParameters.PrimaryScreenWidth)
} {
else if (mw.Core.Controller.GetWindowsDistanceRight() < -0.25 * mw.Width && mw.Core.Controller.GetWindowsDistanceLeft() < System.Windows.SystemParameters.PrimaryScreenWidth) MoveWindows(GetWindowsDistanceRight() / ZoomRatio, 0);
{
mw.Core.Controller.MoveWindows(mw.Core.Controller.GetWindowsDistanceRight() / mw.Core.Controller.ZoomRatio, 0);
}
} }
}); });
} }
public bool CheckPosition() => mw.Dispatcher.Invoke(() =>
GetWindowsDistanceUp() < -0.25 * mw.Height && GetWindowsDistanceDown() < System.Windows.SystemParameters.PrimaryScreenHeight
|| GetWindowsDistanceDown() < -0.25 * mw.Height && GetWindowsDistanceUp() < System.Windows.SystemParameters.PrimaryScreenHeight
|| GetWindowsDistanceLeft() < -0.25 * mw.Width && GetWindowsDistanceRight() < System.Windows.SystemParameters.PrimaryScreenWidth
|| GetWindowsDistanceRight() < -0.25 * mw.Width && GetWindowsDistanceLeft() < System.Windows.SystemParameters.PrimaryScreenWidth
);
public bool RePostionActive { get; set; } = true;
public bool RePostionActive = true;
public double ZoomRatio => mw.Set.ZoomLevel; public double ZoomRatio => mw.Set.ZoomLevel;