CBonusSelection.cpp 18 KB

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