3 protected const int SERVERS_VISIBLE_COUNT = 24;
4 protected const int PAGES_BUTTONS_COUNT = 10;
6 protected int m_TotalServersCount;
8 protected int m_PageStartNum;
9 protected int m_PageEndNum;
10 protected int m_PagesCount;
11 protected int m_ServersEstimateCount;
13 protected Widget m_PnlPagesPanel;
15 protected ButtonWidget m_BtnPagesFirst;
16 protected ButtonWidget m_BtnPagesLast;
18 protected Widget m_FilterSearchIP;
19 protected Widget m_FilterSearchIPBox;
20 protected Widget m_FilterPanelPing;
21 protected Widget m_FilterPanelAccTime;
28 protected override void Construct(
Widget parent, ServerBrowserMenuNew menu,
TabType type )
30 #ifdef PLATFORM_CONSOLE
31 m_Root =
GetGame().GetWorkspace().CreateWidgets(
"gui/layouts/new_ui/server_browser/xbox/server_browser_tab.layout", parent );
33 #ifdef PLATFORM_WINDOWS
34 m_Root =
GetGame().GetWorkspace().CreateWidgets(
"gui/layouts/new_ui/server_browser/pc/server_browser_tab_pages.layout", parent );
70 m_FilterSearchIP =
m_Root.FindAnyWidget(
"search_ip_setting" );
71 m_FilterSearchIPBox =
m_Root.FindAnyWidget(
"search_ip_setting_option" );
73 m_FilterPanelAccTime =
m_Root.FindAnyWidget(
"accelerated_time_setting" );
74 m_FilterPanelPing =
m_Root.FindAnyWidget(
"ping_setting" );
86 m_Filters =
new ServerBrowserFilterContainer(
m_Root.FindAnyWidget(
"filters_content" ),
this );
94 int page_button_num = 1;
95 ButtonWidget page_button = ButtonWidget.Cast(
m_Root.FindAnyWidget(
"servers_navigation_page"+ page_button_num ) );
97 if ( PAGES_BUTTONS_COUNT < 3 || PAGES_BUTTONS_COUNT > 10 )
99 Error(
"ServerBrowserTabPage->PAGES_BUTTONS_COUNT must be in range 3 - 10!");
103 while ( page_button )
105 page_button.Show(
false);
107 if ( page_button_num <= PAGES_BUTTONS_COUNT )
109 m_BtnPages.Insert( page_button );
113 page_button = ButtonWidget.Cast(
m_Root.FindAnyWidget(
"servers_navigation_page"+ page_button_num ) );
118 m_PnlPagesPanel =
m_Root.FindAnyWidget(
"servers_navigation_spacer" );
121 m_BtnPagesFirst = ButtonWidget.Cast(
m_Root.FindAnyWidget(
"servers_navigation_page_first" ) ) ;
122 m_BtnPagesLast = ButtonWidget.Cast(
m_Root.FindAnyWidget(
"servers_navigation_page_last" ) ) ;
124 m_PnlPagesPanel.Show(
true );
134 void DisableFilters()
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 );
144 override void RefreshList()
155 m_TotalServersCount = 0;
157 m_ServersEstimateCount = 0;
163 ButtonRefreshToCancel();
190 void LoadingServersStop()
197 ButtonCancelToRefresh();
207 int count = result_list.m_Results.Count();
210 for (
int i = 0; i < count; i++ )
212 GetServersResultRow result = result_list.m_Results[i];
213 m_TotalServersCount++;
215 result.m_SortName = result.m_Name.ToInt();
216 result.m_SortTime = GetTimeOfDayEnum( result.m_TimeOfDay );
221 if ( sorted_index < (
m_PageIndex * SERVERS_VISIBLE_COUNT + SERVERS_VISIBLE_COUNT) )
245 if ( response ==
"thelastone" )
247 OnLoadServersAsyncPCFinished();
251 m_ServersEstimateCount = result_list.m_NumServers;
258 void OnLoadServersAsyncPCFinished()
260 LoadingServersStop();
265 super.OnClick( w,
x,
y, button );
282 LoadingServersStop();
301 else if ( w == m_BtnPagesLast )
306 else if ( w == m_BtnPagesFirst )
313 bool click = OnClickPage( w );
337 else if ( w == m_FilterSearchIP )
416 void OnClickPagePrev()
424 SetPageIndex( m_PagesCount - 1 );
428 void OnClickPageNext()
440 void OnClickPageEnd()
442 SetPageIndex( m_PagesCount - 1 );
445 void OnClickPageFirst()
450 bool OnClickPage(
Widget w)
452 for (
int i = 0; i < m_BtnPages.Count(); ++i )
454 if ( m_BtnPages[i] == w )
456 SetPageIndex( m_PageStartNum + i - 1 );
464 void SetPageIndex(
int page_index)
504 super.SetSort( type, order);
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 );
511 m_Root.FindAnyWidget(
"time_sort" ).Show(
false );
512 m_Root.FindAnyWidget(
"ping_sort" ).Show(
false );
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 ) );
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 ) );
534 r_name =
"server_list_content_header_host_label";
535 w_name =
"host_sort";
540 r_name =
"server_list_content_header_time_label";
541 w_name =
"time_sort";
546 r_name =
"server_list_content_header_population_label";
547 w_name =
"population_sort";
552 r_name =
"server_list_content_header_slots_label";
553 w_name =
"slots_sort";
558 r_name =
"server_list_content_header_ping_label";
559 w_name =
"ping_sort";
565 root.SetColor(
ARGBF( 1, 1, 0, 0 ) );
567 m_Root.FindAnyWidget( w_name ).Show(
true );
573 int GetTimeOfDayEnum(
string time_of_day )
577 time_of_day.Split(
":", m_TempTime );
581 if ( m_TempTime.Count() > 0 )
583 int h = m_TempTime[0].ToInt();
597 if ( m_TempTime.Count() > 1 )
599 int m = m_TempTime[0].ToInt();
607 override int AddSorted( GetServersResultRow entry )
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 );
640 super.SelectServer( server );
642 #ifdef PLATFORM_CONSOLE
651 m_Menu.SelectServer( server );
654 int SortedInsert(GetServersResultRow entry,
ESortType sort_type)
656 return SortedInsertEx(entry, sort_type,
m_SortInverted[sort_type]);
659 private int SortedInsertEx(GetServersResultRow entry,
ESortType sortType,
bool isDescending)
662 int indexMax = list.Count() - 1;
664 int targetIndex =
Math.Floor( indexMax / 2 );
665 int comparisonMultiplier = 1;
668 if (isDescending ==
true)
670 comparisonMultiplier = -1;
673 if ( indexMax == -1 )
675 list.Insert( entry );
681 int comparisonResult = comparisonMultiplier * entry.CompareTo(list[targetIndex], sortType);
683 if ((indexMax - indexMin) <= 1)
685 for (
int i = indexMin; i <= indexMax; i++ )
687 comparisonResult = comparisonMultiplier * entry.CompareTo(list[i], sortType);
689 if ( comparisonResult > 0 )
691 list.InsertAt( entry, i );
697 targetIndex =
Math.Min(indexMax + 1, list.Count());
698 list.InsertAt(entry, targetIndex);
702 if (comparisonResult == 0)
704 list.InsertAt(entry, targetIndex);
708 if (comparisonResult > 0)
710 indexMax = targetIndex;
713 else if (comparisonResult < 0)
715 indexMin = targetIndex;
718 targetIndex = indexMin +
Math.Floor((indexMax - indexMin) / 2);
725 int SortedInsertAsc( GetServersResultRow entry,
ESortType sort_type )
731 int index_max = list.Count() - 1;
732 int target_index =
Math.Floor( index_max / 2 );
734 if ( index_max == -1 )
736 list.Insert( entry );
742 string entry_value_str = entry.GetValueStr(
ESortType.HOST);
746 string target_value_str = list[target_index].GetValueStr(
ESortType.HOST);
748 if ( entry_value_str == target_value_str || ((index_max - index_min) <= 1) )
750 for ( i = index_min; i <= index_max; i++ )
754 list.InsertAt( entry, i );
760 list.InsertAt( entry, index_max );
763 else if ( entry_value_str < target_value_str )
765 index_max = target_index;
766 target_index =
Math.Floor( target_index / 2 );
768 else if ( entry_value_str > target_value_str )
770 index_min = target_index;
771 target_index +=
Math.Floor( (index_max - index_min) / 2 );
777 int entry_value_int = entry.GetValueInt( sort_type );
781 int target_value_int = list[target_index].GetValueInt( sort_type );
783 if ( entry_value_int == target_value_int || ((index_max - index_min) <= 1) )
785 for ( i = index_min; i <= index_max; i++ )
787 if ( entry_value_int <= list[i].
GetValueInt( sort_type ) )
789 list.InsertAt( entry, i );
795 list.InsertAt( entry, index_max );
798 else if ( entry_value_int < target_value_int )
800 index_max = target_index;
801 target_index =
Math.Floor( target_index / 2 );
803 else if ( entry_value_int > target_value_int )
805 index_min = target_index;
806 target_index +=
Math.Floor( (index_max - index_min) / 2 );
815 int SortedInsertDesc( GetServersResultRow entry,
ESortType sort_type )
821 int index_max = list.Count() - 1;
822 int target_index =
Math.Floor( index_max / 2 );
824 if ( index_max == -1 )
826 list.Insert( entry );
832 string entry_value_str = entry.GetValueStr(
ESortType.HOST);
836 string target_value_str = list[target_index].GetValueStr(
ESortType.HOST);
838 if ( entry_value_str == target_value_str || ((index_max - index_min) <= 1) )
840 for ( i = index_min; i <= index_max; i++ )
844 list.InsertAt( entry, i );
850 list.InsertAt( entry, index_max );
853 else if ( entry_value_str > target_value_str )
855 index_max = target_index;
856 target_index =
Math.Floor( target_index / 2 );
858 else if ( entry_value_str < target_value_str )
860 index_min = target_index;
861 target_index +=
Math.Floor( (index_max - index_min) / 2 );
867 int entry_value_int = entry.GetValueInt( sort_type );
871 int target_value_int = list[target_index].GetValueInt( sort_type );
873 if ( entry_value_int == target_value_int || ((index_max - index_min) <= 1) )
875 for ( i = index_min; i <= index_max; i++ )
877 if ( entry_value_int >= list[i].
GetValueInt( sort_type ) )
879 list.InsertAt( entry, i );
885 list.InsertAt( entry, index_max );
888 else if ( entry_value_int > target_value_int )
890 index_max = target_index;
891 target_index =
Math.Floor( target_index / 2 );
893 else if ( entry_value_int < target_value_int )
895 index_min = target_index;
896 target_index +=
Math.Floor( (index_max - index_min) / 2 );
904 void UpdatePageButtons()
907 if ( m_PagesCount > 1 )
909 m_PnlPagesPanel.Show(
true );
912 int btn_index_center =
Math.Round( PAGES_BUTTONS_COUNT / 2) - 1;
914 m_PageEndNum = PAGES_BUTTONS_COUNT;
916 if ( m_PagesCount <= PAGES_BUTTONS_COUNT )
918 m_PageEndNum = m_PagesCount;
921 for ( i = 1; i <= m_BtnPages.Count(); ++i )
923 bool is_page_button_enable = ( i <= m_PagesCount );
925 int page_index = (i - 1);
926 m_BtnPages[page_index].Show( is_page_button_enable );
927 m_BtnPages[page_index].SetText( i.ToString() );
931 m_BtnPages[page_index].SetState(
true );
935 m_BtnPages[page_index].SetState(
false );
950 m_PageStartNum =
m_PageIndex - btn_index_center + 1;
951 m_PageEndNum =
m_PageIndex + (PAGES_BUTTONS_COUNT - btn_index_center);
953 if ( m_PageEndNum > m_PagesCount )
956 m_PageStartNum -= m_PageEndNum - m_PagesCount;
957 m_PageEndNum -= m_PageEndNum - m_PagesCount;
966 if ( m_PageEndNum == m_PagesCount )
969 selected_btn_index = PAGES_BUTTONS_COUNT - (m_PagesCount -
m_PageIndex);
974 selected_btn_index = btn_index_center;
979 for ( i = 0; i < m_BtnPages.Count(); ++i )
981 m_BtnPages[i].SetText( (m_PageStartNum + i).ToString() );
982 m_BtnPages[i].SetState( ( i == selected_btn_index ) );
1011 if ( m_PageStartNum == 1 )
1013 m_BtnPagesFirst.SetText(
"" );
1014 m_BtnPagesFirst.Enable(
false );
1018 m_BtnPagesFirst.SetText(
"<<" );
1019 m_BtnPagesFirst.Enable(
true );
1023 if ( m_PageEndNum == m_PagesCount )
1025 m_BtnPagesLast.SetText(
"" );
1026 m_BtnPagesLast.Enable(
false );
1030 m_BtnPagesLast.SetText(
">>" );
1031 m_BtnPagesLast.Enable(
true );
1036 m_PnlPagesPanel.Show(
false);
1040 void UpdateServerList()
1042 int lastFilledIndexOnPage = 0;
1044 ServerBrowserEntry entry;
1048 for (
int i = 0; i < SERVERS_VISIBLE_COUNT; ++i )
1050 int serverIndex = i + (SERVERS_VISIBLE_COUNT *
m_PageIndex);
1056 if ( server_info.m_Favorite )
1061 entry = GetServerEntryByIndex(i, server_info.m_Id);
1063 entry.SetIsOnline(
true );
1064 entry.FillInfo( server_info );
1065 entry.SetMods(
m_EntryMods.Get( server_info.m_Id ) );
1066 entry.UpdateEntry();
1070 entry.SetName(
"#dayz_game_loading");
1073 lastFilledIndexOnPage++;
1077 entry = GetServerEntryByIndex(i,
"-1");
1081 entry.Show(
false );
1085 LoadExtraEntries(lastFilledIndexOnPage);
1090 void UpdateStatusBar()
1099 m_LoadingText.SetText(
string.Format(
"#dayz_game_loading %1", serversFound) );
1105 super.OnLoadServerModsAsync( server_id, mods );
1113 protected ServerBrowserEntry GetServerEntryByIndex(
int index,
string server_id )
1115 ref ServerBrowserEntry entry;
1119 if ( index < m_ServerListEntries.Count() )
1121 entry = m_ServerListEntries[index];
1125 entry =
new ServerBrowserEntry(
null, index,
this );
1128 m_ServerListEntries.Insert(entry);
1146 if ( super.IsFocusable( w ) )
1161 if ( w == m_FilterPanelAccTime || m_FilterPanelPing )
1171 void ButtonRefreshToCancel()
1174 btn.SetText(
"#menu_cancel" );
1177 void ButtonCancelToRefresh()
1180 btn.SetText(
"#STR_server_browser_tab_root_filters_root_filters_content_refresh_list_button0" );