Пример #1
0
        public LiveGameViewModel(IGameSettings gameSettings, IQuestsManager questsManager, IDialogService dialogService)
            : base(gameSettings, questsManager, dialogService)
        {
            BlackPortrait = new PlayerPortraitViewModel(Game.Controller.Players.Black, Game);
            WhitePortrait = new PlayerPortraitViewModel(Game.Controller.Players.White, Game);

            // Register tool services
            ToolServices =
                new GameToolServices(
                    Localizer,
                    dialogService,
                    Game.Controller.Ruleset,
                    Game.Controller.GameTree);
            ToolServices.PassSoundShouldBePlayed      += ToolServices_PassSoundShouldBePlayed;
            ToolServices.StoneCapturesShouldBePlayed  += ToolServices_StoneCapturesShouldBePlayed;
            ToolServices.StonePlacementShouldBePlayed += ToolServices_StonePlacementShouldBePlayed;
            ToolServices.NodeChanged += (s, node) =>
            {
                AnalyzeToolsViewModel.OnNodeChanged();
                RefreshBoard(node);
                GameTreeViewModel.SelectedGameTreeNode = node;
                GameTreeViewModel.RaiseGameTreeChanged();
            };
            Tool = null;

            // Initialize analyze mode and register tools
            BoardViewModel.ToolServices = ToolServices;

            AnalyzeToolsViewModel = new AnalyzeToolsViewModel(ToolServices);
            AnalyzeToolsViewModel.CanGoBackToLiveGame = true;
            RegisterAnalyzeTools();
            _isAnalyzeModeEnabled = false;

            // System log visibility
            _isSystemLogEnabled = false;

            // Set up Timeline
            GameTreeViewModel = new GameTreeViewModel(Game.Controller.GameTree);
            GameTreeViewModel.GameTreeSelectionChanged += (s, e) =>
            {
                ToolServices.Node = e;
                BoardViewModel.BoardControlState.ShowTerritory =
                    e.Equals(Game.Controller.GameTree.LastNode) &&
                    (GamePhase == GamePhaseType.LifeDeathDetermination || GamePhase == GamePhaseType.Finished);
                RefreshBoard(e);
                AnalyzeToolsViewModel.OnNodeChanged();
            };

            _portraitUpdateTimer = Mvx.Resolve <ITimerService>()
                                   .StartTimer(TimeSpan.FromMilliseconds(100), UpdatePortraits);

            Game.Controller.MoveUndone += (s, e) => { UpdateTimeline(); };

            // When timeline selected node changes, check whether its not in the past. If it is then disable shadow stones.
            TimelineChanged += (s, e) => BoardViewModel.BoardControlState.IsShadowDrawingEnabled = !IsTimelineInPast;
        }
Пример #2
0
        public AnalyzeOnlyViewModel(IGameSettings gameSettings, IQuestsManager questsManager, IDialogService dialogService)
        {
            _dialogService = dialogService;
            var analyzeBundle = Mvx.Resolve <NavigationBundle>();

            LibraryItem   = analyzeBundle.LibraryItem;
            GameTree      = analyzeBundle.GameTree;
            GameInfo      = analyzeBundle.GameInfo;
            BlackPortrait = new PlayerPortraitViewModel(analyzeBundle.GameInfo.Black);
            WhitePortrait = new PlayerPortraitViewModel(analyzeBundle.GameInfo.White);

            _ruleset = new ChineseRuleset(analyzeBundle.GameInfo.BoardSize);

            // Register tool services
            ToolServices              = new GameToolServices(Localizer, dialogService, _ruleset, analyzeBundle.GameTree);
            ToolServices.NodeChanged += (s, node) =>
            {
                AnalyzeToolsViewModel.OnNodeChanged();
                RefreshBoard(node);
                GameTreeViewModel.SelectedGameTreeNode = node;
                GameTreeViewModel.RaiseGameTreeChanged();
            };
            ToolServices.PassSoundShouldBePlayed      += ToolServices_PassSoundShouldBePlayed;
            ToolServices.StoneCapturesShouldBePlayed  += ToolServices_StoneCapturesShouldBePlayed;
            ToolServices.StonePlacementShouldBePlayed += ToolServices_StonePlacementShouldBePlayed;
            Tool = null;

            BoardViewModel                        = new BoardViewModel(analyzeBundle.GameInfo.BoardSize);
            BoardViewModel.BoardTapped           += (s, e) => OnBoardTapped(e);
            BoardViewModel.GameTreeNode           = GameTree.GameTreeRoot;
            BoardViewModel.IsMarkupDrawingEnabled = true;
            BoardViewModel.IsShadowDrawingEnabled = true;


            // Initialize analyze mode and register tools
            BoardViewModel.ToolServices = ToolServices;

            ToolServices.Node = GameTree.GameTreeRoot;

            AnalyzeToolsViewModel = new AnalyzeToolsViewModel(ToolServices);
            AnalyzeToolsViewModel.CanGoBackToLiveGame = false;
            RegisterAnalyzeTools();
            Tool = AnalyzeToolsViewModel.StonePlacementTool;
            AnalyzeToolsViewModel.SelectedTool = Tool;

            // Set up Timeline
            GameTreeViewModel = new GameTreeViewModel(GameTree);
            GameTreeViewModel.GameTreeSelectionChanged += (s, e) =>
            {
                ToolServices.Node = e;
                RefreshBoard(e);
                AnalyzeToolsViewModel.OnNodeChanged();
            };
            GameTreeViewModel.SelectedGameTreeNode = GameTree.GameTreeRoot;
        }