Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
LegacyMultiplayerClosePlayersOverlay.cs
Go to the documentation of this file.
1using System;
10
12
14{
15 public void Draw()
16 {
17 int teamNamePlateDistance = Main.teamNamePlateDistance;
18 if (teamNamePlateDistance <= 0)
19 {
20 return;
21 }
22 SpriteBatch spriteBatch = Main.spriteBatch;
23 spriteBatch.End();
24 spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, null, null, Main.UIScaleMatrix);
26 int screenWidth = Main.screenWidth;
27 int screenHeight = Main.screenHeight;
28 Vector2 screenPosition = Main.screenPosition;
30 float uIScale = Main.UIScale;
31 int num = teamNamePlateDistance * 8;
32 Player[] player = Main.player;
33 int myPlayer = Main.myPlayer;
34 SpriteViewMatrix gameViewMatrix = Main.GameViewMatrix;
35 byte mouseTextColor = Main.mouseTextColor;
36 Color[] teamColor = Main.teamColor;
37 Camera camera = Main.Camera;
38 IPlayerRenderer playerRenderer = Main.PlayerRenderer;
39 Vector2 screenPosition2 = Main.screenPosition;
40 for (int i = 0; i < 255; i++)
41 {
42 if (!player[i].active || myPlayer == i || player[i].dead || player[myPlayer].team <= 0 || player[myPlayer].team != player[i].team)
43 {
44 continue;
45 }
46 string name = player[i].name;
47 Vector2 namePlatePos = FontAssets.MouseText.Value.MeasureString(name);
48 float num2 = 0f;
49 if (player[i].chatOverhead.timeLeft > 0)
50 {
51 num2 = (0f - namePlatePos.Y) * uIScale;
52 }
53 else if (player[i].emoteTime > 0)
54 {
55 num2 = (0f - namePlatePos.Y) * uIScale;
56 }
57 Vector2 vector = new Vector2((float)(screenWidth / 2) + screenPosition.X, (float)(screenHeight / 2) + screenPosition.Y);
58 Vector2 position = player[i].position;
59 position += (position - vector) * (gameViewMatrix.Zoom - Vector2.One);
60 float num3 = 0f;
61 float num4 = (float)(int)mouseTextColor / 255f;
62 Color namePlateColor = new Color((byte)((float)(int)teamColor[player[i].team].R * num4), (byte)((float)(int)teamColor[player[i].team].G * num4), (byte)((float)(int)teamColor[player[i].team].B * num4), mouseTextColor);
63 float num5 = position.X + (float)(player[i].width / 2) - vector.X;
64 float num6 = position.Y - namePlatePos.Y - 2f + num2 - vector.Y;
65 float num7 = (float)Math.Sqrt(num5 * num5 + num6 * num6);
66 int num8 = screenHeight;
67 if (screenHeight > screenWidth)
68 {
69 num8 = screenWidth;
70 }
71 num8 = num8 / 2 - 50;
72 if (num8 < 100)
73 {
74 num8 = 100;
75 }
76 if (num7 < (float)num8)
77 {
78 namePlatePos.X = position.X + (float)(player[i].width / 2) - namePlatePos.X / 2f - screenPosition.X;
79 namePlatePos.Y = position.Y - namePlatePos.Y - 2f + num2 - screenPosition.Y;
80 }
81 else
82 {
83 num3 = num7;
84 num7 = (float)num8 / num7;
85 namePlatePos.X = (float)(screenWidth / 2) + num5 * num7 - namePlatePos.X / 2f;
86 namePlatePos.Y = (float)(screenHeight / 2) + num6 * num7 + 40f * uIScale;
87 }
88 Vector2 vector2 = FontAssets.MouseText.Value.MeasureString(name);
89 namePlatePos += vector2 / 2f;
90 namePlatePos *= 1f / uIScale;
91 namePlatePos -= vector2 / 2f;
92 if (player[myPlayer].gravDir == -1f)
93 {
94 namePlatePos.Y = (float)screenHeight - namePlatePos.Y;
95 }
96 if (num3 > 0f)
97 {
98 float num9 = 20f;
99 float num10 = -27f;
100 num10 -= (vector2.X - 85f) / 2f;
101 num5 = player[i].Center.X - player[myPlayer].Center.X;
102 num6 = player[i].Center.Y - player[myPlayer].Center.Y;
103 float num11 = (float)Math.Sqrt(num5 * num5 + num6 * num6);
104 if (!(num11 > (float)num))
105 {
106 string textValue = Language.GetTextValue("GameUI.PlayerDistance", (int)(num11 / 16f * 2f));
107 Vector2 npDistPos = FontAssets.MouseText.Value.MeasureString(textValue);
108 npDistPos.X = namePlatePos.X - num10;
109 npDistPos.Y = namePlatePos.Y + vector2.Y / 2f - npDistPos.Y / 2f - num9;
110 DrawPlayerName2(spriteBatch, ref namePlateColor, textValue, ref npDistPos);
111 Color playerHeadBordersColor = Main.GetPlayerHeadBordersColor(player[i]);
112 Vector2 position2 = new Vector2(namePlatePos.X, namePlatePos.Y - num9);
113 position2.X -= 22f + num10;
114 position2.Y += 8f;
115 playerRenderer.DrawPlayerHead(camera, player[i], position2, 1f, 0.8f, playerHeadBordersColor);
116 Vector2 vector3 = npDistPos + screenPosition2 + new Vector2(26f, 20f);
117 if (player[i].statLife != player[i].statLifeMax2)
118 {
119 Main.instance.DrawHealthBar(vector3.X, vector3.Y, player[i].statLife, player[i].statLifeMax2, 1f, 1.25f, noFlip: true);
120 }
121 ChatManager.DrawColorCodedStringWithShadow(spriteBatch, FontAssets.MouseText.Value, name, namePlatePos + new Vector2(0f, -40f), namePlateColor, 0f, Vector2.Zero, Vector2.One);
122 }
123 }
124 else
125 {
126 DrawPlayerName(spriteBatch, name, ref namePlatePos, ref namePlateColor);
127 }
128 }
129 }
130
131 private static void DrawPlayerName2(SpriteBatch spriteBatch, ref Color namePlateColor, string npDist, ref Vector2 npDistPos)
132 {
133 float num = 0.85f;
134 DynamicSpriteFontExtensionMethods.DrawString(spriteBatch, FontAssets.MouseText.Value, npDist, new Vector2(npDistPos.X - 2f, npDistPos.Y), Color.Black, 0f, default(Vector2), num, SpriteEffects.None, 0f);
135 DynamicSpriteFontExtensionMethods.DrawString(spriteBatch, FontAssets.MouseText.Value, npDist, new Vector2(npDistPos.X + 2f, npDistPos.Y), Color.Black, 0f, default(Vector2), num, SpriteEffects.None, 0f);
136 DynamicSpriteFontExtensionMethods.DrawString(spriteBatch, FontAssets.MouseText.Value, npDist, new Vector2(npDistPos.X, npDistPos.Y - 2f), Color.Black, 0f, default(Vector2), num, SpriteEffects.None, 0f);
137 DynamicSpriteFontExtensionMethods.DrawString(spriteBatch, FontAssets.MouseText.Value, npDist, new Vector2(npDistPos.X, npDistPos.Y + 2f), Color.Black, 0f, default(Vector2), num, SpriteEffects.None, 0f);
138 DynamicSpriteFontExtensionMethods.DrawString(spriteBatch, FontAssets.MouseText.Value, npDist, npDistPos, namePlateColor, 0f, default(Vector2), num, SpriteEffects.None, 0f);
139 }
140
141 private static void DrawPlayerName(SpriteBatch spriteBatch, string namePlate, ref Vector2 namePlatePos, ref Color namePlateColor)
142 {
143 DynamicSpriteFontExtensionMethods.DrawString(spriteBatch, FontAssets.MouseText.Value, namePlate, new Vector2(namePlatePos.X - 2f, namePlatePos.Y), Color.Black, 0f, default(Vector2), 1f, SpriteEffects.None, 0f);
144 DynamicSpriteFontExtensionMethods.DrawString(spriteBatch, FontAssets.MouseText.Value, namePlate, new Vector2(namePlatePos.X + 2f, namePlatePos.Y), Color.Black, 0f, default(Vector2), 1f, SpriteEffects.None, 0f);
145 DynamicSpriteFontExtensionMethods.DrawString(spriteBatch, FontAssets.MouseText.Value, namePlate, new Vector2(namePlatePos.X, namePlatePos.Y - 2f), Color.Black, 0f, default(Vector2), 1f, SpriteEffects.None, 0f);
146 DynamicSpriteFontExtensionMethods.DrawString(spriteBatch, FontAssets.MouseText.Value, namePlate, new Vector2(namePlatePos.X, namePlatePos.Y + 2f), Color.Black, 0f, default(Vector2), 1f, SpriteEffects.None, 0f);
147 DynamicSpriteFontExtensionMethods.DrawString(spriteBatch, FontAssets.MouseText.Value, namePlate, namePlatePos, namePlateColor, 0f, default(Vector2), 1f, SpriteEffects.None, 0f);
148 }
149}
static void DrawString(this SpriteBatch spriteBatch, DynamicSpriteFont spriteFont, string text, Vector2 position, Color color)
static double Sqrt(double d)
Vector2 Center
Definition Entity.cs:43
Vector2 position
Definition Entity.cs:14
static Asset< DynamicSpriteFont > MouseText
Definition FontAssets.cs:10
static void DrawPlayerName2(SpriteBatch spriteBatch, ref Color namePlateColor, string npDist, ref Vector2 npDistPos)
static void DrawPlayerName(SpriteBatch spriteBatch, string namePlate, ref Vector2 namePlatePos, ref Color namePlateColor)
static string GetTextValue(string key)
Definition Language.cs:15
static SpriteBatch spriteBatch
Definition Main.cs:974
static int myPlayer
Definition Main.cs:1801
static IPlayerRenderer PlayerRenderer
Definition Main.cs:291
static float UIScale
Definition Main.cs:2624
static Main instance
Definition Main.cs:283
static int screenHeight
Definition Main.cs:1721
static Vector2 screenPosition
Definition Main.cs:1715
static byte mouseTextColor
Definition Main.cs:1751
static Camera Camera
Definition Main.cs:289
static Matrix UIScaleMatrix
Definition Main.cs:2619
static SpriteViewMatrix GameViewMatrix
Definition Main.cs:227
static int teamNamePlateDistance
Definition Main.cs:1729
static Microsoft.Xna.Framework.Color[] teamColor
Definition Main.cs:1276
static Microsoft.Xna.Framework.Color GetPlayerHeadBordersColor(Player plr)
Definition Main.cs:53640
static int screenWidth
Definition Main.cs:1719
static Player[] player
Definition Main.cs:1803
string name
Definition Player.cs:621
static Vector2 DrawColorCodedStringWithShadow(SpriteBatch spriteBatch, DynamicSpriteFont font, TextSnippet[] snippets, Vector2 position, float rotation, Vector2 origin, Vector2 baseScale, out int hoveredSnippet, float maxWidth=-1f, float spread=2f)
void DrawPlayerHead(Camera camera, Player drawPlayer, Vector2 position, float alpha=1f, float scale=1f, Color borderColor=default(Color))