CAdvmapInterface.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. #include "stdafx.h"
  2. #include "CAdvmapInterface.h"
  3. extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX; //fonts
  4. CAdvMapInt::~CAdvMapInt()
  5. {
  6. SDL_FreeSurface(bg);
  7. }
  8. AdventureMapButton::AdventureMapButton ()
  9. {
  10. type=2;
  11. abs=true;
  12. active=false;
  13. ourObj=NULL;
  14. state=0;
  15. }
  16. AdventureMapButton::AdventureMapButton
  17. ( std::string Name, std::string HelpBox, void(CAdvMapInt::*Function)(), int x, int y, std::string defName, bool activ, std::vector<std::string> * add )
  18. {
  19. type=2;
  20. abs=true;
  21. active=false;
  22. ourObj=NULL;
  23. state=0;
  24. name=Name;
  25. helpBox=HelpBox;
  26. int est = LOCPLINT->playerID;
  27. CDefHandler * temp = CGI->spriteh->giveDef(defName); //todo: moze cieknac
  28. for (int i=0;i<temp->ourImages.size();i++)
  29. {
  30. imgs.resize(1);
  31. imgs[0].push_back(temp->ourImages[i].bitmap);
  32. blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID);
  33. }
  34. if (add)
  35. {
  36. imgs.resize(imgs.size()+add->size());
  37. for (int i=0; i<add->size();i++)
  38. {
  39. temp = CGI->spriteh->giveDef((*add)[i]);
  40. for (int j=0;j<temp->ourImages.size();j++)
  41. {
  42. imgs[i+1].push_back(temp->ourImages[j].bitmap);
  43. blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID);
  44. }
  45. }
  46. delete add;
  47. }
  48. function = Function;
  49. pos.x=x;
  50. pos.y=y;
  51. pos.w = imgs[curimg][0]->w;
  52. pos.h = imgs[curimg][0]->h -1;
  53. if (activ)
  54. activate();
  55. }
  56. void AdventureMapButton::clickLeft (tribool down)
  57. {
  58. if (down)
  59. {
  60. state=1;
  61. }
  62. else
  63. {
  64. state=0;
  65. }
  66. show();
  67. if (pressedL && (down==false))
  68. (LOCPLINT->adventureInt->*function)();
  69. pressedL=state;
  70. }
  71. void AdventureMapButton::clickRight (tribool down)
  72. {
  73. //TODO: show/hide infobox
  74. }
  75. void AdventureMapButton::hover (bool on)
  76. {
  77. Hoverable::hover(on);
  78. if (on)
  79. LOCPLINT->adventureInt->statusbar.print(name);
  80. else if (LOCPLINT->adventureInt->statusbar.current==name)
  81. LOCPLINT->adventureInt->statusbar.clear();
  82. }
  83. void AdventureMapButton::activate()
  84. {
  85. if (active) return;
  86. active=true;
  87. ClickableL::activate();
  88. Hoverable::activate();
  89. KeyInterested::activate();
  90. }
  91. void AdventureMapButton::keyPressed (SDL_KeyboardEvent & key)
  92. {
  93. //TODO: check if it's shortcut
  94. }
  95. void AdventureMapButton::deactivate()
  96. {
  97. if (!active) return;
  98. active=false;
  99. ClickableL::deactivate();
  100. Hoverable::deactivate();
  101. KeyInterested::deactivate();
  102. }
  103. void CList::activate()
  104. {
  105. ClickableL::activate();
  106. ClickableR::activate();
  107. Hoverable::activate();
  108. KeyInterested::activate();
  109. };
  110. void CList::deactivate()
  111. {
  112. ClickableL::deactivate();
  113. ClickableR::deactivate();
  114. Hoverable::deactivate();
  115. KeyInterested::deactivate();
  116. };
  117. void CList::clickLeft(tribool down)
  118. {
  119. };
  120. CStatusBar::CStatusBar(int x, int y)
  121. {
  122. bg=CGI->bitmaph->loadBitmap("ADROLLVR.bmp");
  123. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  124. pos.x=x;
  125. pos.y=y;
  126. pos.w=bg->w;
  127. pos.h=bg->h;
  128. middlex=(bg->w/2)+x;
  129. middley=(bg->h/2)+y;
  130. }
  131. CStatusBar::~CStatusBar()
  132. {
  133. SDL_FreeSurface(bg);
  134. }
  135. void CStatusBar::clear()
  136. {
  137. current="";
  138. blitAtWR(bg,pos.x,pos.y);
  139. }
  140. void CStatusBar::print(std::string text)
  141. {
  142. current=text;
  143. blitAtWR(bg,pos.x,pos.y);
  144. printAtMiddle(current,middlex,middley,GEOR13,zwykly);
  145. }
  146. void CStatusBar::show()
  147. {
  148. blitAtWR(bg,pos.x,pos.y);
  149. printAtMiddle(current,middlex,middley,GEOR13,zwykly);
  150. }
  151. void CTerrainRect::activate()
  152. {
  153. ClickableL::activate();
  154. ClickableR::activate();
  155. Hoverable::activate();
  156. KeyInterested::activate();
  157. };
  158. void CTerrainRect::deactivate()
  159. {
  160. ClickableL::deactivate();
  161. ClickableR::deactivate();
  162. Hoverable::deactivate();
  163. KeyInterested::deactivate();
  164. };
  165. void CTerrainRect::clickLeft(tribool down){}
  166. void CTerrainRect::clickRight(tribool down){}
  167. void CTerrainRect::hover(bool on){}
  168. void CTerrainRect::keyPressed (SDL_KeyboardEvent & key){}
  169. void CTerrainRect::show()
  170. {
  171. SDL_Surface * teren = CGI->mh->terrainRect
  172. (LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y,
  173. 19,18,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim);
  174. SDL_BlitSurface(teren,&genRect(547,594,0,0),ekran,&genRect(547,594,7,6));
  175. SDL_FreeSurface(teren);
  176. }
  177. CAdvMapInt::CAdvMapInt(int Player)
  178. :player(Player),
  179. statusbar(7,556),
  180. kingOverview(CGI->preth->advKingdomOverview.first,CGI->preth->advKingdomOverview.second,
  181. &CAdvMapInt::fshowOverview, 679, 196, "IAM002.DEF"),
  182. underground(CGI->preth->advSurfaceSwitch.first,CGI->preth->advSurfaceSwitch.second,
  183. &CAdvMapInt::fswitchLevel, 711, 196, "IAM010.DEF", false, new std::vector<std::string>(1,std::string("IAM003.DEF"))),
  184. questlog(CGI->preth->advQuestlog.first,CGI->preth->advQuestlog.second,
  185. &CAdvMapInt::fshowQuestlog, 679, 228, "IAM004.DEF"),
  186. sleepWake(CGI->preth->advSleepWake.first,CGI->preth->advSleepWake.second,
  187. &CAdvMapInt::fsleepWake, 711, 228, "IAM005.DEF"),
  188. moveHero(CGI->preth->advMoveHero.first,CGI->preth->advMoveHero.second,
  189. &CAdvMapInt::fmoveHero, 679, 260, "IAM006.DEF"),
  190. spellbook(CGI->preth->advCastSpell.first,CGI->preth->advCastSpell.second,
  191. &CAdvMapInt::fshowSpellbok, 711, 260, "IAM007.DEF"),
  192. advOptions(CGI->preth->advAdvOptions.first,CGI->preth->advAdvOptions.second,
  193. &CAdvMapInt::fadventureOPtions, 679, 292, "IAM008.DEF"),
  194. sysOptions(CGI->preth->advSystemOptions.first,CGI->preth->advSystemOptions.second,
  195. &CAdvMapInt::fsystemOptions, 711, 292, "IAM009.DEF"),
  196. nextHero(CGI->preth->advNextHero.first,CGI->preth->advNextHero.second,
  197. &CAdvMapInt::fnextHero, 679, 324, "IAM000.DEF"),
  198. endTurn(CGI->preth->advEndTurn.first,CGI->preth->advEndTurn.second,
  199. &CAdvMapInt::fendTurn, 679, 356, "IAM001.DEF")
  200. {
  201. bg = CGI->bitmaph->loadBitmap("ADVMAP.bmp");
  202. blueToPlayersAdv(bg,player);
  203. scrollingLeft = false;
  204. scrollingRight = false;
  205. scrollingUp = false ;
  206. scrollingDown = false ;
  207. updateScreen = false;
  208. anim=0;
  209. animValHitCount=0; //animation frame
  210. gems.push_back(CGI->spriteh->giveDef("agemLL.def"));
  211. gems.push_back(CGI->spriteh->giveDef("agemLR.def"));
  212. gems.push_back(CGI->spriteh->giveDef("agemUL.def"));
  213. gems.push_back(CGI->spriteh->giveDef("agemUR.def"));
  214. }
  215. void CAdvMapInt::fshowOverview()
  216. {
  217. }
  218. void CAdvMapInt::fswitchLevel()
  219. {
  220. if(!CGI->ac->map.twoLevel)
  221. return;
  222. if (position.z)
  223. {
  224. position.z--;
  225. underground.curimg=0;
  226. underground.show();
  227. }
  228. else
  229. {
  230. underground.curimg=1;
  231. position.z++;
  232. underground.show();
  233. }
  234. updateScreen = true;
  235. }
  236. void CAdvMapInt::fshowQuestlog()
  237. {
  238. }
  239. void CAdvMapInt::fsleepWake()
  240. {
  241. }
  242. void CAdvMapInt::fmoveHero()
  243. {
  244. }
  245. void CAdvMapInt::fshowSpellbok()
  246. {
  247. }
  248. void CAdvMapInt::fadventureOPtions()
  249. {
  250. }
  251. void CAdvMapInt::fsystemOptions()
  252. {
  253. }
  254. void CAdvMapInt::fnextHero()
  255. {
  256. }
  257. void CAdvMapInt::fendTurn()
  258. {
  259. }
  260. void CAdvMapInt::show()
  261. {
  262. blitAt(bg,0,0);
  263. kingOverview.show();
  264. kingOverview.activate();
  265. underground.show();
  266. underground.activate();
  267. questlog.show();
  268. questlog.activate();
  269. sleepWake.show();
  270. sleepWake.activate();
  271. moveHero.show();
  272. moveHero.activate();
  273. spellbook.show();
  274. spellbook.activate();
  275. advOptions.show();
  276. advOptions.activate();
  277. sysOptions.show();
  278. sysOptions.activate();
  279. nextHero.show();
  280. nextHero.activate();
  281. endTurn.show();
  282. endTurn.activate();
  283. statusbar.show();
  284. SDL_Flip(ekran);
  285. }
  286. void CAdvMapInt::update()
  287. {
  288. terrain.show();
  289. blitAt(gems[2]->ourImages[LOCPLINT->playerID].bitmap,6,6);
  290. blitAt(gems[0]->ourImages[LOCPLINT->playerID].bitmap,6,508);
  291. blitAt(gems[1]->ourImages[LOCPLINT->playerID].bitmap,556,508);
  292. blitAt(gems[3]->ourImages[LOCPLINT->playerID].bitmap,556,6);
  293. updateRect(&genRect(550,600,6,6));
  294. }