支持攀爬屏幕侧面和顶部

This commit is contained in:
ZouJin 2022-12-15 02:17:13 +08:00
parent dfb75c1c7e
commit 3873aae9b9
6 changed files with 399 additions and 51 deletions

View File

@ -31,7 +31,7 @@ namespace VPet_Simulator.Core
Bar = new ToolBar(this);
UIGrid.Children.Add(Bar);
Bar.Visibility = Visibility.Collapsed;
//TODO:锚定设置
Core.TouchEvent.Add(new TouchArea(new Point(138, 12), new Size(224, 176), DisplayTouchHead));
Core.TouchEvent.Add(new TouchArea(new Point(0, 0), new Size(500, 180), DisplayRaised, true));
var ig = Core.Graph.FindGraph(GraphCore.GraphType.Default, Core.Save.Mode);
@ -39,11 +39,23 @@ namespace VPet_Simulator.Core
ig.Run();
EventTimer.Elapsed += EventTimer_Elapsed;
MoveTimer.Elapsed += MoveTimer_Elapsed;
}
private void MoveTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
Core.Controller.MoveWindows(MoveTimerPoint.X, MoveTimerPoint.Y);
}
bool isPress = false;
private void MainGrid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
isPress = true;
if (!IsNomal)
{//不是nomal! 可能会卡timer,所有全部timer清空下
MoveTimer.Stop();
MainGrid.MouseMove -= MainGrid_MouseMove;
}
Task.Run(() =>
{
Thread.Sleep(Core.Setting.PressLength);
@ -69,7 +81,7 @@ namespace VPet_Simulator.Core
private void MainGrid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
isPress = false;
if(rasetype != -1)
if (rasetype != -1)
{
MainGrid.MouseMove -= MainGrid_MouseMove;
rasetype = -1;
@ -79,7 +91,7 @@ namespace VPet_Simulator.Core
private void MainGrid_MouseMove(object sender, MouseEventArgs e)
{
var mp = e.GetPosition(MainGrid);
var x = mp.X - 290;
var x = mp.X - 290;//TODO:锚定设置
var y = mp.Y - 128;
Core.Controller.MoveWindows(x, y);
if (Math.Abs(x) + Math.Abs(y) > 10)

View File

@ -5,6 +5,7 @@ using System.Security.AccessControl;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Threading;
@ -26,16 +27,21 @@ namespace VPet_Simulator.Core
public void DisplayTouchHead()
{
IsNomal = false;
if (((IGraph)PetGrid.Child).GraphType == GraphCore.GraphType.Touch_Head_B_Loop)
{
((IGraph)PetGrid.Child).IsContinue = true;
return;
}
if (petgridcrlf)
if (PetGrid.Child is IGraph ig && ig.GraphType == GraphCore.GraphType.Touch_Head_B_Loop)
{
((IGraph)PetGrid.Child).IsContinue = true;
return;
}
else if (PetGrid2.Child is IGraph ig2 && ig2.GraphType == GraphCore.GraphType.Touch_Head_B_Loop)
{
((IGraph)PetGrid.Child).IsContinue = true;
return;
}
Display(Core.Graph.FindGraph(GraphCore.GraphType.Touch_Head_A_Start, Core.Save.Mode), () =>
Display(Core.Graph.FindGraph(GraphCore.GraphType.Touch_Head_B_Loop, Core.Save.Mode), () =>
Display(Core.Graph.FindGraph(GraphCore.GraphType.Touch_Head_C_End, Core.Save.Mode), () =>
Display(Core.Graph.FindGraph(GraphCore.GraphType.Default, Core.Save.Mode)
))));
Display(Core.Graph.FindGraph(GraphCore.GraphType.Touch_Head_C_End, Core.Save.Mode), DisplayNomal
)));
}
/// <summary>
/// 显示拖拽情况
@ -59,6 +65,7 @@ namespace VPet_Simulator.Core
//))));
}
int rasetype = -1;
int walklength = 0;
/// <summary>
/// 显示拖拽中
/// </summary>
@ -91,9 +98,291 @@ namespace VPet_Simulator.Core
{//TODO:爬起
Display(Core.Graph.FindGraph(GraphCore.GraphType.Fall_B_End, Core.Save.Mode), DisplayNomal);
}
/// <summary>
/// 显示向左走 (有判断)
/// </summary>
public void DisplayWalk_Left()
{
//看看距离是否满足调节
if (Core.Controller.GetWindowsDistanceLeft() > 400 * Core.Controller.ZoomRatio)
{
walklength = 0;
IsNomal = false;
Display(Core.Graph.FindGraph(GraphCore.GraphType.Walk_Left_A_Start, Core.Save.Mode), () =>
{
MoveTimerPoint = new Point(-20, 0);//TODO:锚定设置
MoveTimer.Start();
DisplayWalk_Lefting();
});
}
}
/// <summary>
/// 显示向左走
/// </summary>
public void DisplayWalk_Lefting()
{
//看看距离是不是不足
if (Core.Controller.GetWindowsDistanceLeft() < 50 * Core.Controller.ZoomRatio)
{//是,停下恢复默认 or/爬墙
switch (Function.Rnd.Next(3))
{
case 0:
DisplayClimb_Left_UP();
return;
case 1:
DisplayClimb_Left_DOWN();
return;
default:
MoveTimer.Stop();
Display(Core.Graph.FindGraph(GraphCore.GraphType.Walk_Left_C_End, Core.Save.Mode), DisplayNomal);
return;
}
}
//不是:继续右边走or停下
if (Function.Rnd.Next(walklength++) < 5)
{
Display(Core.Graph.FindGraph(GraphCore.GraphType.Walk_Left_B_Loop, Core.Save.Mode), DisplayWalk_Lefting);
}
else
{//停下来
MoveTimer.Stop();
Display(Core.Graph.FindGraph(GraphCore.GraphType.Walk_Left_C_End, Core.Save.Mode), DisplayNomal);
}
}
/// <summary>
/// 显示左墙壁爬行 上
/// </summary>
public void DisplayClimb_Left_UP()
{
//看看距离是否满足调节
if (Core.Controller.GetWindowsDistanceLeft() < 100 * Core.Controller.ZoomRatio && Core.Controller.GetWindowsDistanceUp() > 400 * Core.Controller.ZoomRatio)
{
walklength = 0;
IsNomal = false;
Core.Controller.MoveWindows(-Core.Controller.GetWindowsDistanceLeft() / Core.Controller.ZoomRatio - 145, 0);//TODO:锚定设置
MoveTimerPoint = new Point(0, -10);//TODO:锚定设置
MoveTimer.Start();
DisplayClimb_Lefting_UP();
}
}
/// <summary>
/// 显示左墙壁爬行 上
/// </summary>
public void DisplayClimb_Lefting_UP()
{
//看看距离是不是不足
if (Core.Controller.GetWindowsDistanceUp() < 100 * Core.Controller.ZoomRatio)
{//是,停下恢复默认 or/爬上面的墙
switch (Function.Rnd.Next(3))
{
case 0:
DisplayClimb_Top_Right();
return;
//case 1://TODO:落下
// return;
default:
MoveTimer.Stop();
DisplayNomal();
return;
}
}
//不是:继续or停下
if (Function.Rnd.Next(walklength++) < 5)
{
Display(Core.Graph.FindGraph(GraphCore.GraphType.Climb_Left, Core.Save.Mode), DisplayClimb_Lefting_UP);
}
else
{//停下来
MoveTimer.Stop();
DisplayNomal();
}
}
/// <summary>
/// 显示左墙壁爬行 下
/// </summary>
public void DisplayClimb_Left_DOWN()
{
//看看距离是否满足调节
if (Core.Controller.GetWindowsDistanceLeft() < 50 * Core.Controller.ZoomRatio && Core.Controller.GetWindowsDistanceDown() > 400 * Core.Controller.ZoomRatio)
{
walklength = 0;
IsNomal = false;
Core.Controller.MoveWindows(-Core.Controller.GetWindowsDistanceLeft() / Core.Controller.ZoomRatio - 145, 0);//TODO:锚定设置
MoveTimerPoint = new Point(0, 10);//TODO:锚定设置
MoveTimer.Start();
DisplayClimb_Lefting_DOWN();
}
}
/// <summary>
/// 显示左墙壁爬行 下
/// </summary>
public void DisplayClimb_Lefting_DOWN()
{
//看看距离是不是不足
if (Core.Controller.GetWindowsDistanceDown() < 50 * Core.Controller.ZoomRatio)
{//是,停下恢复默认
MoveTimer.Stop();
DisplayNomal();
}
//不是:继续or停下
if (Function.Rnd.Next(walklength++) < 5)
{
Display(Core.Graph.FindGraph(GraphCore.GraphType.Climb_Left, Core.Save.Mode), DisplayClimb_Lefting_DOWN);
}
else
{//停下来
MoveTimer.Stop();
DisplayNomal();
}
}
/// <summary>
/// 显示右墙壁爬行 上
/// </summary>
public void DisplayClimb_Right_UP()
{
//看看距离是否满足调节
if (Core.Controller.GetWindowsDistanceRight() < 100 * Core.Controller.ZoomRatio && Core.Controller.GetWindowsDistanceUp() > 400 * Core.Controller.ZoomRatio)
{
walklength = 0;
IsNomal = false;
Core.Controller.MoveWindows(Core.Controller.GetWindowsDistanceRight() / Core.Controller.ZoomRatio + 185, 0);//TODO:锚定设置
MoveTimerPoint = new Point(0, -10);//TODO:锚定设置
MoveTimer.Start();
DisplayClimb_Righting_UP();
}
}
/// <summary>
/// 显示右墙壁爬行 上
/// </summary>
public void DisplayClimb_Righting_UP()
{
//看看距离是不是不足
if (Core.Controller.GetWindowsDistanceUp() < 100 * Core.Controller.ZoomRatio)
{//是,停下恢复默认 or/爬上面的墙
switch (3)//Function.Rnd.Next(3))
{
case 0:
return;
case 1:
return;
default:
MoveTimer.Stop();
DisplayNomal();
return;
}
}
//不是:继续or停下
if (Function.Rnd.Next(walklength++) < 5)
{
Display(Core.Graph.FindGraph(GraphCore.GraphType.Climb_Right, Core.Save.Mode), DisplayClimb_Righting_UP);
}
else
{//停下来
MoveTimer.Stop();
DisplayNomal();
}
}
/// <summary>
/// 显示右墙壁爬行 下
/// </summary>
public void DisplayClimb_Right_DOWN()
{
//看看距离是否满足调节
if (Core.Controller.GetWindowsDistanceRight() < 100 * Core.Controller.ZoomRatio && Core.Controller.GetWindowsDistanceDown() > 400 * Core.Controller.ZoomRatio)
{
walklength = 0;
IsNomal = false;
Core.Controller.MoveWindows(Core.Controller.GetWindowsDistanceRight() / Core.Controller.ZoomRatio + 185, 0);//TODO:锚定设置
MoveTimerPoint = new Point(0, 10);//TODO:锚定设置
MoveTimer.Start();
DisplayClimb_Righting_DOWN();
}
}
/// <summary>
/// 显示右墙壁爬行 下
/// </summary>
public void DisplayClimb_Righting_DOWN()
{
//看看距离是不是不足
if (Core.Controller.GetWindowsDistanceDown() < 50 * Core.Controller.ZoomRatio)
{//是,停下恢复默认
MoveTimer.Stop();
DisplayNomal();
}
//不是:继续or停下
if (Function.Rnd.Next(walklength++) < 5)
{
Display(Core.Graph.FindGraph(GraphCore.GraphType.Climb_Right, Core.Save.Mode), DisplayClimb_Righting_DOWN);
}
else
{//停下来
MoveTimer.Stop();
DisplayNomal();
}
}
/// <summary>
/// 显示顶部墙壁爬行向右
/// </summary>
public void DisplayClimb_Top_Right()
{
//看看距离是否满足调节
if (Core.Controller.GetWindowsDistanceUp() < 50 * Core.Controller.ZoomRatio && Core.Controller.GetWindowsDistanceRight() > 400 * Core.Controller.ZoomRatio)
{
walklength = 0;
IsNomal = false;
Core.Controller.MoveWindows(0, -Core.Controller.GetWindowsDistanceUp() / Core.Controller.ZoomRatio - 150);//TODO:锚定设置
MoveTimerPoint = new Point(8, 0);//TODO:锚定设置
MoveTimer.Start();
DisplayClimb_Top_Righting();
}
}
/// <summary>
/// 显示左墙壁爬行 上
/// </summary>
public void DisplayClimb_Top_Righting()
{
//看看距离是不是不足
if (Core.Controller.GetWindowsDistanceRight() < 50 * Core.Controller.ZoomRatio)
{//是,停下恢复默认 or向下爬
switch (3)//Function.Rnd.Next(3))
{
case 0:
return;
case 1:
return;
default:
Core.Controller.MoveWindows(0, -Core.Controller.GetWindowsDistanceUp() / Core.Controller.ZoomRatio);
MoveTimer.Stop();
DisplayNomal();
return;
}
}
//不是:继续or停下
if (Function.Rnd.Next(walklength++) < 10)
{
Display(Core.Graph.FindGraph(GraphCore.GraphType.Climb_Top_Right, Core.Save.Mode), DisplayClimb_Top_Righting);
}
else
{//停下来
Core.Controller.MoveWindows(0, -Core.Controller.GetWindowsDistanceUp() / Core.Controller.ZoomRatio);
MoveTimer.Stop();
DisplayNomal();
}
}
bool petgridcrlf = true;
/// <summary>
/// 显示动画 (自动多层切换)
@ -112,9 +401,9 @@ namespace VPet_Simulator.Core
((IGraph)(PetGrid2.Child)).Run(EndAction);
return;
}
graph.Run(EndAction);
if (petgridcrlf)
{
((IGraph)(PetGrid.Child)).Stop(true);

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
namespace VPet_Simulator.Core
{
@ -13,18 +14,53 @@ namespace VPet_Simulator.Core
/// 是否在默认情况(playnoaml)
/// </summary>
public bool IsNomal = true;
public Timer EventTimer = new Timer(15000)
{
AutoReset = true,
Enabled = true
};
private void EventTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//TODO:饮食等乱七八糟的消耗
if (IsNomal)
{
}
switch (3)//Function.Rnd.Next(10))
{
case 0:
//随机向右
DisplayWalk_Left();
break;
case 1:
DisplayClimb_Left_UP();
break;
case 2:
DisplayClimb_Left_DOWN();
break;
case 3:
DisplayClimb_Right_UP();
break;
case 4:
DisplayClimb_Right_DOWN();
break;
case 10:
DisplayClimb_Top_Right();
break;
default:
break;
}
}
/// <summary>
/// 定点移动位置向量
/// </summary>
private Point MoveTimerPoint = new Point(0, 0);
/// <summary>
/// 定点移动定时器
/// </summary>
private Timer MoveTimer = new Timer(125)
{
AutoReset = true,
};
}
}

