GlobalLobbyWindow.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * GlobalLobbyWindow.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 "GlobalLobbyWindow.h"
  12. #include "GlobalLobbyClient.h"
  13. #include "GlobalLobbyServerSetup.h"
  14. #include "GlobalLobbyWidget.h"
  15. #include "../CServerHandler.h"
  16. #include "../gui/CGuiHandler.h"
  17. #include "../gui/WindowHandler.h"
  18. #include "../widgets/TextControls.h"
  19. #include "../widgets/ObjectLists.h"
  20. #include "../../lib/CConfigHandler.h"
  21. #include "../../lib/MetaString.h"
  22. GlobalLobbyWindow::GlobalLobbyWindow()
  23. : CWindowObject(BORDERED)
  24. {
  25. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  26. widget = std::make_shared<GlobalLobbyWidget>(this);
  27. pos = widget->pos;
  28. center();
  29. widget->getAccountNameLabel()->setText(settings["lobby"]["displayName"].String());
  30. }
  31. void GlobalLobbyWindow::doSendChatMessage()
  32. {
  33. std::string messageText = widget->getMessageInput()->getText();
  34. JsonNode toSend;
  35. toSend["type"].String() = "sendChatMessage";
  36. toSend["messageText"].String() = messageText;
  37. CSH->getGlobalLobby().sendMessage(toSend);
  38. widget->getMessageInput()->setText("");
  39. }
  40. void GlobalLobbyWindow::doCreateGameRoom()
  41. {
  42. GH.windows().createAndPushWindow<GlobalLobbyServerSetup>();
  43. }
  44. void GlobalLobbyWindow::doInviteAccount(const std::string & accountID)
  45. {
  46. assert(0); // TODO
  47. }
  48. void GlobalLobbyWindow::doJoinRoom(const std::string & roomID)
  49. {
  50. JsonNode toSend;
  51. toSend["type"].String() = "joinGameRoom";
  52. toSend["gameRoomID"].String() = roomID;
  53. CSH->getGlobalLobby().sendMessage(toSend);
  54. }
  55. void GlobalLobbyWindow::onGameChatMessage(const std::string & sender, const std::string & message, const std::string & when)
  56. {
  57. MetaString chatMessageFormatted;
  58. chatMessageFormatted.appendRawString("[%s] {%s}: %s\n");
  59. chatMessageFormatted.replaceRawString(when);
  60. chatMessageFormatted.replaceRawString(sender);
  61. chatMessageFormatted.replaceRawString(message);
  62. chatHistory += chatMessageFormatted.toString();
  63. widget->getGameChat()->setText(chatHistory);
  64. }
  65. void GlobalLobbyWindow::onActiveAccounts(const std::vector<GlobalLobbyAccount> & accounts)
  66. {
  67. widget->getAccountList()->reset();
  68. }
  69. void GlobalLobbyWindow::onActiveRooms(const std::vector<GlobalLobbyRoom> & rooms)
  70. {
  71. widget->getRoomList()->reset();
  72. }