* (Re)build the GUI network game list (a.k.a. this->servers) as some * major change has occurred. It ensures appropriate filtering and * sorting, if both or either one is enabled. */
| 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()) { |
| 234 | this->servers.SetFilterState(true); |
| 235 | this->servers.Filter(sf); |
| 236 | } else { |
| 237 | this->servers.SetFilterState(false); |
| 238 | } |
| 239 | |
| 240 | this->servers.RebuildDone(); |
| 241 | this->vscroll->SetCount(this->servers.size()); |
| 242 | |
| 243 | /* Sort the list of network games as requested. */ |
| 244 | this->servers.Sort(); |
| 245 | this->UpdateListPos(); |
| 246 | } |
| 247 | |
| 248 | /** Sort servers by name. */ |
| 249 | static bool NGameNameSorter(NetworkGame * const &a, NetworkGame * const &b) |
no test coverage detected