CSpellWindow.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #pragma once
  2. #include "CWindowObject.h"
  3. /*
  4. * CSpellWindow.h, part of VCMI engine
  5. *
  6. * Authors: listed in file AUTHORS in main folder
  7. *
  8. * License: GNU General Public License v2.0 or later
  9. * Full text of license available in license.txt file, in main folder
  10. *
  11. */
  12. struct SDL_Surface;
  13. struct SDL_Rect;
  14. class IImage;
  15. class CAnimImage;
  16. class CPicture;
  17. class CLabel;
  18. class CGHeroInstance;
  19. class CGStatusBar;
  20. class CPlayerInterface;
  21. class CSpellWindow;
  22. class CSpell;
  23. /// The spell window
  24. class CSpellWindow : public CWindowObject
  25. {
  26. private:
  27. class SpellArea : public CIntObject
  28. {
  29. public:
  30. const CSpell * mySpell;
  31. int schoolLevel; //range: 0 none, 3 - expert
  32. int whichSchool; //0 - air magic, 1 - fire magic, 2 - water magic, 3 - earth magic,
  33. int spellCost;
  34. CSpellWindow * owner;
  35. CAnimImage * image;
  36. IImage * schoolBorder;
  37. SpellArea(SDL_Rect pos, CSpellWindow * owner);
  38. ~SpellArea();
  39. void setSpell(const CSpell * spell);
  40. void clickLeft(tribool down, bool previousState) override;
  41. void clickRight(tribool down, bool previousState) override;
  42. void hover(bool on) override;
  43. void showAll(SDL_Surface * to) override;
  44. };
  45. class InteractiveArea : public CIntObject
  46. {
  47. private:
  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);//c-tor
  57. };
  58. CPicture * leftCorner, * rightCorner;
  59. std::shared_ptr<CAnimation> spells; //pictures of spells
  60. CAnimImage * spellTab; //school select
  61. CAnimImage * schools; //schools' pictures
  62. std::array< std::shared_ptr<CAnimation>, 4> schoolBorders; //schools' 'borders': [0]: air, [1]: fire, [2]: water, [3]: earth
  63. SpellArea * spellAreas[12];
  64. CLabel * mana;
  65. CGStatusBar * statusBar;
  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 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); //c-tor
  80. ~CSpellWindow(); //d-tor
  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(const SDL_KeyboardEvent & key) override;
  90. void show(SDL_Surface * to) override;
  91. };