新增 ClickTextWindow

This commit is contained in:
Hakoyu 2023-08-21 23:30:55 +08:00
parent 50bb025e1b
commit f013b7fecf
27 changed files with 791 additions and 173 deletions

View File

@ -0,0 +1,63 @@
using HKW.HKWViewModels.SimpleObservable;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VPet_Simulator.Windows.Interface;
namespace VPet.Plugin.ModMaker.Models;
public class ClickTextModel : II18nData<I18nClickTextModel>
{
public ObservableValue<string> Id { get; } = new();
public ObservableValue<ClickText.ModeType> Mode { get; } = new();
public ObservableValue<string> Working { get; } = new();
public ObservableValue<int> LikeMin { get; } = new();
public ObservableValue<int> LikeMax { get; } = new();
public ObservableValue<VPet_Simulator.Core.Main.WorkingState> WorkingState { get; } = new();
public ObservableValue<ClickText.DayTime> DayTime { get; } = new();
public ObservableValue<I18nClickTextModel> CurrentI18nData { get; } = new();
public Dictionary<string, I18nClickTextModel> I18nDatas { get; } = new();
public ClickTextModel()
{
foreach (var lang in I18nHelper.Current.CultureNames)
I18nDatas.Add(lang, new());
CurrentI18nData.Value = I18nDatas[I18nHelper.Current.CultureName.Value];
}
public ClickTextModel(ClickTextModel clickText)
: this()
{
Mode.Value = clickText.Mode.Value;
Working.Value = clickText.Working.Value;
WorkingState.Value = clickText.WorkingState.Value;
LikeMax.Value = clickText.LikeMax.Value;
LikeMin.Value = clickText.LikeMin.Value;
DayTime.Value = clickText.DayTime.Value;
foreach (var item in clickText.I18nDatas)
I18nDatas[item.Key] = item.Value;
CurrentI18nData.Value = I18nDatas[I18nHelper.Current.CultureName.Value];
}
public ClickText ToClickText()
{
return new()
{
Mode = Mode.Value,
Working = Working.Value,
State = WorkingState.Value,
LikeMax = LikeMax.Value,
LikeMin = LikeMin.Value,
DaiTime = DayTime.Value,
};
}
}
public class I18nClickTextModel
{
public ObservableValue<string> Text { get; } = new();
}

View File

@ -1,6 +1,7 @@
using HKW.HKWViewModels.SimpleObservable;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -27,13 +28,33 @@ public class FoodModel : II18nData<I18nFoodModel>
public FoodModel()
{
foreach (var lang in I18nHelper.Instance.Langs)
foreach (var lang in I18nHelper.Current.CultureNames)
I18nDatas.Add(lang, new());
CurrentI18nData.Value = I18nDatas[I18nHelper.Instance.CurrentLang.Value];
CurrentI18nData.Value = I18nDatas[I18nHelper.Current.CultureName.Value];
}
public FoodModel(FoodModel food)
: this()
{
Id.Value = food.Id.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] = item.Value;
CurrentI18nData.Value = I18nDatas[I18nHelper.Current.CultureName.Value];
}
public Food ToFood()
{
// 没有 Name 和 Description
return new Food()
{
Type = Type.Value,
@ -45,14 +66,13 @@ public class FoodModel : II18nData<I18nFoodModel>
Likability = Likability.Value,
Price = Price.Value,
ImageSource = Image.Value,
Name = CurrentI18nData is null
? I18nDatas.First().Value.Name.Value
: CurrentI18nData.Value.Name.Value,
Desc = CurrentI18nData is null
? I18nDatas.First().Value.Description.Value
: CurrentI18nData.Value.Description.Value,
};
}
public void Close()
{
Image.Value?.StreamSource?.Close();
}
}
public class I18nFoodModel

View File

