CPreGame.cpp 127 KB

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