[1.10.10]动画系统逻辑重构

This commit is contained in:
ZouJin 2024-04-17 12:48:07 +08:00
parent c255cc1ca1
commit 8be34c391b
9 changed files with 274 additions and 272 deletions

View File

@ -126,12 +126,12 @@ namespace VPet_Simulator.Core
else if (DisplayType.Animat == AnimatType.B_Loop) else if (DisplayType.Animat == AnimatType.B_Loop)
if (Dispatcher.Invoke(() => PetGrid.Tag) is IGraph ig && ig.GraphInfo.Type == GraphType.Touch_Head && ig.GraphInfo.Animat == AnimatType.B_Loop) if (Dispatcher.Invoke(() => PetGrid.Tag) is IGraph ig && ig.GraphInfo.Type == GraphType.Touch_Head && ig.GraphInfo.Animat == AnimatType.B_Loop)
{ {
ig.IsContinue = true; ig.SetContinue();
return; return;
} }
else if (Dispatcher.Invoke(() => PetGrid2.Tag) is IGraph ig2 && ig2.GraphInfo.Type == GraphType.Touch_Head && ig2.GraphInfo.Animat == AnimatType.B_Loop) else if (Dispatcher.Invoke(() => PetGrid2.Tag) is IGraph ig2 && ig2.GraphInfo.Type == GraphType.Touch_Head && ig2.GraphInfo.Animat == AnimatType.B_Loop)
{ {
ig2.IsContinue = true; ig2.SetContinue();
return; return;
} }
} }
@ -164,12 +164,12 @@ namespace VPet_Simulator.Core
else if (DisplayType.Animat == AnimatType.B_Loop) else if (DisplayType.Animat == AnimatType.B_Loop)
if (Dispatcher.Invoke(() => PetGrid.Tag) is IGraph ig && ig.GraphInfo.Type == GraphType.Touch_Body && ig.GraphInfo.Animat == AnimatType.B_Loop) if (Dispatcher.Invoke(() => PetGrid.Tag) is IGraph ig && ig.GraphInfo.Type == GraphType.Touch_Body && ig.GraphInfo.Animat == AnimatType.B_Loop)
{ {
ig.IsContinue = true; ig.SetContinue();
return; return;
} }
else if (Dispatcher.Invoke(() => PetGrid2.Tag) is IGraph ig2 && ig2.GraphInfo.Type == GraphType.Touch_Body && ig2.GraphInfo.Animat == AnimatType.B_Loop) else if (Dispatcher.Invoke(() => PetGrid2.Tag) is IGraph ig2 && ig2.GraphInfo.Type == GraphType.Touch_Body && ig2.GraphInfo.Animat == AnimatType.B_Loop)
{ {
ig2.IsContinue = true; ig2.SetContinue();
return; return;
} }
} }

View File

