CComponent.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. /*
  2. * CComponent.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 "CComponent.h"
  12. #include "Images.h"
  13. #include <vcmi/spells/Service.h>
  14. #include <vcmi/spells/Spell.h>
  15. #include "../gui/CGuiHandler.h"
  16. #include "../gui/CursorHandler.h"
  17. #include "../gui/TextAlignment.h"
  18. #include "../gui/Shortcut.h"
  19. #include "../render/Canvas.h"
  20. #include "../render/IFont.h"
  21. #include "../render/Graphics.h"
  22. #include "../windows/CMessage.h"
  23. #include "../windows/InfoWindows.h"
  24. #include "../widgets/TextControls.h"
  25. #include "../CGameInfo.h"
  26. #include "../../lib/ArtifactUtils.h"
  27. #include "../../lib/CHeroHandler.h"
  28. #include "../../lib/entities/building/CBuilding.h"
  29. #include "../../lib/entities/faction/CFaction.h"
  30. #include "../../lib/entities/faction/CTown.h"
  31. #include "../../lib/entities/faction/CTownHandler.h"
  32. #include "../../lib/networkPacks/Component.h"
  33. #include "../../lib/spells/CSpellHandler.h"
  34. #include "../../lib/CCreatureHandler.h"
  35. #include "../../lib/CSkillHandler.h"
  36. #include "../../lib/texts/CGeneralTextHandler.h"
  37. #include "../../lib/CArtHandler.h"
  38. #include "../../lib/CArtifactInstance.h"
  39. CComponent::CComponent(ComponentType Type, ComponentSubType Subtype, std::optional<int32_t> Val, ESize imageSize, EFonts font)
  40. {
  41. init(Type, Subtype, Val, imageSize, font, "");
  42. }
  43. CComponent::CComponent(ComponentType Type, ComponentSubType Subtype, const std::string & Val, ESize imageSize, EFonts font)
  44. {
  45. init(Type, Subtype, std::nullopt, imageSize, font, Val);
  46. }
  47. CComponent::CComponent(const Component & c, ESize imageSize, EFonts font)
  48. {
  49. init(c.type, c.subType, c.value, imageSize, font, "");
  50. }
  51. void CComponent::init(ComponentType Type, ComponentSubType Subtype, std::optional<int32_t> Val, ESize imageSize, EFonts fnt, const std::string & ValText)
  52. {
  53. OBJECT_CONSTRUCTION;
  54. addUsedEvents(SHOW_POPUP);
  55. data.type = Type;
  56. data.subType = Subtype;
  57. data.value = Val;
  58. customSubtitle = ValText;
  59. size = imageSize;
  60. font = fnt;
  61. assert(size < sizeInvalid);
  62. setSurface(getFileName()[size], (int)getIndex());
  63. pos.w = image->pos.w;
  64. pos.h = image->pos.h;
  65. if (imageSize < small)
  66. font = FONT_TINY; //for tiny images - tiny font
  67. pos.h += 4; //distance between text and image
  68. // WARNING: too low values will lead to bad line-breaks in CPlayerOptionTooltipBox - check right-click on starting town in pregame
  69. int max = 80;
  70. if (size < large)
  71. max = 72;
  72. if (size < medium)
  73. max = 60;
  74. if (size < small)
  75. max = 55;
  76. if(Type == ComponentType::RESOURCE && !ValText.empty())
  77. max = 80;
  78. std::vector<std::string> textLines = CMessage::breakText(getSubtitle(), std::max<int>(max, pos.w), font);
  79. for(auto & line : textLines)
  80. {
  81. int height = static_cast<int>(graphics->fonts[font]->getLineHeight());
  82. auto label = std::make_shared<CLabel>(pos.w/2, pos.h + height/2, font, ETextAlignment::CENTER, Colors::WHITE, line);
  83. pos.h += height;
  84. if(label->pos.w > pos.w)
  85. {
  86. pos.x -= (label->pos.w - pos.w)/2;
  87. pos.w = label->pos.w;
  88. }
  89. lines.push_back(label);
  90. }
  91. }
  92. std::vector<AnimationPath> CComponent::getFileName() const
  93. {
  94. static const std::array<std::string, 4> primSkillsArr = {"PSKIL32", "PSKIL32", "PSKIL42", "PSKILL"};
  95. static const std::array<std::string, 4> secSkillsArr = {"SECSK32", "SECSK32", "SECSKILL", "SECSK82"};
  96. static const std::array<std::string, 4> resourceArr = {"SMALRES", "RESOURCE", "RESOURCE", "RESOUR82"};
  97. static const std::array<std::string, 4> creatureArr = {"CPRSMALL", "CPRSMALL", "CPRSMALL", "TWCRPORT"};
  98. static const std::array<std::string, 4> artifactArr = {"Artifact", "Artifact", "Artifact", "Artifact"};
  99. static const std::array<std::string, 4> spellsArr = {"SpellInt", "SpellInt", "SpellInt", "SPELLSCR"};
  100. static const std::array<std::string, 4> moraleArr = {"IMRL22", "IMRL30", "IMRL42", "imrl82"};
  101. static const std::array<std::string, 4> luckArr = {"ILCK22", "ILCK30", "ILCK42", "ilck82"};
  102. static const std::array<std::string, 4> heroArr = {"PortraitsSmall", "PortraitsSmall", "PortraitsSmall", "PortraitsLarge"};
  103. static const std::array<std::string, 4> flagArr = {"CREST58", "CREST58", "CREST58", "CREST58"};
  104. auto gen = [](const std::array<std::string, 4> & arr) -> std::vector<AnimationPath>
  105. {
  106. return { AnimationPath::builtin(arr[0]), AnimationPath::builtin(arr[1]), AnimationPath::builtin(arr[2]), AnimationPath::builtin(arr[3]) };
  107. };
  108. switch(data.type)
  109. {
  110. case ComponentType::PRIM_SKILL:
  111. case ComponentType::EXPERIENCE:
  112. case ComponentType::MANA:
  113. case ComponentType::LEVEL:
  114. return gen(primSkillsArr);
  115. case ComponentType::NONE:
  116. case ComponentType::SEC_SKILL:
  117. return gen(secSkillsArr);
  118. case ComponentType::RESOURCE:
  119. case ComponentType::RESOURCE_PER_DAY:
  120. return gen(resourceArr);
  121. case ComponentType::CREATURE:
  122. return gen(creatureArr);
  123. case ComponentType::ARTIFACT:
  124. return gen(artifactArr);
  125. case ComponentType::SPELL_SCROLL:
  126. case ComponentType::SPELL:
  127. return gen(spellsArr);
  128. case ComponentType::MORALE:
  129. return gen(moraleArr);
  130. case ComponentType::LUCK:
  131. return gen(luckArr);
  132. case ComponentType::BUILDING:
  133. return std::vector<AnimationPath>(4, (*CGI->townh)[data.subType.as<BuildingTypeUniqueID>().getFaction()]->town->clientInfo.buildingsIcons);
  134. case ComponentType::HERO_PORTRAIT:
  135. return gen(heroArr);
  136. case ComponentType::FLAG:
  137. return gen(flagArr);
  138. default:
  139. assert(0);
  140. return {};
  141. }
  142. }
  143. size_t CComponent::getIndex() const
  144. {
  145. switch(data.type)
  146. {
  147. case ComponentType::NONE:
  148. return 0;
  149. case ComponentType::PRIM_SKILL:
  150. return data.subType.getNum();
  151. case ComponentType::EXPERIENCE:
  152. case ComponentType::LEVEL:
  153. return 4; // for whatever reason, in H3 experience icon is located in primary skills icons
  154. case ComponentType::MANA:
  155. return 5; // for whatever reason, in H3 mana points icon is located in primary skills icons
  156. case ComponentType::SEC_SKILL:
  157. return data.subType.getNum() * 3 + 3 + data.value.value_or(0) - 1;
  158. case ComponentType::RESOURCE:
  159. case ComponentType::RESOURCE_PER_DAY:
  160. return data.subType.getNum();
  161. case ComponentType::CREATURE:
  162. return CGI->creatures()->getById(data.subType.as<CreatureID>())->getIconIndex();
  163. case ComponentType::ARTIFACT:
  164. return CGI->artifacts()->getById(data.subType.as<ArtifactID>())->getIconIndex();
  165. case ComponentType::SPELL_SCROLL:
  166. case ComponentType::SPELL:
  167. return (size < large) ? data.subType.getNum() + 1 : data.subType.getNum();
  168. case ComponentType::MORALE:
  169. return data.value.value_or(0) + 3;
  170. case ComponentType::LUCK:
  171. return data.value.value_or(0) + 3;
  172. case ComponentType::BUILDING:
  173. return data.subType.as<BuildingTypeUniqueID>().getBuilding();
  174. case ComponentType::HERO_PORTRAIT:
  175. return CGI->heroTypes()->getById(data.subType.as<HeroTypeID>())->getIconIndex();
  176. case ComponentType::FLAG:
  177. return data.subType.getNum();
  178. default:
  179. assert(0);
  180. return 0;
  181. }
  182. }
  183. std::string CComponent::getDescription() const
  184. {
  185. switch(data.type)
  186. {
  187. case ComponentType::PRIM_SKILL:
  188. return CGI->generaltexth->arraytxt[2+data.subType.getNum()];
  189. case ComponentType::EXPERIENCE:
  190. case ComponentType::LEVEL:
  191. return CGI->generaltexth->allTexts[241];
  192. case ComponentType::MANA:
  193. return CGI->generaltexth->allTexts[149];
  194. case ComponentType::SEC_SKILL:
  195. return CGI->skillh->getByIndex(data.subType.getNum())->getDescriptionTranslated(data.value.value_or(0));
  196. case ComponentType::RESOURCE:
  197. case ComponentType::RESOURCE_PER_DAY:
  198. return CGI->generaltexth->allTexts[242];
  199. case ComponentType::NONE:
  200. case ComponentType::CREATURE:
  201. return "";
  202. case ComponentType::ARTIFACT:
  203. return CGI->artifacts()->getById(data.subType.as<ArtifactID>())->getDescriptionTranslated();
  204. case ComponentType::SPELL_SCROLL:
  205. {
  206. auto description = ArtifactID(ArtifactID::SPELL_SCROLL).toEntity(CGI)->getDescriptionTranslated();
  207. ArtifactUtils::insertScrrollSpellName(description, data.subType.as<SpellID>());
  208. return description;
  209. }
  210. case ComponentType::SPELL:
  211. return CGI->spells()->getById(data.subType.as<SpellID>())->getDescriptionTranslated(data.value.value_or(0));
  212. case ComponentType::MORALE:
  213. return CGI->generaltexth->heroscrn[ 4 - (data.value.value_or(0)>0) + (data.value.value_or(0)<0)];
  214. case ComponentType::LUCK:
  215. return CGI->generaltexth->heroscrn[ 7 - (data.value.value_or(0)>0) + (data.value.value_or(0)<0)];
  216. case ComponentType::BUILDING:
  217. {
  218. auto index = data.subType.as<BuildingTypeUniqueID>();
  219. return (*CGI->townh)[index.getFaction()]->town->buildings[index.getBuilding()]->getDescriptionTranslated();
  220. }
  221. case ComponentType::HERO_PORTRAIT:
  222. return "";
  223. case ComponentType::FLAG:
  224. return "";
  225. default:
  226. assert(0);
  227. return "";
  228. }
  229. }
  230. std::string CComponent::getSubtitle() const
  231. {
  232. if (!customSubtitle.empty())
  233. return customSubtitle;
  234. switch(data.type)
  235. {
  236. case ComponentType::PRIM_SKILL:
  237. if (data.value)
  238. return boost::str(boost::format("%+d %s") % data.value.value_or(0) % CGI->generaltexth->primarySkillNames[data.subType.getNum()]);
  239. else
  240. return CGI->generaltexth->primarySkillNames[data.subType.getNum()];
  241. case ComponentType::EXPERIENCE:
  242. return std::to_string(data.value.value_or(0));
  243. case ComponentType::LEVEL:
  244. {
  245. std::string level = CGI->generaltexth->allTexts[442];
  246. boost::replace_first(level, "1", std::to_string(data.value.value_or(0)));
  247. return level;
  248. }
  249. case ComponentType::MANA:
  250. return boost::str(boost::format("%+d %s") % data.value.value_or(0) % CGI->generaltexth->allTexts[387]);
  251. case ComponentType::SEC_SKILL:
  252. return CGI->generaltexth->levels[data.value.value_or(0)-1] + "\n" + CGI->skillh->getById(data.subType.as<SecondarySkill>())->getNameTranslated();
  253. case ComponentType::RESOURCE:
  254. return std::to_string(data.value.value_or(0));
  255. case ComponentType::RESOURCE_PER_DAY:
  256. return boost::str(boost::format(CGI->generaltexth->allTexts[3]) % data.value.value_or(0));
  257. case ComponentType::CREATURE:
  258. {
  259. auto creature = CGI->creh->getById(data.subType.as<CreatureID>());
  260. if(data.value)
  261. return std::to_string(*data.value) + " " + (*data.value > 1 ? creature->getNamePluralTranslated() : creature->getNameSingularTranslated());
  262. else
  263. return creature->getNamePluralTranslated();
  264. }
  265. case ComponentType::ARTIFACT:
  266. return CGI->artifacts()->getById(data.subType.as<ArtifactID>())->getNameTranslated();
  267. case ComponentType::SPELL_SCROLL:
  268. case ComponentType::SPELL:
  269. if (data.value < 0)
  270. return "{#A9A9A9|" + CGI->spells()->getById(data.subType.as<SpellID>())->getNameTranslated() + "}";
  271. else
  272. return CGI->spells()->getById(data.subType.as<SpellID>())->getNameTranslated();
  273. case ComponentType::NONE:
  274. case ComponentType::MORALE:
  275. case ComponentType::LUCK:
  276. case ComponentType::HERO_PORTRAIT:
  277. return "";
  278. case ComponentType::BUILDING:
  279. {
  280. auto index = data.subType.as<BuildingTypeUniqueID>();
  281. auto building = (*CGI->townh)[index.getFaction()]->town->buildings[index.getBuilding()];
  282. if(!building)
  283. {
  284. logGlobal->error("Town of faction %s has no building #%d", (*CGI->townh)[index.getFaction()]->town->faction->getNameTranslated(), index.getBuilding().getNum());
  285. return (boost::format("Missing building #%d") % index.getBuilding().getNum()).str();
  286. }
  287. return building->getNameTranslated();
  288. }
  289. case ComponentType::FLAG:
  290. return CGI->generaltexth->capColors[data.subType.as<PlayerColor>().getNum()];
  291. default:
  292. assert(0);
  293. return "";
  294. }
  295. }
  296. void CComponent::setSurface(const AnimationPath & defName, int imgPos)
  297. {
  298. OBJECT_CONSTRUCTION;
  299. image = std::make_shared<CAnimImage>(defName, imgPos);
  300. }
  301. void CComponent::showPopupWindow(const Point & cursorPosition)
  302. {
  303. if(!getDescription().empty())
  304. CRClickPopup::createAndPush(getDescription());
  305. }
  306. void CSelectableComponent::clickPressed(const Point & cursorPosition)
  307. {
  308. if(onSelect)
  309. onSelect();
  310. }
  311. void CSelectableComponent::clickDouble(const Point & cursorPosition)
  312. {
  313. if (!selected)
  314. {
  315. clickPressed(cursorPosition);
  316. }
  317. else
  318. {
  319. if (onChoose)
  320. onChoose();
  321. }
  322. }
  323. void CSelectableComponent::init()
  324. {
  325. selected = false;
  326. }
  327. CSelectableComponent::CSelectableComponent(const Component &c, std::function<void()> OnSelect):
  328. CComponent(c),onSelect(OnSelect)
  329. {
  330. setRedrawParent(true);
  331. addUsedEvents(LCLICK | DOUBLECLICK | KEYBOARD);
  332. init();
  333. }
  334. CSelectableComponent::CSelectableComponent(ComponentType Type, ComponentSubType Sub, int Val, ESize imageSize, std::function<void()> OnSelect):
  335. CComponent(Type,Sub,Val, imageSize),onSelect(OnSelect)
  336. {
  337. setRedrawParent(true);
  338. addUsedEvents(LCLICK | DOUBLECLICK | KEYBOARD);
  339. init();
  340. }
  341. void CSelectableComponent::select(bool on)
  342. {
  343. if(on != selected)
  344. {
  345. selected = on;
  346. redraw();
  347. }
  348. }
  349. void CSelectableComponent::showAll(Canvas & to)
  350. {
  351. CComponent::showAll(to);
  352. if(selected)
  353. {
  354. to.drawBorder(Rect::createAround(image->pos, 1), Colors::BRIGHT_YELLOW);
  355. }
  356. }
  357. void CComponentBox::selectionChanged(std::shared_ptr<CSelectableComponent> newSelection)
  358. {
  359. if (newSelection == selected)
  360. return;
  361. if (selected)
  362. selected->select(false);
  363. selected = newSelection;
  364. if (onSelect)
  365. onSelect(selectedIndex());
  366. if (selected)
  367. selected->select(true);
  368. }
  369. int CComponentBox::selectedIndex()
  370. {
  371. if (selected)
  372. return static_cast<int>(std::find(components.begin(), components.end(), selected) - components.begin());
  373. return -1;
  374. }
  375. Point CComponentBox::getOrTextPos(CComponent *left, CComponent *right)
  376. {
  377. int leftSubtitle = ( left->pos.w - left->image->pos.w) / 2;
  378. int rightSubtitle = (right->pos.w - right->image->pos.w) / 2;
  379. int fullDistance = getDistance(left, right) + leftSubtitle + rightSubtitle;
  380. return Point(fullDistance/2 - leftSubtitle, (left->image->pos.h + right->image->pos.h) / 4);
  381. }
  382. int CComponentBox::getDistance(CComponent *left, CComponent *right)
  383. {
  384. int leftSubtitle = ( left->pos.w - left->image->pos.w) / 2;
  385. int rightSubtitle = (right->pos.w - right->image->pos.w) / 2;
  386. int subtitlesOffset = leftSubtitle + rightSubtitle;
  387. return std::max(betweenSubtitlesMin, betweenImagesMin - subtitlesOffset);
  388. }
  389. void CComponentBox::placeComponents(bool selectable)
  390. {
  391. OBJECT_CONSTRUCTION;
  392. if (components.empty())
  393. return;
  394. //prepare components
  395. for(auto & comp : components)
  396. {
  397. addChild(comp.get());
  398. comp->moveTo(Point(pos.x, pos.y));
  399. }
  400. struct RowData
  401. {
  402. size_t comps;
  403. int width;
  404. int height;
  405. RowData (size_t Comps, int Width, int Height):
  406. comps(Comps), width (Width), height (Height){};
  407. };
  408. std::vector<RowData> rows;
  409. rows.push_back (RowData (0,0,0));
  410. //split components in rows
  411. std::shared_ptr<CComponent> prevComp;
  412. for(std::shared_ptr<CComponent> comp : components)
  413. {
  414. //make sure that components are smaller than our width
  415. //assert(pos.w == 0 || pos.w < comp->pos.w);
  416. const int distance = prevComp ? getDistance(prevComp.get(), comp.get()) : 0;
  417. //start next row
  418. if ((pos.w != 0 && rows.back().width + comp->pos.w + distance > pos.w) // row is full
  419. || rows.back().comps >= componentsInRow)
  420. {
  421. prevComp = nullptr;
  422. rows.push_back (RowData (0,0,0));
  423. }
  424. if (prevComp)
  425. rows.back().width += distance;
  426. rows.back().comps++;
  427. rows.back().width += comp->pos.w;
  428. vstd::amax(rows.back().height, comp->pos.h);
  429. prevComp = comp;
  430. }
  431. if (pos.w == 0)
  432. {
  433. for(auto & row : rows)
  434. vstd::amax(pos.w, row.width);
  435. }
  436. int height = ((int)rows.size() - 1) * betweenRows;
  437. for(auto & row : rows)
  438. height += row.height;
  439. //assert(pos.h == 0 || pos.h < height);
  440. if (pos.h == 0)
  441. pos.h = height;
  442. auto iter = components.begin();
  443. int currentY = (pos.h - height) / 2;
  444. //move components to their positions
  445. for (auto & rows_row : rows)
  446. {
  447. // amount of free space we may add on each side of every component
  448. int freeSpace = (pos.w - rows_row.width) / ((int)rows_row.comps * 2);
  449. prevComp = nullptr;
  450. int currentX = 0;
  451. for (size_t col = 0; col < rows_row.comps; col++)
  452. {
  453. currentX += freeSpace;
  454. if (prevComp)
  455. {
  456. if (selectable)
  457. {
  458. Point orPos = Point(currentX - freeSpace, currentY) + getOrTextPos(prevComp.get(), iter->get());
  459. orLabels.push_back(std::make_shared<CLabel>(orPos.x, orPos.y, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->allTexts[4]));
  460. }
  461. currentX += getDistance(prevComp.get(), iter->get());
  462. }
  463. (*iter)->moveBy(Point(currentX, currentY));
  464. currentX += (*iter)->pos.w;
  465. currentX += freeSpace;
  466. prevComp = *(iter++);
  467. }
  468. currentY += rows_row.height + betweenRows;
  469. }
  470. }
  471. CComponentBox::CComponentBox(std::vector<std::shared_ptr<CComponent>> _components, Rect position):
  472. CComponentBox(_components, position, defaultBetweenImagesMin, defaultBetweenSubtitlesMin, defaultBetweenRows, defaultComponentsInRow)
  473. {
  474. }
  475. CComponentBox::CComponentBox(std::vector<std::shared_ptr<CComponent>> _components, Rect position, int betweenImagesMin, int betweenSubtitlesMin, int betweenRows, int componentsInRow):
  476. components(_components),
  477. betweenImagesMin(betweenImagesMin),
  478. betweenSubtitlesMin(betweenSubtitlesMin),
  479. betweenRows(betweenRows),
  480. componentsInRow(componentsInRow)
  481. {
  482. setRedrawParent(true);
  483. pos = position + pos.topLeft();
  484. placeComponents(false);
  485. }
  486. CComponentBox::CComponentBox(std::vector<std::shared_ptr<CSelectableComponent>> _components, Rect position, std::function<void(int newID)> _onSelect):
  487. CComponentBox(_components, position, _onSelect, defaultBetweenImagesMin, defaultBetweenSubtitlesMin, defaultBetweenRows, defaultComponentsInRow)
  488. {
  489. }
  490. CComponentBox::CComponentBox(std::vector<std::shared_ptr<CSelectableComponent>> _components, Rect position, std::function<void(int newID)> _onSelect, int betweenImagesMin, int betweenSubtitlesMin, int betweenRows, int componentsInRow):
  491. components(_components.begin(), _components.end()),
  492. onSelect(_onSelect),
  493. betweenImagesMin(betweenImagesMin),
  494. betweenSubtitlesMin(betweenSubtitlesMin),
  495. betweenRows(betweenRows),
  496. componentsInRow(componentsInRow)
  497. {
  498. setRedrawParent(true);
  499. pos = position + pos.topLeft();
  500. placeComponents(true);
  501. assert(!components.empty());
  502. auto key = EShortcut::SELECT_INDEX_1;
  503. for(auto & comp : _components)
  504. {
  505. comp->onSelect = std::bind(&CComponentBox::selectionChanged, this, comp);
  506. comp->assignedKey = key;
  507. key = vstd::next(key, 1);
  508. }
  509. selectionChanged(_components.front());
  510. }