CBonusSelection.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. /*
  2. * CBonusSelection.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 "CBonusSelection.h"
  12. #include <vcmi/spells/Spell.h>
  13. #include <vcmi/spells/Service.h>
  14. #include "CSelectionBase.h"
  15. #include "ExtraOptionsTab.h"
  16. #include "../CGameInfo.h"
  17. #include "../CPlayerInterface.h"
  18. #include "../CServerHandler.h"
  19. #include "../mainmenu/CMainMenu.h"
  20. #include "../mainmenu/CPrologEpilogVideo.h"
  21. #include "../media/IMusicPlayer.h"
  22. #include "../widgets/CComponent.h"
  23. #include "../widgets/Buttons.h"
  24. #include "../widgets/MiscWidgets.h"
  25. #include "../widgets/ObjectLists.h"
  26. #include "../widgets/TextControls.h"
  27. #include "../widgets/VideoWidget.h"
  28. #include "../windows/GUIClasses.h"
  29. #include "../windows/InfoWindows.h"
  30. #include "../render/IImage.h"
  31. #include "../render/IRenderHandler.h"
  32. #include "../render/CAnimation.h"
  33. #include "../render/Graphics.h"
  34. #include "../gui/CGuiHandler.h"
  35. #include "../gui/Shortcut.h"
  36. #include "../gui/WindowHandler.h"
  37. #include "../adventureMap/AdventureMapInterface.h"
  38. #include "../../lib/CConfigHandler.h"
  39. #include "../../lib/CCreatureHandler.h"
  40. #include "../../lib/CSkillHandler.h"
  41. #include "../../lib/StartInfo.h"
  42. #include "../../lib/entities/building/CBuilding.h"
  43. #include "../../lib/entities/building/CBuildingHandler.h"
  44. #include "../../lib/entities/faction/CFaction.h"
  45. #include "../../lib/entities/faction/CTown.h"
  46. #include "../../lib/entities/faction/CTownHandler.h"
  47. #include "../../lib/entities/hero/CHeroHandler.h"
  48. #include "../../lib/filesystem/Filesystem.h"
  49. #include "../../lib/texts/CGeneralTextHandler.h"
  50. #include "../../lib/campaign/CampaignState.h"
  51. #include "../../lib/mapping/CMapService.h"
  52. #include "../../lib/mapping/CMapInfo.h"
  53. #include "../../lib/mapping/CMapHeader.h"
  54. #include "../../lib/mapObjects/CGHeroInstance.h"
  55. std::shared_ptr<CampaignState> CBonusSelection::getCampaign()
  56. {
  57. return CSH->si->campState;
  58. }
  59. CBonusSelection::CBonusSelection()
  60. : CWindowObject(BORDERED)
  61. {
  62. OBJECT_CONSTRUCTION;
  63. setBackground(getCampaign()->getRegions().getBackgroundName());
  64. panelBackground = std::make_shared<CPicture>(ImagePath::builtin("CAMPBRF.BMP"), 456, 6);
  65. const auto & playVideo = [this]()
  66. {
  67. GH.windows().createAndPushWindow<CPrologEpilogVideo>(
  68. getCampaign()->scenario(CSH->campaignMap).prolog,
  69. [this]() { redraw(); } );
  70. };
  71. buttonStart = std::make_shared<CButton>(
  72. Point(475, 536), AnimationPath::builtin("CBBEGIB.DEF"), CButton::tooltip(), std::bind(&CBonusSelection::startMap, this), EShortcut::GLOBAL_ACCEPT
  73. );
  74. buttonRestart = std::make_shared<CButton>(Point(475, 536), AnimationPath::builtin("CBRESTB.DEF"), CButton::tooltip(), std::bind(&CBonusSelection::restartMap, this), EShortcut::GLOBAL_ACCEPT);
  75. buttonVideo = std::make_shared<CButton>(Point(705, 214), AnimationPath::builtin("CBVIDEB.DEF"), CButton::tooltip(), playVideo, EShortcut::LOBBY_REPLAY_VIDEO);
  76. buttonBack = std::make_shared<CButton>(Point(624, 536), AnimationPath::builtin("CBCANCB.DEF"), CButton::tooltip(), std::bind(&CBonusSelection::goBack, this), EShortcut::GLOBAL_CANCEL);
  77. campaignName = std::make_shared<CLabel>(481, 28, FONT_BIG, ETextAlignment::TOPLEFT, Colors::YELLOW, CSH->si->getCampaignName(), 250);
  78. iconsMapSizes = std::make_shared<CAnimImage>(AnimationPath::builtin("SCNRMPSZ"), 4, 0, 735, 26);
  79. labelCampaignDescription = std::make_shared<CLabel>(481, 63, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, CGI->generaltexth->allTexts[38]);
  80. campaignDescription = std::make_shared<CTextBox>(getCampaign()->getDescriptionTranslated(), Rect(480, 86, 286, 117), 1);
  81. bool videoButtonActive = CSH->getState() == EClientState::GAMEPLAY;
  82. int availableSpace = videoButtonActive ? 225 : 285;
  83. mapName = std::make_shared<CLabel>(481, 219, FONT_BIG, ETextAlignment::TOPLEFT, Colors::YELLOW, CSH->mi->getNameTranslated(), availableSpace );
  84. labelMapDescription = std::make_shared<CLabel>(481, 253, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, CGI->generaltexth->allTexts[496]);
  85. mapDescription = std::make_shared<CTextBox>("", Rect(480, 278, 286, 108), 1);
  86. labelChooseBonus = std::make_shared<CLabel>(475, 432, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[71]);
  87. groupBonuses = std::make_shared<CToggleGroup>(std::bind(&IServerAPI::setCampaignBonus, CSH, _1));
  88. flagbox = std::make_shared<CFlagBox>(Rect(486, 407, 335, 23));
  89. std::vector<std::string> difficulty;
  90. std::string difficultyString = CGI->generaltexth->allTexts[492];
  91. boost::split(difficulty, difficultyString, boost::is_any_of(" "));
  92. labelDifficulty = std::make_shared<CLabel>(724, settings["general"]["enableUiEnhancements"].Bool() ? 457 : 432, FONT_MEDIUM, ETextAlignment::TOPCENTER, Colors::WHITE, difficulty.back());
  93. for(size_t b = 0; b < difficultyIcons.size(); ++b)
  94. {
  95. difficultyIcons[b] = std::make_shared<CAnimImage>(AnimationPath::builtinTODO("GSPBUT" + std::to_string(b + 3) + ".DEF"), 0, 0, 709, settings["general"]["enableUiEnhancements"].Bool() ? 480 : 455);
  96. difficultyIconAreas[b] = std::make_shared<LRClickableArea>(difficultyIcons[b]->pos - pos.topLeft(), nullptr, [b]() { CRClickPopup::createAndPush(CGI->generaltexth->zelp[24 + b].second); });
  97. }
  98. if(getCampaign()->playerSelectedDifficulty())
  99. {
  100. Point posLeft = settings["general"]["enableUiEnhancements"].Bool() ? Point(693, 495) : Point(694, 508);
  101. Point posRight = settings["general"]["enableUiEnhancements"].Bool() ? Point(739, 495) : Point(738, 508);
  102. buttonDifficultyLeft = std::make_shared<CButton>(posLeft, AnimationPath::builtin("SCNRBLF.DEF"), CButton::tooltip(), std::bind(&CBonusSelection::decreaseDifficulty, this), EShortcut::MOVE_LEFT);
  103. buttonDifficultyRight = std::make_shared<CButton>(posRight, AnimationPath::builtin("SCNRBRT.DEF"), CButton::tooltip(), std::bind(&CBonusSelection::increaseDifficulty, this), EShortcut::MOVE_RIGHT);
  104. }
  105. for(auto scenarioID : getCampaign()->allScenarios())
  106. {
  107. if(getCampaign()->isAvailable(scenarioID))
  108. regions.push_back(std::make_shared<CRegion>(scenarioID, true, true, false, getCampaign()->getRegions()));
  109. else if(getCampaign()->isConquered(scenarioID)) //display as striped
  110. regions.push_back(std::make_shared<CRegion>(scenarioID, false, false, false, getCampaign()->getRegions()));
  111. else
  112. regions.push_back(std::make_shared<CRegion>(scenarioID, false, false, true, getCampaign()->getRegions()));
  113. }
  114. if (!getCampaign()->getMusic().empty())
  115. CCS->musich->playMusic( getCampaign()->getMusic(), true, false);
  116. if(CSH->getState() != EClientState::GAMEPLAY && settings["general"]["enableUiEnhancements"].Bool())
  117. {
  118. tabExtraOptions = std::make_shared<ExtraOptionsTab>();
  119. tabExtraOptions->recActions = UPDATE | SHOWALL | LCLICK | RCLICK_POPUP;
  120. tabExtraOptions->recreate(true);
  121. tabExtraOptions->setEnabled(false);
  122. buttonExtraOptions = std::make_shared<CButton>(Point(643, 431), AnimationPath::builtin("GSPBUT2.DEF"), CGI->generaltexth->zelp[46], [this]{ tabExtraOptions->setEnabled(!tabExtraOptions->isActive()); GH.windows().totalRedraw(); }, EShortcut::LOBBY_EXTRA_OPTIONS);
  123. buttonExtraOptions->setTextOverlay(CGI->generaltexth->translate("vcmi.optionsTab.extraOptions.hover"), FONT_SMALL, Colors::WHITE);
  124. }
  125. }
  126. void CBonusSelection::createBonusesIcons()
  127. {
  128. OBJECT_CONSTRUCTION;
  129. const CampaignScenario & scenario = getCampaign()->scenario(CSH->campaignMap);
  130. const std::vector<CampaignBonus> & bonDescs = scenario.travelOptions.bonusesToChoose;
  131. groupBonuses = std::make_shared<CToggleGroup>(std::bind(&IServerAPI::setCampaignBonus, CSH, _1));
  132. constexpr std::array bonusPics =
  133. {
  134. "SPELLBON.DEF", // Spell
  135. "TWCRPORT.DEF", // Monster
  136. "", // Building - BO*.BMP
  137. "ARTIFBON.DEF", // Artifact
  138. "SPELLBON.DEF", // Spell scroll
  139. "PSKILBON.DEF", // Primary skill
  140. "SSKILBON.DEF", // Secondary skill
  141. "BORES.DEF", // Resource
  142. "PORTRAITSLARGE", // Hero HPL*.BMP
  143. "PORTRAITSLARGE"
  144. // Player - CREST58.DEF
  145. };
  146. for(int i = 0; i < bonDescs.size(); i++)
  147. {
  148. int bonusType = static_cast<size_t>(bonDescs[i].type);
  149. std::string picName = bonusPics[bonusType];
  150. size_t picNumber = bonDescs[i].info2;
  151. MetaString desc;
  152. switch(bonDescs[i].type)
  153. {
  154. case CampaignBonusType::SPELL:
  155. desc.appendLocalString(EMetaText::GENERAL_TXT, 715);
  156. desc.replaceName(SpellID(bonDescs[i].info2));
  157. break;
  158. case CampaignBonusType::MONSTER:
  159. picNumber = bonDescs[i].info2 + 2;
  160. desc.appendLocalString(EMetaText::GENERAL_TXT, 717);
  161. desc.replaceNumber(bonDescs[i].info3);
  162. desc.replaceNamePlural(bonDescs[i].info2);
  163. break;
  164. case CampaignBonusType::BUILDING:
  165. {
  166. FactionID faction;
  167. for(auto & elem : CSH->si->playerInfos)
  168. {
  169. if(elem.second.isControlledByHuman())
  170. {
  171. faction = elem.second.castle;
  172. break;
  173. }
  174. }
  175. assert(faction != -1);
  176. BuildingID buildID;
  177. if(getCampaign()->formatVCMI())
  178. buildID = BuildingID(bonDescs[i].info1);
  179. else
  180. buildID = CBuildingHandler::campToERMU(bonDescs[i].info1, faction, std::set<BuildingID>());
  181. picName = graphics->ERMUtoPicture[faction][buildID];
  182. picNumber = -1;
  183. if(vstd::contains((*CGI->townh)[faction]->town->buildings, buildID))
  184. desc.appendTextID((*CGI->townh)[faction]->town->buildings.find(buildID)->second->getNameTextID());
  185. break;
  186. }
  187. case CampaignBonusType::ARTIFACT:
  188. desc.appendLocalString(EMetaText::GENERAL_TXT, 715);
  189. desc.replaceName(ArtifactID(bonDescs[i].info2));
  190. break;
  191. case CampaignBonusType::SPELL_SCROLL:
  192. desc.appendLocalString(EMetaText::GENERAL_TXT, 716);
  193. desc.replaceName(SpellID(bonDescs[i].info2));
  194. break;
  195. case CampaignBonusType::PRIMARY_SKILL:
  196. {
  197. int leadingSkill = -1;
  198. std::vector<std::pair<int, int>> toPrint; //primary skills to be listed <num, val>
  199. const ui8 * ptr = reinterpret_cast<const ui8 *>(&bonDescs[i].info2);
  200. for(int g = 0; g < GameConstants::PRIMARY_SKILLS; ++g)
  201. {
  202. if(leadingSkill == -1 || ptr[g] > ptr[leadingSkill])
  203. {
  204. leadingSkill = g;
  205. }
  206. if(ptr[g] != 0)
  207. {
  208. toPrint.push_back(std::make_pair(g, ptr[g]));
  209. }
  210. }
  211. picNumber = leadingSkill;
  212. desc.appendLocalString(EMetaText::GENERAL_TXT, 715);
  213. std::string substitute; //text to be printed instead of %s
  214. for(int v = 0; v < toPrint.size(); ++v)
  215. {
  216. substitute += std::to_string(toPrint[v].second);
  217. substitute += " " + CGI->generaltexth->primarySkillNames[toPrint[v].first];
  218. if(v != toPrint.size() - 1)
  219. {
  220. substitute += ", ";
  221. }
  222. }
  223. desc.replaceRawString(substitute);
  224. break;
  225. }
  226. case CampaignBonusType::SECONDARY_SKILL:
  227. desc.appendLocalString(EMetaText::GENERAL_TXT, 718);
  228. desc.replaceTextID(TextIdentifier("core", "skilllev", bonDescs[i].info3 - 1).get());
  229. desc.replaceName(SecondarySkill(bonDescs[i].info2));
  230. picNumber = bonDescs[i].info2 * 3 + bonDescs[i].info3 - 1;
  231. break;
  232. case CampaignBonusType::RESOURCE:
  233. {
  234. desc.appendLocalString(EMetaText::GENERAL_TXT, 717);
  235. switch(bonDescs[i].info1)
  236. {
  237. case 0xFD: //wood + ore
  238. {
  239. desc.replaceLocalString(EMetaText::GENERAL_TXT, 721);
  240. picNumber = 7;
  241. break;
  242. }
  243. case 0xFE: //wood + ore
  244. {
  245. desc.replaceLocalString(EMetaText::GENERAL_TXT, 722);
  246. picNumber = 8;
  247. break;
  248. }
  249. default:
  250. {
  251. desc.replaceName(GameResID(bonDescs[i].info1));
  252. picNumber = bonDescs[i].info1;
  253. }
  254. }
  255. desc.replaceNumber(bonDescs[i].info2);
  256. break;
  257. }
  258. case CampaignBonusType::HEROES_FROM_PREVIOUS_SCENARIO:
  259. {
  260. auto superhero = getCampaign()->strongestHero(static_cast<CampaignScenarioID>(bonDescs[i].info2), PlayerColor(bonDescs[i].info1));
  261. if(!superhero)
  262. logGlobal->warn("No superhero! How could it be transferred?");
  263. picNumber = superhero ? superhero->getIconIndex() : 0;
  264. desc.appendLocalString(EMetaText::GENERAL_TXT, 719);
  265. desc.replaceRawString(getCampaign()->scenario(static_cast<CampaignScenarioID>(bonDescs[i].info2)).scenarioName.toString());
  266. break;
  267. }
  268. case CampaignBonusType::HERO:
  269. if(bonDescs[i].info2 == 0xFFFF)
  270. {
  271. desc.appendLocalString(EMetaText::GENERAL_TXT, 720); // Start with random hero
  272. picNumber = -1;
  273. picName = "CBONN1A3.BMP";
  274. }
  275. else
  276. {
  277. desc.appendLocalString(EMetaText::GENERAL_TXT, 715); // Start with %s
  278. desc.replaceTextID(CGI->heroh->objects[bonDescs[i].info2]->getNameTextID());
  279. }
  280. break;
  281. }
  282. std::shared_ptr<CToggleButton> bonusButton = std::make_shared<CToggleButton>(Point(475 + i * 68, 455), AnimationPath::builtin("campaignBonusSelection"), CButton::tooltip(desc.toString(), desc.toString()), nullptr, EShortcut::NONE, false, [this](){
  283. if(buttonStart->isActive() && !buttonStart->isBlocked())
  284. CBonusSelection::startMap();
  285. });
  286. if(picNumber != -1)
  287. bonusButton->setOverlay(std::make_shared<CAnimImage>(AnimationPath::builtin(picName), picNumber));
  288. else
  289. bonusButton->setOverlay(std::make_shared<CPicture>(ImagePath::builtin(picName)));
  290. if(CSH->campaignBonus == i)
  291. bonusButton->setBorderColor(Colors::BRIGHT_YELLOW);
  292. groupBonuses->addToggle(i, bonusButton);
  293. }
  294. if(getCampaign()->getBonusID(CSH->campaignMap))
  295. groupBonuses->setSelected(*getCampaign()->getBonusID(CSH->campaignMap));
  296. }
  297. void CBonusSelection::updateAfterStateChange()
  298. {
  299. if(CSH->getState() != EClientState::GAMEPLAY)
  300. {
  301. buttonRestart->disable();
  302. buttonVideo->disable();
  303. buttonStart->enable();
  304. buttonBack->block(!getCampaign()->conqueredScenarios().empty());
  305. }
  306. else
  307. {
  308. buttonStart->disable();
  309. buttonRestart->enable();
  310. buttonVideo->enable();
  311. buttonBack->block(false);
  312. if(buttonDifficultyLeft)
  313. buttonDifficultyLeft->disable();
  314. if(buttonDifficultyRight)
  315. buttonDifficultyRight->disable();
  316. }
  317. if(CSH->campaignBonus == -1)
  318. {
  319. buttonStart->block(getCampaign()->scenario(CSH->campaignMap).travelOptions.bonusesToChoose.size());
  320. }
  321. else
  322. {
  323. buttonStart->block(false);
  324. }
  325. for(auto region : regions)
  326. region->updateState();
  327. if(!CSH->mi)
  328. return;
  329. iconsMapSizes->setFrame(CSH->mi->getMapSizeIconId());
  330. mapName->setText(CSH->mi->getNameTranslated());
  331. mapDescription->setText(CSH->mi->getDescriptionTranslated());
  332. for(size_t i = 0; i < difficultyIcons.size(); i++)
  333. {
  334. if(i == CSH->si->difficulty)
  335. {
  336. difficultyIcons[i]->enable();
  337. difficultyIconAreas[i]->enable();
  338. }
  339. else
  340. {
  341. difficultyIcons[i]->disable();
  342. difficultyIconAreas[i]->disable();
  343. }
  344. }
  345. flagbox->recreate();
  346. createBonusesIcons();
  347. }
  348. void CBonusSelection::goBack()
  349. {
  350. if(CSH->getState() != EClientState::GAMEPLAY)
  351. {
  352. GH.windows().popWindows(2);
  353. CMM->playMusic();
  354. }
  355. else
  356. {
  357. close();
  358. if(adventureInt)
  359. adventureInt->onAudioResumed();
  360. }
  361. // TODO: we can actually only pop bonus selection interface for custom campaigns
  362. // Though this would require clearing CLobbyScreen::bonusSel pointer when poping this interface
  363. /*
  364. else
  365. {
  366. close();
  367. CSH->state = EClientState::LOBBY;
  368. }
  369. */
  370. }
  371. void CBonusSelection::startMap()
  372. {
  373. if (!CSH->validateGameStart())
  374. return;
  375. auto showPrologVideo = [=]()
  376. {
  377. auto exitCb = [=]()
  378. {
  379. logGlobal->info("Starting scenario %d", static_cast<int>(CSH->campaignMap));
  380. CSH->sendStartGame();
  381. };
  382. const CampaignScenario & scenario = getCampaign()->scenario(CSH->campaignMap);
  383. if(scenario.prolog.hasPrologEpilog)
  384. {
  385. GH.windows().createAndPushWindow<CPrologEpilogVideo>(scenario.prolog, exitCb);
  386. }
  387. else
  388. {
  389. exitCb();
  390. }
  391. };
  392. //block buttons immediately
  393. buttonStart->block(true);
  394. buttonRestart->block(true);
  395. buttonVideo->block(true);
  396. buttonBack->block(true);
  397. if(LOCPLINT) // we're currently ingame, so ask for starting new map and end game
  398. {
  399. close();
  400. LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[67], [=]()
  401. {
  402. showPrologVideo();
  403. }, 0);
  404. }
  405. else
  406. {
  407. showPrologVideo();
  408. }
  409. }
  410. void CBonusSelection::restartMap()
  411. {
  412. close();
  413. LOCPLINT->showYesNoDialog(
  414. CGI->generaltexth->allTexts[67],
  415. [=]()
  416. {
  417. GH.dispatchMainThread(
  418. []()
  419. {
  420. CSH->sendRestartGame();
  421. }
  422. );
  423. },
  424. 0
  425. );
  426. }
  427. void CBonusSelection::increaseDifficulty()
  428. {
  429. CSH->setDifficulty(CSH->si->difficulty + 1);
  430. }
  431. void CBonusSelection::decreaseDifficulty()
  432. {
  433. // avoid negative overflow (0 - 1 = 255)
  434. if (CSH->si->difficulty > 0)
  435. CSH->setDifficulty(CSH->si->difficulty - 1);
  436. }
  437. CBonusSelection::CRegion::CRegion(CampaignScenarioID id, bool accessible, bool selectable, bool labelOnly, const CampaignRegions & campDsc)
  438. : CIntObject(LCLICK | SHOW_POPUP | TIME), idOfMapAndRegion(id), accessible(accessible), selectable(selectable), labelOnly(labelOnly), blinkAnim({})
  439. {
  440. OBJECT_CONSTRUCTION;
  441. pos += campDsc.getPosition(id);
  442. auto color = CSH->si->campState->scenario(idOfMapAndRegion).regionColor;
  443. graphicsNotSelected = std::make_shared<CPicture>(campDsc.getAvailableName(id, color));
  444. graphicsNotSelected->disable();
  445. graphicsSelected = std::make_shared<CPicture>(campDsc.getSelectedName(id, color));
  446. graphicsSelected->disable();
  447. graphicsStriped = std::make_shared<CPicture>(campDsc.getConqueredName(id, color));
  448. graphicsStriped->disable();
  449. pos.w = graphicsNotSelected->pos.w;
  450. pos.h = graphicsNotSelected->pos.h;
  451. auto labelPos = campDsc.getLabelPosition(id);
  452. if(labelPos)
  453. {
  454. auto mapHeader = CSH->si->campState->getMapHeader(idOfMapAndRegion);
  455. label = std::make_shared<CLabel>((*labelPos).x, (*labelPos).y, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, mapHeader->name.toString());
  456. }
  457. }
  458. void CBonusSelection::CRegion::updateState(bool disableAll)
  459. {
  460. if(labelOnly)
  461. return;
  462. if(disableAll)
  463. {
  464. graphicsNotSelected->disable();
  465. graphicsSelected->disable();
  466. graphicsStriped->disable();
  467. }
  468. else if(!accessible)
  469. {
  470. graphicsNotSelected->disable();
  471. graphicsSelected->disable();
  472. graphicsStriped->enable();
  473. }
  474. else if(CSH->campaignMap == idOfMapAndRegion)
  475. {
  476. graphicsNotSelected->disable();
  477. graphicsSelected->enable();
  478. graphicsStriped->disable();
  479. }
  480. else
  481. {
  482. graphicsNotSelected->enable();
  483. graphicsSelected->disable();
  484. graphicsStriped->disable();
  485. }
  486. }
  487. void CBonusSelection::CRegion::tick(uint32_t msPassed)
  488. {
  489. if(!accessible)
  490. {
  491. removeUsedEvents(TIME);
  492. return;
  493. }
  494. blinkAnim.msPassed += msPassed;
  495. if(blinkAnim.msPassed >= 150)
  496. {
  497. blinkAnim.state = !blinkAnim.state;
  498. blinkAnim.msPassed -= 150;
  499. if(blinkAnim.state)
  500. blinkAnim.count++;
  501. else if(blinkAnim.count >= 3)
  502. removeUsedEvents(TIME);
  503. }
  504. updateState(blinkAnim.state);
  505. setRedrawParent(true);
  506. redraw();
  507. }
  508. void CBonusSelection::CRegion::clickReleased(const Point & cursorPosition)
  509. {
  510. if(!labelOnly && selectable && !graphicsNotSelected->getSurface()->isTransparent(cursorPosition - pos.topLeft()))
  511. {
  512. CSH->setCampaignMap(idOfMapAndRegion);
  513. }
  514. }
  515. void CBonusSelection::CRegion::showPopupWindow(const Point & cursorPosition)
  516. {
  517. // FIXME: For some reason "down" is only ever contain indeterminate_value
  518. auto & text = CSH->si->campState->scenario(idOfMapAndRegion).regionText;
  519. if(!labelOnly && !graphicsNotSelected->getSurface()->isTransparent(cursorPosition - pos.topLeft()) && !text.empty())
  520. {
  521. CRClickPopup::createAndPush(text.toString());
  522. }
  523. }