victoryconditions.cpp 19 KB

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