Fixes for progress bars starting at 100%

This commit is contained in:
Justin Swanson 2019-12-17 21:10:38 -06:00
parent 4fc9f58d88
commit e0a91036d0
6 changed files with 58 additions and 51 deletions

View File

@ -44,6 +44,15 @@ namespace Wabbajack
.Unit();
}
public static IObservable<Unit> EndingExecution(this IReactiveCommand cmd)
{
return cmd.IsExecuting
.DistinctUntilChanged()
.Pairwise()
.Where(x => x.Previous && !x.Current)
.Unit();
}
/// These snippets were provided by RolandPheasant (author of DynamicData)
/// They'll be going into the official library at some point, but are here for now.
#region Dynamic Data EnsureUniqueChanges

View File

@ -52,14 +52,11 @@ namespace Wabbajack
private readonly ObservableAsPropertyHelper<IUserIntervention> _ActiveGlobalUserIntervention;
public IUserIntervention ActiveGlobalUserIntervention => _ActiveGlobalUserIntervention.Value;
private readonly ObservableAsPropertyHelper<bool> _Completed;
public bool Completed => _Completed.Value;
/// <summary>
/// Tracks whether compilation has begun
/// </summary>
[Reactive]
public bool CompilationMode { get; set; }
public bool StartedCompilation { get; set; }
[Reactive]
public bool Completed { get; set; }
public CompilerVM(MainWindowVM mainWindowVM)
{
@ -137,7 +134,8 @@ namespace Wabbajack
execute: () =>
{
mainWindowVM.ActivePane = mainWindowVM.ModeSelectionVM;
CompilationMode = false;
StartedCompilation = false;
Completed = false;
},
canExecute: this.WhenAny(x => x.Compiling)
.Select(x => !x));
@ -166,15 +164,6 @@ namespace Wabbajack
.Subscribe()
.DisposeWith(CompositeDisposable);
_Completed = Observable.CombineLatest(
this.WhenAny(x => x.Compiling),
this.WhenAny(x => x.CompilationMode),
resultSelector: (installing, installingMode) =>
{
return installingMode && !installing;
})
.ToProperty(this, nameof(Completed));
_percentCompleted = this.WhenAny(x => x.Compiler.ActiveCompilation)
.StartWith(default(ACompiler))
.CombineLatest(
@ -185,19 +174,29 @@ namespace Wabbajack
{
return Observable.Return<float>(completed ? 1f : 0f);
}
return compiler.PercentCompleted;
return compiler.PercentCompleted.StartWith(0);
})
.Switch()
.Debounce(TimeSpan.FromMilliseconds(25))
.ToProperty(this, nameof(PercentCompleted));
// When sub compiler begins an install, mark state variable
// When sub compiler begins a compile, mark state variable
this.WhenAny(x => x.Compiler.BeginCommand)
.Select(x => x?.StartingExecution() ?? Observable.Empty<Unit>())
.Switch()
.Subscribe(_ =>
{
CompilationMode = true;
StartedCompilation = true;
})
.DisposeWith(CompositeDisposable);
// When sub compiler finishes a compile, mark state variable
this.WhenAny(x => x.Compiler.BeginCommand)
.Select(x => x?.EndingExecution() ?? Observable.Empty<Unit>())
.Switch()
.Subscribe(_ =>
{
Completed = true;
})
.DisposeWith(CompositeDisposable);

View File

