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