From c3280320da3b00fbdcb1410d3fbe5c7003b8898e Mon Sep 17 00:00:00 2001 From: erri120 Date: Wed, 6 Sep 2023 15:14:41 +0200 Subject: [PATCH] more highlighting --- .../GuidedInstallerStepDesignViewModel.cs | 16 ++++- .../Step/GuidedInstallerStepView.axaml.cs | 7 ++- .../Step/GuidedInstallerStepViewModel.cs | 58 +++++++++++++++++++ 3 files changed, 79 insertions(+), 2 deletions(-) diff --git a/src/Games/NexusMods.Games.FOMOD.UI/Step/GuidedInstallerStepDesignViewModel.cs b/src/Games/NexusMods.Games.FOMOD.UI/Step/GuidedInstallerStepDesignViewModel.cs index 19b7668aba..200cc99592 100644 --- a/src/Games/NexusMods.Games.FOMOD.UI/Step/GuidedInstallerStepDesignViewModel.cs +++ b/src/Games/NexusMods.Games.FOMOD.UI/Step/GuidedInstallerStepDesignViewModel.cs @@ -1,4 +1,6 @@ using System.Reactive; +using System.Reactive.Disposables; +using System.Reactive.Linq; using NexusMods.App.UI; using NexusMods.Common.GuidedInstaller; using NexusMods.Common.GuidedInstaller.ValueObjects; @@ -25,7 +27,19 @@ public GuidedInstallerStepDesignViewModel() Groups = step.Groups .Select(group => (IGuidedInstallerGroupViewModel)new GuidedInstallerGroupDesignViewModel(group)) .ToArray(); - HighlightedOption = step.Groups[0].Options[0]; + + this.WhenActivated(disposables => + { + Groups + .Select(groupVM => groupVM + .WhenAnyValue(x => x.HighlightedOption)) + .CombineLatest() + .SubscribeWithErrorLogging(logger: default, options => + { + HighlightedOption = options.FirstOrDefault(); + }) + .DisposeWith(disposables); + }); } private static GuidedInstallationStep SetupInstallationStep() diff --git a/src/Games/NexusMods.Games.FOMOD.UI/Step/GuidedInstallerStepView.axaml.cs b/src/Games/NexusMods.Games.FOMOD.UI/Step/GuidedInstallerStepView.axaml.cs index 83c81976e0..ddd13ae95b 100644 --- a/src/Games/NexusMods.Games.FOMOD.UI/Step/GuidedInstallerStepView.axaml.cs +++ b/src/Games/NexusMods.Games.FOMOD.UI/Step/GuidedInstallerStepView.axaml.cs @@ -1,5 +1,6 @@ using System.Reactive.Disposables; using Avalonia.ReactiveUI; +using NexusMods.App.UI; using ReactiveUI; namespace NexusMods.Games.FOMOD.UI; @@ -15,7 +16,11 @@ public GuidedInstallerStepView() this.OneWayBind(ViewModel, vm => vm.InstallationStep!.Name, view => view.StepName.Text) .DisposeWith(disposables); - this.OneWayBind(ViewModel, vm => vm.HighlightedOption!.Description, view => view.HighlightedOptionDescription.Text) + this.WhenAnyValue(x => x.ViewModel!.HighlightedOption) + .SubscribeWithErrorLogging(logger: default, option => + { + HighlightedOptionDescription.Text = option?.Description ?? string.Empty; + }) .DisposeWith(disposables); this.OneWayBind(ViewModel, vm => vm.Groups, view => view.GroupItemsControl.ItemsSource) diff --git a/src/Games/NexusMods.Games.FOMOD.UI/Step/GuidedInstallerStepViewModel.cs b/src/Games/NexusMods.Games.FOMOD.UI/Step/GuidedInstallerStepViewModel.cs index b8c1ea6184..de05351559 100644 --- a/src/Games/NexusMods.Games.FOMOD.UI/Step/GuidedInstallerStepViewModel.cs +++ b/src/Games/NexusMods.Games.FOMOD.UI/Step/GuidedInstallerStepViewModel.cs @@ -65,6 +65,64 @@ public GuidedInstallerStepViewModel(ILogger logger .ToArray(); }) .DisposeWith(disposables); + + this.WhenAnyValue(x => x.Groups) + .Where(x => x.Length != 0) + .Select(groupVMs => groupVMs + .Select(groupVM => groupVM + .WhenAnyValue(x => x.HighlightedOption) + ) + .CombineLatest() + ) + .SubscribeWithErrorLogging(logger: default, observable => + { + // TODO: clean this up + observable + .SubscribeWithErrorLogging(logger: default, options => + { + HighlightedOption = options.FirstOrDefault(); + }) + .DisposeWith(disposables); + }) + .DisposeWith(disposables); + + // Groups + // .Select(groupVM => groupVM + // .WhenAnyValue(x => x.HighlightedOption) + // ) + // .CombineLatest() + // // .SelectMany(x => x) + // .SubscribeWithErrorLogging(logger: default, options => + // { + // HighlightedOption = options.FirstOrDefault(x => x is not null); + // }) + // .DisposeWith(disposables); + + // Groups + // .Select(groupVM => groupVM + // .WhenAnyValue(x => x.HighlightedOption) + // .Select(x => (groupVM, option: x)) + // ) + // .CombineLatest() + // .SubscribeWithErrorLogging(logger: default, options => + // { + // var previousOption = HighlightedOption; + // if (previousOption is null) + // { + // HighlightedOption = options + // .Select(x => x.option) + // .FirstOrDefault(x => x is not null); + // return; + // } + // + // var highlightedOptions = options + // .Where(x => x.option is not null) + // .Select(x => x) + // .ToArray(); + // + // + // }) + // .DisposeWith(disposables); }); } }