Base class for screens that contain a menu of options. The user can move up and down to select an entry, or cancel to back out of the screen.
Inheritance: GameScreen
        public override void Draw(MenuScreen screen, bool isSelected, GameTime gameTime)
        {
            // Draw the selected entry in yellow, otherwise white.
            Color color = Color.White;

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

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

            float scale = 1 + pulsate * 0.05f * selectionFade;

            // Modify the alpha to fade text out during transitions.
            int height = (int)((Convert.ToInt32(ProgramSettings.ResolutionHeight) / 4) * screen.TransitionAlpha * (isSelected ? scale : 1f));
            int width = (int)(wToH * height);//(int)((Convert.ToInt32(ProgramSettings.ResolutionWidth) / (2 + wToH)) * screen.TransitionAlpha * (isSelected ? scale : 1f));

            // Draw picture
            ScreenManager screenManager = screen.ScreenManager;
            SpriteBatch spriteBatch = screenManager.SpriteBatch;
            SpriteFont font = screenManager.Font;

            spriteBatch.Draw(picture,
                new Rectangle(
                    (int)(position.X - (isSelected ? (this.GetWidth(null) * scale - this.GetWidth(null)) / 2 : 0)),
                    (int)(position.Y - (isSelected ? (this.GetHeight(null) * scale - this.GetHeight(null)) / 2 : 0)),
                width, height), color);

            // Scale the font so it fits the current resolution (assuming it is made for 1920*1080) TODO: Has to be a smarter way to do this
            float fontScale = (float)(Convert.ToDouble(ProgramSettings.ResolutionWidth) / 1920.0);

            spriteBatch.DrawString(font, this.text, new Vector2(position.X, position.Y + this.GetHeight(null) + (font.LineSpacing * fontScale)), Color.Yellow, 0, new Vector2(0, 0), fontScale, SpriteEffects.None, 0);
        }
Esempio n. 2
0
        /// <summary>
        /// Draws the menu entry. This can be overridden to customize the appearance.
        /// </summary>
        public virtual void Draw(MenuScreen screen, Vector2 position,
                                 bool isSelected, GameTime gameTime)
        {
            // Draw the selected entry in yellow, otherwise white.
            Color color = isSelected ? Color.Yellow : Color.White;

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

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

            float scale = 1 + pulsate * 0.05f * selectionFade;

            // Modify the alpha to fade text out during transitions.
            color = new Color(color.R, color.G, color.B, screen.TransitionAlpha);

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

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

            spriteBatch.DrawString(font, text, position, color, 0,
                                   origin, scale, SpriteEffects.None, 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)
        {
            Color textColor = isSelected ? Color.White : Color.Black;
            Color tintColor = isSelected ? Color.White : Color.Gray;

#if WINDOWS_PHONE || IOS || ANDROID
            // there is no such thing as a selected item on Windows Phone, so we always
            // force isSelected to be false

            isSelected = false;
            tintColor  = Color.White;
            textColor  = Color.Black;
#endif

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

            spriteBatch.Draw(screenManager.ButtonBackground, destination, tintColor);

            spriteBatch.DrawString(screenManager.Font, text, getTextPosition(screen),
                                   textColor, Rotation, Vector2.Zero, Scale, SpriteEffects.None, 0);
        }
        /// <summary>
        /// Updates the menu item text, adding information about the network
        /// quality of service as soon as that becomes available.
        /// </summary>
        public override void Update(MenuScreen screen, bool isSelected,
                                                       GameTime gameTime)
        {
            base.Update(screen, isSelected, gameTime);

            // Quality of service data can take some time to query, so it will not
            // be filled in straight away when NetworkSession.Find returns. We want
            // to display the list of available sessions straight away, and then
            // fill in the quality of service data whenever that becomes available,
            // so we keep checking until this data shows up.
            if (screen.IsActive && !gotQualityOfService)
            {
                QualityOfService qualityOfService = availableSession.QualityOfService;

                if (qualityOfService.IsAvailable)
                {
                    TimeSpan pingTime = qualityOfService.AverageRoundtripTime;

                    Text += string.Format(" - {0:0} ms", pingTime.TotalMilliseconds);

                    gotQualityOfService = true;
                }
            }
        }
Esempio n. 5
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)
        {
            // Draw the selected entry in yellow, otherwise white.
            Color color = Color.White;

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

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

            float scale = 1;

            // Modify the alpha to fade text out during transitions.
            if (enabled)
                color = Color.Lerp(new Color(100,0,0), Color.White,selectionFade) * screen.TransitionAlpha;//Math.Min(screen.TransitionAlpha, Convert.ToByte(selectionFade)));
            else
                color = new Color(color.R, color.G, color.B) * screen.TransitionAlpha * 0.3f;

            // Draw text, centered on the middle of each line.
            ScreenManager screenManager = screen.ScreenManager;
            SpriteBatch spriteBatch = screenManager.SpriteBatch;
            SpriteFont font = screenManager.Font;
            font.LineSpacing = 25;

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

            spriteBatch.DrawString(font, text, Position+Vector2.One, Color.Black*0.2f, 0,
                                   origin, scale, SpriteEffects.None, 0);
            spriteBatch.DrawString(font, text, Position, color, 0,
                                   origin, scale, SpriteEffects.None, 0);

            bounds = new Rectangle((int)Position.X, (int)Position.Y - 10, 300, 25);
        }
 public override int GetWidth(MenuScreen screen)
 {
     //return picture.Width;
     return (int)(wToH * GetHeight(null));
 }
Esempio n. 7
0
 /// <summary>
 /// Queries how much space this menu entry requires.
 /// </summary>
 public virtual int GetHeight(MenuScreen screen)
 {
     return(screen.ScreenManager.Font.LineSpacing);
 }
