Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_FactionPlayerList.c
Go to the documentation of this file.
2{
3 [Attribute("Flag")]
4 protected string m_sFlag;
6
7 [Attribute("Name")]
8 protected string m_sName;
9 protected TextWidget m_wName;
10
11 [Attribute("Count")]
12 protected string m_sPlayerCount;
14
15 [Attribute("Players")]
16 protected string m_sPlayerList;
18
19 [Attribute("{E49B28A2FAEBA264}UI/layouts/Menus/DeployMenu/PlayerName.layout")]
21
22 protected ref array<SCR_PlayerName> m_aPlayerNames = {};
23 protected Widget m_wRoot;
24
25 //------------------------------------------------------------------------------------------------
26 override void HandlerAttached(Widget w)
27 {
28 m_wRoot = w;
29
30 m_wFlag = ImageWidget.Cast(w.FindAnyWidget(m_sFlag));
31 m_wName = TextWidget.Cast(w.FindAnyWidget(m_sName));
32 m_wPlayerCount = TextWidget.Cast(w.FindAnyWidget(m_sPlayerCount));
33 m_wPlayerList = w.FindAnyWidget(m_sPlayerList);
34 }
35
36 //------------------------------------------------------------------------------------------------
38 {
39 }
40
41 //------------------------------------------------------------------------------------------------
43 void ShowPlayerList(bool show)
44 {
45 m_wRoot.SetVisible(show);
46 }
47
48 //------------------------------------------------------------------------------------------------
49 protected void CreatePlayerName(int pid)
50 {
51 Widget player = GetGame().GetWorkspace().CreateWidgets(m_sPlayerName, m_wPlayerList);
52 if (player)
53 {
54 SCR_PlayerName playerName = SCR_PlayerName.Cast(player.FindHandler(SCR_PlayerName));
55 playerName.SetPlayer(pid);
56 // playerName.SetIcon(ResourceName.Empty); // todo@lk: set some icon from somewhere
57 m_aPlayerNames.Insert(playerName);
58 }
59 }
60};
61
63{
66 protected int m_iLastPage;
67
68 [Attribute("10", params: "0 inf", UIWidgets.EditBox, "How much entries should be shown in list.")]
69 protected int m_iEntriesPerPage;
70
71 [Attribute("SpinBox")]
72 protected string m_sSpinBoxElementName;
73
74 [Attribute("ButtonLeft")]
75 protected string m_sPagingButtonLeft;
76
77 [Attribute("ButtonRight")]
78 protected string m_sPagingButtonRight;
79
80 //------------------------------------------------------------------------------------------------
81 override event void HandlerAttached(Widget w)
82 {
83 super.HandlerAttached(w);
84
85 SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
86 if (!factionManager)
87 return;
88
89 factionManager.GetOnPlayerFactionCountChanged().Insert(UpdatePagination);
90 factionManager.GetOnPlayerFactionCountChanged().Insert(UpdatePlayerList);
91
92 Widget spinboxW = m_wRoot.FindAnyWidget(m_sSpinBoxElementName);
93 if (!spinboxW)
94 return;
95
96 m_SpinBoxComp = SCR_SpinBoxComponent.Cast(spinboxW.FindHandler(SCR_SpinBoxComponent));
97 if (!m_SpinBoxComp)
98 return;
99
100 m_SpinBoxComp.m_OnChanged.Insert(UpdatePlayerList);
101 }
102
103 //------------------------------------------------------------------------------------------------
104 void SetFaction(Faction faction)
105 {
106 SCR_Faction scrFaction = SCR_Faction.Cast(faction);
107 if (!scrFaction)
108 return;
109
110 m_Faction = scrFaction;
111
112 if (m_wFlag && !scrFaction.GetFactionFlag().IsEmpty())
113 m_wFlag.LoadImageTexture(0, scrFaction.GetFactionFlag());
114
115 if (m_wName)
116 m_wName.SetText(scrFaction.GetFactionName());
117
118 UpdatePagination(faction);
120
121 //Reset last page as faction was changed
122 m_iLastPage = 0;
123 }
124
125 //------------------------------------------------------------------------------------------------
126 protected void UpdatePagination(Faction faction)
127 {
128 if (faction != m_Faction)
129 return;
130
131 array<int> players = {};
132 m_Faction.GetPlayersInFaction(players);
133
134 int pageCount = players.Count() / m_iEntriesPerPage;
135 if ((players.Count() % m_iEntriesPerPage) > 0)
136 pageCount++;
137
138 SetLastIndex();
139 m_SpinBoxComp.ClearAll();
140
141 for (int i = 0; i < pageCount; i++)
142 {
143 m_SpinBoxComp.AddItem("", i == pageCount - 1);
144 }
145
146 m_SpinBoxComp.SetCurrentItem(m_iLastPage);
147
148 //Show or disable navigation buttons depending on number of visible pagging entries
150 }
151
152 //------------------------------------------------------------------------------------------------
154 protected int GetStartingIndex()
155 {
156 int page = m_SpinBoxComp.GetCurrentIndex();
157 if (page < 1)
158 return 0;
159
160 return page * m_iEntriesPerPage;
161 }
162
163 //------------------------------------------------------------------------------------------------
164 protected void HandleNavigationButtons()
165 {
166 if (!m_SpinBoxComp)
167 return;
168
169 bool showButtons = m_SpinBoxComp.GetNumItems() > 1;
170
171 Widget button = m_wRoot.FindAnyWidget(m_sPagingButtonLeft);
172 if (button)
173 button.SetVisible(showButtons);
174
175 button = m_wRoot.FindAnyWidget(m_sPagingButtonRight);
176 if (button)
177 button.SetVisible(showButtons);
178
179 Widget spinboxW = m_wRoot.FindAnyWidget(m_sSpinBoxElementName);
180 if (spinboxW)
181 spinboxW.SetVisible(showButtons);
182 }
183
184 //------------------------------------------------------------------------------------------------
185 protected void SetLastIndex()
186 {
187 m_iLastPage = m_SpinBoxComp.GetCurrentIndex();
188 }
189
190 //------------------------------------------------------------------------------------------------
191 override void UpdatePlayerList()
192 {
193 if (!m_Faction || !m_wPlayerList)
194 return;
195
196 m_aPlayerNames.Clear();
197
198 Widget child = m_wPlayerList.GetChildren();
199 while (child)
200 {
201 Widget sibling = child.GetSibling();
202 child.RemoveFromHierarchy();
203 child = sibling;
204 }
205
206 array<int> players = {};
207 m_Faction.GetPlayersInFaction(players);
208
209 int startIndex = GetStartingIndex();
210 if (players.IsEmpty() || startIndex < 0)
211 {
212 if (m_wPlayerCount)
213 m_wPlayerCount.SetText("0");
214 return;
215 }
216
217 int maxIndex = startIndex + (m_iEntriesPerPage-1);
218 for (int i = startIndex; i <= maxIndex; i++)
219 {
220 if (i >= players.Count())
221 break;
222
223 if (m_Faction && (SCR_Faction.Cast(SCR_FactionManager.SGetPlayerFaction(players[i])) == m_Faction))
224 CreatePlayerName(players[i]);
225 }
226
227 if (m_wPlayerCount)
228 m_wPlayerCount.SetText(players.Count().ToString());
229 }
230
231 override event void HandlerDeattached(Widget w)
232 {
233 super.HandlerDeattached(w);
234
235 SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
236 if (factionManager)
237 {
238 factionManager.GetOnPlayerFactionCountChanged().Remove(UpdatePagination);
239 factionManager.GetOnPlayerFactionCountChanged().Remove(UpdatePlayerList);
240 }
241 }
242};
243
245{
247
249 {
250 if (!group)
251 return;
252
253 m_Group = group;
254
255 if (m_wFlag && !group.GetGroupFlag().IsEmpty())
256 m_wFlag.LoadImageTexture(0, group.GetGroupFlag());
257
258 if (m_wName)
259 {
260 string name = m_Group.GetCustomName();
261 if (name.IsEmpty())
262 {
263 string company, platoon, squad, character, format;
264 m_Group.GetCallsigns(company, platoon, squad, character, format);
265 name = string.Format("%1 %2 %3 %4 %5", company, platoon, squad, character, format);
266 }
267
268 m_wName.SetText(name);
269 }
270
272 }
273
274 override void UpdatePlayerList()
275 {
276 if (!m_Group || !m_wPlayerList)
277 return;
278
279 m_aPlayerNames.Clear();
280
281 Widget child = m_wPlayerList.GetChildren();
282 while (child)
283 {
284 Widget sibling = child.GetSibling();
285 child.RemoveFromHierarchy();
286 child = sibling;
287 }
288
289 array<int> players = m_Group.GetPlayerIDs();
290 foreach (int pid : players)
291 {
292 CreatePlayerName(pid);
293 }
294
295 if (m_wPlayerCount)
296 m_wPlayerCount.SetText(m_aPlayerNames.Count().ToString());
297 }
298};
299
301{
302 [Attribute("Icon")]
303 protected string m_sIcon;
305
306 [Attribute("Name")]
307 protected string m_sName;
309
310 [Attribute("BadgeWrapper")]
311 protected string m_sBadgeWrapper;
313
314 protected ResourceName m_sIcons = "{D17288006833490F}UI/Textures/Icons/icons_wrapperUI-32.imageset";
315 protected int m_iPlayerId;
316
317
318 override void HandlerAttached(Widget w)
319 {
320 m_wIcon = ImageWidget.Cast(w.FindAnyWidget(m_sIcon));
321 m_wName = TextWidget.Cast(w.FindAnyWidget(m_sName));
322 m_wBadgeWrapper = SizeLayoutWidget.Cast(w.FindAnyWidget(m_sBadgeWrapper));
324 }
325
326 //------------------------------------------------------------------------------------------------
328 {
329 if (!m_wIcon)
330 return;
331
332 if (m_wIcon)
333 m_wIcon.SetVisible(m_wIcon.LoadImageTexture(0, icon));
334 }
335
336 //------------------------------------------------------------------------------------------------
339 {
341
342 if (!badgeWrapper || !m_FactionManager)
343 return;
344
345 Faction faction = m_FactionManager.GetLocalPlayerFaction();
346 if (!faction)
347 return;
348
349 badgeWrapper.SetColor(faction.GetFactionColor());
350 }
351
352 //------------------------------------------------------------------------------------------------
355 void SetPlayer(int pid)
356 {
357 m_iPlayerId = pid;
358 if (m_wName)
359 m_wName.SetText(SCR_PlayerNamesFilterCache.GetInstance().GetPlayerDisplayName(pid));
360
361 SetPlatform();
362 }
363
364 //------------------------------------------------------------------------------------------------
366 {
367 return m_iPlayerId;
368 }
369
370 //------------------------------------------------------------------------------------------------
371 protected void SetPlatform()
372 {
373 if (!m_wIcon)
374 return;
375
377 playerController && playerController.SetPlatformImageTo(m_iPlayerId, m_wIcon, showOnPC: true, showOnXbox: true)
378
379 // todo@lk: local profile pic
380 }
381};
ArmaReforgerScripted GetGame()
Definition game.c:1398
void SCR_FactionManager(IEntitySource src, IEntity parent)
SCR_FactionManager m_FactionManager
ResourceName GetGroupFlag()
ResourceName GetFactionFlag()
void UpdatePagination(Faction faction)
int GetStartingIndex()
Get index of first entry of current page.
override event void HandlerDeattached(Widget w)
void SetFaction(Faction faction)
SCR_SpinBoxComponent m_SpinBoxComp
override event void HandlerAttached(Widget w)
override void UpdatePlayerList()
void SetGroup(SCR_AIGroup group)
override void HandlerAttached(Widget w)
ref array< SCR_PlayerName > m_aPlayerNames
void ShowPlayerList(bool show)
void CreatePlayerName(int pid)
ResourceName m_sPlayerName
void SetBadgeColor(SizeLayoutWidget badgeWrapper)
SizeLayoutWidget m_wBadgeWrapper
void SetIcon(ResourceName icon)
override void HandlerAttached(Widget w)
SCR_FieldOfViewSettings Attribute
proto external PlayerController GetPlayerController()