mirror of
https://github.com/LorisYounger/VPet.ModMaker.git
synced 2024-08-30 18:22:21 +00:00
实装 多语言编辑窗口
This commit is contained in:
parent
7e94da39c4
commit
b163719b69
16
VPet.ModMaker/Models/I18nData.cs
Normal file
16
VPet.ModMaker/Models/I18nData.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;
|
||||||
|
|
||||||
|
namespace VPet.ModMaker.Models;
|
||||||
|
|
||||||
|
public class I18nData
|
||||||
|
{
|
||||||
|
public ObservableValue<string> Id { get; } = new();
|
||||||
|
public ObservableCollection<string> Cultures { get; } = new();
|
||||||
|
public ObservableCollection<ObservableValue<string>> Datas { get; } = new();
|
||||||
|
}
|
@ -40,6 +40,7 @@
|
|||||||
BasedOn="{StaticResource {x:Type TextBlock}}"
|
BasedOn="{StaticResource {x:Type TextBlock}}"
|
||||||
TargetType="TextBlock">
|
TargetType="TextBlock">
|
||||||
<Setter Property="TextWrapping" Value="Wrap" />
|
<Setter Property="TextWrapping" Value="Wrap" />
|
||||||
|
<Setter Property="ToolTip" Value="{Binding Text, RelativeSource={RelativeSource Mode=Self}}" />
|
||||||
</Style>
|
</Style>
|
||||||
<Style
|
<Style
|
||||||
x:Key="TextBlock_Center"
|
x:Key="TextBlock_Center"
|
||||||
@ -47,6 +48,7 @@
|
|||||||
TargetType="TextBlock">
|
TargetType="TextBlock">
|
||||||
<Setter Property="VerticalAlignment" Value="Center" />
|
<Setter Property="VerticalAlignment" Value="Center" />
|
||||||
<Setter Property="HorizontalAlignment" Value="Center" />
|
<Setter Property="HorizontalAlignment" Value="Center" />
|
||||||
|
<Setter Property="ToolTip" Value="{Binding Text, RelativeSource={RelativeSource Mode=Self}}" />
|
||||||
</Style>
|
</Style>
|
||||||
<Style
|
<Style
|
||||||
x:Key="TextBlock_LeftCenter"
|
x:Key="TextBlock_LeftCenter"
|
||||||
@ -54,6 +56,7 @@
|
|||||||
TargetType="TextBlock">
|
TargetType="TextBlock">
|
||||||
<Setter Property="VerticalAlignment" Value="Center" />
|
<Setter Property="VerticalAlignment" Value="Center" />
|
||||||
<Setter Property="HorizontalAlignment" Value="Left" />
|
<Setter Property="HorizontalAlignment" Value="Left" />
|
||||||
|
<Setter Property="ToolTip" Value="{Binding Text, RelativeSource={RelativeSource Mode=Self}}" />
|
||||||
</Style>
|
</Style>
|
||||||
<Style
|
<Style
|
||||||
x:Key="TextBox_Wrap"
|
x:Key="TextBox_Wrap"
|
||||||
@ -62,6 +65,7 @@
|
|||||||
<Setter Property="TextWrapping" Value="Wrap" />
|
<Setter Property="TextWrapping" Value="Wrap" />
|
||||||
<Setter Property="HorizontalContentAlignment" Value="Left" />
|
<Setter Property="HorizontalContentAlignment" Value="Left" />
|
||||||
<Setter Property="VerticalContentAlignment" Value="Top" />
|
<Setter Property="VerticalContentAlignment" Value="Top" />
|
||||||
|
<Setter Property="ToolTip" Value="{Binding Text, RelativeSource={RelativeSource Mode=Self}}" />
|
||||||
</Style>
|
</Style>
|
||||||
<Style
|
<Style
|
||||||
x:Key="TextBox_Center"
|
x:Key="TextBox_Center"
|
||||||
@ -69,6 +73,7 @@
|
|||||||
TargetType="TextBox">
|
TargetType="TextBox">
|
||||||
<Setter Property="VerticalAlignment" Value="Center" />
|
<Setter Property="VerticalAlignment" Value="Center" />
|
||||||
<Setter Property="HorizontalAlignment" Value="Center" />
|
<Setter Property="HorizontalAlignment" Value="Center" />
|
||||||
|
<Setter Property="ToolTip" Value="{Binding Text, RelativeSource={RelativeSource Mode=Self}}" />
|
||||||
</Style>
|
</Style>
|
||||||
<Style
|
<Style
|
||||||
x:Key="TextBox_LeftCenter"
|
x:Key="TextBox_LeftCenter"
|
||||||
@ -76,6 +81,7 @@
|
|||||||
TargetType="TextBox">
|
TargetType="TextBox">
|
||||||
<Setter Property="VerticalAlignment" Value="Center" />
|
<Setter Property="VerticalAlignment" Value="Center" />
|
||||||
<Setter Property="HorizontalAlignment" Value="Left" />
|
<Setter Property="HorizontalAlignment" Value="Left" />
|
||||||
|
<Setter Property="ToolTip" Value="{Binding Text, RelativeSource={RelativeSource Mode=Self}}" />
|
||||||
</Style>
|
</Style>
|
||||||
<Style x:Key="WindowXStyle" TargetType="pu:WindowX">
|
<Style x:Key="WindowXStyle" TargetType="pu:WindowX">
|
||||||
<Setter Property="pu:WindowXCaption.Background" Value="{DynamicResource DARKPrimary}" />
|
<Setter Property="pu:WindowXCaption.Background" Value="{DynamicResource DARKPrimary}" />
|
||||||
|
@ -103,6 +103,7 @@
|
|||||||
<Compile Include="Converters\MaxConverter.cs" />
|
<Compile Include="Converters\MaxConverter.cs" />
|
||||||
<Compile Include="Converters\MarginConverter.cs" />
|
<Compile Include="Converters\MarginConverter.cs" />
|
||||||
<Compile Include="Models\EnumFlagsVM.cs" />
|
<Compile Include="Models\EnumFlagsVM.cs" />
|
||||||
|
<Compile Include="Models\I18nData.cs" />
|
||||||
<Compile Include="Models\ModModel\AnimeModel.cs" />
|
<Compile Include="Models\ModModel\AnimeModel.cs" />
|
||||||
<Compile Include="Models\ModModel\AnimeTypeModel.cs" />
|
<Compile Include="Models\ModModel\AnimeTypeModel.cs" />
|
||||||
<Compile Include="Models\ModModel\ClickTextModel.cs" />
|
<Compile Include="Models\ModModel\ClickTextModel.cs" />
|
||||||
|
@ -90,9 +90,14 @@ public class ModEditWindowVM
|
|||||||
|
|
||||||
private void EditI18n()
|
private void EditI18n()
|
||||||
{
|
{
|
||||||
var window = new I18nEditWindow();
|
if (I18nEditWindow.Instance is not null)
|
||||||
foreach (var culture in I18nHelper.Current.CultureNames)
|
{
|
||||||
window.AddCulture(culture);
|
I18nEditWindow.Instance.Activate();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var window = new I18nEditWindow(ModInfo.Value);
|
||||||
|
//foreach (var culture in I18nHelper.Current.CultureNames)
|
||||||
|
// window.AddCulture(culture);
|
||||||
//if (window.IsCancel)
|
//if (window.IsCancel)
|
||||||
// return;
|
// return;
|
||||||
//I18nHelper.Current.CultureNames.Add(window.ViewModel.Culture.Value);
|
//I18nHelper.Current.CultureNames.Add(window.ViewModel.Culture.Value);
|
||||||
|
@ -14,9 +14,6 @@
|
|||||||
d:DataContext="{d:DesignInstance Type=vm:FoodEditWindowVM}"
|
d:DataContext="{d:DesignInstance Type=vm:FoodEditWindowVM}"
|
||||||
WindowStartupLocation="CenterScreen"
|
WindowStartupLocation="CenterScreen"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
<Window.Resources>
|
|
||||||
<ResourceDictionary Source="/VPet-Simulator.Windows.Interface;component/ResourceStyle.xaml" />
|
|
||||||
</Window.Resources>
|
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="250" />
|
<ColumnDefinition Width="250" />
|
||||||
|
@ -12,20 +12,38 @@
|
|||||||
Width="800"
|
Width="800"
|
||||||
Height="450"
|
Height="450"
|
||||||
d:DataContext="{d:DesignInstance Type=vm:I18nEditWindowVM}"
|
d:DataContext="{d:DesignInstance Type=vm:I18nEditWindowVM}"
|
||||||
|
WindowStartupLocation="CenterScreen"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
|
<Window.Resources />
|
||||||
<Grid>
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<TextBox
|
||||||
|
pu:TextBoxHelper.Watermark="{ll:Str 搜索Id}"
|
||||||
|
Style="{DynamicResource StandardTextBoxStyle}"
|
||||||
|
Text="{Binding Search.Value, UpdateSourceTrigger=PropertyChanged}" />
|
||||||
<DataGrid
|
<DataGrid
|
||||||
x:Name="DataGrid_Datas"
|
x:Name="DataGrid_Datas"
|
||||||
|
Grid.Row="1"
|
||||||
d:ItemsSource="{d:SampleData ItemCount=5}"
|
d:ItemsSource="{d:SampleData ItemCount=5}"
|
||||||
|
AutoGenerateColumns="False"
|
||||||
CanUserAddRows="False"
|
CanUserAddRows="False"
|
||||||
|
CanUserDeleteRows="False"
|
||||||
CanUserReorderColumns="False"
|
CanUserReorderColumns="False"
|
||||||
|
ItemsSource="{Binding ShowI18nDatas.Value}"
|
||||||
ScrollViewer.IsDeferredScrollingEnabled="True"
|
ScrollViewer.IsDeferredScrollingEnabled="True"
|
||||||
VirtualizingStackPanel.VirtualizationMode="Recycling">
|
VirtualizingStackPanel.VirtualizationMode="Recycling">
|
||||||
<DataGrid.Columns>
|
<DataGrid.Columns>
|
||||||
<DataGridTextColumn
|
<DataGridTextColumn
|
||||||
Binding="{Binding Id}"
|
MaxWidth="300"
|
||||||
|
Binding="{Binding Id.Value}"
|
||||||
|
CanUserSort="True"
|
||||||
|
ElementStyle="{StaticResource TextBlock_Wrap}"
|
||||||
Header="Id"
|
Header="Id"
|
||||||
IsReadOnly="True" />
|
IsReadOnly="True"
|
||||||
|
SortMemberPath="Id.Value" />
|
||||||
</DataGrid.Columns>
|
</DataGrid.Columns>
|
||||||
</DataGrid>
|
</DataGrid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
@ -1,20 +1,13 @@
|
|||||||
using Panuon.WPF.UI;
|
using HKW.HKWViewModels.SimpleObservable;
|
||||||
|
using Panuon.WPF.UI;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Data;
|
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.Models;
|
using VPet.ModMaker.Models;
|
||||||
using VPet.ModMaker.ViewModels.ModEdit.I18nEdit;
|
|
||||||
|
|
||||||
namespace VPet.ModMaker.Views.ModEdit.I18nEdit;
|
namespace VPet.ModMaker.Views.ModEdit.I18nEdit;
|
||||||
|
|
||||||
@ -24,12 +17,35 @@ namespace VPet.ModMaker.Views.ModEdit.I18nEdit;
|
|||||||
public partial class I18nEditWindow : WindowX
|
public partial class I18nEditWindow : WindowX
|
||||||
{
|
{
|
||||||
public bool IsCancel { get; private set; } = true;
|
public bool IsCancel { get; private set; } = true;
|
||||||
public I18nEditWindowVM ViewModel => (I18nEditWindowVM)DataContext;
|
|
||||||
|
|
||||||
public I18nEditWindow()
|
public static I18nEditWindow Instance { get; private set; }
|
||||||
|
|
||||||
|
public ObservableValue<string> Search { get; } = new();
|
||||||
|
|
||||||
|
private void Search_ValueChanged(string oldValue, string newValue)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(newValue))
|
||||||
|
{
|
||||||
|
ShowI18nDatas.Value = I18nDatas;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ShowI18nDatas.Value = new(
|
||||||
|
I18nDatas.Where(
|
||||||
|
m => m.Id.Value.Contains(newValue, StringComparison.OrdinalIgnoreCase)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//public I18nEditWindowVM ViewModel => (I18nEditWindowVM)DataContext;
|
||||||
|
|
||||||
|
public I18nEditWindow(ModInfoModel model)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
DataContext = new I18nEditWindowVM();
|
DataContext = this;
|
||||||
|
Instance = this;
|
||||||
|
Search.ValueChanged += Search_ValueChanged;
|
||||||
Closed += (s, e) =>
|
Closed += (s, e) =>
|
||||||
{
|
{
|
||||||
//if (IsCancel)
|
//if (IsCancel)
|
||||||
@ -37,13 +53,128 @@ public partial class I18nEditWindow : WindowX
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
DataContext = null;
|
DataContext = null;
|
||||||
|
Instance = null;
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
};
|
};
|
||||||
|
InitializeI18nData(model);
|
||||||
|
ShowI18nDatas.Value = I18nDatas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InitializeI18nData(ModInfoModel model)
|
||||||
|
{
|
||||||
|
foreach (var culture in I18nHelper.Current.CultureNames)
|
||||||
|
{
|
||||||
|
AddCulture(culture);
|
||||||
|
}
|
||||||
|
LoadFood(model);
|
||||||
|
LoadClickText(model);
|
||||||
|
LoadLowText(model);
|
||||||
|
LoadSelectText(model);
|
||||||
|
LoadPets(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadFood(ModInfoModel model)
|
||||||
|
{
|
||||||
|
foreach (var food in model.Foods)
|
||||||
|
{
|
||||||
|
var nameData = new I18nData();
|
||||||
|
var descriptionData = new I18nData();
|
||||||
|
nameData.Id.Value = food.Id.Value;
|
||||||
|
descriptionData.Id.Value = food.DescriptionId.Value;
|
||||||
|
foreach (var culture in I18nHelper.Current.CultureNames)
|
||||||
|
{
|
||||||
|
nameData.Cultures.Add(culture);
|
||||||
|
nameData.Datas.Add(food.I18nDatas[culture].Name);
|
||||||
|
descriptionData.Cultures.Add(culture);
|
||||||
|
descriptionData.Datas.Add(food.I18nDatas[culture].Description);
|
||||||
|
}
|
||||||
|
I18nDatas.Add(nameData);
|
||||||
|
I18nDatas.Add(descriptionData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadClickText(ModInfoModel model)
|
||||||
|
{
|
||||||
|
foreach (var text in model.ClickTexts)
|
||||||
|
{
|
||||||
|
var data = new I18nData();
|
||||||
|
data.Id.Value = text.Id.Value;
|
||||||
|
foreach (var culture in I18nHelper.Current.CultureNames)
|
||||||
|
{
|
||||||
|
data.Cultures.Add(culture);
|
||||||
|
data.Datas.Add(text.I18nDatas[culture].Text);
|
||||||
|
}
|
||||||
|
I18nDatas.Add(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadLowText(ModInfoModel model)
|
||||||
|
{
|
||||||
|
foreach (var text in model.LowTexts)
|
||||||
|
{
|
||||||
|
var data = new I18nData();
|
||||||
|
data.Id.Value = text.Id.Value;
|
||||||
|
foreach (var culture in I18nHelper.Current.CultureNames)
|
||||||
|
{
|
||||||
|
data.Cultures.Add(culture);
|
||||||
|
data.Datas.Add(text.I18nDatas[culture].Text);
|
||||||
|
}
|
||||||
|
I18nDatas.Add(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadSelectText(ModInfoModel model)
|
||||||
|
{
|
||||||
|
foreach (var text in model.SelectTexts)
|
||||||
|
{
|
||||||
|
var data = new I18nData();
|
||||||
|
var chooseData = new I18nData();
|
||||||
|
data.Id.Value = text.Id.Value;
|
||||||
|
chooseData.Id.Value = text.ChooseId.Value;
|
||||||
|
foreach (var culture in I18nHelper.Current.CultureNames)
|
||||||
|
{
|
||||||
|
data.Cultures.Add(culture);
|
||||||
|
data.Datas.Add(text.I18nDatas[culture].Text);
|
||||||
|
chooseData.Cultures.Add(culture);
|
||||||
|
chooseData.Datas.Add(text.I18nDatas[culture].Choose);
|
||||||
|
}
|
||||||
|
I18nDatas.Add(data);
|
||||||
|
I18nDatas.Add(chooseData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadPets(ModInfoModel model)
|
||||||
|
{
|
||||||
|
foreach (var pet in model.Pets)
|
||||||
|
{
|
||||||
|
var data = new I18nData();
|
||||||
|
var petNameData = new I18nData();
|
||||||
|
var descriptionData = new I18nData();
|
||||||
|
data.Id.Value = pet.Id.Value;
|
||||||
|
petNameData.Id.Value = pet.PetNameId.Value;
|
||||||
|
descriptionData.Id.Value = pet.DescriptionId.Value;
|
||||||
|
foreach (var culture in I18nHelper.Current.CultureNames)
|
||||||
|
{
|
||||||
|
data.Cultures.Add(culture);
|
||||||
|
data.Datas.Add(pet.I18nDatas[culture].Name);
|
||||||
|
petNameData.Cultures.Add(culture);
|
||||||
|
petNameData.Datas.Add(pet.I18nDatas[culture].PetName);
|
||||||
|
descriptionData.Cultures.Add(culture);
|
||||||
|
descriptionData.Datas.Add(pet.I18nDatas[culture].Description);
|
||||||
|
}
|
||||||
|
I18nDatas.Add(data);
|
||||||
|
I18nDatas.Add(petNameData);
|
||||||
|
I18nDatas.Add(descriptionData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly Dictionary<string, DataGridTextColumn> _dataGridI18nColumns = new();
|
private readonly Dictionary<string, DataGridTextColumn> _dataGridI18nColumns = new();
|
||||||
|
public HashSet<string> Ids { get; } = new();
|
||||||
|
public ObservableCollection<I18nData> I18nDatas { get; } = new();
|
||||||
|
public ObservableValue<ObservableCollection<I18nData>> ShowI18nDatas { get; } = new();
|
||||||
|
|
||||||
|
#region CultureEdit
|
||||||
// TODO: 国际化标头
|
// TODO: 国际化标头
|
||||||
private const string ValueBindingFormat = "Datas[{0}].Value";
|
private const string ValueBindingFormat = "Datas[{0}].Value";
|
||||||
|
|
||||||
@ -53,16 +184,18 @@ public partial class I18nEditWindow : WindowX
|
|||||||
/// <param name="culture"></param>
|
/// <param name="culture"></param>
|
||||||
public void AddCulture(string culture)
|
public void AddCulture(string culture)
|
||||||
{
|
{
|
||||||
|
var dataPath = string.Format(
|
||||||
|
ValueBindingFormat,
|
||||||
|
I18nHelper.Current.CultureNames.IndexOf(culture)
|
||||||
|
);
|
||||||
// 文化数据列
|
// 文化数据列
|
||||||
var column = new DataGridTextColumn()
|
var column = new DataGridTextColumn()
|
||||||
{
|
{
|
||||||
MaxWidth = 200,
|
MaxWidth = 300,
|
||||||
Header = culture,
|
Header = culture,
|
||||||
Binding = new Binding(string.Format(ValueBindingFormat, culture))
|
Binding = new Binding(dataPath) { Mode = BindingMode.TwoWay },
|
||||||
{
|
ElementStyle = (Style)Utils.ModMakerStyles["TextBlock_Wrap"],
|
||||||
Mode = BindingMode.TwoWay
|
SortMemberPath = dataPath
|
||||||
},
|
|
||||||
ElementStyle = (Style)Utils.ModMakerStyles["TextBlock_LeftCenter"],
|
|
||||||
};
|
};
|
||||||
DataGrid_Datas.Columns.Add(column);
|
DataGrid_Datas.Columns.Add(column);
|
||||||
_dataGridI18nColumns.Add(culture, column);
|
_dataGridI18nColumns.Add(culture, column);
|
||||||
@ -87,10 +220,16 @@ public partial class I18nEditWindow : WindowX
|
|||||||
{
|
{
|
||||||
//if (_dataGridI18nColumns.ContainsKey(newCultureName))
|
//if (_dataGridI18nColumns.ContainsKey(newCultureName))
|
||||||
// throw new();
|
// throw new();
|
||||||
|
var dataPath = string.Format(
|
||||||
|
ValueBindingFormat,
|
||||||
|
I18nHelper.Current.CultureNames.IndexOf(newCulture)
|
||||||
|
);
|
||||||
var column = _dataGridI18nColumns[oldCulture];
|
var column = _dataGridI18nColumns[oldCulture];
|
||||||
column.Header = newCulture;
|
column.Header = newCulture;
|
||||||
column.Binding = new Binding(string.Format(ValueBindingFormat, newCulture));
|
column.Binding = new Binding(dataPath) { Mode = BindingMode.TwoWay };
|
||||||
|
column.SortMemberPath = dataPath;
|
||||||
_dataGridI18nColumns.Remove(oldCulture);
|
_dataGridI18nColumns.Remove(oldCulture);
|
||||||
_dataGridI18nColumns.Add(newCulture, column);
|
_dataGridI18nColumns.Add(newCulture, column);
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user