Example #1
0
        /// <summary>Render the UI.</summary>
        /// <param name="spriteBatch">The sprite batch being drawn.</param>
        public override void draw(SpriteBatch spriteBatch)
        {
            // disable when game is using immediate sprite sorting
            if (!this.ValidatedDrawMode)
            {
                IReflectedField <SpriteSortMode> sortModeField =
                    this.Reflection.GetField <SpriteSortMode>(Game1.spriteBatch, "spriteSortMode", required: false) // XNA
                    ?? this.Reflection.GetField <SpriteSortMode>(Game1.spriteBatch, "_sortMode");                   // MonoGame
                if (sortModeField.GetValue() == SpriteSortMode.Immediate)
                {
                    this.Monitor.Log("Aborted the weather draw because the game's current rendering mode isn't compatible with the mod's UI. This only happens in rare cases (e.g. the Stardew Valley Fair).", LogLevel.Warn);
                    this.exitThisMenu(playSound: false);
                    return;
                }
                this.ValidatedDrawMode = true;
            }

            // calculate dimensions
            int       x             = this.xPositionOnScreen;
            int       y             = this.yPositionOnScreen;
            const int gutter        = 15;
            float     leftOffset    = gutter;
            float     topOffset     = gutter;
            float     contentWidth  = this.width - gutter * 2;
            float     contentHeight = this.height - gutter * 2;
            //int tableBorderWidth = 1;

            // get font
            SpriteFont font       = Game1.smallFont;
            float      lineHeight = font.MeasureString("ABC").Y;

            //at this point I'm going to manually put this in as I don't need in many places,
            // and I kinda want to have this where I can understand what it's for
            float spaceWidth = DrawHelper.GetSpaceWidth(font);


            // draw background
            // (This uses a separate sprite batch because it needs to be drawn before the
            // foreground batch, and we can't use the foreground batch because the background is
            // outside the clipping area.)
            //spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, null, null);
            spriteBatch.DrawSprite(Sprites.Letter.Sheet, Sprites.Letter.Sprite, x, y, scale: width / (float)Sprites.Letter.Sprite.Width);
            //spriteBatch.End();

            // begin draw

            // draw weather icon
            spriteBatch.Draw(IconSheet.WeatherSource, new Vector2(x + leftOffset, y + topOffset), IconSheet.GetWeatherSprite(CurrentWeather.GetCurrentConditions()), Color.White);
            leftOffset += 72;
            string weatherString = "";

            // draw text as sent from outside the menu
            float wrapWidth = this.width - leftOffset - gutter;

            {
                Vector2 textSize = spriteBatch.DrawTextBlock(font, MenuText, new Vector2(x + leftOffset, y + topOffset), wrapWidth);
                topOffset += textSize.Y;
                topOffset += lineHeight;
            }

            //draw moon info
            spriteBatch.Draw(IconSheet.MoonSource, new Vector2(x + 15, y + topOffset),
                             IconSheet.GetMoonSprite(OurMoon.CurrentPhase), Color.White);

            weatherString = Helper.Get("moon-desc.desc_moonphase",
                                       new { moonPhase = SDVMoon.DescribeMoonPhase(OurMoon.CurrentPhase, Helper) });

            Vector2 moonText = spriteBatch.DrawTextBlock(font,
                                                         weatherString, new Vector2(x + leftOffset, y + topOffset), wrapWidth);

            topOffset += lineHeight; //stop moon from being cut off.

            this.drawMouse(Game1.spriteBatch);
        }
Example #2
0
        /// <summary>Render the UI.</summary>
        /// <param name="spriteBatch">The sprite batch being drawn.</param>
        public override void draw(SpriteBatch spriteBatch)
        {
            // disable when game is using immediate sprite sorting
            if (!ValidatedDrawMode)
            {
                IReflectedField <SpriteSortMode> sortModeField =
                    ClimatesOfFerngill.Reflection.GetField <SpriteSortMode>(Game1.spriteBatch, "spriteSortMode", required: false) // XNA
                    ?? ClimatesOfFerngill.Reflection.GetField <SpriteSortMode>(Game1.spriteBatch, "_sortMode");                   // MonoGame
                if (sortModeField.GetValue() == SpriteSortMode.Immediate)
                {
                    ClimatesOfFerngill.Logger.Log("Aborted the weather draw because the game's current rendering mode isn't compatible with the mod's UI. This only happens in rare cases (e.g. the Stardew Valley Fair).", LogLevel.Warn);
                    exitThisMenu(playSound: false);
                    return;
                }
                ValidatedDrawMode = true;
            }

            // calculate dimensions
            int       x             = xPositionOnScreen;
            int       y             = yPositionOnScreen;
            const int gutter        = 15;
            float     leftOffset    = gutter;
            float     topOffset     = gutter;
            float     contentWidth  = width - gutter * 2;
            float     contentHeight = height - gutter * 2;

            // get font
            SpriteFont font       = Game1.smallFont;
            float      lineHeight = font.MeasureString("ABC").Y;

            //at this point I'm going to manually put this in as I don't need in many places,
            // and I kinda want to have this where I can understand what it's for
            float spaceWidth = DrawHelper.GetSpaceWidth(font);

            // draw background
            // (This uses a separate sprite batch because it needs to be drawn before the
            // foreground batch, and we can't use the foreground batch because the background is
            // outside the clipping area.)
            spriteBatch.DrawSprite(Sprites.Letter.Sheet, Sprites.Letter.Sprite, x, y, scale: width / (float)Sprites.Letter.Sprite.Width);

            // begin draw

            // draw weather icon
            spriteBatch.Draw(IconSheet.WeatherSource, new Vector2(x + leftOffset, y + topOffset), IconSheet.GetWeatherSprite(CurrentWeather.GetCurrentConditions()), Color.White);
            leftOffset += 72;

            // draw text as sent from outside the menu
            float wrapWidth = width - leftOffset - gutter;

            {
                Vector2 textSize = spriteBatch.DrawTextBlock(font, MenuText, new Vector2(x + leftOffset, y + topOffset), wrapWidth);
                topOffset += textSize.Y + lineHeight;
            }

            drawMouse(Game1.spriteBatch);
        }