CPreGame.cpp 122 KB

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