CHeroWindow.cpp 28 KB

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