Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_LoadoutStatistics.c
Go to the documentation of this file.
1
2
3//------------------------------------------------------------------------------------------------
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;
20
21 // Objects and references
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
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);
43
44 if (m_LoadoutSpin)
45 m_LoadoutSpin.m_OnChanged.Insert(OnLoadoutChanged);
46
47 // Setup
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 const 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 const 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; }
168
169 //------------------------------------------------------------------------------------------------
170 void SetCareerUI(CareerMenuUI careerUI) { m_CareerUI = careerUI; }
171};
172
173//------------------------------------------------------------------------------------------------
177{
178 [Attribute("", UIWidgets.Object, "")]
180 [Attribute()]
181 protected ref array<ref LoadoutStat> m_aStats;
182
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};
AddonBuildInfoTool id
ECareerStatId
Ids to receive all.
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
void UpdateStats()
ref array< ref LoadoutStat > m_aStats
SCR_BasePlayerLoadout GetLoadout()
array< ref LoadoutStat > GetStats()
ref SCR_BasePlayerLoadout m_Loadout
Class for switching and displaying stats for different loadouts.
void SetCareerUI(CareerMenuUI careerUI)
array< ref LoadoutStatSet > GetLodoutStatSets()
void SetStatValue(string sName, string sValue, Widget wEntry=null)
void SetStatLabel(string sName, string sLabel, Widget wEntry=null)
void SetStatEntry(string sName, string sLabel, string sValue, Widget wEntry=null)
override void HandlerAttached(Widget w)
ref array< ref LoadoutStatSet > m_aLoadouts
ref array< ref Widget > m_aStatWidgets
void OnLoadoutChanged(SCR_SpinBoxComponent spin, int id)
SCR_FieldOfViewSettings Attribute
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134