Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
GameTipsDisplay.cs
Go to the documentation of this file.
8
10
11public class GameTipsDisplay
12{
13 private class GameTip
14 {
15 private const float APPEAR_FROM = 2.5f;
16
17 private const float APPEAR_TO = 0.5f;
18
19 private const float DISAPPEAR_TO = -1.5f;
20
21 private const float APPEAR_TIME = 0.5f;
22
23 private const float DISAPPEAR_TIME = 1f;
24
25 private const float DURATION = 11.5f;
26
28
29 private string _formattedText;
30
31 public float ScreenAnchorX;
32
33 public readonly float Duration;
34
35 public readonly double SpawnTime;
36
37 public string Text
38 {
39 get
40 {
41 if (_textKey == null)
42 {
43 return "What?!";
44 }
45 return _formattedText;
46 }
47 }
48
49 public bool IsExpired(double currentTime)
50 {
51 return currentTime >= SpawnTime + (double)Duration;
52 }
53
54 public bool IsExpiring(double currentTime)
55 {
56 return currentTime >= SpawnTime + (double)Duration - 1.0;
57 }
58
69
70 public void Update(double currentTime)
71 {
72 double num = currentTime - SpawnTime;
73 if (num < 0.5)
74 {
75 ScreenAnchorX = MathHelper.SmoothStep(2.5f, 0.5f, (float)Utils.GetLerpValue(0.0, 0.5, num, clamped: true));
76 }
77 else if (num >= (double)(Duration - 1f))
78 {
79 ScreenAnchorX = MathHelper.SmoothStep(0.5f, -1.5f, (float)Utils.GetLerpValue(Duration - 1f, Duration, num, clamped: true));
80 }
81 else
82 {
83 ScreenAnchorX = 0.5f;
84 }
85 }
86 }
87
89
91
93
94 private readonly List<GameTip> _currentTips = new List<GameTip>();
95
97
99 {
100 _tipsDefault = Language.FindAll(Lang.CreateDialogFilter("LoadingTips_Default."));
101 _tipsGamepad = Language.FindAll(Lang.CreateDialogFilter("LoadingTips_GamePad."));
102 _tipsKeyboard = Language.FindAll(Lang.CreateDialogFilter("LoadingTips_Keyboard."));
103 _lastTip = null;
104 }
105
106 public void Update()
107 {
108 double time = Main.gameTimeCache.TotalGameTime.TotalSeconds;
109 _currentTips.RemoveAll((GameTip x) => x.IsExpired(time));
110 bool flag = true;
111 foreach (GameTip currentTip in _currentTips)
112 {
113 if (!currentTip.IsExpiring(time))
114 {
115 flag = false;
116 break;
117 }
118 }
119 if (flag)
120 {
121 AddNewTip(time);
122 }
123 foreach (GameTip currentTip2 in _currentTips)
124 {
125 currentTip2.Update(time);
126 }
127 }
128
129 public void ClearTips()
130 {
132 }
133
134 public void Draw()
135 {
136 SpriteBatch spriteBatch = Main.spriteBatch;
137 float num = Main.screenWidth;
138 float y = Main.screenHeight - 150;
139 float num2 = (float)Main.screenWidth * 0.5f;
140 foreach (GameTip currentTip in _currentTips)
141 {
142 if (currentTip.ScreenAnchorX < -0.5f || currentTip.ScreenAnchorX > 1.5f)
143 {
144 continue;
145 }
147 string text = value.CreateWrappedText(currentTip.Text, num2, Language.ActiveCulture.CultureInfo);
148 if (text.Split('\n').Length > 2)
149 {
150 text = value.CreateWrappedText(currentTip.Text, num2 * 1.5f - 50f, Language.ActiveCulture.CultureInfo);
151 }
153 {
154 string text2 = "";
155 for (int num3 = text.Length - 1; num3 >= 0; num3--)
156 {
157 text2 += text.Substring(num3, 1);
158 }
159 text = text2;
160 }
162 {
163 text = string.Concat(Main.rand.Next(999999999));
164 for (int i = 0; i < 14; i++)
165 {
166 if (Main.rand.Next(2) == 0)
167 {
168 text += Main.rand.Next(999999999);
169 }
170 }
171 }
172 Vector2 vector = value.MeasureString(text);
173 float num4 = 1.1f;
174 float num5 = 110f;
175 if (vector.Y > num5)
176 {
177 num4 = num5 / vector.Y;
178 }
179 Vector2 position = new Vector2(num * currentTip.ScreenAnchorX, y);
180 position -= vector * num4 * 0.5f;
182 {
183 ChatManager.DrawColorCodedStringWithShadow(spriteBatch, value, text, position, Color.HotPink, 0f, Vector2.Zero, new Vector2(num4, num4));
184 }
185 else
186 {
187 ChatManager.DrawColorCodedStringWithShadow(spriteBatch, value, text, position, Color.White, 0f, Vector2.Zero, new Vector2(num4, num4));
188 }
189 }
190 }
191
192 private void AddNewTip(double currentTime)
193 {
194 string textKey = "UI.Back";
196 list.AddRange(_tipsDefault);
198 {
199 list.AddRange(_tipsGamepad);
200 }
201 else
202 {
203 list.AddRange(_tipsKeyboard);
204 }
205 if (_lastTip != null)
206 {
207 list.Remove(_lastTip);
208 }
209 string key = (_lastTip = ((list.Count != 0) ? list[Main.rand.Next(list.Count)] : LocalizedText.Empty)).Key;
210 if (Language.Exists(key))
211 {
212 textKey = key;
213 }
215 }
216}
static float SmoothStep(float value1, float value2, float amount)
Definition MathHelper.cs:63
void Add(TKey key, TValue value)
static Asset< DynamicSpriteFont > MouseText
Definition FontAssets.cs:10
GameTip(string textKey, double spawnTime)
static object CreateDialogSubstitutionObject(NPC npc=null)
Definition Lang.cs:74
static LanguageSearchFilter CreateDialogFilter(string startsWith, object substitutions)
Definition Lang.cs:388
static string SupportGlyphs(string tooltip)
Definition Lang.cs:522
static LocalizedText[] FindAll(Regex regex)
Definition Language.cs:55
static GameCulture ActiveCulture
Definition Language.cs:8
static LocalizedText GetText(string key)
Definition Language.cs:10
static bool Exists(string key)
Definition Language.cs:45
static readonly LocalizedText Empty
static GameTime gameTimeCache
Definition Main.cs:409
static SpriteBatch spriteBatch
Definition Main.cs:974
static UnifiedRandom rand
Definition Main.cs:1387
static int screenWidth
Definition Main.cs:1719
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)
static float GetLerpValue(float from, float to, float t, bool clamped=false)
Definition Utils.cs:203
static bool remixWorldGen
Definition WorldGen.cs:1148
static bool tenthAnniversaryWorldGen
Definition WorldGen.cs:1160
static bool drunkWorldGenText
Definition WorldGen.cs:1166
static bool getGoodWorldGen
Definition WorldGen.cs:1156