Exemple #1
0
        /// <summary>
        /// Keeping up to date with the mouse clicks.
        /// </summary>
        /// <param name="currentMouseState">State of the current mouse.</param>
        public static void UpdateMouseClicks(MouseState currentMouseState)
        {
            if (currentMouseState.LeftButton == ButtonState.Pressed && _previousMouseState.LeftButton == ButtonState.Released)
            {
                // Only display info when not selecting/building stuff
                if (!IsMouseOverMenu() && GameState.State == GameStateType.PLAYING)
                {
                    SelectionInfo selection = SelectedTileInfo(GetWorldMousePosition());

                    if (selection != null)
                    {
                        PlayingStateInterface.SelectedTileInfo(selection);
                    }
                    else
                    {
                        _playerSelection = null;
                    }
                }
            }

            if (currentMouseState.RightButton == ButtonState.Pressed && _previousMouseState.RightButton == ButtonState.Released)
            {
                if (!IsMouseOverMenu() && GameState.State == GameStateType.PLAYING)
                {
                    if (_playerSelection != null)
                    {
                        if (_playerSelection.Entities.Count != 0)
                        {
                            // Create an array where all items should fit in
                            Minion[] minions = new Minion[_playerSelection.Entities.Count];
                            int      count   = 0;

                            foreach (ISelectableInterface item in _playerSelection.Entities)
                            {
                                // Check if the item is a minion
                                if (item.GetType() == typeof(Minion))
                                {
                                    minions[count] = (Minion)item;
                                    count++;
                                }
                            }

                            // Check if minions were added to the array
                            if (count > 0)
                            {
                                Vector2 position = GetWorldMousePosition();
                                Tile    tile     = ChunkManager.TileAtWorldPosition((int)position.X, (int)position.Y);

                                if (tile != null)
                                {
                                    // Move the last (visible) minion to the clicked tile
                                    NPCManager.MoveTo(minions.ElementAt(count - 1), tile); // TODO: Check if fully visible minion is the last one in the list
                                }
                            }
                        }
                    }
                }
            }
        }