优化播放逻辑&工具栏支持

This commit is contained in:
ZouJin 2023-01-21 01:01:10 +08:00
parent 5aea3e0d74
commit 1dac23258a
21 changed files with 208 additions and 59 deletions

@ -79,8 +79,7 @@ namespace VPet_Simulator.Core
CountNomal = 0;
if (DisplayType != GraphCore.GraphType.Default)
{//不是nomal! 可能会卡timer,所有全部timer清空下
MoveTimer.Stop();
MainGrid.MouseMove -= MainGrid_MouseMove;
CleanState();
if (DisplayStopMove(DisplayNomal))
return;
}
@ -140,10 +139,20 @@ namespace VPet_Simulator.Core
MoveTimer.Stop();
EventTimer.Dispose();
MoveTimer.Dispose();
MsgBar.Dispose();
ToolBar.Dispose();
if (PetGrid.Child is IGraph g)
g.Stop();
g.Stop(true);
if (PetGrid2.Child is IGraph g2)
g2.Stop();
g2.Stop(true);
}
/// <summary>
/// 清理所有状态
/// </summary>
public void CleanState()
{
MoveTimer.Stop();
MainGrid.MouseMove -= MainGrid_MouseMove;
}
}
}

@ -41,10 +41,10 @@ namespace VPet_Simulator.Core
switch (DisplayType)
{
case GraphCore.GraphType.Boring_B_Loop:
Display(Core.Graph.FindGraph(GraphCore.GraphType.Boring_C_End, Core.Save.Mode), EndAction);
Display(Core.Graph.FindGraph(GraphCore.GraphType.Boring_C_End, Core.Save.Mode, true), EndAction);
return true;
case GraphCore.GraphType.Squat_B_Loop:
Display(Core.Graph.FindGraph(GraphCore.GraphType.Squat_C_End, Core.Save.Mode), EndAction);
Display(Core.Graph.FindGraph(GraphCore.GraphType.Squat_C_End, Core.Save.Mode, true), EndAction);
return true;
}
return false;
@ -70,9 +70,10 @@ namespace VPet_Simulator.Core
ig2.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), DisplayNomal
Core.Graph.RndGraph.Clear();
Display(Core.Graph.FindGraph(GraphCore.GraphType.Touch_Head_A_Start, Core.Save.Mode, true), () =>
Display(Core.Graph.FindGraph(GraphCore.GraphType.Touch_Head_B_Loop, Core.Save.Mode, true), () =>
Display(Core.Graph.FindGraph(GraphCore.GraphType.Touch_Head_C_End, Core.Save.Mode, true), DisplayNomal
)));
}
@ -83,7 +84,8 @@ namespace VPet_Simulator.Core
{
looptimes = 0;
CountNomal = 0;
Display(Core.Graph.FindGraph(GraphCore.GraphType.Boring_A_Start, Core.Save.Mode), DisplayBoringing);
Core.Graph.RndGraph.Clear();
Display(Core.Graph.FindGraph(GraphCore.GraphType.Boring_A_Start, Core.Save.Mode, true), DisplayBoringing);
}
/// <summary>
/// 显示无聊情况
@ -91,9 +93,9 @@ namespace VPet_Simulator.Core
private void DisplayBoringing()
{
if (Function.Rnd.Next(++looptimes) > 10)
Display(Core.Graph.FindGraph(GraphCore.GraphType.Boring_C_End, Core.Save.Mode), DisplayNomal);
Display(Core.Graph.FindGraph(GraphCore.GraphType.Boring_C_End, Core.Save.Mode, true), DisplayNomal);
else
Display(Core.Graph.FindGraph(GraphCore.GraphType.Boring_B_Loop, Core.Save.Mode), DisplayBoringing);
Display(Core.Graph.FindGraph(GraphCore.GraphType.Boring_B_Loop, Core.Save.Mode, true), DisplayBoringing);
}
int looptimes;
/// <summary>
@ -103,7 +105,8 @@ namespace VPet_Simulator.Core
{
looptimes = 0;
CountNomal = 0;
Display(Core.Graph.FindGraph(GraphCore.GraphType.Squat_A_Start, Core.Save.Mode), DisplaySquating);
Core.Graph.RndGraph.Clear();
Display(Core.Graph.FindGraph(GraphCore.GraphType.Squat_A_Start, Core.Save.Mode, true), DisplaySquating);
}
/// <summary>
/// 显示蹲下情况
@ -111,9 +114,9 @@ namespace VPet_Simulator.Core
public void DisplaySquating()
{
if (Function.Rnd.Next(++looptimes) > 10)
Display(Core.Graph.FindGraph(GraphCore.GraphType.Squat_C_End, Core.Save.Mode), DisplayNomal);
Display(Core.Graph.FindGraph(GraphCore.GraphType.Squat_C_End, Core.Save.Mode, true), DisplayNomal);
else
Display(Core.Graph.FindGraph(GraphCore.GraphType.Squat_B_Loop, Core.Save.Mode), DisplaySquating);
Display(Core.Graph.FindGraph(GraphCore.GraphType.Squat_B_Loop, Core.Save.Mode, true), DisplaySquating);
}
/// <summary>
/// 显示拖拽情况
@ -383,7 +386,7 @@ namespace VPet_Simulator.Core
//看看距离是不是不足
if (Core.Controller.GetWindowsDistanceUp() < 100 * Core.Controller.ZoomRatio)
{//是,停下恢复默认 or/爬上面的墙
switch (0)//Function.Rnd.Next(3))
switch (Function.Rnd.Next(3))
{
case 0:
DisplayClimb_Top_Right();
@ -481,7 +484,7 @@ namespace VPet_Simulator.Core
//看看距离是不是不足
if (Core.Controller.GetWindowsDistanceUp() < 100 * Core.Controller.ZoomRatio)
{//是,停下恢复默认 or/爬上面的墙
switch (3)//Function.Rnd.Next(3))
switch (Function.Rnd.Next(3))
{
case 0:
DisplayClimb_Top_Left();
@ -574,7 +577,7 @@ namespace VPet_Simulator.Core
//看看距离是不是不足
if (Core.Controller.GetWindowsDistanceRight() < 50 * Core.Controller.ZoomRatio)
{//是,停下恢复默认 or向下爬or掉落
switch (3)//Function.Rnd.Next(3))
switch (Function.Rnd.Next(3))
{
case 0:
DisplayClimb_Right_DOWN();
@ -625,7 +628,7 @@ namespace VPet_Simulator.Core
//看看距离是不是不足
if (Core.Controller.GetWindowsDistanceLeft() < 50 * Core.Controller.ZoomRatio)
{//是,停下恢复默认 or向下爬
switch (3)//Function.Rnd.Next(3))
switch (Function.Rnd.Next(3))
{
case 0:
DisplayClimb_Left_DOWN();
@ -678,8 +681,8 @@ namespace VPet_Simulator.Core
{
PetGrid.Visibility = Visibility.Visible;
PetGrid2.Visibility = Visibility.Collapsed;
});
((IGraph)(PetGrid.Child)).Run(EndAction);
});
graph.Run(EndAction);
return;
}
else if (PetGrid2.Child == graph.This)
@ -689,7 +692,7 @@ namespace VPet_Simulator.Core
PetGrid2.Visibility = Visibility.Visible;
PetGrid.Visibility = Visibility.Collapsed;
});
((IGraph)(PetGrid2.Child)).Run(EndAction);
graph.Run(EndAction);
return;
}
graph.Run(EndAction);

@ -19,7 +19,7 @@ namespace VPet_Simulator.Core
/// <summary>
/// MessageBar.xaml 的交互逻辑
/// </summary>
public partial class MessageBar : UserControl
public partial class MessageBar : UserControl, IDisposable
{
public MessageBar()
{
@ -98,5 +98,12 @@ namespace VPet_Simulator.Core
this.Visibility = Visibility.Collapsed;
EndAction?.Invoke();
}
public void Dispose()
{
EndTimer.Dispose();
ShowTimer.Dispose();
CloseTimer.Dispose();
}
}
}

