/// <summary> /// Handle all input to the debug system. /// </summary> /// <param name="input">The input to consider.</param> public void HandleInput(InputState input) { if (input.IsNewKeyPress(Keys.F1)) { Debug(); } if (input.IsKeyDown(Keys.LeftShift)) { if (input.IsNewKeyPress(Keys.Q)) { _World.Gravity = new Vector2(0, 0); } if (input.IsNewKeyPress(Keys.W)) { _World.Gravity = new Vector2(1, 0); } if (input.IsNewKeyPress(Keys.E)) { _World.Gravity = new Vector2(10, 0); } if (input.IsNewKeyPress(Keys.R)) { _World.Gravity = new Vector2(100, 0); } if (input.IsNewKeyPress(Keys.T)) { _World.Gravity = new Vector2(1000, 0); } } else { if (input.IsNewKeyPress(Keys.Q)) { _World.Gravity = new Vector2(0, -10); } if (input.IsNewKeyPress(Keys.W)) { _World.Gravity = new Vector2(0, -1); } if (input.IsNewKeyPress(Keys.E)) { _World.Gravity = new Vector2(0, 1); } if (input.IsNewKeyPress(Keys.R)) { _World.Gravity = new Vector2(0, 10); } if (input.IsNewKeyPress(Keys.T)) { _World.Gravity = new Vector2(0, 100); } } /*if (input.CurrentKeyboardStates[i].IsKeyDown(Keys.Z)) { System.UpdateSpeed = 0.1f; } if (input.CurrentKeyboardStates[i].IsKeyDown(Keys.X)) { System.UpdateSpeed = 0.01f; } if (input.CurrentKeyboardStates[i].IsKeyDown(Keys.C)) { System.UpdateSpeed = 0.001f; } if (input.CurrentKeyboardStates[i].IsKeyDown(Keys.V)) { System.UpdateSpeed = 0.0001f; } if (input.CurrentKeyboardStates[i].IsKeyDown(Keys.B)) { System.UpdateSpeed = 0.0f; }*/ }
/// <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 component is not active nor visible, stop here. if (!IsActive || !IsVisible) { return; } //If the component has focus. if (HasFocus) { //Delete text. if (input.IsKeyDown(Keys.Delete) && !_UsedKeys.ContainsKey(Keys.Delete)) { DeleteText(true); } else if (input.IsKeyDown(Keys.Back) && !_UsedKeys.ContainsKey(Keys.Back)) { DeleteText(false); } //Unfocus the textbox. else if (input.IsKeyDown(Keys.Enter) && !_UsedKeys.ContainsKey(Keys.Enter)) { FocusChangeInvoke(false); } //If the marker should be moved. if (input.IsKeyDown(Keys.Left) && !_UsedKeys.ContainsKey(Keys.Left)) { MoveMarkerLeft(); } if (input.IsKeyDown(Keys.Right) && !_UsedKeys.ContainsKey(Keys.Right)) { MoveMarkerRight(); } //If a key has been pressed, write to the textbox. if (input.IsAnyKeyPress()) { InsertText(input, 0, _MarkerIndex); } } }
/// <summary> /// Get a string containing the writable keyboard input from last update. /// </summary> /// <param name="input">The input state.</param> /// <param name="i">The player index.</param> /// <returns>A string of writable keys.</returns> private string GetTextInput(InputState input, int i) { //The list of keys to return. string text = ""; //Make the pressed keys more accessible. Keys[] keys = input.CurrentKeyboardStates[i].GetPressedKeys(); //Loop through the list of recently pressed keys and see if they are eligible for writing. for (int a = 0; a < keys.Length; a++) { //If the key has not been pressed for a while, continue. if (!_UsedKeys.ContainsKey(keys[a])) { //Add the key to the list of recently pressed keys. _UsedKeys.Add(keys[a], _TotalElapsedTime); //If an alphabetical key has been pressed. if ((keys[a] >= Keys.A) && (keys[a] <= Keys.Z)) { //If uppercase. //TODO: No support for Caps Lock. if (input.IsKeyDown(Keys.LeftShift)) { text += keys[a].ToString().ToUpper(); } else { text += keys[a].ToString().ToLower(); } } //If a numerical key has been pressed. else if ((keys[a] >= Keys.D0 && keys[a] <= Keys.D9)) { //If left shift is currently down. if (input.IsKeyDown(Keys.LeftShift)) { //Shifted numerical keys. switch (keys[a]) { case Keys.D1: { text += "!"; break; } case Keys.D2: { text += "\""; break; } case Keys.D3: { text += "#"; break; } case Keys.D4: { text += "¤"; break; } case Keys.D5: { text += "%"; break; } case Keys.D6: { text += "&"; break; } case Keys.D7: { text += "/"; break; } case Keys.D8: { text += "("; break; } case Keys.D9: { text += ")"; break; } case Keys.D0: { text += "="; break; } default: { break; } } } //If right alt is currently down. else if (input.IsKeyDown(Keys.RightAlt)) { //Non-shifted numerical symbol keys. switch (keys[a]) { case Keys.D1: { text += ""; break; } case Keys.D2: { text += "@"; break; } case Keys.D3: { text += "£"; break; } case Keys.D4: { text += "$"; break; } case Keys.D5: { text += "€"; break; } case Keys.D6: { text += ""; break; } case Keys.D7: { text += "{"; break; } case Keys.D8: { text += "["; break; } case Keys.D9: { text += "]"; break; } case Keys.D0: { text += "}"; break; } default: { break; } } } //Use the regular numerical keys. else { text += keys[a].ToString().Replace("D", string.Empty); } } //If another symbol key has been pressed. else { //Non-shifted symbol keys. switch (keys[a]) { case (Keys.OemComma): { text += ","; break; } case (Keys.OemPeriod): { text += "."; break; } case (Keys.OemBackslash): { text += @"\"; break; } case (Keys.Multiply): { text += "*"; break; } case (Keys.OemMinus): { text += "-"; break; } case (Keys.OemPlus): { text += "+"; break; } case (Keys.OemSemicolon): { text += ";"; break; } case (Keys.OemQuotes): { text += "'"; break; } case (Keys.Space): { text += " "; break; } case (Keys.OemQuestion): { text += "?"; break; } default: { break; } } } } } //Return the input in string format. return text; }
/// <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); }