CHeroWindow.cpp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  1. #include "stdafx.h"
  2. #include "global.h"
  3. #include "CHeroWindow.h"
  4. #include "CGameInfo.h"
  5. #include "hch\CHeroHandler.h"
  6. #include "hch\CGeneralTextHandler.h"
  7. #include "SDL.h"
  8. #include "SDL_Extensions.h"
  9. #include "CAdvmapInterface.h"
  10. #include "AdventureMapButton.h"
  11. #include "CMessage.h"
  12. #include <sstream>
  13. extern SDL_Surface * screen;
  14. extern TTF_Font * GEOR16;
  15. CHeroWindow::CHeroWindow(int playerColor): artFeet(0), artHead(0), artLHand(0),
  16. artLRing(0), artMach1(0), artMach2(0), artMach3(0), artMach4(0), artMisc1(0),
  17. artMisc2(0), artMisc3(0), artMisc4(0), artMisc5(0), artNeck(0), artRhand(0),
  18. artRRing(0), artShoulders(0), artSpellBook(0), artTorso(0),
  19. backpackPos(0), player(playerColor)
  20. {
  21. background = CGI->bitmaph->loadBitmap("HEROSCR4.bmp");
  22. CSDL_Ext::blueToPlayersAdv(background, playerColor);
  23. pos.x = 65;
  24. pos.y = 8;
  25. pos.h = background->h;
  26. pos.w = background->w;
  27. curBack = NULL;
  28. curHero = NULL;
  29. quitButton = new AdventureMapButton<CHeroWindow>(std::string(), std::string(), &CHeroWindow::quit, 674, 524, "hsbtns.def", this);
  30. dismissButton = new AdventureMapButton<CHeroWindow>(std::string(), std::string(), &CHeroWindow::dismissCurrent, 519, 437, "hsbtns2.def", this);
  31. questlogButton = new AdventureMapButton<CHeroWindow>(std::string(), std::string(), &CHeroWindow::questlog, 379, 437, "hsbtns4.def", this);
  32. gar1button = new AdventureMapButton<CHeroWindow>(std::string(), std::string(), &CHeroWindow::gar1, 546, 491, "hsbtns6.def", this);
  33. gar2button = new AdventureMapButton<CHeroWindow>(std::string(), std::string(), &CHeroWindow::gar2, 604, 491, "hsbtns8.def", this);
  34. gar3button = new AdventureMapButton<CHeroWindow>(std::string(), std::string(), &CHeroWindow::gar3, 546, 527, "hsbtns7.def", this);
  35. gar4button = new AdventureMapButton<CHeroWindow>(std::string(), std::string(), &CHeroWindow::gar4, 604, 527, "hsbtns9.def", this);
  36. leftArtRoll = new AdventureMapButton<CHeroWindow>(std::string(), std::string(), &CHeroWindow::leftArtRoller, 379, 364, "hsbtns3.def", this);
  37. rightArtRoll = new AdventureMapButton<CHeroWindow>(std::string(), std::string(), &CHeroWindow::rightArtRoller, 632, 364, "hsbtns5.def", this);
  38. for(int g=0; g<8; ++g)
  39. {
  40. //heroList.push_back(new AdventureMapButton<CHeroWindow>(std::string(), std::string(), &CHeroWindow::switchHero, 677, 95+g*54, "hsbtns5.def", this));
  41. heroListMi.push_back(new LClickableAreaHero());
  42. heroListMi[g]->pos.x = 677;
  43. heroListMi[g]->pos.y = 95+g*54;
  44. heroListMi[g]->pos.h = 32;
  45. heroListMi[g]->pos.w = 48;
  46. heroListMi[g]->owner = this;
  47. heroListMi[g]->id = g;
  48. }
  49. skillpics = CGI->spriteh->giveDef("pskil42.def");
  50. flags = CGI->spriteh->giveDef("CREST58.DEF");
  51. //areas
  52. portraitArea = new LRClickableAreaWText();
  53. portraitArea->pos.x = 83;
  54. portraitArea->pos.y = 26;
  55. portraitArea->pos.w = 58;
  56. portraitArea->pos.h = 64;
  57. for(int v=0; v<4; ++v)
  58. {
  59. primSkillAreas.push_back(new LRClickableAreaWTextComp());
  60. primSkillAreas[v]->pos.x = 95 + 70*v;
  61. primSkillAreas[v]->pos.y = 111;
  62. primSkillAreas[v]->pos.w = 42;
  63. primSkillAreas[v]->pos.h = 42;
  64. primSkillAreas[v]->text = CGI->generaltexth->arraytxt[2+v].substr(1, CGI->generaltexth->arraytxt[2+v].size()-2);
  65. primSkillAreas[v]->type = v;
  66. primSkillAreas[v]->bonus = -1; // to be initilized when hero is being set
  67. primSkillAreas[v]->baseType = 0;
  68. }
  69. expArea = new LRClickableAreaWText();
  70. expArea->pos.x = 83;
  71. expArea->pos.y = 236;
  72. expArea->pos.w = 136;
  73. expArea->pos.h = 42;
  74. spellPointsArea = new LRClickableAreaWText();
  75. spellPointsArea->pos.x = 227;
  76. spellPointsArea->pos.y = 236;
  77. spellPointsArea->pos.w = 136;
  78. spellPointsArea->pos.h = 42;
  79. for(int i=0; i<8; ++i)
  80. {
  81. secSkillAreas.push_back(new LRClickableAreaWTextComp());
  82. secSkillAreas[i]->pos.x = (i%2==0) ? (83) : (227);
  83. secSkillAreas[i]->pos.y = 284 + 48 * (i/2);
  84. secSkillAreas[i]->pos.w = 136;
  85. secSkillAreas[i]->pos.h = 42;
  86. secSkillAreas[i]->baseType = 1;
  87. }
  88. }
  89. CHeroWindow::~CHeroWindow()
  90. {
  91. SDL_FreeSurface(background);
  92. delete quitButton;
  93. delete dismissButton;
  94. delete questlogButton;
  95. delete gar1button;
  96. delete gar2button;
  97. delete gar3button;
  98. delete gar4button;
  99. delete leftArtRoll;
  100. delete rightArtRoll;
  101. for(int g=0; g<heroListMi.size(); ++g)
  102. delete heroListMi[g];
  103. if(curBack)
  104. SDL_FreeSurface(curBack);
  105. delete skillpics;
  106. delete flags;
  107. delete artFeet;
  108. delete artHead;
  109. delete artLHand;
  110. delete artLRing;
  111. delete artMach1;
  112. delete artMach2;
  113. delete artMach3;
  114. delete artMach4;
  115. delete artMisc1;
  116. delete artMisc2;
  117. delete artMisc3;
  118. delete artMisc4;
  119. delete artMisc5;
  120. delete artNeck;
  121. delete artRhand;
  122. delete artRRing;
  123. delete artShoulders;
  124. delete artSpellBook;
  125. delete artTorso;
  126. for(int g=0; g<backpack.size(); ++g)
  127. {
  128. delete backpack[g];
  129. }
  130. backpack.clear();
  131. delete portraitArea;
  132. delete expArea;
  133. delete spellPointsArea;
  134. for(int v=0; v<primSkillAreas.size(); ++v)
  135. {
  136. delete primSkillAreas[v];
  137. }
  138. for(int v=0; v<secSkillAreas.size(); ++v)
  139. {
  140. delete secSkillAreas[v];
  141. }
  142. }
  143. void CHeroWindow::show(SDL_Surface *to)
  144. {
  145. if(!to)
  146. to=ekran;
  147. if(curBack)
  148. blitAt(curBack,pos.x,pos.y,to);
  149. quitButton->show();
  150. dismissButton->show();
  151. questlogButton->show();
  152. gar1button->show();
  153. gar2button->show();
  154. gar3button->show();
  155. gar4button->show();
  156. leftArtRoll->show();
  157. rightArtRoll->show();
  158. artFeet->show(to);
  159. artHead->show(to);
  160. artLHand->show(to);
  161. artLRing->show(to);
  162. artMach1->show(to);
  163. artMach2->show(to);
  164. artMach3->show(to);
  165. artMach4->show(to);
  166. artMisc1->show(to);
  167. artMisc2->show(to);
  168. artMisc3->show(to);
  169. artMisc4->show(to);
  170. artMisc5->show(to);
  171. artNeck->show(to);
  172. artRhand->show(to);
  173. artRRing->show(to);
  174. artShoulders->show(to);
  175. artSpellBook->show(to);
  176. artTorso->show(to);
  177. for(int d=0; d<backpack.size(); ++d)
  178. {
  179. backpack[d]->show(to);
  180. }
  181. }
  182. void CHeroWindow::setHero(const CGHeroInstance *hero)
  183. {
  184. if(!hero) //something strange... no hero? it shouldn't happen
  185. {
  186. return;
  187. }
  188. curHero = hero;
  189. portraitArea->text = hero->biography;
  190. for(int g=0; g<primSkillAreas.size(); ++g)
  191. {
  192. primSkillAreas[g]->bonus = hero->primSkills[g];
  193. }
  194. for(int g=0; g<hero->secSkills.size(); ++g)
  195. {
  196. secSkillAreas[g]->type = hero->secSkills[g].first;
  197. secSkillAreas[g]->bonus = hero->secSkills[g].second;
  198. std::string hlp;
  199. switch(hero->secSkills[g].second)
  200. {
  201. case 0: //basic level
  202. hlp = CGI->abilh->abilities[ hero->secSkills[g].first ]->basicText;
  203. secSkillAreas[g]->text = hlp.substr(1, hlp.size()-2);
  204. break;
  205. case 1: //adv level
  206. hlp = CGI->abilh->abilities[ hero->secSkills[g].first ]->advText;
  207. secSkillAreas[g]->text = hlp.substr(1, hlp.size()-2);
  208. break;
  209. case 2: //expert level
  210. hlp = CGI->abilh->abilities[ hero->secSkills[g].first ]->expText;
  211. secSkillAreas[g]->text = hlp.substr(1, hlp.size()-2);
  212. break;
  213. }
  214. }
  215. char * th = new char[200];
  216. sprintf(th, CGI->generaltexth->allTexts[2].substr(1, CGI->generaltexth->allTexts[2].size()-2).c_str(), hero->level, CGI->heroh->reqExp(hero->level+1), hero->exp);
  217. expArea->text = std::string(th);
  218. delete [] th;
  219. th = new char[400];
  220. sprintf(th, CGI->generaltexth->allTexts[205].substr(1, CGI->generaltexth->allTexts[205].size()-2).c_str(), hero->name.c_str(), hero->mana, hero->primSkills[3]*10);
  221. spellPointsArea->text = std::string(th);
  222. delete [] th;
  223. delete artFeet;
  224. delete artHead;
  225. delete artLHand;
  226. delete artLRing;
  227. delete artMach1;
  228. delete artMach2;
  229. delete artMach3;
  230. delete artMach4;
  231. delete artMisc1;
  232. delete artMisc2;
  233. delete artMisc3;
  234. delete artMisc4;
  235. delete artMisc5;
  236. delete artNeck;
  237. delete artRhand;
  238. delete artRRing;
  239. delete artShoulders;
  240. delete artSpellBook;
  241. delete artTorso;
  242. for(int g=0; g<backpack.size(); ++g)
  243. {
  244. delete backpack[g];
  245. }
  246. backpack.clear();
  247. artFeet = new CArtPlace(hero->artFeet);
  248. artFeet->pos.x = 515;
  249. artFeet->pos.y = 295;
  250. artFeet->pos.h = artFeet->pos.w = 44;
  251. if(hero->artFeet)
  252. artFeet->text = hero->artFeet->description;
  253. else
  254. artFeet->text = std::string();
  255. artHead = new CArtPlace(hero->artHead);
  256. artHead->pos.x = 509;
  257. artHead->pos.y = 30;
  258. artHead->pos.h = artHead->pos.w = 44;
  259. if(hero->artHead)
  260. artHead->text = hero->artHead->description;
  261. else
  262. artHead->text = std::string();
  263. artLHand = new CArtPlace(hero->artLHand);
  264. artLHand->pos.x = 564;
  265. artLHand->pos.y = 183;
  266. artLHand->pos.h = artLHand->pos.w = 44;
  267. if(hero->artLHand)
  268. artLHand->text = hero->artLHand->description;
  269. else
  270. artLHand->text = std::string();
  271. artLRing = new CArtPlace(hero->artLRing);
  272. artLRing->pos.x = 610;
  273. artLRing->pos.y = 183;
  274. artLRing->pos.h = artLRing->pos.w = 44;
  275. if(hero->artLRing)
  276. artLRing->text = hero->artLRing->description;
  277. else
  278. artLRing->text = std::string();
  279. artMach1 = new CArtPlace(hero->artMach1);
  280. artMach1->pos.x = 564;
  281. artMach1->pos.y = 30;
  282. artMach1->pos.h = artMach1->pos.w = 44;
  283. if(hero->artMach1)
  284. artMach1->text = hero->artMach1->description;
  285. else
  286. artMach1->text = std::string();
  287. artMach2 = new CArtPlace(hero->artMach2);
  288. artMach2->pos.x = 610;
  289. artMach2->pos.y = 30;
  290. artMach2->pos.h = artMach2->pos.w = 44;
  291. if(hero->artMach2)
  292. artMach2->text = hero->artMach2->description;
  293. else
  294. artMach2->text = std::string();
  295. artMach3 = new CArtPlace(hero->artMach3);
  296. artMach3->pos.x = 610;
  297. artMach3->pos.y = 76;
  298. artMach3->pos.h = artMach3->pos.w = 44;
  299. if(hero->artMach3)
  300. artMach3->text = hero->artMach3->description;
  301. else
  302. artMach3->text = std::string();
  303. artMach4 = new CArtPlace(hero->artMach4);
  304. artMach4->pos.x = 610;
  305. artMach4->pos.y = 122;
  306. artMach4->pos.h = artMach4->pos.w = 44;
  307. if(hero->artMach4)
  308. artMach4->text = hero->artMach4->description;
  309. else
  310. artMach4->text = std::string();
  311. artMisc1 = new CArtPlace(hero->artMisc1);
  312. artMisc1->pos.x = 383;
  313. artMisc1->pos.y = 143;
  314. artMisc1->pos.h = artMisc1->pos.w = 44;
  315. if(hero->artMisc1)
  316. artMisc1->text = hero->artMisc1->description;
  317. else
  318. artMisc1->text = std::string();
  319. artMisc2 = new CArtPlace(hero->artMisc2);
  320. artMisc2->pos.x = 399;
  321. artMisc2->pos.y = 194;
  322. artMisc2->pos.h = artMisc2->pos.w = 44;
  323. if(hero->artMisc2)
  324. artMisc2->text = hero->artMisc2->description;
  325. else
  326. artMisc2->text = std::string();
  327. artMisc3 = new CArtPlace(hero->artMisc3);
  328. artMisc3->pos.x = 415;
  329. artMisc3->pos.y = 245;
  330. artMisc3->pos.h = artMisc3->pos.w = 44;
  331. if(hero->artMisc3)
  332. artMisc3->text = hero->artMisc3->description;
  333. else
  334. artMisc3->text = std::string();
  335. artMisc4 = new CArtPlace(hero->artMisc4);
  336. artMisc4->pos.x = 431;
  337. artMisc4->pos.y = 296;
  338. artMisc4->pos.h = artMisc4->pos.w = 44;
  339. if(hero->artMisc4)
  340. artMisc4->text = hero->artMisc4->description;
  341. else
  342. artMisc4->text = std::string();
  343. artMisc5 = new CArtPlace(hero->artMisc5);
  344. artMisc5->pos.x = 381;
  345. artMisc5->pos.y = 296;
  346. artMisc5->pos.h = artMisc5->pos.w = 44;
  347. if(hero->artMisc5)
  348. artMisc5->text = hero->artMisc5->description;
  349. else
  350. artMisc5->text = std::string();
  351. artNeck = new CArtPlace(hero->artNeck);
  352. artNeck->pos.x = 508;
  353. artNeck->pos.y = 79;
  354. artNeck->pos.h = artNeck->pos.w = 44;
  355. if(hero->artNeck)
  356. artNeck->text = hero->artNeck->description;
  357. else
  358. artNeck->text = std::string();
  359. artRhand = new CArtPlace(hero->artRhand);
  360. artRhand->pos.x = 383;
  361. artRhand->pos.y = 68;
  362. artRhand->pos.h = artRhand->pos.w = 44;
  363. if(hero->artRhand)
  364. artRhand->text = hero->artRhand->description;
  365. else
  366. artRhand->text = std::string();
  367. artRRing = new CArtPlace(hero->artRRing);
  368. artRRing->pos.x = 431;
  369. artRRing->pos.y = 68;
  370. artRRing->pos.h = artRRing->pos.w = 44;
  371. if(hero->artRRing)
  372. artRRing->text = hero->artRRing->description;
  373. else
  374. artRRing->text = std::string();
  375. artShoulders = new CArtPlace(hero->artShoulders);
  376. artShoulders->pos.x = 567;
  377. artShoulders->pos.y = 240;
  378. artShoulders->pos.h = artShoulders->pos.w = 44;
  379. if(hero->artShoulders)
  380. artShoulders->text = hero->artShoulders->description;
  381. else
  382. artShoulders->text = std::string();
  383. artSpellBook = new CArtPlace(hero->artSpellBook);
  384. artSpellBook->pos.x = 610;
  385. artSpellBook->pos.y = 310;
  386. artSpellBook->pos.h = artSpellBook->pos.w = 44;
  387. if(hero->artSpellBook)
  388. artSpellBook->text = hero->artSpellBook->description;
  389. else
  390. artSpellBook->text = std::string();
  391. artTorso = new CArtPlace(hero->artTorso);
  392. artTorso->pos.x = 509;
  393. artTorso->pos.y = 130;
  394. artTorso->pos.h = artTorso->pos.w = 44;
  395. if(hero->artTorso)
  396. artTorso->text = hero->artTorso->description;
  397. else
  398. artTorso->text = std::string();
  399. for(int s=0; s<5 && s<curHero->artifacts.size(); ++s)
  400. {
  401. CArtPlace * add = new CArtPlace(curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ]);
  402. add->pos.x = 403 + 46*s;
  403. add->pos.y = 365;
  404. add->pos.h = add->pos.w = 44;
  405. if(hero->artifacts[s])
  406. add->text = hero->artifacts[s]->description;
  407. else
  408. add->text = std::string();
  409. backpack.push_back(add);
  410. }
  411. redrawCurBack();
  412. }
  413. void CHeroWindow::quit()
  414. {
  415. for(int i=0; i<LOCPLINT->objsToBlit.size(); ++i)
  416. {
  417. if( dynamic_cast<CHeroWindow*>( LOCPLINT->objsToBlit[i] ) )
  418. {
  419. LOCPLINT->objsToBlit.erase(LOCPLINT->objsToBlit.begin()+i);
  420. }
  421. }
  422. deactivate();
  423. LOCPLINT->adventureInt->show();
  424. SDL_FreeSurface(curBack);
  425. curBack = NULL;
  426. /*for(int v=0; v<LOCPLINT->lclickable.size(); ++v)
  427. {
  428. if(dynamic_cast<CArtPlace*>(LOCPLINT->lclickable[v]))
  429. LOCPLINT->lclickable.erase(LOCPLINT->lclickable.begin()+v);
  430. }*/
  431. delete artFeet;
  432. artFeet = 0;
  433. delete artHead;
  434. artHead = 0;
  435. delete artLHand;
  436. artLHand = 0;
  437. delete artLRing;
  438. artLRing = 0;
  439. delete artMach1;
  440. artMach1 = 0;
  441. delete artMach2;
  442. artMach2 = 0;
  443. delete artMach3;
  444. artMach3 = 0;
  445. delete artMach4;
  446. artMach4 = 0;
  447. delete artMisc1;
  448. artMisc1 = 0;
  449. delete artMisc2;
  450. artMisc2 = 0;
  451. delete artMisc3;
  452. artMisc3 = 0;
  453. delete artMisc4;
  454. artMisc4 = 0;
  455. delete artMisc5;
  456. artMisc5 = 0;
  457. delete artNeck;
  458. artNeck = 0;
  459. delete artRhand;
  460. artRhand = 0;
  461. delete artRRing;
  462. artRRing = 0;
  463. delete artShoulders;
  464. artShoulders = 0;
  465. delete artSpellBook;
  466. artSpellBook = 0;
  467. delete artTorso;
  468. artTorso = 0;
  469. for(int g=0; g<backpack.size(); ++g)
  470. {
  471. delete backpack[g];
  472. }
  473. backpack.clear();
  474. }
  475. void CHeroWindow::activate()
  476. {
  477. LOCPLINT->curint = this;
  478. quitButton->activate();
  479. dismissButton->activate();
  480. questlogButton->activate();
  481. gar1button->activate();
  482. gar2button->activate();
  483. gar3button->activate();
  484. gar4button->activate();
  485. leftArtRoll->activate();
  486. rightArtRoll->activate();
  487. portraitArea->activate();
  488. expArea->activate();
  489. spellPointsArea->activate();
  490. for(int v=0; v<primSkillAreas.size(); ++v)
  491. {
  492. primSkillAreas[v]->activate();
  493. }
  494. for(int v=0; v<curHero->secSkills.size(); ++v)
  495. {
  496. secSkillAreas[v]->activate();
  497. }
  498. redrawCurBack();
  499. if(artFeet)
  500. artFeet->activate();
  501. if(artHead)
  502. artHead->activate();
  503. if(artLHand)
  504. artLHand->activate();
  505. if(artLRing)
  506. artLRing->activate();
  507. if(artMach1)
  508. artMach1->activate();
  509. if(artMach2)
  510. artMach2->activate();
  511. if(artMach3)
  512. artMach3->activate();
  513. if(artMach4)
  514. artMach4->activate();
  515. if(artMisc1)
  516. artMisc1->activate();
  517. if(artMisc2)
  518. artMisc2->activate();
  519. if(artMisc3)
  520. artMisc3->activate();
  521. if(artMisc4)
  522. artMisc4->activate();
  523. if(artMisc5)
  524. artMisc5->activate();
  525. if(artNeck)
  526. artNeck->activate();
  527. if(artRhand)
  528. artRhand->activate();
  529. if(artRRing)
  530. artRRing->activate();
  531. if(artShoulders)
  532. artShoulders->activate();
  533. if(artSpellBook)
  534. artSpellBook->activate();
  535. if(artTorso)
  536. artTorso->activate();
  537. for(int f=0; f<backpack.size(); ++f)
  538. {
  539. if(backpack[f])
  540. backpack[f]->activate();
  541. }
  542. for(int e=0; e<heroListMi.size(); ++e)
  543. {
  544. heroListMi[e]->activate();
  545. }
  546. //LOCPLINT->lclickable.push_back(artFeet);
  547. }
  548. void CHeroWindow::deactivate()
  549. {
  550. quitButton->deactivate();
  551. dismissButton->deactivate();
  552. questlogButton->deactivate();
  553. gar1button->deactivate();
  554. gar2button->deactivate();
  555. gar3button->deactivate();
  556. gar4button->deactivate();
  557. leftArtRoll->deactivate();
  558. rightArtRoll->deactivate();
  559. portraitArea->deactivate();
  560. expArea->deactivate();
  561. spellPointsArea->deactivate();
  562. for(int v=0; v<primSkillAreas.size(); ++v)
  563. {
  564. primSkillAreas[v]->deactivate();
  565. }
  566. for(int v=0; v<curHero->secSkills.size(); ++v)
  567. {
  568. secSkillAreas[v]->deactivate();
  569. }
  570. if(artFeet)
  571. artFeet->deactivate();
  572. if(artHead)
  573. artHead->deactivate();
  574. if(artLHand)
  575. artLHand->deactivate();
  576. if(artLRing)
  577. artLRing->deactivate();
  578. if(artMach1)
  579. artMach1->deactivate();
  580. if(artMach2)
  581. artMach2->deactivate();
  582. if(artMach3)
  583. artMach3->deactivate();
  584. if(artMach4)
  585. artMach4->deactivate();
  586. if(artMisc1)
  587. artMisc1->deactivate();
  588. if(artMisc2)
  589. artMisc2->deactivate();
  590. if(artMisc3)
  591. artMisc3->deactivate();
  592. if(artMisc4)
  593. artMisc4->deactivate();
  594. if(artMisc5)
  595. artMisc5->deactivate();
  596. if(artNeck)
  597. artNeck->deactivate();
  598. if(artRhand)
  599. artRhand->deactivate();
  600. if(artRRing)
  601. artRRing->deactivate();
  602. if(artShoulders)
  603. artShoulders->deactivate();
  604. if(artSpellBook)
  605. artSpellBook->deactivate();
  606. if(artTorso)
  607. artTorso->deactivate();
  608. for(int f=0; f<backpack.size(); ++f)
  609. {
  610. if(backpack[f])
  611. backpack[f]->deactivate();
  612. }
  613. for(int e=0; e<heroListMi.size(); ++e)
  614. {
  615. heroListMi[e]->deactivate();
  616. }
  617. }
  618. void CHeroWindow::dismissCurrent()
  619. {
  620. LOCPLINT->cb->dismissHero(curHero);
  621. quit();
  622. }
  623. void CHeroWindow::questlog()
  624. {
  625. }
  626. void CHeroWindow::gar1()
  627. {
  628. }
  629. void CHeroWindow::gar2()
  630. {
  631. }
  632. void CHeroWindow::gar3()
  633. {
  634. }
  635. void CHeroWindow::gar4()
  636. {
  637. }
  638. void CHeroWindow::leftArtRoller()
  639. {
  640. if(curHero->artifacts.size()>5) //if it is <=5, we have nothing to scroll
  641. {
  642. backpackPos+=curHero->artifacts.size()-1; //set new offset
  643. for(int s=0; s<5 && s<curHero->artifacts.size(); ++s) //set new data
  644. {
  645. backpack[s]->ourArt = curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ];
  646. backpack[s]->text = backpack[s]->ourArt->description;
  647. }
  648. }
  649. }
  650. void CHeroWindow::rightArtRoller()
  651. {
  652. if(curHero->artifacts.size()>5) //if it is <=5, we have nothing to scroll
  653. {
  654. backpackPos+=1; //set new offset
  655. for(int s=0; s<5 && s<curHero->artifacts.size(); ++s) //set new data
  656. {
  657. backpack[s]->ourArt = curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ];
  658. backpack[s]->text = backpack[s]->ourArt->description;
  659. }
  660. }
  661. }
  662. void CHeroWindow::switchHero()
  663. {
  664. //int y;
  665. //SDL_GetMouseState(NULL, &y);
  666. //for(int g=0; g<heroListMi.size(); ++g)
  667. //{
  668. // if(y>=94+54*g)
  669. // {
  670. // //quit();
  671. // setHero(LOCPLINT->cb->getHeroInfo(player, g, false));
  672. // //LOCPLINT->openHeroWindow(curHero);
  673. // redrawCurBack();
  674. // }
  675. //}
  676. }
  677. void CHeroWindow::redrawCurBack()
  678. {
  679. if(curBack)
  680. SDL_FreeSurface(curBack);
  681. curBack = CSDL_Ext::copySurface(background);
  682. blitAt(skillpics->ourImages[0].bitmap, 32, 111, curBack);
  683. blitAt(skillpics->ourImages[1].bitmap, 102, 111, curBack);
  684. blitAt(skillpics->ourImages[2].bitmap, 172, 111, curBack);
  685. blitAt(skillpics->ourImages[5].bitmap, 242, 111, curBack);
  686. blitAt(skillpics->ourImages[4].bitmap, 20, 230, curBack);
  687. blitAt(skillpics->ourImages[3].bitmap, 162, 230, curBack);
  688. blitAt(curHero->type->portraitLarge, 19, 19, curBack);
  689. CSDL_Ext::printAtMiddle(curHero->name, 190, 40, GEORXX, tytulowy, curBack);
  690. std::stringstream secondLine;
  691. secondLine<<"Level "<<curHero->level<<" "<<curHero->type->heroClass->name;
  692. CSDL_Ext::printAtMiddle(secondLine.str(), 190, 66, TNRB16, zwykly, curBack);
  693. //primary skliis names
  694. CSDL_Ext::printAtMiddle(CGI->generaltexth->jktexts[1], 53, 98, GEOR13, tytulowy, curBack);
  695. CSDL_Ext::printAtMiddle(CGI->generaltexth->jktexts[2], 123, 98, GEOR13, tytulowy, curBack);
  696. CSDL_Ext::printAtMiddle(CGI->generaltexth->jktexts[3], 193, 98, GEOR13, tytulowy, curBack);
  697. CSDL_Ext::printAtMiddle(CGI->generaltexth->jktexts[4], 263, 98, GEOR13, tytulowy, curBack);
  698. //dismiss / quest log
  699. std::vector<std::string> * toPrin = CMessage::breakText(CGI->generaltexth->jktexts[8].substr(1, CGI->generaltexth->jktexts[8].size()-2));
  700. if(toPrin->size()==1)
  701. {
  702. CSDL_Ext::printAt((*toPrin)[0], 372, 440, GEOR13, zwykly, curBack);
  703. }
  704. else
  705. {
  706. CSDL_Ext::printAt((*toPrin)[0], 372, 431, GEOR13, zwykly, curBack);
  707. CSDL_Ext::printAt((*toPrin)[1], 372, 447, GEOR13, zwykly, curBack);
  708. }
  709. delete toPrin;
  710. toPrin = CMessage::breakText(CGI->generaltexth->jktexts[9].substr(1, CGI->generaltexth->jktexts[9].size()-2));
  711. if(toPrin->size()==1)
  712. {
  713. CSDL_Ext::printAt((*toPrin)[0], 512, 440, GEOR13, zwykly, curBack);
  714. }
  715. else
  716. {
  717. CSDL_Ext::printAt((*toPrin)[0], 512, 431, GEOR13, zwykly, curBack);
  718. CSDL_Ext::printAt((*toPrin)[1], 512, 447, GEOR13, zwykly, curBack);
  719. }
  720. delete toPrin;
  721. //printing primary skills' amounts
  722. std::stringstream primarySkill1;
  723. primarySkill1<<curHero->primSkills[0];
  724. CSDL_Ext::printAtMiddle(primarySkill1.str(), 53, 165, TNRB16, zwykly, curBack);
  725. std::stringstream primarySkill2;
  726. primarySkill2<<curHero->primSkills[1];
  727. CSDL_Ext::printAtMiddle(primarySkill2.str(), 123, 165, TNRB16, zwykly, curBack);
  728. std::stringstream primarySkill3;
  729. primarySkill3<<curHero->primSkills[2];
  730. CSDL_Ext::printAtMiddle(primarySkill3.str(), 193, 165, TNRB16, zwykly, curBack);
  731. std::stringstream primarySkill4;
  732. primarySkill4<<curHero->primSkills[3];
  733. CSDL_Ext::printAtMiddle(primarySkill4.str(), 263, 165, TNRB16, zwykly, curBack);
  734. blitAt(LOCPLINT->luck42->ourImages[curHero->getCurrentLuck()+3].bitmap, 239, 182, curBack);
  735. blitAt(LOCPLINT->morale42->ourImages[curHero->getCurrentMorale()+3].bitmap, 181, 182, curBack);
  736. blitAt(flags->ourImages[player].bitmap, 606, 8, curBack);
  737. //hero list blitting
  738. for(int g=0; g<LOCPLINT->cb->howManyHeroes(); ++g)
  739. {
  740. const CGHeroInstance * cur = LOCPLINT->cb->getHeroInfo(player, g, false);
  741. blitAt(cur->type->portraitSmall, 611, 87+g*54, curBack);
  742. //printing yellow border
  743. if(cur->name == curHero->name)
  744. {
  745. for(int f=0; f<cur->type->portraitSmall->w; ++f)
  746. {
  747. for(int h=0; h<cur->type->portraitSmall->h; ++h)
  748. if(f==0 || h==0 || f==cur->type->portraitSmall->w-1 || h==cur->type->portraitSmall->h-1)
  749. {
  750. CSDL_Ext::SDL_PutPixel(curBack, 611+f, 87+g*54+h, 240, 220, 120);
  751. }
  752. }
  753. }
  754. }
  755. //secondary skills
  756. if(curHero->secSkills.size()>=1)
  757. {
  758. blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[0].first*3+3+curHero->secSkills[0].second].bitmap, 18, 276, curBack);
  759. CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[0].second], 69, 279, GEOR13, zwykly, curBack);
  760. CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[0].first]->name, 69, 299, GEOR13, zwykly, curBack);
  761. }
  762. if(curHero->secSkills.size()>=2)
  763. {
  764. blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[1].first*3+3+curHero->secSkills[1].second].bitmap, 161, 276, curBack);
  765. CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[1].second], 213, 279, GEOR13, zwykly, curBack);
  766. CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[1].first]->name, 213, 299, GEOR13, zwykly, curBack);
  767. }
  768. if(curHero->secSkills.size()>=3)
  769. {
  770. blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[2].first*3+3+curHero->secSkills[2].second].bitmap, 18, 324, curBack);
  771. CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[2].second], 69, 327, GEOR13, zwykly, curBack);
  772. CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[2].first]->name, 69, 347, GEOR13, zwykly, curBack);
  773. }
  774. if(curHero->secSkills.size()>=4)
  775. {
  776. blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[3].first*3+3+curHero->secSkills[3].second].bitmap, 161, 324, curBack);
  777. CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[3].second], 213, 327, GEOR13, zwykly, curBack);
  778. CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[3].first]->name, 213, 347, GEOR13, zwykly, curBack);
  779. }
  780. if(curHero->secSkills.size()>=5)
  781. {
  782. blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[4].first*3+3+curHero->secSkills[4].second].bitmap, 18, 372, curBack);
  783. CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[4].second], 69, 375, GEOR13, zwykly, curBack);
  784. CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[4].first]->name, 69, 395, GEOR13, zwykly, curBack);
  785. }
  786. if(curHero->secSkills.size()>=6)
  787. {
  788. blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[5].first*3+3+curHero->secSkills[5].second].bitmap, 161, 372, curBack);
  789. CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[5].second], 213, 375, GEOR13, zwykly, curBack);
  790. CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[5].first]->name, 213, 395, GEOR13, zwykly, curBack);
  791. }
  792. if(curHero->secSkills.size()>=7)
  793. {
  794. blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[6].first*3+3+curHero->secSkills[6].second].bitmap, 18, 420, curBack);
  795. CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[6].second], 69, 423, GEOR13, zwykly, curBack);
  796. CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[6].first]->name, 69, 443, GEOR13, zwykly, curBack);
  797. }
  798. if(curHero->secSkills.size()>=8)
  799. {
  800. blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[7].first*3+3+curHero->secSkills[7].second].bitmap, 161, 420, curBack);
  801. CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[7].second], 213, 423, GEOR13, zwykly, curBack);
  802. CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[7].first]->name, 213, 443, GEOR13, zwykly, curBack);
  803. }
  804. //printing special ability
  805. blitAt(CGI->heroh->un44->ourImages[curHero->subID].bitmap, 18, 180, curBack);
  806. //printing necessery texts
  807. CSDL_Ext::printAt(CGI->generaltexth->jktexts[6].substr(1, CGI->generaltexth->jktexts[6].size()-2), 69, 231, GEOR13, tytulowy, curBack);
  808. std::stringstream expstr;
  809. expstr<<curHero->exp;
  810. CSDL_Ext::printAt(expstr.str(), 69, 247, GEOR16, zwykly, curBack);
  811. CSDL_Ext::printAt(CGI->generaltexth->jktexts[7].substr(1, CGI->generaltexth->jktexts[7].size()-2), 212, 231, GEOR13, tytulowy, curBack);
  812. std::stringstream manastr;
  813. manastr<<curHero->mana<<'/'<<curHero->primSkills[3]*10;
  814. CSDL_Ext::printAt(manastr.str(), 212, 247, GEOR16, zwykly, curBack);
  815. }
  816. CArtPlace::CArtPlace(CArtifact *art): ourArt(art), active(false){}
  817. void CArtPlace::activate()
  818. {
  819. if(!active)
  820. {
  821. //ClickableL::activate();
  822. LRClickableAreaWTextComp::activate();
  823. active = true;
  824. }
  825. }
  826. void CArtPlace::clickLeft(boost::logic::tribool down)
  827. {
  828. //LRClickableAreaWTextComp::clickLeft(down);
  829. }
  830. void CArtPlace::clickRight(boost::logic::tribool down)
  831. {
  832. if(text.size()) //if there is no description, do nothing ;]
  833. LRClickableAreaWTextComp::clickRight(down);
  834. }
  835. void CArtPlace::deactivate()
  836. {
  837. if(active)
  838. {
  839. active = false;
  840. //ClickableL::deactivate();
  841. LRClickableAreaWTextComp::deactivate();
  842. }
  843. }
  844. void CArtPlace::show(SDL_Surface *to)
  845. {
  846. if(ourArt)
  847. {
  848. blitAt(CGI->arth->artDefs->ourImages[ourArt->id].bitmap, pos.x, pos.y, to);
  849. }
  850. }
  851. CArtPlace::~CArtPlace()
  852. {
  853. deactivate();
  854. }
  855. void LClickableArea::activate()
  856. {
  857. ClickableL::activate();
  858. }
  859. void LClickableArea::deactivate()
  860. {
  861. ClickableL::deactivate();
  862. }
  863. void LClickableArea::clickLeft(boost::logic::tribool down)
  864. {
  865. if(!down)
  866. {
  867. LOCPLINT->showInfoDialog("TEST TEST AAA", std::vector<SComponent*>());
  868. }
  869. }
  870. void RClickableArea::activate()
  871. {
  872. ClickableR::activate();
  873. }
  874. void RClickableArea::deactivate()
  875. {
  876. ClickableR::deactivate();
  877. }
  878. void RClickableArea::clickRight(boost::logic::tribool down)
  879. {
  880. if(!down)
  881. {
  882. LOCPLINT->showInfoDialog("TEST TEST AAA", std::vector<SComponent*>());
  883. }
  884. }
  885. void LRClickableAreaWText::clickLeft(boost::logic::tribool down)
  886. {
  887. if(!down)
  888. {
  889. LOCPLINT->showInfoDialog(text, std::vector<SComponent*>());
  890. }
  891. }
  892. void LRClickableAreaWText::clickRight(boost::logic::tribool down)
  893. {
  894. LOCPLINT->adventureInt->handleRightClick(text, down, this);
  895. }
  896. void LRClickableAreaWText::activate()
  897. {
  898. LClickableArea::activate();
  899. RClickableArea::activate();
  900. }
  901. void LRClickableAreaWText::deactivate()
  902. {
  903. LClickableArea::deactivate();
  904. RClickableArea::deactivate();
  905. }
  906. void LClickableAreaHero::clickLeft(boost::logic::tribool down)
  907. {
  908. if(!down)
  909. {
  910. owner->deactivate();
  911. const CGHeroInstance * buf = LOCPLINT->cb->getHeroInfo(owner->player, id, false);
  912. owner->setHero(buf);
  913. owner->redrawCurBack();
  914. owner->activate();
  915. }
  916. }
  917. void LRClickableAreaWTextComp::clickLeft(boost::logic::tribool down)
  918. {
  919. if((!down) && pressedL)
  920. {
  921. LOCPLINT->showInfoDialog(text, std::vector<SComponent*>(1, new SComponent(SComponent::Etype(baseType), type, bonus)));
  922. }
  923. ClickableL::clickLeft(down);
  924. }
  925. void LRClickableAreaWTextComp::clickRight(boost::logic::tribool down)
  926. {
  927. LOCPLINT->adventureInt->handleRightClick(text, down, this);
  928. }
  929. void LRClickableAreaWTextComp::activate()
  930. {
  931. LClickableArea::activate();
  932. RClickableArea::activate();
  933. }
  934. void LRClickableAreaWTextComp::deactivate()
  935. {
  936. LClickableArea::deactivate();
  937. RClickableArea::deactivate();
  938. }