Exemplo n.º 1
0
        private void MouseControlCheck(InputHelper inputHelper, KeyManager keyManager)
        {
            if (inputHelper.GetMousePosition(false).Y < CameraMouseMargin && inputHelper.GetMousePosition(false).Y >= 0 && inputHelper.GetMousePosition(false).X < cameraBreakoffX)
            {
                MoveCamera("up");
            }

            if (inputHelper.GetMousePosition(false).Y > CameraBreakoffY - CameraMouseMargin && inputHelper.GetMousePosition(false).Y <= CameraBreakoffY && inputHelper.GetMousePosition(false).X < cameraBreakoffX)
            {
                MoveCamera("down");
            }

            if (inputHelper.GetMousePosition(false).X < CameraMouseMargin && inputHelper.GetMousePosition(false).X >= 0)
            {
                MoveCamera("left");
            }

            if (inputHelper.GetMousePosition(false).X > CameraBreakoffX - CameraMouseMargin && inputHelper.GetMousePosition(false).X <= CameraBreakoffX)
            {
                MoveCamera("right");
            }

            if (inputHelper.MouseScrollUp)
            {
                MoveCamera("in");
            }

            if (inputHelper.MouseScrollDown)
            {
                MoveCamera("out");
            }
        }
Exemplo n.º 2
0
        public override void HandleInput(InputHelper helper, KeyManager keyManager)
        {
            // Check if the overlays should be rendered.
            if (keyManager.KeyPressed("unitTargetOverlay", helper))
            {
                CreateUnitTargetOverlays();
            }

            // Check if the player clicked
            if (helper.MouseLeftButtonPressed)
            {
                OnLeftClick(helper);
            }

            if (SelectedTile != null)
            {
                if (SelectedTile.Occupied)
                {
                    //foreach (Point p in walkablePositions)
                    ForEach(obj => {
                        //{
                        Point p = (obj as Tile).PositionInGrid;
                        if ((int)(helper.GetMousePosition(true).X + MaxOfEmpires.camera.Position.X) / 32 == p.X && (int)(helper.GetMousePosition(true).Y + MaxOfEmpires.camera.Position.Y) / 32 == p.Y && p != selectedTile && (this[p] as Tile).Passable(SelectedTile.Unit))
                        {
                            if (mousePoint != p)
                            {
                                mousePoint = p;
                                Point[] pathWithoutOriginalTile = Pathfinding.GetPath(SelectedTile.Unit, p);

                                if (pathWithoutOriginalTile == null)
                                {
                                    return;
                                }

                                path    = new Point[pathWithoutOriginalTile.Length + 1];
                                path[0] = selectedTile;
                                pathWithoutOriginalTile.CopyTo(path, 1);
                            }
                            DisplayPath(path);
                            return;
                        }
                        //}
                    });
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Finds a Tile under the mouse within this Grid.
        /// </summary>
        /// <param name="helper">The InputHelper. Used for mouse position.</param>
        /// <param name="onClick">Whether this is called on click. Used to see if a Tile should be deselected.</param>
        /// <returns>The Tile under the mouse, or null if there is no such Tile.</returns>
        public Tile GetTileUnderMouse(InputHelper helper, bool onClick = false)
        {
            // Get the current grid position the player clicked at
            Vector2 mousePosRelativeToGrid = helper.GetMousePosition(true) - DrawPosition;
            Point   gridPos = (mousePosRelativeToGrid / 32).ToPoint();

            // Just unselect this tile if the user clicks this again.
            if (gridPos.Equals(selectedTile) && onClick)
            {
                SelectTile(InvalidTile);
                return(null);
            }

            // If the tile doesn't exist, return null as well. This is checked implicitly.
            // Get the tile that is hovered over
            Tile clickedTile = this[gridPos] as Tile;

            return(clickedTile);
        }