2019-12-14 20:11:39 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Reactive.Linq;
|
2019-12-20 07:14:43 +00:00
|
|
|
|
using System.Windows.Input;
|
2019-12-14 20:11:39 +00:00
|
|
|
|
using DynamicData;
|
|
|
|
|
using Microsoft.WindowsAPICodePack.Dialogs;
|
2019-12-20 07:14:43 +00:00
|
|
|
|
using ReactiveUI;
|
2019-11-14 05:28:27 +00:00
|
|
|
|
using ReactiveUI.Fody.Helpers;
|
2020-04-16 15:16:49 +00:00
|
|
|
|
using Wabbajack.Common;
|
2019-11-14 05:28:27 +00:00
|
|
|
|
using Wabbajack.Lib;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack
|
|
|
|
|
{
|
|
|
|
|
public class ModlistSettingsEditorVM : ViewModel
|
|
|
|
|
{
|
2020-04-15 17:40:41 +00:00
|
|
|
|
private readonly CompilationModlistSettings _settings;
|
2019-11-14 05:28:27 +00:00
|
|
|
|
|
|
|
|
|
[Reactive]
|
|
|
|
|
public string ModListName { get; set; }
|
|
|
|
|
|
2020-04-16 15:16:49 +00:00
|
|
|
|
[Reactive]
|
|
|
|
|
public string VersionText { get; set; }
|
|
|
|
|
|
2020-04-27 09:58:33 +00:00
|
|
|
|
private readonly ObservableAsPropertyHelper<Version> _version;
|
2020-04-16 15:31:12 +00:00
|
|
|
|
public Version Version => _version.Value;
|
|
|
|
|
|
2019-11-14 05:28:27 +00:00
|
|
|
|
[Reactive]
|
|
|
|
|
public string AuthorText { get; set; }
|
|
|
|
|
|
|
|
|
|
[Reactive]
|
|
|
|
|
public string Description { get; set; }
|
|
|
|
|
|
|
|
|
|
public FilePickerVM ImagePath { get; }
|
|
|
|
|
|
2019-12-20 07:14:43 +00:00
|
|
|
|
[Reactive]
|
2020-04-15 17:40:41 +00:00
|
|
|
|
public string Readme { get; set; }
|
2019-11-14 05:28:27 +00:00
|
|
|
|
|
2021-07-20 05:08:12 +00:00
|
|
|
|
[Reactive] public string MachineUrl { get; set; } = "";
|
|
|
|
|
[Reactive] public bool Publish { get; set; } = false;
|
|
|
|
|
|
2019-11-14 05:28:27 +00:00
|
|
|
|
[Reactive]
|
|
|
|
|
public string Website { get; set; }
|
|
|
|
|
|
2020-04-27 09:58:33 +00:00
|
|
|
|
[Reactive]
|
|
|
|
|
public bool IsNSFW { get; set; }
|
|
|
|
|
|
2019-12-14 20:11:39 +00:00
|
|
|
|
public IObservable<bool> InError { get; }
|
|
|
|
|
|
2019-11-16 22:33:32 +00:00
|
|
|
|
public ModlistSettingsEditorVM(CompilationModlistSettings settings)
|
2019-11-14 05:28:27 +00:00
|
|
|
|
{
|
2020-04-15 17:40:41 +00:00
|
|
|
|
_settings = settings;
|
2020-04-16 15:16:49 +00:00
|
|
|
|
ImagePath = new FilePickerVM
|
2019-11-14 05:28:27 +00:00
|
|
|
|
{
|
2019-12-14 20:11:39 +00:00
|
|
|
|
ExistCheckOption = FilePickerVM.CheckOptions.IfPathNotEmpty,
|
2019-11-14 05:28:27 +00:00
|
|
|
|
PathType = FilePickerVM.PathTypeOptions.File,
|
|
|
|
|
};
|
2019-12-14 20:11:39 +00:00
|
|
|
|
ImagePath.Filters.Add(new CommonFileDialogFilter("Banner image", "*.png"));
|
|
|
|
|
|
2020-04-16 15:31:12 +00:00
|
|
|
|
_version = this.WhenAny(x => x.VersionText)
|
|
|
|
|
.Select(x =>
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(x))
|
|
|
|
|
return new Version(0, 0);
|
|
|
|
|
|
|
|
|
|
return !Version.TryParse(x, out var version) ? new Version(0, 0) : version;
|
|
|
|
|
}).ObserveOnGuiThread()
|
|
|
|
|
.ToProperty(this, x => x.Version);
|
|
|
|
|
|
2020-04-15 17:40:41 +00:00
|
|
|
|
InError = this.WhenAny(x => x.ImagePath.ErrorState)
|
|
|
|
|
.Select(err => err.Failed)
|
2020-04-16 15:16:49 +00:00
|
|
|
|
.CombineLatest(
|
|
|
|
|
this.WhenAny(x => x.VersionText)
|
2020-04-16 15:31:12 +00:00
|
|
|
|
.Select(x => Version.TryParse(x, out _)),
|
2020-04-16 15:16:49 +00:00
|
|
|
|
(image, version) => !image && !version)
|
2019-12-14 20:11:39 +00:00
|
|
|
|
.Publish()
|
|
|
|
|
.RefCount();
|
2019-11-14 05:28:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Init()
|
|
|
|
|
{
|
2019-11-21 15:45:00 +00:00
|
|
|
|
AuthorText = _settings.Author;
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(_settings.ModListName))
|
2019-11-14 05:28:27 +00:00
|
|
|
|
{
|
2019-11-21 15:45:00 +00:00
|
|
|
|
ModListName = _settings.ModListName;
|
2019-11-14 05:28:27 +00:00
|
|
|
|
}
|
2019-11-21 15:45:00 +00:00
|
|
|
|
Description = _settings.Description;
|
2020-04-15 17:40:41 +00:00
|
|
|
|
Readme = _settings.Readme;
|
2019-11-21 15:45:00 +00:00
|
|
|
|
ImagePath.TargetPath = _settings.SplashScreen;
|
|
|
|
|
Website = _settings.Website;
|
2020-04-16 15:16:49 +00:00
|
|
|
|
VersionText = _settings.Version;
|
2020-04-27 09:58:33 +00:00
|
|
|
|
IsNSFW = _settings.IsNSFW;
|
2021-07-20 05:08:12 +00:00
|
|
|
|
MachineUrl = _settings.MachineUrl;
|
|
|
|
|
Publish = _settings.Publish;
|
2019-11-14 05:28:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Save()
|
|
|
|
|
{
|
2020-04-16 15:16:49 +00:00
|
|
|
|
_settings.Version = VersionText;
|
2019-11-21 15:45:00 +00:00
|
|
|
|
_settings.Author = AuthorText;
|
|
|
|
|
_settings.ModListName = ModListName;
|
|
|
|
|
_settings.Description = Description;
|
2020-04-15 17:40:41 +00:00
|
|
|
|
_settings.Readme = Readme;
|
2019-11-21 15:45:00 +00:00
|
|
|
|
_settings.SplashScreen = ImagePath.TargetPath;
|
|
|
|
|
_settings.Website = Website;
|
2020-04-27 09:58:33 +00:00
|
|
|
|
_settings.IsNSFW = IsNSFW;
|
2021-07-20 05:08:12 +00:00
|
|
|
|
_settings.MachineUrl = MachineUrl;
|
|
|
|
|
_settings.Publish = Publish;
|
2019-11-14 05:28:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|