View File

@ -118,26 +118,26 @@ namespace VPet_Simulator.Core
new dynamic[]{ "raised_dynamic" ,false,true},
new dynamic[]{ "raised_static_a", false,true},
new dynamic[]{ "raised_static_b", false,true},
new dynamic[]{ "climb_top_right", true,false},
new dynamic[]{ "climb_top_left", true,false},
new dynamic[]{ "climb_right", true,false},
new dynamic[]{ "climb_left", true,false},
new dynamic[]{ "climb_top_right", false,false},
new dynamic[]{ "climb_top_left", false, false},
new dynamic[]{ "climb_right", false, false},
new dynamic[]{ "climb_left", false, false},
new dynamic[]{ "default", true,true},
new dynamic[]{ "touch_head_a", false,true},
new dynamic[]{ "touch_head_b", false,true},
new dynamic[]{ "touch_head_c", false,true},
new dynamic[]{ "crawl_right", true,true},
new dynamic[]{ "crawl_left", true,true},
new dynamic[]{ "crawl_right", false, true},
new dynamic[]{ "crawl_left", false, true},
new dynamic[]{ "squat_a", false,true},
new dynamic[]{ "squat_b", false, true},
new dynamic[]{ "squat_c", false,true},
new dynamic[]{ "fall_a", true,false},
new dynamic[]{ "fall_a", false, false},
new dynamic[]{ "fall_b", false,true},
new dynamic[]{ "walk_right_a", false,true},
new dynamic[]{ "walk_right_b", true,true},
new dynamic[]{ "walk_right_b", false, true},
new dynamic[]{ "walk_right_c", false,true},
new dynamic[]{ "walk_left_a", false,true},
new dynamic[]{ "walk_left_b", true,true},
new dynamic[]{ "walk_left_b", false, true},
new dynamic[]{ "walk_left_c", false,true},
};
/// <summary>

