コード例 #1
0
        /// <summary>Draw the correct texture for machines that are ready for harvest and displaying their results.</summary>
        /// <remarks>We can't just set <see cref="SObject.readyForHarvest"/> to be false during the draw call and draw the
        /// tool tip ourselves because draw calls getScale, which actually modifies the object scale based upon <see cref="SObject.readyForHarvest"/>.</remarks>
        public static bool Prefix(SObject __instance, SpriteBatch spriteBatch, int x, int y, float alpha = 1f)
        {
            if (!__instance.readyForHarvest.Value || !__instance.bigCraftable.Value || __instance.heldObject.Value == null ||
                !ArtisanGoodsManager.GetDrawInfo(__instance.heldObject.Value, out Texture2D spriteSheet, out Rectangle position, out Rectangle iconPosition))
            {
                return(true);
            }
            Vector2 vector2 = __instance.getScale() * (float)Game1.pixelZoom;
            Vector2 local   = Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), (float)(y * Game1.tileSize - Game1.tileSize)));

            Microsoft.Xna.Framework.Rectangle destinationRectangle = new Microsoft.Xna.Framework.Rectangle((int)((double)local.X - (double)vector2.X / 2.0) + (__instance.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0), (int)((double)local.Y - (double)vector2.Y / 2.0) + (__instance.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0), (int)((double)Game1.tileSize + (double)vector2.X), (int)((double)(Game1.tileSize * 2) + (double)vector2.Y / 2.0));
            spriteBatch.Draw(Game1.bigCraftableSpriteSheet, destinationRectangle, new Microsoft.Xna.Framework.Rectangle?(SObject.getSourceRectForBigCraftable(__instance.showNextIndex.Value ? __instance.ParentSheetIndex + 1 : __instance.ParentSheetIndex)), Color.White * alpha, 0.0f, Vector2.Zero, SpriteEffects.None, (float)((double)Math.Max(0.0f, (float)((y + 1) * Game1.tileSize - Game1.pixelZoom * 6) / 10000f) + (__instance.ParentSheetIndex == 105 ? 0.00350000010803342 : 0.0) + (double)x * 9.99999974737875E-06));
            if (__instance.Name.Equals("Loom") && __instance.MinutesUntilReady > 0)
            {
                spriteBatch.Draw(Game1.objectSpriteSheet, __instance.getLocalPosition(Game1.viewport) + new Vector2((float)(Game1.tileSize / 2f), 0.0f), new Microsoft.Xna.Framework.Rectangle?(Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, 435, 16, 16)), Color.White * alpha, __instance.scale.X, new Vector2(8f, 8f), (float)Game1.pixelZoom, SpriteEffects.None, Math.Max(0.0f, (float)((double)((y + 1) * Game1.tileSize) / 10000.0 + 9.99999974737875E-05 + (double)x * 9.99999974737875E-06)));
            }
            if (__instance.isLamp.Value && Game1.isDarkOut())
            {
                spriteBatch.Draw(Game1.mouseCursors, local + new Vector2((float)(-Game1.tileSize / 2f), (float)(-Game1.tileSize / 2f)), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(88, 1779, 32, 32)), Color.White * 0.75f, 0.0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, Math.Max(0.0f, (float)((y + 1) * Game1.tileSize - Game1.pixelZoom * 5) / 10000f));
            }
            if (__instance.ParentSheetIndex == 126 && __instance.Quality != 0)
            {
                spriteBatch.Draw(FarmerRenderer.hatsTexture, local + new Vector2(-3f, -6f) * (float)Game1.pixelZoom, new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle((__instance.Quality - 1) * 20 % FarmerRenderer.hatsTexture.Width, (__instance.Quality - 1) * 20 / FarmerRenderer.hatsTexture.Width * 20 * 4, 20, 20)), Color.White * alpha, 0.0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, Math.Max(0.0f, (float)((y + 1) * Game1.tileSize - Game1.pixelZoom * 5) / 10000f) + (float)x * 1E-05f);
            }

            float num = (float)(4.0 * Math.Round(Math.Sin(DateTime.Now.TimeOfDay.TotalMilliseconds / 250.0), 2));

            spriteBatch.Draw(Game1.mouseCursors, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize - 8), (float)(y * Game1.tileSize - Game1.tileSize * 3 / 2 - 16) + num)), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(141, 465, 20, 24)), Color.White * 0.75f, 0.0f, Vector2.Zero, 4f, SpriteEffects.None, (float)((double)((y + 1) * Game1.tileSize) / 10000.0 + 9.99999997475243E-07 + (double)__instance.TileLocation.X / 10000.0 + (__instance.ParentSheetIndex == 105 ? 0.00150000001303852 : 0.0)));
            spriteBatch.Draw(spriteSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize + Game1.tileSize / 2), (float)(y * Game1.tileSize - Game1.tileSize - Game1.tileSize / 8) + num)), new Microsoft.Xna.Framework.Rectangle?(position), Color.White * 0.75f, 0.0f, new Vector2(8f, 8f), (float)Game1.pixelZoom, SpriteEffects.None, (float)((double)((y + 1) * Game1.tileSize) / 10000.0 + 9.99999974737875E-06 + (double)__instance.TileLocation.X / 10000.0 + (__instance.ParentSheetIndex == 105 ? 0.00150000001303852 : 0.0)));
            return(false);
        }
コード例 #2
0
        /// <summary>The method to call before <see cref="SObject.draw(SpriteBatch,int,int,float,float)"/>.</summary>
        private static bool Before_Draw1(SObject __instance, SpriteBatch spriteBatch, int xNonTile, int yNonTile, float layerDepth, float alpha)
        {
            if (!__instance.bigCraftable.Value)
            {
                return(true);
            }
            var entry = Mod.Entries.SingleOrDefault(cle => cle.Name == __instance.Name);

            if (entry == null)
            {
                return(true);
            }
            int hdiff = entry.Texture.Height - entry.Length * 16;

            if (__instance.GetBiggerIndex() == 0)
            {
                if (__instance.isTemporarilyInvisible)
                {
                    return(false);
                }

                Vector2 scaleFactor = __instance.getScale();
                scaleFactor *= 4f;
                Vector2 pos = Game1.GlobalToLocal(Game1.viewport, new Vector2(xNonTile, yNonTile));
                spriteBatch.Draw(entry.Texture, pos - new Vector2(0, hdiff * 4 * 2) + scaleFactor / 2f + (__instance.shakeTimer > 0 ? new Vector2(Game1.random.Next(-1, 2), Game1.random.Next(-1, 2)) : Vector2.Zero), null, Color.White * alpha, 0, Vector2.Zero, 4, SpriteEffects.None, layerDepth);
            }
            return(false);
        }
