CSpellWindow.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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>, 12> 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 sitesPerTabAdv[5];
  69. int sitesPerTabBattle[5];
  70. bool battleSpellsOnly; //if true, only battle spells are displayed; if false, only adventure map spells are displayed
  71. uint8_t selectedTab; // 0 - air magic, 1 - fire magic, 2 - water magic, 3 - earth magic, 4 - all schools
  72. int currentPage; //changes when corners are clicked
  73. std::vector<const CSpell *> mySpells; //all spels in this spellbook
  74. const CGHeroInstance * myHero; //hero whose spells are presented
  75. CPlayerInterface * myInt;
  76. void computeSpellsPerArea(); //recalculates spellAreas::mySpell
  77. void setCurrentPage(int value);
  78. void turnPageLeft();
  79. void turnPageRight();
  80. std::shared_ptr<IImage> createBigSpellBook();
  81. public:
  82. CSpellWindow(const CGHeroInstance * _myHero, CPlayerInterface * _myInt, bool openOnBattleSpells = true);
  83. ~CSpellWindow();
  84. void fexitb();
  85. void fadvSpellsb();
  86. void fbattleSpellsb();
  87. void fmanaPtsb();
  88. void fLcornerb();
  89. void fRcornerb();
  90. void selectSchool(int school); //schools: 0 - air magic, 1 - fire magic, 2 - water magic, 3 - earth magic, 4 - all schools
  91. int pagesWithinCurrentTab();
  92. void keyPressed(EShortcut key) override;
  93. void show(Canvas & to) override;
  94. };