Пример #1
0
        public IntegerEditor(string text, int startingNumber, int minimum, int maximum, Vector2 location, ClickCallback onClickCallback)
        {
            if (maximum <= minimum)
            {
                throw new ArgumentException($"{nameof(minimum)} value cannot exceed {nameof(maximum)} value.");
            }
            _onClick = onClickCallback;
            Value    = startingNumber.Clamp(minimum, maximum);
            Minimum  = minimum;
            Maximum  = maximum;
            Text     = text;
            var buttonYOffset = (int)Math.Ceiling(Game1.smallFont.MeasureString(text).Y) + _linePadding;

            _minusButton = new TextureButton(new Rectangle((int)Math.Floor(location.X), (int)Math.Floor(location.Y) + buttonYOffset, PixelsWide * Game1.pixelZoom, PixelsHigh * Game1.pixelZoom), Game1.mouseCursors, OptionsPlusMinus.minusButtonSource, MinusButtonClicked);
            var plusButtonOffset = (int)Math.Ceiling(NumberSprite.getWidth(Maximum) * 1.5) + _minusButton.Bounds.Width * 4;

            _plusButton = new TextureButton(new Rectangle((int)Math.Floor(location.X) + plusButtonOffset, (int)Math.Floor(location.Y) + buttonYOffset, PixelsWide * Game1.pixelZoom, PixelsHigh * Game1.pixelZoom), Game1.mouseCursors, OptionsPlusMinus.plusButtonSource, PlusButtonClicked);
            var maxWidth = new[] { _plusButton.Bounds.X + _plusButton.Bounds.Width - (int)Math.Floor(location.X), (int)Math.Ceiling(Game1.smallFont.MeasureString(text).X) }.Max();
            var maxHeight = buttonYOffset + new[] { _minusButton.Bounds.Height, _plusButton.Bounds.Height, NumberSprite.getHeight() }.Max();

            Bounds = new Rectangle((int)Math.Floor(location.X), (int)Math.Floor(location.Y), maxWidth, maxHeight);
        }