CSpellWindow.cpp 19 KB

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