Intermediate, fixes a lot of update problems, keeping selection in place when updating planets still broken.

This commit is contained in:
2024-11-27 18:40:14 +01:00
parent e79a308243
commit 4789904284
4 changed files with 45 additions and 10 deletions

View File

@ -15,23 +15,38 @@ public partial class BuColViewModel : ViewModelBase
private readonly ReadOnlyObservableCollection<PlayerPlanetViewModel> _playerPlanetsView;
public ReadOnlyObservableCollection<PlayerPlanetViewModel> PlayerPlanets => _playerPlanetsView;
[Reactive]
private PlayerPlanetViewModel? _selectedPlanet;
private string? _lastSelectedPlanetName;
public BuColViewModel()
{
var PlanetManager = Locator.Current.GetService<PlanetManager>()!;
var planetManager = Locator.Current.GetService<PlanetManager>()!;
PlanetManager.PlayerPlanetsSource
planetManager.PlayerPlanetsSource
.ObserveOn(RxApp.MainThreadScheduler)
.Bind(out _playerPlanetsView)
.DisposeMany()
.Subscribe();
this.WhenAnyValue(x => x.SelectedPlanet)
.Subscribe(planet => _lastSelectedPlanetName = planet?.Name);
this.WhenActivated((CompositeDisposable disposables) =>
{
// /* handle activation */
// Disposable
// .Create(() => { /* handle deactivation */ })
// .DisposeWith(disposables);
planetManager.PlanetsReloaded
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(_ => RestoreSelection())
.DisposeWith(disposables);
});
}
private void RestoreSelection()
{
if (_lastSelectedPlanetName != null)
{
SelectedPlanet = PlayerPlanets.FirstOrDefault(p => p.Name == _lastSelectedPlanetName);
}
}
}

View File

@ -67,6 +67,8 @@ public partial class PlayerPlanetViewModel : ViewModelBase
_fleetSummaryChanges = fm.FleetSummariesByDestination
.Connect()
.Watch(Name)
.Replay(1)
.RefCount()
.Log(this, "fleetSummaryChange", change => $"{Name}: {change.Reason}: {change.Previous} => {change.Current}")
;
@ -94,8 +96,9 @@ public partial class PlayerPlanetViewModel : ViewModelBase
.ToProperty(this, vm => vm.EnRouteGermanium)
;
this.WhenActivated((CompositeDisposable disposables) =>
this.WhenActivated((CompositeDisposable disposables) =>
{
_fleetSummaryChanges.Subscribe().DisposeWith(disposables);
disposables.Add(_enRoutePopulationHelper);
disposables.Add(_enRouteIroniumHelper);
disposables.Add(_enRouteBoraniumHelper);