CSpellWindow.cpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. SDL_Rect temp_rect = genRect(45, 35, 569, 407);
  76. exitBtn = new SpellbookInteractiveArea(temp_rect, 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));
  77. temp_rect = genRect(45, 35, 311, 407);
  78. battleSpells = new SpellbookInteractiveArea(temp_rect, 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));
  79. temp_rect = genRect(45, 35, 445, 407);
  80. adventureSpells = new SpellbookInteractiveArea(temp_rect, 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));
  81. temp_rect = genRect(45, 35, 508, 407);
  82. manaPoints = new SpellbookInteractiveArea(temp_rect, 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));
  83. temp_rect = genRect(36, 56, 639, 96);
  84. selectSpellsA = new SpellbookInteractiveArea(temp_rect, 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));
  85. temp_rect = genRect(36, 56, 639, 153);
  86. selectSpellsE = new SpellbookInteractiveArea(temp_rect, 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));
  87. temp_rect = genRect(36, 56, 639, 212);
  88. selectSpellsF = new SpellbookInteractiveArea(temp_rect, 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));
  89. temp_rect = genRect(36, 56, 639, 272);
  90. selectSpellsW = new SpellbookInteractiveArea(temp_rect, 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));
  91. temp_rect = genRect(36, 56, 639, 332);
  92. selectSpellsAll = new SpellbookInteractiveArea(temp_rect, 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));
  93. }
  94. CSpellWindow::~CSpellWindow()
  95. {
  96. SDL_FreeSurface(background);
  97. SDL_FreeSurface(leftCorner);
  98. SDL_FreeSurface(rightCorner);
  99. delete spells;
  100. delete spellTab;
  101. delete schools;
  102. delete schoolW;
  103. delete schoolE;
  104. delete schoolF;
  105. delete schoolA;
  106. delete exitBtn;
  107. delete battleSpells;
  108. delete adventureSpells;
  109. delete manaPoints;
  110. delete statusBar;
  111. delete selectSpellsA;
  112. delete selectSpellsE;
  113. delete selectSpellsF;
  114. delete selectSpellsW;
  115. delete selectSpellsAll;
  116. }
  117. void CSpellWindow::fexitb()
  118. {
  119. deactivate();
  120. for(int g=0; g<LOCPLINT->objsToBlit.size(); ++g)
  121. {
  122. if(dynamic_cast<CSpellWindow*>(LOCPLINT->objsToBlit[g]))
  123. {
  124. LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+g);
  125. break;
  126. }
  127. }
  128. delete this;
  129. LOCPLINT->curint->activate();
  130. }
  131. void CSpellWindow::fadvSpellsb()
  132. {
  133. }
  134. void CSpellWindow::fbattleSpellsb()
  135. {
  136. }
  137. void CSpellWindow::fmanaPtsb()
  138. {
  139. }
  140. void CSpellWindow::fspellsAb()
  141. {
  142. selectedTab = 0;
  143. }
  144. void CSpellWindow::fspellsEb()
  145. {
  146. selectedTab = 3;
  147. }
  148. void CSpellWindow::fspellsFb()
  149. {
  150. selectedTab = 1;
  151. }
  152. void CSpellWindow::fspellsWb()
  153. {
  154. selectedTab = 2;
  155. }
  156. void CSpellWindow::fspellsAllb()
  157. {
  158. selectedTab = 4;
  159. }
  160. void CSpellWindow::show(SDL_Surface *to)
  161. {
  162. if(to == NULL) //evaluating to
  163. to = screen;
  164. SDL_BlitSurface(background, NULL, to, &pos);
  165. blitAt(spellTab->ourImages[selectedTab].bitmap, 614, 96, to);
  166. statusBar->show();
  167. }
  168. void CSpellWindow::activate()
  169. {
  170. exitBtn->activate();
  171. battleSpells->activate();
  172. adventureSpells->activate();
  173. manaPoints->activate();
  174. selectSpellsA->activate();
  175. selectSpellsE->activate();
  176. selectSpellsF->activate();
  177. selectSpellsW->activate();
  178. selectSpellsAll->activate();
  179. }
  180. void CSpellWindow::deactivate()
  181. {
  182. exitBtn->deactivate();
  183. battleSpells->deactivate();
  184. adventureSpells->deactivate();
  185. manaPoints->deactivate();
  186. selectSpellsA->deactivate();
  187. selectSpellsE->deactivate();
  188. selectSpellsF->deactivate();
  189. selectSpellsW->deactivate();
  190. selectSpellsAll->deactivate();
  191. }