Bind the UI to AlwaysEnable

This commit is contained in:
Timothy Baldridge 2021-10-13 15:51:00 -06:00
parent 88cdebccda
commit f4f4b80968
8 changed files with 144 additions and 15 deletions

View File

@ -30,14 +30,8 @@ public class LogViewModel : ViewModelBase, IActivatableViewModel
.Bind(out _messagesFiltered)
.Subscribe();
this.WhenActivated(disposables =>
{
_provider.Messages
.Subscribe(m => _messages.AddOrUpdate(m))
.DisposeWith(disposables);
});
_provider.Messages
.Subscribe(m => _messages.AddOrUpdate(m));
}
}

View File

@ -0,0 +1,14 @@
<UserControl xmlns="https://github.com/avaloniaui"
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:i="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Wabbajack.App.Controls.RemovableListItem">
<StackPanel Orientation="Horizontal">
<Button x:Name="DeleteButton">
<i:MaterialIcon Kind="MinusCircle"></i:MaterialIcon>
</Button>
<TextBlock x:Name="Text"></TextBlock>
</StackPanel>
</UserControl>

View File

@ -0,0 +1,24 @@
using Avalonia.Controls.Mixins;
using Avalonia.ReactiveUI;
using ReactiveUI;
using Wabbajack.App.ViewModels;
namespace Wabbajack.App.Controls;
public partial class RemovableListItem : ReactiveUserControl<RemovableItemViewModel>, IActivatableView
{
public RemovableListItem()
{
InitializeComponent();
this.WhenActivated(disposables =>
{
this.OneWayBind(ViewModel, vm => vm.Text, view => view.Text.Text)
.DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.DeleteCommand, view => view.DeleteButton)
.DisposeWith(disposables);
});
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Reactive;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.App.ViewModels;
namespace Wabbajack.App.Controls;
public class RemovableItemViewModel : ViewModelBase
{
[Reactive]
public string Text { get; set; }
[Reactive]
public ReactiveCommand<Unit, Unit> DeleteCommand { get; set; }
public RemovableItemViewModel()
{
Activator = new ViewModelActivator();
}
}

View File

@ -8,7 +8,7 @@
x:Class="Wabbajack.App.Screens.CompilerConfigurationView">
<Grid RowDefinitions="40, *, 40">
<TextBlock Grid.Row="0" x:Name="StatusText" FontSize="20" FontWeight="Bold">Compiler Configuration</TextBlock>
<Grid Grid.Row="1" ColumnDefinitions="Auto, *" RowDefinitions="Auto, Auto, Auto, Auto, Auto" Margin="4">
<Grid Grid.Row="1" ColumnDefinitions="Auto, *" RowDefinitions="Auto, Auto, Auto, Auto, Auto, Auto, Auto" Margin="4">
<Label Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right">Title:</Label>
<TextBox Grid.Column="1" Grid.Row="0" x:Name="Title"></TextBox>
<Label Grid.Column="0" Grid.Row="1" HorizontalAlignment="Right">Settings File:</Label>
@ -27,6 +27,29 @@
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<Label Grid.Column="0" Grid.Row="5" HorizontalAlignment="Right">Output Folder:</Label>
<controls:FileSelectionBox Grid.Column="1" Grid.Row="5" x:Name="OutputFolder" SelectFolder="True"></controls:FileSelectionBox>
<Label Grid.Column="0" Grid.Row="6" HorizontalAlignment="Right" VerticalAlignment="Top">Always Enabled:</Label>
<StackPanel Grid.Column="1" Grid.Row="6" Orientation="Vertical">
<Button x:Name="AddAlwaysEnabled">
<i:MaterialIcon Kind="AddCircle"></i:MaterialIcon>
</Button>
<ItemsControl x:Name="AlwaysEnabledList">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"></StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<controls:RemovableListItem></controls:RemovableListItem>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</Grid>
<Grid ColumnDefinitions="*, Auto" Grid.Row="2">
<Button Grid.Column="1" x:Name="StartCompilation">

View File

@ -1,9 +1,13 @@
using System.Linq;
using System.Reactive.Disposables;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using ReactiveUI;
using Wabbajack.App.Controls;
using Wabbajack.App.Views;
using Wabbajack.Common;
using Wabbajack.Paths;
namespace Wabbajack.App.Screens
{
@ -12,18 +16,22 @@ namespace Wabbajack.App.Screens
public CompilerConfigurationView()
{
InitializeComponent();
AddAlwaysEnabled.Command = ReactiveCommand.Create(() => AddAlwaysEnabled_Command().FireAndForget());
this.WhenActivated(disposables =>
{
this.Bind(ViewModel, vm => vm.BasePath, view => view.BaseFolder.SelectedPath)
.DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SettingsFile, view => view.SettingsFile.SelectedPath)
.DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.Downloads, view => view.DownloadsFolder.SelectedPath)
.DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.OutputFolder, view => view.OutputFolder.SelectedPath)
.DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.AllGames, view => view.BaseGame.Items)
.DisposeWith(disposables);
@ -33,8 +41,25 @@ namespace Wabbajack.App.Screens
this.BindCommand(ViewModel, vm => vm.StartCompilation, view => view.StartCompilation)
.DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.AlwaysEnabled, view => view.AlwaysEnabledList.Items,
d => d!.Select(itm => new RemovableItemViewModel()
{
Text = itm.ToString(),
DeleteCommand = ReactiveCommand.Create(() => { ViewModel?.RemoveAlwaysExcluded(itm); })
}))
.DisposeWith(disposables);
});
}
private async Task AddAlwaysEnabled_Command()
{
var dialog = new OpenFolderDialog()
{
Title = "Select a folder",
};
var result = await dialog.ShowAsync(App.MainWindow);
if (!string.IsNullOrWhiteSpace(result))
ViewModel!.AddAlwaysExcluded(result.ToAbsolutePath());
}
}
}

