CSpellWindow.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  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/CGeneralTextHandler.h"
  7. #include "../CAdvmapInterface.h"
  8. #include "../CBattleInterface.h"
  9. #include "../CGameInfo.h"
  10. #include "../SDL_Extensions.h"
  11. #include "../CMessage.h"
  12. #include "../CPlayerInterface.h"
  13. #include <boost/bind.hpp>
  14. #include <sstream>
  15. /*
  16. * CSpellWindow.cpp, part of VCMI engine
  17. *
  18. * Authors: listed in file AUTHORS in main folder
  19. *
  20. * License: GNU General Public License v2.0 or later
  21. * Full text of license available in license.txt file, in main folder
  22. *
  23. */
  24. extern SDL_Surface * screen;
  25. extern SDL_Color tytulowy, zwykly ;
  26. extern TTF_Font *GEOR16;
  27. SpellbookInteractiveArea::SpellbookInteractiveArea(const SDL_Rect & myRect, boost::function<void()> funcL, const std::string & textR, boost::function<void()> funcHon, boost::function<void()> funcHoff)
  28. {
  29. pos = myRect;
  30. onLeft = funcL;
  31. textOnRclick = textR;
  32. onHoverOn = funcHon;
  33. onHoverOff = funcHoff;
  34. }
  35. void SpellbookInteractiveArea::clickLeft(boost::logic::tribool down)
  36. {
  37. if(!down)
  38. {
  39. onLeft();
  40. }
  41. }
  42. void SpellbookInteractiveArea::clickRight(boost::logic::tribool down)
  43. {
  44. LOCPLINT->adventureInt->handleRightClick(textOnRclick, down, this);
  45. }
  46. void SpellbookInteractiveArea::hover(bool on)
  47. {
  48. Hoverable::hover(on);
  49. if(on)
  50. {
  51. onHoverOn();
  52. }
  53. else
  54. {
  55. onHoverOff();
  56. }
  57. }
  58. void SpellbookInteractiveArea::activate()
  59. {
  60. ClickableL::activate();
  61. ClickableR::activate();
  62. Hoverable::activate();
  63. }
  64. void SpellbookInteractiveArea::deactivate()
  65. {
  66. ClickableL::deactivate();
  67. ClickableR::deactivate();
  68. Hoverable::deactivate();
  69. }
  70. CSpellWindow::CSpellWindow(const SDL_Rect & myRect, const CGHeroInstance * myHero):
  71. battleSpellsOnly(true),
  72. selectedTab(4),
  73. spellSite(0)
  74. {
  75. //initializing castable spells
  76. for(ui32 v=0; v<CGI->spellh->spells.size(); ++v)
  77. {
  78. if( !CGI->spellh->spells[v].creatureAbility && myHero->canCastThisSpell(&CGI->spellh->spells[v]) )
  79. mySpells.insert(v);
  80. }
  81. //initializing schools' levels
  82. for(int b=0; b<4; ++b) schoolLvls[b] = 0;
  83. for(size_t b=0; b<myHero->secSkills.size(); ++b)
  84. {
  85. switch(myHero->secSkills[b].first)
  86. {
  87. case 14: //fire magic
  88. schoolLvls[1] = myHero->secSkills[b].second;
  89. break;
  90. case 15: //air magic
  91. schoolLvls[0] = myHero->secSkills[b].second;
  92. break;
  93. case 16: //water magic
  94. schoolLvls[2] = myHero->secSkills[b].second;
  95. break;
  96. case 17: //earth magic
  97. schoolLvls[3] = myHero->secSkills[b].second;
  98. break;
  99. }
  100. }
  101. //initializing sizes of spellbook's parts
  102. for(int b=0; b<5; ++b)
  103. sitesPerTabAdv[b] = 0;
  104. for(int b=0; b<5; ++b)
  105. sitesPerTabBattle[b] = 0;
  106. for(std::set<ui32>::const_iterator g = mySpells.begin(); g!=mySpells.end(); ++g)
  107. {
  108. if(CGI->spellh->spells[*g].combatSpell)
  109. {
  110. ++(sitesPerTabBattle[4]);
  111. }
  112. else
  113. {
  114. ++(sitesPerTabAdv[4]);
  115. }
  116. if(CGI->spellh->spells[*g].air)
  117. {
  118. if(CGI->spellh->spells[*g].combatSpell)
  119. {
  120. ++(sitesPerTabBattle[0]);
  121. }
  122. else
  123. {
  124. ++(sitesPerTabAdv[0]);
  125. }
  126. }
  127. if(CGI->spellh->spells[*g].fire)
  128. {
  129. if(CGI->spellh->spells[*g].combatSpell)
  130. {
  131. ++(sitesPerTabBattle[1]);
  132. }
  133. else
  134. {
  135. ++(sitesPerTabAdv[1]);
  136. }
  137. }
  138. if(CGI->spellh->spells[*g].water)
  139. {
  140. if(CGI->spellh->spells[*g].combatSpell)
  141. {
  142. ++(sitesPerTabBattle[2]);
  143. }
  144. else
  145. {
  146. ++(sitesPerTabAdv[2]);
  147. }
  148. }
  149. if(CGI->spellh->spells[*g].earth)
  150. {
  151. if(CGI->spellh->spells[*g].combatSpell)
  152. {
  153. ++(sitesPerTabBattle[3]);
  154. }
  155. else
  156. {
  157. ++(sitesPerTabAdv[3]);
  158. }
  159. }
  160. }
  161. if(sitesPerTabAdv[4] % 12 == 0)
  162. sitesPerTabAdv[4]/=12;
  163. else
  164. sitesPerTabAdv[4] = sitesPerTabAdv[4]/12 + 1;
  165. for(int v=0; v<4; ++v)
  166. {
  167. if(sitesPerTabAdv[v] <= 10)
  168. sitesPerTabAdv[v] = 1;
  169. else
  170. {
  171. if((sitesPerTabAdv[v] - 10) % 12 == 0)
  172. sitesPerTabAdv[v] = (sitesPerTabAdv[v] - 10) / 12 + 1;
  173. else
  174. sitesPerTabAdv[v] = (sitesPerTabAdv[v] - 10) / 12 + 2;
  175. }
  176. }
  177. if(sitesPerTabBattle[4] % 12 == 0)
  178. sitesPerTabBattle[4]/=12;
  179. else
  180. sitesPerTabBattle[4] = sitesPerTabBattle[4]/12 + 1;
  181. for(int v=0; v<4; ++v)
  182. {
  183. if(sitesPerTabBattle[v] <= 10)
  184. sitesPerTabBattle[v] = 1;
  185. else
  186. {
  187. if((sitesPerTabBattle[v] - 10) % 12 == 0)
  188. sitesPerTabBattle[v] = (sitesPerTabBattle[v] - 10) / 12 + 1;
  189. else
  190. sitesPerTabBattle[v] = (sitesPerTabBattle[v] - 10) / 12 + 2;
  191. }
  192. }
  193. //numbers of spell pages computed
  194. pos = myRect;
  195. background = BitmapHandler::loadBitmap("SpelBack.bmp");
  196. graphics->blueToPlayersAdv(background, myHero->tempOwner);
  197. std::stringstream mana;
  198. mana<<myHero->mana;
  199. CSDL_Ext::printAtMiddle(mana.str(), 434, 425, GEOR16, tytulowy, background);
  200. leftCorner = BitmapHandler::loadBitmap("SpelTrnL.bmp", true);
  201. rightCorner = BitmapHandler::loadBitmap("SpelTrnR.bmp", true);
  202. spells = CDefHandler::giveDef("Spells.def");
  203. spellTab = CDefHandler::giveDef("SpelTab.def");
  204. schools = CDefHandler::giveDef("Schools.def");
  205. schoolBorders[0] = CDefHandler::giveDef("SplevA.def");
  206. schoolBorders[1] = CDefHandler::giveDef("SplevF.def");
  207. schoolBorders[2] = CDefHandler::giveDef("SplevW.def");
  208. schoolBorders[3] = CDefHandler::giveDef("SplevE.def");
  209. statusBar = new CStatusBar(7 + pos.x, 569 + pos.y, "Spelroll.bmp");
  210. SDL_Rect temp_rect = genRect(45, 35, 479 + pos.x, 405 + pos.y);
  211. exitBtn = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fexitb, this), CGI->generaltexth->zelp[460].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[460].first)), boost::bind(&CStatusBar::clear, statusBar));
  212. temp_rect = genRect(45, 35, 221 + pos.x, 405 + pos.y);
  213. battleSpells = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fbattleSpellsb, this), CGI->generaltexth->zelp[453].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[453].first)), boost::bind(&CStatusBar::clear, statusBar));
  214. temp_rect = genRect(45, 35, 355 + pos.x, 405 + pos.y);
  215. adventureSpells = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fadvSpellsb, this), CGI->generaltexth->zelp[452].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[452].first)), boost::bind(&CStatusBar::clear, statusBar));
  216. temp_rect = genRect(45, 35, 418 + pos.x, 405 + pos.y);
  217. manaPoints = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fmanaPtsb, this), CGI->generaltexth->zelp[459].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[459].first)), boost::bind(&CStatusBar::clear, statusBar));
  218. temp_rect = genRect(36, 56, 549 + pos.x, 94 + pos.y);
  219. selectSpellsA = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fspellsAb, this), CGI->generaltexth->zelp[454].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[454].first)), boost::bind(&CStatusBar::clear, statusBar));
  220. temp_rect = genRect(36, 56, 549 + pos.x, 151 + pos.y);
  221. selectSpellsE = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fspellsEb, this), CGI->generaltexth->zelp[457].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[457].first)), boost::bind(&CStatusBar::clear, statusBar));
  222. temp_rect = genRect(36, 56, 549 + pos.x, 210 + pos.y);
  223. selectSpellsF = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fspellsFb, this), CGI->generaltexth->zelp[455].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[455].first)), boost::bind(&CStatusBar::clear, statusBar));
  224. temp_rect = genRect(36, 56, 549 + pos.x, 270 + pos.y);
  225. selectSpellsW = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fspellsWb, this), CGI->generaltexth->zelp[456].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[456].first)), boost::bind(&CStatusBar::clear, statusBar));
  226. temp_rect = genRect(36, 56, 549 + pos.x, 330 + pos.y);
  227. selectSpellsAll = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fspellsAllb, this), CGI->generaltexth->zelp[458].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[458].first)), boost::bind(&CStatusBar::clear, statusBar));
  228. temp_rect = genRect(leftCorner->h, leftCorner->w, 97 + pos.x, 77 + pos.y);
  229. lCorner = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fLcornerb, this), CGI->generaltexth->zelp[450].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[450].first)), boost::bind(&CStatusBar::clear, statusBar));
  230. temp_rect = genRect(rightCorner->h, rightCorner->w, 487 + pos.x, 72 + pos.y);
  231. rCorner = new SpellbookInteractiveArea(temp_rect, boost::bind(&CSpellWindow::fRcornerb, this), CGI->generaltexth->zelp[451].second, boost::bind(&CStatusBar::print, statusBar, (CGI->generaltexth->zelp[451].first)), boost::bind(&CStatusBar::clear, statusBar));
  232. //areas for spells
  233. int xpos = 117 + pos.x, ypos = 90 + pos.y;
  234. for(int v=0; v<12; ++v)
  235. {
  236. temp_rect = genRect(65, 78, xpos, ypos);
  237. spellAreas[v] = new SpellArea(temp_rect, this);
  238. if(v == 5) //to right page
  239. {
  240. xpos = 336 + pos.x; ypos = 90 + pos.y;
  241. }
  242. else
  243. {
  244. if(v%2 == 0)
  245. {
  246. xpos+=85;
  247. }
  248. else
  249. {
  250. xpos -= 85; ypos+=97;
  251. }
  252. }
  253. }
  254. computeSpellsPerArea();
  255. }
  256. CSpellWindow::~CSpellWindow()
  257. {
  258. SDL_FreeSurface(background);
  259. SDL_FreeSurface(leftCorner);
  260. SDL_FreeSurface(rightCorner);
  261. delete spells;
  262. delete spellTab;
  263. delete schools;
  264. for(int b=0; b<4; ++b)
  265. delete schoolBorders[b];
  266. delete exitBtn;
  267. delete battleSpells;
  268. delete adventureSpells;
  269. delete manaPoints;
  270. delete statusBar;
  271. delete selectSpellsA;
  272. delete selectSpellsE;
  273. delete selectSpellsF;
  274. delete selectSpellsW;
  275. delete selectSpellsAll;
  276. delete lCorner;
  277. delete rCorner;
  278. for(int g=0; g<12; ++g)
  279. {
  280. delete spellAreas[g];
  281. }
  282. }
  283. void CSpellWindow::fexitb()
  284. {
  285. LOCPLINT->popIntTotally(this);
  286. }
  287. void CSpellWindow::fadvSpellsb()
  288. {
  289. battleSpellsOnly = false;
  290. spellSite = 0;
  291. computeSpellsPerArea();
  292. }
  293. void CSpellWindow::fbattleSpellsb()
  294. {
  295. battleSpellsOnly = true;
  296. spellSite = 0;
  297. computeSpellsPerArea();
  298. }
  299. void CSpellWindow::fmanaPtsb()
  300. {
  301. }
  302. void CSpellWindow::fspellsAb()
  303. {
  304. selectedTab = 0;
  305. spellSite = 0;
  306. computeSpellsPerArea();
  307. }
  308. void CSpellWindow::fspellsEb()
  309. {
  310. selectedTab = 3;
  311. spellSite = 0;
  312. computeSpellsPerArea();
  313. }
  314. void CSpellWindow::fspellsFb()
  315. {
  316. selectedTab = 1;
  317. spellSite = 0;
  318. computeSpellsPerArea();
  319. }
  320. void CSpellWindow::fspellsWb()
  321. {
  322. selectedTab = 2;
  323. spellSite = 0;
  324. computeSpellsPerArea();
  325. }
  326. void CSpellWindow::fspellsAllb()
  327. {
  328. selectedTab = 4;
  329. spellSite = 0;
  330. computeSpellsPerArea();
  331. }
  332. void CSpellWindow::fLcornerb()
  333. {
  334. if(spellSite>0)
  335. --spellSite;
  336. computeSpellsPerArea();
  337. }
  338. void CSpellWindow::fRcornerb()
  339. {
  340. if((spellSite + 1) < (battleSpellsOnly ? sitesPerTabBattle[selectedTab] : sitesPerTabAdv[selectedTab]))
  341. ++spellSite;
  342. computeSpellsPerArea();
  343. }
  344. void CSpellWindow::show(SDL_Surface *to)
  345. {
  346. SDL_BlitSurface(background, NULL, to, &pos);
  347. blitAt(spellTab->ourImages[selectedTab].bitmap, 524 + pos.x, 94 + pos.y, to);
  348. statusBar->show(to);
  349. //printing school images
  350. if(selectedTab!=4 && spellSite == 0)
  351. {
  352. blitAt(schools->ourImages[selectedTab].bitmap, 117 + pos.x, 74 + pos.y, 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; //TODO use me
  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(size_t c=0; c<12; ++c)
  487. {
  488. if(c<spellsCurSite.size())
  489. {
  490. spellAreas[c]->mySpell = spellsCurSite[c];
  491. }
  492. else
  493. {
  494. spellAreas[c]->mySpell = -1;
  495. }
  496. }
  497. }
  498. else
  499. {
  500. spellAreas[0]->mySpell = -1;
  501. spellAreas[1]->mySpell = -1;
  502. for(size_t c=0; c<10; ++c)
  503. {
  504. if(c<spellsCurSite.size())
  505. spellAreas[c+2]->mySpell = spellsCurSite[c];
  506. else
  507. spellAreas[c+2]->mySpell = -1;
  508. }
  509. }
  510. }
  511. void CSpellWindow::activate()
  512. {
  513. exitBtn->activate();
  514. battleSpells->activate();
  515. adventureSpells->activate();
  516. manaPoints->activate();
  517. selectSpellsA->activate();
  518. selectSpellsE->activate();
  519. selectSpellsF->activate();
  520. selectSpellsW->activate();
  521. selectSpellsAll->activate();
  522. lCorner->activate();
  523. rCorner->activate();
  524. for(int g=0; g<12; ++g)
  525. {
  526. spellAreas[g]->activate();
  527. }
  528. }
  529. void CSpellWindow::deactivate()
  530. {
  531. exitBtn->deactivate();
  532. battleSpells->deactivate();
  533. adventureSpells->deactivate();
  534. manaPoints->deactivate();
  535. selectSpellsA->deactivate();
  536. selectSpellsE->deactivate();
  537. selectSpellsF->deactivate();
  538. selectSpellsW->deactivate();
  539. selectSpellsAll->deactivate();
  540. lCorner->deactivate();
  541. rCorner->deactivate();
  542. for(int g=0; g<12; ++g)
  543. {
  544. spellAreas[g]->deactivate();
  545. }
  546. }
  547. CSpellWindow::SpellArea::SpellArea(SDL_Rect pos, CSpellWindow * owner)
  548. {
  549. this->pos = pos;
  550. this->owner = owner;
  551. }
  552. void CSpellWindow::SpellArea::clickLeft(boost::logic::tribool down)
  553. {
  554. if(!down && mySpell!=-1)
  555. {
  556. //we will cast a spell
  557. if(LOCPLINT->battleInt) //if battle window is open
  558. {
  559. LOCPLINT->battleInt->castThisSpell(mySpell);
  560. }
  561. owner->fexitb();
  562. }
  563. }
  564. void CSpellWindow::SpellArea::clickRight(boost::logic::tribool down)
  565. {
  566. if(down && mySpell != -1)
  567. {
  568. CInfoPopup *vinya = new CInfoPopup();
  569. vinya->free = true;
  570. vinya->bitmap = CMessage::drawBoxTextBitmapSub(
  571. LOCPLINT->playerID,
  572. CGI->spellh->spells[mySpell].descriptions[0], this->owner->spells->ourImages[mySpell].bitmap,
  573. CGI->spellh->spells[mySpell].name,30,30);
  574. vinya->pos.x = screen->w/2 - vinya->bitmap->w/2;
  575. vinya->pos.y = screen->h/2 - vinya->bitmap->h/2;
  576. LOCPLINT->pushInt(vinya);
  577. }
  578. }
  579. void CSpellWindow::SpellArea::hover(bool on)
  580. {
  581. Hoverable::hover(on);
  582. if(mySpell != -1)
  583. {
  584. if(on)
  585. {
  586. std::stringstream ss;
  587. ss<<CGI->spellh->spells[mySpell].name<<" ("<<CGI->generaltexth->allTexts[171+CGI->spellh->spells[mySpell].level]<<")";
  588. owner->statusBar->print(ss.str());
  589. }
  590. else
  591. {
  592. owner->statusBar->clear();
  593. }
  594. }
  595. }
  596. void CSpellWindow::SpellArea::activate()
  597. {
  598. ClickableL::activate();
  599. ClickableR::activate();
  600. Hoverable::activate();
  601. }
  602. void CSpellWindow::SpellArea::deactivate()
  603. {
  604. ClickableL::deactivate();
  605. ClickableR::deactivate();
  606. Hoverable::deactivate();
  607. }