CSpellWindow.cpp 18 KB

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