Beispiel #1
0
        public static void Enable()
        {
            m_enabled    = true;
            m_last_input = EMenuInput.None;

            // Debounce going in, so we don't carry over button presses into menus
            m_debounce = DEBOUNCE_ENTRY_TIME;
        }
Beispiel #2
0
 public static EMenuInput PollInput()
 {
     if (m_last_input != EMenuInput.None)
     {
         EMenuInput ret_input = m_last_input;
         m_last_input = EMenuInput.None;
         m_debounce   = DEBOUNCE_TIME;
         return(ret_input);
     }
     return(EMenuInput.None);
 }
Beispiel #3
0
        public override void Update(GameTime gameTime)
        {
            EMenuInput new_input = EMenuInput.None;

            if (m_enabled)
            {
                GamePadState  gamePad  = GamePad.GetState(PlayerIndex.One);
                KeyboardState keyboard = Keyboard.GetState();

                if ((gamePad.ThumbSticks.Left.Y > 0.2f) ||
                    (gamePad.ThumbSticks.Right.Y > 0.2f) ||
                    (gamePad.DPad.Up == ButtonState.Pressed) ||
                    (keyboard.IsKeyDown(Keys.Up)))
                {
                    new_input = EMenuInput.Up;
                }
                else if ((gamePad.ThumbSticks.Left.Y < -0.2f) ||
                         (gamePad.ThumbSticks.Right.Y < -0.2f) ||
                         (gamePad.DPad.Down == ButtonState.Pressed) ||
                         (keyboard.IsKeyDown(Keys.Down)))
                {
                    new_input = EMenuInput.Down;
                }
                else if ((gamePad.Buttons.A == ButtonState.Pressed) ||
                         keyboard.IsKeyDown(Keys.Space) ||
                         keyboard.IsKeyDown(Keys.Enter))
                {
                    new_input = EMenuInput.Select;
                }
                else if ((gamePad.Buttons.B == ButtonState.Pressed) ||
                         (gamePad.Buttons.Back == ButtonState.Pressed) ||
                         keyboard.IsKeyDown(Keys.Escape) ||
                         keyboard.IsKeyDown(Keys.Back))
                {
                    new_input = EMenuInput.Back;
                }
                else if ((gamePad.Buttons.Start == ButtonState.Pressed) ||
                         keyboard.IsKeyDown(Keys.F1))
                {
                    new_input = EMenuInput.Start;
                }

                if (new_input == EMenuInput.None)
                {
                    // Nothing pressed. Reset the debounce so that tapping keys is still nice and fast.
                    m_debounce = 0;
                }
                else if (m_debounce == 0)
                {
                    // Register this reading
                    m_last_input = new_input;
                }
            }

            // Decay the debounce value. Ignore this new reading
            if (m_debounce > 0)
            {
                m_debounce -= gameTime.ElapsedGameTime.Milliseconds;
                if (m_debounce < 0)
                {
                    m_debounce = 0;
                }
            }
        }
Beispiel #4
0
 public static void Disable()
 {
     m_enabled    = false;
     m_last_input = EMenuInput.None;
 }