wabbajack/Wabbajack.App/Controls/InstalledListViewModel.cs

55 lines
1.6 KiB
C#
Raw Normal View History

2021-10-22 04:28:52 +00:00
using System.Reactive;
2021-11-08 13:32:51 +00:00
using System.Threading.Tasks;
using Avalonia.Media.Imaging;
using Avalonia.Threading;
2021-10-22 04:28:52 +00:00
using ReactiveUI;
2021-11-08 13:32:51 +00:00
using ReactiveUI.Fody.Helpers;
2021-10-22 04:28:52 +00:00
using Wabbajack.App.Messages;
2021-11-08 13:32:51 +00:00
using Wabbajack.App.Models;
2021-10-22 04:28:52 +00:00
using Wabbajack.App.Screens;
using Wabbajack.App.ViewModels;
2021-11-08 13:32:51 +00:00
using Wabbajack.Common;
2021-10-22 04:28:52 +00:00
using Wabbajack.DTOs.SavedSettings;
using Wabbajack.Paths;
namespace Wabbajack.App.Controls;
public class InstalledListViewModel : ViewModelBase
{
private readonly InstallationConfigurationSetting _setting;
2021-11-08 13:32:51 +00:00
public InstalledListViewModel(InstallationConfigurationSetting setting, ImageCache imageCache)
2021-10-22 04:28:52 +00:00
{
Activator = new ViewModelActivator();
_setting = setting;
Play = ReactiveCommand.Create(() =>
{
MessageBus.Current.SendMessage(new ConfigureLauncher(InstallPath));
MessageBus.Current.SendMessage(new NavigateTo(typeof(LauncherViewModel)));
2021-10-22 04:28:52 +00:00
});
2021-11-08 13:32:51 +00:00
LoadImage(imageCache).FireAndForget();
}
public async Task LoadImage(ImageCache cache)
{
var img = await cache.From(_setting.Install.Combine("modlist-image.png"), 270, 150);
Dispatcher.UIThread.Post(() =>
{
Image = img;
});
2021-10-22 04:28:52 +00:00
}
2021-10-23 16:51:17 +00:00
public AbsolutePath InstallPath => _setting.Install;
public string Name => _setting.Metadata?.Title ?? "";
2021-11-08 13:32:51 +00:00
public string Version => _setting.Metadata?.Version?.ToString() ?? "";
public string Author => _setting.Metadata?.Author ?? "";
2021-10-23 16:51:17 +00:00
public ReactiveCommand<Unit, Unit> Play { get; }
2021-11-08 13:32:51 +00:00
[Reactive]
public IBitmap Image { get; set; }
2021-10-22 04:28:52 +00:00
}