Ejemplo n.º 1
0
        /// <summary>
        /// Show a list of special abilities that a character may use
        /// </summary>
        /// <param name="character">The character being selected for special abilities</param>
        /// <returns>An event handler to execute to show the abilities.</returns>
        private void SelectSpecialAbility(Combatant character)
        {
            // delete the current radial menu options, which should be move/attack/special/item for the character.
            // should.
            _radialMenuControl.ClearOptions();

            // go through each ability the character can currently use
            foreach (var ability in character.GetAbilities().Where(character.CanUseAbility).Where(a => a.AbilityType == AbilityType.Active))
            {
                var tempAbility = ability;

                var button = new RadialButtonControl
                    {ImageFrame = ability.ImageName, Bounds = new UniRectangle(0, 0, 64, 64), Enabled = false};

                // only bind event handlers onto abilities that are cheap enough to use
                if (ability.ManaCost <= character.CurrentMana)
                {
                    button.Enabled = true;
                    button.MouseOver = () => PreviewAbility(tempAbility);
                    button.MouseOut = () =>
                        {
                            if (_aimAbility != null) return;

                            HideGui(_abilityStatLayer);
                            _battleBoardLayer.ResetGrid();
                        };
                    button.MouseClick = () => { };
                    button.MouseRelease += () => { SelectAbilityTarget(character, tempAbility);
                                                     _aimTime = DateTime.Now;
                    };
                }
                else
                {
                    button.MouseRelease =  () => { };
                }

                _radialMenuControl.AddOption(ability.Name, button);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Process a character that has been selected by the player, showing a radial menu of options.
        /// </summary>
        /// <param name="character">The character whose options are to be displayed.</param>
        public void SelectCharacter(Combatant character)
        {
            // if they clicked on the character already being shown, assume they want to close the menu
            if (character == _selectedCharacter)
            {
                DeselectCharacter();
                return;
            }

            // you can only click on your characters during your turn
            if (_state != BattleState.PlayerTurn) return;
            if (character.Faction != 0) return;

            if (_radialMenuControl != null)
            {
                Gui.Screen.Desktop.Children.Remove(_radialMenuControl);
                _radialMenuControl = null;
            }

            var menu = new RadialMenuControl(((IInputService)Game.Services.GetService(typeof(IInputService))).GetMouse())
                {
                    CenterX = (int)character.Avatar.Sprite.X + character.Avatar.Sprite.Width/2 - 10,
                    CenterY = (int)character.Avatar.Sprite.Y + character.Avatar.Sprite.Height/2,
                    OnExit = DeselectCharacter
                };

            // move icon, plus event handlers
            var icon = new RadialButtonControl {ImageFrame = "move", Bounds = new UniRectangle(0, 0, 64, 64)};
            if (character.CanMove)
            {
                icon.MouseOver += () =>
                    {
                        if (!character.CanMove) return;

                        _battleBoardLayer.SetTargettingGrid(
                            character.GetMovementGrid(BattleBoard.GetAccessibleGrid(character.Faction)),
                            new Grid(1, 1)
                            );
                    };
                icon.MouseOut += () => { if (_aimAbility == null) _battleBoardLayer.ResetGrid(); };
                icon.MouseClick += () => { SelectAbilityTarget(character, Ability.Factory(Game, "move"));
                                             _aimTime = DateTime.Now;
                };
            }
            else
            {

                // if they can't move, this icon does nothing
                icon.MouseOver = () => { };
                icon.MouseOut = () => { };
                icon.MouseClick = () => { };
                icon.MouseRelease = () => { };
                icon.Enabled = false;
            }

            menu.AddOption("move", icon);

            //// attack icon, plus handlers
            icon = new RadialButtonControl { ImageFrame = "attack", Bounds = new UniRectangle(0, 0, 64, 64) };
            if (character.CanAct)
            {
                var ability = Ability.Factory(Game, "attack");
                ability.Character = character;

                icon.MouseOver += () =>
                    {
                        if (!character.CanAct) return;

                        _battleBoardLayer.SetTargettingGrid(
                            ability.GenerateTargetGrid(BattleBoard.Sandbag.Clone()),
                            new Grid(1, 1)
                            );
                    };
                icon.MouseOut += () => { if (_aimAbility == null) _battleBoardLayer.ResetGrid(); };

                icon.MouseRelease += () => { SelectAbilityTarget(character, ability);
                                               _aimTime = DateTime.Now;
                };
            }
            else
            {
                // if they can't act, this icon does nothing
                icon.MouseOver = () => { };
                icon.MouseOut = () => { };
                icon.MouseClick = () => { };
                icon.MouseRelease = () => { };
                icon.Enabled = false;
            }

            menu.AddOption("attack", icon);

            //// special abilities icon, plus event handlers
            icon = new RadialButtonControl { ImageFrame = "special", Bounds = new UniRectangle(0, 0, 64, 64) };
            if (character.CanAct)
            {
                icon.MouseRelease += () => SelectSpecialAbility(character);
            }
            else
            {
                // if they can't act, this icon does nothing
                icon.MouseOver = () => { };
                icon.MouseOut = () => { };
                icon.MouseClick = () => { };
                icon.MouseRelease = () => { };
                icon.Enabled = false;
            }
            menu.AddOption("special", icon);

            icon = new RadialButtonControl
                {ImageFrame = "item", Bounds = new UniRectangle(0, 0, 64, 64), Enabled = false};
            menu.AddOption("item", icon);

            _radialMenuControl = menu;
            Gui.Screen.Desktop.Children.Add(_radialMenuControl);

            _selectedCharacter = character;
            _state = BattleState.CharacterSelected;
        }