1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323 |
- //
- // string allocation/managment
- // leave this at the top of all UI_xxxx files for PCH reasons...
- //
- #include "../server/exe_headers.h"
- #include "ui_local.h"
- //rww - added for ui ghoul2 models
- #define UI_SHARED_CPP
- #include "../game/anims.h"
- #include "../cgame/animtable.h"
- #include "ui_shared.h"
- #include "menudef.h"
- void UI_LoadMenus(const char *menuFile, qboolean reset);
- #ifdef _XBOX
- #include "../win32/glw_win_dx8.h"
- #include "../renderer/tr_lightmanager.h"
- //MAP HACK!
- extern cvar_t *cl_mapname;
- void Menu_MapHack(int key);
- //JLF DEMOCODE MPMOVED
- //support for attract mode demo timer
- #define DEMO_TIME_MAX 45000 //g_demoTimeBeforeStart
- int g_demoLastKeypress = 0; //milliseconds
- bool g_ReturnToSplash = false;
- bool g_runningDemo = false;
- void G_DemoStart();
- void G_DemoEnd();
- void G_DemoKeypress();
- void PlayDemo();
- void UpdateDemoTimer();
- bool TestDemoTimer();
- //END DEMOCODE
- //JLF used by sliders MPMOVED
- #define TICK_COUNT 16
- //JLF MORE PROTOTYPES MPMOVED
- qboolean Item_SetFocus(itemDef_t *item, float x, float y);
- qboolean Item_HandleAction(itemDef_t * item);
- qboolean Item_HandleSelectionNext(itemDef_t * item);
- qboolean Item_HandleSelectionPrev(itemDef_t * item);
- #endif
- extern vmCvar_t ui_char_color_red;
- extern vmCvar_t ui_char_color_green;
- extern vmCvar_t ui_char_color_blue;
- void *UI_Alloc( int size );
- void Controls_GetConfig( void );
- void Fade(int *flags, float *f, float clamp, int *nextTime, int offsetTime, qboolean bFlags, float fadeAmount);
- void Item_Init(itemDef_t *item);
- void Item_InitControls(itemDef_t *item);
- qboolean Item_Parse(itemDef_t *item);
- void Item_RunScript(itemDef_t *item, const char *s);
- void Item_SetupKeywordHash(void);
- void Item_Text_AutoWrapped_Paint(itemDef_t *item);
- void Item_UpdatePosition(itemDef_t *item);
- void Item_ValidateTypeData(itemDef_t *item);
- void LerpColor(vec4_t a, vec4_t b, vec4_t c, float t);
- itemDef_t *Menu_FindItemByName(menuDef_t *menu, const char *p);
- itemDef_t *Menu_GetMatchingItemByNumber(menuDef_t *menu, int index, const char *name);
- void Menu_Paint(menuDef_t *menu, qboolean forcePaint);
- void Menu_SetupKeywordHash(void);
- void Menus_ShowItems(const char *menuName);
- qboolean ParseRect(const char **p, rectDef_t *r);
- const char *String_Alloc(const char *p);
- void ToWindowCoords(float *x, float *y, windowDef_t *window);
- void Window_Paint(Window *w, float fadeAmount, float fadeClamp, float fadeCycle);
- int Item_ListBox_ThumbDrawPosition(itemDef_t *item);
- int Item_ListBox_ThumbPosition(itemDef_t *item);
- int Item_ListBox_MaxScroll(itemDef_t *item);
- static qboolean Rect_ContainsPoint(rectDef_t *rect, float x, float y) ;
- static qboolean Item_Paint(itemDef_t *item, qboolean bDraw);
- int Item_TextScroll_ThumbDrawPosition ( itemDef_t *item );
- static void Item_TextScroll_BuildLines ( itemDef_t* item );
- qboolean Item_EnableShowViaCvar(itemDef_t *item, int flag) ;
- //static qboolean debugMode = qfalse;
- static qboolean g_waitingForKey = qfalse;
- static qboolean g_editingField = qfalse;
- static itemDef_t *g_bindItem = NULL;
- static itemDef_t *g_editItem = NULL;
- static itemDef_t *itemCapture = NULL; // item that has the mouse captured ( if any )
- #define DOUBLE_CLICK_DELAY 300
- static int lastListBoxClickTime = 0;
- static void (*captureFunc) (void *p) = NULL;
- static void *captureData = NULL;
- //const char defaultString[10] = {"default"};
- #ifndef _XBOX
- #ifdef CGAME
- #define MEM_POOL_SIZE 128 * 1024
- #else
- #define MEM_POOL_SIZE 1024 * 1024
- #endif
- #endif // _XBOX
- #define SCROLL_TIME_START 500
- #define SCROLL_TIME_ADJUST 150
- #define SCROLL_TIME_ADJUSTOFFSET 40
- #define SCROLL_TIME_FLOOR 20
- typedef struct scrollInfo_s {
- int nextScrollTime;
- int nextAdjustTime;
- int adjustValue;
- int scrollKey;
- float xStart;
- float yStart;
- itemDef_t *item;
- qboolean scrollDir;
- } scrollInfo_t;
- static scrollInfo_t scrollInfo;
- #ifndef _XBOX
- static char memoryPool[MEM_POOL_SIZE];
- #endif
- static int allocPoint, outOfMemory;
- displayContextDef_t *DC = NULL;
- menuDef_t Menus[MAX_MENUS]; // defined menus
- int menuCount = 0; // how many
- menuDef_t *menuStack[MAX_OPEN_MENUS];
- int openMenuCount = 0;
- static int strPoolIndex = 0;
- static char strPool[STRING_POOL_SIZE];
- typedef struct stringDef_s {
- struct stringDef_s *next;
- const char *str;
- } stringDef_t;
- #define HASH_TABLE_SIZE 2048
- static int strHandleCount = 0;
- static stringDef_t *strHandle[HASH_TABLE_SIZE];
- typedef struct itemFlagsDef_s {
- char *string;
- int value;
- } itemFlagsDef_t;
- itemFlagsDef_t itemFlags [] = {
- "WINDOW_INACTIVE", WINDOW_INACTIVE,
- NULL, NULL
- };
- char *styles [] = {
- "WINDOW_STYLE_EMPTY",
- "WINDOW_STYLE_FILLED",
- "WINDOW_STYLE_GRADIENT",
- "WINDOW_STYLE_SHADER",
- "WINDOW_STYLE_TEAMCOLOR",
- "WINDOW_STYLE_CINEMATIC",
- NULL
- };
- char *types [] = {
- "ITEM_TYPE_TEXT",
- "ITEM_TYPE_BUTTON",
- "ITEM_TYPE_RADIOBUTTON",
- "ITEM_TYPE_CHECKBOX",
- "ITEM_TYPE_EDITFIELD",
- "ITEM_TYPE_COMBO",
- "ITEM_TYPE_LISTBOX",
- "ITEM_TYPE_MODEL",
- "ITEM_TYPE_OWNERDRAW",
- "ITEM_TYPE_NUMERICFIELD",
- "ITEM_TYPE_SLIDER",
- "ITEM_TYPE_YESNO",
- "ITEM_TYPE_MULTI",
- "ITEM_TYPE_BIND",
- "ITEM_TYPE_TEXTSCROLL",
- NULL
- };
- char *alignment [] = {
- "ITEM_ALIGN_LEFT",
- "ITEM_ALIGN_CENTER",
- "ITEM_ALIGN_RIGHT",
- NULL
- };
- /*
- ==================
- Init_Display
- Initializes the display with a structure to all the drawing routines
- ==================
- */
- void Init_Display(displayContextDef_t *dc)
- {
- DC = dc;
- }
- /*
- ==================
- Window_Init
- Initializes a window structure ( windowDef_t ) with defaults
-
- ==================
- */
- void Window_Init(Window *w)
- {
- memset(w, 0, sizeof(windowDef_t));
- w->borderSize = 1;
- w->foreColor[0] = w->foreColor[1] = w->foreColor[2] = w->foreColor[3] = 1.0;
- // w->cinematic = -1;
- }
- /*
- =================
- PC_SourceError
- =================
- */
- #ifndef _XBOX
- void PC_SourceError(int handle, char *format, ...)
- {
- int line;
- char filename[128];
- va_list argptr;
- static char string[4096];
- va_start (argptr, format);
- vsprintf (string, format, argptr);
- va_end (argptr);
- filename[0] = '\0';
- line = 0;
- Com_Printf(S_COLOR_RED "ERROR: %s, line %d: %s\n", filename, line, string);
- }
- #endif
- /*
- =================
- PC_ParseStringMem
- =================
- */
- //static vector<string> RetryPool;
- //void AddMenuPackageRetryKey(const char *psSPPackage)
- //{
- // RetryPool.push_back(psSPPackage);
- //}
- qboolean PC_ParseStringMem(const char **out)
- {
- const char *temp;
- if (PC_ParseString(&temp))
- {
- return qfalse;
- }
- *(out) = String_Alloc(temp);
- return qtrue;
- }
- /*
- =================
- PC_ParseRect
- =================
- */
- qboolean PC_ParseRect(rectDef_t *r)
- {
- if (!PC_ParseFloat(&r->x))
- {
- if (!PC_ParseFloat(&r->y))
- {
- if (!PC_ParseFloat(&r->w))
- {
- if (!PC_ParseFloat(&r->h))
- {
- return qtrue;
- }
- }
- }
- }
- return qfalse;
- }
- /*
- =================
- PC_Script_Parse
- =================
- */
- qboolean PC_Script_Parse(const char **out)
- {
- char script[4096];
- // pc_token_t token;
- char *token2;
- script[0]=0;
- // scripts start with { and have ; separated command lists.. commands are command, arg..
- // basically we want everything between the { } as it will be interpreted at run time
-
- token2 = PC_ParseExt();
- if (!token2)
- {
- return qfalse;
- }
- if (*token2 !='{')
- {
- return qfalse;
- }
- while ( 1 )
- {
- token2 = PC_ParseExt();
- if (!token2)
- {
- return qfalse;
- }
- if (*token2 =='}') // End of the script?
- {
- *out = String_Alloc(script);
- return qtrue;
- }
- if (*(token2 +1) != '\0')
- {
- Q_strcat(script, sizeof(script), va("\"%s\"", token2));
- }
- else
- {
- Q_strcat(script, sizeof(script), token2);
- }
- Q_strcat(script, sizeof(script), " ");
- }
- }
- //--------------------------------------------------------------------------------------------
- // Menu Keyword Parse functions
- //--------------------------------------------------------------------------------------------
- /*
- =================
- MenuParse_font
- =================
- */
- qboolean MenuParse_font( itemDef_t *item)
- {
- menuDef_t *menu = (menuDef_t*)item;
- if (!PC_ParseStringMem(&menu->font))
- {
- return qfalse;
- }
- if (!DC->Assets.fontRegistered)
- {
- DC->Assets.qhMediumFont = DC->registerFont(menu->font);
- DC->Assets.fontRegistered = qtrue;
- }
- return qtrue;
- }
- /*
- =================
- MenuParse_name
- =================
- */
- qboolean MenuParse_name(itemDef_t *item)
- {
- menuDef_t *menu = (menuDef_t*)item;
- if (!PC_ParseStringMem((const char **) &menu->window.name))
- {
- return qfalse;
- }
- // if (Q_stricmp(menu->window.name, "main") == 0)
- // {
- // default main as having focus
- // menu->window.flags |= WINDOW_HASFOCUS;
- // }
- return qtrue;
- }
- /*
- =================
- MenuParse_fullscreen
- =================
- */
- qboolean MenuParse_fullscreen( itemDef_t *item )
- {
- menuDef_t *menu = (menuDef_t*)item;
- if (PC_ParseInt((int *) &menu->fullScreen))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- =================
- MenuParse_rect
- =================
- */
- qboolean MenuParse_rect( itemDef_t *item)
- {
- menuDef_t *menu = (menuDef_t*)item;
- if (!PC_ParseRect(&menu->window.rect))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- =================
- MenuParse_style
- =================
- */
- qboolean MenuParse_style( itemDef_t *item)
- {
- int i;
- const char *tempStr;
- menuDef_t *menu = (menuDef_t*)item;
- if (PC_ParseString(&tempStr))
- {
- return qfalse;
- }
- i=0;
- while (styles[i])
- {
- if (Q_stricmp(tempStr,styles[i])==0)
- {
- menu->window.style = i;
- break;
- }
- i++;
- }
- if (styles[i] == NULL)
- {
- PC_ParseWarning(va("Unknown menu style value '%s'",tempStr));
- }
- return qtrue;
- }
- /*
- =================
- MenuParse_visible
- =================
- */
- qboolean MenuParse_visible( itemDef_t *item )
- {
- int i;
- menuDef_t *menu = (menuDef_t*)item;
- if (PC_ParseInt(&i))
- {
- return qfalse;
- }
- if (i)
- {
- menu->window.flags |= WINDOW_VISIBLE;
- }
- return qtrue;
- }
- /*
- =================
- MenuParse_ignoreescape
- =================
- */
- qboolean MenuParse_ignoreescape( itemDef_t *item )
- {
- int i;
- menuDef_t *menu = (menuDef_t*)item;
- if (PC_ParseInt(&i))
- {
- return qfalse;
- }
- if (i)
- {
- menu->window.flags |= WINDOW_IGNORE_ESCAPE;
- }
- return qtrue;
- }
- /*
- =================
- MenuParse_onOpen
- =================
- */
- qboolean MenuParse_onOpen( itemDef_t *item)
- {
- menuDef_t *menu = (menuDef_t*)item;
- if (!PC_Script_Parse(&menu->onOpen))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- =================
- MenuParse_onClose
- =================
- */
- qboolean MenuParse_onClose( itemDef_t *item )
- {
- menuDef_t *menu = (menuDef_t*)item;
- if (!PC_Script_Parse(&menu->onClose))
- {
- return qfalse;
- }
- return qtrue;
- }
- //JLFACCEPT MPMOVED
- /*
- =================
- MenuParse_onAccept
- =================
- */
- qboolean MenuParse_onAccept( itemDef_t *item )
- {
- menuDef_t *menu = (menuDef_t*)item;
- if (!PC_Script_Parse(&menu->onAccept))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- =================
- MenuParse_onESC
- =================
- */
- qboolean MenuParse_onESC( itemDef_t *item )
- {
- menuDef_t *menu = (menuDef_t*)item;
- if (!PC_Script_Parse(&menu->onESC))
- {
- return qfalse;
- }
- return qtrue;
- }
- qboolean MenuParse_xScript( itemDef_t *item )
- {
- menuDef_t *menu = (menuDef_t*)item;
- if (!PC_Script_Parse(&menu->xScript))
- {
- return qfalse;
- }
- return qtrue;
- }
- qboolean MenuParse_yScript( itemDef_t *item )
- {
- menuDef_t *menu = (menuDef_t*)item;
- if (!PC_Script_Parse(&menu->yScript))
- {
- return qfalse;
- }
- return qtrue;
- }
- qboolean MenuParse_whiteScript( itemDef_t *item )
- {
- menuDef_t *menu = (menuDef_t*)item;
- if (!PC_Script_Parse(&menu->whiteScript))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- =================
- MenuParse_border
- =================
- */
- qboolean MenuParse_border( itemDef_t *item)
- {
- menuDef_t *menu = (menuDef_t*)item;
- if (PC_ParseInt(&menu->window.border))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- =================
- MenuParse_borderSize
- =================
- */
- qboolean MenuParse_borderSize( itemDef_t *item)
- {
- menuDef_t *menu = (menuDef_t*)item;
- if (PC_ParseFloat(&menu->window.borderSize))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- =================
- MenuParse_backcolor
- =================
- */
- qboolean MenuParse_backcolor( itemDef_t *item )
- {
- int i;
- float f;
- menuDef_t *menu = (menuDef_t*)item;
- for (i = 0; i < 4; i++)
- {
- if (PC_ParseFloat(&f))
- {
- return qfalse;
- }
- menu->window.backColor[i] = f;
- }
- return qtrue;
- }
- /*
- =================
- MenuParse_forecolor
- =================
- */
- qboolean MenuParse_forecolor( itemDef_t *item)
- {
- int i;
- float f;
- menuDef_t *menu = (menuDef_t*)item;
- for (i = 0; i < 4; i++)
- {
- if (PC_ParseFloat(&f))
- {
- return qfalse;
- }
- if (f < 0)
- { //special case for player color
- menu->window.flags |= WINDOW_PLAYERCOLOR;
- return qtrue;
- }
- menu->window.foreColor[i] = f;
- menu->window.flags |= WINDOW_FORECOLORSET;
- }
- return qtrue;
- }
- /*
- =================
- MenuParse_bordercolor
- =================
- */
- qboolean MenuParse_bordercolor( itemDef_t *item )
- {
- int i;
- float f;
- menuDef_t *menu = (menuDef_t*)item;
- for (i = 0; i < 4; i++)
- {
- if (PC_ParseFloat(&f))
- {
- return qfalse;
- }
- menu->window.borderColor[i] = f;
- }
- return qtrue;
- }
- /*
- =================
- MenuParse_focuscolor
- =================
- */
- qboolean MenuParse_focuscolor( itemDef_t *item)
- {
- int i;
- float f;
- menuDef_t *menu = (menuDef_t*)item;
- for (i = 0; i < 4; i++)
- {
- if (PC_ParseFloat(&f))
- {
- return qfalse;
- }
- menu->focusColor[i] = f;
- }
- return qtrue;
- }
- /*
- =================
- MenuParse_focuscolor
- =================
- */
- qboolean MenuParse_appearanceIncrement( itemDef_t *item)
- {
- menuDef_t *menu = (menuDef_t*)item;
- if (PC_ParseFloat(&menu->appearanceIncrement))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- =================
- MenuParse_descAlignment
- =================
- */
- qboolean MenuParse_descAlignment( itemDef_t *item)
- {
- menuDef_t *menu = (menuDef_t*)item;
- const char *tempStr;
- int i;
- if (PC_ParseString(&tempStr))
- {
- return qfalse;
- }
- i=0;
- while (alignment[i])
- {
- if (Q_stricmp(tempStr,alignment[i])==0)
- {
- menu->descAlignment = i;
- break;
- }
- i++;
- }
- if (alignment[i] == NULL)
- {
- PC_ParseWarning(va("Unknown desc alignment value '%s'",tempStr));
- }
- return qtrue;
- }
- /*
- =================
- MenuParse_descTextStyle
- =================
- */
- qboolean MenuParse_descTextStyle( itemDef_t *item)
- {
- menuDef_t *menu = (menuDef_t*)item;
- if (PC_ParseInt(&menu->descTextStyle))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- =================
- MenuParse_descX
- =================
- */
- qboolean MenuParse_descX( itemDef_t *item)
- {
- menuDef_t *menu = (menuDef_t*)item;
- if (PC_ParseInt(&menu->descX))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- =================
- MenuParse_descY
- =================
- */
- qboolean MenuParse_descY( itemDef_t *item)
- {
- menuDef_t *menu = (menuDef_t*)item;
- if (PC_ParseInt(&menu->descY))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- =================
- MenuParse_descScale
- =================
- */
- qboolean MenuParse_descScale( itemDef_t *item)
- {
- menuDef_t *menu = (menuDef_t*)item;
- if (PC_ParseFloat(&menu->descScale))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- =================
- MenuParse_descColor
- =================
- */
- qboolean MenuParse_descColor( itemDef_t *item)
- {
- int i;
- float f;
- menuDef_t *menu = (menuDef_t*)item;
- for (i = 0; i < 4; i++)
- {
- if (PC_ParseFloat(&f))
- {
- return qfalse;
- }
- menu->descColor[i] = f;
- }
- return qtrue;
- }
- /*
- =================
- MenuParse_disablecolor
- =================
- */
- qboolean MenuParse_disablecolor( itemDef_t *item)
- {
- int i;
- float f;
- menuDef_t *menu = (menuDef_t*)item;
- for (i = 0; i < 4; i++)
- {
- if (PC_ParseFloat(&f))
- {
- return qfalse;
- }
- menu->disableColor[i] = f;
- }
- return qtrue;
- }
- /*
- =================
- MenuParse_outlinecolor
- =================
- */
- /*
- qboolean MenuParse_outlinecolor( itemDef_t *item)
- {
- menuDef_t *menu = (menuDef_t*)item;
- if (PC_ParseColor(&menu->window.outlineColor))
- {
- return qfalse;
- }
- return qtrue;
- }
- */
- /*
- =================
- MenuParse_background
- =================
- */
- qboolean MenuParse_background( itemDef_t *item)
- {
- const char *buff;
- menuDef_t *menu = (menuDef_t*)item;
- if (PC_ParseString(&buff))
- {
- return qfalse;
- }
- menu->window.background = ui.R_RegisterShaderNoMip(buff);
- return qtrue;
- }
- /*
- =================
- MenuParse_cinematic
- =================
- */
- /*
- qboolean MenuParse_cinematic( itemDef_t *item)
- {
- menuDef_t *menu = (menuDef_t*)item;
- if (!PC_ParseStringMem((const char **) &menu->window.cinematicName))
- {
- return qfalse;
- }
- return qtrue;
- }
- */
- /*
- =================
- MenuParse_ownerdrawFlag
- =================
- */
- qboolean MenuParse_ownerdrawFlag( itemDef_t *item)
- {
- int i;
- menuDef_t *menu = (menuDef_t*)item;
- if (PC_ParseInt(&i))
- {
- return qfalse;
- }
- menu->window.ownerDrawFlags |= i;
- return qtrue;
- }
- /*
- =================
- MenuParse_ownerdraw
- =================
- */
- qboolean MenuParse_ownerdraw( itemDef_t *item)
- {
- menuDef_t *menu = (menuDef_t*)item;
- if (PC_ParseInt(&menu->window.ownerDraw))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- =================
- MenuParse_popup
- =================
- */
- qboolean MenuParse_popup( itemDef_t *item)
- {
- menuDef_t *menu = (menuDef_t*)item;
- menu->window.flags |= WINDOW_POPUP;
- return qtrue;
- }
- /*
- =================
- MenuParse_outOfBounds
- =================
- */
- qboolean MenuParse_outOfBounds( itemDef_t *item)
- {
- menuDef_t *menu = (menuDef_t*)item;
- menu->window.flags |= WINDOW_OOB_CLICK;
- return qtrue;
- }
- /*
- =================
- MenuParse_soundLoop
- =================
- */
- qboolean MenuParse_soundLoop( itemDef_t *item)
- {
- menuDef_t *menu = (menuDef_t*)item;
- if (!PC_ParseStringMem((const char **) &menu->soundName))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ================
- MenuParse_fadeClamp
- ================
- */
- qboolean MenuParse_fadeClamp( itemDef_t *item)
- {
- menuDef_t *menu = (menuDef_t*)item;
- if (PC_ParseFloat(&menu->fadeClamp))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ================
- MenuParse_fadeAmount
- ================
- */
- qboolean MenuParse_fadeAmount( itemDef_t *item)
- {
- menuDef_t *menu = (menuDef_t*)item;
- if (PC_ParseFloat(&menu->fadeAmount))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ================
- MenuParse_fadeCycle
- ================
- */
- qboolean MenuParse_fadeCycle( itemDef_t *item)
- {
- menuDef_t *menu = (menuDef_t*)item;
- if (PC_ParseInt(&menu->fadeCycle))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ================
- MenuParse_itemDef
- ================
- */
- qboolean MenuParse_itemDef( itemDef_t *item)
- {
- menuDef_t *menu = (menuDef_t*)item;
- if (menu->itemCount < MAX_MENUITEMS)
- {
- // Hack. Check for a levelname after "itemDef" - if so, only parse it
- // if we're on that level. Avoids loading wedge all over the place.
- const char *token;
- if (PC_ParseString(&token))
- return qfalse;
- // Check for non-brace could be "protocol" or "wedge":
- if (*token != '{')
- {
- const char *mapname = Cvar_VariableString( "mapname" );
- // Wedge should only be loaded in t2_wedge:
- if( (Q_stricmp(token, "wedge") == 0) && // itemDef is wedge
- (Q_stricmp(mapname, "t2_wedge") != 0) ) // not t2_wedge
- {
- // Skip this itemDef entirely, but don't fail:
- PC_SkipBracedSection();
- return qtrue;
- }
- // C3PO should only be loaded in tier2, and academy3:
- if( (Q_stricmp(token, "protocol") == 0) && // itemDef is c3po
- (!strstr(mapname, "t2_")) && // not a t2 level
- (Q_stricmp(mapname, "academy3") != 0) ) // not academy3
- {
- // Skip this itemDef entirely, but don't fail:
- PC_SkipBracedSection();
- return qtrue;
- }
- // OK. We're on the right level. Eat the real '{':
- PC_ParseString(&token);
- if (*token != '{')
- return qfalse;
- }
- menu->items[menu->itemCount] = (struct itemDef_s *) UI_Alloc(sizeof(itemDef_t));
- Item_Init(menu->items[menu->itemCount]);
- if (!Item_Parse(menu->items[menu->itemCount]))
- {
- return qfalse;
- }
- Item_InitControls(menu->items[menu->itemCount]);
- menu->items[menu->itemCount++]->parent = menu;
- }
- else
- {
- PC_ParseWarning(va("Exceeded item/menu max of %d", MAX_MENUITEMS));
- }
- return qtrue;
- }
- #define KEYWORDHASH_SIZE 512
- typedef struct keywordHash_s
- {
- char *keyword;
- qboolean (*func)(itemDef_t *item);
- struct keywordHash_s *next;
- } keywordHash_t;
- keywordHash_t menuParseKeywords[] = {
- {"appearanceIncrement", MenuParse_appearanceIncrement},
- {"backcolor", MenuParse_backcolor, },
- {"background", MenuParse_background, },
- {"border", MenuParse_border, },
- {"bordercolor", MenuParse_bordercolor, },
- {"borderSize", MenuParse_borderSize, },
- // {"cinematic", MenuParse_cinematic, },
- {"descAlignment", MenuParse_descAlignment },
- {"descTextStyle", MenuParse_descTextStyle },
- {"desccolor", MenuParse_descColor },
- {"descX", MenuParse_descX },
- {"descY", MenuParse_descY },
- {"descScale", MenuParse_descScale },
- {"disablecolor", MenuParse_disablecolor, },
- {"fadeClamp", MenuParse_fadeClamp, },
- {"fadeCycle", MenuParse_fadeCycle, },
- {"fadeAmount", MenuParse_fadeAmount, },
- {"focuscolor", MenuParse_focuscolor, },
- {"font", MenuParse_font, },
- {"forecolor", MenuParse_forecolor, },
- {"fullscreen", MenuParse_fullscreen, },
- {"itemDef", MenuParse_itemDef, },
- {"name", MenuParse_name, },
- {"onClose", MenuParse_onClose, },
- //JLFACCEPT MPMOVED
- {"onAccept", MenuParse_onAccept, },
- {"onESC", MenuParse_onESC, },
- {"xScript", MenuParse_xScript, },
- {"yScript", MenuParse_yScript, },
- {"whiteScript", MenuParse_whiteScript, },
- {"onOpen", MenuParse_onOpen, },
- // {"outlinecolor", MenuParse_outlinecolor, },
- {"outOfBoundsClick", MenuParse_outOfBounds, },
- {"ownerdraw", MenuParse_ownerdraw, },
- {"ownerdrawFlag", MenuParse_ownerdrawFlag,},
- {"popup", MenuParse_popup, },
- {"rect", MenuParse_rect, },
- {"soundLoop", MenuParse_soundLoop, },
- {"style", MenuParse_style, },
- {"visible", MenuParse_visible, },
- {"ignoreescape", MenuParse_ignoreescape, },
- {NULL, NULL, }
- };
- keywordHash_t *menuParseKeywordHash[KEYWORDHASH_SIZE];
- /*
- ================
- KeywordHash_Key
- ================
- */
- int KeywordHash_Key(const char *keyword)
- {
- int register hash, i;
- hash = 0;
- for (i = 0; keyword[i] != '\0'; i++) {
- if (keyword[i] >= 'A' && keyword[i] <= 'Z')
- hash += (keyword[i] + ('a' - 'A')) * (119 + i);
- else
- hash += keyword[i] * (119 + i);
- }
- hash = (hash ^ (hash >> 10) ^ (hash >> 20)) & (KEYWORDHASH_SIZE-1);
- return hash;
- }
- /*
- ================
- KeywordHash_Add
- ================
- */
- void KeywordHash_Add(keywordHash_t *table[], keywordHash_t *key)
- {
- int hash;
- hash = KeywordHash_Key(key->keyword);
- key->next = table[hash];
- table[hash] = key;
- }
- /*
- ===============
- KeywordHash_Find
- ===============
- */
- keywordHash_t *KeywordHash_Find(keywordHash_t *table[], const char *keyword)
- {
- keywordHash_t *key;
- int hash;
- hash = KeywordHash_Key(keyword);
- for (key = table[hash]; key; key = key->next)
- {
- if (!Q_stricmp(key->keyword, keyword))
- return key;
- }
- return NULL;
- }
- /*
- ================
- hashForString
- return a hash value for the string
- ================
- */
- static long hashForString(const char *str)
- {
- int i;
- long hash;
- char letter;
- hash = 0;
- i = 0;
- while (str[i] != '\0')
- {
- letter = tolower((unsigned char)str[i]);
- hash+=(long)(letter)*(i+119);
- i++;
- }
- hash &= (HASH_TABLE_SIZE-1);
- return hash;
- }
- /*
- =================
- String_Alloc
- =================
- */
- const char *String_Alloc(const char *p)
- {
- int len;
- long hash;
- stringDef_t *str, *last;
- static const char *staticNULL = "";
- if (p == NULL)
- {
- return NULL;
- }
- if (*p == 0)
- {
- return staticNULL;
- }
- hash = hashForString(p);
- str = strHandle[hash];
- while (str)
- {
- if (strcmp(p, str->str) == 0)
- {
- return str->str;
- }
- str = str->next;
- }
- len = strlen(p);
- if (len + strPoolIndex + 1 < STRING_POOL_SIZE)
- {
- int ph = strPoolIndex;
- strcpy(&strPool[strPoolIndex], p);
- strPoolIndex += len + 1;
- str = strHandle[hash];
- last = str;
- while (last && last->next)
- {
- last = last->next;
- }
- str = (stringDef_s *) UI_Alloc( sizeof(stringDef_t));
- str->next = NULL;
- str->str = &strPool[ph];
- if (last)
- {
- last->next = str;
- }
- else
- {
- strHandle[hash] = str;
- }
- return &strPool[ph];
- }
- else
- {
- Com_Printf("WARNING: Ran out of strPool space\n");
- }
-
- return NULL;
- }
- /*
- =================
- String_Report
- =================
- */
- void String_Report(void)
- {
- float f;
- Com_Printf("Memory/String Pool Info\n");
- Com_Printf("----------------\n");
- f = strPoolIndex;
- f /= STRING_POOL_SIZE;
- f *= 100;
- Com_Printf("String Pool is %.1f%% full, %i bytes out of %i used.\n", f, strPoolIndex, STRING_POOL_SIZE);
- #ifdef _XBOX
- Com_Printf("Memory Pool is using %i bytes.\n", allocPoint);
- #else
- f = allocPoint;
- f /= MEM_POOL_SIZE;
- f *= 100;
- Com_Printf("Memory Pool is %.1f%% full, %i bytes out of %i used.\n", f, allocPoint, MEM_POOL_SIZE);
- #endif
- }
- /*
- =================
- String_Init
- =================
- */
- void String_Init(void)
- {
- int i;
- for (i = 0; i < HASH_TABLE_SIZE; i++)
- {
- strHandle[i] = 0;
- }
- strHandleCount = 0;
- strPoolIndex = 0;
- UI_InitMemory();
- Item_SetupKeywordHash();
- Menu_SetupKeywordHash();
- if (DC && DC->getBindingBuf)
- {
- Controls_GetConfig();
- }
- }
- //---------------------------------------------------------------------------------------------------------
- // Memory
- //---------------------------------------------------------------------------------------------------------
- /*
- ===============
- UI_Alloc
- ===============
- */
- void *UI_Alloc( int size )
- {
- #ifdef _XBOX
- allocPoint += size;
- return Z_Malloc(size, TAG_UI_ALLOC, qfalse, 4);
- #else
- char *p;
- if ( allocPoint + size > MEM_POOL_SIZE )
- {
- outOfMemory = qtrue;
- if (DC->Print)
- {
- DC->Print("UI_Alloc: Failure. Out of memory!\n");
- }
- return NULL;
- }
- p = &memoryPool[allocPoint];
- allocPoint += ( size + 15 ) & ~15;
- return p;
- #endif
- }
- /*
- ===============
- UI_InitMemory
- ===============
- */
- void UI_InitMemory( void )
- {
- allocPoint = 0;
- outOfMemory = qfalse;
- #ifdef _XBOX
- Z_TagFree(TAG_UI_ALLOC);
- #endif
- }
- /*
- ===============
- Menu_ItemsMatchingGroup
- ===============
- */
- int Menu_ItemsMatchingGroup(menuDef_t *menu, const char *name)
- {
- int i;
- int count = 0;
- for (i = 0; i < menu->itemCount; i++)
- {
- if ((!menu->items[i]->window.name) && (!menu->items[i]->window.group))
- {
- Com_Printf(S_COLOR_YELLOW"WARNING: item has neither name or group\n");
- continue;
- }
- if (Q_stricmp(menu->items[i]->window.name, name) == 0 || (menu->items[i]->window.group && Q_stricmp(menu->items[i]->window.group, name) == 0))
- {
- count++;
- }
- }
- return count;
- }
- /*
- ===============
- Menu_GetMatchingItemByNumber
- ===============
- */
- itemDef_t *Menu_GetMatchingItemByNumber(menuDef_t *menu, int index, const char *name)
- {
- int i;
- int count = 0;
- for (i = 0; i < menu->itemCount; i++)
- {
- if (Q_stricmp(menu->items[i]->window.name, name) == 0 || (menu->items[i]->window.group && Q_stricmp(menu->items[i]->window.group, name) == 0))
- {
- if (count == index)
- {
- return menu->items[i];
- }
- count++;
- }
- }
- return NULL;
- }
- /*
- ===============
- Menu_FadeItemByName
- ===============
- */
- void Menu_FadeItemByName(menuDef_t *menu, const char *p, qboolean fadeOut)
- {
- itemDef_t *item;
- int i;
- int count = Menu_ItemsMatchingGroup(menu, p);
- for (i = 0; i < count; i++)
- {
- item = Menu_GetMatchingItemByNumber(menu, i, p);
- if (item != NULL)
- {
- if (fadeOut)
- {
- item->window.flags |= (WINDOW_FADINGOUT | WINDOW_VISIBLE);
- item->window.flags &= ~WINDOW_FADINGIN;
- }
- else
- {
- item->window.flags |= (WINDOW_VISIBLE | WINDOW_FADINGIN);
- item->window.flags &= ~WINDOW_FADINGOUT;
- }
- }
- }
- }
- /*
- ==========
- Menu_SetItemDecorationByName
- ==========
- */
- void Menu_SetItemDecorationByName(menuDef_t* menu, const char *p, qboolean bShow)
- {
- itemDef_t *item;
- int i;
- int count;
- count = Menu_ItemsMatchingGroup(menu, p);
- if (!count)
- {
- Com_Printf(S_COLOR_YELLOW"WARNING: Menu_SetItemDecorationByName - unable to locate any items named :%s\n",p);
- }
- for (i = 0; i < count; i++)
- {
- item = Menu_GetMatchingItemByNumber(menu, i, p);
- if (item != NULL)
- {
- if (bShow)
- {
- item->window.flags |= WINDOW_DECORATION;
- }
- else
- {
- item->window.flags &= ~WINDOW_DECORATION;
- }
- }
- }
- }
- /*
- ===============
- Menu_ShowItemByName
- ===============
- */
- void Menu_ShowItemByName(menuDef_t *menu, const char *p, qboolean bShow)
- {
- itemDef_t *item;
- int i;
- int count;
- count = Menu_ItemsMatchingGroup(menu, p);
- if (!count)
- {
- Com_Printf(S_COLOR_YELLOW"WARNING: Menu_ShowItemByName - unable to locate any items named :%s\n",p);
- }
- for (i = 0; i < count; i++)
- {
- item = Menu_GetMatchingItemByNumber(menu, i, p);
- if (item != NULL)
- {
- if (bShow)
- {
- item->window.flags |= WINDOW_VISIBLE;
- }
- else
- {
- item->window.flags &= ~(WINDOW_VISIBLE | WINDOW_HASFOCUS);
- // stop cinematics playing in the window
- /*
- if (item->window.cinematic >= 0)
- {
- DC->stopCinematic(item->window.cinematic);
- item->window.cinematic = -1;
- }
- */
- }
- }
- }
- }
- /*
- ===============
- Menu_GetFocused
- ===============
- */
- menuDef_t *Menu_GetFocused(void)
- {
- int i;
- for (i = 0; i < menuCount; i++)
- {
- if ((Menus[i].window.flags & WINDOW_HASFOCUS) && (Menus[i].window.flags & WINDOW_VISIBLE))
- {
- return &Menus[i];
- }
- }
- return NULL;
- }
- /*
- ===============
- Menus_OpenByName
- ===============
- */
- void Menus_OpenByName(const char *p)
- {
- Menus_ActivateByName(p);
- }
- /*
- ===============
- Menus_FindByName
- ===============
- */
- menuDef_t *Menus_FindByName(const char *p)
- {
- int i;
- for (i = 0; i < menuCount; i++)
- {
- if (Q_stricmp(Menus[i].window.name, p) == 0)
- {
- return &Menus[i];
- }
- }
- return NULL;
- }
- /*
- ===============
- Menu_RunCloseScript
- ===============
- */
- static void Menu_RunCloseScript(menuDef_t *menu)
- {
- if (menu && menu->window.flags & WINDOW_VISIBLE && menu->onClose)
- {
- itemDef_t item;
- item.parent = menu;
- Item_RunScript(&item, menu->onClose);
- }
- }
- /*
- ===============
- Item_ActivateByName
- ===============
- */
- void Item_ActivateByName(const char *menuName,const char *itemName)
- {
- itemDef_t *item;
- menuDef_t *menu;
-
- menu = Menus_FindByName(menuName);
- item = (itemDef_s *) Menu_FindItemByName((menuDef_t *) menu, itemName);
- if (item != NULL)
- {
- item->window.flags &= ~WINDOW_INACTIVE;
- }
- }
- /*
- ===============
- Menus_CloseByName
- ===============
- */
- void Menus_CloseByName(const char *p)
- {
- menuDef_t *menu = Menus_FindByName(p);
-
- // If the menu wasnt found just exit
- if (menu == NULL)
- {
- return;
- }
- // Run the close script for the menu
- Menu_RunCloseScript(menu);
- // If this window had the focus then take it away
- if ( menu->window.flags & WINDOW_HASFOCUS )
- {
- // If there is something still in the open menu list then
- // set it to have focus now
- if ( openMenuCount )
- {
- // Subtract one from the open menu count to prepare to
- // remove the top menu from the list
- openMenuCount -= 1;
- // Set the top menu to have focus now
- menuStack[openMenuCount]->window.flags |= WINDOW_HASFOCUS;
- // Remove the top menu from the list
- menuStack[openMenuCount] = NULL;
- }
- }
- // Window is now invisible and doenst have focus
- menu->window.flags &= ~(WINDOW_VISIBLE | WINDOW_HASFOCUS);
- }
- /*
- ===============
- Menu_FindItemByName
- ===============
- */
- itemDef_t *Menu_FindItemByName(menuDef_t *menu, const char *p)
- {
- int i;
- if (menu == NULL || p == NULL)
- {
- return NULL;
- }
- for (i = 0; i < menu->itemCount; i++)
- {
- if (Q_stricmp(p, menu->items[i]->window.name) == 0)
- {
- return menu->items[i];
- }
- }
- return NULL;
- }
- /*
- ===============
- Menu_FindVisibleItemByName
- ===============
- */
- itemDef_t *Menu_FindVisibleItemByName(menuDef_t *menu, const char *p)
- {
- int i;
- if (menu == NULL || p == NULL)
- {
- return NULL;
- }
- for (i = 0; i < menu->itemCount; i++)
- {
- if (Q_stricmp(p, menu->items[i]->window.name) == 0)
- {
- if (menu->items[i]->cvarFlags & (CVAR_ENABLE | CVAR_DISABLE) && !Item_EnableShowViaCvar(menu->items[i], CVAR_ENABLE))
- {
- continue;
- }
- if (menu->items[i]->cvarFlags & (CVAR_SHOW | CVAR_HIDE) && !Item_EnableShowViaCvar(menu->items[i], CVAR_SHOW))
- {
- continue;
- }
- if ( !(menu->items[i]->window.flags & WINDOW_VISIBLE) )
- {
- continue;
- }
- return menu->items[i];
- }
- }
- return NULL;
- }
- /*
- =================
- Menu_ClearFocus
- =================
- */
- itemDef_t *Menu_ClearFocus(menuDef_t *menu)
- {
- int i;
- itemDef_t *ret = NULL;
- if (menu == NULL)
- {
- return NULL;
- }
- for (i = 0; i < menu->itemCount; i++)
- {
- if (menu->items[i]->window.flags & WINDOW_HASFOCUS)
- {
- ret = menu->items[i];
- menu->items[i]->window.flags &= ~WINDOW_HASFOCUS;
- if (menu->items[i]->leaveFocus)
- {
- Item_RunScript(menu->items[i], menu->items[i]->leaveFocus);
- }
- }
- }
- return ret;
- }
- // Set all the items within a given menu, with the given itemName, to the given shader
- void Menu_SetItemBackground(const menuDef_t *menu,const char *itemName, const char *background)
- {
- itemDef_t *item;
- int j, count;
- if (!menu) // No menu???
- {
- return;
- }
- count = Menu_ItemsMatchingGroup( (menuDef_t *) menu, itemName);
- for (j = 0; j < count; j++)
- {
- item = Menu_GetMatchingItemByNumber( (menuDef_t *) menu, j, itemName);
- if (item != NULL)
- {
- // item->window.background = DC->registerShaderNoMip(background);
- item->window.background = ui.R_RegisterShaderNoMip(background);
- }
- }
- }
- // Set all the items within a given menu, with the given itemName, to the given text
- void Menu_SetItemText(const menuDef_t *menu,const char *itemName, const char *text)
- {
- itemDef_t *item;
- int j, count;
- if (!menu) // No menu???
- {
- return;
- }
- count = Menu_ItemsMatchingGroup( (menuDef_t *) menu, itemName);
- for (j = 0; j < count; j++)
- {
- item = Menu_GetMatchingItemByNumber( (menuDef_t *) menu, j, itemName);
- if (item != NULL)
- {
- if (text[0] == '*')
- {
- item->cvar = text+1;
- // Just copying what was in ItemParse_cvar()
- if ( item->typeData)
- {
- editFieldDef_t *editPtr;
- editPtr = (editFieldDef_t*)item->typeData;
- editPtr->minVal = -1;
- editPtr->maxVal = -1;
- editPtr->defVal = -1;
- }
- }
- else
- {
- if (item->type == ITEM_TYPE_TEXTSCROLL )
- {
- char cvartext[1024];
- textScrollDef_t *scrollPtr = (textScrollDef_t*)item->typeData;
- if ( scrollPtr )
- {
- scrollPtr->startPos = 0;
- scrollPtr->endPos = 0;
- }
- if (item->cvar)
- {
- DC->getCVarString(item->cvar, cvartext, sizeof(cvartext));
- item->text = cvartext;
- }
- else
- {
- item->text = (char *) text;
- }
- Item_TextScroll_BuildLines ( item );
- }
- else
- {
- item->text = (char *) text;
- }
- }
- }
- }
- }
- /*
- =================
- Menu_TransitionItemByName
- =================
- */
- void Menu_TransitionItemByName(menuDef_t *menu, const char *p, const rectDef_t *rectFrom, const rectDef_t *rectTo, int time, float amt)
- {
- itemDef_t *item;
- int i;
- int count = Menu_ItemsMatchingGroup(menu, p);
- for (i = 0; i < count; i++)
- {
- item = Menu_GetMatchingItemByNumber(menu, i, p);
- if (item != NULL)
- {
- if (!rectFrom)
- {
- rectFrom = &item->window.rect; //if there are more than one of these with the same name, they'll all use the FIRST one's FROM.
- }
- item->window.flags |= (WINDOW_INTRANSITION | WINDOW_VISIBLE);
- item->window.offsetTime = time;
- memcpy(&item->window.rectClient, rectFrom, sizeof(rectDef_t));
- memcpy(&item->window.rectEffects, rectTo, sizeof(rectDef_t));
- item->window.rectEffects2.x = abs(rectTo->x - rectFrom->x) / amt;
- item->window.rectEffects2.y = abs(rectTo->y - rectFrom->y) / amt;
- item->window.rectEffects2.w = abs(rectTo->w - rectFrom->w) / amt;
- item->window.rectEffects2.h = abs(rectTo->h - rectFrom->h) / amt;
- Item_UpdatePosition(item);
- }
- }
- }
- /*
- =================
- Menu_TransitionItemByName
- =================
- */
- //JLF MOVED
- #define _TRANS3
- #ifdef _TRANS3
- void Menu_Transition3ItemByName(menuDef_t *menu, const char *p, const float minx, const float miny, const float minz,
- const float maxx, const float maxy, const float maxz, const float fovtx, const float fovty,
- const int time, const float amt)
- {
- itemDef_t *item;
- int i;
- int count = Menu_ItemsMatchingGroup(menu, p);
- modelDef_t * modelptr;
- for (i = 0; i < count; i++)
- {
- item = Menu_GetMatchingItemByNumber(menu, i, p);
- if (item != NULL)
- {
- if ( item->type == ITEM_TYPE_MODEL)
- {
- modelptr = (modelDef_t*)item->typeData;
- item->window.flags |= (WINDOW_INTRANSITIONMODEL | WINDOW_VISIBLE);
- item->window.offsetTime = time;
- modelptr->fov_x2 = fovtx;
- modelptr->fov_y2 = fovty;
- VectorSet(modelptr->g2maxs2, maxx, maxy, maxz);
- VectorSet(modelptr->g2mins2, minx, miny, minz);
- // //modelptr->g2maxs2.x= maxx;
- // modelptr->g2maxs2.y= maxy;
- // modelptr->g2maxs2.z= maxz;
- // modelptr->g2mins2.x= minx;
- // modelptr->g2mins2.y= miny;
- // modelptr->g2mins2.z= minz;
- // VectorSet(modelptr->g2maxs2, maxx, maxy, maxz);
- modelptr->g2maxsEffect[0] = abs(modelptr->g2maxs2[0] - modelptr->g2maxs[0]) / amt;
- modelptr->g2maxsEffect[1] = abs(modelptr->g2maxs2[1] - modelptr->g2maxs[1]) / amt;
- modelptr->g2maxsEffect[2] = abs(modelptr->g2maxs2[2] - modelptr->g2maxs[2]) / amt;
- modelptr->g2minsEffect[0] = abs(modelptr->g2mins2[0] - modelptr->g2mins[0]) / amt;
- modelptr->g2minsEffect[1] = abs(modelptr->g2mins2[1] - modelptr->g2mins[1]) / amt;
- modelptr->g2minsEffect[2] = abs(modelptr->g2mins2[2] - modelptr->g2mins[2]) / amt;
-
- modelptr->fov_Effectx = abs(modelptr->fov_x2 - modelptr->fov_x) / amt;
- modelptr->fov_Effecty = abs(modelptr->fov_y2 - modelptr->fov_y) / amt;
- }
-
- }
- }
- }
- #endif
- /*
- =================
- Menu_OrbitItemByName
- =================
- */
- void Menu_OrbitItemByName(menuDef_t *menu, const char *p, float x, float y, float cx, float cy, int time)
- {
- itemDef_t *item;
- int i;
- int count = Menu_ItemsMatchingGroup(menu, p);
- for (i = 0; i < count; i++)
- {
- item = Menu_GetMatchingItemByNumber(menu, i, p);
- if (item != NULL)
- {
- item->window.flags |= (WINDOW_ORBITING | WINDOW_VISIBLE);
- item->window.offsetTime = time;
- item->window.rectEffects.x = cx;
- item->window.rectEffects.y = cy;
- item->window.rectClient.x = x;
- item->window.rectClient.y = y;
- Item_UpdatePosition(item);
- }
- }
- }
- /*
- =================
- Rect_Parse
- =================
- */
- qboolean Rect_Parse(const char **p, rectDef_t *r)
- {
- if (!COM_ParseFloat(p, &r->x))
- {
- if (!COM_ParseFloat(p, &r->y))
- {
- if (!COM_ParseFloat(p, &r->w))
- {
- if (!COM_ParseFloat(p, &r->h))
- {
- return qtrue;
- }
- }
- }
- }
- return qfalse;
- }
- qboolean Script_SetItemRect(itemDef_t *item, const char **args)
- {
- const char *itemname;
- rectDef_t *out;
- rectDef_t rect;
- // expecting type of color to set and 4 args for the color
- if (String_Parse(args, &itemname))
- {
- itemDef_t *item2;
- int j;
- int count = Menu_ItemsMatchingGroup((menuDef_t *) item->parent, itemname);
- if (!Rect_Parse(args, &rect))
- {
- return qtrue;
- }
- for (j = 0; j < count; j++)
- {
- item2 = Menu_GetMatchingItemByNumber((menuDef_t *) item->parent, j, itemname);
- if (item2 != NULL)
- {
- out = &item2->window.rect;
- if (out)
- {
- item2->window.rect.x = rect.x;
- item2->window.rect.y = rect.y;
- item2->window.rect.w = rect.w;
- item2->window.rect.h = rect.h;
- }
- }
- }
- }
- return qtrue;
- }
- /*
- =================
- Script_SetItemBackground
- =================
- */
- qboolean Script_SetItemBackground(itemDef_t *item, const char **args)
- {
- const char *itemName;
- const char *name;
- // expecting name of shader
- if (String_Parse(args, &itemName) && String_Parse(args, &name))
- {
- Menu_SetItemBackground((menuDef_t *) item->parent, itemName, name);
- }
- return qtrue;
- }
- /*
- =================
- Script_SetItemText
- =================
- */
- qboolean Script_SetItemText(itemDef_t *item, const char **args)
- {
- const char *itemName;
- const char *text;
- // expecting text
- if (String_Parse(args, &itemName) && String_Parse(args, &text))
- {
- Menu_SetItemText((menuDef_t *) item->parent, itemName, text);
- }
- return qtrue;
- }
- /*
- =================
- Script_FadeIn
- =================
- */
- qboolean Script_FadeIn(itemDef_t *item, const char **args)
- {
- const char *name;
- if (String_Parse(args, &name))
- {
- Menu_FadeItemByName((menuDef_t *) item->parent, name, qfalse);
- }
- return qtrue;
- }
- /*
- =================
- Script_FadeOut
- =================
- */
- qboolean Script_FadeOut(itemDef_t *item, const char **args)
- {
- const char *name;
- if (String_Parse(args, &name))
- {
- Menu_FadeItemByName((menuDef_t *) item->parent, name, qtrue);
- }
- return qtrue;
- }
- /*
- =================
- Script_Show
- =================
- */
- qboolean Script_Show(itemDef_t *item, const char **args)
- {
- const char *name;
- if (String_Parse(args, &name))
- {
- Menu_ShowItemByName((menuDef_t *) item->parent, name, qtrue);
- }
- return qtrue;
- }
- /*
- ==========
- Script_SetDecoration
- ==========
- */
- qboolean Script_SetDecoration(itemDef_t* item, const char **args)
- {
- const char *name;
- int val;
- if (String_Parse(args, &name))
- {
- if(!strcmp("vstr", name))
- {
- if(String_Parse(args, &name))
- {
- if(Int_Parse( args, &val))
- {
- Menu_SetItemDecorationByName((menuDef_t*) item->parent, Cvar_VariableString(name), val );
- return qtrue;
- }
- }
- }
- else
- {
- if(Int_Parse( args, &val))
- {
- Menu_SetItemDecorationByName((menuDef_t*) item->parent, name, val );
- return qtrue;
- }
- }
- }
- return qfalse;
- }
- /*
- =================
- Script_ShowMenu
- =================
- */
- qboolean Script_ShowMenu(itemDef_t *item, const char **args)
- {
- const char *name;
- if (String_Parse(args, &name))
- {
- Menus_ShowItems(name);
- }
- return qtrue;
- }
- /*
- =================
- Script_Hide
- =================
- */
- qboolean Script_Hide(itemDef_t *item, const char **args)
- {
- const char *name;
- if (String_Parse(args, &name))
- {
- Menu_ShowItemByName((menuDef_t *) item->parent, name, qfalse);
- }
- return qtrue;
- }
- /*
- =================
- Script_SetColor
- =================
- */
- qboolean Script_SetColor(itemDef_t *item, const char **args)
- {
- const char *name;
- int i;
- float f;
- vec4_t *out;
- // expecting type of color to set and 4 args for the color
- if (String_Parse(args, &name))
- {
- out = NULL;
- if (Q_stricmp(name, "backcolor") == 0)
- {
- out = &item->window.backColor;
- item->window.flags |= WINDOW_BACKCOLORSET;
- }
- else if (Q_stricmp(name, "forecolor") == 0)
- {
- out = &item->window.foreColor;
- item->window.flags |= WINDOW_FORECOLORSET;
- }
- else if (Q_stricmp(name, "bordercolor") == 0)
- {
- out = &item->window.borderColor;
- }
- if (out)
- {
- for (i = 0; i < 4; i++)
- {
- // if (!Float_Parse(args, &f))
- if (COM_ParseFloat( args, &f))
- {
- return qtrue;
- }
- (*out)[i] = f;
- }
- }
- }
- return qtrue;
- }
- /*
- =================
- Script_Open
- =================
- */
- qboolean Script_Open(itemDef_t *item, const char **args)
- {
- const char *name;
- if (String_Parse(args, &name))
- {
- if(!strcmp("vstr",name))
- {
- if(String_Parse(args,&name))
- {
- Menus_OpenByName(Cvar_VariableString(name));
- }
- }
- else
- {
- Menus_OpenByName(name);
- }
- }
- return qtrue;
- }
- qboolean Script_OpenGoToMenu(itemDef_t *item, const char **args)
- {
- Menus_OpenByName(GoToMenu); // Give warning
- return qtrue;
- }
- /*
- =================
- Script_Close
- =================
- */
- qboolean Script_Close(itemDef_t *item, const char **args)
- {
- const char *name;
- if (String_Parse(args, &name))
- {
- if (Q_stricmp(name, "all") == 0)
- {
- Menus_CloseAll();
- }
- else
- {
- Menus_CloseByName(name);
- }
- }
- return qtrue;
- }
- /*
- =================
- Script_Activate
- =================
- */
- qboolean Script_Activate(itemDef_t *item, const char **args)
- {
- const char *name, *menu;
- if (String_Parse(args, &menu))
- {
- if (String_Parse(args, &name))
- {
- Item_ActivateByName(menu,name);
- }
- }
- return qtrue;
- }
- /*
- =================
- Script_SetBackground
- =================
- */
- qboolean Script_SetBackground(itemDef_t *item, const char **args)
- {
- const char *name;
- // expecting name to set asset to
- if (String_Parse(args, &name))
- {
- item->window.background = DC->registerShaderNoMip(name);
- }
- return qtrue;
- }
- /*
- =================
- Script_SetAsset
- =================
- */
- qboolean Script_SetAsset(itemDef_t *item, const char **args)
- {
- const char *name;
- // expecting name to set asset to
- if (String_Parse(args, &name))
- {
- // check for a model
- if (item->type == ITEM_TYPE_MODEL)
- {
- }
- }
- return qtrue;
- }
- /*
- =================
- Script_SetFocus
- =================
- */
- qboolean Script_SetFocus(itemDef_t *item, const char **args)
- {
- const char *name;
- itemDef_t *focusItem;
- if (String_Parse(args, &name))
- {
- if(!strcmp("vstr", name))
- {
- if(String_Parse(args, &name))
- {
- #ifdef _XBOX
- focusItem = (itemDef_s *) Menu_FindVisibleItemByName((menuDef_t *) item->parent, Cvar_VariableString(name));
- #else
- focusItem = (itemDef_s *) Menu_FindItemByName((menuDef_t *) item->parent, Cvar_VariableString(name));
- #endif
- }
- else
- {
- return qfalse;
- }
- }
- else
- {
- #ifdef _XBOX
- focusItem = (itemDef_s *) Menu_FindVisibleItemByName((menuDef_t *) item->parent, name);
- #else
- focusItem = (itemDef_s *) Menu_FindItemByName((menuDef_t *) item->parent, name);
- #endif
- }
- if (focusItem && !(focusItem->window.flags & WINDOW_DECORATION) && !(focusItem->window.flags & WINDOW_HASFOCUS))
- {
- Menu_ClearFocus((menuDef_t *) item->parent);
- //JLF
- #ifdef _XBOX
- Item_SetFocus(focusItem, 0,0);
- #else
- focusItem->window.flags |= WINDOW_HASFOCUS;
- #endif
- //END JLF
- if (focusItem->onFocus)
- {
- Item_RunScript(focusItem, focusItem->onFocus);
- }
- if (DC->Assets.itemFocusSound)
- {
- DC->startLocalSound( DC->Assets.itemFocusSound, CHAN_LOCAL_SOUND );
- }
- #ifdef _IMMERSION
- if (DC->Assets.itemFocusForce)
- {
- DC->startForce( DC->Assets.itemFocusForce );
- }
- #endif // _IMMERSION
- }
- }
- return qtrue;
- }
- /*
- =================
- Script_SetItemFlag
- =================
- */
- qboolean Script_SetItemFlag(itemDef_t *item, const char **args)
- {
- const char *itemName,*number;
-
- if (String_Parse(args, &itemName))
- {
- item = (itemDef_s *) Menu_FindItemByName((menuDef_t *) item->parent, itemName);
- if (String_Parse(args, &number))
- {
- int amount = atoi(number);
- item->window.flags |= amount;
- }
- }
- return qtrue;
- }
- void UI_SetItemVisible(menuDef_t *menu,const char *itemname,qboolean visible)
- {
- itemDef_t *item;
- int j;
- int count = Menu_ItemsMatchingGroup(menu, itemname);
- for (j = 0; j < count; j++)
- {
- item = Menu_GetMatchingItemByNumber(menu, j, itemname);
- if (item != NULL)
- {
- if (visible==qtrue)
- {
- item->window.flags |= WINDOW_VISIBLE;
- }
- else
- {
- item->window.flags &= ~WINDOW_VISIBLE;
- }
- }
- }
- }
- void UI_SetItemColor(itemDef_t *item,const char *itemname,const char *name,vec4_t color)
- {
- itemDef_t *item2;
- int i,j;
- vec4_t *out;
- int count = Menu_ItemsMatchingGroup((menuDef_t *) item->parent, itemname);
- for (j = 0; j < count; j++)
- {
- item2 = Menu_GetMatchingItemByNumber((menuDef_t *) item->parent, j, itemname);
- if (item2 != NULL)
- {
- out = NULL;
- if (Q_stricmp(name, "backcolor") == 0)
- {
- out = &item2->window.backColor;
- }
- else if (Q_stricmp(name, "forecolor") == 0)
- {
- out = &item2->window.foreColor;
- item2->window.flags |= WINDOW_FORECOLORSET;
- }
- else if (Q_stricmp(name, "bordercolor") == 0)
- {
- out = &item2->window.borderColor;
- }
- if (out)
- {
- for (i = 0; i < 4; i++)
- {
- (*out)[i] = color[i];
- }
- }
- }
- }
- }
- /*
- =================
- Script_SetItemColor
- =================
- */
- qboolean Script_SetItemColor(itemDef_t *item, const char **args)
- {
- const char *itemname;
- const char *name;
- vec4_t color;
- // expecting type of color to set and 4 args for the color
- if (String_Parse(args, &itemname) && String_Parse(args, &name))
- {
- if (COM_ParseVec4(args, &color))
- {
- return qtrue;
- }
- UI_SetItemColor(item,itemname,name,color);
- }
- return qtrue;
- }
- /*
- =================
- Script_SetFocusColor
- =================
- */
- qboolean Script_SetFocusColor(itemDef_t *item, const char **args)
- {
- menuDef_t *menu = (menuDef_t *) item->parent;
- // expecting type of color to set and 4 args for the color
- if (COM_ParseVec4(args, &menu->focusColor))
- {
- return qtrue;
- }
- return qtrue;
- }
- /*
- =================
- Script_CvarIfEqual
- Egads. OK. Script command should be:
- cvarIfEqual <cvarname> <value> <cvarTrueScript> <cvarFalseScript>
- If the contents of cvarname are equal to value, then the script in
- cvarTrueScript will be executed, otherwise the script in cvarFalseScript
- =================
- */
- qboolean Script_CvarIfEqual ( itemDef_t* item, const char **args )
- {
- const char *cvarName;
- const char *testVal;
- const char *cvarTrueScript;
- const char *cvarFalseScript;
- if (!String_Parse(args, &cvarName) || !String_Parse(args, &testVal) ||
- !String_Parse(args, &cvarTrueScript) || !String_Parse(args, &cvarFalseScript))
- {
- Com_Printf("Error parsing cvarIfEqual\n");
- return qfalse;
- }
- bool testResult = (Q_stricmp(Cvar_VariableString(cvarName), testVal) == 0);
- if( testResult )
- Item_RunScript( item, Cvar_VariableString( cvarTrueScript ) );
- else
- Item_RunScript( item, Cvar_VariableString( cvarFalseScript ) );
- return qtrue;
- }
- /*
- =================
- Script_Defer
- Defers the rest of the script based on the defer condition. The deferred
- portion of the script can later be run with the "rundeferred"
- =================
- */
- qboolean Script_Defer ( itemDef_t* item, const char **args )
- {
- // Should the script be deferred?
- if ( DC->deferScript ( args ) )
- {
- // Need the item the script was being run on
- uiInfo.deferredScriptItem = item;
- // Save the rest of the script
- Q_strncpyz ( uiInfo.deferredScript, *args, MAX_DEFERRED_SCRIPT, qfalse );
- // No more running
- return qfalse;
- }
- // Keep running the script, its ok
- return qtrue;
- }
- /*
- =================
- Script_RunDeferred
- Runs the last deferred script, there can only be one script deferred at a
- time so be careful of recursion
- =================
- */
- qboolean Script_RunDeferred ( itemDef_t* item, const char **args )
- {
- // Make sure there is something to run.
- if ( !uiInfo.deferredScript[0] || !uiInfo.deferredScriptItem )
- {
- return qtrue;
- }
- // Run the deferred script now
- Item_RunScript ( uiInfo.deferredScriptItem, uiInfo.deferredScript );
- uiInfo.deferredScriptItem = NULL;
- uiInfo.deferredScript[0] = 0;
- return qtrue;
- }
- /*
- =================
- Script_Delay
- Delays the rest of the script for the specified amount of time
- =================
- */
- qboolean Script_Delay ( itemDef_t* item, const char **args )
- {
- int time;
- if (Int_Parse(args, &time))
- {
- // item->window.flags |= WINDOW_SCRIPTWAITING;
- // item->window.delayTime = DC->realTime + time; // Flag to set delay time on next paint
- // item->window.delayedScript = (char *)*args; // Copy current location, we'll resume executing here later
- ((menuDef_t*)(item->parent))->window.flags |= WINDOW_SCRIPTWAITING;
- ((menuDef_t*)(item->parent))->window.delayTime = DC->realTime + time; // Flag to set delay time on next paint
- ((menuDef_t*)(item->parent))->window.delayedScript = (char *)*args; // Copy current location, we'll resume executing here later
- }
- else
- {
- Com_Printf(S_COLOR_YELLOW"WARNING: Script_Delay: error parsing\n" );
- }
- // Stop running
- return qfalse;
- }
- /*
- =================
- Script_Transition
- transition rtvscr 321 0 202 264 415 0 202 264 20 25
- =================
- */
- qboolean Script_Transition(itemDef_t *item, const char **args)
- {
- const char *name;
- rectDef_t rectFrom, rectTo;
- int time;
- float amt;
- if (String_Parse(args, &name))
- {
- if ( ParseRect(args, &rectFrom) && ParseRect(args, &rectTo) && Int_Parse(args, &time) && !COM_ParseFloat(args, &amt))
- {
- Menu_TransitionItemByName((menuDef_t *) item->parent, name, &rectFrom, &rectTo, time, amt);
- }
- else
- {
- Com_Printf(S_COLOR_YELLOW"WARNING: Script_Transition: error parsing '%s'\n", name );
- }
- }
- return qtrue;
- }
- /*
- =================
- Script_Transition2
- uses current origin instead of specifing a starting origin
- transition2 lfvscr 25 0 202 264 20 25
- =================
- */
- qboolean Script_Transition2(itemDef_t *item, const char **args)
- {
- const char *name;
- rectDef_t rectTo;
- int time;
- float amt;
- if (String_Parse(args, &name))
- {
- if ( ParseRect(args, &rectTo) && Int_Parse(args, &time) && !COM_ParseFloat(args, &amt))
- {
- Menu_TransitionItemByName((menuDef_t *) item->parent, name, 0, &rectTo, time, amt);
- }
- else
- {
- Com_Printf(S_COLOR_YELLOW"WARNING: Script_Transition2: error parsing '%s'\n", name );
- }
- }
- return qtrue;
- }
- #ifdef _TRANS3
- /*
- JLF MPMOVED
- =================
- Script_Transition3
- used exclusively with model views
- uses current origin instead of specifing a starting origin
- transition3 lfvscr (min extent) (max extent) (fovx,y) 20 25
- =================
- */
- qboolean Script_Transition3(itemDef_t *item, const char **args)
- {
- const char *name;
- const char *value;
- float minx, miny, minz, maxx, maxy, maxz, fovtx, fovty;
- int time;
- float amt;
- if (String_Parse(args, &name))
- {
- if (String_Parse( args, &value))
- {
- minx = atof(value);
- if (String_Parse( args, &value))
- {
- miny = atof(value);
- if (String_Parse( args, &value))
- {
- minz = atof(value);
- if (String_Parse( args, &value))
- {
- maxx = atof(value);
- if (String_Parse( args, &value))
- {
- maxy = atof(value);
- if (String_Parse( args, &value))
- {
- maxz = atof(value);
- if (String_Parse( args, &value))
- {
- fovtx = atof(value);
- if (String_Parse( args, &value))
- {
- fovty = atof(value);
-
- if (String_Parse( args, &value))
- {
- time = atoi(value);
- if (String_Parse( args, &value))
- {
- amt = atof(value);
- //set up the variables
- Menu_Transition3ItemByName((menuDef_t *) item->parent,
- name,
- minx, miny, minz,
- maxx, maxy, maxz,
- fovtx, fovty,
- time, amt);
-
- return qtrue;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- Com_Printf(S_COLOR_YELLOW"WARNING: Script_Transition2: error parsing '%s'\n", name );
- return qtrue;
- }
- #endif
- //only works on some feeders
- int GetCurrentFeederIndex(itemDef_t * item)
- {
- float feederID = item->special;
- char * name;
- int i, max;
-
- if (feederID == FEEDER_PLAYER_SPECIES)
- {
- return uiInfo.playerSpeciesIndex;
- }
- if (feederID == FEEDER_PLAYER_SKIN_HEAD)
- {
- name = Cvar_VariableString("ui_char_skin_head");
- max = uiInfo.playerSpecies[uiInfo.playerSpeciesIndex].SkinHeadCount;
- for ( i = 0; i < max ; i++)
- {
- if (!Q_stricmp(name, uiInfo.playerSpecies[uiInfo.playerSpeciesIndex].SkinHeadNames[i]))
- {
- return i;
- }
- // Cvar_Set("ui_char_skin_head", uiInfo.playerSpecies[uiInfo.playerSpeciesIndex].SkinHeadNames[index]);
- }
- return -1;
- }
- else if (feederID == FEEDER_PLAYER_SKIN_TORSO)
- {
- name = Cvar_VariableString("ui_char_skin_torso");
- max = uiInfo.playerSpecies[uiInfo.playerSpeciesIndex].SkinTorsoCount;
- for ( i = 0; i < max ; i++)
- {
- if (!Q_stricmp(name, uiInfo.playerSpecies[uiInfo.playerSpeciesIndex].SkinTorsoNames[i]))
- {
- return i;
- }
- // Cvar_Set("ui_char_skin_head", uiInfo.playerSpecies[uiInfo.playerSpeciesIndex].SkinHeadNames[index]);
- }
- return -1;
-
- }
- else if (feederID == FEEDER_PLAYER_SKIN_LEGS)
- {
- name = Cvar_VariableString("ui_char_skin_legs");
- max = uiInfo.playerSpecies[uiInfo.playerSpeciesIndex].SkinLegCount;
- for ( i = 0; i < max ; i++)
- {
- if (!Q_stricmp(name, uiInfo.playerSpecies[uiInfo.playerSpeciesIndex].SkinLegNames[i]))
- {
- return i;
- }
- // Cvar_Set("ui_char_skin_head", uiInfo.playerSpecies[uiInfo.playerSpeciesIndex].SkinHeadNames[index]);
- }
- return -1;
- // if (index >= 0 && index < uiInfo.playerSpecies[uiInfo.playerSpeciesIndex].SkinLegCount)
- // {
- // Cvar_Set("ui_char_skin_legs", uiInfo.playerSpecies[uiInfo.playerSpeciesIndex].SkinLegNames[index]);
- // }
- }
-
- else if (feederID == FEEDER_COLORCHOICES)
- {
- extern void Item_RunScript(itemDef_t *item, const char *s); //from ui_shared;
- int currR, currG, currB, newR, newG, newB;
- currR = Cvar_VariableIntegerValue( "ui_char_color_red");
- currG = Cvar_VariableIntegerValue( "ui_char_color_green");
- currB = Cvar_VariableIntegerValue( "ui_char_color_blue");
-
- max = uiInfo.playerSpecies[uiInfo.playerSpeciesIndex].ColorCount;
- for ( i = 0; i < max ; i++)
- {
- Item_RunScript(item, uiInfo.playerSpecies[uiInfo.playerSpeciesIndex].ColorActionText[i]);
- newR = Cvar_VariableIntegerValue( "ui_char_color_red");
- newG = Cvar_VariableIntegerValue( "ui_char_color_green");
- newB = Cvar_VariableIntegerValue( "ui_char_color_blue");
- if ( currR == newR && currG == newG && currB == newB)
- return i;
- }
- return -1;
-
- //JLF junk copied code
- /*
- extern void Item_RunScript(itemDef_t *item, const char *s); //from ui_shared;
- name = Cvar_VariableString("ui_char_skin_legs");
- max = uiInfo.playerSpecies[uiInfo.playerSpeciesIndex].ColorCount;
- for ( i = 0; i < max ; i++)
- if (!qstrcmp(name, uiInfo.playerSpecies[uiInfo.playerSpeciesIndex].SkinLegNames[i]))
- {
- return i;
- // Cvar_Set("ui_char_skin_head", uiInfo.playerSpecies[uiInfo.playerSpeciesIndex].SkinHeadNames[index]);
- }
- return -1;
- if (index >= 0 && index < uiInfo.playerSpecies[uiInfo.playerSpeciesIndex].ColorCount)
- {
- Item_RunScript(item, uiInfo.playerSpecies[uiInfo.playerSpeciesIndex].ColorActionText[index]);
- }
- */
- }
- return -1;
- }
- qboolean Script_IncrementFeeder(itemDef_t * item, const char ** args)
- {
-
- int feedercount = uiInfo.uiDC.feederCount(item->special);
- int value = GetCurrentFeederIndex(item);
- value++;
- if ( value >= feedercount)
- value = 0;
- DC->feederSelection(item->special, value, item);
- return qtrue;
- }
- qboolean Script_DecrementFeeder(itemDef_t * item, const char ** args)
- {
-
- int feedercount = uiInfo.uiDC.feederCount(item->special);
- int value = GetCurrentFeederIndex(item);
- value--;
- if ( value < 0)
- value = feedercount-1;
- DC->feederSelection(item->special, value, item);
- return qtrue;
- }
- /*
- =================
- Script_SetCvar
- =================
- */
- qboolean Script_SetCvar(itemDef_t *item, const char **args)
- {
- const char *cvar, *val;
- if (String_Parse(args, &cvar) && String_Parse(args, &val))
- {
- DC->setCVar(cvar, val);
- }
- return qtrue;
- }
- /*
- =================
- Script_Exec
- =================
- */
- qboolean Script_Exec ( itemDef_t *item, const char **args)
- {
- const char *val;
- if (String_Parse(args, &val))
- {
- DC->executeText(EXEC_APPEND, va("%s ; ", val));
- }
- return qtrue;
- }
- /*
- =================
- Script_Play
- =================
- */
- static qboolean Script_Play(itemDef_t *item, const char **args)
- {
- const char *val;
- if (String_Parse(args, &val))
- {
- DC->startLocalSound(DC->registerSound(val, qfalse), CHAN_AUTO );
- }
- return qtrue;
- }
- /*
- =================
- Script_PlayVoice
- =================
- */
- static qboolean Script_PlayVoice(itemDef_t *item, const char **args)
- {
- const char *val;
- if (String_Parse(args, &val))
- {
- DC->startLocalSound(DC->registerSound(val, qfalse), CHAN_VOICE );
- }
- return qtrue;
- }
- /*
- =================
- Script_StopVoice
- =================
- */
- static qboolean Script_StopVoice(itemDef_t *item, const char **args)
- {
- #ifdef _XBOX
- extern void S_KillEntityChannel(int entnum, int chan);
- S_KillEntityChannel( 0, CHAN_VOICE );
- #else
- DC->startLocalSound(uiInfo.uiDC.Assets.nullSound, CHAN_VOICE );
- #endif
- return qtrue;
- }
- /*
- =================
- Script_playLooped
- =================
- */
- /*
- qboolean Script_playLooped(itemDef_t *item, const char **args)
- {
- const char *val;
- if (String_Parse(args, &val))
- {
- // FIXME BOB - is this needed?
- DC->stopBackgroundTrack();
- DC->startBackgroundTrack(val, val);
- }
- return qtrue;
- }
- */
- #ifdef _IMMERSION
- /*
- =================
- Script_FFPlay
- =================
- */
- qboolean Script_FFPlay(itemDef_t *item, const char **args)
- {
- const char *val;
- if (String_Parse(args, &val))
- {
- DC->startForce(DC->registerForce(val));
- }
- return qtrue;
- }
- #endif // _IMMERSION
- /*
- =================
- Script_Orbit
- =================
- */
- qboolean Script_Orbit(itemDef_t *item, const char **args)
- {
- const char *name;
- float cx, cy, x, y;
- int time;
- if (String_Parse(args, &name))
- {
- // if ( Float_Parse(args, &x) && Float_Parse(args, &y) && Float_Parse(args, &cx) && Float_Parse(args, &cy) && Int_Parse(args, &time) )
- if ( !COM_ParseFloat(args, &x) && !COM_ParseFloat(args, &y) && !COM_ParseFloat(args, &cx) && !COM_ParseFloat(args, &cy) && Int_Parse(args, &time) )
- {
- Menu_OrbitItemByName((menuDef_t *) item->parent, name, x, y, cx, cy, time);
- }
- }
- return qtrue;
- }
- commandDef_t commandList[] =
- {
- {"activate", &Script_Activate}, // menu
- {"close", &Script_Close}, // menu
- {"exec", &Script_Exec}, // group/name
- {"fadein", &Script_FadeIn}, // group/name
- {"fadeout", &Script_FadeOut}, // group/name
- {"hide", &Script_Hide}, // group/name
- {"open", &Script_Open}, // menu
- {"openGoToMenu", &Script_OpenGoToMenu}, //
- {"orbit", &Script_Orbit}, // group/name
- {"play", &Script_Play}, // group/name
- {"playVoice", &Script_PlayVoice}, // group/name
- {"stopVoice", &Script_StopVoice}, // group/name
- // {"playlooped", &Script_playLooped}, // group/name
- #ifdef _IMMERSION
- {"ffplay", &Script_FFPlay},
- #endif // _IMMERSION
- {"setasset", &Script_SetAsset}, // works on this
- {"setbackground", &Script_SetBackground}, // works on this
- {"setcolor", &Script_SetColor}, // works on this
- {"setcvar", &Script_SetCvar}, // group/name
- {"setfocus", &Script_SetFocus}, // sets this background color to team color
- {"setitemcolor", &Script_SetItemColor}, // group/name
- {"setfocuscolor", &Script_SetFocusColor}, // affects whole menu
- {"setitemflag", &Script_SetItemFlag}, // name
- {"show", &Script_Show}, // group/name
- {"showMenu", &Script_ShowMenu}, // menu
- {"transition", &Script_Transition}, // group/name
- {"transition2", &Script_Transition2}, // group/name
- {"setitembackground", &Script_SetItemBackground}, // group/name
- {"setitemtext", &Script_SetItemText}, // group/name
- {"setitemrect", &Script_SetItemRect}, // group/name
- {"defer", &Script_Defer}, //
- {"rundeferred", &Script_RunDeferred}, //
- {"delay", &Script_Delay}, // works on this (script)
- {"transition3", &Script_Transition3}, // model exclusive transition
- {"incrementfeeder", &Script_IncrementFeeder},
- {"decrementfeeder", &Script_DecrementFeeder},
- {"setdecoration", &Script_SetDecoration}, // changes the decoration flag of an object
- {"cvarifequal", &Script_CvarIfEqual}
- };
- int scriptCommandCount = sizeof(commandList) / sizeof(commandDef_t);
- /*
- ===============
- Item_Init
- ===============
- */
- void Item_Init(itemDef_t *item)
- {
- memset(item, 0, sizeof(itemDef_t));
- item->textscale = 0.55f;
- Window_Init(&item->window);
- }
- /*
- ===============
- Item_Multi_Setting
- ===============
- */
- const char *Item_Multi_Setting(itemDef_t *item)
- {
- char buff[1024];
- float value = 0;
- int i;
- multiDef_t *multiPtr = (multiDef_t*)item->typeData;
- if (multiPtr)
- {
- if (multiPtr->strDef)
- {
- if (item->cvar)
- {
- DC->getCVarString(item->cvar, buff, sizeof(buff));
- }
- else
- {
- }
- }
- else
- {
- if (item->cvar) // Was a cvar given?
- {
- value = DC->getCVarValue(item->cvar);
- }
- else
- {
- value = item->value;
- }
- }
- for (i = 0; i < multiPtr->count; i++)
- {
- if (multiPtr->strDef)
- {
- if (Q_stricmp(buff, multiPtr->cvarStr[i]) == 0)
- {
- return multiPtr->cvarList[i];
- }
- }
- else
- {
- if (multiPtr->cvarValue[i] == value)
- {
- return multiPtr->cvarList[i];
- }
- }
- }
- }
- return "";
- }
- //---------------------------------------------------------------------------------------------------------
- // Item Keyword Parse functions
- //---------------------------------------------------------------------------------------------------------
- /*
- ===============
- ItemParse_name
- name <string>
- ===============
- */
- qboolean ItemParse_name( itemDef_t *item)
- {
- if (!PC_ParseStringMem((const char **)&item->window.name))
- {
- return qfalse;
- }
- return qtrue;
- }
- qboolean ItemParse_font( itemDef_t *item )
- {
- if (PC_ParseInt(&item->font))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_focusSound
- name <string>
- ===============
- */
- qboolean ItemParse_focusSound( itemDef_t *item)
- {
- const char *temp;
- if (PC_ParseString(&temp))
- {
- return qfalse;
- }
- item->focusSound = DC->registerSound(temp, qfalse);
- return qtrue;
- }
- #ifdef _IMMERSION
- /*
- ===============
- ItemParse_focusForce
- name <string>
- ===============
- */
- qboolean ItemParse_focusForce( itemDef_t *item)
- {
- const char *temp;
- if (PC_ParseString(&temp))
- {
- //#ifdef _DEBUG
- //extern void UI_Debug_EnterReference(LPCSTR ps4LetterType, LPCSTR psItemString);
- //#endif
- return qfalse;
- }
- item->focusForce = DC->registerForce(temp);
- return qtrue;
- }
- #endif // _IMMERSION
- /*
- ===============
- ItemParse_text
- text <string>
- ===============
- */
- qboolean ItemParse_text( itemDef_t *item)
- {
- if (!PC_ParseStringMem((const char **) &item->text))
- {
- return qfalse;
- }
- //#ifdef _DEBUG
- // UI_Debug_EnterReference("TEXT", item->text);
- //#endif
- return qtrue;
- }
- /*
- ===============
- ItemParse_descText
- text <string>
- ===============
- */
- /*
- qboolean ItemParse_descText( itemDef_t *item)
- {
- if (!PC_ParseStringMem((const char **) &item->descText))
- {
- return qfalse;
- }
- //#ifdef _DEBUG
- // UI_Debug_EnterReference("DESC", item->descText);
- //#endif
- return qtrue;
- }
- */
- /*
- ===============
- ItemParse_text
- text <string>
- ===============
- */
- /*
- qboolean ItemParse_text2( itemDef_t *item)
- {
- if (!PC_ParseStringMem((const char **) &item->text2))
- {
- return qfalse;
- }
- //#ifdef _DEBUG
- // UI_Debug_EnterReference("TXT2", item->text2);
- //#endif
- return qtrue;
- }
- */
- /*
- ===============
- ItemParse_group
- group <string>
- ===============
- */
- qboolean ItemParse_group( itemDef_t *item)
- {
- if (!PC_ParseStringMem((const char **)&item->window.group))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_asset_model
- asset_model <string>
- ===============
- */
- qboolean ItemParse_asset_model_go( itemDef_t *item, const char *name )
- {
- modelDef_t *modelPtr;
- Item_ValidateTypeData(item);
- modelPtr = (modelDef_t*)item->typeData;
- if (!Q_stricmp(&name[strlen(name) - 4], ".glm"))
- { //it's a ghoul2 model then
- if ( item->ghoul2.size() && item->ghoul2[0].mModelindex >= 0)
- {
- DC->g2_RemoveGhoul2Model( item->ghoul2, 0 );
- item->flags &= ~ITF_G2VALID;
- }
- int g2Model = DC->g2_InitGhoul2Model(item->ghoul2, name, 0, 0, 0, 0, 0);
- if (g2Model >= 0)
- {
- item->flags |= ITF_G2VALID;
- if (modelPtr->g2anim)
- { //does the menu request this model be playing an animation?
- DC->g2hilev_SetAnim(&item->ghoul2[0], "model_root", modelPtr->g2anim, qfalse);
- }
- if ( modelPtr->g2skin )
- {
- DC->g2_SetSkin( &item->ghoul2[0], 0, modelPtr->g2skin );//this is going to set the surfs on/off matching the skin file
- }
- }
- }
- else if(!(item->asset))
- { //guess it's just an md3
- item->asset = DC->registerModel(name);
- item->flags &= ~ITF_G2VALID;
- }
- return qtrue;
- }
- qboolean ItemParse_asset_model( itemDef_t *item )
- {
- const char *temp;
- modelDef_t *modelPtr;
- Item_ValidateTypeData(item);
- modelPtr = (modelDef_t*)item->typeData;
- if (PC_ParseString(&temp))
- {
- return qfalse;
- }
- char modelPath[MAX_QPATH];
-
- if (!stricmp(temp,"ui_char_model") )
- {
- Com_sprintf( modelPath, sizeof( modelPath ), "models/players/%s/model.glm", Cvar_VariableString ( "g_char_model" ) );
- }
- else
- {
- Com_sprintf( modelPath, sizeof( modelPath ), temp);
- }
- return (ItemParse_asset_model_go( item, modelPath ));
- }
- /*
- ===============
- ItemParse_asset_model
- asset_shader <string>
- ===============
- */
- qboolean ItemParse_asset_shader( itemDef_t *item)
- {
- const char *temp;
- if (PC_ParseString(&temp))
- {
- return qfalse;
- }
- item->asset = DC->registerShaderNoMip(temp);
- return qtrue;
- }
- /*
- ===============
- ItemParse_asset_model
- model_origin <number> <number> <number>
- ===============
- */
- qboolean ItemParse_model_origin( itemDef_t *item)
- {
- modelDef_t *modelPtr;
- Item_ValidateTypeData(item);
- modelPtr = (modelDef_t*)item->typeData;
- if (!PC_ParseFloat(&modelPtr->origin[0]))
- {
- if (!PC_ParseFloat(&modelPtr->origin[1]))
- {
- if (!PC_ParseFloat(&modelPtr->origin[2]))
- {
- return qtrue;
- }
- }
- }
- return qfalse;
- }
- /*
- ===============
- ItemParse_model_fovx
- model_fovx <number>
- ===============
- */
- qboolean ItemParse_model_fovx( itemDef_t *item)
- {
- modelDef_t *modelPtr;
- Item_ValidateTypeData(item);
- modelPtr = (modelDef_t*)item->typeData;
- if (PC_ParseFloat(&modelPtr->fov_x))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_model_fovy
- model_fovy <number>
- ===============
- */
- qboolean ItemParse_model_fovy( itemDef_t *item)
- {
- modelDef_t *modelPtr;
- Item_ValidateTypeData(item);
- modelPtr = (modelDef_t*)item->typeData;
- if (PC_ParseFloat(&modelPtr->fov_y))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_model_rotation
- model_rotation <integer>
- ===============
- */
- qboolean ItemParse_model_rotation( itemDef_t *item)
- {
- modelDef_t *modelPtr;
- Item_ValidateTypeData(item);
- modelPtr = (modelDef_t*)item->typeData;
- if (PC_ParseInt(&modelPtr->rotationSpeed))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_model_angle
- model_angle <integer>
- ===============
- */
- qboolean ItemParse_model_angle( itemDef_t *item)
- {
- modelDef_t *modelPtr;
- Item_ValidateTypeData(item);
- modelPtr = (modelDef_t*)item->typeData;
- if (PC_ParseInt(&modelPtr->angle))
- {
- return qfalse;
- }
- return qtrue;
- }
- // model_g2mins <number> <number> <number>
- qboolean ItemParse_model_g2mins( itemDef_t *item ) {
- modelDef_t *modelPtr;
- Item_ValidateTypeData(item);
- modelPtr = (modelDef_t*)item->typeData;
- if (!PC_ParseFloat(&modelPtr->g2mins[0])) {
- if (!PC_ParseFloat(&modelPtr->g2mins[1])) {
- if (!PC_ParseFloat(&modelPtr->g2mins[2])) {
- return qtrue;
- }
- }
- }
- return qfalse;
- }
- // model_g2maxs <number> <number> <number>
- qboolean ItemParse_model_g2maxs( itemDef_t *item ) {
- modelDef_t *modelPtr;
- Item_ValidateTypeData(item);
- modelPtr = (modelDef_t*)item->typeData;
- if (!PC_ParseFloat(&modelPtr->g2maxs[0])) {
- if (!PC_ParseFloat(&modelPtr->g2maxs[1])) {
- if (!PC_ParseFloat(&modelPtr->g2maxs[2])) {
- return qtrue;
- }
- }
- }
- return qfalse;
- }
- // model_g2skin <string>
- qboolean ItemParse_model_g2skin_go( itemDef_t *item, const char *skinName )
- {
- modelDef_t *modelPtr;
- Item_ValidateTypeData(item);
- modelPtr = (modelDef_t*)item->typeData;
- if (!skinName || !skinName[0])
- { //it was parsed cor~rectly so still return true.
- modelPtr->g2skin = 0;
- DC->g2_SetSkin( &item->ghoul2[0], -1, 0 );//turn off custom skin
- return qtrue;
- }
- modelPtr->g2skin = DC->registerSkin(skinName);
- if ( item->ghoul2.IsValid() )
- {
- DC->g2_SetSkin( &item->ghoul2[0], 0, modelPtr->g2skin );//this is going to set the surfs on/off matching the skin file
- }
- return qtrue;
- }
- qboolean ItemParse_model_g2skin( itemDef_t *item )
- {
- const char *skinName;
- if (PC_ParseString(&skinName)) {
- return qfalse;
- }
- return (ItemParse_model_g2skin_go( item, skinName ));
- }
- // model_g2anim <number>
- qboolean ItemParse_model_g2anim_go( itemDef_t *item, const char *animName )
- {
- modelDef_t *modelPtr;
- int i = 0;
- Item_ValidateTypeData(item);
- modelPtr = (modelDef_t*)item->typeData;
- if (!animName || !animName[0])
- { //it was parsed correctly so still return true.
- return qtrue;
- }
- while (i < MAX_ANIMATIONS)
- {
- if (!Q_stricmp(animName, animTable[i].name))
- { //found it
- modelPtr->g2anim = animTable[i].id;
- return qtrue;
- }
- i++;
- }
- Com_Printf("Could not find '%s' in the anim table\n", animName);
- return qtrue;
- }
- qboolean ItemParse_model_g2anim( itemDef_t *item ) {
- const char *animName;
- if (PC_ParseString(&animName)) {
- return qfalse;
- }
- return ItemParse_model_g2anim_go( item, animName );
- }
- /*
- ===============
- ItemParse_rect
- rect <rectangle>
- ===============
- */
- qboolean ItemParse_rect( itemDef_t *item)
- {
- if (!PC_ParseRect(&item->window.rectClient))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_flag
- flag <integer>
- ===============
- */
- qboolean ItemParse_flag( itemDef_t *item)
- {
- int i;
- const char *tempStr;
- if (PC_ParseString(&tempStr))
- {
- return qfalse;
- }
- i=0;
- while (itemFlags[i].string)
- {
- if (Q_stricmp(tempStr,itemFlags[i].string)==0)
- {
- item->window.flags |= itemFlags[i].value;
- break;
- }
- i++;
- }
- if (itemFlags[i].string == NULL)
- {
- PC_ParseWarning(va("Unknown item flag value '%s'",tempStr));
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_style
- style <integer>
- ===============
- */
- qboolean ItemParse_style( itemDef_t *item)
- {
- int i;
- const char *tempStr;
- if (PC_ParseString(&tempStr))
- {
- return qfalse;
- }
- i=0;
- while (styles[i])
- {
- if (Q_stricmp(tempStr,styles[i])==0)
- {
- item->window.style = i;
- break;
- }
- i++;
- }
- if (styles[i] == NULL)
- {
- PC_ParseWarning(va("Unknown item style value '%s'",tempStr));
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_decoration
- decoration
- ===============
- */
- qboolean ItemParse_decoration( itemDef_t *item )
- {
- item->window.flags |= WINDOW_DECORATION;
- return qtrue;
- }
- /*
- ===============
- ItemParse_notselectable
- notselectable
- ===============
- */
- qboolean ItemParse_notselectable( itemDef_t *item )
- {
- listBoxDef_t *listPtr;
- Item_ValidateTypeData(item);
- listPtr = (listBoxDef_t*)item->typeData;
- if (item->type == ITEM_TYPE_LISTBOX && listPtr)
- {
- listPtr->notselectable = qtrue;
- }
- return qtrue;
- }
- //JLF
- #ifdef _XBOX
- /*
- ===============
- ItemParse_scrollhidden
- scrollhidden
- ===============
- */
- qboolean ItemParse_scrollhidden( itemDef_t *item )
- {
- listBoxDef_t *listPtr;
- Item_ValidateTypeData(item);
- listPtr = (listBoxDef_t*)item->typeData;
- if (item->type == ITEM_TYPE_LISTBOX && listPtr)
- {
- listPtr->scrollhidden = qtrue;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_selectionShader
- selectionShader
- ===============
- */
- qboolean ItemParse_selectionShader( itemDef_t *item )
- {
- const char *temp;
- if (PC_ParseString(&temp))
- {
- return qfalse;
- }
- listBoxDef_t *listPtr;
- Item_ValidateTypeData( item );
- listPtr = (listBoxDef_t *)item->typeData;
- if (item->type == ITEM_TYPE_LISTBOX && listPtr)
- {
- listPtr->selectionShader = ui.R_RegisterShaderNoMip(temp);
- }
- return qtrue;
- }
- #endif
- /*
- ===============
- ItemParse_wrapped
- manually wrapped
- ===============
- */
- qboolean ItemParse_wrapped( itemDef_t *item )
- {
- item->window.flags |= WINDOW_WRAPPED;
- return qtrue;
- }
- /*
- ===============
- ItemParse_autowrapped
- auto wrapped
- ===============
- */
- qboolean ItemParse_autowrapped( itemDef_t *item)
- {
- item->window.flags |= WINDOW_AUTOWRAPPED;
- return qtrue;
- }
- /*
- ===============
- ItemParse_horizontalscroll
- horizontalscroll
- ===============
- */
- qboolean ItemParse_horizontalscroll( itemDef_t *item )
- {
- item->window.flags |= WINDOW_HORIZONTAL;
- return qtrue;
- }
-
- /*
- ===============
- ItemParse_type
- type <integer>
- ===============
- */
- qboolean ItemParse_type( itemDef_t *item )
- {
- int i;
- const char *tempStr;
- if (PC_ParseString(&tempStr))
- {
- return qfalse;
- }
- i=0;
- while (types[i])
- {
- if (Q_stricmp(tempStr,types[i])==0)
- {
- item->type = i;
- break;
- }
- i++;
- }
- if (types[i] == NULL)
- {
- PC_ParseWarning(va("Unknown item type value '%s'",tempStr));
- }
- else
- {
- Item_ValidateTypeData(item);
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_elementwidth
- elementwidth, used for listbox image elements
- uses textalignx for storage
- ===============
- */
- qboolean ItemParse_elementwidth( itemDef_t *item )
- {
- listBoxDef_t *listPtr;
- Item_ValidateTypeData(item);
- listPtr = (listBoxDef_t*)item->typeData;
- if (PC_ParseFloat(&listPtr->elementWidth))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_elementheight
- elementheight, used for listbox image elements
- uses textaligny for storage
- ===============
- */
- qboolean ItemParse_elementheight( itemDef_t *item )
- {
- listBoxDef_t *listPtr;
- Item_ValidateTypeData(item);
- listPtr = (listBoxDef_t*)item->typeData;
- if (PC_ParseFloat(&listPtr->elementHeight))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_feeder
- feeder <float>
- ===============
- */
- qboolean ItemParse_feeder( itemDef_t *item )
- {
- if (PC_ParseFloat( &item->special))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_elementtype
- elementtype, used to specify what type of elements a listbox contains
- uses textstyle for storage
- ===============
- */
- qboolean ItemParse_elementtype( itemDef_t *item )
- {
- listBoxDef_t *listPtr;
- Item_ValidateTypeData(item);
- if (!item->typeData)
- {
- return qfalse;
- }
- listPtr = (listBoxDef_t*)item->typeData;
- if (PC_ParseInt(&listPtr->elementStyle))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_columns
- columns sets a number of columns and an x pos and width per..
- ===============
- */
- qboolean ItemParse_columns( itemDef_t *item)
- {
- int num, i;
- listBoxDef_t *listPtr;
- Item_ValidateTypeData(item);
- if (!item->typeData)
- {
- return qfalse;
- }
- listPtr = (listBoxDef_t*)item->typeData;
- if (!PC_ParseInt(&num))
- {
- if (num > MAX_LB_COLUMNS)
- {
- num = MAX_LB_COLUMNS;
- }
- listPtr->numColumns = num;
- for (i = 0; i < num; i++)
- {
- int pos, width, maxChars;
- if (!PC_ParseInt(&pos) && !PC_ParseInt(&width) && !PC_ParseInt(&maxChars))
- {
- listPtr->columnInfo[i].pos = pos;
- listPtr->columnInfo[i].width = width;
- listPtr->columnInfo[i].maxChars = maxChars;
- }
- else
- {
- return qfalse;
- }
- }
- }
- else
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_border
- ===============
- */
- qboolean ItemParse_border( itemDef_t *item)
- {
- if (PC_ParseInt(&item->window.border))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_bordersize
- ===============
- */
- qboolean ItemParse_bordersize( itemDef_t *item )
- {
- if (PC_ParseFloat(&item->window.borderSize))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_visible
- ===============
- */
- qboolean ItemParse_visible( itemDef_t *item)
- {
- int i;
- if (PC_ParseInt(&i))
- {
- return qfalse;
- }
- if (i)
- {
- item->window.flags |= WINDOW_VISIBLE;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_ownerdraw
- ===============
- */
- qboolean ItemParse_ownerdraw( itemDef_t *item)
- {
- if (PC_ParseInt(&item->window.ownerDraw))
- {
- return qfalse;
- }
- item->type = ITEM_TYPE_OWNERDRAW;
- return qtrue;
- }
- /*
- ===============
- ItemParse_align
- ===============
- */
- qboolean ItemParse_align( itemDef_t *item)
- {
- if (PC_ParseInt(&item->alignment))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_align
- ===============
- */
- /*
- qboolean ItemParse_Appearance_slot( itemDef_t *item)
- {
- if (PC_ParseInt(&item->appearanceSlot))
- {
- return qfalse;
- }
- return qtrue;
- }
- */
- /*
- ===============
- ItemParse_textalign
- ===============
- */
- qboolean ItemParse_textalign( itemDef_t *item )
- {
- const char *tempStr;
- int i;
- if (PC_ParseString(&tempStr))
- {
- return qfalse;
- }
- i=0;
- while (alignment[i])
- {
- if (Q_stricmp(tempStr,alignment[i])==0)
- {
- item->textalignment = i;
- break;
- }
- i++;
- }
- if (alignment[i] == NULL)
- {
- PC_ParseWarning(va("Unknown text alignment value '%s'",tempStr));
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_text2alignx
- ===============
- */
- /*
- qboolean ItemParse_text2alignx( itemDef_t *item)
- {
- if (PC_ParseFloat(&item->text2alignx))
- {
- return qfalse;
- }
- return qtrue;
- }
- */
- /*
- ===============
- ItemParse_text2aligny
- ===============
- */
- /*
- qboolean ItemParse_text2aligny( itemDef_t *item)
- {
- if (PC_ParseFloat(&item->text2aligny))
- {
- return qfalse;
- }
- return qtrue;
- }
- */
- /*
- ===============
- ItemParse_textalignx
- ===============
- */
- qboolean ItemParse_textalignx( itemDef_t *item)
- {
- if (PC_ParseFloat(&item->textalignx))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_textaligny
- ===============
- */
- qboolean ItemParse_textaligny( itemDef_t *item)
- {
- if (PC_ParseFloat(&item->textaligny))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_textscale
- ===============
- */
- qboolean ItemParse_textscale( itemDef_t *item )
- {
- if (PC_ParseFloat(&item->textscale))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_textstyle
- ===============
- */
- qboolean ItemParse_textstyle( itemDef_t *item)
- {
- if (PC_ParseInt(&item->textStyle))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_invertyesno
- ===============
- */
- /*
- qboolean ItemParse_invertyesno( itemDef_t *item)
- {
- if (PC_ParseInt(&item->invertYesNo))
- {
- return qfalse;
- }
- return qtrue;
- }
- */
- /*
- ===============
- ItemParse_xoffset (used for yes/no and multi)
- ===============
- */
- qboolean ItemParse_xoffset( itemDef_t *item)
- {
- if (PC_ParseInt(&item->xoffset))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_backcolor
- ===============
- */
- qboolean ItemParse_backcolor( itemDef_t *item)
- {
- int i;
- float f;
- for (i = 0; i < 4; i++)
- {
- if (PC_ParseFloat(&f))
- {
- return qfalse;
- }
- item->window.backColor[i] = f;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_forecolor
- ===============
- */
- qboolean ItemParse_forecolor( itemDef_t *item)
- {
- int i;
- float f;
- for (i = 0; i < 4; i++)
- {
- if (PC_ParseFloat(&f))
- {
- return qfalse;
- }
- if (f < 0)
- { //special case for player color
- item->window.flags |= WINDOW_PLAYERCOLOR;
- return qtrue;
- }
- item->window.foreColor[i] = f;
- item->window.flags |= WINDOW_FORECOLORSET;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_bordercolor
- ===============
- */
- qboolean ItemParse_bordercolor( itemDef_t *item)
- {
- int i;
- float f;
- for (i = 0; i < 4; i++)
- {
- if (PC_ParseFloat(&f))
- {
- return qfalse;
- }
- item->window.borderColor[i] = f;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_outlinecolor
- ===============
- */
- /*
- qboolean ItemParse_outlinecolor( itemDef_t *item)
- {
- if (PC_ParseColor(&item->window.outlineColor))
- {
- return qfalse;
- }
- return qtrue;
- }
- */
- /*
- ===============
- ItemParse_background
- ===============
- */
- qboolean ItemParse_background( itemDef_t *item)
- {
- const char *temp;
- if (PC_ParseString(&temp))
- {
- return qfalse;
- }
- item->window.background = ui.R_RegisterShaderNoMip(temp);
- return qtrue;
- }
- /*
- ===============
- ItemParse_cinematic
- ===============
- */
- /*
- qboolean ItemParse_cinematic( itemDef_t *item)
- {
- if (!PC_ParseStringMem((const char **) &item->window.cinematicName))
- {
- return qfalse;
- }
- return qtrue;
- }
- */
- /*
- ===============
- ItemParse_doubleClick
- ===============
- */
- qboolean ItemParse_doubleClick( itemDef_t *item)
- {
- listBoxDef_t *listPtr;
- Item_ValidateTypeData(item);
- if (!item->typeData)
- {
- return qfalse;
- }
- listPtr = (listBoxDef_t*)item->typeData;
- if (!PC_Script_Parse(&listPtr->doubleClick))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_onFocus
- ===============
- */
- qboolean ItemParse_onFocus( itemDef_t *item)
- {
- if (!PC_Script_Parse(&item->onFocus))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_leaveFocus
- ===============
- */
- qboolean ItemParse_leaveFocus( itemDef_t *item )
- {
- if (!PC_Script_Parse(&item->leaveFocus))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_mouseEnter
- ===============
- */
- /*
- qboolean ItemParse_mouseEnter( itemDef_t *item)
- {
- if (!PC_Script_Parse(&item->mouseEnter))
- {
- return qfalse;
- }
- return qtrue;
- }
- */
- /*
- ===============
- ItemParse_mouseExit
- ===============
- */
- /*
- qboolean ItemParse_mouseExit( itemDef_t *item)
- {
- if (!PC_Script_Parse(&item->mouseExit))
- {
- return qfalse;
- }
- return qtrue;
- }
- */
- /*
- ===============
- ItemParse_mouseEnterText
- ===============
- */
- /*
- qboolean ItemParse_mouseEnterText( itemDef_t *item)
- {
- if (!PC_Script_Parse(&item->mouseEnterText))
- {
- return qfalse;
- }
- return qtrue;
- }
- */
- /*
- ===============
- ItemParse_mouseExitText
- ===============
- */
- /*
- qboolean ItemParse_mouseExitText( itemDef_t *item)
- {
- if (!PC_Script_Parse(&item->mouseExitText))
- {
- return qfalse;
- }
- return qtrue;
- }
- */
- /*
- ===============
- ItemParse_accept
- ===============
- */
- /*
- qboolean ItemParse_accept( itemDef_t *item)
- {
- if (!PC_Script_Parse(&item->accept))
- {
- return qfalse;
- }
- return qtrue;
- }
- */
- //JLFDPADSCRIPT
- /*
- ===============
- ItemParse_selectionNext
- ===============
- */
- qboolean ItemParse_selectionNext( itemDef_t *item)
- {
- if (!PC_Script_Parse(&item->selectionNext))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_selectionPrev
- ===============
- */
- qboolean ItemParse_selectionPrev( itemDef_t *item)
- {
- if (!PC_Script_Parse(&item->selectionPrev))
- {
- return qfalse;
- }
- return qtrue;
- }
- // END JLFDPADSCRIPT
- /*
- ===============
- ItemParse_action
- ===============
- */
- qboolean ItemParse_action( itemDef_t *item)
- {
- if (!PC_Script_Parse(&item->action))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_special
- ===============
- */
- qboolean ItemParse_special( itemDef_t *item)
- {
- if (PC_ParseFloat(&item->special))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_cvarTest
- ===============
- */
- qboolean ItemParse_cvarTest( itemDef_t *item)
- {
- if (!PC_ParseStringMem((const char **) &item->cvarTest))
- {
- return qfalse;
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_cvar
- ===============
- */
- qboolean ItemParse_cvar( itemDef_t *item)
- {
- editFieldDef_t *editPtr;
- Item_ValidateTypeData(item);
- if (!PC_ParseStringMem(&item->cvar))
- {
- return qfalse;
- }
- if ( item->typeData)
- {
- switch ( item->type )
- {
- case ITEM_TYPE_EDITFIELD:
- case ITEM_TYPE_NUMERICFIELD:
- case ITEM_TYPE_YESNO:
- case ITEM_TYPE_BIND:
- case ITEM_TYPE_SLIDER:
- case ITEM_TYPE_TEXT:
- case ITEM_TYPE_TEXTSCROLL:
- editPtr = (editFieldDef_t*)item->typeData;
- editPtr->minVal = -1;
- editPtr->maxVal = -1;
- editPtr->defVal = -1;
- break;
- }
- }
- return qtrue;
- }
- /*
- ===============
- ItemParse_maxChars
- ===============
- */
- qboolean ItemParse_maxChars( itemDef_t *item)
- {
- editFieldDef_t *editPtr;
- int maxChars;
- Item_ValidateTypeData(item);
- if (!item->typeData)
- {
- return qfalse;
- }
- if (PC_ParseInt(&maxChars))
- {
- return qfalse;
- }
- editPtr = (editFieldDef_t*)item->typeData;
- editPtr->maxChars = maxChars;
- return qtrue;
- }
- /*
- ===============
- ItemParse_maxPaintChars
- ===============
- */
- qboolean ItemParse_maxPaintChars( itemDef_t *item)
- {
- editFieldDef_t *editPtr;
- int maxChars;
- Item_ValidateTypeData(item);
- if (!item->typeData)
- {
- return qfalse;
- }
- if (PC_ParseInt(&maxChars))
- {
- return qfalse;
- }
- editPtr = (editFieldDef_t*)item->typeData;
- editPtr->maxPaintChars = maxChars;
- return qtrue;
- }
- qboolean ItemParse_lineHeight( itemDef_t *item)
- {
- textScrollDef_t *scrollPtr;
- int height;
- Item_ValidateTypeData(item);
- if (!item->typeData)
- {
- return qfalse;
- }
- if (PC_ParseInt(&height))
- {
- return qfalse;
- }
- scrollPtr = (textScrollDef_t*)item->typeData;
- scrollPtr->lineHeight = height;
- return qtrue;
- }
- /*
- ===============
- ItemParse_cvarFloat
- ===============
- */
- qboolean ItemParse_cvarFloat( itemDef_t *item)
- {
- editFieldDef_t *editPtr;
- Item_ValidateTypeData(item);
- if (!item->typeData)
- {
- return qfalse;
- }
- editPtr = (editFieldDef_t*)item->typeData;
- if (PC_ParseStringMem((const char **) &item->cvar) &&
- !PC_ParseFloat(&editPtr->defVal) &&
- !PC_ParseFloat(&editPtr->minVal) &&
- !PC_ParseFloat(&editPtr->maxVal))
- {
- if (!stricmp(item->cvar,"r_ext_texture_filter_anisotropic"))
- {//hehe, hook up the correct max value here.
- editPtr->maxVal=glConfig.maxTextureFilterAnisotropy;
- }
- return qtrue;
- }
- return qfalse;
- }
- /*
- ===============
- ItemParse_cvarStrList
- ===============
- */
- qboolean ItemParse_cvarStrList( itemDef_t *item)
- {
- const char *token;
- multiDef_t *multiPtr;
- int pass;
-
- Item_ValidateTypeData(item);
- if (!item->typeData)
- {
- return qfalse;
- }
- multiPtr = (multiDef_t*)item->typeData;
- multiPtr->count = 0;
- multiPtr->strDef = qtrue;
- if (PC_ParseString(&token))
- {
- return qfalse;
- }
- if (!stricmp(token,"feeder") && item->special == FEEDER_PLAYER_SPECIES)
- {
- for (; multiPtr->count < uiInfo.playerSpeciesCount; multiPtr->count++)
- {
- multiPtr->cvarList[multiPtr->count] = String_Alloc(strupr(va("@MENUS_%s",uiInfo.playerSpecies[multiPtr->count].Name ))); //look up translation
- multiPtr->cvarStr[multiPtr->count] = uiInfo.playerSpecies[multiPtr->count].Name; //value
- }
- return qtrue;
- }
- // languages
- if (!stricmp(token,"feeder") && item->special == FEEDER_LANGUAGES)
- {
- assert( 0 );
- /*
- for (; multiPtr->count < uiInfo.languageCount; multiPtr->count++)
- {
- // The displayed text
- multiPtr->cvarList[multiPtr->count] = "@MENUS_MYLANGUAGE";
- // The cvar value that goes into se_language
- multiPtr->cvarStr[multiPtr->count] = SE_GetLanguageName( multiPtr->count );
- }
- */
- return qtrue;
- }
- if (*token != '{')
- {
- return qfalse;
- }
- pass = 0;
- while ( 1 )
- {
- if (!PC_ParseStringMem(&token))
- {
- PC_ParseWarning("end of file inside menu item\n");
- return qfalse;
- }
- if (*token == '}')
- {
- return qtrue;
- }
-
- if (*token == ',' || *token == ';')
- {
- continue;
- }
- if (pass == 0)
- {
- multiPtr->cvarList[multiPtr->count] = token;
- pass = 1;
- }
- else
- {
- multiPtr->cvarStr[multiPtr->count] = token;
- pass = 0;
- multiPtr->count++;
- if (multiPtr->count >= MAX_MULTI_CVARS)
- {
- return qfalse;
- }
- }
- }
- return qfalse;
- }
- /*
- ===============
- ItemParse_cvarFloatList
- ===============
- */
- qboolean ItemParse_cvarFloatList( itemDef_t *item)
- {
- const char *token;
- multiDef_t *multiPtr;
-
- Item_ValidateTypeData(item);
- if (!item->typeData)
- {
- return qfalse;
- }
- multiPtr = (multiDef_t*)item->typeData;
- multiPtr->count = 0;
- multiPtr->strDef = qfalse;
- if (PC_ParseString(&token))
- {
- return qfalse;
- }
- if (*token != '{')
- {
- return qfalse;
- }
- while ( 1 )
- {
- if (!PC_ParseStringMem(&token))
- {
- PC_ParseWarning("end of file inside menu item\n");
- return qfalse;
- }
- if (*token == '}')
- {
- return qtrue;
- }
- if (*token == ',' || *token == ';')
- {
- continue;
- }
- multiPtr->cvarList[multiPtr->count] = token; //a StringAlloc ptr
- if (PC_ParseFloat(&multiPtr->cvarValue[multiPtr->count]))
- {
- return qfalse;
- }
- multiPtr->count++;
- if (multiPtr->count >= MAX_MULTI_CVARS)
- {
- return qfalse;
- }
- }
- return qfalse;
- }
- /*
- ===============
- ItemParse_addColorRange
- ===============
- */
- /*
- qboolean ItemParse_addColorRange( itemDef_t *item)
- {
- colorRangeDef_t color;
- if (PC_ParseFloat(&color.low) &&
- PC_ParseFloat(&color.high) &&
- PC_ParseColor(&color.color) )
- {
- if (item->numColors < MAX_COLOR_RANGES)
- {
- memcpy(&item->colorRanges[item->numColors], &color, sizeof(color));
- item->numColors++;
- }
- return qtrue;
- }
- return qfalse;
- }
- */
- /*
- ===============
- ItemParse_ownerdrawFlag
- ===============
- */
- qboolean ItemParse_ownerdrawFlag( itemDef_t *item )
- {
- int i;
- if (PC_ParseInt(&i))
- {
- return qfalse;
- }
- item->window.ownerDrawFlags |= i;
- return qtrue;
- }
- /*
- ===============
- ItemParse_enableCvar
- ===============
- */
- qboolean ItemParse_enableCvar( itemDef_t *item)
- {
- if (PC_Script_Parse(&item->enableCvar))
- {
- item->cvarFlags = CVAR_ENABLE;
- return qtrue;
- }
- return qfalse;
- }
- /*
- ===============
- ItemParse_disableCvar
- ===============
- */
- qboolean ItemParse_disableCvar( itemDef_t *item )
- {
- if (PC_Script_Parse(&item->enableCvar))
- {
- item->cvarFlags = CVAR_DISABLE;
- return qtrue;
- }
- return qfalse;
- }
- /*
- ===============
- ItemParse_showCvar
- ===============
- */
- qboolean ItemParse_showCvar( itemDef_t *item )
- {
- if (PC_Script_Parse(&item->enableCvar))
- {
- item->cvarFlags = CVAR_SHOW;
- return qtrue;
- }
- return qfalse;
- }
- /*
- ===============
- ItemParse_hideCvar
- ===============
- */
- qboolean ItemParse_hideCvar( itemDef_t *item)
- {
- if (PC_Script_Parse(&item->enableCvar))
- {
- item->cvarFlags = CVAR_HIDE;
- return qtrue;
- }
- return qfalse;
- }
- /*
- ===============
- ItemParse_cvarsubstring
- ===============
- */
- qboolean ItemParse_cvarsubstring( itemDef_t *item)
- {
- assert(item->cvarFlags); //need something set first, then we or in our flag.
- item->cvarFlags |= CVAR_SUBSTRING;
- return qtrue;
- }
- /*
- ===============
- Item_ValidateTypeData
- ===============
- */
- void Item_ValidateTypeData(itemDef_t *item)
- {
- if (item->typeData)
- {
- return;
- }
- if (item->type == ITEM_TYPE_LISTBOX)
- {
- item->typeData = UI_Alloc(sizeof(listBoxDef_t));
- memset(item->typeData, 0, sizeof(listBoxDef_t));
- }
- else if (item->type == ITEM_TYPE_EDITFIELD || item->type == ITEM_TYPE_NUMERICFIELD || item->type == ITEM_TYPE_YESNO || item->type == ITEM_TYPE_BIND || item->type == ITEM_TYPE_SLIDER || item->type == ITEM_TYPE_TEXT)
- {
- item->typeData = UI_Alloc(sizeof(editFieldDef_t));
- memset(item->typeData, 0, sizeof(editFieldDef_t));
- if (item->type == ITEM_TYPE_EDITFIELD)
- {
- if (!((editFieldDef_t *) item->typeData)->maxPaintChars)
- {
- ((editFieldDef_t *) item->typeData)->maxPaintChars = MAX_EDITFIELD;
- }
- }
- }
- else if (item->type == ITEM_TYPE_MULTI)
- {
- item->typeData = UI_Alloc(sizeof(multiDef_t));
- }
- else if (item->type == ITEM_TYPE_MODEL)
- {
- item->typeData = UI_Alloc(sizeof(modelDef_t));
- memset(item->typeData, 0, sizeof(modelDef_t));
- }
- else if (item->type == ITEM_TYPE_TEXTSCROLL )
- {
- item->typeData = UI_Alloc(sizeof(textScrollDef_t));
- }
- }
- qboolean ItemParse_isCharacter( itemDef_t *item )
- {
- int i;
- if ( !PC_ParseInt(&i) )
- {
- if ( i )
- {
- item->flags |= ITF_ISCHARACTER;
- }
- else
- {
- item->flags &= ~ITF_ISCHARACTER;
- }
- return qtrue;
- }
- return qfalse;
- }
- qboolean ItemParse_isSaber( itemDef_t *item )
- {
- extern void UI_SaberLoadParms( void );
- extern qboolean ui_saber_parms_parsed;
- extern void UI_CacheSaberGlowGraphics( void );
- int i;
- if ( !PC_ParseInt(&i) )
- {
- if ( i )
- {
- item->flags |= ITF_ISSABER;
- UI_CacheSaberGlowGraphics();
- if ( !ui_saber_parms_parsed )
- {
- UI_SaberLoadParms();
- }
- }
- else
- {
- item->flags &= ~ITF_ISSABER;
- }
- return qtrue;
- }
- return qfalse;
- }
- qboolean ItemParse_isSaber2( itemDef_t *item )
- {
- extern void UI_SaberLoadParms( void );
- extern qboolean ui_saber_parms_parsed;
- extern void UI_CacheSaberGlowGraphics( void );
- int i;
- if ( !PC_ParseInt(&i) )
- {
- if ( i )
- {
- item->flags |= ITF_ISSABER2;
- UI_CacheSaberGlowGraphics();
- if ( !ui_saber_parms_parsed )
- {
- UI_SaberLoadParms();
- }
- }
- else
- {
- item->flags &= ~ITF_ISSABER2;
- }
- return qtrue;
- }
- return qfalse;
- }
- keywordHash_t itemParseKeywords[] = {
- // {"accept", ItemParse_accept, },
- {"selectNext", ItemParse_selectionNext, },
- {"selectPrev", ItemParse_selectionPrev, },
- {"action", ItemParse_action, },
- // {"addColorRange", ItemParse_addColorRange, },
- {"align", ItemParse_align, },
- // {"appearance_slot", ItemParse_Appearance_slot, },
- {"asset_model", ItemParse_asset_model, },
- {"asset_shader", ItemParse_asset_shader, },
- {"isCharacter", ItemParse_isCharacter, },
- {"isSaber", ItemParse_isSaber, },
- {"isSaber2", ItemParse_isSaber2, },
- {"autowrapped", ItemParse_autowrapped, },
- {"backcolor", ItemParse_backcolor, },
- {"background", ItemParse_background, },
- {"border", ItemParse_border, },
- {"bordercolor", ItemParse_bordercolor, },
- {"bordersize", ItemParse_bordersize, },
- // {"cinematic", ItemParse_cinematic, },
- {"columns", ItemParse_columns, },
- {"cvar", ItemParse_cvar, },
- {"cvarFloat", ItemParse_cvarFloat, },
- {"cvarFloatList", ItemParse_cvarFloatList, },
- {"cvarSubString", ItemParse_cvarsubstring },
- {"cvarStrList", ItemParse_cvarStrList, },
- {"cvarTest", ItemParse_cvarTest, },
- {"decoration", ItemParse_decoration, },
- // {"desctext", ItemParse_descText },
- {"disableCvar", ItemParse_disableCvar, },
- {"doubleclick", ItemParse_doubleClick, },
- {"elementheight", ItemParse_elementheight, },
- {"elementtype", ItemParse_elementtype, },
- {"elementwidth", ItemParse_elementwidth, },
- {"enableCvar", ItemParse_enableCvar, },
- {"feeder", ItemParse_feeder, },
- {"flag", ItemParse_flag, },
- {"focusSound", ItemParse_focusSound, },
- #ifdef _IMMERSION
- {"focusForce", ItemParse_focusForce, },
- #endif // _IMMERSION
- {"font", ItemParse_font, },
- {"forecolor", ItemParse_forecolor, },
- {"group", ItemParse_group, },
- {"hideCvar", ItemParse_hideCvar, },
- {"horizontalscroll",ItemParse_horizontalscroll, },
- {"leaveFocus", ItemParse_leaveFocus, },
- {"maxChars", ItemParse_maxChars, },
- {"maxPaintChars", ItemParse_maxPaintChars, },
- {"model_angle", ItemParse_model_angle, },
- {"model_fovx", ItemParse_model_fovx, },
- {"model_fovy", ItemParse_model_fovy, },
- {"model_origin", ItemParse_model_origin, },
- {"model_rotation", ItemParse_model_rotation, },
- //rww - g2 begin
- {"model_g2mins", ItemParse_model_g2mins, },
- {"model_g2maxs", ItemParse_model_g2maxs, },
- {"model_g2skin", ItemParse_model_g2skin, },
- {"model_g2anim", ItemParse_model_g2anim, },
- //rww - g2 end
- // {"mouseEnter", ItemParse_mouseEnter, },
- // {"mouseEnterText", ItemParse_mouseEnterText, },
- // {"mouseExit", ItemParse_mouseExit, },
- // {"mouseExitText", ItemParse_mouseExitText, },
- {"name", ItemParse_name },
- {"notselectable", ItemParse_notselectable, },
- //JLF
- #ifdef _XBOX
- {"scrollhidden", ItemParse_scrollhidden, },
- #endif
- //JLF END
- {"onFocus", ItemParse_onFocus, },
- // {"outlinecolor", ItemParse_outlinecolor, },
- {"ownerdraw", ItemParse_ownerdraw, },
- {"ownerdrawFlag", ItemParse_ownerdrawFlag, },
- {"rect", ItemParse_rect, },
- {"showCvar", ItemParse_showCvar, },
- {"special", ItemParse_special, },
- {"style", ItemParse_style, },
- {"text", ItemParse_text },
- // {"text2", ItemParse_text2 },
- // {"text2alignx", ItemParse_text2alignx, },
- // {"text2aligny", ItemParse_text2aligny, },
- {"textalign", ItemParse_textalign, },
- {"textalignx", ItemParse_textalignx, },
- {"textaligny", ItemParse_textaligny, },
- {"textscale", ItemParse_textscale, },
- {"textstyle", ItemParse_textstyle, },
- {"type", ItemParse_type, },
- {"visible", ItemParse_visible, },
- {"wrapped", ItemParse_wrapped, },
- // {"invertyesno", ItemParse_invertyesno },
- {"xoffset", ItemParse_xoffset },//for yes/no and multi
- {"selectionshader", ItemParse_selectionShader },
- // Text scroll specific
- {"lineHeight", ItemParse_lineHeight, NULL },
- {NULL, NULL, }
- };
- keywordHash_t *itemParseKeywordHash[KEYWORDHASH_SIZE];
- /*
- ===============
- Item_SetupKeywordHash
- ===============
- */
- void Item_SetupKeywordHash(void)
- {
- int i;
- memset(itemParseKeywordHash, 0, sizeof(itemParseKeywordHash));
- for (i = 0; itemParseKeywords[i].keyword; i++)
- {
- KeywordHash_Add(itemParseKeywordHash, &itemParseKeywords[i]);
- }
- }
- /*
- ===============
- Item_Parse
- ===============
- */
- qboolean Item_Parse(itemDef_t *item)
- {
- keywordHash_t *key;
- const char *token;
- // Brace is handled by MenuParse_ItemDef now, to handle wedge hackery
- /*
- if (PC_ParseString(&token))
- {
- return qfalse;
- }
- if (*token != '{')
- {
- return qfalse;
- }
- */
- while ( 1 )
- {
- if (PC_ParseString(&token))
- {
- PC_ParseWarning("End of file inside menu item");
- return qfalse;
- }
- if (*token == '}')
- {
- /* if (!item->window.name)
- {
- item->window.name = defaultString;
- Com_Printf(S_COLOR_YELLOW"WARNING: Menu item has no name\n");
- }
- if (!item->window.group)
- {
- item->window.group = defaultString;
- Com_Printf(S_COLOR_YELLOW"WARNING: Menu item has no group\n");
- }
- */
- return qtrue;
- }
- key = (keywordHash_s *) KeywordHash_Find(itemParseKeywordHash, token);
- if (!key)
- {
- PC_ParseWarning(va("Unknown item keyword '%s'", token));
- continue;
- }
- if ( !key->func(item) )
- {
- PC_ParseWarning(va("Couldn't parse item keyword '%s'", token));
- return qfalse;
- }
- }
- }
- static void Item_TextScroll_BuildLines ( itemDef_t* item )
- {
- // new asian-aware line breaker... (pasted from elsewhere late @ night, hence aliasing-vars ;-)
- //
- textScrollDef_t* scrollPtr = (textScrollDef_t*) item->typeData;
- const char *psText = item->text; // for copy/paste ease
- int iBoxWidth = item->window.rect.w - SCROLLBAR_SIZE - 10;
- // this could probably be simplified now, but it was converted from something else I didn't originally write,
- // and it works anyway so wtf...
- //
- const char *psCurrentTextReadPos;
- const char *psReadPosAtLineStart;
- const char *psBestLineBreakSrcPos;
- const char *psLastGood_s; // needed if we get a full screen of chars with no punctuation or space (see usage notes)
- qboolean bIsTrailingPunctuation;
- unsigned int uiLetter;
- if (!psText)
- {
- return;
- }
- if (*psText == '@') // string reference
- {
- // trap_SP_GetStringTextString( &psText[1], text, sizeof(text));
- psText = SE_GetString( &psText[1] );
- }
- psCurrentTextReadPos = psText;
- psReadPosAtLineStart = psCurrentTextReadPos;
- psBestLineBreakSrcPos = psCurrentTextReadPos;
- scrollPtr->iLineCount = 0;
- memset((char*)scrollPtr->pLines,0,sizeof(scrollPtr->pLines));
- while (*psCurrentTextReadPos && (scrollPtr->iLineCount < MAX_TEXTSCROLL_LINES) )
- {
- char sLineForDisplay[2048]; // ott
- // construct a line...
- //
- psCurrentTextReadPos = psReadPosAtLineStart;
- sLineForDisplay[0] = '\0';
- while ( *psCurrentTextReadPos )
- {
- int iAdvanceCount;
- psLastGood_s = psCurrentTextReadPos;
- // read letter...
- //
- uiLetter = ui.AnyLanguage_ReadCharFromString(psCurrentTextReadPos, &iAdvanceCount, &bIsTrailingPunctuation);
- psCurrentTextReadPos += iAdvanceCount;
- // concat onto string so far...
- //
- if (uiLetter == 32 && sLineForDisplay[0] == '\0')
- {
- psReadPosAtLineStart++;
- continue; // unless it's a space at the start of a line, in which case ignore it.
- }
- if (uiLetter > 255)
- {
- Q_strcat(sLineForDisplay, sizeof(sLineForDisplay),va("%c%c",uiLetter >> 8, uiLetter & 0xFF));
- }
- else
- {
- Q_strcat(sLineForDisplay, sizeof(sLineForDisplay),va("%c",uiLetter & 0xFF));
- }
- if (uiLetter == '\n')
- {
- // explicit new line...
- //
- sLineForDisplay[ strlen(sLineForDisplay)-1 ] = '\0'; // kill the CR
- psReadPosAtLineStart = psCurrentTextReadPos;
- psBestLineBreakSrcPos = psCurrentTextReadPos;
- // hack it to fit in with this code...
- //
- scrollPtr->pLines[ scrollPtr->iLineCount ] = String_Alloc ( sLineForDisplay );
- break; // print this line
- }
- else
- if ( DC->textWidth( sLineForDisplay, item->textscale, item->font ) >= iBoxWidth )
- {
- // reached screen edge, so cap off string at bytepos after last good position...
- //
- if (uiLetter > 255 && bIsTrailingPunctuation && !ui.Language_UsesSpaces())
- {
- // Special case, don't consider line breaking if you're on an asian punctuation char of
- // a language that doesn't use spaces...
- //
- uiLetter = uiLetter; // breakpoint line only
- }
- else
- {
- if (psBestLineBreakSrcPos == psReadPosAtLineStart)
- {
- // aarrrggh!!!!! we'll only get here is someone has fed in a (probably) garbage string,
- // since it doesn't have a single space or punctuation mark right the way across one line
- // of the screen. So far, this has only happened in testing when I hardwired a taiwanese
- // string into this function while the game was running in english (which should NEVER happen
- // normally). On the other hand I suppose it's entirely possible that some taiwanese string
- // might have no punctuation at all, so...
- //
- psBestLineBreakSrcPos = psLastGood_s; // force a break after last good letter
- }
- sLineForDisplay[ psBestLineBreakSrcPos - psReadPosAtLineStart ] = '\0';
- psReadPosAtLineStart = psCurrentTextReadPos = psBestLineBreakSrcPos;
- // hack it to fit in with this code...
- //
- scrollPtr->pLines[ scrollPtr->iLineCount ] = String_Alloc( sLineForDisplay );
- break; // print this line
- }
- }
- // record last-good linebreak pos... (ie if we've just concat'd a punctuation point (western or asian) or space)
- //
- if (bIsTrailingPunctuation || uiLetter == ' ' || (uiLetter > 255 && !ui.Language_UsesSpaces()))
- {
- psBestLineBreakSrcPos = psCurrentTextReadPos;
- }
- }
- /// arrgghh, this is gettng horrible now...
- //
- if (scrollPtr->pLines[ scrollPtr->iLineCount ] == NULL && strlen(sLineForDisplay))
- {
- // then this is the last line and we've just run out of text, no CR, no overflow etc...
- //
- scrollPtr->pLines[ scrollPtr->iLineCount ] = String_Alloc( sLineForDisplay );
- }
-
- scrollPtr->iLineCount++;
- }
- }
- /*
- ===============
- Item_InitControls
- init's special control types
- ===============
- */
- void Item_InitControls(itemDef_t *item)
- {
- if (item == NULL)
- {
- return;
- }
- if (item->type == ITEM_TYPE_LISTBOX)
- {
- listBoxDef_t *listPtr = (listBoxDef_t*)item->typeData;
- item->cursorPos = 0;
- if (listPtr)
- {
- listPtr->cursorPos = 0;
- listPtr->startPos = 0;
- listPtr->endPos = 0;
- listPtr->cursorPos = 0;
- }
- }
- }
- /*
- =================
- Int_Parse
- =================
- */
- qboolean Int_Parse(const char **p, int *i)
- {
- char *token;
- token = COM_ParseExt(p, qfalse);
- if (token && token[0] != 0)
- {
- *i = atoi(token);
- return qtrue;
- }
- else
- {
- return qfalse;
- }
- }
- /*
- =================
- String_Parse
- =================
- */
- qboolean String_Parse(const char **p, const char **out)
- {
- char *token;
- token = COM_ParseExt(p, qfalse);
- if (token && token[0] != 0)
- {
- *(out) = String_Alloc(token);
- return *(out)!=NULL;
- }
- return qfalse;
- }
- /*
- ===============
- Item_RunScript
- ===============
- */
- void Item_RunScript(itemDef_t *item, const char *s)
- {
- const char *p;
- int i;
- qboolean bRan;
- uiInfo.runScriptItem = item;
- if (item && s && s[0])
- {
- p = s;
- while (1)
- {
- const char *command;
- // expect command then arguments, ; ends command, NULL ends script
- if (!String_Parse(&p, &command))
- {
- return;
- }
- if (command[0] == ';' && command[1] == '\0')
- {
- continue;
- }
- bRan = qfalse;
- for (i = 0; i < scriptCommandCount; i++)
- {
- if (Q_stricmp(command, commandList[i].name) == 0)
- {
- if ( !(commandList[i].handler(item, &p)) )
- {
- return;
- }
- bRan = qtrue;
- break;
- }
- }
- // not in our auto list, pass to handler
- if (!bRan)
- {
- // Allow any script command to fail
- if ( !DC->runScript(&p) )
- {
- break;
- }
- }
- }
- }
- }
- /*
- ===============
- Menu_SetupKeywordHash
- ===============
- */
- void Menu_SetupKeywordHash(void)
- {
- int i;
- memset(menuParseKeywordHash, 0, sizeof(menuParseKeywordHash));
- for (i = 0; menuParseKeywords[i].keyword; i++)
- {
- KeywordHash_Add(menuParseKeywordHash, &menuParseKeywords[i]);
- }
- }
- /*
- ===============
- Menus_ActivateByName
- ===============
- */
- void Menu_HandleMouseMove(menuDef_t *menu, float x, float y);
- menuDef_t *Menus_ActivateByName(const char *p)
- {
- int i;
- menuDef_t *m = NULL;
- menuDef_t *focus = Menu_GetFocused();
- for (i = 0; i < menuCount; i++)
- {
- // Look for the name in the current list of windows
- if (Q_stricmp(Menus[i].window.name, p) == 0)
- {
-
-
- m = &Menus[i];
- Menus_Activate(m);
- if (openMenuCount < MAX_OPEN_MENUS && focus != NULL)
- {
- menuStack[openMenuCount++] = focus;
- }
- }
- else
- {
- Menus[i].window.flags &= ~WINDOW_HASFOCUS;
- }
- }
- if (!m)
- { // A hack so we don't have to load all three mission menus before we know what tier we're on
- if (!Q_stricmp( p, "ingameMissionSelect1" ) )
- {
- UI_LoadMenus("ui/tier1.txt",qfalse);
- Menus_CloseAll();
- Menus_OpenByName("ingameMissionSelect1");
- }
- else if (!Q_stricmp( p, "ingameMissionSelect2" ) )
- {
- UI_LoadMenus("ui/tier2.txt",qfalse);
- Menus_CloseAll();
- Menus_OpenByName("ingameMissionSelect2");
- }
- else if (!Q_stricmp( p, "ingameMissionSelect3" ) )
- {
- UI_LoadMenus("ui/tier3.txt",qfalse);
- Menus_CloseAll();
- Menus_OpenByName("ingameMissionSelect3");
- }
- else
- {
- Com_Printf(S_COLOR_YELLOW"WARNING: Menus_ActivateByName: Unable to find menu '%s'\n",p);
- }
- }
- // First time, show force select instructions
- if (!Q_stricmp( p, "ingameForceSelect" ) )
- {
- int tier_storyinfo = Cvar_VariableIntegerValue( "tier_storyinfo" );
- if (tier_storyinfo==1)
- {
- #ifndef _XBOX
- Menus_OpenByName("ingameForceHelp");
- #endif
- }
- }
- // First time, show weapons select instructions
- if (!Q_stricmp( p, "ingameWpnSelect" ) )
- {
- int tier_storyinfo = Cvar_VariableIntegerValue( "tier_storyinfo" );
- if (tier_storyinfo==1)
- {
- #ifndef _XBOX
- Menus_OpenByName("ingameWpnSelectHelp");
- #endif
- }
- }
- // Want to handle a mouse move on the new menu in case your already over an item
- Menu_HandleMouseMove ( m, DC->cursorx, DC->cursory );
-
- return m;
- }
- /*
- ===============
- Menus_Activate
- ===============
- */
- void Menus_Activate(menuDef_t *menu)
- {
- menu->window.flags |= (WINDOW_HASFOCUS | WINDOW_VISIBLE);
- //JLFCALLOUT MPMOVED
- #ifdef _XBOX
- if (!(menu->window.flags & WINDOW_POPUP)&& menu->fullScreen )
- {
- DC->setCVar("ui_showWmove", "0");
- DC->setCVar("ui_showXrls", "0");
- DC->setCVar("ui_showXctrl", "0");
- DC->setCVar("ui_showXNew", "0");
- DC->setCVar("ui_showXforce", "0");
- DC->setCVar("ui_showXdfrc", "0");
- DC->setCVar("ui_showXcstm", "0");
- DC->setCVar("ui_showXhost", "0");
- DC->setCVar("ui_showXchk", "0");
- DC->setCVar("ui_showYref", "0");
- DC->setCVar("ui_showYdel", "0");
- DC->setCVar("ui_showYsaber", "0");
- DC->setCVar("ui_showYwpn", "0");
- DC->setCVar("ui_showAcallout", "0");
- DC->setCVar("ui_showBcallout", "0");
- DC->setCVar("ui_cancelYScript", "0");
- }
- #endif
- //JLF END
- if (menu->onOpen)
- {
- itemDef_t item;
- item.parent = menu;
- item.window.flags = 0; //err, item is fake here, but we want a valid flag before calling runscript
- Item_RunScript(&item, menu->onOpen);
- if (item.window.flags & WINDOW_SCRIPTWAITING) //in case runscript set waiting, copy it up to the menu
- {
- menu->window.flags |= WINDOW_SCRIPTWAITING;
- menu->window.delayedScript = item.window.delayedScript;
- menu->window.delayTime = item.window.delayTime;
- }
- }
- // menu->appearanceTime = DC->realTime + 1000;
- menu->appearanceTime = 0;
- menu->appearanceCnt = 0;
- }
- typedef struct {
- char *command;
- int id;
- int defaultbind1;
- int defaultbind2;
- int bind1;
- int bind2;
- } bind_t;
- static bind_t g_bindings[] =
- {
- {"invuse", A_ENTER, -1, -1, -1},
- {"force_throw", A_F1, -1, -1, -1},
- {"force_pull", A_F2, -1, -1, -1},
- {"force_speed", A_F3, -1, -1, -1},
- {"force_distract", A_F4, -1, -1, -1},
- {"force_heal", A_F5, -1, -1, -1},
- {"+force_grip", A_F6, -1, -1, -1},
- {"+force_lightning",A_F7, -1, -1, -1},
- //new powers
- {"+force_drain", -1, -1, -1, -1},
- {"force_rage", -1, -1, -1, -1},
- {"force_protect", -1, -1, -1, -1},
- {"force_absorb", -1, -1, -1, -1},
- {"force_sight", -1, -1, -1, -1},
- {"taunt", -1, -1, -1, -1},
- {"+useforce", 'f', -1, -1, -1},
- {"forceprev", 'z', -1, -1, -1},
- {"forcenext", 'x', -1, -1, -1},
- {"use_bacta", -1, -1, -1, -1},
- {"use_seeker", -1, -1, -1, -1},
- {"use_sentry", -1, -1, -1, -1},
- {"use_lightamp_goggles",-1, -1, -1, -1},
- {"use_electrobinoculars",-1, -1, -1, -1},
- {"invnext", -1, -1, -1, -1},
- {"invprev", -1, -1, -1, -1},
- {"invuse", -1, -1, -1, -1},
- {"+speed", A_SHIFT, -1, -1, -1},
- {"+forward", A_CURSOR_UP, -1, -1, -1},
- {"+back", A_CURSOR_DOWN, -1, -1, -1},
- {"+moveleft", ',', -1, -1, -1},
- {"+moveright", '.', -1, -1, -1},
- {"+moveup", 'v', -1, -1, -1},
- {"+movedown", 'c', -1, -1, -1},
- {"+left", A_CURSOR_LEFT, -1, -1, -1},
- {"+right", A_CURSOR_RIGHT, -1, -1, -1},
- {"+strafe", -1, -1, -1, -1},
- {"+lookup", A_PAGE_DOWN, -1, -1, -1},
- {"+lookdown", A_DELETE, -1, -1, -1},
- {"+mlook", '/', -1, -1, -1},
- {"centerview", A_END, -1, -1, -1},
- {"zoom", -1, -1, -1, -1},
- {"weapon 0", -1, -1, -1, -1},
- {"weapon 1", '1', -1, -1, -1},
- {"weapon 2", '2', -1, -1, -1},
- {"weapon 3", '3', -1, -1, -1},
- {"weapon 4", '4', -1, -1, -1},
- {"weapon 5", '5', -1, -1, -1},
- {"weapon 6", '6', -1, -1, -1},
- {"weapon 7", '7', -1, -1, -1},
- {"weapon 8", '8', -1, -1, -1},
- {"weapon 9", '9', -1, -1, -1},
- {"weapon 10", '0', -1, -1, -1},
- {"weapon 11", -1, -1, -1, -1},
- {"weapon 12", -1, -1, -1, -1},
- {"weapon 13", -1, -1, -1, -1},
- {"+attack", A_CTRL, -1, -1, -1},
- {"+altattack", A_ALT, -1, -1, -1},
- {"weapprev", '[', -1, -1, -1},
- {"weapnext", ']', -1, -1, -1},
- {"+use", A_SPACE, -1, -1, -1},
- {"datapad", A_TAB, -1, -1, -1},
- {"save quick", A_F9, -1, -1, -1},
- {"load quick", -1, -1, -1, -1},
- {"load auto", -1, -1, -1, -1},
- {"cg_thirdperson !",'p', -1, -1, -1},
- {"exitview", -1, -1, -1, -1},
- {"uimenu ingameloadmenu", A_F10, -1, -1, -1},
- {"uimenu ingamesavemenu", A_F11, -1, -1, -1},
- {"saberAttackCycle",-1, -1, -1, -1},
- };
- static const int g_bindCount = sizeof(g_bindings) / sizeof(bind_t);
- /*
- =================
- Controls_GetKeyAssignment
- =================
- */
- static void Controls_GetKeyAssignment (char *command, int *twokeys)
- {
- int count;
- int j;
- char b[256];
- twokeys[0] = twokeys[1] = -1;
- count = 0;
- for ( j = 0; j < MAX_KEYS; j++ )
- {
- DC->getBindingBuf( j, b, 256 );
- if ( *b == 0 )
- {
- continue;
- }
- if ( !Q_stricmp( b, command ) )
- {
- twokeys[count] = j;
- count++;
- if (count == 2)
- {
- break;
- }
- }
- }
- }
- /*
- =================
- Controls_GetConfig
- =================
- */
- void Controls_GetConfig( void )
- {
- int i;
- int twokeys[2];
- // iterate each command, get its numeric binding
- for (i=0; i < g_bindCount; i++)
- {
- Controls_GetKeyAssignment(g_bindings[i].command, twokeys);
- g_bindings[i].bind1 = twokeys[0];
- g_bindings[i].bind2 = twokeys[1];
- }
- }
- /*
- ===============
- Item_SetScreenCoords
- ===============
- */
- void Item_SetScreenCoords(itemDef_t *item, float x, float y)
- {
-
- if (item == NULL)
- {
- return;
- }
- if (item->window.border != 0)
- {
- x += item->window.borderSize;
- y += item->window.borderSize;
- }
- item->window.rect.x = x + item->window.rectClient.x;
- item->window.rect.y = y + item->window.rectClient.y;
- item->window.rect.w = item->window.rectClient.w;
- item->window.rect.h = item->window.rectClient.h;
- // force the text rects to recompute
- item->textRect.w = 0;
- item->textRect.h = 0;
- switch ( item->type)
- {
- case ITEM_TYPE_TEXTSCROLL:
- {
- textScrollDef_t *scrollPtr = (textScrollDef_t*)item->typeData;
- if ( scrollPtr )
- {
- scrollPtr->startPos = 0;
- scrollPtr->endPos = 0;
- }
- Item_TextScroll_BuildLines ( item );
- break;
- }
- }
- }
- static void Menu_FreeGhoulItems(menuDef_t *menu)
- {
- int i,j;
- for (i = 0; i < menu->itemCount; i++)
- {
- for (j=0; j < menu->items[i]->ghoul2.size(); j++)
- {
- if ( menu->items[i]->ghoul2[j].mModelindex >= 0)
- {
- DC->g2_RemoveGhoul2Model( menu->items[i]->ghoul2, j );
- }
- }
- (menu->items[i]->ghoul2).clear(); //clear is the public Free so i can actually remove this slot
- }
- }
- /*
- ===============
- Menu_Reset
- ===============
- */
- void Menu_Reset(void)
- {
- //FIXME iterate menus to destoy G2 assets.
- int i;
- for (i = 0; i < menuCount; i++)
- {
- Menu_FreeGhoulItems( &Menus[i] );
- }
- menuCount = 0;
- }
- /*
- ===============
- Menu_UpdatePosition
- ===============
- */
- void Menu_UpdatePosition(menuDef_t *menu)
- {
- int i;
- float x, y;
- if (menu == NULL)
- {
- return;
- }
-
- x = menu->window.rect.x;
- y = menu->window.rect.y;
- if (menu->window.border != 0)
- {
- x += menu->window.borderSize;
- y += menu->window.borderSize;
- }
- for (i = 0; i < menu->itemCount; i++)
- {
- Item_SetScreenCoords(menu->items[i], x, y);
- }
- }
- /*
- ===============
- Menu_PostParse
- ===============
- */
- void Menu_PostParse(menuDef_t *menu)
- {
- if (menu == NULL)
- {
- return;
- }
- if (menu->fullScreen)
- {
- menu->window.rect.x = 0;
- menu->window.rect.y = 0;
- menu->window.rect.w = 640;
- menu->window.rect.h = 480;
- }
- Menu_UpdatePosition(menu);
- }
- /*
- ===============
- Menu_Init
- ===============
- */
- void Menu_Init(menuDef_t *menu)
- {
- memset(menu, 0, sizeof(menuDef_t));
- menu->cursorItem = -1;
- UI_Cursor_Show(qtrue);
- if (DC)
- {
- menu->fadeAmount = DC->Assets.fadeAmount;
- menu->fadeClamp = DC->Assets.fadeClamp;
- menu->fadeCycle = DC->Assets.fadeCycle;
- }
- Window_Init(&menu->window);
- }
- /*
- ===============
- Menu_Parse
- ===============
- */
- qboolean Menu_Parse(char *inbuffer, menuDef_t *menu)
- {
- // pc_token_t token;
- keywordHash_t *key;
- char *token2;
- char * buffer;
- bool nest= false;
- buffer = inbuffer;
- #ifdef _XBOX
- char * includeBuffer;
- #endif
- token2 = PC_ParseExt();
- if (!token2)
- {
- return qfalse;
- }
- if (*token2 != '{')
- {
- PC_ParseWarning("Misplaced {");
- return qfalse;
- }
- while ( 1 )
- {
- token2 = PC_ParseExt();
- if (!token2)
- {
- PC_ParseWarning("End of file inside menu.");
- return qfalse;
- }
- if (*token2 == '}')
- {
- return qtrue;
- }
- #ifdef _XBOX
- //JLFCALLOUT
- char * UI_ParseInclude(const char *menuFile, menuDef_t * menu);
- if (!strcmp (token2, "#include"))
- {
- token2 = PC_ParseExt();
- includeBuffer = UI_ParseInclude(token2, menu );
- //bufferize thetoken2
- nest = true;
- buffer = includeBuffer;
- continue;
- }
- #endif
- if (nest && (*token2 == 0))
- {
- PC_EndParseSession(buffer);
- nest = false;
- continue;
- }
- key = KeywordHash_Find(menuParseKeywordHash, token2);
-
- if (!key)
- {
- PC_ParseWarning(va("Unknown menu keyword %s",token2));
- continue;
- }
- if ( !key->func((itemDef_t*)menu) )
- {
- PC_ParseWarning(va("Couldn't parse menu keyword %s as %s",token2, key->keyword));
- return qfalse;
- }
- }
- }
- /*
- ===============
- Menu_New
- ===============
- */
- void Menu_New(char *buffer)
- {
- menuDef_t *menu = &Menus[menuCount];
- if (menuCount < MAX_MENUS)
- {
- Menu_Init(menu);
- if (Menu_Parse(buffer, menu))
- {
- Menu_PostParse(menu);
- menuCount++;
- }
- }
- }
- /*
- ===============
- Menus_CloseAll
- ===============
- */
- void Menus_CloseAll(void)
- {
- int i;
- for (i = 0; i < menuCount; i++)
- {
- Menu_RunCloseScript ( &Menus[i] );
- Menus[i].window.flags &= ~(WINDOW_HASFOCUS | WINDOW_VISIBLE);
- }
- // Clear the menu stack
- openMenuCount = 0;
- }
- /*
- ===============
- PC_StartParseSession
- ===============
- */
- #ifdef _XBOX
- int PC_StartParseSession(const char *fileName,char **buffer, bool nested)
- #else
- int PC_StartParseSession(const char *fileName,char **buffer)
- #endif
- {
- int len;
- // Try to open file and read it in.
- len = ui.FS_ReadFile( fileName,(void **) buffer );
- // Not there?
- if ( len>0 )
- {
- #ifdef _XBOX
- if (nested)
- parseDataCount = 1;
- else
- #endif
- parseDataCount = 0;
- strncpy(parseData[parseDataCount].fileName, fileName, MAX_QPATH);
- parseData[parseDataCount].bufferStart = *buffer;
- parseData[parseDataCount].bufferCurrent = *buffer;
- #ifdef _XBOX
- COM_BeginParseSession(nested);
- #else
- COM_BeginParseSession();
- #endif
- }
- return len;
- }
- /*
- ===============
- PC_EndParseSession
- ===============
- */
- void PC_EndParseSession(char *buffer)
- {
- parseDataCount--;
- ui.FS_FreeFile( buffer ); //let go of the buffer
- }
- /*
- ===============
- PC_ParseWarning
- ===============
- */
- void PC_ParseWarning(const char *message)
- {
- ui.Printf(S_COLOR_YELLOW "WARNING: %s Line #%d of File '%s'\n", message,parseData[parseDataCount].com_lines,parseData[parseDataCount].fileName);
- }
- char *PC_ParseExt(void)
- {
- return (COM_ParseExt(&parseData[parseDataCount].bufferCurrent, qtrue));
- }
- qboolean PC_ParseString(const char **string)
- {
- int hold;
- hold = COM_ParseString(&parseData[parseDataCount].bufferCurrent,string);
- while (hold==0 && **string == 0)
- {
- hold = COM_ParseString(&parseData[parseDataCount].bufferCurrent,string);
- }
- return(hold);
- }
- qboolean PC_ParseInt(int *number)
- {
- return(COM_ParseInt(&parseData[parseDataCount].bufferCurrent,number));
- }
- qboolean PC_ParseFloat(float *number)
- {
- return(COM_ParseFloat(&parseData[parseDataCount].bufferCurrent,number));
- }
- qboolean PC_ParseColor(vec4_t *color)
- {
- return(COM_ParseVec4(&parseData[parseDataCount].bufferCurrent, color));
- }
- void PC_SkipBracedSection( void )
- {
- SkipBracedSection( &parseData[parseDataCount].bufferCurrent );
- }
- /*
- =================
- Menu_Count
- =================
- */
- int Menu_Count(void)
- {
- return menuCount;
- }
- /*
- =================
- Menu_PaintAll
- =================
- */
- void Menu_PaintAll(void)
- {
- int i;
- if (captureFunc)
- {
- captureFunc(captureData);
- }
- for (i = 0; i < menuCount; i++)
- {
- if (!(Menus[i].window.flags & WINDOW_POPUP || !Menus[i].fullScreen))
- Menu_Paint(&Menus[i], qfalse);
- }
- for (i = 0; i < menuCount; i++)
- {
- if ((Menus[i].window.flags & WINDOW_POPUP || !Menus[i].fullScreen))
- Menu_Paint(&Menus[i], qfalse);
- }
- if (uis.debugMode)
- {
- vec4_t v = {1, 1, 1, 1};
- DC->drawText(5, 25, .75, v, va("(%d,%d)",DC->cursorx,DC->cursory), 0, 0, DC->Assets.qhMediumFont);
- DC->drawText(5, 10, .75, v, va("fps: %f", DC->FPS), 0, 0, DC->Assets.qhMediumFont);
- }
- }
- /*
- =================
- Menu_Paint
- =================
- */
- void Menu_Paint(menuDef_t *menu, qboolean forcePaint)
- {
- int i;
- if (menu == NULL)
- {
- return;
- }
- if (menu->window.flags & WINDOW_SCRIPTWAITING)
- {
- if (DC->realTime > menu->window.delayTime)
- { // Time has elapsed, resume running whatever script we saved
- itemDef_t item;
- item.parent = menu;
- item.window.flags = 0; //clear before calling RunScript
- menu->window.flags &= ~WINDOW_SCRIPTWAITING;
- Item_RunScript(&item, menu->window.delayedScript);
- // Could have hit another delay. Need to hoist from fake item
- if (item.window.flags & WINDOW_SCRIPTWAITING)
- {
- menu->window.flags |= WINDOW_SCRIPTWAITING;
- menu->window.delayedScript = item.window.delayedScript;
- menu->window.delayTime = item.window.delayTime;
- }
- }
- }
- if (!(menu->window.flags & WINDOW_VISIBLE) && !forcePaint)
- {
- return;
- }
- // if (menu->window.ownerDrawFlags && DC->ownerDrawVisible && !DC->ownerDrawVisible(menu->window.ownerDrawFlags))
- // {
- // return;
- // }
-
- if (forcePaint)
- {
- menu->window.flags |= WINDOW_FORCED;
- }
- // draw the background if necessary
- if (menu->fullScreen)
- {
- vec4_t color;
- color[0] = menu->window.backColor[0];
- color[1] = menu->window.backColor[1];
- color[2] = menu->window.backColor[2];
- color[3] = menu->window.backColor[3];
- ui.R_SetColor( color);
- if (menu->window.background==0) // No background shader given? Make it blank
- {
- menu->window.background = uis.whiteShader;
- }
- DC->drawHandlePic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, menu->window.background );
- }
- else if (menu->window.background)
- {
- // this allows a background shader without being full screen
- //UI_DrawHandlePic(menu->window.rect.x, menu->window.rect.y, menu->window.rect.w, menu->window.rect.h, menu->backgroundShader);
- }
- // paint the background and or border
- Window_Paint(&menu->window, menu->fadeAmount, menu->fadeClamp, menu->fadeCycle );
- // Loop through all items for the menu and paint them
- int iSlotsVisible = 0;
- for (i = 0; i < menu->itemCount; i++)
- {
- // if (!menu->items[i]->appearanceSlot)
- // {
- Item_Paint(menu->items[i], qtrue);
- // }
- // else // Timed order of appearance
- // {
- // if (Item_Paint(menu->items[i], qfalse) )
- // {
- // iSlotsVisible++; //It would paint
- // }
- // if (menu->items[i]->appearanceSlot<=menu->appearanceCnt)
- // {
- // Item_Paint(menu->items[i], qtrue);
- // }
- // }
- #ifdef _XBOX
- //JLFCALLOUT
- // if ( menu->items[i]->window.flags & WINDOW_HASFOCUS)
- // {
- // if ( menu->items[i]->type == ITEM_TYPE_BUTTON || menu->onAccept)
- // {
- // }
- // }
- #endif
- }
- if (iSlotsVisible && menu->appearanceTime < DC->realTime && menu->appearanceCnt < menu->itemCount) // Time to show another item
- {
- menu->appearanceTime = DC->realTime + menu->appearanceIncrement;
- menu->appearanceCnt++;
- }
- if (uis.debugMode)
- {
- vec4_t color;
- color[0] = color[2] = color[3] = 1;
- color[1] = 0;
- DC->drawRect(menu->window.rect.x, menu->window.rect.y, menu->window.rect.w, menu->window.rect.h, 1, color);
- }
- }
- /*
- =================
- Item_EnableShowViaCvar
- =================
- */
- qboolean Item_EnableShowViaCvar(itemDef_t *item, int flag)
- {
- if (item && item->enableCvar && *item->enableCvar && item->cvarTest && *item->cvarTest)
- {
- char script[1024];
- const char *p;
- char buff[1024];
- if (item->cvarFlags & CVAR_SUBSTRING)
- {
- const char *val;
- p = item->enableCvar;
- if (!String_Parse(&p, &val))
- {//strip the quotes off
- return (item->cvarFlags & flag) ? qfalse : qtrue;
- }
- Q_strncpyz(buff, val, sizeof(buff), qtrue);
- DC->getCVarString(item->cvarTest, script, sizeof(script));
- p = script;
- }
- else
- {
- DC->getCVarString(item->cvarTest, buff, sizeof(buff));
- Q_strncpyz(script, item->enableCvar, sizeof(script), qtrue);
- p = script;
- }
- while (1)
- {
- const char *val;
- // expect value then ; or NULL, NULL ends list
- if (!String_Parse(&p, &val))
- {
- return (item->cvarFlags & flag) ? qfalse : qtrue;
- }
- if (val[0] == ';' && val[1] == '\0')
- {
- continue;
- }
- // enable it if any of the values are true
- if (item->cvarFlags & flag)
- {
- if (Q_stricmp(buff, val) == 0)
- {
- return qtrue;
- }
- }
- else
- {
- // disable it if any of the values are true
- if (Q_stricmp(buff, val) == 0)
- {
- return qfalse;
- }
- }
- }
- return (item->cvarFlags & flag) ? qfalse : qtrue;
- }
- return qtrue;
- }
- /*
- =================
- Item_SetTextExtents
- =================
- */
- void Item_SetTextExtents(itemDef_t *item, int *width, int *height, const char *text)
- {
- const char *textPtr = (text) ? text : item->text;
- if (textPtr == NULL )
- {
- return;
- }
- *width = item->textRect.w;
- *height = item->textRect.h;
- // keeps us from computing the widths and heights more than once
- if (*width == 0 || (item->type == ITEM_TYPE_OWNERDRAW && item->textalignment == ITEM_ALIGN_CENTER)
- || (item->text && item->text[0]=='@' && item->asset != se_language->modificationCount ) //string package language changed
- )
- {
- int originalWidth;
- originalWidth = DC->textWidth(textPtr, item->textscale, item->font);
- if (item->type == ITEM_TYPE_OWNERDRAW && (item->textalignment == ITEM_ALIGN_CENTER || item->textalignment == ITEM_ALIGN_RIGHT))
- {
- originalWidth += DC->ownerDrawWidth(item->window.ownerDraw, item->textscale);
- }
- else if (item->type == ITEM_TYPE_EDITFIELD && item->textalignment == ITEM_ALIGN_CENTER && item->cvar)
- {
- char buff[256];
- DC->getCVarString(item->cvar, buff, 256);
- originalWidth += DC->textWidth(buff, item->textscale, item->font);
- }
- *width = DC->textWidth(textPtr, item->textscale, item->font);
- *height = DC->textHeight(textPtr, item->textscale, item->font);
- item->textRect.w = *width;
- item->textRect.h = *height;
- item->textRect.x = item->textalignx;
- item->textRect.y = item->textaligny;
- if (item->textalignment == ITEM_ALIGN_RIGHT)
- {
- item->textRect.x = item->textalignx - originalWidth;
- }
- else if (item->textalignment == ITEM_ALIGN_CENTER)
- {
- item->textRect.x = item->textalignx - originalWidth / 2;
- }
- ToWindowCoords(&item->textRect.x, &item->textRect.y, &item->window);
- if (item->text && item->text[0]=='@' )//string package
- {//mark language
- item->asset = se_language->modificationCount;
- }
- }
- }
- /*
- =================
- Item_TextColor
- =================
- */
- void Item_TextColor(itemDef_t *item, vec4_t *newColor)
- {
- vec4_t lowLight;
- const vec4_t greyColor = { .5, .5, .5, 1};
- menuDef_t *parent = (menuDef_t*)item->parent;
- Fade(&item->window.flags, &item->window.foreColor[3], parent->fadeClamp, &item->window.nextTime, parent->fadeCycle, qtrue, parent->fadeAmount);
- if ( !(item->type == ITEM_TYPE_TEXT && item->window.flags & WINDOW_AUTOWRAPPED) && item->window.flags & WINDOW_HASFOCUS)
- {
- memcpy(newColor, &parent->focusColor, sizeof(vec4_t));
- /*
- lowLight[0] = 0.8 * parent->focusColor[0];
- lowLight[1] = 0.8 * parent->focusColor[1];
- lowLight[2] = 0.8 * parent->focusColor[2];
- lowLight[3] = 0.8 * parent->focusColor[3];
- LerpColor(parent->focusColor,lowLight,*newColor,0.5+0.5*sin((float)(DC->realTime / PULSE_DIVISOR)));
- */
- }
- #ifdef _XBOX
- else if (item->textStyle == ITEM_TEXTSTYLE_BLINK )
- {
- lowLight[0] = 0.8 * item->window.foreColor[0];
- lowLight[1] = 0.8 * item->window.foreColor[1];
- lowLight[2] = 0.8 * item->window.foreColor[2];
- lowLight[3] = 0.8 * item->window.foreColor[3];
- LerpColor(parent->focusColor,lowLight,*newColor,0.5+0.5*sin((float)(DC->realTime / PULSE_DIVISOR)));
- }
- #endif//_XBOX
- else
- {
- memcpy(newColor, &item->window.foreColor, sizeof(vec4_t));
- }
- // items can be enabled and disabled based on cvars
- if (item->enableCvar && *item->enableCvar && item->cvarTest && *item->cvarTest)
- {
- if (item->cvarFlags & (CVAR_ENABLE | CVAR_DISABLE) && !Item_EnableShowViaCvar(item, CVAR_ENABLE))
- {
- memcpy(newColor, &parent->disableColor, sizeof(vec4_t));
- }
- }
- if (item->window.flags & WINDOW_INACTIVE)
- {
- memcpy(newColor, &greyColor, sizeof(vec4_t));
- }
- }
- /*
- =================
- Item_Text_Wrapped_Paint
- =================
- */
- void Item_Text_Wrapped_Paint(itemDef_t *item)
- {
- char text[1024];
- const char *p, *start, *textPtr;
- char buff[1024];
- int width, height;
- float x, y;
- vec4_t color;
- // now paint the text and/or any optional images
- // default to left
- if (item->text == NULL)
- {
- if (item->cvar == NULL)
- {
- return;
- }
- else
- {
- DC->getCVarString(item->cvar, text, sizeof(text));
- textPtr = text;
- }
- }
- else
- {
- textPtr = item->text;
- }
- if (*textPtr == '@') // string reference
- {
- textPtr = SE_GetString( &textPtr[1] );
- }
- if (*textPtr == '\0')
- {
- return;
- }
- Item_TextColor(item, &color);
- Item_SetTextExtents(item, &width, &height, textPtr);
- x = item->textRect.x;
- y = item->textRect.y;
- start = textPtr;
- p = strchr(textPtr, '\r');
- while (p && *p)
- {
- strncpy(buff, start, p-start+1);
- buff[p-start] = '\0';
- DC->drawText(x, y, item->textscale, color, buff, 0, item->textStyle, item->font);
- y += height + 5;
- start += p - start + 1;
- p = strchr(p+1, '\r');
- }
- DC->drawText(x, y, item->textscale, color, start, 0, item->textStyle, item->font);
- }
- /*
- =================
- Menu_Paint
- =================
- */
- void Item_Text_Paint(itemDef_t *item)
- {
- char text[1024];
- const char *textPtr;
- int height, width;
- vec4_t color;
- if (item->window.flags & WINDOW_WRAPPED)
- {
- Item_Text_Wrapped_Paint(item);
- return;
- }
- if (item->window.flags & WINDOW_AUTOWRAPPED)
- {
- Item_Text_AutoWrapped_Paint(item);
- return;
- }
- if (item->text == NULL)
- {
- if (item->cvar == NULL)
- {
- return;
- }
- else
- {
- DC->getCVarString(item->cvar, text, sizeof(text));
- textPtr = text;
- }
- }
- else
- {
- textPtr = item->text;
- }
- if (*textPtr == '@') // string reference
- {
- textPtr = SE_GetString( &textPtr[1] );
- }
- // this needs to go here as it sets extents for cvar types as well
- Item_SetTextExtents(item, &width, &height, textPtr);
- if (*textPtr == '\0')
- {
- return;
- }
- Item_TextColor(item, &color);
- DC->drawText(item->textRect.x, item->textRect.y, item->textscale, color, textPtr, 0, item->textStyle, item->font);
- /*
- if (item->text2) // Is there a second line of text?
- {
- textPtr = item->text2;
- if (*textPtr == '@') // string reference
- {
- textPtr = SE_GetString( &textPtr[1] );
- }
- Item_TextColor(item, &color);
- DC->drawText(item->textRect.x + item->text2alignx, item->textRect.y + item->text2aligny, item->textscale, color, textPtr, 0, item->textStyle, item->font);
- }
- */
- }
- /*
- =================
- Item_UpdatePosition
- =================
- */
- // FIXME: consolidate this with nearby stuff
- void Item_UpdatePosition(itemDef_t *item)
- {
- float x, y;
- menuDef_t *menu;
- if (item == NULL || item->parent == NULL)
- {
- return;
- }
- menu = (menuDef_t *) item->parent;
- x = menu->window.rect.x;
- y = menu->window.rect.y;
- if (menu->window.border != 0)
- {
- x += menu->window.borderSize;
- y += menu->window.borderSize;
- }
- Item_SetScreenCoords(item, x, y);
- }
- /*
- =================
- Item_TextField_Paint
- =================
- */
- void Item_TextField_Paint(itemDef_t *item)
- {
- char buff[1024];
- vec4_t newColor, lowLight;
- int offset;
- menuDef_t *parent = (menuDef_t*)item->parent;
- editFieldDef_t *editPtr = (editFieldDef_t*)item->typeData;
- Item_Text_Paint(item);
- buff[0] = '\0';
- if (item->cvar)
- {
- DC->getCVarString(item->cvar, buff, sizeof(buff));
- }
- parent = (menuDef_t*)item->parent;
- if (item->window.flags & WINDOW_HASFOCUS)
- {
- lowLight[0] = 0.8 * parent->focusColor[0];
- lowLight[1] = 0.8 * parent->focusColor[1];
- lowLight[2] = 0.8 * parent->focusColor[2];
- lowLight[3] = 0.8 * parent->focusColor[3];
- LerpColor(parent->focusColor,lowLight,newColor,0.5+0.5*sin((float)(DC->realTime / PULSE_DIVISOR)));
- }
- else
- {
- memcpy(&newColor, &item->window.foreColor, sizeof(vec4_t));
- }
- offset = 8;//(item->text && *item->text) ? 8 : 0;
- if (item->window.flags & WINDOW_HASFOCUS && g_editingField)
- {
- char cursor = DC->getOverstrikeMode() ? '_' : '|';
- DC->drawTextWithCursor(item->textRect.x + item->textRect.w + offset, item->textRect.y, item->textscale, newColor, buff + editPtr->paintOffset, item->cursorPos - editPtr->paintOffset , cursor, /*editPtr->maxPaintChars*/ item->window.rect.w, item->textStyle, item->font);
- }
- else
- {
- DC->drawText(item->textRect.x + item->textRect.w + offset, item->textRect.y, item->textscale, newColor, buff + editPtr->paintOffset, /*editPtr->maxPaintChars*/ item->window.rect.w, item->textStyle, item->font);
- }
- }
- void Item_TextScroll_Paint(itemDef_t *item)
- {
- char cvartext[1024];
- float x, y, size, count;
- int i;
- textScrollDef_t *scrollPtr = (textScrollDef_t*)item->typeData;
- size = item->window.rect.h - 2;
- // Re-arranged this function. Previous version had a plethora of bugs.
- // Still a little iffy - BTO (VV)
- if (item->cvar)
- {
- DC->getCVarString(item->cvar, cvartext, sizeof(cvartext));
- item->text = cvartext;
- }
- Item_TextScroll_BuildLines ( item );
- count = scrollPtr->iLineCount;
- // Just fix position - no scrolbar
- scrollPtr->endPos = scrollPtr->startPos;
- // adjust size for item painting
- size = item->window.rect.h - 2;
- x = item->window.rect.x + item->textalignx + 1;
- y = item->window.rect.y + item->textaligny + 1;
- for (i = scrollPtr->startPos; i < count; i++)
- {
- const char *text;
- text = scrollPtr->pLines[i];
- if (!text)
- {
- continue;
- }
- DC->drawText(x + 4, y, item->textscale, item->window.foreColor, text, 0, item->textStyle, item->font);
- size -= scrollPtr->lineHeight;
- if (size < scrollPtr->lineHeight)
- {
- scrollPtr->drawPadding = scrollPtr->lineHeight - size;
- break;
- }
- scrollPtr->endPos++;
- y += scrollPtr->lineHeight;
- }
- }
- /*
- =================
- Item_ListBox_Paint
- =================
- */
- #define COLOR_MAX 255.0f
- void Item_ListBox_Paint(itemDef_t *item)
- {
- float x, y, size;
- int count, i, thumb;
- qhandle_t image;
- qhandle_t optionalImage;
- listBoxDef_t *listPtr = (listBoxDef_t*)item->typeData;
- //JLF MPMOVED
- int numlines;
- int startPos;
- int i2;
- float sizeWidth, sizeHeight;
- // the listbox is horizontal or vertical and has a fixed size scroll bar going either direction
- // elements are enumerated from the DC and either text or image handles are acquired from the DC as well
- // textscale is used to size the text, textalignx and textaligny are used to size image elements
- // there is no clipping available so only the last completely visible item is painted
- count = DC->feederCount(item->special);
- if (count ==0)
- return;
- //JLFLISTBOX MPMOVED
- #ifdef _XBOX
- if (listPtr->notselectable)
- listPtr->startPos = listPtr->cursorPos;//item->cursorPos;
- // item->cursorPos = listPtr->startPos;
- #endif
- //JLFLISTBOX
- if (listPtr->startPos > (count?count-1:count))
- {//probably changed feeders, so reset
- listPtr->startPos = 0;
- }
- if (item->cursorPos > (count?count-1:count))
- {//probably changed feeders, so reset
- item->cursorPos = 0;
- }
- // default is vertical if horizontal flag is not here
- if (item->window.flags & WINDOW_HORIZONTAL)
- {
- //JLF new variable (code just indented)
- if (!listPtr->scrollhidden)
- {
- // draw scrollbar in bottom of the window
- // bar
- if (Item_ListBox_MaxScroll(item) > 0)
- {
- x = item->window.rect.x + 1;
- y = item->window.rect.y + item->window.rect.h - SCROLLBAR_SIZE - 1;
- DC->drawHandlePic(x, y, SCROLLBAR_SIZE, SCROLLBAR_SIZE, DC->Assets.scrollBarArrowLeft);
- x += SCROLLBAR_SIZE - 1;
- size = item->window.rect.w - (SCROLLBAR_SIZE * 2);
- DC->drawHandlePic(x, y, size+1, SCROLLBAR_SIZE, DC->Assets.scrollBar);
- x += size - 1;
- DC->drawHandlePic(x, y, SCROLLBAR_SIZE, SCROLLBAR_SIZE, DC->Assets.scrollBarArrowRight);
- // thumb
- thumb = Item_ListBox_ThumbDrawPosition(item);//Item_ListBox_ThumbPosition(item);
- if (thumb > x - SCROLLBAR_SIZE - 1)
- {
- thumb = x - SCROLLBAR_SIZE - 1;
- }
- DC->drawHandlePic(thumb, y, SCROLLBAR_SIZE, SCROLLBAR_SIZE, DC->Assets.scrollBarThumb);
- }
- else if (listPtr->startPos > 0)
- {
- listPtr->startPos = 0;
- }
- }
- //JLF end
- //
- listPtr->endPos = listPtr->startPos;
- size = item->window.rect.w - 2;
- // items
- // size contains max available space
- if (listPtr->elementStyle == LISTBOX_IMAGE)
- {
- // fit = 0;
- x = item->window.rect.x + 1;
- y = item->window.rect.y + 1;
- for (i = listPtr->startPos; i < count; i++)
- {
- // always draw at least one
- // which may overdraw the box if it is too small for the element
- image = DC->feederItemImage(item->special, i);
- if (image)
- {
- if (item->window.flags & WINDOW_PLAYERCOLOR)
- {
- vec4_t color;
- color[0] = ui_char_color_red.integer/255.0f;
- color[1] = ui_char_color_green.integer/255.0f;
- color[2] = ui_char_color_blue.integer/255.0f;
- color[3] = 1;
- ui.R_SetColor(color);
- }
- DC->drawHandlePic(x+1, y+1, listPtr->elementWidth - 2, listPtr->elementHeight - 2, image);
- }
- if (i == item->cursorPos)
- {
- DC->drawRect(x, y, listPtr->elementWidth-1, listPtr->elementHeight-1, item->window.borderSize, item->window.borderColor);
- }
- size -= listPtr->elementWidth;
- if (size < listPtr->elementWidth)
- {
- listPtr->drawPadding = size; //listPtr->elementWidth - size;
- break;
- }
- x += listPtr->elementWidth;
- listPtr->endPos++;
- // fit++;
- }
- }
- else
- {
- //
- }
- }
- else //VERTICAL
- {
- //JLF MPMOVED
- numlines = item->window.rect.h / listPtr->elementHeight;
- if (listPtr->endPos +1 >= count)
- {
- //Cvar_Set("ui_downArrow","0");
- }
- else
- {
- //Cvar_Set("ui_downArrow","1");
- }
- if (listPtr->startPos <= 0)
- {
- //Cvar_Set("ui_upArrow","0");
- }
- else
- {
- //Cvar_Set("ui_upArrow","1");
- }
- //JLFEND
- //JLF new variable (code idented with if)
- if (!listPtr->scrollhidden)
- {
- // draw scrollbar to right side of the window
- x = item->window.rect.x + item->window.rect.w - SCROLLBAR_SIZE - 1;
- y = item->window.rect.y + 1;
- DC->drawHandlePic(x, y, SCROLLBAR_SIZE, SCROLLBAR_SIZE, DC->Assets.scrollBarArrowUp);
- y += SCROLLBAR_SIZE - 1;
- listPtr->endPos = listPtr->startPos;
- size = item->window.rect.h - (SCROLLBAR_SIZE * 2);
- DC->drawHandlePic(x, y, SCROLLBAR_SIZE, size+1, DC->Assets.scrollBar);
- y += size - 1;
- DC->drawHandlePic(x, y, SCROLLBAR_SIZE, SCROLLBAR_SIZE, DC->Assets.scrollBarArrowDown);
- // thumb
- thumb = Item_ListBox_ThumbDrawPosition(item);//Item_ListBox_ThumbPosition(item);
- if (thumb > y - SCROLLBAR_SIZE - 1)
- {
- thumb = y - SCROLLBAR_SIZE - 1;
- }
- DC->drawHandlePic(x, thumb, SCROLLBAR_SIZE, SCROLLBAR_SIZE, DC->Assets.scrollBarThumb);
- }
- listPtr->endPos = listPtr->startPos;
- //JLF end
- // adjust size for item painting
- size = item->window.rect.h - 2;
- sizeWidth = item->window.rect.w - 2;
- sizeHeight = item->window.rect.h - 2;
- if (listPtr->elementStyle == LISTBOX_IMAGE)
- {
- // Multiple rows and columns (since it's more than twice as wide as an element)
- if ( item->window.rect.w > (listPtr->elementWidth*2) )
- {
- startPos = listPtr->startPos;
- x = item->window.rect.x + 1;
- y = item->window.rect.y + 1;
- // Next row
- for (i2 = startPos; i2 < count; i2++)
- {
- x = item->window.rect.x + 1;
- sizeWidth = item->window.rect.w - 2;
- // print a row
- for (i = startPos; i < count; i++)
- {
- // always draw at least one
- // which may overdraw the box if it is too small for the element
- image = DC->feederItemImage(item->special, i);
- if (image)
- {
- #ifndef CGAME
- if (item->window.flags & WINDOW_PLAYERCOLOR)
- {
- vec4_t color;
- color[0] = ui_char_color_red.integer/COLOR_MAX;
- color[1] = ui_char_color_green.integer/COLOR_MAX;
- color[2] = ui_char_color_blue.integer/COLOR_MAX;
- color[3] = 1.0f;
- DC->setColor(color);
- }
- #endif
- DC->drawHandlePic(x+1, y+1, listPtr->elementWidth - 2, listPtr->elementHeight - 2, image);
- }
- if (i == item->cursorPos)
- {
- DC->drawRect(x, y, listPtr->elementWidth-1, listPtr->elementHeight-1, item->window.borderSize, item->window.borderColor);
- }
- sizeWidth -= listPtr->elementWidth;
- if (sizeWidth < listPtr->elementWidth)
- {
- listPtr->drawPadding = sizeWidth; //listPtr->elementWidth - size;
- break;
- }
- x += listPtr->elementWidth;
- listPtr->endPos++;
- }
- sizeHeight -= listPtr->elementHeight;
- if (sizeHeight < listPtr->elementHeight)
- {
- listPtr->drawPadding = sizeHeight; //listPtr->elementWidth - size;
- break;
- }
- listPtr->endPos++;
- startPos = listPtr->endPos;
- y += listPtr->elementHeight;
- }
- }
- // single column
-
- else
- {
- // fit = 0;
- x = item->window.rect.x + 1;
- y = item->window.rect.y + 1;
- for (i = listPtr->startPos; i < count; i++)
- {
- // always draw at least one
- // which may overdraw the box if it is too small for the element
- image = DC->feederItemImage(item->special, i);
- if (image)
- {
- DC->drawHandlePic(x+1, y+1, listPtr->elementWidth - 2, listPtr->elementHeight - 2, image);
- }
- if (i == item->cursorPos)
- {
- DC->drawRect(x, y, listPtr->elementWidth - 1, listPtr->elementHeight - 1, item->window.borderSize, item->window.borderColor);
- }
- listPtr->endPos++;
- size -= listPtr->elementHeight;
- if (size < listPtr->elementHeight)
- {
- listPtr->drawPadding = listPtr->elementHeight - size;
- break;
- }
- y += listPtr->elementHeight;
- // fit++;
- }
- }
- }
- else
- {
- x = item->window.rect.x + 1;
- y = item->window.rect.y + 1 - listPtr->elementHeight;
- //JLF MPMOVED
- #ifdef _XBOX
- if ( listPtr->notselectable)
- i = listPtr->startPos - (numlines/2);
- else
- i = listPtr->startPos;
- #else
- i = listPtr->startPos;
- #endif
- int enddisplaynum = i + numlines;
- if (enddisplaynum > count)
- enddisplaynum = count;
- for (; i<enddisplaynum; i++)
- // for (; i < count; i++)
- {
- #ifdef _XBOX // Draw selection bar using custom shader - do it first, so fancy gfx are under text:
- if (i == item->cursorPos && listPtr->selectionShader)
- {
- int barWidth = item->window.rect.w - 4 - (listPtr->scrollhidden ? 0 : SCROLLBAR_SIZE);
- // Crazy math to match the text offset below. Ugh.
- int yOff = DC->textHeight("", item->textscale, item->font);
- yOff = (-yOff) / 2 + (listPtr->elementHeight / 2);
- DC->drawHandlePic(x + 2, y + listPtr->elementHeight + 2 + yOff, barWidth, listPtr->elementHeight, listPtr->selectionShader);
- }
- #endif
- const char *text;
- // always draw at least one
- // which may overdraw the box if it is too small for the element
- if ((!listPtr->notselectable) || i>=0)
- {
- if (listPtr->numColumns > 0)
- {
- int j;
- for (j = 0; j < listPtr->numColumns; j++)
- {
- text = DC->feederItemText(item->special, i, j, &optionalImage);
- if (text[0]=='@')
- {
- text = SE_GetString( &text[1] );
- }
- if (optionalImage >= 0)
- {
- DC->drawHandlePic(x + 4 + listPtr->columnInfo[j].pos, y - 1 + listPtr->elementHeight / 2, listPtr->columnInfo[j].width, listPtr->columnInfo[j].width, optionalImage);
- }
- else if (text)
- {
- vec4_t *color;
- vec4_t newColor;
- menuDef_t *parent = (menuDef_t*)item->parent;
- // Use focus color is it has focus.
- if (i == item->cursorPos)
- {
- if (item->window.flags & WINDOW_HASFOCUS)
- {
- Item_TextColor(item,&newColor);
- color = &newColor;
- }
- else
- color = &parent->focusColor;
- }
- else
- {
- color = &item->window.foreColor;
- }
- int textyOffset = 0;
- int textxOffset = 0;
- //JLF MPMOVED
- #ifdef _XBOX
- float fScaleA = item->textscale;
- textyOffset = DC->textHeight (text, fScaleA, item->font);
- textyOffset *= -1;
- textyOffset /=2;
- textyOffset += listPtr->elementHeight/2;
- // First column, always left justified:
- if( j == 0 )
- {
- textxOffset = 0;
- }
- else if( (j > 0) && (j < listPtr->numColumns - 1) )
- { // Middle columns in those with three or more - centered
- // Half the column width minus half the text width -> centered
- textxOffset = (listPtr->columnInfo[j].width / 2) -
- (DC->textWidth (text, fScaleA, item->font) / 2);
- textxOffset -= 4; // Cancel out the +4 from below
- }
- else if( j == listPtr->numColumns - 1 )
- { // Right most column, right justified
- // Colum width, minus text width -> right aligned
- textxOffset = listPtr->columnInfo[j].width -
- DC->textWidth (text, fScaleA, item->font);
- textxOffset -= 8; // Go 4 pixels from the other border (see below)
- }
- #endif
- DC->drawText(x + 4 + listPtr->columnInfo[j].pos + textxOffset, y + listPtr->elementHeight+ textyOffset, item->textscale, *color, text, listPtr->columnInfo[j].maxChars, item->textStyle, item->font);
- }
- }
- }
- else
- {
- //JLF MPMOVED
- #ifdef _XBOX
- if (i >= 0)
- {
- #endif
- text = DC->feederItemText(item->special, i, 0, &optionalImage);
- int textyOffset = 0;
- float fScaleA = item->textscale;
- textyOffset = DC->textHeight (text, fScaleA, item->font);
- textyOffset *= -1;
- textyOffset /=2;
- textyOffset += listPtr->elementHeight/2;
- if (optionalImage >= 0)
- {
- //DC->drawHandlePic(x + 4 + listPtr->elementHeight, y, listPtr->columnInfo[j].width, listPtr->columnInfo[j].width, optionalImage);
- }
- else if (text)
- {
- DC->drawText(x + 4, y + listPtr->elementHeight + textyOffset, item->textscale, item->window.foreColor, text, 0, item->textStyle, item->font);
- }
- //JLF MPMOVED
- #ifdef _XBOX
- }
- #endif
- }
- }
- // The chosen text
- #ifndef _XBOX
- if (i == item->cursorPos)
- {
- DC->fillRect(x + 2, y + listPtr->elementHeight + 2, item->window.rect.w - SCROLLBAR_SIZE - 4, listPtr->elementHeight+2, item->window.outlineColor);
- }
- #endif
- size -= listPtr->elementHeight;
- if (size < listPtr->elementHeight)
- {
- listPtr->drawPadding = listPtr->elementHeight - size;
- break;
- }
- listPtr->endPos++;
- y += listPtr->elementHeight;
- // fit++;
- }
- }
- }
- }
- char g_nameBind1[32];
- char g_nameBind2[32];
- typedef struct
- {
- char* name;
- float defaultvalue;
- float value;
- } configcvar_t;
- /*
- =================
- BindingFromName
- =================
- */
- void BindingFromName(const char *cvar)
- {
- int i, b1, b2;
- // iterate each command, set its default binding
- for (i=0; i < g_bindCount; i++)
- {
- if (Q_stricmp(cvar, g_bindings[i].command) == 0) {
- b1 = g_bindings[i].bind1;
- if (b1 == -1)
- {
- break;
- }
- DC->keynumToStringBuf( b1, g_nameBind1, sizeof(g_nameBind1) );
- // do NOT do this or it corrupts asian text!!! Q_strupr(g_nameBind1);
- b2 = g_bindings[i].bind2;
- if (b2 != -1)
- {
- DC->keynumToStringBuf( b2, g_nameBind2, sizeof(g_nameBind2) );
- // do NOT do this or it corrupts asian text!!!// Q_strupr(g_nameBind2);
- strcat( g_nameBind1, va(" %s ",SE_GetString("MENUS_KEYBIND_OR" )) );
- strcat( g_nameBind1, g_nameBind2 );
- }
- return;
- }
- }
- strcpy(g_nameBind1, "???");
- }
- /*
- =================
- Item_Bind_Paint
- =================
- */
- void Item_Bind_Paint(itemDef_t *item)
- {
- vec4_t newColor, lowLight;
- float value,textScale,textWidth;
- int maxChars = 0, textHeight,yAdj,startingXPos;
- menuDef_t *parent = (menuDef_t*)item->parent;
- editFieldDef_t *editPtr = (editFieldDef_t*)item->typeData;
- if (editPtr)
- {
- maxChars = editPtr->maxPaintChars;
- }
- value = (item->cvar) ? DC->getCVarValue(item->cvar) : 0;
- if (item->window.flags & WINDOW_HASFOCUS)
- {
- if (g_bindItem == item)
- {
- lowLight[0] = 0.8f * 1.0f;
- lowLight[1] = 0.8f * 0.0f;
- lowLight[2] = 0.8f * 0.0f;
- lowLight[3] = 0.8f * 1.0f;
- }
- else
- {
- lowLight[0] = 0.8f * parent->focusColor[0];
- lowLight[1] = 0.8f * parent->focusColor[1];
- lowLight[2] = 0.8f * parent->focusColor[2];
- lowLight[3] = 0.8f * parent->focusColor[3];
- }
- LerpColor(parent->focusColor,lowLight,newColor,0.5+0.5*sin((float)(DC->realTime / PULSE_DIVISOR)));
- }
- else
- {
- Item_TextColor( item,&newColor);
- }
- if (item->text)
- {
- Item_Text_Paint(item);
- BindingFromName(item->cvar);
- // If the text runs past the limit bring the scale down until it fits.
- textScale = item->textscale;
- textWidth = DC->textWidth(g_nameBind1,(float) textScale, uiInfo.uiDC.Assets.qhMediumFont);
- startingXPos = (item->textRect.x + item->textRect.w + 8);
- while ((startingXPos + textWidth) >= SCREEN_WIDTH)
- {
- textScale -= .05f;
- textWidth = DC->textWidth(g_nameBind1,(float) textScale, uiInfo.uiDC.Assets.qhMediumFont);
- }
- // Try to adjust it's y placement if the scale has changed.
- yAdj = 0;
- if (textScale != item->textscale)
- {
- textHeight = DC->textHeight(g_nameBind1, item->textscale, uiInfo.uiDC.Assets.qhMediumFont);
- yAdj = textHeight - DC->textHeight(g_nameBind1, textScale, uiInfo.uiDC.Assets.qhMediumFont);
- }
- DC->drawText(startingXPos, item->textRect.y + yAdj, textScale, newColor, g_nameBind1, maxChars/*item->textRect.w*/, item->textStyle, item->font);
- }
- else
- {
- DC->drawText(item->textRect.x, item->textRect.y, item->textscale, newColor, (value != 0) ? "FIXME 1" : "FIXME 0", maxChars/*item->textRect.w*/, item->textStyle, item->font);
- }
- }
- void UI_ScaleModelAxis(refEntity_t *ent)
- { // scale the model should we need to
- if (ent->modelScale[0] && ent->modelScale[0] != 1.0f)
- {
- VectorScale( ent->axis[0], ent->modelScale[0] , ent->axis[0] );
- ent->nonNormalizedAxes = qtrue;
- }
- if (ent->modelScale[1] && ent->modelScale[1] != 1.0f)
- {
- VectorScale( ent->axis[1], ent->modelScale[1] , ent->axis[1] );
- ent->nonNormalizedAxes = qtrue;
- }
- if (ent->modelScale[2] && ent->modelScale[2] != 1.0f)
- {
- VectorScale( ent->axis[2], ent->modelScale[2] , ent->axis[2] );
- ent->nonNormalizedAxes = qtrue;
- }
- }
- /*
- =================
- Item_Model_Paint
- =================
- */
- #ifdef _XBOX
- extern int *s_entityWavVol;
- #else
- extern int s_entityWavVol[MAX_GENTITIES]; //from snd_dma.cpp
- #endif
- void UI_TalkingHead(itemDef_t *item)
- {
- // static int facial_blink = DC->realTime + Q_flrand(4000.0, 8000.0);
- static int facial_timer = DC->realTime + Q_flrand(10000.0, 30000.0);
- // static animNumber_t facial_anim = FACE_ALERT;
- int anim = -1;
- //are we blinking?
- /* if (facial_blink < 0)
- { // yes, check if we are we done blinking ?
- if (-(facial_blink) < DC->realTime)
- { // yes, so reset blink timer
- facial_blink = DC->realTime + Q_flrand(4000.0, 8000.0);
- CG_G2SetHeadBlink( cent, qfalse ); //stop the blink
- }
- }
- else // no we aren't blinking
- {
- if (facial_blink < DC->realTime)// but should we start ?
- {
- CG_G2SetHeadBlink( cent, qtrue );
- if (facial_blink == 1)
- {//requested to stay shut by SET_FACEEYESCLOSED
- facial_blink = -(DC->realTime + 99999999.0f);// set blink timer
- }
- else
- {
- facial_blink = -(DC->realTime + 300.0f);// set blink timer
- }
- }
- }
- */
- if (s_entityWavVol[0] > 0) // if we aren't talking, then it will be 0, -1 for talking but paused
- {
- anim = FACE_TALK1 + s_entityWavVol[0]-1;
- if( anim > FACE_TALK4 )
- {
- anim = FACE_TALK4;
- }
- // reset timers so we don't start right away after talking
- facial_timer = DC->realTime + Q_flrand(2000.0, 7000.0);
- }
- else if (s_entityWavVol[0] == -1)
- {// talking, but silent
- anim = FACE_TALK0;
- // reset timers so we don't start right away after talking
- facial_timer = DC->realTime + Q_flrand(2000.0, 7000.0);
- }
- /* else if (s_entityWavVol[0] == 0) //don't anim if in a slient part of speech
- {//not talking
- if (facial_timer < 0) // are animating ?
- { //yes
- if (-(facial_timer) < DC->realTime)// are we done animating ?
- { // yes, reset timer
- facial_timer = DC->realTime + Q_flrand(10000.0, 30000.0);
- }
- else
- { // not yet, so choose anim
- anim = facial_anim;
- }
- }
- else // no we aren't animating
- { // but should we start ?
- if (facial_timer < DC->realTime)
- {//yes
- facial_anim = FACE_ALERT + Q_irand(0,2); //alert, smile, frown
- // set aux timer
- facial_timer = -(DC->realTime + 2000.0);
- anim = facial_anim;
- }
- }
- }//talking
- */
- if (facial_timer < DC->realTime)
- {//restart the base anim
- // modelDef_t *modelPtr = (modelDef_t*)item->typeData;
- //ItemParse_model_g2anim_go( item, "BOTH_STAND5IDLE1" );
- // facial_timer = DC->realTime + Q_flrand(2000.0, 7000.0) + DC->g2hilev_SetAnim(&item->ghoul2[0], "model_root", modelPtr->g2anim, qtrue);
- }
- if (anim != -1)
- {
- DC->g2hilev_SetAnim(&item->ghoul2[0], "face", anim, qfalse);
- }
- }
- /*
- =================
- Item_Model_Paint
- =================
- */
- extern void UI_SaberDrawBlades( itemDef_t *item, vec3_t origin, float curYaw );
- void Item_Model_Paint(itemDef_t *item)
- {
- float x, y, w, h;
- refdef_t refdef;
- refEntity_t ent;
- vec3_t mins, maxs, origin;
- vec3_t angles;
- const modelDef_t *modelPtr = (modelDef_t*)item->typeData;
- if (modelPtr == NULL)
- {
- return;
- }
- // a moves datapad anim is playing
- if (uiInfo.moveAnimTime && (uiInfo.moveAnimTime < uiInfo.uiDC.realTime))
- {
- modelDef_t *modelPtr;
- modelPtr = (modelDef_t*)item->typeData;
- if (modelPtr)
- {
- //HACKHACKHACK: check for any multi-part anim sequences, and play the next anim, if needbe
- switch( modelPtr->g2anim )
- {
- case BOTH_FORCEWALLREBOUND_FORWARD:
- case BOTH_FORCEJUMP1:
- ItemParse_model_g2anim_go( item, animTable[BOTH_FORCEINAIR1].name );
- uiInfo.moveAnimTime = DC->g2hilev_SetAnim(&item->ghoul2[0], "model_root", modelPtr->g2anim, qtrue);
- if ( !uiInfo.moveAnimTime )
- {
- uiInfo.moveAnimTime = 500;
- }
- uiInfo.moveAnimTime += uiInfo.uiDC.realTime;
- break;
- case BOTH_FORCEINAIR1:
- ItemParse_model_g2anim_go( item, animTable[BOTH_FORCELAND1].name );
- uiInfo.moveAnimTime = DC->g2hilev_SetAnim(&item->ghoul2[0], "model_root", modelPtr->g2anim, qtrue);
- uiInfo.moveAnimTime += uiInfo.uiDC.realTime;
- break;
- case BOTH_FORCEWALLRUNFLIP_START:
- ItemParse_model_g2anim_go( item, animTable[BOTH_FORCEWALLRUNFLIP_END].name );
- uiInfo.moveAnimTime = DC->g2hilev_SetAnim(&item->ghoul2[0], "model_root", modelPtr->g2anim, qtrue);
- uiInfo.moveAnimTime += uiInfo.uiDC.realTime;
- break;
- case BOTH_FORCELONGLEAP_START:
- ItemParse_model_g2anim_go( item, animTable[BOTH_FORCELONGLEAP_LAND].name );
- uiInfo.moveAnimTime = DC->g2hilev_SetAnim(&item->ghoul2[0], "model_root", modelPtr->g2anim, qtrue);
- uiInfo.moveAnimTime += uiInfo.uiDC.realTime;
- break;
- case BOTH_KNOCKDOWN3://on front - into force getup
- DC->startLocalSound(uiInfo.uiDC.Assets.datapadmoveJumpSound, CHAN_LOCAL );
- ItemParse_model_g2anim_go( item, animTable[BOTH_FORCE_GETUP_F1].name );
- uiInfo.moveAnimTime = DC->g2hilev_SetAnim(&item->ghoul2[0], "model_root", modelPtr->g2anim, qtrue);
- uiInfo.moveAnimTime += uiInfo.uiDC.realTime;
- break;
- case BOTH_KNOCKDOWN2://on back - kick forward getup
- DC->startLocalSound(uiInfo.uiDC.Assets.datapadmoveJumpSound, CHAN_LOCAL );
- ItemParse_model_g2anim_go( item, animTable[BOTH_GETUP_BROLL_F].name );
- uiInfo.moveAnimTime = DC->g2hilev_SetAnim(&item->ghoul2[0], "model_root", modelPtr->g2anim, qtrue);
- uiInfo.moveAnimTime += uiInfo.uiDC.realTime;
- break;
- case BOTH_KNOCKDOWN1://on back - roll-away
- DC->startLocalSound(uiInfo.uiDC.Assets.datapadmoveRollSound, CHAN_LOCAL );
- ItemParse_model_g2anim_go( item, animTable[BOTH_GETUP_BROLL_R].name );
- uiInfo.moveAnimTime = DC->g2hilev_SetAnim(&item->ghoul2[0], "model_root", modelPtr->g2anim, qtrue);
- uiInfo.moveAnimTime += uiInfo.uiDC.realTime;
- break;
- default:
- ItemParse_model_g2anim_go( item, uiInfo.movesBaseAnim );
- DC->g2hilev_SetAnim(&item->ghoul2[0], "model_root", modelPtr->g2anim, qtrue);
- uiInfo.moveAnimTime = 0;
- break;
- }
- }
- }
- // setup the refdef
- memset( &refdef, 0, sizeof( refdef ) );
- refdef.rdflags = RDF_NOWORLDMODEL;
- AxisClear( refdef.viewaxis );
- x = item->window.rect.x+1;
- y = item->window.rect.y+1;
- w = item->window.rect.w-2;
- h = item->window.rect.h-2;
- refdef.x = x * DC->xscale;
- refdef.y = y * DC->yscale;
- refdef.width = w * DC->xscale;
- refdef.height = h * DC->yscale;
- if (item->flags&ITF_G2VALID)
- { //ghoul2 models don't have bounds, so we have to parse them.
- VectorCopy(modelPtr->g2mins, mins);
- VectorCopy(modelPtr->g2maxs, maxs);
- if (!mins[0] && !mins[1] && !mins[2] &&
- !maxs[0] && !maxs[1] && !maxs[2])
- { //we'll use defaults then I suppose.
- VectorSet(mins, -16, -16, -24);
- VectorSet(maxs, 16, 16, 32);
- }
- }
- else
- {
- DC->modelBounds( item->asset, mins, maxs );
- }
- origin[2] = -0.5 * ( mins[2] + maxs[2] );
- origin[1] = 0.5 * ( mins[1] + maxs[1] );
- refdef.fov_x = (modelPtr->fov_x) ? modelPtr->fov_x : (int)((float)refdef.width / 640.0f * 90.0f);
- refdef.fov_y = (modelPtr->fov_y) ? modelPtr->fov_y : atan2( refdef.height, refdef.width / tan( refdef.fov_x / 360 * M_PI ) ) * ( 360 / M_PI );
- // refdef.fov_x = (modelPtr->fov_x) ? modelPtr->fov_x : refdef.width;
- // refdef.fov_y = (modelPtr->fov_y) ? modelPtr->fov_y : refdef.height;
- // calculate distance so the model nearly fills the box
- float len = 0.5 * ( maxs[2] - mins[2] );
- origin[0] = len / 0.268;
- DC->clearScene();
- refdef.time = DC->realTime;
- // add the model
- memset( &ent, 0, sizeof(ent) );
- // use item storage to track
- float curYaw = modelPtr->angle;
- if (modelPtr->rotationSpeed)
- {
- curYaw += (float)refdef.time/modelPtr->rotationSpeed;
- }
- // if ( item->flags&ITF_ISANYSABER && !(item->flags&ITF_ISCHARACTER) )
- // {//hack to put saber on it's side
- // VectorSet( angles, curYaw, 0, 90 );
- // }
- // else
- if (item->flags&ITF_G2VALID)
- {
- VectorSet( angles, 0, curYaw, 0 );
- }
- else
- {
- // Hack to put the spinning saber logo thing on its side
- VectorSet( angles, curYaw, 0, 90 );
- }
-
- AnglesToAxis( angles, ent.axis );
- if (item->flags&ITF_G2VALID)
- {
- ent.ghoul2 = &item->ghoul2;
- ent.radius = 1000;
- ent.customSkin = modelPtr->g2skin;
- if ( (item->flags&ITF_ISCHARACTER) )
- {
- ent.shaderRGBA[0] = ui_char_color_red.integer;
- ent.shaderRGBA[1] = ui_char_color_green.integer;
- ent.shaderRGBA[2] = ui_char_color_blue.integer;
- ent.shaderRGBA[3] = 255;
- UI_TalkingHead(item);
- }
- if ( item->flags&ITF_ISANYSABER )
- {//UGH, draw the saber blade!
- UI_SaberDrawBlades( item, origin, curYaw );
- }
- }
- else
- {
- ent.hModel = item->asset;
- }
- VectorCopy( origin, ent.origin );
- VectorCopy( ent.origin, ent.oldorigin );
- // Set up lighting
- //VectorCopy( refdef.vieworg, ent.lightingOrigin );
- //ent.renderfx = RF_LIGHTING_ORIGIN | RF_NOSHADOW;
- ent.renderfx = RF_NOSHADOW ;
- #ifndef _XBOX
- ui.R_AddLightToScene(refdef.vieworg, 500, 1, 1, 1); //fixme: specify in menu file!
- #endif
- float oldCull = tr.distanceCull;
- tr.distanceCull = 12000;
- DC->addRefEntityToScene( &ent );
- DC->renderScene( &refdef );
- tr.distanceCull = oldCull;
- }
- /*
- =================
- Item_OwnerDraw_Paint
- =================
- */
- void Item_OwnerDraw_Paint(itemDef_t *item)
- {
- menuDef_t *parent;
- if (item == NULL)
- {
- return;
- }
- parent = (menuDef_t*)item->parent;
- if (DC->ownerDrawItem)
- {
- vec4_t color, lowLight;
- menuDef_t *parent = (menuDef_t*)item->parent;
- Fade(&item->window.flags, &item->window.foreColor[3], parent->fadeClamp, &item->window.nextTime, parent->fadeCycle, qtrue, parent->fadeAmount);
- memcpy(&color, &item->window.foreColor, sizeof(color));
- /*
- if (item->numColors > 0 && DC->getValue)
- {
- // if the value is within one of the ranges then set color to that, otherwise leave at default
- int i;
- float f = DC->getValue(item->window.ownerDraw);
- for (i = 0; i < item->numColors; i++)
- {
- if (f >= item->colorRanges[i].low && f <= item->colorRanges[i].high)
- {
- memcpy(&color, &item->colorRanges[i].color, sizeof(color));
- break;
- }
- }
- }
- */
- if (item->window.flags & WINDOW_HASFOCUS)
- {
- memcpy(color, &parent->focusColor, sizeof(vec4_t));
- /*
- lowLight[0] = 0.8 * parent->focusColor[0];
- lowLight[1] = 0.8 * parent->focusColor[1];
- lowLight[2] = 0.8 * parent->focusColor[2];
- lowLight[3] = 0.8 * parent->focusColor[3];
- LerpColor(parent->focusColor,lowLight,color,0.5+0.5*sin((float)(DC->realTime / PULSE_DIVISOR)));
- */
- }
- else if (item->textStyle == ITEM_TEXTSTYLE_BLINK && !((DC->realTime/BLINK_DIVISOR) & 1))
- {
- lowLight[0] = 0.8 * item->window.foreColor[0];
- lowLight[1] = 0.8 * item->window.foreColor[1];
- lowLight[2] = 0.8 * item->window.foreColor[2];
- lowLight[3] = 0.8 * item->window.foreColor[3];
- LerpColor(item->window.foreColor,lowLight,color,0.5+0.5*sin((float)(DC->realTime / PULSE_DIVISOR)));
- }
- if (item->cvarFlags & (CVAR_ENABLE | CVAR_DISABLE) && !Item_EnableShowViaCvar(item, CVAR_ENABLE))
- {
- memcpy(color, parent->disableColor, sizeof(vec4_t));
- }
-
- if (item->text)
- {
- Item_Text_Paint(item);
- // +8 is an offset kludge to properly align owner draw items that have text combined with them
- DC->ownerDrawItem(item->textRect.x + item->textRect.w + 8, item->window.rect.y, item->window.rect.w, item->window.rect.h, 0, item->textaligny, item->window.ownerDraw, item->window.ownerDrawFlags, item->alignment, item->special, item->textscale, color, item->window.background, item->textStyle, item->font );
- }
- else
- {
- DC->ownerDrawItem(item->window.rect.x, item->window.rect.y, item->window.rect.w, item->window.rect.h, item->textalignx, item->textaligny, item->window.ownerDraw, item->window.ownerDrawFlags, item->alignment, item->special, item->textscale, color, item->window.background, item->textStyle, item->font );
- }
- }
- }
- void Item_YesNo_Paint(itemDef_t *item)
- {
- vec4_t newColor;
- float value;
- menuDef_t *parent = (menuDef_t*)item->parent;
- value = (item->cvar) ? DC->getCVarValue(item->cvar) : 0;
- if (item->window.flags & WINDOW_HASFOCUS)
- {
- memcpy(&newColor, &parent->focusColor, sizeof(vec4_t));
- }
- else
- {
- memcpy(&newColor, &item->window.foreColor, sizeof(vec4_t));
- }
- const char *psYes = SE_GetString( "MENUS_YES" );
- const char *psNo = SE_GetString( "MENUS_NO" );
- const char *yesnovalue;
-
- // if (item->invertYesNo)
- // yesnovalue = (value == 0) ? psYes : psNo;
- // else
- yesnovalue = (value != 0) ? psYes : psNo;
- if (item->text)
- {
- Item_Text_Paint(item);
- //JLF
- #ifdef _XBOX
- if (item->xoffset == 0)
- DC->drawText(item->textRect.x + item->textRect.w + item->xoffset + 8, item->textRect.y, item->textscale, newColor, yesnovalue, 0, item->textStyle, item->font);
- else
- #endif
- DC->drawText(item->textRect.x + item->textRect.w + 8, item->textRect.y, item->textscale, newColor, yesnovalue, 0, item->textStyle, item->font);
- }
- else
- {
- //JLF
- #ifdef _XBOX
- DC->drawText(item->textRect.x + item->xoffset, item->textRect.y, item->textscale, newColor, yesnovalue , 0, item->textStyle, item->font);
- #else
- DC->drawText(item->textRect.x, item->textRect.y, item->textscale, newColor, yesnovalue , 0, item->textStyle, item->font);
- #endif
- }
-
- }
- /*
- =================
- Item_Multi_Paint
- =================
- */
- void Item_Multi_Paint(itemDef_t *item)
- {
- vec4_t newColor;
- const char *text = "";
- menuDef_t *parent = (menuDef_t*)item->parent;
- if (item->window.flags & WINDOW_HASFOCUS)
- {
- memcpy(&newColor, &parent->focusColor, sizeof(vec4_t));
- }
- else
- {
- memcpy(&newColor, &item->window.foreColor, sizeof(vec4_t));
- }
- text = Item_Multi_Setting(item);
- if (*text == '@') // string reference
- {
- text = SE_GetString( &text[1] );
- }
- // How big is the string:
- int textWidth = DC->textWidth( text, item->textscale, item->font );
- if (item->text)
- {
- // Draw the item's label:
- Item_Text_Paint(item);
- int x = item->textRect.x; // Start at left edge of rectangle
- x += item->xoffset; // Add xoffset
- x -= textWidth; // Minus width (to get right-justified)
- x -= 20; // Leave 16 pixels (and slack) for arrow
- // Draw the text:
- DC->drawText( x, item->textRect.y, item->textscale, newColor, text, 0, item->textStyle, item->font );
- // If this item has focus, draw the change arrows two pixels out on either end:
- if (item->window.flags & WINDOW_HASFOCUS)
- {
- qhandle_t arrowShader = ui.R_RegisterShaderNoMip( "gfx/menus/newFront/left_arrow" );
- ui.R_SetColor( NULL );
- int textHeight = DC->textHeight( "", item->textscale, item->font );
- ui.R_DrawStretchPic( x - 20, item->textRect.y + (textHeight/2) - 3, 16, 16, 0, 0, 1, 1, arrowShader );
- ui.R_DrawStretchPic( x + textWidth + 4, item->textRect.y + (textHeight/2) - 3, 16, 16, 1, 1, 0, 0, arrowShader );
- }
- }
- else
- {
- int x = item->window.rect.x; // Start at left edge of window
- x += item->xoffset; // Add xoffset
- if( item->textalignment == ITEM_ALIGN_RIGHT )
- {
- x -= 20; // Leave 16 pixels (and slack) for arrow
- x -= textWidth; // Minus width (for right justified)
- }
- else if( item->textalignment == ITEM_ALIGN_CENTER )
- {
- x -= textWidth / 2; // Minus half-width (for centered)
- }
- // Draw the text:
- DC->drawText( x, item->window.rect.y, item->textscale, newColor, text, 0, item->textStyle, item->font );
- // If this item has focus, draw the change arrows two pixels out on either end:
- if (item->window.flags & WINDOW_HASFOCUS)
- {
- qhandle_t arrowShader = ui.R_RegisterShaderNoMip( "gfx/menus/newFront/left_arrow" );
- ui.R_SetColor( NULL );
- int textHeight = DC->textHeight( "", item->textscale, item->font );
- ui.R_DrawStretchPic( x - 20, item->window.rect.y + (textHeight/2) - 3, 16, 16, 0, 0, 1, 1, arrowShader );
- ui.R_DrawStretchPic( x + textWidth + 4, item->window.rect.y + (textHeight/2) - 3, 16, 16, 1, 1, 0, 0, arrowShader );
- }
- }
- }
- int Item_TextScroll_MaxScroll ( itemDef_t *item )
- {
- textScrollDef_t *scrollPtr = (textScrollDef_t*)item->typeData;
-
- int count = scrollPtr->iLineCount;
- int max = count - (int)(item->window.rect.h / scrollPtr->lineHeight) + 1;
- if (max < 0)
- {
- return 0;
- }
- return max;
- }
- int Item_TextScroll_ThumbPosition ( itemDef_t *item )
- {
- float max, pos, size;
- textScrollDef_t *scrollPtr = (textScrollDef_t*)item->typeData;
- max = Item_TextScroll_MaxScroll ( item );
- size = item->window.rect.h - (SCROLLBAR_SIZE * 2) - 2;
- if (max > 0)
- {
- pos = (size-SCROLLBAR_SIZE) / (float) max;
- }
- else
- {
- pos = 0;
- }
-
- pos *= scrollPtr->startPos;
-
- return item->window.rect.y + 1 + SCROLLBAR_SIZE + pos;
- }
- int Item_TextScroll_ThumbDrawPosition ( itemDef_t *item )
- {
- int min, max;
- if (itemCapture == item)
- {
- min = item->window.rect.y + SCROLLBAR_SIZE + 1;
- max = item->window.rect.y + item->window.rect.h - 2*SCROLLBAR_SIZE - 1;
- if (DC->cursory >= min + SCROLLBAR_SIZE/2 && DC->cursory <= max + SCROLLBAR_SIZE/2)
- {
- return DC->cursory - SCROLLBAR_SIZE/2;
- }
- return Item_TextScroll_ThumbPosition(item);
- }
- return Item_TextScroll_ThumbPosition(item);
- }
- int Item_TextScroll_OverLB ( itemDef_t *item, float x, float y )
- {
- rectDef_t r;
- textScrollDef_t *scrollPtr;
- int thumbstart;
- int count;
- scrollPtr = (textScrollDef_t*)item->typeData;
- count = scrollPtr->iLineCount;
- // Scroll bar isn't drawing so ignore this input
- if ((( scrollPtr->iLineCount * scrollPtr->lineHeight ) <= (item->window.rect.h - 2)) && (item->type == ITEM_TYPE_TEXTSCROLL))
- {
- return 0;
- }
- r.x = item->window.rect.x + item->window.rect.w - SCROLLBAR_SIZE;
- r.y = item->window.rect.y;
- r.h = r.w = SCROLLBAR_SIZE;
- if (Rect_ContainsPoint(&r, x, y))
- {
- return WINDOW_LB_LEFTARROW;
- }
- r.y = item->window.rect.y + item->window.rect.h - SCROLLBAR_SIZE;
- if (Rect_ContainsPoint(&r, x, y))
- {
- return WINDOW_LB_RIGHTARROW;
- }
- thumbstart = Item_TextScroll_ThumbPosition(item);
- r.y = thumbstart;
- if (Rect_ContainsPoint(&r, x, y))
- {
- return WINDOW_LB_THUMB;
- }
- r.y = item->window.rect.y + SCROLLBAR_SIZE;
- r.h = thumbstart - r.y;
- if (Rect_ContainsPoint(&r, x, y))
- {
- return WINDOW_LB_PGUP;
- }
- r.y = thumbstart + SCROLLBAR_SIZE;
- r.h = item->window.rect.y + item->window.rect.h - SCROLLBAR_SIZE;
- if (Rect_ContainsPoint(&r, x, y))
- {
- return WINDOW_LB_PGDN;
- }
- return 0;
- }
- void Item_TextScroll_MouseEnter (itemDef_t *item, float x, float y)
- {
- item->window.flags &= ~(WINDOW_LB_LEFTARROW | WINDOW_LB_RIGHTARROW | WINDOW_LB_THUMB | WINDOW_LB_PGUP | WINDOW_LB_PGDN);
- item->window.flags |= Item_TextScroll_OverLB(item, x, y);
- }
- /*
- =================
- Item_Slider_ThumbPosition
- =================
- */
- int Item_ListBox_ThumbDrawPosition(itemDef_t *item)
- {
- int min, max;
- if (itemCapture == item)
- {
- if (item->window.flags & WINDOW_HORIZONTAL)
- {
- min = item->window.rect.x + SCROLLBAR_SIZE + 1;
- max = item->window.rect.x + item->window.rect.w - 2*SCROLLBAR_SIZE - 1;
- if (DC->cursorx >= min + SCROLLBAR_SIZE/2 && DC->cursorx <= max + SCROLLBAR_SIZE/2)
- {
- return DC->cursorx - SCROLLBAR_SIZE/2;
- }
- else
- {
- return Item_ListBox_ThumbPosition(item);
- }
- }
- else
- {
- min = item->window.rect.y + SCROLLBAR_SIZE + 1;
- max = item->window.rect.y + item->window.rect.h - 2*SCROLLBAR_SIZE - 1;
- if (DC->cursory >= min + SCROLLBAR_SIZE/2 && DC->cursory <= max + SCROLLBAR_SIZE/2)
- {
- return DC->cursory - SCROLLBAR_SIZE/2;
- }
- else
- {
- return Item_ListBox_ThumbPosition(item);
- }
- }
- }
- else
- {
- return Item_ListBox_ThumbPosition(item);
- }
- }
- /*
- =================
- Item_Slider_ThumbPosition
- =================
- */
- float Item_Slider_ThumbPosition(itemDef_t *item)
- {
- float value, range;
- editFieldDef_t *editDef = (editFieldDef_t *) item->typeData;
- if (!editDef || !item->cvar)
- return 0.0f;
- value = DC->getCVarValue(item->cvar);
- if (value < editDef->minVal) {
- value = editDef->minVal;
- } else if (value > editDef->maxVal) {
- value = editDef->maxVal;
- }
- range = editDef->maxVal - editDef->minVal;
- value -= editDef->minVal;
- return value / range;
- }
- /*
- =================
- Item_Slider_Paint
- =================
- */
- void Item_Slider_Paint(itemDef_t *item)
- {
- float x, y, value;
- if (item->text) {
- Item_Text_Paint(item);
- }
- // Offset is to right of the (full) slider:
- x = (item->window.rect.x + item->xoffset) - (SLIDER_WIDTH);
- // And if we drew text, we need to shift vertically to be centered as well:
- y = item->window.rect.y;
- if (item->text)
- y += (DC->textHeight("", item->textscale, item->font) / 2) - 2;
- value = Item_Slider_ThumbPosition(item);
- ui.R_SetColor( NULL );
- ui.R_DrawStretchPic( x, y, SLIDER_WIDTH * value, SLIDER_HEIGHT, 0.0f, 0.0f, value, 1.0f, DC->Assets.sliderBar );
- }
- /*
- =================
- Item_Paint
- =================
- */
- static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
- {
- int xPos,textWidth;
- vec4_t red;
- menuDef_t *parent = (menuDef_t*)item->parent;
- red[0] = red[3] = 1;
- red[1] = red[2] = 0;
- if (item == NULL)
- {
- return qfalse;
- }
- if (item->window.flags & WINDOW_SCRIPTWAITING)
- {
- if (DC->realTime > item->window.delayTime)
- { // Time has elapsed, resume running whatever script we saved
- item->window.flags &= ~WINDOW_SCRIPTWAITING;
- Item_RunScript(item, item->window.delayedScript);
- }
- }
- if (item->window.flags & WINDOW_ORBITING)
- {
- if (DC->realTime > item->window.nextTime)
- {
- float rx, ry, a, c, s, w, h;
- item->window.nextTime = DC->realTime + item->window.offsetTime;
- // translate
- w = item->window.rectClient.w / 2;
- h = item->window.rectClient.h / 2;
- rx = item->window.rectClient.x + w - item->window.rectEffects.x;
- ry = item->window.rectClient.y + h - item->window.rectEffects.y;
- a = (float) (3 * M_PI / 180);
- c = cos(a);
- s = sin(a);
- item->window.rectClient.x = (rx * c - ry * s) + item->window.rectEffects.x - w;
- item->window.rectClient.y = (rx * s + ry * c) + item->window.rectEffects.y - h;
- Item_UpdatePosition(item);
- }
- }
- if (item->window.flags & WINDOW_INTRANSITION)
- {
- if (DC->realTime > item->window.nextTime)
- {
- int done = 0;
- item->window.nextTime = DC->realTime + item->window.offsetTime;
- // transition the x,y
- if (item->window.rectClient.x == item->window.rectEffects.x)
- {
- done++;
- }
- else
- {
- if (item->window.rectClient.x < item->window.rectEffects.x)
- {
- item->window.rectClient.x += item->window.rectEffects2.x;
- if (item->window.rectClient.x > item->window.rectEffects.x)
- {
- item->window.rectClient.x = item->window.rectEffects.x;
- done++;
- }
- }
- else
- {
- item->window.rectClient.x -= item->window.rectEffects2.x;
- if (item->window.rectClient.x < item->window.rectEffects.x)
- {
- item->window.rectClient.x = item->window.rectEffects.x;
- done++;
- }
- }
- }
- if (item->window.rectClient.y == item->window.rectEffects.y)
- {
- done++;
- }
- else
- {
- if (item->window.rectClient.y < item->window.rectEffects.y)
- {
- item->window.rectClient.y += item->window.rectEffects2.y;
- if (item->window.rectClient.y > item->window.rectEffects.y)
- {
- item->window.rectClient.y = item->window.rectEffects.y;
- done++;
- }
- }
- else
- {
- item->window.rectClient.y -= item->window.rectEffects2.y;
- if (item->window.rectClient.y < item->window.rectEffects.y)
- {
- item->window.rectClient.y = item->window.rectEffects.y;
- done++;
- }
- }
- }
- if (item->window.rectClient.w == item->window.rectEffects.w)
- {
- done++;
- }
- else
- {
- if (item->window.rectClient.w < item->window.rectEffects.w)
- {
- item->window.rectClient.w += item->window.rectEffects2.w;
- if (item->window.rectClient.w > item->window.rectEffects.w)
- {
- item->window.rectClient.w = item->window.rectEffects.w;
- done++;
- }
- }
- else
- {
- item->window.rectClient.w -= item->window.rectEffects2.w;
- if (item->window.rectClient.w < item->window.rectEffects.w)
- {
- item->window.rectClient.w = item->window.rectEffects.w;
- done++;
- }
- }
- }
- if (item->window.rectClient.h == item->window.rectEffects.h)
- {
- done++;
- }
- else
- {
- if (item->window.rectClient.h < item->window.rectEffects.h)
- {
- item->window.rectClient.h += item->window.rectEffects2.h;
- if (item->window.rectClient.h > item->window.rectEffects.h)
- {
- item->window.rectClient.h = item->window.rectEffects.h;
- done++;
- }
- }
- else
- {
- item->window.rectClient.h -= item->window.rectEffects2.h;
- if (item->window.rectClient.h < item->window.rectEffects.h)
- {
- item->window.rectClient.h = item->window.rectEffects.h;
- done++;
- }
- }
- }
- Item_UpdatePosition(item);
- if (done == 4)
- {
- item->window.flags &= ~WINDOW_INTRANSITION;
- }
- }
- }
- #ifdef _TRANS3
-
- //JLF begin model transition stuff
- if (item->window.flags & WINDOW_INTRANSITIONMODEL)
- {
- if ( item->type == ITEM_TYPE_MODEL)
- {
- //fields ing modelptr
- // vec3_t g2mins2, g2maxs2, g2minsEffect, g2maxsEffect;
- // float fov_x2, fov_y2, fov_Effectx, fov_Effecty;
- modelDef_t * modelptr = (modelDef_t *)item->typeData;
- if (DC->realTime > item->window.nextTime)
- {
- int done = 0;
- item->window.nextTime = DC->realTime + item->window.offsetTime;
- // transition the x,y,z max
- if (modelptr->g2maxs[0] == modelptr->g2maxs2[0])
- {
- done++;
- }
- else
- {
- if (modelptr->g2maxs[0] < modelptr->g2maxs2[0])
- {
- modelptr->g2maxs[0] += modelptr->g2maxsEffect[0];
- if (modelptr->g2maxs[0] > modelptr->g2maxs2[0])
- {
- modelptr->g2maxs[0] = modelptr->g2maxs2[0];
- done++;
- }
- }
- else
- {
- modelptr->g2maxs[0] -= modelptr->g2maxsEffect[0];
- if (modelptr->g2maxs[0] < modelptr->g2maxs2[0])
- {
- modelptr->g2maxs[0] = modelptr->g2maxs2[0];
- done++;
- }
- }
- }
- //y
- if (modelptr->g2maxs[1] == modelptr->g2maxs2[1])
- {
- done++;
- }
- else
- {
- if (modelptr->g2maxs[1] < modelptr->g2maxs2[1])
- {
- modelptr->g2maxs[1] += modelptr->g2maxsEffect[1];
- if (modelptr->g2maxs[1] > modelptr->g2maxs2[1])
- {
- modelptr->g2maxs[1] = modelptr->g2maxs2[1];
- done++;
- }
- }
- else
- {
- modelptr->g2maxs[1] -= modelptr->g2maxsEffect[1];
- if (modelptr->g2maxs[1] < modelptr->g2maxs2[1])
- {
- modelptr->g2maxs[1] = modelptr->g2maxs2[1];
- done++;
- }
- }
- }
- //z
- if (modelptr->g2maxs[2] == modelptr->g2maxs2[2])
- {
- done++;
- }
- else
- {
- if (modelptr->g2maxs[2] < modelptr->g2maxs2[2])
- {
- modelptr->g2maxs[2] += modelptr->g2maxsEffect[2];
- if (modelptr->g2maxs[2] > modelptr->g2maxs2[2])
- {
- modelptr->g2maxs[2] = modelptr->g2maxs2[2];
- done++;
- }
- }
- else
- {
- modelptr->g2maxs[2] -= modelptr->g2maxsEffect[2];
- if (modelptr->g2maxs[2] < modelptr->g2maxs2[2])
- {
- modelptr->g2maxs[2] = modelptr->g2maxs2[2];
- done++;
- }
- }
- }
- // transition the x,y,z min
- if (modelptr->g2mins[0] == modelptr->g2mins2[0])
- {
- done++;
- }
- else
- {
- if (modelptr->g2mins[0] < modelptr->g2mins2[0])
- {
- modelptr->g2mins[0] += modelptr->g2minsEffect[0];
- if (modelptr->g2mins[0] > modelptr->g2mins2[0])
- {
- modelptr->g2mins[0] = modelptr->g2mins2[0];
- done++;
- }
- }
- else
- {
- modelptr->g2mins[0] -= modelptr->g2minsEffect[0];
- if (modelptr->g2mins[0] < modelptr->g2mins2[0])
- {
- modelptr->g2mins[0] = modelptr->g2mins2[0];
- done++;
- }
- }
- }
- //y
- if (modelptr->g2mins[1] == modelptr->g2mins2[1])
- {
- done++;
- }
- else
- {
- if (modelptr->g2mins[1] < modelptr->g2mins2[1])
- {
- modelptr->g2mins[1] += modelptr->g2minsEffect[1];
- if (modelptr->g2mins[1] > modelptr->g2mins2[1])
- {
- modelptr->g2mins[1] = modelptr->g2mins2[1];
- done++;
- }
- }
- else
- {
- modelptr->g2mins[1] -= modelptr->g2minsEffect[1];
- if (modelptr->g2mins[1] < modelptr->g2mins2[1])
- {
- modelptr->g2mins[1] = modelptr->g2mins2[1];
- done++;
- }
- }
- }
- //z
- if (modelptr->g2mins[2] == modelptr->g2mins2[2])
- {
- done++;
- }
- else
- {
- if (modelptr->g2mins[2] < modelptr->g2mins2[2])
- {
- modelptr->g2mins[2] += modelptr->g2minsEffect[2];
- if (modelptr->g2mins[2] > modelptr->g2mins2[2])
- {
- modelptr->g2mins[2] = modelptr->g2mins2[2];
- done++;
- }
- }
- else
- {
- modelptr->g2mins[2] -= modelptr->g2minsEffect[2];
- if (modelptr->g2mins[2] < modelptr->g2mins2[2])
- {
- modelptr->g2mins[2] = modelptr->g2mins2[2];
- done++;
- }
- }
- }
- //fovx
- if (modelptr->fov_x == modelptr->fov_x2)
- {
- done++;
- }
- else
- {
- if (modelptr->fov_x < modelptr->fov_x2)
- {
- modelptr->fov_x += modelptr->fov_Effectx;
- if (modelptr->fov_x > modelptr->fov_x2)
- {
- modelptr->fov_x = modelptr->fov_x2;
- done++;
- }
- }
- else
- {
- modelptr->fov_x -= modelptr->fov_Effectx;
- if (modelptr->fov_x < modelptr->fov_x2)
- {
- modelptr->fov_x = modelptr->fov_x2;
- done++;
- }
- }
- }
- //fovy
- if (modelptr->fov_y == modelptr->fov_y2)
- {
- done++;
- }
- else
- {
- if (modelptr->fov_y < modelptr->fov_y2)
- {
- modelptr->fov_y += modelptr->fov_Effecty;
- if (modelptr->fov_y > modelptr->fov_y2)
- {
- modelptr->fov_y = modelptr->fov_y2;
- done++;
- }
- }
- else
- {
- modelptr->fov_y -= modelptr->fov_Effecty;
- if (modelptr->fov_y < modelptr->fov_y2)
- {
- modelptr->fov_y = modelptr->fov_y2;
- done++;
- }
- }
- }
- if (done == 5)
- {
- item->window.flags &= ~WINDOW_INTRANSITIONMODEL;
- }
- }
- }
- }
- #endif
- //JLF end transition stuff for models
- if (item->window.ownerDrawFlags && DC->ownerDrawVisible)
- {
- if (!DC->ownerDrawVisible(item->window.ownerDrawFlags))
- {
- item->window.flags &= ~WINDOW_VISIBLE;
- }
- else
- {
- item->window.flags |= WINDOW_VISIBLE;
- }
- }
- if (item->cvarFlags & (CVAR_SHOW | CVAR_HIDE))
- {
- if (!Item_EnableShowViaCvar(item, CVAR_SHOW))
- {
- return qfalse;
- }
- }
-
- if (item->window.flags & WINDOW_TIMEDVISIBLE)
- {
- }
- if (!(item->window.flags & WINDOW_VISIBLE))
- {
- return qfalse;
- }
- if (!bDraw)
- {
- return qtrue;
- }
- //okay to paint
- /*
- //JLFMOUSE
- #ifndef _XBOX
- if (item->window.flags & WINDOW_MOUSEOVER)
- #else
- if (item->window.flags & WINDOW_HASFOCUS)
- #endif
- {
- if (item->descText && !Display_KeyBindPending())
- {
- // Make DOUBLY sure that this item should have desctext.
- #ifndef _XBOX
- // NOTE : we can't just check the mouse position on this, what if we TABBED
- // to the current menu item -- in that case our mouse isn't over the item.
- // Removing the WINDOW_MOUSEOVER flag just prevents the item's OnExit script from running
- // if (!Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory))
- // { // It isn't something that should, because it isn't live anymore.
- // item->window.flags &= ~WINDOW_MOUSEOVER;
- // }
- // else
- #endif
- //END JLFMOUSE
- // items can be enabled and disabled based on cvars
- if( !(item->cvarFlags & (CVAR_ENABLE | CVAR_DISABLE) && !Item_EnableShowViaCvar(item, CVAR_ENABLE)) )
- { // Draw the desctext
- const char *textPtr = item->descText;
- if (*textPtr == '@') // string reference
- {
- textPtr = SE_GetString( &textPtr[1] );
- }
- vec4_t color = {1, 1, 1, 1};
- Item_TextColor(item, &color);
- float fDescScale = parent->descScale ? parent->descScale : 1;
- float fDescScaleCopy = fDescScale;
- while (1)
- {
- // FIXME - add some type of parameter in the menu file like descfont to specify the font for the descriptions for this menu.
- textWidth = DC->textWidth(textPtr, fDescScale, 4); // item->font);
- if (parent->descAlignment == ITEM_ALIGN_RIGHT)
- {
- xPos = parent->descX - textWidth; // Right justify
- }
- else if (parent->descAlignment == ITEM_ALIGN_CENTER)
- {
- xPos = parent->descX - (textWidth/2); // Center justify
- }
- else // Left justify
- {
- xPos = parent->descX;
- }
- if (parent->descAlignment == ITEM_ALIGN_CENTER)
- {
- // only this one will auto-shrink the scale until we eventually fit...
- //
- if (xPos + textWidth > (SCREEN_WIDTH-4)) {
- fDescScale -= 0.001f;
- continue;
- }
- }
- // Try to adjust it's y placement if the scale has changed...
- //
- int iYadj = 0;
- if (fDescScale != fDescScaleCopy)
- {
- int iOriginalTextHeight = DC->textHeight(textPtr, fDescScaleCopy, uiInfo.uiDC.Assets.qhMediumFont);
- iYadj = iOriginalTextHeight - DC->textHeight(textPtr, fDescScale, uiInfo.uiDC.Assets.qhMediumFont);
- }
- // FIXME - add some type of parameter in the menu file like descfont to specify the font for the descriptions for this menu.
- DC->drawText(xPos, parent->descY + iYadj, fDescScale, parent->descColor, textPtr, 0, parent->descTextStyle, 4); //item->font);
- break;
- }
- }
- }
- }
- */
- // paint the rect first..
- Window_Paint(&item->window, parent->fadeAmount , parent->fadeClamp, parent->fadeCycle);
- // Print a box showing the extents of the rectangle, when in debug mode
- if (uis.debugMode)
- {
- vec4_t color;
- color[1] = color[3] = 1;
- color[0] = color[2] = 0;
- DC->drawRect(
- item->window.rect.x,
- item->window.rect.y,
- item->window.rect.w,
- item->window.rect.h,
- 1,
- color);
- }
- //DC->drawRect(item->window.rect.x, item->window.rect.y, item->window.rect.w, item->window.rect.h, 1, red);
- switch (item->type)
- {
- case ITEM_TYPE_OWNERDRAW:
- Item_OwnerDraw_Paint(item);
- break;
- case ITEM_TYPE_TEXT:
- case ITEM_TYPE_BUTTON:
- Item_Text_Paint(item);
- break;
- case ITEM_TYPE_RADIOBUTTON:
- break;
- case ITEM_TYPE_CHECKBOX:
- break;
- case ITEM_TYPE_EDITFIELD:
- case ITEM_TYPE_NUMERICFIELD:
- Item_TextField_Paint(item);
- break;
- case ITEM_TYPE_COMBO:
- break;
- case ITEM_TYPE_LISTBOX:
- Item_ListBox_Paint(item);
- break;
- case ITEM_TYPE_TEXTSCROLL:
- Item_TextScroll_Paint ( item );
- break;
- case ITEM_TYPE_MODEL:
- Item_Model_Paint(item);
- break;
- case ITEM_TYPE_YESNO:
- Item_YesNo_Paint(item);
- break;
- case ITEM_TYPE_MULTI:
- Item_Multi_Paint(item);
- break;
- case ITEM_TYPE_BIND:
- Item_Bind_Paint(item);
- break;
- case ITEM_TYPE_SLIDER:
- Item_Slider_Paint(item);
- break;
- default:
- break;
- }
- return qtrue;
- }
- /*
- =================
- LerpColor
- =================
- */
- void LerpColor(vec4_t a, vec4_t b, vec4_t c, float t)
- {
- int i;
- // lerp and clamp each component
- for (i=0; i<4; i++)
- {
- c[i] = a[i] + t*(b[i]-a[i]);
- if (c[i] < 0)
- {
- c[i] = 0;
- }
- else if (c[i] > 1.0)
- {
- c[i] = 1.0;
- }
- }
- }
- /*
- =================
- Fade
- =================
- */
- void Fade(int *flags, float *f, float clamp, int *nextTime, int offsetTime, qboolean bFlags, float fadeAmount)
- {
- if (*flags & (WINDOW_FADINGOUT | WINDOW_FADINGIN))
- {
- if (DC->realTime > *nextTime)
- {
- *nextTime = DC->realTime + offsetTime;
- if (*flags & WINDOW_FADINGOUT)
- {
- *f -= fadeAmount;
- if (bFlags && *f <= 0.0)
- {
- *flags &= ~(WINDOW_FADINGOUT | WINDOW_VISIBLE);
- }
- }
- else
- {
- *f += fadeAmount;
- if (*f >= clamp)
- {
- *f = clamp;
- if (bFlags)
- {
- *flags &= ~WINDOW_FADINGIN;
- }
- }
- }
- }
- }
- }
- /*
- =================
- GradientBar_Paint
- =================
- */
- void GradientBar_Paint(rectDef_t *rect, vec4_t color)
- {
- // gradient bar takes two paints
- DC->setColor( color );
- DC->drawHandlePic(rect->x, rect->y, rect->w, rect->h, DC->Assets.gradientBar);
- DC->setColor( NULL );
- }
- /*
- =================
- Window_Paint
- =================
- */
- void Window_Paint(Window *w, float fadeAmount, float fadeClamp, float fadeCycle)
- {
- //float bordersize = 0;
- vec4_t color;
- rectDef_t fillRect = w->rect;
- if (uis.debugMode)
- {
- color[0] = color[1] = color[2] = color[3] = 1;
- DC->drawRect(w->rect.x, w->rect.y, w->rect.w, w->rect.h, 1, color);
- }
- if (w == NULL || (w->style == 0 && w->border == 0))
- {
- return;
- }
- if (w->border != 0)
- {
- fillRect.x += w->borderSize;
- fillRect.y += w->borderSize;
- fillRect.w -= w->borderSize + 1;
- fillRect.h -= w->borderSize + 1;
- }
- if (w->style == WINDOW_STYLE_FILLED)
- {
- // box, but possible a shader that needs filled
- if (w->background)
- {
- Fade(&w->flags, &w->backColor[3], fadeClamp, &w->nextTime, fadeCycle, qtrue, fadeAmount);
- DC->setColor(w->backColor);
- DC->drawHandlePic(fillRect.x, fillRect.y, fillRect.w, fillRect.h, w->background);
- DC->setColor(NULL);
- }
- else
- {
- DC->fillRect(fillRect.x, fillRect.y, fillRect.w, fillRect.h, w->backColor);
- }
- }
- else if (w->style == WINDOW_STYLE_GRADIENT)
- {
- GradientBar_Paint(&fillRect, w->backColor);
- // gradient bar
- }
- else if (w->style == WINDOW_STYLE_SHADER)
- {
- if (w->flags & WINDOW_PLAYERCOLOR)
- {
- vec4_t color;
- color[0] = ui_char_color_red.integer/255.0f;
- color[1] = ui_char_color_green.integer/255.0f;
- color[2] = ui_char_color_blue.integer/255.0f;
- color[3] = 1;
- ui.R_SetColor(color);
- }
- else if (w->flags & WINDOW_FORECOLORSET)
- {
- DC->setColor(w->foreColor);
- }
- int rectw = fillRect.w;
- #ifdef _XBOX
- if(glw_state->isWidescreen && cls.state == CA_ACTIVE && !(Menus_AnyFullScreenVisible()))
- {
- if(strcmp(w->name, "screenOverlay") == 0)
- rectw = 720;
- if(strcmp(w->name, "imageboxFill") == 0)
- fillRect.x += 40;
- if(strcmp(w->name, "lineLeft") == 0)
- fillRect.x += 40;
- if(strcmp(w->name, "lineRight") == 0)
- fillRect.x += 40;
- if(strcmp(w->name, "lineTop") == 0)
- fillRect.x += 40;
- if(strcmp(w->name, "lineTitle") == 0)
- fillRect.x += 40;
- if(strcmp(w->name, "lineBottom") == 0)
- fillRect.x += 40;
- if(strcmp(w->name, "acceptButton") == 0)
- fillRect.x += 40;
- }
- #endif
- DC->drawHandlePic(fillRect.x, fillRect.y, rectw, fillRect.h, w->background);
- DC->setColor(NULL);
- }
- if (w->border == WINDOW_BORDER_FULL)
- {
- // full
- // HACK HACK HACK
- if (w->style == WINDOW_STYLE_TEAMCOLOR)
- {
- if (color[0] > 0)
- {
- // red
- color[0] = 1;
- color[1] = color[2] = .5;
- }
- else
- {
- color[2] = 1;
- color[0] = color[1] = .5;
- }
- color[3] = 1;
- DC->drawRect(w->rect.x, w->rect.y, w->rect.w, w->rect.h, w->borderSize, color);
- }
- else
- {
- int rectw = w->rect.w;
- #ifdef _XBOX
- if(glw_state->isWidescreen)
- {
- if(strcmp(w->name, "missionfailed_menu") == 0)
- rectw = 720;
- }
- #endif
- DC->drawRect(w->rect.x, w->rect.y, rectw, w->rect.h, w->borderSize, w->borderColor);
- }
- }
- else if (w->border == WINDOW_BORDER_HORZ)
- {
- // top/bottom
- DC->setColor(w->borderColor);
- DC->drawTopBottom(w->rect.x, w->rect.y, w->rect.w, w->rect.h, w->borderSize);
- DC->setColor( NULL );
- }
- else if (w->border == WINDOW_BORDER_VERT)
- {
- // left right
- DC->setColor(w->borderColor);
- DC->drawSides(w->rect.x, w->rect.y, w->rect.w, w->rect.h, w->borderSize);
- DC->setColor( NULL );
- }
- else if (w->border == WINDOW_BORDER_KCGRADIENT)
- {
- // this is just two gradient bars along each horz edge
- rectDef_t r = w->rect;
- r.h = w->borderSize;
- GradientBar_Paint(&r, w->borderColor);
- r.y = w->rect.y + w->rect.h - 1;
- GradientBar_Paint(&r, w->borderColor);
- }
- }
- /*
- =================
- Display_KeyBindPending
- =================
- */
- qboolean Display_KeyBindPending(void)
- {
- return g_waitingForKey;
- }
- /*
- =================
- ToWindowCoords
- =================
- */
- void ToWindowCoords(float *x, float *y, windowDef_t *window)
- {
- if (window->border != 0)
- {
- *x += window->borderSize;
- *y += window->borderSize;
- }
- *x += window->rect.x;
- *y += window->rect.y;
- }
- /*
- =================
- Item_Text_AutoWrapped_Paint
- =================
- */
- void Item_Text_AutoWrapped_Paint(itemDef_t *item)
- {
- char text[1024];
- const char *p, *textPtr, *newLinePtr;
- char buff[1024];
- int height, len, textWidth, newLine, newLineWidth;
- float y;
- vec4_t color;
- textWidth = 0;
- newLinePtr = NULL;
- if (item->text == NULL)
- {
- if (item->cvar == NULL)
- {
- return;
- }
- else
- {
- DC->getCVarString(item->cvar, text, sizeof(text));
- textPtr = text;
- }
- }
- else
- {
- textPtr = item->text;
- }
- if (*textPtr == '@') // string reference
- {
- textPtr = SE_GetString( &textPtr[1] );
- }
- if (*textPtr == '\0')
- {
- return;
- }
- Item_TextColor(item, &color);
- //Item_SetTextExtents(item, &width, &height, textPtr);
- if (item->value == 0)
- {
- item->value = (int)(0.5 + (float)DC->textWidth(textPtr, item->textscale, item->font) / item->window.rect.w);
- }
- height = DC->textHeight(textPtr, item->textscale, item->font);
- item->special = 0;
- y = item->textaligny;
- len = 0;
- buff[0] = '\0';
- newLine = 0;
- newLineWidth = 0;
- p = textPtr;
- int line = 1;
- while (1) //findmeste (this will break widechar languages)!
- {
- if (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\0')
- {
- newLine = len;
- newLinePtr = p+1;
- newLineWidth = textWidth;
- }
- textWidth = DC->textWidth(buff, item->textscale, 0);
- if ( (newLine && textWidth >= item->window.rect.w - item->textalignx) || *p == '\n' || *p == '\0')
- {
- if (line > item->cursorPos) //scroll
- {
- if (len)
- {
- if (item->textalignment == ITEM_ALIGN_LEFT)
- {
- item->textRect.x = item->textalignx;
- }
- else if (item->textalignment == ITEM_ALIGN_RIGHT)
- {
- item->textRect.x = item->textalignx - newLineWidth;
- }
- else if (item->textalignment == ITEM_ALIGN_CENTER)
- {
- item->textRect.x = item->textalignx - newLineWidth / 2;
- }
- item->textRect.y = y;
- ToWindowCoords(&item->textRect.x, &item->textRect.y, &item->window);
- //
- buff[newLine] = '\0';
- if ( *p && y + height + 4 > item->window.rect.h - height)
- {
- item->special = 1;
- strcat(buff,"...");//uhh, let's render some ellipses
- }
- DC->drawText(item->textRect.x, item->textRect.y, item->textscale, color, buff, 0, item->textStyle, item->font);
- }
- y += height + 4;
- if ( y > item->window.rect.h - height)
- {//reached the bottom of the box, so stop
- break;
- }
- len = 0;
- }
- else
- {
- strcpy(buff,"...");
- len = 3;
- }
- if (*p == '\0')
- { //end of string
- break;
- }
- p = newLinePtr;
- newLine = 0;
- newLineWidth = 0;
- line++;
- }
- buff[len++] = *p++;
- buff[len] = '\0';
- }
- item->textRect = item->window.rect;
- }
- /*
- =================
- Rect_ContainsPoint
- =================
- */
- static qboolean Rect_ContainsPoint(rectDef_t *rect, float x, float y)
- {
- //JLF ignore mouse pointer location
- // return true;
- // END JLF
- if (rect)
- {
- // if ((x > rect->x) && (x < (rect->x + rect->w)) && (y > rect->y) && (y < (rect->y + rect->h)))
- if ((x > rect->x) && (x < (rect->x + rect->w)))
- {
- if ((y > rect->y) && (y < (rect->y + rect->h)))
- {
- return qtrue;
- }
- }
- }
- return qfalse;
- }
- qboolean Item_TextScroll_HandleKey ( itemDef_t *item, int key, qboolean down, qboolean force)
- {
- textScrollDef_t *scrollPtr = (textScrollDef_t*)item->typeData;
- int max;
- int viewmax;
- if (force || (Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory) && item->window.flags & WINDOW_HASFOCUS))
- {
- max = Item_TextScroll_MaxScroll(item);
- viewmax = (item->window.rect.h / scrollPtr->lineHeight);
- if ( key == A_CURSOR_UP || key == A_KP_8 )
- {
- scrollPtr->startPos--;
- if (scrollPtr->startPos < 0)
- {
- scrollPtr->startPos = 0;
- }
- return qtrue;
- }
- if ( key == A_CURSOR_DOWN || key == A_KP_2 )
- {
- scrollPtr->startPos++;
- if (scrollPtr->startPos > max)
- {
- scrollPtr->startPos = max;
- }
- return qtrue;
- }
- // mouse hit
- if (key == A_MOUSE1 || key == A_MOUSE2)
- {
- if (item->window.flags & WINDOW_LB_LEFTARROW)
- {
- scrollPtr->startPos--;
- if (scrollPtr->startPos < 0)
- {
- scrollPtr->startPos = 0;
- }
- }
- else if (item->window.flags & WINDOW_LB_RIGHTARROW)
- {
- // one down
- scrollPtr->startPos++;
- if (scrollPtr->startPos > max)
- {
- scrollPtr->startPos = max;
- }
- }
- else if (item->window.flags & WINDOW_LB_PGUP)
- {
- // page up
- scrollPtr->startPos -= viewmax;
- if (scrollPtr->startPos < 0)
- {
- scrollPtr->startPos = 0;
- }
- }
- else if (item->window.flags & WINDOW_LB_PGDN)
- {
- // page down
- scrollPtr->startPos += viewmax;
- if (scrollPtr->startPos > max)
- {
- scrollPtr->startPos = max;
- }
- }
- else if (item->window.flags & WINDOW_LB_THUMB)
- {
- // Display_SetCaptureItem(item);
- }
- return qtrue;
- }
- if ( key == A_HOME || key == A_KP_7)
- {
- // home
- scrollPtr->startPos = 0;
- return qtrue;
- }
- if ( key == A_END || key == A_KP_1)
- {
- // end
- scrollPtr->startPos = max;
- return qtrue;
- }
- if (key == A_PAGE_UP || key == A_KP_9 )
- {
- scrollPtr->startPos -= viewmax;
- if (scrollPtr->startPos < 0)
- {
- scrollPtr->startPos = 0;
- }
- return qtrue;
- }
- if ( key == A_PAGE_DOWN || key == A_KP_3 )
- {
- scrollPtr->startPos += viewmax;
- if (scrollPtr->startPos > max)
- {
- scrollPtr->startPos = max;
- }
- return qtrue;
- }
- }
- return qfalse;
- }
- /*
- =================
- Item_ListBox_MaxScroll
- =================
- */
- int Item_ListBox_MaxScroll(itemDef_t *item)
- {
- listBoxDef_t *listPtr = (listBoxDef_t*)item->typeData;
- int count = DC->feederCount(item->special);
- int max;
- if (item->window.flags & WINDOW_HORIZONTAL)
- {
- max = count - (item->window.rect.w / listPtr->elementWidth) + 1;
- }
- else
- {
- max = count - (item->window.rect.h / listPtr->elementHeight) + 1;
- }
- if (max < 0)
- {
- return 0;
- }
- return max;
- }
- /*
- =================
- Item_ListBox_ThumbPosition
- =================
- */
- int Item_ListBox_ThumbPosition(itemDef_t *item)
- {
- float max, pos, size;
- listBoxDef_t *listPtr = (listBoxDef_t*)item->typeData;
- max = Item_ListBox_MaxScroll(item);
- if (item->window.flags & WINDOW_HORIZONTAL) {
- size = item->window.rect.w - (SCROLLBAR_SIZE * 2) - 2;
- if (max > 0)
- {
- pos = (size-SCROLLBAR_SIZE) / (float) max;
- }
- else
- {
- pos = 0;
- }
- pos *= listPtr->startPos;
- return item->window.rect.x + 1 + SCROLLBAR_SIZE + pos;
- }
- else
- {
- size = item->window.rect.h - (SCROLLBAR_SIZE * 2) - 2;
- if (max > 0)
- {
- pos = (size-SCROLLBAR_SIZE) / (float) max;
- }
- else
- {
- pos = 0;
- }
- pos *= listPtr->startPos;
- return item->window.rect.y + 1 + SCROLLBAR_SIZE + pos;
- }
- }
- /*
- =================
- Item_ListBox_OverLB
- =================
- */
- int Item_ListBox_OverLB(itemDef_t *item, float x, float y)
- {
- rectDef_t r;
- listBoxDef_t *listPtr;
- int thumbstart;
- int count;
- count = DC->feederCount(item->special);
- listPtr = (listBoxDef_t*)item->typeData;
- if (item->window.flags & WINDOW_HORIZONTAL)
- {
- // check if on left arrow
- r.x = item->window.rect.x;
- r.y = item->window.rect.y + item->window.rect.h - SCROLLBAR_SIZE;
- r.h = r.w = SCROLLBAR_SIZE;
- if (Rect_ContainsPoint(&r, x, y))
- {
- return WINDOW_LB_LEFTARROW;
- }
- // check if on right arrow
- r.x = item->window.rect.x + item->window.rect.w - SCROLLBAR_SIZE;
- if (Rect_ContainsPoint(&r, x, y))
- {
- return WINDOW_LB_RIGHTARROW;
- }
- // check if on thumb
- thumbstart = Item_ListBox_ThumbPosition(item);
- r.x = thumbstart;
- if (Rect_ContainsPoint(&r, x, y))
- {
- return WINDOW_LB_THUMB;
- }
- r.x = item->window.rect.x + SCROLLBAR_SIZE;
- r.w = thumbstart - r.x;
- if (Rect_ContainsPoint(&r, x, y))
- {
- return WINDOW_LB_PGUP;
- }
- r.x = thumbstart + SCROLLBAR_SIZE;
- r.w = item->window.rect.x + item->window.rect.w - SCROLLBAR_SIZE;
- if (Rect_ContainsPoint(&r, x, y))
- {
- return WINDOW_LB_PGDN;
- }
- }
- else
- {
- r.x = item->window.rect.x + item->window.rect.w - SCROLLBAR_SIZE;
- r.y = item->window.rect.y;
- r.h = r.w = SCROLLBAR_SIZE;
- if (Rect_ContainsPoint(&r, x, y))
- {
- return WINDOW_LB_LEFTARROW;
- }
- r.y = item->window.rect.y + item->window.rect.h - SCROLLBAR_SIZE;
- if (Rect_ContainsPoint(&r, x, y))
- {
- return WINDOW_LB_RIGHTARROW;
- }
- thumbstart = Item_ListBox_ThumbPosition(item);
- r.y = thumbstart;
- if (Rect_ContainsPoint(&r, x, y))
- {
- return WINDOW_LB_THUMB;
- }
- r.y = item->window.rect.y + SCROLLBAR_SIZE;
- r.h = thumbstart - r.y;
- if (Rect_ContainsPoint(&r, x, y))
- {
- return WINDOW_LB_PGUP;
- }
- r.y = thumbstart + SCROLLBAR_SIZE;
- r.h = item->window.rect.y + item->window.rect.h - SCROLLBAR_SIZE;
- if (Rect_ContainsPoint(&r, x, y))
- {
- return WINDOW_LB_PGDN;
- }
- }
- return 0;
- }
- /*
- =================
- Item_ListBox_MouseEnter
- =================
- */
- void Item_ListBox_MouseEnter(itemDef_t *item, float x, float y)
- {
- rectDef_t r;
- listBoxDef_t *listPtr = (listBoxDef_t*)item->typeData;
-
- item->window.flags &= ~(WINDOW_LB_LEFTARROW | WINDOW_LB_RIGHTARROW | WINDOW_LB_THUMB | WINDOW_LB_PGUP | WINDOW_LB_PGDN);
- item->window.flags |= Item_ListBox_OverLB(item, x, y);
- if (item->window.flags & WINDOW_HORIZONTAL)
- {
- if (!(item->window.flags & (WINDOW_LB_LEFTARROW | WINDOW_LB_RIGHTARROW | WINDOW_LB_THUMB | WINDOW_LB_PGUP | WINDOW_LB_PGDN)))
- {
- // check for selection hit as we have exausted buttons and thumb
- if (listPtr->elementStyle == LISTBOX_IMAGE)
- {
- r.x = item->window.rect.x;
- r.y = item->window.rect.y;
- r.h = item->window.rect.h - SCROLLBAR_SIZE;
- r.w = item->window.rect.w - listPtr->drawPadding;
- if (Rect_ContainsPoint(&r, x, y))
- {
- listPtr->cursorPos = (int)((x - r.x) / listPtr->elementWidth) + listPtr->startPos;
- if (listPtr->cursorPos > listPtr->endPos)
- {
- listPtr->cursorPos = listPtr->endPos;
- }
- }
- }
- else
- {
- // text hit..
- }
- }
- }
- else if (!(item->window.flags & (WINDOW_LB_LEFTARROW | WINDOW_LB_RIGHTARROW | WINDOW_LB_THUMB | WINDOW_LB_PGUP | WINDOW_LB_PGDN)))
- {
- r.x = item->window.rect.x;
- r.y = item->window.rect.y;
- r.w = item->window.rect.w - SCROLLBAR_SIZE;
- r.h = item->window.rect.h - listPtr->drawPadding;
- if (Rect_ContainsPoint(&r, x, y))
- {
- listPtr->cursorPos = (int)((y - 2 - r.y) / listPtr->elementHeight) + listPtr->startPos;
- if (listPtr->cursorPos > listPtr->endPos)
- {
- listPtr->cursorPos = listPtr->endPos;
- }
- }
- }
- }
- /*
- =================
- Item_MouseEnter
- =================
- */
- void Item_MouseEnter(itemDef_t *item, float x, float y)
- {
- rectDef_t r;
- //JLFMOUSE
- if (item)
- {
- r = item->textRect;
- // r.y -= r.h; // NOt sure why this is here, but I commented it out.
- // in the text rect?
- // items can be enabled and disabled based on cvars
- if (item->cvarFlags & (CVAR_ENABLE | CVAR_DISABLE) && !Item_EnableShowViaCvar(item, CVAR_ENABLE))
- {
- return;
- }
- if (item->cvarFlags & (CVAR_SHOW | CVAR_HIDE) && !Item_EnableShowViaCvar(item, CVAR_SHOW))
- {
- return;
- }
- //JLFMOUSE
- #ifndef _XBOX
- if (Rect_ContainsPoint(&r, x, y))
- #else
- if (item->flags & WINDOW_HASFOCUS)
- #endif
- {
- if (!(item->window.flags & WINDOW_MOUSEOVERTEXT))
- {
- // Item_RunScript(item, item->mouseEnterText);
- item->window.flags |= WINDOW_MOUSEOVERTEXT;
- }
- if (!(item->window.flags & WINDOW_MOUSEOVER))
- {
- // Item_RunScript(item, item->mouseEnter);
- item->window.flags |= WINDOW_MOUSEOVER;
- }
- }
- else
- {
- // not in the text rect
- if (item->window.flags & WINDOW_MOUSEOVERTEXT)
- {
- // if we were
- // Item_RunScript(item, item->mouseExitText);
- item->window.flags &= ~WINDOW_MOUSEOVERTEXT;
- }
- if (!(item->window.flags & WINDOW_MOUSEOVER))
- {
- // Item_RunScript(item, item->mouseEnter);
- item->window.flags |= WINDOW_MOUSEOVER;
- }
- if (item->type == ITEM_TYPE_LISTBOX)
- {
- Item_ListBox_MouseEnter(item, x, y);
- }
- else if ( item->type == ITEM_TYPE_TEXTSCROLL )
- {
- Item_TextScroll_MouseEnter ( item, x, y );
- }
- }
- }
- }
- /*
- =================
- Item_SetFocus
- =================
- */
- // will optionaly set focus to this item
- qboolean Item_SetFocus(itemDef_t *item, float x, float y)
- {
- int i;
- itemDef_t *oldFocus;
- sfxHandle_t *sfx = &DC->Assets.itemFocusSound;
- qboolean playSound = qfalse;
- #ifdef _IMMERSION
- ffHandle_t *ff = &DC->Assets.itemFocusForce;
- qboolean playForce = qfalse;
- #endif // _IMMERSION
- // sanity check, non-null, not a decoration and does not already have the focus
- if (item == NULL || item->window.flags & WINDOW_DECORATION || item->window.flags & WINDOW_HASFOCUS || !(item->window.flags & WINDOW_VISIBLE) || (item->window.flags & WINDOW_INACTIVE))
- {
- return qfalse;
- }
- menuDef_t *parent = (menuDef_t*)item->parent;
- // items can be enabled and disabled based on cvars
- if (item->cvarFlags & (CVAR_ENABLE | CVAR_DISABLE) && !Item_EnableShowViaCvar(item, CVAR_ENABLE))
- {
- return qfalse;
- }
- if (item->cvarFlags & (CVAR_SHOW | CVAR_HIDE) && !Item_EnableShowViaCvar(item, CVAR_SHOW))
- {
- return qfalse;
- }
- oldFocus = Menu_ClearFocus((menuDef_t *) item->parent);
- item->window.flags |= WINDOW_HASFOCUS;
- if (item->onFocus)
- {
- Item_RunScript(item, item->onFocus);
- }
- if (item->focusSound)
- {
- sfx = &item->focusSound;
- }
- playSound = qtrue;
- if (playSound && sfx)
- {
- DC->startLocalSound( *sfx, CHAN_LOCAL_SOUND );
- }
- for (i = 0; i < parent->itemCount; i++)
- {
- if (parent->items[i] == item)
- {
- parent->cursorItem = i;
- break;
- }
- }
- return qtrue;
- }
- /*
- =================
- IsVisible
- =================
- */
- qboolean IsVisible(int flags)
- {
- return (flags & WINDOW_VISIBLE && !(flags & WINDOW_FADINGOUT));
- }
- /*
- =================
- Item_MouseLeave
- =================
- */
- void Item_MouseLeave(itemDef_t *item)
- {
- if (item)
- {
- if (item->window.flags & WINDOW_MOUSEOVERTEXT)
- {
- // Item_RunScript(item, item->mouseExitText);
- item->window.flags &= ~WINDOW_MOUSEOVERTEXT;
- }
- // Item_RunScript(item, item->mouseExit);
- item->window.flags &= ~(WINDOW_LB_RIGHTARROW | WINDOW_LB_LEFTARROW);
- }
- }
- /*
- =================
- Item_SetMouseOver
- =================
- */
- void Item_SetMouseOver(itemDef_t *item, qboolean focus)
- {
- if (item)
- {
- if (focus)
- {
- item->window.flags |= WINDOW_MOUSEOVER;
- }
- else
- {
- item->window.flags &= ~WINDOW_MOUSEOVER;
- }
- }
- }
- extern int gScrollDelta;
- /*
- =================
- Menu_HandleMouseMove
- =================
- */
- void Menu_HandleMouseMove(menuDef_t *menu, float x, float y)
- {
- //JLF used exclusively for textscroll items
- #ifdef _XBOX
- if (!menu)
- return;
- itemDef_t * item;
- int i, itemCount;
- itemCount = menu->itemCount;
- textScrollDef_t *scrollPtr;
- if (menu->window.flags && WINDOW_HASFOCUS)
- {
- for( i = 0; i < itemCount ;i++)
- {
- item = menu->items[i];
- if (item->type != ITEM_TYPE_TEXTSCROLL)
- continue;
- if (item->cvarFlags & (CVAR_ENABLE | CVAR_DISABLE) && !Item_EnableShowViaCvar(item, CVAR_ENABLE))
- continue;
- if (item->cvarFlags & (CVAR_SHOW | CVAR_HIDE) && !Item_EnableShowViaCvar(item, CVAR_SHOW))
- continue;
- if ( !(item->window.flags & WINDOW_VISIBLE) )
- continue;
- scrollPtr = (textScrollDef_t*)item->typeData;
- if (gScrollDelta >0)
- {
- if (scrollPtr->endPos < scrollPtr->iLineCount-1)
- {
- scrollPtr->startPos+= gScrollDelta;
- }
- }
- else if (gScrollDelta <0)
- {
- if(scrollPtr->startPos > 0)
- {
- scrollPtr->startPos+=gScrollDelta;
- }
- }
- if ((scrollPtr->endPos +1 >= scrollPtr->iLineCount) || (scrollPtr->endPos == 0))
- {
- Cvar_Set("ui_downArrow","0");
- }
- else
- {
- Cvar_Set("ui_downArrow","1");
- }
- if (scrollPtr->startPos <= 0)
- {
- Cvar_Set("ui_upArrow","0");
- }
- else
- {
- Cvar_Set("ui_upArrow","1");
- }
- }
- }
- #endif
- return ;
- }
- /*
- =================
- Display_MouseMove
- =================
- */
- qboolean Display_MouseMove(void *p, int x, int y)
- {
- //JLFMOUSE AGAIN I THINK THIS SHOULD BE MOOT
-
- int i;
- menuDef_t *menu = (menuDef_t *) p;
- if (menu == NULL)
- {
- menu = Menu_GetFocused();
- if (menu)
- {
- if (menu->window.flags & WINDOW_POPUP)
- {
- Menu_HandleMouseMove(menu, x, y);
- return qtrue;
- }
- }
- for (i = 0; i < menuCount; i++)
- {
- Menu_HandleMouseMove(&Menus[i], x, y);
- }
- }
- else
- {
- menu->window.rect.x += x;
- menu->window.rect.y += y;
- Menu_UpdatePosition(menu);
- }
- return qtrue;
- }
- /*
- =================
- Menus_AnyFullScreenVisible
- =================
- */
- qboolean Menus_AnyFullScreenVisible(void)
- {
- int i;
- for (i = 0; i < menuCount; i++)
- {
- if (Menus[i].window.flags & WINDOW_VISIBLE && Menus[i].fullScreen)
- {
- return qtrue;
- }
- }
- return qfalse;
- }
- /*
- =================
- BindingIDFromName
- =================
- */
- int BindingIDFromName(const char *name)
- {
- int i;
- for (i=0; i < g_bindCount; i++)
- {
- if (Q_stricmp(name, g_bindings[i].command) == 0)
- {
- return i;
- }
- }
- return -1;
- }
- /*
- =================
- Controls_SetConfig
- =================
- */
- void Controls_SetConfig(qboolean restart)
- {
- int i;
- // iterate each command, get its numeric binding
- for (i=0; i < g_bindCount; i++)
- {
- if (g_bindings[i].bind1 != -1)
- {
- DC->setBinding( g_bindings[i].bind1, g_bindings[i].command );
- if (g_bindings[i].bind2 != -1)
- DC->setBinding( g_bindings[i].bind2, g_bindings[i].command );
- }
- }
- //if ( s_controls.invertmouse.curvalue )
- // DC->setCVar("m_pitch", va("%f),-fabs( DC->getCVarValue( "m_pitch" ) ) );
- //else
- // trap_Cvar_SetValue( "m_pitch", fabs( trap_Cvar_VariableValue( "m_pitch" ) ) );
- //trap_Cvar_SetValue( "m_filter", s_controls.smoothmouse.curvalue );
- //trap_Cvar_SetValue( "cl_run", s_controls.alwaysrun.curvalue );
- //trap_Cvar_SetValue( "cg_autoswitch", s_controls.autoswitch.curvalue );
- //trap_Cvar_SetValue( "sensitivity", s_controls.sensitivity.curvalue );
- //trap_Cvar_SetValue( "in_joystick", s_controls.joyenable.curvalue );
- //trap_Cvar_SetValue( "joy_threshold", s_controls.joythreshold.curvalue );
- //trap_Cvar_SetValue( "cl_freelook", s_controls.freelook.curvalue );
- //
- // DC->executeText(EXEC_APPEND, "in_restart\n");
- // ^--this is bad, it shows the cursor during map load, if you need to, add it as an exec cmd to use_joy or something.
- }
- void Item_Bind_Ungrey(itemDef_t *item)
- {
- menuDef_t *menu;
- int i;
- menu = (menuDef_t *) item->parent;
- for (i=0;i<menu->itemCount;++i)
- {
- if (menu->items[i] == item)
- {
- continue;
- }
- menu->items[i]->window.flags &= ~WINDOW_INACTIVE;
- }
- }
- /*
- =================
- Item_Bind_HandleKey
- =================
- */
- qboolean Item_Bind_HandleKey(itemDef_t *item, int key, qboolean down)
- {
- int id;
- int i;
- menuDef_t *menu;
- if (key == A_MOUSE1 && Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory) && !g_waitingForKey)
- {
- if (down)
- {
- g_waitingForKey = qtrue;
- g_bindItem = item;
- // Set all others in the menu to grey
- menu = (menuDef_t *) item->parent;
- for (i=0;i<menu->itemCount;++i)
- {
- if (menu->items[i] == item)
- {
- continue;
- }
- menu->items[i]->window.flags |= WINDOW_INACTIVE;
- }
- }
- return qtrue;
- }
- else if (key == A_ENTER && !g_waitingForKey)
- {
- if (down)
- {
- g_waitingForKey = qtrue;
- g_bindItem = item;
- // Set all others in the menu to grey
- menu = (menuDef_t *) item->parent;
- for (i=0;i<menu->itemCount;++i)
- {
- if (menu->items[i] == item)
- {
- continue;
- }
- menu->items[i]->window.flags |= WINDOW_INACTIVE;
- }
- }
- return qtrue;
- }
- else
- {
- if (!g_waitingForKey || g_bindItem == NULL)
- {
- return qfalse;
- }
- if (key & K_CHAR_FLAG)
- {
- return qtrue;
- }
- switch (key)
- {
- case A_ESCAPE:
- g_waitingForKey = qfalse;
- Item_Bind_Ungrey(item);
- return qtrue;
-
- case A_BACKSPACE:
- id = BindingIDFromName(item->cvar);
- if (id != -1)
- {
- DC->setBinding( g_bindings[id].bind1, "" );
- DC->setBinding( g_bindings[id].bind2, "" );
- g_bindings[id].bind1 = -1;
- g_bindings[id].bind2 = -1;
- }
- Controls_SetConfig(qtrue);
- g_waitingForKey = qfalse;
- g_bindItem = NULL;
- Item_Bind_Ungrey(item);
- return qtrue;
- break;
- case '`':
- return qtrue;
- }
- }
- // Is the same key being bound to something else?
- if (key != -1)
- {
- for (i=0; i < g_bindCount; i++)
- {
- // The second binding matches the key
- if (g_bindings[i].bind2 == key)
- {
- g_bindings[i].bind2 = -1; // NULL it out
- }
- if (g_bindings[i].bind1 == key)
- {
- g_bindings[i].bind1 = g_bindings[i].bind2;
- g_bindings[i].bind2 = -1;
- }
- }
- }
- id = BindingIDFromName(item->cvar);
- if (id != -1)
- {
- if (key == -1)
- {
- if( g_bindings[id].bind1 != -1 )
- {
- DC->setBinding( g_bindings[id].bind1, "" );
- g_bindings[id].bind1 = -1;
- }
- if( g_bindings[id].bind2 != -1 )
- {
- DC->setBinding( g_bindings[id].bind2, "" );
- g_bindings[id].bind2 = -1;
- }
- }
- else if (g_bindings[id].bind1 == -1)
- {
- g_bindings[id].bind1 = key;
- }
- else if (g_bindings[id].bind1 != key && g_bindings[id].bind2 == -1)
- {
- g_bindings[id].bind2 = key;
- }
- else
- {
- DC->setBinding( g_bindings[id].bind1, "" );
- DC->setBinding( g_bindings[id].bind2, "" );
- g_bindings[id].bind1 = key;
- g_bindings[id].bind2 = -1;
- }
- }
- Controls_SetConfig(qtrue);
- g_waitingForKey = qfalse;
- Item_Bind_Ungrey(item);
- return qtrue;
- }
- /*
- =================
- Menu_SetNextCursorItem
- =================
- */
- itemDef_t *Menu_SetNextCursorItem(menuDef_t *menu)
- {
- qboolean wrapped = qfalse;
- int oldCursor = menu->cursorItem;
- if (menu->cursorItem == -1)
- {
- menu->cursorItem = 0;
- wrapped = qtrue;
- }
- while (menu->cursorItem < menu->itemCount)
- {
- menu->cursorItem++;
- if (menu->cursorItem >= menu->itemCount && !wrapped)
- {
- wrapped = qtrue;
- menu->cursorItem = 0;
- }
- if (Item_SetFocus(menu->items[menu->cursorItem], DC->cursorx, DC->cursory))
- {
- Menu_HandleMouseMove(menu, menu->items[menu->cursorItem]->window.rect.x + 1, menu->items[menu->cursorItem]->window.rect.y + 1);
- return menu->items[menu->cursorItem];
- }
- }
- menu->cursorItem = oldCursor;
- return NULL;
- }
- /*
- =================
- Menu_SetPrevCursorItem
- =================
- */
- itemDef_t *Menu_SetPrevCursorItem(menuDef_t *menu)
- {
- qboolean wrapped = qfalse;
- int oldCursor = menu->cursorItem;
- if (menu->cursorItem < 0)
- {
- menu->cursorItem = menu->itemCount-1;
- wrapped = qtrue;
- }
- while (menu->cursorItem > -1)
- {
- menu->cursorItem--;
- if (menu->cursorItem < 0 )
- {
- if (wrapped)
- {
- break;
- }
- wrapped = qtrue;
- menu->cursorItem = menu->itemCount -1;
- }
- if (Item_SetFocus(menu->items[menu->cursorItem], DC->cursorx, DC->cursory))
- {
- Menu_HandleMouseMove(menu, menu->items[menu->cursorItem]->window.rect.x + 1, menu->items[menu->cursorItem]->window.rect.y + 1);
- return menu->items[menu->cursorItem];
- }
- }
- menu->cursorItem = oldCursor;
- return NULL;
- }
- /*
- =================
- Item_TextField_HandleKey
- =================
- */
- qboolean Item_TextField_HandleKey(itemDef_t *item, int key)
- {
- char buff[1024];
- int len;
- itemDef_t *newItem = NULL;
- editFieldDef_t *editPtr = (editFieldDef_t*)item->typeData;
- if (item->cvar)
- {
- memset(buff, 0, sizeof(buff));
- DC->getCVarString(item->cvar, buff, sizeof(buff));
- len = strlen(buff);
- if (editPtr->maxChars && len > editPtr->maxChars)
- {
- len = editPtr->maxChars;
- }
- if ( key & K_CHAR_FLAG )
- {
- key &= ~K_CHAR_FLAG;
- if (key == 'h' - 'a' + 1 )
- { // ctrl-h is backspace
- if ( item->cursorPos > 0 )
- {
- memmove( &buff[item->cursorPos - 1], &buff[item->cursorPos], len + 1 - item->cursorPos);
- item->cursorPos--;
- if (item->cursorPos < editPtr->paintOffset)
- {
- editPtr->paintOffset--;
- }
- }
- DC->setCVar(item->cvar, buff);
- return qtrue;
- }
- //
- // ignore any non printable chars
- //
- if ( key < 32 || !item->cvar)
- {
- return qtrue;
- }
- if (item->type == ITEM_TYPE_NUMERICFIELD)
- {
- if (key < '0' || key > '9')
- {
- return qfalse;
- }
- }
- if (!DC->getOverstrikeMode())
- {
- if (( len == MAX_EDITFIELD - 1 ) || (editPtr->maxChars && len >= editPtr->maxChars))
- {
- return qtrue;
- }
- memmove( &buff[item->cursorPos + 1], &buff[item->cursorPos], len + 1 - item->cursorPos );
- }
- else
- {
- if (editPtr->maxChars && item->cursorPos >= editPtr->maxChars)
- {
- return qtrue;
- }
- }
- buff[item->cursorPos] = key;
- DC->setCVar(item->cvar, buff);
- if (item->cursorPos < len + 1)
- {
- item->cursorPos++;
- if (editPtr->maxPaintChars && item->cursorPos > editPtr->maxPaintChars)
- {
- editPtr->paintOffset++;
- }
- }
- }
- else
- {
- if ( key == A_DELETE || key == A_KP_PERIOD )
- {
- if ( item->cursorPos < len )
- {
- memmove( buff + item->cursorPos, buff + item->cursorPos + 1, len - item->cursorPos);
- DC->setCVar(item->cvar, buff);
- }
- return qtrue;
- }
- if ( key == A_CURSOR_RIGHT || key == A_KP_6 )
- {
- if (editPtr->maxPaintChars && item->cursorPos >= editPtr->maxPaintChars && item->cursorPos < len)
- {
- item->cursorPos++;
- editPtr->paintOffset++;
- return qtrue;
- }
- if (item->cursorPos < len)
- {
- item->cursorPos++;
- }
- return qtrue;
- }
- if ( key == A_CURSOR_LEFT|| key == A_KP_4 )
- {
- if ( item->cursorPos > 0 )
- {
- item->cursorPos--;
- }
- if (item->cursorPos < editPtr->paintOffset)
- {
- editPtr->paintOffset--;
- }
- return qtrue;
- }
- if ( key == A_HOME || key == A_KP_7)
- {
- item->cursorPos = 0;
- editPtr->paintOffset = 0;
- return qtrue;
- }
- if ( key == A_END || key == A_KP_1)
- {
- item->cursorPos = len;
- if(item->cursorPos > editPtr->maxPaintChars)
- {
- editPtr->paintOffset = len - editPtr->maxPaintChars;
- }
- return qtrue;
- }
- if ( key == A_INSERT || key == A_KP_0 )
- {
- DC->setOverstrikeMode(!DC->getOverstrikeMode());
- return qtrue;
- }
- }
- if (key == A_TAB || key == A_CURSOR_DOWN || key == A_KP_2)
- {
- newItem = Menu_SetNextCursorItem((menuDef_t *) item->parent);
- if (newItem && (newItem->type == ITEM_TYPE_EDITFIELD || newItem->type == ITEM_TYPE_NUMERICFIELD))
- {
- g_editItem = newItem;
- }
- }
- if (key == A_CURSOR_UP || key == A_KP_8)
- {
- newItem = Menu_SetPrevCursorItem((menuDef_t *) item->parent);
- if (newItem && (newItem->type == ITEM_TYPE_EDITFIELD || newItem->type == ITEM_TYPE_NUMERICFIELD))
- {
- g_editItem = newItem;
- }
- }
- if ( key == A_ENTER || key == A_KP_ENTER || key == A_ESCAPE)
- {
- return qfalse;
- }
- return qtrue;
- }
- return qfalse;
- }
- static void Scroll_TextScroll_AutoFunc (void *p)
- {
- scrollInfo_t *si = (scrollInfo_t*)p;
- if (DC->realTime > si->nextScrollTime)
- {
- // need to scroll which is done by simulating a click to the item
- // this is done a bit sideways as the autoscroll "knows" that the item is a listbox
- // so it calls it directly
- Item_TextScroll_HandleKey(si->item, si->scrollKey, qtrue, qfalse);
- si->nextScrollTime = DC->realTime + si->adjustValue;
- }
- if (DC->realTime > si->nextAdjustTime)
- {
- si->nextAdjustTime = DC->realTime + SCROLL_TIME_ADJUST;
- if (si->adjustValue > SCROLL_TIME_FLOOR)
- {
- si->adjustValue -= SCROLL_TIME_ADJUSTOFFSET;
- }
- }
- }
- static void Scroll_TextScroll_ThumbFunc(void *p)
- {
- scrollInfo_t *si = (scrollInfo_t*)p;
- rectDef_t r;
- int pos;
- int max;
- textScrollDef_t *scrollPtr = (textScrollDef_t*)si->item->typeData;
- if (DC->cursory != si->yStart)
- {
- r.x = si->item->window.rect.x + si->item->window.rect.w - SCROLLBAR_SIZE - 1;
- r.y = si->item->window.rect.y + SCROLLBAR_SIZE + 1;
- r.h = si->item->window.rect.h - (SCROLLBAR_SIZE*2) - 2;
- r.w = SCROLLBAR_SIZE;
- max = Item_TextScroll_MaxScroll(si->item);
- //
- pos = (DC->cursory - r.y - SCROLLBAR_SIZE/2) * max / (r.h - SCROLLBAR_SIZE);
- if (pos < 0)
- {
- pos = 0;
- }
- else if (pos > max)
- {
- pos = max;
- }
- scrollPtr->startPos = pos;
- si->yStart = DC->cursory;
- }
- if (DC->realTime > si->nextScrollTime)
- {
- // need to scroll which is done by simulating a click to the item
- // this is done a bit sideways as the autoscroll "knows" that the item is a listbox
- // so it calls it directly
- Item_TextScroll_HandleKey(si->item, si->scrollKey, qtrue, qfalse);
- si->nextScrollTime = DC->realTime + si->adjustValue;
- }
- if (DC->realTime > si->nextAdjustTime)
- {
- si->nextAdjustTime = DC->realTime + SCROLL_TIME_ADJUST;
- if (si->adjustValue > SCROLL_TIME_FLOOR)
- {
- si->adjustValue -= SCROLL_TIME_ADJUSTOFFSET;
- }
- }
- }
- /*
- =================
- Menu_OverActiveItem
- =================
- */
- static qboolean Menu_OverActiveItem(menuDef_t *menu, float x, float y)
- {
- if (menu && menu->window.flags & (WINDOW_VISIBLE | WINDOW_FORCED))
- {
- //JLFMOUSE
- #ifdef _XBOX
- return qtrue;
- #endif
- if (Rect_ContainsPoint(&menu->window.rect, x, y))
- {
- int i;
- for (i = 0; i < menu->itemCount; i++)
- {
- // turn off focus each item
- // menu->items[i].window.flags &= ~WINDOW_HASFOCUS;
- if (!(menu->items[i]->window.flags & (WINDOW_VISIBLE | WINDOW_FORCED)))
- {
- continue;
- }
- if (menu->items[i]->window.flags & WINDOW_DECORATION)
- {
- continue;
- }
- if (Rect_ContainsPoint(&menu->items[i]->window.rect, x, y))
- {
- itemDef_t *overItem = menu->items[i];
- if (overItem->type == ITEM_TYPE_TEXT && overItem->text)
- {
- if (Rect_ContainsPoint(&overItem->window.rect, x, y))
- {
- return qtrue;
- }
- else
- {
- continue;
- }
- }
- else
- {
- return qtrue;
- }
- }
- }
- }
- }
- return qfalse;
- }
- /*
- =================
- Display_VisibleMenuCount
- =================
- */
- int Display_VisibleMenuCount(void)
- {
- int i, count;
- count = 0;
- for (i = 0; i < menuCount; i++)
- {
- if (Menus[i].window.flags & (WINDOW_FORCED | WINDOW_VISIBLE))
- {
- count++;
- }
- }
- return count;
- }
- /*
- =================
- Window_CloseCinematic
- =================
- */
- static void Window_CloseCinematic(windowDef_t *window)
- {
- /*
- if (window->style == WINDOW_STYLE_CINEMATIC && window->cinematic >= 0)
- {
- DC->stopCinematic(window->cinematic);
- window->cinematic = -1;
- }
- */
- }
- /*
- =================
- Menu_CloseCinematics
- =================
- */
- static void Menu_CloseCinematics(menuDef_t *menu)
- {
- if (menu)
- {
- int i;
- Window_CloseCinematic(&menu->window);
- for (i = 0; i < menu->itemCount; i++)
- {
- Window_CloseCinematic(&menu->items[i]->window);
- if (menu->items[i]->type == ITEM_TYPE_OWNERDRAW)
- {
- DC->stopCinematic(0-menu->items[i]->window.ownerDraw);
- }
- }
- }
- }
- /*
- =================
- Display_CloseCinematics
- =================
- */
- static void Display_CloseCinematics()
- {
- int i;
- for (i = 0; i < menuCount; i++)
- {
- Menu_CloseCinematics(&Menus[i]);
- }
- }
- /*
- =================
- Item_StopCapture
- =================
- */
- void Item_StopCapture(itemDef_t *item)
- {
- }
- /*
- =================
- Item_ListBox_HandleKey
- =================
- */
- qboolean Item_ListBox_HandleKey(itemDef_t *item, int key, qboolean down, qboolean force)
- {
- listBoxDef_t *listPtr = (listBoxDef_t*)item->typeData;
- int count = DC->feederCount(item->special);
- int max, viewmaxw, viewmaxh,viewmax;
- int gridcount;
- viewmaxw = (item->window.rect.w / listPtr->elementWidth);
- viewmaxh = (item->window.rect.h / listPtr->elementHeight);
- gridcount = viewmaxw * viewmaxh;
- if (count <=0)
- return qfalse;
-
- //JLFMOUSE
- #ifndef _XBOX
- if (force || (Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory) && item->window.flags & WINDOW_HASFOCUS))
- #else
- if (force || item->window.flags & WINDOW_HASFOCUS)
- #endif
- {
- max = Item_ListBox_MaxScroll(item);
- if (item->window.flags & WINDOW_HORIZONTAL)
- {
- viewmax = viewmaxw;
- if ( key == A_CURSOR_LEFT || key == A_KP_4 )
- {
- if (!listPtr->notselectable)
- {
- listPtr->cursorPos--;
- if (listPtr->cursorPos < 0)
- {
- listPtr->cursorPos = 0;
- #ifdef _XBOX
- item->cursorPos = listPtr->cursorPos;
- DC->feederSelection(item->special, item->cursorPos, item);
- return qfalse;
- #endif
- }
- if (listPtr->cursorPos < listPtr->startPos)
- {
- listPtr->startPos = listPtr->cursorPos;
- }
- if (listPtr->cursorPos >= listPtr->startPos + viewmaxw)
- {
- listPtr->startPos = listPtr->cursorPos - viewmaxw + 1;
- }
- item->cursorPos = listPtr->cursorPos;
- DC->feederSelection(item->special, item->cursorPos, item);
- }
- else
- {
- listPtr->startPos--;
- //JLF
- #ifdef _XBOX // MPMOVED
- listPtr->cursorPos--;
- if (listPtr->cursorPos >= 0)
- DC->feederSelection(item->special, listPtr->cursorPos, item);
- else
- listPtr->cursorPos =0;
- #endif
- if (listPtr->startPos < 0)
- {
- listPtr->startPos = 0;
- //JLFMOUSE
- #ifdef _XBOX // MPMOVED
- return false;
- #endif
- }
- }
- return qtrue;
- }
- if ( key == A_CURSOR_RIGHT || key == A_KP_6 )
- {
- if (!listPtr->notselectable)
- {
- listPtr->cursorPos++;
- if (listPtr->cursorPos < listPtr->startPos)
- {
- listPtr->startPos = listPtr->cursorPos;
- }
- if (listPtr->cursorPos >= count)
- {
- listPtr->cursorPos = count-1;
- #ifdef _XBOX
- item->cursorPos = listPtr->cursorPos;
- DC->feederSelection(item->special, item->cursorPos, item);
- return qfalse;
- #endif
- }
- if (listPtr->cursorPos >= listPtr->startPos + viewmaxw)
- {
- listPtr->startPos = listPtr->cursorPos - viewmaxw + 1;
- }
- item->cursorPos = listPtr->cursorPos;
- DC->feederSelection(item->special, item->cursorPos, item);
- }
- else
- {
- listPtr->startPos++;
- //JLF
- #ifdef _XBOX // MPMOVED
- listPtr->cursorPos++;
- if (listPtr->cursorPos < count)
- DC->feederSelection(item->special, listPtr->cursorPos, item);
- else
- listPtr->cursorPos =count -1;
- #endif
- if (listPtr->startPos >= count)
- {
- listPtr->startPos = count-1;
- //JLFMOUSE
- #ifdef _XBOX // MPMOVED
- return false;
- #endif
- }
- }
- return qtrue;
- }
- }
- else //VERTICAL ALIGNMENT *************************
- {
- viewmax = viewmaxh;
- if ( key == A_CURSOR_UP || key == A_KP_8 )
- {
- if (!listPtr->notselectable)
- {
- if (listPtr->elementStyle == LISTBOX_IMAGE)
- { listPtr->cursorPos-= viewmaxw;
- if (listPtr->cursorPos < 0)
- {
- listPtr->cursorPos+=viewmaxw;
- return qfalse;
- }
- }
- else
- listPtr->cursorPos--;
- if (listPtr->cursorPos < 0)
- {
- listPtr->cursorPos = 0;
- #ifdef _XBOX
- item->cursorPos = listPtr->cursorPos;
- DC->feederSelection(item->special, item->cursorPos, item);
- return qfalse;
- #endif
- }
- if (listPtr->cursorPos < listPtr->startPos)
- {
- if (listPtr->elementStyle == LISTBOX_IMAGE)
- listPtr->startPos -= viewmaxw;
- else
- listPtr->startPos = listPtr->cursorPos;
- }
- if (listPtr->elementStyle == LISTBOX_IMAGE)
- {
- if (listPtr->cursorPos >= listPtr->startPos + gridcount)
- listPtr->startPos += gridcount;
- }
- else
- {
- if (listPtr->cursorPos >= listPtr->startPos + viewmaxh)
- listPtr->startPos= listPtr->cursorPos-viewmaxh + 1;
- }
-
- // listPtr->startPos = listPtr->cursorPos - viewmaxh + 1;
-
-
- item->cursorPos = listPtr->cursorPos;
- DC->feederSelection(item->special, item->cursorPos, item);
- }
- else
- {
- listPtr->startPos--;
-
- //JLF
- #ifdef _XBOX // MPMOVED
- listPtr->cursorPos--;
- if (listPtr->cursorPos >= 0)
- {
- item->cursorPos = listPtr->cursorPos;
- DC->feederSelection(item->special, listPtr->cursorPos, item);
- }
- else
- listPtr->cursorPos = 0;
- #endif
- if (listPtr->startPos < 0)
- {
- listPtr->startPos = 0;
- //JLFMOUSE
- #ifdef _XBOX // MPMOVED
- return false;
- #endif
- }
- }
- return qtrue;
- }
- if ( key == A_CURSOR_DOWN || key == A_KP_2 )
- {
- if (!listPtr->notselectable)
- {
- if (listPtr->elementStyle == LISTBOX_IMAGE)
- {
- listPtr->cursorPos+= viewmaxw;
- if (listPtr->cursorPos >=count)
- {
- listPtr->cursorPos-= viewmaxw;
- if ( count-1 == listPtr->cursorPos)
- listPtr->cursorPos++;
- else
- listPtr->cursorPos = count-1;
- }
- }
- else
- listPtr->cursorPos++;
- if (listPtr->cursorPos < listPtr->startPos)
- {
- listPtr->startPos = listPtr->cursorPos;
- }
- if (listPtr->cursorPos >= count)
- {
- listPtr->cursorPos = count-1;
- #ifdef _XBOX
- item->cursorPos = listPtr->cursorPos;
- DC->feederSelection(item->special, item->cursorPos, item);
- return qfalse;
- #endif
- }
- if (listPtr->elementStyle == LISTBOX_IMAGE)
- {
- if (listPtr->cursorPos >= listPtr->startPos + gridcount) {
- #ifdef _XBOX
- listPtr->startPos += viewmaxw;
- #else
- listPtr->startPos = listPtr->cursorPos - viewmax + 1;
- #endif
- }
- }
- else
- {
- if (listPtr->cursorPos >= listPtr->startPos + viewmaxh)
- listPtr->startPos++;
- }
- item->cursorPos = listPtr->cursorPos;
- DC->feederSelection(item->special, item->cursorPos, item);
- }
- else
- {
- listPtr->startPos++;
- //JLF
- #ifdef _XBOX // MPMOVED
- listPtr->cursorPos++;
- if (listPtr->cursorPos < count)
- {
- item->cursorPos = listPtr->cursorPos;
- DC->feederSelection(item->special, listPtr->cursorPos, item);
- }
- else
- listPtr->cursorPos = count -1;
- #endif
-
- //JLFMOUSE
- #ifdef _XBOX // MPMOVED
- if (listPtr->startPos > count-1)
- {
- listPtr->startPos = count-1;
- return false;
- #else
- if (listPtr->startPos > max)
- {
- listPtr->startPos = max;
- #endif
- }
- }
- return qtrue;
- }
- //JLF newstuff
- if ( key == A_CURSOR_LEFT && listPtr->elementStyle == LISTBOX_IMAGE )
- {
- if (viewmaxw <=1)
- return false;
- if (!listPtr->notselectable)
- {
- listPtr->cursorPos--;
- if (listPtr->cursorPos < 0)
- {
- listPtr->cursorPos = 0;
- #ifdef _XBOX
- item->cursorPos = listPtr->cursorPos;
- DC->feederSelection(item->special, item->cursorPos, item);
- return qfalse;
- #endif
- }
- if (listPtr->cursorPos < listPtr->startPos)
- {
- //JLF newgrid
- #ifdef _XBOX
- listPtr->startPos -= viewmaxw;
- #else
- listPtr->startPos = listPtr->cursorPos;
- #endif
- }
- // if (listPtr->cursorPos >= listPtr->startPos + viewmaxh)
- // {
- // listPtr->startPos = listPtr->cursorPos - viewmaxh + 1;
- // }
- item->cursorPos = listPtr->cursorPos;
- DC->feederSelection(item->special, item->cursorPos, item);
- }
- else
- {
- listPtr->startPos--;
- //JLF
- #ifdef _XBOX // MPMOVED
- listPtr->cursorPos--;
- if (listPtr->cursorPos >= 0)
- DC->feederSelection(item->special, listPtr->cursorPos, item);
- else
- listPtr->cursorPos = 0;
- #endif
- if (listPtr->startPos < 0)
- {
- listPtr->startPos = 0;
- //JLFMOUSE
- #ifdef _XBOX // MPMOVED
- return false;
- #endif
- }
- }
- return qtrue;
- }
- if ( key == A_CURSOR_RIGHT && listPtr->elementStyle == LISTBOX_IMAGE )
- {
- if (viewmaxw <=1)
- return false;
- if (!listPtr->notselectable)
- {
- listPtr->cursorPos++;
- if (listPtr->cursorPos >= count)
- {
- listPtr->cursorPos = count-1;
- #ifdef _XBOX
- item->cursorPos = listPtr->cursorPos;
- DC->feederSelection(item->special, item->cursorPos, item);
- return qfalse;
- #endif
- }
- if (listPtr->cursorPos < listPtr->startPos)
- {
- listPtr->startPos = listPtr->cursorPos;
- }
- if (listPtr->cursorPos >= listPtr->startPos + gridcount)
- {
- //listPtr->startPos = listPtr->cursorPos - viewmaxh + 1;
- listPtr->startPos += viewmaxw;
- }
- item->cursorPos = listPtr->cursorPos;
- DC->feederSelection(item->special, item->cursorPos, item);
- }
- else
- {
- listPtr->startPos++;
- //JLF
- #ifdef _XBOX // MPMOVED
- listPtr->cursorPos++;
- if (listPtr->cursorPos < count)
- DC->feederSelection(item->special, listPtr->cursorPos, item);
- else
- listPtr->cursorPos = count-1;
- #endif
- if (listPtr->startPos <count)
- {
- listPtr->startPos = count-1;
- //JLFMOUSE
- #ifdef _XBOX // MPMOVED
- return false;
- #endif
- }
- }
- return qtrue;
- }
- }
- // mouse hit
- if (key == A_MOUSE1 || key == A_MOUSE2)
- {
- #ifdef _XBOX
- if (listPtr->doubleClick)
- {
- Item_RunScript(item, listPtr->doubleClick);
- return qtrue;
- }
- else
- {
- return Item_HandleAction(item);
- }
- #else
- if (item->window.flags & WINDOW_LB_LEFTARROW)
- {
- listPtr->startPos--;
- if (listPtr->startPos < 0)
- {
- listPtr->startPos = 0;
- //JLFMOUSE
- #ifdef _XBOX // MPMOVED
- return false;
- #endif
- }
- }
- else if (item->window.flags & WINDOW_LB_RIGHTARROW)
- {
- // one down
- listPtr->startPos++;
- if (listPtr->startPos > max)
- {
- listPtr->startPos = max;
- //JLFMOUSE
- #ifdef _XBOX // MPMOVED
- return false;
- #endif
- }
- }
- else if (item->window.flags & WINDOW_LB_PGUP)
- {
- // page up
- listPtr->startPos -= viewmax;
- if (listPtr->startPos < 0)
- {
- listPtr->startPos = 0;
- //JLFMOUSE
- #ifdef _XBOX // MPMOVED
- return false;
- #endif
- }
- }
- else if (item->window.flags & WINDOW_LB_PGDN)
- {
- // page down
- listPtr->startPos += viewmax;
- if (listPtr->startPos > max)
- {
- listPtr->startPos = max;
- //JLFMOUSE
- #ifdef _XBOX // MPMOVED
- return false;
- #endif
- }
- }
- else if (item->window.flags & WINDOW_LB_THUMB)
- {
- // Display_SetCaptureItem(item);
- }
- else
- {
- // select an item
- if (DC->realTime < lastListBoxClickTime && listPtr->doubleClick)
- {
- Item_RunScript(item, listPtr->doubleClick);
- }
- lastListBoxClickTime = DC->realTime + DOUBLE_CLICK_DELAY;
- item->cursorPos = listPtr->cursorPos;
- DC->feederSelection(item->special, item->cursorPos, item);
- }
- return qtrue;
- #endif
- }
- }
- return qfalse;
- }
- /*
- =================
- Scroll_ListBox_AutoFunc
- =================
- */
- static void Scroll_ListBox_AutoFunc(void *p)
- {
- scrollInfo_t *si = (scrollInfo_t*)p;
- if (DC->realTime > si->nextScrollTime)
- {
- // need to scroll which is done by simulating a click to the item
- // this is done a bit sideways as the autoscroll "knows" that the item is a listbox
- // so it calls it directly
- Item_ListBox_HandleKey(si->item, si->scrollKey, qtrue, qfalse);
- si->nextScrollTime = DC->realTime + si->adjustValue;
- }
- if (DC->realTime > si->nextAdjustTime)
- {
- si->nextAdjustTime = DC->realTime + SCROLL_TIME_ADJUST;
- if (si->adjustValue > SCROLL_TIME_FLOOR)
- {
- si->adjustValue -= SCROLL_TIME_ADJUSTOFFSET;
- }
- }
- }
- /*
- =================
- Scroll_ListBox_ThumbFunc
- =================
- */
- static void Scroll_ListBox_ThumbFunc(void *p)
- {
- scrollInfo_t *si = (scrollInfo_t*)p;
- rectDef_t r;
- int pos, max;
- listBoxDef_t *listPtr = (listBoxDef_t*)si->item->typeData;
- if (si->item->window.flags & WINDOW_HORIZONTAL)
- {
- if (DC->cursorx == si->xStart)
- {
- return;
- }
- r.x = si->item->window.rect.x + SCROLLBAR_SIZE + 1;
- r.y = si->item->window.rect.y + si->item->window.rect.h - SCROLLBAR_SIZE - 1;
- r.h = SCROLLBAR_SIZE;
- r.w = si->item->window.rect.w - (SCROLLBAR_SIZE*2) - 2;
- max = Item_ListBox_MaxScroll(si->item);
- //
- pos = (DC->cursorx - r.x - SCROLLBAR_SIZE/2) * max / (r.w - SCROLLBAR_SIZE);
- if (pos < 0)
- {
- pos = 0;
- }
- else if (pos > max)
- {
- pos = max;
- }
- listPtr->startPos = pos;
- si->xStart = DC->cursorx;
- }
- else if (DC->cursory != si->yStart)
- {
- r.x = si->item->window.rect.x + si->item->window.rect.w - SCROLLBAR_SIZE - 1;
- r.y = si->item->window.rect.y + SCROLLBAR_SIZE + 1;
- r.h = si->item->window.rect.h - (SCROLLBAR_SIZE*2) - 2;
- r.w = SCROLLBAR_SIZE;
- max = Item_ListBox_MaxScroll(si->item);
- //
- pos = (DC->cursory - r.y - SCROLLBAR_SIZE/2) * max / (r.h - SCROLLBAR_SIZE);
- if (pos < 0)
- {
- pos = 0;
- }
- else if (pos > max)
- {
- pos = max;
- }
- listPtr->startPos = pos;
- si->yStart = DC->cursory;
- }
- if (DC->realTime > si->nextScrollTime)
- {
- // need to scroll which is done by simulating a click to the item
- // this is done a bit sideways as the autoscroll "knows" that the item is a listbox
- // so it calls it directly
- Item_ListBox_HandleKey(si->item, si->scrollKey, qtrue, qfalse);
- si->nextScrollTime = DC->realTime + si->adjustValue;
- }
- if (DC->realTime > si->nextAdjustTime)
- {
- si->nextAdjustTime = DC->realTime + SCROLL_TIME_ADJUST;
- if (si->adjustValue > SCROLL_TIME_FLOOR)
- {
- si->adjustValue -= SCROLL_TIME_ADJUSTOFFSET;
- }
- }
- }
- /*
- =================
- Item_Slider_OverSlider
- =================
- */
- int Item_Slider_OverSlider(itemDef_t *item, float x, float y)
- {
- rectDef_t r;
- r.x = Item_Slider_ThumbPosition(item) - (SLIDER_THUMB_WIDTH / 2);
- r.y = item->window.rect.y - 2;
- r.w = SLIDER_THUMB_WIDTH;
- r.h = SLIDER_THUMB_HEIGHT;
- if (Rect_ContainsPoint(&r, x, y))
- {
- return WINDOW_LB_THUMB;
- }
- return 0;
- }
- /*
- =================
- Scroll_Slider_ThumbFunc
- =================
- */
- static void Scroll_Slider_ThumbFunc(void *p)
- {
- float x, value, cursorx;
- scrollInfo_t *si = (scrollInfo_t*)p;
- editFieldDef_t *editDef = (struct editFieldDef_s *) si->item->typeData;
- if (si->item->text)
- {
- x = si->item->textRect.x + si->item->textRect.w + 8;
- }
- else
- {
- x = si->item->window.rect.x;
- }
- cursorx = DC->cursorx;
- if (cursorx < x)
- {
- cursorx = x;
- }
- else if (cursorx > x + SLIDER_WIDTH)
- {
- cursorx = x + SLIDER_WIDTH;
- }
- value = cursorx - x;
- value /= SLIDER_WIDTH;
- value *= (editDef->maxVal - editDef->minVal);
- value += editDef->minVal;
- DC->setCVar(si->item->cvar, va("%f", value));
- }
- /*
- =================
- Item_StartCapture
- =================
- */
- void Item_StartCapture(itemDef_t *item, int key)
- {
- int flags;
- switch (item->type)
- {
- case ITEM_TYPE_EDITFIELD:
- case ITEM_TYPE_NUMERICFIELD:
- case ITEM_TYPE_LISTBOX:
- {
- flags = Item_ListBox_OverLB(item, DC->cursorx, DC->cursory);
- if (flags & (WINDOW_LB_LEFTARROW | WINDOW_LB_RIGHTARROW))
- {
- scrollInfo.nextScrollTime = DC->realTime + SCROLL_TIME_START;
- scrollInfo.nextAdjustTime = DC->realTime + SCROLL_TIME_ADJUST;
- scrollInfo.adjustValue = SCROLL_TIME_START;
- scrollInfo.scrollKey = key;
- scrollInfo.scrollDir = (flags & WINDOW_LB_LEFTARROW) ? qtrue : qfalse;
- scrollInfo.item = item;
- captureData = &scrollInfo;
- captureFunc = &Scroll_ListBox_AutoFunc;
- itemCapture = item;
- }
- else if (flags & WINDOW_LB_THUMB)
- {
- scrollInfo.scrollKey = key;
- scrollInfo.item = item;
- scrollInfo.xStart = DC->cursorx;
- scrollInfo.yStart = DC->cursory;
- captureData = &scrollInfo;
- captureFunc = &Scroll_ListBox_ThumbFunc;
- itemCapture = item;
- }
- break;
- }
- case ITEM_TYPE_TEXTSCROLL:
- flags = Item_TextScroll_OverLB (item, DC->cursorx, DC->cursory);
- if (flags & (WINDOW_LB_LEFTARROW | WINDOW_LB_RIGHTARROW))
- {
- scrollInfo.nextScrollTime = DC->realTime + SCROLL_TIME_START;
- scrollInfo.nextAdjustTime = DC->realTime + SCROLL_TIME_ADJUST;
- scrollInfo.adjustValue = SCROLL_TIME_START;
- scrollInfo.scrollKey = key;
- scrollInfo.scrollDir = (flags & WINDOW_LB_LEFTARROW) ? qtrue : qfalse;
- scrollInfo.item = item;
- captureData = &scrollInfo;
- captureFunc = &Scroll_TextScroll_AutoFunc;
- itemCapture = item;
- }
- else if (flags & WINDOW_LB_THUMB)
- {
- scrollInfo.scrollKey = key;
- scrollInfo.item = item;
- scrollInfo.xStart = DC->cursorx;
- scrollInfo.yStart = DC->cursory;
- captureData = &scrollInfo;
- captureFunc = &Scroll_TextScroll_ThumbFunc;
- itemCapture = item;
- }
- break;
- case ITEM_TYPE_SLIDER:
- {
- flags = Item_Slider_OverSlider(item, DC->cursorx, DC->cursory);
- if (flags & WINDOW_LB_THUMB)
- {
- scrollInfo.scrollKey = key;
- scrollInfo.item = item;
- scrollInfo.xStart = DC->cursorx;
- scrollInfo.yStart = DC->cursory;
- captureData = &scrollInfo;
- captureFunc = &Scroll_Slider_ThumbFunc;
- itemCapture = item;
- }
- break;
- }
- }
- }
- /*
- =================
- Item_YesNo_HandleKey
- =================
- */
- qboolean Item_YesNo_HandleKey(itemDef_t *item, int key)
- {
- //JLFMOUSE MPMOVED
- #ifndef _XBOX
- if (Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory) && item->window.flags & WINDOW_HASFOCUS && item->cvar)
- #else
- if (item->window.flags & WINDOW_HASFOCUS && item->cvar)
- #endif
- {
- //JLFDPAD MPMOVED
- #ifndef _XBOX
- if (key == A_MOUSE1 || key == A_ENTER || key == A_MOUSE2 || key == A_MOUSE3)
- #else
- if ( key == A_CURSOR_RIGHT || key == A_CURSOR_LEFT)
- #endif
- //end JLFDPAD
- {
- DC->setCVar(item->cvar, va("%i", !DC->getCVarValue(item->cvar)));
- return qtrue;
- }
- }
- return qfalse;
- }
- /*
- =================
- Item_Multi_FindCvarByValue
- =================
- */
- int Item_Multi_FindCvarByValue(itemDef_t *item)
- {
- char buff[1024];
- float value = 0;
- int i;
- multiDef_t *multiPtr = (multiDef_t*)item->typeData;
- if (multiPtr)
- {
- if (multiPtr->strDef)
- {
- DC->getCVarString(item->cvar, buff, sizeof(buff));
- }
- else
- {
- value = DC->getCVarValue(item->cvar);
- }
- for (i = 0; i < multiPtr->count; i++)
- {
- if (multiPtr->strDef)
- {
- if (Q_stricmp(buff, multiPtr->cvarStr[i]) == 0)
- {
- return i;
- }
- }
- else
- {
- if (multiPtr->cvarValue[i] == value)
- {
- return i;
- }
- }
- }
- }
- return 0;
- }
- /*
- =================
- Item_Multi_CountSettings
- =================
- */
- int Item_Multi_CountSettings(itemDef_t *item)
- {
- multiDef_t *multiPtr = (multiDef_t*)item->typeData;
- if (multiPtr == NULL)
- {
- return 0;
- }
- return multiPtr->count;
- }
- /*
- =================
- Item_OwnerDraw_HandleKey
- =================
- */
- qboolean Item_OwnerDraw_HandleKey(itemDef_t *item, int key)
- {
- if (item && DC->ownerDrawHandleKey)
- {
- return DC->ownerDrawHandleKey(item->window.ownerDraw, item->window.ownerDrawFlags, &item->special, key);
- }
- return qfalse;
- }
- //JLF new selection LEFT/RIGHT
- qboolean Item_Button_HandleKey(itemDef_t *item, int key)
- {
- #ifdef _XBOX
- if (key == A_MOUSE1)
- {
- if (Item_HandleAction(item))
- {
- return qtrue;
- }
- }
- if ( key == A_CURSOR_RIGHT)
- {
- if (Item_HandleSelectionNext(item))
- {
- //Item processed it
- return qtrue;
- }
- }
- else if ( key == A_CURSOR_LEFT)
- {
- if (Item_HandleSelectionPrev(item))
- {
- //Item processed it
- return qtrue;
- }
- }
- #endif
- return false;
- }
- /*
- =================
- Item_Text_HandleKey
- =================
- */
- qboolean Item_Text_HandleKey(itemDef_t *item, int key)
- {
- if (key == A_MOUSE1)
- {
- if (Item_HandleAction(item))
- {
- return qtrue;
- }
- }
- else if (key == A_CURSOR_RIGHT)
- {
- if (Item_HandleSelectionNext(item))
- {
- //Item processed it
- return qtrue;
- }
- }
- else if (key == A_CURSOR_LEFT)
- {
- if (Item_HandleSelectionPrev(item))
- {
- //Item processed it
- return qtrue;
- }
- }
- return qfalse;
- }
- /*
- =================
- Item_Multi_HandleKey
- =================
- */
- qboolean Item_Multi_HandleKey(itemDef_t *item, int key)
- {
- multiDef_t *multiPtr = (multiDef_t*)item->typeData;
- if (multiPtr)
- {
- //JLF MPMOVED
- #ifndef _XBOX
- if (Rect_ContainsPoint(&item->window.rect, DC->cursorx, DC->cursory) && item->window.flags & WINDOW_HASFOCUS)
- #else
- if (item->window.flags & WINDOW_HASFOCUS)// JLF* && item->cvar)
- #endif
- {
- #ifndef _XBOX
-
- if (key == A_MOUSE1 || key == A_ENTER || key == A_MOUSE2 || key == A_MOUSE3)
- #else
- //JLFDPAD MPMOVED
- if ( key == A_CURSOR_RIGHT || key == A_CURSOR_LEFT)
- //end JLFDPAD
- #endif
- {
- if (item->cvar)
- {
- int current = Item_Multi_FindCvarByValue(item);
- int max = Item_Multi_CountSettings(item);
- #ifndef _XBOX
- if (key == A_MOUSE2)
- #else
- if (key == A_CURSOR_LEFT)
- #endif
- {
- current--;
- if ( current < 0 )
- {
- current = max-1;
- }
- }
- else
- {
- current++;
- if ( current >= max )
- {
- current = 0;
- }
- }
- if (multiPtr->strDef)
- {
- DC->setCVar(item->cvar, multiPtr->cvarStr[current]);
- }
- else
- {
- float value = multiPtr->cvarValue[current];
- if (((float)((int) value)) == value)
- {
- DC->setCVar(item->cvar, va("%i", (int) value ));
- }
- else
- {
- DC->setCVar(item->cvar, va("%f", value ));
- }
- }
- if (item->special)
- {//its a feeder?
- DC->feederSelection(item->special, current, item);
- }
- }
- else
- {
- int max = Item_Multi_CountSettings(item);
- #ifndef _XBOX
- if (key == A_MOUSE2)
- #else
- if (key == A_CURSOR_LEFT)
- #endif
- {
- item->value--;
- if ( item->value < 0 )
- {
- item->value = max;
- }
- }
- else
- {
- item->value++;
- if ( item->value >= max )
- {
- item->value = 0;
- }
- }
- if (item->special)
- {//its a feeder?
- DC->feederSelection(item->special, item->value, item);
- }
- }
- //JLF
- #ifdef _XBOX
- if ( key == A_CURSOR_RIGHT)
- {
- if (Item_HandleSelectionNext(item))
- {
- //Item processed it
-
- }
- }
- else if ( key == A_CURSOR_LEFT)
- {
- if (Item_HandleSelectionPrev(item))
- {
- //Item processed it
-
- }
- }
- #endif
- return qtrue;
- }
- }
- }
- return qfalse;
- }
- /*
- =================
- Item_Slider_HandleKey
- =================
- */
- qboolean Item_Slider_HandleKey(itemDef_t *item, int key, qboolean down)
- {
- float value;
- if (item->window.flags & WINDOW_HASFOCUS && item->cvar)
- {
- if (key == A_CURSOR_LEFT)
- {
- editFieldDef_t *editDef = (editFieldDef_s *) item->typeData;
- if (editDef)
- {
- value = DC->getCVarValue(item->cvar);
- value -= (editDef->maxVal-editDef->minVal)/TICK_COUNT;
- if ( value < editDef->minVal)
- value = editDef->minVal;
- DC->setCVar(item->cvar, va("%f", value));
- return qtrue;
- }
- }
- if (key == A_CURSOR_RIGHT)
- {
- editFieldDef_t *editDef = (editFieldDef_s *) item->typeData;
- if (editDef)
- {
- value = DC->getCVarValue(item->cvar);
- value += (editDef->maxVal-editDef->minVal)/TICK_COUNT;
- if ( value > editDef->maxVal)
- value = editDef->maxVal;
- DC->setCVar(item->cvar, va("%f", value));
- return qtrue;
- }
- }
- }
- return qfalse;
- }
- /*
- =================
- Item_HandleKey
- =================
- */
- qboolean Item_HandleKey(itemDef_t *item, int key, qboolean down)
- {
- if (itemCapture)
- {
- Item_StopCapture(itemCapture);
- itemCapture = NULL;
- captureFunc = NULL;
- captureData = NULL;
- }
- else
- {
- if (down && key == A_MOUSE1 || key == A_MOUSE2 || key == A_MOUSE3)
- {
- Item_StartCapture(item, key);
- }
- }
- if (!down)
- {
- return qfalse;
- }
- switch (item->type)
- {
- case ITEM_TYPE_BUTTON:
- #ifdef _XBOX
- return Item_Button_HandleKey(item, key);
- #else
- return qfalse;
- #endif
- break;
- case ITEM_TYPE_RADIOBUTTON:
- return qfalse;
- break;
- case ITEM_TYPE_CHECKBOX:
- return qfalse;
- break;
- case ITEM_TYPE_EDITFIELD:
- case ITEM_TYPE_NUMERICFIELD:
- //return Item_TextField_HandleKey(item, key);
- return qfalse;
- break;
- case ITEM_TYPE_COMBO:
- return qfalse;
- break;
- case ITEM_TYPE_LISTBOX:
- return Item_ListBox_HandleKey(item, key, down, qfalse);
- break;
- case ITEM_TYPE_TEXTSCROLL:
- return Item_TextScroll_HandleKey(item, key, down, qfalse);
- break;
- case ITEM_TYPE_YESNO:
- return Item_YesNo_HandleKey(item, key);
- break;
- case ITEM_TYPE_MULTI:
- return Item_Multi_HandleKey(item, key);
- break;
- case ITEM_TYPE_OWNERDRAW:
- return Item_OwnerDraw_HandleKey(item, key);
- break;
- case ITEM_TYPE_BIND:
- return Item_Bind_HandleKey(item, key, down);
- break;
- case ITEM_TYPE_SLIDER:
- return Item_Slider_HandleKey(item, key, down);
- break;
- //JLF MPMOVED
- case ITEM_TYPE_TEXT:
- return Item_Text_HandleKey(item, key);
- break;
- default:
- return qfalse;
- break;
- }
- //return qfalse;
- }
- //JLFACCEPT MPMOVED
- /*
- -----------------------------------------
- Item_HandleAction
- If Item has an action script, run it.
- -------------------------------------------
- */
- qboolean Item_HandleAction(itemDef_t * item)
- {
- if (!item)
- return qfalse;
-
- if (item->action)
- //if (item->accept)
- {
- //Item_RunScript(item, item->accept);
- Item_RunScript(item, item->action);
- return true;
- }
- return false;
- }
- //JLFDPADSCRIPT MPMOVED
- /*
- -----------------------------------------
- Item_HandleSelectionNext
- If Item has an selectionNext script, run it.
- -------------------------------------------
- */
- qboolean Item_HandleSelectionNext(itemDef_t * item)
- {
- if (item->selectionNext)
- {
- Item_RunScript(item, item->selectionNext);
- return true;
- }
- return false;
- }
- //JLFDPADSCRIPT MPMOVED
- /*
- -----------------------------------------
- Item_HandleSelectionPrev
- If Item has an selectionPrev script, run it.
- -------------------------------------------
- */
- qboolean Item_HandleSelectionPrev(itemDef_t * item)
- {
- if (item->selectionPrev)
- {
- Item_RunScript(item, item->selectionPrev);
- return true;
- }
- return false;
- }
- /*
- =================
- Item_Action
- =================
- */
- /*
- void Item_Action(itemDef_t *item)
- {
- if (item)
- {
- Item_RunScript(item, item->action);
- }
- }
- */
- /*
- =================
- Menu_HandleKey
- =================
- */
- void Menu_HandleKey(menuDef_t *menu, int key, qboolean down)
- {
- int i;
- itemDef_t *item = NULL;
- qboolean inHandler = qfalse;
- if (inHandler)
- {
- return;
- }
- inHandler = qtrue;
- if (g_waitingForKey && down)
- {
- Item_Bind_HandleKey(g_bindItem, key, down);
- inHandler = qfalse;
- return;
- }
- if (g_editingField && down)
- {
- if (!Item_TextField_HandleKey(g_editItem, key))
- {
- g_editingField = qfalse;
- g_editItem = NULL;
- inHandler = qfalse;
- return;
- }
- else if (key == A_MOUSE1 || key == A_MOUSE2 || key == A_MOUSE3)
- {
- g_editingField = qfalse;
- g_editItem = NULL;
- Display_MouseMove(NULL, DC->cursorx, DC->cursory);
- }
- else if (key == A_TAB || key == A_CURSOR_UP || key == A_CURSOR_DOWN)
- {
- return;
- }
- }
- if (menu == NULL)
- {
- inHandler = qfalse;
- return;
- }
- #ifdef _XBOX
- Menu_MapHack(key);
- #endif
- // get the item with focus
- for (i = 0; i < menu->itemCount; i++)
- {
- if (menu->items[i]->window.flags & WINDOW_HASFOCUS)
- {
- item = menu->items[i];
- break;
- }
- }
- if (!down)
- {
- inHandler = qfalse;
- return;
- }
- if ( item !=NULL)
- {
- //Handlekey implies that this control was able to interpret and use this input
- if (Item_HandleKey(item, key, down))
- {
- if (((item->type == ITEM_TYPE_MULTI) || (item->type == ITEM_TYPE_SLIDER) || (item->type == ITEM_TYPE_YESNO)) &&
- ((key == A_CURSOR_RIGHT) || (key == A_CURSOR_LEFT)))
- {
- Item_HandleAction(item);
- }
- // if ((item->type != ITEM_TYPE_LISTBOX) && ((key != A_CURSOR_RIGHT && key != A_CURSOR_LEFT) || (item->type == ITEM_TYPE_MULTI)))
- // Item_HandleAction(item);
- inHandler = qfalse;
- return;
- }
- }
- // Special Data Pad key handling (gotta love the datapad)
- if (!(key & K_CHAR_FLAG) )
- { //only check keys not chars
- char b[256];
- DC->getBindingBuf( key, b, 256 );
- if (Q_stricmp(b,"datapad") == 0) // They hit the datapad key again.
- {
- if (( Q_stricmp(menu->window.name,"datapadMissionMenu") == 0) ||
- (Q_stricmp(menu->window.name,"datapadWeaponsMenu") == 0) ||
- (Q_stricmp(menu->window.name,"datapadForcePowersMenu") == 0) ||
- (Q_stricmp(menu->window.name,"datapadInventoryMenu") == 0))
- {
- key = A_ESCAPE; //pop on outta here
- }
- }
- }
- // default handling
- switch ( key )
- {
- case A_CURSOR_UP:
- Menu_SetPrevCursorItem(menu);
- break;
-
- case A_ESCAPE:
- if (menu->onESC)
- {
- itemDef_t it;
- it.parent = menu;
- Item_RunScript(&it, menu->onESC);
- }
- break;
- case A_DELETE:
- if (menu->xScript)
- {
- itemDef_t it;
- it.parent = menu;
- Item_RunScript(&it, menu->xScript);
- }
- break;
- case A_BACKSPACE:
- if (menu->yScript)
- {
- itemDef_t it;
- it.parent = menu;
- if (Cvar_VariableIntegerValue("ui_cancelYScript")==0)
- Item_RunScript(&it, menu->yScript);
- }
- break;
- case A_HOME:
- if (menu->whiteScript)
- {
- itemDef_t it;
- it.parent = menu;
- Item_RunScript(&it, menu->whiteScript);
- }
- break;
- case A_CURSOR_DOWN:
- Menu_SetNextCursorItem(menu);
- break;
- case A_MOUSE1:
- if (menu->onAccept)
- {
- itemDef_t it;
- it.parent = menu;
- Item_RunScript(&it, menu->onAccept);
- }
- break;
- case A_JOY0:
- case A_JOY1:
- case A_JOY2:
- case A_JOY3:
- case A_JOY4:
- case A_AUX0:
- case A_AUX1:
- case A_AUX2:
- case A_AUX3:
- case A_AUX4:
- case A_AUX5:
- case A_AUX6:
- case A_AUX7:
- case A_AUX8:
- case A_AUX9:
- case A_AUX10:
- case A_AUX11:
- case A_AUX12:
- case A_AUX13:
- case A_AUX14:
- case A_AUX15:
- case A_AUX16:
- break;
- case A_KP_ENTER:
- case A_ENTER:
- if (item)
- {
- Item_HandleAction(item);
- }
- break;
- }
- inHandler = qfalse;
- }
- /*
- =================
- ParseRect
- =================
- */
- qboolean ParseRect(const char **p, rectDef_t *r)
- {
- if (!COM_ParseFloat(p, &r->x))
- {
- if (!COM_ParseFloat(p, &r->y))
- {
- if (!COM_ParseFloat(p, &r->w))
- {
- if (!COM_ParseFloat(p, &r->h))
- {
- return qtrue;
- }
- }
- }
- }
- return qfalse;
- }
- /*
- =================
- Menus_HideItems
- =================
- */
- void Menus_HideItems(const char *menuName)
- {
- menuDef_t *menu;
- int i;
- menu =Menus_FindByName(menuName); // Get menu
- if (!menu)
- {
- Com_Printf(S_COLOR_YELLOW"WARNING: No menu was found. Could not hide items.\n");
- return;
- }
- menu->window.flags &= ~(WINDOW_HASFOCUS | WINDOW_VISIBLE);
- for (i = 0; i < menu->itemCount; i++)
- {
- menu->items[i]->cvarFlags = CVAR_HIDE;
- }
- }
- /*
- =================
- Menus_ShowItems
- =================
- */
- void Menus_ShowItems(const char *menuName)
- {
- menuDef_t *menu;
- int i;
- menu =Menus_FindByName(menuName); // Get menu
- if (!menu)
- {
- Com_Printf(S_COLOR_YELLOW"WARNING: No menu was found. Could not show items.\n");
- return;
- }
- menu->window.flags |= (WINDOW_HASFOCUS | WINDOW_VISIBLE);
- for (i = 0; i < menu->itemCount; i++)
- {
- menu->items[i]->cvarFlags = CVAR_SHOW;
- }
- }
- /*
- =================
- UI_Cursor_Show
- =================
- */
- void UI_Cursor_Show(qboolean flag)
- {
- DC->cursorShow = flag;
- if ((DC->cursorShow != qtrue) && (DC->cursorShow != qfalse))
- {
- DC->cursorShow = qtrue;
- }
- }
- #ifdef _XBOX
- /*
- =================
- Menu_MapHack
- =================
- */
- void Menu_MapHack(int key)
- {
- if (key == A_F1 || key == A_F2)
- {
- const char *maps[] =
- {
- "academy1",
- "academy2",
- "academy3",
- "academy4",
- "academy5",
- "academy6",
- "hoth2",
- "hoth3",
- "kor1",
- "kor2",
- "t1_danger",
- "t1_fatal",
- "t1_inter",
- "t1_rail",
- "t1_sour",
- "t1_surprise",
- "t2_dpred",
- "t2_rancor",
- "t2_rogue",
- "t2_trip",
- "t2_wedge",
- "t3_bounty",
- "t3_byss",
- "t3_hevil",
- "t3_rift",
- "t3_stamp",
- "taspir1",
- "taspir2",
- "vjun1",
- "vjun2",
- "vjun3",
- "yavin1",
- "yavin1b",
- "yavin2",
- };
-
- const int num_maps = sizeof(maps) / sizeof(char*);
- int current = 0;
- while (current < num_maps)
- {
- if (!strcmp(cl_mapname->string, maps[current])) break;
- ++current;
- }
-
- if (key == A_F1) --current;
- if (key == A_F2) ++current;
- if (current < 0) current = num_maps - 1;
- if (current >= num_maps) current = 0;
- DC->setCVar( "cl_mapname", maps[current] );
- }
- else if (key == A_F3)
- {
- char localMapname[32];
- DC->getCVarString("cl_mapname", localMapname, sizeof(localMapname));
- DC->executeText( EXEC_APPEND, va("devmapall %s\n", localMapname ) );
- }
- }
- //JLF DEMOCODE
- // IS ALREADY IN #ifdef _XBOX
- void G_DemoStart()
- {
- // demoDelay = 0;
- // lastChange = 0;
- g_runningDemo = true;
- // g_demoLastChange = 0;
- extern void Menus_CloseAll();
-
- Menus_CloseAll();
- trap_Key_SetCatcher( trap_Key_GetCatcher() & ~KEYCATCH_UI );
- trap_Key_ClearStates();
- Cvar_Set( "cl_paused", "0" );
- //We're moving back out to the attract movie - re-enable all controllers to interrupt it!
- Cvar_SetValue( "inSplashMenu", 1 );
- // g_demoStartFade = 0;
- // g_demoStartTransition = 0;
- }
- void G_DemoKeypress()
- {
- g_demoLastKeypress = Sys_Milliseconds();
-
- //JLF moved
- // g_demoLastKeypress = Sys_Milliseconds();
-
- }
- extern void UI_SetActiveMenu( const char* menuname,const char *menuID );
- void G_DemoEnd()
- {
-
- if (!g_runningDemo)
- return;
- //CIN_StopCinematic(1);
- CIN_CloseAllVideos();
- // Key_SetCatcher( KEYCATCH_UI );
- Menus_CloseAll();
- g_ReturnToSplash = true;
- g_runningDemo = qfalse;
- G_DemoKeypress();
- trap_Key_SetCatcher( trap_Key_GetCatcher() & KEYCATCH_UI );
- trap_Key_ClearStates();
- Cvar_Set( "cl_paused", "0" );
- UI_SetActiveMenu("splashMenu", NULL);
- // g_demoStartFade = 0;
- // g_demoStartTransition = 0;
- // g_demoLastKeypress = 0;
- }
- void PlayDemo()
- {
- // bool keypressed = false;
- G_DemoStart();
- CIN_PlayAllFrames( "attract", 0, 0, 640, 480, 0, true );
- // while (!keypressed)
- // keypressed = CIN_PlayAllFrames( "atvi.bik", 0, 0, 640, 480, 0, true );
- G_DemoEnd();
- }
- void UpdateDemoTimer()
- {
- g_demoLastKeypress = Sys_Milliseconds();
- }
- bool TestDemoTimer()
- {
- //JLF TEMP DEBUG
- // return false;
- menuDef_t* curMenu = Menu_GetFocused();
- if (curMenu && curMenu->window.name &&
- (!Q_stricmp(curMenu->window.name , "mainMenu") ||
- !Q_stricmp(curMenu->window.name, "splashMenu")))
- {
- if (!g_demoLastKeypress)
- g_demoLastKeypress = Sys_Milliseconds();
- else if (g_demoLastKeypress + DEMO_TIME_MAX < Sys_Milliseconds())
- return true;
- }
- return false;
- }
- //END DEMOCODE
- #endif // _XBOX
|