DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
ServerBrowserFavoritesTabConsolePages.c
Go to the documentation of this file.
1class 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
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.FillInfo(offlineRow);
90 entry.SetIsOnline(false);
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
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 {
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}
float GetTime()
const int SERVER_BROWSER_PAGE_SIZE
protected ServerBrowserMenuNew m_Menu
protected ref map< ESortType, ref array< ref GetServersResultRow > > m_EntriesSorted
protected ref map< string, ref ServerBrowserEntry > m_EntryWidgets
protected TabType m_TabType
TabType
protected ref GetServersInput m_CurrentFilterInput
void AddFavoritesToFilter(ref GetServersInput input)
protected ESortType m_SortType
protected int m_TotalLoadedServers
protected SelectedPanel m_SelectedPanel
int GetCurrentPage()
void SetCurrentPage(int page_num)
protected ref set< string > m_OnlineFavServers
protected Widget m_Root
Definition SizeToChild.c:91
void SetFavorited(bool show)
Definition EnMath.c:7
static void LoadServers(notnull GetServersInput inputValues)
protected override void Construct(Widget parent, ServerBrowserMenuNew menu, TabType type)
protected override void LoadEntries(int cur_page_index, GetServersResultRowArray page_entries)
override bool PassFilter(GetServersResultRow result)
protected override void LoadExtraEntries(int index)
proto native CGame GetGame()
array< string > TStringArray
Definition EnScript.c:685
static proto float Ceil(float f)
Returns ceil of value.
void Split(string sample, out array< string > output)
Splits string into array of strings separated by 'sample'.
Definition EnString.c:396