Esempio n. 1
0
        public HomeViewModel(
            GamePickerViewModel gamePickerViewModel,
            ActiveGameCategory activeGameCategory,
            GameCategoryService gameCategoryService,
            LaunchRandomGameService launchRandomGameService,
            FanGameEditingService fanGameEditingService
            )
        {
            _gamePickerViewModel     = gamePickerViewModel;
            _activeGameCategory      = activeGameCategory;
            _gameCategoryService     = gameCategoryService;
            _launchRandomGameService = launchRandomGameService;
            _fanGameEditingService   = fanGameEditingService;

            MessengerInstance.Register <object?>(this, RebuildHeadersMessageToken, RebuildHeaders);

            HeaderList = new ObservableCollection <HeaderButton>();

            List <GameCategories> gameCategoryList = _gameCategoryService.CreateGameCategoryList();

            foreach (var category in gameCategoryList)
            {
                HeaderList.Add(new CategoryHeaderButton(category, this));
            }

            HeaderList.Add(CreateRandomGameHeader());

            OpenSettingsCommand = new RelayCommand(
                () => MessengerInstance.Send("SettingsPage.xaml", MainViewModel.ChangePageMessageToken)
                );

            CreateNewFanGameCommand = new RelayCommand(() => {
                _fanGameEditingService.SetFanGameToEdit(null);

                MessengerInstance.Send("FanGameEditorPage.xaml", MainViewModel.ChangePageMessageToken);
            });

            NewFanGameVisibility = Visibility.Hidden;
        }
Esempio n. 2
0
            public GameButton(
                Game game,
                GamePickerViewModel parent,
                LaunchGameService launchGameService,
                GameConfigService gameConfigService,
                FanGameEditingService fanGameEditingService
                )
            {
                _game                  = game;
                _parent                = parent;
                _launchGameService     = launchGameService;
                _gameConfigService     = gameConfigService;
                _fanGameEditingService = fanGameEditingService;

                Command = new RelayCommand(async() => {
                    if (!string.IsNullOrEmpty(_game.FileLocation))
                    {
                        var error = await _launchGameService.LaunchGame(_game);

                        if (error != null)
                        {
                            MessageBox.Show(error.Message, "Error");
                        }
                    }
                    else
                    {
                        _gameConfigService.SetGameToConfigure(_game);
                        new GameConfigWindow().ShowDialog();
                    }
                });

                EditCommand = new RelayCommand(() => {
                    _fanGameEditingService.SetFanGameToEdit((FanGame)_game);

                    _parent.MessengerInstance.Send("FanGameEditorPage.xaml", MainViewModel.ChangePageMessageToken);
                });
            }