Example #1
0
        /// <summary>
        /// Handle user input.
        /// </summary>
        /// <param name="input">The helper for reading input from the user.</param>
        public void HandleInput(InputState input)
        {
            //Let the GUI handle user input.
            _GUI.HandleInput(input);
            //Enable the DebugSystem to handle input.
            _DebugSystem.HandleInput(input);

            #region Camera
            //If the CTRL button is not held down.
            if (!input.IsKeyDown(Keys.LeftControl))
            {
                //Manage the camera movement.
                if (input.IsKeyDown(Keys.W)) { MoveCamera(new Vector2(0, -1)); }
                if (input.IsKeyDown(Keys.S)) { MoveCamera(new Vector2(0, 1)); }
                if (input.IsKeyDown(Keys.A)) { MoveCamera(new Vector2(-1, 0)); }
                if (input.IsKeyDown(Keys.D)) { MoveCamera(new Vector2(1, 0)); }

                //Let the user zoom in and out.
                if (input.IsKeyDown(Keys.Z)) { _Camera.Zoom(-.05f); }
                if (input.IsKeyDown(Keys.X)) { _Camera.Zoom(.05f); }
            }
            #endregion

            #region Editing
            //If the CTRL button is down.
            if (input.IsKeyDown(Keys.LeftControl))
            {
                //Manage the item movement.
                if (input.IsKeyDown(Keys.W)) { MoveItem(new Vector2(0, -5)); }
                if (input.IsKeyDown(Keys.S)) { MoveItem(new Vector2(0, 5)); }
                if (input.IsKeyDown(Keys.A)) { MoveItem(new Vector2(-5, 0)); }
                if (input.IsKeyDown(Keys.D)) { MoveItem(new Vector2(5, 0)); }

                //Let the user rotate the item.
                if (input.IsKeyDown(Keys.Q)) { RotateItem(-.01f); }
                if (input.IsKeyDown(Keys.E)) { RotateItem(.01f); }

                //Let the user scale the item.
                if (input.IsKeyDown(Keys.Z)) { ScaleItem(new Vector2(-.05f, -.05f)); }
                if (input.IsKeyDown(Keys.X)) { ScaleItem(new Vector2(.05f, .05f)); }

                //Let the user copy the item.
                if (input.IsNewKeyPress(Keys.V)) { CopyItem(Helper.GetMousePosition()); }
            }

            //If the GUI hasn't been clicked.
            if (!_IsGUIClicked)
            {
                //Select an item.
                if (input.IsNewLeftMouseClick()) { SelectItem(GetItemAtPosition(Helper.GetMousePosition())); }

                //If the user wants to seize and move an item with the mouse.
                if (input.IsNewLeftMousePress() && _SelectedItem != null)
                {
                    //Handle the item grapple.
                    GrappleItem();
                }
            }

            //If the user disengages the grapple function.
            if (input.IsNewLeftMouseReleased())
            {
                //If the grapple joint exists.
                if (_MouseGrappleJoint != null)
                {
                    //Remove the grapple joint from the world simulation.
                    _Level.World.RemoveJoint(_MouseGrappleJoint);
                    _MouseGrappleJoint = null;
                }

                //Reset the grapple point.
                _ItemGrapplePoint = Vector2.Zero;
            }
            #endregion

            //Quickie.
            if (input.IsKeyDown(Keys.N)) { SetUpTreeView(); }
            if (input.IsNewKeyPress(Keys.M)) { ToggleGUI(); }

            //Let the level handle user input.
            _Level.HandleInput(input);
        }