/// <summary> /// Draws the menu. /// </summary> public override void Draw(GameTime gameTime) { // make sure our entries are in the right place before we draw them UpdateMenuEntryLocations(); SpriteBatch.Begin(); // Draw each menu entry in turn. for (int i = 0; i < MenuItemList.Count; i++) { MenuItem menuEntry = MenuItemList[i]; bool isSelected = IsActive && (i == SelectedItem); menuEntry.Draw(this, isSelected, gameTime); } // Make the menu slide into place during transitions, using a // power curve to make things look more interesting (this makes // the movement slow down as it nears the end). float transitionOffset = (float)Math.Pow(TransitionPosition, 2); // Draw the menu title centered on the screen Vector2 titlePosition = new Vector2(ScreenManager.GraphicsDevice.Viewport.Width / 2, 80); Vector2 titleOrigin = MenuFont.MeasureString(Title) / 2; Color titleColor = new Color(255, 64, 64) * TransitionAlpha; float titleScale = 1.5f; titlePosition.Y -= transitionOffset * 100; SpriteBatch.DrawString(MenuFont, Title, titlePosition, titleColor, 0, titleOrigin, titleScale, SpriteEffects.None, 0); SpriteBatch.End(); }
// TODO: Only works if all menuitems have equal height private Vector2 CalculateMenuItemPosition(MenuItem menuItem, int numberInOrder) { Vector2 textSize = MenuFont.MeasureString(menuItem.Text); float posX = 0; switch (menuItem.MenuPositionX) { case ItemPositionX.LEFT: posX = 0; break; case ItemPositionX.CENTER: posX = (Bounds.Width / 2); break; case ItemPositionX.RIGHT: posX = (Bounds.Width) - textSize.X; break; } float posY = 0; switch (menuItem.MenuPositionY) { case ItemPositionY.TOP: posY = 0 + (numberInOrder * textSize.Y); break; case ItemPositionY.CENTER: posY = (Bounds.Height / 2) + (numberInOrder * textSize.Y); break; case ItemPositionY.BOTTOM: posY = (Bounds.Height) - (numberInOrder * textSize.Y); break; } return(new Vector2(posX, posY)); }
/// <summary> /// Draws the message box. /// </summary> public override void Draw(GameTime gameTime) { // Darken down any other screens that were drawn beneath the popup. ScreenManager.FadeBackBufferToBlack(TransitionAlpha * 2 / 3); // Center the message text in the viewport. Viewport viewport = ScreenManager.GraphicsDevice.Viewport; Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height); Vector2 textSize = MenuFont.MeasureString(Message); Vector2 textPosition = (viewportSize - textSize) / 2; // The background includes a border somewhat larger than the text itself. const int hPad = 32; const int vPad = 16; Rectangle backgroundRectangle = new Rectangle((int)textPosition.X - hPad, (int)textPosition.Y - vPad, (int)textSize.X + hPad * 2, (int)textSize.Y + vPad * 2); // Fade the popup alpha during transitions. Color color = Color.White * TransitionAlpha; SpriteBatch.Begin(); // Draw the background rectangle. if (GradientTexture != null) { SpriteBatch.Draw(GradientTexture, backgroundRectangle, color); } // Draw the message box text. SpriteBatch.DrawString(MenuFont, Message, textPosition, color); SpriteBatch.End(); }
/// <summary> /// Draws the loading screen. /// </summary> public override void Draw(GameTime gameTime) { // If we are the only active screen, that means all the previous screens // must have finished transitioning off. We check for this in the Draw // method, rather than in Update, because it isn't enough just for the // screens to be gone: in order for the transition to look good we must // have actually drawn a frame without them before we perform the load. if ((ScreenState == State.Active) && (ScreenManager.GetScreens().Length == 1)) { OtherScreensAreGone = true; } // The gameplay screen takes a while to load, so we display a loading // message while that is going on, but the menus load very quickly, and // it would look silly if we flashed this up for just a fraction of a // second while returning from the game to the menus. This parameter // tells us how long the loading is going to take, so we know whether // to bother drawing the message. if (LoadingIsSlow) { const string message = "Loading..."; // Center the text in the viewport. Viewport viewport = GraphicsDevice.Viewport; Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height); Vector2 textSize = MenuFont.MeasureString(message); Vector2 textPosition = (viewportSize - textSize) / 2; Color color = Color.White * TransitionAlpha; // Draw the text. SpriteBatch.Begin(); SpriteBatch.DrawString(MenuFont, message, textPosition, color); SpriteBatch.End(); } }