@ -46,11 +46,11 @@ namespace Wabbajack
private readonly ObservableAsPropertyHelper<bool> _installing;
public bool Installing => _installing.Value;
/// <summary>
/// Tracks whether installation has begun
/// </summary>
[Reactive]
public bool InstallingMode { get; set; }
public bool StartedInstallation { get; set; }
[Reactive]
public bool Completed { get; set; }
private readonly ObservableAsPropertyHelper<ImageSource> _image;
public ImageSource Image => _image.Value;
@ -82,9 +82,6 @@ namespace Wabbajack
private readonly ObservableAsPropertyHelper<IUserIntervention> _ActiveGlobalUserIntervention;
public IUserIntervention ActiveGlobalUserIntervention => _ActiveGlobalUserIntervention.Value;
private readonly ObservableAsPropertyHelper<bool> _Completed;
public bool Completed => _Completed.Value;
// Command properties
public IReactiveCommand ShowReportCommand { get; }
public IReactiveCommand OpenReadmeCommand { get; }
@ -163,7 +160,7 @@ namespace Wabbajack
.Select(modList => modList?.ReportHTML)
.ToProperty(this, nameof(HTMLReport));
_installing = this.WhenAny(x => x.Installer.ActiveInstallation)
.Select(compilation => compilation != null)
.Select(i => i != null)
.ObserveOnGuiThread()
.ToProperty(this, nameof(Installing));
_TargetManager = this.WhenAny(x => x.ModList)
@ -182,21 +179,13 @@ namespace Wabbajack
BackCommand = ReactiveCommand.Create(
execute: () =>
{
InstallingMode = false;
StartedInstallation = false;
Completed = false;
mainWindowVM.ActivePane = mainWindowVM.ModeSelectionVM;
},
canExecute: this.WhenAny(x => x.Installing)
.Select(x => !x));
_Completed = Observable.CombineLatest(
this.WhenAny(x => x.Installing),
this.WhenAny(x => x.InstallingMode),
resultSelector: (installing, installingMode) =>
{
return installingMode && !installing;
})
.ToProperty(this, nameof(Completed));
_percentCompleted = this.WhenAny(x => x.Installer.ActiveInstallation)
.StartWith(default(AInstaller))
.CombineLatest(
@ -207,7 +196,7 @@ namespace Wabbajack
{
return Observable.Return<float>(completed ? 1f : 0f);
}
return installer.PercentCompleted;
return installer.PercentCompleted.StartWith(0f);
})
.Switch()
.Debounce(TimeSpan.FromMilliseconds(25))
@ -285,11 +274,11 @@ namespace Wabbajack
_progressTitle = Observable.CombineLatest(
this.WhenAny(x => x.Installing),
this.WhenAny(x => x.InstallingMode),
resultSelector: (installing, mode) =>
this.WhenAny(x => x.StartedInstallation),
resultSelector: (installing, started) =>
{
if (!installing) return "Configuring";
return mode ? "Installing" : "Installed";
return started ? "Installing" : "Installed";
})
.ToProperty(this, nameof(ProgressTitle));
@ -323,7 +312,17 @@ namespace Wabbajack
.Switch()
.Subscribe(_ =>
{
InstallingMode = true;
StartedInstallation = true;
})
.DisposeWith(CompositeDisposable);
// When sub installer ends an install, mark state variable
this.WhenAny(x => x.Installer.BeginCommand)
.Select(x => x?.EndingExecution() ?? Observable.Empty<Unit>())
.Switch()
.Subscribe(_ =>
{
Completed = true;
})
.DisposeWith(CompositeDisposable);

View File

@ -65,7 +65,7 @@
x:Name="LargeProgressBar"
Grid.Column="0"
Grid.ColumnSpan="4"
Background="#88121212"
Background="#AA121212"
BorderThickness="0"
Maximum="1"
Opacity="{Binding ProgressOpacityPercent, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"

View File

@ -174,7 +174,7 @@
Margin="35,0,35,0"
VerticalAlignment="Center"
ClipToBounds="False"
Visibility="{Binding CompilationMode, Converter={StaticResource bool2VisibilityConverter}, ConverterParameter=False}">
Visibility="{Binding StartedCompilation, Converter={StaticResource bool2VisibilityConverter}, ConverterParameter=False}">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
@ -240,7 +240,7 @@
Grid.Column="0"
Grid.ColumnSpan="5"
Margin="5"
Visibility="{Binding CompilationMode, Converter={StaticResource bool2VisibilityConverter}, FallbackValue=Hidden}">
Visibility="{Binding StartedCompilation, Converter={StaticResource bool2VisibilityConverter}, FallbackValue=Hidden}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*" />
<ColumnDefinition Width="5" />

View File

@ -206,7 +206,7 @@
ToolTip="Pause Installation"
Margin="0,0,0,5"
Width="50"
Visibility="{Binding InstallingMode, Converter={StaticResource bool2VisibilityConverter}}">
Visibility="{Binding StartedInstallation, Converter={StaticResource bool2VisibilityConverter}}">
<icon:PackIconMaterial
Kind="Pause" />
</Button>
@ -214,7 +214,7 @@
ToolTip="Stop Installation"
Margin="0,0,0,5"
Width="50"
Visibility="{Binding InstallingMode, Converter={StaticResource bool2VisibilityConverter}}" >
Visibility="{Binding StartedInstallation, Converter={StaticResource bool2VisibilityConverter}}" >
<icon:PackIconFontAwesome
Width="25"
Height="25"
@ -240,7 +240,7 @@
Grid.Row="2"
Margin="5,0,5,5"
ClipToBounds="True"
Visibility="{Binding InstallingMode, Converter={StaticResource bool2VisibilityConverter}, ConverterParameter=False}">
Visibility="{Binding StartedInstallation, Converter={StaticResource bool2VisibilityConverter}, ConverterParameter=False}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="4" />
@ -339,7 +339,7 @@
Margin="5"
VerticalAlignment="Center"
Background="Transparent"
Visibility="{Binding InstallingMode, Converter={StaticResource bool2VisibilityConverter}, ConverterParameter=False}">
Visibility="{Binding StartedInstallation, Converter={StaticResource bool2VisibilityConverter}, ConverterParameter=False}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
@ -394,7 +394,7 @@
<Grid
Grid.Row="2"
Margin="5,0,5,5"
Visibility="{Binding InstallingMode, Converter={StaticResource bool2VisibilityConverter}, FallbackValue=Hidden}">
Visibility="{Binding StartedInstallation, Converter={StaticResource bool2VisibilityConverter}, FallbackValue=Hidden}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*" />
<ColumnDefinition Width="5" />