From 355742b21925293d3842f499f3aa13e4948b686d Mon Sep 17 00:00:00 2001 From: Hakoyu Date: Fri, 20 Oct 2023 23:22:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Converters/CalculatorConverter.cs | 2 +- VPet.ModMaker/Models/Expansions.cs | 30 +++++++ .../Models/ModModel/FoodAnimeTypeModel.cs | 29 ++++-- VPet.ModMaker/Models/ModModel/FoodModel.cs | 2 + VPet.ModMaker/Models/ModModel/ModInfoModel.cs | 4 +- VPet.ModMaker/Models/Utils.cs | 3 +- .../ModEdit/AnimeEdit/AnimeEditWindowVM.cs | 3 +- .../AnimeEdit/FoodAnimeEditWindowVM.cs | 63 ++++++------- .../ModEdit/AnimeEdit/AnimeEditWindow.xaml.cs | 34 +------ .../AnimeEdit/FoodAnimeEditWindow.xaml | 90 +++++++++++++++---- .../AnimeEdit/FoodAnimeEditWindow.xaml.cs | 31 +------ 11 files changed, 166 insertions(+), 125 deletions(-) diff --git a/VPet.ModMaker/Converters/CalculatorConverter.cs b/VPet.ModMaker/Converters/CalculatorConverter.cs index 188accd..f306849 100644 --- a/VPet.ModMaker/Converters/CalculatorConverter.cs +++ b/VPet.ModMaker/Converters/CalculatorConverter.cs @@ -40,7 +40,7 @@ public class CalculatorConverter : IMultiValueConverter public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values.Any(i => i == DependencyProperty.UnsetValue)) - return 0; + return 0.0; if (values.Length == 1) return values[0]; double result = System.Convert.ToDouble(values[0]); diff --git a/VPet.ModMaker/Models/Expansions.cs b/VPet.ModMaker/Models/Expansions.cs index 8338929..13c607b 100644 --- a/VPet.ModMaker/Models/Expansions.cs +++ b/VPet.ModMaker/Models/Expansions.cs @@ -6,6 +6,7 @@ using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows; using System.Windows.Media; using System.Windows.Media.Imaging; using VPet.ModMaker.Models.ModModel; @@ -159,4 +160,33 @@ public static class Extensions return bytesRead; } } + + public static T? FindVisualChild(this DependencyObject obj) + where T : DependencyObject + { + if (obj is null) + return null; + var count = VisualTreeHelper.GetChildrenCount(obj); + for (int i = 0; i < count; i++) + { + var child = VisualTreeHelper.GetChild(obj, i); + if (child is T t) + return t; + if (FindVisualChild(child) is T childItem) + return childItem; + } + return null; + } + + public static T FindParent(this DependencyObject obj) + where T : class + { + while (obj != null) + { + if (obj is T) + return obj as T; + obj = VisualTreeHelper.GetParent(obj); + } + return null; + } } diff --git a/VPet.ModMaker/Models/ModModel/FoodAnimeTypeModel.cs b/VPet.ModMaker/Models/ModModel/FoodAnimeTypeModel.cs index c06f2f4..1014c3d 100644 --- a/VPet.ModMaker/Models/ModModel/FoodAnimeTypeModel.cs +++ b/VPet.ModMaker/Models/ModModel/FoodAnimeTypeModel.cs @@ -137,14 +137,25 @@ public class FoodAnimeTypeModel : this() { Name.Value = Path.GetFileName(path); - var infoFile = Path.Combine(path, ModMakerInfo.InfoFile); - if ( - Directory.EnumerateFiles(path, ModMakerInfo.InfoFile, SearchOption.AllDirectories).Any() - is false - ) - throw new Exception("信息文件\n{0}\n不存在".Translate(infoFile)); - if (File.Exists(infoFile)) - ParseInfoFile(path, infoFile); + //var infoFile = Path.Combine(path, ModMakerInfo.InfoFile); + //if ( + // Directory.EnumerateFiles(path, ModMakerInfo.InfoFile, SearchOption.AllDirectories).Any() + // is false + //) + // throw new Exception("信息文件\n{0}\n不存在".Translate(infoFile)); + //if (File.Exists(infoFile)) + // ParseInfoFile(path, infoFile); + var infoFiles = Directory.EnumerateFiles( + path, + ModMakerInfo.InfoFile, + SearchOption.AllDirectories + ); + if (infoFiles.Any() is false) + throw new Exception("信息文件不存在".Translate()); + foreach (var file in infoFiles) + { + ParseInfoFile(Path.GetDirectoryName(file), file); + } } public FoodAnimeTypeModel(FoodAnimeTypeModel model) @@ -278,6 +289,8 @@ public class FoodAnimeTypeModel ); } } + + public void Save(string path) { } } public class PNGAnimeInfo diff --git a/VPet.ModMaker/Models/ModModel/FoodModel.cs b/VPet.ModMaker/Models/ModModel/FoodModel.cs index e48c5c7..4aed0f2 100644 --- a/VPet.ModMaker/Models/ModModel/FoodModel.cs +++ b/VPet.ModMaker/Models/ModModel/FoodModel.cs @@ -1,4 +1,6 @@ using HKW.HKWViewModels.SimpleObservable; +using LinePutScript; +using LinePutScript.Converter; using System; using System.Collections.Generic; using System.Collections.ObjectModel; diff --git a/VPet.ModMaker/Models/ModModel/ModInfoModel.cs b/VPet.ModMaker/Models/ModModel/ModInfoModel.cs index 79f5644..078a42e 100644 --- a/VPet.ModMaker/Models/ModModel/ModInfoModel.cs +++ b/VPet.ModMaker/Models/ModModel/ModInfoModel.cs @@ -238,8 +238,8 @@ public class ModInfoModel : I18nModel } else if (FoodAnimeTypeModel.FoodAnimeNames.Contains(dirName)) { - //if (FoodAnimeTypeModel.Create(animeDir) is FoodAnimeTypeModel model1) - // petModel.FoodAnimes.Add(model1); + if (FoodAnimeTypeModel.Create(animeDir) is FoodAnimeTypeModel model1) + petModel.FoodAnimes.Add(model1); } } } diff --git a/VPet.ModMaker/Models/Utils.cs b/VPet.ModMaker/Models/Utils.cs index 9f671de..681392d 100644 --- a/VPet.ModMaker/Models/Utils.cs +++ b/VPet.ModMaker/Models/Utils.cs @@ -56,13 +56,12 @@ public static class Utils using var sr = new StreamReader(imagePath); sr.BaseStream.CopyTo(ms); bitmapImage.StreamSource = ms; + bitmapImage.DecodePixelWidth = DecodePixelWidth; } finally { bitmapImage.EndInit(); } - if (bitmapImage.PixelWidth > DecodePixelWidth) - bitmapImage.DecodePixelWidth = DecodePixelWidth; return bitmapImage; } } diff --git a/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimeEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimeEditWindowVM.cs index 52491b5..3c2aaf8 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimeEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimeEditWindowVM.cs @@ -316,8 +316,7 @@ public class AnimeEditWindowVM /// private void StopCommand_ExecuteEvent() { - if (_playing is false) - return; + _playing = false; } /// diff --git a/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/FoodAnimeEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/FoodAnimeEditWindowVM.cs index 21b12ad..806d7fb 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/FoodAnimeEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/FoodAnimeEditWindowVM.cs @@ -479,8 +479,7 @@ public class FoodAnimeEditWindowVM /// private void StopCommand_ExecuteEvent() { - if (_playing is false) - return; + _playing = false; } /// @@ -494,11 +493,16 @@ public class FoodAnimeEditWindowVM return; } _playing = true; - _frontPlayerTask.Start(); - _backPlayerTask.Start(); - _foodPlayerTask.Start(); - await Task.WhenAll(_frontPlayerTask, _backPlayerTask, _foodPlayerTask); - Reset(); + do + { + _frontPlayerTask.Start(); + _backPlayerTask.Start(); + _foodPlayerTask.Start(); + await Task.WhenAll(_frontPlayerTask, _backPlayerTask, _foodPlayerTask); + _frontPlayerTask = new(FrontPlay); + _backPlayerTask = new(BackPlay); + _foodPlayerTask = new(FoodPlay); + } while (Loop.Value && _playing); } /// @@ -506,16 +510,13 @@ public class FoodAnimeEditWindowVM /// private void FrontPlay() { - do + foreach (var model in CurrentAnimeModel.Value.FrontImages) { - foreach (var model in CurrentAnimeModel.Value.FrontImages) - { - CurrentFrontImageModel.Value = model; - Task.Delay(model.Duration.Value).Wait(); - if (_playing is false) - return; - } - } while (Loop.Value); + CurrentFrontImageModel.Value = model; + Task.Delay(model.Duration.Value).Wait(); + if (_playing is false) + return; + } } /// @@ -523,16 +524,13 @@ public class FoodAnimeEditWindowVM /// private void BackPlay() { - do + foreach (var model in CurrentAnimeModel.Value.BackImages) { - foreach (var model in CurrentAnimeModel.Value.BackImages) - { - CurrentBackImageModel.Value = model; - Task.Delay(model.Duration.Value).Wait(); - if (_playing is false) - return; - } - } while (Loop.Value); + CurrentBackImageModel.Value = model; + Task.Delay(model.Duration.Value).Wait(); + if (_playing is false) + return; + } } /// @@ -540,16 +538,13 @@ public class FoodAnimeEditWindowVM /// private void FoodPlay() { - do + foreach (var model in CurrentAnimeModel.Value.FoodLocations) { - foreach (var model in CurrentAnimeModel.Value.FoodLocations) - { - CurrentFoodLocationModel.Value = model; - Task.Delay(model.Duration.Value).Wait(); - if (_playing is false) - return; - } - } while (Loop.Value); + CurrentFoodLocationModel.Value = model; + Task.Delay(model.Duration.Value).Wait(); + if (_playing is false) + return; + } } /// diff --git a/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml.cs b/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml.cs index 01c70b1..65db97a 100644 --- a/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml.cs +++ b/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml.cs @@ -12,6 +12,7 @@ using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; +using VPet.ModMaker.Models; using VPet.ModMaker.Models.ModModel; using VPet.ModMaker.ViewModels.ModEdit.AnimeEdit; using VPet_Simulator.Core; @@ -92,7 +93,7 @@ public partial class AnimeEditWindow : Window HitTestResult result = VisualTreeHelper.HitTest(listBox, pos); if (result is null) return; - var listBoxItem = FindVisualParent(result.VisualHit); + var listBoxItem = result.VisualHit.FindParent(); if (listBoxItem == null || listBoxItem.Content != listBox.SelectedItem) return; var dataObj = new DataObject(listBoxItem.Content); @@ -119,7 +120,7 @@ public partial class AnimeEditWindow : Window if (e.Data.GetData(typeof(ImageModel)) is not ImageModel sourcePerson) return; //查找目标数据 - var listBoxItem = FindVisualParent(result.VisualHit); + var listBoxItem = result.VisualHit.FindParent(); if (listBoxItem == null) return; var targetPerson = listBoxItem.Content as ImageModel; @@ -134,35 +135,6 @@ public partial class AnimeEditWindow : Window list[targetIndex] = temp; } - public static T? FindVisualChild(DependencyObject obj) - where T : DependencyObject - { - if (obj is null) - return null; - var count = VisualTreeHelper.GetChildrenCount(obj); - for (int i = 0; i < count; i++) - { - var child = VisualTreeHelper.GetChild(obj, i); - if (child is T t) - return t; - if (FindVisualChild(child) is T childItem) - return childItem; - } - return null; - } - - public static T FindVisualParent(DependencyObject obj) - where T : class - { - while (obj != null) - { - if (obj is T) - return obj as T; - obj = VisualTreeHelper.GetParent(obj); - } - return null; - } - private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (sender is not ListBox listBox) diff --git a/VPet.ModMaker/Views/ModEdit/AnimeEdit/FoodAnimeEditWindow.xaml b/VPet.ModMaker/Views/ModEdit/AnimeEdit/FoodAnimeEditWindow.xaml index 20b4022..c135ea1 100644 --- a/VPet.ModMaker/Views/ModEdit/AnimeEdit/FoodAnimeEditWindow.xaml +++ b/VPet.ModMaker/Views/ModEdit/AnimeEdit/FoodAnimeEditWindow.xaml @@ -25,7 +25,7 @@ @@ -80,7 +80,16 @@ - @@ -147,7 +155,16 @@ - @@ -214,13 +230,22 @@ - + SelectedItem="{Binding DataContext.CurrentFoodLocationModel.Value, RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}}" + SelectionChanged="ListBox_SelectionChanged"> @@ -371,15 +396,48 @@ + Source="{Binding CurrentBackImageModel.Value.Image.Value}" /> + + + + + + + + + + + + + - + Source="{Binding CurrentFrontImageModel.Value.Image.Value}" /> @@ -447,7 +505,7 @@ ItemsSource="{Binding Anime.Value.HappyAnimes, IsAsync=True}" SelectionChanged="ListBox_Animes_SelectionChanged" /> - + diff --git a/VPet.ModMaker/Views/ModEdit/AnimeEdit/FoodAnimeEditWindow.xaml.cs b/VPet.ModMaker/Views/ModEdit/AnimeEdit/FoodAnimeEditWindow.xaml.cs index 83102ca..b49717c 100644 --- a/VPet.ModMaker/Views/ModEdit/AnimeEdit/FoodAnimeEditWindow.xaml.cs +++ b/VPet.ModMaker/Views/ModEdit/AnimeEdit/FoodAnimeEditWindow.xaml.cs @@ -54,6 +54,8 @@ public partial class FoodAnimeEditWindow : Window private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e) { + if (ViewModel is null) + return; if ( sender is not TabControl tabControl || tabControl.SelectedItem is not TabItem item @@ -136,35 +138,6 @@ public partial class FoodAnimeEditWindow : Window //list[targetIndex] = temp; } - public static T? FindVisualChild(DependencyObject obj) - where T : DependencyObject - { - if (obj is null) - return null; - var count = VisualTreeHelper.GetChildrenCount(obj); - for (int i = 0; i < count; i++) - { - var child = VisualTreeHelper.GetChild(obj, i); - if (child is T t) - return t; - if (FindVisualChild(child) is T childItem) - return childItem; - } - return null; - } - - public static T FindVisualParent(DependencyObject obj) - where T : class - { - while (obj != null) - { - if (obj is T) - return obj as T; - obj = VisualTreeHelper.GetParent(obj); - } - return null; - } - private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (sender is not ListBox listBox)