@ -10,13 +10,13 @@ namespace VPet.Plugin.ModMaker.Models;
public class I18nHelper
{
public static I18nHelper Instance { get; set; } = new();
public ObservableValue<string> CurrentLang { get; } = new();
public ObservableCollection<string> Langs { get; } = new();
public static I18nHelper Current { get; set; } = new();
public ObservableValue<string> CultureName { get; } = new();
public ObservableCollection<string> CultureNames { get; } = new();
public I18nHelper()
{
Langs.CollectionChanged += Langs_CollectionChanged;
CultureNames.CollectionChanged += Langs_CollectionChanged;
}
private void Langs_CollectionChanged(

View File

@ -10,6 +10,7 @@ namespace VPet.Plugin.ModMaker.Models;
public class LowTextModel : II18nData<I18nLowTextModel>
{
public ObservableValue<string> Id { get; } = new();
public ObservableValue<LowText.ModeType> Mode { get; } = new();
public ObservableValue<LowText.StrengthType> Strength { get; } = new();
public ObservableValue<LowText.LikeType> Like { get; } = new();
@ -19,9 +20,33 @@ public class LowTextModel : II18nData<I18nLowTextModel>
public LowTextModel()
{
foreach (var lang in I18nHelper.Instance.Langs)
foreach (var lang in I18nHelper.Current.CultureNames)
I18nDatas.Add(lang, new());
CurrentI18nData.Value = I18nDatas[I18nHelper.Instance.CurrentLang.Value];
CurrentI18nData.Value = I18nDatas[I18nHelper.Current.CultureName.Value];
}
public LowTextModel(LowTextModel lowText)
: this()
{
Mode = lowText.Mode;
Strength = lowText.Strength;
Like = lowText.Like;
foreach (var item in lowText.I18nDatas)
I18nDatas[item.Key] = item.Value;
CurrentI18nData.Value = I18nDatas[I18nHelper.Current.CultureName.Value];
}
public void Close() { }
public LowText ToLowText()
{
// 没有 Text
return new()
{
Mode = Mode.Value,
Strength = Strength.Value,
Like = Like.Value,
};
}
}

View File

@ -20,6 +20,11 @@ internal static class Utils
return bitmapImage;
}
public static BitmapImage LoadImageToStream(BitmapImage image)
{
return LoadImageToStream(((FileStream)image.StreamSource).Name);
}
public static BitmapImage LoadImageToMemoryStream(string imagePath)
{
BitmapImage bitmapImage = new();
@ -33,6 +38,11 @@ internal static class Utils
return bitmapImage;
}
public static BitmapImage LoadImageToMemoryStream(BitmapImage image)
{
return LoadImageToMemoryStream(((FileStream)image.StreamSource).Name);
}
public static void ShowDialogX(this Window window, Window owner)
{
owner.IsEnabled = false;

View File

@ -89,16 +89,24 @@
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="Models\ClickTextModel.cs" />
<Compile Include="Models\FoodModel.cs" />
<Compile Include="Models\I18nHelper.cs" />
<Compile Include="Models\II18nData.cs" />
<Compile Include="Models\LowTextModel.cs" />
<Compile Include="ViewModels\ModEdit\ClickTextEdit\ClickTextEditWindowVM.cs" />
<Compile Include="ViewModels\ModEdit\ClickTextEdit\ClickTextPageVM.cs" />
<Compile Include="ViewModels\ModEdit\FoodEdit\FoodPageVM.cs" />
<Compile Include="ViewModels\ModEdit\FoodEdit\FoodEditWindowVM.cs" />
<Compile Include="ViewModels\ModEdit\LowTextEdit\LowTextEditWindowVM.cs" />
<Compile Include="ViewModels\ModEdit\LowTextEdit\LowTextPageVM.cs" />
<Compile Include="ViewModels\ModEdit\LowTextEdit\MapperConfiguration.cs" />
<Compile Include="ViewModels\ModEdit\ModEditWindowVM.cs" />
<Compile Include="Views\ModEdit\ClickTextEdit\ClickTextPage.xaml.cs">
<DependentUpon>ClickTextPage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\ModEdit\ClickTextEdit\ClickTextEditWindow.xaml.cs">
<DependentUpon>ClickTextEditWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Views\ModEdit\FoodEdit\FoodPage.xaml.cs">
<DependentUpon>FoodPage.xaml</DependentUpon>
</Compile>
@ -155,6 +163,14 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</ApplicationDefinition>
<Page Include="Views\ModEdit\ClickTextEdit\ClickTextPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\ModEdit\ClickTextEdit\ClickTextEditWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\ModEdit\FoodEdit\FoodPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

View File

@ -0,0 +1,36 @@
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 VPet.Plugin.ModMaker.Models;
using VPet_Simulator.Windows.Interface;
namespace VPet.Plugin.ModMaker.ViewModels.ModEdit.ClickTextEdit;
public class ClickTextEditWindowVM
{
public ObservableCollection<ClickTextModel> ClickTexts { get; set; }
#region Value
public ObservableValue<ClickTextModel> ClickText { get; } = new(new());
public ObservableCollection<ClickText.ModeType> ModeTypes { get; } = new();
public ObservableCollection<ClickText.DayTime> DayTimes { get; } = new();
public ObservableCollection<VPet_Simulator.Core.Main.WorkingState> WorkingStates { get; } =
new();
#endregion
public ClickTextEditWindowVM()
{
foreach (ClickText.ModeType item in Enum.GetValues(typeof(ClickText.ModeType)))
ModeTypes.Add(item);
foreach (ClickText.DayTime item in Enum.GetValues(typeof(ClickText.DayTime)))
DayTimes.Add(item);
foreach (
VPet_Simulator.Core.Main.WorkingState item in Enum.GetValues(
typeof(VPet_Simulator.Core.Main.WorkingState)
)
)
WorkingStates.Add(item);
}
}

View File

@ -0,0 +1,139 @@
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 VPet.Plugin.ModMaker.Models;
using VPet.Plugin.ModMaker.Views.ModEdit.ClickTextEdit;
namespace VPet.Plugin.ModMaker.ViewModels.ModEdit.ClickTextEdit;
public class ClickTextPageVM
{
#region Value
public ObservableValue<ObservableCollection<ClickTextModel>> ShowClickTexts { get; } = new();
public ObservableCollection<ClickTextModel> ClickTexts { get; } = new();
public ObservableValue<string> FilterClickText { get; } = new();
#endregion
#region Command
public ObservableCommand AddClickTextCommand { get; } = new();
public ObservableCommand<ClickTextModel> EditClickTextCommand { get; } = new();
public ObservableCommand<ClickTextModel> RemoveClickTextCommand { get; } = new();
#endregion
public ClickTextPageVM()
{
ShowClickTexts.Value = ClickTexts;
FilterClickText.ValueChanged += FilterClickText_ValueChanged;
AddClickTextCommand.ExecuteAction = AddClickText;
EditClickTextCommand.ExecuteAction = EditClickText;
RemoveClickTextCommand.ExecuteAction = RemoveClickText;
I18nHelper.Current.CultureName.ValueChanged += CurrentLang_ValueChanged;
I18nHelper.Current.AddLang += Instance_AddLang;
I18nHelper.Current.RemoveLang += Instance_RemoveLang;
I18nHelper.Current.ReplaceLang += Instance_ReplaceLang;
}
private void FilterClickText_ValueChanged(string value)
{
if (string.IsNullOrEmpty(value))
{
ShowClickTexts.Value = ClickTexts;
}
else
{
ShowClickTexts.Value = new(
ClickTexts.Where(f => f.CurrentI18nData.Value.Text.Value.Contains(value))
);
}
}
private void AddClickText()
{
var window = CreateClickTextEditWindow();
var vm = window.ViewModel;
window.ShowDialog();
if (window.IsCancel)
return;
ClickTexts.Add(vm.ClickText.Value);
}
public void EditClickText(ClickTextModel clickText)
{
var window = CreateClickTextEditWindow();
var vm = window.ViewModel;
var newLowTest = vm.ClickText.Value = new(clickText);
window.ShowDialog();
if (window.IsCancel)
return;
if (ShowClickTexts.Value.Count == ClickTexts.Count)
{
ClickTexts[ClickTexts.IndexOf(clickText)] = newLowTest;
}
else
{
ClickTexts[ClickTexts.IndexOf(clickText)] = newLowTest;
ShowClickTexts.Value[ShowClickTexts.Value.IndexOf(clickText)] = newLowTest;
}
}
private void RemoveClickText(ClickTextModel clickText)
{
if (MessageBox.Show("确定删除吗", "", MessageBoxButton.YesNo) is MessageBoxResult.No)
return;
if (ShowClickTexts.Value.Count == ClickTexts.Count)
{
ClickTexts.Remove(clickText);
}
else
{
ShowClickTexts.Value.Remove(clickText);
ClickTexts.Remove(clickText);
}
}
private void CurrentLang_ValueChanged(string value)
{
foreach (var lowText in ClickTexts)
{
lowText.CurrentI18nData.Value = lowText.I18nDatas[value];
}
}
private void Instance_AddLang(string lang)
{
foreach (var lowText in ClickTexts)
{
lowText.I18nDatas.Add(lang, new());
}
}
private void Instance_RemoveLang(string lang)
{
foreach (var lowText in ClickTexts)
{
lowText.I18nDatas.Remove(lang);
}
}
private void Instance_ReplaceLang(string oldLang, string newLang)
{
foreach (var lowText in ClickTexts)
{
var item = lowText.I18nDatas[oldLang];
lowText.I18nDatas.Remove(oldLang);
lowText.I18nDatas.Add(newLang, item);
}
}
private ClickTextEditWindow CreateClickTextEditWindow()
{
var window = new ClickTextEditWindow();
window.ViewModel.ClickTexts = ClickTexts;
return window;
}
}

View File

@ -34,10 +34,10 @@ public class FoodPageVM
EditFoodCommand.ExecuteAction = EditFood;
RemoveFoodCommand.ExecuteAction = RemoveFood;
I18nHelper.Instance.CurrentLang.ValueChanged += CurrentLang_ValueChanged;
I18nHelper.Instance.AddLang += Instance_AddLang;
I18nHelper.Instance.RemoveLang += Instance_RemoveLang;
I18nHelper.Instance.ReplaceLang += Instance_ReplaceLang;
I18nHelper.Current.CultureName.ValueChanged += CurrentLang_ValueChanged;
I18nHelper.Current.AddLang += Instance_AddLang;
I18nHelper.Current.RemoveLang += Instance_RemoveLang;
I18nHelper.Current.ReplaceLang += Instance_ReplaceLang;
}
private void CurrentLang_ValueChanged(string value)
@ -104,9 +104,20 @@ public class FoodPageVM
{
var window = CreateAddFoodWindow();
var vm = window.ViewModel;
vm.Food.Value = food;
var newFood = vm.Food.Value = new(food);
window.ShowDialog();
// TODO: 需要实现深拷贝
if (window.IsCancel)
return;
if (ShowFoods.Value.Count == Foods.Count)
{
Foods[Foods.IndexOf(food)] = newFood;
}
else
{
Foods[Foods.IndexOf(food)] = newFood;
ShowFoods.Value[ShowFoods.Value.IndexOf(food)] = newFood;
}
food.Close();
}
private void RemoveFood(FoodModel food)

View File

@ -12,22 +12,23 @@ namespace VPet.Plugin.ModMaker.ViewModels.ModEdit.LowTextEdit;
public class LowTextEditWindowVM
{
#region Value
public ObservableCollection<LowTextModel> LowTexts { get; set; }
#region Value
public ObservableValue<LowTextModel> LowText { get; } = new(new());
public ObservableCollection<LowText.ModeType> LowTextModeTypes { get; } = new();
public ObservableCollection<LowText.LikeType> LowTextLikeTypes { get; } = new();
public ObservableCollection<LowText.StrengthType> LowTextStrengthTypes { get; } = new();
public ObservableCollection<LowText.ModeType> ModeTypes { get; } = new();
public ObservableCollection<LowText.LikeType> LikeTypes { get; } = new();
public ObservableCollection<LowText.StrengthType> StrengthTypes { get; } = new();
#endregion
public LowTextEditWindowVM()
{
foreach (LowText.ModeType mode in Enum.GetValues(typeof(LowText.ModeType)))
LowTextModeTypes.Add(mode);
ModeTypes.Add(mode);
foreach (LowText.LikeType mode in Enum.GetValues(typeof(LowText.LikeType)))
LowTextLikeTypes.Add(mode);
LikeTypes.Add(mode);
foreach (LowText.StrengthType mode in Enum.GetValues(typeof(LowText.StrengthType)))
LowTextStrengthTypes.Add(mode);
StrengthTypes.Add(mode);
}
}

View File

@ -35,10 +35,10 @@ public class LowTextPageVM
EditLowTextCommand.ExecuteAction = EditLowText;
RemoveLowTextCommand.ExecuteAction = RemoveLowText;
I18nHelper.Instance.CurrentLang.ValueChanged += CurrentLang_ValueChanged;
I18nHelper.Instance.AddLang += Instance_AddLang;
I18nHelper.Instance.RemoveLang += Instance_RemoveLang;
I18nHelper.Instance.ReplaceLang += Instance_ReplaceLang;
I18nHelper.Current.CultureName.ValueChanged += CurrentLang_ValueChanged;
I18nHelper.Current.AddLang += Instance_AddLang;
I18nHelper.Current.RemoveLang += Instance_RemoveLang;
I18nHelper.Current.ReplaceLang += Instance_ReplaceLang;
}
private void FilterLowText_ValueChanged(string value)
@ -69,20 +69,19 @@ public class LowTextPageVM
{
var window = CreateLowTextEditWindow();
var vm = window.ViewModel;
vm.LowText.Value = lowText;
var newLowTest = vm.LowText.Value = new(lowText);
window.ShowDialog();
// TODO: 需要实现深拷贝
//if (window.IsCancel)
// return;
//if (ShowLowTexts.Value.Count == LowTexts.Count)
//{
// LowTexts[LowTexts.IndexOf(lowText)] = lowText;
//}
//else
//{
// LowTexts[LowTexts.IndexOf(lowText)] = lowText;
// ShowLowTexts.Value[ShowLowTexts.Value.IndexOf(lowText)] = lowText;
//}
if (window.IsCancel)
return;
if (ShowLowTexts.Value.Count == LowTexts.Count)
{
LowTexts[LowTexts.IndexOf(lowText)] = newLowTest;
}
else
{
LowTexts[LowTexts.IndexOf(lowText)] = newLowTest;
ShowLowTexts.Value[ShowLowTexts.Value.IndexOf(lowText)] = newLowTest;
}
}
private void RemoveLowText(LowTextModel lowText)

