NetPacksLobbyClient.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * NetPacksLobbyClient.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "lobby/CSelectionBase.h"
  12. #include "lobby/CLobbyScreen.h"
  13. #include "lobby/OptionsTab.h"
  14. #include "lobby/RandomMapTab.h"
  15. #include "lobby/SelectionTab.h"
  16. #include "lobby/CBonusSelection.h"
  17. #include "CServerHandler.h"
  18. #include "CGameInfo.h"
  19. #include "gui/CGuiHandler.h"
  20. #include "widgets/Buttons.h"
  21. #include "widgets/TextControls.h"
  22. #include "../lib/CConfigHandler.h"
  23. #include "../lib/CGeneralTextHandler.h"
  24. #include "../lib/NetPacksLobby.h"
  25. #include "../lib/serializer/Connection.h"
  26. bool LobbyClientConnected::applyOnLobbyHandler(CServerHandler * handler)
  27. {
  28. // Check if it's LobbyClientConnected for our client
  29. if(uuid == handler->c->uuid)
  30. {
  31. handler->c->connectionID = clientId;
  32. if(!settings["session"]["headless"].Bool())
  33. GH.pushInt(new CLobbyScreen(static_cast<ESelectionScreen>(handler->screenType)));
  34. handler->state = EClientState::LOBBY;
  35. return true;
  36. }
  37. return false;
  38. }
  39. void LobbyClientConnected::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
  40. {
  41. if(uuid == handler->c->uuid)
  42. {
  43. }
  44. }
  45. bool LobbyClientDisconnected::applyOnLobbyHandler(CServerHandler * handler)
  46. {
  47. if(clientId != c->connectionID)
  48. return false;
  49. handler->stopServerConnection();
  50. return true;
  51. }
  52. void LobbyClientDisconnected::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
  53. {
  54. GH.popIntTotally(lobby);
  55. }
  56. void LobbyChatMessage::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
  57. {
  58. if(lobby)
  59. {
  60. lobby->card->chat->addNewMessage(playerName + ": " + message);
  61. lobby->card->setChat(true);
  62. if(lobby->buttonChat)
  63. lobby->buttonChat->addTextOverlay(CGI->generaltexth->allTexts[531], FONT_SMALL);
  64. }
  65. }
  66. void LobbyGuiAction::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
  67. {
  68. if(!handler->isGuest())
  69. return;
  70. switch(action)
  71. {
  72. case NO_TAB:
  73. lobby->toggleTab(lobby->curTab);
  74. break;
  75. case OPEN_OPTIONS:
  76. lobby->toggleTab(lobby->tabOpt);
  77. break;
  78. case OPEN_SCENARIO_LIST:
  79. lobby->toggleTab(lobby->tabSel);
  80. break;
  81. case OPEN_RANDOM_MAP_OPTIONS:
  82. lobby->toggleTab(lobby->tabRand);
  83. break;
  84. }
  85. }
  86. bool LobbyStartGame::applyOnLobbyHandler(CServerHandler * handler)
  87. {
  88. if(handler->state == EClientState::GAMEPLAY)
  89. {
  90. handler->endGameplay(false);
  91. }
  92. handler->state = EClientState::STARTING;
  93. if(handler->si->mode != StartInfo::LOAD_GAME)
  94. {
  95. handler->si = initializedStartInfo;
  96. }
  97. if(settings["session"]["headless"].Bool())
  98. handler->startGameplay();
  99. return true;
  100. }
  101. void LobbyStartGame::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
  102. {
  103. CMM->showLoadingScreen(std::bind(&CServerHandler::startGameplay, handler));
  104. }
  105. bool LobbyUpdateState::applyOnLobbyHandler(CServerHandler * handler)
  106. {
  107. hostChanged = state.hostClientId != handler->hostClientId;
  108. static_cast<LobbyState &>(*handler) = state;
  109. return true;
  110. }
  111. void LobbyUpdateState::applyOnLobbyScreen(CLobbyScreen * lobby, CServerHandler * handler)
  112. {
  113. if(!lobby->bonusSel && handler->si->campState && handler->state == EClientState::LOBBY_CAMPAIGN)
  114. {
  115. lobby->bonusSel = new CBonusSelection();
  116. GH.pushInt(lobby->bonusSel);
  117. }
  118. if(lobby->bonusSel)
  119. lobby->bonusSel->updateAfterStateChange();
  120. else
  121. lobby->updateAfterStateChange();
  122. if(hostChanged)
  123. lobby->toggleMode(handler->isHost());
  124. }