victoryconditions.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. /*
  2. * victoryconditions.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 "victoryconditions.h"
  12. #include "ui_victoryconditions.h"
  13. #include "../mapcontroller.h"
  14. #include "../../lib/GameLibrary.h"
  15. #include "../../lib/constants/StringConstants.h"
  16. #include "../../lib/entities/artifact/CArtHandler.h"
  17. #include "../../lib/entities/faction/CTownHandler.h"
  18. #include "../../lib/entities/ResourceTypeHandler.h"
  19. #include "../../lib/mapObjects/CGCreature.h"
  20. #include "../../lib/texts/CGeneralTextHandler.h"
  21. #include "../inspector/townbuildingswidget.h" //to convert BuildingID to string
  22. VictoryConditions::VictoryConditions(QWidget *parent) :
  23. AbstractSettings(parent),
  24. ui(new Ui::VictoryConditions)
  25. {
  26. ui->setupUi(this);
  27. }
  28. void VictoryConditions::initialize(MapController & c)
  29. {
  30. AbstractSettings::initialize(c);
  31. //victory message
  32. ui->victoryMessageEdit->setText(QString::fromStdString(controller->map()->victoryMessage.toString()));
  33. //victory conditions
  34. const std::array<std::string, 9> conditionStringsWin = {
  35. QT_TR_NOOP("No special victory"),
  36. QT_TR_NOOP("Capture artifact"),
  37. QT_TR_NOOP("Hire creatures"),
  38. QT_TR_NOOP("Accumulate resources"),
  39. QT_TR_NOOP("Construct building"),
  40. QT_TR_NOOP("Capture town"),
  41. QT_TR_NOOP("Defeat hero"),
  42. QT_TR_NOOP("Transport artifact"),
  43. QT_TR_NOOP("Kill monster")
  44. };
  45. for(auto & s : conditionStringsWin)
  46. {
  47. ui->victoryComboBox->addItem(tr(s.c_str()));
  48. }
  49. ui->standardVictoryCheck->setChecked(false);
  50. ui->onlyForHumansCheck->setChecked(false);
  51. for(auto & ev : controller->map()->triggeredEvents)
  52. {
  53. if(ev.effect.type == EventEffect::VICTORY)
  54. {
  55. if(ev.identifier == "standardVictory")
  56. ui->standardVictoryCheck->setChecked(true);
  57. if(ev.identifier == "specialVictory")
  58. {
  59. auto readjson = ev.trigger.toJson(AbstractSettings::conditionToJson);
  60. auto linearNodes = linearJsonArray(readjson);
  61. for(auto & json : linearNodes)
  62. {
  63. switch(json["condition"].Integer())
  64. {
  65. case EventCondition::HAVE_ARTIFACT: {
  66. ui->victoryComboBox->setCurrentIndex(1);
  67. assert(victoryTypeWidget);
  68. auto artifactId = ArtifactID::decode(json["objectType"].String());
  69. auto idx = victoryTypeWidget->findData(artifactId);
  70. victoryTypeWidget->setCurrentIndex(idx);
  71. break;
  72. }
  73. case EventCondition::HAVE_CREATURES: {
  74. ui->victoryComboBox->setCurrentIndex(2);
  75. assert(victoryTypeWidget);
  76. assert(victoryValueWidget);
  77. auto creatureId = CreatureID::decode(json["objectType"].String());
  78. auto idx = victoryTypeWidget->findData(creatureId);
  79. victoryTypeWidget->setCurrentIndex(idx);
  80. victoryValueWidget->setText(QString::number(json["value"].Integer()));
  81. break;
  82. }
  83. case EventCondition::HAVE_RESOURCES: {
  84. ui->victoryComboBox->setCurrentIndex(3);
  85. assert(victoryTypeWidget);
  86. assert(victoryValueWidget);
  87. auto resourceId = EGameResID::decode(json["objectType"].String());
  88. auto idx = victoryTypeWidget->findData(resourceId);
  89. victoryTypeWidget->setCurrentIndex(idx);
  90. victoryValueWidget->setText(QString::number(json["value"].Integer()));
  91. break;
  92. }
  93. case EventCondition::HAVE_BUILDING: {
  94. ui->victoryComboBox->setCurrentIndex(4);
  95. assert(victoryTypeWidget);
  96. assert(victorySelectWidget);
  97. auto buildingId = BuildingID::decode(json["objectType"].String());
  98. auto idx = victoryTypeWidget->findData(buildingId);
  99. victoryTypeWidget->setCurrentIndex(idx);
  100. int townIdx = getObjectByPos<const CGTownInstance>(*controller->map(), posFromJson(json["position"]));
  101. if(townIdx >= 0)
  102. {
  103. auto idx = victorySelectWidget->findData(townIdx);
  104. victorySelectWidget->setCurrentIndex(idx);
  105. }
  106. break;
  107. }
  108. case EventCondition::CONTROL: {
  109. ui->victoryComboBox->setCurrentIndex(5);
  110. assert(victoryTypeWidget);
  111. auto mapObject = MapObjectID::decode(json["objectType"].String());
  112. if(mapObject == Obj::TOWN)
  113. {
  114. int townIdx = getObjectByPos<const CGTownInstance>(*controller->map(), posFromJson(json["position"]));
  115. if(townIdx >= 0)
  116. {
  117. auto idx = victoryTypeWidget->findData(townIdx);
  118. victoryTypeWidget->setCurrentIndex(idx);
  119. }
  120. }
  121. //TODO: support control other objects (dwellings, mines)
  122. break;
  123. }
  124. case EventCondition::DESTROY: {
  125. auto objectType = MapObjectID::decode(json["objectType"].String());
  126. if(objectType == Obj::HERO)
  127. {
  128. ui->victoryComboBox->setCurrentIndex(6);
  129. assert(victoryTypeWidget);
  130. int heroIdx = getObjectByPos<const CGHeroInstance>(*controller->map(), posFromJson(json["position"]));
  131. if(heroIdx >= 0)
  132. {
  133. auto idx = victoryTypeWidget->findData(heroIdx);
  134. victoryTypeWidget->setCurrentIndex(idx);
  135. }
  136. }
  137. if(objectType == Obj::MONSTER)
  138. {
  139. ui->victoryComboBox->setCurrentIndex(8);
  140. assert(victoryTypeWidget);
  141. int monsterIdx = getObjectByPos<const CGCreature>(*controller->map(), posFromJson(json["position"]));
  142. if(monsterIdx >= 0)
  143. {
  144. auto idx = victoryTypeWidget->findData(monsterIdx);
  145. victoryTypeWidget->setCurrentIndex(idx);
  146. }
  147. }
  148. break;
  149. }
  150. case EventCondition::TRANSPORT: {
  151. ui->victoryComboBox->setCurrentIndex(7);
  152. assert(victoryTypeWidget);
  153. assert(victorySelectWidget);
  154. auto artifactId = ArtifactID::decode(json["objectType"].String());
  155. auto idx = victoryTypeWidget->findData(int(artifactId));
  156. victoryTypeWidget->setCurrentIndex(idx);
  157. int townIdx = getObjectByPos<const CGTownInstance>(*controller->map(), posFromJson(json["position"]));
  158. if(townIdx >= 0)
  159. {
  160. auto idx = victorySelectWidget->findData(townIdx);
  161. victorySelectWidget->setCurrentIndex(idx);
  162. }
  163. break;
  164. }
  165. case EventCondition::IS_HUMAN: {
  166. ui->onlyForHumansCheck->setChecked(true);
  167. break;
  168. }
  169. };
  170. }
  171. }
  172. }
  173. }
  174. }
  175. void VictoryConditions::update()
  176. {
  177. //victory messages
  178. bool customMessage = true;
  179. //victory conditions
  180. EventCondition victoryCondition(EventCondition::STANDARD_WIN);
  181. //Victory condition - defeat all
  182. TriggeredEvent standardVictory;
  183. standardVictory.effect.type = EventEffect::VICTORY;
  184. standardVictory.effect.toOtherMessage.appendTextID("core.genrltxt.5");
  185. standardVictory.identifier = "standardVictory";
  186. standardVictory.description.clear(); // TODO: display in quest window
  187. standardVictory.onFulfill.appendTextID("core.genrltxt.659");
  188. standardVictory.trigger = EventExpression(victoryCondition);
  189. //VICTORY
  190. if(ui->victoryComboBox->currentIndex() == 0)
  191. {
  192. controller->map()->triggeredEvents.push_back(standardVictory);
  193. controller->map()->victoryIconIndex = 11;
  194. controller->map()->victoryMessage = MetaString::createFromTextID("core.vcdesc.0");
  195. customMessage = false;
  196. }
  197. else
  198. {
  199. int vicCondition = ui->victoryComboBox->currentIndex() - 1;
  200. TriggeredEvent specialVictory;
  201. specialVictory.effect.type = EventEffect::VICTORY;
  202. specialVictory.identifier = "specialVictory";
  203. specialVictory.description.clear(); // TODO: display in quest window
  204. controller->map()->victoryIconIndex = vicCondition;
  205. controller->map()->victoryMessage = MetaString::createFromTextID("core.vcdesc." + std::to_string(vicCondition + 1));
  206. customMessage = false;
  207. switch(vicCondition)
  208. {
  209. case 0: {
  210. EventCondition cond(EventCondition::HAVE_ARTIFACT);
  211. assert(victoryTypeWidget);
  212. cond.objectType = ArtifactID(victoryTypeWidget->currentData().toInt());
  213. specialVictory.effect.toOtherMessage.appendTextID("core.genrltxt.281");
  214. specialVictory.onFulfill.appendTextID("core.genrltxt.280");
  215. specialVictory.trigger = EventExpression(cond);
  216. break;
  217. }
  218. case 1: {
  219. EventCondition cond(EventCondition::HAVE_CREATURES);
  220. assert(victoryTypeWidget);
  221. cond.objectType = CreatureID(victoryTypeWidget->currentData().toInt());
  222. cond.value = victoryValueWidget->text().toInt();
  223. specialVictory.effect.toOtherMessage.appendTextID("core.genrltxt.277");
  224. specialVictory.onFulfill.appendTextID("core.genrltxt.276");
  225. specialVictory.trigger = EventExpression(cond);
  226. break;
  227. }
  228. case 2: {
  229. EventCondition cond(EventCondition::HAVE_RESOURCES);
  230. assert(victoryTypeWidget);
  231. cond.objectType = GameResID(victoryTypeWidget->currentData().toInt());
  232. cond.value = victoryValueWidget->text().toInt();
  233. specialVictory.effect.toOtherMessage.appendTextID("core.genrltxt.279");
  234. specialVictory.onFulfill.appendTextID("core.genrltxt.278");
  235. specialVictory.trigger = EventExpression(cond);
  236. break;
  237. }
  238. case 3: {
  239. EventCondition cond(EventCondition::HAVE_BUILDING);
  240. assert(victoryTypeWidget);
  241. cond.objectType = BuildingID(victoryTypeWidget->currentData().toInt());
  242. int townIdx = victorySelectWidget->currentData().toInt();
  243. if(townIdx > -1)
  244. cond.position = controller->map()->objects[townIdx]->pos;
  245. specialVictory.effect.toOtherMessage.appendTextID("core.genrltxt.283");
  246. specialVictory.onFulfill.appendTextID("core.genrltxt.282");
  247. specialVictory.trigger = EventExpression(cond);
  248. break;
  249. }
  250. case 4: {
  251. EventCondition cond(EventCondition::CONTROL);
  252. assert(victoryTypeWidget);
  253. cond.objectType = Obj(Obj::TOWN);
  254. int townIdx = victoryTypeWidget->currentData().toInt();
  255. cond.position = controller->map()->objects[townIdx]->pos;
  256. specialVictory.effect.toOtherMessage.appendTextID("core.genrltxt.250");
  257. specialVictory.onFulfill.appendTextID("core.genrltxt.249");
  258. specialVictory.trigger = EventExpression(cond);
  259. break;
  260. }
  261. case 5: {
  262. EventCondition cond(EventCondition::DESTROY);
  263. assert(victoryTypeWidget);
  264. cond.objectType = Obj(Obj::HERO);
  265. int heroIdx = victoryTypeWidget->currentData().toInt();
  266. cond.position = controller->map()->objects[heroIdx]->pos;
  267. specialVictory.effect.toOtherMessage.appendTextID("core.genrltxt.253");
  268. specialVictory.onFulfill.appendTextID("core.genrltxt.252");
  269. specialVictory.trigger = EventExpression(cond);
  270. break;
  271. }
  272. case 6: {
  273. EventCondition cond(EventCondition::TRANSPORT);
  274. assert(victoryTypeWidget);
  275. cond.objectType = ArtifactID(victoryTypeWidget->currentData().toInt());
  276. int townIdx = victorySelectWidget->currentData().toInt();
  277. if(townIdx > -1)
  278. cond.position = controller->map()->objects[townIdx]->pos;
  279. specialVictory.effect.toOtherMessage.appendTextID("core.genrltxt.293");
  280. specialVictory.onFulfill.appendTextID("core.genrltxt.292");
  281. specialVictory.trigger = EventExpression(cond);
  282. break;
  283. }
  284. case 7: {
  285. EventCondition cond(EventCondition::DESTROY);
  286. assert(victoryTypeWidget);
  287. cond.objectType = Obj(Obj::MONSTER);
  288. int monsterIdx = victoryTypeWidget->currentData().toInt();
  289. cond.position = controller->map()->objects[monsterIdx]->pos;
  290. specialVictory.effect.toOtherMessage.appendTextID("core.genrltxt.287");
  291. specialVictory.onFulfill.appendTextID("core.genrltxt.286");
  292. specialVictory.trigger = EventExpression(cond);
  293. break;
  294. }
  295. }
  296. // if condition is human-only turn it into following construction: AllOf(human, condition)
  297. if(ui->onlyForHumansCheck->isChecked())
  298. {
  299. EventExpression::OperatorAll oper;
  300. EventCondition notAI(EventCondition::IS_HUMAN);
  301. notAI.value = 1;
  302. oper.expressions.push_back(notAI);
  303. oper.expressions.push_back(specialVictory.trigger.get());
  304. specialVictory.trigger = EventExpression(oper);
  305. }
  306. // if normal victory allowed - add one more quest
  307. if(ui->standardVictoryCheck->isChecked())
  308. {
  309. controller->map()->victoryMessage.appendRawString(" / ");
  310. controller->map()->victoryMessage.appendTextID("core.vcdesc.0");
  311. controller->map()->triggeredEvents.push_back(standardVictory);
  312. customMessage = false;
  313. }
  314. controller->map()->triggeredEvents.push_back(specialVictory);
  315. }
  316. if(customMessage)
  317. {
  318. controller->map()->victoryMessage = MetaString::createFromTextID(mapRegisterLocalizedString("map", *controller->map(), TextIdentifier("header", "victoryMessage"), ui->victoryMessageEdit->text().toStdString()));
  319. }
  320. }
  321. VictoryConditions::~VictoryConditions()
  322. {
  323. delete ui;
  324. }
  325. void VictoryConditions::on_victoryComboBox_currentIndexChanged(int index)
  326. {
  327. delete victoryTypeWidget;
  328. delete victoryValueWidget;
  329. delete victorySelectWidget;
  330. delete pickObjectButton;
  331. victoryTypeWidget = nullptr;
  332. victoryValueWidget = nullptr;
  333. victorySelectWidget = nullptr;
  334. pickObjectButton = nullptr;
  335. if(index == 0)
  336. {
  337. ui->standardVictoryCheck->setChecked(true);
  338. ui->standardVictoryCheck->setEnabled(false);
  339. ui->onlyForHumansCheck->setChecked(false);
  340. ui->onlyForHumansCheck->setEnabled(false);
  341. return;
  342. }
  343. ui->onlyForHumansCheck->setEnabled(true);
  344. ui->standardVictoryCheck->setEnabled(true);
  345. int vicCondition = index - 1;
  346. switch(vicCondition)
  347. {
  348. case 0: { //EventCondition::HAVE_ARTIFACT
  349. victoryTypeWidget = new QComboBox;
  350. ui->victoryParamsLayout->addWidget(victoryTypeWidget);
  351. for(int i = 0; i < controller->map()->allowedArtifact.size(); ++i)
  352. victoryTypeWidget->addItem(QString::fromStdString(LIBRARY->arth->objects[i]->getNameTranslated()), QVariant::fromValue(i));
  353. break;
  354. }
  355. case 1: { //EventCondition::HAVE_CREATURES
  356. victoryTypeWidget = new QComboBox;
  357. ui->victoryParamsLayout->addWidget(victoryTypeWidget);
  358. for(int i = 0; i < LIBRARY->creh->objects.size(); ++i)
  359. victoryTypeWidget->addItem(QString::fromStdString(LIBRARY->creh->objects[i]->getNamePluralTranslated()), QVariant::fromValue(i));
  360. victoryValueWidget = new QLineEdit;
  361. ui->victoryParamsLayout->addWidget(victoryValueWidget);
  362. victoryValueWidget->setText("1");
  363. break;
  364. }
  365. case 2: { //EventCondition::HAVE_RESOURCES
  366. victoryTypeWidget = new QComboBox;
  367. ui->victoryParamsLayout->addWidget(victoryTypeWidget);
  368. {
  369. for(auto & resType : LIBRARY->resourceTypeHandler->getAllObjects())
  370. {
  371. MetaString str;
  372. str.appendName(GameResID(resType));
  373. auto resName = QString::fromStdString(str.toString());
  374. victoryTypeWidget->addItem(resName, QVariant::fromValue(resType.getNum()));
  375. }
  376. }
  377. victoryValueWidget = new QLineEdit;
  378. ui->victoryParamsLayout->addWidget(victoryValueWidget);
  379. victoryValueWidget->setText("1");
  380. break;
  381. }
  382. case 3: { //EventCondition::HAVE_BUILDING
  383. victoryTypeWidget = new QComboBox;
  384. ui->victoryParamsLayout->addWidget(victoryTypeWidget);
  385. auto * ctown = LIBRARY->townh->randomFaction->town.get();
  386. for(int bId : ctown->getAllBuildings())
  387. victoryTypeWidget->addItem(QString::fromStdString(defaultBuildingIdConversion(BuildingID(bId))), QVariant::fromValue(bId));
  388. victorySelectWidget = new QComboBox;
  389. ui->victoryParamsLayout->addWidget(victorySelectWidget);
  390. victorySelectWidget->addItem(tr("Any town"), QVariant::fromValue(-1));
  391. for(int i : getObjectIndexes<const CGTownInstance>(*controller->map()))
  392. victorySelectWidget->addItem(getTownName(*controller->map(), i).c_str(), QVariant::fromValue(i));
  393. pickObjectButton = new QToolButton;
  394. connect(pickObjectButton, &QToolButton::clicked, this, &VictoryConditions::onObjectSelect);
  395. ui->victoryParamsLayout->addWidget(pickObjectButton);
  396. break;
  397. }
  398. case 4: { //EventCondition::CONTROL (Obj::TOWN)
  399. victoryTypeWidget = new QComboBox;
  400. ui->victoryParamsLayout->addWidget(victoryTypeWidget);
  401. for(int i : getObjectIndexes<const CGTownInstance>(*controller->map()))
  402. victoryTypeWidget->addItem(tr(getTownName(*controller->map(), i).c_str()), QVariant::fromValue(i));
  403. pickObjectButton = new QToolButton;
  404. connect(pickObjectButton, &QToolButton::clicked, this, &VictoryConditions::onObjectSelect);
  405. ui->victoryParamsLayout->addWidget(pickObjectButton);
  406. break;
  407. }
  408. case 5: { //EventCondition::DESTROY (Obj::HERO)
  409. victoryTypeWidget = new QComboBox;
  410. ui->victoryParamsLayout->addWidget(victoryTypeWidget);
  411. for(int i : getObjectIndexes<const CGHeroInstance>(*controller->map()))
  412. victoryTypeWidget->addItem(tr(getHeroName(*controller->map(), i).c_str()), QVariant::fromValue(i));
  413. pickObjectButton = new QToolButton;
  414. connect(pickObjectButton, &QToolButton::clicked, this, &VictoryConditions::onObjectSelect);
  415. ui->victoryParamsLayout->addWidget(pickObjectButton);
  416. break;
  417. }
  418. case 6: { //EventCondition::TRANSPORT (Obj::ARTEFACT)
  419. victoryTypeWidget = new QComboBox;
  420. ui->victoryParamsLayout->addWidget(victoryTypeWidget);
  421. for(int i = 0; i < controller->map()->allowedArtifact.size(); ++i)
  422. victoryTypeWidget->addItem(QString::fromStdString(LIBRARY->arth->objects[i]->getNameTranslated()), QVariant::fromValue(i));
  423. victorySelectWidget = new QComboBox;
  424. ui->victoryParamsLayout->addWidget(victorySelectWidget);
  425. for(int i : getObjectIndexes<const CGTownInstance>(*controller->map()))
  426. victorySelectWidget->addItem(tr(getTownName(*controller->map(), i).c_str()), QVariant::fromValue(i));
  427. pickObjectButton = new QToolButton;
  428. connect(pickObjectButton, &QToolButton::clicked, this, &VictoryConditions::onObjectSelect);
  429. ui->victoryParamsLayout->addWidget(pickObjectButton);
  430. break;
  431. }
  432. case 7: { //EventCondition::DESTROY (Obj::MONSTER)
  433. victoryTypeWidget = new QComboBox;
  434. ui->victoryParamsLayout->addWidget(victoryTypeWidget);
  435. for(int i : getObjectIndexes<const CGCreature>(*controller->map()))
  436. victoryTypeWidget->addItem(getMonsterName(*controller->map(), i).c_str(), QVariant::fromValue(i));
  437. pickObjectButton = new QToolButton;
  438. connect(pickObjectButton, &QToolButton::clicked, this, &VictoryConditions::onObjectSelect);
  439. ui->victoryParamsLayout->addWidget(pickObjectButton);
  440. break;
  441. }
  442. }
  443. }
  444. void VictoryConditions::onObjectSelect()
  445. {
  446. int vicConditions = ui->victoryComboBox->currentIndex() - 1;
  447. for(MapScene * level : controller->getScenes())
  448. {
  449. auto & l = level->objectPickerView;
  450. switch(vicConditions)
  451. {
  452. case 3: { //EventCondition::HAVE_BUILDING
  453. l.highlight<const CGTownInstance>();
  454. break;
  455. }
  456. case 4: { //EventCondition::CONTROL (Obj::TOWN)
  457. l.highlight<const CGTownInstance>();
  458. break;
  459. }
  460. case 5: { //EventCondition::DESTROY (Obj::HERO)
  461. l.highlight<const CGHeroInstance>();
  462. break;
  463. }
  464. case 6: { //EventCondition::TRANSPORT (Obj::ARTEFACT)
  465. l.highlight<const CGTownInstance>();
  466. break;
  467. }
  468. case 7: { //EventCondition::DESTROY (Obj::MONSTER)
  469. l.highlight<const CGCreature>();
  470. break;
  471. }
  472. default:
  473. return;
  474. }
  475. l.update();
  476. QObject::connect(&l, &ObjectPickerLayer::selectionMade, this, &VictoryConditions::onObjectPicked);
  477. }
  478. controller->settingsDialog->hide();
  479. }
  480. void VictoryConditions::onObjectPicked(const CGObjectInstance * obj)
  481. {
  482. controller->settingsDialog->show();
  483. for(MapScene * level : controller->getScenes())
  484. {
  485. auto & l = level->objectPickerView;
  486. l.clear();
  487. l.update();
  488. QObject::disconnect(&l, &ObjectPickerLayer::selectionMade, this, &VictoryConditions::onObjectPicked);
  489. }
  490. if(!obj) //discarded
  491. return;
  492. int vicConditions = ui->victoryComboBox->currentIndex() - 1;
  493. QComboBox * w = victoryTypeWidget;
  494. if(vicConditions == 3 || vicConditions == 6)
  495. w = victorySelectWidget;
  496. for(int i = 0; i < w->count(); ++i)
  497. {
  498. if(w->itemData(i).toInt() < 0)
  499. continue;
  500. auto data = controller->map()->objects.at(w->itemData(i).toInt());
  501. if(data.get() == obj)
  502. {
  503. w->setCurrentIndex(i);
  504. break;
  505. }
  506. }
  507. }