RandomMapTab.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. /*
  2. * RandomMapTab.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 "RandomMapTab.h"
  12. #include "CSelectionBase.h"
  13. #include "CLobbyScreen.h"
  14. #include "SelectionTab.h"
  15. #include "../CGameInfo.h"
  16. #include "../CServerHandler.h"
  17. #include "../gui/CGuiHandler.h"
  18. #include "../gui/MouseButton.h"
  19. #include "../gui/WindowHandler.h"
  20. #include "../widgets/CComponent.h"
  21. #include "../widgets/ComboBox.h"
  22. #include "../widgets/Buttons.h"
  23. #include "../widgets/MiscWidgets.h"
  24. #include "../widgets/ObjectLists.h"
  25. #include "../widgets/Slider.h"
  26. #include "../widgets/TextControls.h"
  27. #include "../windows/GUIClasses.h"
  28. #include "../windows/InfoWindows.h"
  29. #include "../../lib/CGeneralTextHandler.h"
  30. #include "../../lib/mapping/CMapInfo.h"
  31. #include "../../lib/mapping/CMapHeader.h"
  32. #include "../../lib/mapping/MapFormat.h"
  33. #include "../../lib/rmg/CMapGenOptions.h"
  34. #include "../../lib/rmg/CRmgTemplateStorage.h"
  35. #include "../../lib/filesystem/Filesystem.h"
  36. #include "../../lib/RoadHandler.h"
  37. RandomMapTab::RandomMapTab():
  38. InterfaceObjectConfigurable()
  39. {
  40. recActions = 0;
  41. mapGenOptions = std::make_shared<CMapGenOptions>();
  42. addCallback("toggleMapSize", [&](int btnId)
  43. {
  44. auto mapSizeVal = getPossibleMapSizes();
  45. mapGenOptions->setWidth(mapSizeVal[btnId]);
  46. mapGenOptions->setHeight(mapSizeVal[btnId]);
  47. if(mapGenOptions->getMapTemplate())
  48. if(!mapGenOptions->getMapTemplate()->matchesSize(int3{mapGenOptions->getWidth(), mapGenOptions->getHeight(), 1 + mapGenOptions->getHasTwoLevels()}))
  49. setTemplate(nullptr);
  50. updateMapInfoByHost();
  51. });
  52. addCallback("toggleTwoLevels", [&](bool on)
  53. {
  54. mapGenOptions->setHasTwoLevels(on);
  55. if(mapGenOptions->getMapTemplate())
  56. if(!mapGenOptions->getMapTemplate()->matchesSize(int3{mapGenOptions->getWidth(), mapGenOptions->getHeight(), 1 + mapGenOptions->getHasTwoLevels()}))
  57. setTemplate(nullptr);
  58. updateMapInfoByHost();
  59. });
  60. addCallback("setPlayersCount", [&](int btnId)
  61. {
  62. mapGenOptions->setHumanOrCpuPlayerCount(btnId);
  63. setMapGenOptions(mapGenOptions);
  64. updateMapInfoByHost();
  65. });
  66. addCallback("setTeamsCount", [&](int btnId)
  67. {
  68. mapGenOptions->setTeamCount(btnId);
  69. updateMapInfoByHost();
  70. });
  71. addCallback("setCompOnlyPlayers", [&](int btnId)
  72. {
  73. mapGenOptions->setCompOnlyPlayerCount(btnId);
  74. setMapGenOptions(mapGenOptions);
  75. updateMapInfoByHost();
  76. });
  77. addCallback("setCompOnlyTeams", [&](int btnId)
  78. {
  79. mapGenOptions->setCompOnlyTeamCount(btnId);
  80. updateMapInfoByHost();
  81. });
  82. addCallback("setWaterContent", [&](int btnId)
  83. {
  84. mapGenOptions->setWaterContent(static_cast<EWaterContent::EWaterContent>(btnId));
  85. updateMapInfoByHost();
  86. });
  87. addCallback("setMonsterStrength", [&](int btnId)
  88. {
  89. if(btnId < 0)
  90. mapGenOptions->setMonsterStrength(EMonsterStrength::RANDOM);
  91. else
  92. mapGenOptions->setMonsterStrength(static_cast<EMonsterStrength::EMonsterStrength>(btnId)); //value 2 to 4
  93. updateMapInfoByHost();
  94. });
  95. //new callbacks available only from mod
  96. addCallback("teamAlignments", [&](int)
  97. {
  98. GH.windows().createAndPushWindow<TeamAlignmentsWidget>(*this);
  99. });
  100. for(auto road : VLC->roadTypeHandler->objects)
  101. {
  102. std::string cbRoadType = "selectRoad_" + road->getJsonKey();
  103. addCallback(cbRoadType, [&, road](bool on)
  104. {
  105. mapGenOptions->setRoadEnabled(road->getId(), on);
  106. updateMapInfoByHost();
  107. });
  108. }
  109. const JsonNode config(JsonPath::builtin("config/widgets/randomMapTab.json"));
  110. build(config);
  111. if(auto w = widget<CButton>("buttonShowRandomMaps"))
  112. {
  113. w->addCallback([&]()
  114. {
  115. (static_cast<CLobbyScreen *>(parent))->toggleTab((static_cast<CLobbyScreen *>(parent))->tabSel);
  116. (static_cast<CLobbyScreen *>(parent))->tabSel->showRandom = true;
  117. (static_cast<CLobbyScreen *>(parent))->tabSel->filter(0, true);
  118. });
  119. }
  120. //set combo box callbacks
  121. if(auto w = widget<ComboBox>("templateList"))
  122. {
  123. w->onConstructItems = [](std::vector<const void *> & curItems){
  124. auto templates = VLC->tplh->getTemplates();
  125. boost::range::sort(templates, [](const CRmgTemplate * a, const CRmgTemplate * b){
  126. return a->getName() < b->getName();
  127. });
  128. curItems.push_back(nullptr); //default template
  129. for(auto & t : templates)
  130. curItems.push_back(t);
  131. };
  132. w->onSetItem = [&](const void * item){
  133. this->setTemplate(reinterpret_cast<const CRmgTemplate *>(item));
  134. };
  135. w->getItemText = [this](int idx, const void * item){
  136. if(item)
  137. return reinterpret_cast<const CRmgTemplate *>(item)->getName();
  138. if(idx == 0)
  139. return readText(variables["randomTemplate"]);
  140. return std::string("");
  141. };
  142. }
  143. updateMapInfoByHost();
  144. }
  145. void RandomMapTab::updateMapInfoByHost()
  146. {
  147. if(CSH->isGuest())
  148. return;
  149. // Generate header info
  150. mapInfo = std::make_shared<CMapInfo>();
  151. mapInfo->isRandomMap = true;
  152. mapInfo->mapHeader = std::make_unique<CMapHeader>();
  153. mapInfo->mapHeader->version = EMapFormat::VCMI;
  154. mapInfo->mapHeader->name.appendLocalString(EMetaText::GENERAL_TXT, 740);
  155. mapInfo->mapHeader->description.appendLocalString(EMetaText::GENERAL_TXT, 741);
  156. mapInfo->mapHeader->difficulty = 1; // Normal
  157. mapInfo->mapHeader->height = mapGenOptions->getHeight();
  158. mapInfo->mapHeader->width = mapGenOptions->getWidth();
  159. mapInfo->mapHeader->twoLevel = mapGenOptions->getHasTwoLevels();
  160. // Generate player information
  161. int playersToGen = PlayerColor::PLAYER_LIMIT_I;
  162. if(mapGenOptions->getHumanOrCpuPlayerCount() != CMapGenOptions::RANDOM_SIZE)
  163. {
  164. playersToGen = mapGenOptions->getHumanOrCpuPlayerCount();
  165. }
  166. mapInfo->mapHeader->howManyTeams = playersToGen;
  167. //FIXME: Assign all human-controlled colors in first place
  168. //TODO: Where are human / CPU players toggled in player configuration?
  169. //TODO: Get human player count
  170. //std::set<TeamID> occupiedTeams;
  171. for(int i = 0; i < PlayerColor::PLAYER_LIMIT_I; ++i)
  172. {
  173. mapInfo->mapHeader->players[i].canComputerPlay = false;
  174. mapInfo->mapHeader->players[i].canHumanPlay = false;
  175. }
  176. std::vector<PlayerColor> availableColors;
  177. for (ui8 color = 0; color < PlayerColor::PLAYER_LIMIT_I; color++)
  178. {
  179. availableColors.push_back(PlayerColor(color));
  180. }
  181. //First restore known players
  182. for (auto& player : mapGenOptions->getPlayersSettings())
  183. {
  184. PlayerInfo playerInfo;
  185. playerInfo.isFactionRandom = (player.second.getStartingTown() == CMapGenOptions::CPlayerSettings::RANDOM_TOWN);
  186. playerInfo.canComputerPlay = (player.second.getPlayerType() != EPlayerType::HUMAN);
  187. playerInfo.canHumanPlay = (player.second.getPlayerType() != EPlayerType::COMP_ONLY);
  188. auto team = player.second.getTeam();
  189. playerInfo.team = team;
  190. //occupiedTeams.insert(team);
  191. playerInfo.hasMainTown = true;
  192. playerInfo.generateHeroAtMainTown = true;
  193. mapInfo->mapHeader->players[player.first] = playerInfo;
  194. vstd::erase(availableColors, player.first);
  195. }
  196. /*
  197. //Reset teams to default (?)
  198. // TODO: Do not reset teams here, this is handled by CMapGenOptions
  199. for(auto & player : mapInfo->mapHeader->players)
  200. {
  201. for(int i = 0; player.team == TeamID::NO_TEAM; ++i)
  202. {
  203. TeamID team(i);
  204. if(!occupiedTeams.count(team))
  205. {
  206. player.team = team;
  207. occupiedTeams.insert(team);
  208. break; //First assigned team is ok
  209. }
  210. }
  211. }
  212. */
  213. mapInfoChanged(mapInfo, mapGenOptions);
  214. }
  215. // TODO: This method only sets GUI options, doesn't alter any actual configurations done
  216. void RandomMapTab::setMapGenOptions(std::shared_ptr<CMapGenOptions> opts)
  217. {
  218. mapGenOptions = opts;
  219. //Prepare allowed options - add all, then erase the ones above the limit
  220. for(int i = 0; i <= PlayerColor::PLAYER_LIMIT_I; ++i)
  221. {
  222. playerCountAllowed.insert(i);
  223. compCountAllowed.insert(i);
  224. if (i >= 2)
  225. {
  226. playerTeamsAllowed.insert(i);
  227. }
  228. if (i >= 1)
  229. {
  230. compTeamsAllowed.insert(i);
  231. }
  232. }
  233. int minComps = 0;
  234. auto * tmpl = mapGenOptions->getMapTemplate();
  235. if(tmpl)
  236. {
  237. // TODO: Debug / print actual numbers
  238. // Most templates just skip this setting
  239. auto compNumbers = tmpl->getCpuPlayers().getNumbers();
  240. if (!compNumbers.empty())
  241. {
  242. compCountAllowed = compNumbers;
  243. minComps = *boost::min_element(compCountAllowed);
  244. }
  245. playerCountAllowed = tmpl->getPlayers().getNumbers();
  246. auto minPlayerCount = *boost::min_element(playerCountAllowed);
  247. auto maxCompCount = *boost::max_element(compCountAllowed);
  248. for (int i = 1; i >= (minPlayerCount - maxCompCount) && i >= 1; i--)
  249. {
  250. //We can always add extra CPUs to meet the minimum total player count
  251. playerCountAllowed.insert(i);
  252. }
  253. }
  254. si8 playerLimit = opts->getPlayerLimit();
  255. si8 humanOrCpuPlayerCount = opts->getHumanOrCpuPlayerCount();
  256. si8 compOnlyPlayersCount = opts->getCompOnlyPlayerCount();
  257. if(mapGenOptions->getHumanOrCpuPlayerCount() != CMapGenOptions::RANDOM_SIZE)
  258. {
  259. vstd::erase_if(compCountAllowed, [playerLimit, humanOrCpuPlayerCount](int el)
  260. {
  261. return (playerLimit - humanOrCpuPlayerCount) < el;
  262. });
  263. vstd::erase_if(playerTeamsAllowed, [humanOrCpuPlayerCount](int el)
  264. {
  265. return humanOrCpuPlayerCount <= el;
  266. });
  267. if(!playerTeamsAllowed.count(opts->getTeamCount()))
  268. {
  269. opts->setTeamCount(CMapGenOptions::RANDOM_SIZE);
  270. }
  271. }
  272. if(mapGenOptions->getCompOnlyPlayerCount() != CMapGenOptions::RANDOM_SIZE)
  273. {
  274. // This setting doesn't impact total number of players
  275. vstd::erase_if(compTeamsAllowed, [compOnlyPlayersCount](int el)
  276. {
  277. return compOnlyPlayersCount<= el;
  278. });
  279. if(!compTeamsAllowed.count(opts->getCompOnlyTeamCount()))
  280. {
  281. opts->setCompOnlyTeamCount(CMapGenOptions::RANDOM_SIZE);
  282. }
  283. }
  284. if(auto w = widget<CToggleGroup>("groupMapSize"))
  285. {
  286. for(auto toggle : w->buttons)
  287. {
  288. if(auto button = std::dynamic_pointer_cast<CToggleButton>(toggle.second))
  289. {
  290. const auto & mapSizes = getPossibleMapSizes();
  291. int3 size( mapSizes[toggle.first], mapSizes[toggle.first], 1 + mapGenOptions->getHasTwoLevels());
  292. bool sizeAllowed = !mapGenOptions->getMapTemplate() || mapGenOptions->getMapTemplate()->matchesSize(size);
  293. button->block(!sizeAllowed);
  294. }
  295. }
  296. w->setSelected(vstd::find_pos(getPossibleMapSizes(), opts->getWidth()));
  297. }
  298. if(auto w = widget<CToggleButton>("buttonTwoLevels"))
  299. {
  300. int3 size( opts->getWidth(), opts->getWidth(), 2);
  301. bool undergoundAllowed = !mapGenOptions->getMapTemplate() || mapGenOptions->getMapTemplate()->matchesSize(size);
  302. w->setSelected(opts->getHasTwoLevels());
  303. w->block(!undergoundAllowed);
  304. }
  305. if(auto w = widget<CToggleGroup>("groupMaxPlayers"))
  306. {
  307. // FIXME: OH3 allows any setting here, even if currently selected template doesn't fit it
  308. // TODO: Set max players to current template limit wherever template is explicitely selected
  309. w->setSelected(opts->getHumanOrCpuPlayerCount());
  310. deactivateButtonsFrom(*w, playerCountAllowed);
  311. }
  312. if(auto w = widget<CToggleGroup>("groupMaxTeams"))
  313. {
  314. w->setSelected(opts->getTeamCount());
  315. deactivateButtonsFrom(*w, playerTeamsAllowed);
  316. }
  317. if(auto w = widget<CToggleGroup>("groupCompOnlyPlayers"))
  318. {
  319. w->setSelected(opts->getCompOnlyPlayerCount());
  320. deactivateButtonsFrom(*w, compCountAllowed);
  321. }
  322. if(auto w = widget<CToggleGroup>("groupCompOnlyTeams"))
  323. {
  324. w->setSelected(opts->getCompOnlyTeamCount());
  325. deactivateButtonsFrom(*w, compTeamsAllowed);
  326. }
  327. if(auto w = widget<CToggleGroup>("groupWaterContent"))
  328. {
  329. w->setSelected(opts->getWaterContent());
  330. if(opts->getMapTemplate())
  331. {
  332. std::set<int> allowedWater(opts->getMapTemplate()->getWaterContentAllowed().begin(), opts->getMapTemplate()->getWaterContentAllowed().end());
  333. deactivateButtonsFrom(*w, allowedWater);
  334. }
  335. else
  336. deactivateButtonsFrom(*w, {-1});
  337. }
  338. if(auto w = widget<CToggleGroup>("groupMonsterStrength"))
  339. w->setSelected(opts->getMonsterStrength());
  340. if(auto w = widget<CButton>("templateButton"))
  341. {
  342. if(tmpl)
  343. w->addTextOverlay(tmpl->getName(), EFonts::FONT_SMALL, Colors::WHITE);
  344. else
  345. w->addTextOverlay(readText(variables["randomTemplate"]), EFonts::FONT_SMALL, Colors::WHITE);
  346. }
  347. for(auto r : VLC->roadTypeHandler->objects)
  348. {
  349. if(auto w = widget<CToggleButton>(r->getJsonKey()))
  350. {
  351. w->setSelected(opts->isRoadEnabled(r->getId()));
  352. }
  353. }
  354. }
  355. void RandomMapTab::setTemplate(const CRmgTemplate * tmpl)
  356. {
  357. mapGenOptions->setMapTemplate(tmpl);
  358. setMapGenOptions(mapGenOptions);
  359. if(auto w = widget<CButton>("templateButton"))
  360. {
  361. if(tmpl)
  362. w->addTextOverlay(tmpl->getName(), EFonts::FONT_SMALL, Colors::WHITE);
  363. else
  364. w->addTextOverlay(readText(variables["randomTemplate"]), EFonts::FONT_SMALL, Colors::WHITE);
  365. }
  366. updateMapInfoByHost();
  367. }
  368. void RandomMapTab::deactivateButtonsFrom(CToggleGroup & group, const std::set<int> & allowed)
  369. {
  370. logGlobal->debug("Blocking buttons");
  371. for(auto toggle : group.buttons)
  372. {
  373. if(auto button = std::dynamic_pointer_cast<CToggleButton>(toggle.second))
  374. {
  375. if(allowed.count(CMapGenOptions::RANDOM_SIZE)
  376. || allowed.count(toggle.first)
  377. || toggle.first == CMapGenOptions::RANDOM_SIZE)
  378. {
  379. button->block(false);
  380. }
  381. else
  382. {
  383. button->block(true);
  384. }
  385. }
  386. }
  387. }
  388. std::vector<int> RandomMapTab::getPossibleMapSizes()
  389. {
  390. return {CMapHeader::MAP_SIZE_SMALL, CMapHeader::MAP_SIZE_MIDDLE, CMapHeader::MAP_SIZE_LARGE, CMapHeader::MAP_SIZE_XLARGE, CMapHeader::MAP_SIZE_HUGE, CMapHeader::MAP_SIZE_XHUGE, CMapHeader::MAP_SIZE_GIANT};
  391. }
  392. void TeamAlignmentsWidget::checkTeamCount()
  393. {
  394. //Do not allow to select one team only
  395. std::set<TeamID> teams;
  396. for (int plId = 0; plId < players.size(); ++plId)
  397. {
  398. teams.insert(TeamID(players[plId]->getSelected()));
  399. }
  400. if (teams.size() < 2)
  401. {
  402. //Do not let player close the window
  403. buttonOk->block(true);
  404. }
  405. else
  406. {
  407. buttonOk->block(false);
  408. }
  409. }
  410. TeamAlignmentsWidget::TeamAlignmentsWidget(RandomMapTab & randomMapTab):
  411. InterfaceObjectConfigurable()
  412. {
  413. const JsonNode config(JsonPath::builtin("config/widgets/randomMapTeamsWidget.json"));
  414. variables = config["variables"];
  415. int totalPlayers = randomMapTab.obtainMapGenOptions().getTotalPlayersCount();
  416. assert(totalPlayers <= PlayerColor::PLAYER_LIMIT_I);
  417. auto settings = randomMapTab.obtainMapGenOptions().getPlayersSettings();
  418. variables["totalPlayers"].Integer() = totalPlayers;
  419. pos.w = variables["windowSize"]["x"].Integer() + totalPlayers * variables["cellMargin"]["x"].Integer();
  420. pos.h = variables["windowSize"]["y"].Integer() + totalPlayers * variables["cellMargin"]["y"].Integer();
  421. variables["backgroundRect"]["x"].Integer() = pos.x;
  422. variables["backgroundRect"]["y"].Integer() = pos.y;
  423. variables["backgroundRect"]["w"].Integer() = pos.w;
  424. variables["backgroundRect"]["h"].Integer() = pos.h;
  425. variables["okButtonPosition"]["x"].Integer() = variables["buttonsOffset"]["ok"]["x"].Integer();
  426. variables["okButtonPosition"]["y"].Integer() = variables["buttonsOffset"]["ok"]["y"].Integer() + totalPlayers * variables["cellMargin"]["y"].Integer();
  427. variables["cancelButtonPosition"]["x"].Integer() = variables["buttonsOffset"]["cancel"]["x"].Integer();
  428. variables["cancelButtonPosition"]["y"].Integer() = variables["buttonsOffset"]["cancel"]["y"].Integer() + totalPlayers * variables["cellMargin"]["y"].Integer();
  429. addCallback("ok", [&](int)
  430. {
  431. for(int plId = 0; plId < players.size(); ++plId)
  432. {
  433. randomMapTab.obtainMapGenOptions().setPlayerTeam(PlayerColor(plId), TeamID(players[plId]->getSelected()));
  434. }
  435. randomMapTab.updateMapInfoByHost();
  436. assert(GH.windows().isTopWindow(this));
  437. GH.windows().popWindows(1);
  438. });
  439. addCallback("cancel", [&](int)
  440. {
  441. assert(GH.windows().isTopWindow(this));
  442. GH.windows().popWindows(1);
  443. });
  444. build(config);
  445. center(pos);
  446. OBJ_CONSTRUCTION;
  447. // Window should have X * X columns, where X is players + compOnly players.
  448. // For random player count, X is 8
  449. if (totalPlayers > settings.size())
  450. {
  451. auto savedPlayers = randomMapTab.obtainMapGenOptions().getSavedPlayersMap();
  452. for (const auto & player : savedPlayers)
  453. {
  454. if (!vstd::contains(settings, player.first))
  455. {
  456. settings[player.first] = player.second;
  457. }
  458. }
  459. }
  460. std::vector<CMapGenOptions::CPlayerSettings> settingsVec;
  461. for (const auto & player : settings)
  462. {
  463. settingsVec.push_back(player.second);
  464. }
  465. // FIXME: Flag is missing on windows show
  466. for(int plId = 0; plId < totalPlayers; ++plId)
  467. {
  468. players.push_back(std::make_shared<CToggleGroup>([&, totalPlayers, plId](int sel)
  469. {
  470. variables["player_id"].Integer() = plId;
  471. OBJ_CONSTRUCTION_TARGETED(players[plId].get());
  472. for(int teamId = 0; teamId < totalPlayers; ++teamId)
  473. {
  474. auto button = std::dynamic_pointer_cast<CToggleButton>(players[plId]->buttons[teamId]);
  475. assert(button);
  476. if(sel == teamId)
  477. {
  478. button->addOverlay(buildWidget(variables["flagsAnimation"]));
  479. }
  480. else
  481. {
  482. button->addOverlay(nullptr);
  483. }
  484. button->addCallback([this](bool)
  485. {
  486. checkTeamCount();
  487. });
  488. }
  489. }));
  490. OBJ_CONSTRUCTION_TARGETED(players.back().get());
  491. for(int teamId = 0; teamId < totalPlayers; ++teamId)
  492. {
  493. variables["point"]["x"].Integer() = variables["cellOffset"]["x"].Integer() + plId * variables["cellMargin"]["x"].Integer();
  494. variables["point"]["y"].Integer() = variables["cellOffset"]["y"].Integer() + teamId * variables["cellMargin"]["y"].Integer();
  495. auto button = buildWidget(variables["button"]);
  496. players.back()->addToggle(teamId, std::dynamic_pointer_cast<CToggleBase>(button));
  497. }
  498. // plId is not neccessarily player color, just an index
  499. auto team = settingsVec.at(plId).getTeam();
  500. if(team == TeamID::NO_TEAM)
  501. {
  502. logGlobal->warn("Player %d (id %d) has uninitialized team", settingsVec.at(plId).getColor(), plId);
  503. players.back()->setSelected(plId);
  504. }
  505. else
  506. players.back()->setSelected(team.getNum());
  507. }
  508. buttonOk = widget<CButton>("buttonOK");
  509. buttonCancel = widget<CButton>("buttonCancel");
  510. }