Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
NPCStatsReportInfoElement.cs
Go to the documentation of this file.
7using Terraria.UI;
8
10
12{
13 public delegate void StatAdjustmentStep(NPCStatsReportInfoElement element);
14
15 public int NpcId;
16
17 public int Damage;
18
19 public int LifeMax;
20
21 public float MonetaryValue;
22
23 public int Defense;
24
25 public float KnockbackResist;
26
27 private NPC _instance;
28
30
31 public NPCStatsReportInfoElement(int npcNetId)
32 {
33 NpcId = npcNetId;
34 _instance = new NPC();
36 }
37
42
43 private void RefreshStats(GameModeData gameModeFound, NPC instance)
44 {
45 instance.SetDefaults(NpcId, new NPCSpawnParams
46 {
47 gameModeData = gameModeFound,
48 strengthMultiplierOverride = null
49 });
50 Damage = instance.damage;
51 LifeMax = instance.lifeMax;
52 MonetaryValue = instance.value;
53 Defense = instance.defense;
55 if (this.OnRefreshStats != null)
56 {
57 this.OnRefreshStats(this);
58 }
59 }
60
62 {
63 if (info.UnlockState == BestiaryEntryUnlockState.NotKnownAtAll_0)
64 {
65 return null;
66 }
68 UIElement uIElement = new UIElement
69 {
70 Width = new StyleDimension(0f, 1f),
71 Height = new StyleDimension(109f, 0f)
72 };
73 int num = 99;
74 int num2 = 35;
75 int num3 = 3;
76 int num4 = 0;
77 UIImage uIImage = new UIImage(Main.Assets.Request<Texture2D>("Images/UI/Bestiary/Stat_HP", (AssetRequestMode)1))
78 {
79 Top = new StyleDimension(num4, 0f),
80 Left = new StyleDimension(num3, 0f)
81 };
82 UIImage uIImage2 = new UIImage(Main.Assets.Request<Texture2D>("Images/UI/Bestiary/Stat_Attack", (AssetRequestMode)1))
83 {
84 Top = new StyleDimension(num4 + num2, 0f),
85 Left = new StyleDimension(num3, 0f)
86 };
87 UIImage uIImage3 = new UIImage(Main.Assets.Request<Texture2D>("Images/UI/Bestiary/Stat_Defense", (AssetRequestMode)1))
88 {
89 Top = new StyleDimension(num4 + num2, 0f),
90 Left = new StyleDimension(num3 + num, 0f)
91 };
92 UIImage uIImage4 = new UIImage(Main.Assets.Request<Texture2D>("Images/UI/Bestiary/Stat_Knockback", (AssetRequestMode)1))
93 {
94 Top = new StyleDimension(num4, 0f),
95 Left = new StyleDimension(num3 + num, 0f)
96 };
97 uIElement.Append(uIImage);
98 uIElement.Append(uIImage2);
99 uIElement.Append(uIImage3);
100 uIElement.Append(uIImage4);
101 int num5 = -10;
102 int num6 = 0;
103 int num7 = (int)MonetaryValue;
104 string text = Utils.Clamp(num7 / 1000000, 0, 999).ToString();
105 string text2 = Utils.Clamp(num7 % 1000000 / 10000, 0, 99).ToString();
106 string text3 = Utils.Clamp(num7 % 10000 / 100, 0, 99).ToString();
107 string text4 = Utils.Clamp(num7 % 100 / 1, 0, 99).ToString();
108 if (num7 / 1000000 < 1)
109 {
110 text = "-";
111 }
112 if (num7 / 10000 < 1)
113 {
114 text2 = "-";
115 }
116 if (num7 / 100 < 1)
117 {
118 text3 = "-";
119 }
120 if (num7 < 1)
121 {
122 text4 = "-";
123 }
124 string text5 = LifeMax.ToString();
125 string text6 = Damage.ToString();
126 string text7 = Defense.ToString();
127 string text8 = ((KnockbackResist > 0.8f) ? Language.GetText("BestiaryInfo.KnockbackHigh").Value : ((KnockbackResist > 0.4f) ? Language.GetText("BestiaryInfo.KnockbackMedium").Value : ((!(KnockbackResist > 0f)) ? Language.GetText("BestiaryInfo.KnockbackNone").Value : Language.GetText("BestiaryInfo.KnockbackLow").Value)));
128 if (info.UnlockState < BestiaryEntryUnlockState.CanShowStats_2)
129 {
130 text = (text2 = (text3 = (text4 = "?")));
131 text5 = (text6 = (text7 = (text8 = "???")));
132 }
133 UIText element = new UIText(text5)
134 {
135 HAlign = 1f,
136 VAlign = 0.5f,
137 Left = new StyleDimension(num5, 0f),
138 Top = new StyleDimension(num6, 0f),
139 IgnoresMouseInteraction = true
140 };
141 UIText element2 = new UIText(text8)
142 {
143 HAlign = 1f,
144 VAlign = 0.5f,
145 Left = new StyleDimension(num5, 0f),
146 Top = new StyleDimension(num6, 0f),
147 IgnoresMouseInteraction = true
148 };
149 UIText element3 = new UIText(text6)
150 {
151 HAlign = 1f,
152 VAlign = 0.5f,
153 Left = new StyleDimension(num5, 0f),
154 Top = new StyleDimension(num6, 0f),
155 IgnoresMouseInteraction = true
156 };
157 UIText element4 = new UIText(text7)
158 {
159 HAlign = 1f,
160 VAlign = 0.5f,
161 Left = new StyleDimension(num5, 0f),
162 Top = new StyleDimension(num6, 0f),
163 IgnoresMouseInteraction = true
164 };
165 uIImage.Append(element);
166 uIImage2.Append(element3);
167 uIImage3.Append(element4);
168 uIImage4.Append(element2);
169 int num8 = 66;
170 if (num7 > 0)
171 {
173 {
174 Width = StyleDimension.FromPixelsAndPercent(0f, 1f),
175 Color = new Color(89, 116, 213, 255) * 0.9f,
176 Left = new StyleDimension(0f, 0f),
177 Top = new StyleDimension(num6 + num2 * 2, 0f)
178 };
179 uIElement.Append(element5);
180 num8 += 4;
181 int num9 = num3;
182 int num10 = num8 + 8;
183 int num11 = 49;
184 UIImage uIImage5 = new UIImage(Main.Assets.Request<Texture2D>("Images/UI/Bestiary/Stat_Platinum", (AssetRequestMode)1))
185 {
186 Top = new StyleDimension(num10, 0f),
187 Left = new StyleDimension(num9, 0f)
188 };
189 UIImage uIImage6 = new UIImage(Main.Assets.Request<Texture2D>("Images/UI/Bestiary/Stat_Gold", (AssetRequestMode)1))
190 {
191 Top = new StyleDimension(num10, 0f),
192 Left = new StyleDimension(num9 + num11, 0f)
193 };
194 UIImage uIImage7 = new UIImage(Main.Assets.Request<Texture2D>("Images/UI/Bestiary/Stat_Silver", (AssetRequestMode)1))
195 {
196 Top = new StyleDimension(num10, 0f),
197 Left = new StyleDimension(num9 + num11 * 2 + 1, 0f)
198 };
199 UIImage uIImage8 = new UIImage(Main.Assets.Request<Texture2D>("Images/UI/Bestiary/Stat_Copper", (AssetRequestMode)1))
200 {
201 Top = new StyleDimension(num10, 0f),
202 Left = new StyleDimension(num9 + num11 * 3 + 1, 0f)
203 };
204 if (text != "-")
205 {
206 uIElement.Append(uIImage5);
207 }
208 if (text2 != "-")
209 {
210 uIElement.Append(uIImage6);
211 }
212 if (text3 != "-")
213 {
214 uIElement.Append(uIImage7);
215 }
216 if (text4 != "-")
217 {
218 uIElement.Append(uIImage8);
219 }
220 int num12 = num5 + 3;
221 float textScale = 0.85f;
222 UIText element6 = new UIText(text, textScale)
223 {
224 HAlign = 1f,
225 VAlign = 0.5f,
226 Left = new StyleDimension(num12, 0f),
227 Top = new StyleDimension(num6, 0f)
228 };
229 UIText element7 = new UIText(text2, textScale)
230 {
231 HAlign = 1f,
232 VAlign = 0.5f,
233 Left = new StyleDimension(num12, 0f),
234 Top = new StyleDimension(num6, 0f)
235 };
236 UIText element8 = new UIText(text3, textScale)
237 {
238 HAlign = 1f,
239 VAlign = 0.5f,
240 Left = new StyleDimension(num12, 0f),
241 Top = new StyleDimension(num6, 0f)
242 };
243 UIText element9 = new UIText(text4, textScale)
244 {
245 HAlign = 1f,
246 VAlign = 0.5f,
247 Left = new StyleDimension(num12, 0f),
248 Top = new StyleDimension(num6, 0f)
249 };
250 uIImage5.Append(element6);
251 uIImage6.Append(element7);
252 uIImage7.Append(element8);
253 uIImage8.Append(element9);
254 num8 += 34;
255 }
256 num8 += 4;
257 uIElement.Height.Pixels = num8;
258 uIImage2.OnUpdate += ShowStats_Attack;
259 uIImage3.OnUpdate += ShowStats_Defense;
260 uIImage.OnUpdate += ShowStats_Life;
261 uIImage4.OnUpdate += ShowStats_Knockback;
262 return uIElement;
263 }
264
265 private void ShowStats_Attack(UIElement element)
266 {
267 if (element.IsMouseHovering)
268 {
269 Main.instance.MouseText(Language.GetTextValue("BestiaryInfo.Attack"), 0, 0);
270 }
271 }
272
273 private void ShowStats_Defense(UIElement element)
274 {
275 if (element.IsMouseHovering)
276 {
277 Main.instance.MouseText(Language.GetTextValue("BestiaryInfo.Defense"), 0, 0);
278 }
279 }
280
281 private void ShowStats_Knockback(UIElement element)
282 {
283 if (element.IsMouseHovering)
284 {
285 Main.instance.MouseText(Language.GetTextValue("BestiaryInfo.Knockback"), 0, 0);
286 }
287 }
288
289 private void ShowStats_Life(UIElement element)
290 {
291 if (element.IsMouseHovering)
292 {
293 Main.instance.MouseText(Language.GetTextValue("BestiaryInfo.Life"), 0, 0);
294 }
295 }
296}
void RefreshStats(GameModeData gameModeFound, NPC instance)
delegate void StatAdjustmentStep(NPCStatsReportInfoElement element)
static LocalizedText GetText(string key)
Definition Language.cs:10
static string GetTextValue(string key)
Definition Language.cs:15
static Main instance
Definition Main.cs:283
static GameModeData GameModeInfo
Definition Main.cs:2682
static IAssetRepository Assets
Definition Main.cs:209
void SetDefaults(int Type, NPCSpawnParams spawnparams=default(NPCSpawnParams))
Definition NPC.cs:2523
int defense
Definition NPC.cs:463
int damage
Definition NPC.cs:461
int lifeMax
Definition NPC.cs:479
float knockBackResist
Definition NPC.cs:495
float value
Definition NPC.cs:523
void Append(UIElement element)
Definition UIElement.cs:166
static StyleDimension FromPixelsAndPercent(float pixels, float percent)