public MainWindowViewModel(IEliteDangerousApi api, MissionCatchUp missionCatchUp, MissionTargetManager missionTargetManager, StateTracker tracker) { Router = new RoutingState(); Activator = new ViewModelActivator(); api.Events().OnCatchedUp .Select(_ => true) .ObserveOn(RxApp.MainThreadScheduler) .ToPropertyEx(this, x => x.DoneLoading); // Change what is showing this.WhenActivated(disposables => { var filledMissionCountChanged = missionTargetManager .Connect() .Where(m => m.IsFilled) .ObserveOn(RxApp.MainThreadScheduler) .Bind(out var stationMissions) .DisposeMany(); api.Events().OnStart .Select(_ => new LocationUpdate(false, "", "")) .Merge(tracker.Location) .CombineLatest(filledMissionCountChanged.Select(_ => 0).Prepend(0), (dockedLocation, _) => dockedLocation) .CombineLatest(api.Events().OnCatchedUp.Delay(TimeSpan.FromMilliseconds(50)), (location, _) => location) // .Where(_ => DoneLoading) .ObserveOn(RxApp.MainThreadScheduler) .Select(e => { var showTurnIn = e.IsDocked ? stationMissions.Any(m => m.Station == e.Station) : stationMissions.Any(m => m.System == e.System); return(showTurnIn // true ? (IRoutableViewModel)((App)Application.Current).Services .GetService <TurnInViewModel>() ! : (IRoutableViewModel)((App)Application.Current).Services .GetService <MissionStatsViewModel>() !); } ) .Do(vm => Router.Navigate.Execute(vm)) .Subscribe(_ => { }) .DisposeWith(disposables); }); Task.Run(() => { missionCatchUp.CatchUp(); api.StartAsync(); }); }
public TurnInViewModel(IScreen hostScreen, MissionTargetManager missionTargetManager, StateTracker state) { HostScreen = hostScreen; var comparer = SortExpressionComparer <Mission> .Descending(m => m.IsWing).ThenByDescending(m => m.MissionId); missionTargetManager .Connect() .Filter(x => x.IsFilled) .Sort(comparer) .Transform(m => new MissionItemViewModel(m, state)) .ObserveOn(RxApp.MainThreadScheduler) .Bind(out _missions) .Subscribe(); }
public MissionStatsViewModel(IScreen host, MissionTargetManager missionTargetManager) { HostScreen = host; var factionSort = SortExpressionComparer <FactionGroup> .Descending(f => f.KillsRemaining); var factionUpdates = missionTargetManager .Connect() .Select(m => m) .Group(m => m.Faction) // .Filter(g => g.Cache.Count > 0) .Transform(g => new FactionGroup(g)) .Sort(factionSort); factionUpdates .ObserveOn(RxApp.MainThreadScheduler) .Bind(out _factions) .DisposeMany() .Subscribe(); var factionChanges = factionUpdates .WhenAnyPropertyChanged() .Select(_ => Factions); factionChanges .Select(x => x.Select(f => f.KillsRemaining).Append(0).Max()) .ToPropertyEx(this, x => x.StackHeight); factionChanges .Select(x => x.Count(y => y.Mission1Reward != 0)) .ToPropertyEx(this, x => x.StackWidth); factionChanges .Select(x => x.Select(y => y.MissionCount).Sum()) .ToPropertyEx(this, x => x.MissionCount); factionChanges .Select(x => x.Select(y => y.MissionsDoneCount).Sum()) .ToPropertyEx(this, x => x.MissionsDone); factionChanges .Select(x => x.Select(y => y.KillsRemaining).Sum()) .ToPropertyEx(this, x => x.TotalKills); this.WhenAnyValue(x => x.TotalKills, x => x.StackHeight, (totalKills, stackHeight) => (totalKills, stackHeight)) .Where(x => x.stackHeight > 0) .Select(x => (double)x.totalKills / x.stackHeight) .ToPropertyEx(this, x => x.Ratio); factionChanges .Select(x => x.Select(y => y.RewardTotal).Sum()) .ToPropertyEx(this, x => x.TotalPayout); this.WhenAnyValue(x => x.MissionCount, x => x.TotalPayout, (missionCount, totalPayout) => (totalPayout, missionCount)) .Where(x => x.missionCount > 0) .Select(x => (double)x.totalPayout / x.missionCount) .ToPropertyEx(this, x => x.MissionAverageReward); factionChanges .Select(x => x.Where(y => y.Mission1TotalKills > 0) .Select(y => (double)y.Mission1Reward / y.Mission1TotalKills).Sum()) .ToPropertyEx(this, x => x.MillPerKill); }