GlobalLobbyAddChannelWindow.cpp 3.1 KB

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