From 529d556e209fa3029336e9e5fc8338eb1539b669 Mon Sep 17 00:00:00 2001 From: Hakoyu Date: Thu, 31 Aug 2023 16:53:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=20SaveText?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VPet.ModMaker/Models/ClickTextModel.cs | 9 +-- VPet.ModMaker/Models/I18nModel.cs | 8 ++- VPet.ModMaker/Models/LowTextModel.cs | 8 +-- VPet.ModMaker/Models/ModInfoModel.cs | 58 +++++++++++++++++-- .../ClickTextEdit/ClickTextEditWindowVM.cs | 2 + .../ModEdit/ClickTextEdit/ClickTextPageVM.cs | 1 + .../ModEdit/FoodEdit/FoodEditWindowVM.cs | 1 + .../ViewModels/ModEdit/FoodEdit/FoodPageVM.cs | 1 + .../LowTextEdit/LowTextEditWindowVM.cs | 1 + .../ModEdit/LowTextEdit/LowTextPageVM.cs | 1 + .../ViewModels/ModEdit/ModEditWindowVM.cs | 4 +- .../ClickTextEdit/ClickTextEditWindow.xaml | 2 +- .../ClickTextEdit/ClickTextEditWindow.xaml.cs | 12 +++- .../ModEdit/ClickTextEdit/ClickTextPage.xaml | 18 +++--- .../ModEdit/FoodEdit/FoodEditWindow.xaml.cs | 15 +++-- .../Views/ModEdit/FoodEdit/FoodPage.xaml | 22 +++---- .../LowTextEdit/LowTextEditWindow.xaml | 2 +- .../LowTextEdit/LowTextEditWindow.xaml.cs | 9 ++- .../ModEdit/LowTextEdit/LowTextPage.xaml | 12 ++-- 19 files changed, 129 insertions(+), 57 deletions(-) diff --git a/VPet.ModMaker/Models/ClickTextModel.cs b/VPet.ModMaker/Models/ClickTextModel.cs index 593586c..0df8ded 100644 --- a/VPet.ModMaker/Models/ClickTextModel.cs +++ b/VPet.ModMaker/Models/ClickTextModel.cs @@ -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 { - public string Text { get; set; } - public ObservableValue Id { get; } = new(); + public ObservableValue Name { get; } = new(); public ObservableValue Mode { get; } = new(); public ObservableValue Working { get; } = new(); @@ -25,6 +25,7 @@ public class ClickTextModel : I18nModel 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 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 { return new() { - Text = Text, + Text = Name.Value, Mode = Mode.Value, Working = Working.Value, State = WorkingState.Value, diff --git a/VPet.ModMaker/Models/I18nModel.cs b/VPet.ModMaker/Models/I18nModel.cs index 0adc0d0..f62bd70 100644 --- a/VPet.ModMaker/Models/I18nModel.cs +++ b/VPet.ModMaker/Models/I18nModel.cs @@ -19,10 +19,12 @@ public class I18nModel 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]; } diff --git a/VPet.ModMaker/Models/LowTextModel.cs b/VPet.ModMaker/Models/LowTextModel.cs index 6f2ea52..7429519 100644 --- a/VPet.ModMaker/Models/LowTextModel.cs +++ b/VPet.ModMaker/Models/LowTextModel.cs @@ -11,8 +11,7 @@ namespace VPet.ModMaker.Models; public class LowTextModel : I18nModel { - public string Text { get; set; } - public ObservableValue Id { get; } = new(); + public ObservableValue Name { get; } = new(); public ObservableValue Mode { get; } = new(); public ObservableValue Strength { get; } = new(); public ObservableValue Like { get; } = new(); @@ -22,6 +21,7 @@ public class LowTextModel : I18nModel 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 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 { return new() { - Text = Text, + Text = Name.Value, Mode = Mode.Value, Strength = Strength.Value, Like = Like.Value, diff --git a/VPet.ModMaker/Models/ModInfoModel.cs b/VPet.ModMaker/Models/ModInfoModel.cs index 1aeb7ab..9c9873a 100644 --- a/VPet.ModMaker/Models/ModInfoModel.cs +++ b/VPet.ModMaker/Models/ModInfoModel.cs @@ -114,11 +114,12 @@ public class ModInfoModel : I18nModel //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 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(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(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 new Line(food.Description.Value, food.I18nDatas[cultureName].Description.Value) ); } - if (lps.Count > 0) - File.WriteAllText(cultureFile, lps.ToString()); + 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); diff --git a/VPet.ModMaker/ViewModels/ModEdit/ClickTextEdit/ClickTextEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/ClickTextEdit/ClickTextEditWindowVM.cs index 95e5607..747eb30 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/ClickTextEdit/ClickTextEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/ClickTextEdit/ClickTextEditWindowVM.cs @@ -13,6 +13,8 @@ namespace VPet.ModMaker.ViewModels.ModEdit.ClickTextEdit; public class ClickTextEditWindowVM { #region Value + + public ClickTextModel OldClickText { get; set; } public ObservableValue ClickText { get; } = new(new()); public ObservableCollection ModeTypes { get; } = new(); public ObservableCollection DayTimes { get; } = new(); diff --git a/VPet.ModMaker/ViewModels/ModEdit/ClickTextEdit/ClickTextPageVM.cs b/VPet.ModMaker/ViewModels/ModEdit/ClickTextEdit/ClickTextPageVM.cs index 4948f70..6979587 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/ClickTextEdit/ClickTextPageVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/ClickTextEdit/ClickTextPageVM.cs @@ -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) diff --git a/VPet.ModMaker/ViewModels/ModEdit/FoodEdit/FoodEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/FoodEdit/FoodEditWindowVM.cs index b7eb7d0..5773263 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/FoodEdit/FoodEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/FoodEdit/FoodEditWindowVM.cs @@ -16,6 +16,7 @@ namespace VPet.ModMaker.ViewModels.ModEdit.FoodEdit; public class FoodEditWindowVM { #region Value + public FoodModel OldFood { get; set; } public ObservableValue Food { get; } = new(new()); public ObservableCollection FoodTypes { get; } = new(); #endregion diff --git a/VPet.ModMaker/ViewModels/ModEdit/FoodEdit/FoodPageVM.cs b/VPet.ModMaker/ViewModels/ModEdit/FoodEdit/FoodPageVM.cs index e8727a0..43f70c9 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/FoodEdit/FoodPageVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/FoodEdit/FoodPageVM.cs @@ -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) diff --git a/VPet.ModMaker/ViewModels/ModEdit/LowTextEdit/LowTextEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/LowTextEdit/LowTextEditWindowVM.cs index 899e0a9..19cf6eb 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/LowTextEdit/LowTextEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/LowTextEdit/LowTextEditWindowVM.cs @@ -13,6 +13,7 @@ namespace VPet.ModMaker.ViewModels.ModEdit.LowTextEdit; public class LowTextEditWindowVM { #region Value + public LowTextModel OldLowText { get; set; } public ObservableValue LowText { get; } = new(new()); public ObservableCollection ModeTypes { get; } = new(); diff --git a/VPet.ModMaker/ViewModels/ModEdit/LowTextEdit/LowTextPageVM.cs b/VPet.ModMaker/ViewModels/ModEdit/LowTextEdit/LowTextPageVM.cs index 02daabb..753ad09 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/LowTextEdit/LowTextPageVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/LowTextEdit/LowTextPageVM.cs @@ -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) diff --git a/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs index a913e85..3a5da85 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs @@ -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; } } diff --git a/VPet.ModMaker/Views/ModEdit/ClickTextEdit/ClickTextEditWindow.xaml b/VPet.ModMaker/Views/ModEdit/ClickTextEdit/ClickTextEditWindow.xaml index 5f7a27c..dbb0d90 100644 --- a/VPet.ModMaker/Views/ModEdit/ClickTextEdit/ClickTextEditWindow.xaml +++ b/VPet.ModMaker/Views/ModEdit/ClickTextEdit/ClickTextEditWindow.xaml @@ -48,7 +48,7 @@