diff --git a/distribution/changelog.txt b/distribution/changelog.txt index d2bde20c27..5177a0b6e5 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -5,6 +5,7 @@ - Improved: [#26747] Exporting a sprite file now also outputs a JSON file, allowing for round-trip conversions. - Improved: [#26763] The ride colour/appearance tab now visually separates fields using group boxes. - Improved: [#26765] The ride operations tab now visually separates fields using group boxes. +- Fix: [#26610] Player list is not updated automatically when a player joins or leaves. - Fix: [#26639] Handymen could begin a task while another handyman was already doing the exact same task. - Fix: [#26752] The Cut-away View window doesn’t display negative height values correctly on some platforms. - Fix: [#26756] Guests cannot puke or litter on sloped path. diff --git a/src/openrct2-ui/WindowManager.cpp b/src/openrct2-ui/WindowManager.cpp index b6c44db264..198ef8a926 100644 --- a/src/openrct2-ui/WindowManager.cpp +++ b/src/openrct2-ui/WindowManager.cpp @@ -577,6 +577,9 @@ public: case INTENT_ACTION_REMOVE_PROVISIONAL_TRACK_PIECE: RideRemoveProvisionalTrackPiece(); break; + case INTENT_ACTION_REFRESH_PLAYER_LIST: + MultiplayerRefreshList(); + break; default: break; } diff --git a/src/openrct2-ui/windows/Multiplayer.cpp b/src/openrct2-ui/windows/Multiplayer.cpp index 8e9579e0a1..702c06eeb1 100644 --- a/src/openrct2-ui/windows/Multiplayer.cpp +++ b/src/openrct2-ui/windows/Multiplayer.cpp @@ -519,6 +519,7 @@ namespace OpenRCT2::Ui::Windows widgets[WIDX_TITLE].text = WindowMultiplayerPageTitles[page]; setWidgetPressed(WIDX_TAB1 + page, true); + refreshList(); onResize(); onPrepareDraw(); initScrollWidgets(); @@ -611,8 +612,6 @@ namespace OpenRCT2::Ui::Windows { WindowSetResize(*this, { 420, 124 }, { 500, 450 }); - numListItems = (IsServerPlayerInvisible() ? Network::GetNumVisiblePlayers() : Network::GetNumPlayers()); - widgets[WIDX_HEADER_PING].right = width - 5; selectedListItem = -1; @@ -898,6 +897,14 @@ namespace OpenRCT2::Ui::Windows break; } } + + void refreshList() + { + if (page == WINDOW_MULTIPLAYER_PAGE_PLAYERS) + { + numListItems = (IsServerPlayerInvisible() ? Network::GetNumVisiblePlayers() : Network::GetNumPlayers()); + } + } }; WindowBase* MultiplayerOpen() @@ -914,4 +921,14 @@ namespace OpenRCT2::Ui::Windows return window; } + + void MultiplayerRefreshList() + { + auto* windowMgr = GetWindowManager(); + auto w = static_cast(windowMgr->FindByClass(WindowClass::multiplayer)); + if (w != nullptr) + { + w->refreshList(); + } + } } // namespace OpenRCT2::Ui::Windows diff --git a/src/openrct2-ui/windows/Windows.h b/src/openrct2-ui/windows/Windows.h index 077bc10b5e..1577193e82 100644 --- a/src/openrct2-ui/windows/Windows.h +++ b/src/openrct2-ui/windows/Windows.h @@ -160,8 +160,9 @@ namespace OpenRCT2::Ui::Windows WindowBase* MazeConstructionOpen(); void WindowMazeConstructionUpdatePressedWidgets(); - // Multiplatyer + // Multiplayer WindowBase* MultiplayerOpen(); + void MultiplayerRefreshList(); // NewCampaign WindowBase* NewCampaignOpen(int16_t campaignType); diff --git a/src/openrct2/network/NetworkBase.cpp b/src/openrct2/network/NetworkBase.cpp index 21fda352a5..fd6d47388c 100644 --- a/src/openrct2/network/NetworkBase.cpp +++ b/src/openrct2/network/NetworkBase.cpp @@ -1978,6 +1978,13 @@ namespace OpenRCT2::Network { _playerListInvalidated = false; ServerSendPlayerList(); + + if (!gOpenRCT2Headless) + { + // Update player list window + auto intent = Intent(INTENT_ACTION_REFRESH_PLAYER_LIST); + ContextBroadcastIntent(&intent); + } } } else @@ -1985,74 +1992,82 @@ namespace OpenRCT2::Network // As client we have to keep things in order so the update is tick bound. // Commands/Actions reference players and so this list needs to be in sync with those. auto itPending = _pendingPlayerLists.begin(); - while (itPending != _pendingPlayerLists.end()) + if (itPending != _pendingPlayerLists.end()) { - if (itPending->first > getGameState().currentTicks) - break; - - // List of active players found in the list. - std::vector activePlayerIds; - std::vector newPlayers; - std::vector removedPlayers; - - for (const auto& pendingPlayer : itPending->second.players) + while (itPending != _pendingPlayerLists.end()) { - activePlayerIds.push_back(pendingPlayer.id); + if (itPending->first > getGameState().currentTicks) + break; - auto* player = GetPlayerByID(pendingPlayer.id); - if (player == nullptr) + // List of active players found in the list. + std::vector activePlayerIds; + std::vector newPlayers; + std::vector removedPlayers; + + for (const auto& pendingPlayer : itPending->second.players) { - // Add new player. - player = AddPlayer("", ""); - if (player != nullptr) + activePlayerIds.push_back(pendingPlayer.id); + + auto* player = GetPlayerByID(pendingPlayer.id); + if (player == nullptr) { - *player = pendingPlayer; - if (player->flags & PlayerFlags::kIsServer) + // Add new player. + player = AddPlayer("", ""); + if (player != nullptr) { - _serverConnection->player = player; + *player = pendingPlayer; + if (player->flags & PlayerFlags::kIsServer) + { + _serverConnection->player = player; + } + newPlayers.push_back(player->id); } - newPlayers.push_back(player->id); + } + else + { + // Update. + *player = pendingPlayer; } } - else + + // Remove any players that are not in newly received list + for (const auto& player : player_list) { - // Update. - *player = pendingPlayer; + if (std::find(activePlayerIds.begin(), activePlayerIds.end(), player->id) == activePlayerIds.end()) + { + removedPlayers.push_back(player->id); + } } - } - // Remove any players that are not in newly received list - for (const auto& player : player_list) - { - if (std::find(activePlayerIds.begin(), activePlayerIds.end(), player->id) == activePlayerIds.end()) + // Run player removed hooks (must be before players removed from list) + for (auto playerId : removedPlayers) { - removedPlayers.push_back(player->id); + ProcessPlayerLeftPluginHooks(playerId); } + + // Run player joined hooks (must be after players added to list) + for (auto playerId : newPlayers) + { + ProcessPlayerJoinedPluginHooks(playerId); + } + + // Now actually remove removed players from player list + player_list.erase( + std::remove_if( + player_list.begin(), player_list.end(), + [&removedPlayers](const std::unique_ptr& player) { + return std::find(removedPlayers.begin(), removedPlayers.end(), player->id) + != removedPlayers.end(); + }), + player_list.end()); + + _pendingPlayerLists.erase(itPending); + itPending = _pendingPlayerLists.begin(); } - // Run player removed hooks (must be before players removed from list) - for (auto playerId : removedPlayers) - { - ProcessPlayerLeftPluginHooks(playerId); - } - - // Run player joined hooks (must be after players added to list) - for (auto playerId : newPlayers) - { - ProcessPlayerJoinedPluginHooks(playerId); - } - - // Now actually remove removed players from player list - player_list.erase( - std::remove_if( - player_list.begin(), player_list.end(), - [&removedPlayers](const std::unique_ptr& player) { - return std::find(removedPlayers.begin(), removedPlayers.end(), player->id) != removedPlayers.end(); - }), - player_list.end()); - - _pendingPlayerLists.erase(itPending); - itPending = _pendingPlayerLists.begin(); + // Update player list window + auto intent = Intent(INTENT_ACTION_REFRESH_PLAYER_LIST); + ContextBroadcastIntent(&intent); } } } diff --git a/src/openrct2/windows/Intent.h b/src/openrct2/windows/Intent.h index 3fe54d28e6..84508e6646 100644 --- a/src/openrct2/windows/Intent.h +++ b/src/openrct2/windows/Intent.h @@ -57,6 +57,7 @@ namespace OpenRCT2 INTENT_ACTION_RESTORE_PROVISIONAL_ELEMENTS, INTENT_ACTION_REMOVE_PROVISIONAL_FOOTPATH, INTENT_ACTION_REMOVE_PROVISIONAL_TRACK_PIECE, + INTENT_ACTION_REFRESH_PLAYER_LIST, INTENT_ACTION_NULL = 255, };