Beispiel #1
0
        /// <summary>
        /// Gets all text that was written since the information was last retrieved.
        /// </summary>
        public static KeyHandlerState GetKBState()
        {
            KeyHandlerState KB = new KeyHandlerState();

            lock (Locker)
            {
                KB.KeyboardString = _KeyboardString;
                _KeyboardString   = "";
                KB.InitBS         = _InitBS;
                _InitBS           = 0;
                KB.ControlDown    = _ControlDown;
                KB.CopyPressed    = _CopyPressed;
                _CopyPressed      = false;
                KB.EndDelete      = _EndDelete;
                _EndDelete        = 0;
                KB.LeftRights     = _LeftRights;
                _LeftRights       = 0;
                KB.Pages          = _Pages;
                _Pages            = 0;
                KB.Scrolls        = _Scrolls;
                _Scrolls          = 0;
                KB.TogglerPressed = _TogglerPressed;
                _TogglerPressed   = false;
            }
            return(KB);
        }
Beispiel #2
0
 /// <summary>
 /// Updates the console, called every tick.
 /// </summary>
 public static void Tick()
 {
     // Update open/close state
     if (KeyHandler._TogglerPressed)
     {
         KeyHandler.GetKBState();
         Open = !Open;
         if (Open)
         {
             MouseWasCaptured = MouseHandler.MouseCaptured;
             MouseHandler.ReleaseMouse();
             RecentSpot = RecentCommands.Count;
         }
         else
         {
             if (MouseWasCaptured)
             {
                 MouseHandler.CaptureMouse();
             }
             Typing       = "";
             TypingText   = "";
             TypingCursor = 0;
         }
     }
     if (Open)
     {
         KeyHandlerState KeyState = KeyHandler.GetKBState();
         extralines = 0;
         LineBack   = 0;
         // flicker the cursor
         keymark_delta += Client.Central.Delta;
         if (keymark_delta > 0.5f)
         {
             keymark_add   = !keymark_add;
             keymark_delta = 0f;
         }
         // handle backspaces
         if (KeyState.InitBS > 0)
         {
             string partone = TypingCursor > 0 ? TypingText.Substring(0, TypingCursor) : "";
             string parttwo = TypingCursor < TypingText.Length ? TypingText.Substring(TypingCursor) : "";
             if (partone.Length > KeyState.InitBS)
             {
                 partone       = partone.Substring(0, partone.Length - KeyState.InitBS);
                 TypingCursor -= KeyState.InitBS;
             }
             else
             {
                 TypingCursor -= partone.Length;
                 partone       = "";
             }
             TypingText = partone + parttwo;
         }
         // handle input text
         KeyState.KeyboardString = KeyState.KeyboardString.Replace("\t", "    ");
         if (KeyState.KeyboardString.Length > 0)
         {
             if (TypingText.Length == TypingCursor)
             {
                 TypingText += Utilities.CleanStringInput(KeyState.KeyboardString);
             }
             else
             {
                 if (KeyState.KeyboardString.Contains('\n'))
                 {
                     string[] lines = KeyState.KeyboardString.SplitFast('\n', 1);
                     TypingText = TypingText.Insert(TypingCursor, Utilities.CleanStringInput(lines[0])) + "\n" + Utilities.CleanStringInput(lines[1]);
                 }
                 else
                 {
                     TypingText = TypingText.Insert(TypingCursor, Utilities.CleanStringInput(KeyState.KeyboardString));
                 }
             }
             TypingCursor += KeyState.KeyboardString.Length;
             while (TypingText.Contains('\n'))
             {
                 int    index = TypingText.IndexOf('\n');
                 string input = TypingText.Substring(0, index);
                 if (index + 1 < TypingText.Length)
                 {
                     TypingText   = TypingText.Substring(index + 1);
                     TypingCursor = TypingText.Length;
                 }
                 else
                 {
                     TypingText   = "";
                     TypingCursor = 0;
                 }
                 WriteLine("] " + input);
                 RecentCommands.Add(input);
                 if (RecentCommands.Count > MaxRecentCommands)
                 {
                     RecentCommands.RemoveAt(0);
                 }
                 RecentSpot = RecentCommands.Count;
                 Client.Central.Commands.ExecuteCommands(input);
             }
         }
         // handle copying
         if (KeyState.CopyPressed)
         {
             if (TypingText.Length > 0)
             {
                 System.Windows.Forms.Clipboard.SetText(TypingText);
             }
         }
         // handle cursor left/right movement
         if (KeyState.LeftRights != 0)
         {
             TypingCursor += KeyState.LeftRights;
             if (TypingCursor < 0)
             {
                 TypingCursor = 0;
             }
             if (TypingCursor > TypingText.Length)
             {
                 TypingCursor = TypingText.Length;
             }
             keymark_add   = true;
             keymark_delta = 0f;
         }
         // handle scrolling up/down in the console
         if (KeyState.Pages != 0)
         {
             ScrolledLine -= (int)(KeyState.Pages * ((float)Client.Central.Window.Height / 2 / Client.Central.FontSets.Standard.font_default.Height - 3));
         }
         ScrolledLine -= MouseHandler.MouseScroll;
         if (ScrolledLine > 0)
         {
             ScrolledLine = 0;
         }
         if (ScrolledLine < -Lines + 5)
         {
             ScrolledLine = -Lines + 5;
         }
         // handle scrolling through commands
         if (KeyState.Scrolls != 0)
         {
             RecentSpot -= KeyState.Scrolls;
             if (RecentSpot < 0)
             {
                 RecentSpot = 0;
                 TypingText = RecentCommands[0];
             }
             else if (RecentSpot >= RecentCommands.Count)
             {
                 RecentSpot = RecentCommands.Count;
                 TypingText = "";
             }
             else
             {
                 TypingText = RecentCommands[RecentSpot];
             }
             TypingCursor = TypingText.Length;
         }
         // update the rendered text
         Typing = ">" + TypingText;
     }
     else // !Open
     {
         if (extralines > 0)
         {
             LineBack -= Client.Central.Delta;
             if (LineBack <= 0)
             {
                 extralines--;
                 LineBack = 3f;
             }
         }
     }
 }
Beispiel #3
0
 /// <summary>
 /// Gets all text that was written since the information was last retrieved.
 /// </summary>
 public static KeyHandlerState GetKBState()
 {
     KeyHandlerState KB = new KeyHandlerState();
     lock (Locker)
     {
         KB.KeyboardString = _KeyboardString;
         _KeyboardString = "";
         KB.InitBS = _InitBS;
         _InitBS = 0;
         KB.ControlDown = _ControlDown;
         KB.CopyPressed = _CopyPressed;
         _CopyPressed = false;
         KB.EndDelete = _EndDelete;
         _EndDelete = 0;
         KB.LeftRights = _LeftRights;
         _LeftRights = 0;
         KB.Pages = _Pages;
         _Pages = 0;
         KB.Scrolls = _Scrolls;
         _Scrolls = 0;
         KB.TogglerPressed = _TogglerPressed;
         _TogglerPressed = false;
     }
     return KB;
 }