Ticket #1950: t1950_show_who_paused_v1.patch
File t1950_show_who_paused_v1.patch, 11.5 KB (added by , 9 years ago) |
---|
-
binaries/data/mods/public/gui/session/menu.js
651 651 652 652 function togglePause() 653 653 { 654 654 closeMenu(); 655 655 closeOpenDialogs(); 656 656 657 657 var pauseOverlay = Engine.GetGUIObjectByName("pauseOverlay"); 658 658 659 659 if (pauseOverlay.hidden) 660 660 { 661 661 Engine.GetGUIObjectByName("pauseButtonText").caption = RESUME; … … 666 666 Engine.SetPaused(false); 667 667 Engine.GetGUIObjectByName("pauseButtonText").caption = PAUSE; 668 668 } 669 669 670 670 pauseOverlay.hidden = !pauseOverlay.hidden; 671 672 Engine.SendNetworkPaused(pauseOverlay.hidden ? 0 : 1); 671 673 } 672 674 673 675 function openManual() 674 676 { 675 677 closeMenu(); -
binaries/data/mods/public/gui/session/messages.js
299 299 300 300 case "rejoined": 301 301 addChatMessage({ "type": "rejoined", "guid": message.guid}); 302 302 break; 303 303 304 case "paused": 305 addChatMessage({ "type": "paused", "guid": message.guid, "paused": message.paused}); 306 break; 307 304 308 // To prevent errors, ignore these message types that occur during autostart 305 309 case "gamesetup": 306 310 case "start": 307 311 break; 308 312 … … 446 450 formatted = sprintf(translate("%(player)s has left the game."), { player: "[color=\"" + playerColor + "\"]" + username + "[/color]" }); 447 451 break; 448 452 case "rejoined": 449 453 formatted = sprintf(translate("%(player)s has rejoined the game."), { player: "[color=\"" + playerColor + "\"]" + username + "[/color]" }); 450 454 break; 455 case "paused": 456 var pausedMsg = msg.paused > 0 ? "%(player)s has paused the game" : "%(player)s has unpaused the game."; 457 formatted = sprintf(translate(pausedMsg), { player: "[color=\"" + playerColor + "\"]" + username + "[/color]" }); 458 break; 451 459 case "defeat": 452 460 // In singleplayer, the local player is "You". "You has" is incorrect. 453 461 if (!g_IsNetworked && msg.player == Engine.GetPlayerID()) 454 462 formatted = translate("You have been defeated."); 455 463 else -
source/gui/scripting/ScriptFunctions.cpp
400 400 ENSURE(g_NetClient); 401 401 402 402 g_NetClient->SendRejoinedMessage(); 403 403 } 404 404 405 void SendNetworkPaused(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int paused) 406 { 407 ENSURE(g_NetClient); 408 409 g_NetClient->SendPausedMessage(paused); 410 } 411 405 412 JS::Value GetAIs(ScriptInterface::CxPrivate* pCxPrivate) 406 413 { 407 414 return ICmpAIManager::GetAIs(*(pCxPrivate->pScriptInterface)); 408 415 } 409 416 … … 962 969 scriptInterface.RegisterFunction<void, std::string, int, &SetNetworkPlayerStatus>("SetNetworkPlayerStatus"); 963 970 scriptInterface.RegisterFunction<void, &ClearAllPlayerReady>("ClearAllPlayerReady"); 964 971 scriptInterface.RegisterFunction<void, std::wstring, &SendNetworkChat>("SendNetworkChat"); 965 972 scriptInterface.RegisterFunction<void, int, &SendNetworkReady>("SendNetworkReady"); 966 973 scriptInterface.RegisterFunction<void, &SendNetworkRejoined>("SendNetworkRejoined"); 974 scriptInterface.RegisterFunction<void, int, &SendNetworkPaused>("SendNetworkPaused"); 967 975 scriptInterface.RegisterFunction<JS::Value, &GetAIs>("GetAIs"); 968 976 scriptInterface.RegisterFunction<JS::Value, &GetEngineInfo>("GetEngineInfo"); 969 977 970 978 // Saved games 971 979 scriptInterface.RegisterFunction<JS::Value, std::wstring, &StartSavedGame>("StartSavedGame"); -
source/network/NetClient.cpp
108 108 AddTransition(NCS_LOADING, (uint)NMT_GAME_SETUP, NCS_LOADING, (void*)&OnGameSetup, context); 109 109 AddTransition(NCS_LOADING, (uint)NMT_PLAYER_ASSIGNMENT, NCS_LOADING, (void*)&OnPlayerAssignment, context); 110 110 AddTransition(NCS_LOADING, (uint)NMT_LOADED_GAME, NCS_INGAME, (void*)&OnLoadedGame, context); 111 111 112 112 AddTransition(NCS_INGAME, (uint)NMT_REJOINED, NCS_INGAME, (void*)&OnRejoined, context); 113 AddTransition(NCS_INGAME, (uint)NMT_PAUSED, NCS_INGAME, (void*)&OnPaused, context); 113 114 AddTransition(NCS_INGAME, (uint)NMT_CHAT, NCS_INGAME, (void*)&OnChat, context); 114 115 AddTransition(NCS_INGAME, (uint)NMT_GAME_SETUP, NCS_INGAME, (void*)&OnGameSetup, context); 115 116 AddTransition(NCS_INGAME, (uint)NMT_PLAYER_ASSIGNMENT, NCS_INGAME, (void*)&OnPlayerAssignment, context); 116 117 AddTransition(NCS_INGAME, (uint)NMT_SIMULATION_COMMAND, NCS_INGAME, (void*)&OnInGame, context); 117 118 AddTransition(NCS_INGAME, (uint)NMT_SYNC_ERROR, NCS_INGAME, (void*)&OnInGame, context); … … 291 292 { 292 293 CRejoinedMessage rejoinedMessage; 293 294 SendMessage(&rejoinedMessage); 294 295 } 295 296 297 void CNetClient::SendPausedMessage(const int paused) 298 { 299 CPausedMessage pausedMessage; 300 pausedMessage.m_Paused = paused; 301 SendMessage(&pausedMessage); 302 } 303 296 304 bool CNetClient::HandleMessage(CNetMessage* message) 297 305 { 298 306 // Handle non-FSM messages first 299 307 300 308 Status status = m_Session->GetFileTransferer().HandleMessageReceive(message); … … 605 613 client->PushGuiMessage(msg); 606 614 607 615 return true; 608 616 } 609 617 618 bool CNetClient::OnPaused(void *context, CFsmEvent* event) 619 { 620 ENSURE(event->GetType() == (uint)NMT_PAUSED); 621 622 CNetClient* client = (CNetClient*)context; 623 JSContext* cx = client->GetScriptInterface().GetContext(); 624 625 CPausedMessage* message = (CPausedMessage*)event->GetParamRef(); 626 JS::RootedValue msg(cx); 627 client->GetScriptInterface().Eval("({'type':'paused'})", &msg); 628 client->GetScriptInterface().SetProperty(msg, "guid", std::string(message->m_GUID), false); 629 client->GetScriptInterface().SetProperty(msg, "paused", int(message->m_Paused), false); 630 631 client->PushGuiMessage(msg); 632 633 return true; 634 } 635 610 636 bool CNetClient::OnLoadedGame(void* context, CFsmEvent* event) 611 637 { 612 638 ENSURE(event->GetType() == (uint)NMT_LOADED_GAME); 613 639 614 640 CNetClient* client = (CNetClient*)context; -
source/network/NetClient.h
184 184 * Call when the client has rejoined a running match and finished 185 185 * the loading screen. 186 186 */ 187 187 void SendRejoinedMessage(); 188 188 189 /** 190 * Call when the client has paused or unpaused a running match. 191 */ 192 void SendPausedMessage(const int paused); 193 189 194 private: 190 195 // Net message / FSM transition handlers 191 196 static bool OnConnect(void* context, CFsmEvent* event); 192 197 static bool OnHandshake(void* context, CFsmEvent* event); 193 198 static bool OnHandshakeResponse(void* context, CFsmEvent* event); … … 199 204 static bool OnInGame(void* context, CFsmEvent* event); 200 205 static bool OnGameStart(void* context, CFsmEvent* event); 201 206 static bool OnJoinSyncStart(void* context, CFsmEvent* event); 202 207 static bool OnJoinSyncEndCommandBatch(void* context, CFsmEvent* event); 203 208 static bool OnRejoined(void* context, CFsmEvent* event); 209 static bool OnPaused(void* context, CFsmEvent* event); 204 210 static bool OnLoadedGame(void* context, CFsmEvent* event); 205 211 206 212 /** 207 213 * Take ownership of a session object, and use it for all network communication. 208 214 */ -
source/network/NetMessage.cpp
133 133 134 134 case NMT_REJOINED: 135 135 pNewMessage = new CRejoinedMessage; 136 136 break; 137 137 138 case NMT_PAUSED: 139 pNewMessage = new CPausedMessage; 140 break; 141 138 142 case NMT_LOADED_GAME: 139 143 pNewMessage = new CLoadedGameMessage; 140 144 break; 141 145 142 146 case NMT_SERVER_HANDSHAKE: -
source/network/NetMessages.h
59 59 60 60 NMT_REJOINED, 61 61 62 62 NMT_LOADED_GAME, 63 63 NMT_GAME_START, 64 65 NMT_PAUSED, 66 64 67 NMT_END_COMMAND_BATCH, 65 68 NMT_SYNC_CHECK, // OOS-detection hash checking 66 69 NMT_SYNC_ERROR, // OOS-detection error 67 70 NMT_SIMULATION_COMMAND, 68 71 NMT_LAST // Last message in the list … … 159 162 160 163 START_NMT_CLASS_(Rejoined, NMT_REJOINED) 161 164 NMT_FIELD(CStr8, m_GUID) 162 165 END_NMT_CLASS() 163 166 167 START_NMT_CLASS_(Paused, NMT_PAUSED) 168 NMT_FIELD(CStr8, m_GUID) 169 NMT_FIELD_INT(m_Paused, u8, 1) 170 END_NMT_CLASS() 171 164 172 START_NMT_CLASS_(LoadedGame, NMT_LOADED_GAME) 165 173 NMT_FIELD_INT(m_CurrentTurn, u32, 4) 166 174 END_NMT_CLASS() 167 175 168 176 START_NMT_CLASS_(GameStart, NMT_GAME_START) -
source/network/NetServer.cpp
592 592 593 593 session->AddTransition(NSS_JOIN_SYNCING, (uint)NMT_CONNECTION_LOST, NSS_UNCONNECTED, (void*)&OnDisconnect, context); 594 594 session->AddTransition(NSS_JOIN_SYNCING, (uint)NMT_LOADED_GAME, NSS_INGAME, (void*)&OnJoinSyncingLoadedGame, context); 595 595 596 596 session->AddTransition(NSS_INGAME, (uint)NMT_REJOINED, NSS_INGAME, (void*)&OnRejoined, context); 597 session->AddTransition(NSS_INGAME, (uint)NMT_PAUSED, NSS_INGAME, (void*)&OnPaused, context); 597 598 session->AddTransition(NSS_INGAME, (uint)NMT_CONNECTION_LOST, NSS_UNCONNECTED, (void*)&OnDisconnect, context); 598 599 session->AddTransition(NSS_INGAME, (uint)NMT_CHAT, NSS_INGAME, (void*)&OnChat, context); 599 600 session->AddTransition(NSS_INGAME, (uint)NMT_SIMULATION_COMMAND, NSS_INGAME, (void*)&OnInGame, context); 600 601 session->AddTransition(NSS_INGAME, (uint)NMT_SYNC_CHECK, NSS_INGAME, (void*)&OnInGame, context); 601 602 session->AddTransition(NSS_INGAME, (uint)NMT_END_COMMAND_BATCH, NSS_INGAME, (void*)&OnInGame, context); … … 1001 1002 1002 1003 message->m_GUID = session->GetGUID(); 1003 1004 1004 1005 server.Broadcast(message); 1005 1006 1007 return true; 1008 } 1009 1010 bool CNetServerWorker::OnPaused(void* context, CFsmEvent* event) 1011 { 1012 // A client has paused or unpaused the game. 1013 ENSURE(event->GetType() == (uint)NMT_PAUSED); 1014 1015 CNetServerSession* session = (CNetServerSession*)context; 1016 CNetServerWorker& server = session->GetServer(); 1017 1018 CPausedMessage* message = (CPausedMessage*)event->GetParamRef(); 1019 1020 message->m_GUID = session->GetGUID(); 1021 1022 server.Broadcast(message); 1023 1006 1024 return true; 1007 1025 } 1008 1026 1009 1027 bool CNetServerWorker::OnDisconnect(void* context, CFsmEvent* event) 1010 1028 { -
source/network/NetServer.h
261 261 static bool OnChat(void* context, CFsmEvent* event); 262 262 static bool OnReady(void* context, CFsmEvent* event); 263 263 static bool OnLoadedGame(void* context, CFsmEvent* event); 264 264 static bool OnJoinSyncingLoadedGame(void* context, CFsmEvent* event); 265 265 static bool OnRejoined(void* context, CFsmEvent* event); 266 static bool OnPaused(void* context, CFsmEvent* event); 266 267 static bool OnDisconnect(void* context, CFsmEvent* event); 267 268 268 269 void CheckGameLoadStatus(CNetServerSession* changedSession); 269 270 270 271 void ConstructPlayerAssignmentMessage(CPlayerAssignmentMessage& message);