GUIClasses.cpp 138 KB

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