CSpellWindow.h 3.4 KB

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