@ -22,12 +22,12 @@ namespace VPet_Simulator.Core
/// <summary>
/// ToolBar.xaml 的交互逻辑
/// </summary>
public partial class ToolBar : UserControl
public partial class ToolBar : UserControl, IDisposable
{
Main m;
Timer closetimer;
bool onFocus = false;
DispatcherTimer closePanelTimer;
Timer closePanelTimer;
public ToolBar(Main m)
{
@ -40,11 +40,8 @@ namespace VPet_Simulator.Core
Enabled = false
};
closetimer.Elapsed += Closetimer_Elapsed;
closePanelTimer = new DispatcherTimer()
{
Interval = TimeSpan.FromSeconds(0.1),
};
closePanelTimer.Tick += ClosePanelTimer_Tick;
closePanelTimer = new Timer();
closePanelTimer.Elapsed += ClosePanelTimer_Tick;
m.TimeUIHandle += M_TimeUIHandle;
}
@ -70,13 +67,16 @@ namespace VPet_Simulator.Core
private void ClosePanelTimer_Tick(object sender, EventArgs e)
{
if (BdrPanel.IsMouseOver
|| MenuPanel.IsMouseOver)
Dispatcher.Invoke(() =>
{
closePanelTimer.Stop();
return;
}
BdrPanel.Visibility = Visibility.Collapsed;
if (BdrPanel.IsMouseOver
|| MenuPanel.IsMouseOver)
{
closePanelTimer.Stop();
return;
}
BdrPanel.Visibility = Visibility.Collapsed;
});
}
private void Closetimer_Elapsed(object sender, ElapsedEventArgs e)
@ -227,7 +227,14 @@ namespace VPet_Simulator.Core
private void MenuDIY_Click(object sender, RoutedEventArgs e)
{
m.Say("您好,我是萝莉斯, 让我来帮您熟悉并掌握使用vos系统,成为永世流传的虚拟主播.");
//m.Say("您好,我是萝莉斯, 让我来帮您熟悉并掌握使用vos系统,成为永世流传的虚拟主播.");
}
public void Dispose()
{
m = null;
closetimer.Dispose();
closePanelTimer.Dispose();
}
}
}

