CSpellWindow.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  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. LOCPLINT->popIntTotally(this);
  276. }
  277. void CSpellWindow::fadvSpellsb()
  278. {
  279. battleSpellsOnly = false;
  280. spellSite = 0;
  281. computeSpellsPerArea();
  282. }
  283. void CSpellWindow::fbattleSpellsb()
  284. {
  285. battleSpellsOnly = true;
  286. spellSite = 0;
  287. computeSpellsPerArea();
  288. }
  289. void CSpellWindow::fmanaPtsb()
  290. {
  291. }
  292. void CSpellWindow::fspellsAb()
  293. {
  294. selectedTab = 0;
  295. spellSite = 0;
  296. computeSpellsPerArea();
  297. }
  298. void CSpellWindow::fspellsEb()
  299. {
  300. selectedTab = 3;
  301. spellSite = 0;
  302. computeSpellsPerArea();
  303. }
  304. void CSpellWindow::fspellsFb()
  305. {
  306. selectedTab = 1;
  307. spellSite = 0;
  308. computeSpellsPerArea();
  309. }
  310. void CSpellWindow::fspellsWb()
  311. {
  312. selectedTab = 2;
  313. spellSite = 0;
  314. computeSpellsPerArea();
  315. }
  316. void CSpellWindow::fspellsAllb()
  317. {
  318. selectedTab = 4;
  319. spellSite = 0;
  320. computeSpellsPerArea();
  321. }
  322. void CSpellWindow::fLcornerb()
  323. {
  324. if(spellSite>0)
  325. --spellSite;
  326. computeSpellsPerArea();
  327. }
  328. void CSpellWindow::fRcornerb()
  329. {
  330. if((spellSite + 1) < (battleSpellsOnly ? sitesPerTabBattle[selectedTab] : sitesPerTabAdv[selectedTab]))
  331. ++spellSite;
  332. computeSpellsPerArea();
  333. }
  334. void CSpellWindow::show(SDL_Surface *to)
  335. {
  336. SDL_BlitSurface(background, NULL, to, &pos);
  337. blitAt(spellTab->ourImages[selectedTab].bitmap, 524 + pos.x, 94 + pos.y, to);
  338. statusBar->show(to);
  339. //printing school images
  340. if(selectedTab!=4 && spellSite == 0)
  341. {
  342. blitAt(schools->ourImages[selectedTab].bitmap, 117 + pos.x, 74 + pos.y, to);
  343. }
  344. //printing corners
  345. if(spellSite!=0)
  346. {
  347. blitAt(leftCorner, lCorner->pos.x, lCorner->pos.y, to);
  348. }
  349. if((spellSite+1) != (battleSpellsOnly ? sitesPerTabBattle[selectedTab] : sitesPerTabAdv[selectedTab]) )
  350. {
  351. blitAt(rightCorner, rCorner->pos.x, rCorner->pos.y, to);
  352. }
  353. //printing spell info
  354. for(int b=0; b<12; ++b)
  355. {
  356. if(spellAreas[b]->mySpell == -1)
  357. continue;
  358. //int b2 = -1; //TODO use me
  359. blitAt(spells->ourImages[spellAreas[b]->mySpell].bitmap, spellAreas[b]->pos.x, spellAreas[b]->pos.y, to);
  360. Uint8 bestSchool = -1, bestslvl = 0;
  361. if(CGI->spellh->spells[spellAreas[b]->mySpell].air)
  362. if(schoolLvls[0] >= bestslvl)
  363. {
  364. bestSchool = 0;
  365. bestslvl = schoolLvls[0];
  366. }
  367. if(CGI->spellh->spells[spellAreas[b]->mySpell].fire)
  368. if(schoolLvls[1] >= bestslvl)
  369. {
  370. bestSchool = 1;
  371. bestslvl = schoolLvls[1];
  372. }
  373. if(CGI->spellh->spells[spellAreas[b]->mySpell].water)
  374. if(schoolLvls[2] >= bestslvl)
  375. {
  376. bestSchool = 2;
  377. bestslvl = schoolLvls[2];
  378. }
  379. if(CGI->spellh->spells[spellAreas[b]->mySpell].earth)
  380. if(schoolLvls[3] >= bestslvl)
  381. {
  382. bestSchool = 3;
  383. bestslvl = schoolLvls[3];
  384. }
  385. //printing border (indicates level of magic school)
  386. blitAt(schoolBorders[bestSchool]->ourImages[bestslvl].bitmap, spellAreas[b]->pos.x, spellAreas[b]->pos.y, to);
  387. //printing spell's name
  388. CSDL_Ext::printAtMiddle(CGI->spellh->spells[spellAreas[b]->mySpell].name, spellAreas[b]->pos.x + 39, spellAreas[b]->pos.y + 70, GEORM, tytulowy, to);
  389. //printing lvl
  390. 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);
  391. //printing cost
  392. std::stringstream ss;
  393. ss<<CGI->generaltexth->allTexts[387]<<": "<<CGI->spellh->spells[spellAreas[b]->mySpell].costs[bestslvl];
  394. CSDL_Ext::printAtMiddle(ss.str(), spellAreas[b]->pos.x + 39, spellAreas[b]->pos.y + 94, GEORM, zwykly, to);
  395. }
  396. }
  397. class SpellbookSpellSorter
  398. {
  399. public:
  400. bool operator()(const int & a, const int & b)
  401. {
  402. CSpell A = CGI->spellh->spells[a];
  403. CSpell B = CGI->spellh->spells[b];
  404. if(A.level<B.level)
  405. return true;
  406. if(A.level>B.level)
  407. return false;
  408. if(A.air && !B.air)
  409. return true;
  410. if(!A.air && B.air)
  411. return false;
  412. if(A.fire && !B.fire)
  413. return true;
  414. if(!A.fire && B.fire)
  415. return false;
  416. if(A.water && !B.water)
  417. return true;
  418. if(!A.water && B.water)
  419. return false;
  420. if(A.earth && !B.earth)
  421. return true;
  422. if(!A.earth && B.earth)
  423. return false;
  424. return A.name < B.name;
  425. }
  426. } spellsorter;
  427. void CSpellWindow::computeSpellsPerArea()
  428. {
  429. std::vector<ui32> spellsCurSite;
  430. for(std::set<ui32>::const_iterator it = mySpells.begin(); it != mySpells.end(); ++it)
  431. {
  432. if(CGI->spellh->spells[*it].combatSpell ^ !battleSpellsOnly
  433. && ((CGI->spellh->spells[*it].air && selectedTab == 0) ||
  434. (CGI->spellh->spells[*it].fire && selectedTab == 1) ||
  435. (CGI->spellh->spells[*it].water && selectedTab == 2) ||
  436. (CGI->spellh->spells[*it].earth && selectedTab == 3) ||
  437. selectedTab == 4 )
  438. )
  439. {
  440. spellsCurSite.push_back(*it);
  441. }
  442. }
  443. std::sort(spellsCurSite.begin(), spellsCurSite.end(), spellsorter);
  444. if(selectedTab == 4)
  445. {
  446. if(spellsCurSite.size() > 12)
  447. {
  448. spellsCurSite = std::vector<ui32>(spellsCurSite.begin() + spellSite*12, spellsCurSite.end());
  449. if(spellsCurSite.size() > 12)
  450. {
  451. spellsCurSite.erase(spellsCurSite.begin()+12, spellsCurSite.end());
  452. }
  453. }
  454. }
  455. else //selectedTab == 0, 1, 2 or 3
  456. {
  457. if(spellsCurSite.size() > 10)
  458. {
  459. if(spellSite == 0)
  460. {
  461. spellsCurSite.erase(spellsCurSite.begin()+10, spellsCurSite.end());
  462. }
  463. else
  464. {
  465. spellsCurSite = std::vector<ui32>(spellsCurSite.begin() + (spellSite-1)*12 + 10, spellsCurSite.end());
  466. if(spellsCurSite.size() > 12)
  467. {
  468. spellsCurSite.erase(spellsCurSite.begin()+12, spellsCurSite.end());
  469. }
  470. }
  471. }
  472. }
  473. //applying
  474. if(selectedTab == 4 || spellSite != 0)
  475. {
  476. for(size_t c=0; c<12; ++c)
  477. {
  478. if(c<spellsCurSite.size())
  479. {
  480. spellAreas[c]->mySpell = spellsCurSite[c];
  481. }
  482. else
  483. {
  484. spellAreas[c]->mySpell = -1;
  485. }
  486. }
  487. }
  488. else
  489. {
  490. spellAreas[0]->mySpell = -1;
  491. spellAreas[1]->mySpell = -1;
  492. for(size_t c=0; c<10; ++c)
  493. {
  494. if(c<spellsCurSite.size())
  495. spellAreas[c+2]->mySpell = spellsCurSite[c];
  496. else
  497. spellAreas[c+2]->mySpell = -1;
  498. }
  499. }
  500. }
  501. void CSpellWindow::activate()
  502. {
  503. exitBtn->activate();
  504. battleSpells->activate();
  505. adventureSpells->activate();
  506. manaPoints->activate();
  507. selectSpellsA->activate();
  508. selectSpellsE->activate();
  509. selectSpellsF->activate();
  510. selectSpellsW->activate();
  511. selectSpellsAll->activate();
  512. lCorner->activate();
  513. rCorner->activate();
  514. for(int g=0; g<12; ++g)
  515. {
  516. spellAreas[g]->activate();
  517. }
  518. }
  519. void CSpellWindow::deactivate()
  520. {
  521. exitBtn->deactivate();
  522. battleSpells->deactivate();
  523. adventureSpells->deactivate();
  524. manaPoints->deactivate();
  525. selectSpellsA->deactivate();
  526. selectSpellsE->deactivate();
  527. selectSpellsF->deactivate();
  528. selectSpellsW->deactivate();
  529. selectSpellsAll->deactivate();
  530. lCorner->deactivate();
  531. rCorner->deactivate();
  532. for(int g=0; g<12; ++g)
  533. {
  534. spellAreas[g]->deactivate();
  535. }
  536. }
  537. CSpellWindow::SpellArea::SpellArea(SDL_Rect pos, CSpellWindow * owner)
  538. {
  539. this->pos = pos;
  540. this->owner = owner;
  541. }
  542. void CSpellWindow::SpellArea::clickLeft(boost::logic::tribool down)
  543. {
  544. if(!down && mySpell!=-1)
  545. {
  546. //we will cast a spell
  547. if(LOCPLINT->battleInt) //if battle window is open
  548. {
  549. LOCPLINT->battleInt->castThisSpell(mySpell);
  550. }
  551. owner->fexitb();
  552. }
  553. }
  554. void CSpellWindow::SpellArea::clickRight(boost::logic::tribool down)
  555. {
  556. if(down && mySpell != -1)
  557. {
  558. CInfoPopup *vinya = new CInfoPopup();
  559. vinya->free = true;
  560. vinya->bitmap = CMessage::drawBoxTextBitmapSub(
  561. LOCPLINT->playerID,
  562. CGI->spellh->spells[mySpell].descriptions[0], this->owner->spells->ourImages[mySpell].bitmap,
  563. CGI->spellh->spells[mySpell].name,30,30);
  564. vinya->pos.x = screen->w/2 - vinya->bitmap->w/2;
  565. vinya->pos.y = screen->h/2 - vinya->bitmap->h/2;
  566. LOCPLINT->pushInt(vinya);
  567. }
  568. }
  569. void CSpellWindow::SpellArea::hover(bool on)
  570. {
  571. Hoverable::hover(on);
  572. if(mySpell != -1)
  573. {
  574. if(on)
  575. {
  576. std::stringstream ss;
  577. ss<<CGI->spellh->spells[mySpell].name<<" ("<<CGI->generaltexth->allTexts[171+CGI->spellh->spells[mySpell].level]<<")";
  578. owner->statusBar->print(ss.str());
  579. }
  580. else
  581. {
  582. owner->statusBar->clear();
  583. }
  584. }
  585. }
  586. void CSpellWindow::SpellArea::activate()
  587. {
  588. ClickableL::activate();
  589. ClickableR::activate();
  590. Hoverable::activate();
  591. }
  592. void CSpellWindow::SpellArea::deactivate()
  593. {
  594. ClickableL::deactivate();
  595. ClickableR::deactivate();
  596. Hoverable::deactivate();
  597. }