Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_XPInfoDisplay.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
2 class SCR_XPInfoDisplay : SCR_InfoDisplayExtended
3 {
4  protected static const int XP_INFO_DURATION = 10000; //ms
5  protected static const ResourceName RANK_ICON_IMAGESET = "{5D7F0C1AB551F610}UI/Textures/MilitaryIcons/MilitaryIcons.imageset";
6 
7  protected bool m_bNegativeXP;
8  protected bool m_bInitDone;
9  protected bool m_bIsInfoAllowed = true;
10 
11  protected SCR_XPHandlerComponent m_PlayerXPComponent;
12 
13  protected TextWidget m_wTitle;
14  protected TextWidget m_wRank;
15  protected TextWidget m_wRankNoIcon;
16  protected TextWidget m_wSkill;
17  protected ImageWidget m_wRankIcon;
18  protected ProgressBarWidget m_wProgress;
19  protected ProgressBarWidget m_wProgressDiff;
20 
21  //------------------------------------------------------------------------------------------------
22  override void DisplayInit(IEntity owner)
23  {
24  super.DisplayInit(owner);
25 
26  BaseGameMode gameMode = GetGame().GetGameMode();
27 
28  if (!gameMode)
29  return;
30 
31  m_PlayerXPComponent = SCR_XPHandlerComponent.Cast(gameMode.FindComponent(SCR_XPHandlerComponent));
32  }
33 
34  //------------------------------------------------------------------------------------------------
35  override bool DisplayStartDrawInit(IEntity owner)
36  {
37  return (m_PlayerXPComponent != null);
38  }
39 
40  //------------------------------------------------------------------------------------------------
41  override void DisplayStartDraw(IEntity owner)
42  {
43  if (m_bInitDone)
44  return;
45 
46  m_bInitDone = true;
47 
48  SCR_PlayerXPHandlerComponent comp = SCR_PlayerXPHandlerComponent.Cast(owner.FindComponent(SCR_PlayerXPHandlerComponent));
49 
50  if (comp)
51  comp.GetOnXPChanged().Insert(ShowXPInfo);
52 
53  SCR_UITaskManagerComponent.s_OnTaskListVisible.Insert(ToggleXPInfo);
54 
55  m_wTitle = TextWidget.Cast(m_wRoot.FindWidget("Title"));
56  m_wRank = TextWidget.Cast(m_wRoot.FindWidget("Rank"));
57  m_wRankNoIcon = TextWidget.Cast(m_wRoot.FindWidget("RankNoIcon"));
58  m_wRankIcon = ImageWidget.Cast(m_wRoot.FindWidget("RankIcon"));
59  m_wSkill = TextWidget.Cast(m_wRoot.FindWidget("Skill"));
60  m_wProgress = ProgressBarWidget.Cast(m_wRoot.FindWidget("Progress"));
61  m_wProgressDiff = ProgressBarWidget.Cast(m_wRoot.FindWidget("ProgressDiff"));
62 
63  m_wProgress.SetColor(Color.FromInt(UIColors.CONTRAST_COLOR.PackToInt()));
64  }
65 
66  //------------------------------------------------------------------------------------------------
67  protected void RecolorXPBar()
68  {
69  AnimateWidget.Color(m_wProgressDiff, Color.FromInt(UIColors.CONTRAST_COLOR.PackToInt()), UIConstants.FADE_RATE_SLOW);
70  }
71 
72  //------------------------------------------------------------------------------------------------
73  void AllowShowingInfo(bool allow)
74  {
75  m_bIsInfoAllowed = allow;
76  }
77 
78  //------------------------------------------------------------------------------------------------
79  protected void HideHUD()
80  {
81  Show(false, UIConstants.FADE_RATE_SLOW)
82  }
83 
84  //------------------------------------------------------------------------------------------------
85  protected void ShowXPInfo(int totalXP, SCR_EXPRewards rewardID, int XP, bool volunteer, bool profileUsed, int skillLevel)
86  {
87  if (!m_bIsInfoAllowed)
88  return;
89 
90  bool toggled = (XP == 0);
91  bool nonSpecific = (rewardID == SCR_EXPRewards.UNDEFINED);
92  bool notify = !nonSpecific && m_PlayerXPComponent.AllowNotification(rewardID);
93 
94  // XP has been added without specified source, don't show UI (i.e. XP sync upon reconnect)
95  if (nonSpecific && !toggled)
96  return;
97 
98  SCR_Faction faction = SCR_Faction.Cast(SCR_FactionManager.SGetLocalPlayerFaction());
99 
100  if (!faction)
101  return;
102 
103  SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
104 
105  if (!factionManager)
106  return;
107 
108  SCR_ECharacterRank curRank = factionManager.GetRankByXP(totalXP);
109  SCR_ECharacterRank prevRank = factionManager.GetRankByXP(totalXP - XP);
110  string rankText = faction.GetRankName(curRank);
111  string rankIconName = faction.GetRankInsignia(curRank);
112 
113  if (rankIconName.IsEmpty())
114  {
115  m_wRankNoIcon.SetTextFormat(rankText);
116  m_wRankIcon.SetVisible(false);
117  m_wRank.SetTextFormat(string.Empty);
118  }
119  else
120  {
121  m_wRankNoIcon.SetText(string.Empty);
122  m_wRankIcon.LoadImageFromSet(0, RANK_ICON_IMAGESET, rankIconName);
123  m_wRankIcon.SetColor(Color.FromInt(UIColors.CONTRAST_COLOR.PackToInt()));
124  m_wRankIcon.SetVisible(true);
125  m_wRank.SetTextFormat(rankText);
126  }
127 
128  int showXP = XP;
129  m_bNegativeXP = false;
130 
131  if (toggled || !notify)
132  {
133  // We are just showing info on current XP, no change was made - hide reward name
134  m_wTitle.SetText(string.Empty);
135  }
136  else
137  {
138  if (volunteer)
139  m_wTitle.SetTextFormat("#AR-Campaign_RewardBonus_Volunteer", m_PlayerXPComponent.GetXPRewardName(rewardID));
140  else
141  m_wTitle.SetTextFormat(m_PlayerXPComponent.GetXPRewardName(rewardID));
142 
143  // Show green portion of the progress bar when XP gets added, red portion if substracted
144  if (XP > 0)
145  {
146  m_wTitle.SetColor(Color.FromInt(UIColors.CONFIRM.PackToInt()));
147  m_wProgressDiff.SetColor(Color.FromInt(UIColors.CONFIRM.PackToInt()));
148  }
149  else
150  {
151  m_wTitle.SetColor(Color.FromInt(UIColors.WARNING.PackToInt()));
152  m_wProgressDiff.SetColor(Color.FromInt(UIColors.WARNING.PackToInt()));
153  m_bNegativeXP = true;
154  }
155  }
156 
157  UpdateXPProgressBar(factionManager, curRank, prevRank, XP, totalXP, notify);
158 
159  // Show skill info
160  // Disabled for now, funcitonality is being transfered to SCR_PlayerData
161  /*if (XP > 0 && profileUsed)
162  {
163  LocalizedString skillName;
164 
165  switch (m_PlayerXPComponent.GetXPRewardSkill(rewardID))
166  {
167  case EProfileSkillID.WEAPON_HANDLER: {skillName = "#AR-Campaign_SkillWeaponSpecialist"; break;};
168  case EProfileSkillID.DRIVER: {skillName = "#AR-Campaign_SkillDriver"; break;};
169  case EProfileSkillID.SCOUT: {skillName = "#AR-Campaign_SkillScout"; break;};
170  case EProfileSkillID.OPERATOR: {skillName = "#AR-Campaign_SkillOperator"; break;};
171  }
172 
173  if (!skillName.IsEmpty())
174  m_wSkill.SetTextFormat("#AR-Campaign_LevelInfo", skillName, skillLevel);
175  }*/
176 
177  // We updated the UI even if we don't want to show it at this point
178  // This way it's up to date when it gets toggled manually later
179  if (!notify && !toggled)
180  return;
181 
182  // Show the UI
183  Show(true);
184 
185  if (!toggled)
186  {
187  // Hide the UI after a while
188  GetGame().GetCallqueue().Remove(HideHUD);
189  GetGame().GetCallqueue().Remove(RecolorXPBar);
190  GetGame().GetCallqueue().CallLater(HideHUD, XP_INFO_DURATION);
191  GetGame().GetCallqueue().CallLater(RecolorXPBar, XP_INFO_DURATION * 0.7);
192  }
193  }
194 
195  //------------------------------------------------------------------------------------------------
196  protected void UpdateXPProgressBar(notnull SCR_FactionManager factionManager, SCR_ECharacterRank curRank, SCR_ECharacterRank prevRank, int XP, int totalXP, bool notify)
197  {
198  if (factionManager.GetRankNext(curRank) == SCR_ECharacterRank.INVALID)
199  {
200  // Player at max level, no gain to show
201  m_wProgress.SetMin(0);
202  m_wProgress.SetMax(1);
203  m_wProgress.SetCurrent(1);
204  m_wProgressDiff.SetMin(0);
205  m_wProgressDiff.SetMax(1);
206  m_wProgressDiff.SetCurrent(0);
207  }
208  else
209  {
210  if (factionManager.GetRankPrev(curRank) == SCR_ECharacterRank.INVALID && XP < 0)
211  {
212  // Player is renegade and losing XP, just show red bar
213  m_wProgress.SetMin(0);
214  m_wProgress.SetMax(1);
215  m_wProgress.SetCurrent(0);
216  m_wProgressDiff.SetMin(0);
217  m_wProgressDiff.SetMax(1);
218  m_wProgressDiff.SetCurrent(1);
219  }
220  else
221  {
222  int XPCurRank = factionManager.GetRequiredRankXP(curRank);
223  int XPNextRank = factionManager.GetRequiredRankXP(factionManager.GetRankNext(curRank));
224 
225  if (curRank == prevRank)
226  {
227  if (factionManager.GetRankPrev(curRank) != SCR_ECharacterRank.INVALID)
228  {
229  // Standard XP change
230  m_wProgress.SetMin(XPCurRank);
231  m_wProgress.SetMax(XPNextRank);
232  m_wProgressDiff.SetMin(XPCurRank);
233  m_wProgressDiff.SetMax(XPNextRank);
234  }
235  else
236  {
237  // XP change as renegade, show progress towards a normal rank from current XP
238  m_wProgress.SetMin(totalXP - XP);
239  m_wProgress.SetMax(totalXP - XP + 1);
240  m_wProgressDiff.SetMin(totalXP - XP);
241  m_wProgressDiff.SetMax(XPNextRank);
242  }
243 
244  // Progress bar setup
245  if (notify)
246  {
247  if (XP > 0)
248  {
249  m_wProgress.SetCurrent(totalXP - XP);
250  m_wProgressDiff.SetCurrent(totalXP);
251  }
252  else
253  {
254  m_wProgress.SetCurrent(totalXP);
255  m_wProgressDiff.SetCurrent(totalXP - XP);
256  }
257  }
258  else
259  {
260  m_wProgress.SetCurrent(totalXP);
261  }
262  }
263  else
264  {
265  if (curRank > prevRank)
266  {
267  // Promotion
268  m_wProgress.SetMin(0);
269  m_wProgress.SetMax(1);
270  m_wProgress.SetCurrent(0);
271  m_wProgressDiff.SetMin(XPCurRank);
272  m_wProgressDiff.SetMax(XPNextRank);
273  m_wProgressDiff.SetCurrent(totalXP);
274  }
275  else
276  {
277  // Demotion
278  m_wProgress.SetMin(XPCurRank);
279  m_wProgress.SetMax(XPNextRank);
280  m_wProgress.SetCurrent(totalXP);
281  m_wProgressDiff.SetMin(0);
282  m_wProgressDiff.SetMax(1);
283  m_wProgressDiff.SetCurrent(1);
284  }
285  }
286  }
287  }
288  }
289 
290  //------------------------------------------------------------------------------------------------
291  void ToggleXPInfo(bool visible)
292  {
293  // Make sure UI is not hidden automatically if shown a moment before
294  GetGame().GetCallqueue().Remove(HideHUD);
295 
296  if (visible)
297  {
298  SCR_PlayerXPHandlerComponent comp = SCR_PlayerXPHandlerComponent.Cast(m_PlayerController.FindComponent(SCR_PlayerXPHandlerComponent));
299 
300  if (!comp)
301  return;
302 
303  int totalXP = comp.GetPlayerXP();
304 
305  ShowXPInfo(totalXP, SCR_EXPRewards.UNDEFINED, 0, false, false, 0);
306  }
307  else
308  {
309  Show(false, UIConstants.FADE_RATE_SUPER_FAST);
310  }
311  }
312 
313  //------------------------------------------------------------------------------------------------
314  void ~SCR_XPInfoDisplay()
315  {
316  SCR_UITaskManagerComponent.s_OnTaskListVisible.Remove(ToggleXPInfo);
317  }
318 };
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
UIConstants
Definition: Constants.c:130
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_ECharacterRank
SCR_ECharacterRank
Definition: SCR_CharacterRankComponent.c:305
SCR_UITaskManagerComponent
void SCR_UITaskManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_UITaskManagerComponent.c:1096
Show
override void Show(WorkspaceWidget pWorkspace, Widget pToolTipWidget, float desiredPosX, float desiredPosY)
Definition: SCR_ScriptedWidgetTooltip.c:55
SCR_XPInfoDisplay
Definition: SCR_XPInfoDisplay.c:2
UIColors
Definition: Constants.c:16
SCR_EXPRewards
SCR_EXPRewards
Definition: SCR_XPHandlerComponent.c:403
m_PlayerController
SCR_CampaignNetworkComponentClass m_PlayerController
Takes care of Campaign-specific server <> client communication and requests.
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
SCR_Faction
Definition: SCR_Faction.c:6