add modlist selection ui, still WIP

This commit is contained in:
Timothy Baldridge 2019-10-20 05:26:42 -06:00
parent 60925a1f9f
commit f851432d51
9 changed files with 284 additions and 9 deletions

View File

@ -13,6 +13,9 @@ namespace Wabbajack.Common
public static string GameFolderFilesDir = "Game Folder Files";
public static string LOOTFolderFilesDir = "LOOT Config Files";
public static string BSACreationDir = "TEMP_BSA_FILES";
public static string ModListDownloadFolder = "downloaded_mod_lists";
public static string MegaPrefix = "https://mega.nz/#!";
public static HashSet<string> SupportedArchives = new HashSet<string> {".zip", ".rar", ".7z", ".7zip", ".fomod", ".omod"};

View File

@ -15,6 +15,8 @@ namespace Wabbajack.Common
[ThreadStatic] internal static bool WorkerThread;
[ThreadStatic] public static Action<int, string> CustomReportFn;
public static int MaxQueueSize;
public static int CurrentQueueSize;
private static bool _inited;
@ -64,7 +66,10 @@ namespace Wabbajack.Common
public static void Report(string msg, int progress)
{
ReportFunction(CpuId, msg, progress);
if (CustomReportFn != null)
CustomReportFn(progress, msg);
else
ReportFunction(CpuId, msg, progress);
}
public static void QueueTask(Action a)

View File

@ -0,0 +1,22 @@
<Window x:Class="Wabbajack.UI.DownloadWindow"
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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Wabbajack.UI"
Style="{StaticResource {x:Type Window}}" Icon="Icons/wabbajack.ico" WindowStyle="ToolWindow"
mc:Ignorable="d"
Title="Downloading Modlist" Height="200" Width="800">
<StackPanel Margin="20">
<StackPanel Orientation="Horizontal">
<TextBlock FontSize="30" Margin="0, 10">Downloading</TextBlock>
<TextBlock FontSize="30" Text="{Binding DownloadName}"></TextBlock>
</StackPanel>
<ProgressBar Margin="0, 10" Minimum="0" Maximum="100" Height="20" Value="{Binding DownloadProgress}"></ProgressBar>
<StackPanel HorizontalAlignment="Right">
<Button>
<TextBlock TextAlignment="Center" FontSize="20" Width="100">Cancel</TextBlock>
</Button>
</StackPanel>
</StackPanel>
</Window>

View File

