更新全新显示机制PNGAnimation

This commit is contained in:
ZouJin 2023-02-13 20:48:59 +11:00
parent 8f55cfa299
commit 2edc1df1db
8 changed files with 104 additions and 38 deletions

View File

@ -60,8 +60,9 @@ namespace VPet_Simulator.Core
var ig = Core.Graph.FindGraph(GraphCore.GraphType.Default, core.Save.Mode);
PetGrid.Child = ig.This;
var ig2 = Core.Graph.FindGraph(GraphCore.GraphType.Touch_Head_A_Start, core.Save.Mode);
var ig2 = Core.Graph.FindGraph(GraphCore.GraphType.Touch_Head_A_Start, core.Save.Mode);
PetGrid2.Child = ig2.This; //用于缓存
PetGrid2.Visibility = Visibility.Collapsed;
ig.Run(DisplayNomal);

View File

@ -873,7 +873,7 @@ namespace VPet_Simulator.Core
default:
Core.Controller.MoveWindows(0, -Core.Controller.GetWindowsDistanceUp() / Core.Controller.ZoomRatio);
MoveTimer.Enabled = false;
DisplayFalled_Right();
DisplayFalled_Left();
return;
}
}
@ -886,7 +886,7 @@ namespace VPet_Simulator.Core
{//停下来
Core.Controller.MoveWindows(0, -Core.Controller.GetWindowsDistanceUp() / Core.Controller.ZoomRatio);
MoveTimer.Enabled = false;
DisplayFalled_Right();
DisplayFalled_Left();
}
}
/// <summary>

View File

