CSpellWindow.cpp 19 KB

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