fixups for player planet model updates

This commit is contained in:
Torben Nehmer 2025-01-21 20:18:05 +01:00
parent ef5a8ae4af
commit 8f63587966
No known key found for this signature in database
2 changed files with 70 additions and 57 deletions

View File

@ -85,7 +85,7 @@ public class PlanetManager : IDisposable, IEnableLogger
if (playerPlanet.HasValue) if (playerPlanet.HasValue)
playerPlanet.Value.Planet = planet; playerPlanet.Value.Planet = planet;
else else
innerCache.Add(new PlayerPlanetViewModel(planet)); innerCache.AddOrUpdate(new PlayerPlanetViewModel(planet));
} }
} }
); );

View File

@ -16,18 +16,26 @@ public partial class PlayerPlanetViewModel : ViewModelBase
[Reactive] [Reactive]
private Model.Planet _planet; private Model.Planet _planet;
/* TODO /*
public Model.Planet Planet public Model.Planet Planet
{ {
get => _planet; get => _planet;
set set
{ {
this.RaiseAndSetIfChanged(ref _planet, value); //this.RaiseAndSetIfChanged(ref _planet, value);
RaisePropertyChangedForAll(); //RaisePropertyChangedForAll();
} }
} }
*/ */
/*
private void RaisePropertyChangedForAll()
{
ONPropertChanged(nameof(Name));
}
*/
private readonly Services.Game Game; private readonly Services.Game Game;
private readonly IObservable<Change<FleetSummaryByDestination, string>> _fleetSummaryChanges; private readonly IObservable<Change<FleetSummaryByDestination, string>> _fleetSummaryChanges;
@ -42,8 +50,13 @@ public partial class PlayerPlanetViewModel : ViewModelBase
Planet = planet; Planet = planet;
PopulationTargetPercent = planet.PopulationTargetPercent; PopulationTargetPercent = planet.PopulationTargetPercent;
this.WhenAnyValue(vm => vm.Planet)
.Subscribe(_ => this.RaisePlanetChangedNotifications());
_populationTargetHelper = this _populationTargetHelper = this
.WhenAnyValue(vm => vm.PopulationTargetPercent) .WhenAnyValue(vm => vm.PopulationTargetPercent,
vm => vm.Planet,
(popTgtPct, _) => popTgtPct)
.Select(popTgt => this.MaxPopulation * popTgt / 10000 * 100) .Select(popTgt => this.MaxPopulation * popTgt / 10000 * 100)
.ToProperty(this, vm => vm.PopulationTarget); .ToProperty(this, vm => vm.PopulationTarget);
@ -282,55 +295,55 @@ public partial class PlayerPlanetViewModel : ViewModelBase
, 0); , 0);
} }
private void RaisePropertyChangedForAll() private void RaisePlanetChangedNotifications()
{ {
OnPropertyChanged(nameof(Name)); this.RaisePropertyChanged(nameof(Name));
OnPropertyChanged(nameof(Owner)); this.RaisePropertyChanged(nameof(Owner));
OnPropertyChanged(nameof(StarbaseType)); this.RaisePropertyChanged(nameof(StarbaseType));
OnPropertyChanged(nameof(Population)); this.RaisePropertyChanged(nameof(Population));
OnPropertyChanged(nameof(Value)); this.RaisePropertyChanged(nameof(Value));
OnPropertyChanged(nameof(Mines)); this.RaisePropertyChanged(nameof(Mines));
OnPropertyChanged(nameof(Factories)); this.RaisePropertyChanged(nameof(Factories));
OnPropertyChanged(nameof(DefPercent)); this.RaisePropertyChanged(nameof(DefPercent));
OnPropertyChanged(nameof(SurfaceIronium)); this.RaisePropertyChanged(nameof(SurfaceIronium));
OnPropertyChanged(nameof(SurfaceBoranium)); this.RaisePropertyChanged(nameof(SurfaceBoranium));
OnPropertyChanged(nameof(SurfaceGermanium)); this.RaisePropertyChanged(nameof(SurfaceGermanium));
OnPropertyChanged(nameof(MRIronium)); this.RaisePropertyChanged(nameof(MRIronium));
OnPropertyChanged(nameof(MRBoranium)); this.RaisePropertyChanged(nameof(MRBoranium));
OnPropertyChanged(nameof(MRGermanium)); this.RaisePropertyChanged(nameof(MRGermanium));
OnPropertyChanged(nameof(MCIronium)); this.RaisePropertyChanged(nameof(MCIronium));
OnPropertyChanged(nameof(MCBoranium)); this.RaisePropertyChanged(nameof(MCBoranium));
OnPropertyChanged(nameof(MCGermanium)); this.RaisePropertyChanged(nameof(MCGermanium));
OnPropertyChanged(nameof(Resources)); this.RaisePropertyChanged(nameof(Resources));
OnPropertyChanged(nameof(Gravity)); this.RaisePropertyChanged(nameof(Gravity));
OnPropertyChanged(nameof(Temperature)); this.RaisePropertyChanged(nameof(Temperature));
OnPropertyChanged(nameof(Radiation)); this.RaisePropertyChanged(nameof(Radiation));
OnPropertyChanged(nameof(GravityOrig)); this.RaisePropertyChanged(nameof(GravityOrig));
OnPropertyChanged(nameof(TemperatureOrig)); this.RaisePropertyChanged(nameof(TemperatureOrig));
OnPropertyChanged(nameof(RadiationOrig)); this.RaisePropertyChanged(nameof(RadiationOrig));
OnPropertyChanged(nameof(MaxTerraforming)); this.RaisePropertyChanged(nameof(MaxTerraforming));
OnPropertyChanged(nameof(CapacityPercent)); this.RaisePropertyChanged(nameof(CapacityPercent));
OnPropertyChanged(nameof(ScanRange)); this.RaisePropertyChanged(nameof(ScanRange));
OnPropertyChanged(nameof(PenScanRange)); this.RaisePropertyChanged(nameof(PenScanRange));
OnPropertyChanged(nameof(Driver)); this.RaisePropertyChanged(nameof(Driver));
OnPropertyChanged(nameof(DriverWarp)); this.RaisePropertyChanged(nameof(DriverWarp));
OnPropertyChanged(nameof(RouteTarget)); this.RaisePropertyChanged(nameof(RouteTarget));
OnPropertyChanged(nameof(GateRange)); this.RaisePropertyChanged(nameof(GateRange));
OnPropertyChanged(nameof(GateMass)); this.RaisePropertyChanged(nameof(GateMass));
OnPropertyChanged(nameof(PctDamage)); this.RaisePropertyChanged(nameof(PctDamage));
OnPropertyChanged(nameof(EffectiveValue)); this.RaisePropertyChanged(nameof(EffectiveValue));
OnPropertyChanged(nameof(MaxPopulation)); this.RaisePropertyChanged(nameof(MaxPopulation));
OnPropertyChanged(nameof(PopulationGrowth)); this.RaisePropertyChanged(nameof(PopulationGrowth));
OnPropertyChanged(nameof(PopulationT1)); this.RaisePropertyChanged(nameof(PopulationT1));
OnPropertyChanged(nameof(BuildableFactories)); this.RaisePropertyChanged(nameof(BuildableFactories));
OnPropertyChanged(nameof(BuildableMines)); this.RaisePropertyChanged(nameof(BuildableMines));
OnPropertyChanged(nameof(OperableFactories)); this.RaisePropertyChanged(nameof(OperableFactories));
OnPropertyChanged(nameof(OperableMines)); this.RaisePropertyChanged(nameof(OperableMines));
OnPropertyChanged(nameof(ResourcesFromPopulation)); this.RaisePropertyChanged(nameof(ResourcesFromPopulation));
OnPropertyChanged(nameof(ResourcesFromFactories)); this.RaisePropertyChanged(nameof(ResourcesFromFactories));
OnPropertyChanged(nameof(AvailableIronium)); this.RaisePropertyChanged(nameof(AvailableIronium));
OnPropertyChanged(nameof(AvailableBoranium)); this.RaisePropertyChanged(nameof(AvailableBoranium));
OnPropertyChanged(nameof(AvailableGermanium)); this.RaisePropertyChanged(nameof(AvailableGermanium));
} }
#endregion #endregion