Inheritance: ViewModelBase, ICommand
Ejemplo n.º 1
0
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            SkillCommand command = item as SkillCommand;

            if (command == null)
            {
                return(null);
            }
            DataTemplate template = null;

            if (command is GuHuoSkillCommand)
            {
                template = dict["GuHuoButtonTemplate"] as DataTemplate;
            }
            else if (command.HeroName != null)
            {
                template = dict["RulerGivenSkillButtonTemplate"] as DataTemplate;
            }
            else
            {
                template = dict["SkillButtonTemplate"] as DataTemplate;
            }
            return(template);
        }
Ejemplo n.º 2
0
        private void _UpdateSkills()
        {
            // SkillCommands.Clear();
            ActiveSkillCommands.Clear();
            AutoInvokeSkillCommands.Clear();

            var backup = new List<SkillCommand>(DockedSkillCommands);
            backup.AddRange(RulerGivenSkillCommands);

            foreach (ISkill skill in _player.Skills)
            {
                if (!backup.Any(s => s.Skill == skill))
                {
                    SkillCommand command;

                    if (skill is IAdditionalTypedSkill)
                    {
                        command = new GuHuoSkillCommand() { Skill = skill, IsEnabled = false };
                    }
                    else
                    {
                        command = new SkillCommand() { Skill = skill, IsEnabled = false };
                    }

                    if (command.IsAutoInvokeSkill)
                    {
                        command.IsEnabled = true;
                        command.OnSelectedChanged += triggerSkill_OnSelectedChanged;
                    }

                    if (command.HeroName != null)
                    {
                        RulerGivenSkillCommands.Add(command);
                    }
                    else
                    {
                        DockedSkillCommands.Add(command);
                    }

                }
            }

            foreach (var skillCommand in backup)
            {
                if (!_player.Skills.Any(s => skillCommand.Skill == s))
                {
                    AutoInvokeSkillCommands.Remove(skillCommand);
                    DockedSkillCommands.Remove(skillCommand);
                    RulerGivenSkillCommands.Remove(skillCommand);
                }
            }

            foreach (var command in SkillCommands)
            {
                if (command.IsAutoInvokeSkill)
                {
                    AutoInvokeSkillCommands.Add(command);
                }
                else if ((command.Skill is ActiveSkill || command.Skill is CardTransformSkill))
                {
                    ActiveSkillCommands.Add(command);
                }
            }
        }
Ejemplo n.º 3
0
        private void _OnSkillCommandSelected(object sender, EventArgs args)
        {
            var skill = sender as SkillCommand;
            if (skill.IsSelected)
            {
                if (skill == _lastSelectedCommand)
                {
                    Trace.Assert(skill is GuHuoSkillCommand);
                }
                else if (_lastSelectedCommand != null)
                {
                    _cleaningUp = true;
                    _lastSelectedCommand.IsSelected = false;
                    _cleaningUp = false;
                    Trace.Assert(_lastSelectedCommand == null);
                }

                _lastSelectedCommand = skill;

            }
            else
            {
                if (skill != _lastSelectedCommand)
                {
                    Trace.Assert(skill is GuHuoSkillCommand);
                }
                else
                {
                    foreach (EquipCommand equipCmd in EquipCommands)
                    {
                        equipCmd.IsSelected = false;
                    }

                    foreach (CardViewModel card in HandCards)
                    {
                        card.IsSelected = false;
                    }

                    foreach (var playerModel in _game.PlayerModels)
                    {
                        playerModel.IsSelected = false;
                    }

                    _lastSelectedPlayers.Clear();
                    _lastSelectedCommand = null;
                }
            }

            if (!_cleaningUp && currentUsageVerifier != null)
            {
                _UpdateCardUsageStatus();
            }
        }
Ejemplo n.º 4
0
        private void _ResetSkillsAndCards()
        {
            foreach (var equipCommand in EquipCommands)
            {
                equipCommand.OnSelectedChanged -= _OnCardUsageSelectionChanged;
                equipCommand.IsSelectionMode = false;
            }

            foreach (var skillCommand in ActiveSkillCommands)
            {
                skillCommand.OnSelectedChanged -= _OnSkillCommandSelected;
                skillCommand.IsSelected = false;
                skillCommand.IsEnabled = false;
            }

            foreach (CardViewModel card in HandCards)
            {
                card.OnSelectedChanged -= _OnCardSelected;
                card.IsSelectionMode = false;
            }

            foreach (var playerModel in _game.PlayerModels)
            {
                playerModel.OnSelectedChanged -= _OnCardUsageSelectionChanged;
                playerModel.IsSelectionMode = false;
            }
            _lastSelectedPlayers.Clear();
            CurrentSpecialDeck = null;
            _lastSelectedCard = null;
            _lastSelectedCommand = null;
            SubmitAnswerCommand = DisabledCommand;
            CancelAnswerCommand = DisabledCommand;
            AbortAnswerCommand = DisabledCommand;
        }
Ejemplo n.º 5
0
        private void _OnSkillCommandSelected(object sender, EventArgs args)
        {
            var skill = sender as SkillCommand;
            bool doCleanUp = (skill.IsSelected && skill != _lastSelectedCommand) ||
                             (!skill.IsSelected && skill == _lastSelectedCommand);

            if (skill.IsSelected)
            {
                if (skill == _lastSelectedCommand)
                {
                    // Trace.Assert(skill is GuHuoSkillCommand);
                }
                else if (_lastSelectedCommand != null)
                {
                    _lastSelectedCommand.OnSelectedChanged -= _OnSkillCommandSelected;
                    _lastSelectedCommand.IsSelected = false;
                    _lastSelectedCommand.OnSelectedChanged += _OnSkillCommandSelected;
                    // Trace.Assert(_lastSelectedCommand == null);
                }
                _lastSelectedCommand = skill;
                CancelAnswerCommand = cancelSkillSelectionCommand;
            }
            else
            {
                _lastSelectedCommand = null;
                CancelAnswerCommand = cancelCardUsageCommand;
            }

            if (doCleanUp)
            {
                foreach (EquipCommand equipCmd in EquipCommands)
                {
                    equipCmd.IsSelected = false;
                }

                foreach (CardViewModel card in HandCards)
                {
                    card.IsSelected = false;
                }

                foreach (var playerModel in _game.PlayerModels)
                {
                    playerModel.IsSelected = false;
                }

                _lastSelectedPlayers.Clear();

            }

            if (currentUsageVerifier != null)
            {
                _UpdateCardUsageStatus();
            }
        }