From 22be8ad96123ec25a93e1e47ffcc475c65feb15b Mon Sep 17 00:00:00 2001 From: Hakoyu Date: Wed, 6 Sep 2023 23:21:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E8=A3=85=20SelectTextEdit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VPet.ModMaker/Models/FoodModel.cs | 11 +- VPet.ModMaker/Models/ModInfoModel.cs | 64 +++++++-- VPet.ModMaker/Models/ModLoader.cs | 14 +- VPet.ModMaker/Models/SelectTextModel.cs | 127 ++++++++++++++++-- VPet.ModMaker/VPet.ModMaker.csproj | 6 +- .../ViewModels/ModEdit/ModEditWindowVM.cs | 24 ++-- .../SelectTextEdit/SelectTextEditWindowVM.cs | 17 +++ .../SelectTextEdit/SelectTextPageVM.cs | 95 +++++++++++++ .../ClickTextEdit/ClickTextEditWindow.xaml | 7 +- .../ModEdit/ClickTextEdit/ClickTextPage.xaml | 5 +- .../Views/ModEdit/ModEditWindow.xaml | 6 +- .../Views/ModEdit/ModEditWindow.xaml.cs | 12 ++ .../SelectTextEdit/SelectTextEditWindow.xaml | 103 ++++++++++---- .../SelectTextEditWindow.xaml.cs | 63 ++++++--- .../SelectTextEdit/SelectTextPage.xaml | 116 ++++++++++++---- .../SelectTextEdit/SelectTextPage.xaml.cs | 18 ++- 16 files changed, 563 insertions(+), 125 deletions(-) create mode 100644 VPet.ModMaker/ViewModels/ModEdit/SelectTextEdit/SelectTextEditWindowVM.cs create mode 100644 VPet.ModMaker/ViewModels/ModEdit/SelectTextEdit/SelectTextPageVM.cs diff --git a/VPet.ModMaker/Models/FoodModel.cs b/VPet.ModMaker/Models/FoodModel.cs index f1b0103..5773f75 100644 --- a/VPet.ModMaker/Models/FoodModel.cs +++ b/VPet.ModMaker/Models/FoodModel.cs @@ -30,7 +30,14 @@ public class FoodModel : I18nModel public ObservableValue Exp { get; } = new(); public ObservableValue Image { get; } = new(); - public FoodModel() { } + public FoodModel() + { + Description.Value = $"{Name.Value}_{nameof(Description)}"; + Name.ValueChanged += (v) => + { + Description.Value = $"{v}_{nameof(Description)}"; + }; + } public FoodModel(FoodModel food) : this() @@ -81,7 +88,7 @@ public class FoodModel : I18nModel return new Food() { Name = Name.Value, - Desc = $"{Name.Value}_{nameof(Description)}", + Desc = Description.Value, Graph = Graph.Value, Type = Type.Value, Strength = Strength.Value, diff --git a/VPet.ModMaker/Models/ModInfoModel.cs b/VPet.ModMaker/Models/ModInfoModel.cs index 5a68ceb..f42185b 100644 --- a/VPet.ModMaker/Models/ModInfoModel.cs +++ b/VPet.ModMaker/Models/ModInfoModel.cs @@ -34,9 +34,17 @@ public class ModInfoModel : I18nModel public Dictionary> OtherI18nDatas { get; } = new(); - public ModInfoModel() { } + public ModInfoModel() + { + Description.Value = $"{Name.Value}_{nameof(Description)}"; + Name.ValueChanged += (v) => + { + Description.Value = $"{v}_{nameof(Description)}"; + }; + } public ModInfoModel(ModLoader loader) + : this() { SourcePath.Value = loader.Path.FullName; Name.Value = loader.Name; @@ -53,6 +61,9 @@ public class ModInfoModel : I18nModel ClickTexts.Add(new(clickText)); foreach (var lowText in loader.LowTexts) LowTexts.Add(new(lowText)); + foreach (var selectText in loader.SelectTexts) + SelectTexts.Add(new(selectText)); + Summary.Value = GetSummary(); foreach (var lang in loader.I18nDatas) I18nDatas.Add(lang.Key, lang.Value); @@ -123,9 +134,13 @@ public class ModInfoModel : I18nModel private void SaveFoods(string path) { - if (Foods.Count == 0) - return; var foodPath = Path.Combine(path, "food"); + if (Foods.Count == 0) + { + if (Directory.Exists(foodPath)) + Directory.Delete(foodPath, true); + return; + } Directory.CreateDirectory(foodPath); var foodFile = Path.Combine(foodPath, "food.lps"); if (File.Exists(foodFile) is false) @@ -138,12 +153,31 @@ public class ModInfoModel : I18nModel private void SaveText(string path) { - if (LowTexts.Count == 0 && ClickTexts.Count == 0) - return; var textPath = Path.Combine(path, "text"); + if (LowTexts.Count == 0 && ClickTexts.Count == 0 && SelectTexts.Count == 0) + { + if (Directory.Exists(textPath)) + Directory.Delete(textPath, true); + return; + } Directory.CreateDirectory(textPath); SaveLowText(textPath); SaveClickText(textPath); + SaveSelectText(textPath); + } + + private void SaveSelectText(string textPath) + { + if (SelectTexts.Count == 0) + return; + var textFile = Path.Combine(textPath, "selectText.lps"); + File.Create(textFile).Close(); + var lps = new LPS(); + foreach (var text in SelectTexts) + { + lps.Add(LPSConvert.SerializeObjectToLine(text.ToSelectText(), "SelectText")); + } + File.WriteAllText(textFile, lps.ToString()); } private void SaveLowText(string textPath) @@ -192,15 +226,18 @@ public class ModInfoModel : I18nModel new Line(food.Description.Value, food.I18nDatas[cultureName].Description.Value) ); } - foreach (var lowText in LowTexts) + foreach (var text in LowTexts) { - lps.Add(new Line(lowText.Name.Value, lowText.I18nDatas[cultureName].Text.Value)); + lps.Add(new Line(text.Name.Value, text.I18nDatas[cultureName].Text.Value)); } - foreach (var clickText in ClickTexts) + foreach (var text in ClickTexts) { - lps.Add( - new Line(clickText.Name.Value, clickText.I18nDatas[cultureName].Text.Value) - ); + lps.Add(new Line(text.Name.Value, text.I18nDatas[cultureName].Text.Value)); + } + foreach (var text in SelectTexts) + { + lps.Add(new Line(text.Name.Value, text.I18nDatas[cultureName].Text.Value)); + lps.Add(new Line(text.Choose.Value, text.I18nDatas[cultureName].Choose.Value)); } File.WriteAllText(cultureFile, lps.ToString()); } @@ -217,7 +254,10 @@ public class ModInfoModel : I18nModel foreach (var food in Foods) { var foodImagePath = Utils.GetImageSourceFile(food.Image.Value); - var targetImagePath = Path.Combine(foodPath, Path.GetFileName(foodImagePath)); + var targetImagePath = Path.Combine( + foodPath, + $"{food.Name.Value}{Path.GetExtension(foodImagePath)}" + ); if (foodImagePath != targetImagePath) File.Copy(foodImagePath, targetImagePath, true); } diff --git a/VPet.ModMaker/Models/ModLoader.cs b/VPet.ModMaker/Models/ModLoader.cs index f23f929..9607918 100644 --- a/VPet.ModMaker/Models/ModLoader.cs +++ b/VPet.ModMaker/Models/ModLoader.cs @@ -36,10 +36,12 @@ public class ModLoader public List Pets { get; } = new(); public List Foods { get; } = new(); public List LowTexts { get; } = new(); + public List ClickTexts { get; } = new(); + public List SelectTexts { get; } = new(); + public Dictionary I18nDatas { get; } = new(); public Dictionary> OtherI18nDatas { get; } = new(); - public List ClickTexts { get; } = new(); public ModLoader(DirectoryInfo directory) { @@ -142,11 +144,11 @@ public class ModLoader case "clicktext": ClickTexts.Add(LPSConvert.DeserializeObject(li)); break; - //case "selecttext": - // mw.SelectTexts.Add( - // LPSConvert.DeserializeObject(li) - // ); - // break; + case "selecttext": + SelectTexts.Add( + LPSConvert.DeserializeObject(li) + ); + break; } } } diff --git a/VPet.ModMaker/Models/SelectTextModel.cs b/VPet.ModMaker/Models/SelectTextModel.cs index 31b76c3..34d6974 100644 --- a/VPet.ModMaker/Models/SelectTextModel.cs +++ b/VPet.ModMaker/Models/SelectTextModel.cs @@ -6,21 +6,128 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using VPet.ModMaker.Models; +using VPet_Simulator.Windows.Interface; namespace VPet.ModMaker.Models; -public class SelectTextModel : ClickTextModel +public class SelectTextModel : I18nModel { - public ObservableValue Exp { get; } = new(); - public ObservableValue Money { get; } = new(); - public ObservableValue Strength { get; } = new(); - public ObservableValue StrengthFood { get; } = new(); - public ObservableValue StrengthDrink { get; } = new(); - public ObservableValue Feeling { get; } = new(); - public ObservableValue Health { get; } = new(); - public ObservableValue Likability { get; } = new(); + public static ObservableCollection ModeTypes => ClickTextModel.ModeTypes; + + //public ObservableValue Exp { get; } = new(); + //public ObservableValue Money { get; } = new(); + //public ObservableValue Strength { get; } = new(); + //public ObservableValue StrengthFood { get; } = new(); + //public ObservableValue StrengthDrink { get; } = new(); + //public ObservableValue Feeling { get; } = new(); + //public ObservableValue Health { get; } = new(); + //public ObservableValue Likability { get; } = new(); + public ObservableValue Tags { get; } = new(); public ObservableValue ToTags { get; } = new(); - public SelectTextModel() { } + public ObservableValue Name { get; } = new(); + public ObservableValue Choose { get; } = new(); + public ObservableValue Mode { get; } = new(); + + //public ObservableValue Working { get; } = new(); + //public ObservableValue WorkingState { get; } = new(); + //public ObservableValue DayTime { get; } = new(); + + public ObservableRange Like { get; } = new(0, int.MaxValue); + public ObservableRange Health { get; } = new(0, int.MaxValue); + public ObservableRange Level { get; } = new(0, int.MaxValue); + public ObservableRange Money { get; } = new(int.MinValue, int.MaxValue); + public ObservableRange Food { get; } = new(0, int.MaxValue); + public ObservableRange Drink { get; } = new(0, int.MaxValue); + public ObservableRange Feel { get; } = new(0, int.MaxValue); + public ObservableRange Strength { get; } = new(0, int.MaxValue); + + public SelectTextModel() + { + Choose.Value = $"{Name.Value}_{nameof(Choose)}"; + Name.ValueChanged += (v) => + { + Choose.Value = $"{v}_{nameof(Choose)}"; + }; + } + + public SelectTextModel(SelectTextModel model) + : this() + { + Name.Value = model.Name.Value; + Mode.Value = model.Mode.Value; + //Working.Value = model.Working.Value; + //WorkingState.Value = model.WorkingState.Value; + //DayTime.Value = model.DayTime.Value; + Like = model.Like.Copy(); + Health = model.Health.Copy(); + Level = model.Level.Copy(); + Money = model.Money.Copy(); + Food = model.Food.Copy(); + Drink = model.Drink.Copy(); + Feel = model.Feel.Copy(); + Strength = model.Strength.Copy(); + foreach (var item in model.I18nDatas) + { + I18nDatas[item.Key] = new(); + I18nDatas[item.Key].Text.Value = model.I18nDatas[item.Key].Text.Value; + I18nDatas[item.Key].Choose.Value = model.I18nDatas[item.Key].Choose.Value; + } + CurrentI18nData.Value = I18nDatas[I18nHelper.Current.CultureName.Value]; + } + + public SelectTextModel(SelectText text) + : this() + { + Name.Value = text.Text; + Choose.Value = text.Choose ?? string.Empty; + Mode.Value = text.Mode; + //Working.Value = text.Working; + //WorkingState.Value = text.State; + //DayTime.Value = text.DaiTime; + Like.SetValue(text.LikeMin, text.LikeMax); + Health.SetValue(text.HealthMin, text.HealthMax); + Level.SetValue(text.LevelMin, text.LevelMax); + Money.SetValue(text.MoneyMin, text.MoneyMax); + Food.SetValue(text.FoodMin, text.FoodMax); + Drink.SetValue(text.DrinkMin, text.DrinkMax); + Feel.SetValue(text.FeelMin, text.FeelMax); + Strength.SetValue(text.StrengthMin, text.StrengthMax); + } + + public SelectText ToSelectText() + { + return new() + { + Text = Name.Value, + Choose = Choose.Value, + Mode = Mode.Value, + //Working = Working.Value, + //State = WorkingState.Value, + //DaiTime = DayTime.Value, + LikeMax = Like.Max.Value, + LikeMin = Like.Min.Value, + HealthMin = Health.Min.Value, + HealthMax = Health.Max.Value, + LevelMin = Level.Min.Value, + LevelMax = Level.Max.Value, + MoneyMin = Money.Min.Value, + MoneyMax = Money.Max.Value, + FoodMin = Food.Min.Value, + FoodMax = Food.Max.Value, + DrinkMin = Drink.Min.Value, + DrinkMax = Drink.Max.Value, + FeelMin = Feel.Min.Value, + FeelMax = Feel.Max.Value, + StrengthMin = Strength.Min.Value, + StrengthMax = Strength.Max.Value, + }; + } +} + +public class I18nSelectTextModel +{ + public ObservableValue Choose { get; } = new(); + public ObservableValue Text { get; } = new(); } diff --git a/VPet.ModMaker/VPet.ModMaker.csproj b/VPet.ModMaker/VPet.ModMaker.csproj index 7d2a622..d3746f1 100644 --- a/VPet.ModMaker/VPet.ModMaker.csproj +++ b/VPet.ModMaker/VPet.ModMaker.csproj @@ -112,6 +112,8 @@ + + ClickTextPage.xaml @@ -262,8 +264,6 @@ false - - - + \ No newline at end of file diff --git a/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs index 92913b1..2db20ad 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs @@ -51,28 +51,36 @@ public class ModEditWindowVM if (I18nHelper.Current.CultureNames.Count > 0) { I18nHelper.Current.CultureName.Value = I18nHelper.Current.CultureNames.First(); - foreach (var i18n in ModInfo.Value.OtherI18nDatas) + foreach (var i18nData in ModInfo.Value.OtherI18nDatas) { foreach (var food in ModInfo.Value.Foods) { - var foodI18n = food.I18nDatas[i18n.Key]; - if (i18n.Value.TryGetValue(food.Name.Value, out var name)) + var foodI18n = food.I18nDatas[i18nData.Key]; + if (i18nData.Value.TryGetValue(food.Name.Value, out var name)) foodI18n.Name.Value = name; - if (i18n.Value.TryGetValue(food.Description.Value, out var description)) + if (i18nData.Value.TryGetValue(food.Description.Value, out var description)) foodI18n.Description.Value = description; } foreach (var lowText in ModInfo.Value.LowTexts) { - var lowTextI18n = lowText.I18nDatas[i18n.Key]; - if (i18n.Value.TryGetValue(lowText.Name.Value, out var text)) + var lowTextI18n = lowText.I18nDatas[i18nData.Key]; + if (i18nData.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.Name.Value, out var text)) + var clickTextI18n = clickText.I18nDatas[i18nData.Key]; + if (i18nData.Value.TryGetValue(clickText.Name.Value, out var text)) clickTextI18n.Text.Value = text; } + foreach (var selectText in ModInfo.Value.SelectTexts) + { + var selectTextI18n = selectText.I18nDatas[i18nData.Key]; + if (i18nData.Value.TryGetValue(selectText.Name.Value, out var text)) + selectTextI18n.Text.Value = text; + if (i18nData.Value.TryGetValue(selectText.Choose.Value, out var choose)) + selectTextI18n.Choose.Value = choose; + } } } diff --git a/VPet.ModMaker/ViewModels/ModEdit/SelectTextEdit/SelectTextEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/SelectTextEdit/SelectTextEditWindowVM.cs new file mode 100644 index 0000000..23e1e65 --- /dev/null +++ b/VPet.ModMaker/ViewModels/ModEdit/SelectTextEdit/SelectTextEditWindowVM.cs @@ -0,0 +1,17 @@ +using HKW.HKWViewModels.SimpleObservable; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using VPet.ModMaker.Models; + +namespace VPet.ModMaker.ViewModels.ModEdit.SelectTextEdit; + +public class SelectTextEditWindowVM +{ + #region Value + public SelectTextModel OldSelectText { get; set; } + public ObservableValue SelectText { get; } = new(new()); + #endregion +} diff --git a/VPet.ModMaker/ViewModels/ModEdit/SelectTextEdit/SelectTextPageVM.cs b/VPet.ModMaker/ViewModels/ModEdit/SelectTextEdit/SelectTextPageVM.cs new file mode 100644 index 0000000..b42a196 --- /dev/null +++ b/VPet.ModMaker/ViewModels/ModEdit/SelectTextEdit/SelectTextPageVM.cs @@ -0,0 +1,95 @@ +using HKW.HKWViewModels.SimpleObservable; +using LinePutScript.Localization.WPF; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using VPet.ModMaker.Models; +using VPet.ModMaker.Views.ModEdit.SelectTextEdit; + +namespace VPet.ModMaker.ViewModels.ModEdit.SelectTextEdit; + +public class SelectTextPageVM +{ + #region Value + public ObservableValue> ShowSelectTexts { get; } = new(); + public ObservableCollection SelectTexts => ModInfoModel.Current.SelectTexts; + public ObservableValue FilterSelectText { get; } = new(); + #endregion + #region Command + public ObservableCommand AddSelectTextCommand { get; } = new(); + public ObservableCommand EditSelectTextCommand { get; } = new(); + public ObservableCommand RemoveSelectTextCommand { get; } = new(); + #endregion + + public SelectTextPageVM() + { + ShowSelectTexts.Value = SelectTexts; + FilterSelectText.ValueChanged += FilterSelectText_ValueChanged; + AddSelectTextCommand.ExecuteEvent += AddSelectText; + EditSelectTextCommand.ExecuteEvent += EditSelectText; + RemoveSelectTextCommand.ExecuteEvent += RemoveSelectText; + } + + private void FilterSelectText_ValueChanged(string value) + { + if (string.IsNullOrWhiteSpace(value)) + { + ShowSelectTexts.Value = SelectTexts; + } + else + { + ShowSelectTexts.Value = new( + SelectTexts.Where(f => f.CurrentI18nData.Value.Text.Value.Contains(value)) + ); + } + } + + private void AddSelectText() + { + var window = new SelectTextEditWindow(); + var vm = window.ViewModel; + window.ShowDialog(); + if (window.IsCancel) + return; + SelectTexts.Add(vm.SelectText.Value); + } + + public void EditSelectText(SelectTextModel model) + { + var window = new SelectTextEditWindow(); + var vm = window.ViewModel; + vm.OldSelectText = model; + var newLowTest = vm.SelectText.Value = new(model); + window.ShowDialog(); + if (window.IsCancel) + return; + if (ShowSelectTexts.Value.Count == SelectTexts.Count) + { + SelectTexts[SelectTexts.IndexOf(model)] = newLowTest; + } + else + { + SelectTexts[SelectTexts.IndexOf(model)] = newLowTest; + ShowSelectTexts.Value[ShowSelectTexts.Value.IndexOf(model)] = newLowTest; + } + } + + private void RemoveSelectText(SelectTextModel model) + { + if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No) + return; + if (ShowSelectTexts.Value.Count == SelectTexts.Count) + { + SelectTexts.Remove(model); + } + else + { + ShowSelectTexts.Value.Remove(model); + SelectTexts.Remove(model); + } + } +} diff --git a/VPet.ModMaker/Views/ModEdit/ClickTextEdit/ClickTextEditWindow.xaml b/VPet.ModMaker/Views/ModEdit/ClickTextEdit/ClickTextEditWindow.xaml index af23025..fa60ee2 100644 --- a/VPet.ModMaker/Views/ModEdit/ClickTextEdit/ClickTextEditWindow.xaml +++ b/VPet.ModMaker/Views/ModEdit/ClickTextEdit/ClickTextEditWindow.xaml @@ -42,7 +42,7 @@ x:Name="TextBox_Text" Grid.Row="1" d:Text="这是一个测试文本,这是一个测试文本,这是一个测试文本,这是一个测试文本,这是一个测试文本,这是一个测试文本,这是一个测试文本," - pu:TextBoxHelper.Watermark="文本" + pu:TextBoxHelper.Watermark="{ll:Str 文本}" Style="{StaticResource TextBox_Wrap}" Text="{Binding ClickText.Value.CurrentI18nData.Value.Text.Value, UpdateSourceTrigger=PropertyChanged}" /> @@ -66,7 +66,10 @@