From 8f63587966d744d8224c86fb33a1b8e4f4b74553 Mon Sep 17 00:00:00 2001 From: Torben Nehmer Date: Tue, 21 Jan 2025 20:18:05 +0100 Subject: [PATCH] fixups for player planet model updates --- Stars Assistant/Services/PlanetManager.cs | 2 +- .../ViewModels/PlayerPlanetViewModel.cs | 125 ++++++++++-------- 2 files changed, 70 insertions(+), 57 deletions(-) diff --git a/Stars Assistant/Services/PlanetManager.cs b/Stars Assistant/Services/PlanetManager.cs index 72ac62b..bef5ce3 100644 --- a/Stars Assistant/Services/PlanetManager.cs +++ b/Stars Assistant/Services/PlanetManager.cs @@ -85,7 +85,7 @@ public class PlanetManager : IDisposable, IEnableLogger if (playerPlanet.HasValue) playerPlanet.Value.Planet = planet; else - innerCache.Add(new PlayerPlanetViewModel(planet)); + innerCache.AddOrUpdate(new PlayerPlanetViewModel(planet)); } } ); diff --git a/Stars Assistant/ViewModels/PlayerPlanetViewModel.cs b/Stars Assistant/ViewModels/PlayerPlanetViewModel.cs index 08ffd6d..203fad1 100644 --- a/Stars Assistant/ViewModels/PlayerPlanetViewModel.cs +++ b/Stars Assistant/ViewModels/PlayerPlanetViewModel.cs @@ -16,18 +16,26 @@ public partial class PlayerPlanetViewModel : ViewModelBase [Reactive] private Model.Planet _planet; - /* TODO + /* public Model.Planet Planet { get => _planet; set { - this.RaiseAndSetIfChanged(ref _planet, value); - RaisePropertyChangedForAll(); + //this.RaiseAndSetIfChanged(ref _planet, value); + //RaisePropertyChangedForAll(); } } */ + /* + private void RaisePropertyChangedForAll() + { + ONPropertChanged(nameof(Name)); + + } + */ + private readonly Services.Game Game; private readonly IObservable> _fleetSummaryChanges; @@ -41,12 +49,17 @@ public partial class PlayerPlanetViewModel : ViewModelBase Planet = planet; PopulationTargetPercent = planet.PopulationTargetPercent; + + this.WhenAnyValue(vm => vm.Planet) + .Subscribe(_ => this.RaisePlanetChangedNotifications()); _populationTargetHelper = this - .WhenAnyValue(vm => vm.PopulationTargetPercent) + .WhenAnyValue(vm => vm.PopulationTargetPercent, + vm => vm.Planet, + (popTgtPct, _) => popTgtPct) .Select(popTgt => this.MaxPopulation * popTgt / 10000 * 100) .ToProperty(this, vm => vm.PopulationTarget); - + _populationToShipHelper = this .WhenAnyValue(vm => vm.PopulationTarget) .Select(popToShip => this.ComputePopulationToShip()) @@ -281,57 +294,57 @@ public partial class PlayerPlanetViewModel : ViewModelBase AvailableGermanium + EnRouteGermanium + MRGermanium - gerReq , 0); } - - private void RaisePropertyChangedForAll() -{ - OnPropertyChanged(nameof(Name)); - OnPropertyChanged(nameof(Owner)); - OnPropertyChanged(nameof(StarbaseType)); - OnPropertyChanged(nameof(Population)); - OnPropertyChanged(nameof(Value)); - OnPropertyChanged(nameof(Mines)); - OnPropertyChanged(nameof(Factories)); - OnPropertyChanged(nameof(DefPercent)); - OnPropertyChanged(nameof(SurfaceIronium)); - OnPropertyChanged(nameof(SurfaceBoranium)); - OnPropertyChanged(nameof(SurfaceGermanium)); - OnPropertyChanged(nameof(MRIronium)); - OnPropertyChanged(nameof(MRBoranium)); - OnPropertyChanged(nameof(MRGermanium)); - OnPropertyChanged(nameof(MCIronium)); - OnPropertyChanged(nameof(MCBoranium)); - OnPropertyChanged(nameof(MCGermanium)); - OnPropertyChanged(nameof(Resources)); - OnPropertyChanged(nameof(Gravity)); - OnPropertyChanged(nameof(Temperature)); - OnPropertyChanged(nameof(Radiation)); - OnPropertyChanged(nameof(GravityOrig)); - OnPropertyChanged(nameof(TemperatureOrig)); - OnPropertyChanged(nameof(RadiationOrig)); - OnPropertyChanged(nameof(MaxTerraforming)); - OnPropertyChanged(nameof(CapacityPercent)); - OnPropertyChanged(nameof(ScanRange)); - OnPropertyChanged(nameof(PenScanRange)); - OnPropertyChanged(nameof(Driver)); - OnPropertyChanged(nameof(DriverWarp)); - OnPropertyChanged(nameof(RouteTarget)); - OnPropertyChanged(nameof(GateRange)); - OnPropertyChanged(nameof(GateMass)); - OnPropertyChanged(nameof(PctDamage)); - OnPropertyChanged(nameof(EffectiveValue)); - OnPropertyChanged(nameof(MaxPopulation)); - OnPropertyChanged(nameof(PopulationGrowth)); - OnPropertyChanged(nameof(PopulationT1)); - OnPropertyChanged(nameof(BuildableFactories)); - OnPropertyChanged(nameof(BuildableMines)); - OnPropertyChanged(nameof(OperableFactories)); - OnPropertyChanged(nameof(OperableMines)); - OnPropertyChanged(nameof(ResourcesFromPopulation)); - OnPropertyChanged(nameof(ResourcesFromFactories)); - OnPropertyChanged(nameof(AvailableIronium)); - OnPropertyChanged(nameof(AvailableBoranium)); - OnPropertyChanged(nameof(AvailableGermanium)); -} + + private void RaisePlanetChangedNotifications() + { + this.RaisePropertyChanged(nameof(Name)); + this.RaisePropertyChanged(nameof(Owner)); + this.RaisePropertyChanged(nameof(StarbaseType)); + this.RaisePropertyChanged(nameof(Population)); + this.RaisePropertyChanged(nameof(Value)); + this.RaisePropertyChanged(nameof(Mines)); + this.RaisePropertyChanged(nameof(Factories)); + this.RaisePropertyChanged(nameof(DefPercent)); + this.RaisePropertyChanged(nameof(SurfaceIronium)); + this.RaisePropertyChanged(nameof(SurfaceBoranium)); + this.RaisePropertyChanged(nameof(SurfaceGermanium)); + this.RaisePropertyChanged(nameof(MRIronium)); + this.RaisePropertyChanged(nameof(MRBoranium)); + this.RaisePropertyChanged(nameof(MRGermanium)); + this.RaisePropertyChanged(nameof(MCIronium)); + this.RaisePropertyChanged(nameof(MCBoranium)); + this.RaisePropertyChanged(nameof(MCGermanium)); + this.RaisePropertyChanged(nameof(Resources)); + this.RaisePropertyChanged(nameof(Gravity)); + this.RaisePropertyChanged(nameof(Temperature)); + this.RaisePropertyChanged(nameof(Radiation)); + this.RaisePropertyChanged(nameof(GravityOrig)); + this.RaisePropertyChanged(nameof(TemperatureOrig)); + this.RaisePropertyChanged(nameof(RadiationOrig)); + this.RaisePropertyChanged(nameof(MaxTerraforming)); + this.RaisePropertyChanged(nameof(CapacityPercent)); + this.RaisePropertyChanged(nameof(ScanRange)); + this.RaisePropertyChanged(nameof(PenScanRange)); + this.RaisePropertyChanged(nameof(Driver)); + this.RaisePropertyChanged(nameof(DriverWarp)); + this.RaisePropertyChanged(nameof(RouteTarget)); + this.RaisePropertyChanged(nameof(GateRange)); + this.RaisePropertyChanged(nameof(GateMass)); + this.RaisePropertyChanged(nameof(PctDamage)); + this.RaisePropertyChanged(nameof(EffectiveValue)); + this.RaisePropertyChanged(nameof(MaxPopulation)); + this.RaisePropertyChanged(nameof(PopulationGrowth)); + this.RaisePropertyChanged(nameof(PopulationT1)); + this.RaisePropertyChanged(nameof(BuildableFactories)); + this.RaisePropertyChanged(nameof(BuildableMines)); + this.RaisePropertyChanged(nameof(OperableFactories)); + this.RaisePropertyChanged(nameof(OperableMines)); + this.RaisePropertyChanged(nameof(ResourcesFromPopulation)); + this.RaisePropertyChanged(nameof(ResourcesFromFactories)); + this.RaisePropertyChanged(nameof(AvailableIronium)); + this.RaisePropertyChanged(nameof(AvailableBoranium)); + this.RaisePropertyChanged(nameof(AvailableGermanium)); + } #endregion