Example #1
1
        public SubMenu(Menu menu, SubMenu parent, String label)
            : base(menu, label)
        {
            this.menu = menu;
            this.parent = parent;

            children = new List<Option>();
        }
Example #2
0
File: Menu.cs Project: zarac/tgspu
 internal void SetCurrentMenu(SubMenu subMenu)
 {
     currentMenu = subMenu;
     selected = 0;
 }
Example #3
0
File: Menu.cs Project: zarac/tgspu
        //public void setInputStates(KeyboardState keyboardState, KeyboardState lastKeyboardState)
        //{
        //    this.keyboardState = keyboardState;
        //    this.lastKeyboardState = lastKeyboardState;
        //}
        public override void Update(GameTime gameTime)
        {
            //Console.WriteLine("MainMenu.Update(...):");

            // Allow closing menu.
            // TODO: Use gameTime to not disable if we just enabled, instead of setting last state this current (when using same key)?
            if (input.keyboardState.IsKeyDown(Keys.Escape)
                && !input.lastKeyboardState.IsKeyDown(Keys.Escape))
            {
                close();
            }

            if (input.keyboardState.IsKeyDown(Keys.Back)
                && !input.lastKeyboardState.IsKeyDown(Keys.Back)
                && currentMenu.GetParent() != null)
                currentMenu = currentMenu.GetParent();

            // navigation
            if (currentMenu.OptionCount > 0)
            {
                // up / prev
                if (input.keyboardState.IsKeyDown(Keys.Up)
                    && !input.lastKeyboardState.IsKeyDown(Keys.Up))
                {
                    if (selected == 0)
                        selected = currentMenu.OptionCount - 1;
                    else
                        selected--;
                    input.Clear();
                }

                // down / next
                if (input.keyboardState.IsKeyDown(Keys.Down)
                    && !input.lastKeyboardState.IsKeyDown(Keys.Down))
                {
                    if (selected == currentMenu.OptionCount - 1)
                        selected = 0;
                    else
                        selected++;
                    input.Clear();
                }

                // select
                if (input.keyboardState.IsKeyDown(Keys.Enter)
                    && !input.lastKeyboardState.IsKeyDown(Keys.Enter))
                {
                    currentMenu.GetChildren()[selected].Action();
                    input.Clear();
                }
            }

            base.Update(gameTime);
        }