From b7b5a26a57ff9121a519d8c71e4affee1163a0e3 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Fri, 15 May 2020 07:06:41 -0300 Subject: [PATCH] Rename ServerList member variables to prevent shadowing --- src/openrct2-ui/windows/ServerList.cpp | 40 ++++++------- src/openrct2/network/ServerList.cpp | 78 ++++++++++++-------------- src/openrct2/network/ServerList.h | 18 +++--- 3 files changed, 65 insertions(+), 71 deletions(-) diff --git a/src/openrct2-ui/windows/ServerList.cpp b/src/openrct2-ui/windows/ServerList.cpp index 0539e0447f..446b3490bb 100644 --- a/src/openrct2-ui/windows/ServerList.cpp +++ b/src/openrct2-ui/windows/ServerList.cpp @@ -192,12 +192,12 @@ static void window_server_list_mouseup(rct_window* w, rct_widgetindex widgetInde const auto& server = _serverList.GetServer(serverIndex); if (server.IsVersionValid()) { - join_server(server.address); + join_server(server.Address); } else { auto ft = Formatter::Common(); - ft.Add(server.version.c_str()); + ft.Add(server.Version.c_str()); context_show_error(STR_UNABLE_TO_CONNECT_TO_SERVER, STR_MULTIPLAYER_INCORRECT_SOFTWARE_VERSION); } } @@ -231,18 +231,18 @@ static void window_server_list_dropdown(rct_window* w, rct_widgetindex widgetInd case DDIDX_JOIN: if (server.IsVersionValid()) { - join_server(server.address); + join_server(server.Address); } else { auto ft = Formatter::Common(); - ft.Add(server.version.c_str()); + ft.Add(server.Version.c_str()); context_show_error(STR_UNABLE_TO_CONNECT_TO_SERVER, STR_MULTIPLAYER_INCORRECT_SOFTWARE_VERSION); } break; case DDIDX_FAVOURITE: { - server.favourite = !server.favourite; + server.Favourite = !server.Favourite; _serverList.WriteFavourites(); } break; @@ -276,7 +276,7 @@ static void window_server_list_scroll_mousedown(rct_window* w, int32_t scrollInd auto listWidget = &w->widgets[WIDX_LIST]; gDropdownItemsFormat[0] = STR_JOIN_GAME; - if (server.favourite) + if (server.Favourite) { gDropdownItemsFormat[1] = STR_REMOVE_FROM_FAVOURITES; } @@ -363,9 +363,9 @@ static void window_server_list_textinput(rct_window* w, rct_widgetindex widgetIn case WIDX_ADD_SERVER: { ServerListEntry entry; - entry.address = text; - entry.name = text; - entry.favourite = true; + entry.Address = text; + entry.Name = text; + entry.Favourite = true; _serverList.Add(entry); _serverList.WriteFavourites(); w->Invalidate(); @@ -447,16 +447,16 @@ static void window_server_list_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi if (highlighted) { gfx_filter_rect(dpi, 0, screenCoords.y, width, screenCoords.y + ITEM_HEIGHT, PALETTE_DARKEN_1); - _version = serverDetails.version; + _version = serverDetails.Version; w->widgets[WIDX_LIST].tooltip = STR_NETWORK_VERSION_TIP; } int32_t colour = w->colours[1]; - if (serverDetails.favourite) + if (serverDetails.Favourite) { colour = COLOUR_YELLOW; } - else if (serverDetails.local) + else if (serverDetails.Local) { colour = COLOUR_MOSS_GREEN; } @@ -464,13 +464,13 @@ static void window_server_list_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi screenCoords.x = 3; // Draw server information - if (highlighted && !serverDetails.description.empty()) + if (highlighted && !serverDetails.Description.empty()) { - gfx_draw_string(dpi, serverDetails.description.c_str(), colour, screenCoords + ScreenCoordsXY{ 0, 3 }); + gfx_draw_string(dpi, serverDetails.Description.c_str(), colour, screenCoords + ScreenCoordsXY{ 0, 3 }); } else { - gfx_draw_string(dpi, serverDetails.name.c_str(), colour, screenCoords + ScreenCoordsXY{ 0, 3 }); + gfx_draw_string(dpi, serverDetails.Name.c_str(), colour, screenCoords + ScreenCoordsXY{ 0, 3 }); } int32_t right = width - 3 - 14; @@ -478,7 +478,7 @@ static void window_server_list_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi // Draw compatibility icon right -= 10; int32_t compatibilitySpriteId; - if (serverDetails.version.empty()) + if (serverDetails.Version.empty()) { // Server not online... compatibilitySpriteId = SPR_G2_RCT1_CLOSE_BUTTON_0; @@ -486,7 +486,7 @@ static void window_server_list_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi else { // Server online... check version - bool correctVersion = serverDetails.version == network_get_version(); + bool correctVersion = serverDetails.Version == network_get_version(); compatibilitySpriteId = correctVersion ? SPR_G2_RCT1_OPEN_BUTTON_2 : SPR_G2_RCT1_CLOSE_BUTTON_2; } gfx_draw_sprite(dpi, compatibilitySpriteId, right, screenCoords.y + 1, 0); @@ -494,7 +494,7 @@ static void window_server_list_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi // Draw lock icon right -= 8; - if (serverDetails.requiresPassword) + if (serverDetails.RequiresPassword) { gfx_draw_sprite(dpi, SPR_G2_LOCKED, right, screenCoords.y + 4, 0); } @@ -503,9 +503,9 @@ static void window_server_list_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi // Draw number of players char players[32]; players[0] = 0; - if (serverDetails.maxplayers > 0) + if (serverDetails.MaxPlayers > 0) { - snprintf(players, 32, "%d/%d", serverDetails.players, serverDetails.maxplayers); + snprintf(players, 32, "%d/%d", serverDetails.Players, serverDetails.MaxPlayers); } int32_t numPlayersStringWidth = gfx_get_string_width(players); screenCoords.x = right - numPlayersStringWidth; diff --git a/src/openrct2/network/ServerList.cpp b/src/openrct2/network/ServerList.cpp index 156d897943..bc7c400554 100644 --- a/src/openrct2/network/ServerList.cpp +++ b/src/openrct2/network/ServerList.cpp @@ -35,45 +35,39 @@ int32_t ServerListEntry::CompareTo(const ServerListEntry& other) const const auto& a = *this; const auto& b = other; - // Order by favourite - if (a.favourite != b.favourite) + if (a.Favourite != b.Favourite) { - return a.favourite ? -1 : 1; + return a.Favourite ? -1 : 1; } - // Order by local - if (a.local != b.local) + if (a.Local != b.Local) { - return a.local ? -1 : 1; + return a.Local ? -1 : 1; } - // Then by version - bool serverACompatible = a.version == network_get_version(); - bool serverBCompatible = b.version == network_get_version(); + bool serverACompatible = a.Version == network_get_version(); + bool serverBCompatible = b.Version == network_get_version(); if (serverACompatible != serverBCompatible) { return serverACompatible ? -1 : 1; } - // Then by password protection - if (a.requiresPassword != b.requiresPassword) + if (a.RequiresPassword != b.RequiresPassword) { - return a.requiresPassword ? 1 : -1; + return a.RequiresPassword ? 1 : -1; } - // Then by number of players - if (a.players != b.players) + if (a.Players != b.Players) { - return a.players > b.players ? -1 : 1; + return a.Players > b.Players ? -1 : 1; } - // Then by name - return String::Compare(a.name, b.name, true); + return String::Compare(a.Name, b.Name, true); } bool ServerListEntry::IsVersionValid() const { - return version.empty() || version == network_get_version(); + return Version.empty() || Version == network_get_version(); } std::optional ServerListEntry::FromJson(const json_t* server) @@ -97,14 +91,14 @@ std::optional ServerListEntry::FromJson(const json_t* server) else { ServerListEntry entry; - entry.address = String::StdFormat( + entry.Address = String::StdFormat( "%s:%d", json_string_value(addressIp), static_cast(json_integer_value(port))); - entry.name = (name == nullptr ? "" : json_string_value(name)); - entry.description = (description == nullptr ? "" : json_string_value(description)); - entry.version = json_string_value(version); - entry.requiresPassword = json_is_true(requiresPassword); - entry.players = static_cast(json_integer_value(players)); - entry.maxplayers = static_cast(json_integer_value(maxPlayers)); + entry.Name = (name == nullptr ? "" : json_string_value(name)); + entry.Description = (description == nullptr ? "" : json_string_value(description)); + entry.Version = json_string_value(version); + entry.RequiresPassword = json_is_true(requiresPassword); + entry.Players = static_cast(json_integer_value(players)); + entry.MaxPlayers = static_cast(json_integer_value(maxPlayers)); return entry; } } @@ -115,9 +109,9 @@ void ServerList::Sort() std::unique( _serverEntries.begin(), _serverEntries.end(), [](const ServerListEntry& a, const ServerListEntry& b) { - if (a.favourite == b.favourite) + if (a.Favourite == b.Favourite) { - return String::Equals(a.address, b.address, true); + return String::Equals(a.Address, b.Address, true); } return false; }), @@ -169,14 +163,14 @@ std::vector ServerList::ReadFavourites() const for (size_t i = 0; i < numEntries; i++) { ServerListEntry serverInfo; - serverInfo.address = fs.ReadStdString(); - serverInfo.name = fs.ReadStdString(); - serverInfo.requiresPassword = false; - serverInfo.description = fs.ReadStdString(); - serverInfo.version = ""; - serverInfo.favourite = true; - serverInfo.players = 0; - serverInfo.maxplayers = 0; + serverInfo.Address = fs.ReadStdString(); + serverInfo.Name = fs.ReadStdString(); + serverInfo.RequiresPassword = false; + serverInfo.Description = fs.ReadStdString(); + serverInfo.Version = ""; + serverInfo.Favourite = true; + serverInfo.Players = 0; + serverInfo.MaxPlayers = 0; entries.push_back(std::move(serverInfo)); } } @@ -193,7 +187,7 @@ void ServerList::ReadAndAddFavourites() { _serverEntries.erase( std::remove_if( - _serverEntries.begin(), _serverEntries.end(), [](const ServerListEntry& entry) { return entry.favourite; }), + _serverEntries.begin(), _serverEntries.end(), [](const ServerListEntry& entry) { return entry.Favourite; }), _serverEntries.end()); auto entries = ReadFavourites(); AddRange(entries); @@ -205,7 +199,7 @@ void ServerList::WriteFavourites() const std::vector favouriteServers; std::copy_if( _serverEntries.begin(), _serverEntries.end(), std::back_inserter(favouriteServers), - [](const ServerListEntry& entry) { return entry.favourite; }); + [](const ServerListEntry& entry) { return entry.Favourite; }); WriteFavourites(favouriteServers); } @@ -223,9 +217,9 @@ bool ServerList::WriteFavourites(const std::vector& entries) co fs.WriteValue(static_cast(entries.size())); for (const auto& entry : entries) { - fs.WriteString(entry.address); - fs.WriteString(entry.name); - fs.WriteString(entry.description); + fs.WriteString(entry.Address); + fs.WriteString(entry.Name); + fs.WriteString(entry.Description); } return true; } @@ -278,7 +272,7 @@ std::future> ServerList::FetchLocalServerListAsync( auto entry = ServerListEntry::FromJson(jinfo); if (entry.has_value()) { - (*entry).local = true; + (*entry).Local = true; entries.push_back(*entry); } @@ -404,7 +398,7 @@ std::future> ServerList::FetchOnlineServerListAsync uint32_t ServerList::GetTotalPlayerCount() const { return std::accumulate(_serverEntries.begin(), _serverEntries.end(), 0, [](uint32_t acc, const ServerListEntry& entry) { - return acc + entry.players; + return acc + entry.Players; }); } diff --git a/src/openrct2/network/ServerList.h b/src/openrct2/network/ServerList.h index 75bff4eddd..1e1a4218ff 100644 --- a/src/openrct2/network/ServerList.h +++ b/src/openrct2/network/ServerList.h @@ -22,15 +22,15 @@ struct INetworkEndpoint; struct ServerListEntry { - std::string address; - std::string name; - std::string description; - std::string version; - bool requiresPassword{}; - bool favourite{}; - uint8_t players{}; - uint8_t maxplayers{}; - bool local{}; + std::string Address; + std::string Name; + std::string Description; + std::string Version; + bool RequiresPassword{}; + bool Favourite{}; + uint8_t Players{}; + uint8_t MaxPlayers{}; + bool Local{}; int32_t CompareTo(const ServerListEntry& other) const; bool IsVersionValid() const;