CAdvmapInterface.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. #include "stdafx.h"
  2. #include "CAdvmapInterface.h"
  3. extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX; //fonts
  4. using namespace boost::logic;
  5. using namespace CSDL_Ext;
  6. CAdvMapInt::~CAdvMapInt()
  7. {
  8. SDL_FreeSurface(bg);
  9. }
  10. AdventureMapButton::AdventureMapButton ()
  11. {
  12. type=2;
  13. abs=true;
  14. active=false;
  15. ourObj=NULL;
  16. state=0;
  17. }
  18. AdventureMapButton::AdventureMapButton
  19. ( std::string Name, std::string HelpBox, void(CAdvMapInt::*Function)(), int x, int y, std::string defName, bool activ, std::vector<std::string> * add )
  20. {
  21. type=2;
  22. abs=true;
  23. active=false;
  24. ourObj=NULL;
  25. state=0;
  26. name=Name;
  27. helpBox=HelpBox;
  28. int est = LOCPLINT->playerID;
  29. CDefHandler * temp = CGI->spriteh->giveDef(defName); //todo: moze cieknac
  30. for (int i=0;i<temp->ourImages.size();i++)
  31. {
  32. imgs.resize(1);
  33. imgs[0].push_back(temp->ourImages[i].bitmap);
  34. blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID);
  35. }
  36. if (add)
  37. {
  38. imgs.resize(imgs.size()+add->size());
  39. for (int i=0; i<add->size();i++)
  40. {
  41. temp = CGI->spriteh->giveDef((*add)[i]);
  42. for (int j=0;j<temp->ourImages.size();j++)
  43. {
  44. imgs[i+1].push_back(temp->ourImages[j].bitmap);
  45. blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID);
  46. }
  47. }
  48. delete add;
  49. }
  50. function = Function;
  51. pos.x=x;
  52. pos.y=y;
  53. pos.w = imgs[curimg][0]->w;
  54. pos.h = imgs[curimg][0]->h -1;
  55. if (activ)
  56. activate();
  57. }
  58. void AdventureMapButton::clickLeft (tribool down)
  59. {
  60. if (down)
  61. {
  62. state=1;
  63. }
  64. else
  65. {
  66. state=0;
  67. }
  68. show();
  69. if (pressedL && (down==false))
  70. (LOCPLINT->adventureInt->*function)();
  71. pressedL=state;
  72. }
  73. void AdventureMapButton::clickRight (tribool down)
  74. {
  75. //TODO: show/hide infobox
  76. }
  77. void AdventureMapButton::hover (bool on)
  78. {
  79. Hoverable::hover(on);
  80. if (on)
  81. LOCPLINT->adventureInt->statusbar.print(name);
  82. else if (LOCPLINT->adventureInt->statusbar.current==name)
  83. LOCPLINT->adventureInt->statusbar.clear();
  84. }
  85. void AdventureMapButton::activate()
  86. {
  87. if (active) return;
  88. active=true;
  89. ClickableL::activate();
  90. Hoverable::activate();
  91. KeyInterested::activate();
  92. }
  93. void AdventureMapButton::keyPressed (SDL_KeyboardEvent & key)
  94. {
  95. //TODO: check if it's shortcut
  96. }
  97. void AdventureMapButton::deactivate()
  98. {
  99. if (!active) return;
  100. active=false;
  101. ClickableL::deactivate();
  102. Hoverable::deactivate();
  103. KeyInterested::deactivate();
  104. }
  105. void CList::activate()
  106. {
  107. ClickableL::activate();
  108. ClickableR::activate();
  109. Hoverable::activate();
  110. KeyInterested::activate();
  111. };
  112. void CList::deactivate()
  113. {
  114. ClickableL::deactivate();
  115. ClickableR::deactivate();
  116. Hoverable::deactivate();
  117. KeyInterested::deactivate();
  118. };
  119. void CList::clickLeft(tribool down)
  120. {
  121. };
  122. CStatusBar::CStatusBar(int x, int y)
  123. {
  124. bg=CGI->bitmaph->loadBitmap("ADROLLVR.bmp");
  125. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  126. pos.x=x;
  127. pos.y=y;
  128. pos.w=bg->w;
  129. pos.h=bg->h;
  130. middlex=(bg->w/2)+x;
  131. middley=(bg->h/2)+y;
  132. }
  133. CStatusBar::~CStatusBar()
  134. {
  135. SDL_FreeSurface(bg);
  136. }
  137. void CStatusBar::clear()
  138. {
  139. current="";
  140. blitAtWR(bg,pos.x,pos.y);
  141. }
  142. void CStatusBar::print(std::string text)
  143. {
  144. current=text;
  145. blitAtWR(bg,pos.x,pos.y);
  146. printAtMiddle(current,middlex,middley,GEOR13,zwykly);
  147. }
  148. void CStatusBar::show()
  149. {
  150. blitAtWR(bg,pos.x,pos.y);
  151. printAtMiddle(current,middlex,middley,GEOR13,zwykly);
  152. }
  153. CTerrainRect::CTerrainRect():currentPath(NULL)
  154. {
  155. pos.x=7;
  156. pos.y=6;
  157. pos.w=594;
  158. pos.h=547;
  159. arrows = CGI->spriteh->giveDef("ADAG.DEF");
  160. for(int y=0; y<arrows->ourImages.size(); ++y)
  161. {
  162. CSDL_Ext::fullAlphaTransform(arrows->ourImages[y].bitmap);
  163. }
  164. }
  165. void CTerrainRect::activate()
  166. {
  167. ClickableL::activate();
  168. ClickableR::activate();
  169. Hoverable::activate();
  170. KeyInterested::activate();
  171. };
  172. void CTerrainRect::deactivate()
  173. {
  174. ClickableL::deactivate();
  175. ClickableR::deactivate();
  176. Hoverable::deactivate();
  177. KeyInterested::deactivate();
  178. };
  179. void CTerrainRect::clickLeft(tribool down){}
  180. void CTerrainRect::clickRight(tribool down){}
  181. void CTerrainRect::hover(bool on){}
  182. void CTerrainRect::keyPressed (SDL_KeyboardEvent & key){}
  183. void CTerrainRect::show()
  184. {
  185. SDL_Surface * teren = CGI->mh->terrainRect
  186. (LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y,
  187. 19,18,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim);
  188. SDL_BlitSurface(teren,&genRect(547,594,0,0),ekran,&genRect(547,594,7,6));
  189. SDL_FreeSurface(teren);
  190. if (currentPath)
  191. {
  192. for (int i=0;i<currentPath->nodes.size()-1;i++)
  193. {
  194. int pn=-1;//number of picture
  195. if (i==0) //last tile
  196. {
  197. int x = 32*(currentPath->nodes[i].x-LOCPLINT->adventureInt->position.x)+7,
  198. y = 32*(currentPath->nodes[i].y-LOCPLINT->adventureInt->position.y)+6;
  199. if (x<0 || y<0 || x>pos.w || y>pos.h)
  200. continue;
  201. pn=0;
  202. }
  203. else
  204. {
  205. std::vector<CPathNode> & cv = currentPath->nodes;
  206. if (cv[i+1].x == cv[i].x-1 && cv[i+1].y == cv[i].y-1)
  207. {
  208. if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y)
  209. {
  210. pn = 3;
  211. }
  212. else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y+1)
  213. {
  214. pn = 12;
  215. }
  216. else if(cv[i-1].x == cv[i].x && cv[i-1].y == cv[i].y+1)
  217. {
  218. pn = 21;
  219. }
  220. else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y+1)
  221. {
  222. pn = 22;
  223. }
  224. else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y-1)
  225. {
  226. pn = 2;
  227. }
  228. }
  229. else if (cv[i+1].x == cv[i].x && cv[i+1].y == cv[i].y-1)
  230. {
  231. if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y+1)
  232. {
  233. pn = 4;
  234. }
  235. else if(cv[i-1].x == cv[i].x && cv[i-1].y == cv[i].y+1)
  236. {
  237. pn = 13;
  238. }
  239. else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y+1)
  240. {
  241. pn = 22;
  242. }
  243. }
  244. else if (cv[i+1].x == cv[i].x+1 && cv[i+1].y == cv[i].y-1)
  245. {
  246. if(cv[i-1].x == cv[i].x && cv[i-1].y == cv[i].y+1)
  247. {
  248. pn = 5;
  249. }
  250. else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y+1)
  251. {
  252. pn = 14;
  253. }
  254. else if(cv[i-1].x-1 == cv[i].x && cv[i-1].y == cv[i].y)
  255. {
  256. pn = 23;
  257. }
  258. else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y-1)
  259. {
  260. pn = 24;
  261. }
  262. else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y+1)
  263. {
  264. pn = 4;
  265. }
  266. }
  267. else if (cv[i+1].x == cv[i].x+1 && cv[i+1].y == cv[i].y)
  268. {
  269. if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y+1)
  270. {
  271. pn = 6;
  272. }
  273. else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y)
  274. {
  275. pn = 15;
  276. }
  277. else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y-1)
  278. {
  279. pn = 24;
  280. }
  281. }
  282. else if (cv[i+1].x == cv[i].x+1 && cv[i+1].y == cv[i].y+1)
  283. {
  284. if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y)
  285. {
  286. pn = 7;
  287. }
  288. else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y-1)
  289. {
  290. pn = 16;
  291. }
  292. else if(cv[i-1].x == cv[i].x && cv[i-1].y == cv[i].y-1)
  293. {
  294. pn = 17;
  295. }
  296. else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y+1)
  297. {
  298. pn = 6;
  299. }
  300. else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y-1)
  301. {
  302. pn = 18;
  303. }
  304. }
  305. else if (cv[i+1].x == cv[i].x && cv[i+1].y == cv[i].y+1)
  306. {
  307. if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y-1)
  308. {
  309. pn = 8;
  310. }
  311. else if(cv[i-1].x == cv[i].x && cv[i-1].y == cv[i].y-1)
  312. {
  313. pn = 9;
  314. }
  315. else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y-1)
  316. {
  317. pn = 18;
  318. }
  319. }
  320. else if (cv[i+1].x == cv[i].x-1 && cv[i+1].y == cv[i].y+1)
  321. {
  322. if(cv[i-1].x == cv[i].x && cv[i-1].y == cv[i].y-1)
  323. {
  324. pn = 1;
  325. }
  326. else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y-1)
  327. {
  328. pn = 10;
  329. }
  330. else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y)
  331. {
  332. pn = 19;
  333. }
  334. else if(cv[i-1].x == cv[i].x-1 && cv[i-1].y == cv[i].y-1)
  335. {
  336. pn = 8;
  337. }
  338. else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y+1)
  339. {
  340. pn = 20;
  341. }
  342. }
  343. else if (cv[i+1].x == cv[i].x-1 && cv[i+1].y == cv[i].y)
  344. {
  345. if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y-1)
  346. {
  347. pn = 2;
  348. }
  349. else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y)
  350. {
  351. pn = 11;
  352. }
  353. else if(cv[i-1].x == cv[i].x+1 && cv[i-1].y == cv[i].y+1)
  354. {
  355. pn = 20;
  356. }
  357. }
  358. }
  359. if (pn>=0)
  360. {
  361. int x = 32*(currentPath->nodes[i].x-LOCPLINT->adventureInt->position.x)+7,
  362. y = 32*(currentPath->nodes[i].y-LOCPLINT->adventureInt->position.y)+6;
  363. if (x<0 || y<0 || x>pos.w || y>pos.h)
  364. continue;
  365. int hvx = (x+arrows->ourImages[pn].bitmap->w)-(pos.x+pos.w),
  366. hvy = (y+arrows->ourImages[pn].bitmap->h)-(pos.y+pos.h);
  367. if (hvx<0 && hvy<0)
  368. blitAtWR(arrows->ourImages[pn].bitmap,x,y);
  369. else if(hvx<0)
  370. SDL_BlitSurface
  371. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,0,0),
  372. ekran,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,x,y));
  373. else if (hvy<0)
  374. {
  375. SDL_BlitSurface
  376. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,0,0),
  377. ekran,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,x,y));
  378. }
  379. else
  380. SDL_BlitSurface
  381. (arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,0,0),
  382. ekran,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,x,y));
  383. }
  384. }
  385. }
  386. }
  387. CAdvMapInt::CAdvMapInt(int Player)
  388. :player(Player),
  389. statusbar(7,556),
  390. kingOverview(CGI->preth->advKingdomOverview.first,CGI->preth->advKingdomOverview.second,
  391. &CAdvMapInt::fshowOverview, 679, 196, "IAM002.DEF"),
  392. underground(CGI->preth->advSurfaceSwitch.first,CGI->preth->advSurfaceSwitch.second,
  393. &CAdvMapInt::fswitchLevel, 711, 196, "IAM010.DEF", false, new std::vector<std::string>(1,std::string("IAM003.DEF"))),
  394. questlog(CGI->preth->advQuestlog.first,CGI->preth->advQuestlog.second,
  395. &CAdvMapInt::fshowQuestlog, 679, 228, "IAM004.DEF"),
  396. sleepWake(CGI->preth->advSleepWake.first,CGI->preth->advSleepWake.second,
  397. &CAdvMapInt::fsleepWake, 711, 228, "IAM005.DEF"),
  398. moveHero(CGI->preth->advMoveHero.first,CGI->preth->advMoveHero.second,
  399. &CAdvMapInt::fmoveHero, 679, 260, "IAM006.DEF"),
  400. spellbook(CGI->preth->advCastSpell.first,CGI->preth->advCastSpell.second,
  401. &CAdvMapInt::fshowSpellbok, 711, 260, "IAM007.DEF"),
  402. advOptions(CGI->preth->advAdvOptions.first,CGI->preth->advAdvOptions.second,
  403. &CAdvMapInt::fadventureOPtions, 679, 292, "IAM008.DEF"),
  404. sysOptions(CGI->preth->advSystemOptions.first,CGI->preth->advSystemOptions.second,
  405. &CAdvMapInt::fsystemOptions, 711, 292, "IAM009.DEF"),
  406. nextHero(CGI->preth->advNextHero.first,CGI->preth->advNextHero.second,
  407. &CAdvMapInt::fnextHero, 679, 324, "IAM000.DEF"),
  408. endTurn(CGI->preth->advEndTurn.first,CGI->preth->advEndTurn.second,
  409. &CAdvMapInt::fendTurn, 679, 356, "IAM001.DEF")
  410. {
  411. bg = CGI->bitmaph->loadBitmap("ADVMAP.bmp");
  412. blueToPlayersAdv(bg,player);
  413. scrollingLeft = false;
  414. scrollingRight = false;
  415. scrollingUp = false ;
  416. scrollingDown = false ;
  417. updateScreen = false;
  418. anim=0;
  419. animValHitCount=0; //animation frame
  420. gems.push_back(CGI->spriteh->giveDef("agemLL.def"));
  421. gems.push_back(CGI->spriteh->giveDef("agemLR.def"));
  422. gems.push_back(CGI->spriteh->giveDef("agemUL.def"));
  423. gems.push_back(CGI->spriteh->giveDef("agemUR.def"));
  424. }
  425. void CAdvMapInt::fshowOverview()
  426. {
  427. }
  428. void CAdvMapInt::fswitchLevel()
  429. {
  430. if(!CGI->ac->map.twoLevel)
  431. return;
  432. if (position.z)
  433. {
  434. position.z--;
  435. underground.curimg=0;
  436. underground.show();
  437. }
  438. else
  439. {
  440. underground.curimg=1;
  441. position.z++;
  442. underground.show();
  443. }
  444. updateScreen = true;
  445. }
  446. void CAdvMapInt::fshowQuestlog()
  447. {
  448. }
  449. void CAdvMapInt::fsleepWake()
  450. {
  451. }
  452. void CAdvMapInt::fmoveHero()
  453. {
  454. }
  455. void CAdvMapInt::fshowSpellbok()
  456. {
  457. }
  458. void CAdvMapInt::fadventureOPtions()
  459. {
  460. }
  461. void CAdvMapInt::fsystemOptions()
  462. {
  463. }
  464. void CAdvMapInt::fnextHero()
  465. {
  466. }
  467. void CAdvMapInt::fendTurn()
  468. {
  469. }
  470. void CAdvMapInt::show()
  471. {
  472. blitAt(bg,0,0);
  473. kingOverview.show();
  474. kingOverview.activate();
  475. underground.show();
  476. underground.activate();
  477. questlog.show();
  478. questlog.activate();
  479. sleepWake.show();
  480. sleepWake.activate();
  481. moveHero.show();
  482. moveHero.activate();
  483. spellbook.show();
  484. spellbook.activate();
  485. advOptions.show();
  486. advOptions.activate();
  487. sysOptions.show();
  488. sysOptions.activate();
  489. nextHero.show();
  490. nextHero.activate();
  491. endTurn.show();
  492. endTurn.activate();
  493. statusbar.show();
  494. SDL_Flip(ekran);
  495. }
  496. void CAdvMapInt::update()
  497. {
  498. terrain.show();
  499. blitAt(gems[2]->ourImages[LOCPLINT->playerID].bitmap,6,6);
  500. blitAt(gems[0]->ourImages[LOCPLINT->playerID].bitmap,6,508);
  501. blitAt(gems[1]->ourImages[LOCPLINT->playerID].bitmap,556,508);
  502. blitAt(gems[3]->ourImages[LOCPLINT->playerID].bitmap,556,6);
  503. updateRect(&genRect(550,600,6,6));
  504. }