Exemplo n.º 1
0
        /// <summary>
        /// Update the menu.
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="keyState"></param>
        /// <param name="prevState"></param>
        public void Update(GameTime gameTime, KeyboardState keyState, KeyboardState prevState)
        {
            // If we are moving down an item.
            if ( (keyState.IsKeyDown(Keys.S) && prevState.IsKeyUp(Keys.S))
                || (keyState.IsKeyDown(Keys.Down) && prevState.IsKeyUp(Keys.Down)))
            {
                if (lMenuItems.IndexOf(miSelected) == lMenuItems.Count - 1)
                {
                    miSelected.Scale = 1.0f;
                    miSelected = lMenuItems[0];
                }
                else
                {
                    miSelected.Scale = 1.0f;
                    miSelected = lMenuItems[lMenuItems.IndexOf(miSelected) + 1];
                }
            }
                // If we are moving up an item.

            else if ( (keyState.IsKeyDown(Keys.W) && prevState.IsKeyUp(Keys.W))
                || (keyState.IsKeyDown(Keys.Up) && prevState.IsKeyUp(Keys.Up)))
            {
                if (lMenuItems.IndexOf(miSelected) == 0)
                {
                    miSelected.Scale = 1.0f;
                    miSelected = lMenuItems[lMenuItems.Count - 1];
                }
                else
                {
                    miSelected.Scale = 1.0f;
                    miSelected = lMenuItems[lMenuItems.IndexOf(miSelected) - 1];
                }
            }
                // If we are selecting an item.
            else if (keyState.IsKeyDown(Keys.Enter) && prevState.IsKeyUp(Keys.Enter) && prevState != null )
            {
                miSelected.SelectEvent.Invoke(this, new EventArgs());
                return;
            }
                // If we are backing out of the menu.
            else if (keyState.IsKeyDown(Keys.Back) && prevState.IsKeyUp(Keys.Back) && prevState != null)
            {
                // A backspace event is not required for a menu to have, so only do it if it was specified.
                if (BackOutEvent != null)
                    BackOutEvent.Invoke(this, new EventArgs());
                return;
            }

            // Pulse the selected item.
            UpdatePulse(gameTime);

            TransitionEnter.Update(gameTime);
            TransitionExit.Update(gameTime);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Load the content for the menu
        /// </summary>
        /// <param name="contentManager">The content manager.</param>
        /// <param name="options">The names of the options.</param>
        /// <param name="handlers">The event that is fired when the corrosponding option is selected.</param>
        public void LoadContent(ContentManager contentManager, string[] options, EventHandler[] handlers)
        {
            lMenuItems = new List<MenuItem>();
            for (int i = 0; i < options.Length; i++)
            {
                MenuItem item = new MenuItem(handlers[i], options[i]);
                item.LoadContent(contentManager);
                item.Position.Y = i * Spacing; // distance apart, default 64
                item.Position += vPosition; // Can be specified, 0 otherwise
                lMenuItems.Add(item);
            }
            miSelected = lMenuItems[0];

            // Set up the border/background and set default color to white.
            border.LoadContent(contentManager);
            CalculateBorders();
            border.SetColors(Gradients.WhiteGradient);
            border.Thickness = 2;

            TransitionEnter = new MenuTransition(MenuTransition.TransitionStyle.FLY_IN_TOP, this);
            TransitionExit = new MenuTransition(MenuTransition.TransitionStyle.FADE_OUT, this);
        }