コード例 #3
0
        /// <summary>The method to call before <see cref="SObject.draw(SpriteBatch,int,int,float)"/>.</summary>
        private static bool Before_Draw2(SObject __instance, SpriteBatch spriteBatch, int x, int y, float alpha)
        {
            if (!__instance.bigCraftable.Value)
            {
                return(true);
            }
            var entry = Mod.Entries.SingleOrDefault(cle => cle.Name == __instance.Name);

            if (entry == null)
            {
                return(true);
            }
            int hdiff = entry.Texture.Height;

            if (__instance.GetBiggerIndex() == 0)
            {
                if (__instance.isTemporarilyInvisible)
                {
                    return(false);
                }

                Vector2 scaleFactor = __instance.getScale();
                scaleFactor *= 4f;
                Vector2 pos       = Game1.GlobalToLocal(Game1.viewport, new Vector2(x * 64, y * 64));
                float   drawLayer = Math.Max(0f, ((y + 1) * 64 - 24) / 10000f) + x * 1E-05f;
                spriteBatch.Draw(entry.Texture, pos - new Vector2(0, hdiff * 4 - 64) + scaleFactor / 2f + (__instance.shakeTimer > 0 ? new Vector2(Game1.random.Next(-1, 2), Game1.random.Next(-1, 2)) : Vector2.Zero), null, Color.White * alpha, 0, Vector2.Zero, 4, SpriteEffects.None, drawLayer);
            }
            return(false);
        }
コード例 #4
0
 private void RenderedWorld(object sender, RenderedWorldEventArgs e)
 {
     if (TrackedMachines.ContainsKey(Game1.currentLocation))
     {
         foreach (Vector2 tile in TrackedMachines[Game1.currentLocation])
         {
             Object obj = Game1.currentLocation.getObjectAtTile((int) tile.X, (int) tile.Y);
             Color color = determineColor(obj);
             if (color != Color.White)
             {
                 float alpha = Math.Min(Math.Max(config.AlphaValue, 0), 1);
                 int x = (int) tile.X;
                 int y = (int) tile.Y;
                 Vector2 vector2 = obj.getScale() * 4f;
                 Vector2 local = Game1.GlobalToLocal(Game1.viewport,
                     new Vector2(x * 64, y * 64 - 64));
                 Rectangle destinationRectangle = new Rectangle(
                     (int) (local.X - vector2.X / 2.0) + (obj.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0),
                     (int) (local.Y - vector2.Y / 2.0) + (obj.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0),
                     (int) (64.0 + vector2.X), (int) (128.0 + vector2.Y / 2.0));
                 e.SpriteBatch.Draw(Game1.bigCraftableSpriteSheet, destinationRectangle,
                     new Rectangle?(Object.getSourceRectForBigCraftable(obj.showNextIndex.Value
                         ? obj.ParentSheetIndex + 1
                         : obj.ParentSheetIndex)), color * alpha, 0.0f, Vector2.Zero, SpriteEffects.None,
                     (float) (Math.Max(0.0f, ((y + 1) * 64 - 24) / 10000f) +
                              (obj.ParentSheetIndex == 105 ? 0.00350000010803342 : 0.0) +
                              x * 9.99999974737875E-06));
             }
         }
     }
 }
コード例 #5
0
 public static Vector2 getScale(Object __instance)
 {
     if (ProducerController.GetProducerConfig(__instance.Name) is ProducerConfig producerConfig && __instance.MinutesUntilReady > 0 && __instance.heldObject.Value != null)
     {
         if (producerConfig.DisableBouncingAnimationWhileWorking)
         {
             return(Vector2.Zero);
         }
         else if (!producerConfig.CheckLocationCondition(Game1.currentLocation))
         {
             return(Vector2.Zero);
         }
         else if (!producerConfig.CheckSeasonCondition())
         {
             return(Vector2.Zero);
         }
         else if (!producerConfig.CheckWeatherCondition())
         {
             return(Vector2.Zero);
         }
         else if (!producerConfig.CheckCurrentTimeCondition())
         {
             return(Vector2.Zero);
         }
     }
     return(__instance.getScale());
 }
