Esempio n. 1
0
 /// <summary>
 /// Queries how wide the entry is, used for centering on the screen.
 /// </summary>
 public virtual int GetWidth(MenuScreen screen)
 {
     System.Diagnostics.Debug.Assert(Font != null, "Font is null!");
     if (Font != null)
     {
         return (int)(Font.MeasureString(Text).X * SeparationScale);
     }
     else
     {
         System.Diagnostics.Debug.Assert(ScreenManager.FontNormal != null, "Font Normal is null!");
         return (int)(ScreenManager.FontNormal.MeasureString(Text).X * SeparationScale);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Updates the menu entry.
        /// </summary>
        public virtual void Update(MenuScreen screen, bool isSelected, GameTime gameTime)
        {
            // there is no such thing as a selected item on Windows Phone, so we always
            // force isSelected to be false
            #if WINDOWS_PHONE
            isSelected = false;
            #endif

            // When the menu selection changes, entries gradually fade between
            // their selected and deselected appearance, rather than instantly
            // popping to the new state.
            float fadeSpeed = (float)gameTime.ElapsedGameTime.TotalSeconds * 4;

            if (isSelected)
                selectionFade = Math.Min(selectionFade + fadeSpeed, 1);
            else
                selectionFade = Math.Max(selectionFade - fadeSpeed, 0);
        }
Esempio n. 3
0
        /// <summary>
        /// Draws the menu entry. This can be overridden to customize the appearance.
        /// </summary>
        public virtual void Draw(MenuScreen screen, bool isSelected, GameTime gameTime)
        {
            // there is no such thing as a selected item on Windows Phone, so we always
            // force isSelected to be false

            #if WINDOWS_PHONE
            isSelected = false;
            #endif

            // Pulsate the size of the selected menu entry.
            double time = gameTime.TotalGameTime.TotalSeconds;

            float pulsate = (float)Math.Sin(time * 6) + 1;

            //float scale = SeparationScale + pulsate * 0.05f * selectionFade;
            float scale = 1f + pulsate * 0.05f * selectionFade;
            if (IsLink || IsTitle)
            {
                isSelected = true;
                scale *= 1.2f;
            }

            // Draw the selected entry in yellow, otherwise white.
            Color color = isSelected ? Color.Yellow : Color.White;

            // Modify the alpha to fade text out during transitions.
            color *= screen.TransitionAlpha;

            // Draw text, centered on the middle of each line.
            ScreenManager screenManager = screen.ScreenManager;
            SpriteBatch spriteBatch = screenManager.SpriteBatch;

            Vector2 origin = new Vector2(0, Font.LineSpacing / 2);

            spriteBatch.DrawString(Font, text, new Vector2(position.X + 2, position.Y + 2), Color.Black, 0,
                                   origin, scale, SpriteEffects.None, 0);

            spriteBatch.DrawString(Font, text, position, color, 0,
                                   origin, scale, SpriteEffects.None, 0);
        }