Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
serverbrowsertabpc.c
Go to the documentation of this file.
2 {
3  protected const int SERVERS_VISIBLE_COUNT = 24;
4  protected const int PAGES_BUTTONS_COUNT = 10;
5 
6  protected int m_TotalServersCount; //UNUSED
7  protected int m_PageIndex;
8  protected int m_PageStartNum;
9  protected int m_PageEndNum;
10  protected int m_PagesCount;
11  protected int m_ServersEstimateCount;
12 
13  protected Widget m_PnlPagesPanel;
14  protected TextWidget m_PnlPagesLoadingText;
15  protected ButtonWidget m_BtnPagesFirst;
16  protected ButtonWidget m_BtnPagesLast;
17 
18  protected Widget m_FilterSearchIP;
19  protected Widget m_FilterSearchIPBox;
20  protected Widget m_FilterPanelPing;
21  protected Widget m_FilterPanelAccTime;
22 
23  protected ref array<ButtonWidget> m_BtnPages;
24  protected ref array<ref ServerBrowserEntry> m_ServerListEntries;
25 
26  protected ref TStringArray m_TempTime = new TStringArray;
27 
28  protected override void Construct( Widget parent, ServerBrowserMenuNew menu, TabType type )
29  {
30  #ifdef PLATFORM_CONSOLE
31  m_Root = GetGame().GetWorkspace().CreateWidgets( "gui/layouts/new_ui/server_browser/xbox/server_browser_tab.layout", parent );
32  #else
33  #ifdef PLATFORM_WINDOWS
34  m_Root = GetGame().GetWorkspace().CreateWidgets( "gui/layouts/new_ui/server_browser/pc/server_browser_tab_pages.layout", parent );
35  #endif
36  #endif
37 
38  m_ServerListScroller = ScrollWidget.Cast( m_Root.FindAnyWidget( "server_list_scroller" ) );
39  m_ServerList = SpacerBaseWidget.Cast( m_ServerListScroller.FindAnyWidget( "server_list_content" ) );
40  m_ServerListScroller.VScrollToPos01( 0 );
41 
42  m_ServerListEntries = new array<ref ServerBrowserEntry>;
47 
55 
56  m_Menu = menu;
57  m_TabType = type;
58 
59  m_ApplyFilter = m_Root.FindAnyWidget( "apply_filter_button" );
60  m_RefreshList = m_Root.FindAnyWidget( "refresh_list_button" );
61  m_FiltersChanged = m_Root.FindAnyWidget( "unapplied_filters_notify" );
62  m_HostSort = m_Root.FindAnyWidget( "server_list_content_header_host" );
63  m_TimeSort = m_Root.FindAnyWidget( "server_list_content_header_time" );
64  m_PopulationSort = m_Root.FindAnyWidget( "server_list_content_header_population" );
65  m_SlotsSort = m_Root.FindAnyWidget( "server_list_content_header_slots" );
66  m_PingSort = m_Root.FindAnyWidget( "server_list_content_header_ping" );
67 
68  m_FilterSearchText = m_Root.FindAnyWidget( "search_name_setting" );
69  m_FilterSearchTextBox = m_Root.FindAnyWidget( "search_name_setting_option" );
70  m_FilterSearchIP = m_Root.FindAnyWidget( "search_ip_setting" );
71  m_FilterSearchIPBox = m_Root.FindAnyWidget( "search_ip_setting_option" );
72 
73  m_FilterPanelAccTime = m_Root.FindAnyWidget( "accelerated_time_setting" );
74  m_FilterPanelPing = m_Root.FindAnyWidget( "ping_setting" );
75  //m_FilterPanelPing.SetHandler( this );
76 
77  m_LoadingText = TextWidget.Cast( m_Root.FindAnyWidget( "loading_servers_info" ) );
78 
80 
81  if ( type == TabType.LAN)
82  {
83  DisableFilters();
84  }
85 
86  m_Filters = new ServerBrowserFilterContainer( m_Root.FindAnyWidget( "filters_content" ), this );
87 
88  m_Root.SetHandler( this );
89 
90  SetSort(ESortType.HOST, ESortOrder.ASCENDING);
91 
92  m_BtnPages = new array<ButtonWidget>();
93 
94  int page_button_num = 1;
95  ButtonWidget page_button = ButtonWidget.Cast( m_Root.FindAnyWidget( "servers_navigation_page"+ page_button_num ) );
96 
97  if ( PAGES_BUTTONS_COUNT < 3 || PAGES_BUTTONS_COUNT > 10 )
98  {
99  Error("ServerBrowserTabPage->PAGES_BUTTONS_COUNT must be in range 3 - 10!");
100  return;
101  }
102 
103  while ( page_button )
104  {
105  page_button.Show(false);
106 
107  if ( page_button_num <= PAGES_BUTTONS_COUNT )
108  {
109  m_BtnPages.Insert( page_button );
110  }
111 
112  page_button_num++;
113  page_button = ButtonWidget.Cast( m_Root.FindAnyWidget( "servers_navigation_page"+ page_button_num ) );
114  }
115 
116  m_ResetFilters = ButtonWidget.Cast( m_Root.FindAnyWidget( "reset_filter_button" ) ) ;
117 
118  m_PnlPagesPanel = m_Root.FindAnyWidget( "servers_navigation_spacer" );
119  m_BtnPagePrev = ButtonWidget.Cast( m_Root.FindAnyWidget( "servers_navigation_prev" ) ) ;
120  m_BtnPageNext = ButtonWidget.Cast( m_Root.FindAnyWidget( "servers_navigation_next" ) ) ;
121  m_BtnPagesFirst = ButtonWidget.Cast( m_Root.FindAnyWidget( "servers_navigation_page_first" ) ) ;
122  m_BtnPagesLast = ButtonWidget.Cast( m_Root.FindAnyWidget( "servers_navigation_page_last" ) ) ;
123  m_PageIndex = 0;
124  m_PnlPagesPanel.Show( true );
125 
126  UpdatePageButtons();
127  }
128 
129  void ~ServerBrowserTabPc()
130  {
131 
132  }
133 
134  void DisableFilters()
135  {
136  m_Root.FindAnyWidget( "filters_content" ).Show( false );
137  m_Root.FindAnyWidget( "spacer" ).Show( false );
138  m_Root.FindAnyWidget( "spacer2" ).Show( false );
139  m_Root.FindAnyWidget( "reset_filter_button" ).Show( false );
140  m_ApplyFilter.Show( false );
141  m_FiltersChanged.Show( false );
142  }
143 
144  override void RefreshList()
145  {
146  for ( int i = 0; i < m_EntriesSorted.Count(); i++ )
147  {
148  m_EntriesSorted.GetElement(i).Clear();
149  }
150 
151  OnlineServices.m_ServersAsyncInvoker.Insert( m_Menu.OnLoadServersAsync, EScriptInvokerInsertFlags.NONE );
152 
153  m_LoadingFinished = false;
154  m_Loading = true;
155  m_TotalServersCount = 0;
157  m_ServersEstimateCount = 0;
158  m_PageIndex = 0;
159 
160  super.RefreshList();
161 
162  m_ServerListScroller.VScrollToPos01( 0 );
163  ButtonRefreshToCancel();
164  UpdateServerList();
165  UpdatePageButtons();
166  UpdateStatusBar();
167  }
168 
169  override void ResetFilters()
170  {
171  m_Filters.ResetFilters();
172 
174 
175  if ( !m_Loading )
176  {
178  }
179  }
180 
181  override void ApplyFilters()
182  {
183  m_Filters.SaveFilters();
184  //m_CurrentFilterInput = m_Filters.GetFilterOptionsPC();
185  RefreshList();
188  }
189 
190  void LoadingServersStop()
191  {
192  OnlineServices.m_ServersAsyncInvoker.Remove( m_Menu.OnLoadServersAsync );
193 
194  m_LoadingFinished = true;
195  m_Loading = false;
196 
197  ButtonCancelToRefresh();
198 
199  UpdateServerList();
200  UpdateStatusBar();
201  }
202 
203  override void OnLoadServersAsyncPC( ref GetServersResult result_list, EBiosError error, string response )
204  {
205  if ( result_list )
206  {
207  int count = result_list.m_Results.Count();
208  if ( count > 0 )
209  {
210  for ( int i = 0; i < count; i++ )
211  {
212  GetServersResultRow result = result_list.m_Results[i];
213  m_TotalServersCount++;
214 
215  result.m_SortName = result.m_Name.ToInt();
216  result.m_SortTime = GetTimeOfDayEnum( result.m_TimeOfDay );
217 
218  if ( PassFilter( result ) )
219  {
220  int sorted_index = AddSorted( result );
221  if ( sorted_index < (m_PageIndex * SERVERS_VISIBLE_COUNT + SERVERS_VISIBLE_COUNT) )
222  {
223  UpdateServerList();
224  UpdatePageButtons();
225  }
226  }
227 
228  if ( !m_Menu || m_Menu.GetServersLoadingTab() != m_TabType )
229  {
230  return;
231  }
232  }
233  }
234  else
235  {
236  m_Menu.SetServersLoadingTab( TabType.NONE );
237  }
238 
239  }
240  else
241  {
242  m_Menu.SetServersLoadingTab( TabType.NONE );
243  }
244 
245  if ( response == "thelastone" )
246  {
247  OnLoadServersAsyncPCFinished();
248  }
249  else
250  {
251  m_ServersEstimateCount = result_list.m_NumServers;
252  }
253 
254  UpdateServerList();
255  UpdateStatusBar();
256  }
257 
258  void OnLoadServersAsyncPCFinished()
259  {
260  LoadingServersStop();
261  }
262 
263  override bool OnClick( Widget w, int x, int y, int button )
264  {
265  super.OnClick( w, x, y, button );
266 
267  if ( button == MouseState.LEFT )
268  {
269  if ( w == m_ResetFilters )
270  {
271  ResetFilters();
272  }
273  else if ( w == m_ApplyFilter )
274  {
275  ApplyFilters();
276  return true;
277  }
278  else if ( w == m_RefreshList )
279  {
280  if ( m_Loading && !m_LoadingFinished )
281  {
282  LoadingServersStop();
283  }
284  else
285  {
286  RefreshList();
287  }
288 
289  return true;
290  }
291  else if ( w == m_BtnPagePrev )
292  {
293  OnClickPagePrev();
294  return true;
295  }
296  else if ( w == m_BtnPageNext )
297  {
298  OnClickPageNext();
299  return true;
300  }
301  else if ( w == m_BtnPagesLast )
302  {
303  OnClickPageEnd();
304  return true;
305  }
306  else if ( w == m_BtnPagesFirst )
307  {
308  OnClickPageFirst();
309  return true;
310  }
311  else
312  {
313  bool click = OnClickPage( w );
314 
315  if ( click )
316  {
317  return true;
318  }
319 
320  return false;
321  }
322  }
323  return false;
324  }
325 
326  override bool OnMouseEnter( Widget w, int x, int y )
327  {
328  if ( IsFocusable( w ) )
329  {
330  ColorHighlight( w );
331 
332  if ( w == m_FilterSearchText )
333  {
335  return true;
336  }
337  else if ( w == m_FilterSearchIP )
338  {
339  SetFocus( m_FilterSearchIPBox );
340  return true;
341  }
342 
343  return true;
344  }
345  return false;
346  }
347 
348  override bool OnMouseLeave( Widget w, Widget enterW, int x, int y )
349  {
350  if ( IsFocusable( w ) )
351  {
352  ColorNormal( w );
353 
354  if ( w == m_FilterSearchText || w == m_FilterSearchIP )
355  {
356  SetFocus( null );
357  }
358 
359  return true;
360  }
361  return false;
362  }
363 
364  override bool OnMouseButtonUp( Widget w, int x, int y, int button )
365  {
366  //Print("SG OnMouseButtonUp: "+ w.GetName());
367 
368  if ( button == MouseState.LEFT )
369  {
370  if ( w == m_HostSort )
371  {
372  ToggleSort( ESortType.HOST );
373  UpdateServerList();
374  return true;
375  }
376  else if ( w == m_TimeSort )
377  {
378  ToggleSort( ESortType.TIME );
379  UpdateServerList();
380  return true;
381  }
382  else if ( w == m_PopulationSort )
383  {
384  ToggleSort( ESortType.POPULATION );
385  UpdateServerList();
386  return true;
387  }
388  else if ( w == m_SlotsSort )
389  {
390  ToggleSort( ESortType.SLOTS );
391  UpdateServerList();
392  return true;
393  }
394  else if ( w == m_PingSort )
395  {
396  ToggleSort( ESortType.PING );
397  UpdateServerList();
398  return true;
399  }
400  }
401  return false;
402  }
403 
404  override void OnFilterChanged()
405  {
406  //m_FiltersChanged.Show( true );
407 
409 
410  if ( !m_Loading )
411  {
413  }
414  }
415 
416  void OnClickPagePrev()
417  {
418  if ( m_PageIndex > 0 )
419  {
420  SetPageIndex( m_PageIndex - 1);
421  }
422  else
423  {
424  SetPageIndex( m_PagesCount - 1 );
425  }
426  }
427 
428  void OnClickPageNext()
429  {
430  if ( m_PageIndex < (m_PagesCount - 1) )
431  {
432  SetPageIndex( m_PageIndex + 1 );
433  }
434  else
435  {
436  SetPageIndex( 0 );
437  }
438  }
439 
440  void OnClickPageEnd()
441  {
442  SetPageIndex( m_PagesCount - 1 );
443  }
444 
445  void OnClickPageFirst()
446  {
447  SetPageIndex( 0 );
448  }
449 
450  bool OnClickPage(Widget w)
451  {
452  for ( int i = 0; i < m_BtnPages.Count(); ++i )
453  {
454  if ( m_BtnPages[i] == w )
455  {
456  SetPageIndex( m_PageStartNum + i - 1 );
457  return true;
458  }
459  }
460 
461  return false;
462  }
463 
464  void SetPageIndex(int page_index)
465  {
466  m_PageIndex = page_index;
467  UpdateServerList();
468  UpdatePageButtons();
469  }
470 
471  void ToggleSort( ESortType type )
472  {
473  ESortOrder order = ESortOrder.ASCENDING;
474 
475  if ( m_SortType != type )
476  {
477  if ( m_SortInverted[type] == true )
478  {
479  m_EntriesSorted[type].Invert();
480  }
481 
482  m_SortInverted[type] = false;
483  }
484  else
485  {
486  if ( m_SortOrder == ESortOrder.ASCENDING )
487  {
488  m_EntriesSorted[type].Invert();
489  m_SortInverted[type] = true;
490  order = ESortOrder.DESCENDING;
491  }
492  else
493  {
494  m_EntriesSorted[type].Invert();
495  m_SortInverted[type] = false;
496  }
497  }
498 
499  SetSort( type, order );
500  }
501 
502  override void SetSort( ESortType type, ESortOrder order )
503  {
504  super.SetSort( type, order);
505 
506  #ifdef PLATFORM_WINDOWS
507  m_Root.FindAnyWidget( "host_sort" ).Show( false );
508  m_Root.FindAnyWidget( "population_sort" ).Show( false );
509  m_Root.FindAnyWidget( "slots_sort" ).Show( false );
510 
511  m_Root.FindAnyWidget( "time_sort" ).Show( false );
512  m_Root.FindAnyWidget( "ping_sort" ).Show( false );
513 
514  TextWidget root;
515  root = TextWidget.Cast( m_Root.FindAnyWidget( "server_list_content_header_host_label" ) );
516  root.SetColor( ARGBF( 1, 1, 1, 1 ) );
517  root = TextWidget.Cast( m_Root.FindAnyWidget( "server_list_content_header_population_label" ) );
518  root.SetColor( ARGBF( 1, 1, 1, 1 ) );
519  root = TextWidget.Cast( m_Root.FindAnyWidget( "server_list_content_header_slots_label" ) );
520  root.SetColor( ARGBF( 1, 1, 1, 1 ) );
521 
522  root = TextWidget.Cast( m_Root.FindAnyWidget( "server_list_content_header_ping_label" ) );
523  root.SetColor( ARGBF( 1, 1, 1, 1 ) );
524  root = TextWidget.Cast( m_Root.FindAnyWidget( "server_list_content_header_time_label" ) );
525  root.SetColor( ARGBF( 1, 1, 1, 1 ) );
526 
527  string r_name;
528  string w_name;
529 
530  switch ( type )
531  {
532  case ESortType.HOST:
533  {
534  r_name = "server_list_content_header_host_label";
535  w_name = "host_sort";
536  break;
537  }
538  case ESortType.TIME:
539  {
540  r_name = "server_list_content_header_time_label";
541  w_name = "time_sort";
542  break;
543  }
544  case ESortType.POPULATION:
545  {
546  r_name = "server_list_content_header_population_label";
547  w_name = "population_sort";
548  break;
549  }
550  case ESortType.SLOTS:
551  {
552  r_name = "server_list_content_header_slots_label";
553  w_name = "slots_sort";
554  break;
555  }
556  case ESortType.PING:
557  {
558  r_name = "server_list_content_header_ping_label";
559  w_name = "ping_sort";
560  break;
561  }
562  }
563 
564  root = TextWidget.Cast( m_Root.FindAnyWidget( r_name ) );
565  root.SetColor( ARGBF( 1, 1, 0, 0 ) );
566 
567  m_Root.FindAnyWidget( w_name ).Show( true );
568  m_Root.FindAnyWidget( w_name + "_asc" ).Show( !m_SortOrder );
569  m_Root.FindAnyWidget( w_name + "_dsc" ).Show( m_SortOrder );
570  #endif
571  }
572 
573  int GetTimeOfDayEnum( string time_of_day )
574  {
575  m_TempTime.Clear();
576 
577  time_of_day.Split( ":", m_TempTime );
578 
579  int minutes = 0;
580 
581  if ( m_TempTime.Count() > 0 )
582  {
583  int h = m_TempTime[0].ToInt();
584 
585  if ( h >= 5 )
586  {
587  h -= 5;
588  }
589  else
590  {
591  h += 24;
592  }
593 
594  minutes = h * 60;
595  }
596 
597  if ( m_TempTime.Count() > 1 )
598  {
599  int m = m_TempTime[0].ToInt();
600  minutes += m;
601  }
602 
603  return minutes;
604  }
605 
606  // Return sorted index
607  override int AddSorted( GetServersResultRow entry )
608  {
609  int index_host = SortedInsert( entry, ESortType.HOST );
610  int index_time = SortedInsert( entry, ESortType.TIME );
611  int index_popu = SortedInsert( entry, ESortType.POPULATION );
612  int index_slot = SortedInsert( entry, ESortType.SLOTS );
613  int index_ping = SortedInsert( entry, ESortType.PING );
614  int index_favo = SortedInsert( entry, ESortType.FAVORITE );
615  int index_pass = SortedInsert( entry, ESortType.PASSWORDED );
616 
617  switch ( m_SortType )
618  {
619  case ESortType.HOST:
620  return index_host;
621  case ESortType.TIME:
622  return index_time;
623  case ESortType.POPULATION:
624  return index_popu;
625  case ESortType.SLOTS:
626  return index_slot;
627  case ESortType.PING:
628  return index_ping;
629  case ESortType.FAVORITE:
630  return index_favo;
631  case ESortType.PASSWORDED:
632  return index_pass;
633  }
634 
635  return 0;
636  }
637 
638  override void SelectServer( ServerBrowserEntry server )
639  {
640  super.SelectServer( server );
641 
642  #ifdef PLATFORM_CONSOLE
643  ScrollToEntry( server );
644  #endif
645 
646  m_SelectedServer = server;
647 
648  if (!m_Menu)
649  return;
650 
651  m_Menu.SelectServer( server );
652  }
653 
654  int SortedInsert(GetServersResultRow entry, ESortType sort_type)
655  {
656  return SortedInsertEx(entry, sort_type, m_SortInverted[sort_type]);
657  }
658 
659  private int SortedInsertEx(GetServersResultRow entry, ESortType sortType, bool isDescending)
660  {
662  int indexMax = list.Count() - 1;
663  int indexMin = 0;
664  int targetIndex = Math.Floor( indexMax / 2 );
665  int comparisonMultiplier = 1;
666 
667  // if order is descending, then invert comparison results
668  if (isDescending == true)
669  {
670  comparisonMultiplier = -1;
671  }
672 
673  if ( indexMax == -1 )
674  {
675  list.Insert( entry );
676  return 0;
677  }
678 
679  while ( true )
680  {
681  int comparisonResult = comparisonMultiplier * entry.CompareTo(list[targetIndex], sortType);
682 
683  if ((indexMax - indexMin) <= 1)
684  {
685  for (int i = indexMin; i <= indexMax; i++ )
686  {
687  comparisonResult = comparisonMultiplier * entry.CompareTo(list[i], sortType);
688 
689  if ( comparisonResult > 0 )
690  {
691  list.InsertAt( entry, i );
692  return i;
693  }
694  }
695 
696  // adding entry AFTER indexMax
697  targetIndex = Math.Min(indexMax + 1, list.Count());
698  list.InsertAt(entry, targetIndex);
699  return targetIndex;
700  }
701 
702  if (comparisonResult == 0)
703  {
704  list.InsertAt(entry, targetIndex);
705  return targetIndex;
706  }
707 
708  if (comparisonResult > 0)
709  {
710  indexMax = targetIndex;
711  }
712 
713  else if (comparisonResult < 0)
714  {
715  indexMin = targetIndex;
716  }
717 
718  targetIndex = indexMin + Math.Floor((indexMax - indexMin) / 2);
719  }
720 
721  return 0;
722  }
723 
724  // DEPRECATED
725  int SortedInsertAsc( GetServersResultRow entry, ESortType sort_type )
726  {
728 
729  int i;
730  int index_min = 0;
731  int index_max = list.Count() - 1;
732  int target_index = Math.Floor( index_max / 2 );
733 
734  if ( index_max == -1 )
735  {
736  list.Insert( entry );
737  return 0;
738  }
739 
740  if ( sort_type == ESortType.HOST )
741  {
742  string entry_value_str = entry.GetValueStr(ESortType.HOST);
743 
744  while ( true )
745  {
746  string target_value_str = list[target_index].GetValueStr(ESortType.HOST);
747 
748  if ( entry_value_str == target_value_str || ((index_max - index_min) <= 1) )
749  {
750  for ( i = index_min; i <= index_max; i++ )
751  {
752  if ( entry_value_str <= list[i].GetValueStr(ESortType.HOST) )
753  {
754  list.InsertAt( entry, i );
755  return i;
756  }
757  }
758 
759  index_max++;
760  list.InsertAt( entry, index_max );
761  return target_index;
762  }
763  else if ( entry_value_str < target_value_str )
764  {
765  index_max = target_index;
766  target_index = Math.Floor( target_index / 2 );
767  }
768  else if ( entry_value_str > target_value_str )
769  {
770  index_min = target_index;
771  target_index += Math.Floor( (index_max - index_min) / 2 );
772  }
773  }
774  }
775  else
776  {
777  int entry_value_int = entry.GetValueInt( sort_type );
778 
779  while ( true )
780  {
781  int target_value_int = list[target_index].GetValueInt( sort_type );
782 
783  if ( entry_value_int == target_value_int || ((index_max - index_min) <= 1) )
784  {
785  for ( i = index_min; i <= index_max; i++ )
786  {
787  if ( entry_value_int <= list[i].GetValueInt( sort_type ) )
788  {
789  list.InsertAt( entry, i );
790  return i;
791  }
792  }
793 
794  index_max++;
795  list.InsertAt( entry, index_max );
796  return target_index;
797  }
798  else if ( entry_value_int < target_value_int )
799  {
800  index_max = target_index;
801  target_index = Math.Floor( target_index / 2 );
802  }
803  else if ( entry_value_int > target_value_int )
804  {
805  index_min = target_index;
806  target_index += Math.Floor( (index_max - index_min) / 2 );
807  }
808  }
809  }
810 
811  return target_index;
812  }
813 
814  // DEPRECATED
815  int SortedInsertDesc( GetServersResultRow entry, ESortType sort_type )
816  {
818 
819  int i;
820  int index_min = 0;
821  int index_max = list.Count() - 1;
822  int target_index = Math.Floor( index_max / 2 );
823 
824  if ( index_max == -1 )
825  {
826  list.Insert( entry );
827  return 0;
828  }
829 
830  if ( sort_type == ESortType.HOST )
831  {
832  string entry_value_str = entry.GetValueStr(ESortType.HOST);
833 
834  while ( true )
835  {
836  string target_value_str = list[target_index].GetValueStr(ESortType.HOST);
837 
838  if ( entry_value_str == target_value_str || ((index_max - index_min) <= 1) )
839  {
840  for ( i = index_min; i <= index_max; i++ )
841  {
842  if ( entry_value_str >= list[i].GetValueStr(ESortType.HOST) )
843  {
844  list.InsertAt( entry, i );
845  return i;
846  }
847  }
848 
849  index_max++;
850  list.InsertAt( entry, index_max );
851  return target_index;
852  }
853  else if ( entry_value_str > target_value_str )
854  {
855  index_max = target_index;
856  target_index = Math.Floor( target_index / 2 );
857  }
858  else if ( entry_value_str < target_value_str )
859  {
860  index_min = target_index;
861  target_index += Math.Floor( (index_max - index_min) / 2 );
862  }
863  }
864  }
865  else
866  {
867  int entry_value_int = entry.GetValueInt( sort_type );
868 
869  while ( true )
870  {
871  int target_value_int = list[target_index].GetValueInt( sort_type );
872 
873  if ( entry_value_int == target_value_int || ((index_max - index_min) <= 1) )
874  {
875  for ( i = index_min; i <= index_max; i++ )
876  {
877  if ( entry_value_int >= list[i].GetValueInt( sort_type ) )
878  {
879  list.InsertAt( entry, i );
880  return i;
881  }
882  }
883 
884  index_max++;
885  list.InsertAt( entry, index_max );
886  return target_index;
887  }
888  else if ( entry_value_int > target_value_int )
889  {
890  index_max = target_index;
891  target_index = Math.Floor( target_index / 2 );
892  }
893  else if ( entry_value_int < target_value_int )
894  {
895  index_min = target_index;
896  target_index += Math.Floor( (index_max - index_min) / 2 );
897  }
898  }
899  }
900 
901  return target_index;
902  }
903 
904  void UpdatePageButtons()
905  {
906  m_PagesCount = Math.Ceil( m_TotalLoadedServers / SERVERS_VISIBLE_COUNT );
907  if ( m_PagesCount > 1 )
908  {
909  m_PnlPagesPanel.Show( true );
910 
911  int i;
912  int btn_index_center = Math.Round( PAGES_BUTTONS_COUNT / 2) - 1;
913  m_PageStartNum = 1;
914  m_PageEndNum = PAGES_BUTTONS_COUNT;
915 
916  if ( m_PagesCount <= PAGES_BUTTONS_COUNT )
917  {
918  m_PageEndNum = m_PagesCount;
919 
920  // Pages are less like buttons - changing selected button
921  for ( i = 1; i <= m_BtnPages.Count(); ++i )
922  {
923  bool is_page_button_enable = ( i <= m_PagesCount );
924 
925  int page_index = (i - 1);
926  m_BtnPages[page_index].Show( is_page_button_enable );
927  m_BtnPages[page_index].SetText( i.ToString() );
928 
929  if ( m_PageIndex == page_index )
930  {
931  m_BtnPages[page_index].SetState( true );
932  }
933  else
934  {
935  m_BtnPages[page_index].SetState( false );
936  }
937  }
938  }
939  else
940  {
941  // Pages are more like buttons
942  if ( m_PageIndex <= btn_index_center )
943  {
944  //Left side (start of pages)
945  //m_PageStartNum = 1;
946  //m_PageEndNum = PAGES_BUTTONS_COUNT;
947  }
948  else
949  {
950  m_PageStartNum = m_PageIndex - btn_index_center + 1;
951  m_PageEndNum = m_PageIndex + (PAGES_BUTTONS_COUNT - btn_index_center);
952 
953  if ( m_PageEndNum > m_PagesCount )
954  {
955  // Right side (end of pages)
956  m_PageStartNum -= m_PageEndNum - m_PagesCount;
957  m_PageEndNum -= m_PageEndNum - m_PagesCount;
958  }
959  }
960 
961 
962  // Button Selection
963  int selected_btn_index = m_PageIndex;
964  if ( m_PageIndex > btn_index_center )
965  {
966  if ( m_PageEndNum == m_PagesCount )
967  {
968  //Right
969  selected_btn_index = PAGES_BUTTONS_COUNT - (m_PagesCount - m_PageIndex);
970  }
971  else
972  {
973  //Center
974  selected_btn_index = btn_index_center;
975  }
976  }
977 
978 
979  for ( i = 0; i < m_BtnPages.Count(); ++i )
980  {
981  m_BtnPages[i].SetText( (m_PageStartNum + i).ToString() );
982  m_BtnPages[i].SetState( ( i == selected_btn_index ) );
983  }
984  }
985 
986  // Button GoTo Prev Page
987  if ( m_PageIndex > 0 )
988  {
989  m_BtnPagePrev.SetText( "<" );
990  m_BtnPagePrev.Enable( true );
991  }
992  else
993  {
994  m_BtnPagePrev.SetText( "" );
995  m_BtnPagePrev.Enable( false );
996  }
997 
998  // Button GoTo Next Page
999  if ( m_PageIndex < (m_PagesCount - 1) )
1000  {
1001  m_BtnPageNext.SetText( ">" );
1002  m_BtnPageNext.Enable( true );
1003  }
1004  else
1005  {
1006  m_BtnPageNext.SetText( "" );
1007  m_BtnPageNext.Enable( false );
1008  }
1009 
1010  // Button GoTo First Page
1011  if ( m_PageStartNum == 1 )
1012  {
1013  m_BtnPagesFirst.SetText( "" );
1014  m_BtnPagesFirst.Enable( false );
1015  }
1016  else
1017  {
1018  m_BtnPagesFirst.SetText( "<<" );
1019  m_BtnPagesFirst.Enable( true );
1020  }
1021 
1022  // Button GoTo Last Page
1023  if ( m_PageEndNum == m_PagesCount )
1024  {
1025  m_BtnPagesLast.SetText( "" );
1026  m_BtnPagesLast.Enable( false );
1027  }
1028  else
1029  {
1030  m_BtnPagesLast.SetText( ">>" );
1031  m_BtnPagesLast.Enable( true );
1032  }
1033  }
1034  else
1035  {
1036  m_PnlPagesPanel.Show(false);
1037  }
1038  }
1039 
1040  void UpdateServerList()
1041  {
1042  int lastFilledIndexOnPage = 0;
1044  ServerBrowserEntry entry;
1045 
1046  m_EntryWidgets.Clear();
1047 
1048  for ( int i = 0; i < SERVERS_VISIBLE_COUNT; ++i )
1049  {
1050  int serverIndex = i + (SERVERS_VISIBLE_COUNT * m_PageIndex);
1051 
1052  if ( serverIndex < m_EntriesSorted[m_SortType].Count() )
1053  {
1054  GetServersResultRow server_info = m_EntriesSorted[m_SortType][serverIndex];
1055 
1056  if ( server_info.m_Favorite )
1057  {
1058  m_OnlineFavServers.Insert(server_info.m_Id);
1059  }
1060 
1061  entry = GetServerEntryByIndex(i, server_info.m_Id);
1062  entry.Show( true );
1063  entry.SetIsOnline( true );
1064  entry.FillInfo( server_info );
1065  entry.SetMods( m_EntryMods.Get( server_info.m_Id ) );
1066  entry.UpdateEntry();
1067 
1068  if ( GetRootMenu() && GetRootMenu().GetServersLoadingTab() != TabType.NONE )
1069  {
1070  entry.SetName("#dayz_game_loading");
1071  }
1072 
1073  lastFilledIndexOnPage++;
1074  }
1075  else
1076  {
1077  entry = GetServerEntryByIndex(i, "-1");
1078 
1079  if ( entry )
1080  {
1081  entry.Show( false );
1082  }
1083  }
1084  }
1085  LoadExtraEntries(lastFilledIndexOnPage);
1086 
1087  m_ServerList.Update();
1088  }
1089 
1090  void UpdateStatusBar()
1091  {
1092  string serversFound = string.Format("#servers_found: %1", m_TotalLoadedServers);
1093  if ( m_LoadingFinished )
1094  {
1095  m_LoadingText.SetText( serversFound );
1096  }
1097  else
1098  {
1099  m_LoadingText.SetText( string.Format("#dayz_game_loading %1", serversFound) );
1100  }
1101  }
1102 
1103  override void OnLoadServerModsAsync( string server_id, array<string> mods )
1104  {
1105  super.OnLoadServerModsAsync( server_id, mods );
1106 
1107  if ( m_EntryWidgets.Contains( server_id ) )
1108  {
1109  m_EntryWidgets.Get( server_id ).SetMods( mods );
1110  }
1111  }
1112 
1113  protected ServerBrowserEntry GetServerEntryByIndex( int index, string server_id )
1114  {
1115  ref ServerBrowserEntry entry;
1116 
1117  if ( index >= 0 )
1118  {
1119  if ( index < m_ServerListEntries.Count() )
1120  {
1121  entry = m_ServerListEntries[index];
1122  }
1123  else
1124  {
1125  entry = new ServerBrowserEntry( null, index, this );
1126  m_ServerList.AddChild( entry.GetRoot(), false );
1127 
1128  m_ServerListEntries.Insert(entry);
1129  }
1130  }
1131  else
1132  {
1133  return null;
1134  }
1135 
1136  // Refresh list
1137  m_EntryWidgets.Insert( server_id, entry );
1138 
1139  return entry;
1140  }
1141 
1142  override bool IsFocusable( Widget w )
1143  {
1144  if ( w )
1145  {
1146  if ( super.IsFocusable( w ) )
1147  {
1148  return true;
1149  }
1150 
1151  if ( w == m_ServerListScroller )
1152  {
1153  return false;
1154  }
1155 
1156  if ( w == m_HostSort || w == m_TimeSort || w == m_PopulationSort || w == m_SlotsSort || w == m_PingSort || w == m_FilterSearchIP )
1157  {
1158  return true;
1159  }
1160 
1161  if ( w == m_FilterPanelAccTime || m_FilterPanelPing )
1162  {
1163  return true;
1164  }
1165 
1166  return false;
1167  }
1168  return false;
1169  }
1170 
1171  void ButtonRefreshToCancel()
1172  {
1173  ButtonWidget btn = ButtonWidget.Cast( m_RefreshList );
1174  btn.SetText( "#menu_cancel" );
1175  }
1176 
1177  void ButtonCancelToRefresh()
1178  {
1179  ButtonWidget btn = ButtonWidget.Cast( m_RefreshList );
1180  btn.SetText( "#STR_server_browser_tab_root_filters_root_filters_content_refresh_list_button0" );
1181  }
1182 }
GetGame
proto native CGame GetGame()
m_SortType
protected ESortType m_SortType
Definition: serverbrowsertab.c:34
TabType
TabType
Definition: serverbrowsertab.c:1
m_TotalLoadedServers
protected int m_TotalLoadedServers
Definition: serverbrowsertab.c:42
GetValueStr
string GetValueStr(ESortType sort_type)
Definition: bioslobbyservice.c:109
Error
void Error(string err)
Messagebox with error message.
Definition: endebug.c:90
m_EntryMods
protected ref map< string, ref array< string > > m_EntryMods
Definition: serverbrowsertab.c:26
m_BtnPagePrev
protected ButtonWidget m_BtnPagePrev
Definition: serverbrowsertab.c:64
m_ResetFilters
protected Widget m_ResetFilters
Definition: serverbrowsertab.c:54
ButtonDisable
void ButtonDisable(Widget w)
Definition: serverbrowsertab.c:612
ServerBrowserTabPc
Definition: serverbrowserfavoritestabpc.c:1
ButtonEnable
void ButtonEnable(Widget w)
Definition: serverbrowsertab.c:606
m_TimeSort
protected Widget m_TimeSort
Definition: serverbrowsertab.c:57
TStringArray
array< string > TStringArray
Definition: enscript.c:685
m_LoadingFinished
protected bool m_LoadingFinished
Definition: serverbrowsertab.c:45
m_EntryWidgets
protected ref map< string, ref ServerBrowserEntry > m_EntryWidgets
Definition: serverbrowsertab.c:25
m_TabType
protected TabType m_TabType
Definition: serverbrowsertab.c:33
m_FilterSearchTextBox
protected Widget m_FilterSearchTextBox
Definition: serverbrowsertab.c:62
OnLoadServersAsyncPC
void OnLoadServersAsyncPC(ref GetServersResult result_list, EBiosError error, string response)
Definition: serverbrowsertab.c:483
y
Icon y
m_ServerListScroller
protected ScrollWidget m_ServerListScroller
Definition: serverbrowsertab.c:20
EScriptInvokerInsertFlags
EScriptInvokerInsertFlags
Definition: tools.c:129
ScrollToEntry
void ScrollToEntry(ServerBrowserEntry entry)
Definition: serverbrowsertab.c:132
m_SelectedServer
protected ServerBrowserEntry m_SelectedServer
Definition: serverbrowsertab.c:31
m_ServerList
protected SpacerBaseWidget m_ServerList
Definition: serverbrowsertab.c:21
m_Menu
protected ServerBrowserMenuNew m_Menu
Definition: serverbrowsertab.c:30
m_FilterSearchText
protected Widget m_FilterSearchText
Definition: serverbrowsertab.c:61
ApplyFilters
void ApplyFilters()
Definition: serverbrowsertab.c:397
m_ApplyFilter
protected Widget m_ApplyFilter
Definition: serverbrowsertab.c:52
OnMouseLeave
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Definition: uihintpanel.c:276
GetRootMenu
ServerBrowserMenuNew GetRootMenu()
Definition: serverbrowsertab.c:98
OnMouseButtonUp
override bool OnMouseButtonUp(Widget w, int x, int y, int button)
Definition: radialmenu.c:668
m_Loading
protected bool m_Loading
Definition: serverbrowsertab.c:40
ESortType
ESortType
Definition: bioslobbyservice.c:6
m_FiltersChanged
protected Widget m_FiltersChanged
Definition: serverbrowsertab.c:55
map
map
Definition: controlsxboxnew.c:3
ServerBrowserTab
Definition: serverbrowsertabconsole.c:1
m_OnlineFavServers
protected ref set< string > m_OnlineFavServers
Definition: serverbrowsertab.c:69
m_SortInverted
protected ref map< ESortType, ESortOrder > m_SortInverted
Definition: serverbrowsertab.c:68
m_Filters
protected ref ServerBrowserFilterContainer m_Filters
Definition: serverbrowsertab.c:28
SelectServer
void SelectServer(ServerBrowserEntry server)
Definition: serverbrowsertab.c:469
TextWidget
Definition: enwidgets.c:219
SetSort
proto native void SetSort(int sort, bool immedUpdate=true)
ColorNormal
void ColorNormal(Widget w)
Definition: serverbrowsertab.c:668
m_EntriesSorted
protected ref map< ESortType, ref array< ref GetServersResultRow > > m_EntriesSorted
Definition: serverbrowsertab.c:67
ResetFilters
void ResetFilters()
Definition: serverbrowsertab.c:392
m_RefreshList
protected Widget m_RefreshList
Definition: serverbrowsertab.c:53
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
ColorHighlight
void ColorHighlight(Widget w)
Definition: serverbrowsertab.c:619
GetServersResult
GetServersResult the output structure of the GetServers operation.
Definition: bioslobbyservice.c:224
m_SlotsSort
protected Widget m_SlotsSort
Definition: serverbrowsertab.c:59
OnFilterChanged
void OnFilterChanged()
Definition: serverbrowsertab.c:202
ESortOrder
ESortOrder
Definition: bioslobbyservice.c:18
ARGBF
int ARGBF(float fa, float fr, float fg, float fb)
Converts <0.0, 1.0> ARGB into color.
Definition: proto.c:332
MouseState
MouseState
Definition: ensystem.c:310
array< ButtonWidget >
SetFocus
proto native void SetFocus(Widget w)
x
Icon x
m_HostSort
protected Widget m_HostSort
Definition: serverbrowsertab.c:56
m_PingSort
protected Widget m_PingSort
Definition: serverbrowsertab.c:60
m_LoadingText
protected TextWidget m_LoadingText
Definition: serverbrowsertab.c:63
m_SortOrder
protected ESortOrder m_SortOrder
Definition: serverbrowsertab.c:35
m_PopulationSort
protected Widget m_PopulationSort
Definition: serverbrowsertab.c:58
PassFilter
bool PassFilter(GetServersResultRow result)
Definition: serverbrowsertab.c:508
GetValueInt
int GetValueInt(ESortType sort_type)
Definition: bioslobbyservice.c:122
OnLoadServerModsAsync
void OnLoadServerModsAsync(string server_id, array< string > mods)
Definition: serverbrowsertab.c:321
Widget
Definition: enwidgets.c:189
OnClick
override bool OnClick(Widget w, int x, int y, int button)
buttons clicks
Definition: dayzgame.c:146
Math
Definition: enmath.c:6
AddSorted
int AddSorted(GetServersResultRow entry)
Definition: serverbrowsertab.c:587
m_Root
protected Widget m_Root
Definition: sizetochild.c:91
OnMouseEnter
override bool OnMouseEnter(Widget w, int x, int y)
Definition: uihintpanel.c:267
OnlineServices
Definition: onlineservices.c:1
m_BtnPageNext
protected ButtonWidget m_BtnPageNext
Definition: serverbrowsertab.c:65
Count
@ Count
Definition: randomgeneratorsyncmanager.c:7
m_PageIndex
protected int m_PageIndex
Definition: uihintpanel.c:21
IsFocusable
bool IsFocusable(Widget w)
Definition: serverbrowsertab.c:284