2
0

CSpellWindow.cpp 17 KB

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