2
0

CSpellWindow.h 3.7 KB

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