コード例 #6
0
        /// <summary>
        /// Patch for drawing a custom sprite (if available) for the object.
        /// </summary>
        /// <returns>If original method should be executed.</returns>
        /// <param name="__instance">Object to be drawn.</param>
        /// <param name="spriteBatch">Sprite batch to draw onto.</param>
        /// <param name="xNonTile">X non-tile coordinate.</param>
        /// <param name="yNonTile">Y non-tile coordinate.</param>
        /// <param name="layerDepth">Layer depth.</param>
        /// <param name="alpha">Transparency.</param>
        public static bool Prefix(SObject __instance, SpriteBatch spriteBatch, int xNonTile, int yNonTile, float layerDepth, float alpha = 1f)
        {
            if (!SpriteLoader.TryLoadSprite(__instance, out Texture2D texture, out Rectangle sourceRect))
            {
                return(true);
            }

            if (Game1.eventUp && Game1.CurrentEvent.isTileWalkedOn(xNonTile / 64, yNonTile / 64))
            {
                return(false);
            }

            if (__instance.Fragility != 2)
            {
                Texture2D shadowTexture = Game1.shadowTexture;
                spriteBatch.Draw(
                    texture: shadowTexture,
                    position: Game1.GlobalToLocal(
                        viewport: Game1.viewport,
                        globalPosition: new Vector2(xNonTile + 32, yNonTile + 51 + 4)
                        ),
                    sourceRectangle: shadowTexture.Bounds,
                    color: Color.White * alpha,
                    rotation: 0f,
                    origin: new Vector2(shadowTexture.Bounds.Center.X, shadowTexture.Bounds.Center.Y),
                    scale: 4f,
                    effects: SpriteEffects.None,
                    layerDepth: layerDepth - 1E-06f
                    );
            }

            spriteBatch.Draw(
                texture: texture,
                position: Game1.GlobalToLocal(
                    viewport: Game1.viewport,
                    globalPosition: new Vector2(
                        xNonTile + 32 + ((__instance.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0),
                        yNonTile + 32 + ((__instance.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0)
                        )
                    ),
                sourceRectangle: sourceRect,
                color: Color.White * alpha,
                rotation: 0f,
                origin: new Vector2(8f, 8f),
                scale: (__instance.Scale.Y > 1f) ? __instance.getScale().Y : 4f,
                effects: __instance.Flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None,
                layerDepth: layerDepth
                );

            return(false);
        }
コード例 #7
0
ファイル: ModEntry.cs プロジェクト: quizyy/StardewValleyMods
        public static void Object_draw_Postfix(Object __instance, SpriteBatch spriteBatch, float layerDepth, int xNonTile, int yNonTile, float alpha)
        {
            if (!__instance.name.EndsWith("Pet Bowl") || !__instance.modData.ContainsKey("aedenthorn.PetBowl/Watered") || __instance.modData["aedenthorn.PetBowl/Watered"] != "true")
            {
                return;
            }
            Vector2 scaleFactor = __instance.getScale();

            scaleFactor *= 4f;
            Vector2   position    = Game1.GlobalToLocal(Game1.viewport, new Vector2((float)xNonTile, (float)yNonTile));
            Rectangle destination = new Rectangle((int)(position.X - scaleFactor.X / 2f) + ((__instance.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0), (int)(position.Y - scaleFactor.Y / 2f) + ((__instance.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0), (int)(64f + scaleFactor.X), (int)(128f + scaleFactor.Y / 2f));

            spriteBatch.Draw(waterTexture, destination, new Rectangle(0, 0, 16, 32), Color.White * alpha, 0f, Vector2.Zero, SpriteEffects.None, layerDepth + 0.00001f);
        }
コード例 #8
0
 private void Display_RenderedWorld(object sender, RenderedWorldEventArgs e)
 {
     if (!Config.EnableMod)
     {
         return;
     }
     if (heldPiece != null)
     {
         Vector2   scaleFactor = heldPiece.getScale();
         Vector2   position    = Game1.getMousePosition().ToVector2() - new Vector2(32, 92);
         Rectangle destination = new Rectangle((int)(position.X - scaleFactor.X / 2f) + ((heldPiece.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0), (int)(position.Y - scaleFactor.Y / 2f) + ((heldPiece.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0), (int)(64f + scaleFactor.X), (int)(128f + scaleFactor.Y / 2f));
         float     draw_layer  = 1;
         e.SpriteBatch.Draw(piecesSheet, destination, GetSourceRectForPiece(heldPiece.modData[pieceKey]), Color.White * Config.HeldPieceOpacity, 0f, Vector2.Zero, SpriteEffects.None, draw_layer);
     }
 }
コード例 #9
0
            public static bool Prefix(Object __instance, SpriteBatch spriteBatch, int x, int y, float alpha)
            {
                if (!Config.EnableMod || !__instance.modData.TryGetValue(pieceKey, out string piece))
                {
                    return(true);
                }
                if (!drawingPieces)
                {
                    return(false);
                }
                if (Config.WalkThrough)
                {
                    __instance.isTemporarilyInvisible = true;
                }
                if (heldPiece is not null && __instance == heldPiece)
                {
                    return(false);
                }
                Vector2 scaleFactor = __instance.getScale();
                Vector2 tilePosition;
                var     f          = __instance.modData[squareKey];
                Point   square     = new Point(int.Parse(__instance.modData[squareKey].Substring(0, 1)), int.Parse(__instance.modData[squareKey].Substring(2, 1)));
                Vector2 cornerTile = new Vector2(x - square.X + 1, y + square.Y - 1);

                if (Game1.currentLocation.terrainFeatures[cornerTile].modData.ContainsKey(flippedKey))
                {
                    tilePosition = GetFlippedTile(cornerTile, square) * 64 - new Vector2(0, 64);
                }
                else
                {
                    tilePosition = new Vector2(x * 64, y * 64 - 64);
                }
                Vector2   position    = Game1.GlobalToLocal(Game1.viewport, tilePosition);
                Rectangle destination = new Rectangle((int)(position.X - scaleFactor.X / 2f) + ((__instance.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0), (int)(position.Y - scaleFactor.Y / 2f) + ((__instance.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0), (int)(64f + scaleFactor.X), (int)(128f + scaleFactor.Y / 2f));

                float draw_layer = Math.Max(0f, (float)((tilePosition.Y / 64 + 1) * 64 + 40) / 10000f) + (float)tilePosition.X / 64 * 1E-05f;

                spriteBatch.Draw(piecesSheet, destination, GetSourceRectForPiece(piece), Color.White * alpha, 0f, Vector2.Zero, SpriteEffects.None, draw_layer);
                return(false);
            }
コード例 #10
0
        private static void Draw(SObject instance, SpriteBatch spriteBatch, int x, int y, float alpha, Texture2D spriteSheet, Rectangle position)
        {
            if (instance.isTemporarilyInvisible)
            {
                return;
            }
            if ((bool)(instance.bigCraftable))
            {
                Vector2 vector2 = instance.getScale() * 4f;
                Vector2 local   = Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * 64), (float)(y * 64 - 64)));
                Microsoft.Xna.Framework.Rectangle destinationRectangle = new Microsoft.Xna.Framework.Rectangle((int)((double)local.X - (double)vector2.X / 2.0) + (instance.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0), (int)((double)local.Y - (double)vector2.Y / 2.0) + (instance.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0), (int)(64.0 + (double)vector2.X), (int)(128.0 + (double)vector2.Y / 2.0));
                float layerDepth = Math.Max(0.0f, (float)((y + 1) * 64 - 24) / 10000f) + (float)x * 1E-05f;
                if (instance.ParentSheetIndex == 105)
                {
                    layerDepth = Math.Max(0.0f, (float)((y + 1) * 64 + 2) / 10000f) + (float)x / 1000000f;
                }
                spriteBatch.Draw(Game1.bigCraftableSpriteSheet, destinationRectangle, new Microsoft.Xna.Framework.Rectangle?(SObject.getSourceRectForBigCraftable((bool)(instance.showNextIndex) ? instance.ParentSheetIndex + 1 : instance.ParentSheetIndex)), Color.White * alpha, 0.0f, Vector2.Zero, SpriteEffects.None, layerDepth);
                if (instance.Name.Equals("Loom") && (int)(instance.minutesUntilReady) > 0)
                {
                    spriteBatch.Draw(Game1.objectSpriteSheet, instance.getLocalPosition(Game1.viewport) + new Vector2(32f, 0.0f), new Microsoft.Xna.Framework.Rectangle?(Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, 435, 16, 16)), Color.White * alpha, instance.scale.X, new Vector2(8f, 8f), 4f, SpriteEffects.None, Math.Max(0.0f, (float)((double)((y + 1) * 64) / 10000.0 + 9.99999974737875E-05 + (double)x * 9.99999974737875E-06)));
                }
                if ((bool)(instance.isLamp) && Game1.isDarkOut())
                {
                    spriteBatch.Draw(Game1.mouseCursors, local + new Vector2(-32f, -32f), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(88, 1779, 32, 32)), Color.White * 0.75f, 0.0f, Vector2.Zero, 4f, SpriteEffects.None, Math.Max(0.0f, (float)((y + 1) * 64 - 20) / 10000f) + (float)x / 1000000f);
                }
                if ((int)(instance.parentSheetIndex) == 126 && (int)(instance.quality) != 0)
                {
                    spriteBatch.Draw(FarmerRenderer.hatsTexture, local + new Vector2(-3f, -6f) * 4f, new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(((int)(instance.quality) - 1) * 20 % FarmerRenderer.hatsTexture.Width, ((int)(instance.quality) - 1) * 20 / FarmerRenderer.hatsTexture.Width * 20 * 4, 20, 20)), Color.White * alpha, 0.0f, Vector2.Zero, 4f, SpriteEffects.None, Math.Max(0.0f, (float)((y + 1) * 64 - 20) / 10000f) + (float)x * 1E-05f);
                }
            }
            else if (!Game1.eventUp || Game1.CurrentEvent != null && !Game1.CurrentEvent.isTileWalkedOn(x, y))
            {
                if ((int)(instance.parentSheetIndex) == 590)
                {
                    SpriteBatch spriteBatch1 = spriteBatch;
                    Texture2D   mouseCursors = Game1.mouseCursors;
                    Vector2     local        = Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * 64 + 32 + (instance.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0)), (float)(y * 64 + 32 + (instance.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0))));
                    Microsoft.Xna.Framework.Rectangle?sourceRectangle = new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(368 + (Game1.currentGameTime.TotalGameTime.TotalMilliseconds % 1200.0 <= 400.0 ? (int)(Game1.currentGameTime.TotalGameTime.TotalMilliseconds % 400.0 / 100.0) * 16 : 0), 32, 16, 16));
                    Color   color  = Color.White * alpha;
                    Vector2 origin = new Vector2(8f, 8f);
                    Vector2 scale  = instance.scale;
                    double  num1   = (double)instance.scale.Y > 1.0 ? (double)instance.getScale().Y : 4.0;
                    int     num2   = (bool)(instance.flipped) ? 1 : 0;
                    double  num3   = (instance.isPassable() ? (double)instance.getBoundingBox(new Vector2((float)x, (float)y)).Top : (double)instance.getBoundingBox(new Vector2((float)x, (float)y)).Bottom) / 10000.0;
                    spriteBatch1.Draw(mouseCursors, local, sourceRectangle, color, 0.0f, origin, (float)num1, (SpriteEffects)num2, (float)num3);
                    return;
                }
                Microsoft.Xna.Framework.Rectangle rectangle;
                if ((int)(instance.fragility) != 2)
                {
                    SpriteBatch spriteBatch1  = spriteBatch;
                    Texture2D   shadowTexture = Game1.shadowTexture;
                    Vector2     local         = Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * 64 + 32), (float)(y * 64 + 51 + 4)));
                    Microsoft.Xna.Framework.Rectangle?sourceRectangle = new Microsoft.Xna.Framework.Rectangle?(Game1.shadowTexture.Bounds);
                    Color color = Color.White * alpha;
                    rectangle = Game1.shadowTexture.Bounds;
                    double x1 = (double)rectangle.Center.X;
                    rectangle = Game1.shadowTexture.Bounds;
                    double  y1     = (double)rectangle.Center.Y;
                    Vector2 origin = new Vector2((float)x1, (float)y1);
                    rectangle = instance.getBoundingBox(new Vector2((float)x, (float)y));
                    double num = (double)rectangle.Bottom / 15000.0;
                    spriteBatch1.Draw(shadowTexture, local, sourceRectangle, color, 0.0f, origin, 4f, SpriteEffects.None, (float)num);
                }
                SpriteBatch spriteBatch2      = spriteBatch;
                Texture2D   objectSpriteSheet = Game1.objectSpriteSheet;
                Vector2     local1            = Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * 64 + 32 + (instance.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0)), (float)(y * 64 + 32 + (instance.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0))));
                Microsoft.Xna.Framework.Rectangle?sourceRectangle1 = new Microsoft.Xna.Framework.Rectangle?(GameLocation.getSourceRectForObject(instance.ParentSheetIndex));
                Color   color1  = Color.White * alpha;
                Vector2 origin1 = new Vector2(8f, 8f);
                Vector2 scale1  = instance.scale;
                double  num4    = (double)instance.scale.Y > 1.0 ? (double)instance.getScale().Y : 4.0;
                int     num5    = (bool)(instance.flipped) ? 1 : 0;
                int     num6;
                if (!instance.isPassable())
                {
                    rectangle = instance.getBoundingBox(new Vector2((float)x, (float)y));
                    num6      = rectangle.Bottom;
                }
                else
                {
                    rectangle = instance.getBoundingBox(new Vector2((float)x, (float)y));
                    num6      = rectangle.Top;
                }
                double num7 = (double)num6 / 10000.0;
                spriteBatch2.Draw(spriteSheet, local1, position, color1, 0.0f, origin1, (float)num4, (SpriteEffects)num5, (float)num7);
            }
            if (!(bool)(instance.readyForHarvest))
            {
                return;
            }
            float num8 = (float)(4.0 * Math.Round(Math.Sin(DateTime.UtcNow.TimeOfDay.TotalMilliseconds / 250.0), 2));

            spriteBatch.Draw(Game1.mouseCursors, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * 64 - 8), (float)(y * 64 - 96 - 16) + num8)), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(141, 465, 20, 24)), Color.White * 0.75f, 0.0f, Vector2.Zero, 4f, SpriteEffects.None, (float)((double)((y + 1) * 64) / 10000.0 + 9.99999997475243E-07 + (double)instance.tileLocation.X / 10000.0 + ((int)(instance.parentSheetIndex) == 105 ? 0.00150000001303852 : 0.0)));
            if (instance.heldObject.Value == null)
            {
                return;
            }
            spriteBatch.Draw(spriteSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * 64 + 32), (float)(y * 64 - 64 - 8) + num8)), position, Color.White * 0.75f, 0.0f, new Vector2(8f, 8f), 4f, SpriteEffects.None, (float)((double)((y + 1) * 64) / 10000.0 + 9.99999974737875E-06 + (double)instance.tileLocation.X / 10000.0 + ((int)(instance.parentSheetIndex) == 105 ? 0.00150000001303852 : 0.0)));
            if (!(instance.heldObject.Value is ColoredObject))
            {
                return;
            }
            spriteBatch.Draw(spriteSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * 64 + 32), (float)(y * 64 - 64 - 8) + num8)), position, (instance.heldObject.Value as ColoredObject).color.Value * 0.75f, 0.0f, new Vector2(8f, 8f), 4f, SpriteEffects.None, (float)((double)((y + 1) * 64) / 10000.0 + 9.99999974737875E-06 + (double)instance.tileLocation.X / 10000.0 + ((int)(instance.parentSheetIndex) == 105 ? 0.00150000001303852 : 9.99999974737875E-06)));
        }
