Codechange: Replace network related FOR_ALL with range-based for loops

This commit is contained in:
glx
2019-12-16 20:56:10 +01:00
committed by Niels Martin Hansen
parent 09fa39c5b5
commit 41232f18c1
12 changed files with 89 additions and 191 deletions

View File

@@ -1883,10 +1883,9 @@ struct NetworkClientListWindow : Window {
bool CheckClientListHeight()
{
int num = 0;
const NetworkClientInfo *ci;
/* Should be replaced with a loop through all clients */
FOR_ALL_CLIENT_INFOS(ci) {
for (const NetworkClientInfo *ci : NetworkClientInfo::Iterate()) {
if (ci->client_playas != COMPANY_INACTIVE_CLIENT) num++;
}
@@ -1910,8 +1909,7 @@ struct NetworkClientListWindow : Window {
this->line_height = max(this->icon_size.height + 2U, (uint)FONT_HEIGHT_NORMAL);
uint width = 100; // Default width
const NetworkClientInfo *ci;
FOR_ALL_CLIENT_INFOS(ci) {
for (const NetworkClientInfo *ci : NetworkClientInfo::Iterate()) {
width = max(width, GetStringBoundingBox(ci->client_name).width);
}
@@ -1947,8 +1945,7 @@ struct NetworkClientListWindow : Window {
uint name_right = rtl ? right - type_icon_width : right;
int i = 0;
const NetworkClientInfo *ci;
FOR_ALL_CLIENT_INFOS(ci) {
for (const NetworkClientInfo *ci : NetworkClientInfo::Iterate()) {
TextColour colour;
if (this->selected_item == i++) { // Selected item, highlight it
GfxFillRect(r.left + 1, y, r.right - 1, y + this->line_height - 1, PC_BLACK);
@@ -1976,15 +1973,14 @@ struct NetworkClientListWindow : Window {
{
/* Show the popup with option */
if (this->selected_item != -1) {
NetworkClientInfo *ci;
int client_no = this->selected_item;
FOR_ALL_CLIENT_INFOS(ci) {
if (client_no == 0) break;
for (NetworkClientInfo *ci : NetworkClientInfo::Iterate()) {
if (client_no == 0) {
PopupClientList(ci->client_id, pt.x + this->left, pt.y + this->top);
break;
}
client_no--;
}
if (ci != nullptr) PopupClientList(ci->client_id, pt.x + this->left, pt.y + this->top);
}
}