@ -63,22 +63,12 @@ namespace VPet_Simulator.Core
/// 所有动画帧 /// 所有动画帧
/// </summary> /// </summary>
public List<Animation> Animations; public List<Animation> Animations;
/// <summary>
/// 当前动画播放状态
/// </summary>
public bool PlayState { get; set; } = false;
/// <summary>
/// 当前动画是否执行ENDACTION
/// </summary>
private bool DoEndAction = true;
/// <summary> /// <summary>
/// 是否循环播放 /// 是否循环播放
/// </summary> /// </summary>
public bool IsLoop { get; set; } public bool IsLoop { get; set; }
/// <summary>
/// 是否继续播放
/// </summary>
public bool IsContinue { get; set; } = false;
/// <summary> /// <summary>
/// 动画信息 /// 动画信息
/// </summary> /// </summary>
@ -87,10 +77,9 @@ namespace VPet_Simulator.Core
/// 是否准备完成 /// 是否准备完成
/// </summary> /// </summary>
public bool IsReady => true; public bool IsReady => true;
/// <summary>
/// 动画停止时运行的方法 public TaskControl Control { get; set; }
/// </summary>
private Action StopAction;
int nowid; int nowid;
/// <summary> /// <summary>
/// 图片资源 /// 图片资源
@ -153,7 +142,7 @@ namespace VPet_Simulator.Core
/// <summary> /// <summary>
/// 运行该图层 /// 运行该图层
/// </summary> /// </summary>
public void Run(FrameworkElement This, Action EndAction = null) public void Run(FrameworkElement This, TaskControl Control)
{ {
//先显示该图层 //先显示该图层
This.Dispatcher.Invoke(() => This.Dispatcher.Invoke(() =>
@ -176,53 +165,43 @@ namespace VPet_Simulator.Core
//然后等待帧时间毫秒 //然后等待帧时间毫秒
Thread.Sleep(Time); Thread.Sleep(Time);
//判断是否要下一步 //判断是否要下一步
if (parent.PlayState) switch (Control.Type)
{ {
if (++parent.nowid >= parent.Animations.Count) case TaskControl.ControlType.Stop:
if (parent.IsLoop) Control.EndAction?.Invoke();
parent.nowid = 0; return;
else if (parent.IsContinue) case TaskControl.ControlType.Status_Stoped:
{ return;
parent.IsContinue = false; case TaskControl.ControlType.Status_Quo:
parent.nowid = 0; case TaskControl.ControlType.Continue:
} if (++parent.nowid >= parent.Animations.Count)
else if (parent.IsLoop)
{ parent.nowid = 0;
//parent.endwilldo = () => parent.Dispatcher.Invoke(Hidden); else if (Control.Type == TaskControl.ControlType.Continue)
//parent.Dispatcher.Invoke(Hidden); {
parent.PlayState = false; Control.Type = TaskControl.ControlType.Status_Quo;
//等待其他两个动画完成 parent.nowid = 0;
if (parent.DoEndAction) }
EndAction?.Invoke();//运行结束动画时事件 else
parent.StopAction?.Invoke(); {
parent.StopAction = null; //parent.endwilldo = () => parent.Dispatcher.Invoke(Hidden);
////延时隐藏 //parent.Dispatcher.Invoke(Hidden);
//Task.Run(() => Control.Type = TaskControl.ControlType.Status_Stoped;
//{ //等待其他两个动画完成
// Thread.Sleep(25); Control.EndAction?.Invoke(); //运行结束动画时事件
// parent.Dispatcher.Invoke(Hidden); ////延时隐藏
//}); //Task.Run(() =>
return; //{
} // Thread.Sleep(25);
//要下一步,现在就隐藏图层 // parent.Dispatcher.Invoke(Hidden);
//隐藏该图层 //});
//parent.Dispatcher.Invoke(Hidden); return;
parent.Animations[parent.nowid].Run(This, EndAction); }
return; //要下一步,现在就隐藏图层
} //隐藏该图层
else //parent.Dispatcher.Invoke(Hidden);
{ parent.Animations[parent.nowid].Run(This, Control);
parent.IsContinue = false; return;
//parent.Dispatcher.Invoke(Hidden);
if (parent.DoEndAction)
EndAction?.Invoke();//运行结束动画时事件
parent.StopAction?.Invoke();
parent.StopAction = null;
//Task.Run(() =>
//{
// Thread.Sleep(25);
// parent.Dispatcher.Invoke(Hidden);
//});
} }
} }
} }
@ -257,15 +236,13 @@ namespace VPet_Simulator.Core
public void Run(Decorator parant, ImageSource image, Action EndAction = null) public void Run(Decorator parant, ImageSource image, Action EndAction = null)
{ {
if (PlayState) if (Control?.PlayState == true)
{//如果当前正在运行,重置状态 {//如果当前正在运行,重置状态
//IsResetPlay = true; Control.Stop(() => Run(parant, EndAction));
StopAction = () => Run(parant, image, EndAction);
return; return;
} }
nowid = 0; nowid = 0;
PlayState = true; Control = new TaskControl(EndAction);
DoEndAction = true;
parant.Dispatcher.Invoke(() => parant.Dispatcher.Invoke(() =>
{ {
parant.Tag = this; parant.Tag = this;
@ -291,14 +268,8 @@ namespace VPet_Simulator.Core
} }
t1?.Start(); t1?.Start();
t2?.Start(); t2?.Start();
Task.Run(() => Animations[0].Run(FoodGrid.Food, EndAction)); Task.Run(() => Animations[0].Run(FoodGrid.Food, Control));
}); });
} }
public void Stop(bool StopEndAction = false)
{
DoEndAction = !StopEndAction;
PlayState = false;
}
} }
} }

View File

