From bfd45fd2aa87c4ad0fa33abd3b49614e118a1272 Mon Sep 17 00:00:00 2001 From: Hakoyu Date: Sat, 21 Oct 2023 22:52:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ModEdit/AnimeEdit/AnimeEditWindowVM.cs | 2 +- .../ModEdit/AnimeEdit/AnimePageVM.cs | 5 +- .../AnimeEdit/FoodAnimeEditWindowVM.cs | 71 +++- .../ModEdit/AnimeEdit/AnimeEditWindow.xaml | 4 +- .../ModEdit/AnimeEdit/AnimeEditWindow.xaml.cs | 3 +- .../AnimeEdit/FoodAnimeEditWindow.xaml | 346 +++++++++--------- .../AnimeEdit/FoodAnimeEditWindow.xaml.cs | 106 +++--- 7 files changed, 319 insertions(+), 218 deletions(-) diff --git a/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimeEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimeEditWindowVM.cs index 3c2aaf8..91ac9b2 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimeEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimeEditWindowVM.cs @@ -217,8 +217,8 @@ public class AnimeEditWindowVM /// 动画模型 private void RemoveImageCommand_ExecuteEvent(AnimeModel value) { - value.Images.Remove(CurrentImageModel.Value); CurrentImageModel.Value.Close(); + value.Images.Remove(CurrentImageModel.Value); } /// diff --git a/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimePageVM.cs b/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimePageVM.cs index 86cf870..1029c48 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimePageVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimePageVM.cs @@ -1,5 +1,6 @@ using HKW.HKWViewModels.SimpleObservable; using LinePutScript.Localization.WPF; +using Panuon.WPF.UI; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -180,14 +181,15 @@ public class AnimePageVM /// 动画类型模型 public void Edit(object model) { + var pendingHandler = PendingBox.Show("载入中".Translate()); if (model is AnimeTypeModel animeTypeModel) { - // TODO: FoodAnime var window = new AnimeEditWindow(); var vm = window.ViewModel; vm.CurrentPet = CurrentPet.Value; vm.OldAnime = animeTypeModel; var newAnime = vm.Anime.Value = new(animeTypeModel); + pendingHandler.Close(); window.ShowDialog(); if (window.IsCancel) return; @@ -208,6 +210,7 @@ public class AnimePageVM vm.CurrentPet = CurrentPet.Value; vm.OldAnime = foodAnimeTypeModel; var newAnime = vm.Anime.Value = new(foodAnimeTypeModel); + pendingHandler.Close(); window.ShowDialog(); if (window.IsCancel) return; diff --git a/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/FoodAnimeEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/FoodAnimeEditWindowVM.cs index 806d7fb..bb619ec 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/FoodAnimeEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/FoodAnimeEditWindowVM.cs @@ -126,6 +126,11 @@ public class FoodAnimeEditWindowVM /// 清除顶层图片命令 /// public ObservableCommand ClearFrontImageCommand { get; } = new(); + + /// + /// 改变顶层图片命令 + /// + public ObservableCommand ChangeFrontImageCommand { get; } = new(); #endregion #region BackImage @@ -143,6 +148,11 @@ public class FoodAnimeEditWindowVM /// 清除底层图片命令 /// public ObservableCommand ClearBackImageCommand { get; } = new(); + + /// + /// 改变底层图片命令 + /// + public ObservableCommand ChangeBackImageCommand { get; } = new(); #endregion #region FoodLocation /// @@ -169,6 +179,7 @@ public class FoodAnimeEditWindowVM /// 重置食物图片 /// public ObservableCommand ResetFoodImageCommand { get; } = new(); + #endregion /// @@ -210,10 +221,12 @@ public class FoodAnimeEditWindowVM AddFrontImageCommand.ExecuteEvent += AddFrontImageCommand_ExecuteEvent; RemoveFrontImageCommand.ExecuteEvent += RemoveFrontImageCommand_ExecuteEvent; ClearFrontImageCommand.ExecuteEvent += ClearFrontImageCommand_ExecuteEvent; + ChangeFrontImageCommand.ExecuteEvent += ChangeFrontImageCommand_ExecuteEvent; AddBackImageCommand.ExecuteEvent += AddBackImageCommand_ExecuteEvent; RemoveBackImageCommand.ExecuteEvent += RemoveBackImageCommand_ExecuteEvent; ClearBackImageCommand.ExecuteEvent += ClearBackImageCommand_ExecuteEvent; + ChangeBackImageCommand.ExecuteEvent += ChangeBackImageCommand_ExecuteEvent; AddeFoodLocationCommand.ExecuteEvent += AddeFoodLocationCommand_ExecuteEvent; RemoveFoodLocationCommand.ExecuteEvent += RemoveFoodLocationCommand_ExecuteEvent; @@ -318,8 +331,8 @@ public class FoodAnimeEditWindowVM /// 动画模型 private void RemoveFrontImageCommand_ExecuteEvent(FoodAnimeModel value) { - value.FrontImages.Remove(CurrentFrontImageModel.Value); CurrentFrontImageModel.Value.Close(); + value.FrontImages.Remove(CurrentFrontImageModel.Value); } /// @@ -338,6 +351,33 @@ public class FoodAnimeEditWindowVM } } + /// + /// 替换顶层图片 + /// + /// + /// + private void ChangeFrontImageCommand_ExecuteEvent(FoodAnimeModel value) + { + OpenFileDialog openFileDialog = + new() { Title = "选择图片".Translate(), Filter = $"图片|*.png".Translate() }; + if (openFileDialog.ShowDialog() is not true) + return; + BitmapImage newImage; + try + { + newImage = Utils.LoadImageToMemoryStream(openFileDialog.FileName); + } + catch (Exception ex) + { + MessageBox.Show("替换失败失败 \n{0}".Translate(ex)); + return; + } + if (newImage is null) + return; + CurrentFrontImageModel.Value.Close(); + CurrentFrontImageModel.Value.Image.Value = newImage; + } + private void ShowFrontImagesPathInfo(FoodImagesPath imagesPath) { MessageBox.Show( @@ -375,8 +415,8 @@ public class FoodAnimeEditWindowVM /// 动画模型 private void RemoveBackImageCommand_ExecuteEvent(FoodAnimeModel value) { - value.BackImages.Remove(CurrentBackImageModel.Value); CurrentBackImageModel.Value.Close(); + value.BackImages.Remove(CurrentBackImageModel.Value); } /// @@ -394,6 +434,33 @@ public class FoodAnimeEditWindowVM value.BackImages.Clear(); } } + + /// + /// 替换底层图片 + /// + /// + /// + private void ChangeBackImageCommand_ExecuteEvent(FoodAnimeModel value) + { + OpenFileDialog openFileDialog = + new() { Title = "选择图片".Translate(), Filter = $"图片|*.png".Translate() }; + if (openFileDialog.ShowDialog() is not true) + return; + BitmapImage newImage; + try + { + newImage = Utils.LoadImageToMemoryStream(openFileDialog.FileName); + } + catch (Exception ex) + { + MessageBox.Show("替换失败失败 \n{0}".Translate(ex)); + return; + } + if (newImage is null) + return; + CurrentBackImageModel.Value.Close(); + CurrentBackImageModel.Value.Image.Value = newImage; + } #endregion /// diff --git a/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml b/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml index 7b2c6c5..c4236bb 100644 --- a/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml +++ b/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml @@ -84,11 +84,13 @@ ItemsSource="{Binding Images, IsAsync=True}" PreviewMouseMove="ListBox_PreviewMouseMove" PreviewMouseWheel="ListBox_PreviewMouseWheel" + ScrollViewer.HorizontalScrollBarVisibility="Auto" + ScrollViewer.VerticalScrollBarVisibility="Hidden" SelectedItem="{Binding DataContext.CurrentImageModel.Value, RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}}" SelectionChanged="ListBox_SelectionChanged"> - + diff --git a/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml.cs b/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml.cs index 65db97a..3202721 100644 --- a/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml.cs +++ b/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml.cs @@ -97,8 +97,8 @@ public partial class AnimeEditWindow : Window if (listBoxItem == null || listBoxItem.Content != listBox.SelectedItem) return; var dataObj = new DataObject(listBoxItem.Content); - DragDrop.DoDragDrop(listBox, dataObj, DragDropEffects.Move); _dropSender = sender; + DragDrop.DoDragDrop(listBox, dataObj, DragDropEffects.Move); } private void ListBox_Drop(object sender, DragEventArgs e) @@ -141,6 +141,7 @@ public partial class AnimeEditWindow : Window return; if (listBox.DataContext is AnimeModel model) ViewModel.CurrentAnimeModel.Value = model; + listBox.ScrollIntoView(listBox.SelectedItem); e.Handled = true; } diff --git a/VPet.ModMaker/Views/ModEdit/AnimeEdit/FoodAnimeEditWindow.xaml b/VPet.ModMaker/Views/ModEdit/AnimeEdit/FoodAnimeEditWindow.xaml index c135ea1..982ac9c 100644 --- a/VPet.ModMaker/Views/ModEdit/AnimeEdit/FoodAnimeEditWindow.xaml +++ b/VPet.ModMaker/Views/ModEdit/AnimeEdit/FoodAnimeEditWindow.xaml @@ -53,185 +53,34 @@ - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/VPet.ModMaker/Views/ModEdit/AnimeEdit/FoodAnimeEditWindow.xaml.cs b/VPet.ModMaker/Views/ModEdit/AnimeEdit/FoodAnimeEditWindow.xaml.cs index b49717c..e17b3c7 100644 --- a/VPet.ModMaker/Views/ModEdit/AnimeEdit/FoodAnimeEditWindow.xaml.cs +++ b/VPet.ModMaker/Views/ModEdit/AnimeEdit/FoodAnimeEditWindow.xaml.cs @@ -1,5 +1,6 @@ using LinePutScript.Localization.WPF; using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; @@ -12,6 +13,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; @@ -88,54 +90,69 @@ public partial class FoodAnimeEditWindow : Window private void ListBox_PreviewMouseMove(object sender, MouseEventArgs e) { - //if (sender is not ListBox listBox) - // return; - //if (e.LeftButton != MouseButtonState.Pressed) - // return; - //var pos = e.GetPosition(listBox); - //HitTestResult result = VisualTreeHelper.HitTest(listBox, pos); - //if (result is null) - // return; - //var listBoxItem = FindVisualParent(result.VisualHit); - //if (listBoxItem == null || listBoxItem.Content != listBox.SelectedItem) - // return; - //var dataObj = new DataObject(listBoxItem.Content); - //DragDrop.DoDragDrop(listBox, dataObj, DragDropEffects.Move); - //_dropSender = sender; + if (sender is not ListBox listBox) + return; + if (e.LeftButton != MouseButtonState.Pressed) + return; + var pos = e.GetPosition(listBox); + HitTestResult result = VisualTreeHelper.HitTest(listBox, pos); + if (result is null) + return; + var listBoxItem = result.VisualHit.FindParent(); + if (listBoxItem == null || listBoxItem.Content != listBox.SelectedItem) + return; + var dataObj = new DataObject(listBoxItem.Content); + _dropSender = sender; + DragDrop.DoDragDrop(listBox, dataObj, DragDropEffects.Move); } private void ListBox_Drop(object sender, DragEventArgs e) { - //if (sender is not ListBox listBox) - // return; - //if (e.Data.GetData(DataFormats.FileDrop) is Array array) - // ViewModel.AddImages(((AnimeModel)listBox.DataContext, array.Cast()); - //if (_dropSender is not null && sender.Equals(_dropSender) is false) - //{ - // MessageBox.Show("无法移动不同动画的图片".Translate()); - // return; - //} - //var pos = e.GetPosition(listBox); - //var result = VisualTreeHelper.HitTest(listBox, pos); - //if (result == null) - // return; - ////查找元数据 - //if (e.Data.GetData(typeof(ImageModel)) is not ImageModel sourcePerson) - // return; - ////查找目标数据 - //var listBoxItem = FindVisualParent(result.VisualHit); - //if (listBoxItem == null) - // return; - //var targetPerson = listBoxItem.Content as ImageModel; - //if (ReferenceEquals(targetPerson, sourcePerson)) - // return; - //if (listBox.ItemsSource is not IList list) - // return; - //var sourceIndex = list.IndexOf(sourcePerson); - //var targetIndex = list.IndexOf(targetPerson); - //var temp = list[sourceIndex]; - //list[sourceIndex] = list[targetIndex]; - //list[targetIndex] = temp; + if (sender is not ListBox listBox) + return; + if (e.Data.GetData(DataFormats.FileDrop) is Array array) + { + if (listBox.Name == "ListBox_FrontImages") + { + ViewModel.AddImages( + ((FoodAnimeModel)listBox.DataContext).FrontImages, + array.Cast() + ); + } + else if (listBox.Name == "ListBox_BackImages") + { + ViewModel.AddImages( + ((FoodAnimeModel)listBox.DataContext).BackImages, + array.Cast() + ); + } + } + if (_dropSender is not null && sender.Equals(_dropSender) is false) + { + MessageBox.Show("无法移动不同动画的图片".Translate()); + return; + } + var pos = e.GetPosition(listBox); + var result = VisualTreeHelper.HitTest(listBox, pos); + if (result == null) + return; + //查找元数据 + if (e.Data.GetData(typeof(ImageModel)) is not ImageModel sourcePerson) + return; + //查找目标数据 + var listBoxItem = result.VisualHit.FindParent(); + if (listBoxItem == null) + return; + var targetPerson = listBoxItem.Content as ImageModel; + if (ReferenceEquals(targetPerson, sourcePerson)) + return; + if (listBox.ItemsSource is not IList list) + return; + var sourceIndex = list.IndexOf(sourcePerson); + var targetIndex = list.IndexOf(targetPerson); + var temp = list[sourceIndex]; + list[sourceIndex] = list[targetIndex]; + list[targetIndex] = temp; } private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) @@ -144,6 +161,7 @@ public partial class FoodAnimeEditWindow : Window return; if (listBox.DataContext is FoodAnimeModel model) ViewModel.CurrentAnimeModel.Value = model; + listBox.ScrollIntoView(listBox.SelectedItem); e.Handled = true; }