/// <summary> /// Handle user input. /// </summary> /// <param name="input">The helper for reading input from the user.</param> public override void HandleInput(InputState input) { //The inherited method. base.HandleInput(input); //If the animation bar is active, write the input to the box. if (IsActive) { //If the animation bar is visible. if (IsVisible) { //If the animation bar has focus. if (HasFocus) { //If the left mouse button has been pressed. if (input.IsNewLeftMouseClick()) { //If the user clicks somewhere else, defocus the animation bar. if (!Helper.IsPointWithinBox(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), Position, Width, Height)) { //Defocus this animation bar. HasFocus = false; } } } //Let the play button handle input. _PlayButton.HandleInput(input); } } }
/// <summary> /// Handle user input. /// </summary> /// <param name="input">The helper for reading input from the user.</param> public virtual void HandleInput(InputState input) { //If the component is not active nor visible, discontinue. if (!_IsActive || !_IsVisible) { return; } //If the left mouse button has been pressed. if (input.IsNewLeftMouseClick()) { //If the user clicks somewhere on the item, fire the event. if (Helper.IsPointWithinBox(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), Position, Width, Height)) { //Fire the event. MouseClickInvoke(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), MouseButton.Left); } //If not, see if it is appropriate to defocus the component. else { FocusChangeInvoke(false); } } //If the right mouse button has been pressed. if (input.IsNewRightMouseClick()) { //If the user clicks somewhere on the item, fire the event. if (Helper.IsPointWithinBox(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), Position, Width, Height)) { //Fire the event. MouseClickInvoke(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), MouseButton.Right); } //If not, see if it is appropriate to defocus the component. else { FocusChangeInvoke(false); } } //If the left mouse button is being held down. if (input.IsNewLeftMousePress()) { //If the user clicks somewhere on the item, fire the event. if (Helper.IsPointWithinBox(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), Position, Width, Height)) { //Fire the event. MouseDownInvoke(Helper.GetMousePosition(), MouseButton.Left); } } //If the mouse is currently hovering over the component. if (Helper.IsPointWithinBox(Helper.GetMousePosition(), Position, Width, Height)) { //If the mouse has just entered the component's surface, fire the event and enable the flag. if (!_IsMouseHovering) { MouseHoverInvoke(); } } //Else, disable the flag. else { _IsMouseHovering = false; } //Loop through all items and give them access to user input. _Items.ForEach(item => item.HandleInput(input)); }
/// <summary> /// Handle user input. /// </summary> /// <param name="input">The helper for reading input from the user.</param> public void HandleInput(InputState input) { //If the GUI is not active nor visible, discontinue. if (!_IsActive || !_IsVisible) { return; } //Decide which collection of items to use. if (_ForegroundItems.Count != 0) { _ForegroundItems.ForEach(item => item.HandleInput(input)); } else { _Items.ForEach(item => item.HandleInput(input)); } //If the right click list is enabled and the user has pressed the left mouse button. if (_HasRightClicked && input.IsNewLeftMouseClick()) { //If the user clicks somewhere else than on the list, disable it. if (!Helper.IsPointWithinBox(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), _RightClickList.Position, _RightClickList.Width, _RightClickList.Height)) { //Disable the list. EnableOrDisableRightClickList(false, Vector2.Zero); } } //If the right mouse button has been pressed, enable or disable the right click list. if (input.IsNewRightMouseClick()) { EnableOrDisableRightClickList(true, new Vector2(Mouse.GetState().X, Mouse.GetState().Y)); } //Enable the right click list to handle user input, if the time is right. if (_HasRightClicked) { _RightClickList.HandleInput(input); } }
/// <summary> /// Lets the game respond to player input. Unlike the Update method, this will only be called when the gameplay screen is active. /// </summary> /// <param name="input">The InputState instance that relays the state of input.</param> public void HandleInput(InputState input) { //Enable the GUI to handle input as well. _GUI.HandleInput(input); //If the GUI hasn't been clicked. if (!_IsGUIClicked) { #region Mouse Clicks //If a left mouse click has occured, see what the user wants to be selected. if (input.IsNewLeftMouseClick()) { //If the click wasn't on any of the animation bars, select the closest bone to the mouse. //if (!Helper.IsPointWithinBox(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), _AnimationBars.Position, _AnimationBars.Width, _AnimationBars.Height)) { //The bone index. int index = -1; //The shortest distance. float shortest = -1; //Loop through all bones in all skeletons and find the closest one. foreach (Bone b in _Character.Skeleton.Bones) { //The average distance to the bone. float distance = Vector2.Distance(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), Vector2.Divide(Vector2.Add(b.TransformedPosition, Helper.CalculateOrbitPosition(b.TransformedPosition, b.TransformedRotation, b.Length)), 2)); //Determine the shortest distance and the bone. if (shortest == -1) { index = b.Index; shortest = distance; } else if ((shortest != -1) && (distance < shortest)) { //The selected index. index = b.Index; //The shortest distance so far. shortest = distance; } } //Pass along the new selected bone index. _SelectedBoneIndex = index; } } #endregion #region Keyboard Presses //If the user presses the TAB button, loop through all bones in the skeleton. if (input.IsNewKeyPress(Keys.Tab)) { //Increment the counter. _SelectedBoneIndex++; //Check the bounds of the selected bone index. if (_SelectedBoneIndex >= _Character.Skeleton.Bones.Count) { _SelectedBoneIndex = 0; } } //If the user holds down CTRL. if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.LeftControl) || input.CurrentKeyboardStates[0].IsKeyDown(Keys.RightControl)) { //Add a new bone to the skeleton. if (input.IsNewKeyPress(Keys.B)) { DisplayCreateBoneDialog(_SelectedBoneIndex); } //If the user presses the K button, insert a new keyframe after the selected one. if (input.IsNewKeyPress(Keys.K)) { AddKeyframe(GetAnimationBar().SelectedFrameNumber + 1); } //If the user presses the DELETE button, delete the selected keyframe. if (input.IsNewKeyPress(Keys.Delete)) { DeleteKeyframe(GetAnimationBar().SelectedFrameNumber); } } //If the animation has been paused. if (!IsAnyAnimationPlaying()) { //If the user holds down CTRL. if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.LeftControl) || input.CurrentKeyboardStates[0].IsKeyDown(Keys.RightControl)) { //Move the selected bone. if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.Right)) { MoveBone(_SelectedBoneIndex, new Vector2(1, 0)); } else if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.Left)) { MoveBone(_SelectedBoneIndex, new Vector2(-1, 0)); } else if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.Up)) { MoveBone(_SelectedBoneIndex, new Vector2(0, -1)); } else if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.Down)) { MoveBone(_SelectedBoneIndex, new Vector2(0, 1)); } } //Otherwise rotate the selected bone. else { //If a bone is selected and the user presses an arrow button, rotate the bone. if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.Right)) { //Rotate the bone and acknowledge that it has been modified. _Character.Skeleton.Bones[_SelectedBoneIndex].Rotation += .1f; _ModifiedBone[_SelectedBoneIndex] = true; } else if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.Left)) { //Rotate the bone and acknowledge that it has been modified. _Character.Skeleton.Bones[_SelectedBoneIndex].Rotation -= .1f; _ModifiedBone[_SelectedBoneIndex] = true; } } } #endregion } }
/// <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); }