CSpellWindow.h 3.6 KB

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