View File

@ -8,41 +8,45 @@ using System.Threading.Tasks;
namespace VPet_Simulator.Core
{
/// <summary>
/// 桌宠控制器
/// 桌宠控制器 需自行实现
/// </summary>
public abstract class IController
public interface IController
{
/// <summary>
/// 移动桌宠位置
/// </summary>
/// <param name="X">X轴</param>
/// <param name="Y">Y轴</param>
public abstract void MoveWindows(double X, double Y);
void MoveWindows(double X, double Y);
/// <summary>
/// 获取桌宠距离左侧的位置
/// </summary>
public abstract double GetWindowsDistanceLeft();
double GetWindowsDistanceLeft();
/// <summary>
/// 获取桌宠距离右侧的位置
/// </summary>
public abstract double GetWindowsDistanceRight();
double GetWindowsDistanceRight();
/// <summary>
/// 获取桌宠距离上方的位置
/// </summary>
public abstract double GetWindowsDistanceUp();
double GetWindowsDistanceUp();
/// <summary>
/// 获取桌宠距离下方的位置
/// </summary>
public abstract double GetWindowsDistanceDown();
double GetWindowsDistanceDown();
/// <summary>
/// 窗体宽度
/// </summary>
public abstract double WindowsWidth { get; set; }
double WindowsWidth { get; set; }
/// <summary>
/// 窗体高度
/// </summary>
public abstract double WindowsHight { get; set; }
double WindowsHight { get; set; }
/// <summary>
/// 缩放比例
/// </summary>
double ZoomRatio { get; }
}
}

