CHeroWindow.cpp 28 KB

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