Пример #1
0
        public void Update(Game game)
        {
            if (Game.Input.MousePressed(MouseButton.Left))
            {
                if (LeftButtonRectangle.Contains(Game.Input.MousePosition))
                {
                    Choice--;
                    if (Choice < (Choices == null ? MinValue : 0))
                    {
                        Choice = Choices == null ? MaxValue : Choices.Length - 1;
                    }

                    if (ChoiceChanged != null)
                    {
                        ChoiceChanged(this, Choice, Choices == null ? Choice.ToString() : Choices[Choice]);
                    }
                }

                if (RightButtonRectangle.Contains(Game.Input.MousePosition))
                {
                    Choice++;
                    if (Choice > (Choices == null ? MaxValue : Choices.Length - 1))
                    {
                        Choice = Choices == null ? MinValue : 0;
                    }

                    if (ChoiceChanged != null)
                    {
                        ChoiceChanged(this, Choice, Choices == null ? Choice.ToString() : Choices[Choice]);
                    }
                }
            }
        }
Пример #2
0
        public void Draw(Game game)
        {
            bool        hovered = Rectangle.Contains(game.Input.MousePosition);
            SpriteBatch batch   = game.Batch;

            batch.Rectangle(Rectangle, Color.Black * 0.8f);

            if (Icon != null)
            {
                batch.Texture(new Vector2(Position.Value.X + 4, Position.Value.Y + 4), Icon, TextColor * 0.6f);
            }

            batch.Text(Font, 15,
                       Label,
                       new Vector2(Position.Value.X + (Icon != null ? Icon.Width + 8 : 8), Position.Value.Y + 6),
                       TextColor * 0.6f);

            batch.Texture(new Rectangle(LeftButtonRectangle.X + 4, LeftButtonRectangle.Y + 4, 24, 24),
                          Game.Assets.Get <Texture2D>("editor/arrow.png"),
                          Color.White * (LeftButtonRectangle.Contains(Game.Input.MousePosition) ? Game.Input.Mouse(MouseButton.Left) ? 1.0f : 0.8f : 0.6f),
                          null, 0, null, SpriteEffects.FlipHorizontally);
            batch.Texture(new Rectangle(RightButtonRectangle.X + 4, RightButtonRectangle.Y + 4, 24, 24),
                          Game.Assets.Get <Texture2D>("editor/arrow.png"),
                          Color.White * (RightButtonRectangle.Contains(Game.Input.MousePosition) ? Game.Input.Mouse(MouseButton.Left) ? 1.0f : 0.8f : 0.6f));

            Vector2 measure = Font.Measure(13, Choices == null ? Choice.ToString() : Choices[Choice]);
            int     width   = RightButtonRectangle.X - (LeftButtonRectangle.X + LeftButtonRectangle.Width);

            width -= 8;
            Rectangle rect = new Rectangle(LeftButtonRectangle.X + LeftButtonRectangle.Width + 4, LeftButtonRectangle.Y, width, 32);

            batch.Text(Font, 13,
                       Choices == null ? Choice.ToString() : Choices[Choice],
                       new Vector2(rect.X + rect.Width / 2 - measure.X / 2, Position.Value.Y + 7),
                       TextColor * 0.6f);
        }