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}}"
|
||||
TargetType="TextBlock">
|
||||
<Setter Property="TextWrapping" Value="Wrap" />
|
||||
<Setter Property="ToolTip" Value="{Binding Text, RelativeSource={RelativeSource Mode=Self}}" />
|
||||
</Style>
|
||||
<Style
|
||||
x:Key="TextBlock_Center"
|
||||
@ -47,6 +48,7 @@
|
||||
TargetType="TextBlock">
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<Setter Property="HorizontalAlignment" Value="Center" />
|
||||
<Setter Property="ToolTip" Value="{Binding Text, RelativeSource={RelativeSource Mode=Self}}" />
|
||||
</Style>
|
||||
<Style
|
||||
x:Key="TextBlock_LeftCenter"
|
||||
@ -54,6 +56,7 @@
|
||||
TargetType="TextBlock">
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<Setter Property="HorizontalAlignment" Value="Left" />
|
||||
<Setter Property="ToolTip" Value="{Binding Text, RelativeSource={RelativeSource Mode=Self}}" />
|
||||
</Style>
|
||||
<Style
|
||||
x:Key="TextBox_Wrap"
|
||||
@ -62,6 +65,7 @@
|
||||
<Setter Property="TextWrapping" Value="Wrap" />
|
||||
<Setter Property="HorizontalContentAlignment" Value="Left" />
|
||||
<Setter Property="VerticalContentAlignment" Value="Top" />
|
||||
<Setter Property="ToolTip" Value="{Binding Text, RelativeSource={RelativeSource Mode=Self}}" />
|
||||
</Style>
|
||||
<Style
|
||||
x:Key="TextBox_Center"
|
||||
@ -69,6 +73,7 @@
|
||||
TargetType="TextBox">
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<Setter Property="HorizontalAlignment" Value="Center" />
|
||||
<Setter Property="ToolTip" Value="{Binding Text, RelativeSource={RelativeSource Mode=Self}}" />
|
||||
</Style>
|
||||
<Style
|
||||
x:Key="TextBox_LeftCenter"
|
||||
@ -76,6 +81,7 @@
|
||||
TargetType="TextBox">
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<Setter Property="HorizontalAlignment" Value="Left" />
|
||||
<Setter Property="ToolTip" Value="{Binding Text, RelativeSource={RelativeSource Mode=Self}}" />
|
||||
</Style>
|
||||
<Style x:Key="WindowXStyle" TargetType="pu:WindowX">
|
||||
<Setter Property="pu:WindowXCaption.Background" Value="{DynamicResource DARKPrimary}" />
|
||||
|
@ -103,6 +103,7 @@
|
||||
<Compile Include="Converters\MaxConverter.cs" />
|
||||
<Compile Include="Converters\MarginConverter.cs" />
|
||||
<Compile Include="Models\EnumFlagsVM.cs" />
|
||||
<Compile Include="Models\I18nData.cs" />
|
||||
<Compile Include="Models\ModModel\AnimeModel.cs" />
|
||||
<Compile Include="Models\ModModel\AnimeTypeModel.cs" />
|
||||
<Compile Include="Models\ModModel\ClickTextModel.cs" />
|
||||
|
@ -90,9 +90,14 @@ public class ModEditWindowVM
|
||||
|
||||
private void EditI18n()
|
||||
{
|
||||
var window = new I18nEditWindow();
|
||||
foreach (var culture in I18nHelper.Current.CultureNames)
|
||||
window.AddCulture(culture);
|
||||
if (I18nEditWindow.Instance is not null)
|
||||
{
|
||||
I18nEditWindow.Instance.Activate();
|
||||
return;
|
||||
}
|
||||
var window = new I18nEditWindow(ModInfo.Value);
|
||||
//foreach (var culture in I18nHelper.Current.CultureNames)
|
||||
// window.AddCulture(culture);
|
||||
//if (window.IsCancel)
|
||||
// return;
|
||||
//I18nHelper.Current.CultureNames.Add(window.ViewModel.Culture.Value);
|
||||
|
@ -14,9 +14,6 @@
|
||||
d:DataContext="{d:DesignInstance Type=vm:FoodEditWindowVM}"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
mc:Ignorable="d">
|
||||
<Window.Resources>
|
||||
<ResourceDictionary Source="/VPet-Simulator.Windows.Interface;component/ResourceStyle.xaml" />
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="250" />
|
||||
|
@ -12,20 +12,38 @@
|
||||
Width="800"
|
||||
Height="450"
|
||||
d:DataContext="{d:DesignInstance Type=vm:I18nEditWindowVM}"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
mc:Ignorable="d">
|
||||
<Window.Resources />
|
||||
<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
|
||||
x:Name="DataGrid_Datas"
|
||||
Grid.Row="1"
|
||||
d:ItemsSource="{d:SampleData ItemCount=5}"
|
||||
AutoGenerateColumns="False"
|
||||
CanUserAddRows="False"
|
||||
CanUserDeleteRows="False"
|
||||
CanUserReorderColumns="False"
|
||||
ItemsSource="{Binding ShowI18nDatas.Value}"
|
||||
ScrollViewer.IsDeferredScrollingEnabled="True"
|
||||
VirtualizingStackPanel.VirtualizationMode="Recycling">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn
|
||||
Binding="{Binding Id}"
|
||||
MaxWidth="300"
|
||||
Binding="{Binding Id.Value}"
|
||||
CanUserSort="True"
|
||||
ElementStyle="{StaticResource TextBlock_Wrap}"
|
||||
Header="Id"
|
||||
IsReadOnly="True" />
|
||||
IsReadOnly="True"
|
||||
SortMemberPath="Id.Value" />
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</Grid>
|
||||
|
@ -1,20 +1,13 @@
|
||||
using Panuon.WPF.UI;
|
||||
using HKW.HKWViewModels.SimpleObservable;
|
||||
using Panuon.WPF.UI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Collections.ObjectModel;
|
||||
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.Models;
|
||||
using VPet.ModMaker.ViewModels.ModEdit.I18nEdit;
|
||||
|
||||
namespace VPet.ModMaker.Views.ModEdit.I18nEdit;
|
||||
|
||||
@ -24,12 +17,35 @@ namespace VPet.ModMaker.Views.ModEdit.I18nEdit;
|
||||
public partial class I18nEditWindow : WindowX
|
||||
{
|
||||
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();
|
||||
DataContext = new I18nEditWindowVM();
|
||||
DataContext = this;
|
||||
Instance = this;
|
||||
Search.ValueChanged += Search_ValueChanged;
|
||||
Closed += (s, e) =>
|
||||
{
|
||||
//if (IsCancel)
|
||||
@ -37,13 +53,128 @@ public partial class I18nEditWindow : WindowX
|
||||
try
|
||||
{
|
||||
DataContext = null;
|
||||
Instance = null;
|
||||
}
|
||||
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();
|
||||
public HashSet<string> Ids { get; } = new();
|
||||
public ObservableCollection<I18nData> I18nDatas { get; } = new();
|
||||
public ObservableValue<ObservableCollection<I18nData>> ShowI18nDatas { get; } = new();
|
||||
|
||||
#region CultureEdit
|
||||
// TODO: 国际化标头
|
||||
private const string ValueBindingFormat = "Datas[{0}].Value";
|
||||
|
||||
@ -53,16 +184,18 @@ public partial class I18nEditWindow : WindowX
|
||||
/// <param name="culture"></param>
|
||||
public void AddCulture(string culture)
|
||||
{
|
||||
var dataPath = string.Format(
|
||||
ValueBindingFormat,
|
||||
I18nHelper.Current.CultureNames.IndexOf(culture)
|
||||
);
|
||||
// 文化数据列
|
||||
var column = new DataGridTextColumn()
|
||||
{
|
||||
MaxWidth = 200,
|
||||
MaxWidth = 300,
|
||||
Header = culture,
|
||||
Binding = new Binding(string.Format(ValueBindingFormat, culture))
|
||||
{
|
||||
Mode = BindingMode.TwoWay
|
||||
},
|
||||
ElementStyle = (Style)Utils.ModMakerStyles["TextBlock_LeftCenter"],
|
||||
Binding = new Binding(dataPath) { Mode = BindingMode.TwoWay },
|
||||
ElementStyle = (Style)Utils.ModMakerStyles["TextBlock_Wrap"],
|
||||
SortMemberPath = dataPath
|
||||
};
|
||||
DataGrid_Datas.Columns.Add(column);
|
||||
_dataGridI18nColumns.Add(culture, column);
|
||||
@ -87,10 +220,16 @@ public partial class I18nEditWindow : WindowX
|
||||
{
|
||||
//if (_dataGridI18nColumns.ContainsKey(newCultureName))
|
||||
// throw new();
|
||||
var dataPath = string.Format(
|
||||
ValueBindingFormat,
|
||||
I18nHelper.Current.CultureNames.IndexOf(newCulture)
|
||||
);
|
||||
var column = _dataGridI18nColumns[oldCulture];
|
||||
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.Add(newCulture, column);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user