Exemplo n.º 1
0
        /// <summary>
        /// Updates the Entity.
        /// </summary>
        /// <param name="graphics">The graphics.</param>
        /// <param name="input">The input.</param>
        /// <param name="delta">The delta.</param>
        public void Update(GraphicsDevice graphics, Input input, long delta)
        {
            MenuScreen screen = Screens[SelectedMenuScreen];
            int        max    = (Screens[SelectedMenuScreen] == Screens[MainMenuIndex])
                          ? screen.Elements.Count
                          : screen.Elements.Count + 1;

            if (input.Down())
            {
                if (_down == false)
                {
                    _down = true;
                    _menuMove.Play();
                    screen.SelectedIndex += 1;
                    if (screen.SelectedIndex >= max)
                    {
                        screen.SelectedIndex = 0;
                    }
                }
            }
            else
            {
                _down = false;
            }
            if (input.Up())
            {
                if (_up == false)
                {
                    _up = true;
                    _menuMove.Play();
                    screen.SelectedIndex -= 1;
                    if (screen.SelectedIndex < 0)
                    {
                        screen.SelectedIndex = max - 1;
                    }
                }
            }
            else
            {
                _up = false;
            }
            if (input.Fire())
            {
                if (_enter == false)
                {
                    _enter = true;
                    Action[] actions = screen.Elements.Values.ToArray();
                    if (screen.SelectedIndex == actions.Count())
                    {
                        _menuBack.Play();
                        SelectedMenuScreen = screen.Parent == null ? MainMenuIndex : Screens.IndexOf(screen.Parent);
                    }
                    else
                    {
                        Action action = screen.Elements.Values.ToArray()[screen.SelectedIndex];
                        if (action != null)
                        {
                            _menuSelect.Play();
                            action();
                        }
                    }
                }
            }
            else
            {
                _enter = false;
            }

            if (input.Escape())
            {
                if (_escape == false)
                {
                    _escape = true;
                    if (screen.Parent != null)
                    {
                        _menuBack.Play();

                        SelectedMenuScreen = Screens.IndexOf(screen.Parent);
                    }
                    else if (screen != Screens[MainMenuIndex])
                    {
                        _menuBack.Play();
                        SelectedMenuScreen = MainMenuIndex;
                    }
                }
            }
            else
            {
                _escape = false;
            }
        }