Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
playerlistscriptedwidget.c
Go to the documentation of this file.
1 class PlayerListScriptedWidget extends ScriptedWidgetEventHandler
2 {
3  protected Widget m_Root;
4  protected ScrollWidget m_ScrollContainer;
5  protected Widget m_Content;
7 
8  protected int m_TotalEntries;
9  protected PlayerListEntryScriptedWidget m_SelectedEntry;
10 
11  void PlayerListScriptedWidget( Widget parent, string header_text = "" )
12  {
13  m_Root = GetGame().GetWorkspace().CreateWidgets( "gui/layouts/xbox/ingamemenu_xbox/players_info_panel.layout", parent );
14  m_ScrollContainer = ScrollWidget.Cast( m_Root.FindAnyWidget( "ScrollFrame" ) );
15  m_Content = m_Root.FindAnyWidget( "Content" );
16 
18 
19  m_ScrollContainer.VScrollToPos01( 0 );
20  }
21 
22  void ~PlayerListScriptedWidget()
23  {
24  delete m_Root;
25  }
26 
27  void FocusFirst()
28  {
29  if ( m_Content && m_Content.GetChildren() )
30  SetFocus( m_Content.GetChildren().FindAnyWidget( "Button" ) );
31  m_ScrollContainer.VScrollToPos01( 0 );
32  }
33 
34  void Reload( SyncPlayerList player_list )
35  {
36  if ( player_list && player_list.m_PlayerList && m_Entries )
37  {
38  foreach ( string UID, PlayerListEntryScriptedWidget widget : m_Entries )
39  {
40  SyncPlayer player_found;
41  foreach ( SyncPlayer player : player_list.m_PlayerList )
42  {
43  if ( player && player.m_UID == UID )
44  {
45  player_found = player;
46  break;
47  }
48  }
49  if ( !player_found )
50  {
51  RemovePlayer( UID );
52  }
53  }
54 
55  for ( int i = 0; i < player_list.m_PlayerList.Count(); i++ )
56  {
57  SyncPlayer player2 = player_list.m_PlayerList.Get( i );
58  PlayerListEntryScriptedWidget player_widget;
59  m_Entries.Find( player2.m_UID, player_widget );
60  if ( !player_widget )
61  {
62  AddPlayer( player2.m_PlayerName, player2.m_UID, true );
63  }
64  }
65  }
66  }
67 
68  bool IsEmpty()
69  {
70  return ( m_Entries.Count() == 0 );
71  }
72 
73  void OnLoadServersAsync( ref GetServersResult result_list, EBiosError error, string response )
74  {
75 
76  }
77 
78  void Reload( BiosFriendInfoArray player_list )
79  {
80  if ( player_list && m_Entries )
81  {
82  foreach ( string UID, PlayerListEntryScriptedWidget widget : m_Entries )
83  {
84  BiosFriendInfo player_found;
85  int j = 0;
86  while ( !player_found && j < player_list.Count() )
87  {
88  if ( player_list[j].m_Uid == UID )
89  player_found = player_list[j];
90  j++;
91  }
92 
93  if ( !player_found )
94  {
95  RemovePlayer( UID );
96  }
97  }
98 
99  for ( int i = 0; i < player_list.Count(); i++ )
100  {
101  BiosFriendInfo player2 = player_list.Get( i );
102  PlayerListEntryScriptedWidget player_widget;
103  m_Entries.Find( player2.m_Uid, player_widget );
104  if ( !player_widget )
105  {
106  AddPlayer( player2.m_DisplayName, player2.m_Uid, false );
107  }
108  }
109  }
110  }
111 
112  void Reload( BiosPrivacyUidResultArray player_list )
113  {
114  foreach ( BiosPrivacyUidResult result : player_list )
115  {
116  PlayerListEntryScriptedWidget player_widget;
117  m_Entries.Find( result.m_Uid, player_widget );
118  if ( player_widget )
119  {
120  player_widget.LoadPermissions( result.m_Results );
121  }
122  }
123  }
124 
125  void ReloadLocal( map<string, bool> player_list )
126  {
127  if ( player_list )
128  {
129  for ( int i = 0; i < player_list.Count(); i++ )
130  {
131  string uid = player_list.GetKey( i );
132  bool muted = OnlineServices.IsPlayerMuted( uid );
133  PlayerListEntryScriptedWidget player_widget;
134  m_Entries.Find( uid, player_widget );
135  if ( player_widget )
136  {
137  player_widget.SetMute( muted );
138  }
139  }
140  }
141  }
142 
143  PlayerListEntryScriptedWidget FindEntryByWidget( Widget button )
144  {
145  if ( button && m_Entries )
146  {
147  foreach ( string UID, PlayerListEntryScriptedWidget widget : m_Entries )
148  {
149  if ( widget && widget.GetButtonWidget() == button )
150  {
151  return widget;
152  }
153  }
154  }
155 
156  return null;
157  }
158 
159  string FindPlayerByWidget( Widget button )
160  {
161  if ( button && m_Entries )
162  {
163  foreach ( string UID, PlayerListEntryScriptedWidget widget : m_Entries )
164  {
165  if ( widget && widget.GetButtonWidget() == button )
166  {
167  return UID;
168  }
169  }
170  }
171 
172  return "";
173  }
174 
175  void AddPlayer( string name, string UID, bool show_permissions )
176  {
177  if ( m_Entries )
178  {
179  m_Entries.Insert( UID, new PlayerListEntryScriptedWidget( m_Content, name, UID, show_permissions, this ) );
180  m_TotalEntries++;
181  }
182  }
183 
184  void RemovePlayer( string UID )
185  {
186  if ( m_Entries )
187  {
188  PlayerListEntryScriptedWidget next_entry;
189 
190  if ( m_Entries.Get( UID ) == m_SelectedEntry )
191  {
192  for ( int i = 0; i < m_Entries.Count() - 1; i++ )
193  {
194  if ( m_Entries.GetElement( i ) == m_Entries.Get( UID ) )
195  {
196  next_entry = m_Entries.GetElement( i + 1 );
197  }
198  }
199  }
200 
201  m_Entries.Remove( UID );
202  m_TotalEntries--;
203  SelectPlayer( next_entry );
204  m_Content.Update();
205  }
206  }
207 
208  bool IsMuted( string UID )
209  {
210  if ( m_Entries && m_Entries.Get( UID ) )
211  {
212  return m_Entries.Get( UID ).IsMuted();
213  }
214  return false;
215  }
216 
217  bool IsGloballyMuted( string UID )
218  {
219  if ( m_Entries && m_Entries.Get( UID ) )
220  {
221  return m_Entries.Get( UID ).IsGloballyMuted();
222  }
223  return false;
224  }
225 
226  void SetMute( string UID, bool mute )
227  {
228  if ( m_Entries && m_Entries.Get( UID ) )
229  {
230  m_Entries.Get( UID ).SetMute( mute );
231  }
232  }
233 
234  void ToggleMute( string UID )
235  {
236  if ( m_Entries && m_Entries.Get( UID ) )
237  {
238  m_Entries.Get( UID ).ToggleMute();
239  }
240  }
241 
242  PlayerListEntryScriptedWidget GetSelectedPlayer()
243  {
244  return m_SelectedEntry;
245  }
246 
247  void SelectPlayer( PlayerListEntryScriptedWidget entry )
248  {
249  if ( m_SelectedEntry )
250  m_SelectedEntry.Deselect();
251  m_SelectedEntry = entry;
252  if ( GetGame().GetUIManager().GetMenu() )
253  GetGame().GetUIManager().GetMenu().Refresh();
254  ScrollToEntry( entry );
255  }
256 
257  void ScrollToEntry( PlayerListEntryScriptedWidget entry )
258  {
259  if ( entry )
260  {
261  float x, y;
262  float x_s, y_s;
263  float x_l, y_l;
264 
265  Widget root = entry.GetButtonWidget().GetParent();
266  Widget first_child = root.GetParent().GetChildren();
267  Widget last_child = first_child;
268  while ( last_child )
269  {
270  if ( last_child.GetSibling() )
271  last_child = last_child.GetSibling();
272  else
273  break;
274  }
275 
276  root.GetParent().Update();
277  root.Update();
278 
279  m_ScrollContainer.GetScreenPos( x, y );
280  m_ScrollContainer.GetScreenSize( x_s, y_s );
281 
282  float bottom_pos = y + y_s;
283 
284  root.GetScreenPos( x_l, y_l );
285  root.GetScreenSize( x_s, y_s );
286 
287  if ( root == first_child )
288  {
289  m_ScrollContainer.VScrollToPos01( 0 );
290  }
291  else if ( root == last_child )
292  {
293  m_ScrollContainer.VScrollToPos01( 1 );
294  }
295  else if ( y_l + y_s >= bottom_pos )
296  {
297  m_ScrollContainer.VScrollToPos( m_ScrollContainer.GetVScrollPos() + y_s );
298  }
299  else if ( y_l <= y )
300  {
301  m_ScrollContainer.VScrollToPos( m_ScrollContainer.GetVScrollPos() - y_s );
302  }
303  }
304  }
305 }
GetGame
proto native CGame GetGame()
BiosFriendInfo
BiosFriendInfo represents friend information.
Definition: biossocialservice.c:4
y
Icon y
IsEmpty
override bool IsEmpty()
Definition: fireplacebase.c:2454
ScrollToEntry
void ScrollToEntry(ServerBrowserEntry entry)
Definition: serverbrowsertab.c:132
map
map
Definition: controlsxboxnew.c:3
EBiosError
EBiosError
Possible Error codes for bios API. This is the list of errors that can be returned from bios API....
Definition: bioserrormodule.c:6
GetServersResult
GetServersResult the output structure of the GetServers operation.
Definition: bioslobbyservice.c:224
SyncPlayerList
Definition: syncplayerlist.c:1
UID
@ UID
Definition: connecterrorservermodule.c:19
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
SetFocus
proto native void SetFocus(Widget w)
name
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
x
Icon x
BiosPrivacyUidResult
BiosPrivacyUidResult represents the per user result of the GetPermissionsAsync request.
Definition: biosprivacyservice.c:43
SyncPlayer
Definition: syncplayer.c:1
Widget
Definition: enwidgets.c:189
m_Root
protected Widget m_Root
Definition: sizetochild.c:91
OnlineServices
Definition: onlineservices.c:1
ScriptedWidgetEventHandler
map: item x vector(index, width, height)
Definition: enwidgets.c:650