View File

@ -1,12 +0,0 @@
using System;
namespace VPet.Plugin.ModMaker.ViewModels.ModEdit.LowTextEdit;
internal class MapperConfiguration
{
private Func<object, object> value;
public MapperConfiguration(Func<object, object> value)
{
this.value = value;
}
}

View File

@ -23,7 +23,7 @@ public class ModEditWindowVM
public ObservableValue<BitmapImage> ModImage { get; } = new();
public ObservableValue<ModInfoModel> ModInfo { get; } = new(new());
public ObservableValue<string> CurrentLang { get; } = new();
public I18nHelper I18nData => I18nHelper.Instance;
public I18nHelper I18nData => I18nHelper.Current;
#endregion
#region Command
@ -39,11 +39,15 @@ public class ModEditWindowVM
public ModEditWindowVM(ModEditWindow window)
{
#if DEBUG
I18nHelper.Current.CultureNames.Add("zh-CN");
I18nHelper.Current.CultureName.Value = I18nHelper.Current.CultureNames.First();
#endif
ModEditWindow = window;
I18nHelper.Instance.AddLang += I18nData_AddLang;
I18nHelper.Instance.RemoveLang += I18nData_RemoveLang;
I18nHelper.Instance.ReplaceLang += I18nData_ReplaceLang;
I18nHelper.Current.AddLang += I18nData_AddLang;
I18nHelper.Current.RemoveLang += I18nData_RemoveLang;
I18nHelper.Current.ReplaceLang += I18nData_ReplaceLang;
CurrentLang.ValueChanged += CurrentLang_ValueChanged;
AddImageCommand.ExecuteAction = AddImage;
@ -105,21 +109,23 @@ public class ModEditWindowVM
private void AddLang()
{
var window = CreateAddLangWindow();
var window = new Window_AddLang();
window.ShowDialog();
if (window.IsCancel)
return;
I18nHelper.Instance.Langs.Add(window.Lang.Value);
I18nHelper.Current.CultureNames.Add(window.Lang.Value);
}
private void EditLang(string oldLang)
{
var window = CreateAddLangWindow();
var window = new Window_AddLang();
window.Lang.Value = oldLang;
window.ShowDialog();
if (window.IsCancel)
return;
I18nHelper.Instance.Langs[I18nHelper.Instance.Langs.IndexOf(oldLang)] = window.Lang.Value;
I18nHelper.Current.CultureNames[I18nHelper.Current.CultureNames.IndexOf(oldLang)] = window
.Lang
.Value;
CurrentLang.Value = window.Lang.Value;
}
@ -127,13 +133,6 @@ public class ModEditWindowVM
{
if (MessageBox.Show("确定删除吗", "", MessageBoxButton.YesNo) is MessageBoxResult.No)
return;
I18nHelper.Instance.Langs.Remove(oldLang);
}
private Window_AddLang CreateAddLangWindow()
{
var window = new Window_AddLang();
window.Langs = I18nHelper.Instance.Langs;
return window;
I18nHelper.Current.CultureNames.Remove(oldLang);
}
}

