CPreGame.cpp 127 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156
  1. #include "stdafx.h"
  2. #include "CPreGame.h"
  3. #include "hch/CDefHandler.h"
  4. #include "SDL.h"
  5. #include "boost/filesystem.hpp" // includes all needed Boost.Filesystem declarations
  6. #include "boost/algorithm/string.hpp"
  7. //#include "boost/foreach.hpp"
  8. #include "zlib.h"
  9. #include "timeHandler.h"
  10. #include <sstream>
  11. #include "SDL_Extensions.h"
  12. #include "CGameInfo.h"
  13. #include "hch\CGeneralTextHandler.h"
  14. #include "CCursorHandler.h"
  15. #include "CScreenHandler.h"
  16. #include "hch\CLodHandler.h"
  17. #include "hch\CTownHandler.h"
  18. #include "hch\CHeroHandler.h"
  19. #include <cmath>
  20. #include "client/Graphics.h"
  21. #include <boost/thread.hpp>
  22. #include <boost/bind.hpp>
  23. extern SDL_Surface * screen;
  24. extern SDL_Color tytulowy, tlo, zwykly ;
  25. extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM;
  26. SDL_Rect genRect(int hh, int ww, int xx, int yy);
  27. SDL_Color genRGB(int r, int g, int b, int a=0);
  28. //void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen);
  29. CPreGame * CPG;
  30. bool isItIn(const SDL_Rect * rect, int x, int y);
  31. namespace fs = boost::filesystem;
  32. namespace s = CSDL_Ext;
  33. void HighButton::show()
  34. {
  35. blitAt(imgs->ourImages[state].bitmap,pos.x,pos.y);
  36. updateRect(&pos);
  37. }
  38. void HighButton::press(bool down)
  39. {
  40. int i;
  41. if (down) state=i=1;
  42. else state=i=0;
  43. SDL_BlitSurface(imgs->ourImages[i].bitmap,NULL,screen,&pos);
  44. updateRect(&pos);
  45. }
  46. template <class T> void SetrButton<T>::press(bool down=true)
  47. {
  48. if (!down && state==1)
  49. *poin=key;
  50. HighButton::press(down);
  51. }
  52. void HighButton::hover(bool on)
  53. {
  54. if (!highlightable) return;
  55. int i;
  56. if (on)
  57. {
  58. state=i=3;
  59. highlighted=true;
  60. }
  61. else
  62. {
  63. state=i=0;
  64. highlighted=false;
  65. }
  66. SDL_BlitSurface(imgs->ourImages[i].bitmap,NULL,screen,&pos);
  67. updateRect(&pos);
  68. }
  69. template <class T> void Button<T>::hover(bool on=true)
  70. {
  71. HighButton::hover(on);
  72. }
  73. template <class T> void Button<T>::select(bool on)
  74. {
  75. int i;
  76. if (on) state=i=3;
  77. else state=i=0;
  78. SDL_BlitSurface(imgs->ourImages[i].bitmap,NULL,screen,&pos);
  79. updateRect(&pos);
  80. if (ourGroup && on && ourGroup->type==1)
  81. {
  82. if (ourGroup->selected && ourGroup->selected!=this)
  83. ourGroup->selected->select(false);
  84. ourGroup->selected =this;
  85. }
  86. }
  87. //void Slider::clickDown(int x, int y, bool bzgl=true);
  88. //void Slider::clickUp(int x, int y, bool bzgl=true);
  89. //void Slider::mMove(int x, int y, bool bzgl=true);
  90. void Slider<>::updateSlid()
  91. {
  92. float perc = ((float)whereAreWe)/((float)positionsAmnt-capacity);
  93. float myh;
  94. if (vertical)
  95. {
  96. myh=perc*((float)pos.h-48)+pos.y+16;
  97. SDL_FillRect(screen,&genRect(pos.h-32,pos.w,pos.x,pos.y+16),0);
  98. blitAt(slider.imgs->ourImages[0].bitmap,pos.x,(int)myh);
  99. slider.pos.y=(int)myh;
  100. }
  101. else
  102. {
  103. myh=perc*((float)pos.w-48)+pos.x+16;
  104. SDL_FillRect(screen,&genRect(pos.h,pos.w-32,pos.x+16,pos.y),0);
  105. blitAt(slider.imgs->ourImages[0].bitmap,(int)myh,pos.y);
  106. slider.pos.x=(int)myh;
  107. }
  108. updateRect(&pos);
  109. }
  110. void Slider<>::moveDown()
  111. {
  112. if (whereAreWe<positionsAmnt-capacity)
  113. (CPG->*fun)(++whereAreWe);
  114. updateSlid();
  115. }
  116. void Slider<>::moveUp()
  117. {
  118. if (whereAreWe>0)
  119. (CPG->*fun)(--whereAreWe);
  120. updateSlid();
  121. }
  122. //void Slider::moveByOne(bool up);
  123. Slider<>::Slider(int x, int y, int h, int amnt, int cap, bool ver)
  124. {
  125. vertical=ver;
  126. positionsAmnt = amnt;
  127. capacity = cap;
  128. if (ver)
  129. {
  130. pos = genRect(h,16,x,y);
  131. down = Button<void(Slider::*)()>(genRect(16,16,x,y+h-16),&Slider::moveDown,CDefHandler::giveDef("SCNRBDN.DEF"),false);
  132. up = Button<void(Slider::*)()>(genRect(16,16,x,y),&Slider::moveUp,CDefHandler::giveDef("SCNRBUP.DEF"),false);
  133. slider = Button<void(Slider::*)()>(genRect(16,16,x,y+16),NULL,CDefHandler::giveDef("SCNRBSL.DEF"),false);
  134. }
  135. else
  136. {
  137. pos = genRect(16,h,x,y);
  138. down = Button<void(Slider::*)()>(genRect(16,16,x+h-16,y),&Slider::moveDown,CDefHandler::giveDef("SCNRBRT.DEF"),false);
  139. up = Button<void(Slider::*)()>(genRect(16,16,x,y),&Slider::moveUp,CDefHandler::giveDef("SCNRBLF.DEF"),false);
  140. slider = Button<void(Slider::*)()>(genRect(16,16,x+16,y),NULL,CDefHandler::giveDef("SCNRBSL.DEF"),false);
  141. }
  142. moving = false;
  143. whereAreWe=0;
  144. }
  145. void Slider<>::deactivate()
  146. {
  147. CPG->interested.erase(std::find(CPG->interested.begin(),CPG->interested.end(),this));
  148. }
  149. void Slider<>::activate()
  150. {
  151. SDL_FillRect(screen,&pos,0);
  152. up.show();
  153. down.show();
  154. slider.show();
  155. //SDL_Flip(screen);
  156. CSDL_Ext::update(screen);
  157. CPG->interested.push_back(this);
  158. }
  159. void Slider<>::handleIt(SDL_Event sEvent)
  160. {
  161. if ((sEvent.type==SDL_MOUSEBUTTONDOWN) && (sEvent.button.button == SDL_BUTTON_LEFT))
  162. {
  163. if (isItIn(&down.pos,sEvent.motion.x,sEvent.motion.y))
  164. {
  165. down.press();
  166. }
  167. else if (isItIn(&up.pos,sEvent.motion.x,sEvent.motion.y))
  168. {
  169. up.press();
  170. }
  171. else if (isItIn(&slider.pos,sEvent.motion.x,sEvent.motion.y))
  172. {
  173. //slider.press();
  174. moving=true;
  175. }
  176. else if (isItIn(&pos,sEvent.motion.x,sEvent.motion.y))
  177. {
  178. float dy;
  179. float pe;
  180. if (vertical)
  181. {
  182. dy = sEvent.motion.y-pos.y-16;
  183. pe = dy/((float)(pos.h-32));
  184. if (pe>1) pe=1;
  185. if (pe<0) pe=0;
  186. }
  187. else
  188. {
  189. dy = sEvent.motion.x-pos.x-16;
  190. pe = dy/((float)(pos.w-32));
  191. if (pe>1) pe=1;
  192. if (pe<0) pe=0;
  193. }
  194. whereAreWe = pe*(positionsAmnt-capacity);
  195. if (whereAreWe<0)whereAreWe=0;
  196. updateSlid();
  197. (CPG->*fun)(whereAreWe);
  198. }
  199. }
  200. else if ((sEvent.type==SDL_MOUSEBUTTONUP) && (sEvent.button.button == SDL_BUTTON_LEFT))
  201. {
  202. if ((down.state==1) && isItIn(&down.pos,sEvent.motion.x,sEvent.motion.y))
  203. {
  204. (this->*down.fun)();
  205. }
  206. if ((up.state==1) && isItIn(&up.pos,sEvent.motion.x,sEvent.motion.y))
  207. {
  208. (this->*up.fun)();
  209. }
  210. if (down.state==1) down.press(false);
  211. if (up.state==1) up.press(false);
  212. if (moving)
  213. {
  214. //slider.press();
  215. moving=false;
  216. }
  217. }
  218. else if (sEvent.type==SDL_KEYDOWN)
  219. {
  220. switch (sEvent.key.keysym.sym)
  221. {
  222. case (SDLK_UP):
  223. CPG->ourScenSel->mapsel.moveByOne(true);
  224. break;
  225. case (SDLK_DOWN):
  226. CPG->ourScenSel->mapsel.moveByOne(false);
  227. break;
  228. }
  229. }
  230. else if (moving && sEvent.type==SDL_MOUSEMOTION)
  231. {
  232. if (isItIn(&genRect(pos.h,pos.w+64,pos.x-32,pos.y),sEvent.motion.x,sEvent.motion.y))
  233. {
  234. int my;
  235. int all;
  236. float ile;
  237. if (vertical)
  238. {
  239. my = sEvent.motion.y-(pos.y+16);
  240. all =pos.h-48;
  241. ile = (float)my / (float)all;
  242. if (ile>1) ile=1;
  243. if (ile<0) ile=0;
  244. }
  245. else
  246. {
  247. my = sEvent.motion.x-(pos.x+16);
  248. all =pos.w-48;
  249. ile = (float)my / (float)all;
  250. if (ile>1) ile=1;
  251. if (ile<0) ile=0;
  252. }
  253. int ktory = ile*(positionsAmnt-capacity);
  254. if (ktory!=whereAreWe)
  255. {
  256. whereAreWe=ktory;
  257. updateSlid();
  258. }
  259. (CPG->*fun)(whereAreWe);
  260. }
  261. }
  262. /*else if ((sEvent.type==SDL_MOUSEBUTTONUP) && (sEvent.button.button == SDL_BUTTON_LEFT))
  263. {
  264. if (ourScenSel->pressed)
  265. {
  266. ourScenSel->pressed->press(false);
  267. ourScenSel->pressed=NULL;
  268. }
  269. for (int i=0;i<btns.size(); i++)
  270. {
  271. if (isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y))
  272. {
  273. if (btns[i]->selectable)
  274. btns[i]->select(true);
  275. if (btns[i]->fun)
  276. (this->*(btns[i]->fun))();
  277. return;
  278. }
  279. }
  280. if (isItIn(&down.pos,sEvent.motion.x,sEvent.motion.y))
  281. {
  282. (this->*down.fun)();
  283. }
  284. if (isItIn(&up.pos,sEvent.motion.x,sEvent.motion.y))
  285. {
  286. (this->*up.fun)();
  287. }
  288. if (isItIn(&slider.pos,sEvent.motion.x,sEvent.motion.y))
  289. {
  290. (this->*slider.fun)();
  291. }
  292. }*/
  293. }
  294. /********************************************************************************************/
  295. void PreGameTab::show()
  296. {
  297. if (CPG->currentTab)
  298. CPG->currentTab->hide();
  299. showed=true;
  300. CPG->currentTab=this;
  301. }
  302. void PreGameTab::hide()
  303. {
  304. showed=false;
  305. CPG->currentTab=NULL;
  306. }
  307. PreGameTab::PreGameTab()
  308. {
  309. showed=false;
  310. }
  311. /********************************************************************************************/
  312. Options::PlayerOptions::PlayerOptions(int serial, int player)
  313. :Cleft(genRect(24,11,164,133+serial*50),CPG->ourOptions->left,true,-1), //left castle arrow
  314. Cright(genRect(24,11,225,133+serial*50),CPG->ourOptions->right,false,-1), //right castle arrow
  315. Hleft(genRect(24,11,240,133+serial*50),CPG->ourOptions->left,true,0), //left hero arrow
  316. Hright(genRect(24,11,301,133+serial*50),CPG->ourOptions->right,false,0), //right hero arrow
  317. Bleft(genRect(24,11,316,133+serial*50),CPG->ourOptions->left,true,1), //left bonus arrow
  318. Bright(genRect(24,11,377,133+serial*50),CPG->ourOptions->right,false,1), //right bonus arrow
  319. flag(genRect(50,42,14,130+serial*50),CPG->ourOptions->flags[player],player)
  320. {
  321. Bleft.playerID=Bright.playerID=Hleft.playerID=Hright.playerID=Cleft.playerID=Cright.playerID=player;
  322. Bleft.serialID=Bright.serialID=Hleft.serialID=Hright.serialID=Cleft.serialID=Cright.serialID=serial;
  323. }
  324. bool Options::canUseThisHero(int ID)
  325. {
  326. //TODO: check if hero is allowed on selected map
  327. for(int i=0;i<CPG->ret.playerInfos.size();i++)
  328. if(CPG->ret.playerInfos[i].hero==ID)
  329. return false;
  330. return (usedHeroes.find(ID) == usedHeroes.end());
  331. }
  332. int Options::nextAllowedHero(int min, int max, int incl, int dir) //incl 0 - wlacznie; incl 1 - wylacznie; min-max - zakres szukania
  333. {
  334. if(dir>0)
  335. {
  336. for(int i=min+incl; i<=max-incl; i++)
  337. {
  338. if(canUseThisHero(i))
  339. return i;
  340. }
  341. }
  342. else
  343. {
  344. for(int i=max-incl; i>=min+incl; i--)
  345. {
  346. if(canUseThisHero(i))
  347. return i;
  348. }
  349. }
  350. return -1;
  351. }
  352. void Options::OptionSwitch::press(bool down)
  353. {
  354. HighButton::press(down);
  355. StartInfo::PlayerSettings * ourOpt = &CPG->ret.playerInfos[serialID];
  356. PlayerInfo * ourInf = &CPG->ourScenSel->mapsel.ourMaps[CPG->ourScenSel->mapsel.selected].players[playerID];
  357. int dir = (left) ? (-1) : (1);
  358. if (down) return;
  359. switch (which) //which button is this?
  360. {
  361. case -1: //castle change
  362. {
  363. int oCas = ourOpt->castle;
  364. if (ourOpt->castle==-2) //no castle - no change
  365. return;
  366. else if (ourOpt->castle==-1) //random => first/last available
  367. {
  368. int pom = (left) ? (F_NUMBER-1) : (0); // last or first
  369. for (;pom>=0 && pom<F_NUMBER;pom+=dir)
  370. {
  371. if (((int)pow((double)2,pom))&ourInf->allowedFactions)
  372. {
  373. ourOpt->castle=pom;
  374. break;
  375. }
  376. else continue;
  377. }
  378. }
  379. else // next/previous available
  380. {
  381. for (;;)
  382. {
  383. ourOpt->castle+=dir;
  384. if (((int)pow((double)2,ourOpt->castle))&ourInf->allowedFactions)
  385. {
  386. break;
  387. }
  388. if (ourOpt->castle>=F_NUMBER || ourOpt->castle<0)
  389. {
  390. double p1 = log((double)ourInf->allowedFactions)/log(2.0f)+0.000001f;
  391. double check = p1-((int)p1);
  392. if (check < 0.001)
  393. ourOpt->castle=(int)p1;
  394. else
  395. ourOpt->castle=-1;
  396. break;
  397. }
  398. }
  399. }
  400. if (oCas!=ourOpt->castle) //changed castle
  401. {
  402. ourOpt->hero=-1;
  403. ourOpt->bonus = Ebonus::brandom;
  404. CPG->ourOptions->showIcon(0,serialID,false);
  405. CPG->ourOptions->showIcon(1,serialID,false);
  406. }
  407. break;
  408. }
  409. case 0: //hero change
  410. {
  411. if (ourOpt->castle<0)
  412. {
  413. break;
  414. }
  415. if (ourOpt->hero==-2) //no hero - no change
  416. return;
  417. else if (ourOpt->hero==-1) //random => first/last available
  418. {
  419. int max = (ourOpt->castle*HEROES_PER_TYPE*2+15),
  420. min = (ourOpt->castle*HEROES_PER_TYPE*2);
  421. ourOpt->hero = CPG->ourOptions->nextAllowedHero(min,max,0,dir);
  422. }
  423. else
  424. {
  425. if(dir>0)
  426. ourOpt->hero = CPG->ourOptions->nextAllowedHero(ourOpt->hero,(ourOpt->castle*HEROES_PER_TYPE*2+16),1,dir);
  427. else
  428. ourOpt->hero = CPG->ourOptions->nextAllowedHero(ourOpt->castle*HEROES_PER_TYPE*2-1,ourOpt->hero,1,dir);
  429. }
  430. break;
  431. }
  432. case 1: //bonus change
  433. {
  434. if (dir>0 && ourOpt->bonus==bresource)
  435. ourOpt->bonus=brandom;
  436. else if (dir<0 && ourOpt->bonus==brandom)
  437. ourOpt->bonus=bresource;
  438. else ourOpt->bonus=(Ebonus)(ourOpt->bonus+dir);
  439. if (ourOpt->hero==-2 && ourOpt->bonus==bartifact) //no hero - can't be artifact
  440. {
  441. if (dir>0)
  442. ourOpt->bonus=brandom;
  443. else ourOpt->bonus=bgold;
  444. }
  445. if (ourOpt->castle==-1 && ourOpt->bonus==bresource)
  446. {
  447. if (dir<0)
  448. ourOpt->bonus=bgold;
  449. else ourOpt->bonus=brandom;
  450. }
  451. break;
  452. }
  453. }
  454. CPG->ourOptions->showIcon(which,serialID,false);
  455. }
  456. void Options::PlayerFlag::press(bool down)
  457. {
  458. HighButton::press(down);
  459. int i=0;
  460. for(;i<CPG->ret.playerInfos.size();i++)
  461. if(CPG->ret.playerInfos[i].color==color)
  462. break;
  463. if (CPG->ret.playerInfos[i].human || (!CPG->ourScenSel->mapsel.ourMaps[CPG->ourScenSel->mapsel.selected].players[CPG->ret.playerInfos[i].color].canHumanPlay))
  464. return; //if this is already human player, or if human is forbidden
  465. int j=0;
  466. for(;j<CPG->ret.playerInfos.size();j++)
  467. if(CPG->ret.playerInfos[j].human)
  468. break;
  469. CPG->ret.playerInfos[i].human = true;
  470. CPG->ret.playerInfos[j].human = false;
  471. std::string pom = CPG->ret.playerInfos[i].name;
  472. CPG->ret.playerInfos[i].name = CPG->ret.playerInfos[j].name;
  473. CPG->ret.playerInfos[j].name = pom;
  474. SDL_BlitSurface(CPG->ourOptions->bgs[CPG->ret.playerInfos[i].color],&genRect(19,99,5,1),screen,&genRect(19,99,62,129+i*50));
  475. SDL_UpdateRect(screen,62,129+50*i,99,19);
  476. SDL_BlitSurface(CPG->ourOptions->bgs[CPG->ret.playerInfos[j].color],&genRect(19,99,5,1),screen,&genRect(19,99,62,129+j*50));
  477. SDL_UpdateRect(screen,62,129+50*j,99,19);
  478. CSDL_Ext::printAtMiddle(CPG->ret.playerInfos[i].name,111,137+i*50,GEOR13,zwykly);
  479. CSDL_Ext::printAtMiddle(CPG->ret.playerInfos[j].name,111,137+j*50,GEOR13,zwykly);
  480. CPG->playerColor = CPG->ret.playerInfos[i].color;
  481. CPG->ourScenSel->mapsel.printFlags();
  482. };
  483. void Options::PlayerFlag::hover(bool on)
  484. {
  485. HighButton::hover(on);
  486. }
  487. void Options::showIcon (int what, int nr, bool abs) //what: -1=castle, 0=hero, 1=bonus, 2=all; abs=true -> nr is absolute
  488. {
  489. if (what==-2)
  490. {
  491. showIcon(-1,nr,abs);
  492. showIcon(0,nr,abs);
  493. showIcon(1,nr,abs);
  494. }
  495. int ab, se;
  496. if (!abs)
  497. {
  498. ab = CPG->ret.playerInfos[nr].color;
  499. se = nr;
  500. }
  501. else
  502. {
  503. ab = nr;
  504. for (int i=0; i<CPG->ret.playerInfos.size();i++)
  505. {
  506. if (CPG->ret.playerInfos[i].color==nr)
  507. {
  508. se=i;
  509. break;
  510. }
  511. }
  512. }
  513. StartInfo::PlayerSettings * ourOpt = &CPG->ret.playerInfos[se];
  514. switch (what)
  515. {
  516. case -1:
  517. {
  518. int pom=ourOpt->castle;
  519. if (ourOpt->castle<F_NUMBER && ourOpt->castle>=0)
  520. {
  521. blitAtWR(graphics->getPic(ourOpt->castle,true,false),176,130+50*se);
  522. }
  523. else if (ourOpt->castle==-1)
  524. {
  525. blitAtWR(CPG->ourOptions->rCastle,176,130+50*se);
  526. }
  527. else if (ourOpt->castle==-2)
  528. {
  529. blitAtWR(CPG->ourOptions->nCastle,176,130+50*se);
  530. }
  531. break;
  532. }
  533. case 0:
  534. {
  535. int pom=ourOpt->hero;
  536. if (ourOpt->hero==-1)
  537. {
  538. blitAtWR(CPG->ourOptions->rHero,252,130+50*se);
  539. }
  540. else if (ourOpt->hero==-2)
  541. {
  542. if(ourOpt->heroPortrait>=0)
  543. {
  544. //TODO: restore drawing hero portrait
  545. //blitAtWR(CGI->heroh->heroes[ourOpt->heroPortrait]->portraitSmall,252,130+50*se);
  546. }
  547. else
  548. {
  549. blitAtWR(CPG->ourOptions->nHero,252,130+50*se);
  550. }
  551. }
  552. else
  553. {
  554. //TODO: restore drawing hero portrait
  555. //blitAtWR(CGI->heroh->heroes[pom]->portraitSmall,252,130+50*se);
  556. }
  557. break;
  558. }
  559. case 1:
  560. {
  561. int pom;
  562. switch (ourOpt->bonus)
  563. {
  564. case -1:
  565. pom=10;
  566. break;
  567. case 0:
  568. pom=9;
  569. break;
  570. case 1:
  571. pom=8;
  572. break;
  573. case 2:
  574. pom=CGI->townh->towns[ourOpt->castle].bonus;
  575. break;
  576. }
  577. blitAtWR(bonuses->ourImages[pom].bitmap,328,130+50*se);
  578. break;
  579. }
  580. }
  581. }
  582. Options::~Options()
  583. {
  584. if (!inited) return;
  585. for (int i=0; i<bgs.size();i++)
  586. SDL_FreeSurface(bgs[i]);
  587. for (int i=0; i<flags.size();i++)
  588. delete flags[i];
  589. SDL_FreeSurface(bg);
  590. SDL_FreeSurface(rHero);
  591. SDL_FreeSurface(rCastle);
  592. SDL_FreeSurface(nHero);
  593. SDL_FreeSurface(nCastle);
  594. delete turnLength;
  595. delete left;
  596. delete right;
  597. delete bonuses;
  598. }
  599. void Options::init()
  600. {
  601. inited=true;
  602. bg = BitmapHandler::loadBitmap("ADVOPTBK.bmp");
  603. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  604. left = CDefHandler::giveDef("ADOPLFA.DEF");
  605. right = CDefHandler::giveDef("ADOPRTA.DEF");
  606. bonuses = CDefHandler::giveDef("SCNRSTAR.DEF");
  607. rHero = BitmapHandler::loadBitmap("HPSRAND1.bmp");
  608. rCastle = BitmapHandler::loadBitmap("HPSRAND0.bmp");
  609. nHero = BitmapHandler::loadBitmap("HPSRAND6.bmp");
  610. nCastle = BitmapHandler::loadBitmap("HPSRAND5.bmp");
  611. turnLength = new Slider<>(57,557,195,11,1,false);
  612. turnLength->fun=&CPreGame::setTurnLength;
  613. flags.push_back(CDefHandler::giveDef("AOFLGBR.DEF"));
  614. flags.push_back(CDefHandler::giveDef("AOFLGBB.DEF"));
  615. flags.push_back(CDefHandler::giveDef("AOFLGBY.DEF"));
  616. flags.push_back(CDefHandler::giveDef("AOFLGBG.DEF"));
  617. flags.push_back(CDefHandler::giveDef("AOFLGBO.DEF"));
  618. flags.push_back(CDefHandler::giveDef("AOFLGBP.DEF"));
  619. flags.push_back(CDefHandler::giveDef("AOFLGBT.DEF"));
  620. flags.push_back(CDefHandler::giveDef("AOFLGBS.DEF"));
  621. bgs.push_back(BitmapHandler::loadBitmap("ADOPRPNL.bmp"));
  622. bgs.push_back(BitmapHandler::loadBitmap("ADOPBPNL.bmp"));
  623. bgs.push_back(BitmapHandler::loadBitmap("ADOPYPNL.bmp"));
  624. bgs.push_back(BitmapHandler::loadBitmap("ADOPGPNL.bmp"));
  625. bgs.push_back(BitmapHandler::loadBitmap("ADOPOPNL.bmp"));
  626. bgs.push_back(BitmapHandler::loadBitmap("ADOPPPNL.bmp"));
  627. bgs.push_back(BitmapHandler::loadBitmap("ADOPTPNL.bmp"));
  628. bgs.push_back(BitmapHandler::loadBitmap("ADOPSPNL.bmp"));
  629. }
  630. void Options::show()
  631. {
  632. if (showed)return;
  633. PreGameTab::show();
  634. MapSel & ms = CPG->ourScenSel->mapsel;
  635. blitAt(bg,3,6);
  636. CPG->ourScenSel->listShowed=false;
  637. for (int i=0;i<CPG->btns.size();i++)
  638. {
  639. if (CPG->btns[i]->ID!=10) //leave only right panel buttons
  640. {
  641. CPG->btns.erase(CPG->btns.begin()+i);
  642. i--;
  643. }
  644. }
  645. CPG->interested.clear();
  646. CSDL_Ext::printAtMiddle("Advanced Options",225,35,GEORXX);
  647. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[521],224,544,GEOR13); // Player Turn Duration
  648. int playersSoFar=0;
  649. for (int i=0;i<PLAYER_LIMIT;i++)
  650. {
  651. if (!(ms.ourMaps[ms.selected].players[i].canComputerPlay || ms.ourMaps[ms.selected].players[i].canComputerPlay))
  652. continue;
  653. for (int hi=0; hi<ms.ourMaps[ms.selected].players[i].heroesNames.size(); hi++)
  654. usedHeroes.insert(ms.ourMaps[ms.selected].players[i].heroesNames[hi].heroID);
  655. blitAt(bgs[i],57,128+playersSoFar*50);
  656. poptions.push_back(new PlayerOptions(playersSoFar,i));
  657. poptions[poptions.size()-1]->nr=playersSoFar;
  658. poptions[poptions.size()-1]->color=(Ecolor)i;
  659. poptions[poptions.size()-1]->Cleft.show();
  660. poptions[poptions.size()-1]->Cright.show();
  661. poptions[poptions.size()-1]->Hleft.show();
  662. poptions[poptions.size()-1]->Hright.show();
  663. poptions[poptions.size()-1]->Bleft.show();
  664. poptions[poptions.size()-1]->Bright.show();
  665. CPG->btns.push_back(&poptions[poptions.size()-1]->Cleft);
  666. CPG->btns.push_back(&poptions[poptions.size()-1]->Cright);
  667. CPG->btns.push_back(&poptions[poptions.size()-1]->Hleft);
  668. CPG->btns.push_back(&poptions[poptions.size()-1]->Hright);
  669. CPG->btns.push_back(&poptions[poptions.size()-1]->Bleft);
  670. CPG->btns.push_back(&poptions[poptions.size()-1]->Bright);
  671. CSDL_Ext::printAtMiddle(CPG->ret.playerInfos[playersSoFar].name,111,137+playersSoFar*50,GEOR13,zwykly);
  672. if (ms.ourMaps[ms.selected].players[i].canHumanPlay)
  673. {
  674. poptions[poptions.size()-1]->flag.show();
  675. CPG->btns.push_back(&poptions[poptions.size()-1]->flag);
  676. if (ms.ourMaps[ms.selected].players[i].canComputerPlay)
  677. CSDL_Ext::printAtMiddleWB("Human or CPU",86,163+playersSoFar*50,GEORM,7,zwykly);
  678. else
  679. CSDL_Ext::printAtMiddleWB("Human",86,163+playersSoFar*50,GEORM,6,zwykly);
  680. }
  681. else
  682. CSDL_Ext::printAtMiddleWB("CPU",86,163+playersSoFar*50,GEORM,6,zwykly);
  683. playersSoFar++;
  684. }
  685. CSDL_Ext::printAtMiddleWB(CGI->generaltexth->allTexts[516],221,63,GEOR13,55,zwykly);
  686. CSDL_Ext::printAtMiddleWB(CGI->preth->getTitle(CGI->preth->zelp[256].second),109,109,GEOR13,14);
  687. CSDL_Ext::printAtMiddleWB(CGI->preth->getTitle(CGI->preth->zelp[259].second),201,109,GEOR13,10);
  688. CSDL_Ext::printAtMiddleWB(CGI->preth->getTitle(CGI->preth->zelp[260].second),275,109,GEOR13,10);
  689. CSDL_Ext::printAtMiddleWB(CGI->preth->getTitle(CGI->preth->zelp[261].second),354,109,GEOR13,10);
  690. turnLength->activate();
  691. for (int i=0;i<poptions.size();i++)
  692. showIcon(-2,i,false);
  693. for(int i=0;i<12;i++)
  694. turnLength->moveDown();
  695. //SDL_Flip(screen);
  696. CSDL_Ext::update(screen);
  697. }
  698. void Options::hide()
  699. {
  700. if (!showed) return;
  701. PreGameTab::hide();
  702. for (int i=0; i<CPG->btns.size();i++)
  703. if (CPG->btns[i]->ID==7)
  704. CPG->btns.erase(CPG->btns.begin()+i--);
  705. for (int i=0;i<poptions.size();i++)
  706. delete poptions[i];
  707. poptions.clear();
  708. turnLength->deactivate();
  709. }
  710. MapSel::~MapSel()
  711. {
  712. SDL_FreeSurface(bg);
  713. for (int i=0;i<scenImgs.size();i++)
  714. SDL_FreeSurface(scenImgs[i]);
  715. for (int i=0;i<scenList.size();i++)
  716. delete scenList[i];
  717. delete sFlags;
  718. }
  719. int MapSel::countWL()
  720. {
  721. int ret=0;
  722. for (int i=0;i<ourMaps.size();i++)
  723. {
  724. if (sizeFilter && ((ourMaps[i].width) != sizeFilter))
  725. continue;
  726. else ret++;
  727. }
  728. return ret;
  729. }
  730. void MapSel::printMaps(int from, int to, int at, bool abs)
  731. {
  732. if (true)//
  733. {
  734. int help=-1;
  735. for (int i=0;i<ourMaps.size();i++)
  736. {
  737. if (sizeFilter && ((ourMaps[i].width) != sizeFilter))
  738. continue;
  739. else help++;
  740. if (help==from)
  741. {
  742. from=i;
  743. break;
  744. }
  745. }
  746. }
  747. SDL_Surface * scenin = CSDL_Ext::newSurface(351,25);
  748. SDL_Color nasz;
  749. for (int i=at;i<to;i++)
  750. {
  751. if ((i-at+from) > ourMaps.size()-1)
  752. {
  753. SDL_Surface * scenin = CSDL_Ext::newSurface(351,25);
  754. SDL_BlitSurface(bg,&genRect(25,351,22,(i-at)*25+115),scenin,NULL);
  755. blitAt(scenin,24,121+(i-at)*25);
  756. //SDL_Flip(screen);
  757. CSDL_Ext::update(screen);
  758. SDL_FreeSurface(scenin);
  759. continue;
  760. }
  761. if (sizeFilter && ((ourMaps[(i-at)+from].width) != sizeFilter))
  762. {
  763. to++;
  764. at++;
  765. from++;
  766. if (((i-at)+from)>ourMaps.size()-1) break;
  767. else continue;
  768. }
  769. if ((i-at+from) == selected)
  770. nasz=tytulowy;
  771. else nasz=zwykly;
  772. //SDL_Rect pier = genRect(25,351,24,126+(i*25));
  773. SDL_BlitSurface(bg,&genRect(25,351,22,(i-at)*25+115),scenin,NULL);
  774. int temp=-1;
  775. std::ostringstream ostr(std::ostringstream::out); ostr << ourMaps[(i-at)+from].playerAmnt << "/" << ourMaps[(i-at)+from].humenPlayers;
  776. CSDL_Ext::printAt(ostr.str(),6,4,GEOR13,nasz,scenin, 2);
  777. std::string temp2;
  778. switch (ourMaps[(i-at)+from].width)
  779. {
  780. case 36:
  781. temp2="S";
  782. break;
  783. case 72:
  784. temp2="M";
  785. break;
  786. case 108:
  787. temp2="L";
  788. break;
  789. case 144:
  790. temp2="XL";
  791. break;
  792. default:
  793. temp2="C";
  794. break;
  795. }
  796. CSDL_Ext::printAtMiddle(temp2,50,13,GEOR13,nasz,scenin, 2);
  797. switch (ourMaps[(i-at)+from].version)
  798. {
  799. case Eformat::RoE:
  800. temp=0;
  801. break;
  802. case Eformat::AB:
  803. temp=1;
  804. break;
  805. case Eformat::SoD:
  806. temp=2;
  807. break;
  808. case Eformat::WoG:
  809. temp=3;
  810. break;
  811. }
  812. blitAt(Dtypes->ourImages[temp].bitmap,67,2,scenin);
  813. if (!(ourMaps[(i-at)+from].name.length()))
  814. ourMaps[(i-at)+from].name = "Unnamed";
  815. CSDL_Ext::printAtMiddle(ourMaps[(i-at)+from].name,192,13,GEOR13,nasz,scenin, 2);
  816. if (ourMaps[(i-at)+from].victoryCondition==EvictoryConditions::winStandard)
  817. temp=11;
  818. else temp=ourMaps[(i-at)+from].victoryCondition;
  819. blitAt(Dvic->ourImages[temp].bitmap,285,2,scenin);
  820. if (ourMaps[(i-at)+from].lossCondition.typeOfLossCon == ElossCon::lossStandard)
  821. temp=3;
  822. else temp=ourMaps[(i-at)+from].lossCondition.typeOfLossCon;
  823. blitAt(Dloss->ourImages[temp].bitmap,318,2,scenin);
  824. blitAt(scenin,24,121+(i-at)*25);
  825. SDL_UpdateRect(screen,24,121+(i-at)*25,scenin->w,scenin->h);
  826. }
  827. SDL_FreeSurface(scenin);
  828. }
  829. int MapSel::whichWL(int nr)
  830. {
  831. int help=-1;
  832. for (int i=0;i<ourMaps.size();i++)
  833. {
  834. if (sizeFilter && ((ourMaps[i].width) != sizeFilter))
  835. continue;
  836. else help++;
  837. if (help==nr)
  838. {
  839. help=i;
  840. break;
  841. }
  842. }
  843. return help;
  844. }
  845. void MapSel::hide()
  846. {
  847. if (!showed)return;
  848. PreGameTab::hide();
  849. CPG->btns.erase(std::find(CPG->btns.begin(),CPG->btns.end(),&small));
  850. CPG->btns.erase(std::find(CPG->btns.begin(),CPG->btns.end(),&medium));
  851. CPG->btns.erase(std::find(CPG->btns.begin(),CPG->btns.end(),&large));
  852. CPG->btns.erase(std::find(CPG->btns.begin(),CPG->btns.end(),&xlarge));
  853. CPG->btns.erase(std::find(CPG->btns.begin(),CPG->btns.end(),&all));
  854. CPG->btns.erase(std::find(CPG->btns.begin(),CPG->btns.end(),&nrplayer));
  855. CPG->btns.erase(std::find(CPG->btns.begin(),CPG->btns.end(),&mapsize));
  856. CPG->btns.erase(std::find(CPG->btns.begin(),CPG->btns.end(),&type));
  857. CPG->btns.erase(std::find(CPG->btns.begin(),CPG->btns.end(),&name));
  858. CPG->btns.erase(std::find(CPG->btns.begin(),CPG->btns.end(),&viccon));
  859. CPG->btns.erase(std::find(CPG->btns.begin(),CPG->btns.end(),&loscon));
  860. slid->deactivate();
  861. CPG->currentTab = NULL;
  862. };
  863. void MapSel::show()
  864. {
  865. if (showed)return;
  866. PreGameTab::show();
  867. //blit bg
  868. blitAt(bg,3,6);
  869. CSDL_Ext::printAt("Map Sizes",55,60,GEOR13);
  870. CSDL_Ext::printAt("Select a Scenario to Play",110,25,TNRB16);
  871. //size buttons
  872. small.show();
  873. medium.show();
  874. large.show();
  875. xlarge.show();
  876. all.show();
  877. CPG->btns.push_back(&small);
  878. CPG->btns.push_back(&medium);
  879. CPG->btns.push_back(&large);
  880. CPG->btns.push_back(&xlarge);
  881. CPG->btns.push_back(&all);
  882. //sort by buttons
  883. nrplayer.show();
  884. mapsize.show();
  885. type.show();
  886. name.show();
  887. viccon.show();
  888. loscon.show();
  889. CPG->btns.push_back(&nrplayer);
  890. CPG->btns.push_back(&mapsize);
  891. CPG->btns.push_back(&type);
  892. CPG->btns.push_back(&name);
  893. CPG->btns.push_back(&viccon);
  894. CPG->btns.push_back(&loscon);
  895. //print scenario list
  896. printMaps(0,18);
  897. slid->activate();
  898. //SDL_Flip(screen);
  899. CSDL_Ext::update(screen);
  900. }
  901. boost::mutex mx;
  902. void MapSel::processMaps(std::vector<std::string> &pliczkiTemp, int &index)
  903. {
  904. bool areMaps=true;
  905. int pom=-1;
  906. while(areMaps)
  907. {
  908. mx.lock();
  909. if(index>=pliczkiTemp.size())
  910. {
  911. mx.unlock();
  912. break;
  913. }
  914. else
  915. {
  916. pom = index++;
  917. mx.unlock();
  918. }
  919. gzFile tempf = gzopen(pliczkiTemp[pom].c_str(),"rb");
  920. unsigned char * sss = new unsigned char[1000];
  921. int iii=0;
  922. while(true)
  923. {
  924. if (iii>=1000) break;
  925. int z = gzgetc (tempf);
  926. if (z>=0)
  927. {
  928. sss[iii++] = unsigned char(z);
  929. }
  930. else break;
  931. }
  932. gzclose(tempf);
  933. if(iii<50) {std::cout<<"\t\tWarning: corrupted map file: "<<pliczkiTemp[pom]<<std::endl; continue;}
  934. if (!sss[4]) continue; //nie ma graczy? mapa niegrywalna //już to kiedyś komentowałem- - to bzdura //tu calkiem pasuje...
  935. CMapInfo mi(pliczkiTemp[pom],sss);
  936. mx.lock();
  937. ourMaps.push_back(mi);
  938. mx.unlock();
  939. delete[] sss;
  940. }
  941. }
  942. void MapSel::init()
  943. {
  944. //get map files names
  945. std::vector<std::string> pliczkiTemp;
  946. fs::path tie( (fs::initial_path<fs::path>())/"/maps" );
  947. fs::directory_iterator end_iter;
  948. for ( fs::directory_iterator dir (tie); dir!=end_iter; ++dir )
  949. {
  950. if (fs::is_regular(dir->status()));
  951. {
  952. if (boost::ends_with(dir->path().leaf(),std::string(".h3m")))
  953. pliczkiTemp.push_back("Maps/"+(dir->path().leaf()));
  954. }
  955. }
  956. int mapInd=0;
  957. boost::thread_group group;
  958. int cores = max(1,boost::thread::hardware_concurrency());
  959. for(int ti=0;ti<cores;ti++)
  960. group.create_thread(boost::bind(&MapSel::processMaps,this,boost::ref(pliczkiTemp),boost::ref(mapInd)));
  961. bg = BitmapHandler::loadBitmap("SCSELBCK.bmp");
  962. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  963. small.imgs = CDefHandler::giveDef("SCSMBUT.DEF");
  964. small.fun = NULL;
  965. small.pos = genRect(small.imgs->ourImages[0].bitmap->h,small.imgs->ourImages[0].bitmap->w,161,52);
  966. small.ourGroup=NULL;
  967. medium.imgs = CDefHandler::giveDef("SCMDBUT.DEF");
  968. medium.fun = NULL;
  969. medium.pos = genRect(medium.imgs->ourImages[0].bitmap->h,medium.imgs->ourImages[0].bitmap->w,208,52);
  970. medium.ourGroup=NULL;
  971. large.imgs = CDefHandler::giveDef("SCLGBUT.DEF");
  972. large.fun = NULL;
  973. large.pos = genRect(large.imgs->ourImages[0].bitmap->h,large.imgs->ourImages[0].bitmap->w,255,52);
  974. large.ourGroup=NULL;
  975. xlarge.imgs = CDefHandler::giveDef("SCXLBUT.DEF");
  976. xlarge.fun = NULL;
  977. xlarge.pos = genRect(xlarge.imgs->ourImages[0].bitmap->h,xlarge.imgs->ourImages[0].bitmap->w,302,52);
  978. xlarge.ourGroup=NULL;
  979. all.imgs = CDefHandler::giveDef("SCALBUT.DEF");
  980. all.fun = NULL;
  981. all.pos = genRect(all.imgs->ourImages[0].bitmap->h,all.imgs->ourImages[0].bitmap->w,349,52);
  982. all.ourGroup=NULL;
  983. all.selectable=xlarge.selectable=large.selectable=medium.selectable=small.selectable=false;
  984. small.what=medium.what=large.what=xlarge.what=all.what=&sizeFilter;
  985. small.key=36;medium.key=72;large.key=108;xlarge.key=144;all.key=0;
  986. //Button<> nrplayer, mapsize, type, name, viccon, loscon;
  987. nrplayer.imgs = CDefHandler::giveDef("SCBUTT1.DEF");
  988. nrplayer.fun = NULL;
  989. nrplayer.pos = genRect(nrplayer.imgs->ourImages[0].bitmap->h,nrplayer.imgs->ourImages[0].bitmap->w,26,92);
  990. nrplayer.key=ESortBy::playerAm;
  991. mapsize.imgs = CDefHandler::giveDef("SCBUTT2.DEF");
  992. mapsize.fun = NULL;
  993. mapsize.pos = genRect(mapsize.imgs->ourImages[0].bitmap->h,mapsize.imgs->ourImages[0].bitmap->w,58,92);
  994. mapsize.key=ESortBy::size;
  995. type.imgs = CDefHandler::giveDef("SCBUTCP.DEF");
  996. type.fun = NULL;
  997. type.pos = genRect(type.imgs->ourImages[0].bitmap->h,type.imgs->ourImages[0].bitmap->w,91,92);
  998. type.key=ESortBy::format;
  999. name.imgs = CDefHandler::giveDef("SCBUTT3.DEF");
  1000. name.fun = NULL;
  1001. name.pos = genRect(name.imgs->ourImages[0].bitmap->h,name.imgs->ourImages[0].bitmap->w,124,92);
  1002. name.key=ESortBy::name;
  1003. viccon.imgs = CDefHandler::giveDef("SCBUTT4.DEF");
  1004. viccon.fun = NULL;
  1005. viccon.pos = genRect(viccon.imgs->ourImages[0].bitmap->h,viccon.imgs->ourImages[0].bitmap->w,309,92);
  1006. viccon.key=ESortBy::viccon;
  1007. loscon.imgs = CDefHandler::giveDef("SCBUTT5.DEF");
  1008. loscon.fun = NULL;
  1009. loscon.pos = genRect(loscon.imgs->ourImages[0].bitmap->h,loscon.imgs->ourImages[0].bitmap->w,342,92);
  1010. loscon.key=ESortBy::loscon;
  1011. nrplayer.poin=mapsize.poin=type.poin=name.poin=viccon.poin=loscon.poin=(int*)(&sortBy);
  1012. nrplayer.fun=mapsize.fun=type.fun=name.fun=viccon.fun=loscon.fun=&CPreGame::sortMaps;
  1013. Dtypes = CDefHandler::giveDef("SCSELC.DEF");
  1014. Dvic = CDefHandler::giveDef("SCNRVICT.DEF");
  1015. Dloss = CDefHandler::giveDef("SCNRLOSS.DEF");
  1016. //Dsizes = CPG->slh->giveDef("SCNRMPSZ.DEF");
  1017. Dsizes = CDefHandler::giveDef("SCNRMPSZ.DEF");
  1018. sFlags = CDefHandler::giveDef("ITGFLAGS.DEF");
  1019. group.join_all();
  1020. std::sort(ourMaps.begin(),ourMaps.end(),mapSorter(ESortBy::name));
  1021. slid = new Slider<>(375,92,480,ourMaps.size(),18,true);
  1022. slid->fun = &CPreGame::printMapsFrom;
  1023. }
  1024. void MapSel::moveByOne(bool up)
  1025. {
  1026. int help=selected;
  1027. if (up) selected--;
  1028. else selected ++;
  1029. for (int i=selected;i<ourMaps.size() && i>=0;)
  1030. {
  1031. help=i;
  1032. if (!(sizeFilter && ((ourMaps[i].width) != sizeFilter)))
  1033. break;
  1034. if (up)
  1035. {
  1036. i--;
  1037. }
  1038. else
  1039. {
  1040. i++;
  1041. if (i<0) break;
  1042. }
  1043. }
  1044. select(help);
  1045. slid->updateSlid();
  1046. }
  1047. void MapSel::select(int which, bool updateMapsList)
  1048. {
  1049. bool dontSaveSettings = ((selected!=which) || (CPG->ret.playerInfos.size()==0));
  1050. selected = which;
  1051. if(updateMapsList)
  1052. printMaps(slid->whereAreWe,18,0,true);
  1053. int serialC=0;
  1054. if(dontSaveSettings)
  1055. {
  1056. CPG->ret.playerInfos.clear();
  1057. bool wasntpl = true;
  1058. for (int i=0;i<PLAYER_LIMIT;i++)
  1059. {
  1060. if (!(ourMaps[selected].players[i].canComputerPlay || ourMaps[selected].players[i].canComputerPlay))
  1061. continue; // this caused some serious problems becouse of lack of simple bijection between two sets of player's numbers (one is returned by CPreGame, second is used in h3m)
  1062. StartInfo::PlayerSettings pset;
  1063. pset.color=(Ecolor)i;
  1064. pset.serial = serialC;
  1065. serialC++;
  1066. pset.bonus=Ebonus::brandom;
  1067. pset.castle=-2;
  1068. if (ourMaps[which].players[i].canHumanPlay && wasntpl)
  1069. {
  1070. pset.name=CGI->generaltexth->allTexts[434]; //Player
  1071. pset.human = true;
  1072. CPG->playerColor = i;
  1073. wasntpl = false;
  1074. }
  1075. else
  1076. {
  1077. pset.name=CGI->generaltexth->allTexts[468];//Computer
  1078. pset.human = false;
  1079. }
  1080. for (int j=0;j<F_NUMBER;j++)
  1081. {
  1082. if (((int)pow((double)2,j))&ourMaps[selected].players[i].allowedFactions)
  1083. {
  1084. if (pset.castle>=0)
  1085. pset.castle=-1;
  1086. if (pset.castle==-2)
  1087. pset.castle=j;
  1088. }
  1089. }
  1090. pset.heroPortrait=-1;
  1091. if (!((ourMaps[which].players[i].generateHeroAtMainTown && ourMaps[which].players[i].hasMainTown) || ourMaps[which].players[i].p8))
  1092. pset.hero=-2;
  1093. else
  1094. pset.hero=-1;
  1095. if(ourMaps[which].players[i].mainHeroName.length())
  1096. {
  1097. pset.heroName = ourMaps[which].players[i].mainHeroName;
  1098. if((pset.heroPortrait = ourMaps[which].players[i].mainHeroPortrait)==255)
  1099. pset.heroPortrait = ourMaps[which].players[i].p9;
  1100. }
  1101. pset.handicap=0;
  1102. CPG->ret.playerInfos.push_back(pset);
  1103. }
  1104. }
  1105. printSelectedInfo();
  1106. }
  1107. MapSel::MapSel():selected(0),sizeFilter(0)
  1108. {
  1109. }
  1110. void MapSel::printSelectedInfo()
  1111. {
  1112. SDL_BlitSurface(CPG->ourScenSel->scenInf,&genRect(399,337,17,23),screen,&genRect(399,337,413,29));
  1113. SDL_BlitSurface(CPG->ourScenSel->scenInf,&genRect(50,91,18,447),screen,&genRect(50,91,414,453));
  1114. SDL_BlitSurface(CPG->ourScenSel->bScens.imgs->ourImages[0].bitmap,NULL,screen,&CPG->ourScenSel->bScens.pos);
  1115. SDL_BlitSurface(CPG->ourScenSel->bOptions.imgs->ourImages[0].bitmap,NULL,screen,&CPG->ourScenSel->bOptions.pos);
  1116. SDL_BlitSurface(CPG->ourScenSel->bRandom.imgs->ourImages[0].bitmap,NULL,screen,&CPG->ourScenSel->bRandom.pos);
  1117. //blit texts
  1118. CSDL_Ext::printAt(CGI->preth->zelp[21].second,420,25,GEOR13);
  1119. CSDL_Ext::printAt(CGI->generaltexth->allTexts[496],420,135,GEOR13);
  1120. CSDL_Ext::printAt(CGI->generaltexth->allTexts[497],420,285,GEOR13);
  1121. CSDL_Ext::printAt(CGI->generaltexth->allTexts[498],420,340,GEOR13);
  1122. CSDL_Ext::printAt(CGI->generaltexth->allTexts[390],420,406,GEOR13,zwykly);
  1123. CSDL_Ext::printAt(CGI->generaltexth->allTexts[391],585,406,GEOR13,zwykly);
  1124. int temp = ourMaps[selected].victoryCondition+1;
  1125. if (temp>20) temp=0;
  1126. std::string sss = CPG->preth->victoryConditions[temp];
  1127. if (temp && ourMaps[selected].vicConDetails->allowNormalVictory) sss+= "/" + CPG->preth->victoryConditions[0];
  1128. CSDL_Ext::printAt(sss,452,310,GEOR13,zwykly);
  1129. temp = ourMaps[selected].lossCondition.typeOfLossCon+1;
  1130. if (temp>20) temp=0;
  1131. sss = CPG->preth->lossCondtions[temp];
  1132. CSDL_Ext::printAt(sss,452,370,GEOR13,zwykly);
  1133. //blit descrption
  1134. std::vector<std::string> desc = *CMessage::breakText(ourMaps[selected].description,50);
  1135. for (int i=0;i<desc.size();i++)
  1136. CSDL_Ext::printAt(desc[i],417,152+i*13,GEOR13,zwykly);
  1137. if ((selected < 0) || (selected >= ourMaps.size()))
  1138. return;
  1139. if (ourMaps[selected].name.length())
  1140. CSDL_Ext::printAt(ourMaps[selected].name,420,41,GEORXX);
  1141. else CSDL_Ext::printAt("Unnamed",420,41,GEORXX);
  1142. std::string diff;
  1143. switch (ourMaps[selected].difficulty)
  1144. {
  1145. case 0:
  1146. diff=gdiff(CPG->preth->zelp[24].second);
  1147. break;
  1148. case 1:
  1149. diff=gdiff(CPG->preth->zelp[25].second);
  1150. break;
  1151. case 2:
  1152. diff=gdiff(CPG->preth->zelp[26].second);
  1153. break;
  1154. case 3:
  1155. diff=gdiff(CPG->preth->zelp[27].second);
  1156. break;
  1157. case 4:
  1158. diff=gdiff(CPG->preth->zelp[28].second);
  1159. break;
  1160. }
  1161. temp=-1;
  1162. switch (ourMaps[selected].width)
  1163. {
  1164. case 36:
  1165. temp=0;
  1166. break;
  1167. case 72:
  1168. temp=1;
  1169. break;
  1170. case 108:
  1171. temp=2;
  1172. break;
  1173. case 144:
  1174. temp=3;
  1175. break;
  1176. default:
  1177. temp=4;
  1178. break;
  1179. }
  1180. blitAt(Dsizes->ourImages[temp].bitmap,714,28);
  1181. temp=ourMaps[selected].victoryCondition;
  1182. if (temp>12) temp=11;
  1183. blitAt(Dvic->ourImages[temp].bitmap,420,308); //v
  1184. temp=ourMaps[selected].lossCondition.typeOfLossCon;
  1185. if (temp>12) temp=3;
  1186. blitAt(Dloss->ourImages[temp].bitmap,420,366); //l
  1187. CSDL_Ext::printAtMiddle(diff,458,477,GEOR13,zwykly);
  1188. //SDL_Flip(screen);
  1189. printFlags();
  1190. CSDL_Ext::update(screen);
  1191. }
  1192. void MapSel::printFlags()
  1193. {
  1194. int hy=405, fx=460, ex=640, myT;
  1195. if (ourMaps[selected].howManyTeams)
  1196. myT = ourMaps[selected].players[CPG->playerColor].team;
  1197. else myT = -1;
  1198. for (int i=0;i<CPG->ret.playerInfos.size();i++)
  1199. {
  1200. if (myT>=0)
  1201. {
  1202. if(ourMaps[selected].players[CPG->ret.playerInfos[i].color].team==myT)
  1203. {
  1204. blitAtWR(sFlags->ourImages[CPG->ret.playerInfos[i].color].bitmap,fx,hy);
  1205. fx+=sFlags->ourImages[CPG->ret.playerInfos[i].color].bitmap->w;
  1206. }
  1207. else
  1208. {
  1209. blitAtWR(sFlags->ourImages[CPG->ret.playerInfos[i].color].bitmap,ex,hy);
  1210. ex+=sFlags->ourImages[CPG->ret.playerInfos[i].color].bitmap->w;
  1211. }
  1212. }
  1213. else
  1214. {
  1215. if(CPG->ret.playerInfos[i].color==CPG->playerColor)
  1216. {
  1217. blitAtWR(sFlags->ourImages[CPG->ret.playerInfos[i].color].bitmap,fx,hy);
  1218. fx+=sFlags->ourImages[CPG->ret.playerInfos[i].color].bitmap->w;
  1219. }
  1220. else
  1221. {
  1222. blitAtWR(sFlags->ourImages[CPG->ret.playerInfos[i].color].bitmap,ex,hy);
  1223. ex+=sFlags->ourImages[CPG->ret.playerInfos[i].color].bitmap->w;
  1224. }
  1225. }
  1226. }
  1227. }
  1228. std::string MapSel::gdiff(std::string ss)
  1229. {
  1230. std::string ret;
  1231. for (int i=2;i<ss.length();i++)
  1232. {
  1233. if (ss[i]==' ')
  1234. break;
  1235. ret+=ss[i];
  1236. }
  1237. return ret;
  1238. }
  1239. void CPreGame::printRating()
  1240. {
  1241. SDL_BlitSurface(CPG->ourScenSel->scenInf,&genRect(47,83,271,449),screen,&genRect(47,83,666,455));
  1242. updateRect(&genRect(47,83,666,455));
  1243. std::string tob;
  1244. switch (ourScenSel->selectedDiff)
  1245. {
  1246. case 0:
  1247. tob="80%";
  1248. break;
  1249. case 1:
  1250. tob="100%";
  1251. break;
  1252. case 2:
  1253. tob="130%";
  1254. break;
  1255. case 3:
  1256. tob="160%";
  1257. break;
  1258. case 4:
  1259. tob="200%";
  1260. break;
  1261. }
  1262. CSDL_Ext::printAtMiddle(tob,703,477,GEOR13,zwykly);
  1263. }
  1264. void CPreGame::printMapsFrom(int from)
  1265. {
  1266. ourScenSel->mapsel.printMaps(from);
  1267. }
  1268. void CPreGame::showScenList()
  1269. {
  1270. if (currentTab!=&ourScenSel->mapsel)
  1271. {
  1272. ourScenSel->listShowed=true;
  1273. ourScenSel->mapsel.show();
  1274. }
  1275. else
  1276. {
  1277. currentTab->hide();
  1278. showScenSel();
  1279. }
  1280. }
  1281. CPreGame::CPreGame()
  1282. {
  1283. highlighted=NULL;
  1284. currentTab=NULL;
  1285. run=true;
  1286. timeHandler tmh;tmh.getDif();
  1287. tytulowy.r=229;tytulowy.g=215;tytulowy.b=123;tytulowy.unused=0;
  1288. zwykly.r=255;zwykly.g=255;zwykly.b=255;zwykly.unused=0; //gbr
  1289. tlo.r=66;tlo.g=44;tlo.b=24;tlo.unused=0;
  1290. preth = new CPreGameTextHandler;
  1291. preth->loadTexts();
  1292. CGI->preth=preth;
  1293. THC std::cout<<"\tCPreGame: loading txts: "<<tmh.getDif()<<std::endl;
  1294. currentMessage=NULL;
  1295. behindCurMes=NULL;
  1296. initMainMenu();
  1297. THC std::cout<<"\tCPreGame: main menu initialization: "<<tmh.getDif()<<std::endl;
  1298. initNewMenu();
  1299. THC std::cout<<"\tCPreGame: newgame menu initialization: "<<tmh.getDif()<<std::endl;
  1300. initScenSel();
  1301. THC std::cout<<"\tCPreGame: scenario choice initialization: "<<tmh.getDif()<<std::endl;
  1302. initOptions();
  1303. THC std::cout<<"\tCPreGame: scenario options initialization: "<<tmh.getDif()<<std::endl;
  1304. showMainMenu();
  1305. THC std::cout<<"\tCPreGame: displaying main menu: "<<tmh.getDif()<<std::endl;
  1306. CPG=this;
  1307. playerName="Player";
  1308. }
  1309. void CPreGame::initOptions()
  1310. {
  1311. ourOptions = new Options();
  1312. ourOptions->init();
  1313. }
  1314. void CPreGame::initScenSel()
  1315. {
  1316. ourScenSel = new ScenSel();
  1317. ourScenSel->listShowed=false;
  1318. if (rand()%2) ourScenSel->background=BitmapHandler::loadBitmap("ZPIC1000.bmp");
  1319. else ourScenSel->background=BitmapHandler::loadBitmap("ZPIC1001.bmp");
  1320. ourScenSel->pressed=NULL;
  1321. ourScenSel->scenInf=BitmapHandler::loadBitmap("GSELPOP1.bmp");//SDL_LoadBMP("h3bitmap.lod\\GSELPOP1.bmp");
  1322. ourScenSel->randMap=BitmapHandler::loadBitmap("RANMAPBK.bmp");
  1323. ourScenSel->options=BitmapHandler::loadBitmap("ADVOPTBK.bmp");
  1324. SDL_SetColorKey(ourScenSel->scenInf,SDL_SRCCOLORKEY,SDL_MapRGB(ourScenSel->scenInf->format,0,255,255));
  1325. //SDL_SetColorKey(ourScenSel->scenList,SDL_SRCCOLORKEY,SDL_MapRGB(ourScenSel->scenList->format,0,255,255));
  1326. SDL_SetColorKey(ourScenSel->randMap,SDL_SRCCOLORKEY,SDL_MapRGB(ourScenSel->randMap->format,0,255,255));
  1327. SDL_SetColorKey(ourScenSel->options,SDL_SRCCOLORKEY,SDL_MapRGB(ourScenSel->options->format,0,255,255));
  1328. ourScenSel->difficulty = new CPoinGroup<>();
  1329. ourScenSel->difficulty->type=1;
  1330. ourScenSel->selectedDiff=-77;
  1331. ourScenSel->difficulty->gdzie = &ourScenSel->selectedDiff;
  1332. ourScenSel->bEasy = IntSelBut<>(genRect(0,0,506,456),NULL,CDefHandler::giveDef("GSPBUT3.DEF"),true,ourScenSel->difficulty,0);
  1333. ourScenSel->bNormal = IntSelBut<>(genRect(0,0,538,456),NULL,CDefHandler::giveDef("GSPBUT4.DEF"),true,ourScenSel->difficulty,1);
  1334. ourScenSel->bHard = IntSelBut<>(genRect(0,0,570,456),NULL,CDefHandler::giveDef("GSPBUT5.DEF"),true,ourScenSel->difficulty,2);
  1335. ourScenSel->bExpert = IntSelBut<>(genRect(0,0,602,456),NULL,CDefHandler::giveDef("GSPBUT6.DEF"),true,ourScenSel->difficulty,3);
  1336. ourScenSel->bImpossible = IntSelBut<>(genRect(0,0,634,456),NULL,CDefHandler::giveDef("GSPBUT7.DEF"),true,ourScenSel->difficulty,4);
  1337. ourScenSel->bBack = Button<>(genRect(0,0,584,535),&CPreGame::showNewMenu,CDefHandler::giveDef("SCNRBACK.DEF"));
  1338. ourScenSel->bBegin = Button<>(genRect(0,0,414,535),&CPreGame::begin,CDefHandler::giveDef("SCNRBEG.DEF"));
  1339. ourScenSel->bScens = Button<>(genRect(0,0,414,81),&CPreGame::showScenList,CDefHandler::giveDef("GSPBUTT.DEF"));
  1340. for (int i=0; i<ourScenSel->bScens.imgs->ourImages.size(); i++)
  1341. CSDL_Ext::printAt(CGI->generaltexth->allTexts[500],25+i,2+i,GEOR13,zwykly,ourScenSel->bScens.imgs->ourImages[i].bitmap); //"Show Available Scenarios"
  1342. ourScenSel->bRandom = Button<>(genRect(0,0,414,105),&CPreGame::showScenList,CDefHandler::giveDef("GSPBUTT.DEF"));
  1343. for (int i=0; i<ourScenSel->bRandom.imgs->ourImages.size(); i++)
  1344. CSDL_Ext::printAt(CGI->generaltexth->allTexts[740],25+i,2+i,GEOR13,zwykly,ourScenSel->bRandom.imgs->ourImages[i].bitmap);
  1345. ourScenSel->bOptions = Button<>(genRect(0,0,414,509),&CPreGame::showOptions,CDefHandler::giveDef("GSPBUTT.DEF"));
  1346. for (int i=0; i<ourScenSel->bOptions.imgs->ourImages.size(); i++)
  1347. CSDL_Ext::printAt(CGI->generaltexth->allTexts[501],25+i,2+i,GEOR13,zwykly,ourScenSel->bOptions.imgs->ourImages[i].bitmap); //"Show Advanced Options"
  1348. CPG=this;
  1349. ourScenSel->mapsel.init();
  1350. }
  1351. void CPreGame::showScenSel()
  1352. {
  1353. state=EState::ScenarioList;
  1354. SDL_BlitSurface(ourScenSel->background,NULL,screen,NULL);
  1355. SDL_BlitSurface(ourScenSel->scenInf,NULL,screen,&genRect(ourScenSel->scenInf->h,ourScenSel->scenInf->w,396,6));
  1356. CSDL_Ext::printAt(CGI->generaltexth->allTexts[494],427,438,GEOR13);//"Map Diff:"
  1357. CSDL_Ext::printAt(CGI->generaltexth->allTexts[492],527,438,GEOR13); //player difficulty
  1358. CSDL_Ext::printAt(CGI->generaltexth->allTexts[218],685,438,GEOR13);//"Rating:"
  1359. //blit buttons
  1360. SDL_BlitSurface(ourScenSel->bEasy.imgs->ourImages[0].bitmap,NULL,screen,&ourScenSel->bEasy.pos);
  1361. SDL_BlitSurface(ourScenSel->bNormal.imgs->ourImages[0].bitmap,NULL,screen,&ourScenSel->bNormal.pos);
  1362. SDL_BlitSurface(ourScenSel->bHard.imgs->ourImages[0].bitmap,NULL,screen,&ourScenSel->bHard.pos);
  1363. SDL_BlitSurface(ourScenSel->bExpert.imgs->ourImages[0].bitmap,NULL,screen,&ourScenSel->bExpert.pos);
  1364. SDL_BlitSurface(ourScenSel->bImpossible.imgs->ourImages[0].bitmap,NULL,screen,&ourScenSel->bImpossible.pos);
  1365. SDL_BlitSurface(ourScenSel->bBegin.imgs->ourImages[0].bitmap,NULL,screen,&ourScenSel->bBegin.pos);
  1366. SDL_BlitSurface(ourScenSel->bBack.imgs->ourImages[0].bitmap,NULL,screen,&ourScenSel->bBack.pos);
  1367. //blitAt(ourScenSel->bScens.imgs->ourImages[0].bitmap,ourScenSel->bScens.pos.x,ourScenSel->bScens.pos.y);
  1368. //blitAt(ourScenSel->bRandom.imgs->ourImages[0].bitmap,414,105);
  1369. //blitAt(ourScenSel->bOptions.imgs->ourImages[0].bitmap,414,509);
  1370. //blitAt(ourScenSel->bBegin.imgs->ourImages[0].bitmap,414,535);
  1371. //blitAt(ourScenSel->bBack.imgs->ourImages[0].bitmap,584,535);
  1372. //add buttons info
  1373. if(first)
  1374. {
  1375. btns.push_back(&ourScenSel->bEasy);
  1376. btns.push_back(&ourScenSel->bNormal);
  1377. btns.push_back(&ourScenSel->bHard);
  1378. btns.push_back(&ourScenSel->bExpert);
  1379. btns.push_back(&ourScenSel->bImpossible);
  1380. btns.push_back(&ourScenSel->bScens);
  1381. btns.push_back(&ourScenSel->bRandom);
  1382. btns.push_back(&ourScenSel->bOptions);
  1383. btns.push_back(&ourScenSel->bBegin);
  1384. btns.push_back(&ourScenSel->bBack);
  1385. ourScenSel->selectedDiff=1;
  1386. ourScenSel->bNormal.select(true);
  1387. handleOther = &CPreGame::scenHandleEv;
  1388. ourScenSel->mapsel.select(0,false);
  1389. for (int i=0;i<btns.size();i++)
  1390. {
  1391. btns[i]->pos.w=btns[i]->imgs->ourImages[0].bitmap->w;
  1392. btns[i]->pos.h=btns[i]->imgs->ourImages[0].bitmap->h;
  1393. btns[i]->ID=10;
  1394. }
  1395. }
  1396. else
  1397. {
  1398. ourScenSel->mapsel.select(ourScenSel->mapsel.selected,false);
  1399. switch (ourScenSel->selectedDiff)
  1400. {
  1401. case 0:
  1402. ourScenSel->bEasy.select(true);
  1403. break;
  1404. case 1:
  1405. ourScenSel->bNormal.select(true);
  1406. break;
  1407. case 2:
  1408. ourScenSel->bHard.select(true);
  1409. break;
  1410. case 3:
  1411. ourScenSel->bExpert.select(true);
  1412. break;
  1413. case 4:
  1414. ourScenSel->bImpossible.select(true);
  1415. break;
  1416. }
  1417. }
  1418. //ourScenSel->mapsel.printSelectedInfo(); // this is already called in select()
  1419. //SDL_Flip(screen);
  1420. CSDL_Ext::update(screen);
  1421. first = false;
  1422. }
  1423. void CPreGame::showOptions()
  1424. {
  1425. ourOptions->show();
  1426. }
  1427. void CPreGame::initNewMenu()
  1428. {
  1429. ourNewMenu = new menuItems();
  1430. ourNewMenu->bgAd = BitmapHandler::loadBitmap("ZNEWGAM.bmp");
  1431. ourNewMenu->background = BitmapHandler::loadBitmap("ZPIC1005.bmp");
  1432. blitAt(ourNewMenu->bgAd,114,312,ourNewMenu->background);
  1433. //loading menu buttons
  1434. ourNewMenu->newGame = CDefHandler::giveDef("ZTSINGL.DEF");
  1435. ourNewMenu->loadGame = CDefHandler::giveDef("ZTMULTI.DEF");
  1436. ourNewMenu->highScores = CDefHandler::giveDef("ZTCAMPN.DEF");
  1437. ourNewMenu->credits = CDefHandler::giveDef("ZTTUTOR.DEF");
  1438. ourNewMenu->quit = CDefHandler::giveDef("ZTBACK.DEF");
  1439. ok = CDefHandler::giveDef("IOKAY.DEF");
  1440. cancel = CDefHandler::giveDef("ICANCEL.DEF");
  1441. // single scenario
  1442. ourNewMenu->lNewGame.h=ourNewMenu->newGame->ourImages[0].bitmap->h;
  1443. ourNewMenu->lNewGame.w=ourNewMenu->newGame->ourImages[0].bitmap->w;
  1444. ourNewMenu->lNewGame.x=545;
  1445. ourNewMenu->lNewGame.y=4;
  1446. ourNewMenu->fNewGame=&CPreGame::showScenSel;
  1447. //multiplayer
  1448. ourNewMenu->lLoadGame.h=ourNewMenu->loadGame->ourImages[0].bitmap->h;
  1449. ourNewMenu->lLoadGame.w=ourNewMenu->loadGame->ourImages[0].bitmap->w;
  1450. ourNewMenu->lLoadGame.x=568;
  1451. ourNewMenu->lLoadGame.y=120;
  1452. //campaign
  1453. ourNewMenu->lHighScores.h=ourNewMenu->highScores->ourImages[0].bitmap->h;
  1454. ourNewMenu->lHighScores.w=ourNewMenu->highScores->ourImages[0].bitmap->w;
  1455. ourNewMenu->lHighScores.x=541;
  1456. ourNewMenu->lHighScores.y=233;
  1457. //tutorial
  1458. ourNewMenu->lCredits.h=ourNewMenu->credits->ourImages[0].bitmap->h;
  1459. ourNewMenu->lCredits.w=ourNewMenu->credits->ourImages[0].bitmap->w;
  1460. ourNewMenu->lCredits.x=545;
  1461. ourNewMenu->lCredits.y=358;
  1462. //back
  1463. ourNewMenu->lQuit.h=ourNewMenu->quit->ourImages[0].bitmap->h;
  1464. ourNewMenu->lQuit.w=ourNewMenu->quit->ourImages[0].bitmap->w;
  1465. ourNewMenu->lQuit.x=582;
  1466. ourNewMenu->lQuit.y=464;
  1467. ourNewMenu->fQuit=&CPreGame::showMainMenu;
  1468. ourNewMenu->highlighted=0;
  1469. }
  1470. void CPreGame::showNewMenu()
  1471. {
  1472. if (currentTab/*==&ourScenSel->mapsel*/)
  1473. currentTab->hide();
  1474. btns.clear();
  1475. interested.clear();
  1476. handleOther=NULL;
  1477. state = EState::newGame;
  1478. SDL_BlitSurface(ourNewMenu->background,NULL,screen,NULL);
  1479. SDL_BlitSurface(ourNewMenu->newGame->ourImages[0].bitmap,NULL,screen,&ourNewMenu->lNewGame);
  1480. SDL_BlitSurface(ourNewMenu->loadGame->ourImages[0].bitmap,NULL,screen,&ourNewMenu->lLoadGame);
  1481. SDL_BlitSurface(ourNewMenu->highScores->ourImages[0].bitmap,NULL,screen,&ourNewMenu->lHighScores);
  1482. SDL_BlitSurface(ourNewMenu->credits->ourImages[0].bitmap,NULL,screen,&ourNewMenu->lCredits);
  1483. SDL_BlitSurface(ourNewMenu->quit->ourImages[0].bitmap,NULL,screen,&ourNewMenu->lQuit);
  1484. //SDL_Flip(screen);
  1485. CSDL_Ext::update(screen);
  1486. first = true;
  1487. }
  1488. void CPreGame::initMainMenu()
  1489. {
  1490. ourMainMenu = new menuItems();
  1491. ourMainMenu->background = BitmapHandler::loadBitmap("ZPIC1005.bmp"); //SDL_LoadBMP("h3bitmap.lod\\ZPIC1005.bmp");
  1492. //loading menu buttons
  1493. ourMainMenu->newGame = CDefHandler::giveDef("ZMENUNG.DEF");
  1494. ourMainMenu->loadGame = CDefHandler::giveDef("ZMENULG.DEF");
  1495. ourMainMenu->highScores = CDefHandler::giveDef("ZMENUHS.DEF");
  1496. ourMainMenu->credits = CDefHandler::giveDef("ZMENUCR.DEF");
  1497. ourMainMenu->quit = CDefHandler::giveDef("ZMENUQT.DEF");
  1498. ok = CDefHandler::giveDef("IOKAY.DEF");
  1499. cancel = CDefHandler::giveDef("ICANCEL.DEF");
  1500. // new game button location
  1501. ourMainMenu->lNewGame.h=ourMainMenu->newGame->ourImages[0].bitmap->h;
  1502. ourMainMenu->lNewGame.w=ourMainMenu->newGame->ourImages[0].bitmap->w;
  1503. ourMainMenu->lNewGame.x=540;
  1504. ourMainMenu->lNewGame.y=10;
  1505. ourMainMenu->fNewGame=&CPreGame::showNewMenu;
  1506. //load game location
  1507. ourMainMenu->lLoadGame.h=ourMainMenu->loadGame->ourImages[0].bitmap->h;
  1508. ourMainMenu->lLoadGame.w=ourMainMenu->loadGame->ourImages[0].bitmap->w;
  1509. ourMainMenu->lLoadGame.x=532;
  1510. ourMainMenu->lLoadGame.y=132;
  1511. //high scores
  1512. ourMainMenu->lHighScores.h=ourMainMenu->highScores->ourImages[0].bitmap->h;
  1513. ourMainMenu->lHighScores.w=ourMainMenu->highScores->ourImages[0].bitmap->w;
  1514. ourMainMenu->lHighScores.x=524;
  1515. ourMainMenu->lHighScores.y=251;
  1516. //credits
  1517. ourMainMenu->lCredits.h=ourMainMenu->credits->ourImages[0].bitmap->h;
  1518. ourMainMenu->lCredits.w=ourMainMenu->credits->ourImages[0].bitmap->w;
  1519. ourMainMenu->lCredits.x=557;
  1520. ourMainMenu->lCredits.y=359;
  1521. //quit
  1522. ourMainMenu->lQuit.h=ourMainMenu->quit->ourImages[0].bitmap->h;
  1523. ourMainMenu->lQuit.w=ourMainMenu->quit->ourImages[0].bitmap->w;
  1524. ourMainMenu->lQuit.x=586;
  1525. ourMainMenu->lQuit.y=468;
  1526. ourMainMenu->fQuit=&CPreGame::quitAskBox;
  1527. ourMainMenu->highlighted=0;
  1528. }
  1529. void CPreGame::showMainMenu()
  1530. {
  1531. state = EState::mainMenu;
  1532. SDL_BlitSurface(ourMainMenu->background,NULL,screen,NULL);
  1533. SDL_BlitSurface(ourMainMenu->newGame->ourImages[0].bitmap,NULL,screen,&ourMainMenu->lNewGame);
  1534. SDL_BlitSurface(ourMainMenu->loadGame->ourImages[0].bitmap,NULL,screen,&ourMainMenu->lLoadGame);
  1535. SDL_BlitSurface(ourMainMenu->highScores->ourImages[0].bitmap,NULL,screen,&ourMainMenu->lHighScores);
  1536. SDL_BlitSurface(ourMainMenu->credits->ourImages[0].bitmap,NULL,screen,&ourMainMenu->lCredits);
  1537. SDL_BlitSurface(ourMainMenu->quit->ourImages[0].bitmap,NULL,screen,&ourMainMenu->lQuit);
  1538. //SDL_Flip(screen);
  1539. CSDL_Ext::update(screen);
  1540. }
  1541. void CPreGame::highlightButton(int which, int on)
  1542. {
  1543. menuItems * current = currentItems();
  1544. switch (which)
  1545. {
  1546. case 1:
  1547. {
  1548. SDL_BlitSurface(current->newGame->ourImages[on].bitmap,NULL,screen,&current->lNewGame);
  1549. break;
  1550. }
  1551. case 2:
  1552. {
  1553. SDL_BlitSurface(current->loadGame->ourImages[on].bitmap,NULL,screen,&current->lLoadGame);
  1554. break;
  1555. }
  1556. case 3:
  1557. {
  1558. SDL_BlitSurface(current->highScores->ourImages[on].bitmap,NULL,screen,&current->lHighScores);
  1559. break;
  1560. }
  1561. case 4:
  1562. {
  1563. SDL_BlitSurface(current->credits->ourImages[on].bitmap,NULL,screen,&current->lCredits);
  1564. break;
  1565. }
  1566. case 5:
  1567. {
  1568. SDL_BlitSurface(current->quit->ourImages[on].bitmap,NULL,screen,&current->lQuit);
  1569. break;
  1570. }
  1571. }
  1572. //SDL_Flip(screen);
  1573. CSDL_Ext::update(screen);
  1574. }
  1575. void CPreGame::showCenBox (std::string data)
  1576. {
  1577. CMessage * cmh = new CMessage();
  1578. SDL_Surface * infoBox = cmh->genMessage(preth->getTitle(data), preth->getDescr(data));
  1579. behindCurMes = CSDL_Ext::newSurface(infoBox->w,infoBox->h,screen);
  1580. SDL_Rect pos = genRect(infoBox->h,infoBox->w,
  1581. (screen->w/2)-(infoBox->w/2),(screen->h/2)-(infoBox->h/2));
  1582. SDL_BlitSurface(screen,&pos,behindCurMes,NULL);
  1583. SDL_BlitSurface(infoBox,NULL,screen,&pos);
  1584. SDL_UpdateRect(screen,pos.x,pos.y,pos.w,pos.h);
  1585. SDL_FreeSurface(infoBox);
  1586. currentMessage = new SDL_Rect(pos);
  1587. delete cmh;
  1588. }
  1589. void CPreGame::showAskBox (std::string data, void(*f1)(),void(*f2)())
  1590. {
  1591. CMessage * cmh = new CMessage();
  1592. std::vector<CDefHandler*> * przyciski = new std::vector<CDefHandler*>(0);
  1593. std::vector<SDL_Rect> * btnspos= new std::vector<SDL_Rect>(0);
  1594. przyciski->push_back(ok);
  1595. przyciski->push_back(cancel);
  1596. SDL_Surface * infoBox = cmh->genMessage(preth->getTitle(data), preth->getDescr(data), EWindowType::yesOrNO, przyciski, btnspos);
  1597. behindCurMes = CSDL_Ext::newSurface(infoBox->w,infoBox->h,screen);
  1598. SDL_Rect pos = genRect(infoBox->h,infoBox->w,
  1599. (screen->w/2)-(infoBox->w/2),(screen->h/2)-(infoBox->h/2));
  1600. SDL_BlitSurface(screen,&pos,behindCurMes,NULL);
  1601. SDL_BlitSurface(infoBox,NULL,screen,&pos);
  1602. SDL_UpdateRect(screen,pos.x,pos.y,pos.w,pos.h);
  1603. SDL_FreeSurface(infoBox);
  1604. currentMessage = new SDL_Rect(pos);
  1605. (*btnspos)[0].x+=pos.x;
  1606. (*btnspos)[0].y+=pos.y;
  1607. (*btnspos)[1].x+=pos.x;
  1608. (*btnspos)[1].y+=pos.y;
  1609. btns.push_back(new Button<>((*btnspos)[0],&CPreGame::quit,ok,false, NULL,2));
  1610. btns.push_back(new Button<>((*btnspos)[1],(&CPreGame::hideBox),cancel,false, NULL,2));
  1611. delete cmh;
  1612. delete przyciski;
  1613. delete btnspos;
  1614. }
  1615. void CPreGame::hideBox ()
  1616. {
  1617. SDL_BlitSurface(behindCurMes,NULL,screen,currentMessage);
  1618. SDL_UpdateRect
  1619. (screen,currentMessage->x,currentMessage->y,currentMessage->w,currentMessage->h);
  1620. for (int i=0;i<btns.size();i++)
  1621. {
  1622. if (btns[i]->ID==2)
  1623. {
  1624. delete btns[i];
  1625. btns.erase(btns.begin()+i);
  1626. i--;
  1627. }
  1628. }
  1629. SDL_FreeSurface(behindCurMes);
  1630. delete currentMessage;
  1631. currentMessage = NULL;
  1632. behindCurMes=NULL;
  1633. }
  1634. CPreGame::menuItems * CPreGame::currentItems()
  1635. {
  1636. switch (state)
  1637. {
  1638. case EState::mainMenu:
  1639. return ourMainMenu;
  1640. case EState::newGame:
  1641. return ourNewMenu;
  1642. default:
  1643. return NULL;
  1644. }
  1645. }
  1646. void CPreGame::scenHandleEv(SDL_Event& sEvent)
  1647. {
  1648. if(sEvent.type == SDL_MOUSEMOTION)
  1649. {
  1650. CGI->curh->cursorMove(sEvent.motion.x, sEvent.motion.y);
  1651. }
  1652. if ((sEvent.type==SDL_MOUSEBUTTONDOWN) && (sEvent.button.button == SDL_BUTTON_LEFT))
  1653. {
  1654. for (int i=0;i<btns.size(); i++)
  1655. {
  1656. if (isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y))
  1657. {
  1658. btns[i]->press(true);
  1659. ourScenSel->pressed=(Button<>*)btns[i];
  1660. }
  1661. }
  1662. if ((currentTab==&ourScenSel->mapsel) && (sEvent.button.y>121) &&(sEvent.button.y<570)
  1663. && (sEvent.button.x>55) && (sEvent.button.x<372))
  1664. {
  1665. int py = ((sEvent.button.y-121)/25)+ourScenSel->mapsel.slid->whereAreWe;
  1666. ourScenSel->mapsel.select(ourScenSel->mapsel.whichWL(py));
  1667. }
  1668. }
  1669. else if ((sEvent.type==SDL_MOUSEBUTTONUP) && (sEvent.button.button == SDL_BUTTON_LEFT))
  1670. {
  1671. Button<> * prnr=ourScenSel->pressed;
  1672. if (ourScenSel->pressed && ourScenSel->pressed->state==1)
  1673. {
  1674. ourScenSel->pressed->press(false);
  1675. ourScenSel->pressed=NULL;
  1676. }
  1677. for (int i=0;i<btns.size(); i++)
  1678. {
  1679. if (isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y))
  1680. {
  1681. if (btns[i]->selectable)
  1682. btns[i]->select(true);
  1683. if (btns[i]->type==1 && ((Button<>*)btns[i])->fun)
  1684. (this->*(((Button<>*)btns[i])->fun))();
  1685. int zz = btns.size();
  1686. if (i>=zz)
  1687. break;
  1688. if (btns[i]==prnr && btns[i]->type==2)
  1689. {
  1690. ((IntBut<> *)(btns[i]))->set();
  1691. ourScenSel->mapsel.slid->whereAreWe=0;
  1692. ourScenSel->mapsel.slid->updateSlid();
  1693. ourScenSel->mapsel.slid->positionsAmnt=ourScenSel->mapsel.countWL();
  1694. ourScenSel->mapsel.printMaps(0);
  1695. }
  1696. }
  1697. }
  1698. }
  1699. else if (sEvent.type==SDL_MOUSEMOTION)
  1700. {
  1701. if (highlighted)
  1702. {
  1703. if (isItIn(&highlighted->pos,sEvent.motion.x,sEvent.motion.y))
  1704. return;
  1705. else
  1706. {
  1707. highlighted->hover(false);
  1708. highlighted = NULL;
  1709. }
  1710. }
  1711. for (int i=0;i<btns.size();i++)
  1712. {
  1713. if (!btns[i]->highlightable)
  1714. continue;
  1715. if(isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y))
  1716. {
  1717. btns[i]->hover(true);
  1718. highlighted=btns[i];
  1719. return;
  1720. }
  1721. else if (btns[i]->highlighted)
  1722. btns[i]->hover(false);
  1723. }
  1724. }
  1725. }
  1726. StartInfo CPreGame::runLoop()
  1727. {
  1728. SDL_Event sEvent;
  1729. while(run)
  1730. {
  1731. CGI->screenh->updateScreen();
  1732. try
  1733. {
  1734. if(SDL_PollEvent(&sEvent)) //wait for event...
  1735. {
  1736. menuItems * current = currentItems();
  1737. if(sEvent.type==SDL_QUIT)
  1738. {
  1739. exit(0);
  1740. return ret;
  1741. }
  1742. for (int i=0;i<interested.size();i++)
  1743. interested[i]->handleIt(sEvent);
  1744. if (!current)
  1745. {
  1746. (this->*handleOther)(sEvent);
  1747. }
  1748. else if (sEvent.type==SDL_KEYDOWN)
  1749. {
  1750. if (sEvent.key.keysym.sym==SDLK_q)
  1751. {
  1752. exit(0);
  1753. }
  1754. /*if (state==EState::newGame)
  1755. {
  1756. switch (sEvent.key.keysym.sym)
  1757. {
  1758. case SDLK_LEFT:
  1759. {
  1760. if(currentItems()->lNewGame.x>0)
  1761. currentItems()->lNewGame.x--;
  1762. break;
  1763. }
  1764. case (SDLK_RIGHT):
  1765. {
  1766. currentItems()->lNewGame.x++;
  1767. break;
  1768. }
  1769. case (SDLK_UP):
  1770. {
  1771. if(currentItems()->lNewGame.y>0)
  1772. currentItems()->lNewGame.y--;
  1773. break;
  1774. }
  1775. case (SDLK_DOWN):
  1776. {
  1777. currentItems()->lNewGame.y++;
  1778. break;
  1779. }
  1780. }
  1781. showNewMenu();
  1782. }*/
  1783. }
  1784. else if (sEvent.type==SDL_MOUSEMOTION)
  1785. {
  1786. CGI->curh->cursorMove(sEvent.motion.x, sEvent.motion.y); //for graphical mouse
  1787. if (currentMessage) continue;
  1788. if (current->highlighted)
  1789. {
  1790. switch (current->highlighted)
  1791. {
  1792. case 1:
  1793. {
  1794. if(isItIn(&current->lNewGame,sEvent.motion.x,sEvent.motion.y))
  1795. continue;
  1796. else
  1797. {
  1798. current->highlighted=0;
  1799. highlightButton(1,0);
  1800. }
  1801. break;
  1802. }
  1803. case 2:
  1804. {
  1805. if(isItIn(&current->lLoadGame,sEvent.motion.x,sEvent.motion.y))
  1806. continue;
  1807. else
  1808. {
  1809. current->highlighted=0;
  1810. highlightButton(2,0);
  1811. }
  1812. break;
  1813. }
  1814. case 3:
  1815. {
  1816. if(isItIn(&current->lHighScores,sEvent.motion.x,sEvent.motion.y))
  1817. continue;
  1818. else
  1819. {
  1820. current->highlighted=0;
  1821. highlightButton(3,0);
  1822. }
  1823. break;
  1824. }
  1825. case 4:
  1826. {
  1827. if(isItIn(&current->lCredits,sEvent.motion.x,sEvent.motion.y))
  1828. continue;
  1829. else
  1830. {
  1831. current->highlighted=0;
  1832. highlightButton(4,0);
  1833. }
  1834. break;
  1835. }
  1836. case 5:
  1837. {
  1838. if(isItIn(&current->lQuit,sEvent.motion.x,sEvent.motion.y))
  1839. continue;
  1840. else
  1841. {
  1842. current->highlighted=0;
  1843. highlightButton(5,0);
  1844. }
  1845. break;
  1846. }
  1847. } //switch (current->highlighted)
  1848. } // if (current->highlighted)
  1849. if (isItIn(&current->lNewGame,sEvent.motion.x,sEvent.motion.y))
  1850. {
  1851. highlightButton(1,2);
  1852. current->highlighted=1;
  1853. }
  1854. else if (isItIn(&current->lLoadGame,sEvent.motion.x,sEvent.motion.y))
  1855. {
  1856. highlightButton(2,2);
  1857. current->highlighted=2;
  1858. }
  1859. else if (isItIn(&current->lHighScores,sEvent.motion.x,sEvent.motion.y))
  1860. {
  1861. highlightButton(3,2);
  1862. current->highlighted=3;
  1863. }
  1864. else if (isItIn(&current->lCredits,sEvent.motion.x,sEvent.motion.y))
  1865. {
  1866. highlightButton(4,2);
  1867. current->highlighted=4;
  1868. }
  1869. else if (isItIn(&current->lQuit,sEvent.motion.x,sEvent.motion.y))
  1870. {
  1871. highlightButton(5,2);
  1872. current->highlighted=5;
  1873. }
  1874. }
  1875. else if ((sEvent.type==SDL_MOUSEBUTTONDOWN) && (sEvent.button.button == SDL_BUTTON_LEFT))
  1876. {
  1877. mush->playClick();
  1878. for (int i=0;i<btns.size(); i++)
  1879. {
  1880. if (isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y))
  1881. {
  1882. btns[i]->press(true);
  1883. //SDL_BlitSurface((btns[i].imgs)->ourImages[1].bitmap,NULL,screen,&btns[i].pos);
  1884. //updateRect(&btns[i].pos);
  1885. }
  1886. }
  1887. if (currentMessage) continue;
  1888. if (isItIn(&current->lNewGame,sEvent.motion.x,sEvent.motion.y))
  1889. {
  1890. highlightButton(1,1);
  1891. current->highlighted=1;
  1892. }
  1893. else if (isItIn(&current->lLoadGame,sEvent.motion.x,sEvent.motion.y))
  1894. {
  1895. highlightButton(2,1);
  1896. current->highlighted=2;
  1897. }
  1898. else if (isItIn(&current->lHighScores,sEvent.motion.x,sEvent.motion.y))
  1899. {
  1900. highlightButton(3,1);
  1901. current->highlighted=3;
  1902. }
  1903. else if (isItIn(&current->lCredits,sEvent.motion.x,sEvent.motion.y))
  1904. {
  1905. highlightButton(4,1);
  1906. current->highlighted=4;
  1907. }
  1908. else if (isItIn(&current->lQuit,sEvent.motion.x,sEvent.motion.y))
  1909. {
  1910. highlightButton(5,1);
  1911. current->highlighted=5;
  1912. }
  1913. }
  1914. else if ((sEvent.type==SDL_MOUSEBUTTONUP) && (sEvent.button.button == SDL_BUTTON_LEFT))
  1915. {
  1916. for (int i=0;i<btns.size(); i++)
  1917. {
  1918. if (isItIn(&btns[i]->pos,sEvent.motion.x,sEvent.motion.y))
  1919. (this->*(((Button<>*)btns[i])->fun))();
  1920. else
  1921. {
  1922. btns[i]->press(false);
  1923. //SDL_BlitSurface((btns[i].imgs)->ourImages[0].bitmap,NULL,screen,&btns[i].pos);
  1924. //updateRect(&btns[i].pos);
  1925. }
  1926. }
  1927. if (currentMessage) continue;
  1928. if (isItIn(&current->lNewGame,sEvent.motion.x,sEvent.motion.y))
  1929. {
  1930. highlightButton(1,2);
  1931. current->highlighted=1;
  1932. (this->*(current->fNewGame))();
  1933. }
  1934. else if (isItIn(&current->lLoadGame,sEvent.motion.x,sEvent.motion.y))
  1935. {
  1936. highlightButton(2,2);
  1937. current->highlighted=2;
  1938. }
  1939. else if (isItIn(&current->lHighScores,sEvent.motion.x,sEvent.motion.y))
  1940. {
  1941. highlightButton(3,2);
  1942. current->highlighted=3;
  1943. }
  1944. else if (isItIn(&current->lCredits,sEvent.motion.x,sEvent.motion.y))
  1945. {
  1946. highlightButton(4,2);
  1947. current->highlighted=4;
  1948. }
  1949. else if (isItIn(&current->lQuit,sEvent.motion.x,sEvent.motion.y))
  1950. {
  1951. highlightButton(5,2);
  1952. current->highlighted=5;
  1953. (this->*(current->fQuit))();
  1954. }
  1955. }
  1956. else if ((sEvent.type==SDL_MOUSEBUTTONDOWN) && (sEvent.button.button == SDL_BUTTON_RIGHT))
  1957. {
  1958. if (currentMessage) continue;
  1959. if (isItIn(&current->lNewGame,sEvent.motion.x,sEvent.motion.y))
  1960. {
  1961. showCenBox(buttonText(0));
  1962. }
  1963. else if (isItIn(&current->lLoadGame,sEvent.motion.x,sEvent.motion.y))
  1964. {
  1965. showCenBox(buttonText(1));
  1966. }
  1967. else if (isItIn(&current->lHighScores,sEvent.motion.x,sEvent.motion.y))
  1968. {
  1969. showCenBox(buttonText(2));
  1970. }
  1971. else if (isItIn(&current->lCredits,sEvent.motion.x,sEvent.motion.y))
  1972. {
  1973. showCenBox(buttonText(3));
  1974. }
  1975. else if (isItIn(&ourMainMenu->lQuit,sEvent.motion.x,sEvent.motion.y))
  1976. {
  1977. showCenBox(buttonText(4));
  1978. }
  1979. }
  1980. else if ((sEvent.type==SDL_MOUSEBUTTONUP) && (sEvent.button.button == SDL_BUTTON_RIGHT) && currentMessage)
  1981. {
  1982. hideBox();
  1983. }
  1984. }
  1985. }
  1986. catch(...)
  1987. { continue; }
  1988. SDL_Delay(1); //give time for other apps
  1989. }
  1990. return ret;
  1991. }
  1992. std::string CPreGame::buttonText(int which)
  1993. {
  1994. if (state==EState::mainMenu)
  1995. {
  1996. switch (which)
  1997. {
  1998. case 0:
  1999. return CPG->preth->zelp[3].second;
  2000. case 1:
  2001. return CPG->preth->zelp[4].second;
  2002. case 2:
  2003. return CPG->preth->zelp[5].second;
  2004. case 3:
  2005. return CPG->preth->zelp[6].second;
  2006. case 4:
  2007. return CPG->preth->zelp[7].second;
  2008. }
  2009. }
  2010. else if (state==EState::newGame)
  2011. {
  2012. switch (which)
  2013. {
  2014. case 0:
  2015. return CPG->preth->zelp[10].second;
  2016. case 1:
  2017. return CPG->preth->zelp[11].second;
  2018. case 2:
  2019. return CPG->preth->zelp[12].second;
  2020. case 3:
  2021. return CPG->preth->zelp[13].second;
  2022. case 4:
  2023. return CPG->preth->zelp[14].second;
  2024. }
  2025. }
  2026. return std::string();
  2027. }
  2028. void CPreGame::quitAskBox()
  2029. {
  2030. showAskBox("\"{} Are you sure you want to quit?\"",NULL,NULL);
  2031. }
  2032. void CPreGame::sortMaps()
  2033. {
  2034. std::sort(ourScenSel->mapsel.ourMaps.begin(),ourScenSel->mapsel.ourMaps.end(),mapSorter(ourScenSel->mapsel.sortBy));
  2035. ourScenSel->mapsel.select(0);
  2036. printMapsFrom(0);
  2037. }
  2038. void CPreGame::setTurnLength(int on)
  2039. {
  2040. int min;
  2041. switch (on)
  2042. {
  2043. case 0:
  2044. min=1;
  2045. break;
  2046. case 1:
  2047. min=2;
  2048. break;
  2049. case 2:
  2050. min=4;
  2051. break;
  2052. case 3:
  2053. min=6;
  2054. break;
  2055. case 4:
  2056. min=8;
  2057. break;
  2058. case 5:
  2059. min=10;
  2060. break;
  2061. case 6:
  2062. min=15;
  2063. break;
  2064. case 7:
  2065. min=20;
  2066. break;
  2067. case 8:
  2068. min=25;
  2069. break;
  2070. case 9:
  2071. min=30;
  2072. break;
  2073. case 10:
  2074. min=0;
  2075. break;
  2076. default:
  2077. min=0;
  2078. break;
  2079. }
  2080. SDL_BlitSurface(ourOptions->bg,&genRect(23,134,256,547),screen,&genRect(23,134,258,553));
  2081. updateRect(&genRect(23,134,258,553));
  2082. if (min)
  2083. {
  2084. std::ostringstream os;
  2085. os<<min<<" Minutes";
  2086. CSDL_Ext::printAtMiddle(os.str(),323,563,GEOR13);
  2087. }
  2088. else CSDL_Ext::printAtMiddle("Unlimited",323,563,GEOR13);
  2089. }