优化界面

This commit is contained in:
Hakoyu
2023-10-21 22:52:14 +08:00
parent 355742b219
commit bfd45fd2aa
7 changed files with 319 additions and 218 deletions

View File

@ -217,8 +217,8 @@ public class AnimeEditWindowVM
/// <param name="value">动画模型</param> /// <param name="value">动画模型</param>
private void RemoveImageCommand_ExecuteEvent(AnimeModel value) private void RemoveImageCommand_ExecuteEvent(AnimeModel value)
{ {
value.Images.Remove(CurrentImageModel.Value);
CurrentImageModel.Value.Close(); CurrentImageModel.Value.Close();
value.Images.Remove(CurrentImageModel.Value);
} }
/// <summary> /// <summary>

View File

@ -1,5 +1,6 @@
using HKW.HKWViewModels.SimpleObservable; using HKW.HKWViewModels.SimpleObservable;
using LinePutScript.Localization.WPF; using LinePutScript.Localization.WPF;
using Panuon.WPF.UI;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
@ -180,14 +181,15 @@ public class AnimePageVM
/// <param name="model">动画类型模型</param> /// <param name="model">动画类型模型</param>
public void Edit(object model) public void Edit(object model)
{ {
var pendingHandler = PendingBox.Show("载入中".Translate());
if (model is AnimeTypeModel animeTypeModel) if (model is AnimeTypeModel animeTypeModel)
{ {
// TODO: FoodAnime
var window = new AnimeEditWindow(); var window = new AnimeEditWindow();
var vm = window.ViewModel; var vm = window.ViewModel;
vm.CurrentPet = CurrentPet.Value; vm.CurrentPet = CurrentPet.Value;
vm.OldAnime = animeTypeModel; vm.OldAnime = animeTypeModel;
var newAnime = vm.Anime.Value = new(animeTypeModel); var newAnime = vm.Anime.Value = new(animeTypeModel);
pendingHandler.Close();
window.ShowDialog(); window.ShowDialog();
if (window.IsCancel) if (window.IsCancel)
return; return;
@ -208,6 +210,7 @@ public class AnimePageVM
vm.CurrentPet = CurrentPet.Value; vm.CurrentPet = CurrentPet.Value;
vm.OldAnime = foodAnimeTypeModel; vm.OldAnime = foodAnimeTypeModel;
var newAnime = vm.Anime.Value = new(foodAnimeTypeModel); var newAnime = vm.Anime.Value = new(foodAnimeTypeModel);
pendingHandler.Close();
window.ShowDialog(); window.ShowDialog();
if (window.IsCancel) if (window.IsCancel)
return; return;

View File

@ -126,6 +126,11 @@ public class FoodAnimeEditWindowVM
/// 清除顶层图片命令 /// 清除顶层图片命令
/// </summary> /// </summary>
public ObservableCommand<FoodAnimeModel> ClearFrontImageCommand { get; } = new(); public ObservableCommand<FoodAnimeModel> ClearFrontImageCommand { get; } = new();
/// <summary>
/// 改变顶层图片命令
/// </summary>
public ObservableCommand<FoodAnimeModel> ChangeFrontImageCommand { get; } = new();
#endregion #endregion
#region BackImage #region BackImage
@ -143,6 +148,11 @@ public class FoodAnimeEditWindowVM
/// 清除底层图片命令 /// 清除底层图片命令
/// </summary> /// </summary>
public ObservableCommand<FoodAnimeModel> ClearBackImageCommand { get; } = new(); public ObservableCommand<FoodAnimeModel> ClearBackImageCommand { get; } = new();
/// <summary>
/// 改变底层图片命令
/// </summary>
public ObservableCommand<FoodAnimeModel> ChangeBackImageCommand { get; } = new();
#endregion #endregion
#region FoodLocation #region FoodLocation
/// <summary> /// <summary>
@ -169,6 +179,7 @@ public class FoodAnimeEditWindowVM
/// 重置食物图片 /// 重置食物图片
/// </summary> /// </summary>
public ObservableCommand ResetFoodImageCommand { get; } = new(); public ObservableCommand ResetFoodImageCommand { get; } = new();
#endregion #endregion
/// <summary> /// <summary>
@ -210,10 +221,12 @@ public class FoodAnimeEditWindowVM
AddFrontImageCommand.ExecuteEvent += AddFrontImageCommand_ExecuteEvent; AddFrontImageCommand.ExecuteEvent += AddFrontImageCommand_ExecuteEvent;
RemoveFrontImageCommand.ExecuteEvent += RemoveFrontImageCommand_ExecuteEvent; RemoveFrontImageCommand.ExecuteEvent += RemoveFrontImageCommand_ExecuteEvent;
ClearFrontImageCommand.ExecuteEvent += ClearFrontImageCommand_ExecuteEvent; ClearFrontImageCommand.ExecuteEvent += ClearFrontImageCommand_ExecuteEvent;
ChangeFrontImageCommand.ExecuteEvent += ChangeFrontImageCommand_ExecuteEvent;
AddBackImageCommand.ExecuteEvent += AddBackImageCommand_ExecuteEvent; AddBackImageCommand.ExecuteEvent += AddBackImageCommand_ExecuteEvent;
RemoveBackImageCommand.ExecuteEvent += RemoveBackImageCommand_ExecuteEvent; RemoveBackImageCommand.ExecuteEvent += RemoveBackImageCommand_ExecuteEvent;
ClearBackImageCommand.ExecuteEvent += ClearBackImageCommand_ExecuteEvent; ClearBackImageCommand.ExecuteEvent += ClearBackImageCommand_ExecuteEvent;
ChangeBackImageCommand.ExecuteEvent += ChangeBackImageCommand_ExecuteEvent;
AddeFoodLocationCommand.ExecuteEvent += AddeFoodLocationCommand_ExecuteEvent; AddeFoodLocationCommand.ExecuteEvent += AddeFoodLocationCommand_ExecuteEvent;
RemoveFoodLocationCommand.ExecuteEvent += RemoveFoodLocationCommand_ExecuteEvent; RemoveFoodLocationCommand.ExecuteEvent += RemoveFoodLocationCommand_ExecuteEvent;
@ -318,8 +331,8 @@ public class FoodAnimeEditWindowVM
/// <param name="value">动画模型</param> /// <param name="value">动画模型</param>
private void RemoveFrontImageCommand_ExecuteEvent(FoodAnimeModel value) private void RemoveFrontImageCommand_ExecuteEvent(FoodAnimeModel value)
{ {
value.FrontImages.Remove(CurrentFrontImageModel.Value);
CurrentFrontImageModel.Value.Close(); CurrentFrontImageModel.Value.Close();
value.FrontImages.Remove(CurrentFrontImageModel.Value);
} }
/// <summary> /// <summary>
@ -338,6 +351,33 @@ public class FoodAnimeEditWindowVM
} }
} }
/// <summary>
/// 替换顶层图片
/// </summary>
/// <param name="value"></param>
/// <exception cref="NotImplementedException"></exception>
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) private void ShowFrontImagesPathInfo(FoodImagesPath imagesPath)
{ {
MessageBox.Show( MessageBox.Show(
@ -375,8 +415,8 @@ public class FoodAnimeEditWindowVM
/// <param name="value">动画模型</param> /// <param name="value">动画模型</param>
private void RemoveBackImageCommand_ExecuteEvent(FoodAnimeModel value) private void RemoveBackImageCommand_ExecuteEvent(FoodAnimeModel value)
{ {
value.BackImages.Remove(CurrentBackImageModel.Value);
CurrentBackImageModel.Value.Close(); CurrentBackImageModel.Value.Close();
value.BackImages.Remove(CurrentBackImageModel.Value);
} }
/// <summary> /// <summary>
@ -394,6 +434,33 @@ public class FoodAnimeEditWindowVM
value.BackImages.Clear(); value.BackImages.Clear();
} }
} }
/// <summary>
/// 替换底层图片
/// </summary>
/// <param name="value"></param>
/// <exception cref="NotImplementedException"></exception>
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 #endregion
/// <summary> /// <summary>

