From c6806e03b584333a2610a024b93cdbd05dfee68d Mon Sep 17 00:00:00 2001 From: Hakoyu Date: Sun, 24 Sep 2023 20:49:30 +0800 Subject: [PATCH] =?UTF-8?q?AnimeEidt=20=E6=94=AF=E6=8C=81=20Raised=5FDynam?= =?UTF-8?q?ic=20=E5=92=8C=20Raised=5FStatic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VPet.ModMaker/Models/ModModel/AnimeModel.cs | 88 +++++++++++++++++-- VPet.ModMaker/Models/ModModel/ModInfoModel.cs | 67 +++++++++----- .../ModEdit/AnimeEdit/AnimeEditWindowVM.cs | 5 ++ .../ModEdit/AnimeEdit/AnimeEditWindow.xaml | 4 +- .../ModEdit/AnimeEdit/AnimeEditWindow.xaml.cs | 12 ++- 5 files changed, 144 insertions(+), 32 deletions(-) diff --git a/VPet.ModMaker/Models/ModModel/AnimeModel.cs b/VPet.ModMaker/Models/ModModel/AnimeModel.cs index 1f9df97..45cae1f 100644 --- a/VPet.ModMaker/Models/ModModel/AnimeModel.cs +++ b/VPet.ModMaker/Models/ModModel/AnimeModel.cs @@ -68,6 +68,7 @@ public class AnimeTypeModel or GraphInfo.GraphType.Switch_Down or GraphInfo.GraphType.Switch_Thirsty or GraphInfo.GraphType.Switch_Hunger + or GraphInfo.GraphType.Raised_Dynamic ) LoadDefault(path); else if ( @@ -75,6 +76,7 @@ public class AnimeTypeModel is GraphInfo.GraphType.Touch_Head or GraphInfo.GraphType.Touch_Body or GraphInfo.GraphType.Sleep + or GraphInfo.GraphType.Raised_Static ) LoadMultiType(path); else @@ -98,19 +100,39 @@ public class AnimeTypeModel foreach (var dir in Directory.EnumerateDirectories(path)) { var dirName = Path.GetFileName(dir); - if (dirName.Contains(nameof(GameSave.ModeType.Happy))) + if ( + dirName.Contains( + nameof(GameSave.ModeType.Happy), + StringComparison.InvariantCultureIgnoreCase + ) + ) { AddAnime(HappyAnimes, dir); } - else if (dirName.Contains(nameof(GameSave.ModeType.Nomal))) + else if ( + dirName.Contains( + nameof(GameSave.ModeType.Nomal), + StringComparison.InvariantCultureIgnoreCase + ) + ) { AddAnime(NomalAnimes, dir); } - else if (dirName.Contains(nameof(GameSave.ModeType.PoorCondition))) + else if ( + dirName.Contains( + nameof(GameSave.ModeType.PoorCondition), + StringComparison.InvariantCultureIgnoreCase + ) + ) { AddAnime(PoorConditionAnimes, dir); } - else if (dirName.Contains(nameof(GameSave.ModeType.Ill))) + else if ( + dirName.Contains( + nameof(GameSave.ModeType.Ill), + StringComparison.InvariantCultureIgnoreCase + ) + ) { AddAnime(IllAnimes, dir); } @@ -228,7 +250,7 @@ public class AnimeTypeModel or GraphInfo.GraphType.Touch_Body or GraphInfo.GraphType.Sleep ) - SaveMultiType(path, this); + SaveWithModeType(path, this); else if ( GraphType.Value is GraphInfo.GraphType.Switch_Up @@ -237,6 +259,22 @@ public class AnimeTypeModel or GraphInfo.GraphType.Switch_Hunger ) SaveSwitch(path, this); + else if ( + GraphType.Value + is GraphInfo.GraphType.Raised_Dynamic + or GraphInfo.GraphType.Raised_Static + ) + SaveRaise(path, this); + } + + void SaveRaise(string path, AnimeTypeModel animeTypeModel) + { + var animePath = Path.Combine(path, "Raise"); + Directory.CreateDirectory(animePath); + if (animeTypeModel.GraphType.Value is GraphInfo.GraphType.Raised_Dynamic) + SaveDefault(animePath, animeTypeModel); + else if (animeTypeModel.GraphType.Value is GraphInfo.GraphType.Raised_Static) + SaveWithModeType(animePath, animeTypeModel); } void SaveSwitch(string path, AnimeTypeModel animeTypeModel) @@ -247,7 +285,22 @@ public class AnimeTypeModel SaveWithAnimeType(Path.Combine(animePath, switchName), animeTypeModel); } - void SaveMultiType(string path, AnimeTypeModel animeTypeModel) + /// + /// 保存为 ModeType 划分的样式 + /// + /// + /// + /// + /// + void SaveWithModeType(string path, AnimeTypeModel animeTypeModel) { var animePath = Path.Combine(path, animeTypeModel.GraphType.ToString()); Directory.CreateDirectory(animePath); @@ -305,6 +358,11 @@ public class AnimeTypeModel } } + /// + /// 保存成默认样式 + /// + /// + /// static void SaveDefault(string path, AnimeTypeModel animeTypeModel) { var animePath = Path.Combine(path, animeTypeModel.GraphType.ToString()); @@ -312,6 +370,19 @@ public class AnimeTypeModel SaveWithAnimeType(animePath, animeTypeModel); } + /// + /// 保存为 AnimeType 划分的样式 + /// + /// + /// + /// + /// static void SaveWithAnimeType(string animePath, AnimeTypeModel animeType) { if (animeType.HappyAnimes.Count > 0) @@ -346,6 +417,11 @@ public class AnimeTypeModel } } + /// + /// 保存图片 + /// + /// + /// static void SaveImages(string imagesPath, AnimeModel model) { Directory.CreateDirectory(imagesPath); diff --git a/VPet.ModMaker/Models/ModModel/ModInfoModel.cs b/VPet.ModMaker/Models/ModModel/ModInfoModel.cs index 2f67df3..0bfa584 100644 --- a/VPet.ModMaker/Models/ModModel/ModInfoModel.cs +++ b/VPet.ModMaker/Models/ModModel/ModInfoModel.cs @@ -77,29 +77,7 @@ public class ModInfoModel : I18nModel // TODO: 动画加载 foreach (var p in pet.path) { - foreach (var dir in Directory.EnumerateDirectories(p)) - { - var dirName = Path.GetFileName(dir); - Enum.TryParse(dirName, true, out var animeType); - if (AnimeTypeModel.Create(animeType, dir) is AnimeTypeModel model) - petModel.Animes.Add(model); - else if (dirName.Equals("Switch", StringComparison.InvariantCultureIgnoreCase)) - { - foreach (var switchDir in Directory.EnumerateDirectories(dir)) - { - Enum.TryParse( - $"{dirName}_{Path.GetFileName(switchDir)}", - true, - out var switchType - ); - if ( - AnimeTypeModel.Create(switchType, Path.Combine(dir, switchDir)) - is AnimeTypeModel switchModel - ) - petModel.Animes.Add(switchModel); - } - } - } + LoadAnime(petModel, p); } } @@ -108,6 +86,49 @@ public class ModInfoModel : I18nModel OtherI18nDatas = loader.OtherI18nDatas; LoadI18nData(); + + static void LoadAnime(PetModel petModel, string path) + { + foreach (var animeDir in Directory.EnumerateDirectories(path)) + { + var dirName = Path.GetFileName(animeDir); + Enum.TryParse(dirName, true, out var animeType); + if (AnimeTypeModel.Create(animeType, animeDir) is AnimeTypeModel model) + petModel.Animes.Add(model); + else if (dirName.Equals("Switch", StringComparison.InvariantCultureIgnoreCase)) + { + foreach (var dir in Directory.EnumerateDirectories(animeDir)) + { + Enum.TryParse( + $"{dirName}_{Path.GetFileName(dir)}", + true, + out var switchType + ); + if ( + AnimeTypeModel.Create(switchType, Path.Combine(animeDir, dir)) + is AnimeTypeModel switchModel + ) + petModel.Animes.Add(switchModel); + } + } + else if (dirName.Equals("Raise", StringComparison.InvariantCultureIgnoreCase)) + { + foreach (var dir in Directory.EnumerateDirectories(animeDir)) + { + Enum.TryParse( + Path.GetFileName(dir), + true, + out var switchType + ); + if ( + AnimeTypeModel.Create(switchType, Path.Combine(animeDir, dir)) + is AnimeTypeModel switchModel + ) + petModel.Animes.Add(switchModel); + } + } + } + } } private void LoadI18nData() diff --git a/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimeEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimeEditWindowVM.cs index 90dfaae..de93005 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimeEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimeEditWindowVM.cs @@ -175,6 +175,11 @@ public class AnimeEditWindowVM MessageBox.Show("正在播放".Translate()); return; } + if (CurrentAnimeModel.Value is null) + { + MessageBox.Show("未选中动画".Translate()); + return; + } _playing = true; _playerTask.Start(); } diff --git a/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml b/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml index bb7daa9..b663818 100644 --- a/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml +++ b/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml @@ -196,11 +196,13 @@ + ItemsSource="{Binding Anime.Value.HappyAnimes, IsAsync=True}" + SelectionChanged="ListBox_Animes_SelectionChanged" /> diff --git a/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml.cs b/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml.cs index 5a0de71..b281cbc 100644 --- a/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml.cs +++ b/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml.cs @@ -1,4 +1,5 @@ -using System; +using LinePutScript.Localization.WPF; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -62,6 +63,7 @@ public partial class AnimeEditWindow : Window if (Enum.TryParse(str, true, out var mode)) { ViewModel.CurrentMode = mode; + ViewModel.CurrentImageModel.Value = null; ViewModel.CurrentAnimeModel.Value = null; } } @@ -106,7 +108,7 @@ public partial class AnimeEditWindow : Window ViewModel.AddImages((AnimeModel)listBox.DataContext, array.Cast()); if (_dropSender is not null && sender.Equals(_dropSender) is false) { - MessageBox.Show("无法移动不同动画的图片"); + MessageBox.Show("无法移动不同动画的图片".Translate()); return; } var pos = e.GetPosition(listBox); @@ -179,5 +181,11 @@ public partial class AnimeEditWindow : Window return; if (listBox.DataContext is AnimeModel model) ViewModel.CurrentAnimeModel.Value = model; + e.Handled = true; + } + + private void ListBox_Animes_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + e.Handled = true; } }