示例#1
0
        private void DrawMarkers()
        {
            var b           = Game1.spriteBatch;
            var color       = Color.White;
            var offsetMmX   = mmX + offset;
            var offsetMmLoc = new Vector2(mmLoc.X + offset + 2, mmLoc.Y + 2);

            //
            // ===== Farm types =====
            //
            // The farms are always overlayed at (0, 43) on the map
            // The crop position, dimensions, and overlay position must all be adjusted accordingly
            // When any part of the cropped farm is outside of the minimap as player moves
            var farmWidth  = 131;
            var farmHeight = 61;
            var farmX      = NormalizeToMap(MathHelper.Clamp(offsetMmLoc.X, offsetMmX, offsetMmX + mmWidth));
            var farmY      = NormalizeToMap(MathHelper.Clamp(offsetMmLoc.Y + 172, mmY, mmY + mmHeight) + 2);
            var farmCropX  = (int)MathHelper.Clamp((offsetMmX - offsetMmLoc.X) / Game1.pixelZoom, 0, farmWidth);
            var farmCropY  = (int)MathHelper.Clamp((mmY - offsetMmLoc.Y - 172) / Game1.pixelZoom, 0, farmHeight);

            // Check if farm crop extends outside of minimap
            var farmCropWidth  = (farmX / Game1.pixelZoom + farmWidth > (offsetMmX + mmWidth) / Game1.pixelZoom) ? (int)((offsetMmX + mmWidth - farmX) / Game1.pixelZoom) : farmWidth - farmCropX;
            var farmCropHeight = (farmY / Game1.pixelZoom + farmHeight > (mmY + mmHeight) / Game1.pixelZoom) ? (int)((mmY + mmHeight - farmY) / Game1.pixelZoom) : farmHeight - farmCropY;

            // Check if farm crop extends beyond farm size
            if (farmCropX + farmCropWidth > farmWidth)
            {
                farmCropWidth = farmWidth - farmCropX;
            }

            if (farmCropY + farmCropHeight > farmHeight)
            {
                farmCropHeight = farmHeight - farmCropY;
            }

            switch (Game1.whichFarm)
            {
            case 1:
                b.Draw(ModMain.Map, new Vector2(farmX, farmY),
                       new Rectangle(0 + farmCropX, 180 + farmCropY, farmCropWidth, farmCropHeight), color,
                       0f,
                       Vector2.Zero, 4f, SpriteEffects.None, 0.861f);
                break;

            case 2:
                b.Draw(ModMain.Map, new Vector2(farmX, farmY),
                       new Rectangle(131 + farmCropX, 180 + farmCropY, farmCropWidth, farmCropHeight), color,
                       0f,
                       Vector2.Zero, 4f, SpriteEffects.None, 0.861f);
                break;

            case 3:
                b.Draw(ModMain.Map, new Vector2(farmX, farmY),
                       new Rectangle(0 + farmCropX, 241 + farmCropY, farmCropWidth, farmCropHeight), color,
                       0f,
                       Vector2.Zero, 4f, SpriteEffects.None, 0.861f);
                break;

            case 4:
                b.Draw(ModMain.Map, new Vector2(farmX, farmY),
                       new Rectangle(131 + farmCropX, 241 + farmCropY, farmCropWidth, farmCropHeight), color,
                       0f,
                       Vector2.Zero, 4f, SpriteEffects.None, 0.861f);
                break;

            case 5:
                b.Draw(ModMain.Map, new Vector2(farmX, farmY),
                       new Rectangle(0 + farmCropX, 302 + farmCropY, farmCropWidth, farmCropHeight), color,
                       0f,
                       Vector2.Zero, 4f, SpriteEffects.None, 0.861f);
                break;
            }

            if (drawPamHouseUpgrade)
            {
                var houseLoc = ModMain.LocationToMap("Trailer_Big");
                if (IsWithinMapArea(houseLoc.X, houseLoc.Y))
                {
                    b.Draw(ModMain.Map, new Vector2(NormalizeToMap(offsetMmLoc.X + houseLoc.X - 16), NormalizeToMap(offsetMmLoc.Y + houseLoc.Y - 11)),
                           new Rectangle(263, 181, 8, 8), color,
                           0f, Vector2.Zero, 4f, SpriteEffects.None, 0.861f);
                }
            }

            if (drawMovieTheater || drawMovieTheaterJoja)
            {
                var theaterLoc = ModMain.LocationToMap("JojaMart");
                if (IsWithinMapArea(theaterLoc.X, theaterLoc.Y))
                {
                    b.Draw(ModMain.Map, new Vector2(NormalizeToMap(offsetMmLoc.X + theaterLoc.X - 20), NormalizeToMap(offsetMmLoc.Y + theaterLoc.Y - 11)),
                           new Rectangle(275, 181, 15, 11), color,
                           0f, Vector2.Zero, 4f, SpriteEffects.None, 0.861f);
                }
            }

            //
            // ===== Farm buildings =====
            //
            if (ModMain.Globals.ShowFarmBuildings && FarmBuildings != null && BuildingMarkers != null)
            {
                var sortedBuildings = FarmBuildings.ToList();
                sortedBuildings.Sort((x, y) => x.Value.Value.Y.CompareTo(y.Value.Value.Y));

                foreach (var building in sortedBuildings)
                {
                    if (ModConstants.FarmBuildingRects.TryGetValue(building.Value.Key, out var buildingRect))
                    {
                        if (IsWithinMapArea(building.Value.Value.X - buildingRect.Width / 2,
                                            building.Value.Value.Y - buildingRect.Height / 2))
                        {
                            //  if (Customizations.MapName == "starblue_map")
                            //   buildingRect.Y = 7;
                            //  else if (Customizations.MapName == "eemie_recolour_map")
                            //    buildingRect.Y = 14;

                            b.Draw(
                                BuildingMarkers,
                                new Vector2(
                                    NormalizeToMap(offsetMmLoc.X + building.Value.Value.X - (float)Math.Floor(buildingRect.Width / 2.0)),
                                    NormalizeToMap(offsetMmLoc.Y + building.Value.Value.Y - (float)Math.Floor(buildingRect.Height / 2.0))
                                    ),
                                buildingRect, color, 0f, Vector2.Zero, 3f, SpriteEffects.None, 1f
                                );
                        }
                    }
                }
            }

            //
            // ===== Traveling Merchant =====
            //
            if (ModMain.Config.ShowTravelingMerchant && ConditionalNpcs["Merchant"])
            {
                Vector2 merchantLoc = new Vector2(ModConstants.MapVectors["Merchant"][0].MapX, ModConstants.MapVectors["Merchant"][0].MapY);
                if (IsWithinMapArea(merchantLoc.X - 16, merchantLoc.Y - 16))
                {
                    b.Draw(Game1.mouseCursors, new Vector2(NormalizeToMap(offsetMmLoc.X + merchantLoc.X - 16), NormalizeToMap(offsetMmLoc.Y + merchantLoc.Y - 15)), new Rectangle(191, 1410, 22, 21), Color.White, 0f, Vector2.Zero, 1.3f, SpriteEffects.None,
                           1f);
                }
            }

            //
            // ===== NPCs =====
            //
            // Sort by drawing order
            if (NpcMarkers != null)
            {
                var sortedMarkers = NpcMarkers.ToList();
                sortedMarkers.Sort((x, y) => x.Value.Layer.CompareTo(y.Value.Layer));

                foreach (var npcMarker in sortedMarkers)
                {
                    var name   = npcMarker.Key;
                    var marker = npcMarker.Value;

                    // Skip if no specified location
                    if (marker.Sprite == null ||
                        !IsWithinMapArea(marker.MapX, marker.MapY) ||
                        ModMain.Globals.NpcBlacklist.Contains(name) ||
                        (!ModMain.Config.ShowHiddenVillagers && marker.IsHidden) ||
                        (ConditionalNpcs.ContainsKey(name) && !ConditionalNpcs[name])
                        )
                    {
                        continue;
                    }

                    var markerColor = marker.IsHidden ? Color.DarkGray * 0.7f : Color.White;

                    // Draw NPC marker
                    var spriteRect = marker.Type == Character.Horse ? new Rectangle(17, 104, 16, 14) : new Rectangle(0, marker.CropOffset, 16, 15);

                    if (marker.Type == Character.Horse)
                    {
                        b.Draw(marker.Sprite,
                               new Rectangle(NormalizeToMap(offsetMmLoc.X + marker.MapX),
                                             NormalizeToMap(offsetMmLoc.Y + marker.MapY),
                                             30, 32),
                               spriteRect, markerColor);
                    }
                    else
                    {
                        b.Draw(marker.Sprite,
                               new Rectangle(NormalizeToMap(offsetMmLoc.X + marker.MapX),
                                             NormalizeToMap(offsetMmLoc.Y + marker.MapY),
                                             30, 32),
                               spriteRect, markerColor);
                    }

                    // Icons for birthday/quest
                    if (ModMain.Config.MarkQuests)
                    {
                        if (marker.IsBirthday && (Game1.player.friendshipData.ContainsKey(name) && Game1.player.friendshipData[name].GiftsToday == 0))
                        {
                            b.Draw(Game1.mouseCursors,
                                   new Vector2(NormalizeToMap(offsetMmLoc.X + marker.MapX + 20),
                                               NormalizeToMap(offsetMmLoc.Y + marker.MapY)),
                                   new Rectangle(147, 412, 10, 11), markerColor, 0f, Vector2.Zero, 1.8f,
                                   SpriteEffects.None,
                                   0f);
                        }

                        if (marker.HasQuest)
                        {
                            b.Draw(Game1.mouseCursors,
                                   new Vector2(NormalizeToMap(offsetMmLoc.X + marker.MapX + 22),
                                               NormalizeToMap(offsetMmLoc.Y + marker.MapY - 3)),
                                   new Rectangle(403, 496, 5, 14), markerColor, 0f, Vector2.Zero, 1.8f, SpriteEffects.None,
                                   0f);
                        }
                    }
                }
            }

            if (Context.IsMultiplayer)
            {
                foreach (var farmer in Game1.getOnlineFarmers())
                {
                    // Temporary solution to handle desync of farmhand location/tile position when changing location
                    if (FarmerMarkers.TryGetValue(farmer.UniqueMultiplayerID, out var farMarker))
                    {
                        if (IsWithinMapArea(farMarker.MapX - 16, farMarker.MapY - 15) && farMarker.DrawDelay == 0)
                        {
                            farmer.FarmerRenderer.drawMiniPortrat(b,
                                                                  new Vector2(NormalizeToMap(offsetMmLoc.X + farMarker.MapX - 16),
                                                                              NormalizeToMap(offsetMmLoc.Y + farMarker.MapY - 15)),
                                                                  0.00011f, 2f, 1, farmer);
                        }
                    }
                }
            }
            else
            {
                Game1.player.FarmerRenderer.drawMiniPortrat(b,
                                                            new Vector2(NormalizeToMap(offsetMmLoc.X + playerLoc.X - 16), NormalizeToMap(offsetMmLoc.Y + playerLoc.Y - 15)), 0.00011f,
                                                            2f, 1,
                                                            Game1.player);
            }
        }