@ -12,19 +12,15 @@ namespace VPet_Simulator.Core
/// <summary> /// <summary>
/// 从0开始运行该动画 /// 从0开始运行该动画
/// </summary> /// </summary>
/// <param name="EndAction">停止动作</param>
/// <param name="parant">显示位置</param>
void Run(Decorator parant, Action EndAction = null); void Run(Decorator parant, Action EndAction = null);
/// <summary>
/// 当前动画播放状态
/// </summary>
bool PlayState { get; set; }
/// <summary> /// <summary>
/// 是否循环播放 /// 是否循环播放
/// </summary> /// </summary>
bool IsLoop { get; set; } bool IsLoop { get; set; }
/// <summary>
/// 是否继续播放
/// </summary>
bool IsContinue { get; set; }
/// <summary> /// <summary>
/// 是否准备完成 /// 是否准备完成
/// </summary> /// </summary>
@ -33,11 +29,31 @@ namespace VPet_Simulator.Core
/// 该动画信息 /// 该动画信息
/// </summary> /// </summary>
GraphInfo GraphInfo { get; } GraphInfo GraphInfo { get; }
/// <summary>
/// 当前动画播放状态和控制
/// </summary>
TaskControl Control { get; }
/// <summary> /// <summary>
/// 停止动画 /// 停止动画
/// </summary> /// </summary>
/// <param name="StopEndAction">停止动画时是否允许执行停止帧</param> /// <param name="StopEndAction">停止动画时是否不运行结束动画</param>
void Stop(bool StopEndAction = false); void Stop(bool StopEndAction)
{
if (Control == null)
return;
if (StopEndAction)
Control.EndAction = null;
Control.Type = TaskControl.ControlType.Stop;
}
/// <summary>
/// 设置为继续播放
/// </summary>
void SetContinue()
{
Control.Type = TaskControl.ControlType.Continue;
}
/// <summary> /// <summary>
/// 指示该ImageRun支持 /// 指示该ImageRun支持
/// </summary> /// </summary>
@ -51,5 +67,61 @@ namespace VPet_Simulator.Core
/// <param name="image">额外图片</param> /// <param name="image">额外图片</param>
void Run(Decorator parant, ImageSource image, Action EndAction = null); void Run(Decorator parant, ImageSource image, Action EndAction = null);
} }
/// <summary>
/// 动画控制类
/// </summary>
public class TaskControl
{
/// <summary>
/// 当前动画播放状态
/// </summary>
public bool PlayState => Type != ControlType.Status_Stoped && Type != ControlType.Stop;
/// <summary>
/// 设置为继续播放
/// </summary>
public void SetContinue() { Type = ControlType.Continue; }
/// <summary>
/// 停止播放
/// </summary>
public void Stop(Action endAction = null) { EndAction = endAction; Type = ControlType.Stop; }
/// <summary>
/// 控制类型
/// </summary>
public enum ControlType
{
/// <summary>
/// 维持现状, 不进行任何超控
/// </summary>
Status_Quo,
/// <summary>
/// 停止当前动画
/// </summary>
Stop,
/// <summary>
/// 播放完成后继续播放,仅生效一次, 之后将恢复为Status_Quo
/// </summary>
Continue,
/// <summary>
/// 动画已停止
/// </summary>
Status_Stoped,
}
/// <summary>
/// 结束动作
/// </summary>
public Action EndAction;
/// <summary>
/// 控制类型
/// </summary>
public ControlType Type = ControlType.Status_Quo;
/// <summary>
/// 为动画控制类提供操作和结束动作
/// </summary>
/// <param name="endAction"></param>
public TaskControl(Action endAction = null)
{
EndAction = endAction;
}
}
} }
} }

View File

