CPreGame.cpp 125 KB

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