serverbrowserfavoritestabconsolepages.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. class ServerBrowserFavoritesTabConsolePages extends ServerBrowserTabConsolePages
  2. {
  3. protected override void Construct(Widget parent, ServerBrowserMenuNew menu, TabType type)
  4. {
  5. super.Construct(parent, menu, type);
  6. // disabling filter section
  7. m_ResetFilters.Show(false);
  8. m_Root.FindAnyWidget("filters_content").Show(false);
  9. m_Root.FindAnyWidget("show_details_button").Show(false);
  10. m_Root.FindAnyWidget("spacer").Show(false);
  11. m_Root.FindAnyWidget("spacer1").Show(false);
  12. m_Root.FindAnyWidget("spacer5").Show(false);
  13. m_Root.FindAnyWidget("server_list_root_nav_wrapper").Show(false);
  14. m_RefreshList.Show(m_MouseKeyboardControlled);
  15. SwitchToDetails(false);
  16. m_Menu.ShowYButton(false);
  17. }
  18. override void OnLoadServersAsyncFinished()
  19. {
  20. // m_TotalLoadedServers for FAVORITES tab is determined by total number of favorited servers
  21. TStringArray favIds = m_Menu.GetFavoritedServerIds();
  22. m_TotalLoadedServers = favIds.Count();
  23. super.OnLoadServersAsyncFinished();
  24. SetFocusServers();
  25. }
  26. protected override void LoadEntries(int cur_page_index , GetServersResultRowArray page_entries)
  27. {
  28. if (cur_page_index == 1)
  29. {
  30. m_OnlineFavServers.Clear();
  31. }
  32. super.LoadEntries(cur_page_index, page_entries);
  33. }
  34. protected override void LoadExtraEntries(int index)
  35. {
  36. if ( !m_Menu || m_Menu.GetServersLoadingTab() != m_TabType )
  37. {
  38. return;
  39. }
  40. // m_PagesCount for FAVORITES tab is determined by total number of favorited servers
  41. TStringArray favIds = m_Menu.GetFavoritedServerIds();
  42. m_PagesCount = Math.Ceil((float)favIds.Count() / SERVER_BROWSER_PAGE_SIZE);
  43. // offlineFavIds will always have same order, even across pages,
  44. // to ensure we display only fav servers that HAVEN'T been displayed yet
  45. TStringArray offlineFavIds = new TStringArray();
  46. offlineFavIds.Reserve(favIds.Count() - m_OnlineFavServers.Count());
  47. foreach (string ipPort : favIds)
  48. {
  49. if (m_OnlineFavServers.Find(ipPort) == -1)
  50. {
  51. offlineFavIds.Insert(ipPort);
  52. }
  53. }
  54. // appending offline servers to server list
  55. int totalServersAlreadyShown = (GetCurrentPage() - 1) * SERVER_BROWSER_PAGE_SIZE + index;
  56. int startingIndex = totalServersAlreadyShown - m_OnlineFavServers.Count();
  57. for (int i = startingIndex; i < offlineFavIds.Count(); ++i)
  58. {
  59. string favServerId = offlineFavIds[i];
  60. // only append server if there is a free entry left on the page
  61. if (index >= SERVER_BROWSER_PAGE_SIZE)
  62. {
  63. break;
  64. }
  65. if (m_OnlineFavServers.Find(favServerId) > -1)
  66. {
  67. continue;
  68. }
  69. array<string> parts = new array<string>;
  70. favServerId.Split(":", parts);
  71. // ensure server id has correct format
  72. if (parts.Count() != 2)
  73. {
  74. continue;
  75. }
  76. GetServersResultRow offlineRow = new GetServersResultRow();
  77. offlineRow.m_Name = favServerId;
  78. offlineRow.m_Id = favServerId;
  79. offlineRow.m_HostIp = parts[0];
  80. offlineRow.m_HostPort = parts[1].ToInt();
  81. offlineRow.m_SteamQueryPort = offlineRow.m_HostPort;
  82. offlineRow.m_Favorite = true;
  83. ServerBrowserEntry entry = GetServerEntryByIndex( index );
  84. entry.SetIsOnline(false);
  85. entry.FillInfo(offlineRow);
  86. entry.UpdateEntry();
  87. m_EntryWidgets.Insert(favServerId, entry);
  88. m_EntriesSorted[m_SortType].Insert(offlineRow);
  89. index++;
  90. }
  91. }
  92. override void RefreshList()
  93. {
  94. super.RefreshList();
  95. #ifdef PLATFORM_WINDOWS
  96. m_CurrentFilterInput.SetFavorited( true );
  97. #endif
  98. AddFavoritesToFilter(m_CurrentFilterInput);
  99. OnlineServices.LoadServers(m_CurrentFilterInput);
  100. }
  101. override bool PassFilter(GetServersResultRow result)
  102. {
  103. if (m_TabType == TabType.FAVORITE)
  104. {
  105. if (!m_Menu.IsFavorited(result.GetIpPort()))
  106. {
  107. return false;
  108. }
  109. }
  110. return super.PassFilter(result);
  111. }
  112. override void PressThumbRight()
  113. {
  114. switch (m_SelectedPanel)
  115. {
  116. // filters are disabled for console FAVORITES tab, so do nothing
  117. case SelectedPanel.FILTERS:
  118. {
  119. break;
  120. }
  121. default:
  122. {
  123. super.PressThumbRight();
  124. break;
  125. }
  126. }
  127. }
  128. override void PressX()
  129. {
  130. if ( (GetGame().GetTime() - m_TimeLastServerRefresh) > 1000 )
  131. {
  132. SetCurrentPage(1);
  133. super.PressX();
  134. }
  135. }
  136. override void SetFocusFilters()
  137. {
  138. super.SetFocusFilters();
  139. UpdatePageButtons();
  140. }
  141. }