Пример #1
0
        /// <summary>Draw the value (or return <c>null</c> to render the <see cref="GenericField.Value"/> using the default format).</summary>
        /// <param name="spriteBatch">The sprite batch being drawn.</param>
        /// <param name="font">The recommended font.</param>
        /// <param name="position">The position at which to draw.</param>
        /// <param name="wrapWidth">The maximum width before which content should be wrapped.</param>
        /// <returns>Returns the drawn dimensions, or <c>null</c> to draw the <see cref="GenericField.Value"/> using the default format.</returns>
        public override Vector2?DrawValue(SpriteBatch spriteBatch, SpriteFont font, Vector2 position, float wrapWidth)
        {
            float height = 0;

            // draw preface
            if (!string.IsNullOrWhiteSpace(this.Preface))
            {
                Vector2 prefaceSize = spriteBatch.DrawTextBlock(font, this.Preface, position, wrapWidth);
                height += (int)prefaceSize.Y;
            }

            // calculate sizes
            float checkboxSize   = CommonSprites.Icons.FilledCheckbox.Width * (Game1.pixelZoom / 2);
            float lineHeight     = Math.Max(checkboxSize, Game1.smallFont.MeasureString("ABC").Y);
            float checkboxOffset = (lineHeight - checkboxSize) / 2;
            float outerIndent    = checkboxSize + 7;
            float innerIndent    = outerIndent * 2;

            // list drops
            Vector2 iconSize             = new Vector2(font.MeasureString("ABC").Y);
            int     lastGroup            = -1;
            bool    isPrevDropGuaranteed = false;

            foreach (FishPondDrop drop in this.Drops)
            {
                bool disabled = !drop.IsUnlocked || isPrevDropGuaranteed;

                // draw group checkbox + requirement
                if (lastGroup != drop.MinPopulation)
                {
                    lastGroup = drop.MinPopulation;

                    spriteBatch.Draw(
                        texture: CommonSprites.Icons.Sheet,
                        position: new Vector2(position.X + outerIndent, position.Y + height + checkboxOffset),
                        sourceRectangle: drop.IsUnlocked ? CommonSprites.Icons.FilledCheckbox : CommonSprites.Icons.EmptyCheckbox,
                        color: Color.White * (disabled ? 0.5f : 1f),
                        rotation: 0,
                        origin: Vector2.Zero,
                        scale: checkboxSize / CommonSprites.Icons.FilledCheckbox.Width,
                        effects: SpriteEffects.None,
                        layerDepth: 1f
                        );
                    Vector2 textSize = spriteBatch.DrawTextBlock(
                        font: Game1.smallFont,
                        text: I18n.Building_FishPond_Drops_MinFish(count: drop.MinPopulation),
                        position: new Vector2(position.X + outerIndent + checkboxSize + 7, position.Y + height),
                        wrapWidth: wrapWidth - checkboxSize - 7,
                        color: disabled ? Color.Gray : Color.Black
                        );

                    // cross out if it's guaranteed not to drop
                    if (isPrevDropGuaranteed)
                    {
                        spriteBatch.DrawLine(position.X + outerIndent + checkboxSize + 7, position.Y + height + iconSize.Y / 2, new Vector2(textSize.X, 1), Color.Gray);
                    }

                    height += Math.Max(checkboxSize, textSize.Y);
                }

                // draw drop
                bool isGuaranteed = drop.Probability > .99f;
                {
                    // draw icon
                    spriteBatch.DrawSpriteWithin(drop.Sprite, position.X + innerIndent, position.Y + height, iconSize, Color.White * (disabled ? 0.5f : 1f));

                    // draw text
                    string text = I18n.Generic_PercentChanceOf(percent: (int)(Math.Round(drop.Probability, 4) * 100), label: drop.SampleItem.DisplayName);
                    if (drop.MinDrop != drop.MaxDrop)
                    {
                        text += $" ({I18n.Generic_Range(min: drop.MinDrop, max: drop.MaxDrop)})";
                    }
                    else if (drop.MinDrop > 1)
                    {
                        text += $" ({drop.MinDrop})";
                    }
                    Vector2 textSize = spriteBatch.DrawTextBlock(font, text, position + new Vector2(innerIndent + iconSize.X + 5, height + 5), wrapWidth, disabled ? Color.Gray : Color.Black);

                    // cross out if it's guaranteed not to drop
                    if (isPrevDropGuaranteed)
                    {
                        spriteBatch.DrawLine(position.X + innerIndent + iconSize.X + 5, position.Y + height + iconSize.Y / 2, new Vector2(textSize.X, 1), Color.Gray);
                    }

                    height += textSize.Y + 5;
                }

                // stop if drop is guaranteed
                if (drop.IsUnlocked && isGuaranteed)
                {
                    isPrevDropGuaranteed = true;
                }
            }

            // return size
            return(new Vector2(wrapWidth, height));
        }