GlobalLobbyWindow.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 "../../lib/CConfigHandler.h"
  20. #include "../../lib/MetaString.h"
  21. GlobalLobbyWindow::GlobalLobbyWindow()
  22. : CWindowObject(BORDERED)
  23. {
  24. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  25. widget = std::make_shared<GlobalLobbyWidget>(this);
  26. pos = widget->pos;
  27. center();
  28. widget->getAccountNameLabel()->setText(settings["lobby"]["displayName"].String());
  29. }
  30. void GlobalLobbyWindow::doSendChatMessage()
  31. {
  32. std::string messageText = widget->getMessageInput()->getText();
  33. JsonNode toSend;
  34. toSend["type"].String() = "sendChatMessage";
  35. toSend["messageText"].String() = messageText;
  36. CSH->getGlobalLobby().sendMessage(toSend);
  37. widget->getMessageInput()->setText("");
  38. }
  39. void GlobalLobbyWindow::doCreateGameRoom()
  40. {
  41. GH.windows().createAndPushWindow<GlobalLobbyServerSetup>();
  42. // TODO:
  43. // start local server and supply our UUID / client credentials to it
  44. // server logs into lobby ( uuid = client, mode = server ). This creates 'room' in mode 'empty'
  45. // server starts accepting connections from players (including host)
  46. // client connects to local server
  47. // client sends createGameRoom query to lobby with own / server UUID and mode 'direct' (non-proxy)
  48. // client requests to change room status to private or public
  49. }
  50. void GlobalLobbyWindow::onGameChatMessage(const std::string & sender, const std::string & message, const std::string & when)
  51. {
  52. MetaString chatMessageFormatted;
  53. chatMessageFormatted.appendRawString("[%s] {%s}: %s\n");
  54. chatMessageFormatted.replaceRawString(when);
  55. chatMessageFormatted.replaceRawString(sender);
  56. chatMessageFormatted.replaceRawString(message);
  57. chatHistory += chatMessageFormatted.toString();
  58. widget->getGameChat()->setText(chatHistory);
  59. }