CSpellWindow.h 3.2 KB

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