@ -0,0 +1,116 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
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 System.Windows.Threading;
using Wabbajack.Common;
using Wabbajack.Lib;
using Wabbajack.Lib.Downloaders;
namespace Wabbajack.UI
{
/// <summary>
/// Interaction logic for DownloadWindow.xaml
/// </summary>
public partial class DownloadWindow : Window
{
public enum WindowResult
{
Undefined,
Completed,
Canceled
}
public WindowResult Result { get; internal set; } = WindowResult.Undefined;
public DownloadWindow(string url, string name, string destination)
{
InitializeComponent();
DataContext = new DownloadWindowViewModel(this, url, name, destination);
}
}
public class DownloadWindowViewModel : ViewModel
{
private readonly string _destination;
private readonly DownloadWindow _parent;
public DownloadWindowViewModel(DownloadWindow parent, string url, string name, string destination)
{
_parent = parent;
_url = url;
_downloadName = name;
_destination = destination;
_resultFn = resultFn;
Start();
}
private void Start()
{
_downloadThread = new Thread(() =>
{
WorkQueue.CustomReportFn = (progress, msg) => { DownloadProgress = progress; };
var state = DownloadDispatcher.ResolveArchive(_url);
state.Download(new Archive() {Name = _downloadName}, _destination);
_parent.Result = DownloadWindow.WindowResult.Completed;
_parent.Dispatcher.Invoke(() => _parent.Close());
_resultFn(DownloadWindow.WindowResult.Completed);
});
_downloadThread.Start();
}
public void Cancel()
{
if (_downloadThread != null && _downloadThread.IsAlive)
{
_downloadThread.Abort();
}
File.Delete(_destination);
_parent.Result = DownloadWindow.WindowResult.Canceled;
_resultFn(DownloadWindow.WindowResult.Canceled);
}
private int _downloadProgress;
public int DownloadProgress
{
get => _downloadProgress;
set => RaiseAndSetIfChanged(ref _downloadProgress, value);
}
private string _url;
public string Url
{
get => _url;
set => RaiseAndSetIfChanged(ref _url, value);
}
private string _downloadName;
private Thread _downloadThread;
public string DownloadName
{
get => _downloadName;
set => RaiseAndSetIfChanged(ref _downloadName, value);
}
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wabbajack.Lib;
using Wabbajack.Lib.ModListRegistry;
namespace Wabbajack.UI
{
public class ModListDefinition : ViewModel
{
private readonly ModlistMetadata _meta;
public ModListDefinition(ModlistMetadata meta)
{
_meta = meta;
}
}
}

View File

@ -6,7 +6,7 @@
Style="{StaticResource {x:Type Window}}" Icon="Icons/wabbajack.ico" WindowStyle="ToolWindow"
xmlns:local="clr-namespace:Wabbajack"
mc:Ignorable="d"
Title="Wabbajack" Height="500" Width="800" ResizeMode="NoResize"
Title="Wabbajack" Height="800" Width="1024" ResizeMode="CanResize"
Closing="Close_Window">
<Grid Margin="20">
<Grid.ColumnDefinitions>
@ -16,6 +16,7 @@
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="150"/>
<RowDefinition Height="*"/>
<RowDefinition Height="70"/>
<RowDefinition Height="70"/>
@ -24,10 +25,39 @@
<Image MouseLeftButtonDown="Patreon_MouseLeftButtonDown" Margin="5,0,0,0" Grid.Row="0" Grid.Column="1" Name="Patreon"/>
<Image MouseLeftButtonDown="Discord_MouseLeftButtonDown" Margin="5,0,0,0" Grid.Row="0" Grid.Column="2" Name="Discord"/>
<Image Grid.Row="1" Grid.ColumnSpan="3" Name="Banner" Stretch="Uniform" Margin="2,0,2,0"/>
<Button Name="InstallModlist" Grid.ColumnSpan="3" Grid.Row="2" Margin="2" Click="InstallModlist_Click">
<TextBlock FontSize="40">Install a ModList</TextBlock>
<ListBox ScrollViewer.CanContentScroll="False" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Grid.Row="2" Grid.ColumnSpan="3"
ItemsSource="{Binding ModLists}" SelectedItem="{Binding Path=SelectedModList, Mode=TwoWay}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300"></ColumnDefinition>
<ColumnDefinition Width="20"></ColumnDefinition>
<ColumnDefinition Width="200"></ColumnDefinition>
<ColumnDefinition Width="200"></ColumnDefinition>
<ColumnDefinition Width="200"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20"></RowDefinition>
<RowDefinition Height="15"></RowDefinition>
<RowDefinition Height="150"></RowDefinition>
<RowDefinition Height="20"></RowDefinition>
</Grid.RowDefinitions>
<Image Source="{Binding Links.ImageUri}" Grid.Column="0" Grid.Row="0" Grid.RowSpan="4"></Image>
<TextBlock Text="{Binding Title}" FontSize="20" Grid.Column="2" Grid.Row="0"></TextBlock>
<TextBlock Text="{Binding Author}" Grid.Column="2" Grid.Row="1"></TextBlock>
<TextBlock Text="{Binding Game}" HorizontalAlignment="Right" TextAlignment="Right" Grid.Column="4" Grid.Row="1"></TextBlock>
<TextBlock Text="{Binding Description}" VerticalAlignment="Top" HorizontalAlignment="Left" TextWrapping="Wrap" Grid.Column="2" Grid.Row="2" Grid.ColumnSpan="3"></TextBlock>
<Button Grid.Row="3" Grid.Column="2">More Info</Button>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Button Name="InstallModlist" Grid.ColumnSpan="3" Grid.Row="3" Margin="2" Click="InstallModlist_Click">
<TextBlock FontSize="40">Download and Install</TextBlock>
</Button>
<Button Name="CreateModlist" Grid.ColumnSpan="3" Grid.Row="3" Margin="2" Click="CreateModlist_Click">
<Button Name="CreateModlist" Grid.ColumnSpan="3" Grid.Row="5" Margin="2" Click="CreateModlist_Click">
<TextBlock FontSize="40">Create a ModList</TextBlock>
</Button>
</Grid>

View File

@ -1,9 +1,12 @@
using System.ComponentModel;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Input;
using Wabbajack.Common;
using Wabbajack.Lib;
using Wabbajack.Lib.ModListRegistry;
using Wabbajack.UI;
using static Wabbajack.MainWindow;
namespace Wabbajack
@ -13,6 +16,8 @@ namespace Wabbajack
/// </summary>
public partial class ModeSelectionWindow : Window
{
private List<ModlistMetadata> _lists;
public ModeSelectionWindow()
{
InitializeComponent();
@ -24,6 +29,8 @@ namespace Wabbajack
GitHub.Source = githubIcon;
var discordIcon = UIUtils.BitmapImageFromResource("Wabbajack.UI.Icons.discord.png");
Discord.Source = discordIcon;
DataContext = new ModeSelectionWindowViewModel();
}
private void CreateModlist_Click(object sender, RoutedEventArgs e)
@ -35,9 +42,11 @@ namespace Wabbajack
private void InstallModlist_Click(object sender, RoutedEventArgs e)
{
OpenMainWindow(
RunMode.Install,
UIUtils.OpenFileDialog($"Wabbajack Modlist (*{Consts.ModlistExtension})|*{Consts.ModlistExtension}"));
//OpenMainWindow(
// RunMode.Install,
// UIUtils.OpenFileDialog($"Wabbajack Modlist (*{Consts.ModlistExtension})|*{Consts.ModlistExtension}"));
var result = ((ModeSelectionWindowViewModel)DataContext).Download();
}
private void OpenMainWindow(RunMode mode, string file)

View File

@ -0,0 +1,60 @@
using Alphaleonis.Win32.Filesystem;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wabbajack.Common;
using Wabbajack.Lib;
using Wabbajack.Lib.ModListRegistry;
namespace Wabbajack.UI
{
public class ModeSelectionWindowViewModel : ViewModel
{
public ModeSelectionWindowViewModel()
{
_modLists = new ObservableCollection<ModlistMetadata>(ModlistMetadata.LoadFromGithub());
}
private ObservableCollection<ModlistMetadata> _modLists;
public ObservableCollection<ModlistMetadata> ModLists
{
get => _modLists;
}
private ModlistMetadata _selectedModList;
public ModlistMetadata SelectedModList
{
get => _selectedModList;
set => RaiseAndSetIfChanged(ref _selectedModList, value);
}
internal string Download()
{
if (!Directory.Exists(Consts.ModListDownloadFolder))
Directory.CreateDirectory(Consts.ModListDownloadFolder);
string dest = Path.Combine(Consts.ModListDownloadFolder, SelectedModList.Links.MachineURL);
string result = null;
var window = new DownloadWindow(SelectedModList.Links.Download, SelectedModList.Title, dest,
complete =>
{
if (complete == DownloadWindow.WindowResult.Completed)
result = dest;
});
window.ShowDialog();
if (window.Result == DownloadWindow.WindowResult.Completed)
return dest;
return null;
}
}
}

View File

@ -227,6 +227,11 @@
<Compile Include="Converters\IsNotNullVisibilityConverter.cs" />
<Compile Include="Enums\RunMode.cs" />
<Compile Include="Extensions\ReactiveUIExt.cs" />
<Compile Include="UI\DownloadWindow.xaml.cs">
<DependentUpon>DownloadWindow.xaml</DependentUpon>
</Compile>
<Compile Include="UI\ModeSelectionWindowViewModel.cs" />
<Compile Include="UI\ModListDefinition.cs" />
<Compile Include="UI\SlideshowView.xaml.cs">
<DependentUpon>SlideshowView.xaml</DependentUpon>
</Compile>
@ -242,6 +247,10 @@
<Compile Include="UI\TextViewer.xaml.cs">
<DependentUpon>TextViewer.xaml</DependentUpon>
</Compile>
<Page Include="UI\DownloadWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UI\SlideshowView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>