GUIClasses.cpp 108 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086
  1. #include "GUIClasses.h"
  2. #include "SDL_Extensions.h"
  3. #include "../stdafx.h"
  4. #include "CAdvmapInterface.h"
  5. #include "CBattleInterface.h"
  6. #include "../CCallback.h"
  7. #include "CCastleInterface.h"
  8. #include "CCursorHandler.h"
  9. #include "CGameInfo.h"
  10. #include "CHeroWindow.h"
  11. #include "CMessage.h"
  12. #include "CConfigHandler.h"
  13. #include "SDL_framerate.h"
  14. #include "CConfigHandler.h"
  15. #include "CCreatureAnimation.h"
  16. #include "Graphics.h"
  17. #include "../hch/CArtHandler.h"
  18. #include "../hch/CGeneralTextHandler.h"
  19. #include "../hch/CHeroHandler.h"
  20. #include "../hch/CLodHandler.h"
  21. #include "../hch/CObjectHandler.h"
  22. #include "../hch/CSpellHandler.h"
  23. #include "../hch/CTownHandler.h"
  24. #include "../lib/CondSh.h"
  25. #include "../lib/map.h"
  26. #include "../mapHandler.h"
  27. #include "../timeHandler.h"
  28. #include <boost/lexical_cast.hpp>
  29. #include <boost/algorithm/string.hpp>
  30. #include <boost/algorithm/string/replace.hpp>
  31. #include <boost/assign/std/vector.hpp>
  32. #include <boost/assign/list_of.hpp>
  33. #include <boost/date_time/posix_time/posix_time.hpp>
  34. //#include <boost/thread.hpp>
  35. #include <cmath>
  36. #include <queue>
  37. #include <sstream>
  38. #include "../lib/NetPacks.h"
  39. #include "CSpellWindow.h"
  40. #include "CHeroWindow.h"
  41. #include "../hch/CVideoHandler.h"
  42. /*
  43. * GUIClasses.cpp, part of VCMI engine
  44. *
  45. * Authors: listed in file AUTHORS in main folder
  46. *
  47. * License: GNU General Public License v2.0 or later
  48. * Full text of license available in license.txt file, in main folder
  49. *
  50. */
  51. using namespace boost::assign;
  52. using namespace CSDL_Ext;
  53. extern TTF_Font * GEOR16;
  54. extern std::queue<SDL_Event*> events;
  55. extern boost::mutex eventsM;
  56. #undef min
  57. #undef max
  58. static StackState* getStackState(const CGObjectInstance *obj, int pos, bool town)
  59. {
  60. const CGHeroInstance *h = dynamic_cast<const CGHeroInstance *>(obj);
  61. if(!h) return NULL;
  62. StackState *pom = new StackState();
  63. pom->shotsLeft = -1;
  64. pom->healthBonus = h->valOfBonuses(HeroBonus::STACK_HEALTH);
  65. pom->currentHealth = 0;
  66. pom->attackBonus = h->getPrimSkillLevel(0);
  67. pom->defenseBonus = h->getPrimSkillLevel(1);
  68. pom->luck = h->getCurrentLuck();
  69. pom->morale = h->getCurrentMorale(pos,town);
  70. pom->speedBonus = h->valOfBonuses(HeroBonus::STACKS_SPEED);
  71. return pom;
  72. }
  73. void CGarrisonSlot::hover (bool on)
  74. {
  75. Hoverable::hover(on);
  76. if(on)
  77. {
  78. std::string temp;
  79. if(creature)
  80. {
  81. if(owner->highlighted)
  82. {
  83. if(owner->highlighted == this)
  84. {
  85. temp = CGI->generaltexth->tcommands[4]; //View %s
  86. boost::algorithm::replace_first(temp,"%s",creature->nameSing);
  87. }
  88. else if (owner->highlighted->creature == creature)
  89. {
  90. temp = CGI->generaltexth->tcommands[2]; //Combine %s armies
  91. boost::algorithm::replace_first(temp,"%s",creature->nameSing);
  92. }
  93. else if (owner->highlighted->creature)
  94. {
  95. temp = CGI->generaltexth->tcommands[7]; //Exchange %s with %s
  96. boost::algorithm::replace_first(temp,"%s",owner->highlighted->creature->nameSing);
  97. boost::algorithm::replace_first(temp,"%s",creature->nameSing);
  98. }
  99. else
  100. {
  101. tlog2 << "Warning - shouldn't be - highlighted void slot "<<owner->highlighted<<std::endl;
  102. tlog2 << "Highlighted set to NULL"<<std::endl;
  103. owner->highlighted = NULL;
  104. }
  105. }
  106. else
  107. {
  108. if(upg)
  109. {
  110. temp = CGI->generaltexth->tcommands[32]; //Select %s (visiting)
  111. }
  112. else if(owner->oup && owner->oup->ID == TOWNI_TYPE)
  113. {
  114. temp = CGI->generaltexth->tcommands[12]; //Select %s (in garrison)
  115. }
  116. else
  117. {
  118. temp = CGI->generaltexth->allTexts[481]; //Select %s
  119. }
  120. boost::algorithm::replace_first(temp,"%s",creature->nameSing);
  121. };
  122. }
  123. else
  124. {
  125. if(owner->highlighted)
  126. {
  127. const CArmedInstance *highl = owner->highlighted->getObj();
  128. if( highl->needsLastStack() //we are moving stack from hero's
  129. && highl->army.slots.size() == 1 //it's only stack
  130. && owner->highlighted->upg != upg //we're moving it to the other garrison
  131. )
  132. {
  133. temp = CGI->generaltexth->tcommands[5]; //Cannot move last army to garrison
  134. }
  135. else
  136. {
  137. temp = CGI->generaltexth->tcommands[6]; //Move %s
  138. boost::algorithm::replace_first(temp,"%s",owner->highlighted->creature->nameSing);
  139. }
  140. }
  141. else
  142. {
  143. temp = CGI->generaltexth->tcommands[11]; //Empty
  144. }
  145. }
  146. LOCPLINT->statusbar->print(temp);
  147. }
  148. else
  149. {
  150. LOCPLINT->statusbar->clear();
  151. }
  152. }
  153. const CArmedInstance * CGarrisonSlot::getObj()
  154. {
  155. return (!upg)?(owner->oup):(owner->odown);
  156. }
  157. void CGarrisonSlot::clickRight (tribool down)
  158. {
  159. StackState *pom = getStackState(getObj(),ID, LOCPLINT->topInt() == LOCPLINT->castleInt);
  160. if(down && creature)
  161. {
  162. LOCPLINT->pushInt(new CCreInfoWindow(creature->idNumber,0,count,pom,0,0,NULL));
  163. }
  164. delete pom;
  165. }
  166. void CGarrisonSlot::clickLeft(tribool down)
  167. {
  168. if(owner->ignoreEvent)
  169. {
  170. owner->ignoreEvent = false;
  171. return;
  172. }
  173. if(down)
  174. {
  175. bool refr = false;
  176. if(owner->highlighted)
  177. {
  178. if(owner->highlighted == this) //view info
  179. {
  180. StackState *pom2 = getStackState(getObj(), ID, LOCPLINT->topInt() == LOCPLINT->castleInt);
  181. UpgradeInfo pom = LOCPLINT->cb->getUpgradeInfo(getObj(), ID);
  182. CCreInfoWindow *creWindow = NULL;
  183. if(pom.oldID>=0) //upgrade is possible
  184. {
  185. creWindow = new CCreInfoWindow(
  186. creature->idNumber,1,count,pom2,
  187. boost::bind(&CCallback::upgradeCreature,LOCPLINT->cb,getObj(),ID,pom.newID[0]), //bind upgrade function
  188. boost::bind(&CCallback::dismissCreature,LOCPLINT->cb,getObj(),ID),&pom);
  189. }
  190. else
  191. {
  192. creWindow = new CCreInfoWindow(
  193. creature->idNumber,1,count,pom2,0,
  194. boost::bind(&CCallback::dismissCreature,LOCPLINT->cb,getObj(),ID), NULL);
  195. }
  196. LOCPLINT->pushInt(creWindow);
  197. owner->highlighted = NULL;
  198. show(screen2);
  199. refr = true;
  200. delete pom2;
  201. }
  202. else if((owner->splitting || LOCPLINT->shiftPressed())
  203. && (!creature
  204. || (creature == owner->highlighted->creature))
  205. ) //we want to split
  206. {
  207. owner->p2 = ID; //store the second stack pos
  208. owner->pb = upg;//store the second stack owner (up or down army)
  209. owner->splitting = false;
  210. int totalAmount = owner->highlighted->count;
  211. if(creature)
  212. totalAmount += count;
  213. int last = -1;
  214. if(upg != owner->highlighted->upg) //not splitting within same army
  215. {
  216. if(owner->highlighted->getObj()->army.slots.size() == 1
  217. && owner->highlighted->getObj()->needsLastStack() )
  218. {
  219. last = 0;
  220. }
  221. if(getObj()->army.slots.size() == 1
  222. && getObj()->needsLastStack() )
  223. {
  224. last += 2;
  225. }
  226. }
  227. CSplitWindow * spw = new CSplitWindow(owner->highlighted->creature->idNumber, totalAmount, owner, last, count);
  228. LOCPLINT->pushInt(spw);
  229. refr = true;
  230. }
  231. else if(creature != owner->highlighted->creature) //swap
  232. {
  233. LOCPLINT->cb->swapCreatures(
  234. (!upg)?(owner->oup):(owner->odown),
  235. (!owner->highlighted->upg)?(owner->oup):(owner->odown),
  236. ID,owner->highlighted->ID);
  237. }
  238. else //merge
  239. {
  240. LOCPLINT->cb->mergeStacks(
  241. (!owner->highlighted->upg)?(owner->oup):(owner->odown),
  242. (!upg)?(owner->oup):(owner->odown),
  243. owner->highlighted->ID,ID);
  244. }
  245. }
  246. else //highlight
  247. {
  248. if(creature)
  249. owner->highlighted = this;
  250. show(screen2);
  251. refr = true;
  252. }
  253. if(refr) {hover(false); hover(true); } //to refresh statusbar
  254. }
  255. }
  256. void CGarrisonSlot::activate()
  257. {
  258. if(!active) active=true;
  259. else return;
  260. ClickableL::activate();
  261. ClickableR::activate();
  262. Hoverable::activate();
  263. }
  264. void CGarrisonSlot::deactivate()
  265. {
  266. if(active) active=false;
  267. else return;
  268. ClickableL::deactivate();
  269. ClickableR::deactivate();
  270. Hoverable::deactivate();
  271. }
  272. CGarrisonSlot::CGarrisonSlot(CGarrisonInt *Owner, int x, int y, int IID, int Upg, const CCreature * Creature, int Count)
  273. {
  274. active = false;
  275. upg = Upg;
  276. count = Count;
  277. ID = IID;
  278. creature = Creature;
  279. pos.x = x;
  280. pos.y = y;
  281. if(Owner->smallIcons)
  282. {
  283. pos.w = 32;
  284. pos.h = 32;
  285. }
  286. else
  287. {
  288. pos.w = 58;
  289. pos.h = 64;
  290. }
  291. owner = Owner;
  292. }
  293. CGarrisonSlot::~CGarrisonSlot()
  294. {
  295. if(active)
  296. deactivate();
  297. }
  298. void CGarrisonSlot::show(SDL_Surface * to)
  299. {
  300. std::map<int,SDL_Surface*> &imgs = (owner->smallIcons ? graphics->smallImgs : graphics->bigImgs);
  301. if(creature)
  302. {
  303. char buf[15];
  304. SDL_itoa(count,buf,10);
  305. blitAt(imgs[creature->idNumber],pos,to);
  306. printToWR(buf, pos.x+pos.w-2, pos.y+pos.h-2, owner->smallIcons ? GEORM : GEOR16, zwykly, to);
  307. if((owner->highlighted==this)
  308. || (owner->splitting && owner->highlighted->creature == creature))
  309. {
  310. blitAt(imgs[-1],pos,to);
  311. }
  312. }
  313. else //empty slot
  314. {
  315. Rect pos1 = pos, pos2 = pos; //positions on the garr bg sur and scren
  316. pos1.x = owner->surOffset.x;
  317. pos1.y = owner->surOffset.y;
  318. SDL_BlitSurface(owner->sur,&pos1,to,&pos2);
  319. if(owner->splitting)
  320. blitAt(imgs[-1],pos,to);
  321. }
  322. }
  323. CGarrisonInt::~CGarrisonInt()
  324. {
  325. if(sup)
  326. {
  327. for(size_t i=0;i<sup->size();i++)
  328. {
  329. delete (*sup)[i];
  330. }
  331. delete sup;
  332. }
  333. if(sdown)
  334. {
  335. for(size_t i=0;i<sdown->size();i++)
  336. {
  337. delete (*sdown)[i]; //XXX what about smartpointers? boost or auto_ptr from std
  338. }
  339. delete sdown;
  340. }
  341. }
  342. void CGarrisonInt::show(SDL_Surface * to)
  343. {
  344. if(sup)
  345. {
  346. for(size_t i = 0; i<sup->size(); i++)
  347. {
  348. if((*sup)[i])
  349. {
  350. (*sup)[i]->show(to);
  351. }
  352. }
  353. }
  354. if(sdown)
  355. {
  356. for(size_t i = 0; i<sdown->size(); i++)
  357. {
  358. if((*sdown)[i])
  359. {
  360. (*sdown)[i]->show(to);
  361. }
  362. }
  363. }
  364. }
  365. void CGarrisonInt::deactiveteSlots()
  366. {
  367. if(sup)
  368. {
  369. for(int i = 0; i<sup->size(); i++)
  370. {
  371. if((*sup)[i])
  372. {
  373. (*sup)[i]->deactivate();
  374. }
  375. }
  376. }
  377. if(sdown)
  378. {
  379. for(int i = 0; i<sdown->size(); i++)
  380. {
  381. if((*sdown)[i])
  382. {
  383. (*sdown)[i]->deactivate();
  384. }
  385. }
  386. }
  387. }
  388. void CGarrisonInt::activeteSlots()
  389. {
  390. if(sup)
  391. {
  392. for(int i = 0; i<sup->size(); i++)
  393. {
  394. if((*sup)[i])
  395. {
  396. (*sup)[i]->activate();
  397. }
  398. }
  399. }
  400. if(sdown)
  401. {
  402. for(int i = 0; i<sdown->size(); i++)
  403. {
  404. if((*sdown)[i])
  405. {
  406. (*sdown)[i]->activate();
  407. }
  408. }
  409. }
  410. }
  411. void CGarrisonInt::createSlots()
  412. {
  413. int h, w; //height and width of slot
  414. if(smallIcons)
  415. {
  416. h = w = 32;
  417. }
  418. else
  419. {
  420. h = 64;
  421. w = 58;
  422. }
  423. if(set1)
  424. {
  425. sup = new std::vector<CGarrisonSlot*>(7,(CGarrisonSlot *)(NULL));
  426. for
  427. (std::map<si32,std::pair<ui32,si32> >::const_iterator i=set1->slots.begin();
  428. i!=set1->slots.end(); i++)
  429. {
  430. (*sup)[i->first] =
  431. new CGarrisonSlot(this, pos.x + (i->first*(w+interx)), pos.y,i->first, 0,
  432. &CGI->creh->creatures[i->second.first],i->second.second);
  433. }
  434. for(int i=0; i<sup->size(); i++)
  435. if((*sup)[i] == NULL)
  436. (*sup)[i] = new CGarrisonSlot(this, pos.x + (i*(w+interx)), pos.y,i,0,NULL, 0);
  437. }
  438. if(set2)
  439. {
  440. sdown = new std::vector<CGarrisonSlot*>(7,(CGarrisonSlot *)(NULL));
  441. for
  442. (std::map<si32,std::pair<ui32,si32> >::const_iterator i=set2->slots.begin();
  443. i!=set2->slots.end(); i++)
  444. {
  445. (*sdown)[i->first] =
  446. new CGarrisonSlot(this, pos.x + (i->first*(w+interx)) + garOffset.x, pos.y + garOffset.y,i->first,1,
  447. &CGI->creh->creatures[i->second.first],i->second.second);
  448. }
  449. for(int i=0; i<sdown->size(); i++)
  450. if((*sdown)[i] == NULL)
  451. (*sdown)[i] = new CGarrisonSlot(this, pos.x + (i*(w+interx)) + garOffset.x, pos.y + garOffset.y,i,1, NULL, 0);
  452. }
  453. }
  454. void CGarrisonInt::deleteSlots()
  455. {
  456. if(sup)
  457. {
  458. for(int i = 0; i<sup->size(); i++)
  459. {
  460. if((*sup)[i])
  461. {
  462. delete (*sup)[i];
  463. }
  464. }
  465. delete sup;
  466. sup = NULL;
  467. }
  468. if(sdown)
  469. {
  470. for(int i = 0; i<sdown->size(); i++)
  471. {
  472. if((*sdown)[i])
  473. {
  474. delete (*sdown)[i];
  475. }
  476. }
  477. delete sdown;
  478. sdown = NULL;
  479. }
  480. }
  481. void CGarrisonInt::recreateSlots()
  482. {
  483. splitting = false;
  484. highlighted = NULL;
  485. if(active)
  486. {
  487. deactiveteSlots();
  488. }
  489. deleteSlots();
  490. createSlots();
  491. if(active)
  492. {
  493. //ignoreEvent = true;
  494. activeteSlots();
  495. //show(screen2);
  496. }
  497. }
  498. void CGarrisonInt::splitClick()
  499. {
  500. if(!highlighted)
  501. return;
  502. splitting = !splitting;
  503. show(screen2);
  504. }
  505. void CGarrisonInt::splitStacks(int am2)
  506. {
  507. LOCPLINT->cb->splitStack(
  508. (highlighted->upg)?(odown):(oup),
  509. (pb)?(odown):(oup),
  510. highlighted->ID,
  511. p2,
  512. am2);
  513. }
  514. CGarrisonInt::CGarrisonInt(int x, int y, int inx, const Point &garsOffset, SDL_Surface *&pomsur, const Point& SurOffset,
  515. const CArmedInstance *s1, const CArmedInstance *s2, bool smallImgs)
  516. :interx(inx),garOffset(garsOffset),highlighted(NULL),sur(pomsur),surOffset(SurOffset),sup(NULL),
  517. sdown(NULL),oup(s1),odown(s2), smallIcons(smallImgs)
  518. {
  519. active = false;
  520. splitting = false;
  521. set1 = LOCPLINT->cb->getGarrison(s1);
  522. set2 = LOCPLINT->cb->getGarrison(s2);
  523. ignoreEvent = false;
  524. update = true;
  525. pos.x=(x);
  526. pos.y=(y);
  527. pos.w=(58);
  528. pos.h=(64);
  529. createSlots();
  530. }
  531. void CGarrisonInt::activate()
  532. {
  533. active = true;
  534. if(sup)
  535. {
  536. for(int i = 0; i<sup->size(); i++)
  537. if((*sup)[i])
  538. (*sup)[i]->activate();
  539. }
  540. if(sdown)
  541. {
  542. for(int i = 0; i<sdown->size(); i++)
  543. if((*sdown)[i])
  544. (*sdown)[i]->activate();
  545. }
  546. }
  547. void CGarrisonInt::deactivate()
  548. {
  549. active = false;
  550. deactiveteSlots();
  551. }
  552. CInfoWindow::CInfoWindow(std::string text, int player, int charperline, const std::vector<SComponent*> &comps, std::vector<std::pair<std::string,CFunctionList<void()> > > &Buttons, bool delComps)
  553. {
  554. ID = -1;
  555. this->delComps = delComps;
  556. for(int i=0;i<Buttons.size();i++)
  557. {
  558. buttons.push_back(new AdventureMapButton("","",boost::bind(&CInfoWindow::close,this),0,0,Buttons[i].first));
  559. buttons[i]->callback.add(Buttons[i].second); //each button will close the window apart from call-defined actions
  560. }
  561. buttons.front()->assignedKeys.insert(SDLK_RETURN); //first button - reacts on enter
  562. buttons.back()->assignedKeys.insert(SDLK_ESCAPE); //last button - reacts on escape
  563. for(int i=0;i<comps.size();i++)
  564. {
  565. components.push_back(comps[i]);
  566. }
  567. CMessage::drawIWindow(this,text,player,charperline);
  568. }
  569. CInfoWindow::CInfoWindow()
  570. {
  571. ID = -1;
  572. delComps = false;
  573. }
  574. void CInfoWindow::close()
  575. {
  576. LOCPLINT->popIntTotally(this);
  577. LOCPLINT->showingDialog->setn(false);
  578. }
  579. void CInfoWindow::show(SDL_Surface * to)
  580. {
  581. CSimpleWindow::show(to);
  582. for(int i=0;i<buttons.size();i++)
  583. buttons[i]->show(to);
  584. }
  585. CInfoWindow::~CInfoWindow()
  586. {
  587. if(delComps)
  588. {
  589. for (int i=0;i<components.size();i++)
  590. delete components[i];
  591. }
  592. for(int i=0;i<buttons.size();i++)
  593. delete buttons[i];
  594. }
  595. void CInfoWindow::activate()
  596. {
  597. for (int i=0;i<components.size();i++)
  598. components[i]->activate();
  599. for(int i=0;i<buttons.size();i++)
  600. buttons[i]->activate();
  601. }
  602. void CInfoWindow::deactivate()
  603. {
  604. for (int i=0;i<components.size();i++)
  605. components[i]->deactivate();
  606. for(int i=0;i<buttons.size();i++)
  607. buttons[i]->deactivate();
  608. }
  609. void CRClickPopup::clickRight (tribool down)
  610. {
  611. if(down)
  612. return;
  613. close();
  614. }
  615. void CRClickPopup::activate()
  616. {
  617. ClickableR::activate();
  618. }
  619. void CRClickPopup::deactivate()
  620. {
  621. ClickableR::deactivate();
  622. }
  623. void CRClickPopup::close()
  624. {
  625. LOCPLINT->popIntTotally(this);
  626. }
  627. CInfoPopup::CInfoPopup(SDL_Surface * Bitmap, int x, int y, bool Free)
  628. :free(Free),bitmap(Bitmap)
  629. {
  630. pos.x = x;
  631. pos.y = y;
  632. pos.h = bitmap->h;
  633. pos.w = bitmap->w;
  634. // Put the window back on screen if necessary
  635. amax(pos.x, 0);
  636. amax(pos.y, 0);
  637. amin(pos.x, conf.cc.resx - bitmap->w);
  638. amin(pos.y, conf.cc.resy - bitmap->h);
  639. }
  640. CInfoPopup::CInfoPopup(SDL_Surface *Bitmap, bool Free)
  641. {
  642. free=Free;
  643. bitmap=Bitmap;
  644. }
  645. void CInfoPopup::close()
  646. {
  647. if(free)
  648. SDL_FreeSurface(bitmap);
  649. LOCPLINT->popIntTotally(this);
  650. }
  651. void CInfoPopup::show(SDL_Surface * to)
  652. {
  653. blitAt(bitmap,pos.x,pos.y,to);
  654. }
  655. void SComponent::init(Etype Type, int Subtype, int Val)
  656. {
  657. std::ostringstream oss;
  658. switch (Type)
  659. {
  660. case artifact:
  661. description = CGI->arth->artifacts[Subtype].Description();
  662. subtitle = CGI->arth->artifacts[Subtype].Name();
  663. break;
  664. case primskill:
  665. oss << std::showpos << Val << " ";
  666. if(Subtype < 4)
  667. {
  668. description = CGI->generaltexth->arraytxt[2+Subtype];
  669. oss << CGI->generaltexth->primarySkillNames[Subtype];
  670. }
  671. else if(Subtype == 5) //spell points
  672. {
  673. description = CGI->generaltexth->allTexts[149];
  674. oss << CGI->generaltexth->allTexts[387];
  675. }
  676. else
  677. {
  678. tlog1 << "Wrong subtype=" << Subtype << std::endl;
  679. }
  680. subtitle = oss.str();
  681. break;
  682. case secskill44: case secskill:
  683. subtitle += CGI->generaltexth->levels[Val-1] + " " + CGI->generaltexth->skillName[Subtype];
  684. description = CGI->generaltexth->skillInfoTexts[Subtype][Val-1];
  685. break;
  686. case resource:
  687. description = CGI->generaltexth->allTexts[242];
  688. oss << Val;
  689. subtitle = oss.str();
  690. break;
  691. case spell:
  692. description = CGI->spellh->spells[Subtype].descriptions[Val];
  693. subtitle = CGI->spellh->spells[Subtype].name;
  694. break;
  695. case creature:
  696. subtitle = boost::lexical_cast<std::string>(Val) + " " + CGI->creh->creatures[Subtype].*(val != 1 ? &CCreature::namePl : &CCreature::nameSing);
  697. break;
  698. case experience:
  699. description = CGI->generaltexth->allTexts[241];
  700. oss << Val ;
  701. if(Subtype && Val==1)
  702. {
  703. subtitle = CGI->generaltexth->allTexts[442];
  704. }
  705. else
  706. {
  707. subtitle = oss.str();
  708. }
  709. break;
  710. }
  711. type = Type;
  712. subtype = Subtype;
  713. val = Val;
  714. SDL_Surface * temp = this->getImg();
  715. if(!temp)
  716. {
  717. tlog1 << "Error: cannot find graphic for component with id=" << type << " subid=" << subtype << " val=" << val << std::endl;
  718. return;
  719. }
  720. pos.w = temp->w;
  721. pos.h = temp->h;
  722. }
  723. SComponent::SComponent(Etype Type, int Subtype, int Val)
  724. {
  725. init(Type,Subtype,Val);
  726. }
  727. SComponent::SComponent(const Component &c)
  728. {
  729. if(c.id==5)
  730. init(experience,c.subtype,c.val);
  731. else if(c.id == Component::SPELL)
  732. init(spell,c.subtype,c.val);
  733. else
  734. init((Etype)c.id,c.subtype,c.val);
  735. if(c.id==2 && c.when==-1)
  736. subtitle += CGI->generaltexth->allTexts[3].substr(2,CGI->generaltexth->allTexts[3].length()-2);
  737. }
  738. void SComponent::show(SDL_Surface * to)
  739. {
  740. blitAt(getImg(),pos.x,pos.y,to);
  741. }
  742. SDL_Surface * SComponent::getImg()
  743. {
  744. switch (type)
  745. {
  746. case artifact:
  747. return graphics->artDefs->ourImages[subtype].bitmap;
  748. break;
  749. case primskill:
  750. return graphics->pskillsb->ourImages[subtype].bitmap;
  751. break;
  752. case secskill44:
  753. return graphics->abils44->ourImages[subtype*3 + 3 + val - 1].bitmap;
  754. break;
  755. case secskill:
  756. return graphics->abils82->ourImages[subtype*3 + 3 + val - 1].bitmap;
  757. break;
  758. case resource:
  759. return graphics->resources->ourImages[subtype].bitmap;
  760. break;
  761. case experience:
  762. return graphics->pskillsb->ourImages[4].bitmap;
  763. break;
  764. case morale:
  765. return graphics->morale82->ourImages[val+3].bitmap;
  766. break;
  767. case luck:
  768. return graphics->luck82->ourImages[val+3].bitmap;
  769. break;
  770. case spell:
  771. return graphics->spellscr->ourImages[subtype].bitmap;
  772. break;
  773. case creature:
  774. return graphics->bigImgs[subtype];
  775. }
  776. return NULL;
  777. }
  778. void SComponent::clickRight (tribool down)
  779. {
  780. if(description.size())
  781. LOCPLINT->adventureInt->handleRightClick(description,down,this);
  782. }
  783. void SComponent::activate()
  784. {
  785. ClickableR::activate();
  786. }
  787. void SComponent::deactivate()
  788. {
  789. ClickableR::deactivate();
  790. }
  791. void CSelectableComponent::clickLeft(tribool down)
  792. {
  793. if (down)
  794. {
  795. if(onSelect)
  796. onSelect();
  797. }
  798. }
  799. void CSelectableComponent::init(SDL_Surface * Border)
  800. {
  801. SDL_Surface * symb = SComponent::getImg();
  802. myBitmap = CSDL_Ext::newSurface(symb->w+2,symb->h+2,screen);
  803. SDL_SetColorKey(myBitmap,SDL_SRCCOLORKEY,SDL_MapRGB(myBitmap->format,0,255,255));
  804. blitAt(symb,1,1,myBitmap);
  805. if (Border) //use custom border
  806. {
  807. border = Border;
  808. customB = true;
  809. }
  810. else //we need to draw border
  811. {
  812. customB = false;
  813. border = CSDL_Ext::newSurface(symb->w+2,symb->h+2,screen);
  814. SDL_FillRect(border,NULL,0x00FFFF);
  815. for (int i=0;i<border->w;i++)
  816. {
  817. SDL_PutPixelWithoutRefresh(border,i,0,239,215,123);
  818. SDL_PutPixelWithoutRefresh(border,i,(border->h)-1,239,215,123);
  819. }
  820. for (int i=0;i<border->h;i++)
  821. {
  822. SDL_PutPixelWithoutRefresh(border,0,i,239,215,123);
  823. SDL_PutPixelWithoutRefresh(border,(border->w)-1,i,239,215,123);
  824. }
  825. SDL_SetColorKey(border,SDL_SRCCOLORKEY,SDL_MapRGB(border->format,0,255,255));
  826. }
  827. selected = false;
  828. }
  829. CSelectableComponent::CSelectableComponent(const Component &c, boost::function<void()> OnSelect, SDL_Surface * Border)
  830. :SComponent(c),onSelect(OnSelect)
  831. {
  832. init(Border);
  833. }
  834. CSelectableComponent::CSelectableComponent(Etype Type, int Sub, int Val, boost::function<void()> OnSelect, SDL_Surface * Border)
  835. :SComponent(Type,Sub,Val),onSelect(OnSelect)
  836. {
  837. init(Border);
  838. }
  839. CSelectableComponent::~CSelectableComponent()
  840. {
  841. SDL_FreeSurface(myBitmap);
  842. if (!customB)
  843. SDL_FreeSurface(border);
  844. }
  845. void CSelectableComponent::activate()
  846. {
  847. KeyInterested::activate();
  848. SComponent::activate();
  849. ClickableL::activate();
  850. }
  851. void CSelectableComponent::deactivate()
  852. {
  853. KeyInterested::deactivate();
  854. SComponent::deactivate();
  855. ClickableL::deactivate();
  856. }
  857. SDL_Surface * CSelectableComponent::getImg()
  858. {
  859. return myBitmap;
  860. }
  861. void CSelectableComponent::select(bool on)
  862. {
  863. if(on != selected)
  864. {
  865. SDL_FillRect(myBitmap,NULL,0x000000);
  866. blitAt(SComponent::getImg(),1,1,myBitmap);
  867. if (on)
  868. {
  869. blitAt(border,0,0,myBitmap);
  870. }
  871. selected = on;
  872. return;
  873. }
  874. else
  875. {
  876. return;
  877. }
  878. }
  879. void CSelectableComponent::show(SDL_Surface * to)
  880. {
  881. blitAt(myBitmap,pos.x,pos.y,to);
  882. printAtMiddleWB(subtitle,pos.x+pos.w/2,pos.y+pos.h+14,GEOR13,12,zwykly,to);
  883. }
  884. void CSimpleWindow::show(SDL_Surface * to)
  885. {
  886. blitAt(bitmap,pos.x,pos.y,to);
  887. }
  888. CSimpleWindow::~CSimpleWindow()
  889. {
  890. if (bitmap)
  891. {
  892. SDL_FreeSurface(bitmap);
  893. bitmap=NULL;
  894. }
  895. }
  896. void CSelWindow::selectionChange(unsigned to)
  897. {
  898. for (unsigned i=0;i<components.size();i++)
  899. {
  900. CSelectableComponent * pom = dynamic_cast<CSelectableComponent*>(components[i]);
  901. if (!pom)
  902. continue;
  903. pom->select(i==to);
  904. blitAt(pom->getImg(),pom->pos.x-pos.x,pom->pos.y-pos.y,bitmap);
  905. }
  906. }
  907. CSelWindow::CSelWindow(const std::string &text, int player, int charperline, const std::vector<CSelectableComponent*> &comps, const std::vector<std::pair<std::string,CFunctionList<void()> > > &Buttons, int askID)
  908. {
  909. ID = askID;
  910. for(int i=0;i<Buttons.size();i++)
  911. {
  912. buttons.push_back(new AdventureMapButton("","",Buttons[i].second,0,0,Buttons[i].first));
  913. if(!i && askID >= 0)
  914. buttons.back()->callback += boost::bind(&CSelWindow::madeChoice,this);
  915. buttons[i]->callback += boost::bind(&CInfoWindow::close,this); //each button will close the window apart from call-defined actions
  916. }
  917. buttons.front()->assignedKeys.insert(SDLK_RETURN); //first button - reacts on enter
  918. buttons.back()->assignedKeys.insert(SDLK_ESCAPE); //last button - reacts on escape
  919. if(buttons.size() > 1 && askID >= 0) //cancel button functionality
  920. buttons.back()->callback += boost::bind(&ICallback::selectionMade,LOCPLINT->cb,0,askID);
  921. for(int i=0;i<comps.size();i++)
  922. {
  923. components.push_back(comps[i]);
  924. comps[i]->onSelect = boost::bind(&CSelWindow::selectionChange,this,i);
  925. if(i<9)
  926. comps[i]->assignedKeys.insert(SDLK_1+i);
  927. }
  928. CMessage::drawIWindow(this,text,player,charperline);
  929. }
  930. void CSelWindow::madeChoice()
  931. {
  932. if(ID < 0)
  933. return;
  934. int ret = -1;
  935. for (int i=0;i<components.size();i++)
  936. {
  937. if(dynamic_cast<CSelectableComponent*>(components[i])->selected)
  938. {
  939. ret = i;
  940. }
  941. }
  942. LOCPLINT->cb->selectionMade(ret+1,ID);
  943. }
  944. CStatusBar::CStatusBar(int x, int y, std::string name, int maxw)
  945. {
  946. bg=BitmapHandler::loadBitmap(name);
  947. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  948. pos.x=x;
  949. pos.y=y;
  950. if(maxw >= 0)
  951. pos.w = std::min(bg->w,maxw);
  952. else
  953. pos.w=bg->w;
  954. pos.h=bg->h;
  955. middlex=(pos.w/2)+x;
  956. middley=(bg->h/2)+y;
  957. }
  958. CStatusBar::~CStatusBar()
  959. {
  960. SDL_FreeSurface(bg);
  961. }
  962. void CStatusBar::clear()
  963. {
  964. if(LOCPLINT->cingconsole->enteredText == "") //for appropriate support for in-game console
  965. {
  966. current="";
  967. show(screen);
  968. }
  969. }
  970. void CStatusBar::print(const std::string & text)
  971. {
  972. if(LOCPLINT->cingconsole->enteredText == "" || text == LOCPLINT->cingconsole->enteredText) //for appropriate support for in-game console
  973. {
  974. current=text;
  975. show(LOCPLINT->topInt()==LOCPLINT->adventureInt ? screen : screen2); //if there are now windows opened, update statusbar on screen, else to cache surface
  976. }
  977. }
  978. void CStatusBar::show(SDL_Surface * to)
  979. {
  980. SDL_Rect pom = genRect(pos.h,pos.w,pos.x,pos.y);
  981. SDL_BlitSurface(bg,&genRect(pos.h,pos.w,0,0),to,&pom);
  982. printAtMiddle(current,middlex,middley,GEOR13,zwykly,to);
  983. }
  984. std::string CStatusBar::getCurrent()
  985. {
  986. return current;
  987. }
  988. void CList::activate()
  989. {
  990. ClickableL::activate();
  991. ClickableR::activate();
  992. Hoverable::activate();
  993. KeyInterested::activate();
  994. MotionInterested::activate();
  995. };
  996. void CList::deactivate()
  997. {
  998. ClickableL::deactivate();
  999. ClickableR::deactivate();
  1000. Hoverable::deactivate();
  1001. KeyInterested::deactivate();
  1002. MotionInterested::deactivate();
  1003. };
  1004. void CList::clickLeft(tribool down)
  1005. {
  1006. };
  1007. CList::CList(int Size)
  1008. :SIZE(Size)
  1009. {
  1010. }
  1011. CHeroList::CHeroList(int Size)
  1012. :CList(Size), heroes(LOCPLINT->wanderingHeroes)
  1013. {
  1014. arrup = CDefHandler::giveDef(conf.go()->ac.hlistAU);
  1015. arrdo = CDefHandler::giveDef(conf.go()->ac.hlistAD);
  1016. mobile = CDefHandler::giveDef(conf.go()->ac.hlistMB);
  1017. mana = CDefHandler::giveDef(conf.go()->ac.hlistMN);
  1018. empty = BitmapHandler::loadBitmap("HPSXXX.bmp");
  1019. selection = BitmapHandler::loadBitmap("HPSYYY.bmp");
  1020. SDL_SetColorKey(selection,SDL_SRCCOLORKEY,SDL_MapRGB(selection->format,0,255,255));
  1021. pos = genRect(32*SIZE+arrup->height+arrdo->height, std::max(arrup->width,arrdo->width), conf.go()->ac.hlistX, conf.go()->ac.hlistY);
  1022. arrupp = genRect(arrup->height, arrup->width, pos.x, pos.y);
  1023. arrdop = genRect(arrdo->height, arrdo->width, pos.x, pos.y+32*SIZE+arrup->height);
  1024. //32px per hero
  1025. posmobx = pos.x+1;
  1026. posmoby = pos.y+arrup->height+1;
  1027. posporx = pos.x+mobile->width+2;
  1028. pospory = pos.y+arrup->height;
  1029. posmanx = pos.x+1+50+mobile->width;
  1030. posmany = pos.y+arrup->height+1;
  1031. from = 0;
  1032. selected = -1;
  1033. pressed = indeterminate;
  1034. }
  1035. void CHeroList::init()
  1036. {
  1037. int w = pos.w+1, h = pos.h+4;
  1038. bg = CSDL_Ext::newSurface(w,h,screen);
  1039. SDL_BlitSurface(LOCPLINT->adventureInt->bg,&genRect(w,h,pos.x,pos.y),bg,&genRect(w,h,0,0));
  1040. }
  1041. void CHeroList::genList()
  1042. {
  1043. //int howMany = LOCPLINT->cb->howManyHeroes();
  1044. //for (int i=0;i<howMany;i++)
  1045. //{
  1046. // const CGHeroInstance * h = LOCPLINT->cb->getHeroInfo(i,0);
  1047. // if(!h->inTownGarrison)
  1048. // items.push_back(std::pair<const CGHeroInstance *,CPath *>(h,NULL));
  1049. //}
  1050. }
  1051. void CHeroList::select(int which)
  1052. {
  1053. if (which<0)
  1054. {
  1055. selected = which;
  1056. LOCPLINT->adventureInt->selection = NULL;
  1057. LOCPLINT->adventureInt->terrain.currentPath = NULL;
  1058. draw(screen);
  1059. LOCPLINT->adventureInt->infoBar.draw(screen);
  1060. }
  1061. if (which>=heroes.size())
  1062. return;
  1063. selected = which;
  1064. LOCPLINT->adventureInt->select(heroes[which]);
  1065. }
  1066. void CHeroList::clickLeft(tribool down)
  1067. {
  1068. if (down)
  1069. {
  1070. /***************************ARROWS*****************************************/
  1071. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  1072. {
  1073. if(from>0)
  1074. {
  1075. blitAt(arrup->ourImages[1].bitmap,arrupp.x,arrupp.y);
  1076. pressed = true;
  1077. }
  1078. return;
  1079. }
  1080. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  1081. {
  1082. if(heroes.size()-from>SIZE)
  1083. {
  1084. blitAt(arrdo->ourImages[1].bitmap,arrdop.x,arrdop.y);
  1085. pressed = false;
  1086. }
  1087. return;
  1088. }
  1089. /***************************HEROES*****************************************/
  1090. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  1091. hx-=pos.x;
  1092. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  1093. int ny = hy/32;
  1094. if (ny>=SIZE || ny<0)
  1095. return;
  1096. if ( (ny+from)==selected && (LOCPLINT->adventureInt->selection->ID == HEROI_TYPE))
  1097. LOCPLINT->openHeroWindow(heroes[selected]);//print hero screen
  1098. select(ny+from);
  1099. }
  1100. else
  1101. {
  1102. if (indeterminate(pressed))
  1103. return;
  1104. if (pressed) //up
  1105. {
  1106. blitAt(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
  1107. pressed = indeterminate;
  1108. if (!down)
  1109. {
  1110. from--;
  1111. if (from<0)
  1112. from=0;
  1113. draw(screen);
  1114. }
  1115. }
  1116. else if (!pressed) //down
  1117. {
  1118. blitAt(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
  1119. pressed = indeterminate;
  1120. if (!down)
  1121. {
  1122. from++;
  1123. //if (from<items.size()-5)
  1124. // from=items.size()-5;
  1125. draw(screen);
  1126. }
  1127. }
  1128. else
  1129. throw 0;
  1130. }
  1131. }
  1132. void CHeroList::mouseMoved (const SDL_MouseMotionEvent & sEvent)
  1133. {
  1134. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  1135. {
  1136. if (from>0)
  1137. LOCPLINT->adventureInt->statusbar.print(CGI->generaltexth->zelp[303].first);
  1138. else
  1139. LOCPLINT->adventureInt->statusbar.clear();
  1140. return;
  1141. }
  1142. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  1143. {
  1144. if ((heroes.size()-from) > SIZE)
  1145. LOCPLINT->adventureInt->statusbar.print(CGI->generaltexth->zelp[304].first);
  1146. else
  1147. LOCPLINT->adventureInt->statusbar.clear();
  1148. return;
  1149. }
  1150. //if not buttons then heroes
  1151. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  1152. hx-=pos.x;
  1153. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  1154. int ny = hy/32;
  1155. if ((ny>SIZE || ny<0) || (from+ny>=heroes.size()))
  1156. {
  1157. LOCPLINT->adventureInt->statusbar.clear();
  1158. return;
  1159. }
  1160. std::vector<std::string> temp;
  1161. temp.push_back(heroes[from+ny]->name);
  1162. temp.push_back(heroes[from+ny]->type->heroClass->name);
  1163. LOCPLINT->adventureInt->statusbar.print( processStr(CGI->generaltexth->allTexts[15],temp) );
  1164. //select(ny+from);
  1165. }
  1166. void CHeroList::clickRight(tribool down)
  1167. {
  1168. if (down)
  1169. {
  1170. /***************************ARROWS*****************************************/
  1171. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
  1172. {
  1173. LOCPLINT->adventureInt->handleRightClick(CGI->generaltexth->zelp[303].second,down,this);
  1174. }
  1175. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (heroes.size()-from>5))
  1176. {
  1177. LOCPLINT->adventureInt->handleRightClick(CGI->generaltexth->zelp[304].second,down,this);
  1178. }
  1179. else
  1180. {
  1181. //if not buttons then heroes
  1182. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  1183. hx-=pos.x;
  1184. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  1185. int ny = hy/32;
  1186. if ((ny>SIZE || ny<0) || (from+ny>=heroes.size()))
  1187. {
  1188. return;
  1189. }
  1190. //show popup
  1191. CInfoPopup * ip = new CInfoPopup(graphics->heroWins[heroes[from+ny]->subID],
  1192. LOCPLINT->current->motion.x-graphics->heroWins[heroes[from+ny]->subID]->w,
  1193. LOCPLINT->current->motion.y-graphics->heroWins[heroes[from+ny]->subID]->h,
  1194. false);
  1195. LOCPLINT->pushInt(ip);
  1196. }
  1197. }
  1198. else
  1199. {
  1200. LOCPLINT->adventureInt->handleRightClick(CGI->generaltexth->zelp[303].second,down,this);
  1201. LOCPLINT->adventureInt->handleRightClick(CGI->generaltexth->zelp[304].second,down,this);
  1202. }
  1203. }
  1204. void CHeroList::hover (bool on)
  1205. {
  1206. }
  1207. void CHeroList::keyPressed (const SDL_KeyboardEvent & key)
  1208. {
  1209. }
  1210. void CHeroList::updateHList(const CGHeroInstance *toRemove)
  1211. {
  1212. if(toRemove) //remove specific hero
  1213. heroes -= toRemove;
  1214. else
  1215. LOCPLINT->recreateWanderingHeroes();
  1216. if(selected >= heroes.size())
  1217. select(heroes.size()-1);
  1218. if(heroes.size() == 0)
  1219. LOCPLINT->adventureInt->townList.select(0);
  1220. else
  1221. select(selected);
  1222. }
  1223. void CHeroList::updateMove(const CGHeroInstance* which) //draws move points bar
  1224. {
  1225. int ser = -1;
  1226. for(int i=0; i<heroes.size() && ser<0; i++)
  1227. if(heroes[i]->subID == which->subID)
  1228. ser = i;
  1229. ser -= from;
  1230. if(ser<0 || ser > SIZE) return;
  1231. int pom = std::min((which->movement)/100,(si32)mobile->ourImages.size()-1);
  1232. blitAt(mobile->ourImages[pom].bitmap,posmobx,posmoby+ser*32); //move point
  1233. }
  1234. void CHeroList::draw(SDL_Surface * to)
  1235. {
  1236. for (int iT=0+from;iT<SIZE+from;iT++)
  1237. {
  1238. int i = iT-from;
  1239. if (iT>=heroes.size())
  1240. {
  1241. blitAt(mobile->ourImages[0].bitmap,posmobx,posmoby+i*32,to);
  1242. blitAt(mana->ourImages[0].bitmap,posmanx,posmany+i*32,to);
  1243. blitAt(empty,posporx,pospory+i*32,to);
  1244. continue;
  1245. }
  1246. const CGHeroInstance *cur = heroes[iT];
  1247. int pom = cur->movement / 100;
  1248. if (pom>25) pom=25;
  1249. if (pom<0) pom=0;
  1250. blitAt(mobile->ourImages[pom].bitmap,posmobx,posmoby+i*32,to); //move point
  1251. pom = cur->mana / 5;
  1252. if (pom>25) pom=25;
  1253. if (pom<0) pom=0;
  1254. blitAt(mana->ourImages[pom].bitmap,posmanx,posmany+i*32,to); //mana
  1255. SDL_Surface * temp = graphics->portraitSmall[cur->portrait];
  1256. blitAt(temp,posporx,pospory+i*32,to);
  1257. if ((selected == iT) && (LOCPLINT->adventureInt->selection->ID == HEROI_TYPE))
  1258. {
  1259. blitAt(selection,posporx,pospory+i*32,to);
  1260. }
  1261. //TODO: support for custom portraits
  1262. }
  1263. if (from>0)
  1264. blitAt(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y,to);
  1265. else
  1266. blitAt(arrup->ourImages[2].bitmap,arrupp.x,arrupp.y,to);
  1267. if (heroes.size()-from > SIZE)
  1268. blitAt(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y,to);
  1269. else
  1270. blitAt(arrdo->ourImages[2].bitmap,arrdop.x,arrdop.y,to);
  1271. }
  1272. int CHeroList::getPosOfHero(const CGHeroInstance* h)
  1273. {
  1274. return vstd::findPos(heroes, h, std::equal_to<const CGHeroInstance*>());
  1275. }
  1276. CTownList::~CTownList()
  1277. {
  1278. delete arrup;
  1279. delete arrdo;
  1280. }
  1281. CTownList::CTownList(int Size, int x, int y, std::string arrupg, std::string arrdog)
  1282. :CList(Size)
  1283. {
  1284. arrup = CDefHandler::giveDef(arrupg);
  1285. arrdo = CDefHandler::giveDef(arrdog);
  1286. pos.x = x;
  1287. pos.y = y;
  1288. pos.w = std::max(arrdo->width, arrup->width);
  1289. pos.h = arrdo->height + arrup->height + Size*32;
  1290. arrupp.x=x;
  1291. arrupp.y=y;
  1292. arrupp.w=arrup->width;
  1293. arrupp.h=arrup->height;
  1294. arrdop.x=x;
  1295. arrdop.y=y+arrup->height+32*SIZE;
  1296. arrdop.w=arrdo->width;
  1297. arrdop.h=arrdo->height;
  1298. posporx = arrdop.x;
  1299. pospory = arrupp.y + arrupp.h;
  1300. pressed = indeterminate;
  1301. from = 0;
  1302. selected = -1;
  1303. }
  1304. void CTownList::genList()
  1305. {
  1306. int howMany = LOCPLINT->cb->howManyTowns();
  1307. for (int i=0;i<howMany;i++)
  1308. {
  1309. items.push_back(LOCPLINT->cb->getTownInfo(i,0));
  1310. }
  1311. }
  1312. void CTownList::select(int which)
  1313. {
  1314. if (which>=items.size())
  1315. return;
  1316. selected = which;
  1317. if(!fun.empty())
  1318. fun();
  1319. }
  1320. void CTownList::mouseMoved (const SDL_MouseMotionEvent & sEvent)
  1321. {
  1322. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  1323. {
  1324. if (from>0)
  1325. LOCPLINT->statusbar->print(CGI->generaltexth->zelp[306].first);
  1326. else
  1327. LOCPLINT->statusbar->clear();
  1328. return;
  1329. }
  1330. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  1331. {
  1332. if ((items.size()-from) > SIZE)
  1333. LOCPLINT->statusbar->print(CGI->generaltexth->zelp[307].first);
  1334. else
  1335. LOCPLINT->statusbar->clear();
  1336. return;
  1337. }
  1338. //if not buttons then towns
  1339. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  1340. hx-=pos.x;
  1341. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  1342. int ny = hy/32;
  1343. if ((ny>SIZE || ny<0) || (from+ny>=items.size()))
  1344. {
  1345. LOCPLINT->statusbar->clear();
  1346. return;
  1347. };
  1348. LOCPLINT->statusbar->print(items[from+ny]->name);
  1349. }
  1350. void CTownList::clickLeft(tribool down)
  1351. {
  1352. if (down)
  1353. {
  1354. /***************************ARROWS*****************************************/
  1355. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  1356. {
  1357. if(from>0)
  1358. {
  1359. blitAt(arrup->ourImages[1].bitmap,arrupp.x,arrupp.y,screenBuf);
  1360. pressed = true;
  1361. }
  1362. return;
  1363. }
  1364. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  1365. {
  1366. if(items.size()-from > SIZE)
  1367. {
  1368. blitAt(arrdo->ourImages[1].bitmap,arrdop.x,arrdop.y,screenBuf);
  1369. pressed = false;
  1370. }
  1371. return;
  1372. }
  1373. /***************************TOWNS*****************************************/
  1374. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  1375. hx-=pos.x;
  1376. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  1377. int ny = hy/32;
  1378. if (ny>SIZE || ny<0)
  1379. return;
  1380. if(LOCPLINT->topInt() == LOCPLINT->adventureInt
  1381. && (ny+from)==selected
  1382. && LOCPLINT->adventureInt->selection->ID == TOWNI_TYPE
  1383. )
  1384. LOCPLINT->openTownWindow(items[selected]);//print town screen
  1385. else
  1386. select(ny+from);
  1387. }
  1388. else
  1389. {
  1390. if (indeterminate(pressed))
  1391. return;
  1392. if (pressed) //up
  1393. {
  1394. blitAt(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y,screenBuf);
  1395. pressed = indeterminate;
  1396. if (!down)
  1397. {
  1398. from--;
  1399. if (from<0)
  1400. from=0;
  1401. draw(screenBuf);
  1402. }
  1403. }
  1404. else if (!pressed) //down
  1405. {
  1406. blitAt(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y,screenBuf);
  1407. pressed = indeterminate;
  1408. if (!down)
  1409. {
  1410. from++;
  1411. //if (from<items.size()-5)
  1412. // from=items.size()-5;
  1413. draw(screenBuf);
  1414. }
  1415. }
  1416. else
  1417. throw 0;
  1418. }
  1419. }
  1420. void CTownList::clickRight(tribool down)
  1421. {
  1422. if (down)
  1423. {
  1424. /***************************ARROWS*****************************************/
  1425. if(isItIn(&arrupp,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && from>0)
  1426. {
  1427. LOCPLINT->adventureInt->handleRightClick(CGI->generaltexth->zelp[306].second,down,this);
  1428. }
  1429. else if(isItIn(&arrdop,LOCPLINT->current->motion.x,LOCPLINT->current->motion.y) && (items.size()-from>5))
  1430. {
  1431. LOCPLINT->adventureInt->handleRightClick(CGI->generaltexth->zelp[307].second,down,this);
  1432. }
  1433. //if not buttons then towns
  1434. int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y;
  1435. hx-=pos.x;
  1436. hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h;
  1437. int ny = hy/32;
  1438. if ((ny>5 || ny<0) || (from+ny>=items.size()))
  1439. {
  1440. return;
  1441. }
  1442. //show popup
  1443. CInfoPopup * ip = new CInfoPopup(
  1444. graphics->townWins[items[from+ny]->id],
  1445. LOCPLINT->current->motion.x-graphics->townWins[items[from+ny]->id]->w,
  1446. LOCPLINT->current->motion.y-graphics->townWins[items[from+ny]->id]->h,
  1447. false);
  1448. LOCPLINT->pushInt(ip);
  1449. }
  1450. else
  1451. {
  1452. LOCPLINT->adventureInt->handleRightClick(CGI->generaltexth->zelp[306].second,down,this);
  1453. LOCPLINT->adventureInt->handleRightClick(CGI->generaltexth->zelp[307].second,down,this);
  1454. }
  1455. }
  1456. void CTownList::hover (bool on)
  1457. {
  1458. }
  1459. void CTownList::keyPressed (const SDL_KeyboardEvent & key)
  1460. {
  1461. }
  1462. void CTownList::draw(SDL_Surface * to)
  1463. {
  1464. for (int iT=0+from;iT<SIZE+from;iT++)
  1465. {
  1466. int i = iT-from;
  1467. if (iT>=items.size())
  1468. {
  1469. blitAt(graphics->getPic(-1),posporx,pospory+i*32,to);
  1470. continue;
  1471. }
  1472. blitAt(graphics->getPic(items[iT]->subID,items[iT]->hasFort(),items[iT]->builded),posporx,pospory+i*32,to);
  1473. if ((selected == iT) && (LOCPLINT->adventureInt->selection->ID == TOWNI_TYPE))
  1474. {
  1475. blitAt(graphics->getPic(-2),posporx,pospory+i*32,to);
  1476. }
  1477. }
  1478. if (from>0)
  1479. blitAt(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y,to);
  1480. else
  1481. blitAt(arrup->ourImages[2].bitmap,arrupp.x,arrupp.y,to);
  1482. if (items.size()-from>SIZE)
  1483. blitAt(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y,to);
  1484. else
  1485. blitAt(arrdo->ourImages[2].bitmap,arrdop.x,arrdop.y,to);
  1486. }
  1487. CCreaturePic::CCreaturePic(const CCreature *cre, bool Big)
  1488. :c(cre),big(Big)
  1489. {
  1490. anim = new CCreatureAnimation(cre->animDefName);
  1491. }
  1492. CCreaturePic::~CCreaturePic()
  1493. {
  1494. delete anim;
  1495. }
  1496. int CCreaturePic::blitPic(SDL_Surface *to, int x, int y, bool nextFrame)
  1497. {
  1498. SDL_Rect dst;
  1499. if(big)
  1500. {
  1501. blitAt(graphics->backgrounds[c->faction],x,y,to);//curx-50,pos.y+130-65);
  1502. dst = genRect(130,100,x,y);
  1503. }
  1504. else
  1505. {
  1506. blitAt(graphics->backgroundsm[c->faction],x,y,to);//curx-50,pos.y+130-65);
  1507. dst = genRect(120,100,x,y);
  1508. }
  1509. if(c->isDoubleWide())
  1510. x-=15;
  1511. return anim->nextFrameMiddle(to,x+78,y+(big ? 55 : 45),true,0,nextFrame,false,false,&dst);
  1512. }
  1513. SDL_Surface * CCreaturePic::getPic(bool nextFrame)
  1514. {
  1515. //TODO: write
  1516. return NULL;
  1517. }
  1518. void CRecruitmentWindow::close()
  1519. {
  1520. LOCPLINT->popIntTotally(this);
  1521. }
  1522. void CRecruitmentWindow::Max()
  1523. {
  1524. slider->moveTo(slider->amount);
  1525. }
  1526. void CRecruitmentWindow::Buy()
  1527. {
  1528. recruit(creatures[which].ID, slider->value);
  1529. if(level >= 0)
  1530. close();
  1531. else
  1532. slider->moveTo(0);
  1533. }
  1534. void CRecruitmentWindow::Cancel()
  1535. {
  1536. close();
  1537. }
  1538. void CRecruitmentWindow::sliderMoved(int to)
  1539. {
  1540. buy->block(!to);
  1541. }
  1542. void CRecruitmentWindow::clickLeft(tribool down)
  1543. {
  1544. int curx = 192 + 51 - (102*creatures.size()/2) - (18*(creatures.size()-1)/2);
  1545. for(int i=0;i<creatures.size();i++)
  1546. {
  1547. if(isItIn(&genRect(132,102,pos.x+curx,pos.y+64),LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  1548. {
  1549. which = i;
  1550. int newAmount = std::min(amounts[i],creatures[i].amount);
  1551. slider->amount = newAmount;
  1552. if(slider->value > newAmount)
  1553. slider->moveTo(newAmount);
  1554. else
  1555. slider->moveTo(slider->value);
  1556. curx = 192 + 51 - (102*creatures.size()/2) - (13*(creatures.size()-1)/2);
  1557. for(int j=0;j<creatures.size();j++)
  1558. {
  1559. if(which==j)
  1560. drawBorder(bitmap,curx,64,102,132,int3(255,0,0));
  1561. else
  1562. drawBorder(bitmap,curx,64,102,132,int3(239,215,123));
  1563. curx += 115;
  1564. }
  1565. break;
  1566. }
  1567. curx += 115;
  1568. }
  1569. }
  1570. void CRecruitmentWindow::clickRight( boost::logic::tribool down )
  1571. {
  1572. if(down)
  1573. {
  1574. int curx = 192 + 51 - (102*creatures.size()/2) - (13*(creatures.size()-1)/2);
  1575. for(int i=0;i<creatures.size();i++)
  1576. {
  1577. if(isItIn(&genRect(132,102,pos.x+curx,pos.y+64),LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
  1578. {
  1579. CCreInfoWindow *popup = new CCreInfoWindow(creatures[i].ID,0,0,NULL,NULL,NULL,NULL);
  1580. LOCPLINT->pushInt(popup);
  1581. break;
  1582. }
  1583. curx += 115;
  1584. }
  1585. }
  1586. }
  1587. void CRecruitmentWindow::activate()
  1588. {
  1589. ClickableL::activate();
  1590. ClickableR::activate();
  1591. buy->activate();
  1592. max->activate();
  1593. cancel->activate();
  1594. slider->activate();
  1595. LOCPLINT->statusbar = bar;
  1596. }
  1597. void CRecruitmentWindow::deactivate()
  1598. {
  1599. ClickableL::deactivate();
  1600. ClickableR::deactivate();
  1601. buy->deactivate();
  1602. max->deactivate();
  1603. cancel->deactivate();
  1604. slider->deactivate();
  1605. }
  1606. void CRecruitmentWindow::show(SDL_Surface * to)
  1607. {
  1608. static char animCounter=0; //animation counter - for determining appropriate animation frame to be shown
  1609. blitAt(bitmap,pos.x,pos.y,to);
  1610. buy->show(to);
  1611. max->show(to);
  1612. cancel->show(to);
  1613. slider->show(to);
  1614. char pom[15];
  1615. SDL_itoa(creatures[which].amount-slider->value,pom,10); //available
  1616. printAtMiddle(pom,pos.x+205,pos.y+252,GEOR13,zwykly,to);
  1617. SDL_itoa(slider->value,pom,10); //recruit
  1618. printAtMiddle(pom,pos.x+279,pos.y+252,GEOR13,zwykly,to);
  1619. printAtMiddle(CGI->generaltexth->allTexts[16] + " " + CGI->creh->creatures[creatures[which].ID].namePl,pos.x+243,pos.y+32,GEOR16,tytulowy,to); //eg "Recruit Dragon flies"
  1620. int curx = pos.x+115-creatures[which].res.size()*16;
  1621. for(int i=0;i<creatures[which].res.size();i++)
  1622. {
  1623. blitAt(graphics->resources32->ourImages[creatures[which].res[i].first].bitmap,curx,pos.y+243,to);
  1624. blitAt(graphics->resources32->ourImages[creatures[which].res[i].first].bitmap,curx+258,pos.y+243,to);
  1625. SDL_itoa(creatures[which].res[i].second,pom,10);
  1626. printAtMiddle(pom,curx+12,pos.y+286,GEOR13,zwykly,to);
  1627. SDL_itoa(creatures[which].res[i].second * slider->value,pom,10);
  1628. printAtMiddle(pom,curx+12+258,pos.y+286,GEOR13,zwykly,to);
  1629. curx+=32;
  1630. }
  1631. curx = pos.x + 192 + 102 - (102*creatures.size()/2) - (13*(creatures.size()-1)/2);
  1632. for(int i=0; i<creatures.size(); ++i)
  1633. {
  1634. creatures[i].pic->blitPic(to, curx-50, pos.y+130-65, !(animCounter%4));
  1635. curx += 115;
  1636. }
  1637. ++animCounter;
  1638. bar->show(to);
  1639. }
  1640. CRecruitmentWindow::CRecruitmentWindow(const CGDwelling *Dwelling, int Level, const CArmedInstance *Dst, const boost::function<void(int,int)> &Recruit)
  1641. :recruit(Recruit), dwelling(Dwelling), dst(Dst), level(Level)
  1642. {
  1643. which = 0;
  1644. SDL_Surface *hhlp = BitmapHandler::loadBitmap("TPRCRT.bmp");
  1645. graphics->blueToPlayersAdv(hhlp,LOCPLINT->playerID);
  1646. bitmap = SDL_ConvertSurface(hhlp,screen->format,0);
  1647. SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255));
  1648. SDL_FreeSurface(hhlp);
  1649. pos.x = screen->w/2 - bitmap->w/2;
  1650. pos.y = screen->h/2 - bitmap->h/2;
  1651. pos.w = bitmap->w;
  1652. pos.h = bitmap->h;
  1653. bar = new CStatusBar(pos.x+8, pos.y+370, "APHLFTRT.bmp", 471);
  1654. max = new AdventureMapButton(CGI->generaltexth->zelp[553],boost::bind(&CRecruitmentWindow::Max,this),pos.x+134,pos.y+313,"IRCBTNS.DEF",SDLK_m);
  1655. buy = new AdventureMapButton(CGI->generaltexth->zelp[554],boost::bind(&CRecruitmentWindow::Buy,this),pos.x+212,pos.y+313,"IBY6432.DEF",SDLK_RETURN);
  1656. cancel = new AdventureMapButton(CGI->generaltexth->zelp[555],boost::bind(&CRecruitmentWindow::Cancel,this),pos.x+290,pos.y+313,"ICN6432.DEF",SDLK_ESCAPE);
  1657. slider = new CSlider(pos.x+176,pos.y+279,135,boost::bind(&CRecruitmentWindow::sliderMoved,this, _1),1,0,0,true);
  1658. initCres();
  1659. printAtMiddle(CGI->generaltexth->allTexts[346],113,231,GEOR13,zwykly,bitmap); //cost per troop t
  1660. printAtMiddle(CGI->generaltexth->allTexts[465],205,231,GEOR13,zwykly,bitmap); //available t
  1661. printAtMiddle(CGI->generaltexth->allTexts[16],279,231,GEOR13,zwykly,bitmap); //recruit t
  1662. printAtMiddle(CGI->generaltexth->allTexts[466],373,231,GEOR13,zwykly,bitmap); //total cost t
  1663. drawBorder(bitmap,172,222,67,42,int3(239,215,123));
  1664. drawBorder(bitmap,246,222,67,42,int3(239,215,123));
  1665. drawBorder(bitmap,64,222,99,76,int3(239,215,123));
  1666. drawBorder(bitmap,322,222,99,76,int3(239,215,123));
  1667. drawBorder(bitmap,133,312,66,34,int3(173,142,66));
  1668. drawBorder(bitmap,211,312,66,34,int3(173,142,66));
  1669. drawBorder(bitmap,289,312,66,34,int3(173,142,66));
  1670. //border for creatures
  1671. int curx = 192 + 51 - (102*creatures.size()/2) - (13*(creatures.size()-1)/2);
  1672. for(int i=0;i<creatures.size();i++)
  1673. {
  1674. creatures[i].pos.x = curx+1;
  1675. creatures[i].pos.y = 65;
  1676. creatures[i].pos.w = 100;
  1677. creatures[i].pos.h = 130;
  1678. if(which==i)
  1679. drawBorder(bitmap,curx,64,102,132,int3(255,0,0));
  1680. else
  1681. drawBorder(bitmap,curx,64,102,132,int3(239,215,123));
  1682. curx += 115;
  1683. }
  1684. if(!creatures[0].amount || !amounts[0])
  1685. {
  1686. max->block(true);
  1687. slider->block(true);
  1688. }
  1689. //buy->block(true); //not needed, will be blocked by initing slider on 0
  1690. }
  1691. CRecruitmentWindow::~CRecruitmentWindow()
  1692. {
  1693. cleanCres();
  1694. delete max;
  1695. delete buy;
  1696. delete cancel;
  1697. SDL_FreeSurface(bitmap);
  1698. delete slider;
  1699. delete bar;
  1700. }
  1701. void CRecruitmentWindow::initCres()
  1702. {
  1703. cleanCres();
  1704. for(int i=0; i<dwelling->creatures.size(); i++)
  1705. {
  1706. if(level >= 0 && i != level)
  1707. continue;
  1708. for(int j = dwelling->creatures[i].second.size() - 1; j >= 0 ; j--)
  1709. {
  1710. creatures.resize(creatures.size()+1);
  1711. creinfo &cur = creatures.back();
  1712. cur.amount = dwelling->creatures[i].first;
  1713. cur.ID = dwelling->creatures[i].second[j];
  1714. const CCreature *cre = &CGI->creh->creatures[cur.ID];
  1715. cur.pic = new CCreaturePic(cre);
  1716. for(int k=0; k<cre->cost.size(); k++)
  1717. if(cre->cost[k])
  1718. cur.res.push_back(std::make_pair(k,cre->cost[k]));
  1719. amounts.push_back(cre->maxAmount(LOCPLINT->cb->getResourceAmount()));
  1720. }
  1721. }
  1722. slider->amount = std::min(amounts[which],creatures[which].amount);
  1723. }
  1724. void CRecruitmentWindow::cleanCres()
  1725. {
  1726. for(int i=0;i<creatures.size();i++)
  1727. {
  1728. delete creatures[i].pic;
  1729. }
  1730. creatures.clear();
  1731. amounts.clear();
  1732. }
  1733. CSplitWindow::CSplitWindow(int cid, int max, CGarrisonInt *Owner, int Last, int val)
  1734. {
  1735. last = Last;
  1736. which = 1;
  1737. c=cid;
  1738. slider = NULL;
  1739. gar = Owner;
  1740. bitmap = BitmapHandler::loadBitmap("GPUCRDIV.bmp");
  1741. graphics->blueToPlayersAdv(bitmap,LOCPLINT->playerID);
  1742. SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255));
  1743. pos.x = screen->w/2 - bitmap->w/2;
  1744. pos.y = screen->h/2 - bitmap->h/2;
  1745. pos.w = bitmap->w;
  1746. pos.h = bitmap->h;
  1747. ok = new AdventureMapButton("","",boost::bind(&CSplitWindow::split,this),pos.x+20,pos.y+263,"IOK6432.DEF",SDLK_RETURN);
  1748. cancel = new AdventureMapButton("","",boost::bind(&CSplitWindow::close,this),pos.x+214,pos.y+263,"ICN6432.DEF",SDLK_ESCAPE);
  1749. int sliderPositions = max - (last>=0) - (last==2);
  1750. slider = new CSlider(pos.x+21,pos.y+194,257,boost::bind(&CSplitWindow::sliderMoved,this,_1),1,sliderPositions,val,true);
  1751. a1 = max-val;
  1752. a2 = val;
  1753. anim = new CCreaturePic(&CGI->creh->creatures[cid]);
  1754. anim->anim->setType(1);
  1755. std::string title = CGI->generaltexth->allTexts[256];
  1756. boost::algorithm::replace_first(title,"%s",CGI->creh->creatures[cid].namePl);
  1757. printAtMiddle(title,150,34,GEOR16,tytulowy,bitmap);
  1758. }
  1759. CSplitWindow::~CSplitWindow() //d-tor
  1760. {
  1761. SDL_FreeSurface(bitmap);
  1762. delete ok;
  1763. delete cancel;
  1764. delete slider;
  1765. delete anim;
  1766. }
  1767. void CSplitWindow::activate()
  1768. {
  1769. ClickableL::activate();
  1770. KeyInterested::activate();
  1771. ok->activate();
  1772. cancel->activate();
  1773. slider->activate();
  1774. }
  1775. void CSplitWindow::deactivate()
  1776. {
  1777. ClickableL::deactivate();
  1778. KeyInterested::deactivate();
  1779. ok->deactivate();
  1780. cancel->deactivate();
  1781. slider->deactivate();
  1782. }
  1783. void CSplitWindow::split()
  1784. {
  1785. gar->splitStacks(a2);
  1786. close();
  1787. }
  1788. void CSplitWindow::close()
  1789. {
  1790. LOCPLINT->popIntTotally(this);
  1791. }
  1792. void CSplitWindow::sliderMoved(int to)
  1793. {
  1794. int all = a1+a2;
  1795. a2 = to + (last==1 || last==2);
  1796. if(slider)
  1797. a1 = all - a2;
  1798. }
  1799. void CSplitWindow::show(SDL_Surface * to)
  1800. {
  1801. blitAt(bitmap,pos.x,pos.y,to);
  1802. ok->show(to);
  1803. cancel->show(to);
  1804. slider->show(to);
  1805. printAtMiddle(boost::lexical_cast<std::string>(a1) + (!which ? "_" : ""),pos.x+70,pos.y+237,GEOR16,zwykly,to);
  1806. printAtMiddle(boost::lexical_cast<std::string>(a2) + (which ? "_" : ""),pos.x+233,pos.y+237,GEOR16,zwykly,to);
  1807. anim->blitPic(to,pos.x+20,pos.y+54,false);
  1808. anim->blitPic(to,pos.x+177,pos.y+54,false);
  1809. }
  1810. void CSplitWindow::keyPressed (const SDL_KeyboardEvent & key)
  1811. {
  1812. if(key.state != SDL_PRESSED)
  1813. return;
  1814. int &cur = (which ? a2 : a1),
  1815. &sec = (which ? a1 : a2),
  1816. ncur = cur;
  1817. if (key.keysym.sym == SDLK_BACKSPACE)
  1818. {
  1819. ncur /= 10;
  1820. }
  1821. else if(key.keysym.sym == SDLK_TAB)
  1822. {
  1823. which = !which;
  1824. }
  1825. else
  1826. {
  1827. int number = key.keysym.sym - SDLK_0;
  1828. if (number < 0 || number > 9) //not a number pressed
  1829. {
  1830. return;
  1831. }
  1832. ncur = cur*10 + number;
  1833. }
  1834. int delta = ncur - cur;
  1835. if(delta > sec)
  1836. {
  1837. cur += sec;
  1838. sec = 0;
  1839. }
  1840. slider->moveTo(which ? ncur : a1+a2-ncur);
  1841. }
  1842. void CSplitWindow::clickLeft( boost::logic::tribool down )
  1843. {
  1844. if(down)
  1845. {
  1846. Point click(LOCPLINT->current->motion.x,LOCPLINT->current->motion.y);
  1847. click -= pos.topLeft();
  1848. if(Rect(19,216,105,40).isIn(click)) //left picture
  1849. which = 0;
  1850. else if(Rect(175,216,105,40).isIn(click)) //right picture
  1851. which = 1;
  1852. }
  1853. }
  1854. void CCreInfoWindow::show(SDL_Surface * to)
  1855. {
  1856. char pom[15];
  1857. blitAt(bitmap,pos.x,pos.y,to);
  1858. anim->blitPic(to,pos.x+21,pos.y+48,(type) && !(anf%4));
  1859. if(++anf==4)
  1860. anf=0;
  1861. if(count.size())
  1862. printTo(count.c_str(),pos.x+114,pos.y+174,GEOR16,zwykly,to);
  1863. if(upgrade)
  1864. upgrade->show(to);
  1865. if(dismiss)
  1866. dismiss->show(to);
  1867. if(ok)
  1868. ok->show(to);
  1869. }
  1870. CCreInfoWindow::CCreInfoWindow(int Cid, int Type, int creatureCount, StackState *State, boost::function<void()> Upg, boost::function<void()> Dsm, UpgradeInfo *ui)
  1871. :type(Type),dsm(Dsm),dismiss(0),upgrade(0),ok(0)
  1872. {
  1873. //active = false;
  1874. anf = 0;
  1875. c = &CGI->creh->creatures[Cid];
  1876. bitmap = BitmapHandler::loadBitmap("CRSTKPU.bmp");
  1877. pos.x = screen->w/2 - bitmap->w/2;
  1878. pos.y = screen->h/2 - bitmap->h/2;
  1879. pos.w = bitmap->w;
  1880. pos.h = bitmap->h;
  1881. graphics->blueToPlayersAdv(bitmap,LOCPLINT->playerID);
  1882. SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255));
  1883. anim = new CCreaturePic(c);
  1884. if(!type) anim->anim->setType(2);
  1885. char pom[75];int hlp=0;
  1886. if(creatureCount)
  1887. {
  1888. SDL_itoa(creatureCount,pom,10);
  1889. count = pom;
  1890. }
  1891. printAtMiddle(c->namePl,149,30,GEOR13,tytulowy,bitmap); //creature name
  1892. //atttack
  1893. printAt(CGI->generaltexth->primarySkillNames[0],155,48,GEOR13,zwykly,bitmap);
  1894. SDL_itoa(c->attack,pom,10);
  1895. if(State && State->attackBonus)
  1896. {
  1897. int hlp;
  1898. if(c->attack > 0)
  1899. hlp = log10f(c->attack)+2;
  1900. else
  1901. hlp = 2;
  1902. pom[hlp-1] = ' '; pom[hlp] = '(';
  1903. SDL_itoa(c->attack+State->attackBonus,pom+hlp+1,10);
  1904. hlp += 2+(int)log10f(State->attackBonus+c->attack);
  1905. pom[hlp] = ')'; pom[hlp+1] = '\0';
  1906. }
  1907. printToWR(pom,276,61,GEOR13,zwykly,bitmap);
  1908. //defense
  1909. printAt(CGI->generaltexth->primarySkillNames[1],155,67,GEOR13,zwykly,bitmap);
  1910. SDL_itoa(c->defence,pom,10);
  1911. if(State && State->defenseBonus)
  1912. {
  1913. int hlp;
  1914. if(c->defence > 0)
  1915. hlp = log10f(c->defence)+2;
  1916. else
  1917. hlp = 2;
  1918. pom[hlp-1] = ' '; pom[hlp] = '(';
  1919. SDL_itoa(c->defence+State->defenseBonus,pom+hlp+1,10);
  1920. hlp += 2+(int)log10f(State->defenseBonus+c->defence);
  1921. pom[hlp] = ')'; pom[hlp+1] = '\0';
  1922. }
  1923. printToWR(pom,276,80,GEOR13,zwykly,bitmap);
  1924. //shots
  1925. if(c->shots)
  1926. {
  1927. printAt(CGI->generaltexth->allTexts[198],155,86,GEOR13,zwykly,bitmap);
  1928. if(State && State->shotsLeft >= 0)
  1929. sprintf(pom,"%d (%d)",c->shots,State->shotsLeft);
  1930. else
  1931. SDL_itoa(c->shots,pom,10);
  1932. printToWR(pom,276,99,GEOR13,zwykly,bitmap);
  1933. }
  1934. //damage
  1935. printAt(CGI->generaltexth->allTexts[199],155,105,GEOR13,zwykly,bitmap);
  1936. SDL_itoa(c->damageMin,pom,10);
  1937. if(c->damageMin > 0)
  1938. hlp = log10f(c->damageMin)+2;
  1939. else
  1940. hlp = 2;
  1941. pom[hlp-1]=' '; pom[hlp]='-'; pom[hlp+1]=' ';
  1942. SDL_itoa(c->damageMax,pom+hlp+2,10);
  1943. printToWR(pom,276,118,GEOR13,zwykly,bitmap);
  1944. //health
  1945. printAt(CGI->generaltexth->allTexts[388],155,124,GEOR13,zwykly,bitmap);
  1946. if(State && State->healthBonus)
  1947. sprintf(pom,"%d (%d)",c->hitPoints, c->hitPoints + State->healthBonus);
  1948. else
  1949. SDL_itoa(c->hitPoints,pom,10);
  1950. printToWR(pom,276,137,GEOR13,zwykly,bitmap);
  1951. //remaining health
  1952. if(State && State->currentHealth)
  1953. {
  1954. printAt(CGI->generaltexth->allTexts[200],155,143,GEOR13,zwykly,bitmap);
  1955. SDL_itoa(State->currentHealth,pom,10);
  1956. printToWR(pom,276,156,GEOR13,zwykly,bitmap);
  1957. }
  1958. //speed
  1959. printAt(CGI->generaltexth->zelp[441].first,155,162,GEOR13,zwykly,bitmap);
  1960. SDL_itoa(c->speed,pom,10);
  1961. if(State && State->speedBonus)
  1962. {
  1963. int hlp;
  1964. if(c->speed > 0)
  1965. hlp = log10f(c->speed)+2;
  1966. else
  1967. hlp = 2;
  1968. pom[hlp-1] = ' '; pom[hlp] = '(';
  1969. SDL_itoa(c->speed + State->speedBonus, pom+hlp+1, 10);
  1970. hlp += 2+(int)log10f(c->speed + State->speedBonus);
  1971. pom[hlp] = ')'; pom[hlp+1] = '\0';
  1972. }
  1973. printToWR(pom,276,175,GEOR13,zwykly,bitmap);
  1974. //luck and morale
  1975. blitAt(graphics->morale42->ourImages[(State)?(State->morale+3):(3)].bitmap,24,189,bitmap);
  1976. blitAt(graphics->luck42->ourImages[(State)?(State->luck+3):(3)].bitmap,77,189,bitmap);
  1977. //print abilities text - if r-click popup
  1978. if(type)
  1979. {
  1980. if(Upg && ui)
  1981. {
  1982. bool enough = true;
  1983. for(std::set<std::pair<int,int> >::iterator i=ui->cost[0].begin(); i!=ui->cost[0].end(); i++) //calculate upgrade cost
  1984. {
  1985. if(LOCPLINT->cb->getResourceAmount(i->first) < i->second*creatureCount)
  1986. enough = false;
  1987. upgResCost.push_back(new SComponent(SComponent::resource,i->first,i->second*creatureCount));
  1988. }
  1989. if(enough)
  1990. {
  1991. CFunctionList<void()> fs[2];
  1992. fs[0] += Upg;
  1993. fs[0] += boost::bind(&CCreInfoWindow::close,this);
  1994. CFunctionList<void()> cfl;
  1995. cfl = boost::bind(&CPlayerInterface::showYesNoDialog,LOCPLINT,CGI->generaltexth->allTexts[207],boost::ref(upgResCost),fs[0],fs[1],false);
  1996. upgrade = new AdventureMapButton("",CGI->generaltexth->zelp[446].second,cfl,pos.x+76,pos.y+237,"IVIEWCR.DEF",SDLK_u);
  1997. }
  1998. else
  1999. {
  2000. upgrade = new AdventureMapButton("",CGI->generaltexth->zelp[446].second,boost::function<void()>(),pos.x+76,pos.y+237,"IVIEWCR.DEF");
  2001. upgrade->callback.funcs.clear();
  2002. upgrade->bitmapOffset = 2;
  2003. }
  2004. }
  2005. if(Dsm)
  2006. {
  2007. CFunctionList<void()> fs[2];
  2008. //on dismiss confirmed
  2009. fs[0] += Dsm; //dismiss
  2010. fs[0] += boost::bind(&CCreInfoWindow::close,this);//close this window
  2011. CFunctionList<void()> cfl;
  2012. cfl = boost::bind(&CPlayerInterface::showYesNoDialog,LOCPLINT,CGI->generaltexth->allTexts[12],std::vector<SComponent*>(),fs[0],fs[1],false);
  2013. dismiss = new AdventureMapButton("",CGI->generaltexth->zelp[445].second,cfl,pos.x+21,pos.y+237,"IVIEWCR2.DEF",SDLK_d);
  2014. }
  2015. ok = new AdventureMapButton("",CGI->generaltexth->zelp[445].second,boost::bind(&CCreInfoWindow::close,this),pos.x+216,pos.y+237,"IOKAY.DEF",SDLK_RETURN);
  2016. }
  2017. else
  2018. {
  2019. printAtWB(c->abilityText,17,231,GEOR13,35,zwykly,bitmap);
  2020. }
  2021. //spell effects
  2022. if(State)
  2023. {
  2024. int printed=0; //how many effect pics have been printed
  2025. for(std::set<int>::const_iterator it = State->effects.begin(); it!=State->effects.end(); ++it)
  2026. {
  2027. blitAt(graphics->spellEffectsPics->ourImages[*it + 1].bitmap, 127 + 52 * printed, 186, bitmap);
  2028. ++printed;
  2029. if(printed >= 3)
  2030. {
  2031. break;
  2032. }
  2033. }
  2034. }
  2035. }
  2036. CCreInfoWindow::~CCreInfoWindow()
  2037. {
  2038. SDL_FreeSurface(bitmap);
  2039. delete anim;
  2040. delete upgrade;
  2041. delete ok;
  2042. delete dismiss;
  2043. for(int i=0; i<upgResCost.size();i++)
  2044. delete upgResCost[i];
  2045. }
  2046. void CCreInfoWindow::activate()
  2047. {
  2048. //if(active) return;
  2049. //active = true;
  2050. if(!type)
  2051. ClickableR::activate();
  2052. if(ok)
  2053. ok->activate();
  2054. if(dismiss)
  2055. dismiss->activate();
  2056. if(upgrade)
  2057. upgrade->activate();
  2058. }
  2059. void CCreInfoWindow::close()
  2060. {
  2061. LOCPLINT->popIntTotally(this);
  2062. }
  2063. void CCreInfoWindow::clickRight(boost::logic::tribool down)
  2064. {
  2065. if(down)
  2066. return;
  2067. close();
  2068. }
  2069. void CCreInfoWindow::dismissF()
  2070. {
  2071. dsm();
  2072. close();
  2073. }
  2074. void CCreInfoWindow::keyPressed (const SDL_KeyboardEvent & key)
  2075. {
  2076. }
  2077. void CCreInfoWindow::deactivate()
  2078. {
  2079. //if(!active) return;
  2080. //active = false;
  2081. if(!type)
  2082. ClickableR::deactivate();
  2083. if(ok)
  2084. ok->deactivate();
  2085. if(dismiss)
  2086. dismiss->deactivate();
  2087. if(upgrade)
  2088. upgrade->deactivate();
  2089. }
  2090. void CLevelWindow::close()
  2091. {
  2092. for(int i=0;i<comps.size();i++)
  2093. {
  2094. if(comps[i]->selected)
  2095. {
  2096. cb(i);
  2097. break;
  2098. }
  2099. }
  2100. LOCPLINT->popIntTotally(this);
  2101. LOCPLINT->showingDialog->setn(false);
  2102. }
  2103. CLevelWindow::CLevelWindow(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback)
  2104. {
  2105. LOCPLINT->showingDialog->setn(true);
  2106. heroType = hero->subID;
  2107. cb = callback;
  2108. for(int i=0;i<skills.size();i++)
  2109. {
  2110. comps.push_back(new CSelectableComponent(SComponent::secskill44,skills[i],hero->getSecSkillLevel(skills[i])+1,boost::bind(&CLevelWindow::selectionChanged,this,i)));
  2111. comps.back()->assignedKeys.insert(SDLK_1 + i);
  2112. }
  2113. bitmap = BitmapHandler::loadBitmap("LVLUPBKG.bmp");
  2114. graphics->blueToPlayersAdv(bitmap,hero->tempOwner);
  2115. SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255));
  2116. pos.x = screen->w/2 - bitmap->w/2;
  2117. pos.y = screen->h/2 - bitmap->h/2;
  2118. pos.w = bitmap->w;
  2119. pos.h = bitmap->h;
  2120. ok = new AdventureMapButton("","",boost::bind(&CLevelWindow::close,this),pos.x+297,pos.y+413,"IOKAY.DEF",SDLK_RETURN);
  2121. //draw window
  2122. char buf[100], buf2[100];
  2123. strcpy(buf2,CGI->generaltexth->allTexts[444].c_str()); //%s has gained a level.
  2124. sprintf(buf,buf2,hero->name.c_str());
  2125. printAtMiddle(buf,192,35,GEOR16,zwykly,bitmap);
  2126. strcpy(buf2,CGI->generaltexth->allTexts[445].c_str()); //%s is now a level %d %s.
  2127. sprintf(buf,buf2,hero->name.c_str(),hero->level,hero->type->heroClass->name.c_str());
  2128. printAtMiddle(buf,192,162,GEOR16,zwykly,bitmap);
  2129. blitAt(graphics->pskillsm->ourImages[pskill].bitmap,174,190,bitmap);
  2130. printAtMiddle((CGI->generaltexth->primarySkillNames[pskill] + " +1"),192,252,GEOR16,zwykly,bitmap);
  2131. SDL_Surface * ort = TTF_RenderText_Blended(GEOR16,CGI->generaltexth->allTexts[4].c_str(),zwykly);
  2132. int curx = bitmap->w/2 - ( skills.size()*44 + (skills.size()-1)*(36+ort->w) )/2;
  2133. for(int i=0;i<comps.size();i++)
  2134. {
  2135. comps[i]->pos.x = curx+pos.x;
  2136. comps[i]->pos.y = 326+pos.y;
  2137. if( i < (comps.size()-1) )
  2138. {
  2139. curx += 44 + 18; //skill width + margin to "or"
  2140. blitAt(ort,curx,346,bitmap);
  2141. curx += ort->w + 18;
  2142. }
  2143. }
  2144. if(comps.size() > 1)
  2145. {
  2146. ok->block(true);
  2147. }
  2148. else if(comps.size() == 1)
  2149. {
  2150. comps[0]->select(true);
  2151. }
  2152. SDL_FreeSurface(ort);
  2153. }
  2154. void CLevelWindow::selectionChanged(unsigned to)
  2155. {
  2156. if(ok->blocked)
  2157. ok->block(false);
  2158. for(int i=0;i<comps.size();i++)
  2159. if(i==to)
  2160. comps[i]->select(true);
  2161. else
  2162. comps[i]->select(false);
  2163. }
  2164. CLevelWindow::~CLevelWindow()
  2165. {
  2166. delete ok;
  2167. for(int i=0;i<comps.size();i++)
  2168. delete comps[i];
  2169. SDL_FreeSurface(bitmap);
  2170. }
  2171. void CLevelWindow::activate()
  2172. {
  2173. ok->activate();
  2174. for(int i=0;i<comps.size();i++)
  2175. comps[i]->activate();
  2176. }
  2177. void CLevelWindow::deactivate()
  2178. {
  2179. ok->deactivate();
  2180. for(int i=0;i<comps.size();i++)
  2181. comps[i]->deactivate();
  2182. }
  2183. void CLevelWindow::show(SDL_Surface * to)
  2184. {
  2185. blitAt(bitmap,pos.x,pos.y,to);
  2186. blitAt(graphics->portraitLarge[heroType],170+pos.x,66+pos.y,to);
  2187. ok->show(to);
  2188. for(int i=0;i<comps.size();i++)
  2189. comps[i]->show(to);
  2190. }
  2191. void CMinorResDataBar::show(SDL_Surface * to)
  2192. {
  2193. blitAt(bg,pos.x,pos.y,to);
  2194. char buf[30];
  2195. for (int i=0;i<7;i++)
  2196. {
  2197. SDL_itoa(LOCPLINT->cb->getResourceAmount(i),buf,10);
  2198. CSDL_Ext::printAtMiddle(buf,pos.x + 50 + 76*i,pos.y+pos.h/2,GEOR13,zwykly,to);
  2199. }
  2200. std::vector<std::string> temp;
  2201. SDL_itoa(LOCPLINT->cb->getDate(3),buf,10); temp.push_back(std::string(buf));
  2202. SDL_itoa(LOCPLINT->cb->getDate(2),buf,10); temp.push_back(buf);
  2203. SDL_itoa(LOCPLINT->cb->getDate(1),buf,10); temp.push_back(buf);
  2204. CSDL_Ext::printAtMiddle(CSDL_Ext::processStr(
  2205. CGI->generaltexth->allTexts[62]
  2206. +": %s, "
  2207. + CGI->generaltexth->allTexts[63]
  2208. + ": %s, "
  2209. + CGI->generaltexth->allTexts[64]
  2210. + ": %s",temp)
  2211. ,pos.x+545+(pos.w-545)/2,pos.y+pos.h/2,GEOR13,zwykly,to);
  2212. }
  2213. CMinorResDataBar::CMinorResDataBar()
  2214. {
  2215. bg = BitmapHandler::loadBitmap("Z2ESBAR.bmp");
  2216. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  2217. graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
  2218. pos.x = 7;
  2219. pos.y = 575;
  2220. pos.w = bg->w;
  2221. pos.h = bg->h;
  2222. }
  2223. CMinorResDataBar::~CMinorResDataBar()
  2224. {
  2225. SDL_FreeSurface(bg);
  2226. }
  2227. SDL_Surface * CCustomImgComponent::getImg()
  2228. {
  2229. return bmp;
  2230. }
  2231. CCustomImgComponent::CCustomImgComponent( Etype Type, int Subtype, int Val, SDL_Surface *sur, bool freeSur )
  2232. :bmp(sur), free(freeSur)
  2233. {
  2234. init(Type,Subtype,Val);
  2235. }
  2236. CCustomImgComponent::~CCustomImgComponent()
  2237. {
  2238. if(free)
  2239. SDL_FreeSurface(bmp);
  2240. }
  2241. CMarketplaceWindow::CTradeableItem::CTradeableItem( int Type, int ID, bool Left)
  2242. {
  2243. left = Left;
  2244. type = Type;
  2245. id = ID;
  2246. }
  2247. void CMarketplaceWindow::CTradeableItem::show(SDL_Surface * to)
  2248. {
  2249. SDL_Surface *hlp = getSurface();
  2250. blitAt(hlp,pos.x+19,pos.y+9,to);
  2251. }
  2252. void CMarketplaceWindow::CTradeableItem::clickLeft( boost::logic::tribool down )
  2253. {
  2254. CMarketplaceWindow *mw = dynamic_cast<CMarketplaceWindow *>(LOCPLINT->topInt());
  2255. assert(mw);
  2256. if(down)
  2257. {
  2258. if(left)
  2259. {
  2260. if(mw->hLeft != this)
  2261. mw->hLeft = this;
  2262. else
  2263. return;
  2264. }
  2265. else
  2266. {
  2267. if(mw->hRight != this)
  2268. mw->hRight = this;
  2269. else
  2270. return;
  2271. }
  2272. mw->selectionChanged(left);
  2273. }
  2274. }
  2275. void CMarketplaceWindow::CTradeableItem::activate()
  2276. {
  2277. ClickableL::activate();
  2278. }
  2279. void CMarketplaceWindow::CTradeableItem::deactivate()
  2280. {
  2281. ClickableL::deactivate();
  2282. }
  2283. SDL_Surface * CMarketplaceWindow::CTradeableItem::getSurface()
  2284. {
  2285. switch(type)
  2286. {
  2287. case 0:
  2288. return graphics->resources32->ourImages[id].bitmap;
  2289. case 1:
  2290. return graphics->artDefs->ourImages[id].bitmap;
  2291. default:
  2292. return NULL;
  2293. }
  2294. }
  2295. static void initItems( std::vector<CMarketplaceWindow::CTradeableItem*> &i, std::vector<SDL_Rect> &p, int type, int amount, bool left, std::vector<int> *ids/*=NULL*/ )
  2296. {
  2297. i.resize(amount);
  2298. for(int j=0;j<amount;j++)
  2299. {
  2300. i[j] = new CMarketplaceWindow::CTradeableItem(type,(ids && ids->size()>j) ? (*ids)[j] : j, left);
  2301. i[j]->pos = p[j];
  2302. }
  2303. }
  2304. void CMarketplaceWindow::setMode( int mode )
  2305. {
  2306. std::vector<SDL_Rect> lpos, rpos;
  2307. clear();
  2308. switch(mode)
  2309. {
  2310. case 0:
  2311. {
  2312. SDL_Surface *bg2 = BitmapHandler::loadBitmap("TPMRKRES.bmp");
  2313. SDL_SetColorKey(bg2,SDL_SRCCOLORKEY,SDL_MapRGB(bg2->format,0,255,255));
  2314. graphics->blueToPlayersAdv(bg2,LOCPLINT->playerID);
  2315. bg = SDL_ConvertSurface(bg2,screen->format,0);
  2316. SDL_FreeSurface(bg2);
  2317. lpos += genRect(66,69,39,180), genRect(66,69,122,180), genRect(66,69,204,180),
  2318. genRect(66,69,39,259), genRect(66,69,122,259), genRect(66,69,204,259),
  2319. genRect(66,69,122,338);
  2320. for(int i=0;i<lpos.size();i++)
  2321. {
  2322. lpos[i].x += pos.x;
  2323. lpos[i].y += pos.y;
  2324. rpos.push_back(lpos[i]);
  2325. rpos[rpos.size()-1].x += 288;
  2326. }
  2327. initItems(left,lpos,0,7,true,NULL);
  2328. initItems(right,rpos,0,7,false,NULL);
  2329. printAtMiddle(CGI->generaltexth->allTexts[158],303,28,GEORXX,tytulowy,bg); //title
  2330. printAtMiddle(CGI->generaltexth->allTexts[270],158,148,GEOR13,zwykly,bg); //kingdom res.
  2331. printAtMiddle(CGI->generaltexth->allTexts[168],450,148,GEOR13,zwykly,bg); //available for trade
  2332. }
  2333. }
  2334. }
  2335. void CMarketplaceWindow::clear()
  2336. {
  2337. for(int i=0;i<left.size();i++)
  2338. delete left[i];
  2339. for(int i=0;i<right.size();i++)
  2340. delete right[i];
  2341. left.clear();
  2342. right.clear();
  2343. SDL_FreeSurface(bg);
  2344. }
  2345. CMarketplaceWindow::CMarketplaceWindow(int Mode)
  2346. {
  2347. mode = Mode;
  2348. bg = NULL;
  2349. ok = max = deal = NULL;
  2350. pos.x = screen->w/2 - 300;
  2351. pos.y = screen->h/2 - 296;
  2352. slider = new CSlider(pos.x+231,pos.y+490,137,boost::bind(&CMarketplaceWindow::sliderMoved,this,_1),0,0);
  2353. setMode(mode);
  2354. hLeft = hRight = NULL;
  2355. ok = new AdventureMapButton("","",boost::bind(&CPlayerInterface::popIntTotally,LOCPLINT,this),pos.x+516,pos.y+520,"IOK6432.DEF",SDLK_RETURN);
  2356. ok->assignedKeys.insert(SDLK_ESCAPE);
  2357. deal = new AdventureMapButton("","",boost::bind(&CMarketplaceWindow::makeDeal,this),pos.x+307,pos.y+520,"TPMRKB.DEF");
  2358. max = new AdventureMapButton("","",boost::bind(&CMarketplaceWindow::setMax,this),pos.x+229,pos.y+520,"IRCBTNS.DEF");
  2359. max->block(true);
  2360. deal->block(true);
  2361. }
  2362. CMarketplaceWindow::~CMarketplaceWindow()
  2363. {
  2364. clear();
  2365. delete slider;
  2366. }
  2367. void CMarketplaceWindow::show(SDL_Surface * to)
  2368. {
  2369. blitAt(bg,pos,to);
  2370. if(hRight)
  2371. CSDL_Ext::drawBorder(to,hRight->pos.x-1,hRight->pos.y-1,hRight->pos.w+2,hRight->pos.h+2,int3(255,231,148));
  2372. if(hLeft)
  2373. CSDL_Ext::drawBorder(to,hLeft->pos.x-1,hLeft->pos.y-1,hLeft->pos.w+2,hLeft->pos.h+2,int3(255,231,148));
  2374. ok->show(to);
  2375. deal->show(to);
  2376. max->show(to);
  2377. slider->show(to);
  2378. for(int i=0;i<left.size();i++)
  2379. left[i]->show(to);
  2380. for(int i=0;i<right.size();i++)
  2381. right[i]->show(to);
  2382. if(mode==0)
  2383. {
  2384. char buf[15];
  2385. for(int i=0;i<left.size();i++)
  2386. {
  2387. SDL_itoa(LOCPLINT->cb->getResourceAmount(i),buf,10);
  2388. printAtMiddle(buf,left[i]->pos.x+35,left[i]->pos.y+56,GEOR13,zwykly,to);
  2389. }
  2390. if(hLeft) //print prices
  2391. {
  2392. for(int i=0; i<right.size();i++)
  2393. {
  2394. if(right[i]->id != hLeft->id)
  2395. printAtMiddle(rSubs[i],right[i]->pos.x+35,right[i]->pos.y+56,GEOR13,zwykly,to);
  2396. else
  2397. printAtMiddle(CGI->generaltexth->allTexts[164],right[i]->pos.x+35,right[i]->pos.y+56,GEOR13,zwykly,to);
  2398. }
  2399. }
  2400. if(hLeft && hRight && hLeft->id!= hRight->id)
  2401. {
  2402. blitAt(hLeft->getSurface(),pos.x+142,pos.y+457,to);
  2403. blitAt(hRight->getSurface(),pos.x+430,pos.y+457,to);
  2404. SDL_itoa(slider->value * r1,buf,10);
  2405. printAtMiddle(buf,pos.x+158,pos.y+504,GEOR13,zwykly,to);
  2406. SDL_itoa(slider->value * r2,buf,10);
  2407. printAtMiddle(buf,pos.x+446,pos.y+504,GEOR13,zwykly,to);
  2408. }
  2409. }
  2410. }
  2411. void CMarketplaceWindow::activate()
  2412. {
  2413. for(int i=0;i<left.size();i++)
  2414. left[i]->activate();
  2415. for(int i=0;i<right.size();i++)
  2416. right[i]->activate();
  2417. ok->activate();
  2418. max->activate();
  2419. deal->activate();
  2420. slider->activate();
  2421. }
  2422. void CMarketplaceWindow::deactivate()
  2423. {
  2424. for(int i=0;i<left.size();i++)
  2425. left[i]->deactivate();
  2426. for(int i=0;i<right.size();i++)
  2427. right[i]->deactivate();
  2428. ok->deactivate();
  2429. max->deactivate();
  2430. deal->deactivate();
  2431. slider->deactivate();
  2432. }
  2433. void CMarketplaceWindow::setMax()
  2434. {
  2435. slider->moveTo(slider->amount);
  2436. }
  2437. void CMarketplaceWindow::makeDeal()
  2438. {
  2439. LOCPLINT->cb->trade(mode,hLeft->id,hRight->id,slider->value*r1);
  2440. slider->moveTo(0);
  2441. hLeft = NULL;
  2442. selectionChanged(true);
  2443. }
  2444. void CMarketplaceWindow::sliderMoved( int to )
  2445. {
  2446. }
  2447. void CMarketplaceWindow::selectionChanged(bool side)
  2448. {
  2449. if(hLeft && hRight && hLeft->id!= hRight->id)
  2450. {
  2451. LOCPLINT->cb->getMarketOffer(hLeft->id,hRight->id,r1,r2,0);
  2452. slider->amount = LOCPLINT->cb->getResourceAmount(hLeft->id) / r1;
  2453. slider->moveTo(0);
  2454. max->block(false);
  2455. deal->block(false);
  2456. }
  2457. else
  2458. {
  2459. max->block(true);
  2460. deal->block(true);
  2461. slider->amount = 0;
  2462. slider->moveTo(0);
  2463. }
  2464. if(side && hLeft) //left selection changed, recalculate offers
  2465. {
  2466. rSubs.clear();
  2467. rSubs.resize(right.size());
  2468. int h1, h2;
  2469. for(int i=0;i<right.size();i++)
  2470. {
  2471. std::ostringstream oss;
  2472. LOCPLINT->cb->getMarketOffer(hLeft->id,i,h1,h2,0);
  2473. oss << h2;
  2474. if(h1!=1)
  2475. oss << "/" << h1;
  2476. rSubs[i] = oss.str();
  2477. }
  2478. }
  2479. }
  2480. CSystemOptionsWindow::CSystemOptionsWindow(const SDL_Rect &pos, CPlayerInterface * owner)
  2481. {
  2482. this->pos = pos;
  2483. background = BitmapHandler::loadBitmap("SysOpbck.bmp", true);
  2484. graphics->blueToPlayersAdv(background, LOCPLINT->playerID);
  2485. //printing texts
  2486. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[568], 240, 32, GEOR16, tytulowy, background); //window title
  2487. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[569], 122, 65, GEOR16, tytulowy, background); //hero speed
  2488. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[570], 122, 131, GEOR16, tytulowy, background); //enemy speed
  2489. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[571], 122, 197, GEOR16, tytulowy, background); //map scroll speed
  2490. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[20], 122, 263, GEOR16, tytulowy, background); //video quality
  2491. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[394], 122, 348, GEOR16, tytulowy, background); //music volume
  2492. CSDL_Ext::printAtMiddle(CGI->generaltexth->allTexts[395], 122, 414, GEOR16, tytulowy, background); //effects volume
  2493. CSDL_Ext::printAt(CGI->generaltexth->allTexts[572], 283, 57, GEOR16, zwykly, background); //show move path
  2494. CSDL_Ext::printAt(CGI->generaltexth->allTexts[573], 283, 89, GEOR16, zwykly, background); //show hero reminder
  2495. CSDL_Ext::printAt(CGI->generaltexth->allTexts[574], 283, 121, GEOR16, zwykly, background); //quick combat
  2496. CSDL_Ext::printAt(CGI->generaltexth->allTexts[575], 283, 153, GEOR16, zwykly, background); //video subtitles
  2497. CSDL_Ext::printAt(CGI->generaltexth->allTexts[576], 283, 185, GEOR16, zwykly, background); //town building outlines
  2498. CSDL_Ext::printAt(CGI->generaltexth->allTexts[577], 283, 217, GEOR16, zwykly, background); //spell book animation
  2499. //setting up buttons
  2500. save = new AdventureMapButton (CGI->generaltexth->zelp[321].first, CGI->generaltexth->zelp[321].second, boost::bind(&CSystemOptionsWindow::bsavef, this), 516, 354, "SOSAVE.DEF", SDLK_s);
  2501. std::swap(save->imgs[0][0], save->imgs[0][1]);
  2502. quitGame = new AdventureMapButton (CGI->generaltexth->zelp[324].first, CGI->generaltexth->zelp[324].second, boost::bind(&CSystemOptionsWindow::bquitf, this), 405, 471, "soquit.def", SDLK_q);
  2503. std::swap(quitGame->imgs[0][0], quitGame->imgs[0][1]);
  2504. backToMap = new AdventureMapButton (CGI->generaltexth->zelp[325].first, CGI->generaltexth->zelp[325].second, boost::bind(&CSystemOptionsWindow::breturnf, this), 516, 471, "soretrn.def", SDLK_RETURN);
  2505. backToMap->assignedKeys.insert(SDLK_ESCAPE);
  2506. std::swap(backToMap->imgs[0][0], backToMap->imgs[0][1]);
  2507. heroMoveSpeed = new CHighlightableButtonsGroup(0);
  2508. heroMoveSpeed->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[349].first),CGI->generaltexth->zelp[349].second, "sysopb1.def", 187, 134, 1);
  2509. heroMoveSpeed->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[350].first),CGI->generaltexth->zelp[350].second, "sysopb2.def", 235, 134, 2);
  2510. heroMoveSpeed->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[351].first),CGI->generaltexth->zelp[351].second, "sysopb3.def", 283, 134, 4);
  2511. heroMoveSpeed->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[352].first),CGI->generaltexth->zelp[352].second, "sysopb4.def", 331, 134, 8);
  2512. heroMoveSpeed->select(owner->sysOpts.heroMoveSpeed, 1);
  2513. heroMoveSpeed->onChange = boost::bind(&SystemOptions::setHeroMoveSpeed, &owner->sysOpts, _1);
  2514. mapScrollSpeed = new CHighlightableButtonsGroup(0);
  2515. mapScrollSpeed->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[357].first),CGI->generaltexth->zelp[357].second, "sysopb9.def", 187, 267, 1);
  2516. mapScrollSpeed->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[358].first),CGI->generaltexth->zelp[358].second, "sysob10.def", 251, 267, 2);
  2517. mapScrollSpeed->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[359].first),CGI->generaltexth->zelp[359].second, "sysob11.def", 315, 267, 4);
  2518. mapScrollSpeed->select(owner->sysOpts.mapScrollingSpeed, 1);
  2519. mapScrollSpeed->onChange = boost::bind(&SystemOptions::setMapScrollingSpeed, &owner->sysOpts, _1);
  2520. musicVolume = new CHighlightableButtonsGroup(0, true);
  2521. for(int i=0; i<10; ++i)
  2522. {
  2523. musicVolume->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[326+i].first),CGI->generaltexth->zelp[326+i].second, "syslb.def", 188 + 19*i, 416, i*11);
  2524. }
  2525. musicVolume->select(CGI->musich->getVolume(), 1);
  2526. musicVolume->onChange = boost::bind(&SystemOptions::setMusicVolume, &owner->sysOpts, _1);
  2527. effectsVolume = new CHighlightableButtonsGroup(0, true);
  2528. for(int i=0; i<10; ++i)
  2529. {
  2530. effectsVolume->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[336+i].first),CGI->generaltexth->zelp[336+i].second, "syslb.def", 188 + 19*i, 482, i*11);
  2531. }
  2532. effectsVolume->select(CGI->soundh->getVolume(), 1);
  2533. effectsVolume->onChange = boost::bind(&SystemOptions::setSoundVolume, &owner->sysOpts, _1);
  2534. }
  2535. CSystemOptionsWindow::~CSystemOptionsWindow()
  2536. {
  2537. SDL_FreeSurface(background);
  2538. delete save;
  2539. delete quitGame;
  2540. delete backToMap;
  2541. delete heroMoveSpeed;
  2542. delete mapScrollSpeed;
  2543. delete musicVolume;
  2544. delete effectsVolume;
  2545. }
  2546. void CSystemOptionsWindow::bquitf()
  2547. {
  2548. LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[578], std::vector<SComponent*>(), boost::bind(exit, 0), boost::bind(&CSystemOptionsWindow::activate, this), false);
  2549. }
  2550. void CSystemOptionsWindow::breturnf()
  2551. {
  2552. LOCPLINT->popIntTotally(this);
  2553. }
  2554. void CSystemOptionsWindow::bsavef()
  2555. {
  2556. using namespace boost::posix_time;
  2557. std::ostringstream fnameStream;
  2558. fnameStream << second_clock::local_time();
  2559. std::string fname = fnameStream.str();
  2560. boost::algorithm::replace_all(fname,":","");
  2561. boost::algorithm::replace_all(fname," ","-");
  2562. LOCPLINT->showYesNoDialog("Do you want to save current game as " + fname, std::vector<SComponent*>(), boost::bind(&CCallback::save, LOCPLINT->cb, fname), boost::bind(&CSystemOptionsWindow::activate, this), false);
  2563. }
  2564. void CSystemOptionsWindow::activate()
  2565. {
  2566. save->activate();
  2567. quitGame->activate();
  2568. backToMap->activate();
  2569. heroMoveSpeed->activate();
  2570. mapScrollSpeed->activate();
  2571. musicVolume->activate();
  2572. effectsVolume->activate();
  2573. }
  2574. void CSystemOptionsWindow::deactivate()
  2575. {
  2576. save->deactivate();
  2577. quitGame->deactivate();
  2578. backToMap->deactivate();
  2579. heroMoveSpeed->deactivate();
  2580. mapScrollSpeed->deactivate();
  2581. musicVolume->deactivate();
  2582. effectsVolume->deactivate();
  2583. }
  2584. void CSystemOptionsWindow::show(SDL_Surface *to)
  2585. {
  2586. SDL_BlitSurface(background, NULL, to, &pos);
  2587. save->show(to);
  2588. quitGame->show(to);
  2589. backToMap->show(to);
  2590. heroMoveSpeed->show(to);
  2591. mapScrollSpeed->show(to);
  2592. musicVolume->show(to);
  2593. effectsVolume->show(to);
  2594. }
  2595. CTavernWindow::CTavernWindow(const CGHeroInstance *H1, const CGHeroInstance *H2, const std::string &gossip)
  2596. :h1(selected,0,72,299,H1),h2(selected,1,162,299,H2)
  2597. {
  2598. if(H1)
  2599. selected = 0;
  2600. else
  2601. selected = -1;
  2602. oldSelected = -1;
  2603. bg = BitmapHandler::loadBitmap("TPTAVERN.bmp");
  2604. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  2605. graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
  2606. printAtMiddle(CGI->generaltexth->jktexts[37],200,35,GEOR16,tytulowy,bg);
  2607. printAtMiddle("2500",320,328,GEOR13,zwykly,bg);
  2608. printAtMiddle(CGI->generaltexth->jktexts[38],146,283,GEOR16,tytulowy,bg);
  2609. printAtMiddleWB(gossip,200,220,GEOR13,50,zwykly,bg);
  2610. pos.w = bg->w;
  2611. pos.h = bg->h;
  2612. pos.x = (screen->w-bg->w)/2;
  2613. pos.y = (screen->h-bg->h)/2;
  2614. bar = new CStatusBar(pos.x+8, pos.y+478, "APHLFTRT.bmp", 380);
  2615. h1.pos.x += pos.x;
  2616. h2.pos.x += pos.x;
  2617. h1.pos.y += pos.y;
  2618. h2.pos.y += pos.y;
  2619. cancel = new AdventureMapButton(CGI->generaltexth->tavernInfo[7],"",boost::bind(&CTavernWindow::close,this),pos.x+310,pos.y+428,"ICANCEL.DEF",SDLK_ESCAPE);
  2620. recruit = new AdventureMapButton("","",boost::bind(&CTavernWindow::recruitb,this),pos.x+272,pos.y+355,"TPTAV01.DEF",SDLK_RETURN);
  2621. thiefGuild = new AdventureMapButton(CGI->generaltexth->tavernInfo[5],"",0,pos.x+22,pos.y+428,"TPTAV02.DEF",SDLK_t);
  2622. if(LOCPLINT->cb->getResourceAmount(6) < 2500) //not enough gold
  2623. {
  2624. recruit->hoverTexts[0] = CGI->generaltexth->tavernInfo[0]; //Cannot afford a Hero
  2625. recruit->block(2);
  2626. }
  2627. else if(LOCPLINT->cb->howManyHeroes(false) >= 8)
  2628. {
  2629. recruit->hoverTexts[0] = CGI->generaltexth->tavernInfo[1]; //Cannot recruit. You already have %d Heroes.
  2630. boost::algorithm::replace_first(recruit->hoverTexts[0],"%d",boost::lexical_cast<std::string>(LOCPLINT->cb->howManyHeroes()));
  2631. recruit->block(2);
  2632. }
  2633. else if(LOCPLINT->castleInt && LOCPLINT->castleInt->town->visitingHero)
  2634. {
  2635. recruit->hoverTexts[0] = CGI->generaltexth->tavernInfo[2]; //Cannot recruit. You already have a Hero in this town.
  2636. recruit->block(2);
  2637. }
  2638. else
  2639. {
  2640. if(!H1)
  2641. recruit->block(1);
  2642. }
  2643. #ifdef _WIN32
  2644. CGI->videoh->open("TAVERN.BIK");
  2645. #else
  2646. CGI->videoh->open("tavern.mjpg", true, false);
  2647. #endif
  2648. }
  2649. void CTavernWindow::recruitb()
  2650. {
  2651. const CGHeroInstance *toBuy = (selected ? h2 : h1).h;
  2652. close();
  2653. LOCPLINT->cb->recruitHero(LOCPLINT->castleInt->town,toBuy);
  2654. }
  2655. CTavernWindow::~CTavernWindow()
  2656. {
  2657. CGI->videoh->close();
  2658. SDL_FreeSurface(bg);
  2659. delete cancel;
  2660. delete thiefGuild;
  2661. delete recruit;
  2662. delete bar;
  2663. }
  2664. void CTavernWindow::activate()
  2665. {
  2666. thiefGuild->activate();
  2667. cancel->activate();
  2668. if(h1.h)
  2669. h1.activate();
  2670. if(h2.h)
  2671. h2.activate();
  2672. recruit->activate();
  2673. LOCPLINT->statusbar = bar;
  2674. }
  2675. void CTavernWindow::deactivate()
  2676. {
  2677. thiefGuild->deactivate();
  2678. cancel->deactivate();
  2679. if(h1.h)
  2680. h1.deactivate();
  2681. if(h2.h)
  2682. h2.deactivate();
  2683. recruit->deactivate();
  2684. }
  2685. void CTavernWindow::close()
  2686. {
  2687. LOCPLINT->popIntTotally(this);
  2688. }
  2689. void CTavernWindow::show(SDL_Surface * to)
  2690. {
  2691. blitAt(bg,pos.x,pos.y,to);
  2692. CGI->videoh->update(pos.x+70, pos.y+56, to, true, false);
  2693. if(h1.h)
  2694. h1.show(to);
  2695. if(h2.h)
  2696. h2.show(to);
  2697. thiefGuild->show(to);
  2698. cancel->show(to);
  2699. recruit->show(to);
  2700. bar->show(to);
  2701. if(selected >= 0)
  2702. {
  2703. HeroPortrait *sel = selected ? &h2 : &h1;
  2704. if (selected != oldSelected && !recruit->blocked)
  2705. {
  2706. // Selected hero just changed. Update RECRUIT button hover text if recruitment is allowed.
  2707. oldSelected = selected;
  2708. recruit->hoverTexts[0] = CGI->generaltexth->tavernInfo[3]; //Recruit %s the %s
  2709. boost::algorithm::replace_first(recruit->hoverTexts[0],"%s",sel->h->name);
  2710. boost::algorithm::replace_first(recruit->hoverTexts[0],"%s",sel->h->type->heroClass->name);
  2711. }
  2712. printAtMiddleWB(sel->descr,pos.x+146,pos.y+389,GEOR13,40,zwykly,to);
  2713. CSDL_Ext::drawBorder(to,sel->pos.x-2,sel->pos.y-2,sel->pos.w+4,sel->pos.h+4,int3(247,223,123));
  2714. }
  2715. }
  2716. void CTavernWindow::HeroPortrait::clickLeft(boost::logic::tribool down)
  2717. {
  2718. if(pressedL && !down)
  2719. as();
  2720. ClickableL::clickLeft(down);
  2721. }
  2722. void CTavernWindow::HeroPortrait::activate()
  2723. {
  2724. ClickableL::activate();
  2725. ClickableR::activate();
  2726. Hoverable::activate();
  2727. }
  2728. void CTavernWindow::HeroPortrait::deactivate()
  2729. {
  2730. ClickableL::deactivate();
  2731. ClickableR::deactivate();
  2732. Hoverable::deactivate();
  2733. }
  2734. void CTavernWindow::HeroPortrait::clickRight(boost::logic::tribool down)
  2735. {
  2736. if(down)
  2737. {
  2738. LOCPLINT->adventureInt->heroWindow->setHero(h);
  2739. LOCPLINT->pushInt(new CRClickPopupInt(LOCPLINT->adventureInt->heroWindow,false));
  2740. }
  2741. }
  2742. CTavernWindow::HeroPortrait::HeroPortrait(int &sel, int id, int x, int y, const CGHeroInstance *H)
  2743. :as(sel,id)
  2744. {
  2745. h = H;
  2746. pos.x = x;
  2747. pos.y = y;
  2748. pos.w = 58;
  2749. pos.h = 64;
  2750. if(H)
  2751. {
  2752. hoverName = CGI->generaltexth->tavernInfo[4];
  2753. boost::algorithm::replace_first(hoverName,"%s",H->name);
  2754. int artifs = h->artifWorn.size() + h->artifacts.size();
  2755. for(int i=13; i<=17; i++) //war machines and spellbook don't count
  2756. if(vstd::contains(h->artifWorn,i))
  2757. artifs--;
  2758. sprintf_s(descr, sizeof(descr),CGI->generaltexth->allTexts[215].c_str(),
  2759. h->name.c_str(), h->level, h->type->heroClass->name.c_str(), artifs);
  2760. descr[sizeof(descr)-1] = '\0';
  2761. }
  2762. }
  2763. void CTavernWindow::HeroPortrait::show(SDL_Surface * to)
  2764. {
  2765. blitAt(graphics->portraitLarge[h->subID],pos,to);
  2766. }
  2767. void CTavernWindow::HeroPortrait::hover( bool on )
  2768. {
  2769. Hoverable::hover(on);
  2770. if(on)
  2771. LOCPLINT->statusbar->print(hoverName);
  2772. else
  2773. LOCPLINT->statusbar->clear();
  2774. }
  2775. void CInGameConsole::activate()
  2776. {
  2777. KeyInterested::activate();
  2778. }
  2779. void CInGameConsole::deactivate()
  2780. {
  2781. KeyInterested::deactivate();
  2782. }
  2783. void CInGameConsole::show(SDL_Surface * to)
  2784. {
  2785. int number = 0;
  2786. std::vector<std::list< std::pair< std::string, int > >::iterator> toDel;
  2787. texts_mx.lock();
  2788. for(std::list< std::pair< std::string, int > >::iterator it = texts.begin(); it != texts.end(); ++it, ++number)
  2789. {
  2790. SDL_Color green = {0,0xff,0,0};
  2791. Point leftBottomCorner(0, screen->h);
  2792. if(LOCPLINT->battleInt)
  2793. {
  2794. leftBottomCorner = LOCPLINT->battleInt->pos.bottomLeft();
  2795. }
  2796. CSDL_Ext::printAt(it->first, leftBottomCorner.x + 50, leftBottomCorner.y - texts.size() * 20 - 80 + number*20, TNRB16, green);
  2797. if(SDL_GetTicks() - it->second > defaultTimeout)
  2798. {
  2799. toDel.push_back(it);
  2800. }
  2801. }
  2802. for(int it=0; it<toDel.size(); ++it)
  2803. {
  2804. texts.erase(toDel[it]);
  2805. }
  2806. texts_mx.unlock();
  2807. }
  2808. void CInGameConsole::print(const std::string &txt)
  2809. {
  2810. texts_mx.lock();
  2811. texts.push_back(std::make_pair(txt, SDL_GetTicks()));
  2812. if(texts.size() > maxDisplayedTexts)
  2813. {
  2814. texts.pop_front();
  2815. }
  2816. texts_mx.unlock();
  2817. }
  2818. void CInGameConsole::keyPressed (const SDL_KeyboardEvent & key)
  2819. {
  2820. if(key.type != SDL_KEYDOWN) return;
  2821. if(!captureAllKeys && key.keysym.sym != SDLK_TAB) return; //because user is not entering any text
  2822. switch(key.keysym.sym)
  2823. {
  2824. case SDLK_TAB:
  2825. {
  2826. if(captureAllKeys)
  2827. {
  2828. captureAllKeys = false;
  2829. endEnteringText(false);
  2830. }
  2831. else
  2832. {
  2833. captureAllKeys = true;
  2834. startEnteringText();
  2835. }
  2836. break;
  2837. }
  2838. case SDLK_RETURN: //enter key
  2839. {
  2840. if(enteredText.size() > 0 && captureAllKeys)
  2841. {
  2842. captureAllKeys = false;
  2843. endEnteringText(true);
  2844. }
  2845. break;
  2846. }
  2847. case SDLK_BACKSPACE:
  2848. {
  2849. if(enteredText.size() > 1)
  2850. {
  2851. enteredText.resize(enteredText.size()-1);
  2852. enteredText[enteredText.size()-1] = '_';
  2853. refreshEnteredText();
  2854. }
  2855. break;
  2856. }
  2857. case SDLK_UP: //up arrow
  2858. {
  2859. if(prevEntDisp == -1)
  2860. {
  2861. prevEntDisp = previouslyEntered.size() - 1;
  2862. enteredText = previouslyEntered[prevEntDisp] + "_";
  2863. refreshEnteredText();
  2864. }
  2865. else if( prevEntDisp > 0)
  2866. {
  2867. --prevEntDisp;
  2868. enteredText = previouslyEntered[prevEntDisp] + "_";
  2869. refreshEnteredText();
  2870. }
  2871. break;
  2872. }
  2873. case SDLK_DOWN: //down arrow
  2874. {
  2875. if(prevEntDisp != -1 && prevEntDisp+1 < previouslyEntered.size())
  2876. {
  2877. ++prevEntDisp;
  2878. enteredText = previouslyEntered[prevEntDisp] + "_";
  2879. refreshEnteredText();
  2880. }
  2881. else if(prevEntDisp+1 == previouslyEntered.size()) //useful feature
  2882. {
  2883. prevEntDisp = -1;
  2884. enteredText = "_";
  2885. refreshEnteredText();
  2886. }
  2887. break;
  2888. }
  2889. default:
  2890. {
  2891. if(enteredText.size() > 0)
  2892. {
  2893. if( key.keysym.unicode < 0x80 && key.keysym.unicode > 0 )
  2894. {
  2895. enteredText[enteredText.size()-1] = (char)key.keysym.unicode;
  2896. enteredText += "_";
  2897. refreshEnteredText();
  2898. }
  2899. }
  2900. break;
  2901. }
  2902. }
  2903. }
  2904. void CInGameConsole::startEnteringText()
  2905. {
  2906. enteredText = "_";
  2907. if(LOCPLINT->topInt() == LOCPLINT->adventureInt)
  2908. {
  2909. LOCPLINT->statusbar->print(enteredText);
  2910. }
  2911. else if(LOCPLINT->battleInt)
  2912. {
  2913. LOCPLINT->battleInt->console->ingcAlter = enteredText;
  2914. }
  2915. }
  2916. void CInGameConsole::endEnteringText(bool printEnteredText)
  2917. {
  2918. prevEntDisp = -1;
  2919. if(printEnteredText)
  2920. {
  2921. std::string txt = enteredText.substr(0, enteredText.size()-1);
  2922. LOCPLINT->cb->sendMessage(txt);
  2923. previouslyEntered.push_back(txt);
  2924. print(txt);
  2925. }
  2926. enteredText = "";
  2927. if(LOCPLINT->topInt() == LOCPLINT->adventureInt)
  2928. {
  2929. LOCPLINT->statusbar->clear();
  2930. }
  2931. else if(LOCPLINT->battleInt)
  2932. {
  2933. LOCPLINT->battleInt->console->ingcAlter = "";
  2934. }
  2935. }
  2936. void CInGameConsole::refreshEnteredText()
  2937. {
  2938. if(LOCPLINT->topInt() == LOCPLINT->adventureInt)
  2939. {
  2940. LOCPLINT->statusbar->print(enteredText);
  2941. }
  2942. else if(LOCPLINT->battleInt)
  2943. {
  2944. LOCPLINT->battleInt->console->ingcAlter = enteredText;
  2945. }
  2946. }
  2947. CInGameConsole::CInGameConsole() : prevEntDisp(-1), defaultTimeout(10000), maxDisplayedTexts(10)
  2948. {
  2949. }
  2950. void CGarrisonWindow::close()
  2951. {
  2952. LOCPLINT->popIntTotally(this);
  2953. }
  2954. void CGarrisonWindow::activate()
  2955. {
  2956. split->activate();
  2957. quit->activate();
  2958. garr->activate();
  2959. }
  2960. void CGarrisonWindow::deactivate()
  2961. {
  2962. split->deactivate();
  2963. quit->deactivate();
  2964. garr->deactivate();
  2965. }
  2966. void CGarrisonWindow::show(SDL_Surface * to)
  2967. {
  2968. blitAt(bg,pos,to);
  2969. split->show(to);
  2970. quit->show(to);
  2971. garr->show(to);
  2972. blitAt(graphics->flags->ourImages[garr->odown->getOwner()].bitmap,pos.x+28,pos.y+124,to);
  2973. blitAt(graphics->portraitLarge[static_cast<const CGHeroInstance*>(garr->odown)->portrait],pos.x+29,pos.y+222,to);
  2974. printAtMiddle(CGI->generaltexth->allTexts[709],pos.x+275,pos.y+30,GEOR16,tytulowy,to);
  2975. }
  2976. CGarrisonWindow::CGarrisonWindow( const CArmedInstance *up, const CGHeroInstance *down )
  2977. {
  2978. bg = BitmapHandler::loadBitmap("GARRISON.bmp");
  2979. SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
  2980. graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
  2981. pos.x = screen->w/2 - bg->w/2;
  2982. pos.y = screen->h/2 - bg->h/2;
  2983. pos.w = screen->w;
  2984. pos.h = screen->h;
  2985. garr = new CGarrisonInt(pos.x+92, pos.y+127, 4, Point(0,96), bg, Point(93,127), up, down);
  2986. split = new AdventureMapButton(CGI->generaltexth->tcommands[3],"",boost::bind(&CGarrisonInt::splitClick,garr),pos.x+88,pos.y+314,"IDV6432.DEF");
  2987. quit = new AdventureMapButton(CGI->generaltexth->tcommands[8],"",boost::bind(&CGarrisonWindow::close,this),pos.x+399,pos.y+314,"IOK6432.DEF",SDLK_RETURN);
  2988. }
  2989. CGarrisonWindow::~CGarrisonWindow()
  2990. {
  2991. SDL_FreeSurface(bg);
  2992. delete split;
  2993. delete quit;
  2994. delete garr;
  2995. }
  2996. IShowActivable::IShowActivable()
  2997. {
  2998. type = 0;
  2999. }
  3000. CWindowWithGarrison::CWindowWithGarrison()
  3001. {
  3002. type |= WITH_GARRISON;
  3003. }
  3004. void CRClickPopupInt::show(SDL_Surface * to)
  3005. {
  3006. inner->show(to);
  3007. }
  3008. CRClickPopupInt::CRClickPopupInt( IShowActivable *our, bool deleteInt )
  3009. {
  3010. inner = our;
  3011. delInner = deleteInt;
  3012. }
  3013. CRClickPopupInt::~CRClickPopupInt()
  3014. {
  3015. //workaround for hero window issue - if it's our interface, call dispose to properly reset it's state
  3016. //TODO? it might be better to rewrite hero window so it will bee newed/deleted on opening / closing (not effort-worthy now, but on some day...?)
  3017. if(inner == LOCPLINT->adventureInt->heroWindow)
  3018. LOCPLINT->adventureInt->heroWindow->dispose();
  3019. if(delInner)
  3020. delete inner;
  3021. }
  3022. CArtPlace::CArtPlace(const CArtifact* Art): active(false), clicked(false), ourArt(Art)/*,
  3023. spellBook(false), warMachine1(false), warMachine2(false), warMachine3(false),
  3024. warMachine4(false),misc1(false), misc2(false), misc3(false), misc4(false),
  3025. misc5(false), feet(false), lRing(false), rRing(false), torso(false),
  3026. lHand(false), rHand(false), neck(false), shoulders(false), head(false) */{}
  3027. void CArtPlace::activate()
  3028. {
  3029. if(!active)
  3030. {
  3031. //ClickableL::activate();
  3032. LRClickableAreaWTextComp::activate();
  3033. active = true;
  3034. }
  3035. }
  3036. void CArtPlace::clickLeft(boost::logic::tribool down)
  3037. {
  3038. //LRClickableAreaWTextComp::clickLeft(down);
  3039. if(ourArt && !down && pressedL) //we are spellbook
  3040. {
  3041. if(ourArt->id == 0)
  3042. {
  3043. CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (conf.cc.resx - 620)/2, (conf.cc.resy - 595)/2), ourOwner->curHero);
  3044. LOCPLINT->pushInt(spellWindow);
  3045. }
  3046. }
  3047. if(!down && !clicked && pressedL) //not clicked before
  3048. {
  3049. if(ourArt && ourArt->id == 0)
  3050. return; //this is handled separately
  3051. if(!ourOwner->commonInfo->activeArtPlace) //nothing has been clicked
  3052. {
  3053. if(ourArt) //to prevent selecting empty slots (bugfix to what GrayFace reported)
  3054. {
  3055. clicked = true;
  3056. ourOwner->commonInfo->activeArtPlace = this;
  3057. }
  3058. }
  3059. else //perform artifact substitution
  3060. {
  3061. if(slotID >= 19) //we are an backpack slot - remove active artifact and put it to the last free pos in backpack
  3062. { //TODO: putting artifacts in the middle of backpack (pushing following arts)
  3063. LOCPLINT->cb->swapArtifacts(ourOwner->commonInfo->activeArtPlace->ourOwner->curHero, ourOwner->commonInfo->activeArtPlace->slotID, ourOwner->curHero, ourOwner->curHero->artifacts.size()+19);
  3064. }
  3065. //check if swap is possible
  3066. else if(this->fitsHere(ourOwner->commonInfo->activeArtPlace->ourArt) && ourOwner->commonInfo->activeArtPlace->fitsHere(this->ourArt))
  3067. {
  3068. int destSlot = slotID,
  3069. srcSlot = ourOwner->commonInfo->activeArtPlace->slotID;
  3070. LOCPLINT->cb->swapArtifacts(ourOwner->curHero,destSlot,ourOwner->commonInfo->activeArtPlace->ourOwner->curHero,srcSlot);
  3071. ourOwner->commonInfo->activeArtPlace->clicked = false;
  3072. ourOwner->commonInfo->activeArtPlace = NULL;
  3073. }
  3074. }
  3075. }
  3076. else if(!down && clicked)
  3077. {
  3078. if(ourArt && ourArt->id == 0)
  3079. return; //this is handled separately
  3080. clicked = false;
  3081. ourOwner->commonInfo->activeArtPlace = NULL;
  3082. }
  3083. ClickableL::clickLeft(down);
  3084. }
  3085. void CArtPlace::clickRight(boost::logic::tribool down)
  3086. {
  3087. if(text.size()) //if there is no description, do nothing ;]
  3088. LRClickableAreaWTextComp::clickRight(down);
  3089. }
  3090. void CArtPlace::deactivate()
  3091. {
  3092. if(active)
  3093. {
  3094. active = false;
  3095. //ClickableL::deactivate();
  3096. LRClickableAreaWTextComp::deactivate();
  3097. }
  3098. }
  3099. void CArtPlace::show(SDL_Surface *to)
  3100. {
  3101. if(ourArt)
  3102. {
  3103. blitAt(graphics->artDefs->ourImages[ourArt->id].bitmap, pos.x, pos.y, to);
  3104. }
  3105. if(clicked && active)
  3106. {
  3107. for(int i=0; i<pos.h; ++i)
  3108. {
  3109. for(int j=0; j<pos.w; ++j)
  3110. {
  3111. if(i==0 || j==0 || i==pos.h-1 || j==pos.w-1)
  3112. {
  3113. CSDL_Ext::SDL_PutPixelWithoutRefresh(to, pos.x+j, pos.y+i, 240, 220, 120);
  3114. }
  3115. }
  3116. }
  3117. }
  3118. }
  3119. bool CArtPlace::fitsHere(const CArtifact * art)
  3120. {
  3121. if(!art)
  3122. return true; //you can have no artifact somewhere
  3123. if(slotID > 18 || vstd::contains(art->possibleSlots,slotID)) //backpack or right slot
  3124. return true;
  3125. return false;
  3126. }
  3127. CArtPlace::~CArtPlace()
  3128. {
  3129. deactivate();
  3130. }
  3131. void LClickableArea::activate()
  3132. {
  3133. ClickableL::activate();
  3134. }
  3135. void LClickableArea::deactivate()
  3136. {
  3137. ClickableL::deactivate();
  3138. }
  3139. void LClickableArea::clickLeft(boost::logic::tribool down)
  3140. {
  3141. //if(!down)
  3142. //{
  3143. // LOCPLINT->showInfoDialog("TEST TEST AAA", std::vector<SComponent*>());
  3144. //}
  3145. }
  3146. void RClickableArea::activate()
  3147. {
  3148. ClickableR::activate();
  3149. }
  3150. void RClickableArea::deactivate()
  3151. {
  3152. ClickableR::deactivate();
  3153. }
  3154. void RClickableArea::clickRight(boost::logic::tribool down)
  3155. {
  3156. //if(!down)
  3157. //{
  3158. // LOCPLINT->showInfoDialog("TEST TEST AAA", std::vector<SComponent*>());
  3159. //}
  3160. }
  3161. void LRClickableAreaWText::clickLeft(boost::logic::tribool down)
  3162. {
  3163. if(!down && pressedL)
  3164. {
  3165. LOCPLINT->showInfoDialog(text, std::vector<SComponent*>(), soundBase::sound_todo);
  3166. }
  3167. ClickableL::clickLeft(down);
  3168. }
  3169. void LRClickableAreaWText::clickRight(boost::logic::tribool down)
  3170. {
  3171. LOCPLINT->adventureInt->handleRightClick(text, down, this);
  3172. }
  3173. void LRClickableAreaWText::activate()
  3174. {
  3175. LClickableArea::activate();
  3176. RClickableArea::activate();
  3177. Hoverable::activate();
  3178. }
  3179. void LRClickableAreaWText::deactivate()
  3180. {
  3181. LClickableArea::deactivate();
  3182. RClickableArea::deactivate();
  3183. Hoverable::deactivate();
  3184. }
  3185. void LRClickableAreaWText::hover(bool on)
  3186. {
  3187. Hoverable::hover(on);
  3188. if (on)
  3189. LOCPLINT->statusbar->print(hoverText);
  3190. else if (LOCPLINT->statusbar->getCurrent()==hoverText)
  3191. LOCPLINT->statusbar->clear();
  3192. }
  3193. void LClickableAreaHero::clickLeft(boost::logic::tribool down)
  3194. {
  3195. if(!down)
  3196. {
  3197. owner->deactivate();
  3198. const CGHeroInstance * buf = LOCPLINT->getWHero(id);
  3199. owner->setHero(buf);
  3200. owner->redrawCurBack();
  3201. owner->activate();
  3202. }
  3203. }
  3204. void LRClickableAreaWTextComp::clickLeft(boost::logic::tribool down)
  3205. {
  3206. if((!down) && pressedL)
  3207. {
  3208. std::vector<SComponent*> comp(1, new SComponent(SComponent::Etype(baseType), type, bonus));
  3209. LOCPLINT->showInfoDialog(text, comp, soundBase::sound_todo);
  3210. }
  3211. ClickableL::clickLeft(down);
  3212. }
  3213. void LRClickableAreaWTextComp::clickRight(boost::logic::tribool down)
  3214. {
  3215. LOCPLINT->adventureInt->handleRightClick(text, down, this);
  3216. }
  3217. void LRClickableAreaWTextComp::activate()
  3218. {
  3219. LClickableArea::activate();
  3220. RClickableArea::activate();
  3221. Hoverable::activate();
  3222. }
  3223. void LRClickableAreaWTextComp::deactivate()
  3224. {
  3225. LClickableArea::deactivate();
  3226. RClickableArea::deactivate();
  3227. Hoverable::deactivate();
  3228. }
  3229. void LRClickableAreaWTextComp::hover(bool on)
  3230. {
  3231. Hoverable::hover(on);
  3232. if (on)
  3233. LOCPLINT->statusbar->print(hoverText);
  3234. else if (LOCPLINT->statusbar->getCurrent()==hoverText)
  3235. LOCPLINT->statusbar->clear();
  3236. }
  3237. void CArtifactsOfHero::activate()
  3238. {
  3239. for(size_t f=0; f<artWorn.size(); ++f)
  3240. {
  3241. if(artWorn[f])
  3242. artWorn[f]->activate();
  3243. }
  3244. for(size_t f=0; f<backpack.size(); ++f)
  3245. {
  3246. if(backpack[f])
  3247. backpack[f]->activate();
  3248. }
  3249. leftArtRoll->activate();
  3250. rightArtRoll->activate();
  3251. }
  3252. void CArtifactsOfHero::deactivate()
  3253. {
  3254. for(size_t f=0; f<artWorn.size(); ++f)
  3255. {
  3256. if(artWorn[f])
  3257. artWorn[f]->deactivate();
  3258. }
  3259. for(size_t f=0; f<backpack.size(); ++f)
  3260. {
  3261. if(backpack[f])
  3262. backpack[f]->deactivate();
  3263. }
  3264. leftArtRoll->deactivate();
  3265. rightArtRoll->deactivate();
  3266. }
  3267. void CArtifactsOfHero::show(SDL_Surface * to)
  3268. {
  3269. for(size_t d=0; d<artWorn.size(); ++d)
  3270. {
  3271. artWorn[d]->show(to);
  3272. }
  3273. for(size_t d=0; d<backpack.size(); ++d)
  3274. {
  3275. backpack[d]->show(to);
  3276. }
  3277. leftArtRoll->show(to);
  3278. rightArtRoll->show(to);
  3279. }
  3280. void CArtifactsOfHero::setHero(const CGHeroInstance * hero)
  3281. {
  3282. curHero = hero;
  3283. char bufor[400];
  3284. for(size_t g=0; g<artWorn.size(); ++g)
  3285. {
  3286. delete artWorn[g];
  3287. }
  3288. for(size_t g=0; g<backpack.size(); ++g)
  3289. {
  3290. delete backpack[g];
  3291. }
  3292. backpack.clear();
  3293. std::vector<SDL_Rect> slotPos;
  3294. backpackPos = 0;
  3295. slotPos += genRect(44,44,pos.x+509,pos.y+30), genRect(44,44,pos.x+567,pos.y+240), genRect(44,44,pos.x+509,pos.y+80),
  3296. genRect(44,44,pos.x+383,pos.y+68), genRect(44,44,pos.x+564,pos.y+183), genRect(44,44,pos.x+509,pos.y+130),
  3297. genRect(44,44,pos.x+431,pos.y+68), genRect(44,44,pos.x+610,pos.y+183), genRect(44,44,pos.x+515,pos.y+295),
  3298. genRect(44,44,pos.x+383,pos.y+143), genRect(44,44,pos.x+399,pos.y+194), genRect(44,44,pos.x+415,pos.y+245),
  3299. genRect(44,44,pos.x+431,pos.y+296), genRect(44,44,pos.x+564,pos.y+30), genRect(44,44,pos.x+610,pos.y+30),
  3300. genRect(44,44,pos.x+610,pos.y+76), genRect(44,44,pos.x+610,pos.y+122), genRect(44,44,pos.x+610,pos.y+310),
  3301. genRect(44,44,pos.x+381,pos.y+296);
  3302. for (int g = 0; g < 19 ; g++)
  3303. {
  3304. artWorn[g] = new CArtPlace(hero->getArt(g));
  3305. artWorn[g]->pos = slotPos[g];
  3306. if(hero->getArt(g))
  3307. artWorn[g]->text = hero->getArt(g)->Description();
  3308. artWorn[g]->ourOwner = this;
  3309. }
  3310. for(size_t g=0; g<artWorn.size(); ++g)
  3311. {
  3312. artWorn[g]->slotID = g;
  3313. if(artWorn[g]->ourArt)
  3314. {
  3315. sprintf(bufor, CGI->generaltexth->heroscrn[1].c_str(), artWorn[g]->ourArt->Name().c_str());
  3316. artWorn[g]->hoverText = std::string(bufor);
  3317. }
  3318. else
  3319. {
  3320. artWorn[g]->hoverText = CGI->generaltexth->allTexts[507];
  3321. }
  3322. }
  3323. for(size_t s=0; s<5; ++s)
  3324. {
  3325. CArtPlace * add;
  3326. if( s < curHero->artifacts.size() )
  3327. {
  3328. add = new CArtPlace(&CGI->arth->artifacts[curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ]]);
  3329. sprintf(bufor, CGI->generaltexth->heroscrn[1].c_str(), add->ourArt->Name().c_str());
  3330. add->hoverText = bufor;
  3331. }
  3332. else
  3333. {
  3334. add = new CArtPlace(NULL);
  3335. add->hoverText = CGI->generaltexth->allTexts[507];
  3336. }
  3337. add->pos.x = pos.x + 403 + 46*s;
  3338. add->pos.y = pos.y + 365;
  3339. add->pos.h = add->pos.w = 44;
  3340. if(s<hero->artifacts.size() && hero->artifacts[s])
  3341. {
  3342. add->text = hero->getArt(19+s)->Description();
  3343. }
  3344. else
  3345. {
  3346. add->text = std::string();
  3347. }
  3348. add->ourOwner = this;
  3349. add->slotID = 19+s;
  3350. backpack.push_back(add);
  3351. }
  3352. commonInfo->activeArtPlace = NULL;
  3353. //blocking scrolling if there is not enough artifacts to scroll
  3354. leftArtRoll->block(hero->artifacts.size()<6);
  3355. rightArtRoll->block(hero->artifacts.size()<6);
  3356. }
  3357. void CArtifactsOfHero::dispose()
  3358. {
  3359. curHero = NULL;
  3360. for(size_t g=0; g<artWorn.size(); ++g)
  3361. {
  3362. delete artWorn[g];
  3363. artWorn[g] = NULL;
  3364. }
  3365. for(size_t g=0; g<backpack.size(); ++g)
  3366. {
  3367. delete backpack[g];
  3368. backpack[g] = NULL;
  3369. }
  3370. backpack.clear();
  3371. if(commonInfo)
  3372. commonInfo->activeArtPlace = NULL;
  3373. }
  3374. void CArtifactsOfHero::scrollBackpack(int dir)
  3375. {
  3376. backpackPos += dir + curHero->artifacts.size();
  3377. backpackPos %= curHero->artifacts.size();
  3378. for(size_t s=0; s<5 && s<curHero->artifacts.size(); ++s) //set new data
  3379. {
  3380. CArtPlace *cur = backpack[s];
  3381. cur->slotID = 19+((s+backpackPos)%curHero->artifacts.size());
  3382. cur->ourArt = curHero->getArt(cur->slotID);
  3383. if(cur->ourArt)
  3384. cur->text = cur->ourArt->Description();
  3385. else
  3386. cur->text = std::string();
  3387. }
  3388. }
  3389. CArtifactsOfHero::CArtifactsOfHero(const SDL_Rect & position) :
  3390. backpackPos(0)
  3391. {
  3392. pos = position;
  3393. artWorn.resize(19);
  3394. leftArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind(&CArtifactsOfHero::scrollBackpack,this,-1), pos.x+379, pos.y+364, "hsbtns3.def", SDLK_LEFT);
  3395. rightArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind(&CArtifactsOfHero::scrollBackpack,this,+1), pos.x+632, pos.y+364, "hsbtns5.def", SDLK_RIGHT);
  3396. }
  3397. CArtifactsOfHero::~CArtifactsOfHero()
  3398. {
  3399. dispose();
  3400. artWorn.clear();
  3401. delete leftArtRoll;
  3402. delete rightArtRoll;
  3403. }
  3404. void CExchangeWindow::close()
  3405. {
  3406. LOCPLINT->popIntTotally(this);
  3407. }
  3408. void CExchangeWindow::activate()
  3409. {
  3410. quit->activate();
  3411. garr->activate();
  3412. artifs[0]->activate();
  3413. artifs[1]->activate();
  3414. for(int g=0; g<ARRAY_COUNT(secSkillAreas); g++)
  3415. {
  3416. for(int b=0; b<secSkillAreas[g].size(); ++b)
  3417. {
  3418. secSkillAreas[g][b]->activate();
  3419. }
  3420. }
  3421. for(int b=0; b<primSkillAreas.size(); ++b)
  3422. {
  3423. primSkillAreas[b]->activate();
  3424. }
  3425. LOCPLINT->statusbar = ourBar;
  3426. for(int g=0; g<ARRAY_COUNT(questlogButton); g++)
  3427. {
  3428. questlogButton[g]->activate();
  3429. }
  3430. for(int g=0; g<ARRAY_COUNT(morale); g++)
  3431. {
  3432. morale[g]->activate();
  3433. }
  3434. for(int g=0; g<ARRAY_COUNT(luck); g++)
  3435. {
  3436. luck[g]->activate();
  3437. }
  3438. }
  3439. void CExchangeWindow::deactivate()
  3440. {
  3441. quit->deactivate();
  3442. garr->deactivate();
  3443. artifs[0]->deactivate();
  3444. artifs[1]->deactivate();
  3445. for(int g=0; g<ARRAY_COUNT(secSkillAreas); g++)
  3446. {
  3447. for(int b=0; b<secSkillAreas[g].size(); ++b)
  3448. {
  3449. secSkillAreas[g][b]->deactivate();
  3450. }
  3451. }
  3452. for(int b=0; b<primSkillAreas.size(); ++b)
  3453. {
  3454. primSkillAreas[b]->deactivate();
  3455. }
  3456. for(int g=0; g<ARRAY_COUNT(questlogButton); g++)
  3457. {
  3458. questlogButton[g]->deactivate();
  3459. }
  3460. for(int g=0; g<ARRAY_COUNT(morale); g++)
  3461. {
  3462. morale[g]->deactivate();
  3463. }
  3464. for(int g=0; g<ARRAY_COUNT(luck); g++)
  3465. {
  3466. luck[g]->deactivate();
  3467. }
  3468. }
  3469. void CExchangeWindow::show(SDL_Surface * to)
  3470. {
  3471. blitAt(bg, pos, to);
  3472. quit->show(to);
  3473. //printing border around window
  3474. if(screen->w != 800 || screen->h !=600)
  3475. CMessage::drawBorder(LOCPLINT->playerID,to,828,628,pos.x-14,pos.y-15);
  3476. artifs[0]->show(to);
  3477. artifs[1]->show(to);
  3478. ourBar->show(to);
  3479. for(int g=0; g<ARRAY_COUNT(secSkillAreas); g++)
  3480. {
  3481. questlogButton[g]->show(to);
  3482. }
  3483. garr->show(to);
  3484. }
  3485. void CExchangeWindow::questlog(int whichHero)
  3486. {
  3487. }
  3488. void CExchangeWindow::prepareBackground()
  3489. {
  3490. if(bg)
  3491. SDL_FreeSurface(bg);
  3492. SDL_Surface * bgtemp; //loaded as 8bpp surface
  3493. bgtemp = BitmapHandler::loadBitmap("TRADE2.BMP");
  3494. graphics->blueToPlayersAdv(bgtemp, heroInst[0]->tempOwner);
  3495. bg = SDL_ConvertSurface(bgtemp, screen->format, screen->flags); //to 24 bpp
  3496. SDL_FreeSurface(bgtemp);
  3497. //printing heroes' names and levels
  3498. std::ostringstream os, os2;
  3499. os<<heroInst[0]->name<<", Level "<<heroInst[0]->level<<" "<<heroInst[0]->type->heroClass->name;
  3500. CSDL_Ext::printAtMiddle(os.str(), 147, 23, GEOR13, zwykly, bg);
  3501. os2<<heroInst[1]->name<<", Level "<<heroInst[1]->level<<" "<<heroInst[1]->type->heroClass->name;
  3502. CSDL_Ext::printAtMiddle(os2.str(), 653, 23, GEOR13, zwykly, bg);
  3503. //printing primary skills
  3504. CDefHandler * skilldef = CDefHandler::giveDef("PSKIL32.DEF");
  3505. for(int g=0; g<4; ++g)
  3506. {
  3507. //graphics
  3508. blitAt(skilldef->ourImages[g].bitmap, genRect(32, 32, 385, 19 + 36 * g), bg);
  3509. }
  3510. CDefHandler * un32 = CDefHandler::giveDef("UN32.DEF");
  3511. //heroes related thing
  3512. for(int b=0; b<ARRAY_COUNT(heroInst); b++)
  3513. {
  3514. //printing primary skills' amounts
  3515. for(int m=0; m<4; ++m)
  3516. {
  3517. std::ostringstream primarySkill;
  3518. primarySkill<<heroInst[b]->getPrimSkillLevel(m);
  3519. CSDL_Ext::printAtMiddle(primarySkill.str(), 353 + 93 * b, 35 + 36 * m, TNRB16, zwykly, bg);
  3520. }
  3521. //printing secondary skills
  3522. for(int m=0; m<heroInst[b]->secSkills.size(); ++m)
  3523. {
  3524. blitAt(graphics->abils32->ourImages[heroInst[b]->secSkills[m].first * 3 + heroInst[b]->secSkills[m].second + 2].bitmap, genRect(32, 32, 32 + 36 * m + 454 * b, 88), bg);
  3525. }
  3526. //hero's specialty
  3527. blitAt(un32->ourImages[heroInst[b]->subID].bitmap, 67 + 490*b, 45, bg);
  3528. //experience
  3529. blitAt(skilldef->ourImages[4].bitmap, 103 + 490*b, 45, bg);
  3530. printAtMiddle( makeNumberShort(heroInst[b]->exp), 119 + 490*b, 71, GEOR13, zwykly, bg );
  3531. //mana points
  3532. blitAt(skilldef->ourImages[5].bitmap, 139 + 490*b, 45, bg);
  3533. printAtMiddle( makeNumberShort(heroInst[b]->mana), 155 + 490*b, 71, GEOR13, zwykly, bg );
  3534. //setting morale
  3535. blitAt(graphics->morale30->ourImages[heroInst[b]->getCurrentMorale()+3].bitmap, 177 + 490*b, 45, bg);
  3536. //setting luck
  3537. blitAt(graphics->luck30->ourImages[heroInst[b]->getCurrentLuck()+3].bitmap, 213 + 490*b, 45, bg);
  3538. }
  3539. //printing portraits
  3540. blitAt(graphics->portraitLarge[heroInst[0]->portrait], 257, 13, bg);
  3541. blitAt(graphics->portraitLarge[heroInst[1]->portrait], 485, 13, bg);
  3542. delete un32;
  3543. delete skilldef;
  3544. }
  3545. CExchangeWindow::CExchangeWindow(si32 hero1, si32 hero2) : bg(NULL)
  3546. {
  3547. char bufor[400];
  3548. heroInst[0] = LOCPLINT->cb->getHeroInfo(hero1, 2);
  3549. heroInst[1] = LOCPLINT->cb->getHeroInfo(hero2, 2);
  3550. prepareBackground();
  3551. pos.x = screen->w/2 - bg->w/2;
  3552. pos.y = screen->h/2 - bg->h/2;
  3553. pos.w = screen->w;
  3554. pos.h = screen->h;
  3555. artifs[0] = new CArtifactsOfHero(genRect(600, 800, pos.x + -334, pos.y + 150));
  3556. artifs[0]->commonInfo = new CArtifactsOfHero::SCommonPart;
  3557. artifs[0]->setHero(heroInst[0]);
  3558. artifs[0]->commonInfo->activeArtPlace = NULL;
  3559. artifs[1] = new CArtifactsOfHero(genRect(600, 800, pos.x + 96, pos.y + 150));
  3560. artifs[1]->commonInfo = artifs[0]->commonInfo;
  3561. artifs[1]->setHero(heroInst[1]);
  3562. //primary skills
  3563. for(int g=0; g<4; ++g)
  3564. {
  3565. //primary skill's clickable areas
  3566. primSkillAreas.push_back(new LRClickableAreaWTextComp());
  3567. primSkillAreas[g]->pos = genRect(32, 32, pos.x+385, pos.y + 19 + 36 * g);
  3568. primSkillAreas[g]->text = CGI->generaltexth->arraytxt[2+g];
  3569. primSkillAreas[g]->type = g;
  3570. primSkillAreas[g]->bonus = -1;
  3571. primSkillAreas[g]->baseType = 0;
  3572. }
  3573. //heroes related thing
  3574. for(int b=0; b<ARRAY_COUNT(heroInst); b++)
  3575. {
  3576. //secondary skill's clickable areas
  3577. for(int g=0; g<heroInst[b]->secSkills.size(); ++g)
  3578. {
  3579. secSkillAreas[b].push_back(new LRClickableAreaWTextComp());
  3580. secSkillAreas[b][g]->pos = genRect(32, 32, pos.x + 32 + g*36 + b*454 , pos.y + 88);
  3581. secSkillAreas[b][g]->baseType = 1;
  3582. secSkillAreas[b][g]->type = heroInst[b]->secSkills[g].first;
  3583. secSkillAreas[b][g]->bonus = heroInst[b]->secSkills[g].second;
  3584. std::string hlp = CGI->generaltexth->skillInfoTexts[ heroInst[b]->secSkills[g].first ][heroInst[b]->secSkills[g].second-1];
  3585. secSkillAreas[b][g]->text = hlp.substr(1, hlp.size()-2);
  3586. sprintf(bufor, CGI->generaltexth->heroscrn[21].c_str(), CGI->generaltexth->levels[heroInst[b]->secSkills[g].second-1].c_str(), CGI->generaltexth->skillName[heroInst[b]->secSkills[g].first].c_str());
  3587. secSkillAreas[b][g]->hoverText = std::string(bufor);
  3588. }
  3589. //setting morale
  3590. morale[b] = new LRClickableAreaWTextComp();
  3591. morale[b]->pos = genRect(32, 32, pos.x + 177 + 490*b, pos.y + 45);
  3592. std::vector<std::pair<int,std::string> > mrl = heroInst[b]->getCurrentMoraleModifiers();
  3593. int mrlv = heroInst[b]->getCurrentMorale();
  3594. int mrlt = (mrlv>0)-(mrlv<0); //signum: -1 - bad morale[b], 0 - neutral, 1 - good
  3595. morale[b]->hoverText = CGI->generaltexth->heroscrn[4 - mrlt];
  3596. morale[b]->baseType = SComponent::morale;
  3597. morale[b]->bonus = mrlv;
  3598. morale[b]->text = CGI->generaltexth->arraytxt[88];
  3599. boost::algorithm::replace_first(morale[b]->text,"%s",CGI->generaltexth->arraytxt[86-mrlt]);
  3600. for(int it=0; it < mrl.size(); it++)
  3601. morale[b]->text += mrl[it].second;
  3602. //setting luck
  3603. luck[b] = new LRClickableAreaWTextComp();
  3604. luck[b]->pos = genRect(32, 32, pos.x + 213 + 490*b, pos.y + 45);
  3605. mrl = heroInst[b]->getCurrentLuckModifiers();
  3606. mrlv = heroInst[b]->getCurrentLuck();
  3607. mrlt = (mrlv>0)-(mrlv<0); //signum: -1 - bad luck[b], 0 - neutral, 1 - good
  3608. luck[b]->hoverText = CGI->generaltexth->heroscrn[7 - mrlt];
  3609. luck[b]->baseType = SComponent::luck;
  3610. luck[b]->bonus = mrlv;
  3611. luck[b]->text = CGI->generaltexth->arraytxt[62];
  3612. boost::algorithm::replace_first(luck[b]->text,"%s",CGI->generaltexth->arraytxt[60-mrlt]);
  3613. for(int it=0; it < mrl.size(); it++)
  3614. luck[b]->text += mrl[it].second;
  3615. }
  3616. //buttons
  3617. quit = new AdventureMapButton(CGI->generaltexth->tcommands[8], "", boost::bind(&CExchangeWindow::close, this), pos.x+732, pos.y+567, "IOKAY.DEF", SDLK_RETURN);
  3618. questlogButton[0] = new AdventureMapButton(CGI->generaltexth->heroscrn[0], std::string(), boost::bind(&CExchangeWindow::questlog,this, 0), pos.x+10, pos.y+44, "hsbtns4.def");
  3619. questlogButton[1] = new AdventureMapButton(CGI->generaltexth->heroscrn[0], std::string(), boost::bind(&CExchangeWindow::questlog,this, 1), pos.x+740, pos.y+44, "hsbtns4.def");
  3620. //statusbar
  3621. ourBar = new CStatusBar(pos.x + 3, pos.y + 577, "TSTATBAR.bmp", 726);
  3622. //garrison interface
  3623. garr = new CGarrisonInt(pos.x + 69, pos.y + 131, 4, Point(418,0), bg, Point(69,131), heroInst[0],heroInst[1], true);
  3624. }
  3625. CExchangeWindow::~CExchangeWindow() //d-tor
  3626. {
  3627. SDL_FreeSurface(bg);
  3628. delete quit;
  3629. //warning: don't experiment with these =NULL lines, they prevent heap corruption!
  3630. delete artifs[0]->commonInfo;
  3631. artifs[0]->commonInfo = NULL;
  3632. delete artifs[0];
  3633. artifs[1]->commonInfo = NULL;
  3634. delete artifs[1];
  3635. delete garr;
  3636. delete ourBar;
  3637. for(int g=0; g<ARRAY_COUNT(secSkillAreas); g++)
  3638. {
  3639. for(int b=0; b<secSkillAreas[g].size(); ++b)
  3640. {
  3641. delete secSkillAreas[g][b];
  3642. }
  3643. }
  3644. for(int b=0; b<primSkillAreas.size(); ++b)
  3645. {
  3646. delete primSkillAreas[b];
  3647. }
  3648. for(int g=0; g<ARRAY_COUNT(questlogButton); g++)
  3649. {
  3650. delete questlogButton[g];
  3651. }
  3652. for(int g=0; g<ARRAY_COUNT(morale); g++)
  3653. {
  3654. delete morale[g];
  3655. }
  3656. for(int g=0; g<ARRAY_COUNT(luck); g++)
  3657. {
  3658. delete luck[g];
  3659. }
  3660. }
  3661. void CShipyardWindow::activate()
  3662. {
  3663. build->activate();
  3664. quit->activate();
  3665. }
  3666. void CShipyardWindow::deactivate()
  3667. {
  3668. build->deactivate();
  3669. quit->deactivate();
  3670. }
  3671. void CShipyardWindow::show( SDL_Surface * to )
  3672. {
  3673. blitAt(bg,pos,to);
  3674. CSDL_Ext::blit8bppAlphaTo24bpp(graphics->boatAnims[1]->ourImages[21 + frame++/8%8].bitmap, NULL, to, &genRect(64, 96, pos.x+110, pos.y+85));
  3675. build->show(to);
  3676. quit->show(to);
  3677. }
  3678. CShipyardWindow::~CShipyardWindow()
  3679. {
  3680. delete build;
  3681. delete quit;
  3682. }
  3683. CShipyardWindow::CShipyardWindow(const std::vector<si32> &cost, int state, const boost::function<void()> &onBuy)
  3684. {
  3685. frame = 0;
  3686. SDL_Surface * bgtemp; //loaded as 8bpp surface
  3687. bgtemp = BitmapHandler::loadBitmap("TPSHIP.bmp");
  3688. pos.x = screen->w/2 - bgtemp->w/2;
  3689. pos.y = screen->h/2 - bgtemp->h/2;
  3690. pos.w = bgtemp->w;
  3691. pos.h = bgtemp->h;
  3692. SDL_SetColorKey(bgtemp,SDL_SRCCOLORKEY,SDL_MapRGB(bgtemp->format,0,255,255));
  3693. graphics->blueToPlayersAdv(bgtemp, LOCPLINT->playerID);
  3694. bg = SDL_ConvertSurface(bgtemp, screen->format, screen->flags); //to 24 bpp
  3695. SDL_FreeSurface(bgtemp);
  3696. bgtemp = BitmapHandler::loadBitmap("TPSHIPBK.bmp");
  3697. blitAt(bgtemp, 100, 69, bg);
  3698. SDL_FreeSurface(bgtemp);
  3699. bool affordable = true;
  3700. for(int i = 0; i < cost.size(); i++)
  3701. {
  3702. if(cost[i] > LOCPLINT->cb->getResourceAmount(i))
  3703. {
  3704. affordable = false;
  3705. break;
  3706. }
  3707. }
  3708. quit = new AdventureMapButton(CGI->generaltexth->allTexts[599], "", boost::bind(&CPlayerInterface::popIntTotally, LOCPLINT, this), pos.x+224, pos.y+312, "ICANCEL.DEF", SDLK_RETURN);
  3709. build = new AdventureMapButton(CGI->generaltexth->allTexts[598], "", boost::bind(&CPlayerInterface::popIntTotally, LOCPLINT, this), pos.x+42, pos.y+312, "IBY6432.DEF", SDLK_RETURN);
  3710. build->callback += onBuy;
  3711. if(!affordable)
  3712. build->block(true);
  3713. printAtMiddle(CGI->generaltexth->jktexts[15], 165, 26, GEOR13, zwykly, bg); //Resource cost:
  3714. printAtMiddle(CGI->generaltexth->jktexts[14], 165, 218, GEOR16, tytulowy, bg); //Build A New Ship
  3715. }