CSpellWindow.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * CSpellWindow.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 "CWindowObject.h"
  12. #include "../widgets/IVideoHolder.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class CGHeroInstance;
  15. class CSpell;
  16. VCMI_LIB_NAMESPACE_END
  17. class IImage;
  18. class CAnimImage;
  19. class CPicture;
  20. class CLabel;
  21. class CGStatusBar;
  22. class CPlayerInterface;
  23. class CSpellWindow;
  24. class CTextInput;
  25. class TransparentFilledRectangle;
  26. class CToggleButton;
  27. class VideoWidgetOnce;
  28. /// The spell window
  29. class CSpellWindow : public CWindowObject, public IVideoHolder
  30. {
  31. class SpellArea : public CIntObject
  32. {
  33. const CSpell * mySpell;
  34. int schoolLevel; //range: 0 none, 3 - expert
  35. CSpellWindow * owner;
  36. std::shared_ptr<CAnimImage> image;
  37. std::shared_ptr<CAnimImage> schoolBorder;
  38. std::shared_ptr<CLabel> name;
  39. std::shared_ptr<CLabel> level;
  40. std::shared_ptr<CLabel> cost;
  41. public:
  42. SpellArea(Rect pos, CSpellWindow * owner);
  43. ~SpellArea();
  44. void setSpell(const CSpell * spell);
  45. void clickPressed(const Point & cursorPosition) override;
  46. void showPopupWindow(const Point & cursorPosition) override;
  47. void hover(bool on) override;
  48. };
  49. class InteractiveArea : public CIntObject
  50. {
  51. std::function<void()> onLeft;
  52. CSpellWindow * owner;
  53. std::string hoverText;
  54. std::string helpText;
  55. public:
  56. void clickPressed(const Point & cursorPosition) override;
  57. void showPopupWindow(const Point & cursorPosition) override;
  58. void hover(bool on) override;
  59. InteractiveArea(const Rect &myRect, std::function<void()> funcL, int helpTextId, CSpellWindow * _owner);
  60. InteractiveArea(const Rect &myRect, std::function<void()> funcL, std::string textId, CSpellWindow * _owner);
  61. };
  62. std::shared_ptr<CPicture> leftCorner;
  63. std::shared_ptr<CPicture> rightCorner;
  64. std::shared_ptr<CAnimImage> schoolTab;
  65. std::vector<std::shared_ptr<CAnimImage>> schoolTabCustom;
  66. std::shared_ptr<CPicture> schoolTabAnyDisabled;
  67. std::shared_ptr<CAnimImage> schoolPicture;
  68. std::shared_ptr<CPicture> schoolPictureCustom;
  69. std::array<std::shared_ptr<SpellArea>, 24> spellAreas;
  70. std::shared_ptr<CLabel> mana;
  71. std::shared_ptr<CGStatusBar> statusBar;
  72. std::vector<std::shared_ptr<InteractiveArea>> interactiveAreas;
  73. std::shared_ptr<CTextInput> searchBox;
  74. std::shared_ptr<TransparentFilledRectangle> searchBoxRectangle;
  75. std::shared_ptr<CLabel> searchBoxDescription;
  76. std::shared_ptr<CToggleButton> showAllSpells;
  77. std::shared_ptr<CLabel> showAllSpellsDescription;
  78. std::shared_ptr<VideoWidgetOnce> video;
  79. bool isBigSpellbook;
  80. int spellsPerPage;
  81. int offL;
  82. int offR;
  83. int offRM;
  84. int offT;
  85. int offB;
  86. std::map<SpellSchool, int> sitesPerTabAdv;
  87. std::map<SpellSchool, int> sitesPerTabBattle;
  88. const int MAX_CUSTOM_SPELL_SCHOOLS = 5;
  89. const int MAX_CUSTOM_SPELL_SCHOOLS_BIG = 6;
  90. std::vector<SpellSchool> customSpellSchools;
  91. bool battleSpellsOnly; //if true, only battle spells are displayed; if false, only adventure map spells are displayed
  92. SpellSchool selectedTab;
  93. int currentPage; //changes when corners are clicked
  94. std::vector<const CSpell *> mySpells; //all spels in this spellbook
  95. const CGHeroInstance * myHero; //hero whose spells are presented
  96. CPlayerInterface * myInt;
  97. void processSpells();
  98. void searchInput();
  99. void computeSpellsPerArea(); //recalculates spellAreas::mySpell
  100. void setSchoolImages(SpellSchool school);
  101. void setCurrentPage(int value);
  102. void turnPageLeft();
  103. void turnPageRight();
  104. void onVideoPlaybackFinished() override;
  105. bool openOnBattleSpells;
  106. std::function<void(SpellID)> onSpellSelect; //external processing of selected spell
  107. public:
  108. CSpellWindow(const CGHeroInstance * _myHero, CPlayerInterface * _myInt, bool openOnBattleSpells = true, const std::function<void(SpellID)> & onSpellSelect = nullptr);
  109. ~CSpellWindow();
  110. void fexitb();
  111. void fadvSpellsb();
  112. void fbattleSpellsb();
  113. void toggleSearchBoxFocus();
  114. void fmanaPtsb();
  115. void fLcornerb();
  116. void fRcornerb();
  117. void selectSchool(SpellSchool school);
  118. int pagesWithinCurrentTab();
  119. void keyPressed(EShortcut key) override;
  120. void show(Canvas & to) override;
  121. };