mirror of
https://github.com/LorisYounger/VPet.ModMaker.git
synced 2024-08-30 18:22:21 +00:00
初始化AnimeEdit
This commit is contained in:
parent
164a129e6a
commit
d4349147d6
@ -40,4 +40,43 @@ public static class Extensions
|
||||
dictionary.Add(key, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 流内容对比
|
||||
/// </summary>
|
||||
/// <param name="source">原始流</param>
|
||||
/// <param name="target">目标流</param>
|
||||
/// <param name="bufferLength">缓冲区大小 (越大速度越快(流内容越大效果越明显), 但会提高内存占用 (bufferSize = bufferLength * sizeof(long) * 2))</param>
|
||||
/// <returns>内容相同为 <see langword="true"/> 否则为 <see langword="false"/></returns>
|
||||
public static bool ContentsEqual(this Stream source, Stream target, int bufferLength = 8)
|
||||
{
|
||||
int bufferSize = bufferLength * sizeof(long);
|
||||
var sourceBuffer = new byte[bufferSize];
|
||||
var targetBuffer = new byte[bufferSize];
|
||||
while (true)
|
||||
{
|
||||
int sourceCount = ReadFullBuffer(source, sourceBuffer);
|
||||
int targetCount = ReadFullBuffer(target, targetBuffer);
|
||||
if (sourceCount != targetCount)
|
||||
return false;
|
||||
if (sourceCount == 0)
|
||||
return true;
|
||||
|
||||
for (int i = 0; i < sourceCount; i += sizeof(long))
|
||||
if (BitConverter.ToInt64(sourceBuffer, i) != BitConverter.ToInt64(targetBuffer, i))
|
||||
return false;
|
||||
}
|
||||
static int ReadFullBuffer(Stream stream, byte[] buffer)
|
||||
{
|
||||
int bytesRead = 0;
|
||||
while (bytesRead < buffer.Length)
|
||||
{
|
||||
int read = stream.Read(buffer, bytesRead, buffer.Length - bytesRead);
|
||||
if (read == 0)
|
||||
return bytesRead;
|
||||
bytesRead += read;
|
||||
}
|
||||
return bytesRead;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
16
VPet.ModMaker/Models/ModModel/AnimeModel.cs
Normal file
16
VPet.ModMaker/Models/ModModel/AnimeModel.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using HKW.HKWViewModels.SimpleObservable;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace VPet.ModMaker.Models.ModModel;
|
||||
|
||||
public class AnimeModel
|
||||
{
|
||||
public ObservableValue<ImageModel> CurrentImageModel { get; } = new();
|
||||
public ObservableCollection<ImageModel> ImageModels { get; } = new();
|
||||
}
|
21
VPet.ModMaker/Models/ModModel/ImageModel.cs
Normal file
21
VPet.ModMaker/Models/ModModel/ImageModel.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using HKW.HKWViewModels.SimpleObservable;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace VPet.ModMaker.Models.ModModel;
|
||||
|
||||
public class ImageModel
|
||||
{
|
||||
public ObservableValue<BitmapImage> Image { get; } = new();
|
||||
|
||||
public ObservableValue<int> Duration { get; } = new(100);
|
||||
|
||||
public ImageModel(BitmapImage image)
|
||||
{
|
||||
Image.Value = image;
|
||||
}
|
||||
}
|
@ -98,11 +98,13 @@
|
||||
<Compile Include="Converters\MaxConverter.cs" />
|
||||
<Compile Include="Converters\MarginConverter.cs" />
|
||||
<Compile Include="Models\EnumFlagsVM.cs" />
|
||||
<Compile Include="Models\ModModel\AnimeModel.cs" />
|
||||
<Compile Include="Models\ModModel\ClickTextModel.cs" />
|
||||
<Compile Include="Models\Expansions.cs" />
|
||||
<Compile Include="Models\ModModel\FoodModel.cs" />
|
||||
<Compile Include="Models\I18nHelper.cs" />
|
||||
<Compile Include="Models\I18nModel.cs" />
|
||||
<Compile Include="Models\ModModel\ImageModel.cs" />
|
||||
<Compile Include="Models\ModModel\LowTextModel.cs" />
|
||||
<Compile Include="Models\ModLoader.cs" />
|
||||
<Compile Include="Models\ModMakerHistory.cs" />
|
||||
@ -114,6 +116,7 @@
|
||||
<Compile Include="Models\ModModel\WorkModel.cs" />
|
||||
<Compile Include="SimpleObservable\ObservableCommandT.cs" />
|
||||
<Compile Include="Styles.cs" />
|
||||
<Compile Include="ViewModels\ModEdit\AnimeEdit\AnimeEditWindowVM.cs" />
|
||||
<Compile Include="ViewModels\ModEdit\ClickTextEdit\ClickTextEditWindowVM.cs" />
|
||||
<Compile Include="ViewModels\ModEdit\ClickTextEdit\ClickTextPageVM.cs" />
|
||||
<Compile Include="ViewModels\ModEdit\FoodEdit\FoodPageVM.cs" />
|
||||
@ -129,6 +132,9 @@
|
||||
<Compile Include="ViewModels\ModEdit\SelectTextEdit\SelectTextPageVM.cs" />
|
||||
<Compile Include="ViewModels\ModEdit\WorkEdit\WorkEditWindowVM.cs" />
|
||||
<Compile Include="ViewModels\ModEdit\WorkEdit\WorkPageVM.cs" />
|
||||
<Compile Include="Views\ModEdit\AnimeEdit\AnimeEditWindow.xaml.cs">
|
||||
<DependentUpon>AnimeEditWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\ModEdit\ClickTextEdit\ClickTextPage.xaml.cs">
|
||||
<DependentUpon>ClickTextPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
@ -227,6 +233,10 @@
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\ModEdit\AnimeEdit\AnimeEditWindow.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\ModEdit\ClickTextEdit\ClickTextPage.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
@ -0,0 +1,61 @@
|
||||
using HKW.HKWViewModels.SimpleObservable;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VPet.ModMaker.Models;
|
||||
using VPet.ModMaker.Models.ModModel;
|
||||
|
||||
namespace VPet.ModMaker.ViewModels.ModEdit.AnimeEdit;
|
||||
|
||||
public class AnimeEditWindowVM
|
||||
{
|
||||
public AnimeModel OldAnime { get; set; }
|
||||
public ObservableValue<AnimeModel> Anime { get; } = new(new());
|
||||
#region Command
|
||||
public ObservableCommand PlayCommand { get; } = new();
|
||||
public ObservableCommand PauseCommand { get; } = new();
|
||||
#endregion
|
||||
|
||||
public bool _pause = false;
|
||||
public Task _playerTask;
|
||||
|
||||
public AnimeEditWindowVM()
|
||||
{
|
||||
foreach (
|
||||
var file in Directory.EnumerateFiles(
|
||||
@"C:\Users\HKW\Desktop\TestPicture\0000_core\pet\vup\Default\Happy\1"
|
||||
)
|
||||
)
|
||||
{
|
||||
Anime.Value.ImageModels.Add(new(Utils.LoadImageToMemoryStream(file)));
|
||||
}
|
||||
_playerTask = new(Play);
|
||||
PlayCommand.ExecuteEvent += PlayCommand_ExecuteEvent;
|
||||
PauseCommand.ExecuteEvent += PauseCommand_ExecuteEvent;
|
||||
}
|
||||
|
||||
private void PauseCommand_ExecuteEvent()
|
||||
{
|
||||
_pause = true;
|
||||
}
|
||||
|
||||
private void PlayCommand_ExecuteEvent()
|
||||
{
|
||||
_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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
128
VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml
Normal file
128
VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml
Normal file
@ -0,0 +1,128 @@
|
||||
<Window
|
||||
x:Class="VPet.ModMaker.Views.ModEdit.AnimeEdit.AnimeEditWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:ll="clr-namespace:LinePutScript.Localization.WPF;assembly=LinePutScript.Localization.WPF"
|
||||
xmlns:local="clr-namespace:VPet.ModMaker.Views.ModEdit.AnimeEdit"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:pu="https://opensource.panuon.com/wpf-ui"
|
||||
xmlns:vm="clr-namespace:VPet.ModMaker.ViewModels.ModEdit.AnimeEdit"
|
||||
Title="AnimeEditWindow"
|
||||
Width="800"
|
||||
Height="450"
|
||||
mc:Ignorable="d">
|
||||
<d:Window.DataContext>
|
||||
<vm:AnimeEditWindowVM />
|
||||
</d:Window.DataContext>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<Image
|
||||
Width="250"
|
||||
Height="250"
|
||||
Source="{Binding Anime.Value.CurrentImageModel.Value.Image.Value}" />
|
||||
<Grid Grid.Row="1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Button Command="{Binding PauseCommand}" Content="{ll:Str 停止}" />
|
||||
<Button
|
||||
Grid.Column="1"
|
||||
Command="{Binding PlayCommand}"
|
||||
Content="{ll:Str 播放}" />
|
||||
<ToggleButton Grid.Column="2" Content="{ll:Str 循环}" />
|
||||
</Grid>
|
||||
<Grid Grid.Row="2">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Label Content="{ll:Str 动画Id}" />
|
||||
<TextBox Grid.Column="1" />
|
||||
<Label Grid.Row="1" Content="{ll:Str 动画类型}" />
|
||||
<ComboBox Grid.Row="1" Grid.Column="1" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid Grid.Column="1">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<ListBox
|
||||
x:Name="ListBox_Images"
|
||||
d:ItemsSource="{d:SampleData ItemCount=5}"
|
||||
d:SelectedIndex="0"
|
||||
ItemsSource="{Binding Anime.Value.ImageModels}"
|
||||
SelectedItem="{Binding Anime.Value.CurrentImageModel.Value}">
|
||||
<ListBox.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<WrapPanel />
|
||||
</ItemsPanelTemplate>
|
||||
</ListBox.ItemsPanel>
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid Width="150" Height="200">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<Image
|
||||
Width="150"
|
||||
Height="150"
|
||||
Source="{Binding Image.Value}">
|
||||
<Image.ToolTip>
|
||||
<Image
|
||||
Width="250"
|
||||
Height="250"
|
||||
Source="{Binding Image.Value}" />
|
||||
</Image.ToolTip>
|
||||
</Image>
|
||||
<Grid Grid.Row="1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Content="持续时间" />
|
||||
<pu:NumberInput Grid.Column="1" Value="{Binding Duration.Value}" />
|
||||
</Grid>
|
||||
<TextBox Grid.Row="2" Text="ImageName" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<Grid Grid.Row="1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Button
|
||||
x:Name="Button_Cancel"
|
||||
Margin="10"
|
||||
Click="Button_Cancel_Click"
|
||||
Content="{ll:Str 取消}" />
|
||||
<Button
|
||||
x:Name="Button_Yes"
|
||||
Grid.Column="1"
|
||||
Margin="10"
|
||||
Click="Button_Yes_Click"
|
||||
Content="{ll:Str 确定}" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Window>
|
@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
using VPet.ModMaker.ViewModels.ModEdit.AnimeEdit;
|
||||
|
||||
namespace VPet.ModMaker.Views.ModEdit.AnimeEdit;
|
||||
|
||||
/// <summary>
|
||||
/// AnimeEditWindow.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class AnimeEditWindow : Window
|
||||
{
|
||||
public AnimeEditWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = new AnimeEditWindowVM();
|
||||
}
|
||||
|
||||
public AnimeEditWindowVM ViewModel => (AnimeEditWindowVM)DataContext;
|
||||
|
||||
public bool IsCancel { get; private set; } = true;
|
||||
|
||||
private void Button_Cancel_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private void Button_Yes_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
//if (string.IsNullOrEmpty(ViewModel.Work.Value.Id.Value))
|
||||
//{
|
||||
// MessageBox.Show("Id不可为空".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
// return;
|
||||
//}
|
||||
//if (string.IsNullOrEmpty(ViewModel.Work.Value.Graph.Value))
|
||||
//{
|
||||
// MessageBox.Show(
|
||||
// "指定动画Id不可为空".Translate(),
|
||||
// "",
|
||||
// MessageBoxButton.OK,
|
||||
// MessageBoxImage.Warning
|
||||
// );
|
||||
// return;
|
||||
//}
|
||||
//if (
|
||||
// ViewModel.OldWork?.Id.Value != ViewModel.Work.Value.Id.Value
|
||||
// && ViewModel.CurrentPet.Works.Any(i => i.Id.Value == ViewModel.Work.Value.Id.Value)
|
||||
//)
|
||||
//{
|
||||
// MessageBox.Show("此Id已存在".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
// return;
|
||||
//}
|
||||
IsCancel = false;
|
||||
Close();
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@ using System.Windows.Shapes;
|
||||
using VPet.ModMaker.Models;
|
||||
using VPet.ModMaker.ViewModels;
|
||||
using VPet.ModMaker.Views.ModEdit;
|
||||
using VPet.ModMaker.Views.ModEdit.AnimeEdit;
|
||||
using VPet.ModMaker.Views.ModEdit.PetEdit;
|
||||
|
||||
namespace VPet.ModMaker.Views;
|
||||
@ -35,6 +36,7 @@ public partial class ModMakerWindow : Window
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = new ModMakerWindowVM(this);
|
||||
new AnimeEditWindow().Show();
|
||||
}
|
||||
|
||||
private void ListBoxItem_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
||||
|
Loading…
x
Reference in New Issue
Block a user