From 112a633e8c418ffbda88f204f169c26ac6730f09 Mon Sep 17 00:00:00 2001 From: ZouJin Date: Wed, 22 Feb 2023 16:37:23 +1100 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VPet-Simulator.Core/Display/Main.xaml.cs | 3 +- VPet-Simulator.Core/Display/MainDisplay.cs | 4 +- VPet-Simulator.Core/Graph/IGraph.cs | 6 +- VPet-Simulator.Core/Graph/PNGAnimation.xaml | 4 +- .../Graph/PNGAnimation.xaml.cs | 116 ++++++++++-------- VPet-Simulator.Core/Graph/Picture.xaml.cs | 2 + VPet-Simulator.Core/Handle/PetLoader.cs | 57 ++++----- VPet-Simulator.Tool/Program.cs | 5 +- VPet-Simulator.Windows/MainWindow.xaml.cs | 4 +- 9 files changed, 109 insertions(+), 92 deletions(-) diff --git a/VPet-Simulator.Core/Display/Main.xaml.cs b/VPet-Simulator.Core/Display/Main.xaml.cs index a4b8378..735cf10 100644 --- a/VPet-Simulator.Core/Display/Main.xaml.cs +++ b/VPet-Simulator.Core/Display/Main.xaml.cs @@ -44,6 +44,7 @@ namespace VPet_Simulator.Core public event Action
TimeUIHandle; public Main(GameCore core, bool loadtouchevent = true) { + Console.WriteLine(DateTime.Now.ToString("T:fff")); InitializeComponent(); Core = core; @@ -64,7 +65,7 @@ namespace VPet_Simulator.Core 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); + ig.WaitForReadyRun(DisplayNomal); EventTimer.Elapsed += EventTimer_Elapsed; diff --git a/VPet-Simulator.Core/Display/MainDisplay.cs b/VPet-Simulator.Core/Display/MainDisplay.cs index 5dd2f05..b7db3a3 100644 --- a/VPet-Simulator.Core/Display/MainDisplay.cs +++ b/VPet-Simulator.Core/Display/MainDisplay.cs @@ -137,11 +137,11 @@ namespace VPet_Simulator.Core ig2.IsContinue = true; return; } - + Core.Graph.RndGraph.Clear(); Display(GraphCore.GraphType.Touch_Body_A_Start, () => Display(GraphCore.GraphType.Touch_Body_B_Loop, () => Display(GraphCore.GraphType.Touch_Body_C_End, DisplayNomal - ))); + , true), true), true); } /// /// 显示待机(模式1)情况 diff --git a/VPet-Simulator.Core/Graph/IGraph.cs b/VPet-Simulator.Core/Graph/IGraph.cs index e6b24c3..dcc130f 100644 --- a/VPet-Simulator.Core/Graph/IGraph.cs +++ b/VPet-Simulator.Core/Graph/IGraph.cs @@ -29,6 +29,10 @@ namespace VPet_Simulator.Core /// 是否继续播放 /// bool IsContinue { get; set; } + /// + /// 从0开始运行该动画, 等待部署完成后执行 + /// + void WaitForReadyRun(Action EndAction = null); ///// //经过测试,储存到内存好处多多,不储存也要占用很多内存,干脆存了吧 ///// 是否储存到内存以支持快速显示 ///// @@ -36,7 +40,7 @@ namespace VPet_Simulator.Core /// /// 该动画UI状态 /// - Save.ModeType ModeType { get;} + Save.ModeType ModeType { get; } /// /// 该动画UI状态 /// diff --git a/VPet-Simulator.Core/Graph/PNGAnimation.xaml b/VPet-Simulator.Core/Graph/PNGAnimation.xaml index 53a2513..30d3fa2 100644 --- a/VPet-Simulator.Core/Graph/PNGAnimation.xaml +++ b/VPet-Simulator.Core/Graph/PNGAnimation.xaml @@ -1,4 +1,4 @@ - - + diff --git a/VPet-Simulator.Core/Graph/PNGAnimation.xaml.cs b/VPet-Simulator.Core/Graph/PNGAnimation.xaml.cs index 9c2beb1..0c38c79 100644 --- a/VPet-Simulator.Core/Graph/PNGAnimation.xaml.cs +++ b/VPet-Simulator.Core/Graph/PNGAnimation.xaml.cs @@ -19,13 +19,14 @@ using System.Drawing; using LinePutScript; using static System.Windows.Forms.VisualStyles.VisualStyleElement.TreeView; using Panuon.WPF.UI; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock; namespace VPet_Simulator.Core { /// /// PNGAnimation.xaml 的交互逻辑 /// - public partial class PNGAnimation : Grid, IGraph + public partial class PNGAnimation : System.Windows.Controls.Image, IGraph { /// /// 所有动画帧 @@ -61,6 +62,10 @@ namespace VPet_Simulator.Core public GraphCore.GraphType GraphType { get; private set; } /// + /// 是否准备完成 + /// + public bool IsReady { get; private set; } = false; + /// /// 动画停止时运行的方法 /// private Action StopAction; @@ -79,59 +84,7 @@ namespace VPet_Simulator.Core //StoreMemory = storemem; GraphType = graphtype; ModeType = modetype; - //新方法:加载大图片 - //生成大文件加载非常慢,先看看有没有缓存能用 - string cp = GraphCore.CachePath + $"\\{Sub.GetHashCode(path)}_{paths.Length}.png"; - if (File.Exists(cp)) - { - var img = new System.Windows.Controls.Image() - { - HorizontalAlignment = HorizontalAlignment.Left, - Width = 500 * (paths.Length + 1), - Height = 500 - }; - 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()); - 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 imgs = new List(); - 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 - }; - 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)); - } - - + Task.Run(() => startup(path, paths)); //if (storemem) //foreach (var file in paths) //{ @@ -196,6 +149,50 @@ namespace VPet_Simulator.Core // , () => imgs[last % 3].Visibility = Visibility.Hidden)); //} } + private void startup(string path, FileInfo[] paths) + { + //新方法:加载大图片 + //生成大文件加载非常慢,先看看有没有缓存能用 + string cp = GraphCore.CachePath + $"\\{Sub.GetHashCode(path)}_{paths.Length}.png"; + Dispatcher.Invoke(() => Width = 500 * (paths.Length + 1)); + if (File.Exists(cp)) + { + 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, () => Margin = new Thickness(wxi, 0, 0, 0))); + } + Dispatcher.Invoke(() => Source = new BitmapImage(new Uri(cp))); + IsReady = true; + } + else + { + List imgs = new List(); + 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); + 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, () => Margin = new Thickness(wxi, 0, 0, 0))); + } + joinedBitmap.Save(cp); + graph.Dispose(); + joinedBitmap.Dispose(); + imgs.ForEach(x => x.Dispose()); + Dispatcher.Invoke(() => Source = new BitmapImage(new Uri(cp))); + IsReady = true; + } + } + /// /// 单帧动画 /// @@ -310,5 +307,16 @@ namespace VPet_Simulator.Core //IsResetPlay = false; } + public void WaitForReadyRun(Action EndAction = null) + { + Task.Run(() => + { + while (!IsReady) + { + Thread.Sleep(100); + } + Run(EndAction); + }); + } } } diff --git a/VPet-Simulator.Core/Graph/Picture.xaml.cs b/VPet-Simulator.Core/Graph/Picture.xaml.cs index 0e46b3b..380fbf5 100644 --- a/VPet-Simulator.Core/Graph/Picture.xaml.cs +++ b/VPet-Simulator.Core/Graph/Picture.xaml.cs @@ -72,5 +72,7 @@ namespace VPet_Simulator.Core PlayState = false; this.StopEndAction = StopEndAction; } + + public void WaitForReadyRun(Action EndAction = null) => Run(EndAction); } } diff --git a/VPet-Simulator.Core/Handle/PetLoader.cs b/VPet-Simulator.Core/Handle/PetLoader.cs index 1a30ec8..fee6459 100644 --- a/VPet-Simulator.Core/Handle/PetLoader.cs +++ b/VPet-Simulator.Core/Handle/PetLoader.cs @@ -52,41 +52,38 @@ namespace VPet_Simulator.Core var list = di.EnumerateDirectories(); if (list.Count() == 0) { - if (File.Exists(di.FullName + @"\info.lps")) - {//如果自带描述信息,则手动加载 - //TODO: - } - else - {//自动加载 PNG ANMIN - path_name = path_name.Trim('_').ToLower(); - for (int i = 0; i < GraphTypeValue.Length; i++) + //自动加载 PNG ANMIN + path_name = path_name.Trim('_').ToLower(); + for (int i = 0; i < GraphTypeValue.Length; i++) + { + if (path_name.StartsWith(GraphTypeValue[i])) { - if (path_name.StartsWith(GraphTypeValue[i])) + if (path_name.Contains("happy")) { - - if (path_name.Contains("happy")) - { - graph.AddGraph(di.FullName, Save.ModeType.Happy, (GraphType)i); - } - if (path_name.Contains("nomal")) - { - graph.AddGraph(di.FullName, Save.ModeType.Nomal, (GraphType)i); - } - if (path_name.Contains("poorcondition")) - { - graph.AddGraph(di.FullName, Save.ModeType.PoorCondition, (GraphType)i); - } - if (path_name.Contains("ill")) - { - graph.AddGraph(di.FullName, Save.ModeType.Ill, (GraphType)i); - } - return; + graph.AddGraph(di.FullName, Save.ModeType.Happy, (GraphType)i); } + if (path_name.Contains("nomal")) + { + graph.AddGraph(di.FullName, Save.ModeType.Nomal, (GraphType)i); + } + if (path_name.Contains("poorcondition")) + { + graph.AddGraph(di.FullName, Save.ModeType.PoorCondition, (GraphType)i); + } + if (path_name.Contains("ill")) + { + graph.AddGraph(di.FullName, Save.ModeType.Ill, (GraphType)i); + } + return; } -#if DEMO - throw new Exception("未知的图像类型: " + path_name); -#endif } +#if DEBUG + throw new Exception("未知的图像类型: " + path_name); +#endif + } + else if (File.Exists(di.FullName + @"\info.lps")) + {//如果自带描述信息,则手动加载 + //TODO: } else foreach (var p in list) diff --git a/VPet-Simulator.Tool/Program.cs b/VPet-Simulator.Tool/Program.cs index 28f29c4..e61f8d2 100644 --- a/VPet-Simulator.Tool/Program.cs +++ b/VPet-Simulator.Tool/Program.cs @@ -36,7 +36,10 @@ namespace VPet_Simulator.Tool { Console.WriteLine("请输入每张图片的持续时间 (单位: 毫秒)"); string timestr = Console.ReadLine(); - int time = timestr == "" ? 125 : int.Parse(timestr); + if(!int.TryParse(timestr,out int time)) + { + time = 125; + } Console.WriteLine("请输入图片位置"); DirectoryInfo directoryInfo = new DirectoryInfo(Console.ReadLine()); int id = 0; diff --git a/VPet-Simulator.Windows/MainWindow.xaml.cs b/VPet-Simulator.Windows/MainWindow.xaml.cs index 4d835ae..099ac72 100644 --- a/VPet-Simulator.Windows/MainWindow.xaml.cs +++ b/VPet-Simulator.Windows/MainWindow.xaml.cs @@ -144,15 +144,16 @@ namespace VPet_Simulator.Windows AutoSaveTimer.Start(); } - Dispatcher.Invoke(new Action(() => { LoadingText.Content = "尝试加载动画和生成缓存"; var pl = Pets.Find(x => x.Name == Set.PetGraph); Core.Graph = pl == null ? Pets[0].Graph() : pl.Graph(); LoadingText.Content = "正在加载游戏"; + winSetting = new winGameSetting(this); Main = new Main(Core) { }; + Main.DefaultClickAction = () => { if (new TimeSpan(DateTime.Now.Ticks - lastclicktime).TotalSeconds > 20) @@ -188,6 +189,7 @@ namespace VPet_Simulator.Windows Top = (SystemParameters.PrimaryScreenHeight - Height) / 2; })); m_menu.MenuItems.Add(new MenuItem("反馈中心", (x, y) => { new winReport(this).Show(); })); + m_menu.MenuItems.Add(new MenuItem("开发控制台", (x, y) => { new winConsole(this).Show(); })); m_menu.MenuItems.Add(new MenuItem("设置面板", (x, y) => {