@ -8,6 +8,7 @@ using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using static VPet_Simulator.Core.IGraph;
using static VPet_Simulator.Core.Picture; using static VPet_Simulator.Core.Picture;
namespace VPet_Simulator.Core namespace VPet_Simulator.Core
@ -23,21 +24,9 @@ namespace VPet_Simulator.Core
/// </summary> /// </summary>
public List<Animation> Animations; public List<Animation> Animations;
/// <summary> /// <summary>
/// 当前动画播放状态
/// </summary>
public bool PlayState { get; set; } = false;
/// <summary>
/// 当前动画是否执行ENDACTION
/// </summary>
private bool DoEndAction = true;
/// <summary>
/// 是否循环播放 /// 是否循环播放
/// </summary> /// </summary>
public bool IsLoop { get; set; } public bool IsLoop { get; set; }
/// <summary>
/// 是否循环播放
/// </summary>
public bool IsContinue { get; set; } = false;
/// <summary> /// <summary>
/// 动画信息 /// 动画信息
@ -48,10 +37,9 @@ namespace VPet_Simulator.Core
/// 是否准备完成 /// 是否准备完成
/// </summary> /// </summary>
public bool IsReady { get; private set; } = false; public bool IsReady { get; private set; } = false;
/// <summary>
/// 动画停止时运行的方法 public TaskControl Control { get; set; }
/// </summary>
private Action StopAction;
int nowid; int nowid;
/// <summary> /// <summary>
/// 图片资源 /// 图片资源
@ -80,6 +68,7 @@ namespace VPet_Simulator.Core
GraphCore.CommConfig["PA_Setup"] = true; GraphCore.CommConfig["PA_Setup"] = true;
GraphCore.CommUIElements["Image1.PNGAnimation"] = new System.Windows.Controls.Image() { Height = 500 }; GraphCore.CommUIElements["Image1.PNGAnimation"] = new System.Windows.Controls.Image() { Height = 500 };
GraphCore.CommUIElements["Image2.PNGAnimation"] = new System.Windows.Controls.Image() { Height = 500 }; GraphCore.CommUIElements["Image2.PNGAnimation"] = new System.Windows.Controls.Image() { Height = 500 };
GraphCore.CommUIElements["Image3.PNGAnimation"] = new System.Windows.Controls.Image() { Height = 500 }; // 多整个, 防止动画闪烁
} }
Task.Run(() => startup(path, paths)); Task.Run(() => startup(path, paths));
} }
@ -163,7 +152,6 @@ namespace VPet_Simulator.Core
Interlocked.Decrement(ref NowLoading); Interlocked.Decrement(ref NowLoading);
} }
/// <summary> /// <summary>
/// 单帧动画 /// 单帧动画
/// </summary> /// </summary>
@ -194,60 +182,41 @@ namespace VPet_Simulator.Core
/// <summary> /// <summary>
/// 运行该图层 /// 运行该图层
/// </summary> /// </summary>
public void Run(FrameworkElement This, Action EndAction = null) /// <param name="Control">动画控制</param>
/// <param name="This">显示的图层</param>
public void Run(FrameworkElement This, TaskControl Control)
{ {
//先显示该图层 //先显示该图层
This.Dispatcher.Invoke(() => This.Margin = new Thickness(MarginWIX, 0, 0, 0)); This.Dispatcher.Invoke(() => This.Margin = new Thickness(MarginWIX, 0, 0, 0));
//然后等待帧时间毫秒 //然后等待帧时间毫秒
Thread.Sleep(Time); Thread.Sleep(Time);
//判断是否要下一步 //判断是否要下一步
if (parent.PlayState) switch (Control.Type)
{ {
if (++parent.nowid >= parent.Animations.Count) case TaskControl.ControlType.Stop:
if (parent.IsLoop) Control.EndAction?.Invoke();
parent.nowid = 0; return;
else if (parent.IsContinue) case TaskControl.ControlType.Status_Stoped:
{ return;
parent.IsContinue = false; case TaskControl.ControlType.Status_Quo:
parent.nowid = 0; case TaskControl.ControlType.Continue:
} if (++parent.nowid >= parent.Animations.Count)
else if (parent.IsLoop)
{ parent.nowid = 0;
//parent.endwilldo = () => parent.Dispatcher.Invoke(Hidden); else if (Control.Type == TaskControl.ControlType.Continue)
//parent.Dispatcher.Invoke(Hidden); {
parent.PlayState = false; Control.Type = TaskControl.ControlType.Status_Quo;
if (parent.DoEndAction) parent.nowid = 0;
EndAction?.Invoke();//运行结束动画时事件 }
parent.StopAction?.Invoke(); else
parent.StopAction = null; {
////延时隐藏 Control.Type = TaskControl.ControlType.Status_Stoped;
//Task.Run(() => Control.EndAction?.Invoke(); //运行结束动画时事件
//{ return;
// Thread.Sleep(25); }
// parent.Dispatcher.Invoke(Hidden); //要下一步
//}); parent.Animations[parent.nowid].Run(This, Control);
return; return;
}
//要下一步,现在就隐藏图层
//隐藏该图层
//parent.Dispatcher.Invoke(Hidden);
parent.Animations[parent.nowid].Run(This, EndAction);
return;
}
else
{
parent.IsContinue = false;
//不运行结束事件
////parent.Dispatcher.Invoke(Hidden);
//if (parent.DoEndAction)
// EndAction?.Invoke();//运行结束动画时事件
//parent.StopAction?.Invoke();
//parent.StopAction = null;
////Task.Run(() =>
////{
//// Thread.Sleep(25);
//// parent.Dispatcher.Invoke(Hidden);
////});
} }
} }
} }
@ -256,31 +225,23 @@ namespace VPet_Simulator.Core
/// </summary> /// </summary>
public void Run(Decorator parant, Action EndAction = null) public void Run(Decorator parant, Action EndAction = null)
{ {
//if(endwilldo != null && nowid != Animations.Count)
//{
// endwilldo.Invoke();
// endwilldo = null;
//}
if (!IsReady) if (!IsReady)
{ {
EndAction?.Invoke(); EndAction?.Invoke();
return; return;
} }
if (PlayState) if (Control?.PlayState == true)
{//如果当前正在运行,重置状态 {//如果当前正在运行,重置状态
//IsResetPlay = true; Control.Stop(() => Run(parant, EndAction));
Stop();
StopAction = () => Run(parant, EndAction);
return; return;
} }
nowid = 0; nowid = 0;
PlayState = true; Control = new TaskControl(EndAction);
DoEndAction = true;
parant.Dispatcher.Invoke(() => parant.Dispatcher.Invoke(() =>
{ {
if (parant.Tag == this) if (parant.Tag == this)
{ {
Task.Run(() => Animations[0].Run((System.Windows.Controls.Image)parant.Child, EndAction)); Task.Run(() => Animations[0].Run((System.Windows.Controls.Image)parant.Child, Control));
return; return;
} }
System.Windows.Controls.Image img; System.Windows.Controls.Image img;
@ -289,6 +250,10 @@ namespace VPet_Simulator.Core
{ {
img = (System.Windows.Controls.Image)GraphCore.CommUIElements["Image1.PNGAnimation"]; img = (System.Windows.Controls.Image)GraphCore.CommUIElements["Image1.PNGAnimation"];
} }
else if (parant.Child == GraphCore.CommUIElements["Image3.PNGAnimation"])
{
img = (System.Windows.Controls.Image)GraphCore.CommUIElements["Image3.PNGAnimation"];
}
else else
{ {
img = (System.Windows.Controls.Image)GraphCore.CommUIElements["Image2.PNGAnimation"]; img = (System.Windows.Controls.Image)GraphCore.CommUIElements["Image2.PNGAnimation"];
@ -308,16 +273,9 @@ namespace VPet_Simulator.Core
} }
} }
parant.Tag = this; parant.Tag = this;
//var bitmap = new BitmapImage();
//bitmap.BeginInit();
//stream.Seek(0, SeekOrigin.Begin);
//bitmap.StreamSource = stream;
//bitmap.CacheOption = BitmapCacheOption.OnLoad;
//bitmap.EndInit();
img.Source = new BitmapImage(new Uri(Path)); img.Source = new BitmapImage(new Uri(Path));
img.Width = Width; img.Width = Width;
Task.Run(() => Animations[0].Run((System.Windows.Controls.Image)parant.Child, EndAction)); Task.Run(() => Animations[0].Run((System.Windows.Controls.Image)parant.Child, Control));
}); });
} }
/// <summary> /// <summary>
@ -328,26 +286,30 @@ namespace VPet_Simulator.Core
/// <returns>准备好的线程</returns> /// <returns>准备好的线程</returns>
public Task Run(System.Windows.Controls.Image img, Action EndAction = null) public Task Run(System.Windows.Controls.Image img, Action EndAction = null)
{ {
if (!IsReady)
{
EndAction?.Invoke();
return Task.CompletedTask;
}
if (Control?.PlayState == true)
{//如果当前正在运行,重置状态
Control.EndAction = null;
Control.Type = TaskControl.ControlType.Stop;
}
nowid = 0; nowid = 0;
PlayState = true; Control = new TaskControl(EndAction);
DoEndAction = true;
return img.Dispatcher.Invoke(() => return img.Dispatcher.Invoke(() =>
{ {
if (img.Tag == this) if (img.Tag == this)
{ {
return new Task(() => Animations[0].Run(img, EndAction)); return new Task(() => Animations[0].Run(img, Control));
} }
img.Tag = this; img.Tag = this;
img.Source = new BitmapImage(new Uri(Path)); img.Source = new BitmapImage(new Uri(Path));
img.Width = Width; img.Width = Width;
return new Task(() => Animations[0].Run(img, EndAction)); return new Task(() => Animations[0].Run(img, Control));
}); });
}
public void Stop(bool StopEndAction = false)
{
DoEndAction = !StopEndAction;
PlayState = false;
//IsResetPlay = false;
} }
} }
} }

