Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_XPInfoDisplay.c
Go to the documentation of this file.
1class SCR_XPInfoDisplay : SCR_InfoDisplayExtended
2{
3 protected static const int XP_INFO_DURATION = 10000; //ms
4 protected static const ResourceName RANK_ICON_IMAGESET = "{70E828A2F6EBE7D0}UI/Textures/Nametags/nametagicons.imageset";
5
6 protected bool m_bInitDone;
7 protected bool m_bIsInfoAllowed = true;
8
9 protected SCR_XPHandlerComponent m_PlayerXPComponent;
11
13
15
16 protected string m_sCurrentRankName;
17 protected string m_sCurrentRankIcon;
18
19 protected string m_sNextRankIcon;
20
21 protected SCR_ECharacterRank m_ECurrentRank;
22 protected SCR_ECharacterRank m_EPrevRank;
23
25 protected string m_sRewardName;
26
27 protected bool m_bIsHUDbarActive;
28 protected int m_iSavedXPIncrease;
29
30 //------------------------------------------------------------------------------------------------
31 override void DisplayInit(IEntity owner)
32 {
33 super.DisplayInit(owner);
34
35 BaseGameMode gameMode = GetGame().GetGameMode();
36
37 if (!gameMode)
38 return;
39
40 m_PlayerXPComponent = SCR_XPHandlerComponent.Cast(gameMode.FindComponent(SCR_XPHandlerComponent));
41 }
42
43 //------------------------------------------------------------------------------------------------
44 override bool DisplayStartDrawInit(IEntity owner)
45 {
46 return (m_PlayerXPComponent != null);
47 }
48
49 //------------------------------------------------------------------------------------------------
50 override void DisplayStartDraw(IEntity owner)
51 {
52 if (m_bInitDone)
53 return;
54
55 m_bInitDone = true;
56
58 return;
59
61 m_PlayerXPHandlerComp.GetOnXPChanged().Insert(ShowXPInfo);
62
64 if (taskManager)
65 taskManager.GetOnTaskHUDVisible().Insert(ToggleXPInfo);
66
67 SCR_XPInfoWidgetData hudXPWidget = new SCR_XPInfoWidgetData();
68 hudXPWidget.InitWidgets(m_wRoot);
69 AddNewWidgets(hudXPWidget, SCR_EXPInfoWidget.HUD);
70 }
71
72 //------------------------------------------------------------------------------------------------
82
83 //------------------------------------------------------------------------------------------------
84 void AddNewWidgets(notnull SCR_XPInfoWidgetData hudXPWidget, int id)
85 {
86 if (m_Widgets.Get(id))
87 return;
88
89 m_Widgets.Insert(id, hudXPWidget);
90
91 if (m_sCurrentRankName == string.Empty)
92 UpdateData();
93
95 return;
96
97 m_FactionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
98
100 return;
101
102 SCR_RankContainer ranks = m_FactionManager.GetFactionRanks(m_PlayerController.GetPlayerId());
103
104 int totalXP = m_PlayerXPHandlerComp.GetPlayerXP();
105 m_ECurrentRank = ranks.GetRankByXP(totalXP);
107
108 //If the HUD's rank progress bar is currently showing an increase/decrease, set the color of this widget's bar to the color of the bar in the HUD (when the HUD's bar fades out, this widget's bar's color will update according to the player's total XP)
109 //If the HUD's rank progress bar is NOT showing an increase/decrease, set the color according to the player's current total XP
111 {
112 hudXPWidget.UpdateXPTexts(false, false, m_iSavedXPIncrease, totalXP, true, m_EReward, ranks, m_ECurrentRank, m_sCurrentRankIcon, m_sCurrentRankName, m_sNextRankIcon, m_sRewardName);
113 }
114 else
115 {
116 hudXPWidget.UpdateXPTexts(false, false, 0, totalXP, false, m_EReward, ranks, m_ECurrentRank, m_sCurrentRankIcon, m_sCurrentRankName, m_sNextRankIcon, m_sRewardName);
117 hudXPWidget.UpdateInventoryBarColor(m_ECurrentRank, totalXP, ranks);
118 }
119
120 hudXPWidget.UpdateXPProgressBar(m_ECurrentRank, m_EPrevRank, m_iSavedXPIncrease, totalXP, m_bIsHUDbarActive, ranks);
121 }
122
123 //------------------------------------------------------------------------------------------------
124 bool RemoveWidgetsById(int widgetDataId)
125 {
126 m_Widgets.Remove(widgetDataId);
127
128 return true;
129 }
130
131 //------------------------------------------------------------------------------------------------
132 override void OnSettingsChanged()
133 {
134 BaseContainer interfaceSettings = GetGame().GetGameUserSettings().GetModule(m_HUDManager.GetInterfaceSettingsClass());
135 if (!interfaceSettings)
136 return;
137
138 bool state;
139 interfaceSettings.Get(m_sInterfaceSettingName, state);
140
141 AllowShowingInfo(state);
142 }
143
144 //------------------------------------------------------------------------------------------------
145 void AllowShowingInfo(bool allow)
146 {
147 m_bIsInfoAllowed = allow;
148 }
149
150 //------------------------------------------------------------------------------------------------
151 protected void RecolorXPBar()
152 {
153 int color;
154
155 SCR_RankContainer ranks = m_FactionManager.GetFactionRanks(m_PlayerController.GetPlayerId());
156
158 color = UIColors.WARNING.PackToInt();
159 else if (m_iSavedXPIncrease < 0)
160 color = UIColors.IDLE_DISABLED.PackToInt();
161 else
162 color = UIColors.CONTRAST_COLOR.PackToInt();
163
164 foreach(int id, SCR_XPInfoWidgetData widgetData: m_Widgets)
165 {
166 widgetData.RecolorXPBar(color);
167 }
168 }
169
170 //------------------------------------------------------------------------------------------------
171 protected void RecolorXPText()
172 {
173 foreach(int id, SCR_XPInfoWidgetData widgetData: m_Widgets)
174 {
175 widgetData.RecolorXPText();
176 }
177 }
178
179 //------------------------------------------------------------------------------------------------
180 protected void HideHUD()
181 {
182 Show(false, UIConstants.FADE_RATE_SLOW);
183 m_bIsHUDbarActive = false;
184 }
185
186 //------------------------------------------------------------------------------------------------
187 protected void ShowXPInfo(int totalXP, SCR_EXPRewards rewardID, int XP, bool volunteer, bool profileUsed, int skillLevel)
188 {
189 if (!m_bIsInfoAllowed)
190 return;
191
192 m_bIsHUDbarActive = true;
194
195 bool toggled = (XP == 0);
196 bool nonSpecific = (rewardID == SCR_EXPRewards.UNDEFINED);
197 bool notify = !nonSpecific && m_PlayerXPComponent.AllowNotification(rewardID);
198
199 // XP has been added without specified source, don't show UI (i.e. XP sync upon reconnect)
200 if (nonSpecific && !toggled)
201 return;
202
203 SCR_Faction faction = SCR_Faction.Cast(SCR_FactionManager.SGetLocalPlayerFaction());
204
205 if (!faction)
206 return;
207
208 m_FactionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
209
210 if (!m_FactionManager)
211 return;
212
213 SCR_RankContainer ranks = m_FactionManager.GetFactionRanks(m_PlayerController.GetPlayerId());
214
215 m_ECurrentRank = ranks.GetRankByXP(totalXP);
216 SCR_ECharacterRank nextRank = ranks.GetNextRank(m_ECurrentRank);
217
218 m_EReward = rewardID;
220 m_sNextRankIcon = ranks.GetRankInsignia(nextRank);
222 m_sRewardName = m_PlayerXPComponent.GetXPRewardName(rewardID);
223 m_EPrevRank = ranks.GetRankByXP(totalXP - XP);
224
225 foreach(int id, SCR_XPInfoWidgetData widgetData: m_Widgets)
226 {
227 widgetData.UpdateXPTexts(toggled, volunteer, XP, totalXP, notify, m_EReward, ranks, m_ECurrentRank, m_sCurrentRankIcon, m_sCurrentRankName, m_sNextRankIcon, m_sRewardName);
228 widgetData.UpdateXPProgressBar(m_ECurrentRank, m_EPrevRank, XP, totalXP, notify, ranks);
229 }
230
231 // Show skill info
232 // Disabled for now, funcitonality is being transfered to SCR_PlayerData
233 /*
234 if (profileUsed && XP > 0)
235 {
236 LocalizedString skillName;
237
238 switch (m_PlayerXPComponent.GetXPRewardSkill(rewardID))
239 {
240 case EProfileSkillID.WEAPON_HANDLER: {skillName = "#AR-Campaign_SkillWeaponSpecialist"; break;};
241 case EProfileSkillID.DRIVER: {skillName = "#AR-Campaign_SkillDriver"; break;};
242 case EProfileSkillID.SCOUT: {skillName = "#AR-Campaign_SkillScout"; break;};
243 case EProfileSkillID.OPERATOR: {skillName = "#AR-Campaign_SkillOperator"; break;};
244 }
245
246 if (!skillName.IsEmpty())
247 m_wSkill.SetTextFormat("#AR-Campaign_LevelInfo", skillName, skillLevel);
248 }
249 */
250
251 // We updated the UI even if we don't want to show it at this point
252 // This way it's up to date when it gets toggled manually later
253 if (!notify && !toggled)
254 return;
255
256 // Show the UI
257 Show(true);
258
259 if (!toggled)
260 {
261 // Hide and recolor the UI after a while
262 ScriptCallQueue queue = GetGame().GetCallqueue();
263 queue.Remove(HideHUD);
264 queue.Remove(RecolorXPBar);
265 queue.Remove(RecolorXPText);
266
267 queue.CallLater(HideHUD, XP_INFO_DURATION);
268
270 return;
271
272 int currentXP = m_PlayerXPHandlerComp.GetPlayerXP();
273
274 //If it's renagade rank it should stay the same color (red)
275 if (XP < 0 && ranks.IsRankRenegade(m_ECurrentRank))
276 return;
277
278 queue.CallLater(RecolorXPBar, XP_INFO_DURATION);
279 queue.CallLater(RecolorXPText, XP_INFO_DURATION);
280 }
281 }
282
283 //------------------------------------------------------------------------------------------------
284 void ToggleXPInfo(bool visible)
285 {
286 // Make sure UI is not hidden automatically if shown a moment before
287 GetGame().GetCallqueue().Remove(HideHUD);
288
289 if (visible)
290 {
292 return;
293
294 ShowXPInfo(m_PlayerXPHandlerComp.GetPlayerXP(), SCR_EXPRewards.UNDEFINED, 0, false, false, 0);
295 }
296 else
297 {
298 Show(false, UIConstants.FADE_RATE_SUPER_FAST);
299 }
300 }
301
302 //------------------------------------------------------------------------------------------------
303 protected void UpdateData()
304 {
305 SCR_Faction faction = SCR_Faction.Cast(SCR_FactionManager.SGetLocalPlayerFaction());
306
307 if (!faction)
308 return;
309
310 SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
311
312 if (!factionManager)
313 return;
314
315 SCR_RankContainer ranks = factionManager.GetFactionRanks(m_PlayerController.GetPlayerId());
316
318 return;
319
320 int totalXP = m_PlayerXPHandlerComp.GetPlayerXP();
321
322 m_ECurrentRank = ranks.GetRankByXP(totalXP);
323 SCR_ECharacterRank nextRank = ranks.GetNextRank(m_ECurrentRank);
324
325 m_EReward = SCR_EXPRewards.UNDEFINED;
329 m_EPrevRank = ranks.GetRankByXP(totalXP);
330 }
331
332 //------------------------------------------------------------------------------------------------
335 {
336 return RANK_ICON_IMAGESET;
337 }
338
339 //------------------------------------------------------------------------------------------------
341 {
343 if (taskManager)
344 taskManager.GetOnTaskHUDVisible().Remove(ToggleXPInfo);
345 }
346};
347
353
354class SCR_XPInfoWidgetData
355{
356 protected const string STRING_REWARD_VOLUNTEER = "#AR-Campaign_RewardBonus_Volunteer";
357
367
368 void InitWidgets(notnull Widget root)
369 {
370 m_wTitle = TextWidget.Cast(root.FindAnyWidget("InfoText"));
371 m_wRank = TextWidget.Cast(root.FindAnyWidget("Rank"));
372 m_wRankIcon = ImageWidget.Cast(root.FindAnyWidget("RankIcon"));
373 m_wNextRankIcon = ImageWidget.Cast(root.FindAnyWidget("NextRankIcon"));
374 m_wNextRankArrowIcon = ImageWidget.Cast(root.FindAnyWidget("NextRankArrowIcon"));
375 m_wRankNoIcon = TextWidget.Cast(root.FindAnyWidget("RankNoIcon"));
376 m_wProgress = ProgressBarWidget.Cast(root.FindAnyWidget("XPProgress"));
377 m_wProgressDiff = ProgressBarWidget.Cast(root.FindAnyWidget("XPProgressDiff"));
378 m_wSkill = TextWidget.Cast(root.FindAnyWidget("Skill"));
379
380 m_wProgress.SetColor(Color.FromInt(UIColors.CONTRAST_COLOR.PackToInt()));
381 }
382
383 //------------------------------------------------------------------------------------------------
384 void RecolorXPBar(int color)
385 {
386 AnimateWidget.Color(m_wProgressDiff, Color.FromInt(color), UIConstants.FADE_RATE_SLOW);
387 }
388
389 //------------------------------------------------------------------------------------------------
391 {
392 AnimateWidget.Color(m_wTitle, Color.FromInt(UIColors.NEUTRAL_INFORMATION.PackToInt()), UIConstants.FADE_RATE_SLOW);
393 }
394
395 //------------------------------------------------------------------------------------------------
396 void UpdateXPTexts(bool toggled, bool volunteer, int XP, int totalXP, bool notify, SCR_EXPRewards rewardID, notnull SCR_RankContainer ranks, SCR_ECharacterRank currentRank, string rankIconName, string rankText, string nextRankIconName, string rewardName)
397 {
398 if (rankIconName.IsEmpty())
399 {
400 m_wRankNoIcon.SetTextFormat(rankText);
401 m_wRankIcon.SetVisible(false);
402 m_wRank.SetTextFormat(string.Empty);
403 }
404 else
405 {
406 m_wRankNoIcon.SetText(string.Empty);
407 m_wRankIcon.LoadImageFromSet(0, SCR_XPInfoDisplay.GetRankIconImageSet(), rankIconName);
408 m_wRankIcon.SetColor(Color.FromInt(UIColors.NEUTRAL_INFORMATION.PackToInt()));
409 m_wRankIcon.SetVisible(true);
410 m_wRank.SetTextFormat(rankText);
411 }
412
413 if (m_wNextRankIcon)
414 {
415 if (nextRankIconName.IsEmpty())
416 {
417 m_wNextRankIcon.SetVisible(false);
418 m_wNextRankArrowIcon.SetVisible(false);
419 }
420 else
421 {
422 m_wNextRankIcon.SetVisible(true);
423 m_wNextRankArrowIcon.SetVisible(true);
424
425 m_wNextRankIcon.LoadImageFromSet(0, SCR_XPInfoDisplay.GetRankIconImageSet(), nextRankIconName);
426 m_wNextRankIcon.SetColor(Color.FromInt(UIColors.NEUTRAL_INFORMATION.PackToInt()));
427 }
428 }
429
430 if (toggled || !notify)
431 {
432 m_wTitle.SetText(string.Empty);
433 m_wProgressDiff.SetColor(Color.FromInt(UIColors.IDLE_DISABLED.PackToInt()));
434 }
435 else
436 {
437 if (volunteer)
438 m_wTitle.SetTextFormat(STRING_REWARD_VOLUNTEER, rewardName);
439 else
440 m_wTitle.SetTextFormat(rewardName);
441
442 //Setting the color of the ProgressDifference bar based on the increase/decrease in XP
443 Color titleColor;
444 Color barColor;
445
446 if (XP < 0 || ranks.IsRankRenegade(currentRank))
447 {
448 titleColor = UIColors.WARNING;
449 barColor = UIColors.WARNING;
450 }
451 else if (XP == 0)
452 {
453 titleColor = UIColors.NEUTRAL_INFORMATION;
454 barColor = UIColors.IDLE_DISABLED;
455 }
456 else
457 {
458 titleColor = UIColors.CONFIRM;
459 barColor = UIColors.CONFIRM;
460 }
461
462 m_wTitle.SetColor(Color.FromInt(titleColor.PackToInt()));
463 m_wProgressDiff.SetColor(Color.FromInt(barColor.PackToInt()));
464 }
465 }
466
467 //------------------------------------------------------------------------------------------------
468 void UpdateInventoryBarColor(SCR_ECharacterRank currentRank, int XP, notnull SCR_RankContainer ranks)
469 {
470 //If renegade rank, the bar should always be red
471 if (ranks.IsRankRenegade(currentRank))
472 {
473 m_wTitle.SetColor(Color.FromInt(UIColors.WARNING.PackToInt()));
474 m_wProgressDiff.SetColor(Color.FromInt(UIColors.WARNING.PackToInt()));
475 }
476 else
477 {
478 m_wTitle.SetColor(Color.FromInt(UIColors.NEUTRAL_INFORMATION.PackToInt()));
479 m_wProgressDiff.SetColor(Color.FromInt(UIColors.IDLE_DISABLED.PackToInt()));
480 }
481 }
482
483 //------------------------------------------------------------------------------------------------
484 void UpdateXPProgressBar(SCR_ECharacterRank curRank, SCR_ECharacterRank prevRank, int XP, int totalXP, bool notify, notnull SCR_RankContainer ranks)
485 {
486 if (ranks.GetNextRank(curRank) == SCR_ECharacterRank.INVALID)
487 {
488 // Player at max level, no gain to show
489 m_wProgress.SetMin(0);
490 m_wProgress.SetMax(1);
491 m_wProgress.SetCurrent(1);
492 m_wProgressDiff.SetMin(0);
493 m_wProgressDiff.SetMax(1);
494 m_wProgressDiff.SetCurrent(0);
495 }
496 else
497 {
498 if (ranks.GetPreviousRank(curRank) == SCR_ECharacterRank.INVALID && XP < 0)
499 {
500 // Player is renegade and losing XP, just show red bar
501 m_wProgress.SetMin(0);
502 m_wProgress.SetMax(1);
503 m_wProgress.SetCurrent(0);
504 m_wProgressDiff.SetMin(0);
505 m_wProgressDiff.SetMax(1);
506 m_wProgressDiff.SetCurrent(1);
507 }
508 else
509 {
510 int XPCurRank = ranks.GetRequiredRankXP(curRank);
511 int XPNextRank = ranks.GetRequiredRankXP(ranks.GetNextRank(curRank));
512
513 if (curRank == prevRank)
514 {
515 if (ranks.GetPreviousRank(curRank) != SCR_ECharacterRank.INVALID)
516 {
517 // Standard XP change
518 m_wProgress.SetMin(XPCurRank);
519 m_wProgress.SetMax(XPNextRank);
520 m_wProgressDiff.SetMin(XPCurRank);
521 m_wProgressDiff.SetMax(XPNextRank);
522 }
523 else
524 {
525 // XP change as renegade, show progress towards a normal rank from current XP
526 m_wProgress.SetMin(0);
527 m_wProgress.SetMax(1);
528 m_wProgress.SetCurrent(0);
529 m_wProgressDiff.SetMin(totalXP - XP);
530 m_wProgressDiff.SetMax(XPNextRank);
531 m_wProgressDiff.SetCurrent(totalXP);
532 return;
533 }
534
535 // Progress bar setup
536 if (notify)
537 {
538 if (XP > 0)
539 {
540 m_wProgress.SetCurrent(totalXP - XP);
541 m_wProgressDiff.SetCurrent(totalXP);
542 }
543 else
544 {
545 m_wProgress.SetCurrent(totalXP);
546 m_wProgressDiff.SetCurrent(totalXP - XP);
547 }
548 }
549 else
550 {
551 m_wProgress.SetCurrent(totalXP);
552 }
553 }
554 else
555 {
556 if (curRank > prevRank)
557 {
558 // Promotion
559 m_wProgress.SetMin(0);
560 m_wProgress.SetMax(1);
561 m_wProgress.SetCurrent(0);
562 m_wProgressDiff.SetMin(XPCurRank);
563 m_wProgressDiff.SetMax(XPNextRank);
564 m_wProgressDiff.SetCurrent(totalXP);
565 }
566 else
567 {
568 // Demotion
569 m_wProgress.SetMin(XPCurRank);
570 m_wProgress.SetMax(XPNextRank);
571 m_wProgress.SetCurrent(totalXP);
572 m_wProgressDiff.SetMin(0);
573 m_wProgressDiff.SetMax(1);
574 m_wProgressDiff.SetCurrent(1);
575 }
576 }
577 }
578 }
579 }
580}
@ INVENTORY
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_HUDManagerComponent m_HUDManager
Definition game.c:39
void SCR_FactionManager(IEntitySource src, IEntity parent)
SCR_FastTravelComponentClass m_PlayerController
Widget m_wRoot
string m_sInterfaceSettingName
void RecolorXPText()
void RecolorXPBar(int color)
void UpdateXPTexts(bool toggled, bool volunteer, int XP, int totalXP, bool notify, SCR_EXPRewards rewardID, notnull SCR_RankContainer ranks, SCR_ECharacterRank currentRank, string rankIconName, string rankText, string nextRankIconName, string rewardName)
ImageWidget m_wRankIcon
void UpdateInventoryBarColor(SCR_ECharacterRank currentRank, int XP, notnull SCR_RankContainer ranks)
void UpdateXPProgressBar(SCR_ECharacterRank curRank, SCR_ECharacterRank prevRank, int XP, int totalXP, bool notify, notnull SCR_RankContainer ranks)
TextWidget m_wRank
ImageWidget m_wNextRankArrowIcon
TextWidget m_wTitle
ProgressBarWidget m_wProgressDiff
SCR_EXPInfoWidget
ImageWidget m_wNextRankIcon
TextWidget m_wSkill
enum SCR_EXPInfoWidget STRING_REWARD_VOLUNTEER
ProgressBarWidget m_wProgress
TextWidget m_wRankNoIcon
static WidgetAnimationColor Color(Widget widget, Color color, float speed)
Definition Color.c:13
SCR_ECharacterRank GetNextRank(SCR_ECharacterRank rankID)
bool IsRankRenegade(SCR_ECharacterRank rankID)
SCR_ECharacterRank GetRankByXP(int XP)
string GetRankInsignia(SCR_ECharacterRank rankID)
string GetRankName(SCR_ECharacterRank rankID)
static SCR_TaskManagerUIComponent GetInstance()
SCR_EXPRewards m_EReward
static const int XP_INFO_DURATION
override void DisplayInit(IEntity owner)
bool RemoveWidgetsById(int widgetDataId)
override void OnSettingsChanged()
static ResourceName GetRankIconImageSet()
override bool DisplayStartDrawInit(IEntity owner)
SCR_XPHandlerComponent m_PlayerXPComponent
SCR_ECharacterRank m_EPrevRank
SCR_PlayerXPHandlerComponent m_PlayerXPHandlerComp
static const ResourceName RANK_ICON_IMAGESET
void ToggleXPInfo(bool visible)
SCR_FactionManager m_FactionManager
SCR_ECharacterRank m_ECurrentRank
void AllowShowingInfo(bool allow)
override void DisplayStartDraw(IEntity owner)
void ShowXPInfo(int totalXP, SCR_EXPRewards rewardID, int XP, bool volunteer, bool profileUsed, int skillLevel)
void AddNewWidgets(notnull SCR_XPInfoWidgetData hudXPWidget, int id)
ref map< int, ref SCR_XPInfoWidgetData > m_Widgets
ScriptCallQueue Class provide "lazy" calls - when we don't want to execute function immediately but l...
Definition tools.c:53
Definition Types.c:486
override void Show()
Definition gameLib.c:262