Esempio n. 1
0
        private void HandleMouseInput()
        {
            if (GamePadInput.ActiveMode != GamePadInput.InputMode.KeyboardMouse)
            {
                return;
            }

            // If in focus element has help available, get it.
            UIGridElement e           = grid.SelectionElement;
            string        helpID      = e.HelpID;
            string        helpText    = TweakScreenHelp.GetHelp(helpID);
            bool          hitAnything = false;

            // Check for help tile.
            Matrix  mat   = Matrix.CreateTranslation(-helpSquare.Position.X, -helpSquare.Position.Y, 0);
            Vector2 hitUV = MouseInput.GetHitUV(camera, ref mat, helpSquare.Size, helpSquare.Size, true);

            if (grid.SelectionElement.ShowHelpButton)
            {
                if (hitUV.X >= 0 && hitUV.X < 1 && hitUV.Y >= 0 && hitUV.Y < 1)
                {
                    if (MouseInput.Left.WasPressed)
                    {
                        MouseInput.ClickedOnObject = helpSquare;
                    }
                    if (MouseInput.Left.WasReleased && MouseInput.ClickedOnObject == helpSquare)
                    {
                        if (helpText != null)
                        {
                            ShowHelp(helpText);
                        }
                    }

                    hitAnything = true;
                }
            }

            // Check if mouse hitting current selection object.  Or should this be done in the object?
            mat   = Matrix.Invert(e.WorldMatrix);
            hitUV = MouseInput.GetHitUV(camera, ref mat, e.Size.X, e.Size.Y, true);

            bool focusElementHit = false;

            if (hitUV.X >= 0 && hitUV.X < 1 && hitUV.Y >= 0 && hitUV.Y < 1)
            {
                e.HandleMouseInput(hitUV);
                focusElementHit = true;

                hitAnything = true;
            }

            // If we didn't hit the focus object, see if we hit any of the others.
            // If so, bring them into focus.
            if (!focusElementHit && MouseInput.Left.WasPressed)
            {
                for (int i = 0; i < grid.ActualDimensions.Y; i++)
                {
                    if (i == grid.SelectionIndex.Y)
                    {
                        continue;
                    }

                    e     = grid.Get(0, i);
                    mat   = Matrix.Invert(e.WorldMatrix);
                    hitUV = MouseInput.GetHitUV(camera, ref mat, e.Size.X, e.Size.Y, true);

                    if (hitUV.X >= 0 && hitUV.X < 1 && hitUV.Y >= 0 && hitUV.Y < 1)
                    {
                        // We hit an element, so bring it into focus.
                        grid.SelectionIndex = new Point(0, i);

                        hitAnything = true;
                        break;
                    }
                }
            }

            // Check for edges of screen.
            if (MouseInput.AtWindowTop())
            {
                grid.MoveUp();
            }
            if (MouseInput.AtWindowBottom())
            {
                grid.MoveDown();
            }

            // Allow right click or left click on nothing to exit.
            if (MouseInput.Right.WasPressed || (!hitAnything && MouseInput.Left.WasPressed))
            {
                Deactivate();
            }
        }