예제 #1
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;
        }
예제 #2
0
        /// <summary>
        /// Deselect a character, hiding the radial menu of options and resetting the battlegrid to normal highlighting.
        /// </summary>
        public void DeselectCharacter()
        {
            if (_state != BattleState.CharacterSelected) return;

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

            ResetState();

            _state = BattleState.PlayerTurn;
        }