예제 #1
0
        /// <summary>
        /// This function is used to update the contents of the text box.
        /// </summary>
        /// <param name="CurrTime">Currend time information</param>
        /// <param name="CurrKeyboard">Current state of the keyboard.</param>
        /// <param name="CurrMouse">Current state of the mouse.</param>
        /// <param name="ProcessMouseEvent">Set true to allow this object to process mouse events, false to ignore them</param>
        protected override void UpdateContents(GameTime CurrTime, Microsoft.Xna.Framework.Input.KeyboardState CurrKeyboard, Microsoft.Xna.Framework.Input.MouseState CurrMouse, bool ProcessMouseEvent)
        {
            if ((ProcessMouseEvent == true) && ((CurrMouse.LeftButton == ButtonState.Pressed) || (CurrMouse.LeftButton == ButtonState.Pressed))) //Mouse button is pressed
            {
                if (ClientRegion.Contains(CurrMouse.Position) == false)                                                                          //Mouse is outside of the control, it has lost focus
                {
                    if (HasFocus != false)
                    {
                        HasChanged = true;
                    }

                    HasFocus = false;
                }
            }

            if (HasFocus != false)               //Only update if the control has focus
            {
                string Input = MGInput.GetTypedChars(CurrKeyboard, cPriorKeys);

                if (CurrTime.TotalGameTime.Milliseconds <= 500)
                {
                    if (cCursorOn == false)
                    {
                        HasChanged = true;
                    }

                    cCursorOn = true;
                }
                else
                {
                    if (cCursorOn == true)
                    {
                        HasChanged = true;
                    }

                    cCursorOn = false;
                }

                if (Input.CompareTo("\b") == 0)
                {
                    if (Text.Length > 0)
                    {
                        Text       = Text.Substring(0, Text.Length - 1);
                        HasChanged = true;
                    }
                }
                else
                {
                    Text      += Input;
                    HasChanged = true;
                }
            }
        }
        /// <summary>
        /// Processes inputs to determine if any new content should be displayed in the console
        /// </summary>
        /// <param name="CurrKeys">Current state of the keyboard.</param>
        /// <param name="CurrMouse">Current state of the mouse.</param>
        /// <param name="TotalTime">Current time information</param>
        /// <param name="ProcessMouseEvent">Set true to allow this object to process mouse events, false to ignore them</param>
        protected override void UpdateContents(GameTime TotalTime, KeyboardState CurrKeys, MouseState CurrMouse, bool ProcessMouseEvent)
        {
            string NewKeys = MGInput.GetTypedChars(CurrKeys, cPriorKeys);

            if (TotalTime.TotalGameTime.Milliseconds <= 500)
            {
                if (cCursorOn == false)
                {
                    HasChanged = true;
                }

                cCursorOn = true;
            }
            else
            {
                if (cCursorOn == true)
                {
                    HasChanged = true;
                }

                cCursorOn = false;
            }

            if (NewKeys.CompareTo("") != 0)
            {
                HasChanged = true;

                if (NewKeys.CompareTo("\b") == 0)
                {
                    if (cCommand.Length > 2)
                    {
                        cCommand = cCommand.Substring(0, cCommand.Length - 1);
                    }
                }
                else if (NewKeys.CompareTo("\n") == 0)
                {
                    if (CommandSent != null)
                    {
                        CommandSent(this, cCommand.Substring(2));                         //Start at two to chop off the > prompt

                        //Add command to history
                        cCommandHist.Enqueue(cCommand.Substring(2));

                        while (cCommandHist.Count > 10)
                        {
                            cCommandHist.Dequeue();
                        }

                        cHistCtr = cCommandHist.Count;
                    }

                    cCommand = "> ";
                }
                else
                {
                    cCommand += NewKeys;
                }
            }

            if ((CurrKeys.IsKeyDown(Keys.Up) == true) && (cPriorKeys.IsKeyDown(Keys.Up) == false))
            {
                cHistCtr--;

                if (cHistCtr < 0)                   //0 is oldest command in the history
                {
                    cHistCtr = 0;
                }

                if (cHistCtr < cCommandHist.Count)
                {
                    cCommand   = "> " + cCommandHist.ElementAt(cHistCtr);
                    HasChanged = true;
                }
            }

            if ((CurrKeys.IsKeyDown(Keys.Down) == true) && (cPriorKeys.IsKeyDown(Keys.Down) == false))
            {
                cHistCtr++;

                if (cHistCtr > cCommandHist.Count)
                {
                    cHistCtr = cCommandHist.Count;
                }

                if (cHistCtr < cCommandHist.Count)
                {
                    cCommand   = "> " + cCommandHist.ElementAt(cHistCtr);
                    HasChanged = true;
                }
            }

            //Update the prior keys
            cPriorKeys = CurrKeys;
        }