View File

@ -6,6 +6,8 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
using static VPet_Simulator.Core.IGraph;
using static VPet_Simulator.Core.Picture; using static VPet_Simulator.Core.Picture;
@ -32,6 +34,7 @@ namespace VPet_Simulator.Core
GraphCore.CommConfig["PIC_Setup"] = true; GraphCore.CommConfig["PIC_Setup"] = true;
GraphCore.CommUIElements["Image1.Picture"] = new Image() { Width = 500, Height = 500 }; GraphCore.CommUIElements["Image1.Picture"] = new Image() { Width = 500, Height = 500 };
GraphCore.CommUIElements["Image2.Picture"] = new Image() { Width = 500, Height = 500 }; GraphCore.CommUIElements["Image2.Picture"] = new Image() { Width = 500, Height = 500 };
GraphCore.CommUIElements["Image3.Picture"] = new Image() { Width = 500, Height = 500 };
} }
} }
public static void LoadGraph(GraphCore graph, FileSystemInfo path, ILine info) public static void LoadGraph(GraphCore graph, FileSystemInfo path, ILine info)
@ -56,11 +59,12 @@ namespace VPet_Simulator.Core
/// </summary> /// </summary>
public string Path; public string Path;
private GraphCore GraphCore; private GraphCore GraphCore;
public bool PlayState { get; set; }
public bool IsLoop { get; set; } public bool IsLoop { get; set; }
/// <summary>
/// 播放持续时间 毫秒
/// </summary>
public int Length { get; set; } public int Length { get; set; }
//public bool StoreMemory => true;//经过测试,储存到内存好处多多,不储存也要占用很多内存,干脆存了吧 //public bool StoreMemory => true;//经过测试,储存到内存好处多多,不储存也要占用很多内存,干脆存了吧
public bool IsContinue { get; set; }
/// <summary> /// <summary>
/// 动画信息 /// 动画信息
@ -69,15 +73,18 @@ namespace VPet_Simulator.Core
public bool IsReady => true; public bool IsReady => true;
public TaskControl Control { get; set; }
public void Run(Decorator parant, Action EndAction = null) public void Run(Decorator parant, Action EndAction = null)
{ {
if (PlayState) if (Control?.PlayState == true)
{ {//如果当前正在运行,重置状态
IsContinue = true; Control.SetContinue();
Control.EndAction = EndAction;
return; return;
} }
PlayState = true; Control = new TaskControl(EndAction);
DoEndAction = true;
parant.Dispatcher.Invoke(() => parant.Dispatcher.Invoke(() =>
{ {
if (parant.Tag != this) if (parant.Tag != this)
@ -87,6 +94,10 @@ namespace VPet_Simulator.Core
{ {
img = (Image)GraphCore.CommUIElements["Image1.Picture"]; img = (Image)GraphCore.CommUIElements["Image1.Picture"];
} }
else if (parant.Child == GraphCore.CommUIElements["Image3.Picture"])
{
img = (Image)GraphCore.CommUIElements["Image3.Picture"];
}
else else
{ {
img = (Image)GraphCore.CommUIElements["Image2.Picture"]; img = (Image)GraphCore.CommUIElements["Image2.Picture"];
@ -94,7 +105,6 @@ namespace VPet_Simulator.Core
{ {
if (img.Parent == null) if (img.Parent == null)
{ {
parant.Child = null;
parant.Child = img; parant.Child = img;
} }
else else
@ -106,78 +116,65 @@ namespace VPet_Simulator.Core
} }
} }
} }
//var bitmap = new BitmapImage();
//bitmap.BeginInit();
//stream.Seek(0, SeekOrigin.Begin);
//bitmap.StreamSource = stream;
//bitmap.CacheOption = BitmapCacheOption.OnLoad;
//bitmap.EndInit();
img.Width = 500; img.Width = 500;
img.Source = new BitmapImage(new Uri(Path)); img.Source = new BitmapImage(new Uri(Path));
parant.Tag = this; parant.Tag = this;
} }
Task.Run(() => Task.Run(() => Run(Control));
{
Thread.Sleep(Length);
if (IsLoop && PlayState)
{
Run(parant, EndAction);
}
else
{
PlayState = false;
if (DoEndAction)
EndAction?.Invoke();//运行结束动画时事件
}
});
}); });
} }
bool DoEndAction = true; bool DoEndAction = true;
public void Stop(bool StopEndAction = false) /// <summary>
/// 通过控制器运行
/// </summary>
/// <param name="Control"></param>
public void Run(TaskControl Control)
{ {
PlayState = false; Thread.Sleep(Length);
this.DoEndAction = !StopEndAction; //判断是否要下一步
switch (Control.Type)
{
case TaskControl.ControlType.Stop:
Control.EndAction?.Invoke();
return;
case TaskControl.ControlType.Status_Stoped:
return;
case TaskControl.ControlType.Continue:
Control.Type = TaskControl.ControlType.Status_Quo;
Run(Control);
return;
case TaskControl.ControlType.Status_Quo:
if (IsLoop)
{
Run(Control);
}
else
{
Control.Type = TaskControl.ControlType.Status_Stoped;
Control.EndAction?.Invoke(); //运行结束动画时事件
}
return;
}
} }
public Task Run(System.Windows.Controls.Image img, Action EndAction = null)
public Task Run(Image img, Action EndAction = null)
{ {
PlayState = true; if (Control?.PlayState == true)
DoEndAction = true; {//如果当前正在运行,重置状态
Control.EndAction = null;
Control.Type = TaskControl.ControlType.Stop;
}
Control = new TaskControl(EndAction);
return img.Dispatcher.Invoke(() => return img.Dispatcher.Invoke(() =>
{ {
if (img.Tag == this) if (img.Tag == this)
{ {
return new Task(() => return new Task(() => Run(Control));
{
Thread.Sleep(Length);
if (IsLoop && PlayState)
{
Run(img, EndAction);
}
else
{
PlayState = false;
if (DoEndAction)
EndAction?.Invoke();//运行结束动画时事件
}
});
} }
img.Tag = this; img.Tag = this;
img.Source = new BitmapImage(new Uri(Path)); img.Source = new BitmapImage(new Uri(Path));
img.Width = 500; img.Width = 500;
return new Task(() => return new Task(() => Run(Control));
{
Thread.Sleep(Length);
if (IsLoop && PlayState)
{
Run(img, EndAction);
}
else
{
PlayState = false;
if (DoEndAction)
EndAction?.Invoke();//运行结束动画时事件
}
});
}); });
} }
public interface IImageRun : IGraph public interface IImageRun : IGraph

