GlobalLobbyAddChannelWindow.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * GlobalLobbyAddChannelWindow.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 "GlobalLobbyAddChannelWindow.h"
  12. #include "GlobalLobbyClient.h"
  13. #include "../CServerHandler.h"
  14. #include "../GameEngine.h"
  15. #include "../GameInstance.h"
  16. #include "../gui/Shortcut.h"
  17. #include "../gui/WindowHandler.h"
  18. #include "../widgets/Buttons.h"
  19. #include "../widgets/GraphicalPrimitiveCanvas.h"
  20. #include "../widgets/Images.h"
  21. #include "../widgets/ObjectLists.h"
  22. #include "../widgets/TextControls.h"
  23. #include "../../lib/texts/MetaString.h"
  24. #include "../../lib/texts/Languages.h"
  25. GlobalLobbyAddChannelWindowCard::GlobalLobbyAddChannelWindowCard(const std::string & languageID)
  26. : languageID(languageID)
  27. {
  28. pos.w = 200;
  29. pos.h = 40;
  30. addUsedEvents(LCLICK);
  31. OBJECT_CONSTRUCTION;
  32. const auto & language = Languages::getLanguageOptions(languageID);
  33. backgroundOverlay = std::make_shared<TransparentFilledRectangle>(Rect(0, 0, pos.w, pos.h), ColorRGBA(0, 0, 0, 128), ColorRGBA(64, 64, 64, 64), 1);
  34. labelNameNative = std::make_shared<CLabel>(5, 10, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::WHITE, language.nameNative);
  35. if (language.nameNative != language.nameEnglish)
  36. labelNameTranslated = std::make_shared<CLabel>(5, 30, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::WHITE, language.nameEnglish);
  37. }
  38. void GlobalLobbyAddChannelWindowCard::clickPressed(const Point & cursorPosition)
  39. {
  40. GAME->server().getGlobalLobby().addChannel(languageID);
  41. ENGINE->windows().popWindows(1);
  42. }
  43. GlobalLobbyAddChannelWindow::GlobalLobbyAddChannelWindow()
  44. : CWindowObject(BORDERED)
  45. {
  46. OBJECT_CONSTRUCTION;
  47. pos.w = 236;
  48. pos.h = 420;
  49. filledBackground = std::make_shared<FilledTexturePlayerColored>(Rect(0, 0, pos.w, pos.h));
  50. filledBackground->setPlayerColor(PlayerColor(1));
  51. labelTitle = std::make_shared<CLabel>(
  52. pos.w / 2, 20, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, MetaString::createFromTextID("vcmi.lobby.channel.add").toString()
  53. );
  54. const auto & allLanguages = Languages::getLanguageList();
  55. std::vector<std::string> newLanguages;
  56. for (const auto & language : allLanguages)
  57. if (!vstd::contains(GAME->server().getGlobalLobby().getActiveChannels(), language.identifier))
  58. newLanguages.push_back(language.identifier);
  59. const auto & createChannelCardCallback = [newLanguages](size_t index) -> std::shared_ptr<CIntObject>
  60. {
  61. if(index < newLanguages.size())
  62. return std::make_shared<GlobalLobbyAddChannelWindowCard>(newLanguages[index]);
  63. return std::make_shared<CIntObject>();
  64. };
  65. listBackground = std::make_shared<TransparentFilledRectangle>(Rect(8, 48, 220, 324), ColorRGBA(0, 0, 0, 64), ColorRGBA(64, 80, 128, 255), 1);
  66. languageList = std::make_shared<CListBox>(createChannelCardCallback, Point(10, 50), Point(0, 40), 8, newLanguages.size(), 0, 1 | 4, Rect(200, 0, 320, 320));
  67. languageList->setRedrawParent(true);
  68. buttonClose = std::make_shared<CButton>(Point(86, 384), AnimationPath::builtin("MuBcanc"), CButton::tooltip(), [this]() { close(); }, EShortcut::GLOBAL_RETURN );
  69. center();
  70. }