mirror of https://github.com/OpenTTD/OpenTTD.git
Add: [Network] Keep the refresh button in lowered state while refreshing (#9600)
This gives user visual feedback that the refresh is still pending, and prevents people from clicking again and again thinking nothing is happening. This is especially true for connections that fall back to TURN, as that takes a few seconds to kick in. Additionally, prevent clicking on the button again while a refresh is pending. This is only delaying a successful result.
This commit is contained in:
parent
2144cd98a3
commit
e4ad632989
|
@ -635,6 +635,7 @@ public:
|
|||
{
|
||||
NetworkGameList *item = NetworkGameListAddItem(connection_string);
|
||||
item->status = NGLS_OFFLINE;
|
||||
item->refreshing = false;
|
||||
|
||||
UpdateNetworkGameWindow();
|
||||
}
|
||||
|
@ -653,6 +654,10 @@ void NetworkQueryServer(const std::string &connection_string)
|
|||
{
|
||||
if (!_network_available) return;
|
||||
|
||||
/* Mark the entry as refreshing, so the GUI can show the refresh is pending. */
|
||||
NetworkGameList *item = NetworkGameListAddItem(connection_string);
|
||||
item->refreshing = true;
|
||||
|
||||
new TCPQueryConnecter(connection_string);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ struct NetworkGameList {
|
|||
std::string connection_string; ///< Address of the server.
|
||||
NetworkGameListStatus status = NGLS_OFFLINE; ///< Stats of the server.
|
||||
bool manually = false; ///< True if the server was added manually.
|
||||
uint8 retries = 0; ///< Number of retries (to stop requerying).
|
||||
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.
|
||||
NetworkGameList *next = nullptr; ///< Next pointer to make a linked game list.
|
||||
};
|
||||
|
|
|
@ -613,6 +613,8 @@ public:
|
|||
sel->info.clients_on >= sel->info.clients_max || // Server full
|
||||
!sel->info.compatible); // Revision mismatch
|
||||
|
||||
this->SetWidgetLoweredState(WID_NG_REFRESH, sel != nullptr && sel->refreshing);
|
||||
|
||||
/* 'NewGRF Settings' button invisible if no NewGRF is used */
|
||||
this->GetWidget<NWidgetStacked>(WID_NG_NEWGRF_SEL)->SetDisplayedPlane(sel == nullptr || sel->status != NGLS_ONLINE || sel->info.grfconfig == nullptr);
|
||||
this->GetWidget<NWidgetStacked>(WID_NG_NEWGRF_MISSING_SEL)->SetDisplayedPlane(sel == nullptr || sel->status != NGLS_ONLINE || sel->info.grfconfig == nullptr || !sel->info.version_compatible || sel->info.compatible);
|
||||
|
@ -790,7 +792,7 @@ public:
|
|||
break;
|
||||
|
||||
case WID_NG_REFRESH: // Refresh
|
||||
if (this->server != nullptr) NetworkQueryServer(this->server->connection_string);
|
||||
if (this->server != nullptr && !this->server->refreshing) NetworkQueryServer(this->server->connection_string);
|
||||
break;
|
||||
|
||||
case WID_NG_NEWGRF: // NewGRF Settings
|
||||
|
|
|
@ -79,6 +79,7 @@ NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_FULL(Packet *p)
|
|||
{
|
||||
NetworkGameList *item = NetworkGameListAddItem(this->connection_string);
|
||||
item->status = NGLS_FULL;
|
||||
item->refreshing = false;
|
||||
|
||||
UpdateNetworkGameWindow();
|
||||
|
||||
|
@ -89,6 +90,7 @@ NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_BANNED(Packet *p
|
|||
{
|
||||
NetworkGameList *item = NetworkGameListAddItem(this->connection_string);
|
||||
item->status = NGLS_BANNED;
|
||||
item->refreshing = false;
|
||||
|
||||
UpdateNetworkGameWindow();
|
||||
|
||||
|
@ -107,6 +109,7 @@ NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_GAME_INFO(Packet
|
|||
CheckGameCompatibility(item->info);
|
||||
/* Ensure we consider the server online. */
|
||||
item->status = NGLS_ONLINE;
|
||||
item->refreshing = false;
|
||||
|
||||
UpdateNetworkGameWindow();
|
||||
|
||||
|
@ -128,6 +131,7 @@ NetworkRecvStatus QueryNetworkGameSocketHandler::Receive_SERVER_ERROR(Packet *p)
|
|||
} else {
|
||||
item->status = NGLS_OFFLINE;
|
||||
}
|
||||
item->refreshing = false;
|
||||
|
||||
UpdateNetworkGameWindow();
|
||||
|
||||
|
|
Loading…
Reference in New Issue