CSpellWindow.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. #include "CSpellWindow.h"
  2. #include "Graphics.h"
  3. #include "../hch/CDefHandler.h"
  4. #include "../hch/CObjectHandler.h"
  5. #include "../hch/CSpellHandler.h"
  6. #include "../hch/CPreGameTextHandler.h"
  7. #include "../hch/CGeneralTextHandler.h"
  8. #include "../CAdvmapInterface.h"
  9. #include "../CBattleInterface.h"
  10. #include "../CGameInfo.h"
  11. #include "../SDL_Extensions.h"
  12. #include "../CMessage.h"
  13. #include <boost/bind.hpp>
  14. #include <sstream>
  15. extern SDL_Surface * screen;
  16. extern SDL_Color tytulowy, zwykly ;
  17. extern TTF_Font *GEOR16;
  18. SpellbookInteractiveArea::SpellbookInteractiveArea(const SDL_Rect & myRect, boost::function<void()> funcL, const std::string & textR, boost::function<void()> funcHon, boost::function<void()> funcHoff)
  19. {
  20. pos = myRect;
  21. onLeft = funcL;
  22. textOnRclick = textR;
  23. onHoverOn = funcHon;
  24. onHoverOff = funcHoff;
  25. }
  26. void SpellbookInteractiveArea::clickLeft(boost::logic::tribool down)
  27. {
  28. if(!down)
  29. {
  30. onLeft();
  31. }
  32. }
  33. void SpellbookInteractiveArea::clickRight(boost::logic::tribool down)
  34. {
  35. LOCPLINT->adventureInt->handleRightClick(textOnRclick, down, this);
  36. }
  37. void SpellbookInteractiveArea::hover(bool on)
  38. {
  39. Hoverable::hover(on);
  40. if(on)
  41. {
  42. onHoverOn();
  43. }
  44. else
  45. {
  46. onHoverOff();
  47. }
  48. }
  49. void SpellbookInteractiveArea::activate()
  50. {
  51. ClickableL::activate();
  52. ClickableR::activate();
  53. Hoverable::activate();
  54. }
  55. void SpellbookInteractiveArea::deactivate()
  56. {
  57. ClickableL::deactivate();
  58. ClickableR::deactivate();
  59. Hoverable::deactivate();
  60. }
  61. CSpellWindow::CSpellWindow(const SDL_Rect & myRect, const CGHeroInstance * myHero): selectedTab(4), spellSite(0), battleSpellsOnly(true)
  62. {
  63. //for testing only
  64. //mySpells = myHero->spells;
  65. for(ui32 v=0; v<CGI->spellh->spells.size(); ++v)
  66. {
  67. if(!CGI->spellh->spells[v].creatureAbility)
  68. mySpells.insert(v);
  69. }
  70. for(int b=0; b<4; ++b) schoolLvls[b] = 0;
  71. for(int b=0; b<myHero->secSkills.size(); ++b)
  72. {
  73. switch(myHero->secSkills[b].first)
  74. {
  75. case 14: //fire magic
  76. schoolLvls[1] = myHero->secSkills[b].second;
  77. break;
  78. case 15: //air magic
  79. schoolLvls[0] = myHero->secSkills[b].second;
  80. break;
  81. case 16: //water magic
  82. schoolLvls[2] = myHero->secSkills[b].second;
  83. break;
  84. case 17: //earth magic
  85. schoolLvls[3] = myHero->secSkills[b].second;
  86. break;
  87. }
  88. }
  89. //initializing sizes of spellbook's parts
  90. for(int b=0; b<5; ++b)
  91. sitesPerTabAdv[b] = 0;
  92. for(int b=0; b<5; ++b)
  93. sitesPerTabBattle[b] = 0;
  94. for(std::set<ui32>::const_iterator g = mySpells.begin(); g!=mySpells.end(); ++g)
  95. {
  96. if(CGI->spellh->spells[*g].combatSpell)
  97. {
  98. ++(sitesPerTabBattle[4]);
  99. }
  100. else
  101. {
  102. ++(sitesPerTabAdv[4]);
  103. }
  104. if(CGI->spellh->spells[*g].air)
  105. {
  106. if(CGI->spellh->spells[*g].combatSpell)
  107. {
  108. ++(sitesPerTabBattle[0]);
  109. }
  110. else
  111. {
  112. ++(sitesPerTabAdv[0]);
  113. }
  114. }
  115. if(CGI->spellh->spells[*g].fire)
  116. {
  117. if(CGI->spellh->spells[*g].combatSpell)
  118. {
  119. ++(sitesPerTabBattle[1]);
  120. }
  121. else
  122. {
  123. ++(sitesPerTabAdv[1]);
  124. }
  125. }
  126. if(CGI->spellh->spells[*g].water)
  127. {
  128. if(CGI->spellh->spells[*g].combatSpell)
  129. {
  130. ++(sitesPerTabBattle[2]);
  131. }
  132. else
  133. {
  134. ++(sitesPerTabAdv[2]);
  135. }
  136. }
  137. if(CGI->spellh->spells[*g].earth)
  138. {
  139. if(CGI->spellh->spells[*g].combatSpell)
  140. {
  141. ++(sitesPerTabBattle[3]);
  142. }
  143. else
  144. {
  145. ++(sitesPerTabAdv[3]);
  146. }
  147. }
  148. }
  149. if(sitesPerTabAdv[4] % 12 == 0)
  150. sitesPerTabAdv[4]/=12;
  151. else
  152. sitesPerTabAdv[4] = sitesPerTabAdv[4]/12 + 1;
  153. for(int v=0; v<4; ++v)
  154. {
  155. if(sitesPerTabAdv[v] <= 10)
  156. sitesPerTabAdv[v] = 1;
  157. else
  158. {
  159. if((sitesPerTabAdv[v] - 10) % 12 == 0)
  160. sitesPerTabAdv[v] = (sitesPerTabAdv[v] - 10) / 12 + 1;
  161. else
  162. sitesPerTabAdv[v] = (sitesPerTabAdv[v] - 10) / 12 + 2;
  163. }
  164. }
  165. if(sitesPerTabBattle[4] % 12 == 0)
  166. sitesPerTabBattle[4]/=12;
  167. else
  168. sitesPerTabBattle[4] = sitesPerTabBattle[4]/12 + 1;
  169. for(int v=0; v<4; ++v)
  170. {
  171. if(sitesPerTabBattle[v] <= 10)
  172. sitesPerTabBattle[v] = 1;
  173. else
  174. {
  175. if((sitesPerTabBattle[v] - 10) % 12 == 0)
  176. sitesPerTabBattle[v] = (sitesPerTabBattle[v] - 10) / 12 + 1;
  177. else
  178. sitesPerTabBattle[v] = (sitesPerTabBattle[v] - 10) / 12 + 2;
  179. }
  180. }
  181. //numbers of spell pages computed
  182. pos = myRect;
  183. background = BitmapHandler::loadBitmap("SpelBack.bmp");
  184. graphics->blueToPlayersAdv(background, myHero->tempOwner);
  185. std::stringstream mana;
  186. mana<<myHero->mana;
  187. CSDL_Ext::printAtMiddle(mana.str(), 434, 425, GEOR16, tytulowy, background);
  188. leftCorner = BitmapHandler::loadBitmap("SpelTrnL.bmp", true);
  189. rightCorner = BitmapHandler::loadBitmap("SpelTrnR.bmp", true);
  190. spells = CDefHandler::giveDef("Spells.def");
  191. spellTab = CDefHandler::giveDef("SpelTab.def");
  192. schools = CDefHandler::giveDef("Schools.def");
  193. schoolBorders[0] = CDefHandler::giveDef("SplevA.def");
  194. schoolBorders[1] = CDefHandler::giveDef("SplevF.def");
  195. schoolBorders[2] = CDefHandler::giveDef("SplevW.def");
  196. schoolBorders[3] = CDefHandler::giveDef("SplevE.def");
  197. statusBar = new CStatusBar(97, 571, "Spelroll.bmp");
  198. SDL_Rect temp_rect = genRect(45, 35, 569, 407);
  199. 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));
  200. temp_rect = genRect(45, 35, 311, 407);
  201. 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));
  202. temp_rect = genRect(45, 35, 445, 407);
  203. 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));
  204. temp_rect = genRect(45, 35, 508, 407);
  205. 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));
  206. temp_rect = genRect(36, 56, 639, 96);
  207. 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));
  208. temp_rect = genRect(36, 56, 639, 153);
  209. 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));
  210. temp_rect = genRect(36, 56, 639, 212);
  211. 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));
  212. temp_rect = genRect(36, 56, 639, 272);
  213. 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));
  214. temp_rect = genRect(36, 56, 639, 332);
  215. 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));
  216. temp_rect = genRect(leftCorner->h, leftCorner->w, 187, 79);
  217. lCorner = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fLcornerb, this), CGI->preth->zelp[450].second, boost::bind(&CStatusBar::print, statusBar, (CGI->preth->zelp[450].first)), boost::bind(&CStatusBar::clear, statusBar));
  218. temp_rect = genRect(rightCorner->h, rightCorner->w, 577, 76);
  219. rCorner = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fRcornerb, this), CGI->preth->zelp[451].second, boost::bind(&CStatusBar::print, statusBar, (CGI->preth->zelp[451].first)), boost::bind(&CStatusBar::clear, statusBar));
  220. //areas for spells
  221. int xpos = 207, ypos = 92;
  222. for(int v=0; v<12; ++v)
  223. {
  224. temp_rect = genRect(65, 78, xpos, ypos);
  225. spellAreas[v] = new SpellArea(temp_rect, this);
  226. if(v == 5) //to right page
  227. {
  228. xpos = 426; ypos = 92;
  229. }
  230. else
  231. {
  232. if(v%2 == 0)
  233. {
  234. xpos+=85;
  235. }
  236. else
  237. {
  238. xpos -= 85; ypos+=97;
  239. }
  240. }
  241. }
  242. computeSpellsPerArea();
  243. }
  244. CSpellWindow::~CSpellWindow()
  245. {
  246. SDL_FreeSurface(background);
  247. SDL_FreeSurface(leftCorner);
  248. SDL_FreeSurface(rightCorner);
  249. delete spells;
  250. delete spellTab;
  251. delete schools;
  252. for(int b=0; b<4; ++b)
  253. delete schoolBorders[b];
  254. delete exitBtn;
  255. delete battleSpells;
  256. delete adventureSpells;
  257. delete manaPoints;
  258. delete statusBar;
  259. delete selectSpellsA;
  260. delete selectSpellsE;
  261. delete selectSpellsF;
  262. delete selectSpellsW;
  263. delete selectSpellsAll;
  264. delete lCorner;
  265. delete rCorner;
  266. for(int g=0; g<12; ++g)
  267. {
  268. delete spellAreas[g];
  269. }
  270. }
  271. void CSpellWindow::fexitb()
  272. {
  273. deactivate();
  274. for(int g=0; g<LOCPLINT->objsToBlit.size(); ++g)
  275. {
  276. if(dynamic_cast<CSpellWindow*>(LOCPLINT->objsToBlit[g]))
  277. {
  278. LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+g);
  279. break;
  280. }
  281. }
  282. delete this;
  283. LOCPLINT->curint->activate();
  284. }
  285. void CSpellWindow::fadvSpellsb()
  286. {
  287. battleSpellsOnly = false;
  288. spellSite = 0;
  289. computeSpellsPerArea();
  290. }
  291. void CSpellWindow::fbattleSpellsb()
  292. {
  293. battleSpellsOnly = true;
  294. spellSite = 0;
  295. computeSpellsPerArea();
  296. }
  297. void CSpellWindow::fmanaPtsb()
  298. {
  299. }
  300. void CSpellWindow::fspellsAb()
  301. {
  302. selectedTab = 0;
  303. spellSite = 0;
  304. computeSpellsPerArea();
  305. }
  306. void CSpellWindow::fspellsEb()
  307. {
  308. selectedTab = 3;
  309. spellSite = 0;
  310. computeSpellsPerArea();
  311. }
  312. void CSpellWindow::fspellsFb()
  313. {
  314. selectedTab = 1;
  315. spellSite = 0;
  316. computeSpellsPerArea();
  317. }
  318. void CSpellWindow::fspellsWb()
  319. {
  320. selectedTab = 2;
  321. spellSite = 0;
  322. computeSpellsPerArea();
  323. }
  324. void CSpellWindow::fspellsAllb()
  325. {
  326. selectedTab = 4;
  327. spellSite = 0;
  328. computeSpellsPerArea();
  329. }
  330. void CSpellWindow::fLcornerb()
  331. {
  332. if(spellSite>0)
  333. --spellSite;
  334. computeSpellsPerArea();
  335. }
  336. void CSpellWindow::fRcornerb()
  337. {
  338. if((spellSite + 1) < (battleSpellsOnly ? sitesPerTabBattle[selectedTab] : sitesPerTabAdv[selectedTab]))
  339. ++spellSite;
  340. computeSpellsPerArea();
  341. }
  342. void CSpellWindow::show(SDL_Surface *to)
  343. {
  344. if(to == NULL) //evaluating to
  345. to = screen;
  346. SDL_BlitSurface(background, NULL, to, &pos);
  347. blitAt(spellTab->ourImages[selectedTab].bitmap, 614, 96, to);
  348. statusBar->show();
  349. //printing school images
  350. if(selectedTab!=4 && spellSite == 0)
  351. {
  352. blitAt(schools->ourImages[selectedTab].bitmap, 207, 76, to);
  353. }
  354. //printing corners
  355. if(spellSite!=0)
  356. {
  357. blitAt(leftCorner, lCorner->pos.x, lCorner->pos.y, to);
  358. }
  359. if((spellSite+1) != (battleSpellsOnly ? sitesPerTabBattle[selectedTab] : sitesPerTabAdv[selectedTab]) )
  360. {
  361. blitAt(rightCorner, rCorner->pos.x, rCorner->pos.y, to);
  362. }
  363. //printing spell info
  364. for(int b=0; b<12; ++b)
  365. {
  366. if(spellAreas[b]->mySpell == -1)
  367. continue;
  368. int b2 = -1;
  369. blitAt(spells->ourImages[spellAreas[b]->mySpell].bitmap, spellAreas[b]->pos.x, spellAreas[b]->pos.y, to);
  370. Uint8 bestSchool = -1, bestslvl = 0;
  371. if(CGI->spellh->spells[spellAreas[b]->mySpell].air)
  372. if(schoolLvls[0] >= bestslvl)
  373. {
  374. bestSchool = 0;
  375. bestslvl = schoolLvls[0];
  376. }
  377. if(CGI->spellh->spells[spellAreas[b]->mySpell].fire)
  378. if(schoolLvls[1] >= bestslvl)
  379. {
  380. bestSchool = 1;
  381. bestslvl = schoolLvls[1];
  382. }
  383. if(CGI->spellh->spells[spellAreas[b]->mySpell].water)
  384. if(schoolLvls[2] >= bestslvl)
  385. {
  386. bestSchool = 2;
  387. bestslvl = schoolLvls[2];
  388. }
  389. if(CGI->spellh->spells[spellAreas[b]->mySpell].earth)
  390. if(schoolLvls[3] >= bestslvl)
  391. {
  392. bestSchool = 3;
  393. bestslvl = schoolLvls[3];
  394. }
  395. //printing border (indicates level of magic school)
  396. blitAt(schoolBorders[bestSchool]->ourImages[bestslvl].bitmap, spellAreas[b]->pos.x, spellAreas[b]->pos.y, to);
  397. //printing spell's name
  398. CSDL_Ext::printAtMiddle(CGI->spellh->spells[spellAreas[b]->mySpell].name, spellAreas[b]->pos.x + 39, spellAreas[b]->pos.y + 70, GEORM, tytulowy, to);
  399. //printing lvl
  400. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[171 + CGI->spellh->spells[spellAreas[b]->mySpell].level], spellAreas[b]->pos.x + 39, spellAreas[b]->pos.y + 82, GEORM, zwykly, to);
  401. //printing cost
  402. std::stringstream ss;
  403. ss<<CGI->generaltexth->allTexts[387]<<": "<<CGI->spellh->spells[spellAreas[b]->mySpell].costs[bestslvl];
  404. CSDL_Ext::printAtMiddle(ss.str(), spellAreas[b]->pos.x + 39, spellAreas[b]->pos.y + 94, GEORM, zwykly, to);
  405. }
  406. }
  407. class SpellbookSpellSorter
  408. {
  409. public:
  410. bool operator()(const int & a, const int & b)
  411. {
  412. CSpell A = CGI->spellh->spells[a];
  413. CSpell B = CGI->spellh->spells[b];
  414. if(A.level<B.level)
  415. return true;
  416. if(A.level>B.level)
  417. return false;
  418. if(A.air && !B.air)
  419. return true;
  420. if(!A.air && B.air)
  421. return false;
  422. if(A.fire && !B.fire)
  423. return true;
  424. if(!A.fire && B.fire)
  425. return false;
  426. if(A.water && !B.water)
  427. return true;
  428. if(!A.water && B.water)
  429. return false;
  430. if(A.earth && !B.earth)
  431. return true;
  432. if(!A.earth && B.earth)
  433. return false;
  434. return A.name < B.name;
  435. }
  436. } spellsorter;
  437. void CSpellWindow::computeSpellsPerArea()
  438. {
  439. std::vector<ui32> spellsCurSite;
  440. for(std::set<ui32>::const_iterator it = mySpells.begin(); it != mySpells.end(); ++it)
  441. {
  442. if(CGI->spellh->spells[*it].combatSpell ^ !battleSpellsOnly
  443. && ((CGI->spellh->spells[*it].air && selectedTab == 0) ||
  444. (CGI->spellh->spells[*it].fire && selectedTab == 1) ||
  445. (CGI->spellh->spells[*it].water && selectedTab == 2) ||
  446. (CGI->spellh->spells[*it].earth && selectedTab == 3) ||
  447. selectedTab == 4 )
  448. )
  449. {
  450. spellsCurSite.push_back(*it);
  451. }
  452. }
  453. std::sort(spellsCurSite.begin(), spellsCurSite.end(), spellsorter);
  454. if(selectedTab == 4)
  455. {
  456. if(spellsCurSite.size() > 12)
  457. {
  458. spellsCurSite = std::vector<ui32>(spellsCurSite.begin() + spellSite*12, spellsCurSite.end());
  459. if(spellsCurSite.size() > 12)
  460. {
  461. spellsCurSite.erase(spellsCurSite.begin()+12, spellsCurSite.end());
  462. }
  463. }
  464. }
  465. else //selectedTab == 0, 1, 2 or 3
  466. {
  467. if(spellsCurSite.size() > 10)
  468. {
  469. if(spellSite == 0)
  470. {
  471. spellsCurSite.erase(spellsCurSite.begin()+10, spellsCurSite.end());
  472. }
  473. else
  474. {
  475. spellsCurSite = std::vector<ui32>(spellsCurSite.begin() + (spellSite-1)*12 + 10, spellsCurSite.end());
  476. if(spellsCurSite.size() > 12)
  477. {
  478. spellsCurSite.erase(spellsCurSite.begin()+12, spellsCurSite.end());
  479. }
  480. }
  481. }
  482. }
  483. //applying
  484. if(selectedTab == 4 || spellSite != 0)
  485. {
  486. for(int c=0; c<12; ++c)
  487. {
  488. if(c<spellsCurSite.size())
  489. spellAreas[c]->mySpell = spellsCurSite[c];
  490. else
  491. spellAreas[c]->mySpell = -1;
  492. }
  493. }
  494. else
  495. {
  496. spellAreas[0]->mySpell = -1;
  497. spellAreas[1]->mySpell = -1;
  498. for(int c=0; c<10; ++c)
  499. {
  500. if(c<spellsCurSite.size())
  501. spellAreas[c+2]->mySpell = spellsCurSite[c];
  502. else
  503. spellAreas[c+2]->mySpell = -1;
  504. }
  505. }
  506. }
  507. void CSpellWindow::activate()
  508. {
  509. exitBtn->activate();
  510. battleSpells->activate();
  511. adventureSpells->activate();
  512. manaPoints->activate();
  513. selectSpellsA->activate();
  514. selectSpellsE->activate();
  515. selectSpellsF->activate();
  516. selectSpellsW->activate();
  517. selectSpellsAll->activate();
  518. lCorner->activate();
  519. rCorner->activate();
  520. for(int g=0; g<12; ++g)
  521. {
  522. spellAreas[g]->activate();
  523. }
  524. }
  525. void CSpellWindow::deactivate()
  526. {
  527. exitBtn->deactivate();
  528. battleSpells->deactivate();
  529. adventureSpells->deactivate();
  530. manaPoints->deactivate();
  531. selectSpellsA->deactivate();
  532. selectSpellsE->deactivate();
  533. selectSpellsF->deactivate();
  534. selectSpellsW->deactivate();
  535. selectSpellsAll->deactivate();
  536. lCorner->deactivate();
  537. rCorner->deactivate();
  538. for(int g=0; g<12; ++g)
  539. {
  540. spellAreas[g]->deactivate();
  541. }
  542. }
  543. CSpellWindow::SpellArea::SpellArea(SDL_Rect pos, CSpellWindow * owner)
  544. {
  545. this->pos = pos;
  546. this->owner = owner;
  547. }
  548. void CSpellWindow::SpellArea::clickLeft(boost::logic::tribool down)
  549. {
  550. owner->fexitb();
  551. //we will cast a spell
  552. if(dynamic_cast<CBattleInterface*>(LOCPLINT->curint)) //if battle window is open
  553. {
  554. dynamic_cast<CBattleInterface*>(LOCPLINT->curint)->castThisSpell(mySpell);
  555. }
  556. }
  557. void CSpellWindow::SpellArea::clickRight(boost::logic::tribool down)
  558. {
  559. if(down && mySpell != -1)
  560. {
  561. CInfoPopup *vinya = new CInfoPopup();
  562. vinya->free = true;
  563. vinya->bitmap = CMessage::drawBoxTextBitmapSub
  564. (LOCPLINT->playerID,
  565. CGI->spellh->spells[mySpell].descriptions[0], this->owner->spells->ourImages[mySpell].bitmap
  566. ,
  567. CGI->spellh->spells[mySpell].name,30,30);
  568. vinya->pos.x = screen->w/2 - vinya->bitmap->w/2;
  569. vinya->pos.y = screen->h/2 - vinya->bitmap->h/2;
  570. vinya->activate();
  571. }
  572. }
  573. void CSpellWindow::SpellArea::hover(bool on)
  574. {
  575. Hoverable::hover(on);
  576. if(mySpell != -1)
  577. {
  578. if(on)
  579. {
  580. std::stringstream ss;
  581. ss<<CGI->spellh->spells[mySpell].name<<" ("<<CGI->generaltexth->allTexts[171+CGI->spellh->spells[mySpell].level]<<")";
  582. owner->statusBar->print(ss.str());
  583. }
  584. else
  585. {
  586. owner->statusBar->clear();
  587. }
  588. }
  589. }
  590. void CSpellWindow::SpellArea::activate()
  591. {
  592. ClickableL::activate();
  593. ClickableR::activate();
  594. Hoverable::activate();
  595. }
  596. void CSpellWindow::SpellArea::deactivate()
  597. {
  598. ClickableL::deactivate();
  599. ClickableR::deactivate();
  600. Hoverable::deactivate();
  601. }