* Part of RebuildList() to create the information for a single company. * @param company_id The company to build the list for. * @param client_playas The company the client is joined as. * @param can_join_company Whether this company can be joined by us. */
| 1653 | * @param can_join_company Whether this company can be joined by us. |
| 1654 | */ |
| 1655 | void RebuildListCompany(CompanyID company_id, CompanyID client_playas, bool can_join_company) |
| 1656 | { |
| 1657 | ButtonLine &company_line = *this->buttons.emplace_back(std::make_unique<CompanyButtonLine>(company_id)); |
| 1658 | if (_network_server) company_line.AddButton<CompanyButton>(SPR_ADMIN, STR_NETWORK_CLIENT_LIST_ADMIN_COMPANY_TOOLTIP, COLOUR_RED, company_id, &NetworkClientListWindow::OnClickCompanyAdmin, company_id == COMPANY_SPECTATOR); |
| 1659 | ButtonCommon &chat_button = company_line.AddButton<CompanyButton>(SPR_CHAT, company_id == COMPANY_SPECTATOR ? STR_NETWORK_CLIENT_LIST_CHAT_SPECTATOR_TOOLTIP : STR_NETWORK_CLIENT_LIST_CHAT_COMPANY_TOOLTIP, COLOUR_ORANGE, company_id, &NetworkClientListWindow::OnClickCompanyChat); |
| 1660 | if (can_join_company) company_line.AddButton<CompanyButton>(SPR_JOIN, STR_NETWORK_CLIENT_LIST_JOIN_TOOLTIP, COLOUR_ORANGE, company_id, &NetworkClientListWindow::OnClickCompanyJoin, company_id != COMPANY_SPECTATOR && Company::Get(company_id)->is_ai); |
| 1661 | |
| 1662 | bool has_players = false; |
| 1663 | for (const NetworkClientInfo *ci : NetworkClientInfo::Iterate()) { |
| 1664 | if (ci->client_playas != company_id) continue; |
| 1665 | has_players = true; |
| 1666 | |
| 1667 | ButtonLine &line = *this->buttons.emplace_back(std::make_unique<ClientButtonLine>(ci->index)); |
| 1668 | if (_network_server) line.AddButton<ClientButton>(SPR_ADMIN, STR_NETWORK_CLIENT_LIST_ADMIN_CLIENT_TOOLTIP, COLOUR_RED, ci->client_id, &NetworkClientListWindow::OnClickClientAdmin, _network_own_client_id == ci->client_id); |
| 1669 | if (_network_own_client_id != ci->client_id) line.AddButton<ClientButton>(SPR_CHAT, STR_NETWORK_CLIENT_LIST_CHAT_CLIENT_TOOLTIP, COLOUR_ORANGE, ci->client_id, &NetworkClientListWindow::OnClickClientChat); |
| 1670 | if (_network_own_client_id != ci->client_id && client_playas != COMPANY_SPECTATOR && !ci->CanJoinCompany(client_playas)) line.AddButton<ClientButton>(SPR_JOIN, STR_NETWORK_CLIENT_LIST_COMPANY_AUTHORIZE_TOOLTIP, COLOUR_GREEN, ci->client_id, &NetworkClientListWindow::OnClickClientAuthorize); |
| 1671 | } |
| 1672 | |
| 1673 | /* Disable the chat button when there are players in this company. */ |
| 1674 | chat_button.disabled = !has_players; |
| 1675 | } |
| 1676 | |
| 1677 | /** |
| 1678 | * Rebuild the list, meaning: calculate the lines needed and what buttons go on which line. |
no test coverage detected