GUIClasses.cpp 114 KB

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