Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
serverbrowserfavoritestabconsolepages.c
Go to the documentation of this file.
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 
7  // disabling filter section
8  m_Root.FindAnyWidget("filters_content").Show(false);
9  m_Root.FindAnyWidget("reset_filter_button").Show(false);
10  }
11 
12  override void OnLoadServersAsyncFinished()
13  {
14  // m_TotalLoadedServers for FAVORITES tab is determined by total number of favorited servers
15  TStringArray favIds = m_Menu.GetFavoritedServerIds();
16  m_TotalLoadedServers = favIds.Count();
17  super.OnLoadServersAsyncFinished();
18  }
19 
20  protected override void LoadEntries( int cur_page_index , GetServersResultRowArray page_entries )
21  {
22  if (cur_page_index == 1)
23  {
24  m_OnlineFavServers.Clear();
25  }
26 
27  super.LoadEntries(cur_page_index, page_entries);
28  }
29 
30  protected override void LoadExtraEntries(int index)
31  {
32  if ( !m_Menu || m_Menu.GetServersLoadingTab() != m_TabType )
33  {
34  return;
35  }
36 
37  // m_PagesCount for FAVORITES tab is determined by total number of favorited servers
38  TStringArray favIds = m_Menu.GetFavoritedServerIds();
39  m_PagesCount = Math.Ceil((float)favIds.Count() / SERVER_BROWSER_PAGE_SIZE);
40 
41  // offlineFavIds will always have same order, even across pages,
42  // to ensure we display only fav servers that HAVEN'T been displayed yet
43  TStringArray offlineFavIds = new TStringArray();
44  offlineFavIds.Reserve(favIds.Count() - m_OnlineFavServers.Count());
45  foreach (string ipPort : favIds)
46  {
47  if (m_OnlineFavServers.Find(ipPort) == -1)
48  {
49  offlineFavIds.Insert(ipPort);
50  }
51  }
52 
53  // appending offline servers to server list
54  int totalServersAlreadyShown = (GetCurrentPage() - 1) * SERVER_BROWSER_PAGE_SIZE + index;
55  int startingIndex = totalServersAlreadyShown - m_OnlineFavServers.Count();
56  for (int i = startingIndex; i < offlineFavIds.Count(); ++i)
57  {
58  string favServerId = offlineFavIds[i];
59 
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 
66  if (m_OnlineFavServers.Find(favServerId) > -1)
67  {
68  continue;
69  }
70 
71  array<string> parts = new array<string>;
72  favServerId.Split(":", parts);
73 
74  // ensure server id has correct format
75  if (parts.Count() != 2)
76  {
77  continue;
78  }
79 
80  GetServersResultRow offlineRow = new GetServersResultRow();
81  offlineRow.m_Name = favServerId;
82  offlineRow.m_Id = favServerId;
83  offlineRow.m_HostIp = parts[0];
84  offlineRow.m_HostPort = parts[1].ToInt();
85  offlineRow.m_SteamQueryPort = offlineRow.m_HostPort;
86  offlineRow.m_Favorite = true;
87 
88  ServerBrowserEntry entry = GetServerEntryByIndex( index );
89  entry.SetIsOnline(false);
90  entry.FillInfo(offlineRow);
91  entry.UpdateEntry();
92 
93  m_EntryWidgets.Insert(favServerId, entry);
94  m_EntriesSorted[m_SortType].Insert(offlineRow);
95 
96  index++;
97  }
98  }
99 
100  override void RefreshList()
101  {
102  super.RefreshList();
103 #ifdef PLATFORM_WINDOWS
104  m_CurrentFilterInput.SetFavorited( true );
105 #endif
108  }
109 
110  override bool PassFilter(GetServersResultRow result)
111  {
112  if (m_TabType == TabType.FAVORITE)
113  {
114  if (!m_Menu.IsFavorited(result.GetIpPort()))
115  {
116  return false;
117  }
118  }
119 
120  return super.PassFilter(result);
121  }
122 
123  override void PressY()
124  {
125  switch ( m_SelectedPanel )
126  {
127  // filters are disabled for console FAVORITES tab, so do nothing
128  case SelectedPanel.FILTERS:
129  {
130  break;
131  }
132  default:
133  {
134  super.PressY();
135  break;
136  }
137  }
138  }
139 
140  override void PressX()
141  {
142  if ( (GetGame().GetTime() - m_TimeLastServerRefresh) > 1000 )
143  {
144  SetCurrentPage(1);
145  super.PressX();
146  }
147  }
148 
149  override void SetFocusFilters()
150  {
151  super.SetFocusFilters();
152 
153  m_Menu.ShowYButton(false);
154  m_Menu.ShowAButton(false);
155 
156  // focus on the back button instead of filter section
157  m_Menu.BackButtonFocus();
158 
159  UpdatePageButtons();
160  }
161 }
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
GetCurrentPage
int GetCurrentPage()
Definition: serverbrowsertab.c:382
TStringArray
array< string > TStringArray
Definition: enscript.c:685
RefreshList
void RefreshList()
Definition: serverbrowsertab.c:407
m_EntryWidgets
protected ref map< string, ref ServerBrowserEntry > m_EntryWidgets
Definition: serverbrowsertab.c:25
m_TabType
protected TabType m_TabType
Definition: serverbrowsertab.c:33
PressY
void PressY()
AddFavoritesToFilter
void AddFavoritesToFilter(ref GetServersInput input)
Definition: serverbrowsertab.c:402
m_Menu
protected ServerBrowserMenuNew m_Menu
Definition: serverbrowsertab.c:30
SetCurrentPage
void SetCurrentPage(int page_num)
Definition: serverbrowsertab.c:377
ServerBrowserTabConsolePages
Definition: serverbrowserfavoritestabconsolepages.c:1
m_OnlineFavServers
protected ref set< string > m_OnlineFavServers
Definition: serverbrowsertab.c:69
SERVER_BROWSER_PAGE_SIZE
const int SERVER_BROWSER_PAGE_SIZE
Definition: serverbrowsermenunew.c:6
m_EntriesSorted
protected ref map< ESortType, ref array< ref GetServersResultRow > > m_EntriesSorted
Definition: serverbrowsertab.c:67
Construct
protected void Construct(Widget parent, ServerBrowserMenuNew menu, TabType type)
Definition: serverbrowsertab.c:78
LoadExtraEntries
protected void LoadExtraEntries(int index)
Definition: serverbrowsertab.c:542
array< string >
PressX
void PressX()
Definition: serverbrowsertab.c:303
PassFilter
bool PassFilter(GetServersResultRow result)
Definition: serverbrowsertab.c:508
m_CurrentFilterInput
protected ref GetServersInput m_CurrentFilterInput
Definition: serverbrowsertab.c:50
GetTime
float GetTime()
Definition: notificationsystem.c:35
m_SelectedPanel
protected SelectedPanel m_SelectedPanel
Definition: serverbrowsertab.c:37
Widget
Definition: enwidgets.c:189
Math
Definition: enmath.c:6
m_Root
protected Widget m_Root
Definition: sizetochild.c:91
OnlineServices
Definition: onlineservices.c:1