Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
InGamePopups.cs
Go to the documentation of this file.
8
9namespace Terraria.UI;
10
11public class InGamePopups
12{
14 {
16
18
20
21 private const int _iconSize = 64;
22
23 private const int _iconSizeWithSpace = 66;
24
25 private const int _iconsPerRow = 8;
26
27 private int _iconIndex;
28
30
31 private string _title;
32
34
35 public bool ShouldBeRemoved { get; private set; }
36
37 public object CreationObject { get; private set; }
38
39 private float Scale
40 {
41 get
42 {
44 {
45 return MathHelper.Lerp(0f, 1f, (float)_ingameDisplayTimeLeft / 30f);
46 }
47 if (_ingameDisplayTimeLeft > 285)
48 {
49 return MathHelper.Lerp(1f, 0f, ((float)_ingameDisplayTimeLeft - 285f) / 15f);
50 }
51 return 1f;
52 }
53 }
54
55 private float Opacity
56 {
57 get
58 {
59 float scale = Scale;
60 if (scale <= 0.5f)
61 {
62 return 0f;
63 }
64 return (scale - 0.5f) / 0.5f;
65 }
66 }
67
69 {
70 CreationObject = achievement;
72 _theAchievement = achievement;
73 _title = achievement.FriendlyName.Value;
74 int num = (_iconIndex = Main.Achievements.GetIconIndex(achievement.Name));
75 _achievementIconFrame = new Rectangle(num % 8 * 66, num / 8 * 66, 64, 64);
76 _achievementTexture = Main.Assets.Request<Texture2D>("Images/UI/Achievements", (AssetRequestMode)2);
77 _achievementBorderTexture = Main.Assets.Request<Texture2D>("Images/UI/Achievement_Borders", (AssetRequestMode)2);
78 }
79
80 public void Update()
81 {
84 {
86 }
87 }
88
89 public void PushAnchor(ref Vector2 anchorPosition)
90 {
91 float num = 50f * Opacity;
92 anchorPosition.Y -= num;
93 }
94
95 public void DrawInGame(SpriteBatch sb, Vector2 bottomAnchorPosition)
96 {
97 float opacity = Opacity;
98 if (opacity > 0f)
99 {
100 float num = Scale * 1.1f;
101 Vector2 size = (FontAssets.ItemStack.Value.MeasureString(_title) + new Vector2(58f, 10f)) * num;
102 Rectangle r = Utils.CenteredRectangle(bottomAnchorPosition + new Vector2(0f, (0f - size.Y) * 0.5f), size);
103 Vector2 mouseScreen = Main.MouseScreen;
104 bool num2 = r.Contains(mouseScreen.ToPoint());
105 Utils.DrawInvBG(c: num2 ? (new Color(64, 109, 164) * 0.75f) : (new Color(64, 109, 164) * 0.5f), sb: sb, R: r);
106 float num3 = num * 0.3f;
107 Vector2 vector = r.Right() - Vector2.UnitX * num * (12f + num3 * (float)_achievementIconFrame.Width);
108 sb.Draw(_achievementTexture.Value, vector, _achievementIconFrame, Color.White * opacity, 0f, new Vector2(0f, _achievementIconFrame.Height / 2), num3, SpriteEffects.None, 0f);
109 sb.Draw(_achievementBorderTexture.Value, vector, null, Color.White * opacity, 0f, new Vector2(0f, _achievementIconFrame.Height / 2), num3, SpriteEffects.None, 0f);
110 Utils.DrawBorderString(color: new Color(Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor / 5, Main.mouseTextColor) * opacity, sb: sb, text: _title, pos: vector - Vector2.UnitX * 10f, scale: num * 0.9f, anchorx: 1f, anchory: 0.4f);
111 if (num2)
112 {
113 OnMouseOver();
114 }
115 }
116 }
117
118 private void OnMouseOver()
119 {
121 {
122 Main.player[Main.myPlayer].mouseInterface = true;
124 {
125 Main.mouseLeftRelease = false;
128 ShouldBeRemoved = true;
129 }
130 }
131 }
132
133 public void DrawInNotificationsArea(SpriteBatch spriteBatch, Rectangle area, ref int gamepadPointLocalIndexTouse)
134 {
135 Utils.DrawInvBG(spriteBatch, area, Color.Red);
136 }
137 }
138
140 {
141 private int _timeLeft;
142
143 private const int _timeLeftMax = 1800;
144
146
148
149 private float Scale
150 {
151 get
152 {
153 if (_timeLeft < 30)
154 {
155 return MathHelper.Lerp(0f, 1f, (float)_timeLeft / 30f);
156 }
157 if (_timeLeft > 1785)
158 {
159 return MathHelper.Lerp(1f, 0f, ((float)_timeLeft - 1785f) / 15f);
160 }
161 return 1f;
162 }
163 }
164
165 private float Opacity
166 {
167 get
168 {
169 float scale = Scale;
170 if (scale <= 0.5f)
171 {
172 return 0f;
173 }
174 return (scale - 0.5f) / 0.5f;
175 }
176 }
177
178 public object CreationObject { get; private set; }
179
180 public bool ShouldBeRemoved => _timeLeft <= 0;
181
183 {
184 _request = request;
185 CreationObject = request;
186 _timeLeft = 1800;
187 switch (Main.rand.Next(5))
188 {
189 default:
190 _displayTextWithoutTime = "This Bloke Wants to Join you";
191 break;
192 case 1:
193 _displayTextWithoutTime = "This Fucker Wants to Join you";
194 break;
195 case 2:
196 _displayTextWithoutTime = "This Weirdo Wants to Join you";
197 break;
198 case 3:
199 _displayTextWithoutTime = "This Great Gal Wants to Join you";
200 break;
201 case 4:
202 _displayTextWithoutTime = "The one guy who beat you up 30 years ago Wants to Join you";
203 break;
204 }
205 }
206
207 public void Update()
208 {
209 _timeLeft--;
210 }
211
212 public void DrawInGame(SpriteBatch spriteBatch, Vector2 bottomAnchorPosition)
213 {
214 float opacity = Opacity;
215 if (opacity > 0f)
216 {
217 string text = Utils.FormatWith(_request.GetUserWrapperText(), new
218 {
219 DisplayName = _request.UserDisplayName,
220 FullId = _request.UserFullIdentifier
221 });
222 float num = Scale * 1.1f;
223 Vector2 size = (FontAssets.ItemStack.Value.MeasureString(text) + new Vector2(58f, 10f)) * num;
224 Rectangle r = Utils.CenteredRectangle(bottomAnchorPosition + new Vector2(0f, (0f - size.Y) * 0.5f), size);
225 Vector2 mouseScreen = Main.MouseScreen;
226 Color c = (r.Contains(mouseScreen.ToPoint()) ? (new Color(64, 109, 164) * 0.75f) : (new Color(64, 109, 164) * 0.5f));
227 Utils.DrawInvBG(spriteBatch, r, c);
228 Vector2 vector = new Vector2(r.Left, r.Center.Y);
229 vector.X += 32f;
230 Texture2D value = Main.Assets.Request<Texture2D>("Images/UI/ButtonPlay", (AssetRequestMode)1).Value;
231 Vector2 vector2 = new Vector2(r.Left + 7, MathHelper.Lerp(r.Top, r.Bottom, 0.5f) - (float)(value.Height / 2) - 1f);
232 bool flag = Utils.CenteredRectangle(vector2 + new Vector2(value.Width / 2, 0f), value.Size()).Contains(mouseScreen.ToPoint());
233 spriteBatch.Draw(value, vector2, null, Color.White * (flag ? 1f : 0.5f), 0f, new Vector2(0f, 0.5f) * value.Size(), 1f, SpriteEffects.None, 0f);
234 if (flag)
235 {
236 OnMouseOver();
237 }
238 value = Main.Assets.Request<Texture2D>("Images/UI/ButtonDelete", (AssetRequestMode)1).Value;
239 vector2 = new Vector2(r.Left + 7, MathHelper.Lerp(r.Top, r.Bottom, 0.5f) + (float)(value.Height / 2) + 1f);
240 flag = Utils.CenteredRectangle(vector2 + new Vector2(value.Width / 2, 0f), value.Size()).Contains(mouseScreen.ToPoint());
241 spriteBatch.Draw(value, vector2, null, Color.White * (flag ? 1f : 0.5f), 0f, new Vector2(0f, 0.5f) * value.Size(), 1f, SpriteEffects.None, 0f);
242 if (flag)
243 {
244 OnMouseOver(reject: true);
245 }
246 Utils.DrawBorderString(color: new Color(Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor / 5, Main.mouseTextColor) * opacity, sb: spriteBatch, text: text, pos: r.Center.ToVector2() + new Vector2(10f, 0f), scale: num * 0.9f, anchorx: 0.5f, anchory: 0.4f);
247 }
248 }
249
250 private void OnMouseOver(bool reject = false)
251 {
253 {
254 return;
255 }
256 Main.player[Main.myPlayer].mouseInterface = true;
258 {
259 Main.mouseLeftRelease = false;
260 _timeLeft = 0;
261 if (reject)
262 {
264 }
265 else
266 {
268 }
269 }
270 }
271
272 public void PushAnchor(ref Vector2 positionAnchorBottom)
273 {
274 float num = 70f * Opacity;
275 positionAnchorBottom.Y -= num;
276 }
277
278 public void DrawInNotificationsArea(SpriteBatch spriteBatch, Rectangle area, ref int gamepadPointLocalIndexTouse)
279 {
280 string userWrapperText = _request.GetUserWrapperText();
281 string text = _request.UserDisplayName;
282 Utils.TrimTextIfNeeded(ref text, FontAssets.MouseText.Value, 0.9f, area.Width / 4);
283 string text2 = Utils.FormatWith(userWrapperText, new
284 {
285 DisplayName = text,
286 FullId = _request.UserFullIdentifier
287 });
288 Vector2 mouseScreen = Main.MouseScreen;
289 Color c = (area.Contains(mouseScreen.ToPoint()) ? (new Color(64, 109, 164) * 0.75f) : (new Color(64, 109, 164) * 0.5f));
290 Utils.DrawInvBG(spriteBatch, area, c);
291 Vector2 pos = new Vector2(area.Left, area.Center.Y);
292 pos.X += 32f;
293 Texture2D value = Main.Assets.Request<Texture2D>("Images/UI/ButtonPlay", (AssetRequestMode)1).Value;
294 Vector2 vector = new Vector2(area.Left + 7, MathHelper.Lerp(area.Top, area.Bottom, 0.5f) - (float)(value.Height / 2) - 1f);
295 bool flag = Utils.CenteredRectangle(vector + new Vector2(value.Width / 2, 0f), value.Size()).Contains(mouseScreen.ToPoint());
296 spriteBatch.Draw(value, vector, null, Color.White * (flag ? 1f : 0.5f), 0f, new Vector2(0f, 0.5f) * value.Size(), 1f, SpriteEffects.None, 0f);
297 if (flag)
298 {
299 OnMouseOver();
300 }
301 value = Main.Assets.Request<Texture2D>("Images/UI/ButtonDelete", (AssetRequestMode)1).Value;
302 vector = new Vector2(area.Left + 7, MathHelper.Lerp(area.Top, area.Bottom, 0.5f) + (float)(value.Height / 2) + 1f);
303 flag = Utils.CenteredRectangle(vector + new Vector2(value.Width / 2, 0f), value.Size()).Contains(mouseScreen.ToPoint());
304 spriteBatch.Draw(value, vector, null, Color.White * (flag ? 1f : 0.5f), 0f, new Vector2(0f, 0.5f) * value.Size(), 1f, SpriteEffects.None, 0f);
305 if (flag)
306 {
307 OnMouseOver(reject: true);
308 }
309 pos.X += 6f;
310 Utils.DrawBorderString(color: new Color(Main.mouseTextColor, Main.mouseTextColor, Main.mouseTextColor / 5, Main.mouseTextColor), sb: spriteBatch, text: text2, pos: pos, scale: 0.9f, anchorx: 0f, anchory: 0.4f);
311 }
312 }
313}
void Draw(Texture2D texture, Vector2 position, Color color)
static float Lerp(float value1, float value2, float amount)
Definition MathHelper.cs:53
readonly LocalizedText FriendlyName
static Asset< DynamicSpriteFont > ItemStack
Definition FontAssets.cs:8
static Asset< DynamicSpriteFont > MouseText
Definition FontAssets.cs:10
static AchievementManager Achievements
Definition Main.cs:2756
static int myPlayer
Definition Main.cs:1801
static bool mouseLeftRelease
Definition Main.cs:1755
static Vector2 MouseScreen
Definition Main.cs:2773
static byte mouseTextColor
Definition Main.cs:1751
static UnifiedRandom rand
Definition Main.cs:1387
static IAssetRepository Assets
Definition Main.cs:209
static Player[] player
Definition Main.cs:1803
static bool mouseLeft
Definition Main.cs:614
void PushAnchor(ref Vector2 anchorPosition)
void DrawInNotificationsArea(SpriteBatch spriteBatch, Rectangle area, ref int gamepadPointLocalIndexTouse)
void DrawInGame(SpriteBatch sb, Vector2 bottomAnchorPosition)
void DrawInNotificationsArea(SpriteBatch spriteBatch, Rectangle area, ref int gamepadPointLocalIndexTouse)
PlayerWantsToJoinGamePopup(UserJoinToServerRequest request)
void DrawInGame(SpriteBatch spriteBatch, Vector2 bottomAnchorPosition)
void PushAnchor(ref Vector2 positionAnchorBottom)
static void OpenAchievementsAndGoto(Achievement achievement)
static string FormatWith(string original, object obj)
Definition Utils.cs:739
static void DrawInvBG(SpriteBatch sb, Rectangle R, Color c=default(Color))
Definition Utils.cs:1921
static Vector2 DrawBorderString(SpriteBatch sb, string text, Vector2 pos, Color color, float scale=1f, float anchorx=0f, float anchory=0f, int maxCharactersDisplayed=-1)
Definition Utils.cs:1891
static void TrimTextIfNeeded(ref string text, DynamicSpriteFont font, float scale, float maxWidth)
Definition Utils.cs:723
static Rectangle CenteredRectangle(Vector2 center, Vector2 size)
Definition Utils.cs:604
bool Contains(int x, int y)
Definition Rectangle.cs:92