CHeroWindow.cpp 28 KB

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