@ -59,7 +59,7 @@ namespace VPet_Simulator.Core
{
Task.Run(() =>
{
Thread.Sleep(timeleft * 50);
Thread.Sleep(timeleft * 100);
if (m.DisplayType == GraphCore.GraphType.Default || m.DisplayType.ToString().Contains("Say"))
m.Display(GraphCore.GraphType.Say_C_End, m.DisplayNomal);
});

View File

@ -11,7 +11,7 @@ namespace VPet_Simulator.Core
{
public class GraphCore
{
public static string CachePath = AppDomain.CurrentDomain.BaseDirectory + @"\cache";
/// <summary>
/// 动画类型
/// </summary>
@ -298,7 +298,7 @@ namespace VPet_Simulator.Core
AddGraph(new Picture(paths[0].FullName, modetype, graphtype,
int.Parse(paths[0].Name.Split('.').Reverse().ToArray()[1].Split('_').Last())), graphtype);
else
AddGraph(new PNGAnimation(paths, modetype, graphtype), graphtype);
AddGraph(new PNGAnimation(path, paths, modetype, graphtype), graphtype);
}
/// <summary>
/// 随机数字典(用于确保随机动画不会错位)

View File

@ -13,9 +13,11 @@ using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows;
using static System.Net.WebRequestMethods;
using System.Windows.Threading;
using System.Threading;
using System.Drawing;
using LinePutScript;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TreeView;
namespace VPet_Simulator.Core
{
@ -65,9 +67,10 @@ namespace VPet_Simulator.Core
/// <summary>
/// 新建 PNG 动画
/// </summary>
/// <param name="paths">文件夹位置</param>
/// <param name="path">文件夹位置</param>
/// <param name="paths">文件内容列表</param>
/// <param name="isLoop">是否循环</param>
public PNGAnimation(FileInfo[] paths, Save.ModeType modetype, GraphCore.GraphType graphtype, bool isLoop = false)
public PNGAnimation(string path, FileInfo[] paths, Save.ModeType modetype, GraphCore.GraphType graphtype, bool isLoop = false)
{
InitializeComponent();
Animations = new List<Animation>();
@ -75,18 +78,71 @@ namespace VPet_Simulator.Core
//StoreMemory = storemem;
GraphType = graphtype;
ModeType = modetype;
//if (storemem)
foreach (var file in paths)
//新方法:加载大图片
//生成大文件加载非常慢,先看看有没有缓存能用
string cp = GraphCore.CachePath + $"\\{Sub.GetHashCode(path)}_{paths.Length}.png";
if (File.Exists(cp))
{
int time = int.Parse(file.Name.Split('.').Reverse().ToArray()[1].Split('_').Last());
var img = new Image()
var img = new System.Windows.Controls.Image()
{
Source = new BitmapImage(new Uri(file.FullName)),
Visibility = Visibility.Hidden
HorizontalAlignment = HorizontalAlignment.Left,
Width = 500 * (paths.Length + 1),
Height = 500
};
MainGrid.Children.Add(img);
Animations.Add(new Animation(this, time, () => img.Visibility = Visibility.Visible, () => img.Visibility = Visibility.Hidden));
for (int i = 0; i < paths.Length; i++)
{
FileInfo file = paths[i];
int time = int.Parse(file.Name.Split('.').Reverse().ToArray()[1].Split('_').Last());
int wxi = -500 * i;
Animations.Add(new Animation(this, time, () => img.Margin = new Thickness(wxi, 0, 0, 0)));
}
img.Source = new BitmapImage(new Uri(cp));
}
else
{
List<System.Drawing.Image> imgs = new List<System.Drawing.Image>();
foreach (var file in paths)
imgs.Add(System.Drawing.Image.FromFile(file.FullName));
int w = imgs[0].Width;
int h = imgs[0].Height;
Bitmap joinedBitmap = new Bitmap(w * paths.Length, h);
var graph = Graphics.FromImage(joinedBitmap);
var img = new System.Windows.Controls.Image()
{
HorizontalAlignment = HorizontalAlignment.Left,
Width = 500 * (paths.Length + 1),
Height = 500
};
MainGrid.Children.Add(img);
for (int i = 0; i < paths.Length; i++)
{
FileInfo file = paths[i];
int time = int.Parse(file.Name.Split('.').Reverse().ToArray()[1].Split('_').Last());
graph.DrawImage(imgs[i], w * i, 0, w, h);
int wxi = -500 * i;
Animations.Add(new Animation(this, time, () => img.Margin = new Thickness(wxi, 0, 0, 0)));
}
joinedBitmap.Save(cp);
graph.Dispose();
joinedBitmap.Dispose();
imgs.ForEach(x => x.Dispose());
img.Source = new BitmapImage(new Uri(cp));
}
//if (storemem)
//foreach (var file in paths)
//{
// int time = int.Parse(file.Name.Split('.').Reverse().ToArray()[1].Split('_').Last());
// var img = new Image()
// {
// Source = new BitmapImage(new Uri(file.FullName)),
// Visibility = Visibility.Hidden
// };
// MainGrid.Children.Add(img);
// Animations.Add(new Animation(this, time, () => img.Visibility = Visibility.Visible, () => img.Visibility = Visibility.Hidden));
//}
//else
//{
// Image[] imgs = new Image[3];
@ -149,20 +205,20 @@ namespace VPet_Simulator.Core
/// 显示
/// </summary>
public Action Visible;
/// <summary>
/// 隐藏
/// </summary>
public Action Hidden;
///// <summary>
///// 隐藏
///// </summary>
//public Action Hidden;
/// <summary>
/// 帧时间
/// </summary>
public int Time;
public Animation(PNGAnimation parent, int time, Action visible, Action hidden)
public Animation(PNGAnimation parent, int time, Action visible)//, Action hidden)
{
this.parent = parent;
Time = time;
Visible = visible;
Hidden = hidden;
//Hidden = hidden;
}
/// <summary>
/// 运行该图层
@ -193,24 +249,24 @@ namespace VPet_Simulator.Core
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;
}
//要下一步,现在就隐藏图层
//隐藏该图层
parent.Dispatcher.Invoke(Hidden);
//parent.Dispatcher.Invoke(Hidden);
parent.Animations[parent.nowid].Run(EndAction);
return;
}
else
{
parent.IsContinue = false;
parent.Dispatcher.Invoke(Hidden);
//parent.Dispatcher.Invoke(Hidden);
if (parent.DoEndAction)
EndAction?.Invoke();//运行结束动画时事件
parent.StopAction?.Invoke();

View File

@ -69,15 +69,13 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="LinePutScript, Version=1.5.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\LinePutScript.1.6.1\lib\net462\LinePutScript.dll</HintPath>
<HintPath>..\..\VUPSimulator\packages\LinePutScript.1.6.1\lib\net462\LinePutScript.dll</HintPath>
</Reference>
<Reference Include="Panuon.WPF, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Refer\Panuon.WPF.dll</HintPath>
<HintPath>..\..\VUPSimulator\packages\Panuon.WPF.1.0.1\lib\net462\Panuon.WPF.dll</HintPath>
</Reference>
<Reference Include="Panuon.WPF.UI, Version=1.1.6.5, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Refer\Panuon.WPF.UI.dll</HintPath>
<Reference Include="Panuon.WPF.UI, Version=1.1.6.7, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\VUPSimulator\packages\Panuon.WPF.UI.1.1.6.7\lib\net462\Panuon.WPF.UI.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />

View File

@ -2,5 +2,5 @@
<packages>
<package id="LinePutScript" version="1.6.1" targetFramework="net462" />
<package id="Panuon.WPF" version="1.0.1" targetFramework="net462" />
<package id="Panuon.WPF.UI" version="1.1.6.5" targetFramework="net462" />
<package id="Panuon.WPF.UI" version="1.1.6.7" targetFramework="net462" />
</packages>

View File

@ -72,6 +72,11 @@ namespace VPet_Simulator.Windows
}
else
Set = new Setting("Setting#VPET:|\n");
if (!Directory.Exists(GraphCore.CachePath))
{
Directory.CreateDirectory(GraphCore.CachePath);
}
//this.Width = 400 * ZoomSlider.Value;
//this.Height = 450 * ZoomSlider.Value;
@ -156,7 +161,6 @@ namespace VPet_Simulator.Windows
Dispatcher.Invoke(new Action(() =>
{
Core.Graph = Pets[0].Graph();
LoadingText.Visibility = Visibility.Collapsed;
winSetting = new winGameSetting(this);
Main = new Main(Core) { };
Main.DefaultClickAction = () =>
@ -179,6 +183,7 @@ namespace VPet_Simulator.Windows
Main.SetMoveMode(Set.AllowMove, Set.SmartMove, Set.SmartMoveInterval * 1000);
Main.SetLogicInterval((int)(Set.LogicInterval * 1000));
LoadingText.Visibility = Visibility.Collapsed;
//加载图标
notifyIcon = new NotifyIcon();
notifyIcon.Text = "虚拟桌宠模拟器";
@ -217,6 +222,12 @@ namespace VPet_Simulator.Windows
Main.Say("欢迎使用虚拟桌宠模拟器\n这是个早期的测试版,若有bug请多多包涵\n欢迎在菜单栏-管理-反馈中提交bug或建议");
});
}
else if (Set["SingleTips"].GetDateTime("update") <= new DateTime(2023, 2, 13))
{
Set["SingleTips"].SetDateTime("update", DateTime.Now);
notifyIcon.ShowBalloonTip(10, "更新通知 02/13",
"现在使用缓存机制,不仅占用小,而且再也不会有那种闪闪的问题了!", ToolTipIcon.Info);
}
}));
}