完善 SaveText

This commit is contained in:
Hakoyu 2023-08-31 16:53:35 +08:00
parent 30f272ad25
commit 529d556e20
19 changed files with 129 additions and 57 deletions

View File

@ -1,4 +1,5 @@
using HKW.HKWViewModels.SimpleObservable;
using LinePutScript.Converter;
using System;
using System.Collections.Generic;
using System.Linq;
@ -10,8 +11,7 @@ namespace VPet.ModMaker.Models;
public class ClickTextModel : I18nModel<I18nClickTextModel>
{
public string Text { get; set; }
public ObservableValue<string> Id { get; } = new();
public ObservableValue<string> Name { get; } = new();
public ObservableValue<ClickText.ModeType> Mode { get; } = new();
public ObservableValue<string> Working { get; } = new();
@ -25,6 +25,7 @@ public class ClickTextModel : I18nModel<I18nClickTextModel>
public ClickTextModel(ClickTextModel clickText)
: this()
{
Name.Value = clickText.Name.Value;
Mode.Value = clickText.Mode.Value;
Working.Value = clickText.Working.Value;
WorkingState.Value = clickText.WorkingState.Value;
@ -42,7 +43,7 @@ public class ClickTextModel : I18nModel<I18nClickTextModel>
public ClickTextModel(ClickText clickText)
: this()
{
Text = clickText.Text;
Name.Value = clickText.Text;
Mode.Value = clickText.Mode;
Working.Value = clickText.Working;
WorkingState.Value = clickText.State;
@ -55,7 +56,7 @@ public class ClickTextModel : I18nModel<I18nClickTextModel>
{
return new()
{
Text = Text,
Text = Name.Value,
Mode = Mode.Value,
Working = Working.Value,
State = WorkingState.Value,

View File

@ -19,10 +19,12 @@ public class I18nModel<T>
I18nHelper.Current.AddLang += AddLang;
I18nHelper.Current.RemoveLang += RemoveLang;
I18nHelper.Current.ReplaceLang += ReplaceLang;
if (I18nDatas.Count == 0)
if (I18nHelper.Current.CultureNames.Count == 0)
return;
foreach (var item in I18nDatas)
I18nDatas[item.Key] = item.Value;
foreach (var item in I18nHelper.Current.CultureNames)
{
I18nDatas.Add(item, new());
}
CurrentI18nData.Value = I18nDatas[I18nHelper.Current.CultureName.Value];
}

View File

@ -11,8 +11,7 @@ namespace VPet.ModMaker.Models;
public class LowTextModel : I18nModel<I18nLowTextModel>
{
public string Text { get; set; }
public ObservableValue<string> Id { get; } = new();
public ObservableValue<string> Name { get; } = new();
public ObservableValue<LowText.ModeType> Mode { get; } = new();
public ObservableValue<LowText.StrengthType> Strength { get; } = new();
public ObservableValue<LowText.LikeType> Like { get; } = new();
@ -22,6 +21,7 @@ public class LowTextModel : I18nModel<I18nLowTextModel>
public LowTextModel(LowTextModel lowText)
: this()
{
Name.Value = lowText.Name.Value;
Mode.Value = lowText.Mode.Value;
Strength.Value = lowText.Strength.Value;
Like.Value = lowText.Like.Value;
@ -36,7 +36,7 @@ public class LowTextModel : I18nModel<I18nLowTextModel>
public LowTextModel(LowText lowText)
: this()
{
Text = lowText.Text;
Name.Value = lowText.Text;
Mode.Value = lowText.Mode;
Strength.Value = lowText.Strength;
Like.Value = lowText.Like;
@ -48,7 +48,7 @@ public class LowTextModel : I18nModel<I18nLowTextModel>
{
return new()
{
Text = Text,
Text = Name.Value,
Mode = Mode.Value,
Strength = Strength.Value,
Like = Like.Value,

View File

@ -114,11 +114,12 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
//lps.FindorAddLine("itemid").info = "0";
File.WriteAllText(modInfoFile, lps.ToString());
SaveFoods(path);
SaveText(path);
SaveLang(path);
SaveImage(path);
}
public void SaveFoods(string path)
private void SaveFoods(string path)
{
if (Foods.Count == 0)
return;
@ -133,7 +134,45 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
File.WriteAllText(foodFile, lps.ToString());
}
public void SaveLang(string path)
private void SaveText(string path)
{
if (LowTexts.Count == 0 && ClickTexts.Count == 0)
return;
var textPath = Path.Combine(path, "text");
Directory.CreateDirectory(textPath);
SaveLowText(textPath);
SaveClickText(textPath);
}
private void SaveLowText(string textPath)
{
if (LowTexts.Count == 0)
return;
var textFile = Path.Combine(textPath, "lowText.lps");
File.Create(textFile).Close();
var lps = new LPS();
foreach (var text in LowTexts)
{
lps.Add(LPSConvert.SerializeObjectToLine<Line>(text.ToLowText(), "lowfoodtext"));
}
File.WriteAllText(textFile, lps.ToString());
}
private void SaveClickText(string textPath)
{
if (ClickTexts.Count == 0)
return;
var textFile = Path.Combine(textPath, "clickText.lps");
File.Create(textFile).Close();
var lps = new LPS();
foreach (var text in ClickTexts)
{
lps.Add(LPSConvert.SerializeObjectToLine<Line>(text.ToClickText(), "clicktext"));
}
File.WriteAllText(textFile, lps.ToString());
}
private void SaveLang(string path)
{
var langPath = Path.Combine(path, "lang");
Directory.CreateDirectory(langPath);
@ -151,12 +190,21 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
new Line(food.Description.Value, food.I18nDatas[cultureName].Description.Value)
);
}
if (lps.Count > 0)
foreach (var lowText in LowTexts)
{
lps.Add(new Line(lowText.Name.Value, lowText.I18nDatas[cultureName].Text.Value));
}
foreach (var clickText in ClickTexts)
{
lps.Add(
new Line(clickText.Name.Value, clickText.I18nDatas[cultureName].Text.Value)
);
}
File.WriteAllText(cultureFile, lps.ToString());
}
}
public void SaveImage(string path)
private void SaveImage(string path)
{
var imagePath = Path.Combine(path, "image");
Directory.CreateDirectory(imagePath);

View File

@ -13,6 +13,8 @@ namespace VPet.ModMaker.ViewModels.ModEdit.ClickTextEdit;
public class ClickTextEditWindowVM
{
#region Value
public ClickTextModel OldClickText { get; set; }
public ObservableValue<ClickTextModel> ClickText { get; } = new(new());
public ObservableCollection<ClickText.ModeType> ModeTypes { get; } = new();
public ObservableCollection<ClickText.DayTime> DayTimes { get; } = new();

View File

@ -61,6 +61,7 @@ public class ClickTextPageVM
{
var window = new ClickTextEditWindow();
var vm = window.ViewModel;
vm.OldClickText = clickText;
var newLowTest = vm.ClickText.Value = new(clickText);
window.ShowDialog();
if (window.IsCancel)

View File

@ -16,6 +16,7 @@ namespace VPet.ModMaker.ViewModels.ModEdit.FoodEdit;
public class FoodEditWindowVM
{
#region Value
public FoodModel OldFood { get; set; }
public ObservableValue<FoodModel> Food { get; } = new(new());
public ObservableCollection<Food.FoodType> FoodTypes { get; } = new();
#endregion

View File

@ -65,6 +65,7 @@ public class FoodPageVM
{
var window = new FoodEditWindow();
var vm = window.ViewModel;
vm.OldFood = food;
var newFood = vm.Food.Value = new(food);
window.ShowDialog();
if (window.IsCancel)

View File

@ -13,6 +13,7 @@ namespace VPet.ModMaker.ViewModels.ModEdit.LowTextEdit;
public class LowTextEditWindowVM
{
#region Value
public LowTextModel OldLowText { get; set; }
public ObservableValue<LowTextModel> LowText { get; } = new(new());
public ObservableCollection<LowText.ModeType> ModeTypes { get; } = new();

View File

@ -64,6 +64,7 @@ public class LowTextPageVM
{
var window = new LowTextEditWindow();
var vm = window.ViewModel;
vm.OldLowText = lowText;
var newLowTest = vm.LowText.Value = new(lowText);
window.ShowDialog();
if (window.IsCancel)

View File

@ -63,13 +63,13 @@ public class ModEditWindowVM
foreach (var lowText in ModInfo.Value.LowTexts)
{
var lowTextI18n = lowText.I18nDatas[i18n.Key];
if (i18n.Value.TryGetValue(lowText.Text, out var text))
if (i18n.Value.TryGetValue(lowText.Name.Value, out var text))
lowTextI18n.Text.Value = text;
}
foreach (var clickText in ModInfo.Value.ClickTexts)
{
var clickTextI18n = clickText.I18nDatas[i18n.Key];
if (i18n.Value.TryGetValue(clickText.Text, out var text))
if (i18n.Value.TryGetValue(clickText.Name.Value, out var text))
clickTextI18n.Text.Value = text;
}
}

View File

@ -48,7 +48,7 @@
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Content="Id" />
<TextBox Grid.Column="1" Text="{Binding ClickText.Value.Id.Value, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Grid.Column="1" Text="{Binding ClickText.Value.Name.Value, UpdateSourceTrigger=PropertyChanged}" />
<Label Grid.Row="1" Content="指定工作" />
<TextBox
Grid.Row="1"

View File

@ -37,20 +37,26 @@ public partial class ClickTextEditWindow : Window
private void Button_Yes_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(ViewModel.ClickText.Value.Id.Value))
if (string.IsNullOrEmpty(ViewModel.ClickText.Value.Name.Value))
{
MessageBox.Show("Id不可为空", "", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
if (
ModInfoModel.Current.ClickTexts.Any(
i => i.Id.Value == ViewModel.ClickText.Value.Id.Value
ViewModel.OldClickText?.Name.Value != ViewModel.ClickText.Value.Name.Value
&& ModInfoModel.Current.ClickTexts.Any(
i => i.Name.Value == ViewModel.ClickText.Value.Name.Value
)
)
{
MessageBox.Show("此Id已存在", "", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
if (string.IsNullOrEmpty(ViewModel.ClickText.Value.CurrentI18nData.Value.Text.Value))
{
MessageBox.Show("文本不可为空", "", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
IsCancel = false;
Close();
}

View File

@ -60,10 +60,10 @@
</DataGrid.RowStyle>
<DataGrid.Columns>
<DataGridTextColumn
Binding="{Binding Id.Value}"
Binding="{Binding Name.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="Id">
SortMemberPath="Name.Value">
<DataGridTextColumn.Header>
<Label Content="Id" />
</DataGridTextColumn.Header>
@ -72,7 +72,7 @@
Binding="{Binding CurrentI18nData.Value.Text.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="Text">
SortMemberPath="CurrentI18nData.Value.Text.Value">
<DataGridTextColumn.Header>
<Label Content="文本" />
</DataGridTextColumn.Header>
@ -81,7 +81,7 @@
Binding="{Binding Mode.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="Mode">
SortMemberPath="Mode.Value">
<DataGridTextColumn.Header>
<Label Content="状态" />
</DataGridTextColumn.Header>
@ -90,7 +90,7 @@
Binding="{Binding Working.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="Working">
SortMemberPath="Working.Value">
<DataGridTextColumn.Header>
<Label Content="指定工作" />
</DataGridTextColumn.Header>
@ -99,7 +99,7 @@
Binding="{Binding WorkingState.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="WorkingState">
SortMemberPath="WorkingState.Value">
<DataGridTextColumn.Header>
<Label Content="工作状态" />
</DataGridTextColumn.Header>
@ -108,7 +108,7 @@
Binding="{Binding LikeMin.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="LikeMin">
SortMemberPath="LikeMin.Value">
<DataGridTextColumn.Header>
<Label Content="最小好感" />
</DataGridTextColumn.Header>
@ -117,7 +117,7 @@
Binding="{Binding LikeMax.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="LikeMax">
SortMemberPath="LikeMax.Value">
<DataGridTextColumn.Header>
<Label Content="最大好感" />
</DataGridTextColumn.Header>
@ -126,7 +126,7 @@
Binding="{Binding DayTime.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="DayTime">
SortMemberPath="DayTime.Value">
<DataGridTextColumn.Header>
<Label Content="时间" />
</DataGridTextColumn.Header>

View File

@ -46,11 +46,11 @@ public partial class FoodEditWindow : Window
private void Button_Yes_Click(object sender, RoutedEventArgs e)
{
//if (string.IsNullOrEmpty(ViewModel.Food.Value.Id.Value))
//{
// MessageBox.Show("Id不可为空", "", MessageBoxButton.OK, MessageBoxImage.Warning);
// return;
//}
if (string.IsNullOrEmpty(ViewModel.Food.Value.Name.Value))
{
MessageBox.Show("Id不可为空", "", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
if (ViewModel.Food.Value.CurrentI18nData.Value.Name.Value is null)
{
MessageBox.Show("名称不可为空", "", MessageBoxButton.OK, MessageBoxImage.Warning);
@ -61,7 +61,10 @@ public partial class FoodEditWindow : Window
MessageBox.Show("图像不可为空", "", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
if (ModInfoModel.Current.Foods.Any(i => i.Name == ViewModel.Food.Value.Name))
if (
ViewModel.OldFood?.Name.Value != ViewModel.Food.Value.Name.Value
&& ModInfoModel.Current.Foods.Any(i => i.Name == ViewModel.Food.Value.Name)
)
{
MessageBox.Show("此Id已存在", "", MessageBoxButton.OK, MessageBoxImage.Warning);
return;

View File

@ -60,7 +60,7 @@
Binding="{Binding Name.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="Name">
SortMemberPath="Name.Value">
<DataGridTextColumn.Header>
<Label Content="食物ID" />
</DataGridTextColumn.Header>
@ -95,7 +95,7 @@
Binding="{Binding CurrentI18nData.Value.Name.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="Name">
SortMemberPath="CurrentI18nData.Value.Name.Value">
<DataGridTextColumn.Header>
<Label Content="食物名称" />
</DataGridTextColumn.Header>
@ -113,7 +113,7 @@
Binding="{Binding StrengthFood.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="StrengthFood">
SortMemberPath="StrengthFood.Value">
<DataGridTextColumn.Header>
<Label Content="饱腹值" />
</DataGridTextColumn.Header>
@ -122,7 +122,7 @@
Binding="{Binding StrengthDrink.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="StrengthDrink">
SortMemberPath="StrengthDrink.Value">
<DataGridTextColumn.Header>
<Label Content="口渴值" />
</DataGridTextColumn.Header>
@ -131,7 +131,7 @@
Binding="{Binding Health.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="Health">
SortMemberPath="Health.Value">
<DataGridTextColumn.Header>
<Label Content="健康值" />
</DataGridTextColumn.Header>
@ -140,7 +140,7 @@
Binding="{Binding Strength.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="Strength">
SortMemberPath="Strength.Value">
<DataGridTextColumn.Header>
<Label Content="体力值" />
</DataGridTextColumn.Header>
@ -149,7 +149,7 @@
Binding="{Binding Feeling.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="Feeling">
SortMemberPath="Feeling.Value">
<DataGridTextColumn.Header>
<Label Content="心情值" />
</DataGridTextColumn.Header>
@ -158,7 +158,7 @@
Binding="{Binding Likability.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="Likability">
SortMemberPath="Likability.Value">
<DataGridTextColumn.Header>
<Label Content="好感值" />
</DataGridTextColumn.Header>
@ -167,7 +167,7 @@
Binding="{Binding Exp.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="Exp">
SortMemberPath="Exp.Value">
<DataGridTextColumn.Header>
<Label Content="经验值" />
</DataGridTextColumn.Header>
@ -176,7 +176,7 @@
Binding="{Binding Price.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="Price">
SortMemberPath="Price.Value">
<DataGridTextColumn.Header>
<Label Content="价格" />
</DataGridTextColumn.Header>
@ -185,7 +185,7 @@
Binding="{Binding CurrentI18nData.Value.Description.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="Description">
SortMemberPath="CurrentI18nData.Value.Description.Value">
<DataGridTextColumn.Header>
<Label Content="描述" />
</DataGridTextColumn.Header>

View File

@ -45,7 +45,7 @@
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Content="Id" />
<TextBox Grid.Column="1" Text="{Binding LowText.Value.Id.Value, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Grid.Column="1" Text="{Binding LowText.Value.Name.Value, UpdateSourceTrigger=PropertyChanged}" />
<Label Grid.Row="1" Content="口渴/饥饿状态" />
<Label Grid.Row="1" Content="状态" />
<ComboBox

View File

@ -38,12 +38,17 @@ public partial class LowTextEditWindow : Window
private void Button_Yes_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(ViewModel.LowText.Value.Id.Value))
if (string.IsNullOrEmpty(ViewModel.LowText.Value.Name.Value))
{
MessageBox.Show("Id不可为空", "", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
if (ModInfoModel.Current.LowTexts.Any(i => i.Id.Value == ViewModel.LowText.Value.Id.Value))
if (
ViewModel.OldLowText?.Name.Value != ViewModel.LowText.Value.Name.Value
&& ModInfoModel.Current.LowTexts.Any(
i => i.Name.Value == ViewModel.LowText.Value.Name.Value
)
)
{
MessageBox.Show("此Id已存在", "", MessageBoxButton.OK, MessageBoxImage.Warning);
return;

View File

@ -57,10 +57,10 @@
</DataGrid.RowStyle>
<DataGrid.Columns>
<DataGridTextColumn
Binding="{Binding Id.Value}"
Binding="{Binding Name.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="Id">
SortMemberPath="Id.Value">
<DataGridTextColumn.Header>
<Label Content="Id" />
</DataGridTextColumn.Header>
@ -69,7 +69,7 @@
Binding="{Binding CurrentI18nData.Value.Text.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="Name">
SortMemberPath="CurrentI18nData.Value.Text.Value">
<DataGridTextColumn.Header>
<Label Content="文本" />
</DataGridTextColumn.Header>
@ -78,7 +78,7 @@
Binding="{Binding Mode.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="Mode">
SortMemberPath="Mode.Value">
<DataGridTextColumn.Header>
<Label Content="状态" />
</DataGridTextColumn.Header>
@ -87,7 +87,7 @@
Binding="{Binding Strength.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="StrengthFood">
SortMemberPath="Strength.Value">
<DataGridTextColumn.Header>
<Label Content="口渴/饥饿需求" />
</DataGridTextColumn.Header>
@ -96,7 +96,7 @@
Binding="{Binding Like.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="Like">
SortMemberPath="Like.Value">
<DataGridTextColumn.Header>
<Label Content="好感需求" />
</DataGridTextColumn.Header>