View File

@ -2193,12 +2193,12 @@ namespace VPet_Simulator.Windows
else if (Main.DisplayType.Animat == AnimatType.B_Loop) else if (Main.DisplayType.Animat == AnimatType.B_Loop)
if (Dispatcher.Invoke(() => Main.PetGrid.Tag) is IGraph ig && ig.GraphInfo.Name == "pinch" && ig.GraphInfo.Animat == AnimatType.B_Loop) if (Dispatcher.Invoke(() => Main.PetGrid.Tag) is IGraph ig && ig.GraphInfo.Name == "pinch" && ig.GraphInfo.Animat == AnimatType.B_Loop)
{ {
ig.IsContinue = true; ig.SetContinue();
return true; return true;
} }
else if (Dispatcher.Invoke(() => Main.PetGrid2.Tag) is IGraph ig2 && ig2.GraphInfo.Name == "pinch" && ig2.GraphInfo.Animat == AnimatType.B_Loop) else if (Dispatcher.Invoke(() => Main.PetGrid2.Tag) is IGraph ig2 && ig2.GraphInfo.Name == "pinch" && ig2.GraphInfo.Animat == AnimatType.B_Loop)
{ {
ig2.IsContinue = true; ig2.SetContinue();
return true; return true;
} }
} }

View File

