/// <summary> /// Returns a screen position of a given world position as if projected onto the overlay map. /// </summary> /// <param name="worldArea"></param> /// <returns>A tuple indicating the screen-relative position and whether the point is within the screen /// boundaries.</returns> public static (Vector2 ScreenPosition, bool IsOnScreen) GetOverlayMapPositionAsScreenPosition(Rectangle worldArea) //Main.mapStyle == 2 { float mapScale = Main.mapOverlayScale; //var scrSize = UILibraries.GetScreenSize(); var scrSize = UIZoomLibraries.GetScreenSize(null, false); float offscrLitX = 10f * mapScale; float offscrLitY = 10f * mapScale; float scrWrldPosMidX = (Main.screenPosition.X + (float)(Main.screenWidth / 2)) / 16f; float scrWrldPosMidY = (Main.screenPosition.Y + (float)(Main.screenHeight / 2)) / 16f; scrWrldPosMidX *= mapScale; scrWrldPosMidY *= mapScale; float mapX = -scrWrldPosMidX + (float)(Main.screenWidth / 2); float mapY = -scrWrldPosMidY + (float)(Main.screenHeight / 2); float originMidX = (worldArea.X / 16f) * mapScale; float originMidY = (worldArea.Y / 16f) * mapScale; originMidX += mapX; originMidY += mapY; var scrPos = new Vector2(originMidX, originMidY); bool isOnscreen = originMidX >= 0 && originMidY >= 0 && originMidX < scrSize.Item1 && originMidY < scrSize.Item2; return(scrPos, isOnscreen); }
/// <summary> /// Draws a given projectile /// </summary> /// <param name="sb"></param> /// <param name="proj"></param> /// <param name="pos"></param> /// <param name="rot"></param> /// <param name="color"></param> /// <param name="scale"></param> /// <param name="applyZoom">Whether to convert to current zoom amount of the screen.</param> public static void DrawSimple(SpriteBatch sb, Projectile proj, Vector2 pos, float rot, Color color, float scale, bool applyZoom = false) { Texture2D tex = Main.projectileTexture[proj.type]; int texHeight = tex.Height / Main.projFrames[proj.type]; var rect = new Rectangle(0, proj.frame * texHeight, tex.Width, texHeight); var origin = new Vector2(tex.Width * 0.5f, (float)texHeight * 0.5f); SpriteEffects dir = SpriteEffects.None; if (proj.spriteDirection == -1) { dir = SpriteEffects.FlipHorizontally; } if (proj.type == 681 && (double)proj.velocity.X > 0.0) { dir ^= SpriteEffects.FlipHorizontally; } Vector2 newpos; if (applyZoom) { //newpos = UILibraries.ConvertToScreenPosition( pos ); newpos = UIZoomLibraries.ApplyZoomFromScreenCenter(pos - Main.screenPosition, null, false, null, null); } else { newpos = pos - Main.screenPosition; } sb.Draw(tex, newpos, rect, color, rot, origin, scale, dir, 1); }
//// /// <summary> /// Gets all buff icon rectangles by buff index. /// </summary> /// <param name="applyGameZoom">Factors game zoom into position calculations.</param> /// <returns></returns> public static IDictionary <int, Rectangle> GetVanillaBuffIconRectanglesByPosition(bool applyGameZoom) { var rects = new Dictionary <int, Rectangle>(); var player = Main.LocalPlayer; int dim = 32; Vector2 screenOffset = Vector2.Zero; if (applyGameZoom) { //var worldFrame = UILibraries.GetWorldFrameOfScreen(); var worldFrame = UIZoomLibraries.GetWorldFrameOfScreen(null, false); screenOffset.X = worldFrame.X - Main.screenPosition.X; screenOffset.Y = worldFrame.Y - Main.screenPosition.Y; } //if( scaleType == InterfaceScaleType.UI ) { //if( scaleType == InterfaceScaleType.Game ) { if (applyGameZoom) { dim = (int)(((float)dim * Main.UIScale) / Main.GameZoomTarget); } for (int i = 0; i < player.buffType.Length; i++) { if (player.buffType[i] <= 0) { continue; } int x = 32 + ((i % 11) * 38); int y = 76 + (50 * (i / 11)); //if( scaleType == InterfaceScaleType.UI ) { //if( scaleType == InterfaceScaleType.Game ) { if (applyGameZoom) { x = (int)((((float)x * Main.UIScale) / Main.GameZoomTarget) + screenOffset.X); y = (int)((((float)y * Main.UIScale) / Main.GameZoomTarget) + screenOffset.Y); } rects[i] = new Rectangle(x, y, dim, dim); } return(rects); }
/// <summary> /// Draws an NPC. /// </summary> /// <param name="sb">SpriteBatch to draw to. Typically `Main.spriteBatch`.</param> /// <param name="npc">NPC to draw.</param> /// <param name="frame">Frame of the NPC's animation to draw.</param> /// <param name="position"></param> /// <param name="rotation"></param> /// <param name="scale"></param> /// <param name="color"></param> /// <param name="applyZoom">Whether to convert to current zoom amount or draw it directly.</param> public static void DrawSimple( SpriteBatch sb, NPC npc, int frame, Vector2 position, float rotation, float scale, Color color, bool applyZoom = false) { Texture2D tex = Main.npcTexture[npc.type]; int frameCount = Main.npcFrameCount[npc.type]; int texHeight = tex.Height / frameCount; Rectangle frameRect = new Rectangle(0, frame * texHeight, tex.Width, texHeight); float yOffset = 0.0f; float heightOffset = Main.NPCAddHeight(npc.whoAmI); Vector2 origin = new Vector2((float)(tex.Width / 2), (float)((tex.Height / frameCount) / 2)); if (npc.type == NPCID.Wizard || npc.type == NPCID.Mechanic) { yOffset = 2f; } else if (npc.type == NPCID.Worm) { yOffset = npc.localAI[0]; } else if (npc.type == NPCID.DeadlySphere) { yOffset = 7f; } else if (npc.type == NPCID.SandSlime) { yOffset = 2f; } else if (npc.type == NPCID.FlyingAntlion) { yOffset = -6f; } else if (npc.type == NPCID.Drippler) { yOffset = 4f; } else if (npc.type == NPCID.EnchantedNightcrawler) { yOffset = 2f; } else if (npc.type == NPCID.GraniteFlyer) { yOffset = 14f; } else if (npc.type == NPCID.Mothron) { heightOffset = 22f; } else if (npc.type == NPCID.MothronEgg) { yOffset -= 2f; } else if (npc.type == NPCID.ThePossessed && (double)npc.ai[2] == 1.0) { yOffset = 14f; } else if (npc.type == NPCID.EyeofCthulhu) { origin = new Vector2(55f, 107f); } else if (npc.type == NPCID.Retinazer) { origin = new Vector2(55f, 107f); } else if (npc.type == NPCID.Spazmatism) { origin = new Vector2(55f, 107f); } else if (npc.type == NPCID.BlueJellyfish || npc.type == NPCID.PinkJellyfish || npc.type == NPCID.GreenJellyfish) { origin.Y += 4f; } else if (npc.type == NPCID.Antlion) { origin.Y += 8f; } else if (npc.type == NPCID.Plantera) { origin.Y = 77f; heightOffset += 26f; } else if (npc.type == NPCID.PlanterasTentacle) { origin.Y = 21f; heightOffset += 2f; } else if (npc.type == NPCID.BrainofCthulhu) { heightOffset += 50f; } else if (npc.type == NPCID.IchorSticker) { heightOffset += 16f; } else if (npc.type == NPCID.DungeonSpirit) { heightOffset += 6f; } //if( npc.aiStyle == 10 || npc.type == 72 ) // color1 = Color.White; SpriteEffects fx = SpriteEffects.None; if (npc.spriteDirection == 1) { fx = SpriteEffects.FlipHorizontally; } float yOff = heightOffset + yOffset + npc.gfxOffY + 4f; float x = position.X + ((float)npc.width / 2f) - (((float)tex.Width * scale) / 2f) + (origin.X * scale); float y = position.Y + (float)npc.height - ((float)texHeight * scale) + (origin.Y * scale) + yOff; Vector2 pos = new Vector2(x, y) - Main.screenPosition; if (applyZoom) { //pos = UILibraries.ConvertToScreenPosition( pos ); pos = UIZoomLibraries.ApplyZoomFromScreenCenter(pos, null, false, null, null); } sb.Draw(tex, pos, frameRect, color, rotation, origin, scale, fx, 1f); }