Example #1
0
 void TouchEnded(CCTouch touch, CCEvent touchEvent)
 {
     Debug.Assert(MenuState == CCMenuState.TrackingTouch, "[Menu TouchEnded] -- invalid state");
     if (SelectedMenuItem != null)
     {
         SelectedMenuItem.Selected = false;
         SelectedMenuItem.Activate();
     }
     MenuState = CCMenuState.Waiting;
 }
Example #2
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);


            foreach (MenuItem item in m_menuItems)
            {
                item.Update(gameTime);
            }

            if (KeyboardExtended.Current.NothingPressed)
            {
                KeyboardState state = Keyboard.GetState();
                if (state.GetPressedKeys().Length == 0)
                {
                    m_lastKeyboardInput = DateTime.MinValue;
                }

                if ((DateTime.Now - m_lastKeyboardInput).TotalMilliseconds > KeyboardDelay)
                {
                    if (state.IsKeyDown(Keys.Down) || (state.IsKeyDown(Keys.Tab) && !(state.IsKeyDown(Keys.LeftShift) || state.IsKeyDown(Keys.RightShift))))
                    {
                        SelectedIndex++;
                        ResetLastKeyboardTime();
                    }
                    if (state.IsKeyDown(Keys.Up) || (state.IsKeyDown(Keys.Tab) && (state.IsKeyDown(Keys.LeftShift) || state.IsKeyDown(Keys.RightShift))))
                    {
                        SelectedIndex--;
                        ResetLastKeyboardTime();
                    }


                    if (state.IsKeyDown(Keys.Home))
                    {
                        SelectedIndex = 0;
                    }
                    if (state.IsKeyDown(Keys.End))
                    {
                        SelectedIndex = m_menuItems.Count - 1;
                    }
                }
                if (state.IsKeyDown(Keys.Enter) || state.IsKeyDown(Keys.Space))
                {
                    SelectedMenuItem.Activate();
                }
            }
        }