CSpellWindow.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. VCMI_LIB_NAMESPACE_BEGIN
  13. class CGHeroInstance;
  14. class CSpell;
  15. VCMI_LIB_NAMESPACE_END
  16. class IImage;
  17. class CAnimation;
  18. class CAnimImage;
  19. class CPicture;
  20. class CLabel;
  21. class CGStatusBar;
  22. class CPlayerInterface;
  23. class CSpellWindow;
  24. /// The spell window
  25. class CSpellWindow : public CWindowObject
  26. {
  27. class SpellArea : public CIntObject
  28. {
  29. const CSpell * mySpell;
  30. int schoolLevel; //range: 0 none, 3 - expert
  31. CSpellWindow * owner;
  32. std::shared_ptr<CAnimImage> image;
  33. std::shared_ptr<CAnimImage> schoolBorder;
  34. std::shared_ptr<CLabel> name;
  35. std::shared_ptr<CLabel> level;
  36. std::shared_ptr<CLabel> cost;
  37. public:
  38. SpellArea(Rect pos, CSpellWindow * owner);
  39. ~SpellArea();
  40. void setSpell(const CSpell * spell);
  41. void clickPressed(const Point & cursorPosition) override;
  42. void showPopupWindow(const Point & cursorPosition) override;
  43. void hover(bool on) override;
  44. };
  45. class InteractiveArea : public CIntObject
  46. {
  47. std::function<void()> onLeft;
  48. CSpellWindow * owner;
  49. std::string hoverText;
  50. std::string helpText;
  51. public:
  52. void clickPressed(const Point & cursorPosition) override;
  53. void showPopupWindow(const Point & cursorPosition) override;
  54. void hover(bool on) override;
  55. InteractiveArea(const Rect &myRect, std::function<void()> funcL, int helpTextId, CSpellWindow * _owner);
  56. };
  57. std::shared_ptr<CAnimation> spellIcons;
  58. std::array<std::shared_ptr<CAnimation>, 4> schoolBorders; //[0]: air, [1]: fire, [2]: water, [3]: earth
  59. std::shared_ptr<CPicture> leftCorner;
  60. std::shared_ptr<CPicture> rightCorner;
  61. std::shared_ptr<CAnimImage> schoolTab;
  62. std::shared_ptr<CAnimImage> schoolPicture;
  63. std::array<std::shared_ptr<SpellArea>, 21> spellAreas;
  64. std::shared_ptr<CLabel> mana;
  65. std::shared_ptr<CGStatusBar> statusBar;
  66. std::vector<std::shared_ptr<InteractiveArea>> interactiveAreas;
  67. bool isBigSpellbook;
  68. int offL = -11;
  69. int offR = 195;
  70. int offT = -37;
  71. int offB = 56;
  72. int sitesPerTabAdv[5];
  73. int sitesPerTabBattle[5];
  74. bool battleSpellsOnly; //if true, only battle spells are displayed; if false, only adventure map spells are displayed
  75. uint8_t selectedTab; // 0 - air magic, 1 - fire magic, 2 - water magic, 3 - earth magic, 4 - all schools
  76. int currentPage; //changes when corners are clicked
  77. std::vector<const CSpell *> mySpells; //all spels in this spellbook
  78. const CGHeroInstance * myHero; //hero whose spells are presented
  79. CPlayerInterface * myInt;
  80. void computeSpellsPerArea(); //recalculates spellAreas::mySpell
  81. void setCurrentPage(int value);
  82. void turnPageLeft();
  83. void turnPageRight();
  84. std::shared_ptr<IImage> createBigSpellBook();
  85. public:
  86. CSpellWindow(const CGHeroInstance * _myHero, CPlayerInterface * _myInt, bool openOnBattleSpells = true);
  87. ~CSpellWindow();
  88. void fexitb();
  89. void fadvSpellsb();
  90. void fbattleSpellsb();
  91. void fmanaPtsb();
  92. void fLcornerb();
  93. void fRcornerb();
  94. void selectSchool(int school); //schools: 0 - air magic, 1 - fire magic, 2 - water magic, 3 - earth magic, 4 - all schools
  95. int pagesWithinCurrentTab();
  96. void keyPressed(EShortcut key) override;
  97. void show(Canvas & to) override;
  98. };