View File

@ -29,7 +29,7 @@ public class WindowVM_ModMaker
private void CreateNewMod()
{
I18nHelper.Instance = new();
I18nHelper.Current = new();
ModEditWindow = new();
ModEditWindow.Show();
ModMakerWindow.Hide();

View File

@ -14,6 +14,7 @@ using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using VPet.Plugin.ModMaker.Models;
using VPet.Plugin.ModMaker.ViewModels.ModEdit;
namespace VPet.Plugin.ModMaker.Views.ModEdit;
@ -25,8 +26,6 @@ public partial class Window_AddLang : Window
{
public bool IsCancel { get; internal set; } = true;
public ObservableCollection<string> Langs { get; internal set; }
public ObservableValue<string> Lang { get; } = new();
public Window_AddLang()
@ -48,7 +47,7 @@ public partial class Window_AddLang : Window
MessageBox.Show("Lang不可为空", "", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
if (Langs.Contains(Lang.Value))
if (I18nHelper.Current.CultureNames.Contains(Lang.Value))
{
MessageBox.Show("此语言已存在", "", MessageBoxButton.OK, MessageBoxImage.Warning);
return;

View File

@ -0,0 +1,105 @@
<Window
x:Class="VPet.Plugin.ModMaker.Views.ModEdit.ClickTextEdit.ClickTextEditWindow"
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:local="clr-namespace:VPet.Plugin.ModMaker.Views.ModEdit.ClickTextEdit"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pu="https://opensource.panuon.com/wpf-ui"
xmlns:vm="clr-namespace:VPet.Plugin.ModMaker.ViewModels.ModEdit.ClickTextEdit"
Title="ClickTextWindow"
Width="800"
Height="450"
mc:Ignorable="d">
<d:Window.DataContext>
<vm:ClickTextEditWindowVM />
</d:Window.DataContext>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" MinWidth="200" />
</Grid.ColumnDefinitions>
<Grid>
<TextBox
x:Name="TextBox_Text"
VerticalContentAlignment="Top"
d:Text="这是一个测试文本,这是一个测试文本,这是一个测试文本,这是一个测试文本,这是一个测试文本,这是一个测试文本,这是一个测试文本,"
pu:TextBoxHelper.Watermark="文本"
Text="{Binding ClickText.Value.CurrentI18nData.Value.Text.Value, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap" />
</Grid>
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Content="Id" />
<TextBox Grid.Column="1" Text="{Binding ClickText.Value.Id.Value, UpdateSourceTrigger=PropertyChanged}" />
<Label Grid.Row="1" Content="指定工作" />
<TextBox
Grid.Row="1"
Grid.Column="1"
Text="{Binding ClickText.Value.Working.Value, UpdateSourceTrigger=PropertyChanged}" />
<Label Grid.Row="2" Content="最小好感度" />
<pu:NumberInput
Grid.Row="2"
Grid.Column="1"
Value="{Binding ClickText.Value.LikeMin.Value}" />
<Label Grid.Row="3" Content="最大好感度" />
<pu:NumberInput
Grid.Row="3"
Grid.Column="1"
Value="{Binding ClickText.Value.LikeMax.Value}" />
<Label Grid.Row="4" Content="模式" />
<ComboBox
Grid.Row="4"
Grid.Column="1"
ItemsSource="{Binding ModeTypes}"
SelectedItem="{Binding ClickText.Value.Mode.Value}" />
<Label Grid.Row="5" Content="工作状态" />
<ComboBox
Grid.Row="5"
Grid.Column="1"
ItemsSource="{Binding WorkingStates}"
SelectedItem="{Binding ClickText.Value.WorkingState.Value}" />
<Label Grid.Row="6" Content="日期区间" />
<ComboBox
Grid.Row="6"
Grid.Column="1"
ItemsSource="{Binding DayTimes}"
SelectedItem="{Binding ClickText.Value.DayTime.Value}" />
</Grid>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Button
x:Name="Button_Cancel"
Margin="10"
Click="Button_Cancel_Click"
Content="取消" />
<Button
x:Name="Button_Yes"
Grid.Column="1"
Margin="10"
Click="Button_Yes_Click"
Content="确定" />
</Grid>
</Grid>
</Grid>
</Window>

View File

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using VPet.Plugin.ModMaker.ViewModels.ModEdit.ClickTextEdit;
namespace VPet.Plugin.ModMaker.Views.ModEdit.ClickTextEdit;
/// <summary>
/// ClickTextWindow.xaml 的交互逻辑
/// </summary>
public partial class ClickTextEditWindow : Window
{
public bool IsCancel { get; private set; } = true;
public ClickTextEditWindowVM ViewModel => (ClickTextEditWindowVM)DataContext;
public ClickTextEditWindow()
{
InitializeComponent();
DataContext = new ClickTextEditWindowVM();
}
private void Button_Cancel_Click(object sender, RoutedEventArgs e)
{
Close();
}
private void Button_Yes_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(ViewModel.ClickText.Value.Id.Value))
{
MessageBox.Show("Id不可为空", "", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
if (ViewModel.ClickTexts.Any(i => i.Id.Value == ViewModel.ClickText.Value.Id.Value))
{
MessageBox.Show("此Id已存在", "", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
IsCancel = false;
Close();
}
}

View File

@ -0,0 +1,144 @@
<Page
x:Class="VPet.Plugin.ModMaker.Views.ModEdit.ClickTextEdit.ClickTextPage"
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:local="clr-namespace:VPet.Plugin.ModMaker.Views.ModEdit.ClickTextEdit"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pu="https://opensource.panuon.com/wpf-ui"
xmlns:vm="clr-namespace:VPet.Plugin.ModMaker.ViewModels.ModEdit.ClickTextEdit"
Title="ClickTextPage"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
<d:Page.DataContext>
<vm:ClickTextPageVM />
</d:Page.DataContext>
<Page.Resources>
<ResourceDictionary>
<ContextMenu x:Key="ContextMenu_DataGridRow" x:Shared="false">
<MenuItem
Command="{Binding DataContext.EditLowTextCommand, RelativeSource={RelativeSource AncestorType=Page, Mode=FindAncestor}}"
CommandParameter="{Binding DataContext, RelativeSource={RelativeSource AncestorType=DataGridRow, Mode=FindAncestor}}"
Header="修改点击文本" />
<MenuItem
Command="{Binding DataContext.RemoveLowTextCommand, RelativeSource={RelativeSource AncestorType=Page, Mode=FindAncestor}}"
CommandParameter="{Binding DataContext, RelativeSource={RelativeSource AncestorType=DataGridRow, Mode=FindAncestor}}"
Header="删除点击文本" />
</ContextMenu>
</ResourceDictionary>
</Page.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<TextBox
x:Name="TextBox_SearchFood"
pu:TextBoxHelper.Watermark="搜索文本"
Text="{Binding FilterClickText.Value, UpdateSourceTrigger=PropertyChanged}" />
<DataGrid
x:Name="DataGrid_ClickText"
Grid.Row="1"
d:ItemsSource="{d:SampleData ItemCount=5}"
pu:DataGridHelper.ColumnHeaderHorizontalContentAlignment="Center"
AutoGenerateColumns="False"
CanUserAddRows="False"
GridLinesVisibility="Horizontal"
ItemsSource="{Binding ShowClickTexts.Value}"
MouseDoubleClick="DataGrid_ClickText_MouseDoubleClick"
RowDetailsVisibilityMode="Visible"
RowHeight="64"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling">
<DataGrid.RowStyle>
<Style BasedOn="{StaticResource {x:Type DataGridRow}}" TargetType="DataGridRow">
<Setter Property="Height" Value="64" />
<Setter Property="Tag" Value="{Binding}" />
<Setter Property="ContextMenu" Value="{StaticResource ContextMenu_DataGridRow}" />
</Style>
</DataGrid.RowStyle>
<DataGrid.Columns>
<DataGridTextColumn
Binding="{Binding Id.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="Id">
<DataGridTextColumn.Header>
<Label Content="Id" />
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn
Binding="{Binding CurrentI18nData.Value.Text.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="Text">
<DataGridTextColumn.Header>
<Label Content="文本" />
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn
Binding="{Binding Mode.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="Mode">
<DataGridTextColumn.Header>
<Label Content="状态" />
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn
Binding="{Binding Working.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="Working">
<DataGridTextColumn.Header>
<Label Content="指定工作" />
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn
Binding="{Binding WorkingState.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="WorkingState">
<DataGridTextColumn.Header>
<Label Content="工作状态" />
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn
Binding="{Binding LikeMin.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="LikeMin">
<DataGridTextColumn.Header>
<Label Content="最小好感" />
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn
Binding="{Binding LikeMax.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="LikeMax">
<DataGridTextColumn.Header>
<Label Content="最大好感" />
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn
Binding="{Binding DayTime.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="DayTime">
<DataGridTextColumn.Header>
<Label Content="时间" />
</DataGridTextColumn.Header>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
<Button
Grid.Row="1"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Command="{Binding AddClickTextCommand}"
Content=""
Style="{StaticResource AddButton}" />
</Grid>
</Page>

View File

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using VPet.Plugin.ModMaker.Models;
using VPet.Plugin.ModMaker.ViewModels.ModEdit.ClickTextEdit;
namespace VPet.Plugin.ModMaker.Views.ModEdit.ClickTextEdit;
/// <summary>
/// ClickTextPage.xaml 的交互逻辑
/// </summary>
public partial class ClickTextPage : Page
{
public ClickTextPageVM ViewModel => (ClickTextPageVM)DataContext;
public ClickTextPage()
{
InitializeComponent();
DataContext = new ClickTextPageVM();
}
private void DataGrid_ClickText_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (
sender is not DataGrid dataGrid || dataGrid.SelectedItem is not ClickTextModel clickText
)
return;
ViewModel.EditClickText(clickText);
}
}

View File

@ -67,7 +67,7 @@
<Label Content="食物Id:" />
<TextBox
Grid.Column="1"
pu:TextBoxHelper.Watermark="食物Id"
pu:TextBoxHelper.Watermark="Id"
Text="{Binding Food.Value.Id.Value}" />
<Label Grid.Row="1" Content="食物类型:" />
<ComboBox
@ -82,7 +82,6 @@
Grid.Column="1"
pu:TextBoxHelper.Watermark="食物名称"
Text="{Binding Food.Value.CurrentI18nData.Value.Name.Value}" />
<Label Content="食物名称:" />
<Label Grid.Row="3" Content="食物描述:" />
<TextBox
Grid.Row="3"

View File

@ -60,6 +60,11 @@ public partial class FoodEditWindow : Window
MessageBox.Show("图像不可为空", "", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
if (ViewModel.Foods.Any(i => i.Id.Value == ViewModel.Food.Value.Id.Value))
{
MessageBox.Show("此Id已存在", "", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
IsCancel = false;
Close();
}

View File

@ -17,7 +17,7 @@
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" MinWidth="200" />
</Grid.ColumnDefinitions>
<Grid>
<TextBox
@ -42,23 +42,28 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Content="状态" />
<ComboBox
Grid.Column="1"
ItemsSource="{Binding LowTextModeTypes}"
SelectedItem="{Binding LowText.Value.Mode.Value}" />
<Label Content="Id" />
<TextBox Grid.Column="1" Text="{Binding LowText.Value.Id.Value, UpdateSourceTrigger=PropertyChanged}" />
<Label Grid.Row="1" Content="口渴/饥饿状态" />
<Label Grid.Row="1" Content="状态" />
<ComboBox
Grid.Row="1"
Grid.Column="1"
ItemsSource="{Binding LowTextStrengthTypes}"
SelectedItem="{Binding LowText.Value.Strength.Value}" />
<Label Grid.Row="2" Content="好感度需求" />
ItemsSource="{Binding ModeTypes}"
SelectedItem="{Binding LowText.Value.Mode.Value}" />
<Label Grid.Row="2" Content="口渴/饥饿状态" />
<ComboBox
Grid.Row="2"
Grid.Column="1"
ItemsSource="{Binding LowTextLikeTypes}"
ItemsSource="{Binding StrengthTypes}"
SelectedItem="{Binding LowText.Value.Strength.Value}" />
<Label Grid.Row="3" Content="好感度需求" />
<ComboBox
Grid.Row="3"
Grid.Column="1"
ItemsSource="{Binding LikeTypes}"
SelectedItem="{Binding LowText.Value.Like.Value}" />
</Grid>
<Grid Grid.Row="1">

View File

@ -37,6 +37,16 @@ public partial class LowTextEditWindow : Window
private void Button_Yes_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(ViewModel.LowText.Value.Id.Value))
{
MessageBox.Show("Id不可为空", "", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
if (ViewModel.LowTexts.Any(i => i.Id.Value == ViewModel.LowText.Value.Id.Value))
{
MessageBox.Show("此Id已存在", "", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
IsCancel = false;
Close();
}

View File

@ -33,10 +33,7 @@
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<TextBox
x:Name="TextBox_SearchFood"
pu:TextBoxHelper.Watermark="搜索文本"
Text="{Binding FilterLowText.Value, UpdateSourceTrigger=PropertyChanged}" />
<TextBox pu:TextBoxHelper.Watermark="搜索文本" Text="{Binding FilterLowText.Value, UpdateSourceTrigger=PropertyChanged}" />
<DataGrid
x:Name="DataGrid_LowText"
Grid.Row="1"
@ -46,7 +43,7 @@
CanUserAddRows="False"
GridLinesVisibility="Horizontal"
ItemsSource="{Binding ShowLowTexts.Value}"
MouseDoubleClick="DataGrid_Food_MouseDoubleClick"
MouseDoubleClick="DataGrid_LowText_MouseDoubleClick"
RowDetailsVisibilityMode="Visible"
RowHeight="64"
VirtualizingStackPanel.IsVirtualizing="True"
@ -59,6 +56,15 @@
</Style>
</DataGrid.RowStyle>
<DataGrid.Columns>
<DataGridTextColumn
Binding="{Binding Id.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="Id">
<DataGridTextColumn.Header>
<Label Content="Id" />
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn
Binding="{Binding CurrentI18nData.Value.Text.Value}"
CanUserSort="True"
@ -72,7 +78,7 @@
Binding="{Binding Mode.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="Type">
SortMemberPath="Mode">
<DataGridTextColumn.Header>
<Label Content="状态" />
</DataGridTextColumn.Header>
@ -90,7 +96,7 @@
Binding="{Binding Like.Value}"
CanUserSort="True"
IsReadOnly="True"
SortMemberPath="StrengthDrink">
SortMemberPath="Like">
<DataGridTextColumn.Header>
<Label Content="好感需求" />
</DataGridTextColumn.Header>

View File

@ -33,65 +33,10 @@ public partial class LowTextPage : Page
DataContext = new LowTextPageVM();
}
//private void Button_AddLowText_Click(object sender, RoutedEventArgs e)
//{
// var window = new LowTextEditWindow();
// window.Closed += (s, e) =>
// {
// if (s is not LowTextEditWindow addLowTextWindow || addLowTextWindow.IsCancel)
// return;
// var lowText = CreateLowTextFromWindow(addLowTextWindow);
// if (LowTextDict.TryGetValue(lowText.Text, out var oldText))
// {
// LowTextDict[lowText.Text] = LowTexts[LowTexts.IndexOf(oldText)] = lowText;
// }
// else
// {
// LowTexts.Add(lowText);
// LowTextDict.Add(lowText.Text, lowText);
// }
// };
// ShowDialogX(window);
//}
private void DataGrid_Food_MouseDoubleClick(object sender, MouseButtonEventArgs e)
private void DataGrid_LowText_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (sender is not DataGrid dataGrid || dataGrid.SelectedItem is not LowTextModel lowText)
return;
ViewModel.EditLowText(lowText);
}
//private void TextBox_SearchFood_TextChanged(object sender, TextChangedEventArgs e)
//{
// if (sender is not TextBox textBox)
// return;
// if (textBox.Text.Length > 0)
// {
// var newList = new ObservableCollection<LowText>(
// LowTexts.Where(i => i.Text.Contains(textBox.Text))
// );
// if (newList.Count != LowTexts.Count)
// DataGrid_LowText.ItemsSource = newList;
// }
// else
// DataGrid_LowText.ItemsSource = LowTexts;
//}
//private void MenuItem_ChangeLowText_Click(object sender, RoutedEventArgs e)
//{
// if (sender is not MenuItem menuItem || menuItem.Tag is not LowText lowText)
// return;
// ChangeLowText(lowText);
//}
//private void MenuItem_RemoveLowText_Click(object sender, RoutedEventArgs e)
//{
// if (sender is not MenuItem menuItem || menuItem.Tag is not LowText lowText)
// return;
// if (DataGrid_LowText.ItemsSource is IList list && list.Count != LowTexts.Count)
// list.Remove(lowText);
// else
// LowTexts.Remove(lowText);
// LowTextDict.Remove(lowText.Text);
//}
}

View File

@ -197,23 +197,11 @@
Style="{StaticResource AddButton}" />
</Grid>
</TabItem>
<TabItem Header="点击文本 (0)">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<TextBox x:Name="TextBox_SearchClickText" />
<ListBox x:Name="ListBox_ClickText" />
<Button
x:Name="Button_AddClickText"
Grid.Row="1"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Click="Button_AddClickText_Click"
Content=""
Style="{StaticResource AddButton}" />
</Grid>
<TabItem
x:Name="TabItem_ClickText"
Header="点击文本 (0)"
Tag="点击文本">
<Frame Content="{Binding ModEditWindow.ClickTextPage}" />
</TabItem>
<TabItem
x:Name="TabItem_LowText"
@ -237,9 +225,9 @@
x:Name="ListBox_Langs"
Grid.Row="1"
d:ItemsSource="{d:SampleData ItemCount=5}"
ItemsSource="{Binding I18nData.Langs}"
ItemsSource="{Binding I18nData.CultureNames}"
ScrollViewer.VerticalScrollBarVisibility="Auto"
SelectedItem="{Binding I18nData.CurrentLang.Value}">
SelectedItem="{Binding I18nData.CultureName.Value}">
<ListBox.ItemContainerStyle>
<Style BasedOn="{StaticResource {x:Type ListBoxItem}}" TargetType="ListBoxItem">
<Setter Property="Content" Value="{Binding}" />

View File

@ -17,6 +17,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using VPet.Plugin.ModMaker.ViewModels.ModEdit;
using VPet.Plugin.ModMaker.Views.ModEdit.ClickTextEdit;
using VPet.Plugin.ModMaker.Views.ModEdit.FoodEdit;
using VPet.Plugin.ModMaker.Views.ModEdit.LowTextEdit;
using VPet_Simulator.Windows.Interface;
@ -29,8 +30,9 @@ namespace VPet.Plugin.ModMaker.Views.ModEdit;
public partial class ModEditWindow : Window
{
public ModEditWindowVM ViewModel => (ModEditWindowVM)this.DataContext;
public FoodPage FoodPage { get; } = new FoodPage();
public LowTextPage LowTextPage { get; } = new LowTextPage();
public FoodPage FoodPage { get; } = new();
public LowTextPage LowTextPage { get; } = new();
public ClickTextPage ClickTextPage { get; } = new();
public ModEditWindow()
{
@ -39,6 +41,16 @@ public partial class ModEditWindow : Window
Closed += Window_ModEdit_Closed;
FoodPage.ViewModel.Foods.CollectionChanged += Foods_CollectionChanged;
LowTextPage.ViewModel.LowTexts.CollectionChanged += LowTexts_CollectionChanged;
ClickTextPage.ViewModel.ClickTexts.CollectionChanged += ClickTexts_CollectionChanged;
}
private void ClickTexts_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
ClickTextPage.ViewModel.ClickTexts.CollectionChanged += (s, e) =>
{
TabItem_ClickText.Header =
$"{TabItem_ClickText.Tag} ({ClickTextPage.ViewModel.ClickTexts.Count})";
};
}
private void LowTexts_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)