CSpellWindow.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. #include "CSpellWindow.h"
  2. #include "client/Graphics.h"
  3. #include "hch/CDefHandler.h"
  4. #include "hch/CObjectHandler.h"
  5. #include "hch/CPreGameTextHandler.h"
  6. #include "CAdvmapInterface.h"
  7. #include "CGameInfo.h"
  8. #include "SDL_Extensions.h"
  9. #include <boost/bind.hpp>
  10. #include <sstream>
  11. extern SDL_Surface * screen;
  12. extern SDL_Color tytulowy, zwykly ;
  13. extern TTF_Font *GEOR16;
  14. SpellbookInteractiveArea::SpellbookInteractiveArea(SDL_Rect & myRect, boost::function<void()> funcL, std::string textR, boost::function<void()> funcHon, boost::function<void()> funcHoff)
  15. {
  16. pos = myRect;
  17. onLeft = funcL;
  18. textOnRclick = textR;
  19. onHoverOn = funcHon;
  20. onHoverOff = funcHoff;
  21. }
  22. void SpellbookInteractiveArea::clickLeft(boost::logic::tribool down)
  23. {
  24. if(!down)
  25. {
  26. onLeft();
  27. }
  28. }
  29. void SpellbookInteractiveArea::clickRight(boost::logic::tribool down)
  30. {
  31. LOCPLINT->adventureInt->handleRightClick(textOnRclick, down, this);
  32. }
  33. void SpellbookInteractiveArea::hover(bool on)
  34. {
  35. Hoverable::hover(on);
  36. if(on)
  37. {
  38. onHoverOn();
  39. }
  40. else
  41. {
  42. onHoverOff();
  43. }
  44. }
  45. void SpellbookInteractiveArea::activate()
  46. {
  47. ClickableL::activate();
  48. ClickableR::activate();
  49. Hoverable::activate();
  50. }
  51. void SpellbookInteractiveArea::deactivate()
  52. {
  53. ClickableL::deactivate();
  54. ClickableR::deactivate();
  55. Hoverable::deactivate();
  56. }
  57. CSpellWindow::CSpellWindow(const SDL_Rect & myRect, const CGHeroInstance * myHero): selectedTab(4)
  58. {
  59. pos = myRect;
  60. background = BitmapHandler::loadBitmap("SpelBack.bmp");
  61. graphics->blueToPlayersAdv(background, myHero->tempOwner);
  62. std::stringstream mana;
  63. mana<<myHero->mana;
  64. CSDL_Ext::printAtMiddle(mana.str(), 434, 425, GEOR16, tytulowy, background);
  65. leftCorner = BitmapHandler::loadBitmap("SpelTrnL.bmp");
  66. rightCorner = BitmapHandler::loadBitmap("SpelTrnL.bmp");
  67. spells = CDefHandler::giveDef("Spells.def");
  68. spellTab = CDefHandler::giveDef("SpelTab.def");
  69. schools = CDefHandler::giveDef("Schools.def");
  70. schoolW = CDefHandler::giveDef("SplevW.def");
  71. schoolE = CDefHandler::giveDef("SplevE.def");
  72. schoolF = CDefHandler::giveDef("SplevF.def");
  73. schoolA = CDefHandler::giveDef("SplevA.def");
  74. statusBar = new CStatusBar(97, 571, "Spelroll.bmp");
  75. exitBtn = new SpellbookInteractiveArea(genRect(45, 35, 569, 407), boost::bind(&CSpellWindow::fexitb, this), CGI->preth->zelp[460].second, boost::bind(&CStatusBar::print, statusBar, (CGI->preth->zelp[460].first)), boost::bind(&CStatusBar::clear, statusBar));
  76. battleSpells = new SpellbookInteractiveArea(genRect(45, 35, 311, 407), boost::bind(&CSpellWindow::fbattleSpellsb, this), CGI->preth->zelp[453].second, boost::bind(&CStatusBar::print, statusBar, (CGI->preth->zelp[453].first)), boost::bind(&CStatusBar::clear, statusBar));
  77. adventureSpells = new SpellbookInteractiveArea(genRect(45, 35, 445, 407), boost::bind(&CSpellWindow::fadvSpellsb, this), CGI->preth->zelp[452].second, boost::bind(&CStatusBar::print, statusBar, (CGI->preth->zelp[452].first)), boost::bind(&CStatusBar::clear, statusBar));
  78. manaPoints = new SpellbookInteractiveArea(genRect(45, 35, 508, 407), boost::bind(&CSpellWindow::fmanaPtsb, this), CGI->preth->zelp[459].second, boost::bind(&CStatusBar::print, statusBar, (CGI->preth->zelp[459].first)), boost::bind(&CStatusBar::clear, statusBar));
  79. selectSpellsA = new SpellbookInteractiveArea(genRect(36, 56, 639, 96), boost::bind(&CSpellWindow::fspellsAb, this), CGI->preth->zelp[454].second, boost::bind(&CStatusBar::print, statusBar, (CGI->preth->zelp[454].first)), boost::bind(&CStatusBar::clear, statusBar));
  80. selectSpellsE = new SpellbookInteractiveArea(genRect(36, 56, 639, 153), boost::bind(&CSpellWindow::fspellsEb, this), CGI->preth->zelp[457].second, boost::bind(&CStatusBar::print, statusBar, (CGI->preth->zelp[457].first)), boost::bind(&CStatusBar::clear, statusBar));
  81. selectSpellsF = new SpellbookInteractiveArea(genRect(36, 56, 639, 212), boost::bind(&CSpellWindow::fspellsFb, this), CGI->preth->zelp[455].second, boost::bind(&CStatusBar::print, statusBar, (CGI->preth->zelp[455].first)), boost::bind(&CStatusBar::clear, statusBar));
  82. selectSpellsW = new SpellbookInteractiveArea(genRect(36, 56, 639, 272), boost::bind(&CSpellWindow::fspellsWb, this), CGI->preth->zelp[456].second, boost::bind(&CStatusBar::print, statusBar, (CGI->preth->zelp[456].first)), boost::bind(&CStatusBar::clear, statusBar));
  83. selectSpellsAll = new SpellbookInteractiveArea(genRect(36, 56, 639, 332), boost::bind(&CSpellWindow::fspellsAllb, this), CGI->preth->zelp[458].second, boost::bind(&CStatusBar::print, statusBar, (CGI->preth->zelp[458].first)), boost::bind(&CStatusBar::clear, statusBar));
  84. }
  85. CSpellWindow::~CSpellWindow()
  86. {
  87. SDL_FreeSurface(background);
  88. SDL_FreeSurface(leftCorner);
  89. SDL_FreeSurface(rightCorner);
  90. delete spells;
  91. delete spellTab;
  92. delete schools;
  93. delete schoolW;
  94. delete schoolE;
  95. delete schoolF;
  96. delete schoolA;
  97. delete exitBtn;
  98. delete battleSpells;
  99. delete adventureSpells;
  100. delete manaPoints;
  101. delete statusBar;
  102. delete selectSpellsA;
  103. delete selectSpellsE;
  104. delete selectSpellsF;
  105. delete selectSpellsW;
  106. delete selectSpellsAll;
  107. }
  108. void CSpellWindow::fexitb()
  109. {
  110. deactivate();
  111. for(int g=0; g<LOCPLINT->objsToBlit.size(); ++g)
  112. {
  113. if(dynamic_cast<CSpellWindow*>(LOCPLINT->objsToBlit[g]))
  114. {
  115. LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+g);
  116. break;
  117. }
  118. }
  119. delete this;
  120. LOCPLINT->curint->activate();
  121. }
  122. void CSpellWindow::fadvSpellsb()
  123. {
  124. }
  125. void CSpellWindow::fbattleSpellsb()
  126. {
  127. }
  128. void CSpellWindow::fmanaPtsb()
  129. {
  130. }
  131. void CSpellWindow::fspellsAb()
  132. {
  133. selectedTab = 0;
  134. }
  135. void CSpellWindow::fspellsEb()
  136. {
  137. selectedTab = 3;
  138. }
  139. void CSpellWindow::fspellsFb()
  140. {
  141. selectedTab = 1;
  142. }
  143. void CSpellWindow::fspellsWb()
  144. {
  145. selectedTab = 2;
  146. }
  147. void CSpellWindow::fspellsAllb()
  148. {
  149. selectedTab = 4;
  150. }
  151. void CSpellWindow::show(SDL_Surface *to)
  152. {
  153. if(to == NULL) //evaluating to
  154. to = screen;
  155. SDL_BlitSurface(background, NULL, to, &pos);
  156. blitAt(spellTab->ourImages[selectedTab].bitmap, 614, 96, to);
  157. statusBar->show();
  158. }
  159. void CSpellWindow::activate()
  160. {
  161. exitBtn->activate();
  162. battleSpells->activate();
  163. adventureSpells->activate();
  164. manaPoints->activate();
  165. selectSpellsA->activate();
  166. selectSpellsE->activate();
  167. selectSpellsF->activate();
  168. selectSpellsW->activate();
  169. selectSpellsAll->activate();
  170. }
  171. void CSpellWindow::deactivate()
  172. {
  173. exitBtn->deactivate();
  174. battleSpells->deactivate();
  175. adventureSpells->deactivate();
  176. manaPoints->deactivate();
  177. selectSpellsA->deactivate();
  178. selectSpellsE->deactivate();
  179. selectSpellsF->deactivate();
  180. selectSpellsW->deactivate();
  181. selectSpellsAll->deactivate();
  182. }