diff --git a/VPet.ModMaker/Models/ClickTextModel.cs b/VPet.ModMaker/Models/ClickTextModel.cs index b4eeda0..283c2a0 100644 --- a/VPet.ModMaker/Models/ClickTextModel.cs +++ b/VPet.ModMaker/Models/ClickTextModel.cs @@ -56,10 +56,7 @@ public class ClickTextModel : I18nModel Feel = clickText.Feel.Copy(); Strength = clickText.Strength.Copy(); foreach (var item in clickText.I18nDatas) - { - I18nDatas[item.Key] = new(); - I18nDatas[item.Key].Text.Value = clickText.I18nDatas[item.Key].Text.Value; - } + I18nDatas[item.Key] = item.Value.Copy(); CurrentI18nData.Value = I18nDatas[I18nHelper.Current.CultureName.Value]; } @@ -113,4 +110,11 @@ public class ClickTextModel : I18nModel public class I18nClickTextModel { public ObservableValue Text { get; } = new(); + + public I18nClickTextModel Copy() + { + var result = new I18nClickTextModel(); + result.Text.Value = Text.Value; + return result; + } } diff --git a/VPet.ModMaker/Models/Expansions.cs b/VPet.ModMaker/Models/Expansions.cs new file mode 100644 index 0000000..41dbe8d --- /dev/null +++ b/VPet.ModMaker/Models/Expansions.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VPet.ModMaker.Models; + +public static class Extensions +{ + public static bool Contains(this string source, string value, StringComparison comparisonType) + { + return source.IndexOf(value, comparisonType) >= 0; + } +} diff --git a/VPet.ModMaker/Models/FoodModel.cs b/VPet.ModMaker/Models/FoodModel.cs index 5773f75..e6b859d 100644 --- a/VPet.ModMaker/Models/FoodModel.cs +++ b/VPet.ModMaker/Models/FoodModel.cs @@ -39,28 +39,24 @@ public class FoodModel : I18nModel }; } - public FoodModel(FoodModel food) + public FoodModel(FoodModel model) : this() { - Name.Value = food.Name.Value; - Description.Value = food.Description.Value; - Graph.Value = food.Graph.Value; - Type.Value = food.Type.Value; - Strength.Value = food.Strength.Value; - StrengthFood.Value = food.StrengthFood.Value; - StrengthDrink.Value = food.StrengthDrink.Value; - Feeling.Value = food.Feeling.Value; - Health.Value = food.Health.Value; - Likability.Value = food.Likability.Value; - Price.Value = food.Price.Value; - Exp.Value = food.Exp.Value; - Image.Value = Utils.LoadImageToStream(food.Image.Value); - foreach (var item in food.I18nDatas) - { - I18nDatas[item.Key] = new(); - I18nDatas[item.Key].Name.Value = food.I18nDatas[item.Key].Name.Value; - I18nDatas[item.Key].Description.Value = food.I18nDatas[item.Key].Description.Value; - } + Name.Value = model.Name.Value; + Description.Value = model.Description.Value; + Graph.Value = model.Graph.Value; + Type.Value = model.Type.Value; + Strength.Value = model.Strength.Value; + StrengthFood.Value = model.StrengthFood.Value; + StrengthDrink.Value = model.StrengthDrink.Value; + Feeling.Value = model.Feeling.Value; + Health.Value = model.Health.Value; + Likability.Value = model.Likability.Value; + Price.Value = model.Price.Value; + Exp.Value = model.Exp.Value; + Image.Value = Utils.LoadImageToStream(model.Image.Value); + foreach (var item in model.I18nDatas) + I18nDatas[item.Key] = item.Value.Copy(); CurrentI18nData.Value = I18nDatas[I18nHelper.Current.CultureName.Value]; } @@ -112,4 +108,12 @@ public class I18nFoodModel { public ObservableValue Name { get; } = new(); public ObservableValue Description { get; } = new(); + + public I18nFoodModel Copy() + { + var result = new I18nFoodModel(); + result.Name.Value = Name.Value; + result.Description.Value = Description.Value; + return result; + } } diff --git a/VPet.ModMaker/Models/LowTextModel.cs b/VPet.ModMaker/Models/LowTextModel.cs index 3c39ad0..f415577 100644 --- a/VPet.ModMaker/Models/LowTextModel.cs +++ b/VPet.ModMaker/Models/LowTextModel.cs @@ -33,11 +33,9 @@ public class LowTextModel : I18nModel Mode.Value = lowText.Mode.Value; Strength.Value = lowText.Strength.Value; Like.Value = lowText.Like.Value; + foreach (var item in lowText.I18nDatas) - { - I18nDatas[item.Key] = item.Value; - I18nDatas[item.Key].Text.Value = lowText.I18nDatas[item.Key].Text.Value; - } + I18nDatas[item.Key] = item.Value.Copy(); CurrentI18nData.Value = I18nDatas[I18nHelper.Current.CultureName.Value]; } @@ -67,4 +65,11 @@ public class LowTextModel : I18nModel public class I18nLowTextModel { public ObservableValue Text { get; } = new(); + + public I18nLowTextModel Copy() + { + var result = new I18nLowTextModel(); + result.Text.Value = Text.Value; + return result; + } } diff --git a/VPet.ModMaker/Models/ModInfoModel.cs b/VPet.ModMaker/Models/ModInfoModel.cs index f42185b..fec9342 100644 --- a/VPet.ModMaker/Models/ModInfoModel.cs +++ b/VPet.ModMaker/Models/ModInfoModel.cs @@ -17,6 +17,7 @@ namespace VPet.ModMaker.Models; public class ModInfoModel : I18nModel { + public const string ModInfoFile = "info.lps"; public static ModInfoModel Current { get; set; } = new(); public ObservableValue Name { get; } = new(); @@ -26,11 +27,13 @@ public class ModInfoModel : I18nModel public ObservableValue GameVersion { get; } = new(); public ObservableValue ModVersion { get; } = new(); public ObservableValue Image { get; } = new(); + public ObservableValue SourcePath { get; } = new(); + public ObservableCollection Foods { get; } = new(); public ObservableCollection ClickTexts { get; } = new(); public ObservableCollection LowTexts { get; } = new(); public ObservableCollection SelectTexts { get; } = new(); - public ObservableValue SourcePath { get; } = new(); + public ObservableCollection Pets { get; } = new(); public Dictionary> OtherI18nDatas { get; } = new(); @@ -63,23 +66,76 @@ public class ModInfoModel : I18nModel LowTexts.Add(new(lowText)); foreach (var selectText in loader.SelectTexts) SelectTexts.Add(new(selectText)); + foreach (var pet in loader.Pets) + Pets.Add(new(pet)); - Summary.Value = GetSummary(); foreach (var lang in loader.I18nDatas) I18nDatas.Add(lang.Key, lang.Value); OtherI18nDatas = loader.OtherI18nDatas; + + LoadI18nData(); } - public string GetSummary() + private void LoadI18nData() { - return @"包含以下内容: -食物: {0} -点击文本: {1} -低状态文本: {2}".Translate(Foods.Count, ClickTexts.Count, LowTexts.Count); + foreach (var lang in I18nDatas) + { + if (I18nHelper.Current.CultureNames.Contains(lang.Key) is false) + I18nHelper.Current.CultureNames.Add(lang.Key); + } + if (I18nHelper.Current.CultureNames.Count > 0) + { + I18nHelper.Current.CultureName.Value = I18nHelper.Current.CultureNames.First(); + foreach (var i18nData in OtherI18nDatas) + { + foreach (var food in Foods) + { + var foodI18n = food.I18nDatas[i18nData.Key]; + if (i18nData.Value.TryGetValue(food.Name.Value, out var name)) + foodI18n.Name.Value = name; + if (i18nData.Value.TryGetValue(food.Description.Value, out var description)) + foodI18n.Description.Value = description; + } + foreach (var lowText in LowTexts) + { + var lowTextI18n = lowText.I18nDatas[i18nData.Key]; + if (i18nData.Value.TryGetValue(lowText.Name.Value, out var text)) + lowTextI18n.Text.Value = text; + } + foreach (var clickText in ClickTexts) + { + var clickTextI18n = clickText.I18nDatas[i18nData.Key]; + if (i18nData.Value.TryGetValue(clickText.Name.Value, out var text)) + clickTextI18n.Text.Value = text; + } + foreach (var selectText in 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; + } + foreach (var pet in Pets) + { + var petI18n = pet.I18nDatas[i18nData.Key]; + if (i18nData.Value.TryGetValue(pet.Name.Value, out var name)) + petI18n.Name.Value = name; + if (i18nData.Value.TryGetValue(pet.PetName.Value, out var petName)) + petI18n.PetName.Value = petName; + if (i18nData.Value.TryGetValue(pet.Description.Value, out var description)) + petI18n.Description.Value = description; + foreach (var work in pet.Works) + { + var workI18n = work.I18nDatas[i18nData.Key]; + if (i18nData.Value.TryGetValue(work.Name.Value, out var workName)) + workI18n.Name.Value = workName; + } + } + } + } } - public const string ModInfoFile = "info.lps"; - public void Save() { SaveTo(SourcePath.Value); diff --git a/VPet.ModMaker/Models/PetModel.cs b/VPet.ModMaker/Models/PetModel.cs index 0997e4f..82996ba 100644 --- a/VPet.ModMaker/Models/PetModel.cs +++ b/VPet.ModMaker/Models/PetModel.cs @@ -1,55 +1,210 @@ using HKW.HKWViewModels.SimpleObservable; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Media.Imaging; +using VPet_Simulator.Core; namespace VPet.ModMaker.Models; public class PetModel : I18nModel { - public ObservableValue Id { get; } = new(); - public ObservableValue Image { get; } = new(); - public ObservableValue TouchHeadRect { get; } = new(new()); - public ObservableValue TouchRaisedRect { get; } = new(new()); - public ObservableValue RaisePoint { get; } = new(new()); + public ObservableValue Name { get; } = new(); + public ObservableValue PetName { get; } = new(); + public ObservableValue Description { get; } = new(); + public ObservableValue> TouchHeadRect { get; } = new(new()); + public ObservableValue TouchRaisedRect { get; } = new(new()); + public ObservableValue RaisePoint { get; } = new(new()); + + public ObservableCollection Works { get; } = new(); + + public PetModel() + { + PetName.Value = $"{Name.Value}_{nameof(PetName)}"; + Description.Value = $"{Name.Value}_{nameof(Description)}"; + Name.ValueChanged += (v) => + { + PetName.Value = $"{v}_{nameof(PetName)}"; + Description.Value = $"{v}_{nameof(Description)}"; + }; + } + + public PetModel(PetModel model) + : this() + { + Name.Value = model.Name.Value; + TouchHeadRect.Value = model.TouchHeadRect.Value.Copy(); + TouchRaisedRect.Value = model.TouchRaisedRect.Value.Copy(); + RaisePoint.Value = model.RaisePoint.Value.Copy(); + foreach (var work in model.Works) + Works.Add(work); + + foreach (var item in model.I18nDatas) + I18nDatas[item.Key] = item.Value.Copy(); + CurrentI18nData.Value = I18nDatas[I18nHelper.Current.CultureName.Value]; + } + + public PetModel(PetLoader loader) + : this() + { + Name.Value = loader.Name; + PetName.Value = loader.PetName; + Description.Value = loader.Intor; + + TouchHeadRect.Value.SetValue( + loader.Config.TouchHeadLocate.X, + loader.Config.TouchHeadLocate.Y, + loader.Config.TouchHeadSize.Width, + loader.Config.TouchHeadSize.Height + ); + + TouchRaisedRect.Value.Happy.Value.SetValue( + loader.Config.TouchRaisedLocate[0].X, + loader.Config.TouchRaisedLocate[0].Y, + loader.Config.TouchRaisedSize[0].Width, + loader.Config.TouchRaisedSize[0].Height + ); + TouchRaisedRect.Value.Nomal.Value.SetValue( + loader.Config.TouchRaisedLocate[1].X, + loader.Config.TouchRaisedLocate[1].Y, + loader.Config.TouchRaisedSize[1].Width, + loader.Config.TouchRaisedSize[1].Height + ); + TouchRaisedRect.Value.PoorCondition.Value.SetValue( + loader.Config.TouchRaisedLocate[2].X, + loader.Config.TouchRaisedLocate[2].Y, + loader.Config.TouchRaisedSize[2].Width, + loader.Config.TouchRaisedSize[2].Height + ); + TouchRaisedRect.Value.Ill.Value.SetValue( + loader.Config.TouchRaisedLocate[3].X, + loader.Config.TouchRaisedLocate[3].Y, + loader.Config.TouchRaisedSize[3].Width, + loader.Config.TouchRaisedSize[3].Height + ); + + RaisePoint.Value.Happy.Value.SetValue( + loader.Config.RaisePoint[0].X, + loader.Config.RaisePoint[0].Y + ); + RaisePoint.Value.Nomal.Value.SetValue( + loader.Config.RaisePoint[1].X, + loader.Config.RaisePoint[1].Y + ); + RaisePoint.Value.PoorCondition.Value.SetValue( + loader.Config.RaisePoint[2].X, + loader.Config.RaisePoint[2].Y + ); + RaisePoint.Value.Ill.Value.SetValue( + loader.Config.RaisePoint[3].X, + loader.Config.RaisePoint[3].Y + ); + + foreach (var work in loader.Config.Works) + Works.Add(new(work)); + } + + public void Close() { } } public class I18nPetInfoModel { - public ObservableValue Name { get; set; } = new(); - public ObservableValue Description { get; set; } = new(); + public ObservableValue Name { get; } = new(); + public ObservableValue PetName { get; } = new(); + public ObservableValue Description { get; } = new(); + + public I18nPetInfoModel Copy() + { + var result = new I18nPetInfoModel(); + result.Name.Value = Name.Value; + result.PetName.Value = PetName.Value; + result.Description.Value = Description.Value; + return result; + } } -public class MultiStateRect +public class ObservableMultiStateRect { - public ObservableValue Happy { get; } = new(new()); - public ObservableValue Nomal { get; } = new(new()); - public ObservableValue PoorCondition { get; } = new(new()); - public ObservableValue Ill { get; } = new(new()); + public ObservableValue> Happy { get; } = new(new()); + public ObservableValue> Nomal { get; } = new(new()); + public ObservableValue> PoorCondition { get; } = new(new()); + public ObservableValue> Ill { get; } = new(new()); + + public ObservableMultiStateRect Copy() + { + var result = new ObservableMultiStateRect(); + result.Happy.Value = Happy.Value.Copy(); + result.Nomal.Value = Nomal.Value.Copy(); + result.PoorCondition.Value = PoorCondition.Value.Copy(); + result.Ill.Value = Ill.Value.Copy(); + return result; + } } -public class MultiStatePoint +public class ObservableMultiStatePoint { - public ObservableValue Happy { get; } = new(new()); - public ObservableValue Nomal { get; } = new(new()); - public ObservableValue PoorCondition { get; } = new(new()); - public ObservableValue Ill { get; } = new(new()); + public ObservableValue> Happy { get; } = new(new()); + public ObservableValue> Nomal { get; } = new(new()); + public ObservableValue> PoorCondition { get; } = new(new()); + public ObservableValue> Ill { get; } = new(new()); + + public ObservableMultiStatePoint Copy() + { + var result = new ObservableMultiStatePoint(); + result.Happy.Value = Happy.Value.Copy(); + result.Nomal.Value = Nomal.Value.Copy(); + result.PoorCondition.Value = PoorCondition.Value.Copy(); + result.Ill.Value = Ill.Value.Copy(); + return result; + } } -public class ObservableInt32Rect +public class ObservableRect { - public ObservableValue X { get; } = new(); - public ObservableValue Y { get; } = new(); - public ObservableValue Width { get; } = new(); - public ObservableValue Height { get; } = new(); + public ObservableValue X { get; } = new(); + public ObservableValue Y { get; } = new(); + public ObservableValue Width { get; } = new(); + public ObservableValue Height { get; } = new(); + + public void SetValue(T x, T y, T width, T hetght) + { + X.Value = x; + Y.Value = y; + Width.Value = width; + Height.Value = hetght; + } + + public ObservableRect Copy() + { + var result = new ObservableRect(); + result.X.Value = X.Value; + result.Y.Value = Y.Value; + result.Width.Value = Width.Value; + result.Height.Value = Height.Value; + return result; + } } -public class ObservablePoint +public class ObservablePoint { - public ObservableValue X { get; } = new(); - public ObservableValue Y { get; } = new(); + public ObservableValue X { get; } = new(); + public ObservableValue Y { get; } = new(); + + public void SetValue(T x, T y) + { + X.Value = x; + Y.Value = y; + } + + public ObservablePoint Copy() + { + var result = new ObservablePoint(); + result.X.Value = X.Value; + result.Y.Value = Y.Value; + return result; + } } diff --git a/VPet.ModMaker/Models/SelectTextModel.cs b/VPet.ModMaker/Models/SelectTextModel.cs index 34d6974..1032b17 100644 --- a/VPet.ModMaker/Models/SelectTextModel.cs +++ b/VPet.ModMaker/Models/SelectTextModel.cs @@ -57,6 +57,8 @@ public class SelectTextModel : I18nModel { Name.Value = model.Name.Value; Mode.Value = model.Mode.Value; + Tags.Value = model.Tags.Value; + ToTags.Value = model.ToTags.Value; //Working.Value = model.Working.Value; //WorkingState.Value = model.WorkingState.Value; //DayTime.Value = model.DayTime.Value; @@ -68,12 +70,9 @@ public class SelectTextModel : I18nModel 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; - } + I18nDatas[item.Key] = item.Value.Copy(); CurrentI18nData.Value = I18nDatas[I18nHelper.Current.CultureName.Value]; } @@ -83,6 +82,8 @@ public class SelectTextModel : I18nModel Name.Value = text.Text; Choose.Value = text.Choose ?? string.Empty; Mode.Value = text.Mode; + Tags.Value = text.Tags is null ? string.Empty : string.Join(", ", text.Tags); + ToTags.Value = text.ToTags is null ? string.Empty : string.Join(", ", text.ToTags); //Working.Value = text.Working; //WorkingState.Value = text.State; //DayTime.Value = text.DaiTime; @@ -96,6 +97,8 @@ public class SelectTextModel : I18nModel Strength.SetValue(text.StrengthMin, text.StrengthMax); } + private readonly static char[] rs_splitChar = { ',', ' ' }; + public SelectText ToSelectText() { return new() @@ -103,6 +106,8 @@ public class SelectTextModel : I18nModel Text = Name.Value, Choose = Choose.Value, Mode = Mode.Value, + Tags = new(Tags.Value.Split(rs_splitChar, StringSplitOptions.RemoveEmptyEntries)), + ToTags = new(ToTags.Value.Split(rs_splitChar, StringSplitOptions.RemoveEmptyEntries)), //Working = Working.Value, //State = WorkingState.Value, //DaiTime = DayTime.Value, @@ -130,4 +135,12 @@ public class I18nSelectTextModel { public ObservableValue Choose { get; } = new(); public ObservableValue Text { get; } = new(); + + public I18nSelectTextModel Copy() + { + var result = new I18nSelectTextModel(); + result.Text.Value = Text.Value; + result.Choose.Value = Choose.Value; + return result; + } } diff --git a/VPet.ModMaker/Models/WorkModel.cs b/VPet.ModMaker/Models/WorkModel.cs new file mode 100644 index 0000000..a5f7ffb --- /dev/null +++ b/VPet.ModMaker/Models/WorkModel.cs @@ -0,0 +1,142 @@ +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 WorkModel : I18nModel +{ + public static ObservableCollection WorkTypes { get; } = + new( + Enum.GetValues(typeof(VPet_Simulator.Core.GraphHelper.Work.WorkType)) + .Cast() + ); + + //public VPet_Simulator.Core.GraphHelper.Work + public ObservableValue WorkType { get; } = + new(VPet_Simulator.Core.GraphHelper.Work.WorkType.Work); + + public ObservableValue Name { get; } = new(); + public ObservableValue Graph { get; } = new(); + + public ObservableValue MoneyLevel { get; } = new(); + public ObservableValue MoneyBase { get; } = new(); + public ObservableValue StrengthFood { get; } = new(); + public ObservableValue StrengthDrink { get; } = new(); + public ObservableValue Feeling { get; } = new(); + public ObservableValue LevelLimit { get; } = new(); + public ObservableValue Time { get; } = new(); + public ObservableValue FinishBonus { get; } = new(); + + public ObservableValue BorderBrush { get; } = new("0290D5"); + public ObservableValue Background { get; } = new("81d4fa"); + public ObservableValue ButtonBackground { get; } = new("0286C6"); + public ObservableValue ButtonForeground { get; } = new("ffffff"); + public ObservableValue Foreground { get; } = new("0286C6"); + + public ObservableValue Left { get; } = new(100); + public ObservableValue Top { get; } = new(160); + public ObservableValue Width { get; } = new(300); + + public WorkModel() { } + + public WorkModel(WorkModel model) + : this() + { + WorkType.Value = model.WorkType.Value; + Name.Value = model.Name.Value; + Graph.Value = model.Graph.Value; + MoneyLevel.Value = model.MoneyLevel.Value; + MoneyBase.Value = model.MoneyBase.Value; + StrengthFood.Value = model.StrengthFood.Value; + StrengthDrink.Value = model.StrengthDrink.Value; + Feeling.Value = model.Feeling.Value; + LevelLimit.Value = model.LevelLimit.Value; + Time.Value = model.Time.Value; + FinishBonus.Value = model.FinishBonus.Value; + + BorderBrush.Value = model.BorderBrush.Value; + Background.Value = model.Background.Value; + ButtonBackground.Value = model.ButtonBackground.Value; + ButtonForeground.Value = model.ButtonForeground.Value; + Foreground.Value = model.Foreground.Value; + + Left.Value = model.Left.Value; + Top.Value = model.Top.Value; + Width.Value = model.Width.Value; + + foreach (var item in model.I18nDatas) + I18nDatas[item.Key] = item.Value.Copy(); + CurrentI18nData.Value = I18nDatas[I18nHelper.Current.CultureName.Value]; + } + + public WorkModel(VPet_Simulator.Core.GraphHelper.Work work) + : this() + { + WorkType.Value = work.Type; + Name.Value = work.Name; + Graph.Value = work.Graph; + MoneyLevel.Value = work.MoneyLevel; + MoneyBase.Value = work.MoneyBase; + StrengthFood.Value = work.StrengthFood; + StrengthDrink.Value = work.StrengthDrink; + Feeling.Value = work.Feeling; + LevelLimit.Value = work.LevelLimit; + Time.Value = work.Time; + FinishBonus.Value = work.FinishBonus; + + BorderBrush.Value = work.BorderBrush; + Background.Value = work.Background; + ButtonBackground.Value = work.ButtonBackground; + ButtonForeground.Value = work.ButtonForeground; + Foreground.Value = work.Foreground; + + Left.Value = work.Left; + Top.Value = work.Top; + Width.Value = work.Width; + } + + public VPet_Simulator.Core.GraphHelper.Work ToWork() + { + return new() + { + Type = WorkType.Value, + Name = Name.Value, + Graph = Graph.Value, + MoneyLevel = MoneyLevel.Value, + MoneyBase = MoneyBase.Value, + StrengthFood = StrengthFood.Value, + StrengthDrink = StrengthDrink.Value, + Feeling = Feeling.Value, + LevelLimit = LevelLimit.Value, + Time = Time.Value, + FinishBonus = FinishBonus.Value, + // + BorderBrush = BorderBrush.Value, + Background = Background.Value, + ButtonBackground = ButtonBackground.Value, + ButtonForeground = ButtonForeground.Value, + Foreground = Foreground.Value, + // + Left = Left.Value, + Top = Top.Value, + Width = Width.Value, + }; + } +} + +public class I18nWorkModel +{ + public ObservableValue Name { get; } = new(); + + public I18nWorkModel Copy() + { + var result = new I18nWorkModel(); + result.Name.Value = Name.Value; + return result; + } +} diff --git a/VPet.ModMaker/VPet.ModMaker.csproj b/VPet.ModMaker/VPet.ModMaker.csproj index d3746f1..2ce01ae 100644 --- a/VPet.ModMaker/VPet.ModMaker.csproj +++ b/VPet.ModMaker/VPet.ModMaker.csproj @@ -92,6 +92,7 @@ + @@ -102,6 +103,7 @@ + @@ -114,6 +116,8 @@ + + ClickTextPage.xaml @@ -169,6 +173,12 @@ SelectTextEditWindow.xaml + + WorkEditWindow.xaml + + + WorkPage.xaml + ModMakerWindow.xaml @@ -243,6 +253,14 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/VPet.ModMaker/ViewModels/ModEdit/ClickTextEdit/ClickTextPageVM.cs b/VPet.ModMaker/ViewModels/ModEdit/ClickTextEdit/ClickTextPageVM.cs index a2f1eb9..e9088b7 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/ClickTextEdit/ClickTextPageVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/ClickTextEdit/ClickTextPageVM.cs @@ -17,38 +17,40 @@ public class ClickTextPageVM #region Value public ObservableValue> ShowClickTexts { get; } = new(); public ObservableCollection ClickTexts => ModInfoModel.Current.ClickTexts; - public ObservableValue FilterClickText { get; } = new(); + public ObservableValue Filter { get; } = new(); #endregion #region Command - public ObservableCommand AddClickTextCommand { get; } = new(); - public ObservableCommand EditClickTextCommand { get; } = new(); - public ObservableCommand RemoveClickTextCommand { get; } = new(); + public ObservableCommand AddCommand { get; } = new(); + public ObservableCommand EditCommand { get; } = new(); + public ObservableCommand RemoveCommand { get; } = new(); #endregion public ClickTextPageVM() { ShowClickTexts.Value = ClickTexts; - FilterClickText.ValueChanged += FilterClickText_ValueChanged; - AddClickTextCommand.ExecuteEvent += AddClickText; - EditClickTextCommand.ExecuteEvent += EditClickText; - RemoveClickTextCommand.ExecuteEvent += RemoveClickText; + Filter.ValueChanged += Filter_ValueChanged; + AddCommand.ExecuteEvent += Add; + EditCommand.ExecuteEvent += Edit; + RemoveCommand.ExecuteEvent += Remove; } - private void FilterClickText_ValueChanged(string value) + private void Filter_ValueChanged(string value) { - if (string.IsNullOrEmpty(value)) + if (string.IsNullOrWhiteSpace(value)) { ShowClickTexts.Value = ClickTexts; } else { ShowClickTexts.Value = new( - ClickTexts.Where(f => f.CurrentI18nData.Value.Text.Value.Contains(value)) + ClickTexts.Where( + m => m.Name.Value.Contains(value, StringComparison.OrdinalIgnoreCase) + ) ); } } - private void AddClickText() + private void Add() { var window = new ClickTextEditWindow(); var vm = window.ViewModel; @@ -58,38 +60,38 @@ public class ClickTextPageVM ClickTexts.Add(vm.ClickText.Value); } - public void EditClickText(ClickTextModel clickText) + public void Edit(ClickTextModel model) { var window = new ClickTextEditWindow(); var vm = window.ViewModel; - vm.OldClickText = clickText; - var newLowTest = vm.ClickText.Value = new(clickText); + vm.OldClickText = model; + var newLowTest = vm.ClickText.Value = new(model); window.ShowDialog(); if (window.IsCancel) return; if (ShowClickTexts.Value.Count == ClickTexts.Count) { - ClickTexts[ClickTexts.IndexOf(clickText)] = newLowTest; + ClickTexts[ClickTexts.IndexOf(model)] = newLowTest; } else { - ClickTexts[ClickTexts.IndexOf(clickText)] = newLowTest; - ShowClickTexts.Value[ShowClickTexts.Value.IndexOf(clickText)] = newLowTest; + ClickTexts[ClickTexts.IndexOf(model)] = newLowTest; + ShowClickTexts.Value[ShowClickTexts.Value.IndexOf(model)] = newLowTest; } } - private void RemoveClickText(ClickTextModel clickText) + private void Remove(ClickTextModel model) { if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No) return; if (ShowClickTexts.Value.Count == ClickTexts.Count) { - ClickTexts.Remove(clickText); + ClickTexts.Remove(model); } else { - ShowClickTexts.Value.Remove(clickText); - ClickTexts.Remove(clickText); + ShowClickTexts.Value.Remove(model); + ClickTexts.Remove(model); } } } diff --git a/VPet.ModMaker/ViewModels/ModEdit/FoodEdit/FoodEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/FoodEdit/FoodEditWindowVM.cs index 3aec3ca..7056fd1 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/FoodEdit/FoodEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/FoodEdit/FoodEditWindowVM.cs @@ -28,14 +28,14 @@ public class FoodEditWindowVM public FoodEditWindowVM() { - InitializeFoodTypes(); AddImageCommand.ExecuteEvent += AddImage; ChangeImageCommand.ExecuteEvent += ChangeImage; } - public void Close() { } - - private void InitializeFoodTypes() { } + public void Close() + { + Food.Value.Close(); + } private void AddImage() { diff --git a/VPet.ModMaker/ViewModels/ModEdit/FoodEdit/FoodPageVM.cs b/VPet.ModMaker/ViewModels/ModEdit/FoodEdit/FoodPageVM.cs index 4d6fb92..ccc6bca 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/FoodEdit/FoodPageVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/FoodEdit/FoodPageVM.cs @@ -19,40 +19,40 @@ public class FoodPageVM #region Value public ObservableValue> ShowFoods { get; } = new(); public ObservableCollection Foods => ModInfoModel.Current.Foods; - public ObservableValue FilterFoodText { get; } = new(); + public ObservableValue Filter { get; } = new(); #endregion #region Command - public ObservableCommand AddFoodCommand { get; } = new(); - public ObservableCommand EditFoodCommand { get; } = new(); - public ObservableCommand RemoveFoodCommand { get; } = new(); + public ObservableCommand AddCommand { get; } = new(); + public ObservableCommand EditCommand { get; } = new(); + public ObservableCommand RemoveCommand { get; } = new(); #endregion public FoodPageVM() { ShowFoods.Value = Foods; - FilterFoodText.ValueChanged += FilterFoodText_ValueChanged; + Filter.ValueChanged += Filter_ValueChanged; - AddFoodCommand.ExecuteEvent += AddFood; - EditFoodCommand.ExecuteEvent += EditFood; - RemoveFoodCommand.ExecuteEvent += RemoveFood; + AddCommand.ExecuteEvent += Add; + EditCommand.ExecuteEvent += Edit; + RemoveCommand.ExecuteEvent += Remove; } - private void FilterFoodText_ValueChanged(string value) + private void Filter_ValueChanged(string value) { - if (string.IsNullOrEmpty(value)) + if (string.IsNullOrWhiteSpace(value)) { ShowFoods.Value = Foods; } else { ShowFoods.Value = new( - Foods.Where(f => f.CurrentI18nData.Value.Name.Value.Contains(value)) + Foods.Where(m => m.Name.Value.Contains(value, StringComparison.OrdinalIgnoreCase)) ); } } public void Close() { } - private void AddFood() + private void Add() { var window = new FoodEditWindow(); var vm = window.ViewModel; @@ -62,7 +62,7 @@ public class FoodPageVM Foods.Add(vm.Food.Value); } - public void EditFood(FoodModel food) + public void Edit(FoodModel food) { var window = new FoodEditWindow(); var vm = window.ViewModel; @@ -83,7 +83,7 @@ public class FoodPageVM food.Close(); } - private void RemoveFood(FoodModel food) + private void Remove(FoodModel food) { if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No) return; diff --git a/VPet.ModMaker/ViewModels/ModEdit/LowTextEdit/LowTextPageVM.cs b/VPet.ModMaker/ViewModels/ModEdit/LowTextEdit/LowTextPageVM.cs index 12f072a..8a8e48f 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/LowTextEdit/LowTextPageVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/LowTextEdit/LowTextPageVM.cs @@ -18,40 +18,42 @@ namespace VPet.ModMaker.ViewModels.ModEdit.LowTextEdit; public class LowTextPageVM { #region Value - public ObservableValue FilterLowText { get; } = new(); public ObservableValue> ShowLowTexts { get; } = new(); public ObservableCollection LowTexts => ModInfoModel.Current.LowTexts; + public ObservableValue Filter { get; } = new(); #endregion #region Command - public ObservableCommand AddLowTextCommand { get; } = new(); - public ObservableCommand EditLowTextCommand { get; } = new(); - public ObservableCommand RemoveLowTextCommand { get; } = new(); + public ObservableCommand AddCommand { get; } = new(); + public ObservableCommand EditCommand { get; } = new(); + public ObservableCommand RemoveCommand { get; } = new(); #endregion public LowTextPageVM() { ShowLowTexts.Value = LowTexts; - FilterLowText.ValueChanged += FilterLowText_ValueChanged; - AddLowTextCommand.ExecuteEvent += AddLowText; - EditLowTextCommand.ExecuteEvent += EditLowText; - RemoveLowTextCommand.ExecuteEvent += RemoveLowText; + Filter.ValueChanged += Filter_ValueChanged; + AddCommand.ExecuteEvent += Add; + EditCommand.ExecuteEvent += Edit; + RemoveCommand.ExecuteEvent += Remove; } - private void FilterLowText_ValueChanged(string value) + private void Filter_ValueChanged(string value) { - if (string.IsNullOrEmpty(value)) + if (string.IsNullOrWhiteSpace(value)) { ShowLowTexts.Value = LowTexts; } else { ShowLowTexts.Value = new( - LowTexts.Where(f => f.CurrentI18nData.Value.Text.Value.Contains(value)) + LowTexts.Where( + m => m.Name.Value.Contains(value, StringComparison.OrdinalIgnoreCase) + ) ); } } - private void AddLowText() + private void Add() { var window = new LowTextEditWindow(); var vm = window.ViewModel; @@ -61,38 +63,38 @@ public class LowTextPageVM LowTexts.Add(vm.LowText.Value); } - public void EditLowText(LowTextModel lowText) + public void Edit(LowTextModel model) { var window = new LowTextEditWindow(); var vm = window.ViewModel; - vm.OldLowText = lowText; - var newLowTest = vm.LowText.Value = new(lowText); + vm.OldLowText = model; + var newLowTest = vm.LowText.Value = new(model); window.ShowDialog(); if (window.IsCancel) return; if (ShowLowTexts.Value.Count == LowTexts.Count) { - LowTexts[LowTexts.IndexOf(lowText)] = newLowTest; + LowTexts[LowTexts.IndexOf(model)] = newLowTest; } else { - LowTexts[LowTexts.IndexOf(lowText)] = newLowTest; - ShowLowTexts.Value[ShowLowTexts.Value.IndexOf(lowText)] = newLowTest; + LowTexts[LowTexts.IndexOf(model)] = newLowTest; + ShowLowTexts.Value[ShowLowTexts.Value.IndexOf(model)] = newLowTest; } } - private void RemoveLowText(LowTextModel lowText) + private void Remove(LowTextModel model) { if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No) return; if (ShowLowTexts.Value.Count == LowTexts.Count) { - LowTexts.Remove(lowText); + LowTexts.Remove(model); } else { - ShowLowTexts.Value.Remove(lowText); - LowTexts.Remove(lowText); + ShowLowTexts.Value.Remove(model); + LowTexts.Remove(model); } } } diff --git a/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs index 2db20ad..5d08249 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs @@ -43,47 +43,6 @@ public class ModEditWindowVM public ModEditWindowVM(ModEditWindow window) { - foreach (var lang in ModInfo.Value.I18nDatas) - { - if (I18nHelper.Current.CultureNames.Contains(lang.Key) is false) - I18nHelper.Current.CultureNames.Add(lang.Key); - } - if (I18nHelper.Current.CultureNames.Count > 0) - { - I18nHelper.Current.CultureName.Value = I18nHelper.Current.CultureNames.First(); - foreach (var i18nData in ModInfo.Value.OtherI18nDatas) - { - foreach (var food in ModInfo.Value.Foods) - { - var foodI18n = food.I18nDatas[i18nData.Key]; - if (i18nData.Value.TryGetValue(food.Name.Value, out var name)) - foodI18n.Name.Value = name; - 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[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[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; - } - } - } - ModEditWindow = window; CurrentLang.ValueChanged += CurrentLang_ValueChanged; diff --git a/VPet.ModMaker/ViewModels/ModEdit/PetEdit/PetEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/PetEdit/PetEditWindowVM.cs index 400be8f..7707916 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/PetEdit/PetEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/PetEdit/PetEditWindowVM.cs @@ -1,17 +1,64 @@ using HKW.HKWViewModels.SimpleObservable; +using LinePutScript.Localization.WPF; +using Microsoft.Win32; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; +using System.Windows.Media.Imaging; using VPet.ModMaker.Models; namespace VPet.ModMaker.ViewModels.ModEdit.PetEdit; public class PetEditWindowVM { + public PetModel OldPet { get; set; } public ObservableValue Pet { get; } = new(new()); - public PetEditWindowVM() { } + public ObservableValue Image { get; } = new(); + #region Command + public ObservableCommand AddImageCommand { get; } = new(); + public ObservableCommand ChangeImageCommand { get; } = new(); + #endregion + public PetEditWindowVM() + { + AddImageCommand.ExecuteEvent += AddImage; + ChangeImageCommand.ExecuteEvent += ChangeImage; + } + + public void Close() + { + Image.Value?.StreamSource?.Close(); + } + + private void AddImage() + { + OpenFileDialog openFileDialog = + new() + { + Title = "选择图片".Translate(), + Filter = $"图片|*.jpg;*.jpeg;*.png;*.bmp".Translate() + }; + if (openFileDialog.ShowDialog() is true) + { + Image.Value = Utils.LoadImageToStream(openFileDialog.FileName); + } + } + + private void ChangeImage() + { + OpenFileDialog openFileDialog = + new() + { + Title = "选择图片".Translate(), + Filter = $"图片|*.jpg;*.jpeg;*.png;*.bmp".Translate() + }; + if (openFileDialog.ShowDialog() is true) + { + Image.Value?.StreamSource?.Close(); + Image.Value = Utils.LoadImageToStream(openFileDialog.FileName); + } + } } diff --git a/VPet.ModMaker/ViewModels/ModEdit/PetEdit/PetPageVM.cs b/VPet.ModMaker/ViewModels/ModEdit/PetEdit/PetPageVM.cs index 2e0ee48..9837171 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/PetEdit/PetPageVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/PetEdit/PetPageVM.cs @@ -1,9 +1,98 @@ -using System; +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.PetEdit; namespace VPet.ModMaker.ViewModels.ModEdit.PetEdit; -public class PetPageVM { } +public class PetPageVM +{ + #region Value + public ObservableValue> ShowPets { get; } = new(); + public ObservableCollection Pets => ModInfoModel.Current.Pets; + public ObservableValue Filter { get; } = new(); + #endregion + #region Command + public ObservableCommand AddCommand { get; } = new(); + public ObservableCommand EditCommand { get; } = new(); + public ObservableCommand RemoveCommand { get; } = new(); + #endregion + public PetPageVM() + { + ShowPets.Value = Pets; + Filter.ValueChanged += Filter_ValueChanged; + + AddCommand.ExecuteEvent += Add; + EditCommand.ExecuteEvent += Edit; + RemoveCommand.ExecuteEvent += Remove; + } + + private void Filter_ValueChanged(string value) + { + if (string.IsNullOrWhiteSpace(value)) + { + ShowPets.Value = Pets; + } + else + { + ShowPets.Value = new( + Pets.Where(m => m.Name.Value.Contains(value, StringComparison.OrdinalIgnoreCase)) + ); + } + } + + public void Close() { } + + private void Add() + { + var window = new PetEditWindow(); + var vm = window.ViewModel; + window.ShowDialog(); + if (window.IsCancel) + return; + Pets.Add(vm.Pet.Value); + } + + public void Edit(PetModel model) + { + var window = new PetEditWindow(); + var vm = window.ViewModel; + vm.OldPet = model; + var newPet = vm.Pet.Value = new(model); + window.ShowDialog(); + if (window.IsCancel) + return; + if (ShowPets.Value.Count == Pets.Count) + { + Pets[Pets.IndexOf(model)] = newPet; + } + else + { + Pets[Pets.IndexOf(model)] = newPet; + ShowPets.Value[ShowPets.Value.IndexOf(model)] = newPet; + } + model.Close(); + } + + private void Remove(PetModel food) + { + if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No) + return; + if (ShowPets.Value.Count == Pets.Count) + { + Pets.Remove(food); + } + else + { + ShowPets.Value.Remove(food); + Pets.Remove(food); + } + } +} diff --git a/VPet.ModMaker/ViewModels/ModEdit/SelectTextEdit/SelectTextPageVM.cs b/VPet.ModMaker/ViewModels/ModEdit/SelectTextEdit/SelectTextPageVM.cs index b42a196..a9cf0f2 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/SelectTextEdit/SelectTextPageVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/SelectTextEdit/SelectTextPageVM.cs @@ -17,24 +17,24 @@ public class SelectTextPageVM #region Value public ObservableValue> ShowSelectTexts { get; } = new(); public ObservableCollection SelectTexts => ModInfoModel.Current.SelectTexts; - public ObservableValue FilterSelectText { get; } = new(); + public ObservableValue Filter { get; } = new(); #endregion #region Command - public ObservableCommand AddSelectTextCommand { get; } = new(); - public ObservableCommand EditSelectTextCommand { get; } = new(); - public ObservableCommand RemoveSelectTextCommand { get; } = new(); + public ObservableCommand AddCommand { get; } = new(); + public ObservableCommand EditCommand { get; } = new(); + public ObservableCommand RemoveCommand { get; } = new(); #endregion public SelectTextPageVM() { ShowSelectTexts.Value = SelectTexts; - FilterSelectText.ValueChanged += FilterSelectText_ValueChanged; - AddSelectTextCommand.ExecuteEvent += AddSelectText; - EditSelectTextCommand.ExecuteEvent += EditSelectText; - RemoveSelectTextCommand.ExecuteEvent += RemoveSelectText; + Filter.ValueChanged += Filter_ValueChanged; + AddCommand.ExecuteEvent += Add; + EditCommand.ExecuteEvent += Edit; + RemoveCommand.ExecuteEvent += Remove; } - private void FilterSelectText_ValueChanged(string value) + private void Filter_ValueChanged(string value) { if (string.IsNullOrWhiteSpace(value)) { @@ -43,12 +43,14 @@ public class SelectTextPageVM else { ShowSelectTexts.Value = new( - SelectTexts.Where(f => f.CurrentI18nData.Value.Text.Value.Contains(value)) + SelectTexts.Where( + m => m.Name.Value.Contains(value, StringComparison.OrdinalIgnoreCase) + ) ); } } - private void AddSelectText() + private void Add() { var window = new SelectTextEditWindow(); var vm = window.ViewModel; @@ -58,7 +60,7 @@ public class SelectTextPageVM SelectTexts.Add(vm.SelectText.Value); } - public void EditSelectText(SelectTextModel model) + public void Edit(SelectTextModel model) { var window = new SelectTextEditWindow(); var vm = window.ViewModel; @@ -78,7 +80,7 @@ public class SelectTextPageVM } } - private void RemoveSelectText(SelectTextModel model) + private void Remove(SelectTextModel model) { if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No) return; diff --git a/VPet.ModMaker/ViewModels/ModEdit/WorkEdit/WorkEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/WorkEdit/WorkEditWindowVM.cs new file mode 100644 index 0000000..15c3244 --- /dev/null +++ b/VPet.ModMaker/ViewModels/ModEdit/WorkEdit/WorkEditWindowVM.cs @@ -0,0 +1,18 @@ +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.WorkEdit; + +public class WorkEditWindowVM +{ + #region Value + public PetModel CurrentPet { get; set; } + public WorkModel OldWork { get; set; } + public ObservableValue Work { get; } = new(new()); + #endregion +} diff --git a/VPet.ModMaker/ViewModels/ModEdit/WorkEdit/WorkPageVM.cs b/VPet.ModMaker/ViewModels/ModEdit/WorkEdit/WorkPageVM.cs new file mode 100644 index 0000000..2c07bfb --- /dev/null +++ b/VPet.ModMaker/ViewModels/ModEdit/WorkEdit/WorkPageVM.cs @@ -0,0 +1,108 @@ +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.WorkEdit; + +namespace VPet.ModMaker.ViewModels.ModEdit.WorkEdit; + +public class WorkPageVM +{ + #region Value + public ObservableValue> ShowWorks { get; } = new(); + public ObservableCollection Works => CurrentPet.Value.Works; + + public ObservableCollection Pets => ModInfoModel.Current.Pets; + public ObservableValue CurrentPet { get; } = new(new()); + public ObservableValue Filter { get; } = new(); + #endregion + #region Command + public ObservableCommand AddCommand { get; } = new(); + public ObservableCommand EditCommand { get; } = new(); + public ObservableCommand RemoveCommand { get; } = new(); + #endregion + public WorkPageVM() + { + ShowWorks.Value = Works; + CurrentPet.ValueChanged += CurrentPet_ValueChanged; + Filter.ValueChanged += Filter_ValueChanged; + + AddCommand.ExecuteEvent += Add; + EditCommand.ExecuteEvent += Edit; + RemoveCommand.ExecuteEvent += Remove; + } + + private void CurrentPet_ValueChanged(PetModel value) + { + ShowWorks.Value = value.Works; + } + + private void Filter_ValueChanged(string value) + { + if (string.IsNullOrWhiteSpace(value)) + { + ShowWorks.Value = Works; + } + else + { + ShowWorks.Value = new( + Works.Where(m => m.Name.Value.Contains(value, StringComparison.OrdinalIgnoreCase)) + ); + } + } + + public void Close() { } + + private void Add() + { + var window = new WorkEditWindow(); + var vm = window.ViewModel; + vm.CurrentPet = CurrentPet.Value; + window.ShowDialog(); + if (window.IsCancel) + return; + Works.Add(vm.Work.Value); + } + + public void Edit(WorkModel model) + { + var window = new WorkEditWindow(); + var vm = window.ViewModel; + vm.CurrentPet = CurrentPet.Value; + vm.OldWork = model; + var newWork = vm.Work.Value = new(model); + window.ShowDialog(); + if (window.IsCancel) + return; + if (ShowWorks.Value.Count == Works.Count) + { + Works[Works.IndexOf(model)] = newWork; + } + else + { + Works[Works.IndexOf(model)] = newWork; + ShowWorks.Value[ShowWorks.Value.IndexOf(model)] = newWork; + } + } + + private void Remove(WorkModel food) + { + if (MessageBox.Show("确定删除吗".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No) + return; + if (ShowWorks.Value.Count == Works.Count) + { + Works.Remove(food); + } + else + { + ShowWorks.Value.Remove(food); + Works.Remove(food); + } + } +} diff --git a/VPet.ModMaker/ViewModels/ModMakerWindowVM.cs b/VPet.ModMaker/ViewModels/ModMakerWindowVM.cs index cd73fb8..ef733a0 100644 --- a/VPet.ModMaker/ViewModels/ModMakerWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModMakerWindowVM.cs @@ -146,22 +146,26 @@ public class ModMakerWindowVM }; if (openFileDialog.ShowDialog() is true) { - try + LoadMod(Path.GetDirectoryName(openFileDialog.FileName)); + } + } + + public void LoadMod(string path) + { + try + { + var mod = new ModLoader(new DirectoryInfo(path)); + if (mod.SuccessLoad is false) { - var path = Path.GetDirectoryName(openFileDialog.FileName); - var mod = new ModLoader(new DirectoryInfo(path)); - if (mod.SuccessLoad is false) - { - MessageBox.Show("模组载入失败".Translate()); - return; - } - ModInfoModel.Current = new ModInfoModel(mod); - CreateNewMod(); - } - catch (Exception ex) - { - MessageBox.Show("模组载入失败:\n{0}".Translate(ex)); + MessageBox.Show("模组载入失败".Translate()); + return; } + var modInfo = new ModInfoModel(mod); + EditMod(modInfo); + } + catch (Exception ex) + { + MessageBox.Show("模组载入失败:\n{0}".Translate(ex)); } } } diff --git a/VPet.ModMaker/Views/ModEdit/AddLangWindow.xaml b/VPet.ModMaker/Views/ModEdit/AddLangWindow.xaml index a6362f2..2d58696 100644 --- a/VPet.ModMaker/Views/ModEdit/AddLangWindow.xaml +++ b/VPet.ModMaker/Views/ModEdit/AddLangWindow.xaml @@ -3,6 +3,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:ll="clr-namespace:LinePutScript.Localization.WPF;assembly=LinePutScript.Localization.WPF" xmlns:local="clr-namespace:VPet.ModMaker.Views.ModEdit" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:pu="https://opensource.panuon.com/wpf-ui" @@ -10,6 +11,7 @@ Title="Window_AddLang" Width="400" Height="300" + WindowStartupLocation="CenterOwner" mc:Ignorable="d"> @@ -26,10 +28,12 @@ - 详情请参阅 Windows 支持的语言/区域名称列表中的“语言标记”列 + + + @@ -41,13 +45,13 @@ x:Name="Button_Cancel" Margin="10" Click="Button_Cancel_Click" - Content="取消" /> + Content="{ll:Str 取消}" /> + + + + + + + + + + diff --git a/VPet.ModMaker/Views/ModEdit/FoodEdit/FoodEditWindow.xaml.cs b/VPet.ModMaker/Views/ModEdit/FoodEdit/FoodEditWindow.xaml.cs index a7ef013..6ae8b3f 100644 --- a/VPet.ModMaker/Views/ModEdit/FoodEdit/FoodEditWindow.xaml.cs +++ b/VPet.ModMaker/Views/ModEdit/FoodEdit/FoodEditWindow.xaml.cs @@ -24,7 +24,7 @@ namespace VPet.ModMaker.Views.ModEdit.FoodEdit; /// public partial class FoodEditWindow : Window { - public bool IsCancel { get; internal set; } = true; + public bool IsCancel { get; private set; } = true; public FoodEditWindowVM ViewModel => (FoodEditWindowVM)DataContext; @@ -34,9 +34,8 @@ public partial class FoodEditWindow : Window DataContext = new FoodEditWindowVM(); Closed += (s, e) => { - ViewModel.Close(); if (IsCancel) - ViewModel.Food.Value.Image.Value?.StreamSource?.Close(); + ViewModel.Close(); }; } @@ -47,21 +46,21 @@ public partial class FoodEditWindow : Window private void Button_Yes_Click(object sender, RoutedEventArgs e) { - if (string.IsNullOrEmpty(ViewModel.Food.Value.Name.Value)) + if (string.IsNullOrWhiteSpace(ViewModel.Food.Value.Name.Value)) { MessageBox.Show("Id不可为空".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning); return; } - if (ViewModel.Food.Value.CurrentI18nData.Value.Name.Value is null) - { - MessageBox.Show("名称不可为空".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning); - return; - } if (ViewModel.Food.Value.Image.Value is null) { MessageBox.Show("图像不可为空".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning); return; } + if (string.IsNullOrWhiteSpace(ViewModel.Food.Value.CurrentI18nData.Value.Name.Value)) + { + MessageBox.Show("名称不可为空".Translate(), "", MessageBoxButton.OK, MessageBoxImage.Warning); + return; + } if ( ViewModel.OldFood?.Name.Value != ViewModel.Food.Value.Name.Value && ModInfoModel.Current.Foods.Any(i => i.Name == ViewModel.Food.Value.Name) diff --git a/VPet.ModMaker/Views/ModEdit/FoodEdit/FoodPage.xaml b/VPet.ModMaker/Views/ModEdit/FoodEdit/FoodPage.xaml index b499d18..9d08560 100644 --- a/VPet.ModMaker/Views/ModEdit/FoodEdit/FoodPage.xaml +++ b/VPet.ModMaker/Views/ModEdit/FoodEdit/FoodPage.xaml @@ -15,28 +15,13 @@ - - - - - - - - - + - - @@ -98,7 +83,7 @@ IsReadOnly="True" SortMemberPath="CurrentI18nData.Value.Name.Value"> - - - - - - - - - - - + + + + + + + + + + + + @@ -227,30 +251,35 @@ + - + + + + @@ -349,7 +378,7 @@ + Value="{Binding Pet.Value.TouchRaisedRect.Value.Happy.Value.Y.Value, Mode=TwoWay}" /> + + + + + +