Пример #1
0
        public void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            for (int i = 0; i < Options.Count; i++)
            {
                MenuOption option = Options[i];
                Rectangle  rect   = GetBounds(i);

                Color color = hoveredOption == option ? Color.White : Color.Gray;
                if (option.Text == null)
                {
                    spriteBatch.Draw(option.Texture, rect, Color.White);
                }
                else if (option.Texture == null)
                {
                    Vector2 textDim      = font.MeasureString(option.Text);
                    Vector2 textPosition = new Vector2(rect.X + (rect.Width / 2) - (textDim.X / 2), rect.Y + (rect.Height / 2) - (textDim.Y / 2));
                    spriteBatch.DrawString(font, option.Text, textPosition, color);
                    //if (option.Texture != null)
                    //{
                    //    Rectangle iconPosition = new Rectangle(rect.X - rect.Height - 10, (int)rect.Y + 5, rect.Height - 10, rect.Height - 10);
                    //    spriteBatch.Draw(option.Texture, iconPosition, Color.White);
                    //}
                }
                else
                {
                    Vector2   textDim      = font.MeasureString(option.Text);
                    Vector2   textPosition = new Vector2(rect.X + (rect.Width / 2) - (textDim.X / 2), rect.Y + (rect.Height / 2) - (textDim.Y / 2));
                    Rectangle iconPosition = new Rectangle(rect.X - rect.Height, (int)rect.Y + (20 / 2), rect.Height - 20, rect.Height - 20);
                    spriteBatch.DrawString(font, option.Text, textPosition, color);
                    spriteBatch.Draw(option.Texture, iconPosition, Color.White);
                }

                //spriteBatch.Draw(debugTexture, rect, color);
            }
        }
Пример #2
0
        public void Update(GameTime gameTime)
        {
            hoveredOption = null;

            for (int i = 0; i < Options.Count; i++)
            {
                Rectangle rect = GetBounds(i);
                if (rect.Contains(KeyMouseReader.MouseScreenPosition))
                {
                    hoveredOption = Options[i];
                    if (KeyMouseReader.LeftClick())
                    {
                        Options[i].Action();
                    }
                }
            }
        }