コード例 #11
0
    private static bool ObjectDrawOverloadPrefix(SObject __instance, SpriteBatch spriteBatch, int xNonTile, int yNonTile,
                                                 float layerDepth, float alpha = 1f)
    {
        if (__instance.isTemporarilyInvisible || Game1.eventUp && Game1.CurrentEvent.isTileWalkedOn(xNonTile / 64, yNonTile / 64))
        {
            return(false); // don't run original logic
        }
        if (__instance is not {
            ParentSheetIndex : Globals.MEAD_INDEX_I, preservedParentSheetIndex.Value : > 0
        } mead)
        {
            return(true);                                                                                                         // run original logic
        }
        var parameters = new object?[] { __instance, null, null, null };
        var got        = (bool)_GetDrawInfo.Invoke(null, parameters) !;

        if (!got)
        {
            return(true);      // run original logic
        }
        var spritesheet     = (Texture2D)parameters[1] !;
        var sourceRectangle = (Rectangle)parameters[2] !;

        if (__instance.Fragility != 2)
        {
            var shadowTexture = Game1.shadowTexture;
            spriteBatch.Draw(
                texture: shadowTexture,
                position: Game1.GlobalToLocal(
                    viewport: Game1.viewport,
                    globalPosition: new Vector2(xNonTile + 32, yNonTile + 51 + 4)
                    ),
                sourceRectangle: shadowTexture.Bounds,
                color: Color.White * alpha,
                rotation: 0f,
                origin: new(shadowTexture.Bounds.Center.X, shadowTexture.Bounds.Center.Y),
                scale: 4f,
                effects: SpriteEffects.None,
                layerDepth: layerDepth - 1E-06f
                );
        }

        spriteBatch.Draw(
            texture: spritesheet,
            position: Game1.GlobalToLocal(
                viewport: Game1.viewport,
                globalPosition: new Vector2(
                    xNonTile + 32 + (__instance.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0),
                    yNonTile + 32 + (__instance.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0)
                    )
                ),
            sourceRectangle: sourceRectangle,
            color: Color.White * alpha,
            rotation: 0f,
            origin: new Vector2(8f, 8f),
            scale: __instance.Scale.Y > 1f ? __instance.getScale().Y : 4f,
            effects: __instance.Flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None,
            layerDepth: layerDepth
            );

        return(false); // don't run original logic
    }
