Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ServerListComponent.c
Go to the documentation of this file.
1 // Lobby Rooms handling
2 //
3 
5 {
6  SCR_ServerListComponent m_ServerList;
7 };
8 
9 class OnRoomsSearch extends ServerListCallback
10 {
11  array<Room> m_Rooms;
12  override void OnSuccess(int code)
13  {
14  GetGame().GetBackendApi().GetClientLobby().Rooms(m_Rooms);
15  Print("OnSearchServers Success");
16 
17  //m_ServerList.OnGetServersRoom();
18  }
19  override void OnError( int code, int restCode, int apiCode )
20  {
21  Print("OnSearchServers Error");
22  }
23 
24  override void OnTimeout()
25  {
26  Print("OnSearchServers Timeout");
27  }
28 };
29 
30 class OnRoomJoin extends ServerListCallback
31 {
32  override void OnSuccess(int code)
33  {
34  //m_ServerList.OnJoined();
35  Print("OnJoinRoomSB Success");
36  }
37  override void OnError( int code, int restCode, int apiCode )
38  {
39  Print("OnJoinRoomSB Error");
40  }
41  override void OnTimeout()
42  {
43  Print("OnJoinRoomSB Timeout");
44  }
45 };
46 
47 //
48 // Lobby Rooms handling
49 
50 //------------------------------------------------------------------------------------------------
52 {
53  // Server entries behavior list list
54  protected ref array<SCR_ServerBrowserEntryComponent> m_aRoomEntries = new array<SCR_ServerBrowserEntryComponent>;
55 
56  // Rooms data
57  protected ref array<Room> m_aRooms = new array<Room>;
58 
59  //-------------------------------------
60  // List component override
61  //-------------------------------------
62 
63  //------------------------------------------------------------------------------------------------
64  override void HandlerAttached(Widget w)
65  {
66  super.HandlerAttached(w);
67  }
68 
69  //------------------------------------------------------------------------------------------------
71  override protected void SetupEntryBehavior(Widget entry)
72  {
73  super.SetupEntryBehavior(entry);
74 
75  // Entry check
76  if (!entry)
77  return;
78 
79  // Find server entry component
81  if (!entryComp)
82  return;
83 
84  entryComp.GetOnFocus().Insert(OnRoomEntryFocus);
85  entryComp.m_OnClick.Insert(OnRoomEntryClick);
86 
87  // Insert to list
88  m_aRoomEntries.Insert(entryComp);
89 
90  }
91 
92  //------------------------------------------------------------------------------------------------
94  override protected void FillEntry(Widget w)
95  {
96  // Find entry
97  int id = m_aEntryWidgets.Find(w);
98  SCR_ServerBrowserEntryComponent roomEntry = m_aRoomEntries[id];
99 
100  if (!roomEntry)
101  return;
102 
103  // Get room
104  Room room = null;
105 
106  int iPos = m_iLastScrollPosition;
107 
108  int roomId = id + iPos;
109  if (roomId < m_aRooms.Count())
110  room = m_aRooms[id + iPos];
111 
112  // Update info
113  roomEntry.SetRoomInfo(room);
114 
115  // Hide entry if no room
116  w.SetVisible(room != null);
117  if (!room)
118  return;
119 
120  // Animated appearing
121  if (m_bAnimateListAppearing)
122  {
123  int delay = 100 / m_fAnimationAppearTime * id;
124  roomEntry.AnimateOpacity(delay, m_fAnimationAppearTime, 1, 0);
125  }
126  }
127 
128 
129  //------------------------------------------------------------------------------------------------
131  override protected void ClearServerList()
132  {
133  // Remove entyr actions
134  foreach (SCR_ServerBrowserEntryComponent entry : m_aRoomEntries)
135  {
136  entry.GetOnFocus().Clear();
137  entry.GetOnFocusLost().Clear();
138  }
139 
140  // Clear list
141  m_aRoomEntries.Clear();
142  m_aRooms.Clear();
143 
144  super.ClearServerList();
145  }
146 
147  //-------------------------------------
148  // public functions
149  //-------------------------------------
150 
151  //------------------------------------------------------------------------------------------------
152  void UpdateRooms(array<Room> rooms, bool animated = false)
153  {
154  if (!rooms)
155  return;
156 
157  m_aRooms = rooms;
158 
159  // Set entries to list
160  m_iEntriesCount = rooms.Count();
161  GetGame().GetCallqueue().Remove(OpacityAnimation);
162  UpdateScrollbar();
163  UpdateEntries(animated);
164  }
165 
166  //-------------------------------------
167  // protected functions
168  //-------------------------------------
169 
170  //------------------------------------------------------------------------------------------------
171  protected Room RoomByWidget(Widget w)
172  {
173  // Find room entyr widget id by root widget
174  int id = m_aEntryWidgets.Find(w);
175  if (id < 0)
176  return null;
177 
178  // Add scroll to get actual room
179  id += Math.Floor(m_fScrollPosition);
180 
181  // Get entry room
182  return m_aRoomEntries[id].GetRoomInfo();
183  }
184 
185  //-------------------------------------
186  // Invoker actions
187  //-------------------------------------
188 
189  //------------------------------------------------------------------------------------------------
191  protected void OnRoomEntryFocus(SCR_ScriptedWidgetComponent entry)
192  {
194 
195  // Get entry room
196  Room room = serverEntry.GetRoomInfo();
197 
198  if (room)
199  m_OnEntryFocus.Invoke(room);
200  }
201 
202  //------------------------------------------------------------------------------------------------
203  protected void OnRoomEntryClick(SCR_ServerBrowserEntryComponent entry)
204  {
205  m_iFocusedEntryId = m_aRoomEntries.Find(entry) + Math.Floor(m_fScrollPosition);
206  }
207 
208  //------------------------------------------------------------------------------------------------
209  array<SCR_ServerBrowserEntryComponent> GetRoomEntries() { return m_aRoomEntries; }
210 };
ServerListCallback
Definition: SCR_ServerListComponent.c:9
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
OnTimeout
override void OnTimeout()
Definition: UploadSaveCommand.c:23
SCR_ServerBrowserEntryComponent
This component handles server entry and visiualization of server data.
Definition: SCR_ServerBrowserEntryComponent.c:2
SCR_ButtonListViewComponent
Definition: SCR_ButtonListComponent.c:6
BackendCallback
Base server browser callback.
Definition: SCR_ServerListComponent.c:4
OnError
override void OnError(int code, int restCode, int apiCode)
Definition: UploadSaveCommand.c:13
SCR_ServerListComponent
Definition: SCR_ServerListComponent.c:51
OnSuccess
class RoomJoinData extends JsonApiStruct OnSuccess
SCR_ScriptedWidgetComponent
Definition: SCR_ScriptedWidgetComponent.c:7