GlobalLobbyInviteWindow.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * GlobalLobbyInviteWindow.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 "GlobalLobbyInviteWindow.h"
  12. #include "GlobalLobbyClient.h"
  13. #include "../CServerHandler.h"
  14. #include "../gui/CGuiHandler.h"
  15. #include "../widgets/Buttons.h"
  16. #include "../widgets/GraphicalPrimitiveCanvas.h"
  17. #include "../widgets/Images.h"
  18. #include "../widgets/ObjectLists.h"
  19. #include "../widgets/TextControls.h"
  20. #include "../../lib/MetaString.h"
  21. #include "../../lib/json/JsonNode.h"
  22. GlobalLobbyInviteAccountCard::GlobalLobbyInviteAccountCard(const GlobalLobbyAccount & accountDescription)
  23. : accountID(accountDescription.accountID)
  24. {
  25. pos.w = 200;
  26. pos.h = 40;
  27. addUsedEvents(LCLICK);
  28. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  29. backgroundOverlay = std::make_shared<TransparentFilledRectangle>(Rect(0, 0, pos.w, pos.h), ColorRGBA(0, 0, 0, 128), ColorRGBA(64, 64, 64, 64), 1);
  30. labelName = std::make_shared<CLabel>(5, 10, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::WHITE, accountDescription.displayName);
  31. labelStatus = std::make_shared<CLabel>(5, 30, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::YELLOW, accountDescription.status);
  32. }
  33. void GlobalLobbyInviteAccountCard::clickPressed(const Point & cursorPosition)
  34. {
  35. JsonNode message;
  36. message["type"].String() = "sendInvite";
  37. message["accountID"].String() = accountID;
  38. CSH->getGlobalLobby().sendMessage(message);
  39. }
  40. GlobalLobbyInviteWindow::GlobalLobbyInviteWindow()
  41. : CWindowObject(BORDERED)
  42. {
  43. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  44. pos.w = 236;
  45. pos.h = 400;
  46. filledBackground = std::make_shared<FilledTexturePlayerColored>(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w, pos.h));
  47. filledBackground->playerColored(PlayerColor(1));
  48. labelTitle = std::make_shared<CLabel>(
  49. pos.w / 2, 20, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, MetaString::createFromTextID("vcmi.lobby.invite.header").toString()
  50. );
  51. const auto & createAccountCardCallback = [](size_t index) -> std::shared_ptr<CIntObject>
  52. {
  53. const auto & accounts = CSH->getGlobalLobby().getActiveAccounts();
  54. if(index < accounts.size())
  55. return std::make_shared<GlobalLobbyInviteAccountCard>(accounts[index]);
  56. return std::make_shared<CIntObject>();
  57. };
  58. listBackground = std::make_shared<TransparentFilledRectangle>(Rect(8, 48, 220, 304), ColorRGBA(0, 0, 0, 64), ColorRGBA(64, 80, 128, 255), 1);
  59. accountList = std::make_shared<CListBox>(createAccountCardCallback, Point(10, 50), Point(0, 40), 8, 0, 0, 1 | 4, Rect(200, 0, 300, 300));
  60. buttonClose = std::make_shared<CButton>(Point(86, 364), AnimationPath::builtin("MuBchck"), CButton::tooltip(), [this]() { close(); } );
  61. center();
  62. }