GlobalLobbyInviteWindow.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. bool thisAccountInvited = false;
  29. const auto & myRoomID = CSH->getGlobalLobby().getCurrentGameRoomID();
  30. if (!myRoomID.empty())
  31. {
  32. const auto & myRoom = CSH->getGlobalLobby().getActiveRoomByName(myRoomID);
  33. for (auto const & invited : myRoom.invited)
  34. {
  35. if (invited.accountID == accountID)
  36. {
  37. thisAccountInvited = true;
  38. break;
  39. }
  40. }
  41. }
  42. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  43. if (thisAccountInvited)
  44. backgroundOverlay = std::make_shared<TransparentFilledRectangle>(Rect(0, 0, pos.w, pos.h), ColorRGBA(0, 0, 0, 128), Colors::WHITE, 1);
  45. else
  46. backgroundOverlay = std::make_shared<TransparentFilledRectangle>(Rect(0, 0, pos.w, pos.h), ColorRGBA(0, 0, 0, 128), ColorRGBA(64, 64, 64, 64), 1);
  47. labelName = std::make_shared<CLabel>(5, 10, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::WHITE, accountDescription.displayName);
  48. if (thisAccountInvited)
  49. labelStatus = std::make_shared<CLabel>(5, 30, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::YELLOW, MetaString::createFromTextID("vcmi.lobby.room.state.invited").toString());
  50. else
  51. labelStatus = std::make_shared<CLabel>(5, 30, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::YELLOW, accountDescription.status);
  52. }
  53. void GlobalLobbyInviteAccountCard::clickPressed(const Point & cursorPosition)
  54. {
  55. JsonNode message;
  56. message["type"].String() = "sendInvite";
  57. message["accountID"].String() = accountID;
  58. CSH->getGlobalLobby().sendMessage(message);
  59. }
  60. GlobalLobbyInviteWindow::GlobalLobbyInviteWindow()
  61. : CWindowObject(BORDERED)
  62. {
  63. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  64. pos.w = 236;
  65. pos.h = 400;
  66. filledBackground = std::make_shared<FilledTexturePlayerColored>(ImagePath::builtin("DiBoxBck"), Rect(0, 0, pos.w, pos.h));
  67. filledBackground->playerColored(PlayerColor(1));
  68. labelTitle = std::make_shared<CLabel>(
  69. pos.w / 2, 20, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, MetaString::createFromTextID("vcmi.lobby.invite.header").toString()
  70. );
  71. const auto & createAccountCardCallback = [](size_t index) -> std::shared_ptr<CIntObject>
  72. {
  73. const auto & accounts = CSH->getGlobalLobby().getActiveAccounts();
  74. if(index < accounts.size())
  75. return std::make_shared<GlobalLobbyInviteAccountCard>(accounts[index]);
  76. return std::make_shared<CIntObject>();
  77. };
  78. listBackground = std::make_shared<TransparentFilledRectangle>(Rect(8, 48, 220, 304), ColorRGBA(0, 0, 0, 64), ColorRGBA(64, 80, 128, 255), 1);
  79. accountList = std::make_shared<CListBox>(createAccountCardCallback, Point(10, 50), Point(0, 40), 8, 0, 0, 1 | 4, Rect(200, 0, 300, 300));
  80. buttonClose = std::make_shared<CButton>(Point(86, 364), AnimationPath::builtin("MuBchck"), CButton::tooltip(), [this]() { close(); } );
  81. center();
  82. }