@ -404,7 +404,7 @@ namespace VPet_Simulator.Windows
{ {
foreach (var ig3 in ig2) foreach (var ig3 in ig2)
{ {
ig3.Stop(); ig3.Stop(true);
} }
} }
} }
@ -455,7 +455,7 @@ namespace VPet_Simulator.Windows
{ {
foreach (var ig3 in ig2) foreach (var ig3 in ig2)
{ {
ig3.Stop(); ig3.Stop(true);
} }
} }
} }

View File

@ -482,12 +482,12 @@ public partial class MPFriends : WindowX, IMPFriend
else if (Main.DisplayType.Animat == AnimatType.B_Loop) else if (Main.DisplayType.Animat == AnimatType.B_Loop)
if (Dispatcher.Invoke(() => Main.PetGrid.Tag) is IGraph ig && ig.GraphInfo.Name == "pinch" && ig.GraphInfo.Animat == AnimatType.B_Loop) if (Dispatcher.Invoke(() => Main.PetGrid.Tag) is IGraph ig && ig.GraphInfo.Name == "pinch" && ig.GraphInfo.Animat == AnimatType.B_Loop)
{ {
ig.IsContinue = true; ig.SetContinue();
return true; return true;
} }
else if (Dispatcher.Invoke(() => Main.PetGrid2.Tag) is IGraph ig2 && ig2.GraphInfo.Name == "pinch" && ig2.GraphInfo.Animat == AnimatType.B_Loop) else if (Dispatcher.Invoke(() => Main.PetGrid2.Tag) is IGraph ig2 && ig2.GraphInfo.Name == "pinch" && ig2.GraphInfo.Animat == AnimatType.B_Loop)
{ {
ig2.IsContinue = true; ig2.SetContinue();
return true; return true;
} }
} }
@ -522,12 +522,12 @@ public partial class MPFriends : WindowX, IMPFriend
else if (Main.DisplayType.Animat == AnimatType.B_Loop) else if (Main.DisplayType.Animat == AnimatType.B_Loop)
if (Dispatcher.Invoke(() => Main.PetGrid.Tag) is IGraph ig && ig.GraphInfo.Type == GraphType.Touch_Head && ig.GraphInfo.Animat == AnimatType.B_Loop) if (Dispatcher.Invoke(() => Main.PetGrid.Tag) is IGraph ig && ig.GraphInfo.Type == GraphType.Touch_Head && ig.GraphInfo.Animat == AnimatType.B_Loop)
{ {
ig.IsContinue = true; ig.SetContinue();
return; return;
} }
else if (Dispatcher.Invoke(() => Main.PetGrid2.Tag) is IGraph ig2 && ig2.GraphInfo.Type == GraphType.Touch_Head && ig2.GraphInfo.Animat == AnimatType.B_Loop) else if (Dispatcher.Invoke(() => Main.PetGrid2.Tag) is IGraph ig2 && ig2.GraphInfo.Type == GraphType.Touch_Head && ig2.GraphInfo.Animat == AnimatType.B_Loop)
{ {
ig2.IsContinue = true; ig2.SetContinue();
return; return;
} }
} }
@ -548,12 +548,12 @@ public partial class MPFriends : WindowX, IMPFriend
else if (Main.DisplayType.Animat == AnimatType.B_Loop) else if (Main.DisplayType.Animat == AnimatType.B_Loop)
if (Dispatcher.Invoke(() => Main.PetGrid.Tag) is IGraph ig && ig.GraphInfo.Type == GraphType.Touch_Body && ig.GraphInfo.Animat == AnimatType.B_Loop) if (Dispatcher.Invoke(() => Main.PetGrid.Tag) is IGraph ig && ig.GraphInfo.Type == GraphType.Touch_Body && ig.GraphInfo.Animat == AnimatType.B_Loop)
{ {
ig.IsContinue = true; ig.SetContinue();
return; return;
} }
else if (Dispatcher.Invoke(() => Main.PetGrid2.Tag) is IGraph ig2 && ig2.GraphInfo.Type == GraphType.Touch_Body && ig2.GraphInfo.Animat == AnimatType.B_Loop) else if (Dispatcher.Invoke(() => Main.PetGrid2.Tag) is IGraph ig2 && ig2.GraphInfo.Type == GraphType.Touch_Body && ig2.GraphInfo.Animat == AnimatType.B_Loop)
{ {
ig2.IsContinue = true; ig2.SetContinue();
return; return;
} }
} }
@ -574,12 +574,12 @@ public partial class MPFriends : WindowX, IMPFriend
else if (Main.DisplayType.Animat == AnimatType.B_Loop) else if (Main.DisplayType.Animat == AnimatType.B_Loop)
if (Dispatcher.Invoke(() => Main.PetGrid.Tag) is IGraph ig && ig.GraphInfo.Type == GraphType.Touch_Body && ig.GraphInfo.Animat == AnimatType.B_Loop) if (Dispatcher.Invoke(() => Main.PetGrid.Tag) is IGraph ig && ig.GraphInfo.Type == GraphType.Touch_Body && ig.GraphInfo.Animat == AnimatType.B_Loop)
{ {
ig.IsContinue = true; ig.SetContinue();
return; return;
} }
else if (Dispatcher.Invoke(() => Main.PetGrid2.Tag) is IGraph ig2 && ig2.GraphInfo.Type == GraphType.Touch_Body && ig2.GraphInfo.Animat == AnimatType.B_Loop) else if (Dispatcher.Invoke(() => Main.PetGrid2.Tag) is IGraph ig2 && ig2.GraphInfo.Type == GraphType.Touch_Body && ig2.GraphInfo.Animat == AnimatType.B_Loop)
{ {
ig2.IsContinue = true; ig2.SetContinue();
return; return;
} }
} }
@ -723,7 +723,7 @@ public partial class MPFriends : WindowX, IMPFriend
{ {
foreach (var ig3 in ig2) foreach (var ig3 in ig2)
{ {
ig3.Stop(); ig3.Stop(true);
} }
} }
} }

