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