CKingdomInterface.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. #include "CKingdomInterface.h"
  2. #include "AdventureMapButton.h"
  3. #include "CAdvmapInterface.h"
  4. #include "../CCallback.h"
  5. #include "CGameInfo.h"
  6. #include "CHeroWindow.h"
  7. #include "CMessage.h"
  8. #include "SDL_Extensions.h"
  9. #include "Graphics.h"
  10. #include "../hch/CArtHandler.h"
  11. #include "../hch/CDefHandler.h"
  12. #include "../hch/CGeneralTextHandler.h"
  13. #include "../hch/CObjectHandler.h"
  14. #include "../hch/CTownHandler.h"
  15. #include "../lib/map.h"
  16. #include "../lib/NetPacks.h"
  17. #include <boost/assign/std/vector.hpp>
  18. #include <sstream>
  19. using namespace boost::assign;
  20. using namespace CSDL_Ext;
  21. /*
  22. * CKingdomInterface.cpp, part of VCMI engine
  23. *
  24. * Authors: listed in file AUTHORS in main folder
  25. *
  26. * License: GNU General Public License v2.0 or later
  27. * Full text of license available in license.txt file, in main folder
  28. *
  29. */
  30. int PicCount = 4;//how many pictures for background present in .def TODO - move to config
  31. int size = 4;//we have 4 visible items in the list, would be nice to move this value to configs later
  32. CDefEssential* CKingdomInterface::slots;
  33. CDefEssential* CKingdomInterface::fort;
  34. CDefEssential* CKingdomInterface::hall;
  35. CKingdomInterface::CKingdomInterface()
  36. {
  37. OBJ_CONSTRUCTION_CAPTURING_ALL;
  38. defActions = /*ACTIVATE | DEACTIVATE |*/ SHARE_POS | DISPOSE;//??? why buttons dont receive activate/deactivate???
  39. pos.x = screen->w/2 - 400;
  40. pos.y = screen->h/2 - (68+58*size);
  41. heroPos = townPos = objPos = 0;
  42. state = 2;
  43. showHarrisoned = false;
  44. bg = BitmapHandler::loadBitmap("OVCAST.bmp");
  45. graphics->blueToPlayersAdv(bg, LOCPLINT->playerID);
  46. mines = CDefHandler::giveDefEss("OVMINES.DEF");
  47. slots = CDefHandler::giveDefEss("OVSLOT.DEF");
  48. title = CDefHandler::giveDefEss("OVTITLE.DEF");
  49. hall = CDefHandler::giveDefEss("ITMTL.DEF");
  50. fort = CDefHandler::giveDefEss("ITMCL.DEF");
  51. objPics = CDefHandler::giveDefEss("FLAGPORT.DEF");
  52. toHeroes = new AdventureMapButton (CGI->generaltexth->overview[11],"",
  53. boost::bind(&CKingdomInterface::listToHeroes,this),748,28+size*116,"OVBUTN1.DEF");
  54. toHeroes->block(2);
  55. toTowns = new AdventureMapButton (CGI->generaltexth->overview[12],"",
  56. boost::bind(&CKingdomInterface::listToTowns,this),748,64+size*116,"OVBUTN6.DEF");
  57. toTowns->block(0);
  58. exit = new AdventureMapButton (CGI->generaltexth->allTexts[600],"",
  59. boost::bind(&CKingdomInterface::close,this),748,99+size*116,"OVBUTN1.DEF");
  60. exit->bitmapOffset = 3;
  61. statusbar = new CStatusBar(pos.x+7,pos.y+91+size*116,"TSTATBAR.bmp",732);
  62. resdatabar = new CResDataBar("KRESBAR.bmp",pos.x+3,pos.y+111+size*116,32,2,76,76);
  63. for (int i=0; i<RESOURCE_QUANTITY; i++)
  64. incomes.push_back(new CResIncomePic(i,mines));
  65. heroes.resize(size);
  66. for(size_t i=0;i<size;i++)//preparing lists for input
  67. heroes[i] = new CHeroItem(i);
  68. towns.resize(size);
  69. for(size_t i=0;i<size;i++)
  70. towns[i] = new CTownItem(i);
  71. slider = new CSlider(4, 4, size*116+19, boost::bind (&CKingdomInterface::sliderMoved, this, _1),
  72. size, LOCPLINT->cb->howManyHeroes(showHarrisoned), 0, false, 0);
  73. //creating objects list
  74. ObjTop = new AdventureMapButton ("","", boost::bind(&CKingdomInterface::moveObjectList,this,0),
  75. 733,4,"OVBUTN4.DEF");
  76. ObjUp = new AdventureMapButton ("","", boost::bind(&CKingdomInterface::moveObjectList,this,1),
  77. 733,24,"OVBUTN4.DEF");
  78. ObjUp->bitmapOffset = 4;
  79. ObjDown = new AdventureMapButton ("","", boost::bind(&CKingdomInterface::moveObjectList,this,2),
  80. 733,size*116-18,"OVBUTN4.DEF");
  81. ObjDown->bitmapOffset = 6;
  82. ObjBottom = new AdventureMapButton ("","", boost::bind(&CKingdomInterface::moveObjectList,this,3),
  83. 733,size*116+2,"OVBUTN4.DEF");
  84. ObjBottom->bitmapOffset = 2;
  85. std::map<std::pair<int,int>,int> addObjects;//objects to print, except 17th dwelling
  86. //format: (id,subID),image index
  87. #define INSERT_MAP addObjects.insert(std::pair<std::pair<int,int>,int>(std::pair<int,int>
  88. INSERT_MAP (20,1) ,81));//Golem factory
  89. INSERT_MAP (42,0) ,82));//Lighthouse
  90. INSERT_MAP (33,0) ,83));//Garrison
  91. INSERT_MAP (219,0),83));//Garrison
  92. INSERT_MAP (33,1) ,84));//Anti-magic Garrison
  93. INSERT_MAP (219,1),84));//Anti-magic Garrison
  94. INSERT_MAP (53,7) ,85));//Abandoned mine
  95. INSERT_MAP (20,0) ,86));//Conflux
  96. INSERT_MAP (87,0) ,87));//Harbor
  97. #undef INSERT_MAP
  98. for(size_t i = 0; i<CGI->state->map->objects.size(); i++)
  99. {
  100. CGObjectInstance* obj = CGI->state->map->objects[i];
  101. if (obj)
  102. {
  103. std::pair<int,int > curElm = std::pair<int,int >(obj->ID, obj->subID);
  104. if (obj->tempOwner == CGI->state->currentPlayer)
  105. {
  106. if ( obj->ID == 17 )
  107. {
  108. objList[obj->subID].first += 1;
  109. objList[obj->subID].second = & CGI->creh->creatures[CGI->objh->cregens[obj->subID]].namePl;
  110. }
  111. else if (addObjects.find(curElm) != addObjects.end())
  112. {
  113. objList[addObjects[curElm]].first += 1;
  114. objList[addObjects[curElm]].second = & obj->hoverName;
  115. }
  116. }
  117. }
  118. }
  119. addObjects.clear();
  120. objSize = (size*116-64)/57; //in object list will fit (height of panel)/(height of one element) items
  121. ObjList.resize(objSize);
  122. for(size_t i=0;i<objSize;i++)
  123. {
  124. ObjList[i] = new HoverableArea();
  125. ObjList[i]->pos = genRect(50,50,pos.x+740,pos.y+44+i*57);
  126. }
  127. }
  128. void CKingdomInterface::moveObjectList(int newPos)
  129. {
  130. int top = objList.size() > objSize ? 0 : objList.size() - objSize ;
  131. int bottom = objList.size() > objSize ? objList.size() - objSize : 0 ;
  132. switch (newPos)//checking what button was pressed
  133. {
  134. case 0: objPos = top;
  135. break;
  136. case 1: objPos = objPos==top?top:(objPos-1);
  137. break;
  138. case 2: objPos = objPos==bottom?bottom:(objPos+1);
  139. break;
  140. case 3: objPos = bottom;
  141. break;
  142. }
  143. GH.totalRedraw();
  144. }
  145. CKingdomInterface::~CKingdomInterface()
  146. {
  147. SDL_FreeSurface(bg);
  148. delete title;
  149. delete slots;
  150. delete fort;
  151. delete hall;
  152. delete mines;
  153. towns.clear();
  154. heroes.clear();
  155. incomes.clear();
  156. ObjList.clear();
  157. objList.clear();
  158. }
  159. void CKingdomInterface::close()
  160. {
  161. GH.popIntTotally(this);
  162. }
  163. void CKingdomInterface::showAll( SDL_Surface * to/*=NULL*/)
  164. {
  165. LOCPLINT->adventureInt->resdatabar.draw(to);
  166. blitAt(bg,pos,to);
  167. resdatabar->draw(to);
  168. toTowns->show(to);
  169. toHeroes->show(to);
  170. exit->show(to);
  171. ObjTop->show(to);
  172. ObjUp->show(to);
  173. ObjDown->show(to);
  174. ObjBottom->show(to);
  175. for (size_t i=0; i<ObjList.size(); i++)//list may be moved, recreate hover text
  176. ObjList[i]->hoverText = "";
  177. int skipCount=0, curPos=objPos<0?(-objPos):0;
  178. for (std::map<int,std::pair<int, std::string*> >::iterator it=objList.begin(); it!= objList.end(); it++)
  179. {
  180. if (skipCount<objPos)
  181. {
  182. skipCount++;
  183. continue;
  184. }
  185. blitAt(objPics->ourImages[(*it).first].bitmap,pos.x+740,pos.y+44+curPos*57,to);
  186. std::ostringstream ostrs;
  187. ostrs << (*it).second.first;
  188. CSDL_Ext::printTo(ostrs.str(),pos.x+790,pos.y+94+curPos*57,GEOR13,zwykly,to);
  189. ObjList[curPos]->hoverText = * (*it).second.second;
  190. curPos++;
  191. if (curPos == objSize)
  192. break;
  193. }
  194. if (state == 1)
  195. {//printing text "Town", "Harrisoned hero", "Visiting hero"
  196. CSDL_Ext::printAtMiddle(CGI->generaltexth->overview[3],pos.x+145,pos.y+12,TNRB16,zwykly,to);
  197. CSDL_Ext::printAtMiddle(CGI->generaltexth->overview[4],pos.x+370,pos.y+12,TNRB16,zwykly,to);
  198. CSDL_Ext::printAtMiddle(CGI->generaltexth->overview[5],pos.x+600,pos.y+12,TNRB16,zwykly,to);
  199. for (size_t i=0; i<size; i++)
  200. towns[i]->show(to);//show town list
  201. }
  202. else
  203. {//text "Hero/stats" and "Skills"
  204. CSDL_Ext::printAtMiddle(CGI->generaltexth->overview[0],pos.x+150,pos.y+12,TNRB16,zwykly,to);
  205. CSDL_Ext::printAtMiddle(CGI->generaltexth->overview[1],pos.x+500,pos.y+12,TNRB16,zwykly,to);
  206. for (size_t i=0; i<size; i++)
  207. heroes[i]->show(to);//show hero list
  208. }
  209. for(size_t i=0;i<incomes.size();i++)
  210. incomes[i]->show(to);//printing resource incomes
  211. slider->showAll(to);
  212. if(screen->w != 800 || screen->h !=600)
  213. CMessage::drawBorder(LOCPLINT->playerID,to,828,136+116*size+29,pos.x-14,pos.y-15);
  214. show(to);
  215. }
  216. void CKingdomInterface::show(SDL_Surface * to)
  217. {
  218. statusbar->show(to);
  219. }
  220. void CKingdomInterface::activate()
  221. {
  222. LOCPLINT->statusbar = statusbar;
  223. exit->activate();
  224. toTowns->activate();
  225. toHeroes->activate();
  226. ObjTop->activate();
  227. ObjUp->activate();
  228. ObjDown->activate();
  229. ObjBottom->activate();
  230. for (size_t i=0; i<ObjList.size(); i++)
  231. ObjList[i]->activate();
  232. for (size_t i=0; i<incomes.size(); i++)
  233. incomes[i]->activate();
  234. if (state == 1)
  235. for (int i=0; i<size; i++)
  236. towns[i]->activate();
  237. else
  238. for (int i=0; i<size; i++)
  239. heroes[i]->activate();
  240. slider->activate();
  241. }
  242. void CKingdomInterface::deactivate()
  243. {
  244. exit->deactivate();
  245. toTowns->deactivate();
  246. toHeroes->deactivate();
  247. ObjTop->deactivate();
  248. ObjUp->deactivate();
  249. ObjDown->deactivate();
  250. ObjBottom->deactivate();
  251. for (size_t i=0; i<ObjList.size(); i++)
  252. ObjList[i]->deactivate();
  253. for (size_t i=0; i<incomes.size(); i++)
  254. incomes[i]->deactivate();
  255. if (state == 1)
  256. for (int i=0; i<size; i++)
  257. towns[i]->deactivate();
  258. else
  259. for (int i=0; i<size; i++)
  260. heroes[i]->deactivate();
  261. slider->deactivate();
  262. }
  263. void CKingdomInterface::keyPressed(const SDL_KeyboardEvent & key)
  264. {
  265. }
  266. void CKingdomInterface::recreateHeroList(int pos)
  267. {
  268. std::vector<const CGHeroInstance*> Heroes = LOCPLINT->cb->getHeroesInfo(true);
  269. int i=0, cnt=0;
  270. for (int j = 0; ((j<Heroes.size()) && (i<size));j++)
  271. {
  272. if (Heroes[j]->inTownGarrison && (!showHarrisoned))//if hero in garrison and we don't show them
  273. {
  274. continue;
  275. }
  276. if (cnt<pos)//skipping heroes
  277. {
  278. cnt++;
  279. continue;
  280. }//this hero will be added
  281. heroes[i]->hero = Heroes[j];
  282. i++;
  283. }
  284. for (i;i<size;i++)//if we still have empty pieces
  285. heroes[i]->hero = NULL;//empty pic
  286. GH.totalRedraw();
  287. }
  288. void CKingdomInterface::recreateTownList(int pos)
  289. {
  290. std::vector<const CGTownInstance*> Towns = LOCPLINT->cb->getTownsInfo(true);
  291. for(int i=0;i<size;i++)
  292. {
  293. if (i+pos<Towns.size())
  294. towns[i]->town = Towns[i+pos];//replace town
  295. else
  296. towns[i]->town = NULL;//only empty pic
  297. }
  298. GH.totalRedraw();
  299. }
  300. void CKingdomInterface::listToTowns()
  301. {
  302. state = 1;
  303. toHeroes->block(0);
  304. toTowns->block(2);
  305. heroPos = slider->value;
  306. slider->setAmount(LOCPLINT->cb->howManyTowns());
  307. slider->value=townPos;//moving slider
  308. recreateTownList(townPos);
  309. for (size_t i=0;i<size;i++)//TODO:is this loop needed?
  310. {
  311. towns[i]->deactivate();
  312. heroes[i]->activate();
  313. }
  314. }
  315. void CKingdomInterface::listToHeroes()
  316. {
  317. state = 2;
  318. toHeroes->block(2);
  319. toTowns->block(0);
  320. townPos = slider->value;
  321. slider->setAmount(LOCPLINT->cb->howManyHeroes(showHarrisoned));
  322. slider->value=heroPos;//moving slider
  323. recreateHeroList(heroPos);
  324. for (size_t i=0;i<size;i++)//TODO:is this loop needed?
  325. {
  326. towns[i]->deactivate();
  327. heroes[i]->activate();
  328. }
  329. }
  330. void CKingdomInterface::sliderMoved(int newpos)
  331. {
  332. if ( state == 1 )//towns
  333. {
  334. townPos = newpos;
  335. recreateTownList(newpos);
  336. }
  337. else//heroes
  338. {
  339. heroPos = newpos;
  340. recreateHeroList(newpos);
  341. }
  342. }
  343. CKingdomInterface::CResIncomePic::CResIncomePic(int RID, CDefEssential * Mines)
  344. {
  345. used = HOVER;
  346. recActions = DISPOSE | SHARE_POS;
  347. resID = RID;
  348. pos.x += 20 + RID*80;
  349. pos.y += 31+size*116;
  350. pos.h = 54;
  351. pos.w = (resID!=7)?68:136;//gold pile is bigger
  352. mines = Mines;
  353. if ( resID != 7)
  354. {
  355. MetaString ms;
  356. ms << std::pair<ui8,ui32>(9,resID);
  357. ms.toString(hoverText);
  358. }
  359. else
  360. hoverText = CGI->generaltexth->allTexts[255];
  361. tlog1<<hoverText<<"\n";
  362. value = 0;
  363. int resource = resID==7?6:resID;
  364. for(size_t i = 0; i<CGI->state->map->objects.size(); i++)
  365. {
  366. CGObjectInstance* obj = CGI->state->map->objects[i];
  367. if (obj)
  368. if (obj->ID == 53 && obj->subID == resource && //this is mine, produce required resource
  369. CGI->state->currentPlayer == obj->tempOwner )//mine is ours
  370. value++;
  371. }
  372. if (resID == 7)//we need to calculate income of whole kingdom
  373. {
  374. value *=1000;// mines = 1000 gold
  375. std::vector<const CGHeroInstance*> heroes = LOCPLINT->cb->getHeroesInfo(true);
  376. for(size_t i=0; i<heroes.size();i++)
  377. switch(heroes[i]->getSecSkillLevel(13))//some heroes may have estates
  378. {
  379. case 1: //basic
  380. value += 125;
  381. break;
  382. case 2: //advanced
  383. value += 250;
  384. break;
  385. case 3: //expert
  386. value += 500;
  387. break;
  388. }
  389. std::vector<const CGTownInstance*> towns = LOCPLINT->cb->getTownsInfo(true);
  390. for(size_t i=0; i<towns.size();i++)
  391. value += towns[i]->dailyIncome();
  392. }
  393. }
  394. CKingdomInterface::CResIncomePic::~CResIncomePic()
  395. {
  396. }
  397. void CKingdomInterface::CResIncomePic::hover(bool on)
  398. {
  399. if (on)
  400. {
  401. LOCPLINT->statusbar->print(hoverText);
  402. }
  403. else
  404. LOCPLINT->statusbar->clear();
  405. }
  406. void CKingdomInterface::CResIncomePic::show(SDL_Surface * to)
  407. {
  408. if (resID < 7)//this is not income
  409. blitAt(mines->ourImages[resID].bitmap,pos.x,pos.y,to);
  410. std::ostringstream oss;
  411. oss << value;
  412. CSDL_Ext::printAtMiddle(oss.str(),pos.x+pos.w/2,pos.y+50,GEOR13,zwykly,to);
  413. }
  414. CKingdomInterface::CTownItem::CTownItem(int num)
  415. {
  416. recActions = DISPOSE | SHARE_POS;
  417. numb = num;
  418. pos.x += 23;
  419. pos.y += 26+num*116;
  420. pos.w = 702;
  421. pos.h = 114;
  422. town = NULL;
  423. }
  424. CKingdomInterface::CTownItem::~CTownItem()
  425. {
  426. }
  427. void CKingdomInterface::CTownItem::activate()
  428. {
  429. }
  430. void CKingdomInterface::CTownItem::deactivate()
  431. {
  432. }
  433. void CKingdomInterface::CTownItem::show(SDL_Surface * to)
  434. {
  435. if (!town)
  436. {//if NULL - print background & exit
  437. blitAt(slots->ourImages[numb % PicCount].bitmap,pos.x,pos.y,to);
  438. return;
  439. }//background
  440. blitAt(slots->ourImages[PicCount+2].bitmap,pos.x,pos.y,to);
  441. //town pic/name
  442. int townPic = town->subID*2;
  443. if (!town->hasFort())
  444. townPic += F_NUMBER*2;
  445. if(town->builded >= MAX_BUILDING_PER_TURN)
  446. townPic++;
  447. blitAt(graphics->bigTownPic->ourImages[townPic].bitmap,pos.x+5,pos.y+6,to);
  448. CSDL_Ext::printAt(town->name,pos.x+73,pos.y+7,GEOR13,zwykly,to);
  449. //fort pic
  450. townPic = town->fortLevel()-1;
  451. if (townPic==-1) townPic = 3;
  452. blitAt(fort->ourImages[townPic].bitmap,pos.x+111,pos.y+31,to);
  453. //hall pic
  454. townPic = town->hallLevel();
  455. blitAt(hall->ourImages[townPic].bitmap,pos.x+69,pos.y+31,to);
  456. //income pic
  457. std::ostringstream oss;
  458. oss << town->dailyIncome();
  459. CSDL_Ext::printAtMiddle(oss.str(),pos.x+188,pos.y+60,GEOR13,zwykly,to);
  460. // Creature bonuses/ Creature available texts - need to find text wrapper thingy
  461. // CSDL_Ext::printAtWR(CGI->generaltexth->allTexts[265],pos.x,pos.y+80,GEOR13,zwykly,to);
  462. // CSDL_Ext::printTo(CGI->generaltexth->allTexts[266],pos.x+350,pos.y+80,GEOR13,zwykly,to);
  463. for (int i=0; i<CREATURES_PER_TOWN;i++)
  464. {//creatures info
  465. int crid = -1;
  466. int bid = 30+i;
  467. if (!vstd::contains(town->builtBuildings,bid))
  468. continue;
  469. if (vstd::contains(town->builtBuildings,bid+CREATURES_PER_TOWN))
  470. {
  471. crid = town->town->upgradedCreatures[i];
  472. bid += CREATURES_PER_TOWN;
  473. }
  474. else
  475. crid = town->town->basicCreatures[i];
  476. //creature growth
  477. blitAt(graphics->smallImgs[crid],pos.x+56+i*37,pos.y+78,to);
  478. std::ostringstream oss;
  479. oss << '+' << town->creatureGrowth(i);
  480. CSDL_Ext::printTo(oss.str(),pos.x+87+i*37,pos.y+110,GEORM,zwykly,to);
  481. //creature available
  482. blitAt(graphics->smallImgs[crid],pos.x+409+i*37,pos.y+78,to);
  483. std::ostringstream ostrs;
  484. ostrs << town->creatures[i].first;
  485. CSDL_Ext::printTo(ostrs.str(),pos.x+440+i*37,pos.y+110,GEORM,zwykly,to);
  486. }
  487. const CGHeroInstance * hero = town->garrisonHero;
  488. int posX = 244;
  489. for (int i=0;i<2;i++)
  490. {//heroes info
  491. if (hero)
  492. {
  493. int iter = 0;//portrait
  494. blitAt(graphics->portraitLarge[hero->portrait],pos.x+posX,pos.y+6,to);
  495. for(std::map<si32,std::pair<ui32,si32> >::const_iterator
  496. j=hero->army.slots.begin(); j!=hero->army.slots.end(); j++)
  497. {//army
  498. int X = (iter<4)?(pos.x+posX+70+36*iter):(pos.x+posX+88+36*(iter-4));
  499. int Y = (iter<4)?(pos.y+3):(pos.y+40);
  500. iter++;
  501. blitAt(graphics->smallImgs[j->second.first],X,Y,to);
  502. std::ostringstream creanum;
  503. creanum << (j->second.second);
  504. CSDL_Ext::printTo(creanum.str(),X+30,Y+32,GEORM,zwykly,to);
  505. }
  506. }
  507. hero = town->visitingHero;
  508. posX = 476;
  509. }
  510. }
  511. CKingdomInterface::CHeroItem::CHeroItem(int num)
  512. {
  513. recActions = DISPOSE | SHARE_POS;
  514. numb = num;
  515. pos.x += 23;
  516. pos.y += 26+num*116;
  517. pos.w = 702;
  518. pos.h = 114;
  519. hero = NULL;
  520. artGroup = 0;
  521. }
  522. CKingdomInterface::CHeroItem::~CHeroItem()
  523. {
  524. }
  525. void CKingdomInterface::CHeroItem::show(SDL_Surface * to)
  526. {
  527. if (!hero)
  528. {//if we have no hero for this slot - print background & exit
  529. blitAt(slots->ourImages[numb % PicCount].bitmap,pos.x,pos.y,to);
  530. return;
  531. }//print background, different for arts view/backpack mode
  532. blitAt(slots->ourImages[(artGroup=2)?PicCount:(PicCount+1)].bitmap,pos.x,pos.y,to);
  533. //text "Artifacts"
  534. CSDL_Ext::printAtMiddle(CGI->generaltexth->overview[2],pos.x+320,pos.y+55,GEOR13,zwykly,to);
  535. int X = pos.x+6;//portrait
  536. blitAt(graphics->portraitLarge[hero->portrait],pos.x+5,pos.y+6,to);
  537. for(std::map<si32,std::pair<ui32,si32> >::const_iterator
  538. j=hero->army.slots.begin(); j!=hero->army.slots.end(); j++)
  539. {//army
  540. blitAt(graphics->smallImgs[j->second.first],X,pos.y+78,to);
  541. std::ostringstream creanum;
  542. creanum << (j->second.second);
  543. CSDL_Ext::printTo(creanum.str(),X+30,pos.y+110,GEOR13,zwykly,to);
  544. X+=36;
  545. }//hero name
  546. CSDL_Ext::printAt(hero->name,pos.x+73,pos.y+7,GEOR13,zwykly,to);
  547. for (int i = 0; i<6; i++)
  548. {//primary skills, mana and exp. pics
  549. blitAt(graphics->pskillst->ourImages[i].bitmap,(i<4)?(pos.x+78+36*i):(pos.x+539-52*i),
  550. (i<4)?(pos.y+26):(pos.y+6),to);
  551. if (i>3) continue;//primary skills text
  552. std::ostringstream str;
  553. str << (hero->primSkills[i]);
  554. CSDL_Ext::printAtMiddle(str.str(),pos.x+95+36*i,pos.y+65,GEOR13,zwykly,to);
  555. }
  556. {//luck and morale pics, experience and mana text
  557. blitAt(graphics->luck30->ourImages[hero->getCurrentLuck()+3].bitmap,pos.x+222,pos.y+30,to);
  558. blitAt(graphics->morale30->ourImages[hero->getCurrentMorale()+3].bitmap,pos.x+222,pos.y+54,to);
  559. std::ostringstream str;
  560. str << (hero->exp);
  561. CSDL_Ext::printAtMiddle(str.str(),(pos.x+348),(pos.y+31),GEORM,zwykly,to);
  562. std::ostringstream strnew;
  563. strnew << (hero->mana)<<"/"<<(hero->manaLimit());
  564. CSDL_Ext::printAtMiddle(strnew.str(),(pos.x+298),(pos.y+31),GEORM,zwykly,to);
  565. }
  566. //hero speciality
  567. blitAt(graphics->un32->ourImages[hero->subID].bitmap, pos.x+375, pos.y+6, to);
  568. for(int i=0; i<hero->secSkills.size(); i++)
  569. {//secondary skills
  570. int skill = hero->secSkills[i].first,
  571. level = hero->secSkills[i].second;
  572. blitAt(graphics->abils32->ourImages[skill*3+level+2].bitmap,pos.x+411+i*36,pos.y+6,to);
  573. }
  574. int iter=0;
  575. switch (artGroup)
  576. {//arts
  577. case 1:iter = 9;//misc. arts, spellbook, war machines
  578. case 0://equipped arts
  579. for (int i = iter ; i<iter+9;i++)
  580. {
  581. int artID = hero->getArtAtPos(i);
  582. if (artID>=0)
  583. blitAt(graphics->artDefs->ourImages[artID].bitmap,pos.x+268+48*(i%9),pos.y+66,to);
  584. }
  585. break;
  586. case 2://TODO:backpack
  587. break;
  588. default: tlog1<<"Unknown artifact group: "<<artGroup<<"\n";
  589. }
  590. }
  591. void CKingdomInterface::CHeroItem::onArtChange(int newstate)
  592. {
  593. artGroup = newstate;
  594. }
  595. void CKingdomInterface::CHeroItem::activate()
  596. {
  597. }
  598. void CKingdomInterface::CHeroItem::deactivate()
  599. {
  600. }