View File

@ -84,11 +84,13 @@
ItemsSource="{Binding Images, IsAsync=True}" ItemsSource="{Binding Images, IsAsync=True}"
PreviewMouseMove="ListBox_PreviewMouseMove" PreviewMouseMove="ListBox_PreviewMouseMove"
PreviewMouseWheel="ListBox_PreviewMouseWheel" PreviewMouseWheel="ListBox_PreviewMouseWheel"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
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"> SelectionChanged="ListBox_SelectionChanged">
<ListBox.ItemsPanel> <ListBox.ItemsPanel>
<ItemsPanelTemplate> <ItemsPanelTemplate>
<WrapPanel /> <StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate> </ItemsPanelTemplate>
</ListBox.ItemsPanel> </ListBox.ItemsPanel>
<ListBox.ItemTemplate> <ListBox.ItemTemplate>

View File

@ -97,8 +97,8 @@ public partial class AnimeEditWindow : Window
if (listBoxItem == null || listBoxItem.Content != listBox.SelectedItem) if (listBoxItem == null || listBoxItem.Content != listBox.SelectedItem)
return; return;
var dataObj = new DataObject(listBoxItem.Content); var dataObj = new DataObject(listBoxItem.Content);
DragDrop.DoDragDrop(listBox, dataObj, DragDropEffects.Move);
_dropSender = sender; _dropSender = sender;
DragDrop.DoDragDrop(listBox, dataObj, DragDropEffects.Move);
} }
private void ListBox_Drop(object sender, DragEventArgs e) private void ListBox_Drop(object sender, DragEventArgs e)
@ -141,6 +141,7 @@ public partial class AnimeEditWindow : Window
return; return;
if (listBox.DataContext is AnimeModel model) if (listBox.DataContext is AnimeModel model)
ViewModel.CurrentAnimeModel.Value = model; ViewModel.CurrentAnimeModel.Value = model;
listBox.ScrollIntoView(listBox.SelectedItem);
e.Handled = true; e.Handled = true;
} }

