From 1e1e9f1b35055daabfb675b65df947a61b0b77f2 Mon Sep 17 00:00:00 2001 From: ZouJin Date: Sun, 13 Aug 2023 17:28:08 +1000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=8A=A8=E5=A4=87?= =?UTF-8?q?=E4=BB=BD=E7=9B=B8=E5=85=B3=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VPet-Simulator.Core/Graph/PNGAnimation.cs | 4 +- VPet-Simulator.Core/Graph/Picture.cs | 3 +- VPet-Simulator.Windows/MainWindow.xaml.cs | 42 ++++++++++--------- .../WinDesign/TalkBox.xaml.cs | 2 +- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/VPet-Simulator.Core/Graph/PNGAnimation.cs b/VPet-Simulator.Core/Graph/PNGAnimation.cs index 5336dd5..e376cb0 100644 --- a/VPet-Simulator.Core/Graph/PNGAnimation.cs +++ b/VPet-Simulator.Core/Graph/PNGAnimation.cs @@ -184,7 +184,7 @@ namespace VPet_Simulator.Core imgs.Add(System.Drawing.Image.FromFile(file.FullName)); int w = imgs[0].Width; int h = imgs[0].Height; - if(w > GraphCore.Resolution) + if (w > GraphCore.Resolution) { w = GraphCore.Resolution; h = (int)(h * (GraphCore.Resolution / (double)imgs[0].Width)); @@ -340,6 +340,8 @@ namespace VPet_Simulator.Core else { img = (System.Windows.Controls.Image)GraphCore.CommUIElements["Image1.PNGAnimation"]; + if (img.Parent != null) + ((Decorator)img.Parent).Child = null; parant.Child = img; } } diff --git a/VPet-Simulator.Core/Graph/Picture.cs b/VPet-Simulator.Core/Graph/Picture.cs index 1bb6a5b..1a83e69 100644 --- a/VPet-Simulator.Core/Graph/Picture.cs +++ b/VPet-Simulator.Core/Graph/Picture.cs @@ -101,7 +101,8 @@ namespace VPet_Simulator.Core else { img = (Image)GraphCore.CommUIElements["Image1.Picture"]; - parant.Child = null; + if (img.Parent != null) + ((Decorator)img.Parent).Child = null; parant.Child = img; } } diff --git a/VPet-Simulator.Windows/MainWindow.xaml.cs b/VPet-Simulator.Windows/MainWindow.xaml.cs index 6dcb8be..42b124a 100644 --- a/VPet-Simulator.Windows/MainWindow.xaml.cs +++ b/VPet-Simulator.Windows/MainWindow.xaml.cs @@ -165,20 +165,20 @@ namespace VPet_Simulator.Windows .GetFiles("*.lps").OrderByDescending(x => x.LastWriteTime).FirstOrDefault(); if (latestsave != null) { - GameLoad(new Line(File.ReadAllText(latestsave.FullName))); - return; + if (GameLoad(new Line(File.ReadAllText(latestsave.FullName)))) + return; } } Core.Save = new GameSave(petname.Translate()); } - public void GameLoad() + public async void GameLoad() { //加载所有MOD List Path = new List(); Path.AddRange(new DirectoryInfo(ModPath).EnumerateDirectories()); if (IsSteamUser)//如果是steam用户,尝试加载workshop { - Dispatcher.Invoke(new Action(() => LoadingText.Content = "Loading Steam Workshop")); + await Dispatcher.InvokeAsync(new Action(() => LoadingText.Content = "Loading Steam Workshop")); int i = 1; while (true) { @@ -197,13 +197,13 @@ namespace VPet_Simulator.Windows } } } - Dispatcher.Invoke(new Action(() => LoadingText.Content = "Loading MOD")); + await Dispatcher.InvokeAsync(new Action(() => LoadingText.Content = "Loading MOD")); //加载mod foreach (DirectoryInfo di in Path) { if (!File.Exists(di.FullName + @"\info.lps")) continue; - Dispatcher.Invoke(new Action(() => LoadingText.Content = $"Loading MOD: {di.Name}")); + await Dispatcher.InvokeAsync(new Action(() => LoadingText.Content = $"Loading MOD: {di.Name}")); CoreMODs.Add(new CoreMOD(di, this)); } @@ -218,7 +218,8 @@ namespace VPet_Simulator.Windows Directory.CreateDirectory(CachePath); } } - Dispatcher.BeginInvoke(new Action(() => LoadingText.Content = "Loading Translate")); + + await Dispatcher.InvokeAsync(new Action(() => LoadingText.Content = "Loading Translate")); //加载语言 LocalizeCore.StoreTranslation = true; if (Set.Language == "null") @@ -249,16 +250,17 @@ namespace VPet_Simulator.Windows } - Dispatcher.BeginInvoke(new Action(() => LoadingText.Content = "尝试加载游戏MOD".Translate())); + await Dispatcher.InvokeAsync(new Action(() => LoadingText.Content = "尝试加载游戏MOD".Translate())); //当前桌宠动画 var petloader = Pets.Find(x => x.Name == Set.PetGraph); petloader ??= Pets[0]; + await Dispatcher.InvokeAsync(new Action(() => LoadingText.Content = "尝试加载游戏存档".Translate())); //加载存档 Core.Controller = new MWController(this); - if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"\Save.lps") && - !GameLoad(new LpsDocument(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"\Save.lps")).First())) + if (!(File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"\Save.lps") && + GameLoad(new LpsDocument(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + @"\Save.lps")).First()))) //如果加载存档失败了,试试加载备份,如果没备份,就新建一个 LoadLatestSave(petloader.PetName); @@ -283,6 +285,7 @@ namespace VPet_Simulator.Windows "长按脑袋拖动桌宠到你喜欢的任意位置".Translate(), "欢迎加入 虚拟主播模拟器群 430081239".Translate() }; + await Dispatcher.InvokeAsync(new Action(() => LoadingText.Content = "尝试加载Steam内容".Translate())); //给正在玩这个游戏的主播/游戏up主做个小功能 if (IsSteamUser) { @@ -306,19 +309,15 @@ namespace VPet_Simulator.Windows }; MusicTimer.Elapsed += MusicTimer_Elapsed; - - Dispatcher.Invoke(new Action(() => + await Dispatcher.InvokeAsync(new Action(() => LoadingText.Content = "尝试加载游戏动画".Translate())); + await Dispatcher.InvokeAsync(new Action(() => { LoadingText.Content = "尝试加载动画和生成缓存".Translate(); Core.Graph = petloader.Graph(Set.Resolution); - LoadingText.Content = "正在加载CGPT".Translate(); - - winSetting = new winGameSetting(this); - winBetterBuy = new winBetterBuy(this); Main = new Main(Core); Main.NoFunctionMOD = Set.CalFunState; - + LoadingText.Content = "正在加载CGPT".Translate(); switch (Set["CGPT"][(gstr)"type"]) { case "API": @@ -334,7 +333,6 @@ namespace VPet_Simulator.Windows break; } - LoadingText.Content = "正在加载游戏".Translate(); var m = new System.Windows.Controls.MenuItem() { @@ -366,6 +364,10 @@ namespace VPet_Simulator.Windows Main.TimeHandle += Handle_Steam; Main.TimeHandle += (x) => DiagnosisUPLoad(); + //窗口部件 + winSetting = new winGameSetting(this); + winBetterBuy = new winBetterBuy(this); + Main.DefaultClickAction = () => { if (new TimeSpan(DateTime.Now.Ticks - lastclicktime).TotalSeconds > 20) @@ -377,13 +379,13 @@ namespace VPet_Simulator.Windows Main.PlayVoiceVolume = Set.VoiceVolume; Main.FunctionSpendHandle += StatisticsCalHandle; DisplayGrid.Child = Main; - Task.Run(() => + Task.Run(async () => { while (Main.IsWorking) { Thread.Sleep(100); } - Dispatcher.Invoke(() => LoadingText.Visibility = Visibility.Collapsed); + await Dispatcher.InvokeAsync(() => LoadingText.Visibility = Visibility.Collapsed); }); Main.ToolBar.AddMenuButton(VPet_Simulator.Core.ToolBar.MenuType.Setting, "退出桌宠".Translate(), () => { Main.ToolBar.Visibility = Visibility.Collapsed; Close(); }); diff --git a/VPet-Simulator.Windows/WinDesign/TalkBox.xaml.cs b/VPet-Simulator.Windows/WinDesign/TalkBox.xaml.cs index 79dbb1c..11e9b3e 100644 --- a/VPet-Simulator.Windows/WinDesign/TalkBox.xaml.cs +++ b/VPet-Simulator.Windows/WinDesign/TalkBox.xaml.cs @@ -144,7 +144,7 @@ namespace VPet_Simulator.Windows /// public void TalkChatInfoDisplay() { - Dispatcher.Invoke(() => this.IsEnabled = false); + //Dispatcher.Invoke(() => this.IsEnabled = false); var l = ConnectAIOpen("VPet/Data", "GET"); if (l.Name == "Info") {