Esempio n. 8
0
 /// <summary>
 /// Queries how much space this menu entry requires.
 /// </summary>
 public virtual int GetHeight(MenuScreen screen)
 {
     return screen.ScreenManager.Font.LineSpacing;
 }
Esempio n. 9
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. 10
0
 /// <summary>
 /// Queries how wide the entry is, used for centering on the screen.
 /// </summary>
 public virtual int GetWidth(MenuScreen screen)
 {
     return((int)screen.ScreenManager.Font.MeasureString(Text).X);
 }
Esempio n. 11
0
 public override int GetHeight(MenuScreen screen)
 {
     return((int)(screen.ScreenManager.Font.LineSpacing * Scale));
 }
Esempio n. 12
0
        private Vector2 getTextPosition(MenuScreen screen)
        {
            Vector2 textPosition = Vector2.Zero;
            if (Scale == 1f)
            {
                textPosition = new Vector2((int)destination.X + destination.Width / 2 - GetWidth(screen) / 2,
                                   (int)destination.Y);
            }
            else
            {
                textPosition = new Vector2(
                    (int)destination.X + (destination.Width / 2 - ((GetWidth(screen) / 2) * Scale)),
                                 (int)destination.Y + (GetHeight(screen) - GetHeight(screen) * Scale) / 2);
            }

            return textPosition;
        }
Esempio n. 13
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)
        {
            Color textColor = isSelected ? Color.White : Color.Black;
            Color tintColor = isSelected ? Color.White : Color.Gray;

            #if WINDOWS_PHONE || IOS || ANDROID
            // there is no such thing as a selected item on Windows Phone, so we always
            // force isSelected to be false

            isSelected = false;
            tintColor = Color.White;
            textColor = Color.Black;
            #endif

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

            spriteBatch.Draw(screenManager.ButtonBackground, destination, tintColor);

            spriteBatch.DrawString(screenManager.Font, text, getTextPosition(screen),
                textColor, Rotation, Vector2.Zero, Scale, SpriteEffects.None, 0);
        }
Esempio n. 14
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.Foundation.Metadata.ApiInformation.IsApiContractPresent("Windows.Phone.PhoneContract", 1))
                isSelected = false;

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

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

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

            float scale = 1 + pulsate * 0.05f * selectionFade;

            // Modify the alpha to fade text out during transitions.
            color = new Color(color.R, color.G, color.B) * screen.TransitionAlpha;

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

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

            spriteBatch.DrawString(font, text, position + new Vector2(4, 4), Color.Black, 0,
                       origin, scale, SpriteEffects.None, 0);
            spriteBatch.DrawString(font, text, position, color, 0,
                                   origin, scale, SpriteEffects.None, 0);
        }
Esempio n. 15
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.Foundation.Metadata.ApiInformation.IsApiContractPresent("Windows.Phone.PhoneContract", 1))
                isSelected = false;

            // 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. 16
0
 public override int GetHeight(MenuScreen screen)
 {
     return(_texture.Height);
 }
Esempio n. 17
0
 public override int GetWidth(MenuScreen screen)
 {
     return(_texture.Width);
 }
Esempio n. 18
0
 /// <summary>
 /// Draws the menu entry. This can be overridden to customize the appearance.
 /// </summary>
 public abstract void Draw(MenuScreen screen, GameTime gameTime);
Esempio n. 19
0
 public override int GetWidth(MenuScreen screen)
 {
     return((int)(screen.ScreenManager.Font.MeasureString(Text).X *Scale));
 }
Esempio n. 20
0
 /// <summary>
 /// Queries how much space this menu entry requires.
 /// </summary>
 public abstract int GetHeight(MenuScreen screen);
Esempio n. 21
0
        /// <summary>
        /// Updates the menu entry.
        /// </summary>
        public virtual void Update(MenuScreen screen, bool isSelected,
                                                      GameTime gameTime)
        {
            // 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. 22
0
 /// <summary>
 /// Queries how wide the entry is, used for centering on the screen.
 /// </summary>
 public abstract int GetWidth(MenuScreen screen);
Esempio n. 23
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

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

            // Pulsate the size of the selected menu entry.
            double time = gameTime.TotalGameTime.TotalSeconds;
            
            float pulsate = (float)Math.Sin(time * 6) + 1;

            float scale = 1 + pulsate * 0.05f * selectionFade;

            // 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;
            SpriteFont font = screenManager.Font;

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

            spriteBatch.DrawString(font, text, position, color, 0,
                                   origin, scale, SpriteEffects.None, 0);
        }
Esempio n. 24
0
 public override int GetWidth(MenuScreen screen)
 {
     return(TextureBack.Width + Spacing + (int)screen.ScreenManager.Font.MeasureString(Text).X);
 }
Esempio n. 25
0
 /// <summary>
 /// Queries how wide the entry is, used for centering on the screen.
 /// </summary>
 public virtual int GetWidth(MenuScreen screen)
 {
     return (int)screen.ScreenManager.Font.MeasureString(Text).X;
 }
Esempio n. 26
0
 public override int GetHeight(MenuScreen screen)
 {
     return(Math.Max(TextureBack.Height, screen.ScreenManager.Font.LineSpacing));
 }
Esempio n. 27
0
 public override void Update(MenuScreen menu, Microsoft.Xna.Framework.GameTime gameTime)
 {
 }
 public override int GetHeight(MenuScreen screen)
 {
     //return picture.Height;
     return (int)(Convert.ToInt32(ProgramSettings.ResolutionHeight) / 4);
 }