CSpellWindow.cpp 18 KB

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