View File

@ -7,41 +7,48 @@ using VPet_Simulator.Core;
namespace VPet_Simulator.Windows
{
/// <summary>
/// 窗体控制器实现
/// </summary>
public class MWController : IController
{
MainWindow mw;
readonly MainWindow mw;
public MWController(MainWindow mw)
{
this.mw = mw;
}
public override double WindowsWidth { get => mw.Width; set => mw.Width = value; }
public override double WindowsHight { get => mw.Height; set => mw.Height = value; }
public double WindowsWidth { get => mw.Dispatcher.Invoke(() => mw.Width); set => mw.Dispatcher.Invoke(() => mw.Width = value); }
public double WindowsHight { get => mw.Dispatcher.Invoke(() => mw.Height); set => mw.Dispatcher.Invoke(() => mw.Height = value); }
public override double GetWindowsDistanceDown()
public double GetWindowsDistanceDown()
{
return System.Windows.SystemParameters.PrimaryScreenHeight - mw.Top - mw.Height;
return mw.Dispatcher.Invoke(() => System.Windows.SystemParameters.PrimaryScreenHeight - mw.Top - mw.Height);
}
public override double GetWindowsDistanceLeft()
public double GetWindowsDistanceLeft()
{
return mw.Left;
return mw.Dispatcher.Invoke(() => mw.Left);
}
public override double GetWindowsDistanceRight()
public double GetWindowsDistanceRight()
{
return System.Windows.SystemParameters.PrimaryScreenWidth - mw.Left - mw.Width;
return mw.Dispatcher.Invoke(() => System.Windows.SystemParameters.PrimaryScreenWidth - mw.Left - mw.Width);
}
public override double GetWindowsDistanceUp()
public double GetWindowsDistanceUp()
{
return mw.Top;
return mw.Dispatcher.Invoke(() => mw.Top);
}
public override void MoveWindows(double X, double Y)
public void MoveWindows(double X, double Y)
{
mw.Left += X * .5;
mw.Top += Y * .5;
mw.Dispatcher.Invoke(() =>
{
mw.Left += X * ZoomRatio;
mw.Top += Y * ZoomRatio;
});
}
public double ZoomRatio => 0.5;
}
}