View File

@ -53,185 +53,34 @@
<Expander.Header> <Expander.Header>
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="200" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<!--<TextBlock Margin="10,0,10,0"> <TextBlock Margin="10,0,10,0">
<TextBlock.Text> <TextBlock.Text>
<MultiBinding Converter="{StaticResource StringFormatConverter}" ConverterParameter="{}({0})"> <MultiBinding Converter="{StaticResource StringFormatConverter}" ConverterParameter="{}({0}, {1}, {2})">
<Binding Path="Images.Count" /> <Binding Path="FrontImages.Count" />
<Binding Path="BackImages.Count" />
<Binding Path="FoodLocations.Count" />
</MultiBinding> </MultiBinding>
</TextBlock.Text> </TextBlock.Text>
</TextBlock>--> </TextBlock>
<TextBox Grid.Column="1" Text="{Binding Id.Value, UpdateSourceTrigger=PropertyChanged}" /> <TextBox
Grid.Column="1"
pu:TextBoxHelper.Watermark="{ll:Str 动画Id(非必要)}"
Text="{Binding Id.Value, UpdateSourceTrigger=PropertyChanged}" />
<!-- pu:TextBoxHelper.Watermark="{ll:Str 动画Id(非必要)}" --> <!-- pu:TextBoxHelper.Watermark="{ll:Str 动画Id(非必要)}" -->
</Grid> </Grid>
</Expander.Header> </Expander.Header>
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.RowDefinitions>
<ColumnDefinition /> <RowDefinition Height="Auto" />
<ColumnDefinition Width="Auto" MinWidth="200" /> <RowDefinition Height="Auto" />
</Grid.ColumnDefinitions> <RowDefinition Height="Auto" />
<Grid> </Grid.RowDefinitions>
<Grid.RowDefinitions> <GroupBox>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<GroupBox>
<GroupBox.Header>
<StackPanel Orientation="Horizontal">
<Label d:Content="顶层图片" Content="{ll:Str 顶层图片}" />
<TextBlock Margin="10,0,0,0">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource StringFormatConverter}" ConverterParameter="{}({0})">
<Binding Path="FrontImages.Count" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</StackPanel>
</GroupBox.Header>
<ListBox
d:ItemsSource="{d:SampleData ItemCount=5}"
AllowDrop="True"
Drop="ListBox_Drop"
ItemsSource="{Binding FrontImages, IsAsync=True}"
PreviewMouseMove="ListBox_PreviewMouseMove"
SelectedItem="{Binding DataContext.CurrentFrontImageModel.Value, RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}}"
SelectionChanged="ListBox_SelectionChanged">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType=Expander, Mode=FindAncestor}}" Tag="{Binding DataContext, RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}}">
<Grid.ContextMenu>
<ContextMenu>
<MenuItem
d:Header="修改图片"
Command="{Binding PlacementTarget.Tag.ChangeImageCommand, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
CommandParameter="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
Header="{ll:Str 修改图片}"
IsEnabled="{Binding PlacementTarget.Tag.PlayCommand.CurrentCanExecute.Value, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}" />
<MenuItem
d:Header="删除图片"
Command="{Binding PlacementTarget.Tag.RemoveImageCommand, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
CommandParameter="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
Header="{ll:Str 删除图片}"
IsEnabled="{Binding PlacementTarget.Tag.PlayCommand.CurrentCanExecute.Value, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}" />
</ContextMenu>
</Grid.ContextMenu>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Image
Width="150"
Height="150"
d:DataContext=""
DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType=ListBoxItem, Mode=FindAncestor}}"
Source="{Binding Image.Value, IsAsync=True}">
<Image.ToolTip>
<Image
Width="250"
Height="250"
Source="{Binding Image.Value, IsAsync=True}" />
</Image.ToolTip>
</Image>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Label d:Content="持续时间(ms)" Content="{ll:Str 持续时间(ms)}" />
<pu:NumberInput Grid.Column="1" Value="{Binding DataContext.Duration.Value, RelativeSource={RelativeSource AncestorType=ListBoxItem, Mode=FindAncestor}}" />
</Grid>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</GroupBox>
<GroupBox Grid.Row="1">
<GroupBox.Header>
<StackPanel Orientation="Horizontal">
<Label d:Content="底层图片" Content="{ll:Str 底层图片}" />
<TextBlock Margin="10,0,0,0">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource StringFormatConverter}" ConverterParameter="{}({0})">
<Binding Path="BackImages.Count" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</StackPanel>
</GroupBox.Header>
<ListBox
d:ItemsSource="{d:SampleData ItemCount=5}"
AllowDrop="True"
Drop="ListBox_Drop"
ItemsSource="{Binding BackImages, IsAsync=True}"
PreviewMouseMove="ListBox_PreviewMouseMove"
SelectedItem="{Binding DataContext.CurrentBackImageModel.Value, RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}}"
SelectionChanged="ListBox_SelectionChanged">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType=Expander, Mode=FindAncestor}}" Tag="{Binding DataContext, RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}}">
<Grid.ContextMenu>
<ContextMenu>
<MenuItem
d:Header="修改图片"
Command="{Binding PlacementTarget.Tag.ChangeImageCommand, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
CommandParameter="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
Header="{ll:Str 修改图片}"
IsEnabled="{Binding PlacementTarget.Tag.PlayCommand.CurrentCanExecute.Value, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}" />
<MenuItem
d:Header="删除图片"
Command="{Binding PlacementTarget.Tag.RemoveImageCommand, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
CommandParameter="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
Header="{ll:Str 删除图片}" />
</ContextMenu>
</Grid.ContextMenu>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Image
Width="150"
Height="150"
d:DataContext=""
DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType=ListBoxItem, Mode=FindAncestor}}"
Source="{Binding Image.Value, IsAsync=True}">
<Image.ToolTip>
<Image
Width="250"
Height="250"
Source="{Binding Image.Value, IsAsync=True}" />
</Image.ToolTip>
</Image>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Label d:Content="持续时间(ms)" Content="{ll:Str 持续时间(ms)}" />
<pu:NumberInput Grid.Column="1" Value="{Binding DataContext.Duration.Value, RelativeSource={RelativeSource AncestorType=ListBoxItem, Mode=FindAncestor}}" />
</Grid>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</GroupBox>
</Grid>
<GroupBox Grid.Column="1">
<GroupBox.Header> <GroupBox.Header>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<Label d:Content="食物位置" Content="{ll:Str 食物位置}" /> <Label d:Content="顶层图片" Content="{ll:Str 顶层图片}" />
<TextBlock Margin="10,0,0,0"> <TextBlock Margin="10,0,0,0">
<TextBlock.Text> <TextBlock.Text>
<MultiBinding Converter="{StaticResource StringFormatConverter}" ConverterParameter="{}({0})"> <MultiBinding Converter="{StaticResource StringFormatConverter}" ConverterParameter="{}({0})">
@ -241,11 +90,172 @@
</TextBlock> </TextBlock>
</StackPanel> </StackPanel>
</GroupBox.Header> </GroupBox.Header>
<ListBox
d:ItemsSource="{d:SampleData ItemCount=5}"
AllowDrop="True"
Drop="ListBox_Drop"
ItemsSource="{Binding FrontImages, IsAsync=True}"
PreviewMouseMove="ListBox_PreviewMouseMove"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
SelectedItem="{Binding DataContext.CurrentFrontImageModel.Value, RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}}"
SelectionChanged="ListBox_SelectionChanged">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType=Expander, Mode=FindAncestor}}" Tag="{Binding DataContext, RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}}">
<Grid.ContextMenu>
<ContextMenu>
<MenuItem
d:Header="修改图片"
Command="{Binding PlacementTarget.Tag.ChangeFrontImageCommand, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
CommandParameter="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
Header="{ll:Str 修改图片}"
IsEnabled="{Binding PlacementTarget.Tag.PlayCommand.CurrentCanExecute.Value, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}" />
<MenuItem
d:Header="删除图片"
Command="{Binding PlacementTarget.Tag.RemoveFrontImageCommand, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
CommandParameter="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
Header="{ll:Str 删除图片}"
IsEnabled="{Binding PlacementTarget.Tag.PlayCommand.CurrentCanExecute.Value, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}" />
</ContextMenu>
</Grid.ContextMenu>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Image
Width="150"
Height="150"
d:DataContext=""
DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType=ListBoxItem, Mode=FindAncestor}}"
Source="{Binding Image.Value, IsAsync=True}">
<Image.ToolTip>
<Image
Width="250"
Height="250"
Source="{Binding Image.Value, IsAsync=True}" />
</Image.ToolTip>
</Image>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Label d:Content="持续时间(ms)" Content="{ll:Str 持续时间(ms)}" />
<pu:NumberInput Grid.Column="1" Value="{Binding DataContext.Duration.Value, RelativeSource={RelativeSource AncestorType=ListBoxItem, Mode=FindAncestor}}" />
</Grid>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</GroupBox>
<GroupBox Grid.Row="1">
<GroupBox.Header>
<StackPanel Orientation="Horizontal">
<Label d:Content="底层图片" Content="{ll:Str 底层图片}" />
<TextBlock Margin="10,0,0,0">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource StringFormatConverter}" ConverterParameter="{}({0})">
<Binding Path="BackImages.Count" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</StackPanel>
</GroupBox.Header>
<ListBox
d:ItemsSource="{d:SampleData ItemCount=5}"
AllowDrop="True"
Drop="ListBox_Drop"
ItemsSource="{Binding BackImages, IsAsync=True}"
PreviewMouseMove="ListBox_PreviewMouseMove"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
SelectedItem="{Binding DataContext.CurrentBackImageModel.Value, RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}}"
SelectionChanged="ListBox_SelectionChanged">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType=Expander, Mode=FindAncestor}}" Tag="{Binding DataContext, RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}}">
<Grid.ContextMenu>
<ContextMenu>
<MenuItem
d:Header="修改图片"
Command="{Binding PlacementTarget.Tag.ChangeBackImageCommand, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
CommandParameter="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
Header="{ll:Str 修改图片}"
IsEnabled="{Binding PlacementTarget.Tag.PlayCommand.CurrentCanExecute.Value, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}" />
<MenuItem
d:Header="删除图片"
Command="{Binding PlacementTarget.Tag.RemoveBackImageCommand, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
CommandParameter="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}"
Header="{ll:Str 删除图片}"
IsEnabled="{Binding PlacementTarget.Tag.PlayCommand.CurrentCanExecute.Value, RelativeSource={RelativeSource AncestorType=ContextMenu, Mode=FindAncestor}}" />
</ContextMenu>
</Grid.ContextMenu>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Image
Width="150"
Height="150"
d:DataContext=""
DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType=ListBoxItem, Mode=FindAncestor}}"
Source="{Binding Image.Value, IsAsync=True}">
<Image.ToolTip>
<Image
Width="250"
Height="250"
Source="{Binding Image.Value, IsAsync=True}" />
</Image.ToolTip>
</Image>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Label d:Content="持续时间(ms)" Content="{ll:Str 持续时间(ms)}" />
<pu:NumberInput Grid.Column="1" Value="{Binding DataContext.Duration.Value, RelativeSource={RelativeSource AncestorType=ListBoxItem, Mode=FindAncestor}}" />
</Grid>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</GroupBox>
<GroupBox Grid.Row="2">
<GroupBox.Header>
<StackPanel Orientation="Horizontal">
<Label d:Content="食物位置" Content="{ll:Str 食物位置}" />
<TextBlock Margin="10,0,0,0">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource StringFormatConverter}" ConverterParameter="{}({0})">
<Binding Path="FoodLocations.Count" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</StackPanel>
</GroupBox.Header>
<ListBox <ListBox
d:ItemsSource="{d:SampleData ItemCount=5}" d:ItemsSource="{d:SampleData ItemCount=5}"
ItemsSource="{Binding FoodLocations, IsAsync=True}" ItemsSource="{Binding FoodLocations, IsAsync=True}"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
SelectedItem="{Binding DataContext.CurrentFoodLocationModel.Value, RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}}" SelectedItem="{Binding DataContext.CurrentFoodLocationModel.Value, RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}}"
SelectionChanged="ListBox_SelectionChanged"> SelectionChanged="ListBox_SelectionChanged">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<Grid> <Grid>