示例#2
0
        // Draw event
        // Subtractions within location vectors are to set the origin to the center of the sprite
        public void DrawMarkers(SpriteBatch b)
        {
            if (ModMain.Globals.ShowFarmBuildings && FarmBuildings != null && BuildingMarkers != null)
            {
                var sortedBuildings = FarmBuildings.ToList();
                sortedBuildings.Sort((x, y) => x.Value.Value.Y.CompareTo(y.Value.Value.Y));

                foreach (KeyValuePair <string, KeyValuePair <string, Vector2> > building in sortedBuildings)
                {
                    if (ModConstants.FarmBuildingRects.TryGetValue(building.Value.Key, out Rectangle buildingRect))
                    {
                        b.Draw(
                            BuildingMarkers,
                            new Vector2(
                                mapX + building.Value.Value.X - buildingRect.Width / 2,
                                mapY + building.Value.Value.Y - buildingRect.Height / 2
                                ),
                            new Rectangle?(buildingRect), Color.White, 0f, Vector2.Zero, 3f, SpriteEffects.None, 1f
                            );
                    }
                }
            }

            // Traveling Merchant
            if (ModMain.Config.ShowTravelingMerchant && ConditionalNpcs["Merchant"])
            {
                Vector2 merchantLoc = new Vector2(ModConstants.MapVectors["Merchant"][0].MapX, ModConstants.MapVectors["Merchant"][0].MapY);
                b.Draw(Game1.mouseCursors, new Vector2(mapX + merchantLoc.X - 16, mapY + merchantLoc.Y - 15),
                       new Rectangle?(new Rectangle(191, 1410, 22, 21)), Color.White, 0f, Vector2.Zero, 1.3f, SpriteEffects.None,
                       1f);
            }

            // NPCs
            // Sort by drawing order
            if (NpcMarkers != null)
            {
                var sortedMarkers = NpcMarkers.ToList();
                sortedMarkers.Sort((x, y) => x.Value.Layer.CompareTo(y.Value.Layer));

                foreach (var npcMarker in sortedMarkers)
                {
                    var name   = npcMarker.Key;
                    var marker = npcMarker.Value;

                    // Skip if no specified location or should be hidden
                    if (marker.Sprite == null ||
                        ModMain.Globals.NpcBlacklist.Contains(name) ||
                        (!ModMain.Config.ShowHiddenVillagers && marker.IsHidden) ||
                        (ConditionalNpcs.ContainsKey(name) && !ConditionalNpcs[name])
                        )
                    {
                        continue;
                    }

                    // Dim marker for hidden markers
                    var markerColor = marker.IsHidden ? Color.DarkGray * 0.7f : Color.White;

                    // Draw NPC marker
                    var spriteRect = marker.Type == Character.Horse ? new Rectangle(17, 104, 16, 14) : new Rectangle(0, marker.CropOffset, 16, 15);

                    b.Draw(marker.Sprite,
                           new Rectangle((int)(mapX + marker.MapX), (int)(mapY + marker.MapY),
                                         32, 30),
                           new Rectangle?(spriteRect), markerColor);

                    // Draw icons for quests/birthday
                    if (ModMain.Config.MarkQuests)
                    {
                        if (marker.IsBirthday && (Game1.player.friendshipData.ContainsKey(name) && Game1.player.friendshipData[name].GiftsToday == 0))
                        {
                            // Gift icon
                            b.Draw(Game1.mouseCursors,
                                   new Vector2(mapX + marker.MapX + 20, mapY + marker.MapY),
                                   new Rectangle?(new Rectangle(147, 412, 10, 11)), markerColor, 0f, Vector2.Zero, 1.8f,
                                   SpriteEffects.None, 0f);
                        }

                        if (marker.HasQuest)
                        {
                            // Quest icon
                            b.Draw(Game1.mouseCursors,
                                   new Vector2(mapX + marker.MapX + 22, mapY + marker.MapY - 3),
                                   new Rectangle?(new Rectangle(403, 496, 5, 14)), markerColor, 0f, Vector2.Zero, 1.8f,
                                   SpriteEffects.None, 0f);
                        }
                    }
                }
            }

            // Farmers
            if (Context.IsMultiplayer)
            {
                foreach (Farmer farmer in Game1.getOnlineFarmers())
                {
                    // Temporary solution to handle desync of farmhand location/tile position when changing location
                    if (FarmerMarkers.TryGetValue(farmer.UniqueMultiplayerID, out FarmerMarker farMarker))
                    {
                        if (farMarker == null)
                        {
                            continue;
                        }
                    }
                    if (farMarker != null && farMarker.DrawDelay == 0)
                    {
                        farmer.FarmerRenderer.drawMiniPortrat(b,
                                                              new Vector2(mapX + farMarker.MapX - 16, mapY + farMarker.MapY - 15),
                                                              0.00011f, 2f, 1, farmer);
                    }
                }
            }
            else
            {
                Vector2 playerLoc = ModMain.LocationToMap(Game1.player.currentLocation.uniqueName.Value ?? Game1.player.currentLocation.Name, Game1.player.getTileX(),
                                                          Game1.player.getTileY(), Customizations.MapVectors, Customizations.LocationBlacklist, true);

                Game1.player.FarmerRenderer.drawMiniPortrat(b,
                                                            new Vector2(mapX + playerLoc.X - 16, mapY + playerLoc.Y - 15), 0.00011f, 2f, 1,
                                                            Game1.player);
            }
        }