예제 #1
0
        private void MainViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
            case nameof(IsPlayMode):
            case nameof(IsReviewMode):
                AppVM.DoOnUIThread(() =>
                {
                    RaisePropertyChanged(nameof(Title));

                    PlayTarget.RaiseCanExecuteChanged();
                    Pass.RaiseCanExecuteChanged();
                    UndoLastMove.RaiseCanExecuteChanged();

                    MoveToStart.RaiseCanExecuteChanged();
                    MoveBack.RaiseCanExecuteChanged();
                    MoveForward.RaiseCanExecuteChanged();
                    MoveToEnd.RaiseCanExecuteChanged();

                    SwitchToPlayMode.RaiseCanExecuteChanged();
                    ShowGameMetadata.RaiseCanExecuteChanged();
                    SwitchToReviewMode.RaiseCanExecuteChanged();

                    UpdateBoardHistory();
                });
                break;

            case nameof(ViewerConfig):
                AppVM.DoOnUIThread(() =>
                {
                    RaisePropertyChanged(nameof(ShowBoardHistory));
                    RaisePropertyChanged(nameof(ShowMoveCommentary));
                });
                break;
            }
        }
예제 #2
0
        public MainViewModel()
        {
            AppVM.EngineWrapper.BoardUpdated += (sender, args) =>
            {
                AppVM.DoOnUIThread(() =>
                {
                    RaisePropertyChanged(nameof(Board));
                    SaveGame.RaiseCanExecuteChanged();

                    PlayTarget.RaiseCanExecuteChanged();
                    Pass.RaiseCanExecuteChanged();
                    UndoLastMove.RaiseCanExecuteChanged();

                    MoveToStart.RaiseCanExecuteChanged();
                    MoveBack.RaiseCanExecuteChanged();
                    MoveForward.RaiseCanExecuteChanged();
                    MoveToEnd.RaiseCanExecuteChanged();

                    FindBestMove.RaiseCanExecuteChanged();
                    RaisePropertyChanged(nameof(GameState));

                    if (AppVM.EngineWrapper.GameIsOver && AppVM.EngineWrapper.CurrentGameSettings.GameMode == GameMode.Play)
                    {
                        if (ViewerConfig.PlaySoundEffects)
                        {
                            SoundUtils.PlaySound(GameSound.GameOver);
                        }

                        switch (Board.BoardState)
                        {
                        case BoardState.WhiteWins:
                            Messenger.Default.Send(new InformationMessage("White has won the game.", "Game Over"));
                            break;

                        case BoardState.BlackWins:
                            Messenger.Default.Send(new InformationMessage("Black has won the game.", "Game Over"));
                            break;

                        case BoardState.Draw:
                            Messenger.Default.Send(new InformationMessage("The game is a draw.", "Game Over"));
                            break;
                        }
                    }

                    UpdateBoardHistory();
                });
            };

            AppVM.EngineWrapper.ValidMovesUpdated += (sender, args) =>
            {
                AppVM.DoOnUIThread(() =>
                {
                    RaisePropertyChanged(nameof(ValidMoves));
                });
            };

            AppVM.EngineWrapper.TargetPieceUpdated += (sender, args) =>
            {
                AppVM.DoOnUIThread(() =>
                {
                    RaisePropertyChanged(nameof(TargetMove));
                    PlayTarget.RaiseCanExecuteChanged();
                });
            };

            AppVM.EngineWrapper.TargetPositionUpdated += (sender, args) =>
            {
                AppVM.DoOnUIThread(() =>
                {
                    RaisePropertyChanged(nameof(TargetMove));
                    PlayTarget.RaiseCanExecuteChanged();

                    if (!ViewerConfig.RequireMoveConfirmation)
                    {
                        if (PlayTarget.CanExecute(null) && null != AppVM.EngineWrapper.TargetMove)
                        {
                            // Only fast-play if a move is selected
                            PlayTarget.Execute(null);
                        }
                        else if (Pass.CanExecute(null) && AppVM.EngineWrapper.CanPass)
                        {
                            // Only fast-pass if pass is available
                            Pass.Execute(null);
                        }
                    }
                });
            };

            AppVM.EngineWrapper.IsIdleUpdated += (sender, args) =>
            {
                AppVM.DoOnUIThread(() =>
                {
                    IsIdle = AppVM.EngineWrapper.IsIdle;
                });
            };

            AppVM.EngineWrapper.TimedCommandProgressUpdated += (sender, args) =>
            {
                AppVM.DoOnUIThread(() =>
                {
                    IsRunningTimedCommand = args.IsRunning;
                    TimedCommandProgress  = args.Progress;
                });
            };

            AppVM.EngineWrapper.MovePlaying += (sender, args) =>
            {
                if (ViewerConfig.PlaySoundEffects)
                {
                    SoundUtils.PlaySound(GameSound.Move);
                }
            };

            AppVM.EngineWrapper.MoveUndoing += (sender, args) =>
            {
                if (ViewerConfig.PlaySoundEffects)
                {
                    SoundUtils.PlaySound(GameSound.Undo);
                }
            };

            AppVM.EngineWrapper.GameModeChanged += (sender, args) =>
            {
                RaisePropertyChanged(nameof(IsPlayMode));
                RaisePropertyChanged(nameof(IsReviewMode));
            };

            PropertyChanged += MainViewModel_PropertyChanged;
        }