2023-08-19 21:52:13 +00:00
|
|
|
|
using HKW.HKWViewModels.SimpleObservable;
|
|
|
|
|
using Microsoft.Win32;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
using VPet.Plugin.ModMaker.Models;
|
|
|
|
|
using System.Collections.Specialized;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using VPet.Plugin.ModMaker.Views.ModEdit;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
|
|
|
|
namespace VPet.Plugin.ModMaker.ViewModels.ModEdit;
|
|
|
|
|
|
|
|
|
|
public class ModEditWindowVM
|
|
|
|
|
{
|
|
|
|
|
public ModEditWindow ModEditWindow { get; }
|
|
|
|
|
|
|
|
|
|
#region Value
|
|
|
|
|
public ObservableValue<BitmapImage> ModImage { get; } = new();
|
|
|
|
|
public ObservableValue<ModInfoModel> ModInfo { get; } = new(new());
|
|
|
|
|
public ObservableValue<string> CurrentLang { get; } = new();
|
2023-08-21 15:30:55 +00:00
|
|
|
|
public I18nHelper I18nData => I18nHelper.Current;
|
2023-08-19 21:52:13 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Command
|
|
|
|
|
public ObservableCommand AddImageCommand { get; } = new();
|
|
|
|
|
public ObservableCommand ChangeImageCommand { get; } = new();
|
|
|
|
|
public ObservableCommand AddLangCommand { get; } = new();
|
|
|
|
|
|
|
|
|
|
public ObservableCommand<string> EditLangCommand { get; } = new();
|
|
|
|
|
public ObservableCommand<string> RemoveLangCommand { get; } = new();
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
public ModEditWindowVM() { }
|
|
|
|
|
|
|
|
|
|
public ModEditWindowVM(ModEditWindow window)
|
|
|
|
|
{
|
2023-08-21 15:30:55 +00:00
|
|
|
|
#if DEBUG
|
|
|
|
|
I18nHelper.Current.CultureNames.Add("zh-CN");
|
|
|
|
|
I18nHelper.Current.CultureName.Value = I18nHelper.Current.CultureNames.First();
|
|
|
|
|
#endif
|
2023-08-19 21:52:13 +00:00
|
|
|
|
ModEditWindow = window;
|
|
|
|
|
|
2023-08-21 15:30:55 +00:00
|
|
|
|
I18nHelper.Current.AddLang += I18nData_AddLang;
|
|
|
|
|
I18nHelper.Current.RemoveLang += I18nData_RemoveLang;
|
|
|
|
|
I18nHelper.Current.ReplaceLang += I18nData_ReplaceLang;
|
2023-08-19 21:52:13 +00:00
|
|
|
|
CurrentLang.ValueChanged += CurrentLang_ValueChanged;
|
|
|
|
|
|
|
|
|
|
AddImageCommand.ExecuteAction = AddImage;
|
|
|
|
|
ChangeImageCommand.ExecuteAction = ChangeImage;
|
|
|
|
|
AddLangCommand.ExecuteAction = AddLang;
|
|
|
|
|
EditLangCommand.ExecuteAction = EditLang;
|
|
|
|
|
RemoveLangCommand.ExecuteAction = RemoveLang;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void I18nData_AddLang(string lang)
|
|
|
|
|
{
|
|
|
|
|
ModInfo.Value.I18nDatas.Add(lang, new());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void I18nData_RemoveLang(string lang)
|
|
|
|
|
{
|
|
|
|
|
ModInfo.Value.I18nDatas.Remove(lang);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void I18nData_ReplaceLang(string oldLang, string newLang)
|
|
|
|
|
{
|
|
|
|
|
var info = ModInfo.Value.I18nDatas[oldLang];
|
|
|
|
|
ModInfo.Value.I18nDatas.Remove(oldLang);
|
|
|
|
|
ModInfo.Value.I18nDatas.Add(newLang, info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CurrentLang_ValueChanged(string value)
|
|
|
|
|
{
|
|
|
|
|
if (value is null)
|
|
|
|
|
return;
|
|
|
|
|
ModInfo.Value.CurrentI18nData.Value = ModInfo.Value.I18nDatas[value];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Close()
|
|
|
|
|
{
|
|
|
|
|
ModInfo.Value.ModImage.Value?.StreamSource?.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddImage()
|
|
|
|
|
{
|
|
|
|
|
OpenFileDialog openFileDialog =
|
|
|
|
|
new() { Title = "选择图片", Filter = $"图片|*.jpg;*.jpeg;*.png;*.bmp" };
|
|
|
|
|
if (openFileDialog.ShowDialog() is true)
|
|
|
|
|
{
|
|
|
|
|
ModInfo.Value.ModImage.Value = Utils.LoadImageToStream(openFileDialog.FileName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ChangeImage()
|
|
|
|
|
{
|
|
|
|
|
OpenFileDialog openFileDialog =
|
|
|
|
|
new() { Title = "选择图片", Filter = $"图片|*.jpg;*.jpeg;*.png;*.bmp" };
|
|
|
|
|
if (openFileDialog.ShowDialog() is true)
|
|
|
|
|
{
|
|
|
|
|
ModInfo.Value.ModImage.Value?.StreamSource?.Close();
|
|
|
|
|
ModInfo.Value.ModImage.Value = Utils.LoadImageToStream(openFileDialog.FileName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddLang()
|
|
|
|
|
{
|
2023-08-21 15:30:55 +00:00
|
|
|
|
var window = new Window_AddLang();
|
2023-08-19 21:52:13 +00:00
|
|
|
|
window.ShowDialog();
|
|
|
|
|
if (window.IsCancel)
|
|
|
|
|
return;
|
2023-08-21 15:30:55 +00:00
|
|
|
|
I18nHelper.Current.CultureNames.Add(window.Lang.Value);
|
2023-08-19 21:52:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void EditLang(string oldLang)
|
|
|
|
|
{
|
2023-08-21 15:30:55 +00:00
|
|
|
|
var window = new Window_AddLang();
|
2023-08-19 21:52:13 +00:00
|
|
|
|
window.Lang.Value = oldLang;
|
|
|
|
|
window.ShowDialog();
|
|
|
|
|
if (window.IsCancel)
|
|
|
|
|
return;
|
2023-08-21 15:30:55 +00:00
|
|
|
|
I18nHelper.Current.CultureNames[I18nHelper.Current.CultureNames.IndexOf(oldLang)] = window
|
|
|
|
|
.Lang
|
|
|
|
|
.Value;
|
2023-08-19 21:52:13 +00:00
|
|
|
|
CurrentLang.Value = window.Lang.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RemoveLang(string oldLang)
|
|
|
|
|
{
|
|
|
|
|
if (MessageBox.Show("确定删除吗", "", MessageBoxButton.YesNo) is MessageBoxResult.No)
|
|
|
|
|
return;
|
2023-08-21 15:30:55 +00:00
|
|
|
|
I18nHelper.Current.CultureNames.Remove(oldLang);
|
2023-08-19 21:52:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|