using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using static System.Windows.Forms.AxHost;
using System.Windows.Media;
using static VPet_Simulator.Core.Picture;
namespace VPet_Simulator.Core
{
public class FoodAnimation : IGraph
{
///
/// 前层名字
///
public string Front_Lay;
///
/// 后层名字
///
public string Back_Lay;
///
/// 所有动画帧
///
public List Animations;
///
/// 当前动画播放状态
///
public bool PlayState { get; set; } = false;
///
/// 当前动画是否执行ENDACTION
///
private bool DoEndAction = true;
///
/// 是否循环播放
///
public bool IsLoop { get; set; }
///
/// 是否循环播放
///
public bool IsContinue { get; set; } = false;
public GameSave.ModeType ModeType { get; private set; }
public GraphCore.GraphType GraphType { get; private set; }
///
/// 是否准备完成
///
public bool IsReady { get; private set; } = false;
///
/// 动画停止时运行的方法
///
private Action StopAction;
int nowid;
///
/// 图片资源
///
public string Path;
private GraphCore GraphCore;
///
/// 单帧动画
///
public class Animation
{
private FoodAnimation parent;
public Thickness MarginWI;
public double Rotate;
///
/// 帧时间
///
public int Time;
///
/// 创建单帧动画
///
/// FoodAnimation
/// 持续时间
///
public Animation(FoodAnimation parent, int time, Thickness wx, double rotate)
{
this.parent = parent;
Time = time;
MarginWI = wx;
Rotate = rotate;
}
///
/// 运行该图层
///
public void Run(FrameworkElement This, Action EndAction = null)
{
//先显示该图层
This.Dispatcher.Invoke(() =>
{
This.Margin = MarginWI;
This.LayoutTransform = new RotateTransform(Rotate);
});
//然后等待帧时间毫秒
Thread.Sleep(Time);
//判断是否要下一步
if (parent.PlayState)
{
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);
//});
}
}
}
public static FoodAnimatGrid FoodGrid = new FoodAnimatGrid();
public class FoodAnimatGrid : Grid
{
public FoodAnimatGrid()
{
Width = 500;
Height = 500;
Front = new Image();
Back = new Image();
Food = new Image();
Food.RenderTransformOrigin = new Point(0.5, 0.5);
this.Children.Add(Front);
this.Children.Add(Back);
}
public Image Front;
public Image Food;
public Image Back;
}
public void Run(Border parant, Action EndAction = null)
{
throw new NotImplementedException();
}
public void Stop(bool StopEndAction = false)
{
throw new NotImplementedException();
}
}
}