CSpellWindow.h 3.3 KB

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