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(
  61. const SDL_Rect & myRect,
  62. const CGHeroInstance * myHero):
  63. battleSpellsOnly(true),
  64. selectedTab(4),
  65. spellSite(0)
  66. {
  67. //XXX for testing only
  68. //mySpells = myHero->spells;
  69. for(ui32 v=0; v<CGI->spellh->spells.size(); ++v)
  70. {
  71. if(!CGI->spellh->spells[v].creatureAbility)
  72. mySpells.insert(v);
  73. }
  74. for(int b=0; b<4; ++b) schoolLvls[b] = 0;
  75. for(size_t b=0; b<myHero->secSkills.size(); ++b)
  76. {
  77. switch(myHero->secSkills[b].first)
  78. {
  79. case 14: //fire magic
  80. schoolLvls[1] = myHero->secSkills[b].second;
  81. break;
  82. case 15: //air magic
  83. schoolLvls[0] = myHero->secSkills[b].second;
  84. break;
  85. case 16: //water magic
  86. schoolLvls[2] = myHero->secSkills[b].second;
  87. break;
  88. case 17: //earth magic
  89. schoolLvls[3] = myHero->secSkills[b].second;
  90. break;
  91. }
  92. }
  93. //initializing sizes of spellbook's parts
  94. for(int b=0; b<5; ++b)
  95. sitesPerTabAdv[b] = 0;
  96. for(int b=0; b<5; ++b)
  97. sitesPerTabBattle[b] = 0;
  98. for(std::set<ui32>::const_iterator g = mySpells.begin(); g!=mySpells.end(); ++g)
  99. {
  100. if(CGI->spellh->spells[*g].combatSpell)
  101. {
  102. ++(sitesPerTabBattle[4]);
  103. }
  104. else
  105. {
  106. ++(sitesPerTabAdv[4]);
  107. }
  108. if(CGI->spellh->spells[*g].air)
  109. {
  110. if(CGI->spellh->spells[*g].combatSpell)
  111. {
  112. ++(sitesPerTabBattle[0]);
  113. }
  114. else
  115. {
  116. ++(sitesPerTabAdv[0]);
  117. }
  118. }
  119. if(CGI->spellh->spells[*g].fire)
  120. {
  121. if(CGI->spellh->spells[*g].combatSpell)
  122. {
  123. ++(sitesPerTabBattle[1]);
  124. }
  125. else
  126. {
  127. ++(sitesPerTabAdv[1]);
  128. }
  129. }
  130. if(CGI->spellh->spells[*g].water)
  131. {
  132. if(CGI->spellh->spells[*g].combatSpell)
  133. {
  134. ++(sitesPerTabBattle[2]);
  135. }
  136. else
  137. {
  138. ++(sitesPerTabAdv[2]);
  139. }
  140. }
  141. if(CGI->spellh->spells[*g].earth)
  142. {
  143. if(CGI->spellh->spells[*g].combatSpell)
  144. {
  145. ++(sitesPerTabBattle[3]);
  146. }
  147. else
  148. {
  149. ++(sitesPerTabAdv[3]);
  150. }
  151. }
  152. }
  153. if(sitesPerTabAdv[4] % 12 == 0)
  154. sitesPerTabAdv[4]/=12;
  155. else
  156. sitesPerTabAdv[4] = sitesPerTabAdv[4]/12 + 1;
  157. for(int v=0; v<4; ++v)
  158. {
  159. if(sitesPerTabAdv[v] <= 10)
  160. sitesPerTabAdv[v] = 1;
  161. else
  162. {
  163. if((sitesPerTabAdv[v] - 10) % 12 == 0)
  164. sitesPerTabAdv[v] = (sitesPerTabAdv[v] - 10) / 12 + 1;
  165. else
  166. sitesPerTabAdv[v] = (sitesPerTabAdv[v] - 10) / 12 + 2;
  167. }
  168. }
  169. if(sitesPerTabBattle[4] % 12 == 0)
  170. sitesPerTabBattle[4]/=12;
  171. else
  172. sitesPerTabBattle[4] = sitesPerTabBattle[4]/12 + 1;
  173. for(int v=0; v<4; ++v)
  174. {
  175. if(sitesPerTabBattle[v] <= 10)
  176. sitesPerTabBattle[v] = 1;
  177. else
  178. {
  179. if((sitesPerTabBattle[v] - 10) % 12 == 0)
  180. sitesPerTabBattle[v] = (sitesPerTabBattle[v] - 10) / 12 + 1;
  181. else
  182. sitesPerTabBattle[v] = (sitesPerTabBattle[v] - 10) / 12 + 2;
  183. }
  184. }
  185. //numbers of spell pages computed
  186. pos = myRect;
  187. background = BitmapHandler::loadBitmap("SpelBack.bmp");
  188. graphics->blueToPlayersAdv(background, myHero->tempOwner);
  189. std::stringstream mana;
  190. mana<<myHero->mana;
  191. CSDL_Ext::printAtMiddle(mana.str(), 434, 425, GEOR16, tytulowy, background);
  192. leftCorner = BitmapHandler::loadBitmap("SpelTrnL.bmp", true);
  193. rightCorner = BitmapHandler::loadBitmap("SpelTrnR.bmp", true);
  194. spells = CDefHandler::giveDef("Spells.def");
  195. spellTab = CDefHandler::giveDef("SpelTab.def");
  196. schools = CDefHandler::giveDef("Schools.def");
  197. schoolBorders[0] = CDefHandler::giveDef("SplevA.def");
  198. schoolBorders[1] = CDefHandler::giveDef("SplevF.def");
  199. schoolBorders[2] = CDefHandler::giveDef("SplevW.def");
  200. schoolBorders[3] = CDefHandler::giveDef("SplevE.def");
  201. statusBar = new CStatusBar(97, 571, "Spelroll.bmp");
  202. SDL_Rect temp_rect = genRect(45, 35, 569, 407);
  203. 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));
  204. temp_rect = genRect(45, 35, 311, 407);
  205. 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));
  206. temp_rect = genRect(45, 35, 445, 407);
  207. 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));
  208. temp_rect = genRect(45, 35, 508, 407);
  209. 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));
  210. temp_rect = genRect(36, 56, 639, 96);
  211. 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));
  212. temp_rect = genRect(36, 56, 639, 153);
  213. 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));
  214. temp_rect = genRect(36, 56, 639, 212);
  215. 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));
  216. temp_rect = genRect(36, 56, 639, 272);
  217. 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));
  218. temp_rect = genRect(36, 56, 639, 332);
  219. 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));
  220. temp_rect = genRect(leftCorner->h, leftCorner->w, 187, 79);
  221. 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));
  222. temp_rect = genRect(rightCorner->h, rightCorner->w, 577, 76);
  223. 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));
  224. //areas for spells
  225. int xpos = 207, ypos = 92;
  226. for(int v=0; v<12; ++v)
  227. {
  228. temp_rect = genRect(65, 78, xpos, ypos);
  229. spellAreas[v] = new SpellArea(temp_rect, this);
  230. if(v == 5) //to right page
  231. {
  232. xpos = 426; ypos = 92;
  233. }
  234. else
  235. {
  236. if(v%2 == 0)
  237. {
  238. xpos+=85;
  239. }
  240. else
  241. {
  242. xpos -= 85; ypos+=97;
  243. }
  244. }
  245. }
  246. computeSpellsPerArea();
  247. }
  248. CSpellWindow::~CSpellWindow()
  249. {
  250. SDL_FreeSurface(background);
  251. SDL_FreeSurface(leftCorner);
  252. SDL_FreeSurface(rightCorner);
  253. delete spells;
  254. delete spellTab;
  255. delete schools;
  256. for(int b=0; b<4; ++b)
  257. delete schoolBorders[b];
  258. delete exitBtn;
  259. delete battleSpells;
  260. delete adventureSpells;
  261. delete manaPoints;
  262. delete statusBar;
  263. delete selectSpellsA;
  264. delete selectSpellsE;
  265. delete selectSpellsF;
  266. delete selectSpellsW;
  267. delete selectSpellsAll;
  268. delete lCorner;
  269. delete rCorner;
  270. for(int g=0; g<12; ++g)
  271. {
  272. delete spellAreas[g];
  273. }
  274. }
  275. void CSpellWindow::fexitb()
  276. {
  277. deactivate();
  278. for(size_t g=0; g<LOCPLINT->objsToBlit.size(); ++g) //TODO what about
  279. {
  280. if(dynamic_cast<CSpellWindow*>(LOCPLINT->objsToBlit[g]))
  281. {
  282. LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+g);
  283. break;
  284. }
  285. }
  286. delete this;
  287. LOCPLINT->curint->activate();
  288. }
  289. void CSpellWindow::fadvSpellsb()
  290. {
  291. battleSpellsOnly = false;
  292. spellSite = 0;
  293. computeSpellsPerArea();
  294. }
  295. void CSpellWindow::fbattleSpellsb()
  296. {
  297. battleSpellsOnly = true;
  298. spellSite = 0;
  299. computeSpellsPerArea();
  300. }
  301. void CSpellWindow::fmanaPtsb()
  302. {
  303. }
  304. void CSpellWindow::fspellsAb()
  305. {
  306. selectedTab = 0;
  307. spellSite = 0;
  308. computeSpellsPerArea();
  309. }
  310. void CSpellWindow::fspellsEb()
  311. {
  312. selectedTab = 3;
  313. spellSite = 0;
  314. computeSpellsPerArea();
  315. }
  316. void CSpellWindow::fspellsFb()
  317. {
  318. selectedTab = 1;
  319. spellSite = 0;
  320. computeSpellsPerArea();
  321. }
  322. void CSpellWindow::fspellsWb()
  323. {
  324. selectedTab = 2;
  325. spellSite = 0;
  326. computeSpellsPerArea();
  327. }
  328. void CSpellWindow::fspellsAllb()
  329. {
  330. selectedTab = 4;
  331. spellSite = 0;
  332. computeSpellsPerArea();
  333. }
  334. void CSpellWindow::fLcornerb()
  335. {
  336. if(spellSite>0)
  337. --spellSite;
  338. computeSpellsPerArea();
  339. }
  340. void CSpellWindow::fRcornerb()
  341. {
  342. if((spellSite + 1) < (battleSpellsOnly ? sitesPerTabBattle[selectedTab] : sitesPerTabAdv[selectedTab]))
  343. ++spellSite;
  344. computeSpellsPerArea();
  345. }
  346. void CSpellWindow::show(SDL_Surface *to)
  347. {
  348. if(to == NULL) //evaluating to
  349. to = screen;
  350. SDL_BlitSurface(background, NULL, to, &pos);
  351. blitAt(spellTab->ourImages[selectedTab].bitmap, 614, 96, to);
  352. statusBar->show();
  353. //printing school images
  354. if(selectedTab!=4 && spellSite == 0)
  355. {
  356. blitAt(schools->ourImages[selectedTab].bitmap, 207, 76, to);
  357. }
  358. //printing corners
  359. if(spellSite!=0)
  360. {
  361. blitAt(leftCorner, lCorner->pos.x, lCorner->pos.y, to);
  362. }
  363. if((spellSite+1) != (battleSpellsOnly ? sitesPerTabBattle[selectedTab] : sitesPerTabAdv[selectedTab]) )
  364. {
  365. blitAt(rightCorner, rCorner->pos.x, rCorner->pos.y, to);
  366. }
  367. //printing spell info
  368. for(int b=0; b<12; ++b)
  369. {
  370. if(spellAreas[b]->mySpell == -1)
  371. continue;
  372. //int b2 = -1; //TODO use me
  373. blitAt(spells->ourImages[spellAreas[b]->mySpell].bitmap, spellAreas[b]->pos.x, spellAreas[b]->pos.y, to);
  374. Uint8 bestSchool = -1, bestslvl = 0;
  375. if(CGI->spellh->spells[spellAreas[b]->mySpell].air)
  376. if(schoolLvls[0] >= bestslvl)
  377. {
  378. bestSchool = 0;
  379. bestslvl = schoolLvls[0];
  380. }
  381. if(CGI->spellh->spells[spellAreas[b]->mySpell].fire)
  382. if(schoolLvls[1] >= bestslvl)
  383. {
  384. bestSchool = 1;
  385. bestslvl = schoolLvls[1];
  386. }
  387. if(CGI->spellh->spells[spellAreas[b]->mySpell].water)
  388. if(schoolLvls[2] >= bestslvl)
  389. {
  390. bestSchool = 2;
  391. bestslvl = schoolLvls[2];
  392. }
  393. if(CGI->spellh->spells[spellAreas[b]->mySpell].earth)
  394. if(schoolLvls[3] >= bestslvl)
  395. {
  396. bestSchool = 3;
  397. bestslvl = schoolLvls[3];
  398. }
  399. //printing border (indicates level of magic school)
  400. blitAt(schoolBorders[bestSchool]->ourImages[bestslvl].bitmap, spellAreas[b]->pos.x, spellAreas[b]->pos.y, to);
  401. //printing spell's name
  402. CSDL_Ext::printAtMiddle(CGI->spellh->spells[spellAreas[b]->mySpell].name, spellAreas[b]->pos.x + 39, spellAreas[b]->pos.y + 70, GEORM, tytulowy, to);
  403. //printing lvl
  404. 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);
  405. //printing cost
  406. std::stringstream ss;
  407. ss<<CGI->generaltexth->allTexts[387]<<": "<<CGI->spellh->spells[spellAreas[b]->mySpell].costs[bestslvl];
  408. CSDL_Ext::printAtMiddle(ss.str(), spellAreas[b]->pos.x + 39, spellAreas[b]->pos.y + 94, GEORM, zwykly, to);
  409. }
  410. }
  411. class SpellbookSpellSorter
  412. {
  413. public:
  414. bool operator()(const int & a, const int & b)
  415. {
  416. CSpell A = CGI->spellh->spells[a];
  417. CSpell B = CGI->spellh->spells[b];
  418. if(A.level<B.level)
  419. return true;
  420. if(A.level>B.level)
  421. return false;
  422. if(A.air && !B.air)
  423. return true;
  424. if(!A.air && B.air)
  425. return false;
  426. if(A.fire && !B.fire)
  427. return true;
  428. if(!A.fire && B.fire)
  429. return false;
  430. if(A.water && !B.water)
  431. return true;
  432. if(!A.water && B.water)
  433. return false;
  434. if(A.earth && !B.earth)
  435. return true;
  436. if(!A.earth && B.earth)
  437. return false;
  438. return A.name < B.name;
  439. }
  440. } spellsorter;
  441. void CSpellWindow::computeSpellsPerArea()
  442. {
  443. std::vector<ui32> spellsCurSite;
  444. for(std::set<ui32>::const_iterator it = mySpells.begin(); it != mySpells.end(); ++it)
  445. {
  446. if(CGI->spellh->spells[*it].combatSpell ^ !battleSpellsOnly
  447. && ((CGI->spellh->spells[*it].air && selectedTab == 0) ||
  448. (CGI->spellh->spells[*it].fire && selectedTab == 1) ||
  449. (CGI->spellh->spells[*it].water && selectedTab == 2) ||
  450. (CGI->spellh->spells[*it].earth && selectedTab == 3) ||
  451. selectedTab == 4 )
  452. )
  453. {
  454. spellsCurSite.push_back(*it);
  455. }
  456. }
  457. std::sort(spellsCurSite.begin(), spellsCurSite.end(), spellsorter);
  458. if(selectedTab == 4)
  459. {
  460. if(spellsCurSite.size() > 12)
  461. {
  462. spellsCurSite = std::vector<ui32>(spellsCurSite.begin() + spellSite*12, spellsCurSite.end());
  463. if(spellsCurSite.size() > 12)
  464. {
  465. spellsCurSite.erase(spellsCurSite.begin()+12, spellsCurSite.end());
  466. }
  467. }
  468. }
  469. else //selectedTab == 0, 1, 2 or 3
  470. {
  471. if(spellsCurSite.size() > 10)
  472. {
  473. if(spellSite == 0)
  474. {
  475. spellsCurSite.erase(spellsCurSite.begin()+10, spellsCurSite.end());
  476. }
  477. else
  478. {
  479. spellsCurSite = std::vector<ui32>(spellsCurSite.begin() + (spellSite-1)*12 + 10, spellsCurSite.end());
  480. if(spellsCurSite.size() > 12)
  481. {
  482. spellsCurSite.erase(spellsCurSite.begin()+12, spellsCurSite.end());
  483. }
  484. }
  485. }
  486. }
  487. //applying
  488. if(selectedTab == 4 || spellSite != 0)
  489. {
  490. for(size_t c=0; c<12; ++c)
  491. {
  492. if(c<spellsCurSite.size()) {
  493. spellAreas[c]->mySpell = spellsCurSite[c];
  494. }
  495. else {
  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. }