Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_LoadoutStatistics.c
Go to the documentation of this file.
1 
3 //------------------------------------------------------------------------------------------------
4 class SCR_LoadoutStatisticsComponent : ScriptedWidgetComponent
5 {
6  [Attribute()]
7  protected ref array<ref LoadoutStatSet> m_aLoadouts;
8 
9  // Resources
10  protected const ResourceName ENTRY_LAYOUT = "{C87F7F6734B61688}UI/layouts/Menus/Career/CareerEntry.layout";
11 
12  // Strings
13  protected const string WIDGET_LOADOUT_SPIN = "SpinLoadout";
14  protected const string WIDGET_STAT_LIST = "vStatList";
15 
16  // Widgets
17  protected Widget m_wRoot;
18  protected Widget m_wStatList;
19  protected Widget m_wLoadoutSpin;
20 
21  // Objects and references
22  protected CareerMenuUI m_CareerUI;
23  protected SCR_SpinBoxComponent m_LoadoutSpin;
24 
25  protected ref array<ref Widget> m_aStatWidgets = new array<ref Widget>();
26 
27  // Values
28  protected int m_iEntryCount = 0;
29  protected int m_iSelected = 0;
30 
31  ref ScriptInvoker m_OnLoadoutChange = new ScriptInvoker();
32 
33  //------------------------------------------------------------------------------------------------
34  override void HandlerAttached(Widget w)
35  {
36  m_wRoot = w;
37  m_wStatList = w.FindAnyWidget(WIDGET_STAT_LIST);
38 
39  // Loadout spin
40  m_wLoadoutSpin = w.FindAnyWidget(WIDGET_LOADOUT_SPIN);
41  if (m_wLoadoutSpin)
42  m_LoadoutSpin = SCR_SpinBoxComponent.Cast(m_wLoadoutSpin.FindHandler(SCR_SpinBoxComponent));
43 
44  if (m_LoadoutSpin)
45  m_LoadoutSpin.m_OnChanged.Insert(OnLoadoutChanged);
46 
47  // Setup
48  SetupLoadoutSpin();
49  CreateStatEntries(m_iEntryCount);
50 
51  OnLoadoutChanged(null, m_LoadoutSpin.GetCurrentIndex());
52  }
53 
54  //------------------------------------------------------------------------------------------------
56  protected void SetupLoadoutSpin()
57  {
58  if (!m_LoadoutSpin)
59  return;
60 
61  // Get info from loadout stats
62  int total = m_aLoadouts.Count();
63  foreach (int i, LoadoutStatSet statSet : m_aLoadouts)
64  {
65  if (!statSet)
66  continue;
67 
68  m_LoadoutSpin.AddItem(statSet.GetLoadout().GetLoadoutName(), i == total - 1);
69 
70  // Get max entry count
71  int c = 0;
72  if (statSet)
73  {
74  if (statSet.GetStats())
75  c = statSet.GetStats().Count();
76  }
77 
78  if (c > m_iEntryCount)
79  m_iEntryCount = c;
80  }
81  }
82 
83  //------------------------------------------------------------------------------------------------
84  protected void CreateStatEntries(int count)
85  {
86  for (int i = 0; i < count; i++)
87  {
88  Widget entry = GetGame().GetWorkspace().CreateWidgets(ENTRY_LAYOUT, m_wStatList);
89  m_aStatWidgets.Insert(entry);
90  entry.SetVisible(false);
91  }
92  }
93 
94  //------------------------------------------------------------------------------------------------
95  protected void OnLoadoutChanged(SCR_SpinBoxComponent spin, int id)
96  {
97  UpdateStats(id);
98  m_OnLoadoutChange.Invoke(id);
99  }
100 
101  //------------------------------------------------------------------------------------------------
102  void UpdateStats(int id)
103  {
104  m_iSelected = id;
105  int count = 0;
106  if (m_aLoadouts[id])
107  {
108  if (m_aLoadouts[id].GetStats())
109  count = m_aLoadouts[id].GetStats().Count();
110  }
111 
112  for (int i = 0; i < m_aStatWidgets.Count(); i++)
113  {
114  Widget entry = m_aStatWidgets[i];
115 
116  bool display = i < count;
117  // Hiding entries
118  entry.SetVisible(display);
119  if (!display)
120  continue;
121 
122  string name = m_aLoadouts[id].GetStats()[i].m_sName;
123  int valueId = m_aLoadouts[id].GetStats()[i].m_iValueId;
124  string value = "";
125  if (m_CareerUI)
126  value = m_CareerUI.GetBackendValues()[valueId];
127  SetStatEntry("", name, value, entry);
128  }
129  }
130 
131  //------------------------------------------------------------------------------------------------
132  protected void SetStatEntry(string sName, string sLabel, string sValue, Widget wEntry = null)
133  {
134  if(!wEntry)
135  return;
136 
137  SetStatLabel(sName, sLabel, wEntry);
138  SetStatValue(sName, sValue, wEntry);
139  }
140 
141  //------------------------------------------------------------------------------------------------
142  protected void SetStatLabel(string sName, string sLabel, Widget wEntry = null)
143  {
144  if(!wEntry)
145  return;
146 
147  string sLabelName = "txtLabel";
148  TextWidget wLabel = TextWidget.Cast(wEntry.FindAnyWidget(sLabelName));
149  if(wLabel)
150  wLabel.SetText(sLabel);
151  }
152 
153  //------------------------------------------------------------------------------------------------
154  protected void SetStatValue(string sName, string sValue, Widget wEntry = null)
155  {
156  if(!wEntry)
157  return;
158 
159  string sValueName = "txtValue";
160  TextWidget wValue = TextWidget.Cast(wEntry.FindAnyWidget(sValueName));
161  if(wValue)
162  wValue.SetText(sValue);
163  }
164 
165  //------------------------------------------------------------------------------------------------
166  array<ref LoadoutStatSet> GetLodoutStatSets() { return m_aLoadouts; }
167  int GetCurrentLoadoutId() { return m_iSelected; }
168 
169  //------------------------------------------------------------------------------------------------
170  void SetCareerUI(CareerMenuUI careerUI) { m_CareerUI = careerUI; }
171 };
172 
173 //------------------------------------------------------------------------------------------------
177 {
178  [Attribute("", UIWidgets.Object, "")]
179  protected ref SCR_BasePlayerLoadout m_Loadout;
180  [Attribute()]
181  protected ref array<ref LoadoutStat> m_aStats;
182 
183  SCR_BasePlayerLoadout GetLoadout() { return m_Loadout; }
184  array<ref LoadoutStat> GetStats() { return m_aStats; }
185 };
186 
187 //------------------------------------------------------------------------------------------------
190 {
191  [Attribute()]
192  string m_sName;
193  /*[Attribute()]
194  string m_sValue; */
195  [Attribute("0", uiwidget: UIWidgets.ComboBox, "", "", ParamEnumArray.FromEnum(ECareerStatId))]
196  ECareerStatId m_iValueId;
197 };
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
SCR_LoadoutStatisticsComponent
Class for switching and displaying stats for different loadouts.
Definition: SCR_LoadoutStatistics.c:4
LoadoutStatSet
Definition: SCR_LoadoutStatistics.c:176
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
LoadoutStat
Definition: SCR_LoadoutStatistics.c:189
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_SpinBoxComponent
Definition: SCR_SpinBoxComponent.c:1
ECareerStatId
ECareerStatId
Ids to receive all.
Definition: CareerMenuUI.c:241
CareerMenuUI
Definition: CareerMenuUI.c:2
SCR_BasePlayerLoadout
Definition: SCR_BasePlayerLoadout.c:2
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468