Fix up the load modlist button

This commit is contained in:
trawzified 2024-05-09 17:20:11 +02:00
parent ce72a6e80c
commit 7d206315af
5 changed files with 38 additions and 4 deletions

View File

@ -1,5 +1,8 @@
using ReactiveUI; using ReactiveUI;
using System.IO;
using Wabbajack.Compiler; using Wabbajack.Compiler;
using Wabbajack.DTOs.JsonConverters;
using Wabbajack.Paths;
namespace Wabbajack.Messages; namespace Wabbajack.Messages;
@ -11,6 +14,7 @@ public class LoadModlistForCompiling
CompilerSettings = cs; CompilerSettings = cs;
} }
public static void Send(CompilerSettings cs) public static void Send(CompilerSettings cs)
{ {
MessageBus.Current.SendMessage(new LoadModlistForCompiling(cs)); MessageBus.Current.SendMessage(new LoadModlistForCompiling(cs));

View File

@ -12,6 +12,7 @@ using System.Windows.Input;
using DynamicData; using DynamicData;
using DynamicData.Binding; using DynamicData.Binding;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.WindowsAPICodePack.Dialogs;
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using SteamKit2.GC.Dota.Internal; using SteamKit2.GC.Dota.Internal;
@ -37,10 +38,13 @@ namespace Wabbajack
private readonly DTOSerializer _dtos; private readonly DTOSerializer _dtos;
public ICommand NewModListCommand { get; set; } public ICommand NewModListCommand { get; set; }
public ICommand LoadSettingsCommand { get; set; }
[Reactive] [Reactive]
public ObservableCollection<CreatedModlistVM> CreatedModlists { get; set; } public ObservableCollection<CreatedModlistVM> CreatedModlists { get; set; }
public FilePickerVM CompilerSettingsPicker { get; private set; }
public CreateModListVM(ILogger<CreateModListVM> logger, SettingsManager settingsManager, public CreateModListVM(ILogger<CreateModListVM> logger, SettingsManager settingsManager,
IServiceProvider serviceProvider, DTOSerializer dtos) IServiceProvider serviceProvider, DTOSerializer dtos)
{ {
@ -48,10 +52,33 @@ namespace Wabbajack
_settingsManager = settingsManager; _settingsManager = settingsManager;
_serviceProvider = serviceProvider; _serviceProvider = serviceProvider;
_dtos = dtos; _dtos = dtos;
CompilerSettingsPicker = new FilePickerVM
{
ExistCheckOption = FilePickerVM.CheckOptions.On,
PathType = FilePickerVM.PathTypeOptions.File,
PromptTitle = "Select a compiler settings file"
};
CompilerSettingsPicker.Filters.AddRange([
new CommonFileDialogFilter("Compiler Settings File", "*" + Ext.CompilerSettings)
]);
NewModListCommand = ReactiveCommand.Create(() => { NewModListCommand = ReactiveCommand.Create(() => {
NavigateToGlobal.Send(ScreenType.Compiler); NavigateToGlobal.Send(ScreenType.Compiler);
LoadModlistForCompiling.Send(new()); LoadModlistForCompiling.Send(new());
}); });
LoadSettingsCommand = ReactiveCommand.Create(() =>
{
CompilerSettingsPicker.SetTargetPathCommand.Execute(null);
if(CompilerSettingsPicker.TargetPath != default)
{
NavigateToGlobal.Send(ScreenType.Compiler);
var compilerSettings = _dtos.Deserialize<CompilerSettings>(File.ReadAllText(CompilerSettingsPicker.TargetPath.ToString()));
LoadModlistForCompiling.Send(compilerSettings);
}
});
this.WhenActivated(disposables => this.WhenActivated(disposables =>
{ {
LoadAllCompilerSettings().DisposeWith(disposables); LoadAllCompilerSettings().DisposeWith(disposables);

View File

@ -139,9 +139,6 @@ namespace Wabbajack
.DisposeWith(disposables); .DisposeWith(disposables);
// Settings // Settings
this.Bind(ViewModel, vm => vm.Settings.ModListName, view => view.ModListNameSetting.Text) this.Bind(ViewModel, vm => vm.Settings.ModListName, view => view.ModListNameSetting.Text)

View File

@ -60,7 +60,7 @@
</Grid> </Grid>
</Border> </Border>
<Border Grid.Column="1" BorderBrush="{StaticResource PrimaryVariantBrush}" CornerRadius="8" BorderThickness="19" Margin="0, 0, 20, 20"> <Border Grid.Column="1" BorderBrush="{StaticResource PrimaryVariantBrush}" CornerRadius="8" BorderThickness="19" Margin="0, 0, 20, 20" x:Name="LoadSettingsBorder">
<Grid Background="{StaticResource PrimaryVariantBrush}" Margin="-1"> <Grid Background="{StaticResource PrimaryVariantBrush}" Margin="-1">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>

View File

@ -39,6 +39,12 @@ namespace Wabbajack
.Select(args => Unit.Default) .Select(args => Unit.Default)
.InvokeCommand(this, x => x.ViewModel.NewModListCommand) .InvokeCommand(this, x => x.ViewModel.NewModListCommand)
.DisposeWith(dispose); .DisposeWith(dispose);
LoadSettingsBorder
.Events().MouseDown
.Select(args => Unit.Default)
.InvokeCommand(this, x => x.ViewModel.LoadSettingsCommand)
.DisposeWith(dispose);
}); });
} }
} }