abstractsettings.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * abstractsettings.h, 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. #pragma once
  11. #include <QWidget>
  12. #include "../../lib/mapping/CMap.h"
  13. #include "../../lib/mapObjects/CGTownInstance.h"
  14. #include "../../lib/mapObjects/CGHeroInstance.h"
  15. //parses date for lose condition (1m 1w 1d)
  16. int expiredDate(const QString & date);
  17. QString expiredDate(int date);
  18. int3 posFromJson(const JsonNode & json);
  19. std::vector<JsonNode> linearJsonArray(const JsonNode & json);
  20. class MapController;
  21. class AbstractSettings : public QWidget
  22. {
  23. Q_OBJECT
  24. public:
  25. explicit AbstractSettings(QWidget *parent = nullptr);
  26. virtual ~AbstractSettings() = default;
  27. virtual void initialize(MapController & controller);
  28. virtual void update() = 0;
  29. static std::string getTownName(const CMap & map, int objectIdx);
  30. static std::string getHeroName(const CMap & map, int objectIdx);
  31. static std::string getMonsterName(const CMap & map, int objectIdx);
  32. static JsonNode conditionToJson(const EventCondition & event);
  33. template<class T>
  34. static std::vector<int> getObjectIndexes(const CMap & map)
  35. {
  36. std::vector<int> result;
  37. for(int i = 0; i < map.objects.size(); ++i)
  38. {
  39. if(auto obj = dynamic_cast<T*>(map.objects[i].get()))
  40. result.push_back(i);
  41. }
  42. return result;
  43. }
  44. template<class T>
  45. static int getObjectByPos(const CMap & map, const int3 & pos)
  46. {
  47. for(int i = 0; i < map.objects.size(); ++i)
  48. {
  49. if(auto obj = dynamic_cast<T*>(map.objects[i].get()))
  50. {
  51. if(obj->pos == pos)
  52. return i;
  53. }
  54. }
  55. return -1;
  56. }
  57. protected:
  58. MapController * controller = nullptr;
  59. };