public override void Draw(MenuScreen screen, GameTime gameTime) { if (IsVisible) { // Draw the selected entry in teal, otherwise white. Color color = IsSelected ? Color.Teal : Color.White; // Draw text, centered on the middle of each line. var spriteBatch = Game.Services.GetService<SpriteBatch>(); spriteBatch.Begin(); if ((Font != null) && !String.IsNullOrEmpty(Text)) { spriteBatch.DrawString(Font, Text, Position, color, 0, Vector2.Zero, _currentScale, SpriteEffects.None, 0); } spriteBatch.End(); } }
/// <summary> /// Updates the menu entry. /// </summary> public virtual void Update(MenuScreen screen, GameTime gameTime) { }
public virtual bool IsClicked(MenuScreen host) { Point size; if (Texture != null) { size = new Point(Texture.Width, Texture.Height); } else { var measuredSize = Font.MeasureString(Text); size = new Point((int)measuredSize.X, (int)measuredSize.Y); } // the hit bounds are the entire width of the screen, and the height of the entry // with some additional padding above and below. var rect = new Rectangle( (int)Position.X, (int)Position.Y, size.X + 2, size.Y + 2); return InputManager.IsButtonClicked(rect); }
/// <summary> /// Draws the menu entry. This can be overridden to customize the appearance. /// </summary> public virtual void Draw(MenuScreen screen, GameTime gameTime) { // Draw the selected entry in teal, otherwise white. //Color color = isSelected ? Color.Teal : Color.White; var color = Color.White; // Draw text, centered on the middle of each line. ScreenManager screenManager = screen.ScreenManager; SpriteBatch spriteBatch = screenManager.SpriteBatch; if (Texture != null) { spriteBatch.Draw(Texture, Position, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); if ((Font != null) && !String.IsNullOrEmpty(Text)) { Vector2 textSize = Font.MeasureString(Text); Vector2 textPosition = Position + new Vector2( (float)Math.Floor((Texture.Width - textSize.X) / 2), (float)Math.Floor((Texture.Height - textSize.Y) / 2)); spriteBatch.DrawString(Font, Text, textPosition, color); } } else if ((Font != null) && !String.IsNullOrEmpty(Text)) { spriteBatch.DrawString(Font, Text, Position, color); } }
public virtual void Update(MenuScreen screen, GameTime gameTime) { _isSelected = _menuEntry.EntryArea.Contains(InputManager.CurrentMouseState.X, InputManager.CurrentMouseState.Y) && !IsDisabled; _menuEntry.Position = new Vector2(ThumbnailRenderRectangle.X, ThumbnailRenderRectangle.Y + ThumbnailRenderRectangle.Height + 5); _menuEntry.EntryArea = new Rectangle((int) Position.X, (int) Position.Y, Texture.Width, (int) (Texture.Height + _menuEntry.Font.MeasureString(_menuEntry.Text).Y + TextOffset.Y)); _menuEntry.Update(screen, gameTime); }
public bool IsClicked(MenuScreen host) { return InputManager.IsButtonClicked(ThumbnailRenderRectangle) || _menuEntry.IsClicked(host); }
public void Initialize(Game game, MenuScreen host) { _menuEntry.Initialize(game); var gameState = game.Services.GetService<GameState>(); StoryEntry = gameState.GameStory.GetStoryEntry(LevelName); if (gameState.GameStory.IsLevelAvailable(StoryEntry)) { Selected += (o, e) => InformativeLoadingScreen.Load(host.ScreenManager, true, TestData.BuildLevelScreen(game, StoryEntry.GetLevel)); } else { IsDisabled = true; _menuEntry.IsDisabled = true; } Border = game.Content.Load<Texture2D>(@"Textures\Borders\Border1"); }
public void Draw(MenuScreen screen, GameTime gameTime) { SpriteBatch spriteBatch = screen.ScreenManager.SpriteBatch; if (Texture != null) { spriteBatch.Draw(Texture, ThumbnailRenderRectangle, IsDisabled ? _disabledTintColor : Color.White); } if (Border != null) { spriteBatch.Draw(Border, new Rectangle(_thumbnailRenderRectangle.X - 4, _thumbnailRenderRectangle.Y - 4, _thumbnailRenderRectangle.Width + 8, _thumbnailRenderRectangle.Height + 8), null, Color.White); } _menuEntry.Draw(screen, gameTime); }
public override void Update(MenuScreen screen, GameTime gameTime) { IsSelected = EntryArea.Contains(InputManager.CurrentMouseState.X, InputManager.CurrentMouseState.Y) && !IsDisabled; float direction = IsSelected ? 1 : -1; _currentScale += direction * _scaleDelta * (float)gameTime.ElapsedGameTime.TotalMilliseconds; _currentScale = _currentScale > MaxScale ? MaxScale : _currentScale < DefaultScale ? DefaultScale : _currentScale; }
public void Initialize(Game game, MenuScreen host) { _game = game; _host = host; int count = 0; var currentThumbnailY = (int)Position.Y; while (count < Thumbnails.Count) { var currentThumbnailX = (int)Position.X; for (int i = 0; i < ColumnsCount; i++ ) { var thumbnail = Thumbnails[count]; thumbnail.Initialize(game, host); thumbnail.ThumbnailRenderRectangle = new Rectangle(currentThumbnailX, currentThumbnailY, ThumbnailWidth, ThumbnailHeight); count++; if (count >= Thumbnails.Count) { break; } currentThumbnailX += ThumbnailWidth + 40; } currentThumbnailY += ThumbnailHeight + 50; } }