コード例 #12
0
    private static bool ObjectDrawPrefix(SObject __instance, SpriteBatch spriteBatch, int x, int y, float alpha = 1f)
    {
        if (__instance.isTemporarilyInvisible)
        {
            return(false);                                   // don't run original logic
        }
        if (!__instance.bigCraftable.Value || !__instance.readyForHarvest.Value || __instance.heldObject.Value is not
        {
            ParentSheetIndex : Globals.MEAD_INDEX_I, preservedParentSheetIndex.Value : > 0
        } mead)
        {
            return(true);                                                                                       // run original logic
        }
        var parameters = new object?[] { __instance, null, null, null };
        var got        = (bool)_GetDrawInfo.Invoke(null, parameters) !;

        if (!got)
        {
            return(true);      // run original logic
        }
        var spritesheet = (Texture2D)parameters[1] !;
        var position    = (Rectangle)parameters[2] !;

        var(sx, sy) = __instance.getScale() * Game1.pixelZoom;

        var(px, py) = Game1.GlobalToLocal(
            viewport: Game1.viewport,
            globalPosition: new Vector2(x * Game1.tileSize, y * Game1.tileSize - Game1.tileSize)
            );

        var destinationRect = new Rectangle(
            (int)(px - sx / 2f) + (__instance.shakeTimer > 0
                ? Game1.random.Next(-1, 2) : 0),
            (int)(py - sy / 2f) + (__instance.shakeTimer > 0
                ? Game1.random.Next(-1, 2) : 0),
            (int)(64f + sx),
            (int)(128f + sy / 2f)
            );

        spriteBatch.Draw(
            texture: Game1.bigCraftableSpriteSheet,
            destinationRectangle: destinationRect,
            sourceRectangle: SObject.getSourceRectForBigCraftable(__instance.showNextIndex.Value
                ? __instance.ParentSheetIndex + 1
                : __instance.ParentSheetIndex),
            color: Color.White * alpha,
            rotation: 0f,
            origin: Vector2.Zero,
            effects: SpriteEffects.None,
            layerDepth: Math.Max(0f, ((y + 1) * 64 - 24) / 10000f) + x * 1E-05f
            );

        var num = 4f * (float)Math.Round(Math.Sin(Game1.currentGameTime.TotalGameTime.TotalMilliseconds / 250.0), 2);

        spriteBatch.Draw(
            texture: Game1.mouseCursors,
            position: Game1.GlobalToLocal(
                viewport: Game1.viewport,
                globalPosition: new Vector2(
                    x * 64 - 8,
                    y * 64 - 96 - 16 + num
                    )
                ),
            sourceRectangle: new Rectangle(141, 465, 20, 24),
            color: Color.White * 0.75f,
            rotation: 0f,
            origin: Vector2.Zero,
            scale: 4f,
            effects: SpriteEffects.None,
            layerDepth: (float)((y + 1) * 64 / 10000f + 1E-06f + __instance.TileLocation.X / 10000f + 9.99999997475243E-07 + __instance.TileLocation.X / 10000.0)
            );

        spriteBatch.Draw(
            texture: spritesheet,
            position: Game1.GlobalToLocal(
                viewport: Game1.viewport,
                globalPosition: new Vector2(
                    x * 64 + 32,
                    y * 64 - 64 - 8 + num
                    )
                ),
            sourceRectangle: position,
            color: Color.White * 0.75f,
            rotation: 0f,
            origin: new Vector2(8f, 8f),
            scale: 4f,
            effects: SpriteEffects.None,
            layerDepth: (float)((y + 1) * 64 / 10000f + __instance.TileLocation.X / 10000f + 9.99999974737875E-06 + __instance.TileLocation.X / 10000.0)
            );

        return(false); // don't run original logic
    }
