diff --git a/VPet.ModMaker/Models/ModModel/AnimeModel.cs b/VPet.ModMaker/Models/ModModel/AnimeModel.cs index 655d6b0..fd2e5fd 100644 --- a/VPet.ModMaker/Models/ModModel/AnimeModel.cs +++ b/VPet.ModMaker/Models/ModModel/AnimeModel.cs @@ -108,10 +108,7 @@ public class AnimeModel .Split(_splits, StringSplitOptions.RemoveEmptyEntries); Id.Value = info[0]; var duration = info.Last(); - var imageModel = new ImageModel( - Utils.LoadImageToMemoryStream(file), - int.Parse(duration) - ); + var imageModel = new ImageModel(Utils.LoadImageToStream(file), int.Parse(duration)); Images.Add(imageModel); } } @@ -125,4 +122,10 @@ public class AnimeModel model.Images.Add(image); return model; } + + public void Close() + { + foreach (var image in Images) + image.Close(); + } } diff --git a/VPet.ModMaker/Models/ModModel/ImageModel.cs b/VPet.ModMaker/Models/ModModel/ImageModel.cs index f713af8..8ecbf46 100644 --- a/VPet.ModMaker/Models/ModModel/ImageModel.cs +++ b/VPet.ModMaker/Models/ModModel/ImageModel.cs @@ -27,4 +27,9 @@ public class ImageModel ); return model; } + + public void Close() + { + Image.Value?.CloseStream(); + } } diff --git a/VPet.ModMaker/Models/ModModel/ModInfoModel.cs b/VPet.ModMaker/Models/ModModel/ModInfoModel.cs index 23b9b2e..35d0cdd 100644 --- a/VPet.ModMaker/Models/ModModel/ModInfoModel.cs +++ b/VPet.ModMaker/Models/ModModel/ModInfoModel.cs @@ -223,14 +223,6 @@ public class ModInfoModel : I18nModel Directory.CreateDirectory(petPath); foreach (var pet in Pets) { - var petFile = Path.Combine(petPath, $"{pet.Id.Value}.lps"); - if (File.Exists(petFile) is false) - File.Create(petFile).Close(); - var lps = new LPS(); - GetPetInfo(lps, pet); - GetWorksInfo(lps, pet); - GetMoveInfo(lps, pet); - File.WriteAllText(petFile, lps.ToString()); foreach (var cultureName in I18nHelper.Current.CultureNames) { _saveI18nDatas[cultureName].TryAdd( @@ -246,6 +238,77 @@ public class ModInfoModel : I18nModel pet.I18nDatas[cultureName].Description.Value ); } + var petFile = Path.Combine(petPath, $"{pet.Id.Value}.lps"); + if (File.Exists(petFile) is false) + File.Create(petFile).Close(); + var lps = new LPS(); + GetPetInfo(lps, pet); + GetWorksInfo(lps, pet); + GetMoveInfo(lps, pet); + File.WriteAllText(petFile, lps.ToString()); + + var petAnimePath = Path.Combine(petPath, pet.Id.Value); + Directory.CreateDirectory(petAnimePath); + SaveAnime_Default(petAnimePath, pet); + } + } + + void SaveAnime_Default(string path, PetModel pet) + { + if ( + pet.Animes.FirstOrDefault(m => m.GraphType.Value == GraphInfo.GraphType.Default) + is not AnimeTypeModel animeType + ) + return; + var animePath = Path.Combine(path, nameof(GraphInfo.GraphType.Default)); + Directory.CreateDirectory(animePath); + if (animeType.HappyAnimes.Count > 0) + { + var modePath = Path.Combine(animePath, nameof(GameSave.ModeType.Happy)); + SaveImage(animeType.HappyAnimes, animeType, modePath); + } + if (animeType.NomalAnimes.Count > 0) + { + var modePath = Path.Combine(animePath, nameof(GameSave.ModeType.Nomal)); + SaveImage(animeType.NomalAnimes, animeType, modePath); + } + if (animeType.PoorConditionAnimes.Count > 0) + { + var modePath = Path.Combine(animePath, nameof(GameSave.ModeType.PoorCondition)); + SaveImage(animeType.PoorConditionAnimes, animeType, modePath); + } + if (animeType.IllAnimes.Count > 0) + { + var modePath = Path.Combine(animePath, nameof(GameSave.ModeType.Ill)); + SaveImage(animeType.IllAnimes, animeType, modePath); + } + + static void SaveImage( + ObservableCollection animes, + AnimeTypeModel animeType, + string modePath + ) + { + Directory.CreateDirectory(modePath); + var count = 0; + foreach (var anime in animes) + { + var imagePath = Path.Combine(modePath, count.ToString()); + Directory.CreateDirectory(imagePath); + var imageIndex = 0; + foreach (var image in anime.Images) + { + File.Copy( + image.Image.Value.GetSourceFile(), + Path.Combine( + imagePath, + $"{anime.Id.Value}_{imageIndex:000}_{image.Duration.Value}.png" + ) + ); + imageIndex++; + } + count++; + } } } diff --git a/VPet.ModMaker/VPet.ModMaker.csproj b/VPet.ModMaker/VPet.ModMaker.csproj index 8936635..9229814 100644 --- a/VPet.ModMaker/VPet.ModMaker.csproj +++ b/VPet.ModMaker/VPet.ModMaker.csproj @@ -139,6 +139,9 @@ AnimePage.xaml + + SelectGraphTypeWindow.xaml + ClickTextPage.xaml @@ -245,6 +248,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimeEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimeEditWindowVM.cs index f038414..e244e42 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimeEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimeEditWindowVM.cs @@ -20,10 +20,12 @@ public class AnimeEditWindowVM public AnimeTypeModel OldAnime { get; set; } public ObservableValue Anime { get; } = new(new()); public ObservableValue CurrentImageModel { get; } = new(); + public ObservableValue CurrentAnimeModel { get; } = new(); public GameSave.ModeType CurrentMode { get; set; } + public ObservableValue Loop { get; } = new(); #region Command public ObservableCommand PlayCommand { get; } = new(); - public ObservableCommand PauseCommand { get; } = new(); + public ObservableCommand StopCommand { get; } = new(); public ObservableCommand AddImageCommand { get; } = new(); public ObservableCommand ClearImageCommand { get; } = new(); @@ -31,22 +33,42 @@ public class AnimeEditWindowVM public ObservableCommand RemoveImageCommand { get; } = new(); #endregion - public bool _pause = false; - public Task _playerTask; + private bool _playing = false; + private Task _playerTask; public AnimeEditWindowVM() { - //_playerTask = new(Play); - //PlayCommand.ExecuteEvent += PlayCommand_ExecuteEvent; - //PauseCommand.ExecuteEvent += PauseCommand_ExecuteEvent; + _playerTask = new(Play); + + CurrentAnimeModel.ValueChanged += CurrentAnimeModel_ValueChanged; + ; + + PlayCommand.ExecuteEvent += PlayCommand_ExecuteEvent; + StopCommand.ExecuteEvent += StopCommand_ExecuteEvent; AddImageCommand.ExecuteEvent += AddImageCommand_ExecuteEvent; ClearImageCommand.ExecuteEvent += ClearImageCommand_ExecuteEvent; RemoveAnimeCommand.ExecuteEvent += RemoveAnimeCommand_ExecuteEvent; RemoveImageCommand.ExecuteEvent += RemoveImageCommand_ExecuteEvent; } + private void CurrentAnimeModel_ValueChanged(AnimeModel oldValue, AnimeModel newValue) + { + StopCommand_ExecuteEvent(); + oldValue.Images.CollectionChanged -= Images_CollectionChanged; + newValue.Images.CollectionChanged += Images_CollectionChanged; + } + + private void Images_CollectionChanged( + object sender, + System.Collections.Specialized.NotifyCollectionChangedEventArgs e + ) + { + StopCommand_ExecuteEvent(); + } + private void RemoveImageCommand_ExecuteEvent(AnimeModel value) { + CurrentImageModel.Value.Close(); value.Images.Remove(CurrentImageModel.Value); } @@ -64,6 +86,7 @@ public class AnimeEditWindowVM Anime.Value.PoorConditionAnimes.Remove(value); else if (CurrentMode is GameSave.ModeType.Ill) Anime.Value.IllAnimes.Remove(value); + value.Close(); } } @@ -72,7 +95,10 @@ public class AnimeEditWindowVM if ( MessageBox.Show("确定清空吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.Yes ) + { + value.Close(); value.Images.Clear(); + } } private void AddImageCommand_ExecuteEvent(AnimeModel value) @@ -89,25 +115,42 @@ public class AnimeEditWindowVM } } - private void PauseCommand_ExecuteEvent() + private void StopCommand_ExecuteEvent() { - //_pause = true; + if (_playing is false) + return; + Reset(); } private void PlayCommand_ExecuteEvent() { - //_playerTask.Start(); + if (_playing) + { + MessageBox.Show("正在播放".Translate()); + return; + } + _playing = true; + _playerTask.Start(); } private void Play() { - //while (_pause is false) - //{ - // foreach (var model in Anime.Value.ImageModels) - // { - // Anime.Value.CurrentImageModel.Value = model; - // Task.Delay(model.Duration.Value).Wait(); - // } - //} + do + { + foreach (var model in CurrentAnimeModel.Value.Images) + { + CurrentImageModel.Value = model; + Task.Delay(model.Duration.Value).Wait(); + if (_playing is false) + return; + } + } while (Loop.Value); + Reset(); + } + + private void Reset() + { + _playing = false; + _playerTask = new(Play); } } diff --git a/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimePageVM.cs b/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimePageVM.cs index 76234e1..feddeb2 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimePageVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimePageVM.cs @@ -62,9 +62,16 @@ public class AnimePageVM private void Add() { + var selectGraphTypeWindow = new SelectGraphTypeWindow(); + selectGraphTypeWindow.CurrentPet.Value = CurrentPet.Value; + selectGraphTypeWindow.ShowDialog(); + var graphType = selectGraphTypeWindow.GraphType.Value; + if (selectGraphTypeWindow.IsCancel) + return; var window = new AnimeEditWindow(); var vm = window.ViewModel; vm.CurrentPet = CurrentPet.Value; + vm.Anime.Value.GraphType.Value = graphType; window.ShowDialog(); if (window.IsCancel) return; diff --git a/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml b/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml index d54f82c..2645310 100644 --- a/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml +++ b/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml @@ -68,7 +68,8 @@ ItemsSource="{Binding Images, IsAsync=True}" PreviewMouseMove="ListBox_PreviewMouseMove" PreviewMouseWheel="ListBox_PreviewMouseWheel" - SelectedItem="{Binding DataContext.CurrentImageModel.Value, RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}}"> + SelectedItem="{Binding DataContext.CurrentImageModel.Value, RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}}" + SelectionChanged="ListBox_SelectionChanged"> @@ -128,9 +129,15 @@ - + - + @@ -139,12 +146,15 @@ -