CHeroWindow.cpp 28 KB

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