Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CareerSpecializationsUI.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
2 class SCR_CareerSpecializationsUI : ScriptedWidgetComponent
3 {
4  protected Widget m_wRootWidget;
5  protected Widget m_wCareerLeftSide;
6  protected Widget m_wCareerRightSide;
7  protected Widget m_wSpiderNet;
8  protected SCR_SpiderNet m_SpiderNetHandler;
9 
10  //Controller navigation buttons
11  protected Widget m_wPagingButtons;
12  SCR_InputButtonComponent m_HandlerChangeSpLeft;
13  SCR_InputButtonComponent m_HandlerChangeSpRight;
14 
15  protected SCR_PlayerData m_PlayerData;
16 
17  protected ref array<Widget> m_aSpecializationsStatsWidgets = {};
18 
19  RichTextWidget m_twSpecializationTitle, m_twSpecializationProgress;
20  protected SCR_ProgressBarWithSegments m_SpecializationBar;
21 
22  protected int m_iSelectedLegend = 0;
23  protected ref array<SCR_ButtonLegendComponent> m_aSpLegendButtonHandlers = {};
24  protected ref array<SCR_ButtonSpecializationProgressComponent> m_aSpProgressButtonHandlers = {};
25 
26  [Attribute(params: "SpecializationProgress layout")]
27  protected ResourceName m_sSpProgressLayout;
28 
29  protected ResourceName m_sStatsLayout;
30  protected ResourceName m_sHeaderStatsLayout;
31  protected ResourceName m_sProgressionStatsLayout;
32 
33  protected bool m_bShowProgression = false;
34 
35  //------------------------------------------------------------------------------------------------
36  protected override void HandlerAttached(Widget w)
37  {
38  m_wRootWidget = w;
39 
40  m_wCareerLeftSide = m_wRootWidget.FindAnyWidget("CareerLeftSide");
41  m_wCareerRightSide = m_wRootWidget.FindAnyWidget("CareerRightSide");
42 
43  if (!m_wCareerLeftSide || !m_wCareerRightSide)
44  return;
45 
46  m_wSpiderNet = m_wCareerLeftSide.FindAnyWidget("SpiderNet0");
47  if (!m_wSpiderNet)
48  return;
49 
50  m_SpiderNetHandler = SCR_SpiderNet.Cast(m_wSpiderNet.FindHandler(SCR_SpiderNet));
51  if (!m_SpiderNetHandler)
52  return;
53 
54  m_wPagingButtons = m_wCareerLeftSide.FindAnyWidget("PagingButtons");
55 
56  if (!m_wPagingButtons)
57  return;
58 
59  Widget navLeft = m_wPagingButtons.FindAnyWidget("NavigationButtonNextSp");
60  Widget navRight = m_wPagingButtons.FindAnyWidget("NavigationButtonPrevSp");
61 
62  if (!navLeft || !navRight)
63  return;
64 
65  m_HandlerChangeSpLeft = SCR_InputButtonComponent.Cast(navLeft.FindHandler(SCR_InputButtonComponent));
66  m_HandlerChangeSpRight = SCR_InputButtonComponent.Cast(navRight.FindHandler(SCR_InputButtonComponent));
67 
68  if (!m_HandlerChangeSpLeft || !m_HandlerChangeSpRight)
69  return;
70 
71  //Navigation actions found in the CareerProfileContext and also in the EndgameScreenContext
72  m_HandlerChangeSpLeft.m_OnActivated.Insert(NavLeft);
73  m_HandlerChangeSpRight.m_OnActivated.Insert(NavRight);
74  }
75 
76  //------------------------------------------------------------------------------------------------
77  protected void NavLeft(SCR_InputButtonComponent handler, string action)
78  {
79  int next = m_iSelectedLegend + 1;
80  if (next >= m_aSpLegendButtonHandlers.Count())
81  next = 0;
82  UpdateSpecialization(next);
83  }
84 
85  //------------------------------------------------------------------------------------------------
86  protected void NavRight(SCR_InputButtonComponent handler, string action)
87  {
88  int prev = m_iSelectedLegend - 1;
89  if (prev < 0)
90  prev = m_aSpLegendButtonHandlers.Count() - 1;
91  UpdateSpecialization(prev);
92  }
93 
94  //------------------------------------------------------------------------------------------------
95  void SetShowProgression(bool b)
96  {
97  m_bShowProgression = b;
98  }
99 
100  //------------------------------------------------------------------------------------------------
101  void FillSpecializations(SCR_PlayerData playerData, ResourceName statsLayout, ResourceName headerStatsLayout, ResourceName progressionStatsLayout)
102  {
103  if (!playerData)
104  return;
105 
106  m_PlayerData = playerData;
107  m_sStatsLayout = statsLayout;
108  m_sHeaderStatsLayout = headerStatsLayout;
109  m_sProgressionStatsLayout = progressionStatsLayout;
110 
111  m_SpiderNetHandler.RegisterCareerProfileHandler(this);
112  array<float> SpPoints = {};
113 
114  //Prepare vertices for the spidernet
115  m_PlayerData.FillArrayWithSpecializationPoints(SpPoints);
116  m_SpiderNetHandler.SetSpPoints(SpPoints);
117 
118  //Progression with previous stats?
119  if (m_bShowProgression)
120  {
121  //Prepare old vertices for the spidernet
122  SpPoints.Clear();
123  m_PlayerData.FillArrayWithSpecializationPoints(SpPoints, false);
124  m_SpiderNetHandler.SetSpPoints(SpPoints, false);
125 
126  m_PlayerData.PrepareSpecializationProgressionStatsDisplay();
127  }
128  else
129  {
130  m_PlayerData.PrepareSpecializationStatsDisplay();
131  }
132 
133  SetUpSpecializationDisplay();
134  //Draw spidernet
135  m_SpiderNetHandler.DrawSpiderNet();
136  }
137 
140  //------------------------------------------------------------------------------------------------
141  protected void SetUpSpecializationDisplay()
142  {
143  Widget specializationProgressWidget = m_wCareerLeftSide.FindAnyWidget("SpecializationsSummary");
144  Widget specializationsPanelWidget = m_wCareerRightSide.FindAnyWidget("SpecializationsPanel");
145  if (!specializationProgressWidget || !specializationsPanelWidget)
146  return;
147 
148  //Specializations Panel
149  m_twSpecializationTitle = RichTextWidget.Cast(specializationsPanelWidget.FindAnyWidget("SpecializationTitleText"));
150  m_twSpecializationProgress = RichTextWidget.Cast(specializationsPanelWidget.FindAnyWidget("SpecializationProgressText"));
151  m_SpecializationBar = SCR_ProgressBarWithSegments.Cast(SCR_WLibProgressBarComponent.GetProgressBar("SpecializationBar", specializationsPanelWidget, true));
152 
153  m_SpecializationBar.SetMin(0);
154  m_SpecializationBar.SetMax(SCR_PlayerDataConfigs.SPECIALIZATION_MAX);
155 
156  //Specializations Progress Summary
157  Widget progressLeft = specializationProgressWidget.FindAnyWidget("LeftSpecializations");
158  Widget progressRight = specializationProgressWidget.FindAnyWidget("RightSpecializations");
159 
160  if (!progressLeft || !progressRight)
161  return;
162 
163  Widget tempWidget;
164 
165  int tempCount;
166  int maxCount = m_PlayerData.GetSpecializationCount(0);
167  int i;
168  int specializationsCount = SCR_PlayerDataConfigs.GetInstance().SPECIALIZATIONS_COUNT;
169 
170  if (specializationsCount % 2 != 0)
171  specializationsCount += 1;
172 
173  for (i = 0; i < specializationsCount; i++)
174  {
175  tempCount = m_PlayerData.GetSpecializationCount(i);
176  maxCount = Math.Max(tempCount, maxCount);
177 
178  if (i < specializationsCount * 0.5)
179  tempWidget = progressLeft;
180  else
181  tempWidget = progressRight;
182 
183  CreateSpecializationProgressButtonWidget(tempWidget, i);
184  }
185 
186  for (i = 0; i < maxCount; i++)
187  {
188  Widget tempW;
189 
190  if (!m_bShowProgression)
191  tempW = SCR_CareerUI.CreateStatEntry(specializationsPanelWidget, m_sStatsLayout);
192  else
193  tempW = SCR_CareerUI.CreateProgressionStatEntry(specializationsPanelWidget, m_sProgressionStatsLayout);
194 
195  if (tempW)
196  m_aSpecializationsStatsWidgets.Insert(tempW);
197  }
198  }
199 
200  //------------------------------------------------------------------------------------------------
201  protected void UpdateSpecializationPanel(int n)
202  {
203  if (n < 0 || n >= SCR_PlayerDataConfigs.GetInstance().SPECIALIZATIONS_COUNT || !m_twSpecializationTitle || !m_twSpecializationProgress)
204  return;
205 
206  string title = ""+(n+ 1)+". "+SCR_PlayerDataConfigs.GetInstance().GetSpecializationName(n);
207  float value = m_PlayerData.GetSpecializationPoints(n) * SCR_PlayerDataConfigs.SPPOINTS_CONVERSIONPERCENTAGE;
208 
209  m_twSpecializationTitle.SetText(title);
210  m_twSpecializationProgress.SetText(""+value.ToString(-1, 2)+"%");
211 
212  float warCrimes = 0;
213  array<float> EarntPoints;
214 
215  if (m_bShowProgression)
216  {
217  if (!m_PlayerData.IsDataProgressionReady())
218  return;
219  EarntPoints = m_PlayerData.GetArrayEarntPoints();
220 
221  if (m_PlayerData.GetStat(SCR_EDataStats.WARCRIMES) != 0)
222  warCrimes = SCR_PlayerDataConfigs.WARCRIMES_PUNISHMENT;
223 
224  int spEnumId;
225  switch (n)
226  {
227  case 0: spEnumId = SCR_EDataStats.SPPOINTS0;
228  break;
229  case 1: spEnumId = SCR_EDataStats.SPPOINTS1;
230  break;
231  case 2: spEnumId = SCR_EDataStats.SPPOINTS2;
232  break;
233  default: return;
234  }
235  float original = m_PlayerData.GetSpecializationPoints(n, false);
236  float minus = EarntPoints[spEnumId] * warCrimes;
237  float progressed = EarntPoints[spEnumId] - minus;
238 
239  m_SpecializationBar.SetProgressBarValues(original, progressed, minus);
240  }
241  else
242  {
243  m_SpecializationBar.SetValue(value);
244  }
245 
246  int numStats = SCR_PlayerDataConfigs.GetInstance().GetSpecializationStatsCount(n);
247  SpecializationStatsSetVisible(numStats);
248 
249  array<ref SCR_PlayerDataSpecializationDisplay> statsToDisplay = SCR_PlayerDataConfigs.GetInstance().GetSpecializationArray(n);
250 
251  for (int i = 0; i < numStats; i++)
252  {
253  if (m_bShowProgression)
254  SCR_CareerUI.UpdateStatProgressionEntry(m_aSpecializationsStatsWidgets[i], statsToDisplay[i].GetTitle(), EarntPoints[statsToDisplay[i].GetEnumId()] * warCrimes, EarntPoints[statsToDisplay[i].GetEnumId()], statsToDisplay[i].GetUnits(), ""+statsToDisplay[i].GetValue());
255  else
256  SCR_CareerUI.UpdateStatEntry(m_aSpecializationsStatsWidgets[i], statsToDisplay[i].GetTitle(), statsToDisplay[i].GetUnits(), ""+statsToDisplay[i].GetValue());
257  }
258  }
259 
261  //------------------------------------------------------------------------------------------------
262  protected void SpecializationStatsSetVisible(int n)
263  {
264  int statWidgetsCount = m_aSpecializationsStatsWidgets.Count();
265 
266  if (n < 0 || n > statWidgetsCount)
267  return;
268 
269  int i;
270 
271  //Make n stats visible
272  for (i = 0; i < n; i++)
273  {
274  m_aSpecializationsStatsWidgets[i].SetVisible(true);
275  }
276 
277  //Make the remaining ones invisible
278  for (i = n; i < statWidgetsCount; i++)
279  {
280  m_aSpecializationsStatsWidgets[i].SetVisible(false);
281  }
282  }
283 
286  //------------------------------------------------------------------------------------------------
287  void UpdateSpecialization(int specializationId)
288  {
289  if (!m_aSpecializationsStatsWidgets || m_aSpecializationsStatsWidgets.IsEmpty() || !m_aSpLegendButtonHandlers ||m_aSpLegendButtonHandlers.IsEmpty())
290  return;
291 
292  //Deactivate old selected legend
293  m_aSpLegendButtonHandlers[m_iSelectedLegend].Deactivate();
294  m_aSpProgressButtonHandlers[m_iSelectedLegend].Deactivate();
295 
296  //Activate new selected legend
297  m_iSelectedLegend = specializationId;
298  m_aSpLegendButtonHandlers[m_iSelectedLegend].Activate();
299  m_aSpProgressButtonHandlers[m_iSelectedLegend].Activate();
300 
301  //We set the focus in case the player uses a controller
302  m_aSpProgressButtonHandlers[m_iSelectedLegend].SetFocus();
303 
304  //Update panel
305  UpdateSpecializationPanel(specializationId);
306  }
307 
308  //------------------------------------------------------------------------------------------------
309  void UpdateHoveredSpecialization(int specializationId, bool hover)
310  {
311  m_aSpLegendButtonHandlers[specializationId].SetOnHover(hover);
312  m_aSpProgressButtonHandlers[specializationId].SetOnHover(hover);
313  }
314 
315  //------------------------------------------------------------------------------------------------
316  protected Widget CreateSpecializationProgressButtonWidget(Widget container, int id)
317  {
318  WorkspaceWidget workspace = GetGame().GetWorkspace();
319  if (!workspace)
320  return null;
321 
322  Widget SpecializationProgressButton = Widget.Cast(workspace.CreateWidgets(m_sSpProgressLayout, container));
323  if (!SpecializationProgressButton)
324  return null;
325 
327  if (!handler)
328  return null;
329 
330  //If ID is higher to the number of Specializations, we fill it empty and make it invisible because its created for layout purposes
331  if (id >= SCR_PlayerDataConfigs.GetInstance().SPECIALIZATIONS_COUNT)
332  {
333  handler.SetValue(0);
334  handler.Hide();
335  return null;
336  }
337 
338  handler.SetButtonId(id);
339  handler.SetValue(m_PlayerData.GetSpecializationPoints(id) * SCR_PlayerDataConfigs.SPPOINTS_CONVERSIONPERCENTAGE);
340  handler.GetOnClicked().Insert(UpdateSpecialization);
341  handler.GetOnMouseEnter().Insert(UpdateHoveredSpecialization);
342  handler.GetOnMouseLeave().Insert(UpdateHoveredSpecialization);
343 
344  AddProgressButtonHandler(handler);
345 
346  return SpecializationProgressButton;
347  }
348 
349  //------------------------------------------------------------------------------------------------
350  void AddLegendButtonHandler(SCR_ButtonLegendComponent handler)
351  {
352  if (handler)
353  m_aSpLegendButtonHandlers.Insert(handler);
354  }
355 
356  //------------------------------------------------------------------------------------------------
357  void AddProgressButtonHandler(SCR_ButtonSpecializationProgressComponent handler)
358  {
359  if (handler)
360  m_aSpProgressButtonHandlers.Insert(handler);
361  }
362 
363  //------------------------------------------------------------------------------------------------
364  void SetLeftAndRightUIActivate(bool flag)
365  {
366  for (int i = m_aSpLegendButtonHandlers.Count(); i > 0; i--)
367  {
368  m_aSpLegendButtonHandlers[m_iSelectedLegend].SetLeftAndRightUIActivate(flag);
369  }
370  }
371 
372  //War crimes
373  //------------------------------------------------------------------------------------------------
374  void FillWarCrimes()
375  {
376  //TODO: choose the texture dynamically: m_wImgTitleIcon.LoadImageFromSet(0, image, imageName);
377  //where image is the resourceName of imageset, and imageName is the string of the specific icon in the imageset
378 
379  Widget WarCrimesPanelWidget = m_wCareerRightSide.FindAnyWidget("WarCrimesPanel");
380  if (!WarCrimesPanelWidget)
381  return;
382 
383  SCR_WarCrimesPanelUI handler = SCR_WarCrimesPanelUI.Cast(WarCrimesPanelWidget.FindHandler(SCR_WarCrimesPanelUI));
384  if (!handler)
385  return;
386 
387  if (m_PlayerData.GetStat(SCR_EDataStats.WARCRIMES) > 0)
388  {
389  if (m_PlayerData.GetStat(SCR_EDataStats.WARCRIME_HARMING_FRIENDLIES) > 0)
390  {
391  handler.CreateWarCrimeEntry(SCR_EWarCrimes.HARMINGFRIENDLIES);
392  }
393  else
394  {
395  Print ("SCR_CareerSpecializationsUI:FillWarCrimes: War Crimes amount not 0 but Harming Friendlies is 0", LogLevel.ERROR);
396  }
397  }
398  }
399 };
SCR_SpiderNet
Definition: SCR_SpiderNet.c:2
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_ProgressBarWithSegments
Definition: SCR_ProgressBarWithSegments.c:2
SCR_EWarCrimes
SCR_EWarCrimes
Definition: SCR_WarCrimesPanelUI.c:153
SCR_PlayerData
Definition: SCR_PlayerData.c:2
SCR_PlayerDataConfigs
Definition: SCR_PlayerDataConfigs.c:102
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_CareerSpecializationsUI
Definition: SCR_CareerSpecializationsUI.c:2
GetValue
override int GetValue()
Definition: SCR_VotingBase.c:69
SCR_EDataStats
SCR_EDataStats
Definition: SCR_PlayerData.c:950
SCR_CareerUI
Definition: SCR_CareerUI.c:2
SCR_WarCrimesPanelUI
Definition: SCR_WarCrimesPanelUI.c:2
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_WLibProgressBarComponent
Minimalist progress bar.
Definition: SCR_WLibProgressBar.c:3
SCR_ButtonLegendComponent
Definition: SCR_ButtonLegendComponent .c:2
SCR_ButtonSpecializationProgressComponent
Definition: SCR_ButtonSpecializationProgressComponent.c:2
SCR_InputButtonComponent
Definition: SCR_InputButtonComponent.c:1