Пример #1
0
        void updateButtons()
        {
            var mouse = InputManager.MousePosition;

            var cursor = Cursors.Default;

            foreach (var button in buttons)
            {
                if (!button.Disabled && button.Bounds.Contains(mouse))
                {
                    if (InputManager.IsMouseButtonClicked(MouseButton.Left))
                    {
                        if (button.OnClick != null)
                        {
                            button.OnClick(null, EventArgs.Empty);
                        }

                        button.SetHovering(false);
                    }
                    else
                    {
                        button.SetHovering(true);

                        cursor = Cursors.Pointer;
                    }
                }
                else
                {
                    button.SetHovering(false);
                }
            }

            MarsRTS.SetCursor(cursor);
        }
Пример #2
0
        /// <summary>
        /// Transition out and remove the screen from the manager
        /// </summary>
        public void ExitScreen()
        {
            IsExiting = true;

            // no transition, remove it right away
            if (TransitionOutDuration == TimeSpan.Zero)
            {
                ScreenManager.RemoveScreen(this);
            }

            MarsRTS.SetCursor(Cursors.Default);
        }
Пример #3
0
        public void Update(GameTime gameTime)
        {
            if (state == MenuState.Hidden)
            {
                return;
            }

            updateTransition(gameTime);

            var mouse = InputManager.MousePosition;

            if (!getMenuBounds(world.Camera.RawPosition).Contains(mouse))
            {
                Close();

                return;
            }

            bool mouseDown =
                InputManager.IsMouseButtonPressed(MouseButton.Left);

            var cursor = Cursors.Default;

            foreach (var item in menuItems)
            {
                var offset = (menuBounds.Location.ToVector() +
                              world.Camera.RawPosition).ToPoint();

                var bounds = item.GetBounds(offset);

                if (bounds.Contains(mouse))
                {
                    if (mouseDown)
                    {
                        item.SetState(ButtonState.Active);
                    }
                    else
                    {
                        item.SetState(ButtonState.Hover);
                    }

                    cursor = Cursors.Pointer;
                }
                else
                {
                    item.SetState(ButtonState.None);
                }
            }

            MarsRTS.SetCursor(cursor);
        }
Пример #4
0
        public void Close(bool immediate = false)
        {
            if (immediate)
            {
                state            = MenuState.Hidden;
                transitionOffset = 0;
            }
            else if (state != MenuState.Hidden)
            {
                state = MenuState.TransitionOut;
            }

            MarsRTS.SetCursor(Cursors.Default);
        }
        void updateBuildingIcons()
        {
            var mouse  = InputManager.MousePosition;
            var cursor = MarsRTS.Cursor;

            for (int i = 0; i < currentIcons.Count; i++)
            {
                var icon = currentIcons[i];

                var position = menuPosition + iconPositions[i];

                var bounds = new Rectangle()
                {
                    X      = (int)position.X,
                    Y      = (int)position.Y,
                    Width  = BuildingIcon.Size.X,
                    Height = BuildingIcon.Size.Y,
                };

                if (bounds.Contains(mouse))
                {
                    if (InputManager.IsMouseButtonClicked(MouseButton.Left))
                    {
                        if (icon.OnClick != null)
                        {
                            currentIcons[i].OnClick(null, null);
                        }

                        return;
                    }

                    icon.SetHovering(true);
                    cursor = Cursors.Pointer;
                }
                else
                {
                    icon.SetHovering(false);
                }
            }

            MarsRTS.SetCursor(cursor);
        }
Пример #6
0
        public void OnClick(Vector2 location)
        {
            var point = location.ToPoint();

            foreach (var item in menuItems)
            {
                if (item.GetBounds(menuBounds.Location).Contains(point))
                {
                    item.SetState(ButtonState.Active);

                    MarsRTS.SetCursor(Cursors.Default);

                    if (item.OnClick != null)
                    {
                        item.OnClick(item.Tag, EventArgs.Empty);
                    }

                    Close(true);

                    return;
                }
            }
        }
Пример #7
0
        public override void HandleInput()
        {
            if (InputManager.IsKeyTriggered(Keys.Escape))
            {
                // reset the dragged building if it exists
                if (draggedBuilding != null)
                {
                    resetDraggedBuilding();
                }

                ExitScreen();
            }

            // current mouse position
            var mouse = InputManager.MousePosition;

            // mouse position at last update
            var lastMouse = InputManager.LastMousePosition;

            // determines if the mouse is inside the grid bounds
            shouldDrawNodeLocation = gridViewport.Bounds.Contains(mouse);

            // mouse position converted to a grid node index
            mouseNodeLocation = getGridMouseNodeIndex(mouse);

            // determine if the mouse node has changed since the last update
            if (mouseNodeLocation != getGridMouseNodeIndex(lastMouse))
            {
                // invoke the mouse node changed callback if the mouse is
                // actually inside the grid bounds
                if (shouldDrawNodeLocation)
                {
                    onMouseNodeChanged(mouseNodeLocation);
                }
            }

            var exitButton = new Rectangle()
            {
                X      = (int)(boxOffset.X + boxSize.X) - exitButtonSize.X,
                Y      = (int)boxOffset.Y,
                Width  = exitButtonSize.X,
                Height = exitButtonSize.Y
            };

            bool mouseInExit = exitButton.Contains(mouse);

            if (mouseInExit)
            {
                MarsRTS.SetCursor(Cursors.Pointer);
            }
            else
            {
                MarsRTS.SetCursor(Cursors.Default);
            }

            if (InputManager.IsMouseButtonPressed(MouseButton.Left))
            {
                // initially pressed, set last mouse down to the mouse's
                // current position
                if (InputManager.IsMouseButtonTriggered(MouseButton.Left))
                {
                    lastMouseDown = mouse;

                    wasMouseInGridLastPressed = shouldDrawNodeLocation;
                }

                // drag only if the last pressed mouse location was inside
                // the grid viewport
                if (wasMouseInGridLastPressed)
                {
                    dragGrid(mouse, lastMouse);
                }
            }
            else if (InputManager.IsMouseButtonClicked(MouseButton.Left))
            {
                if (mouseInExit)
                {
                    if (draggedBuilding != null)
                    {
                        resetDraggedBuilding();
                    }

                    ExitScreen();
                }

                if (shouldDrawNodeLocation)
                {
                    // distance between the mouse's current position and
                    // when it was last pressed
                    var distance = Vector2.Distance(
                        mouse.ToVector(),
                        lastMouseDown.ToVector());

                    // can we detect a click?
                    if (distance <= nodeClickDistanceThreshold)
                    {
                        // we aren't dragging a building, try and detect
                        // a building where we clicked.
                        if (draggedBuilding == null)
                        {
                            var point = getGridMousePosition(mouse);

                            point.X += (int)gridCamera.X;
                            point.Y += (int)gridCamera.Y;

                            // find a building at the mouse position
                            var building = getBuildingFromPoint(point);

                            // start dragging this building if it's found
                            if (building != null)
                            {
                                setDraggedBuilding(building);
                            }
                        }
                        else
                        {
                            // we're already dragging a building - place it
                            placeDraggedBuilding();
                        }
                    }
                }
            }
        }