View File

@ -1,14 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Avalonia.Controls.Mixins;
using DynamicData;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Wabbajack.App.Extensions;
using Wabbajack.App.Messages;
using Wabbajack.App.ViewModels;
using Wabbajack.Common;
using Wabbajack.Compiler;
using Wabbajack.DTOs;
using Wabbajack.Installer;
@ -38,12 +41,18 @@ public class CompilerConfigurationViewModel : ViewModelBase, IReceiverMarker
[Reactive]
public string SelectedProfile { get; set; }
[Reactive]
public AbsolutePath OutputFolder { get; set; }
[Reactive]
public IEnumerable<GameMetaData> AllGames { get; set; }
[Reactive]
public ReactiveCommand<Unit, Unit> StartCompilation { get; set; }
[Reactive]
public IEnumerable<RelativePath> AlwaysEnabled { get; set; } = Array.Empty<RelativePath>();
public CompilerConfigurationViewModel()
{
@ -52,6 +61,8 @@ public class CompilerConfigurationViewModel : ViewModelBase, IReceiverMarker
AllGames = GameRegistry.Games.Values.ToArray();
StartCompilation = ReactiveCommand.Create(() => BeginCompilation());
OutputFolder = KnownFolders.EntryPoint;
this.WhenActivated(disposables =>
{
@ -88,7 +99,9 @@ public class CompilerConfigurationViewModel : ViewModelBase, IReceiverMarker
Source = BasePath,
Game = BaseGame.Game,
Profile = SelectedProfile,
UseGamePaths = true
UseGamePaths = true,
OutputFile = OutputFolder.Combine(SelectedProfile).WithExtension(Ext.Wabbajack),
AlwaysEnabled = AlwaysEnabled.ToArray()
};
MessageBus.Instance.Send(new StartCompilation(settings));
@ -125,5 +138,18 @@ public class CompilerConfigurationViewModel : ViewModelBase, IReceiverMarker
return default;
}
public bool AddAlwaysExcluded(AbsolutePath path)
{
if (!path.InFolder(BasePath)) return false;
var relative = path.RelativeTo(BasePath);
AlwaysEnabled = AlwaysEnabled.Append(relative).Distinct().ToArray();
return true;
}
public void RemoveAlwaysExcluded(RelativePath path)
{
AlwaysEnabled = AlwaysEnabled.Where(p => p != path).ToArray();
}
}

View File

@ -5,5 +5,6 @@ namespace Wabbajack.Compiler
public class MO2CompilerSettings : CompilerSettings
{
public string Profile { get; set; }
public RelativePath[] AlwaysEnabled { get; set; }
}
}