CBonusSelection.cpp 18 KB

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