mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2026-07-24 03:56:43 +00:00
Codechange: make NetworkGameStatus a scoped enum
This commit is contained in:
committed by
Peter Nelson
parent
62d71bd43f
commit
fe989c3dc4
@@ -668,7 +668,7 @@ public:
|
||||
Debug(net, 9, "Query::OnFailure(): connection_string={}", this->connection_string);
|
||||
|
||||
NetworkGame *item = NetworkGameListAddItem(connection_string);
|
||||
item->status = NGLS_OFFLINE;
|
||||
item->status = NetworkGameStatus::Offline;
|
||||
item->refreshing = false;
|
||||
|
||||
UpdateNetworkGameWindow();
|
||||
|
||||
@@ -153,7 +153,7 @@ bool ClientNetworkCoordinatorSocketHandler::ReceiveGameCoordinatorError(Packet &
|
||||
|
||||
/* Mark the server as offline. */
|
||||
NetworkGame *item = NetworkGameListAddItem(detail);
|
||||
item->status = NGLS_OFFLINE;
|
||||
item->status = NetworkGameStatus::Offline;
|
||||
|
||||
UpdateNetworkGameWindow();
|
||||
return true;
|
||||
@@ -259,7 +259,7 @@ bool ClientNetworkCoordinatorSocketHandler::ReceiveGameCoordinatorListing(Packet
|
||||
/* Check for compatibility with the client. */
|
||||
CheckGameCompatibility(item->info);
|
||||
/* Mark server as online. */
|
||||
item->status = NGLS_ONLINE;
|
||||
item->status = NetworkGameStatus::Online;
|
||||
/* Mark the item as up-to-date. */
|
||||
item->version = _network_game_list_version;
|
||||
}
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
#include "network_type.h"
|
||||
|
||||
/** The status a server can be in. */
|
||||
enum NetworkGameStatus : uint8_t {
|
||||
NGLS_OFFLINE, ///< Server is offline (or cannot be queried).
|
||||
NGLS_ONLINE, ///< Server is online.
|
||||
NGLS_FULL, ///< Server is full and cannot be queried.
|
||||
NGLS_BANNED, ///< You are banned from this server.
|
||||
NGLS_TOO_OLD, ///< Server is too old to query.
|
||||
enum class NetworkGameStatus : uint8_t {
|
||||
Offline, ///< Server is offline (or cannot be queried).
|
||||
Online, ///< Server is online.
|
||||
Full, ///< Server is full and cannot be queried.
|
||||
Banned, ///< You are banned from this server.
|
||||
TooOld, ///< Server is too old to query.
|
||||
};
|
||||
|
||||
/** Structure with information shown in the game list (GUI) */
|
||||
@@ -33,7 +33,7 @@ struct NetworkGame {
|
||||
|
||||
NetworkGameInfo info{}; ///< The game information of this server.
|
||||
std::string connection_string; ///< Address of the server.
|
||||
NetworkGameStatus status = NGLS_OFFLINE; ///< Stats of the server.
|
||||
NetworkGameStatus status = NetworkGameStatus::Offline; ///< Stats of the server.
|
||||
bool manually = false; ///< True if the server was added manually.
|
||||
bool refreshing = false; ///< Whether this server is being queried.
|
||||
int version = 0; ///< Used to see which servers are no longer available on the Game Coordinator and can be removed.
|
||||
|
||||
+10
-10
@@ -378,7 +378,7 @@ protected:
|
||||
DrawString(name.left, name.right, y + text_y_offset, cur_item->info.server_name, TextColour::Black);
|
||||
|
||||
/* only draw details if the server is online */
|
||||
if (cur_item->status == NGLS_ONLINE) {
|
||||
if (cur_item->status == NetworkGameStatus::Online) {
|
||||
if (const NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_NG_CLIENTS); nwid->current_x != 0) {
|
||||
Rect clients = nwid->GetCurrentRect();
|
||||
DrawString(clients.left, clients.right, y + text_y_offset,
|
||||
@@ -585,7 +585,7 @@ public:
|
||||
this->SetWidgetDisabledState(WID_NG_REFRESH, sel == nullptr);
|
||||
/* 'Join' button disabling conditions */
|
||||
this->SetWidgetDisabledState(WID_NG_JOIN, sel == nullptr || // no Selected Server
|
||||
sel->status != NGLS_ONLINE || // Server offline
|
||||
sel->status != NetworkGameStatus::Online || // Server offline
|
||||
sel->info.clients_on >= sel->info.clients_max || // Server full
|
||||
!sel->info.compatible); // Revision mismatch
|
||||
|
||||
@@ -593,8 +593,8 @@ public:
|
||||
|
||||
/* 'NewGRF Settings' button invisible if no NewGRF is used */
|
||||
bool changed = false;
|
||||
changed |= this->GetWidget<NWidgetStacked>(WID_NG_NEWGRF_SEL)->SetDisplayedPlane(sel == nullptr || sel->status != NGLS_ONLINE || sel->info.grfconfig.empty() ? SZSP_NONE : 0);
|
||||
changed |= this->GetWidget<NWidgetStacked>(WID_NG_NEWGRF_MISSING_SEL)->SetDisplayedPlane(sel == nullptr || sel->status != NGLS_ONLINE || sel->info.grfconfig.empty() || !sel->info.version_compatible || sel->info.compatible ? SZSP_NONE : 0);
|
||||
changed |= this->GetWidget<NWidgetStacked>(WID_NG_NEWGRF_SEL)->SetDisplayedPlane(sel == nullptr || sel->status != NetworkGameStatus::Online || sel->info.grfconfig.empty() ? SZSP_NONE : 0);
|
||||
changed |= this->GetWidget<NWidgetStacked>(WID_NG_NEWGRF_MISSING_SEL)->SetDisplayedPlane(sel == nullptr || sel->status != NetworkGameStatus::Online || sel->info.grfconfig.empty() || !sel->info.version_compatible || sel->info.compatible ? SZSP_NONE : 0);
|
||||
if (changed) {
|
||||
this->ReInit();
|
||||
return;
|
||||
@@ -618,11 +618,11 @@ public:
|
||||
{
|
||||
if (this->server == nullptr) return STR_NETWORK_SERVER_LIST_GAME_INFO;
|
||||
switch (this->server->status) {
|
||||
case NGLS_OFFLINE: return STR_NETWORK_SERVER_LIST_SERVER_OFFLINE;
|
||||
case NGLS_ONLINE: return STR_NETWORK_SERVER_LIST_GAME_INFO;
|
||||
case NGLS_FULL: return STR_NETWORK_SERVER_LIST_SERVER_FULL;
|
||||
case NGLS_BANNED: return STR_NETWORK_SERVER_LIST_SERVER_BANNED;
|
||||
case NGLS_TOO_OLD: return STR_NETWORK_SERVER_LIST_SERVER_TOO_OLD;
|
||||
case NetworkGameStatus::Offline: return STR_NETWORK_SERVER_LIST_SERVER_OFFLINE;
|
||||
case NetworkGameStatus::Online: return STR_NETWORK_SERVER_LIST_GAME_INFO;
|
||||
case NetworkGameStatus::Full: return STR_NETWORK_SERVER_LIST_SERVER_FULL;
|
||||
case NetworkGameStatus::Banned: return STR_NETWORK_SERVER_LIST_SERVER_BANNED;
|
||||
case NetworkGameStatus::TooOld: return STR_NETWORK_SERVER_LIST_SERVER_TOO_OLD;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
}
|
||||
@@ -652,7 +652,7 @@ public:
|
||||
if (sel == nullptr) return;
|
||||
|
||||
hr.top = DrawStringMultiLine(hr, sel->info.server_name, TextColour::Orange, SA_HOR_CENTER); // game name
|
||||
if (sel->status != NGLS_ONLINE) {
|
||||
if (sel->status != NetworkGameStatus::Online) {
|
||||
tr.top = DrawStringMultiLine(tr, header_msg, TextColour::FromString, SA_HOR_CENTER);
|
||||
} else { // show game info
|
||||
tr.top = DrawStringMultiLine(tr, GetString(STR_NETWORK_SERVER_LIST_CLIENTS, sel->info.clients_on, sel->info.clients_max, sel->info.companies_on, sel->info.companies_max));
|
||||
|
||||
@@ -25,7 +25,7 @@ NetworkRecvStatus QueryNetworkGameSocketHandler::CloseConnection(NetworkRecvStat
|
||||
/* Connection is closed, but we never received a packet. Must be offline. */
|
||||
NetworkGame *item = NetworkGameListAddItem(this->connection_string);
|
||||
if (item->refreshing) {
|
||||
item->status = NGLS_OFFLINE;
|
||||
item->status = NetworkGameStatus::Offline;
|
||||
item->refreshing = false;
|
||||
|
||||
UpdateNetworkGameWindow();
|
||||
@@ -92,7 +92,7 @@ NetworkRecvStatus QueryNetworkGameSocketHandler::ReceiveServerFull(Packet &)
|
||||
Debug(net, 9, "Query::ReceiveServerFull()");
|
||||
|
||||
NetworkGame *item = NetworkGameListAddItem(this->connection_string);
|
||||
item->status = NGLS_FULL;
|
||||
item->status = NetworkGameStatus::Full;
|
||||
item->refreshing = false;
|
||||
|
||||
UpdateNetworkGameWindow();
|
||||
@@ -105,7 +105,7 @@ NetworkRecvStatus QueryNetworkGameSocketHandler::ReceiveServerBanned(Packet &)
|
||||
Debug(net, 9, "Query::ReceiveServerBanned()");
|
||||
|
||||
NetworkGame *item = NetworkGameListAddItem(this->connection_string);
|
||||
item->status = NGLS_BANNED;
|
||||
item->status = NetworkGameStatus::Banned;
|
||||
item->refreshing = false;
|
||||
|
||||
UpdateNetworkGameWindow();
|
||||
@@ -126,7 +126,7 @@ NetworkRecvStatus QueryNetworkGameSocketHandler::ReceiveServerGameInfo(Packet &p
|
||||
/* Check for compatibility with the client. */
|
||||
CheckGameCompatibility(item->info);
|
||||
/* Ensure we consider the server online. */
|
||||
item->status = NGLS_ONLINE;
|
||||
item->status = NetworkGameStatus::Online;
|
||||
item->refreshing = false;
|
||||
|
||||
UpdateNetworkGameWindow();
|
||||
@@ -147,9 +147,9 @@ NetworkRecvStatus QueryNetworkGameSocketHandler::ReceiveServerError(Packet &p)
|
||||
* NetworkErrorCode::NotExpected on requesting the game info. Show to the
|
||||
* user this server is too old to query.
|
||||
*/
|
||||
item->status = NGLS_TOO_OLD;
|
||||
item->status = NetworkGameStatus::TooOld;
|
||||
} else {
|
||||
item->status = NGLS_OFFLINE;
|
||||
item->status = NetworkGameStatus::Offline;
|
||||
}
|
||||
item->refreshing = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user