CSpellWindow.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  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. }
  295. computeSpellsPerArea();
  296. }
  297. void CSpellWindow::fbattleSpellsb()
  298. {
  299. if (battleSpellsOnly == false) {
  300. turnPageLeft();
  301. battleSpellsOnly = true;
  302. spellSite = 0;
  303. }
  304. computeSpellsPerArea();
  305. }
  306. void CSpellWindow::fmanaPtsb()
  307. {
  308. }
  309. void CSpellWindow::fspellsAb()
  310. {
  311. if (selectedTab != 0) {
  312. turnPageRight();
  313. selectedTab = 0;
  314. spellSite = 0;
  315. }
  316. computeSpellsPerArea();
  317. }
  318. void CSpellWindow::fspellsEb()
  319. {
  320. if (selectedTab != 3) {
  321. turnPageRight();
  322. selectedTab = 3;
  323. spellSite = 0;
  324. }
  325. computeSpellsPerArea();
  326. }
  327. void CSpellWindow::fspellsFb()
  328. {
  329. if (selectedTab != 1) {
  330. turnPageRight();
  331. selectedTab = 1;
  332. spellSite = 0;
  333. }
  334. computeSpellsPerArea();
  335. }
  336. void CSpellWindow::fspellsWb()
  337. {
  338. if (selectedTab != 2) {
  339. turnPageRight();
  340. selectedTab = 2;
  341. spellSite = 0;
  342. }
  343. computeSpellsPerArea();
  344. }
  345. void CSpellWindow::fspellsAllb()
  346. {
  347. if (selectedTab != 4) {
  348. turnPageRight();
  349. selectedTab = 4;
  350. spellSite = 0;
  351. }
  352. computeSpellsPerArea();
  353. }
  354. void CSpellWindow::fLcornerb()
  355. {
  356. if(spellSite>0) {
  357. turnPageLeft();
  358. --spellSite;
  359. }
  360. computeSpellsPerArea();
  361. }
  362. void CSpellWindow::fRcornerb()
  363. {
  364. if((spellSite + 1) < (battleSpellsOnly ? sitesPerTabBattle[selectedTab] : sitesPerTabAdv[selectedTab])) {
  365. turnPageRight();
  366. ++spellSite;
  367. }
  368. computeSpellsPerArea();
  369. }
  370. void CSpellWindow::show(SDL_Surface *to)
  371. {
  372. SDL_BlitSurface(background, NULL, to, &pos);
  373. blitAt(spellTab->ourImages[selectedTab].bitmap, 524 + pos.x, 88 + pos.y, to);
  374. statusBar->show(to);
  375. //printing school images
  376. if(selectedTab!=4 && spellSite == 0)
  377. {
  378. blitAt(schools->ourImages[selectedTab].bitmap, 117 + pos.x, 74 + pos.y, to);
  379. }
  380. //printing corners
  381. if(spellSite!=0)
  382. {
  383. blitAt(leftCorner, lCorner->pos.x, lCorner->pos.y, to);
  384. }
  385. if((spellSite+1) < (battleSpellsOnly ? sitesPerTabBattle[selectedTab] : sitesPerTabAdv[selectedTab]) )
  386. {
  387. blitAt(rightCorner, rCorner->pos.x, rCorner->pos.y, to);
  388. }
  389. //printing spell info
  390. for(int b=0; b<12; ++b)
  391. {
  392. if(spellAreas[b]->mySpell == -1)
  393. continue;
  394. //int b2 = -1; //TODO use me
  395. blitAt(spells->ourImages[spellAreas[b]->mySpell].bitmap, spellAreas[b]->pos.x, spellAreas[b]->pos.y, to);
  396. Uint8 bestSchool = -1, bestslvl = 0;
  397. if(CGI->spellh->spells[spellAreas[b]->mySpell].air)
  398. if(schoolLvls[0] >= bestslvl)
  399. {
  400. bestSchool = 0;
  401. bestslvl = schoolLvls[0];
  402. }
  403. if(CGI->spellh->spells[spellAreas[b]->mySpell].fire)
  404. if(schoolLvls[1] >= bestslvl)
  405. {
  406. bestSchool = 1;
  407. bestslvl = schoolLvls[1];
  408. }
  409. if(CGI->spellh->spells[spellAreas[b]->mySpell].water)
  410. if(schoolLvls[2] >= bestslvl)
  411. {
  412. bestSchool = 2;
  413. bestslvl = schoolLvls[2];
  414. }
  415. if(CGI->spellh->spells[spellAreas[b]->mySpell].earth)
  416. if(schoolLvls[3] >= bestslvl)
  417. {
  418. bestSchool = 3;
  419. bestslvl = schoolLvls[3];
  420. }
  421. //printing border (indicates level of magic school)
  422. blitAt(schoolBorders[bestSchool]->ourImages[bestslvl].bitmap, spellAreas[b]->pos.x, spellAreas[b]->pos.y, to);
  423. //printing spell's name
  424. CSDL_Ext::printAtMiddle(CGI->spellh->spells[spellAreas[b]->mySpell].name, spellAreas[b]->pos.x + 39, spellAreas[b]->pos.y + 70, GEORM, tytulowy, to);
  425. //printing lvl
  426. 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);
  427. //printing cost
  428. std::ostringstream ss;
  429. ss<<CGI->generaltexth->allTexts[387]<<": "<<CGI->spellh->spells[spellAreas[b]->mySpell].costs[bestslvl];
  430. CSDL_Ext::printAtMiddle(ss.str(), spellAreas[b]->pos.x + 39, spellAreas[b]->pos.y + 94, GEORM, zwykly, to);
  431. }
  432. }
  433. class SpellbookSpellSorter
  434. {
  435. public:
  436. bool operator()(const int & a, const int & b)
  437. {
  438. CSpell A = CGI->spellh->spells[a];
  439. CSpell B = CGI->spellh->spells[b];
  440. if(A.level<B.level)
  441. return true;
  442. if(A.level>B.level)
  443. return false;
  444. if(A.air && !B.air)
  445. return true;
  446. if(!A.air && B.air)
  447. return false;
  448. if(A.fire && !B.fire)
  449. return true;
  450. if(!A.fire && B.fire)
  451. return false;
  452. if(A.water && !B.water)
  453. return true;
  454. if(!A.water && B.water)
  455. return false;
  456. if(A.earth && !B.earth)
  457. return true;
  458. if(!A.earth && B.earth)
  459. return false;
  460. return A.name < B.name;
  461. }
  462. } spellsorter;
  463. void CSpellWindow::computeSpellsPerArea()
  464. {
  465. std::vector<ui32> spellsCurSite;
  466. for(std::set<ui32>::const_iterator it = mySpells.begin(); it != mySpells.end(); ++it)
  467. {
  468. if(CGI->spellh->spells[*it].combatSpell ^ !battleSpellsOnly
  469. && ((CGI->spellh->spells[*it].air && selectedTab == 0) ||
  470. (CGI->spellh->spells[*it].fire && selectedTab == 1) ||
  471. (CGI->spellh->spells[*it].water && selectedTab == 2) ||
  472. (CGI->spellh->spells[*it].earth && selectedTab == 3) ||
  473. selectedTab == 4 )
  474. )
  475. {
  476. spellsCurSite.push_back(*it);
  477. }
  478. }
  479. std::sort(spellsCurSite.begin(), spellsCurSite.end(), spellsorter);
  480. if(selectedTab == 4)
  481. {
  482. if(spellsCurSite.size() > 12)
  483. {
  484. spellsCurSite = std::vector<ui32>(spellsCurSite.begin() + spellSite*12, spellsCurSite.end());
  485. if(spellsCurSite.size() > 12)
  486. {
  487. spellsCurSite.erase(spellsCurSite.begin()+12, spellsCurSite.end());
  488. }
  489. }
  490. }
  491. else //selectedTab == 0, 1, 2 or 3
  492. {
  493. if(spellsCurSite.size() > 10)
  494. {
  495. if(spellSite == 0)
  496. {
  497. spellsCurSite.erase(spellsCurSite.begin()+10, spellsCurSite.end());
  498. }
  499. else
  500. {
  501. spellsCurSite = std::vector<ui32>(spellsCurSite.begin() + (spellSite-1)*12 + 10, spellsCurSite.end());
  502. if(spellsCurSite.size() > 12)
  503. {
  504. spellsCurSite.erase(spellsCurSite.begin()+12, spellsCurSite.end());
  505. }
  506. }
  507. }
  508. }
  509. //applying
  510. if(selectedTab == 4 || spellSite != 0)
  511. {
  512. for(size_t c=0; c<12; ++c)
  513. {
  514. if(c<spellsCurSite.size())
  515. {
  516. spellAreas[c]->mySpell = spellsCurSite[c];
  517. }
  518. else
  519. {
  520. spellAreas[c]->mySpell = -1;
  521. }
  522. }
  523. }
  524. else
  525. {
  526. spellAreas[0]->mySpell = -1;
  527. spellAreas[1]->mySpell = -1;
  528. for(size_t c=0; c<10; ++c)
  529. {
  530. if(c<spellsCurSite.size())
  531. spellAreas[c+2]->mySpell = spellsCurSite[c];
  532. else
  533. spellAreas[c+2]->mySpell = -1;
  534. }
  535. }
  536. }
  537. void CSpellWindow::activate()
  538. {
  539. exitBtn->activate();
  540. battleSpells->activate();
  541. adventureSpells->activate();
  542. manaPoints->activate();
  543. selectSpellsA->activate();
  544. selectSpellsE->activate();
  545. selectSpellsF->activate();
  546. selectSpellsW->activate();
  547. selectSpellsAll->activate();
  548. lCorner->activate();
  549. rCorner->activate();
  550. for(int g=0; g<12; ++g)
  551. {
  552. spellAreas[g]->activate();
  553. }
  554. }
  555. void CSpellWindow::deactivate()
  556. {
  557. exitBtn->deactivate();
  558. battleSpells->deactivate();
  559. adventureSpells->deactivate();
  560. manaPoints->deactivate();
  561. selectSpellsA->deactivate();
  562. selectSpellsE->deactivate();
  563. selectSpellsF->deactivate();
  564. selectSpellsW->deactivate();
  565. selectSpellsAll->deactivate();
  566. lCorner->deactivate();
  567. rCorner->deactivate();
  568. for(int g=0; g<12; ++g)
  569. {
  570. spellAreas[g]->deactivate();
  571. }
  572. }
  573. void CSpellWindow::turnPageLeft()
  574. {
  575. // Note: video decoders are different, and one is buggy.
  576. #ifndef _WIN32
  577. if (CGI->videoh->open("PGTRNLFT.SMK", pos.x+13, pos.y+14))
  578. {
  579. while(CGI->videoh->nextFrame())
  580. {
  581. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  582. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  583. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  584. }
  585. CGI->videoh->close();
  586. }
  587. #else
  588. CGI->videoh->openAndPlayVideo("PGTRNLFT.SMK", pos.x+13, pos.y+15, screen);
  589. #endif
  590. //#ifdef _WIN32
  591. // const int y = pos.y+15;
  592. //
  593. //#endif
  594. //
  595. // if (CGI->videoh->open("PGTRNLFT.SMK", pos.x+13, y)) {
  596. // while(CGI->videoh->nextFrame()) {
  597. // SDL_framerateDelay(LOCPLINT->mainFPSmng);
  598. //#ifndef _WIN32
  599. // SDL_framerateDelay(LOCPLINT->mainFPSmng);
  600. // SDL_framerateDelay(LOCPLINT->mainFPSmng);
  601. //#endif
  602. // }
  603. // CGI->videoh->close();
  604. // }
  605. }
  606. void CSpellWindow::turnPageRight()
  607. {
  608. // Note: video decoders are different, and one is buggy.
  609. #ifndef _WIN32
  610. if (CGI->videoh->open("PGTRNRGH.SMK", pos.x+13, pos.y+14))
  611. {
  612. while(CGI->videoh->nextFrame())
  613. {
  614. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  615. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  616. SDL_framerateDelay(LOCPLINT->mainFPSmng);
  617. }
  618. CGI->videoh->close();
  619. }
  620. #else
  621. CGI->videoh->openAndPlayVideo("PGTRNRGH.SMK", pos.x+13, pos.y+15, screen);
  622. #endif
  623. //#ifdef _WIN32
  624. // const int y = pos.y+15;
  625. //#else
  626. // const int y = pos.y+14;
  627. //#endif
  628. //
  629. // if (CGI->videoh->open("PGTRNRGH.SMK", pos.x+13, y)) {
  630. // while(CGI->videoh->nextFrame()) {
  631. // SDL_framerateDelay(LOCPLINT->mainFPSmng);
  632. //#ifndef _WIN32
  633. // SDL_framerateDelay(LOCPLINT->mainFPSmng);
  634. // SDL_framerateDelay(LOCPLINT->mainFPSmng);
  635. //#endif
  636. // }
  637. // CGI->videoh->close();
  638. // }
  639. }
  640. CSpellWindow::SpellArea::SpellArea(SDL_Rect pos, CSpellWindow * owner)
  641. {
  642. this->pos = pos;
  643. this->owner = owner;
  644. }
  645. void CSpellWindow::SpellArea::clickLeft(boost::logic::tribool down)
  646. {
  647. if(!down && mySpell!=-1)
  648. {
  649. //we will cast a spell
  650. if(LOCPLINT->battleInt) //if battle window is open
  651. {
  652. LOCPLINT->battleInt->castThisSpell(mySpell);
  653. }
  654. owner->fexitb();
  655. }
  656. }
  657. void CSpellWindow::SpellArea::clickRight(boost::logic::tribool down)
  658. {
  659. if(down && mySpell != -1)
  660. {
  661. CInfoPopup *vinya = new CInfoPopup();
  662. vinya->free = true;
  663. vinya->bitmap = CMessage::drawBoxTextBitmapSub(
  664. LOCPLINT->playerID,
  665. CGI->spellh->spells[mySpell].descriptions[0], this->owner->spells->ourImages[mySpell].bitmap,
  666. CGI->spellh->spells[mySpell].name,30,30);
  667. vinya->pos.x = screen->w/2 - vinya->bitmap->w/2;
  668. vinya->pos.y = screen->h/2 - vinya->bitmap->h/2;
  669. LOCPLINT->pushInt(vinya);
  670. }
  671. }
  672. void CSpellWindow::SpellArea::hover(bool on)
  673. {
  674. Hoverable::hover(on);
  675. if(mySpell != -1)
  676. {
  677. if(on)
  678. {
  679. std::ostringstream ss;
  680. ss<<CGI->spellh->spells[mySpell].name<<" ("<<CGI->generaltexth->allTexts[171+CGI->spellh->spells[mySpell].level]<<")";
  681. owner->statusBar->print(ss.str());
  682. }
  683. else
  684. {
  685. owner->statusBar->clear();
  686. }
  687. }
  688. }
  689. void CSpellWindow::SpellArea::activate()
  690. {
  691. ClickableL::activate();
  692. ClickableR::activate();
  693. Hoverable::activate();
  694. }
  695. void CSpellWindow::SpellArea::deactivate()
  696. {
  697. ClickableL::deactivate();
  698. ClickableR::deactivate();
  699. Hoverable::deactivate();
  700. }