CSpellWindow.cpp 19 KB

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