View File

@ -1,5 +1,6 @@
using LinePutScript.Localization.WPF; using LinePutScript.Localization.WPF;
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -12,6 +13,7 @@ using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Shapes; using System.Windows.Shapes;
using VPet.ModMaker.Models;
using VPet.ModMaker.Models.ModModel; using VPet.ModMaker.Models.ModModel;
using VPet.ModMaker.ViewModels.ModEdit.AnimeEdit; using VPet.ModMaker.ViewModels.ModEdit.AnimeEdit;
using VPet_Simulator.Core; using VPet_Simulator.Core;
@ -88,54 +90,69 @@ public partial class FoodAnimeEditWindow : Window
private void ListBox_PreviewMouseMove(object sender, MouseEventArgs e) private void ListBox_PreviewMouseMove(object sender, MouseEventArgs e)
{ {
//if (sender is not ListBox listBox) if (sender is not ListBox listBox)
// return; return;
//if (e.LeftButton != MouseButtonState.Pressed) if (e.LeftButton != MouseButtonState.Pressed)
// return; return;
//var pos = e.GetPosition(listBox); var pos = e.GetPosition(listBox);
//HitTestResult result = VisualTreeHelper.HitTest(listBox, pos); HitTestResult result = VisualTreeHelper.HitTest(listBox, pos);
//if (result is null) if (result is null)
// return; return;
//var listBoxItem = FindVisualParent<ListBoxItem>(result.VisualHit); var listBoxItem = result.VisualHit.FindParent<ListBoxItem>();
//if (listBoxItem == null || listBoxItem.Content != listBox.SelectedItem) if (listBoxItem == null || listBoxItem.Content != listBox.SelectedItem)
// return; return;
//var dataObj = new DataObject(listBoxItem.Content); var dataObj = new DataObject(listBoxItem.Content);
//DragDrop.DoDragDrop(listBox, dataObj, DragDropEffects.Move); _dropSender = sender;
//_dropSender = sender; DragDrop.DoDragDrop(listBox, dataObj, DragDropEffects.Move);
} }
private void ListBox_Drop(object sender, DragEventArgs e) private void ListBox_Drop(object sender, DragEventArgs e)
{ {
//if (sender is not ListBox listBox) if (sender is not ListBox listBox)
// return; return;
//if (e.Data.GetData(DataFormats.FileDrop) is Array array) if (e.Data.GetData(DataFormats.FileDrop) is Array array)
// ViewModel.AddImages(((AnimeModel)listBox.DataContext, array.Cast<string>()); {
//if (_dropSender is not null && sender.Equals(_dropSender) is false) if (listBox.Name == "ListBox_FrontImages")
//{ {
// MessageBox.Show("无法移动不同动画的图片".Translate()); ViewModel.AddImages(
// return; ((FoodAnimeModel)listBox.DataContext).FrontImages,
//} array.Cast<string>()
//var pos = e.GetPosition(listBox); );
//var result = VisualTreeHelper.HitTest(listBox, pos); }
//if (result == null) else if (listBox.Name == "ListBox_BackImages")
// return; {
////查找元数据 ViewModel.AddImages(
//if (e.Data.GetData(typeof(ImageModel)) is not ImageModel sourcePerson) ((FoodAnimeModel)listBox.DataContext).BackImages,
// return; array.Cast<string>()
////查找目标数据 );
//var listBoxItem = FindVisualParent<ListBoxItem>(result.VisualHit); }
//if (listBoxItem == null) }
// return; if (_dropSender is not null && sender.Equals(_dropSender) is false)
//var targetPerson = listBoxItem.Content as ImageModel; {
//if (ReferenceEquals(targetPerson, sourcePerson)) MessageBox.Show("无法移动不同动画的图片".Translate());
// return; return;
//if (listBox.ItemsSource is not IList<ImageModel> list) }
// return; var pos = e.GetPosition(listBox);
//var sourceIndex = list.IndexOf(sourcePerson); var result = VisualTreeHelper.HitTest(listBox, pos);
//var targetIndex = list.IndexOf(targetPerson); if (result == null)
//var temp = list[sourceIndex]; return;
//list[sourceIndex] = list[targetIndex]; //查找元数据
//list[targetIndex] = temp; if (e.Data.GetData(typeof(ImageModel)) is not ImageModel sourcePerson)
return;
//查找目标数据
var listBoxItem = result.VisualHit.FindParent<ListBoxItem>();
if (listBoxItem == null)
return;
var targetPerson = listBoxItem.Content as ImageModel;
if (ReferenceEquals(targetPerson, sourcePerson))
return;
if (listBox.ItemsSource is not IList<ImageModel> 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) private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
@ -144,6 +161,7 @@ public partial class FoodAnimeEditWindow : Window
return; return;
if (listBox.DataContext is FoodAnimeModel model) if (listBox.DataContext is FoodAnimeModel model)
ViewModel.CurrentAnimeModel.Value = model; ViewModel.CurrentAnimeModel.Value = model;
listBox.ScrollIntoView(listBox.SelectedItem);
e.Handled = true; e.Handled = true;
} }