Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_PooledListServerComponent.c
Go to the documentation of this file.
3 {
4  // Server arrays
5  protected ref array<SCR_ServerBrowserEntryComponent> m_aRoomEntries = {};
6  protected ref array<Room> m_aRooms = {};
7 
8  protected int m_iLoadedPage;
9 
10  //------------------------------------------------------------------------------------------------
11  // Override functions
12  //------------------------------------------------------------------------------------------------
13 
14  //------------------------------------------------------------------------------------------------
15  override protected Widget CreateEntry(Widget parent)
16  {
17  Widget entry = super.CreateEntry(parent);
18 
19  // Check entry
20  if (!entry)
21  return null;
22 
23  // Access server entry component
25 
26  if (!serverEntry)
27  return null;
28 
29  // Setup server entry
30  serverEntry.GetOnFocus().Insert(OnServerEntryFocusEnter);
31 
32  // Save server entry
33  m_aRoomEntries.Insert(serverEntry);
34  return entry;
35  }
36 
37  //------------------------------------------------------------------------------------------------
40  override protected void FillEntry(Widget w)
41  {
42  int entryId = -1;
43  int roomId = -1;
44 
45  if (!w)
46  return;
47 
48  SCR_ServerBrowserEntryComponent serverEntry = ServerEntryByWidget(w, entryId);
49  if (!serverEntry)
50  return;
51 
52  // Check if can be displayed
53  if (!IsPageLoaded(w.GetParent()))
54  return;
55 
56  // Setup room id
57  roomId = entryId;
58 
59  if (m_bPagesInverted)
60  {
61  // Modify count if pages are inverted
62  if (w.GetParent() == m_wPage0)
63  roomId = entryId + m_iPageEntriesCount;
64  if (w.GetParent() == m_wPage1)
65  roomId = entryId - m_iPageEntriesCount;
66  }
67 
68  // Get addons manager
69  SCR_AddonManager mgr = SCR_AddonManager.GetInstance();
70  ClientLobbyApi lobby = GetGame().GetBackendApi().GetClientLobby();
71 
72  // Fill room
73 
74  if (roomId < 0 || roomId >= m_aRooms.Count())
75  return;
76 
77  if (IsEntryVisible(w))
78  {
79  serverEntry.SetRoomInfo(m_aRooms[roomId]);
80  m_aRoomEntries[entryId].EmptyVisuals(false);
81  }
82  else
83  {
84  serverEntry.SetRoomInfo(null);
85  }
86  }
87 
88  //------------------------------------------------------------------------------------------------
90  override void MoveToTop()
91  {
92  //UpdateLoadedPage();
93  super.MoveToTop();
94  UpdateLoadedPage();
95  }
96 
97  //------------------------------------------------------------------------------------------------
98  override protected void SetCurrentPage(int page)
99  {
100  // Update base and invoke
101  SetCurrentPageBase(page);
102 
103  // Display unloaded
104  if (m_iLoadedPage == m_iCurrentPage)
105  return;
106 
107  // Muliple pages
108  if (Math.AbsInt(m_iLoadedPage - m_iCurrentPage) > 1)
109  {
110  foreach (SCR_ServerBrowserEntryComponent entry : m_aRoomEntries)
111  {
112  entry.EmptyVisuals(true);
113  }
114 
115  return;
116  }
117 
118  // Single page change
119  int start = 0;
120 
121  // + 1 page - go down
122  if (m_iLoadedPage + 1 == m_iCurrentPage)
123  {
124  if (!m_bPagesInverted)
125  start = m_iPageEntriesCount;
126 
127  // Loading
128  for (int i = m_iPageEntriesCount + start - 1; i >= start; i--)
129  {
130  m_aRoomEntries[i].EmptyVisuals(true);
131  }
132 
133  return;
134  }
135 
136  // -1 page - go up
137  if (m_iLoadedPage - 1 == m_iCurrentPage)
138  {
139  if (m_bPagesInverted)
140  start = m_iPageEntriesCount;
141 
142  // Loading
143  for (int i = start, max = m_iPageEntriesCount + start; i < max; i++)
144  {
145  m_aRoomEntries[i].EmptyVisuals(true);
146  }
147  }
148  }
149 
150  //------------------------------------------------------------------------------------------------
151  protected bool IsPageLoaded(Widget wPage)
152  {
153  // Multiple pages scroll
154  if (Math.AbsInt(m_iLoadedPage - m_iCurrentPage) > 1)
155  return false;
156 
157  // Down
158  if (m_iLoadedPage + 1 == m_iCurrentPage)
159  {
160  if (m_bPagesInverted && wPage == m_wPage1)
161  return true;
162 
163  if (!m_bPagesInverted && wPage == m_wPage0)
164  return true;
165 
166  return false;
167  }
168 
169  // Up
170  if (m_iLoadedPage - 1 == m_iCurrentPage)
171  {
172  if (m_bPagesInverted && wPage == m_wPage1)
173  return true;
174 
175  if (!m_bPagesInverted && wPage == m_wPage0)
176  return true;
177 
178  return false;
179  }
180 
181  // Current page loaded
182  return true;
183  }
184 
185  //------------------------------------------------------------------------------------------------
186  // Invoker actions
187  //------------------------------------------------------------------------------------------------
188 
189  //------------------------------------------------------------------------------------------------
193  protected void OnServerEntryFocusEnter(SCR_ScriptedWidgetComponent entry)
194  {
196 
197  // Set current focused id
198  int entryId = m_aRoomEntries.Find(serverEntry);
199  entryId += m_iCurrentPage * m_iPageEntriesCount;
200 
201  if (m_bPagesInverted)
202  {
203  // Modify count if pages are inverted
204  if (serverEntry.GetRootWidget().GetParent() == m_wPage0)
205  entryId += m_iPageEntriesCount;
206  else if (serverEntry.GetRootWidget().GetParent() == m_wPage1)
207  entryId -= m_iPageEntriesCount;
208  }
209  }
210 
211  //------------------------------------------------------------------------------------------------
212  // Protectted functions
213  //------------------------------------------------------------------------------------------------
214 
215  //------------------------------------------------------------------------------------------------
219  protected SCR_ServerBrowserEntryComponent ServerEntryByWidget(Widget entryWidget, out int id)
220  {
221  // Check widget
222  if (!entryWidget)
223  return null;
224 
225  // Find server entry by id
226  id = m_aEntryWidgets.Find(entryWidget);
227 
228  if (0 <= id && id < m_aRoomEntries.Count())
229  return m_aRoomEntries[id];
230 
231  return null;
232  }
233 
234  //------------------------------------------------------------------------------------------------
235  // Public functions
236  //------------------------------------------------------------------------------------------------
237 
238  //------------------------------------------------------------------------------------------------
242  void SetRooms(array<Room> rooms, int allRoomsCount = -1, bool animate = false)
243  {
244  m_wRoot.SetVisible(true);
245 
246  m_aRooms = rooms;
247 
248  int roomsCount = rooms.Count();
249 
250  // Update data
251  int dataCount = allRoomsCount;
252  if (allRoomsCount == -1)
253  dataCount = m_aRooms.Count();
254 
255  SetDataEntries(allRoomsCount);
256 
257  UpdateEntries(animate);
258  }
259 
260  //------------------------------------------------------------------------------------------------
262  void ShowEmptyRooms()
263  {
264  m_aRooms.Clear();
265  UpdateEntries(false);
266 
267  // Hide entries
268  foreach (Widget widget : m_aEntryWidgets)
269  {
270  widget.SetVisible(false);
271  }
272 
273  if (m_bIsMeasured)
274  {
275  m_wRoot.ClearFlags(WidgetFlags.CLIPCHILDREN);
276  m_wRoot.ClearFlags(WidgetFlags.INHERIT_CLIPPING);
277  }
278  }
279 
280  //------------------------------------------------------------------------------------------------
282  void UpdateLoadedPage()
283  {
284  m_iLoadedPage = m_iCurrentPage;
285  }
286 
287  //------------------------------------------------------------------------------------------------
292  bool IsRoomLoaded(notnull SCR_ServerBrowserEntryComponent entry)
293  {
294  if (m_aRoomEntries.IsEmpty())
295  return false;
296 
297  int id = m_aRoomEntries.Find(entry);
298  if (id == -1)
299  return false;
300 
301  return m_iLoadedPage == m_iCurrentPage;
302  }
303 
304  //------------------------------------------------------------------------------------------------
307  protected bool IsEntryVisible(Widget entry)
308  {
309  // Current id - based on current page
310  int id = m_aEntryWidgets.Find(entry);
311  id += m_iCurrentPage * m_iPageEntriesCount;
312 
313  // Is over count?
314  if (id > m_iAllEntriesCount)
315  return false;
316 
317  return true;
318  }
319 
320  //------------------------------------------------------------------------------------------------
322  array<SCR_ServerBrowserEntryComponent> GetRoomEntries()
323  {
324  return m_aRoomEntries;
325  }
326 
327  //------------------------------------------------------------------------------------------------
329  int GetLoadedPage()
330  {
331  return m_iLoadedPage;
332  }
333 
334  //------------------------------------------------------------------------------------------------
336  int GetCurrentPage()
337  {
338  return m_iCurrentPage;
339  }
340 }
m_iCurrentPage
protected int m_iCurrentPage
Definition: SCR_ContentBrowser_AddonsSubMenu.c:75
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_ServerBrowserEntryComponent
This component handles server entry and visiualization of server data.
Definition: SCR_ServerBrowserEntryComponent.c:2
SCR_PooledServerListComponent
Pooled scrollable list with server entries handling.
Definition: SCR_PooledListServerComponent.c:2
SCR_AddonManager
Definition: SCR_AddonManager.c:72
SCR_PooledListComponent
Definition: SCR_PooledListComponent.c:10
SCR_ScriptedWidgetComponent
Definition: SCR_ScriptedWidgetComponent.c:7