victoryconditions.cpp 19 KB

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