コード例 #1
0
 // navigate to the previous sub-menu (or toggle the menu, if appropriate)
 public void back()
 {
     if (m_currentMenu == MenuType.Main)
     {
         m_interpreter.execute("menu toggle");
     }
     else if (m_currentMenu == MenuType.SinglePlayer)
     {
         m_menu[(int)m_currentMenu].index = 0;
         m_currentMenu = MenuType.Main;
     }
 }
コード例 #2
0
ファイル: ControlSystem.cs プロジェクト: nitro404/Scrap_Heap
        public void handleInput(GameTime gameTime)
        {
            // get the keys currently pressed
            Keys[] pressedKeys = Keyboard.GetState().GetPressedKeys();

            // loop through all of the input keys, and if the current pressed key has a command associated with it, execute the command
            for (int i = 0; i < pressedKeys.Length; i++)
            {
                for (int j = 0; j < m_keys.Length; j++)
                {
                    if (pressedKeys[i] == m_keys[j] && m_commands[j] != null)
                    {
                        m_interpreter.execute(m_commands[j]);
                        break;
                    }
                }
            }
        }
コード例 #3
0
ファイル: GameConsole.cs プロジェクト: nitro404/Scrap_Heap
        public void handleInput(GameTime gameTime)
        {
            KeyboardState keyboard = Keyboard.GetState();
            MouseState    mouse    = Mouse.GetState();

            // remember if the console was already open or not
            bool consoleWasOpen = m_active;

            // allow the console to be toggled with tilde
            if (keyboard.IsKeyDown(Keys.OemTilde))
            {
                if (!m_consoleKeyPressed)
                {
                    m_interpreter.execute("console toggle");
                    m_consoleKeyPressed = true;
                }
            }
            else
            {
                m_consoleKeyPressed = false;
            }

            // allow the console to be closed with escape
            if (keyboard.IsKeyDown(Keys.Escape))
            {
                if (!m_escKeyPressed)
                {
                    m_interpreter.execute("console hide");
                    m_escKeyPressed = true;
                }
            }
            else
            {
                m_escKeyPressed = false;
            }

            // if the console was already open, do not handle any other input
            if (!consoleWasOpen)
            {
                return;
            }

            // if the user pressed enter, allow the current input string to be parsed and interpreted (and store it in the history)
            if (keyboard.IsKeyDown(Keys.Enter))
            {
                if (!m_enterKeyPressed)
                {
                    // trim history if it is full
                    if (m_outputHistory.Count() >= m_maxOutputHistory)
                    {
                        m_outputHistory.RemoveAt(0);
                    }

                    if (m_inputHistory.Count() >= m_maxInputHistory)
                    {
                        m_inputHistory.RemoveAt(0);
                    }

                    m_outputHistory.Add(m_input);
                    m_inputHistory.Add(m_input);

                    // execute the command
                    m_interpreter.execute(m_input);

                    // clear the input and reset animations
                    m_input     = "";
                    m_cursorPos = 0;
                    resetCursorAnimation();

                    m_enterKeyPressed = true;

                    return;
                }
            }
            else
            {
                m_enterKeyPressed = false;
            }

            // allow the user to navigate the cursor left
            if (keyboard.IsKeyDown(Keys.Left))
            {
                if (!m_leftKeyPressed)
                {
                    if (m_cursorPos > 0)
                    {
                        m_cursorPos--;
                    }
                    resetCursorAnimation();
                    m_leftKeyPressed = true;
                }
            }
            else
            {
                m_leftKeyPressed = false;
            }

            // allow the user to navigate the cursor right
            if (keyboard.IsKeyDown(Keys.Right))
            {
                if (!m_rightKeyPressed)
                {
                    if (m_cursorPos < m_input.Length)
                    {
                        m_cursorPos++;
                    }
                    resetCursorAnimation();
                    m_rightKeyPressed = true;
                }
            }
            else
            {
                m_rightKeyPressed = false;
            }

            // allow the user to navigate the cursor to the beginning of the line
            if (keyboard.IsKeyDown(Keys.Home))
            {
                if (!m_homeKeyPressed)
                {
                    m_cursorPos = 0;
                    resetCursorAnimation();
                    m_homeKeyPressed = true;
                }
            }
            else
            {
                m_homeKeyPressed = false;
            }

            // allow the user to navigate the cursor to the end of the line
            if (keyboard.IsKeyDown(Keys.End))
            {
                if (!m_endKeyPressed)
                {
                    m_cursorPos = m_input.Length;
                    resetCursorAnimation();
                    m_endKeyPressed = true;
                }
            }
            else
            {
                m_endKeyPressed = false;
            }

            // allow the user to backspace at the cursor's current position
            if (keyboard.IsKeyDown(Keys.Back))
            {
                if (!m_backspaceKeyPressed)
                {
                    if (m_input.Length > 0 && m_cursorPos > 0)
                    {
                        m_input = m_input.Substring(0, m_cursorPos - 1)
                                  + m_input.Substring(m_cursorPos, m_input.Length - m_cursorPos);
                        m_cursorPos--;
                    }
                    resetCursorAnimation();
                    m_backspaceKeyPressed = true;
                }
            }
            else
            {
                m_backspaceKeyPressed = false;
            }

            // allow the user to delete at the cursor's current position
            if (keyboard.IsKeyDown(Keys.Delete))
            {
                if (!m_deleteKeyPressed)
                {
                    if (m_input.Length > 0 && m_cursorPos < m_input.Length)
                    {
                        m_input = m_input.Substring(0, m_cursorPos)
                                  + m_input.Substring(m_cursorPos + 1, m_input.Length - m_cursorPos - 1);
                    }
                    resetCursorAnimation();
                    m_deleteKeyPressed = true;
                }
            }
            else
            {
                m_deleteKeyPressed = false;
            }

            bool upperCase = keyboard.IsKeyDown(Keys.LeftShift) || keyboard.IsKeyDown(Keys.RightShift);

            // TODO: fix backslash key not registering

            // allow the keys the user presses to show up as input in the console using brute force checks
            for (int i = 0; i < m_inputKeys.Length; i++)
            {
                // check to see if a corresponding input key is pressed
                if (keyboard.IsKeyDown(m_inputKeys[i]))
                {
                    // ensure that the key is not already pressed
                    if (!m_inputKeyPressed[i])
                    {
                        // get the input character (and check to see if shift is pressed, and modify the char appropriately)
                        char inputChar = (upperCase) ? m_upperCaseChar[i] : m_lowerCaseChar[i];

                        // append the char to the appropriate place in the string (based on where the cursor is located)
                        if (m_cursorPos == m_input.Length)
                        {
                            m_input += inputChar;
                        }
                        else
                        {
                            m_input = m_input.Substring(0, m_cursorPos)
                                      + inputChar
                                      + m_input.Substring(m_cursorPos, m_input.Length - m_cursorPos);
                        }

                        // increment the cursor position and set the key as pressed
                        m_cursorPos++;
                        m_inputKeyPressed[i] = true;
                    }
                }
                else
                {
                    m_inputKeyPressed[i] = false;
                }
            }
        }