コード例 #13
0
        private static bool Object_draw_Prefix(Object __instance, SpriteBatch spriteBatch, int x, int y, float alpha)
        {
            if (!(Game1.currentLocation is MineShaft))
            {
                return(true);
            }


            if (rocks.Contains(__instance.parentSheetIndex) || treasures.Contains(__instance.parentSheetIndex))
            {
                if (!flippedObjects.ContainsKey(new Vector2(x, y)))
                {
                    flippedObjects[new Vector2(x, y)] = Game1.random.NextDouble() < 0.5;
                }

                bool flip = flippedObjects[new Vector2(x, y)];

                Vector2 origin = new Vector2(8f, 8f);
                GetTileInfo(Game1.currentLocation.objects, x, y, __instance.parentSheetIndex, flip, out int tileIndex);
                if (tileIndex == -1)
                {
                    return(true);
                }

                Rectangle sourceRect = new Rectangle(tileIndex * 16 % (sheetWidth * 16), tileIndex * 16 / (sheetWidth * 16) * 16, 16, 16);
                Vector2   position   = Game1.GlobalToLocal(Game1.viewport, new Vector2(x * 64 + 32 + ((__instance.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0), y * 64 + 32 + ((__instance.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0)));
                spriteBatch.Draw(tilesheet, position, sourceRect, Color.White, 0, origin, (__instance.scale.Y > 1f) ? __instance.getScale().Y : 4f, flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (__instance.isPassable() ? __instance.getBoundingBox(new Vector2(x, y)).Top : __instance.getBoundingBox(new Vector2(x, y)).Bottom) / 10000f);
                if (treasures.Contains(__instance.parentSheetIndex))
                {
                    Rectangle treasureRect = new Rectangle((treasures.IndexOf(__instance.parentSheetIndex) % sheetWidth) * 16, (10 + treasures.IndexOf(__instance.parentSheetIndex) / sheetWidth) * 16, 16, 16);
                    spriteBatch.Draw(tilesheet, position, treasureRect, Color.White, 0, origin, (__instance.scale.Y > 1f) ? __instance.getScale().Y : 4f, flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (__instance.isPassable() ? __instance.getBoundingBox(new Vector2(x, y)).Top : __instance.getBoundingBox(new Vector2(x, y)).Bottom) / 10000f + 0.001f);
                }

                return(false);
            }
            return(true);
        }
コード例 #14
0
        internal static bool DrawPrefix(Object __instance, SpriteBatch spriteBatch, int x, int y, float alpha = 1f)
        {
            if (__instance.modData.ContainsKey("AlternativeTextureName"))
            {
                var textureModel = AlternativeTextures.textureManager.GetSpecificTextureModel(__instance.modData["AlternativeTextureName"]);
                if (textureModel is null)
                {
                    return(true);
                }

                var textureVariation = Int32.Parse(__instance.modData["AlternativeTextureVariation"]);
                if (textureVariation == -1 || AlternativeTextures.modConfig.IsTextureVariationDisabled(textureModel.GetId(), textureVariation))
                {
                    return(true);
                }
                var textureOffset = textureModel.GetTextureOffset(textureVariation);

                // Get the current X index for the source tile
                var xTileOffset = __instance.modData.ContainsKey("AlternativeTextureSheetId") ? __instance.ParentSheetIndex - Int32.Parse(__instance.modData["AlternativeTextureSheetId"]) : 0;
                if (__instance.showNextIndex)
                {
                    xTileOffset += 1;
                }

                // Override xTileOffset if AlternativeTextureModel has an animation
                if (textureModel.HasAnimation(textureVariation))
                {
                    if (!__instance.modData.ContainsKey("AlternativeTextureCurrentFrame") || !__instance.modData.ContainsKey("AlternativeTextureFrameDuration") || !__instance.modData.ContainsKey("AlternativeTextureElapsedDuration"))
                    {
                        __instance.modData["AlternativeTextureCurrentFrame"]    = "0";
                        __instance.modData["AlternativeTextureFrameDuration"]   = textureModel.GetAnimationDataAtIndex(textureVariation, 0).Duration.ToString();
                        __instance.modData["AlternativeTextureElapsedDuration"] = "0";
                    }

                    var currentFrame    = Int32.Parse(__instance.modData["AlternativeTextureCurrentFrame"]);
                    var frameDuration   = Int32.Parse(__instance.modData["AlternativeTextureFrameDuration"]);
                    var elapsedDuration = Int32.Parse(__instance.modData["AlternativeTextureElapsedDuration"]);

                    if (elapsedDuration >= frameDuration)
                    {
                        currentFrame = currentFrame + 1 >= textureModel.GetAnimationData(textureVariation).Count() ? 0 : currentFrame + 1;

                        __instance.modData["AlternativeTextureCurrentFrame"]    = currentFrame.ToString();
                        __instance.modData["AlternativeTextureFrameDuration"]   = textureModel.GetAnimationDataAtIndex(textureVariation, currentFrame).Duration.ToString();
                        __instance.modData["AlternativeTextureElapsedDuration"] = "0";
                    }
                    else
                    {
                        __instance.modData["AlternativeTextureElapsedDuration"] = (elapsedDuration + Game1.currentGameTime.ElapsedGameTime.Milliseconds).ToString();
                    }

                    xTileOffset = currentFrame;
                }
                xTileOffset *= textureModel.TextureWidth;

                if (__instance.bigCraftable)
                {
                    // Get required draw values
                    Vector2   scaleFactor = __instance.getScale() * 4f;
                    Vector2   position    = Game1.GlobalToLocal(Game1.viewport, new Vector2(x * 64, y * 64 - 64));
                    Rectangle destination = new Rectangle((int)(position.X - scaleFactor.X / 2f) + ((__instance.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0), (int)(position.Y - scaleFactor.Y / 2f) + ((__instance.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0), (int)(64f + scaleFactor.X), (int)(128f + scaleFactor.Y / 2f));
                    float     draw_layer  = Math.Max(0f, (float)((y + 1) * 64 - 24) / 10000f) + (float)x * 1E-05f;

                    // Handle outliers for draw
                    if (__instance.ParentSheetIndex == 105 || __instance.ParentSheetIndex == 264)
                    {
                        draw_layer = Math.Max(0f, (float)((y + 1) * 64 + 2) / 10000f) + (float)x / 1000000f;
                    }
                    if (__instance.ParentSheetIndex == 272)
                    {
                        spriteBatch.Draw(textureModel.GetTexture(textureVariation), destination, new Rectangle(16, textureOffset, 16, 32), Color.White * alpha, 0f, Vector2.Zero, SpriteEffects.None, draw_layer);
                        spriteBatch.Draw(textureModel.GetTexture(textureVariation), position + new Vector2(8.5f, 12f) * 4f, new Rectangle(32, textureOffset, 16, 32), Color.White * alpha, (float)Game1.currentGameTime.TotalGameTime.TotalSeconds * -1.5f, new Vector2(7.5f, 15.5f), 4f, SpriteEffects.None, draw_layer + 1E-05f);
                        return(false);
                    }

                    // Perform base game draw logic
                    spriteBatch.Draw(textureModel.GetTexture(textureVariation), destination, new Rectangle(xTileOffset, textureOffset, textureModel.TextureWidth, textureModel.TextureHeight), Color.White * alpha, 0f, Vector2.Zero, SpriteEffects.None, draw_layer);

                    // Replicate the extra draw logic from the base game
                    if (__instance.Name.Equals("Loom") && (int)__instance.minutesUntilReady > 0)
                    {
                        spriteBatch.Draw(textureModel.GetTexture(textureVariation), __instance.getLocalPosition(Game1.viewport) + new Vector2(32f, 0f), new Rectangle(32, textureOffset, 16, 16), Color.White * alpha, __instance.scale.X, new Vector2(8f, 8f), 4f, SpriteEffects.None, Math.Max(0f, (float)((y + 1) * 64) / 10000f + 0.0001f + (float)x * 1E-05f));
                    }
                    if ((bool)__instance.isLamp && Game1.isDarkOut())
                    {
                        spriteBatch.Draw(Game1.mouseCursors, position + new Vector2(-32f, -32f), new Rectangle(88, 1779, 32, 32), Color.White * 0.75f, 0f, Vector2.Zero, 4f, SpriteEffects.None, Math.Max(0f, (float)((y + 1) * 64 - 20) / 10000f) + (float)x / 1000000f);
                    }
                    if ((int)__instance.parentSheetIndex == 126 && (int)__instance.quality != 0)
                    {
                        spriteBatch.Draw(FarmerRenderer.hatsTexture, position + new Vector2(-3f, -6f) * 4f, new Rectangle(((int)__instance.quality - 1) * 20 % FarmerRenderer.hatsTexture.Width, ((int)__instance.quality - 1) * 20 / FarmerRenderer.hatsTexture.Width * 20 * 4, 20, 20), Color.White * alpha, 0f, Vector2.Zero, 4f, SpriteEffects.None, Math.Max(0f, (float)((y + 1) * 64 - 20) / 10000f) + (float)x * 1E-05f);
                    }
                }
                else if (!Game1.eventUp || (Game1.CurrentEvent != null && !Game1.CurrentEvent.isTileWalkedOn(x, y)))
                {
                    if ((int)__instance.parentSheetIndex == 590)
                    {
                        Vector2 position2 = Game1.GlobalToLocal(Game1.viewport, new Vector2(x * 64 + 32 + ((__instance.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0), y * 64 + 32 + ((__instance.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0)));
                        Color   color     = Color.White * alpha;
                        Vector2 origin    = new Vector2(8f, 8f);

                        int artifactOffset = ((Game1.currentGameTime.TotalGameTime.TotalMilliseconds % 1200.0 <= 400.0) ? ((int)(Game1.currentGameTime.TotalGameTime.TotalMilliseconds % 400.0 / 100.0) * 16) : 0);
                        spriteBatch.Draw(textureModel.GetTexture(textureVariation), position2, new Rectangle(artifactOffset, textureOffset, 16, 16), color, 0f, origin, (__instance.scale.Y > 1f) ? __instance.getScale().Y : 4f, __instance.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (float)(__instance.isPassable() ? __instance.getBoundingBox(new Vector2(x, y)).Top : __instance.getBoundingBox(new Vector2(x, y)).Bottom) / 10000f);
                        return(false);
                    }
                    if ((int)__instance.fragility != 2)
                    {
                        spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2(x * 64 + 32, y * 64 + 51 + 4)), Game1.shadowTexture.Bounds, Color.White * alpha, 0f, new Vector2(Game1.shadowTexture.Bounds.Center.X, Game1.shadowTexture.Bounds.Center.Y), 4f, SpriteEffects.None, (float)__instance.getBoundingBox(new Vector2(x, y)).Bottom / 15000f);
                    }

                    Color   color2    = Color.White * alpha;
                    Vector2 origin2   = new Vector2(8f, 8f);
                    Vector2 position3 = Game1.GlobalToLocal(Game1.viewport, new Vector2(x * 64 + 32 + ((__instance.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0), y * 64 + 32 + ((__instance.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0)));
                    if (__instance.ParentSheetIndex == 746)
                    {
                        origin2   = Vector2.Zero;
                        position3 = Game1.GlobalToLocal(Game1.viewport, new Vector2(x * 64, y * 64 - 64));
                    }

                    spriteBatch.Draw(textureModel.GetTexture(textureVariation), position3, new Rectangle(xTileOffset, textureOffset, textureModel.TextureWidth, textureModel.TextureHeight), color2, 0f, origin2, (__instance.scale.Y > 1f) ? __instance.getScale().Y : 4f, __instance.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (float)(__instance.isPassable() ? __instance.getBoundingBox(new Vector2(x, y)).Top : __instance.getBoundingBox(new Vector2(x, y)).Bottom) / 10000f);
                    if (__instance.heldObject.Value != null && __instance.IsSprinkler())
                    {
                        // Unhandled sprinkler attachments
                        return(false);
                    }
                }

                // Check if product is ready to display (if applicable)
                if (!__instance.readyForHarvest)
                {
                    return(false);
                }
                float base_sort = (float)((y + 1) * 64) / 10000f + __instance.tileLocation.X / 50000f;
                if ((int)__instance.parentSheetIndex == 105 || (int)__instance.parentSheetIndex == 264)
                {
                    base_sort += 0.02f;
                }
                float yOffset = 4f * (float)Math.Round(Math.Sin(Game1.currentGameTime.TotalGameTime.TotalMilliseconds / 250.0), 2);
                spriteBatch.Draw(Game1.mouseCursors, Game1.GlobalToLocal(Game1.viewport, new Vector2(x * 64 - 8, (float)(y * 64 - 96 - 16) + yOffset)), new Microsoft.Xna.Framework.Rectangle(141, 465, 20, 24), Color.White * 0.75f, 0f, Vector2.Zero, 4f, SpriteEffects.None, base_sort + 1E-06f);
                if (__instance.heldObject.Value != null)
                {
                    spriteBatch.Draw(Game1.objectSpriteSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2(x * 64 + 32, (float)(y * 64 - 64 - 8) + yOffset)), Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, __instance.heldObject.Value.parentSheetIndex, 16, 16), Color.White * 0.75f, 0f, new Vector2(8f, 8f), 4f, SpriteEffects.None, base_sort + 1E-05f);
                    if (__instance.heldObject.Value is ColoredObject)
                    {
                        spriteBatch.Draw(Game1.objectSpriteSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2(x * 64 + 32, (float)(y * 64 - 64 - 8) + yOffset)), Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, (int)__instance.heldObject.Value.parentSheetIndex + 1, 16, 16), (__instance.heldObject.Value as ColoredObject).color.Value * 0.75f, 0f, new Vector2(8f, 8f), 4f, SpriteEffects.None, base_sort + 1.1E-05f);
                    }
                }

                return(false);
            }

            return(true);
        }
コード例 #15
0
        private static bool Object_draw_Prefix(Object __instance, SpriteBatch spriteBatch, int x, int y, float alpha = 1f)
        {
            CustomOreNode node = customOreNodesList.Find(n => n.parentSheetIndex == __instance.ParentSheetIndex);

            if (node == null)
            {
                return(true);
            }

            if (__instance.Fragility != 2)
            {
                spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2(x * 64 + 32, y * 64 + 51 + 4)), new Rectangle?(Game1.shadowTexture.Bounds), Color.White * alpha, 0f, new Vector2(Game1.shadowTexture.Bounds.Center.X, Game1.shadowTexture.Bounds.Center.Y), 4f, SpriteEffects.None, __instance.getBoundingBox(new Vector2(x, y)).Bottom / 15000f);
            }
            Vector2   position3        = Game1.GlobalToLocal(Game1.viewport, new Vector2(x * 64 + 32 + ((__instance.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0), y * 64 + 32 + ((__instance.shakeTimer > 0) ? Game1.random.Next(-1, 2) : 0)));
            Rectangle?sourceRectangle2 = new Rectangle(node.spriteX, node.spriteY, node.spriteW, node.spriteH);
            Color     color2           = Color.White * alpha;
            float     rotation2        = 0f;
            Vector2   origin2          = new Vector2(8f, 8f);
            Vector2   vector2          = __instance.scale;

            spriteBatch.Draw(node.texture, position3, sourceRectangle2, color2, rotation2, origin2, (__instance.scale.Y > 1f) ? __instance.getScale().Y : 4f, __instance.Flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (__instance.isPassable() ? __instance.getBoundingBox(new Vector2(x, y)).Top : __instance.getBoundingBox(new Vector2(x, y)).Bottom) / 10000f);
            return(false);
        }
コード例 #16
0
        /// <summary>
        /// Patch for drawing a custom sprite (if available) for the object held by the instance.
        /// </summary>
        /// <param name="__instance">Object to be drawn.</param>
        /// <param name="spriteBatch">Sprite batch to draw onto.</param>
        /// <param name="x">The x tile coordinate.</param>
        /// <param name="y">The y tile coordinate.</param>
        /// <param name="alpha">Transparency.</param>
        public static bool Prefix(SObject __instance, SpriteBatch spriteBatch, int x, int y, float alpha = 1f)
        {
            if (
                !(bool)__instance.bigCraftable.Value ||
                !(bool)__instance.readyForHarvest.Value ||
                __instance.heldObject.Value == null ||
                !SpriteLoader.TryLoadSprite(__instance.heldObject.Value, out Texture2D texture, out Rectangle sourceRect)
                )
            {
                return(true);
            }

            Vector2 value = 4 * __instance.getScale();

            Vector2 vector = Game1.GlobalToLocal(
                viewport: Game1.viewport,
                globalPosition: new Vector2(x * 64, y * 64 - 64)
                );

            Rectangle destinationRectangle = new Rectangle(
                (int)(vector.X - value.X / 2f) + ((__instance.shakeTimer > 0)
                    ? Game1.random.Next(-1, 2) : 0),
                (int)(vector.Y - value.Y / 2f) + ((__instance.shakeTimer > 0)
                    ? Game1.random.Next(-1, 2) : 0),
                (int)(64f + value.X),
                (int)(128f + value.Y / 2f)
                );

            spriteBatch.Draw(
                texture: Game1.bigCraftableSpriteSheet,
                destinationRectangle: destinationRectangle,
                sourceRectangle: SObject.getSourceRectForBigCraftable(__instance.showNextIndex.Value
                    ? (__instance.ParentSheetIndex + 1) : __instance.ParentSheetIndex),
                color: Color.White * alpha,
                rotation: 0f,
                origin: Vector2.Zero,
                effects: SpriteEffects.None,
                layerDepth: Math.Max(0f, ((y + 1) * 64 - 24) / 10000f) + (__instance.ParentSheetIndex == 105 ? 0.0035f : 0f) + x * 1E-05f
                );

            if (__instance.Name.Equals("Loom") && __instance.MinutesUntilReady > 0)
            {
                spriteBatch.Draw(
                    texture: Game1.objectSpriteSheet,
                    position: __instance.getLocalPosition(Game1.viewport) + new Vector2(32f, 0f),
                    sourceRectangle: Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, 435, 16, 16),
                    color: Color.White * alpha,
                    rotation: __instance.Scale.X,
                    origin: new Vector2(8f, 8f),
                    scale: 4f,
                    effects: SpriteEffects.None,
                    layerDepth: Math.Max(0f, (y + 1) * 64 / 10000f + 0.0001f + x * 1E-05f)
                    );
            }

            if (__instance.isLamp.Value && Game1.isDarkOut())
            {
                spriteBatch.Draw(
                    texture: Game1.mouseCursors,
                    position: vector + new Vector2(-32f, -32f),
                    sourceRectangle: new Rectangle(88, 1779, 32, 32),
                    color: Color.White * 0.75f,
                    rotation: 0f,
                    origin: Vector2.Zero,
                    scale: 4f,
                    effects: SpriteEffects.None,
                    layerDepth: Math.Max(0f, ((y + 1) * 64 - 20) / 10000f)
                    );
            }

            if (__instance.ParentSheetIndex == 126 && __instance.Quality != 0)
            {
                spriteBatch.Draw(
                    texture: FarmerRenderer.hatsTexture,
                    position: vector + new Vector2(-3f, -6f) * 4f,
                    sourceRectangle: new Rectangle(
                        (__instance.Quality - 1) * 20 % FarmerRenderer.hatsTexture.Width,
                        (__instance.Quality - 1) * 20 / FarmerRenderer.hatsTexture.Width * 20 * 4,
                        20,
                        20
                        ),
                    color: Color.White * alpha,
                    rotation: 0f,
                    origin: Vector2.Zero,
                    scale: 4f,
                    effects: SpriteEffects.None,
                    layerDepth: Math.Max(0f, ((y + 1) * 64 - 20) / 10000f) + x * 1E-05f
                    );
            }

            TimeSpan timeSpan = DateTime.UtcNow.TimeOfDay;
            float    num6     = 4f * (float)Math.Round(Math.Sin(timeSpan.TotalMilliseconds / 250.0), 2);

            spriteBatch.Draw(
                texture: Game1.mouseCursors,
                position: Game1.GlobalToLocal(
                    viewport: Game1.viewport,
                    globalPosition: new Vector2(
                        x * 64 - 8,
                        y * 64 - 96 - 16 + num6
                        )
                    ),
                sourceRectangle: new Rectangle(141, 465, 20, 24),
                color: Color.White * 0.75f,
                rotation: 0f,
                origin: Vector2.Zero,
                scale: 4f,
                effects: SpriteEffects.None,
                layerDepth: (y + 1) * 64 / 10000f + 1E-06f + __instance.TileLocation.X / 10000f
                + ((__instance.ParentSheetIndex == 105) ? 0.0015f : 0f)
                );

            spriteBatch.Draw(
                texture: texture,
                position: Game1.GlobalToLocal(
                    viewport: Game1.viewport,
                    globalPosition: new Vector2(
                        x * 64 + 32,
                        y * 64 - 64 - 8 + num6
                        )
                    ),
                sourceRectangle: sourceRect,
                color: Color.White * 0.75f,
                rotation: 0f,
                origin: new Vector2(8f, 8f),
                scale: 4f,
                effects: SpriteEffects.None,
                layerDepth: (y + 1) * 64 / 10000f + 1E-05f + __instance.TileLocation.X / 10000f
                + ((__instance.ParentSheetIndex == 105) ? 0.0015f : 0f)
                );

            return(false);
        }