View File

@ -486,12 +486,12 @@ public partial class winMutiPlayer : WindowX, IMPWindows
else if (mw.Main.DisplayType.Animat == AnimatType.B_Loop) else if (mw.Main.DisplayType.Animat == AnimatType.B_Loop)
if (Dispatcher.Invoke(() => mw.Main.PetGrid.Tag) is IGraph ig && ig.GraphInfo.Type == GraphType.Touch_Head && ig.GraphInfo.Animat == AnimatType.B_Loop) if (Dispatcher.Invoke(() => mw.Main.PetGrid.Tag) is IGraph ig && ig.GraphInfo.Type == GraphType.Touch_Head && ig.GraphInfo.Animat == AnimatType.B_Loop)
{ {
ig.IsContinue = true; ig.SetContinue();
return; return;
} }
else if (Dispatcher.Invoke(() => mw.Main.PetGrid2.Tag) is IGraph ig2 && ig2.GraphInfo.Type == GraphType.Touch_Head && ig2.GraphInfo.Animat == AnimatType.B_Loop) else if (Dispatcher.Invoke(() => mw.Main.PetGrid2.Tag) is IGraph ig2 && ig2.GraphInfo.Type == GraphType.Touch_Head && ig2.GraphInfo.Animat == AnimatType.B_Loop)
{ {
ig2.IsContinue = true; ig2.SetContinue();
return; return;
} }
} }
@ -512,12 +512,12 @@ public partial class winMutiPlayer : WindowX, IMPWindows
else if (mw.Main.DisplayType.Animat == AnimatType.B_Loop) else if (mw.Main.DisplayType.Animat == AnimatType.B_Loop)
if (Dispatcher.Invoke(() => mw.Main.PetGrid.Tag) is IGraph ig && ig.GraphInfo.Type == GraphType.Touch_Body && ig.GraphInfo.Animat == AnimatType.B_Loop) if (Dispatcher.Invoke(() => mw.Main.PetGrid.Tag) is IGraph ig && ig.GraphInfo.Type == GraphType.Touch_Body && ig.GraphInfo.Animat == AnimatType.B_Loop)
{ {
ig.IsContinue = true; ig.SetContinue();
return; return;
} }
else if (Dispatcher.Invoke(() => mw.Main.PetGrid2.Tag) is IGraph ig2 && ig2.GraphInfo.Type == GraphType.Touch_Body && ig2.GraphInfo.Animat == AnimatType.B_Loop) else if (Dispatcher.Invoke(() => mw.Main.PetGrid2.Tag) is IGraph ig2 && ig2.GraphInfo.Type == GraphType.Touch_Body && ig2.GraphInfo.Animat == AnimatType.B_Loop)
{ {
ig2.IsContinue = true; ig2.SetContinue();
return; return;
} }
} }
@ -538,12 +538,12 @@ public partial class winMutiPlayer : WindowX, IMPWindows
else if (mw.Main.DisplayType.Animat == AnimatType.B_Loop) else if (mw.Main.DisplayType.Animat == AnimatType.B_Loop)
if (Dispatcher.Invoke(() => mw.Main.PetGrid.Tag) is IGraph ig && ig.GraphInfo.Type == GraphType.Touch_Head && ig.GraphInfo.Animat == AnimatType.B_Loop) if (Dispatcher.Invoke(() => mw.Main.PetGrid.Tag) is IGraph ig && ig.GraphInfo.Type == GraphType.Touch_Head && ig.GraphInfo.Animat == AnimatType.B_Loop)
{ {
ig.IsContinue = true; ig.SetContinue();
return; return;
} }
else if (Dispatcher.Invoke(() => mw.Main.PetGrid2.Tag) is IGraph ig2 && ig2.GraphInfo.Type == GraphType.Touch_Head && ig2.GraphInfo.Animat == AnimatType.B_Loop) else if (Dispatcher.Invoke(() => mw.Main.PetGrid2.Tag) is IGraph ig2 && ig2.GraphInfo.Type == GraphType.Touch_Head && ig2.GraphInfo.Animat == AnimatType.B_Loop)
{ {
ig2.IsContinue = true; ig2.SetContinue();
return; return;
} }
} }