mirror of
https://github.com/LorisYounger/VPet.git
synced 2024-08-30 18:42:36 +00:00
[1.10.10]动画系统逻辑重构
This commit is contained in:
parent
c255cc1ca1
commit
8be34c391b
@ -126,12 +126,12 @@ namespace VPet_Simulator.Core
|
||||
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)
|
||||
{
|
||||
ig.IsContinue = true;
|
||||
ig.SetContinue();
|
||||
return;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -164,12 +164,12 @@ namespace VPet_Simulator.Core
|
||||
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)
|
||||
{
|
||||
ig.IsContinue = true;
|
||||
ig.SetContinue();
|
||||
return;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -63,22 +63,12 @@ namespace VPet_Simulator.Core
|
||||
/// 所有动画帧
|
||||
/// </summary>
|
||||
public List<Animation> Animations;
|
||||
/// <summary>
|
||||
/// 当前动画播放状态
|
||||
/// </summary>
|
||||
public bool PlayState { get; set; } = false;
|
||||
/// <summary>
|
||||
/// 当前动画是否执行ENDACTION
|
||||
/// </summary>
|
||||
private bool DoEndAction = true;
|
||||
|
||||
/// <summary>
|
||||
/// 是否循环播放
|
||||
/// </summary>
|
||||
public bool IsLoop { get; set; }
|
||||
/// <summary>
|
||||
/// 是否继续播放
|
||||
/// </summary>
|
||||
public bool IsContinue { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 动画信息
|
||||
/// </summary>
|
||||
@ -87,10 +77,9 @@ namespace VPet_Simulator.Core
|
||||
/// 是否准备完成
|
||||
/// </summary>
|
||||
public bool IsReady => true;
|
||||
/// <summary>
|
||||
/// 动画停止时运行的方法
|
||||
/// </summary>
|
||||
private Action StopAction;
|
||||
|
||||
public TaskControl Control { get; set; }
|
||||
|
||||
int nowid;
|
||||
/// <summary>
|
||||
/// 图片资源
|
||||
@ -153,7 +142,7 @@ namespace VPet_Simulator.Core
|
||||
/// <summary>
|
||||
/// 运行该图层
|
||||
/// </summary>
|
||||
public void Run(FrameworkElement This, Action EndAction = null)
|
||||
public void Run(FrameworkElement This, TaskControl Control)
|
||||
{
|
||||
//先显示该图层
|
||||
This.Dispatcher.Invoke(() =>
|
||||
@ -176,53 +165,43 @@ namespace VPet_Simulator.Core
|
||||
//然后等待帧时间毫秒
|
||||
Thread.Sleep(Time);
|
||||
//判断是否要下一步
|
||||
if (parent.PlayState)
|
||||
switch (Control.Type)
|
||||
{
|
||||
if (++parent.nowid >= parent.Animations.Count)
|
||||
if (parent.IsLoop)
|
||||
parent.nowid = 0;
|
||||
else if (parent.IsContinue)
|
||||
{
|
||||
parent.IsContinue = false;
|
||||
parent.nowid = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//parent.endwilldo = () => parent.Dispatcher.Invoke(Hidden);
|
||||
//parent.Dispatcher.Invoke(Hidden);
|
||||
parent.PlayState = false;
|
||||
//等待其他两个动画完成
|
||||
if (parent.DoEndAction)
|
||||
EndAction?.Invoke();//运行结束动画时事件
|
||||
parent.StopAction?.Invoke();
|
||||
parent.StopAction = null;
|
||||
////延时隐藏
|
||||
//Task.Run(() =>
|
||||
//{
|
||||
// Thread.Sleep(25);
|
||||
// parent.Dispatcher.Invoke(Hidden);
|
||||
//});
|
||||
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);
|
||||
//});
|
||||
case TaskControl.ControlType.Stop:
|
||||
Control.EndAction?.Invoke();
|
||||
return;
|
||||
case TaskControl.ControlType.Status_Stoped:
|
||||
return;
|
||||
case TaskControl.ControlType.Status_Quo:
|
||||
case TaskControl.ControlType.Continue:
|
||||
if (++parent.nowid >= parent.Animations.Count)
|
||||
if (parent.IsLoop)
|
||||
parent.nowid = 0;
|
||||
else if (Control.Type == TaskControl.ControlType.Continue)
|
||||
{
|
||||
Control.Type = TaskControl.ControlType.Status_Quo;
|
||||
parent.nowid = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//parent.endwilldo = () => parent.Dispatcher.Invoke(Hidden);
|
||||
//parent.Dispatcher.Invoke(Hidden);
|
||||
Control.Type = TaskControl.ControlType.Status_Stoped;
|
||||
//等待其他两个动画完成
|
||||
Control.EndAction?.Invoke(); //运行结束动画时事件
|
||||
////延时隐藏
|
||||
//Task.Run(() =>
|
||||
//{
|
||||
// Thread.Sleep(25);
|
||||
// parent.Dispatcher.Invoke(Hidden);
|
||||
//});
|
||||
return;
|
||||
}
|
||||
//要下一步,现在就隐藏图层
|
||||
//隐藏该图层
|
||||
//parent.Dispatcher.Invoke(Hidden);
|
||||
parent.Animations[parent.nowid].Run(This, Control);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -257,15 +236,13 @@ namespace VPet_Simulator.Core
|
||||
|
||||
public void Run(Decorator parant, ImageSource image, Action EndAction = null)
|
||||
{
|
||||
if (PlayState)
|
||||
if (Control?.PlayState == true)
|
||||
{//如果当前正在运行,重置状态
|
||||
//IsResetPlay = true;
|
||||
StopAction = () => Run(parant, image, EndAction);
|
||||
Control.Stop(() => Run(parant, EndAction));
|
||||
return;
|
||||
}
|
||||
nowid = 0;
|
||||
PlayState = true;
|
||||
DoEndAction = true;
|
||||
Control = new TaskControl(EndAction);
|
||||
parant.Dispatcher.Invoke(() =>
|
||||
{
|
||||
parant.Tag = this;
|
||||
@ -291,14 +268,8 @@ namespace VPet_Simulator.Core
|
||||
}
|
||||
t1?.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,19 +12,15 @@ namespace VPet_Simulator.Core
|
||||
/// <summary>
|
||||
/// 从0开始运行该动画
|
||||
/// </summary>
|
||||
/// <param name="EndAction">停止动作</param>
|
||||
/// <param name="parant">显示位置</param>
|
||||
void Run(Decorator parant, Action EndAction = null);
|
||||
/// <summary>
|
||||
/// 当前动画播放状态
|
||||
/// </summary>
|
||||
bool PlayState { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否循环播放
|
||||
/// </summary>
|
||||
bool IsLoop { get; set; }
|
||||
/// <summary>
|
||||
/// 是否继续播放
|
||||
/// </summary>
|
||||
bool IsContinue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否准备完成
|
||||
/// </summary>
|
||||
@ -33,11 +29,31 @@ namespace VPet_Simulator.Core
|
||||
/// 该动画信息
|
||||
/// </summary>
|
||||
GraphInfo GraphInfo { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前动画播放状态和控制
|
||||
/// </summary>
|
||||
TaskControl Control { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 停止动画
|
||||
/// </summary>
|
||||
/// <param name="StopEndAction">停止动画时是否允许执行停止帧</param>
|
||||
void Stop(bool StopEndAction = false);
|
||||
/// <param name="StopEndAction">停止动画时是否不运行结束动画</param>
|
||||
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>
|
||||
/// 指示该ImageRun支持
|
||||
/// </summary>
|
||||
@ -51,5 +67,61 @@ namespace VPet_Simulator.Core
|
||||
/// <param name="image">额外图片</param>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media.Imaging;
|
||||
using static VPet_Simulator.Core.IGraph;
|
||||
using static VPet_Simulator.Core.Picture;
|
||||
|
||||
namespace VPet_Simulator.Core
|
||||
@ -23,21 +24,9 @@ namespace VPet_Simulator.Core
|
||||
/// </summary>
|
||||
public List<Animation> Animations;
|
||||
/// <summary>
|
||||
/// 当前动画播放状态
|
||||
/// </summary>
|
||||
public bool PlayState { get; set; } = false;
|
||||
/// <summary>
|
||||
/// 当前动画是否执行ENDACTION
|
||||
/// </summary>
|
||||
private bool DoEndAction = true;
|
||||
/// <summary>
|
||||
/// 是否循环播放
|
||||
/// </summary>
|
||||
public bool IsLoop { get; set; }
|
||||
/// <summary>
|
||||
/// 是否循环播放
|
||||
/// </summary>
|
||||
public bool IsContinue { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 动画信息
|
||||
@ -48,10 +37,9 @@ namespace VPet_Simulator.Core
|
||||
/// 是否准备完成
|
||||
/// </summary>
|
||||
public bool IsReady { get; private set; } = false;
|
||||
/// <summary>
|
||||
/// 动画停止时运行的方法
|
||||
/// </summary>
|
||||
private Action StopAction;
|
||||
|
||||
public TaskControl Control { get; set; }
|
||||
|
||||
int nowid;
|
||||
/// <summary>
|
||||
/// 图片资源
|
||||
@ -80,6 +68,7 @@ namespace VPet_Simulator.Core
|
||||
GraphCore.CommConfig["PA_Setup"] = true;
|
||||
GraphCore.CommUIElements["Image1.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));
|
||||
}
|
||||
@ -163,7 +152,6 @@ namespace VPet_Simulator.Core
|
||||
Interlocked.Decrement(ref NowLoading);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 单帧动画
|
||||
/// </summary>
|
||||
@ -194,60 +182,41 @@ namespace VPet_Simulator.Core
|
||||
/// <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));
|
||||
//然后等待帧时间毫秒
|
||||
Thread.Sleep(Time);
|
||||
//判断是否要下一步
|
||||
if (parent.PlayState)
|
||||
switch (Control.Type)
|
||||
{
|
||||
if (++parent.nowid >= parent.Animations.Count)
|
||||
if (parent.IsLoop)
|
||||
parent.nowid = 0;
|
||||
else if (parent.IsContinue)
|
||||
{
|
||||
parent.IsContinue = false;
|
||||
parent.nowid = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//parent.endwilldo = () => parent.Dispatcher.Invoke(Hidden);
|
||||
//parent.Dispatcher.Invoke(Hidden);
|
||||
parent.PlayState = false;
|
||||
if (parent.DoEndAction)
|
||||
EndAction?.Invoke();//运行结束动画时事件
|
||||
parent.StopAction?.Invoke();
|
||||
parent.StopAction = null;
|
||||
////延时隐藏
|
||||
//Task.Run(() =>
|
||||
//{
|
||||
// Thread.Sleep(25);
|
||||
// parent.Dispatcher.Invoke(Hidden);
|
||||
//});
|
||||
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);
|
||||
////});
|
||||
case TaskControl.ControlType.Stop:
|
||||
Control.EndAction?.Invoke();
|
||||
return;
|
||||
case TaskControl.ControlType.Status_Stoped:
|
||||
return;
|
||||
case TaskControl.ControlType.Status_Quo:
|
||||
case TaskControl.ControlType.Continue:
|
||||
if (++parent.nowid >= parent.Animations.Count)
|
||||
if (parent.IsLoop)
|
||||
parent.nowid = 0;
|
||||
else if (Control.Type == TaskControl.ControlType.Continue)
|
||||
{
|
||||
Control.Type = TaskControl.ControlType.Status_Quo;
|
||||
parent.nowid = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Control.Type = TaskControl.ControlType.Status_Stoped;
|
||||
Control.EndAction?.Invoke(); //运行结束动画时事件
|
||||
return;
|
||||
}
|
||||
//要下一步
|
||||
parent.Animations[parent.nowid].Run(This, Control);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -256,31 +225,23 @@ namespace VPet_Simulator.Core
|
||||
/// </summary>
|
||||
public void Run(Decorator parant, Action EndAction = null)
|
||||
{
|
||||
//if(endwilldo != null && nowid != Animations.Count)
|
||||
//{
|
||||
// endwilldo.Invoke();
|
||||
// endwilldo = null;
|
||||
//}
|
||||
if (!IsReady)
|
||||
{
|
||||
EndAction?.Invoke();
|
||||
return;
|
||||
}
|
||||
if (PlayState)
|
||||
if (Control?.PlayState == true)
|
||||
{//如果当前正在运行,重置状态
|
||||
//IsResetPlay = true;
|
||||
Stop();
|
||||
StopAction = () => Run(parant, EndAction);
|
||||
Control.Stop(() => Run(parant, EndAction));
|
||||
return;
|
||||
}
|
||||
nowid = 0;
|
||||
PlayState = true;
|
||||
DoEndAction = true;
|
||||
Control = new TaskControl(EndAction);
|
||||
parant.Dispatcher.Invoke(() =>
|
||||
{
|
||||
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;
|
||||
}
|
||||
System.Windows.Controls.Image img;
|
||||
@ -289,6 +250,10 @@ namespace VPet_Simulator.Core
|
||||
{
|
||||
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
|
||||
{
|
||||
img = (System.Windows.Controls.Image)GraphCore.CommUIElements["Image2.PNGAnimation"];
|
||||
@ -308,16 +273,9 @@ namespace VPet_Simulator.Core
|
||||
}
|
||||
}
|
||||
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.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>
|
||||
@ -328,26 +286,30 @@ namespace VPet_Simulator.Core
|
||||
/// <returns>准备好的线程</returns>
|
||||
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;
|
||||
PlayState = true;
|
||||
DoEndAction = true;
|
||||
Control = new TaskControl(EndAction);
|
||||
return img.Dispatcher.Invoke(() =>
|
||||
{
|
||||
if (img.Tag == this)
|
||||
{
|
||||
return new Task(() => Animations[0].Run(img, EndAction));
|
||||
}
|
||||
img.Tag = this;
|
||||
img.Source = new BitmapImage(new Uri(Path));
|
||||
img.Width = Width;
|
||||
return new Task(() => Animations[0].Run(img, EndAction));
|
||||
});
|
||||
}
|
||||
public void Stop(bool StopEndAction = false)
|
||||
{
|
||||
DoEndAction = !StopEndAction;
|
||||
PlayState = false;
|
||||
//IsResetPlay = false;
|
||||
{
|
||||
if (img.Tag == this)
|
||||
{
|
||||
return new Task(() => Animations[0].Run(img, Control));
|
||||
}
|
||||
img.Tag = this;
|
||||
img.Source = new BitmapImage(new Uri(Path));
|
||||
img.Width = Width;
|
||||
return new Task(() => Animations[0].Run(img, Control));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
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;
|
||||
|
||||
|
||||
@ -32,6 +34,7 @@ namespace VPet_Simulator.Core
|
||||
GraphCore.CommConfig["PIC_Setup"] = true;
|
||||
GraphCore.CommUIElements["Image1.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)
|
||||
@ -56,11 +59,12 @@ namespace VPet_Simulator.Core
|
||||
/// </summary>
|
||||
public string Path;
|
||||
private GraphCore GraphCore;
|
||||
public bool PlayState { get; set; }
|
||||
public bool IsLoop { get; set; }
|
||||
/// <summary>
|
||||
/// 播放持续时间 毫秒
|
||||
/// </summary>
|
||||
public int Length { get; set; }
|
||||
//public bool StoreMemory => true;//经过测试,储存到内存好处多多,不储存也要占用很多内存,干脆存了吧
|
||||
public bool IsContinue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 动画信息
|
||||
@ -69,15 +73,18 @@ namespace VPet_Simulator.Core
|
||||
|
||||
public bool IsReady => true;
|
||||
|
||||
public TaskControl Control { get; set; }
|
||||
|
||||
public void Run(Decorator parant, Action EndAction = null)
|
||||
{
|
||||
if (PlayState)
|
||||
{
|
||||
IsContinue = true;
|
||||
if (Control?.PlayState == true)
|
||||
{//如果当前正在运行,重置状态
|
||||
Control.SetContinue();
|
||||
Control.EndAction = EndAction;
|
||||
return;
|
||||
}
|
||||
PlayState = true;
|
||||
DoEndAction = true;
|
||||
Control = new TaskControl(EndAction);
|
||||
|
||||
parant.Dispatcher.Invoke(() =>
|
||||
{
|
||||
if (parant.Tag != this)
|
||||
@ -87,6 +94,10 @@ namespace VPet_Simulator.Core
|
||||
{
|
||||
img = (Image)GraphCore.CommUIElements["Image1.Picture"];
|
||||
}
|
||||
else if (parant.Child == GraphCore.CommUIElements["Image3.Picture"])
|
||||
{
|
||||
img = (Image)GraphCore.CommUIElements["Image3.Picture"];
|
||||
}
|
||||
else
|
||||
{
|
||||
img = (Image)GraphCore.CommUIElements["Image2.Picture"];
|
||||
@ -94,7 +105,6 @@ namespace VPet_Simulator.Core
|
||||
{
|
||||
if (img.Parent == null)
|
||||
{
|
||||
parant.Child = null;
|
||||
parant.Child = img;
|
||||
}
|
||||
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.Source = new BitmapImage(new Uri(Path));
|
||||
parant.Tag = this;
|
||||
}
|
||||
Task.Run(() =>
|
||||
{
|
||||
Thread.Sleep(Length);
|
||||
if (IsLoop && PlayState)
|
||||
{
|
||||
Run(parant, EndAction);
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayState = false;
|
||||
if (DoEndAction)
|
||||
EndAction?.Invoke();//运行结束动画时事件
|
||||
}
|
||||
});
|
||||
Task.Run(() => Run(Control));
|
||||
});
|
||||
}
|
||||
bool DoEndAction = true;
|
||||
public void Stop(bool StopEndAction = false)
|
||||
/// <summary>
|
||||
/// 通过控制器运行
|
||||
/// </summary>
|
||||
/// <param name="Control"></param>
|
||||
public void Run(TaskControl Control)
|
||||
{
|
||||
PlayState = false;
|
||||
this.DoEndAction = !StopEndAction;
|
||||
Thread.Sleep(Length);
|
||||
//判断是否要下一步
|
||||
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;
|
||||
DoEndAction = true;
|
||||
if (Control?.PlayState == true)
|
||||
{//如果当前正在运行,重置状态
|
||||
Control.EndAction = null;
|
||||
Control.Type = TaskControl.ControlType.Stop;
|
||||
}
|
||||
Control = new TaskControl(EndAction);
|
||||
return img.Dispatcher.Invoke(() =>
|
||||
{
|
||||
if (img.Tag == this)
|
||||
{
|
||||
return new Task(() =>
|
||||
{
|
||||
Thread.Sleep(Length);
|
||||
if (IsLoop && PlayState)
|
||||
{
|
||||
Run(img, EndAction);
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayState = false;
|
||||
if (DoEndAction)
|
||||
EndAction?.Invoke();//运行结束动画时事件
|
||||
}
|
||||
});
|
||||
return new Task(() => Run(Control));
|
||||
}
|
||||
img.Tag = this;
|
||||
img.Source = new BitmapImage(new Uri(Path));
|
||||
img.Width = 500;
|
||||
return new Task(() =>
|
||||
{
|
||||
Thread.Sleep(Length);
|
||||
if (IsLoop && PlayState)
|
||||
{
|
||||
Run(img, EndAction);
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayState = false;
|
||||
if (DoEndAction)
|
||||
EndAction?.Invoke();//运行结束动画时事件
|
||||
}
|
||||
});
|
||||
return new Task(() => Run(Control));
|
||||
});
|
||||
}
|
||||
public interface IImageRun : IGraph
|
||||
|
@ -2193,12 +2193,12 @@ namespace VPet_Simulator.Windows
|
||||
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)
|
||||
{
|
||||
ig.IsContinue = true;
|
||||
ig.SetContinue();
|
||||
return true;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -404,7 +404,7 @@ namespace VPet_Simulator.Windows
|
||||
{
|
||||
foreach (var ig3 in ig2)
|
||||
{
|
||||
ig3.Stop();
|
||||
ig3.Stop(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -455,7 +455,7 @@ namespace VPet_Simulator.Windows
|
||||
{
|
||||
foreach (var ig3 in ig2)
|
||||
{
|
||||
ig3.Stop();
|
||||
ig3.Stop(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -482,12 +482,12 @@ public partial class MPFriends : WindowX, IMPFriend
|
||||
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)
|
||||
{
|
||||
ig.IsContinue = true;
|
||||
ig.SetContinue();
|
||||
return true;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -522,12 +522,12 @@ public partial class MPFriends : WindowX, IMPFriend
|
||||
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)
|
||||
{
|
||||
ig.IsContinue = true;
|
||||
ig.SetContinue();
|
||||
return;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -548,12 +548,12 @@ public partial class MPFriends : WindowX, IMPFriend
|
||||
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)
|
||||
{
|
||||
ig.IsContinue = true;
|
||||
ig.SetContinue();
|
||||
return;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -574,12 +574,12 @@ public partial class MPFriends : WindowX, IMPFriend
|
||||
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)
|
||||
{
|
||||
ig.IsContinue = true;
|
||||
ig.SetContinue();
|
||||
return;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -723,7 +723,7 @@ public partial class MPFriends : WindowX, IMPFriend
|
||||
{
|
||||
foreach (var ig3 in ig2)
|
||||
{
|
||||
ig3.Stop();
|
||||
ig3.Stop(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -486,12 +486,12 @@ public partial class winMutiPlayer : WindowX, IMPWindows
|
||||
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)
|
||||
{
|
||||
ig.IsContinue = true;
|
||||
ig.SetContinue();
|
||||
return;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -512,12 +512,12 @@ public partial class winMutiPlayer : WindowX, IMPWindows
|
||||
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)
|
||||
{
|
||||
ig.IsContinue = true;
|
||||
ig.SetContinue();
|
||||
return;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -538,12 +538,12 @@ public partial class winMutiPlayer : WindowX, IMPWindows
|
||||
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)
|
||||
{
|
||||
ig.IsContinue = true;
|
||||
ig.SetContinue();
|
||||
return;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user