CHeroWindow.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  1. #include "stdafx.h"
  2. #include "AdventureMapButton.h"
  3. #include "CAdvmapInterface.h"
  4. #include "CCallback.h"
  5. #include "CCastleInterface.h"
  6. #include "CGameInfo.h"
  7. #include "CHeroWindow.h"
  8. #include "CMessage.h"
  9. #include "SDL.h"
  10. #include "SDL_Extensions.h"
  11. #include "client/CBitmapHandler.h"
  12. #include "client/Graphics.h"
  13. #include "global.h"
  14. #include "hch/CAbilityHandler.h"
  15. #include "hch/CArtHandler.h"
  16. #include "hch/CDefHandler.h"
  17. #include "hch/CGeneralTextHandler.h"
  18. #include "hch/CHeroHandler.h"
  19. #include "hch/CLodHandler.h"
  20. #include "hch/CObjectHandler.h"
  21. #include <boost/assign/std/vector.hpp>
  22. #include <cstdlib>
  23. #include <sstream>
  24. extern SDL_Surface * screen;
  25. extern TTF_Font * GEOR16;
  26. using namespace boost::assign;
  27. CHeroWindow::CHeroWindow(int playerColor):
  28. backpackPos(0), player(playerColor)
  29. {
  30. artWorn.resize(19);
  31. background = BitmapHandler::loadBitmap("HEROSCR4.bmp");
  32. graphics->blueToPlayersAdv(background, playerColor);
  33. pos.x = 65;
  34. pos.y = 8;
  35. pos.h = background->h;
  36. pos.w = background->w;
  37. curBack = NULL;
  38. curHero = NULL;
  39. activeArtPlace = NULL;
  40. garInt = NULL;
  41. ourBar = new CStatusBar(72, 567, "ADROLLVR.bmp", 660);
  42. quitButton = new AdventureMapButton(CGI->generaltexth->heroscrn[17], std::string(), boost::function<void()>(), 674, 524, "hsbtns.def", false, NULL, false);
  43. dismissButton = new AdventureMapButton(std::string(), CGI->generaltexth->heroscrn[28], boost::bind(&CHeroWindow::dismissCurrent,this), 519, 437, "hsbtns2.def", false, NULL, false);
  44. questlogButton = new AdventureMapButton(CGI->generaltexth->heroscrn[0], std::string(), boost::bind(&CHeroWindow::questlog,this), 379, 437, "hsbtns4.def", false, NULL, false);
  45. gar1button = new AdventureMapButton(CGI->generaltexth->heroscrn[23], CGI->generaltexth->heroscrn[29], boost::bind(&CHeroWindow::gar1,this), 546, 491, "hsbtns6.def", false, NULL, false);
  46. gar2button = new AdventureMapButton(std::string(), std::string(), boost::bind(&CHeroWindow::gar2,this), 604, 491, "hsbtns8.def", false, NULL, false);
  47. gar3button = new AdventureMapButton(CGI->generaltexth->heroscrn[24], CGI->generaltexth->heroscrn[30], boost::bind(&CHeroWindow::gar3,this), 546, 527, "hsbtns7.def", false, NULL, false);
  48. gar4button = new AdventureMapButton(std::string(), CGI->generaltexth->heroscrn[32], boost::function<void()>(), 604, 527, "hsbtns9.def", false, NULL, false);
  49. leftArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind(&CHeroWindow::leftArtRoller,this), 379, 364, "hsbtns3.def", false, NULL, false);
  50. rightArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind(&CHeroWindow::rightArtRoller,this), 632, 364, "hsbtns5.def", false, NULL, false);
  51. for(int g=0; g<8; ++g)
  52. {
  53. //heroList.push_back(new AdventureMapButton<CHeroWindow>(std::string(), std::string(), &CHeroWindow::switchHero, 677, 95+g*54, "hsbtns5.def", this));
  54. heroListMi.push_back(new LClickableAreaHero());
  55. heroListMi[g]->pos.x = 677;
  56. heroListMi[g]->pos.y = 95+g*54;
  57. heroListMi[g]->pos.h = 32;
  58. heroListMi[g]->pos.w = 48;
  59. heroListMi[g]->owner = this;
  60. heroListMi[g]->id = g;
  61. }
  62. flags = CDefHandler::giveDef("CREST58.DEF");
  63. //areas
  64. portraitArea = new LRClickableAreaWText();
  65. portraitArea->pos.x = 83;
  66. portraitArea->pos.y = 26;
  67. portraitArea->pos.w = 58;
  68. portraitArea->pos.h = 64;
  69. for(int v=0; v<4; ++v)
  70. {
  71. primSkillAreas.push_back(new LRClickableAreaWTextComp());
  72. primSkillAreas[v]->pos.x = 95 + 70*v;
  73. primSkillAreas[v]->pos.y = 111;
  74. primSkillAreas[v]->pos.w = 42;
  75. primSkillAreas[v]->pos.h = 42;
  76. primSkillAreas[v]->text = CGI->generaltexth->arraytxt[2+v].substr(1, CGI->generaltexth->arraytxt[2+v].size()-2);
  77. primSkillAreas[v]->type = v;
  78. primSkillAreas[v]->bonus = -1; // to be initilized when hero is being set
  79. primSkillAreas[v]->baseType = 0;
  80. }
  81. expArea = new LRClickableAreaWText();
  82. expArea->pos.x = 83;
  83. expArea->pos.y = 236;
  84. expArea->pos.w = 136;
  85. expArea->pos.h = 42;
  86. expArea->hoverText = CGI->generaltexth->heroscrn[9];
  87. spellPointsArea = new LRClickableAreaWText();
  88. spellPointsArea->pos.x = 227;
  89. spellPointsArea->pos.y = 236;
  90. spellPointsArea->pos.w = 136;
  91. spellPointsArea->pos.h = 42;
  92. spellPointsArea->hoverText = CGI->generaltexth->heroscrn[22];
  93. for(int i=0; i<8; ++i)
  94. {
  95. secSkillAreas.push_back(new LRClickableAreaWTextComp());
  96. secSkillAreas[i]->pos.x = (i%2==0) ? (83) : (227);
  97. secSkillAreas[i]->pos.y = 284 + 48 * (i/2);
  98. secSkillAreas[i]->pos.w = 136;
  99. secSkillAreas[i]->pos.h = 42;
  100. secSkillAreas[i]->baseType = 1;
  101. }
  102. }
  103. CHeroWindow::~CHeroWindow()
  104. {
  105. SDL_FreeSurface(background);
  106. delete quitButton;
  107. delete dismissButton;
  108. delete questlogButton;
  109. delete gar1button;
  110. delete gar2button;
  111. delete gar3button;
  112. delete gar4button;
  113. delete leftArtRoll;
  114. delete rightArtRoll;
  115. for(int g=0; g<heroListMi.size(); ++g)
  116. delete heroListMi[g];
  117. if(curBack)
  118. SDL_FreeSurface(curBack);
  119. delete flags;
  120. delete garInt;
  121. delete ourBar;
  122. for(int g=0; g<artWorn.size(); ++g)
  123. {
  124. delete artWorn[g];
  125. }
  126. artWorn.clear();
  127. for(int g=0; g<backpack.size(); ++g)
  128. {
  129. delete backpack[g];
  130. }
  131. backpack.clear();
  132. delete portraitArea;
  133. delete expArea;
  134. delete spellPointsArea;
  135. for(int v=0; v<primSkillAreas.size(); ++v)
  136. {
  137. delete primSkillAreas[v];
  138. }
  139. for(int v=0; v<secSkillAreas.size(); ++v)
  140. {
  141. delete secSkillAreas[v];
  142. }
  143. }
  144. void CHeroWindow::show(SDL_Surface *to)
  145. {
  146. if(!to)
  147. to=screen;
  148. if(curBack)
  149. blitAt(curBack,pos.x,pos.y,to);
  150. quitButton->show();
  151. dismissButton->show();
  152. questlogButton->show();
  153. gar1button->show();
  154. gar2button->show();
  155. gar3button->show();
  156. gar4button->show();
  157. leftArtRoll->show();
  158. rightArtRoll->show();
  159. garInt->show();
  160. ourBar->show();
  161. for(int d=0; d<artWorn.size(); ++d)
  162. {
  163. artWorn[d]->show(to);
  164. }
  165. for(int d=0; d<backpack.size(); ++d)
  166. {
  167. backpack[d]->show(to);
  168. }
  169. }
  170. void CHeroWindow::setHero(const CGHeroInstance *Hero)
  171. {
  172. CGHeroInstance *hero = const_cast<CGHeroInstance*>(Hero); //but don't modify hero! - it's only for easy map reading
  173. if(!hero) //something strange... no hero? it shouldn't happen
  174. {
  175. return;
  176. }
  177. curHero = hero;
  178. char * prhlp = new char[200];
  179. sprintf(prhlp, CGI->generaltexth->heroscrn[16].c_str(), curHero->name.c_str(), curHero->type->heroClass->name.c_str());
  180. dismissButton->name = std::string(prhlp);
  181. delete [] prhlp;
  182. prhlp = new char[200];
  183. sprintf(prhlp, CGI->generaltexth->allTexts[15].c_str(), curHero->name.c_str(), curHero->type->heroClass->name.c_str());
  184. portraitArea->hoverText = std::string(prhlp);
  185. delete [] prhlp;
  186. portraitArea->text = hero->biography;
  187. delete garInt;
  188. /*gar4button->owner = */garInt = new CGarrisonInt(80, 493, 8, 0, curBack, 13, 482, curHero);
  189. garInt->update = false;
  190. gar4button->callback = boost::bind(&CGarrisonInt::splitClick,garInt);//actualization of callback function
  191. for(int g=0; g<primSkillAreas.size(); ++g)
  192. {
  193. primSkillAreas[g]->bonus = hero->primSkills[g];
  194. }
  195. for(int g=0; g<hero->secSkills.size(); ++g)
  196. {
  197. secSkillAreas[g]->type = hero->secSkills[g].first;
  198. secSkillAreas[g]->bonus = hero->secSkills[g].second;
  199. std::string hlp = CGI->abilh->abilities[ hero->secSkills[g].first ]->infoTexts[hero->secSkills[g].second];
  200. secSkillAreas[g]->text = hlp.substr(1, hlp.size()-2);
  201. char * hlpp = new char[200];
  202. sprintf(hlpp, CGI->generaltexth->heroscrn[21].c_str(), CGI->abilh->levels[hero->secSkills[g].second].c_str(), CGI->abilh->abilities[hero->secSkills[g].first]->name.c_str());
  203. secSkillAreas[g]->hoverText = std::string(hlpp);
  204. delete [] hlpp;
  205. }
  206. char * th = new char[200];
  207. 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);
  208. expArea->text = std::string(th);
  209. delete [] th;
  210. th = new char[400];
  211. 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);
  212. spellPointsArea->text = std::string(th);
  213. delete [] th;
  214. for(int g=0; g<artWorn.size(); ++g)
  215. {
  216. delete artWorn[g];
  217. }
  218. for(int g=0; g<backpack.size(); ++g)
  219. {
  220. delete backpack[g];
  221. }
  222. backpack.clear();
  223. std::vector<SDL_Rect> slotPos;
  224. slotPos += genRect(44,44,509,30), genRect(44,44,567,240), genRect(44,44,509,30), genRect(44,44,383,68),
  225. genRect(44,44,564,183), genRect(44,44,509,130), genRect(44,44,431,68), genRect(44,44,610,183),
  226. genRect(44,44,515,295), genRect(44,44,383,143), genRect(44,44,399,194), genRect(44,44,415,245),
  227. genRect(44,44,431,296), genRect(44,44,564,30), genRect(44,44,610,30), genRect(44,44,610,76),
  228. genRect(44,44,610,122), genRect(44,44,610,310), genRect(44,44,381,296);
  229. for (int g = 0; g < 19 ; g++)
  230. {
  231. artWorn[g] = new CArtPlace(hero->getArt(g));
  232. artWorn[g]->pos = slotPos[g];
  233. if(hero->getArt(g))
  234. artWorn[g]->text = hero->getArt(g)->description;
  235. artWorn[g]->ourWindow = this;
  236. }
  237. for(int g=0; g<artWorn.size(); ++g)
  238. {
  239. artWorn[g]->slotID = g;
  240. char * hll = new char[200];
  241. sprintf(hll, CGI->generaltexth->heroscrn[1].c_str(), (artWorn[g]->ourArt ? artWorn[g]->ourArt->name.c_str() : ""));
  242. artWorn[g]->hoverText = std::string(hll);
  243. delete [] hll;
  244. }
  245. for(int s=0; s<5; ++s)
  246. {
  247. CArtPlace * add;
  248. if( s < curHero->artifacts.size() )
  249. add = new CArtPlace(&CGI->arth->artifacts[curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ]]);
  250. else
  251. add = new CArtPlace(NULL);
  252. add->pos.x = 403 + 46*s;
  253. add->pos.y = 365;
  254. add->pos.h = add->pos.w = 44;
  255. if(s<hero->artifacts.size() && hero->artifacts[s])
  256. add->text = hero->getArt(19+s)->description;
  257. else
  258. add->text = std::string();
  259. add->ourWindow = this;
  260. add->slotID = 19+s;
  261. backpack.push_back(add);
  262. }
  263. activeArtPlace = NULL;
  264. redrawCurBack();
  265. }
  266. void CHeroWindow::quit()
  267. {
  268. LOCPLINT->curint->subInt = NULL;
  269. LOCPLINT->objsToBlit -= this;
  270. if(LOCPLINT->curint == LOCPLINT->castleInt)
  271. LOCPLINT->castleInt->subInt = NULL;
  272. LOCPLINT->curint->activate();
  273. SDL_FreeSurface(curBack);
  274. curBack = NULL;
  275. for(int g=0; g<artWorn.size(); ++g)
  276. {
  277. delete artWorn[g];
  278. artWorn[g] = NULL;
  279. }
  280. for(int g=0; g<backpack.size(); ++g)
  281. {
  282. delete backpack[g];
  283. backpack[g] = NULL;
  284. }
  285. backpack.clear();
  286. activeArtPlace = NULL;
  287. }
  288. void CHeroWindow::activate()
  289. {
  290. LOCPLINT->curint->subInt = this;
  291. quitButton->activate();
  292. dismissButton->activate();
  293. questlogButton->activate();
  294. gar1button->activate();
  295. gar2button->activate();
  296. gar3button->activate();
  297. gar4button->activate();
  298. leftArtRoll->activate();
  299. rightArtRoll->activate();
  300. portraitArea->activate();
  301. expArea->activate();
  302. spellPointsArea->activate();
  303. garInt->activate();
  304. LOCPLINT->statusbar = ourBar;
  305. for(int v=0; v<primSkillAreas.size(); ++v)
  306. {
  307. primSkillAreas[v]->activate();
  308. }
  309. for(int v=0; v<curHero->secSkills.size(); ++v)
  310. {
  311. secSkillAreas[v]->activate();
  312. }
  313. redrawCurBack();
  314. for(int f=0; f<artWorn.size(); ++f)
  315. {
  316. if(artWorn[f])
  317. artWorn[f]->activate();
  318. }
  319. for(int f=0; f<backpack.size(); ++f)
  320. {
  321. if(backpack[f])
  322. backpack[f]->activate();
  323. }
  324. for(int e=0; e<heroListMi.size(); ++e)
  325. {
  326. heroListMi[e]->activate();
  327. }
  328. //LOCPLINT->lclickable.push_back(artFeet);
  329. }
  330. void CHeroWindow::deactivate()
  331. {
  332. quitButton->deactivate();
  333. dismissButton->deactivate();
  334. questlogButton->deactivate();
  335. gar1button->deactivate();
  336. gar2button->deactivate();
  337. gar3button->deactivate();
  338. gar4button->deactivate();
  339. leftArtRoll->deactivate();
  340. rightArtRoll->deactivate();
  341. portraitArea->deactivate();
  342. expArea->deactivate();
  343. spellPointsArea->deactivate();
  344. garInt->deactivate();
  345. for(int v=0; v<primSkillAreas.size(); ++v)
  346. {
  347. primSkillAreas[v]->deactivate();
  348. }
  349. for(int v=0; v<curHero->secSkills.size(); ++v)
  350. {
  351. secSkillAreas[v]->deactivate();
  352. }
  353. for(int f=0; f<artWorn.size(); ++f)
  354. {
  355. if(artWorn[f])
  356. artWorn[f]->deactivate();
  357. }
  358. for(int f=0; f<backpack.size(); ++f)
  359. {
  360. if(backpack[f])
  361. backpack[f]->deactivate();
  362. }
  363. for(int e=0; e<heroListMi.size(); ++e)
  364. {
  365. heroListMi[e]->deactivate();
  366. }
  367. }
  368. void CHeroWindow::dismissCurrent()
  369. {
  370. CFunctionList<void()> ony = boost::bind(&CHeroWindow::quit,this);
  371. ony += boost::bind(&CCallback::dismissHero,LOCPLINT->cb,curHero);
  372. LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[22],std::vector<SComponent*>(), ony, boost::bind(&CHeroWindow::activate,this), true, false);
  373. }
  374. void CHeroWindow::questlog()
  375. {
  376. }
  377. void CHeroWindow::gar1()
  378. {
  379. }
  380. void CHeroWindow::gar2()
  381. {
  382. }
  383. void CHeroWindow::gar3()
  384. {
  385. }
  386. void CHeroWindow::gar4()
  387. {
  388. }
  389. void CHeroWindow::leftArtRoller()
  390. {
  391. if(curHero->artifacts.size()>5) //if it is <=5, we have nothing to scroll
  392. {
  393. backpackPos+=curHero->artifacts.size()-1; //set new offset
  394. for(int s=0; s<5 && s<curHero->artifacts.size(); ++s) //set new data
  395. {
  396. backpack[s]->ourArt = &CGI->arth->artifacts[curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ]];
  397. if(backpack[s]->ourArt)
  398. backpack[s]->text = backpack[s]->ourArt->description;
  399. else
  400. backpack[s]->text = std::string();
  401. }
  402. }
  403. }
  404. void CHeroWindow::rightArtRoller()
  405. {
  406. if(curHero->artifacts.size()>5) //if it is <=5, we have nothing to scroll
  407. {
  408. backpackPos+=1; //set new offset
  409. for(int s=0; s<5 && s<curHero->artifacts.size(); ++s) //set new data
  410. {
  411. backpack[s]->ourArt = &CGI->arth->artifacts[curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ] ];
  412. if(backpack[s]->ourArt)
  413. backpack[s]->text = backpack[s]->ourArt->description;
  414. else
  415. backpack[s]->text = std::string();
  416. }
  417. }
  418. }
  419. void CHeroWindow::switchHero()
  420. {
  421. //int y;
  422. //SDL_GetMouseState(NULL, &y);
  423. //for(int g=0; g<heroListMi.size(); ++g)
  424. //{
  425. // if(y>=94+54*g)
  426. // {
  427. // //quit();
  428. // setHero(LOCPLINT->cb->getHeroInfo(player, g, false));
  429. // //LOCPLINT->openHeroWindow(curHero);
  430. // redrawCurBack();
  431. // }
  432. //}
  433. }
  434. void CHeroWindow::redrawCurBack()
  435. {
  436. if(curBack)
  437. SDL_FreeSurface(curBack);
  438. curBack = SDL_DisplayFormat(background);
  439. blitAt(graphics->pskillsm->ourImages[0].bitmap, 32, 111, curBack);
  440. blitAt(graphics->pskillsm->ourImages[1].bitmap, 102, 111, curBack);
  441. blitAt(graphics->pskillsm->ourImages[2].bitmap, 172, 111, curBack);
  442. blitAt(graphics->pskillsm->ourImages[5].bitmap, 242, 111, curBack);
  443. blitAt(graphics->pskillsm->ourImages[4].bitmap, 20, 230, curBack);
  444. blitAt(graphics->pskillsm->ourImages[3].bitmap, 162, 230, curBack);
  445. blitAt(graphics->portraitLarge[curHero->portrait], 19, 19, curBack);
  446. CSDL_Ext::printAtMiddle(curHero->name, 190, 40, GEORXX, tytulowy, curBack);
  447. std::stringstream secondLine;
  448. secondLine<<"Level "<<curHero->level<<" "<<curHero->type->heroClass->name;
  449. CSDL_Ext::printAtMiddle(secondLine.str(), 190, 66, TNRB16, zwykly, curBack);
  450. //primary skliis names
  451. CSDL_Ext::printAtMiddle(CGI->generaltexth->jktexts[1], 53, 98, GEOR13, tytulowy, curBack);
  452. CSDL_Ext::printAtMiddle(CGI->generaltexth->jktexts[2], 123, 98, GEOR13, tytulowy, curBack);
  453. CSDL_Ext::printAtMiddle(CGI->generaltexth->jktexts[3], 193, 98, GEOR13, tytulowy, curBack);
  454. CSDL_Ext::printAtMiddle(CGI->generaltexth->jktexts[4], 263, 98, GEOR13, tytulowy, curBack);
  455. //dismiss / quest log
  456. std::vector<std::string> * toPrin = CMessage::breakText(CGI->generaltexth->jktexts[8].substr(1, CGI->generaltexth->jktexts[8].size()-2));
  457. if(toPrin->size()==1)
  458. {
  459. CSDL_Ext::printAt((*toPrin)[0], 372, 440, GEOR13, zwykly, curBack);
  460. }
  461. else
  462. {
  463. CSDL_Ext::printAt((*toPrin)[0], 372, 431, GEOR13, zwykly, curBack);
  464. CSDL_Ext::printAt((*toPrin)[1], 372, 447, GEOR13, zwykly, curBack);
  465. }
  466. delete toPrin;
  467. toPrin = CMessage::breakText(CGI->generaltexth->jktexts[9].substr(1, CGI->generaltexth->jktexts[9].size()-2));
  468. if(toPrin->size()==1)
  469. {
  470. CSDL_Ext::printAt((*toPrin)[0], 512, 440, GEOR13, zwykly, curBack);
  471. }
  472. else
  473. {
  474. CSDL_Ext::printAt((*toPrin)[0], 512, 431, GEOR13, zwykly, curBack);
  475. CSDL_Ext::printAt((*toPrin)[1], 512, 447, GEOR13, zwykly, curBack);
  476. }
  477. delete toPrin;
  478. //printing primary skills' amounts
  479. std::stringstream primarySkill1;
  480. primarySkill1<<curHero->primSkills[0];
  481. CSDL_Ext::printAtMiddle(primarySkill1.str(), 53, 165, TNRB16, zwykly, curBack);
  482. std::stringstream primarySkill2;
  483. primarySkill2<<curHero->primSkills[1];
  484. CSDL_Ext::printAtMiddle(primarySkill2.str(), 123, 165, TNRB16, zwykly, curBack);
  485. std::stringstream primarySkill3;
  486. primarySkill3<<curHero->primSkills[2];
  487. CSDL_Ext::printAtMiddle(primarySkill3.str(), 193, 165, TNRB16, zwykly, curBack);
  488. std::stringstream primarySkill4;
  489. primarySkill4<<curHero->primSkills[3];
  490. CSDL_Ext::printAtMiddle(primarySkill4.str(), 263, 165, TNRB16, zwykly, curBack);
  491. blitAt(graphics->luck42->ourImages[curHero->getCurrentLuck()+3].bitmap, 239, 182, curBack);
  492. blitAt(graphics->morale42->ourImages[curHero->getCurrentMorale()+3].bitmap, 181, 182, curBack);
  493. blitAt(flags->ourImages[player].bitmap, 606, 8, curBack);
  494. //hero list blitting
  495. for(int g=0; g<LOCPLINT->cb->howManyHeroes(); ++g)
  496. {
  497. const CGHeroInstance * cur = LOCPLINT->cb->getHeroInfo(g, false);
  498. blitAt(graphics->portraitSmall[cur->portrait], 611, 87+g*54, curBack);
  499. //printing yellow border
  500. if(cur->name == curHero->name)
  501. {
  502. for(int f=0; f<graphics->portraitSmall[cur->portrait]->w; ++f)
  503. {
  504. for(int h=0; h<graphics->portraitSmall[cur->portrait]->h; ++h)
  505. if(f==0 || h==0 || f==graphics->portraitSmall[cur->portrait]->w-1 || h==graphics->portraitSmall[cur->portrait]->h-1)
  506. {
  507. CSDL_Ext::SDL_PutPixel(curBack, 611+f, 87+g*54+h, 240, 220, 120);
  508. }
  509. }
  510. }
  511. }
  512. //secondary skills
  513. if(curHero->secSkills.size()>=1)
  514. {
  515. blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[0].first*3+3+curHero->secSkills[0].second].bitmap, 18, 276, curBack);
  516. CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[0].second], 69, 279, GEOR13, zwykly, curBack);
  517. CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[0].first]->name, 69, 299, GEOR13, zwykly, curBack);
  518. }
  519. if(curHero->secSkills.size()>=2)
  520. {
  521. blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[1].first*3+3+curHero->secSkills[1].second].bitmap, 161, 276, curBack);
  522. CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[1].second], 213, 279, GEOR13, zwykly, curBack);
  523. CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[1].first]->name, 213, 299, GEOR13, zwykly, curBack);
  524. }
  525. if(curHero->secSkills.size()>=3)
  526. {
  527. blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[2].first*3+3+curHero->secSkills[2].second].bitmap, 18, 324, curBack);
  528. CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[2].second], 69, 327, GEOR13, zwykly, curBack);
  529. CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[2].first]->name, 69, 347, GEOR13, zwykly, curBack);
  530. }
  531. if(curHero->secSkills.size()>=4)
  532. {
  533. blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[3].first*3+3+curHero->secSkills[3].second].bitmap, 161, 324, curBack);
  534. CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[3].second], 213, 327, GEOR13, zwykly, curBack);
  535. CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[3].first]->name, 213, 347, GEOR13, zwykly, curBack);
  536. }
  537. if(curHero->secSkills.size()>=5)
  538. {
  539. blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[4].first*3+3+curHero->secSkills[4].second].bitmap, 18, 372, curBack);
  540. CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[4].second], 69, 375, GEOR13, zwykly, curBack);
  541. CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[4].first]->name, 69, 395, GEOR13, zwykly, curBack);
  542. }
  543. if(curHero->secSkills.size()>=6)
  544. {
  545. blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[5].first*3+3+curHero->secSkills[5].second].bitmap, 161, 372, curBack);
  546. CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[5].second], 213, 375, GEOR13, zwykly, curBack);
  547. CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[5].first]->name, 213, 395, GEOR13, zwykly, curBack);
  548. }
  549. if(curHero->secSkills.size()>=7)
  550. {
  551. blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[6].first*3+3+curHero->secSkills[6].second].bitmap, 18, 420, curBack);
  552. CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[6].second], 69, 423, GEOR13, zwykly, curBack);
  553. CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[6].first]->name, 69, 443, GEOR13, zwykly, curBack);
  554. }
  555. if(curHero->secSkills.size()>=8)
  556. {
  557. blitAt(CGI->abilh->abils44->ourImages[curHero->secSkills[7].first*3+3+curHero->secSkills[7].second].bitmap, 161, 420, curBack);
  558. CSDL_Ext::printAt(CGI->abilh->levels[curHero->secSkills[7].second], 213, 423, GEOR13, zwykly, curBack);
  559. CSDL_Ext::printAt(CGI->abilh->abilities[curHero->secSkills[7].first]->name, 213, 443, GEOR13, zwykly, curBack);
  560. }
  561. //printing special ability
  562. blitAt(graphics->un44->ourImages[curHero->subID].bitmap, 18, 180, curBack);
  563. //printing necessery texts
  564. CSDL_Ext::printAt(CGI->generaltexth->jktexts[6].substr(1, CGI->generaltexth->jktexts[6].size()-2), 69, 231, GEOR13, tytulowy, curBack);
  565. std::stringstream expstr;
  566. expstr<<curHero->exp;
  567. CSDL_Ext::printAt(expstr.str(), 69, 247, GEOR16, zwykly, curBack);
  568. CSDL_Ext::printAt(CGI->generaltexth->jktexts[7].substr(1, CGI->generaltexth->jktexts[7].size()-2), 212, 231, GEOR13, tytulowy, curBack);
  569. std::stringstream manastr;
  570. manastr<<curHero->mana<<'/'<<curHero->primSkills[3]*10;
  571. CSDL_Ext::printAt(manastr.str(), 212, 247, GEOR16, zwykly, curBack);
  572. }
  573. CArtPlace::CArtPlace(const CArtifact* Art): ourArt(Art), active(false), clicked(false)/*,
  574. spellBook(false), warMachine1(false), warMachine2(false), warMachine3(false),
  575. warMachine4(false),misc1(false), misc2(false), misc3(false), misc4(false),
  576. misc5(false), feet(false), lRing(false), rRing(false), torso(false),
  577. lHand(false), rHand(false), neck(false), shoulders(false), head(false) */{}
  578. void CArtPlace::activate()
  579. {
  580. if(!active)
  581. {
  582. //ClickableL::activate();
  583. LRClickableAreaWTextComp::activate();
  584. active = true;
  585. }
  586. }
  587. void CArtPlace::clickLeft(boost::logic::tribool down)
  588. {
  589. //LRClickableAreaWTextComp::clickLeft(down);
  590. if(!down && !clicked) //not clicked before
  591. {
  592. if(!ourWindow->activeArtPlace) //nothing has benn clicked
  593. {
  594. if(ourArt) //to prevent selecting empty slots (bugfix to what GrayFace reported)
  595. {
  596. clicked = true;
  597. ourWindow->activeArtPlace = this;
  598. }
  599. }
  600. else //perform artifact substitution
  601. {
  602. //chceck if swap is possible
  603. if(this->fitsHere(ourWindow->activeArtPlace->ourArt) && ourWindow->activeArtPlace->fitsHere(this->ourArt))
  604. {
  605. LOCPLINT->cb->swapArifacts(ourWindow->curHero,slotID,ourWindow->curHero,ourWindow->activeArtPlace->slotID);
  606. const CArtifact * pmh = ourArt;
  607. ourArt = ourWindow->activeArtPlace->ourArt;
  608. ourWindow->activeArtPlace->ourArt = pmh;
  609. //set texts
  610. if(pmh)
  611. ourWindow->activeArtPlace->text = pmh->description;
  612. else
  613. ourWindow->activeArtPlace->text = std::string();
  614. if(ourArt)
  615. text = ourArt->description;
  616. else
  617. text = std::string();
  618. ourWindow->activeArtPlace->clicked = false;
  619. ourWindow->activeArtPlace = NULL;
  620. }
  621. else
  622. {
  623. int backID = -1;
  624. for(int g=0; g<ourWindow->backpack.size(); ++g)
  625. {
  626. if(ourWindow->backpack[g]==this) //if user wants to put something to backpack
  627. {
  628. backID = g;
  629. break;
  630. }
  631. }
  632. if(backID>=0) //put to backpack
  633. {
  634. /*ourWindow->activeArtPlace->ourArt = NULL;
  635. ourWindow->activeArtPlace->clicked = false;
  636. ourWindow->activeArtPlace = NULL;*/
  637. }
  638. }
  639. }
  640. }
  641. else if(!down && clicked)
  642. {
  643. clicked = false;
  644. ourWindow->activeArtPlace = NULL;
  645. }
  646. }
  647. void CArtPlace::clickRight(boost::logic::tribool down)
  648. {
  649. if(text.size()) //if there is no description, do nothing ;]
  650. LRClickableAreaWTextComp::clickRight(down);
  651. }
  652. void CArtPlace::deactivate()
  653. {
  654. if(active)
  655. {
  656. active = false;
  657. //ClickableL::deactivate();
  658. LRClickableAreaWTextComp::deactivate();
  659. }
  660. }
  661. void CArtPlace::show(SDL_Surface *to)
  662. {
  663. if(ourArt)
  664. {
  665. blitAt(graphics->artDefs->ourImages[ourArt->id].bitmap, pos.x, pos.y, to);
  666. }
  667. if(clicked && active)
  668. {
  669. for(int i=0; i<pos.h; ++i)
  670. {
  671. for(int j=0; j<pos.w; ++j)
  672. {
  673. if(i==0 || j==0 || i==pos.h-1 || j==pos.w-1)
  674. {
  675. CSDL_Ext::SDL_PutPixel(to, pos.x+j, pos.y+i, 240, 220, 120);
  676. }
  677. }
  678. }
  679. }
  680. }
  681. bool CArtPlace::fitsHere(const CArtifact * art)
  682. {
  683. if(!art)
  684. return true; //you can have no artifact somewhere
  685. if(slotID > 18 || vstd::contains(art->possibleSlots,slotID)) //backpack or right slot
  686. return true;
  687. return false;
  688. }
  689. CArtPlace::~CArtPlace()
  690. {
  691. deactivate();
  692. }
  693. void LClickableArea::activate()
  694. {
  695. ClickableL::activate();
  696. }
  697. void LClickableArea::deactivate()
  698. {
  699. ClickableL::deactivate();
  700. }
  701. void LClickableArea::clickLeft(boost::logic::tribool down)
  702. {
  703. //if(!down)
  704. //{
  705. // LOCPLINT->showInfoDialog("TEST TEST AAA", std::vector<SComponent*>());
  706. //}
  707. }
  708. void RClickableArea::activate()
  709. {
  710. ClickableR::activate();
  711. }
  712. void RClickableArea::deactivate()
  713. {
  714. ClickableR::deactivate();
  715. }
  716. void RClickableArea::clickRight(boost::logic::tribool down)
  717. {
  718. //if(!down)
  719. //{
  720. // LOCPLINT->showInfoDialog("TEST TEST AAA", std::vector<SComponent*>());
  721. //}
  722. }
  723. void LRClickableAreaWText::clickLeft(boost::logic::tribool down)
  724. {
  725. if(!down)
  726. {
  727. LOCPLINT->showInfoDialog(text, std::vector<SComponent*>());
  728. }
  729. }
  730. void LRClickableAreaWText::clickRight(boost::logic::tribool down)
  731. {
  732. LOCPLINT->adventureInt->handleRightClick(text, down, this);
  733. }
  734. void LRClickableAreaWText::activate()
  735. {
  736. LClickableArea::activate();
  737. RClickableArea::activate();
  738. Hoverable::activate();
  739. }
  740. void LRClickableAreaWText::deactivate()
  741. {
  742. LClickableArea::deactivate();
  743. RClickableArea::deactivate();
  744. Hoverable::deactivate();
  745. }
  746. void LRClickableAreaWText::hover(bool on)
  747. {
  748. Hoverable::hover(on);
  749. if (on)
  750. LOCPLINT->statusbar->print(hoverText);
  751. else if (LOCPLINT->statusbar->getCurrent()==hoverText)
  752. LOCPLINT->statusbar->clear();
  753. }
  754. void LClickableAreaHero::clickLeft(boost::logic::tribool down)
  755. {
  756. if(!down)
  757. {
  758. owner->deactivate();
  759. const CGHeroInstance * buf = LOCPLINT->cb->getHeroInfo(id, false);
  760. owner->setHero(buf);
  761. owner->redrawCurBack();
  762. owner->activate();
  763. }
  764. }
  765. void LRClickableAreaWTextComp::clickLeft(boost::logic::tribool down)
  766. {
  767. if((!down) && pressedL)
  768. {
  769. std::vector<SComponent*> comp(1, new SComponent(SComponent::Etype(baseType), type, bonus));
  770. LOCPLINT->showInfoDialog(text, comp);
  771. }
  772. ClickableL::clickLeft(down);
  773. }
  774. void LRClickableAreaWTextComp::clickRight(boost::logic::tribool down)
  775. {
  776. LOCPLINT->adventureInt->handleRightClick(text, down, this);
  777. }
  778. void LRClickableAreaWTextComp::activate()
  779. {
  780. LClickableArea::activate();
  781. RClickableArea::activate();
  782. Hoverable::activate();
  783. }
  784. void LRClickableAreaWTextComp::deactivate()
  785. {
  786. LClickableArea::deactivate();
  787. RClickableArea::deactivate();
  788. Hoverable::deactivate();
  789. }
  790. void LRClickableAreaWTextComp::hover(bool on)
  791. {
  792. Hoverable::hover(on);
  793. if (on)
  794. LOCPLINT->statusbar->print(hoverText);
  795. else if (LOCPLINT->statusbar->getCurrent()==hoverText)
  796. LOCPLINT->statusbar->clear();
  797. }