// TODO: We probably want to create a new viewmodel for each game, also pass in the game? // Or should we merge these viewmodels into this one as the more important part is the libraries that are within those viewmodels? public GameViewModel(Game game, ServersViewModel serversViewModel, ModsViewModel modsViewModel, MissionsViewModel missionsViewModel, Lazy <ContentViewModel> cvmLazy) { _game = game; _cvmLazy = cvmLazy; if (game.SupportsServers()) { Servers = serversViewModel; } serversViewModel.SwitchGame(game); if (game.SupportsMods()) { Mods = modsViewModel; } modsViewModel.SwitchGame(game); if (game.SupportsMissions()) { Missions = missionsViewModel; } missionsViewModel.SwitchGame(game); this.SetCommand(x => ActivateServerList).Subscribe(() => ShowServerList()); this.SetCommand(x => ActivateMissionList).Subscribe(() => ShowMissionList()); }
public ContentViewModel(IPlayShellViewModel shellVM, GamesViewModel games, ServersViewModel servers, MissionsViewModel missions, ModsViewModel mods, HomeViewModel home, IUpdateManager updateManager, Func <RepoAppsContextMenu> contextMenu, IViewModelFactory factory, IDialogManager dialogManager) { _dialogManager = dialogManager; HostScreen = shellVM; Games = games; Servers = servers; Missions = missions; Mods = mods; Home = home; UpdateManager = updateManager; Factory = factory; RepoAppsContextMenu = contextMenu(); Activator = new ViewModelActivator(); _overlay = this.WhenAnyValue(x => x.ActiveItem.Overlay.ActiveItem) .ToProperty(this, x => x.Overlay, null, Scheduler.Immediate); var once = false; this.WhenActivated(d => { d(this.WhenAnyValue(x => x.ActiveItem.DisplayName) .BindTo(this, x => x.DisplayName)); d(Games.DoubleClickedCommand.Subscribe(GameBrowserDoubleClicked)); d(UpdateManager.StateChange.ObserveOn(RxApp.MainThreadScheduler).Subscribe(data => { var customModSet = data.Item1 as CustomCollection; RepoAppsContextMenu.Refresh(customModSet); if (((IIsEmpty)RepoAppsContextMenu).IsEmpty()) { IsServerAppsEnabled = 0; } else { IsServerAppsEnabled = null; } })); d(DomainEvilGlobal.SelectedGame.WhenAnyValue(x => x.ActiveGame) .Subscribe(GameChanged)); /* this.WhenAnyValue(x => x.ActiveGame.Mods.LibraryVM.ActiveItem) * .Where(x => x != null) * .Subscribe(ActiveItemChanged);*/ d(ReactiveCommand.Create().SetNewCommand(this, x => x.SwitchMenuOpen) .Select(_ => !IsMenuOpen) .BindTo(this, x => x.IsMenuOpen)); var observable = shellVM.WhenAnyValue(x => x.GridMode) .Where(x => x.HasValue) .Select(x => x.Value ? ViewType.Grid : ViewType.List); d(observable.BindTo(Missions, x => x.LibraryVM.ViewType)); d(observable.BindTo(Mods, x => x.LibraryVM.ViewType)); d(observable.BindTo(Servers, x => x.LibraryVM.ViewType)); if (once) { return; } InitializeModules(); once = true; }); }