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