| 174 | }; |
| 175 | |
| 176 | class NetworkGameWindow : public Window { |
| 177 | protected: |
| 178 | /* Runtime saved values */ |
| 179 | static Listing last_sorting; |
| 180 | |
| 181 | /* Constants for sorting servers */ |
| 182 | static const std::initializer_list<GUIGameServerList::SortFunction * const> sorter_funcs; |
| 183 | static const std::initializer_list<GUIGameServerList::FilterFunction * const> filter_funcs; |
| 184 | |
| 185 | NetworkGame *server = nullptr; ///< Selected server. |
| 186 | NetworkGame *last_joined = nullptr; ///< The last joined server. |
| 187 | GUIGameServerList servers{}; ///< List with game servers. |
| 188 | ServerListPosition list_pos = SLP_INVALID; ///< Position of the selected server. |
| 189 | Scrollbar *vscroll = nullptr; ///< Vertical scrollbar of the list of servers. |
| 190 | QueryString name_editbox; ///< Client name editbox. |
| 191 | QueryString filter_editbox; ///< Editbox for filter on servers. |
| 192 | bool searched_internet = false; ///< Did we ever press "Search Internet" button? |
| 193 | |
| 194 | Dimension lock{}; /// Dimension of lock icon. |
| 195 | Dimension blot{}; /// Dimension of compatibility icon. |
| 196 | |
| 197 | /** |
| 198 | * (Re)build the GUI network game list (a.k.a. this->servers) as some |
| 199 | * major change has occurred. It ensures appropriate filtering and |
| 200 | * sorting, if both or either one is enabled. |
| 201 | */ |
| 202 | void BuildGUINetworkGameList() |
| 203 | { |
| 204 | if (!this->servers.NeedRebuild()) return; |
| 205 | |
| 206 | /* Create temporary array of games to use for listing */ |
| 207 | this->servers.clear(); |
| 208 | |
| 209 | bool found_current_server = false; |
| 210 | bool found_last_joined = false; |
| 211 | for (const auto &ngl : _network_game_list) { |
| 212 | this->servers.push_back(ngl.get()); |
| 213 | if (ngl.get() == this->server) { |
| 214 | found_current_server = true; |
| 215 | } |
| 216 | if (ngl.get() == this->last_joined) { |
| 217 | found_last_joined = true; |
| 218 | } |
| 219 | } |
| 220 | /* A refresh can cause the current server to be delete; so unselect. */ |
| 221 | if (!found_last_joined) { |
| 222 | this->last_joined = nullptr; |
| 223 | } |
| 224 | if (!found_current_server) { |
| 225 | this->server = nullptr; |
| 226 | this->list_pos = SLP_INVALID; |
| 227 | } |
| 228 | |
| 229 | /* Apply the filter condition immediately, if a search string has been provided. */ |
| 230 | StringFilter sf; |
| 231 | sf.SetFilterTerm(this->filter_editbox.text.GetText()); |
| 232 | |
| 233 | if (!sf.IsEmpty()) { |
nothing calls this directly
no test coverage detected