CSpellWindow.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #pragma once
  2. #include "UIFramework/CIntObject.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. class CDefHandler;
  14. struct SDL_Rect;
  15. class CGHeroInstance;
  16. class CStatusBar;
  17. class CPlayerInterface;
  18. /// Spellbook button is used by the spell window class
  19. class SpellbookInteractiveArea : public CIntObject
  20. {
  21. private:
  22. boost::function<void()> onLeft;
  23. std::string textOnRclick;
  24. boost::function<void()> onHoverOn;
  25. boost::function<void()> onHoverOff;
  26. CPlayerInterface * myInt;
  27. public:
  28. void clickLeft(tribool down, bool previousState);
  29. void clickRight(tribool down, bool previousState);
  30. void hover(bool on);
  31. SpellbookInteractiveArea(const SDL_Rect & myRect, boost::function<void()> funcL, const std::string & textR,
  32. boost::function<void()> funcHon, boost::function<void()> funcHoff, CPlayerInterface * _myInt);//c-tor
  33. };
  34. /// The spell window
  35. class CSpellWindow : public CIntObject
  36. {
  37. private:
  38. class SpellArea : public CIntObject
  39. {
  40. public:
  41. int mySpell;
  42. int schoolLevel; //range: 0 none, 3 - expert
  43. int whichSchool; //0 - air magic, 1 - fire magic, 2 - water magic, 3 - earth magic,
  44. int spellCost;
  45. CSpellWindow * owner;
  46. SpellArea(SDL_Rect pos, CSpellWindow * owner);
  47. void setSpell(int spellID);
  48. void clickLeft(tribool down, bool previousState);
  49. void clickRight(tribool down, bool previousState);
  50. void hover(bool on);
  51. void showAll(SDL_Surface *to);
  52. };
  53. SDL_Surface * background, * leftCorner, * rightCorner;
  54. CDefHandler * spells, //pictures of spells
  55. * spellTab, //school select
  56. * schools, //schools' pictures
  57. * schoolBorders [4]; //schools' 'borders': [0]: air, [1]: fire, [2]: water, [3]: earth
  58. SpellbookInteractiveArea * exitBtn, * battleSpells, * adventureSpells, * manaPoints;
  59. SpellbookInteractiveArea * selectSpellsA, * selectSpellsE, * selectSpellsF, * selectSpellsW, * selectSpellsAll;
  60. SpellbookInteractiveArea * lCorner, * rCorner;
  61. SpellArea * spellAreas[12];
  62. CStatusBar * statusBar;
  63. Uint8 sitesPerTabAdv[5];
  64. Uint8 sitesPerTabBattle[5];
  65. bool battleSpellsOnly; //if true, only battle spells are displayed; if false, only adventure map spells are displayed
  66. Uint8 selectedTab; // 0 - air magic, 1 - fire magic, 2 - water magic, 3 - earth magic, 4 - all schools
  67. Uint8 currentPage; //changes when corners are clicked
  68. std::set<ui32> mySpells; //all spels in this spellbook
  69. const CGHeroInstance * myHero; //hero whose spells are presented
  70. void computeSpellsPerArea(); //recalculates spellAreas::mySpell
  71. void turnPageLeft();
  72. void turnPageRight();
  73. CPlayerInterface * myInt;
  74. public:
  75. CSpellWindow(const SDL_Rect & myRect, const CGHeroInstance * _myHero, CPlayerInterface * _myInt, bool openOnBattleSpells = true); //c-tor
  76. ~CSpellWindow(); //d-tor
  77. void fexitb();
  78. void fadvSpellsb();
  79. void fbattleSpellsb();
  80. void fmanaPtsb();
  81. void fLcornerb();
  82. void fRcornerb();
  83. void selectSchool(int school); //schools: 0 - air magic, 1 - fire magic, 2 - water magic, 3 - earth magic, 4 - all schools
  84. Uint8 pagesWithinCurrentTab();
  85. void keyPressed(const SDL_KeyboardEvent & key);
  86. void activate();
  87. void deactivate();
  88. void showAll(SDL_Surface * to);
  89. void teleportTo(int town, const CGHeroInstance * hero);
  90. };