Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
NewMultiplayerClosePlayersOverlay.cs
Go to the documentation of this file.
1using System;
10
12
14{
15 private struct PlayerOnScreenCache
16 {
17 private string _name;
18
19 private Vector2 _pos;
20
21 private Color _color;
22
23 public PlayerOnScreenCache(string name, Vector2 pos, Color color)
24 {
25 _name = name;
26 _pos = pos;
27 _color = color;
28 }
29
31 {
32 _pos = _pos.Floor();
33 DynamicSpriteFontExtensionMethods.DrawString(spriteBatch, FontAssets.MouseText.Value, _name, new Vector2(_pos.X - 2f, _pos.Y), Color.Black, 0f, default(Vector2), 1f, SpriteEffects.None, 0f);
34 DynamicSpriteFontExtensionMethods.DrawString(spriteBatch, FontAssets.MouseText.Value, _name, new Vector2(_pos.X + 2f, _pos.Y), Color.Black, 0f, default(Vector2), 1f, SpriteEffects.None, 0f);
35 DynamicSpriteFontExtensionMethods.DrawString(spriteBatch, FontAssets.MouseText.Value, _name, new Vector2(_pos.X, _pos.Y - 2f), Color.Black, 0f, default(Vector2), 1f, SpriteEffects.None, 0f);
36 DynamicSpriteFontExtensionMethods.DrawString(spriteBatch, FontAssets.MouseText.Value, _name, new Vector2(_pos.X, _pos.Y + 2f), Color.Black, 0f, default(Vector2), 1f, SpriteEffects.None, 0f);
38 }
39 }
40
41 private struct PlayerOffScreenCache
42 {
43 private Player player;
44
45 private string nameToShow;
46
48
50
52
53 private string distanceString;
54
56
58 {
59 nameToShow = name;
60 namePlatePos = pos.Floor();
61 namePlateColor = color;
66 }
67
72
73 public void DrawPlayerHead()
74 {
75 float num = 20f;
76 float num2 = -27f;
77 num2 -= (measurement.X - 85f) / 2f;
80 vec.X -= 22f + num2;
81 vec.Y += 8f;
82 vec = vec.Floor();
84 }
85
86 public void DrawLifeBar()
87 {
88 Vector2 vector = Main.screenPosition + distanceDrawPosition + new Vector2(26f, 20f);
90 {
91 Main.instance.DrawHealthBar(vector.X, vector.Y, player.statLife, player.statLifeMax2, 1f, 1.25f, noFlip: true);
92 }
93 }
94
104 }
105
107
109
110 public void Draw()
111 {
112 int teamNamePlateDistance = Main.teamNamePlateDistance;
113 if (teamNamePlateDistance <= 0)
114 {
115 return;
116 }
119 SpriteBatch spriteBatch = Main.spriteBatch;
121 int screenWidth = Main.screenWidth;
122 int screenHeight = Main.screenHeight;
123 Vector2 screenPosition = Main.screenPosition;
125 int num = teamNamePlateDistance * 8;
126 Player[] player = Main.player;
127 int myPlayer = Main.myPlayer;
128 byte mouseTextColor = Main.mouseTextColor;
129 Color[] teamColor = Main.teamColor;
131 Player player2 = player[myPlayer];
132 float num2 = (float)(int)mouseTextColor / 255f;
133 if (player2.team == 0)
134 {
135 return;
136 }
138 for (int i = 0; i < 255; i++)
139 {
140 if (i == myPlayer)
141 {
142 continue;
143 }
144 Player player3 = player[i];
145 if (!player3.active || player3.dead || player3.team != player2.team)
146 {
147 continue;
148 }
149 string name = player3.name;
150 GetDistance(screenWidth, screenHeight, screenPosition, player2, value, player3, name, out var namePlatePos, out var namePlateDist, out var measurement);
151 Color color = new Color((byte)((float)(int)teamColor[player3.team].R * num2), (byte)((float)(int)teamColor[player3.team].G * num2), (byte)((float)(int)teamColor[player3.team].B * num2), mouseTextColor);
152 if (namePlateDist > 0f)
153 {
154 float num3 = player3.Distance(player2.Center);
155 if (!(num3 > (float)num))
156 {
157 float num4 = 20f;
158 float num5 = -27f;
159 num5 -= (measurement.X - 85f) / 2f;
160 string textValue = Language.GetTextValue("GameUI.PlayerDistance", (int)(num3 / 16f * 2f));
161 Vector2 npDistPos = value.MeasureString(textValue);
162 npDistPos.X = namePlatePos.X - num5;
163 npDistPos.Y = namePlatePos.Y + measurement.Y / 2f - npDistPos.Y / 2f - num4;
164 _playerOffScreenCache.Add(new PlayerOffScreenCache(name, namePlatePos, color, npDistPos, textValue, player3, measurement));
165 }
166 }
167 else
168 {
169 _playerOnScreenCache.Add(new PlayerOnScreenCache(name, namePlatePos, color));
170 }
171 }
172 spriteBatch.End();
173 spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, Main.UIScaleMatrix);
174 for (int j = 0; j < _playerOnScreenCache.Count; j++)
175 {
176 _playerOnScreenCache[j].DrawPlayerName_WhenPlayerIsOnScreen(spriteBatch);
177 }
178 for (int k = 0; k < _playerOffScreenCache.Count; k++)
179 {
180 _playerOffScreenCache[k].DrawPlayerName(spriteBatch);
181 }
182 for (int l = 0; l < _playerOffScreenCache.Count; l++)
183 {
184 _playerOffScreenCache[l].DrawPlayerDistance(spriteBatch);
185 }
186 spriteBatch.End();
187 spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, Main.UIScaleMatrix);
188 for (int m = 0; m < _playerOffScreenCache.Count; m++)
189 {
190 _playerOffScreenCache[m].DrawLifeBar();
191 }
192 spriteBatch.End();
193 spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, null, null, Main.UIScaleMatrix);
194 for (int n = 0; n < _playerOffScreenCache.Count; n++)
195 {
196 _playerOffScreenCache[n].DrawPlayerHead();
197 }
198 }
199
200 private static void GetDistance(int testWidth, int testHeight, Vector2 testPosition, Player localPlayer, DynamicSpriteFont font, Player player, string nameToShow, out Vector2 namePlatePos, out float namePlateDist, out Vector2 measurement)
201 {
202 float uIScale = Main.UIScale;
204 namePlatePos = font.MeasureString(nameToShow);
205 float num = 0f;
206 if (player.chatOverhead.timeLeft > 0)
207 {
208 num = (0f - namePlatePos.Y) * uIScale;
209 }
210 else if (player.emoteTime > 0)
211 {
212 num = (0f - namePlatePos.Y) * uIScale;
213 }
214 Vector2 vector = new Vector2((float)(testWidth / 2) + testPosition.X, (float)(testHeight / 2) + testPosition.Y);
215 Vector2 position = player.position;
216 position += (position - vector) * (gameViewMatrix.Zoom - Vector2.One);
217 namePlateDist = 0f;
218 float num2 = position.X + (float)(player.width / 2) - vector.X;
219 float num3 = position.Y - namePlatePos.Y - 2f + num - vector.Y;
220 float num4 = (float)Math.Sqrt(num2 * num2 + num3 * num3);
221 int num5 = testHeight;
222 if (testHeight > testWidth)
223 {
224 num5 = testWidth;
225 }
226 num5 = num5 / 2 - 50;
227 if (num5 < 100)
228 {
229 num5 = 100;
230 }
231 if (num4 < (float)num5)
232 {
233 namePlatePos.X = position.X + (float)(player.width / 2) - namePlatePos.X / 2f - testPosition.X;
234 namePlatePos.Y = position.Y - namePlatePos.Y - 2f + num - testPosition.Y;
235 }
236 else
237 {
239 num4 = (float)num5 / num4;
240 namePlatePos.X = (float)(testWidth / 2) + num2 * num4 - namePlatePos.X / 2f;
241 namePlatePos.Y = (float)(testHeight / 2) + num3 * num4 + 40f * uIScale;
242 }
243 measurement = font.MeasureString(nameToShow);
244 namePlatePos += measurement / 2f;
245 namePlatePos *= 1f / uIScale;
246 namePlatePos -= measurement / 2f;
247 if (localPlayer.gravDir == -1f)
248 {
249 namePlatePos.Y = (float)testHeight - namePlatePos.Y;
250 }
251 }
252}
static void DrawString(this SpriteBatch spriteBatch, DynamicSpriteFont spriteFont, string text, Vector2 position, Color color)
void Add(TKey key, TValue value)
static double Sqrt(double d)
Vector2 position
Definition Entity.cs:14
static Asset< DynamicSpriteFont > MouseText
Definition FontAssets.cs:10
static void GetDistance(int testWidth, int testHeight, Vector2 testPosition, Player localPlayer, DynamicSpriteFont font, Player player, string nameToShow, out Vector2 namePlatePos, out float namePlateDist, out Vector2 measurement)
static string GetTextValue(string key)
Definition Language.cs:15
static SpriteBatch spriteBatch
Definition Main.cs:974
static int myPlayer
Definition Main.cs:1801
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 MapHeadRenderer MapPlayerRenderer
Definition Main.cs:295
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
OverheadMessage chatOverhead
Definition Player.cs:581
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)
PlayerOffScreenCache(string name, Vector2 pos, Color color, Vector2 npDistPos, string npDist, Player thePlayer, Vector2 theMeasurement)