inspector.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  1. /*
  2. * inspector.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 "inspector.h"
  12. #include "../lib/CArtHandler.h"
  13. #include "../lib/spells/CSpellHandler.h"
  14. #include "../lib/CHeroHandler.h"
  15. #include "../lib/CRandomGenerator.h"
  16. #include "../lib/mapObjects/CObjectClassesHandler.h"
  17. #include "../lib/mapping/CMap.h"
  18. #include "townbulidingswidget.h"
  19. #include "armywidget.h"
  20. #include "messagewidget.h"
  21. #include "rewardswidget.h"
  22. //===============IMPLEMENT OBJECT INITIALIZATION FUNCTIONS================
  23. Initializer::Initializer(CGObjectInstance * o, const PlayerColor & pl) : defaultPlayer(pl)
  24. {
  25. logGlobal->info("New object instance initialized");
  26. ///IMPORTANT! initialize order should be from base objects to derived objects
  27. INIT_OBJ_TYPE(CGResource);
  28. INIT_OBJ_TYPE(CGArtifact);
  29. INIT_OBJ_TYPE(CArmedInstance);
  30. INIT_OBJ_TYPE(CGShipyard);
  31. INIT_OBJ_TYPE(CGGarrison);
  32. INIT_OBJ_TYPE(CGMine);
  33. INIT_OBJ_TYPE(CGDwelling);
  34. INIT_OBJ_TYPE(CGTownInstance);
  35. INIT_OBJ_TYPE(CGCreature);
  36. INIT_OBJ_TYPE(CGHeroInstance);
  37. INIT_OBJ_TYPE(CGSignBottle);
  38. INIT_OBJ_TYPE(CGLighthouse);
  39. //INIT_OBJ_TYPE(CGPandoraBox);
  40. //INIT_OBJ_TYPE(CGEvent);
  41. //INIT_OBJ_TYPE(CGSeerHut);
  42. }
  43. bool stringToBool(const QString & s)
  44. {
  45. if(s == "TRUE")
  46. return true;
  47. //if(s == "FALSE")
  48. return false;
  49. }
  50. void Initializer::initialize(CArmedInstance * o)
  51. {
  52. if(!o) return;
  53. }
  54. void Initializer::initialize(CGSignBottle * o)
  55. {
  56. if(!o) return;
  57. }
  58. void Initializer::initialize(CGCreature * o)
  59. {
  60. if(!o) return;
  61. o->character = CGCreature::Character::HOSTILE;
  62. o->putStack(SlotID(0), new CStackInstance(CreatureID(o->subID), 0, false));
  63. }
  64. void Initializer::initialize(CGDwelling * o)
  65. {
  66. if(!o) return;
  67. o->tempOwner = defaultPlayer;
  68. switch(o->ID)
  69. {
  70. case Obj::RANDOM_DWELLING:
  71. case Obj::RANDOM_DWELLING_LVL:
  72. case Obj::RANDOM_DWELLING_FACTION:
  73. o->initRandomObjectInfo();
  74. }
  75. }
  76. void Initializer::initialize(CGGarrison * o)
  77. {
  78. if(!o) return;
  79. o->tempOwner = defaultPlayer;
  80. o->removableUnits = true;
  81. }
  82. void Initializer::initialize(CGShipyard * o)
  83. {
  84. if(!o) return;
  85. o->tempOwner = defaultPlayer;
  86. }
  87. void Initializer::initialize(CGLighthouse * o)
  88. {
  89. if(!o) return;
  90. o->tempOwner = defaultPlayer;
  91. }
  92. void Initializer::initialize(CGHeroInstance * o)
  93. {
  94. if(!o) return;
  95. o->tempOwner = defaultPlayer;
  96. if(o->ID == Obj::PRISON)
  97. o->tempOwner = PlayerColor::NEUTRAL;
  98. if(o->ID == Obj::HERO)
  99. {
  100. for(auto t : VLC->heroh->objects)
  101. {
  102. if(t->heroClass == VLC->heroh->classes.objects[o->subID].get())
  103. {
  104. o->type = VLC->heroh->objects[o->subID];
  105. break;
  106. }
  107. }
  108. }
  109. if(!o->type)
  110. o->type = VLC->heroh->objects.at(o->subID);
  111. o->name = o->type->getName();
  112. o->sex = o->type->sex;
  113. o->biography = o->type->biography;
  114. o->portrait = o->type->imageIndex;
  115. o->randomizeArmy(o->type->heroClass->faction);
  116. }
  117. void Initializer::initialize(CGTownInstance * o)
  118. {
  119. if(!o) return;
  120. const std::vector<std::string> castleLevels{"village", "fort", "citadel", "castle", "capitol"};
  121. int lvl = vstd::find_pos(castleLevels, o->appearance->stringID);
  122. o->builtBuildings.insert(BuildingID::DEFAULT);
  123. if(lvl > -1) o->builtBuildings.insert(BuildingID::TAVERN);
  124. if(lvl > 0) o->builtBuildings.insert(BuildingID::FORT);
  125. if(lvl > 1) o->builtBuildings.insert(BuildingID::CITADEL);
  126. if(lvl > 2) o->builtBuildings.insert(BuildingID::CASTLE);
  127. if(lvl > 3) o->builtBuildings.insert(BuildingID::CAPITOL);
  128. for(auto spell : VLC->spellh->objects) //add all regular spells to town
  129. {
  130. if(!spell->isSpecial() && !spell->isCreatureAbility())
  131. o->possibleSpells.push_back(spell->id);
  132. }
  133. }
  134. void Initializer::initialize(CGArtifact * o)
  135. {
  136. if(!o) return;
  137. if(o->ID == Obj::SPELL_SCROLL)
  138. {
  139. std::vector<SpellID> out;
  140. for(auto spell : VLC->spellh->objects) //spellh size appears to be greater (?)
  141. {
  142. //if(map->isAllowedSpell(spell->id))
  143. {
  144. out.push_back(spell->id);
  145. }
  146. }
  147. auto a = CArtifactInstance::createScroll(*RandomGeneratorUtil::nextItem(out, CRandomGenerator::getDefault()));
  148. o->storedArtifact = a;
  149. }
  150. }
  151. void Initializer::initialize(CGMine * o)
  152. {
  153. if(!o) return;
  154. o->tempOwner = defaultPlayer;
  155. o->producedResource = Res::ERes(o->subID);
  156. o->producedQuantity = o->defaultResProduction();
  157. }
  158. void Initializer::initialize(CGResource * o)
  159. {
  160. if(!o) return;
  161. o->amount = CGResource::RANDOM_AMOUNT;
  162. }
  163. //===============IMPLEMENT PROPERTIES SETUP===============================
  164. void Inspector::updateProperties(CArmedInstance * o)
  165. {
  166. if(!o) return;
  167. auto * delegate = new ArmyDelegate(*o);
  168. addProperty("Army", PropertyEditorPlaceholder(), delegate, false);
  169. }
  170. void Inspector::updateProperties(CGDwelling * o)
  171. {
  172. if(!o) return;
  173. addProperty("Owner", o->tempOwner, false);
  174. }
  175. void Inspector::updateProperties(CGLighthouse * o)
  176. {
  177. if(!o) return;
  178. addProperty("Owner", o->tempOwner, false);
  179. }
  180. void Inspector::updateProperties(CGGarrison * o)
  181. {
  182. if(!o) return;
  183. addProperty("Owner", o->tempOwner, false);
  184. addProperty("Removable units", o->removableUnits, InspectorDelegate::boolDelegate(), false);
  185. }
  186. void Inspector::updateProperties(CGShipyard * o)
  187. {
  188. if(!o) return;
  189. addProperty("Owner", o->tempOwner, false);
  190. }
  191. void Inspector::updateProperties(CGHeroInstance * o)
  192. {
  193. if(!o) return;
  194. addProperty("Owner", o->tempOwner, o->ID == Obj::PRISON); //field is not editable for prison
  195. addProperty<int>("Experience", o->exp, false);
  196. addProperty("Hero class", o->type->heroClass->getName(), true);
  197. { //Sex
  198. auto * delegate = new InspectorDelegate;
  199. delegate->options << "MALE" << "FEMALE";
  200. addProperty<std::string>("Sex", (o->sex ? "FEMALE" : "MALE"), delegate , false);
  201. }
  202. addProperty("Name", o->name, false);
  203. addProperty("Biography", o->biography, new MessageDelegate, false);
  204. addProperty("Portrait", o->portrait, false);
  205. { //Hero type
  206. auto * delegate = new InspectorDelegate;
  207. for(int i = 0; i < VLC->heroh->objects.size(); ++i)
  208. {
  209. if(map->allowedHeroes.at(i))
  210. {
  211. if(o->ID == Obj::PRISON || (o->type && VLC->heroh->objects[i]->heroClass->getIndex() == o->type->heroClass->getIndex()))
  212. delegate->options << QObject::tr(VLC->heroh->objects[i]->getName().c_str());
  213. }
  214. }
  215. addProperty("Hero type", o->type->getName(), delegate, false);
  216. }
  217. }
  218. void Inspector::updateProperties(CGTownInstance * o)
  219. {
  220. if(!o) return;
  221. addProperty("Town name", o->name, false);
  222. auto * delegate = new TownBuildingsDelegate(*o);
  223. addProperty("Buildings", PropertyEditorPlaceholder(), delegate, false);
  224. }
  225. void Inspector::updateProperties(CGArtifact * o)
  226. {
  227. if(!o) return;
  228. addProperty("Message", o->message, false);
  229. CArtifactInstance * instance = o->storedArtifact;
  230. if(instance)
  231. {
  232. SpellID spellId = instance->getGivenSpellID();
  233. if(spellId != -1)
  234. {
  235. auto * delegate = new InspectorDelegate;
  236. for(auto spell : VLC->spellh->objects)
  237. {
  238. //if(map->isAllowedSpell(spell->id))
  239. delegate->options << QObject::tr(spell->name.c_str());
  240. }
  241. addProperty("Spell", VLC->spellh->objects[spellId]->name, delegate, false);
  242. }
  243. }
  244. }
  245. void Inspector::updateProperties(CGMine * o)
  246. {
  247. if(!o) return;
  248. addProperty("Owner", o->tempOwner, false);
  249. addProperty("Resource", o->producedResource);
  250. addProperty("Productivity", o->producedQuantity, false);
  251. }
  252. void Inspector::updateProperties(CGResource * o)
  253. {
  254. if(!o) return;
  255. addProperty("Amount", o->amount, false);
  256. addProperty("Message", o->message, false);
  257. }
  258. void Inspector::updateProperties(CGSignBottle * o)
  259. {
  260. if(!o) return;
  261. addProperty("Message", o->message, new MessageDelegate, false);
  262. }
  263. void Inspector::updateProperties(CGCreature * o)
  264. {
  265. if(!o) return;
  266. addProperty("Message", o->message, false);
  267. { //Character
  268. auto * delegate = new InspectorDelegate;
  269. delegate->options << "COMPLIANT" << "FRIENDLY" << "AGRESSIVE" << "HOSTILE" << "SAVAGE";
  270. addProperty<CGCreature::Character>("Character", (CGCreature::Character)o->character, delegate, false);
  271. }
  272. addProperty("Never flees", o->neverFlees, InspectorDelegate::boolDelegate(), false);
  273. addProperty("Not growing", o->notGrowingTeam, InspectorDelegate::boolDelegate(), false);
  274. addProperty("Artifact reward", o->gainedArtifact); //TODO: implement in setProperty
  275. addProperty("Army", PropertyEditorPlaceholder(), true);
  276. addProperty("Amount", o->stacks[SlotID(0)]->count, false);
  277. //addProperty("Resources reward", o->resources); //TODO: implement in setProperty
  278. }
  279. void Inspector::updateProperties(CGPandoraBox * o)
  280. {
  281. if(!o) return;
  282. addProperty("Message", o->message, new MessageDelegate, false);
  283. auto * delegate = new RewardsPandoraDelegate(*map, *o);
  284. addProperty("Reward", PropertyEditorPlaceholder(), delegate, false);
  285. }
  286. void Inspector::updateProperties(CGEvent * o)
  287. {
  288. if(!o) return;
  289. addProperty("Remove after", o->removeAfterVisit, InspectorDelegate::boolDelegate(), false);
  290. addProperty("Human trigger", o->humanActivate, InspectorDelegate::boolDelegate(), false);
  291. addProperty("Cpu trigger", o->computerActivate, InspectorDelegate::boolDelegate(), false);
  292. //ui8 availableFor; //players whom this event is available for
  293. }
  294. void Inspector::updateProperties(CGSeerHut * o)
  295. {
  296. if(!o) return;
  297. { //Mission type
  298. auto * delegate = new InspectorDelegate;
  299. delegate->options << "Reach level" << "Stats" << "Kill hero" << "Kill creature" << "Artifact" << "Army" << "Resources" << "Hero" << "Player";
  300. addProperty<CQuest::Emission>("Mission type", o->quest->missionType, delegate, false);
  301. }
  302. addProperty("First visit text", o->quest->firstVisitText, new MessageDelegate, false);
  303. addProperty("Next visit text", o->quest->nextVisitText, new MessageDelegate, false);
  304. addProperty("Completed text", o->quest->completedText, new MessageDelegate, false);
  305. auto * delegate = new RewardsSeerhutDelegate(*map, *o);
  306. addProperty("Reward", PropertyEditorPlaceholder(), delegate, false);
  307. }
  308. void Inspector::updateProperties()
  309. {
  310. if(!obj)
  311. return;
  312. table->setRowCount(0); //cleanup table
  313. addProperty("Indentifier", obj);
  314. addProperty("ID", obj->ID.getNum());
  315. addProperty("SubID", obj->subID);
  316. addProperty("InstanceName", obj->instanceName);
  317. addProperty("TypeName", obj->typeName);
  318. addProperty("SubTypeName", obj->subTypeName);
  319. if(!dynamic_cast<CGHeroInstance*>(obj))
  320. {
  321. auto factory = VLC->objtypeh->getHandlerFor(obj->ID, obj->subID);
  322. addProperty("IsStatic", factory->isStaticObject());
  323. }
  324. auto * delegate = new InspectorDelegate();
  325. delegate->options << "NEUTRAL";
  326. for(int p = 0; p < map->players.size(); ++p)
  327. if(map->players[p].canAnyonePlay())
  328. delegate->options << QString("PLAYER %1").arg(p);
  329. addProperty("Owner", obj->tempOwner, delegate, true);
  330. UPDATE_OBJ_PROPERTIES(CArmedInstance);
  331. UPDATE_OBJ_PROPERTIES(CGResource);
  332. UPDATE_OBJ_PROPERTIES(CGArtifact);
  333. UPDATE_OBJ_PROPERTIES(CGMine);
  334. UPDATE_OBJ_PROPERTIES(CGGarrison);
  335. UPDATE_OBJ_PROPERTIES(CGShipyard);
  336. UPDATE_OBJ_PROPERTIES(CGDwelling);
  337. UPDATE_OBJ_PROPERTIES(CGTownInstance);
  338. UPDATE_OBJ_PROPERTIES(CGCreature);
  339. UPDATE_OBJ_PROPERTIES(CGHeroInstance);
  340. UPDATE_OBJ_PROPERTIES(CGSignBottle);
  341. UPDATE_OBJ_PROPERTIES(CGLighthouse);
  342. UPDATE_OBJ_PROPERTIES(CGPandoraBox);
  343. UPDATE_OBJ_PROPERTIES(CGEvent);
  344. UPDATE_OBJ_PROPERTIES(CGSeerHut);
  345. table->show();
  346. }
  347. //===============IMPLEMENT PROPERTY UPDATE================================
  348. void Inspector::setProperty(const QString & key, const QVariant & value)
  349. {
  350. if(!obj)
  351. return;
  352. if(key == "Owner")
  353. {
  354. PlayerColor owner(value.toString().mid(6).toInt()); //receiving PLAYER N, N has index 6
  355. if(value == "NEUTRAL")
  356. owner = PlayerColor::NEUTRAL;
  357. if(value == "UNFLAGGABLE")
  358. owner = PlayerColor::UNFLAGGABLE;
  359. obj->tempOwner = owner;
  360. }
  361. SET_PROPERTIES(CArmedInstance);
  362. SET_PROPERTIES(CGTownInstance);
  363. SET_PROPERTIES(CGArtifact);
  364. SET_PROPERTIES(CGMine);
  365. SET_PROPERTIES(CGResource);
  366. SET_PROPERTIES(CGDwelling);
  367. SET_PROPERTIES(CGGarrison);
  368. SET_PROPERTIES(CGCreature);
  369. SET_PROPERTIES(CGHeroInstance);
  370. SET_PROPERTIES(CGShipyard);
  371. SET_PROPERTIES(CGSignBottle);
  372. SET_PROPERTIES(CGLighthouse);
  373. SET_PROPERTIES(CGPandoraBox);
  374. SET_PROPERTIES(CGEvent);
  375. SET_PROPERTIES(CGSeerHut);
  376. }
  377. void Inspector::setProperty(CArmedInstance * o, const QString & key, const QVariant & value)
  378. {
  379. if(!o) return;
  380. }
  381. void Inspector::setProperty(CGLighthouse * o, const QString & key, const QVariant & value)
  382. {
  383. if(!o) return;
  384. }
  385. void Inspector::setProperty(CGPandoraBox * o, const QString & key, const QVariant & value)
  386. {
  387. if(!o) return;
  388. }
  389. void Inspector::setProperty(CGEvent * o, const QString & key, const QVariant & value)
  390. {
  391. if(!o) return;
  392. if(key == "Remove after")
  393. o->removeAfterVisit = stringToBool(value.toString());
  394. if(key == "Human trigger")
  395. o->humanActivate = stringToBool(value.toString());
  396. if(key == "Cpu trigger")
  397. o->computerActivate = stringToBool(value.toString());
  398. }
  399. void Inspector::setProperty(CGTownInstance * o, const QString & key, const QVariant & value)
  400. {
  401. if(!o) return;
  402. if(key == "Town name")
  403. o->name = value.toString().toStdString();
  404. }
  405. void Inspector::setProperty(CGSignBottle * o, const QString & key, const QVariant & value)
  406. {
  407. if(!o) return;
  408. if(key == "Message")
  409. o->message = value.toString().toStdString();
  410. }
  411. void Inspector::setProperty(CGMine * o, const QString & key, const QVariant & value)
  412. {
  413. if(!o) return;
  414. if(key == "Productivity")
  415. o->producedQuantity = value.toString().toInt();
  416. }
  417. void Inspector::setProperty(CGArtifact * o, const QString & key, const QVariant & value)
  418. {
  419. if(!o) return;
  420. if(key == "Message")
  421. o->message = value.toString().toStdString();
  422. if(o->storedArtifact && key == "Spell")
  423. {
  424. for(auto spell : VLC->spellh->objects)
  425. {
  426. if(spell->name == value.toString().toStdString())
  427. {
  428. o->storedArtifact = CArtifactInstance::createScroll(spell->getId());
  429. break;
  430. }
  431. }
  432. }
  433. }
  434. void Inspector::setProperty(CGDwelling * o, const QString & key, const QVariant & value)
  435. {
  436. if(!o) return;
  437. }
  438. void Inspector::setProperty(CGGarrison * o, const QString & key, const QVariant & value)
  439. {
  440. if(!o) return;
  441. if(key == "Removable units")
  442. o->removableUnits = stringToBool(value.toString());
  443. }
  444. void Inspector::setProperty(CGHeroInstance * o, const QString & key, const QVariant & value)
  445. {
  446. if(!o) return;
  447. if(key == "Sex")
  448. o->sex = value.toString() == "MALE" ? 0 : 1;
  449. if(key == "Name")
  450. o->name = value.toString().toStdString();
  451. if(key == "Hero type")
  452. {
  453. for(auto t : VLC->heroh->objects)
  454. {
  455. if(t->getName() == value.toString().toStdString())
  456. o->type = t.get();
  457. }
  458. o->name = o->type->getName();
  459. o->sex = o->type->sex;
  460. o->biography = o->type->biography;
  461. o->portrait = o->type->imageIndex;
  462. o->randomizeArmy(o->type->heroClass->faction);
  463. updateProperties(); //updating other properties after change
  464. }
  465. }
  466. void Inspector::setProperty(CGShipyard * o, const QString & key, const QVariant & value)
  467. {
  468. if(!o) return;
  469. }
  470. void Inspector::setProperty(CGResource * o, const QString & key, const QVariant & value)
  471. {
  472. if(!o) return;
  473. if(key == "Amount")
  474. o->amount = value.toString().toInt();
  475. }
  476. void Inspector::setProperty(CGCreature * o, const QString & key, const QVariant & value)
  477. {
  478. if(!o) return;
  479. if(key == "Message")
  480. o->message = value.toString().toStdString();
  481. if(key == "Character")
  482. {
  483. //COMPLIANT = 0, FRIENDLY = 1, AGRESSIVE = 2, HOSTILE = 3, SAVAGE = 4
  484. if(value == "COMPLIANT")
  485. o->character = CGCreature::Character::COMPLIANT;
  486. if(value == "FRIENDLY")
  487. o->character = CGCreature::Character::FRIENDLY;
  488. if(value == "AGRESSIVE")
  489. o->character = CGCreature::Character::AGRESSIVE;
  490. if(value == "HOSTILE")
  491. o->character = CGCreature::Character::HOSTILE;
  492. if(value == "SAVAGE")
  493. o->character = CGCreature::Character::SAVAGE;
  494. }
  495. if(key == "Never flees")
  496. o->neverFlees = stringToBool(value.toString());
  497. if(key == "Not growing")
  498. o->notGrowingTeam = stringToBool(value.toString());
  499. if(key == "Amount")
  500. o->stacks[SlotID(0)]->count = value.toString().toInt();
  501. }
  502. void Inspector::setProperty(CGSeerHut * o, const QString & key, const QVariant & value)
  503. {
  504. if(!o) return;
  505. if(key == "Mission type")
  506. {
  507. if(value == "Reach level")
  508. o->quest->missionType = CQuest::Emission::MISSION_LEVEL;
  509. if(value == "Stats")
  510. o->quest->missionType = CQuest::Emission::MISSION_PRIMARY_STAT;
  511. if(value == "Kill hero")
  512. o->quest->missionType = CQuest::Emission::MISSION_KILL_HERO;
  513. if(value == "Kill creature")
  514. o->quest->missionType = CQuest::Emission::MISSION_KILL_CREATURE;
  515. if(value == "Artifact")
  516. o->quest->missionType = CQuest::Emission::MISSION_ART;
  517. if(value == "Army")
  518. o->quest->missionType = CQuest::Emission::MISSION_ARMY;
  519. if(value == "Resources")
  520. o->quest->missionType = CQuest::Emission::MISSION_RESOURCES;
  521. if(value == "Hero")
  522. o->quest->missionType = CQuest::Emission::MISSION_HERO;
  523. if(value == "Player")
  524. o->quest->missionType = CQuest::Emission::MISSION_PLAYER;
  525. }
  526. if(key == "First visit text")
  527. o->quest->firstVisitText = value.toString().toStdString();
  528. if(key == "Next visit text")
  529. o->quest->nextVisitText = value.toString().toStdString();
  530. if(key == "Completed text")
  531. o->quest->completedText = value.toString().toStdString();
  532. }
  533. //===============IMPLEMENT PROPERTY VALUE TYPE============================
  534. QTableWidgetItem * Inspector::addProperty(CGObjectInstance * value)
  535. {
  536. return new QTableWidgetItem(QString::number(data_cast<CGObjectInstance>(value)));
  537. }
  538. QTableWidgetItem * Inspector::addProperty(Inspector::PropertyEditorPlaceholder value)
  539. {
  540. auto item = new QTableWidgetItem("");
  541. item->setData(Qt::UserRole, QString("PropertyEditor"));
  542. return item;
  543. }
  544. QTableWidgetItem * Inspector::addProperty(unsigned int value)
  545. {
  546. return new QTableWidgetItem(QString::number(value));
  547. }
  548. QTableWidgetItem * Inspector::addProperty(int value)
  549. {
  550. return new QTableWidgetItem(QString::number(value));
  551. }
  552. QTableWidgetItem * Inspector::addProperty(bool value)
  553. {
  554. return new QTableWidgetItem(value ? "TRUE" : "FALSE");
  555. }
  556. QTableWidgetItem * Inspector::addProperty(const std::string & value)
  557. {
  558. return addProperty(QString::fromStdString(value));
  559. }
  560. QTableWidgetItem * Inspector::addProperty(const QString & value)
  561. {
  562. return new QTableWidgetItem(value);
  563. }
  564. QTableWidgetItem * Inspector::addProperty(const int3 & value)
  565. {
  566. return new QTableWidgetItem(QString("(%1, %2, %3)").arg(value.x, value.y, value.z));
  567. }
  568. QTableWidgetItem * Inspector::addProperty(const PlayerColor & value)
  569. {
  570. auto str = QString("PLAYER %1").arg(value.getNum());
  571. if(value == PlayerColor::NEUTRAL)
  572. str = "NEUTRAL";
  573. if(value == PlayerColor::UNFLAGGABLE)
  574. str = "UNFLAGGABLE";
  575. return new QTableWidgetItem(str);
  576. }
  577. QTableWidgetItem * Inspector::addProperty(const Res::ERes & value)
  578. {
  579. QString str;
  580. switch (value) {
  581. case Res::ERes::WOOD:
  582. str = "WOOD";
  583. break;
  584. case Res::ERes::ORE:
  585. str = "ORE";
  586. break;
  587. case Res::ERes::SULFUR:
  588. str = "SULFUR";
  589. break;
  590. case Res::ERes::GEMS:
  591. str = "GEMS";
  592. break;
  593. case Res::ERes::MERCURY:
  594. str = "MERCURY";
  595. break;
  596. case Res::ERes::CRYSTAL:
  597. str = "CRYSTAL";
  598. break;
  599. case Res::ERes::GOLD:
  600. str = "GOLD";
  601. break;
  602. default:
  603. break;
  604. }
  605. return new QTableWidgetItem(str);
  606. }
  607. QTableWidgetItem * Inspector::addProperty(CGCreature::Character value)
  608. {
  609. QString str;
  610. switch (value) {
  611. case CGCreature::Character::COMPLIANT:
  612. str = "COMPLIANT";
  613. break;
  614. case CGCreature::Character::FRIENDLY:
  615. str = "FRIENDLY";
  616. break;
  617. case CGCreature::Character::AGRESSIVE:
  618. str = "AGRESSIVE";
  619. break;
  620. case CGCreature::Character::HOSTILE:
  621. str = "HOSTILE";
  622. break;
  623. case CGCreature::Character::SAVAGE:
  624. str = "SAVAGE";
  625. break;
  626. default:
  627. break;
  628. }
  629. return new QTableWidgetItem(str);
  630. }
  631. QTableWidgetItem * Inspector::addProperty(CQuest::Emission value)
  632. {
  633. QString str;
  634. switch (value) {
  635. case CQuest::Emission::MISSION_LEVEL:
  636. str = "Reach level";
  637. break;
  638. case CQuest::Emission::MISSION_PRIMARY_STAT:
  639. str = "Stats";
  640. break;
  641. case CQuest::Emission::MISSION_KILL_HERO:
  642. str = "Kill hero";
  643. break;
  644. case CQuest::Emission::MISSION_KILL_CREATURE:
  645. str = "Kill creature";
  646. break;
  647. case CQuest::Emission::MISSION_ART:
  648. str = "Artifact";
  649. break;
  650. case CQuest::Emission::MISSION_ARMY:
  651. str = "Army";
  652. break;
  653. case CQuest::Emission::MISSION_RESOURCES:
  654. str = "Resources";
  655. break;
  656. case CQuest::Emission::MISSION_HERO:
  657. str = "Hero";
  658. break;
  659. case CQuest::Emission::MISSION_PLAYER:
  660. str = "Player";
  661. break;
  662. case CQuest::Emission::MISSION_KEYMASTER:
  663. str = "Key master";
  664. break;
  665. default:
  666. break;
  667. }
  668. return new QTableWidgetItem(str);
  669. }
  670. //========================================================================
  671. Inspector::Inspector(CMap * m, CGObjectInstance * o, QTableWidget * t): obj(o), table(t), map(m)
  672. {
  673. }
  674. /*
  675. * Delegates
  676. */
  677. InspectorDelegate * InspectorDelegate::boolDelegate()
  678. {
  679. auto * d = new InspectorDelegate;
  680. d->options << "TRUE" << "FALSE";
  681. return d;
  682. }
  683. QWidget * InspectorDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
  684. {
  685. return new QComboBox(parent);
  686. }
  687. void InspectorDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
  688. {
  689. if(QComboBox *ed = qobject_cast<QComboBox *>(editor))
  690. {
  691. ed->addItems(options);
  692. }
  693. else
  694. {
  695. QStyledItemDelegate::setEditorData(editor, index);
  696. }
  697. }
  698. void InspectorDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
  699. {
  700. if(QComboBox *ed = qobject_cast<QComboBox *>(editor))
  701. {
  702. if(!options.isEmpty())
  703. {
  704. QMap<int, QVariant> data;
  705. data[0] = options[ed->currentIndex()];
  706. model->setItemData(index, data);
  707. }
  708. }
  709. else
  710. {
  711. QStyledItemDelegate::setModelData(editor, model, index);
  712. }
  713. }