@ -1,4 +1,4 @@
<UserControl x:Class="VPet_Simulator.Core.IEyeTracking"
<UserControl x:Class="VPet_Simulator.Core.EyeTracking"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

@ -18,9 +18,9 @@ namespace VPet_Simulator.Core
/// <summary>
/// IEyeTracking.xaml 的交互逻辑
/// </summary>
public partial class IEyeTracking : UserControl
public partial class EyeTracking : UserControl
{
public IEyeTracking()
public EyeTracking()
{
InitializeComponent();
}

@ -0,0 +1,11 @@
<UserControl x:Class="VPet_Simulator.Core.Graph.FoodAnimation"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:VPet_Simulator.Core.Graph"
mc:Ignorable="d" d:DesignHeight="500" d:DesignWidth="500">
<Grid>
</Grid>
</UserControl>

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace VPet_Simulator.Core.Graph
{
/// <summary>
/// FoodAnimation.xaml 的交互逻辑
/// </summary>
public partial class FoodAnimation : UserControl
{
public FoodAnimation()
{
InitializeComponent();
}
}
}

@ -221,19 +221,38 @@ namespace VPet_Simulator.Core
AddGraph(new PNGAnimation(paths, modetype, graphtype, storemem), graphtype);
}
/// <summary>
/// 随机数字典(用于确保随机动画不会错位)
/// </summary>
public Dictionary<int, int> RndGraph = new Dictionary<int, int>();
/// <summary>
/// 查找动画
/// </summary>
/// <param name="type">动画类型</param>
/// <param name="mode">状态类型,找不到就找相同动画类型</param>
/// <param name="storernd">是否储存随机数字典</param>
/// <returns></returns>
public IGraph FindGraph(GraphType type, Save.ModeType mode)
public IGraph FindGraph(GraphType type, Save.ModeType mode, bool storernd = false)
{
if (Graphs.ContainsKey(type))
{
var list = Graphs[type].FindAll(x => x.ModeType == mode);
if (list.Count > 0)
{
return list[Function.Rnd.Next(list.Count)];
if (list.Count == 1)
return list[0];
if (storernd)
if (RndGraph.TryGetValue(list.Count, out int index))
{
return list[index];
}
else
{
index = Function.Rnd.Next(list.Count);
RndGraph.Add(list.Count, index);
return list[index];
}
else
return list[Function.Rnd.Next(list.Count)];
}
else
{

@ -44,6 +44,10 @@ namespace VPet_Simulator.Core
/// 是否循环播放
/// </summary>
public bool IsContinue { get; set; } = false;
///// <summary>
///// 是否重置状态从0开始播放
///// </summary>
//public bool IsResetPlay { get; set; } = false;
/// <summary>
/// 是否储存到内存以支持快速显示
/// </summary>
@ -53,8 +57,10 @@ namespace VPet_Simulator.Core
public Save.ModeType ModeType { get; private set; }
public GraphCore.GraphType GraphType { get; private set; }
//private Action endwilldo;
/// <summary>
/// 动画停止时运行的方法
/// </summary>
private Action StopAction;
int nowid;
/// <summary>
/// 新建 PNG 动画
@ -188,13 +194,14 @@ namespace VPet_Simulator.Core
//parent.Dispatcher.Invoke(Hidden);
if (parent.DoEndAction)
EndAction?.Invoke();//运行结束动画时事件
parent.StopAction?.Invoke();
parent.StopAction = null;
//重新加载第一帧
//Task.Run(() =>
//{
// Thread.Sleep(25);
// parent.Dispatcher.Invoke(Hidden);
//});
Task.Run(() =>
{
Thread.Sleep(25);
parent.Dispatcher.Invoke(Hidden);
});
return;
}
//要下一步,现在就隐藏图层
@ -209,6 +216,8 @@ namespace VPet_Simulator.Core
parent.Dispatcher.Invoke(Hidden);
if (parent.DoEndAction)
EndAction?.Invoke();//运行结束动画时事件
parent.StopAction?.Invoke();
parent.StopAction = null;
//Task.Run(() =>
//{
// Thread.Sleep(25);
@ -227,6 +236,13 @@ namespace VPet_Simulator.Core
// endwilldo.Invoke();
// endwilldo = null;
//}
if (PlayState)
{//如果当前正在运行,重置状态
//IsResetPlay = true;
Stop(true);
StopAction = () => Run(EndAction);
return;
}
nowid = 0;
PlayState = true;
DoEndAction = true;
@ -237,6 +253,7 @@ namespace VPet_Simulator.Core
{
DoEndAction = !StopEndAction;
PlayState = false;
//IsResetPlay = false;
}
}

@ -121,7 +121,11 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Graph\IEyeTracking.xaml">
<Page Include="Graph\EyeTracking.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Graph\FoodAnimation.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
@ -143,9 +147,12 @@
<Compile Include="Display\ToolBar.xaml.cs">
<DependentUpon>ToolBar.xaml</DependentUpon>
</Compile>
<Compile Include="Graph\FoodAnimation.xaml.cs">
<DependentUpon>FoodAnimation.xaml</DependentUpon>
</Compile>
<Compile Include="Graph\GraphCore.cs" />
<Compile Include="Graph\IEyeTracking.xaml.cs">
<DependentUpon>IEyeTracking.xaml</DependentUpon>
<Compile Include="Graph\EyeTracking.xaml.cs">
<DependentUpon>EyeTracking.xaml</DependentUpon>
</Compile>
<Compile Include="Graph\IGraph.cs" />
<Compile Include="Graph\Picture.xaml.cs">

@ -17,6 +17,12 @@ using System.Windows.Navigation;
using System.Windows.Shapes;
using VPet_Simulator.Core;
using static VPet_Simulator.Core.GraphCore;
using Microsoft.Win32;
using System.Windows.Forms;
using MessageBox = System.Windows.MessageBox;
using ContextMenu = System.Windows.Forms.ContextMenu;
using MenuItem = System.Windows.Forms.MenuItem;
using Application = System.Windows.Application;
namespace VPet_Simulator.Windows
{
@ -25,7 +31,7 @@ namespace VPet_Simulator.Windows
/// </summary>
public partial class MainWindow : Window
{
private NotifyIcon notifyIcon;
public MainWindow()
{
//判断是不是Steam用户,因为本软件会发布到Steam
@ -102,19 +108,52 @@ namespace VPet_Simulator.Windows
//加载游戏内容
Core.Controller = new MWController(this);
Core.Save = new Save("萝莉斯");
Dispatcher.Invoke(new Action(() => {
Dispatcher.Invoke(new Action(() =>
{
Core.Graph = Pets[0].Graph(Set.StoreInMemory);
LoadingText.Visibility = Visibility.Collapsed;
winSetting = new winGameSetting(this);
var main = new Main(Core) { };
winSetting = new winGameSetting(this);
var main = new Main(Core) { };
main.DefaultClickAction = () => { Dispatcher.Invoke(() => { main.Say("你知道吗? 鼠标右键可以打开菜单栏"); }); };
DisplayGrid.Child = main;
DisplayGrid.Child = main;
main.ToolBar.AddMenuButton(VPet_Simulator.Core.ToolBar.MenuType.DIY, "退出桌宠", () => { Close(); });
//加载图标
notifyIcon = new NotifyIcon();
ContextMenu m_menu;
m_menu = new ContextMenu();
m_menu.MenuItems.Add(new MenuItem("重置", (x, y) => {
main.CleanState();
main.DisplayNomal();
}));
m_menu.MenuItems.Add(new MenuItem("居中", (x, y) =>
{
Left = (SystemParameters.PrimaryScreenWidth - Width) / 2;
Top = (SystemParameters.PrimaryScreenHeight - Height) / 2;
}));
m_menu.MenuItems.Add(new MenuItem("设置", (x, y) => Core.Controller.ShowSetting()));
m_menu.MenuItems.Add(new MenuItem("退出", (x, y) => Close()));
notifyIcon.ContextMenu = m_menu;
var streamResourceInfo = Application.GetResourceStream(new Uri("pack://application:,,,/vpeticon.ico"));
if (streamResourceInfo != null)
notifyIcon.Icon = new System.Drawing.Icon(streamResourceInfo.Stream);
notifyIcon.Visible = true;
//notifyIcon.ShowBalloonTip(5, "你好 " + Environment.UserName,
// "Press Alt+C to show Clock\nRight Click on Tray to Close", ToolTipIcon.Info);
}));
}
private void Window_Closed(object sender, EventArgs e)
{
((Main)DisplayGrid.Child).Dispose();
notifyIcon.Dispose();
System.Environment.Exit(0);
}
//public void DEBUGValue()

@ -91,6 +91,8 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />

@ -1,6 +1,6 @@
pet#默认虚拟桌宠:|intor#虚拟主播模拟器默认人物形象:|path#vup:|
touchhead:|px#138:|py#12:|sw#224:|sh#176:|
touchraised:|px#0:|py#0:|sw#500:|sh#180:|
touchraised:|px#0:|py#50:|sw#500:|sh#200:|
raisepoint:|x#290:|y#128:|
speed:|walk#20:|climb#10:|climbtop#8:|crawl#8:|
locate:|climbleft#145:|climbright#185:|climbtop#150:|