* Rebuild the list, meaning: calculate the lines needed and what buttons go on which line. */
| 1678 | * Rebuild the list, meaning: calculate the lines needed and what buttons go on which line. |
| 1679 | */ |
| 1680 | void RebuildList() |
| 1681 | { |
| 1682 | const NetworkClientInfo *own_ci = NetworkClientInfo::GetByClientID(_network_own_client_id); |
| 1683 | CompanyID client_playas = own_ci == nullptr ? COMPANY_SPECTATOR : own_ci->client_playas; |
| 1684 | |
| 1685 | this->buttons.clear(); |
| 1686 | |
| 1687 | /* As spectator, show a line to create a new company. */ |
| 1688 | if (client_playas == COMPANY_SPECTATOR && !NetworkMaxCompaniesReached()) { |
| 1689 | ButtonLine &line = *this->buttons.emplace_back(std::make_unique<CompanyButtonLine>(COMPANY_NEW_COMPANY)); |
| 1690 | line.AddButton<CompanyButton>(SPR_JOIN, STR_NETWORK_CLIENT_LIST_NEW_COMPANY_TOOLTIP, COLOUR_ORANGE, COMPANY_SPECTATOR, &NetworkClientListWindow::OnClickCompanyNew); |
| 1691 | } |
| 1692 | |
| 1693 | if (client_playas != COMPANY_SPECTATOR) { |
| 1694 | this->RebuildListCompany(client_playas, client_playas, false); |
| 1695 | } |
| 1696 | |
| 1697 | /* Companies */ |
| 1698 | for (const Company *c : Company::Iterate()) { |
| 1699 | if (c->index == client_playas) continue; |
| 1700 | |
| 1701 | this->RebuildListCompany(c->index, client_playas, (own_ci != nullptr && c->allow_list.Contains(own_ci->public_key)) || _network_server); |
| 1702 | } |
| 1703 | |
| 1704 | /* Spectators */ |
| 1705 | this->RebuildListCompany(COMPANY_SPECTATOR, client_playas, client_playas != COMPANY_SPECTATOR); |
| 1706 | |
| 1707 | this->vscroll->SetCount(this->buttons.size()); |
| 1708 | } |
| 1709 | |
| 1710 | public: |
| 1711 | NetworkClientListWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc) |
no test coverage detected