mapsettings.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * mapsettings.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 <QDialog>
  12. #include "mapcontroller.h"
  13. namespace Ui {
  14. class MapSettings;
  15. }
  16. class MapSettings : public QDialog
  17. {
  18. Q_OBJECT
  19. public:
  20. explicit MapSettings(MapController & controller, QWidget *parent = nullptr);
  21. ~MapSettings();
  22. private slots:
  23. void on_pushButton_clicked();
  24. void on_victoryComboBox_currentIndexChanged(int index);
  25. void on_loseComboBox_currentIndexChanged(int index);
  26. private:
  27. std::string getTownName(int townObjectIdx);
  28. std::string getHeroName(int townObjectIdx);
  29. std::string getMonsterName(int townObjectIdx);
  30. template<class T>
  31. std::vector<int> getObjectIndexes() const
  32. {
  33. std::vector<int> result;
  34. for(int i = 0; i < controller.map()->objects.size(); ++i)
  35. {
  36. if(auto town = dynamic_cast<T*>(controller.map()->objects[i].get()))
  37. result.push_back(i);
  38. }
  39. return result;
  40. }
  41. template<class T>
  42. int getObjectByPos(const int3 & pos)
  43. {
  44. for(int i = 0; i < controller.map()->objects.size(); ++i)
  45. {
  46. if(auto town = dynamic_cast<T*>(controller.map()->objects[i].get()))
  47. {
  48. if(town->pos == pos)
  49. return i;
  50. }
  51. }
  52. return -1;
  53. }
  54. Ui::MapSettings *ui;
  55. MapController & controller;
  56. QComboBox * victoryTypeWidget = nullptr, * loseTypeWidget = nullptr;
  57. QComboBox * victorySelectWidget = nullptr, * loseSelectWidget = nullptr;
  58. QLineEdit * victoryValueWidget = nullptr, * loseValueWidget = nullptr;
  59. };