CSpellWindow.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. };
  61. std::shared_ptr<CPicture> leftCorner;
  62. std::shared_ptr<CPicture> rightCorner;
  63. std::shared_ptr<CAnimImage> schoolTab;
  64. std::shared_ptr<CAnimImage> schoolPicture;
  65. std::array<std::shared_ptr<SpellArea>, 24> spellAreas;
  66. std::shared_ptr<CLabel> mana;
  67. std::shared_ptr<CGStatusBar> statusBar;
  68. std::vector<std::shared_ptr<InteractiveArea>> interactiveAreas;
  69. std::shared_ptr<CTextInput> searchBox;
  70. std::shared_ptr<TransparentFilledRectangle> searchBoxRectangle;
  71. std::shared_ptr<CLabel> searchBoxDescription;
  72. std::shared_ptr<CToggleButton> showAllSpells;
  73. std::shared_ptr<CLabel> showAllSpellsDescription;
  74. std::shared_ptr<VideoWidgetOnce> video;
  75. bool isBigSpellbook;
  76. int spellsPerPage;
  77. int offL;
  78. int offR;
  79. int offRM;
  80. int offT;
  81. int offB;
  82. int sitesPerTabAdv[5];
  83. int sitesPerTabBattle[5];
  84. bool battleSpellsOnly; //if true, only battle spells are displayed; if false, only adventure map spells are displayed
  85. uint8_t selectedTab; // 0 - air magic, 1 - fire magic, 2 - water magic, 3 - earth magic, 4 - all schools
  86. int currentPage; //changes when corners are clicked
  87. std::vector<const CSpell *> mySpells; //all spels in this spellbook
  88. const CGHeroInstance * myHero; //hero whose spells are presented
  89. CPlayerInterface * myInt;
  90. void processSpells();
  91. void searchInput();
  92. void computeSpellsPerArea(); //recalculates spellAreas::mySpell
  93. void setCurrentPage(int value);
  94. void turnPageLeft();
  95. void turnPageRight();
  96. void onVideoPlaybackFinished() override;
  97. bool openOnBattleSpells;
  98. std::function<void(SpellID)> onSpellSelect; //external processing of selected spell
  99. public:
  100. CSpellWindow(const CGHeroInstance * _myHero, CPlayerInterface * _myInt, bool openOnBattleSpells = true, const std::function<void(SpellID)> & onSpellSelect = nullptr);
  101. ~CSpellWindow();
  102. void fexitb();
  103. void fadvSpellsb();
  104. void fbattleSpellsb();
  105. void toggleSearchBoxFocus();
  106. void fmanaPtsb();
  107. void fLcornerb();
  108. void fRcornerb();
  109. void selectSchool(int school); //schools: 0 - air magic, 1 - fire magic, 2 - water magic, 3 - earth magic, 4 - all schools
  110. int pagesWithinCurrentTab();
  111. void keyPressed(EShortcut key) override;
  112. void show(Canvas & to) override;
  113. };