CHeroWindow.cpp 29 KB

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