forked from rosebudai/OpenRCT2-Web
Update player automatically when a player joins or leaves (#26610)
Send intent to refresh list when a player joins / leaves / has group changed.
This commit is contained in:
1 parent
9f6aa8f3ef
commit
b7ec766a62
6 files changed
+93
-55
No files matched your search
@@ -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.
|
||||
|
||||
@@ -577,6 +577,9 @@ public:
|
||||
case INTENT_ACTION_REMOVE_PROVISIONAL_TRACK_PIECE:
|
||||
RideRemoveProvisionalTrackPiece();
|
||||
break;
|
||||
case INTENT_ACTION_REFRESH_PLAYER_LIST:
|
||||
MultiplayerRefreshList();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -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<MultiplayerWindow*>(windowMgr->FindByClass(WindowClass::multiplayer));
|
||||
if (w != nullptr)
|
||||
{
|
||||
w->refreshList();
|
||||
}
|
||||
}
|
||||
} // namespace OpenRCT2::Ui::Windows
|
||||
@@ -160,8 +160,9 @@ namespace OpenRCT2::Ui::Windows
|
||||
WindowBase* MazeConstructionOpen();
|
||||
void WindowMazeConstructionUpdatePressedWidgets();
|
||||
|
||||
// Multiplatyer
|
||||
// Multiplayer
|
||||
WindowBase* MultiplayerOpen();
|
||||
void MultiplayerRefreshList();
|
||||
|
||||
// NewCampaign
|
||||
WindowBase* NewCampaignOpen(int16_t campaignType);
|
||||
|
||||
@@ -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<uint8_t> activePlayerIds;
|
||||
std::vector<uint8_t> newPlayers;
|
||||
std::vector<uint8_t> 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<uint8_t> activePlayerIds;
|
||||
std::vector<uint8_t> newPlayers;
|
||||
std::vector<uint8_t> 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>& 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>& 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user