victoryconditions.cpp 19 KB

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