CPreGame.cpp 64 KB

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