fairygui.js 768 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026
  1. window.fgui = {};
  2. window.fairygui = window.fgui;
  3. window.__extends = (this && this.__extends) || (function () {
  4. var extendStatics = function (d, b) {
  5. extendStatics = Object.setPrototypeOf ||
  6. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  7. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  8. return extendStatics(d, b);
  9. };
  10. return function (d, b) {
  11. extendStatics(d, b);
  12. function __() { this.constructor = d; }
  13. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  14. };
  15. })();
  16. (function (fgui) {
  17. var AsyncOperation = (function () {
  18. function AsyncOperation() {
  19. }
  20. AsyncOperation.prototype.createObject = function (pkgName, resName) {
  21. if (this._node)
  22. throw 'Already running';
  23. var pkg = fgui.UIPackage.getByName(pkgName);
  24. if (pkg) {
  25. var pi = pkg.getItemByName(resName);
  26. if (!pi)
  27. throw new Error("resource not found: " + resName);
  28. this.internalCreateObject(pi);
  29. }
  30. else
  31. throw new Error("package not found: " + pkgName);
  32. };
  33. AsyncOperation.prototype.createObjectFromURL = function (url) {
  34. if (this._node)
  35. throw 'Already running';
  36. var pi = fgui.UIPackage.getItemByURL(url);
  37. if (pi)
  38. this.internalCreateObject(pi);
  39. else
  40. throw new Error("resource not found: " + url);
  41. };
  42. AsyncOperation.prototype.cancel = function () {
  43. if (this._node) {
  44. this._node.destroy();
  45. this._node = null;
  46. }
  47. };
  48. AsyncOperation.prototype.internalCreateObject = function (item) {
  49. this._node = new cc.Node("[AsyncCreating:" + item.name + "]");
  50. this._node.parent = cc.director.getScene();
  51. this._node.on("#", this.completed, this);
  52. this._node.addComponent(AsyncOperationRunner).init(item);
  53. };
  54. AsyncOperation.prototype.completed = function (result) {
  55. this.cancel();
  56. if (this.callback)
  57. this.callback(result);
  58. };
  59. return AsyncOperation;
  60. }());
  61. fgui.AsyncOperation = AsyncOperation;
  62. var AsyncOperationRunner = (function (_super) {
  63. __extends(AsyncOperationRunner, _super);
  64. function AsyncOperationRunner() {
  65. var _this = _super.call(this) || this;
  66. _this._itemList = new Array();
  67. _this._objectPool = new Array();
  68. return _this;
  69. }
  70. AsyncOperationRunner.prototype.init = function (item) {
  71. this._itemList.length = 0;
  72. this._objectPool.length = 0;
  73. var di = { pi: item, type: item.objectType };
  74. di.childCount = this.collectComponentChildren(item);
  75. this._itemList.push(di);
  76. this._index = 0;
  77. };
  78. AsyncOperationRunner.prototype.onDestroy = function () {
  79. this._itemList.length = 0;
  80. var cnt = this._objectPool.length;
  81. if (cnt > 0) {
  82. for (var i = 0; i < cnt; i++)
  83. this._objectPool[i].dispose();
  84. this._objectPool.length = 0;
  85. }
  86. };
  87. AsyncOperationRunner.prototype.collectComponentChildren = function (item) {
  88. var buffer = item.rawData;
  89. buffer.seek(0, 2);
  90. var di;
  91. var pi;
  92. var i;
  93. var dataLen;
  94. var curPos;
  95. var pkg;
  96. var dcnt = buffer.readShort();
  97. for (i = 0; i < dcnt; i++) {
  98. dataLen = buffer.readShort();
  99. curPos = buffer.position;
  100. buffer.seek(curPos, 0);
  101. var type = buffer.readByte();
  102. var src = buffer.readS();
  103. var pkgId = buffer.readS();
  104. buffer.position = curPos;
  105. if (src != null) {
  106. if (pkgId != null)
  107. pkg = fgui.UIPackage.getById(pkgId);
  108. else
  109. pkg = item.owner;
  110. pi = pkg != null ? pkg.getItemById(src) : null;
  111. di = { pi: pi, type: type };
  112. if (pi && pi.type == fgui.PackageItemType.Component)
  113. di.childCount = this.collectComponentChildren(pi);
  114. }
  115. else {
  116. di = { type: type };
  117. if (type == fgui.ObjectType.List)
  118. di.listItemCount = this.collectListChildren(buffer);
  119. }
  120. this._itemList.push(di);
  121. buffer.position = curPos + dataLen;
  122. }
  123. return dcnt;
  124. };
  125. AsyncOperationRunner.prototype.collectListChildren = function (buffer) {
  126. buffer.seek(buffer.position, 8);
  127. var listItemCount = 0;
  128. var i;
  129. var nextPos;
  130. var url;
  131. var pi;
  132. var di;
  133. var defaultItem = buffer.readS();
  134. var itemCount = buffer.readShort();
  135. for (i = 0; i < itemCount; i++) {
  136. nextPos = buffer.readShort();
  137. nextPos += buffer.position;
  138. url = buffer.readS();
  139. if (url == null)
  140. url = defaultItem;
  141. if (url) {
  142. pi = fgui.UIPackage.getItemByURL(url);
  143. if (pi) {
  144. di = { pi: pi, type: pi.objectType };
  145. if (pi.type == fgui.PackageItemType.Component)
  146. di.childCount = this.collectComponentChildren(pi);
  147. this._itemList.push(di);
  148. listItemCount++;
  149. }
  150. }
  151. buffer.position = nextPos;
  152. }
  153. return listItemCount;
  154. };
  155. AsyncOperationRunner.prototype.update = function () {
  156. var obj;
  157. var di;
  158. var poolStart;
  159. var k;
  160. var t = fgui.ToolSet.getTime();
  161. var frameTime = fgui.UIConfig.frameTimeForAsyncUIConstruction;
  162. var totalItems = this._itemList.length;
  163. while (this._index < totalItems) {
  164. di = this._itemList[this._index];
  165. if (di.pi) {
  166. obj = fgui.UIObjectFactory.newObject(di.pi);
  167. this._objectPool.push(obj);
  168. fgui.UIPackage._constructing++;
  169. if (di.pi.type == fgui.PackageItemType.Component) {
  170. poolStart = this._objectPool.length - di.childCount - 1;
  171. obj.constructFromResource2(this._objectPool, poolStart);
  172. this._objectPool.splice(poolStart, di.childCount);
  173. }
  174. else {
  175. obj.constructFromResource();
  176. }
  177. fgui.UIPackage._constructing--;
  178. }
  179. else {
  180. obj = fgui.UIObjectFactory.newObject(di.type);
  181. this._objectPool.push(obj);
  182. if (di.type == fgui.ObjectType.List && di.listItemCount > 0) {
  183. poolStart = this._objectPool.length - di.listItemCount - 1;
  184. for (k = 0; k < di.listItemCount; k++)
  185. obj.itemPool.returnObject(this._objectPool[k + poolStart]);
  186. this._objectPool.splice(poolStart, di.listItemCount);
  187. }
  188. }
  189. this._index++;
  190. if ((this._index % 5 == 0) && fgui.ToolSet.getTime() - t >= frameTime)
  191. return;
  192. }
  193. var result = this._objectPool[0];
  194. this._itemList.length = 0;
  195. this._objectPool.length = 0;
  196. this.node.emit("#", result);
  197. };
  198. return AsyncOperationRunner;
  199. }(cc.Component));
  200. })(fgui || (fgui = {}));
  201. (function (fgui) {
  202. var _nextPageId = 0;
  203. var Controller = (function (_super) {
  204. __extends(Controller, _super);
  205. function Controller() {
  206. var _this = _super.call(this) || this;
  207. _this._pageIds = [];
  208. _this._pageNames = [];
  209. _this._selectedIndex = -1;
  210. _this._previousIndex = -1;
  211. return _this;
  212. }
  213. Controller.prototype.dispose = function () {
  214. };
  215. Object.defineProperty(Controller.prototype, "selectedIndex", {
  216. get: function () {
  217. return this._selectedIndex;
  218. },
  219. set: function (value) {
  220. if (this._selectedIndex != value) {
  221. if (value > this._pageIds.length - 1)
  222. throw "index out of bounds: " + value;
  223. this.changing = true;
  224. this._previousIndex = this._selectedIndex;
  225. this._selectedIndex = value;
  226. this.parent.applyController(this);
  227. this.emit(fgui.Event.STATUS_CHANGED, this);
  228. this.changing = false;
  229. }
  230. },
  231. enumerable: false,
  232. configurable: true
  233. });
  234. Controller.prototype.onChanged = function (callback, target) {
  235. this.on(fgui.Event.STATUS_CHANGED, callback, target);
  236. };
  237. Controller.prototype.offChanged = function (callback, target) {
  238. this.off(fgui.Event.STATUS_CHANGED, callback, target);
  239. };
  240. Controller.prototype.setSelectedIndex = function (value) {
  241. if (this._selectedIndex != value) {
  242. if (value > this._pageIds.length - 1)
  243. throw "index out of bounds: " + value;
  244. this.changing = true;
  245. this._previousIndex = this._selectedIndex;
  246. this._selectedIndex = value;
  247. this.parent.applyController(this);
  248. this.changing = false;
  249. }
  250. };
  251. Object.defineProperty(Controller.prototype, "previsousIndex", {
  252. get: function () {
  253. return this._previousIndex;
  254. },
  255. enumerable: false,
  256. configurable: true
  257. });
  258. Object.defineProperty(Controller.prototype, "selectedPage", {
  259. get: function () {
  260. if (this._selectedIndex == -1)
  261. return null;
  262. else
  263. return this._pageNames[this._selectedIndex];
  264. },
  265. set: function (val) {
  266. var i = this._pageNames.indexOf(val);
  267. if (i == -1)
  268. i = 0;
  269. this.selectedIndex = i;
  270. },
  271. enumerable: false,
  272. configurable: true
  273. });
  274. Controller.prototype.setSelectedPage = function (value) {
  275. var i = this._pageNames.indexOf(value);
  276. if (i == -1)
  277. i = 0;
  278. this.setSelectedIndex(i);
  279. };
  280. Object.defineProperty(Controller.prototype, "previousPage", {
  281. get: function () {
  282. if (this._previousIndex == -1)
  283. return null;
  284. else
  285. return this._pageNames[this._previousIndex];
  286. },
  287. enumerable: false,
  288. configurable: true
  289. });
  290. Object.defineProperty(Controller.prototype, "pageCount", {
  291. get: function () {
  292. return this._pageIds.length;
  293. },
  294. enumerable: false,
  295. configurable: true
  296. });
  297. Controller.prototype.getPageName = function (index) {
  298. return this._pageNames[index];
  299. };
  300. Controller.prototype.addPage = function (name) {
  301. if (name === void 0) { name = ""; }
  302. this.addPageAt(name, this._pageIds.length);
  303. };
  304. Controller.prototype.addPageAt = function (name, index) {
  305. var nid = "" + (_nextPageId++);
  306. if (index == this._pageIds.length) {
  307. this._pageIds.push(nid);
  308. this._pageNames.push(name);
  309. }
  310. else {
  311. this._pageIds.splice(index, 0, nid);
  312. this._pageNames.splice(index, 0, name);
  313. }
  314. };
  315. Controller.prototype.removePage = function (name) {
  316. var i = this._pageNames.indexOf(name);
  317. if (i != -1) {
  318. this._pageIds.splice(i, 1);
  319. this._pageNames.splice(i, 1);
  320. if (this._selectedIndex >= this._pageIds.length)
  321. this.selectedIndex = this._selectedIndex - 1;
  322. else
  323. this.parent.applyController(this);
  324. }
  325. };
  326. Controller.prototype.removePageAt = function (index) {
  327. this._pageIds.splice(index, 1);
  328. this._pageNames.splice(index, 1);
  329. if (this._selectedIndex >= this._pageIds.length)
  330. this.selectedIndex = this._selectedIndex - 1;
  331. else
  332. this.parent.applyController(this);
  333. };
  334. Controller.prototype.clearPages = function () {
  335. this._pageIds.length = 0;
  336. this._pageNames.length = 0;
  337. if (this._selectedIndex != -1)
  338. this.selectedIndex = -1;
  339. else
  340. this.parent.applyController(this);
  341. };
  342. Controller.prototype.hasPage = function (aName) {
  343. return this._pageNames.indexOf(aName) != -1;
  344. };
  345. Controller.prototype.getPageIndexById = function (aId) {
  346. return this._pageIds.indexOf(aId);
  347. };
  348. Controller.prototype.getPageIdByName = function (aName) {
  349. var i = this._pageNames.indexOf(aName);
  350. if (i != -1)
  351. return this._pageIds[i];
  352. else
  353. return null;
  354. };
  355. Controller.prototype.getPageNameById = function (aId) {
  356. var i = this._pageIds.indexOf(aId);
  357. if (i != -1)
  358. return this._pageNames[i];
  359. else
  360. return null;
  361. };
  362. Controller.prototype.getPageId = function (index) {
  363. return this._pageIds[index];
  364. };
  365. Object.defineProperty(Controller.prototype, "selectedPageId", {
  366. get: function () {
  367. if (this._selectedIndex == -1)
  368. return null;
  369. else
  370. return this._pageIds[this._selectedIndex];
  371. },
  372. set: function (val) {
  373. var i = this._pageIds.indexOf(val);
  374. this.selectedIndex = i;
  375. },
  376. enumerable: false,
  377. configurable: true
  378. });
  379. Object.defineProperty(Controller.prototype, "oppositePageId", {
  380. set: function (val) {
  381. var i = this._pageIds.indexOf(val);
  382. if (i > 0)
  383. this.selectedIndex = 0;
  384. else if (this._pageIds.length > 1)
  385. this.selectedIndex = 1;
  386. },
  387. enumerable: false,
  388. configurable: true
  389. });
  390. Object.defineProperty(Controller.prototype, "previousPageId", {
  391. get: function () {
  392. if (this._previousIndex == -1)
  393. return null;
  394. else
  395. return this._pageIds[this._previousIndex];
  396. },
  397. enumerable: false,
  398. configurable: true
  399. });
  400. Controller.prototype.runActions = function () {
  401. if (this._actions) {
  402. var cnt = this._actions.length;
  403. for (var i = 0; i < cnt; i++)
  404. this._actions[i].run(this, this.previousPageId, this.selectedPageId);
  405. }
  406. };
  407. Controller.prototype.setup = function (buffer) {
  408. var beginPos = buffer.position;
  409. buffer.seek(beginPos, 0);
  410. this.name = buffer.readS();
  411. if (buffer.readBool())
  412. this.autoRadioGroupDepth = true;
  413. buffer.seek(beginPos, 1);
  414. var i;
  415. var nextPos;
  416. var cnt = buffer.readShort();
  417. for (i = 0; i < cnt; i++) {
  418. this._pageIds.push(buffer.readS());
  419. this._pageNames.push(buffer.readS());
  420. }
  421. var homePageIndex = 0;
  422. if (buffer.version >= 2) {
  423. var homePageType = buffer.readByte();
  424. switch (homePageType) {
  425. case 1:
  426. homePageIndex = buffer.readShort();
  427. break;
  428. case 2:
  429. homePageIndex = this._pageNames.indexOf(fgui.UIPackage.branch);
  430. if (homePageIndex == -1)
  431. homePageIndex = 0;
  432. break;
  433. case 3:
  434. homePageIndex = this._pageNames.indexOf(fgui.UIPackage.getVar(buffer.readS()));
  435. if (homePageIndex == -1)
  436. homePageIndex = 0;
  437. break;
  438. }
  439. }
  440. buffer.seek(beginPos, 2);
  441. cnt = buffer.readShort();
  442. if (cnt > 0) {
  443. if (!this._actions)
  444. this._actions = new Array();
  445. for (i = 0; i < cnt; i++) {
  446. nextPos = buffer.readShort();
  447. nextPos += buffer.position;
  448. var action = fgui.ControllerAction.createAction(buffer.readByte());
  449. action.setup(buffer);
  450. this._actions.push(action);
  451. buffer.position = nextPos;
  452. }
  453. }
  454. if (this.parent && this._pageIds.length > 0)
  455. this._selectedIndex = homePageIndex;
  456. else
  457. this._selectedIndex = -1;
  458. };
  459. return Controller;
  460. }(cc.EventTarget));
  461. fgui.Controller = Controller;
  462. })(fgui || (fgui = {}));
  463. (function (fgui) {
  464. var DragDropManager = (function () {
  465. function DragDropManager() {
  466. this._agent = new fgui.GLoader();
  467. this._agent.draggable = true;
  468. this._agent.touchable = false;
  469. this._agent.setSize(100, 100);
  470. this._agent.setPivot(0.5, 0.5, true);
  471. this._agent.align = fgui.AlignType.Center;
  472. this._agent.verticalAlign = fgui.VertAlignType.Middle;
  473. this._agent.sortingOrder = 1000000;
  474. this._agent.on(fgui.Event.DRAG_END, this.onDragEnd, this);
  475. }
  476. Object.defineProperty(DragDropManager, "inst", {
  477. get: function () {
  478. if (!DragDropManager._inst)
  479. DragDropManager._inst = new DragDropManager();
  480. return DragDropManager._inst;
  481. },
  482. enumerable: false,
  483. configurable: true
  484. });
  485. Object.defineProperty(DragDropManager.prototype, "dragAgent", {
  486. get: function () {
  487. return this._agent;
  488. },
  489. enumerable: false,
  490. configurable: true
  491. });
  492. Object.defineProperty(DragDropManager.prototype, "dragging", {
  493. get: function () {
  494. return this._agent.parent != null;
  495. },
  496. enumerable: false,
  497. configurable: true
  498. });
  499. DragDropManager.prototype.startDrag = function (source, icon, sourceData, touchId) {
  500. if (this._agent.parent)
  501. return;
  502. this._sourceData = sourceData;
  503. this._agent.url = icon;
  504. fgui.GRoot.inst.addChild(this._agent);
  505. var pt = fgui.GRoot.inst.getTouchPosition(touchId);
  506. pt = fgui.GRoot.inst.globalToLocal(pt.x, pt.y);
  507. this._agent.setPosition(pt.x, pt.y);
  508. this._agent.startDrag(touchId);
  509. };
  510. DragDropManager.prototype.cancel = function () {
  511. if (this._agent.parent) {
  512. this._agent.stopDrag();
  513. fgui.GRoot.inst.removeChild(this._agent);
  514. this._sourceData = null;
  515. }
  516. };
  517. DragDropManager.prototype.onDragEnd = function () {
  518. if (!this._agent.parent)
  519. return;
  520. fgui.GRoot.inst.removeChild(this._agent);
  521. var sourceData = this._sourceData;
  522. this._sourceData = null;
  523. var obj = fgui.GRoot.inst.touchTarget;
  524. while (obj) {
  525. if (obj.node.hasEventListener(fgui.Event.DROP)) {
  526. obj.requestFocus();
  527. obj.node.emit(fgui.Event.DROP, obj, sourceData);
  528. return;
  529. }
  530. obj = obj.parent;
  531. }
  532. };
  533. return DragDropManager;
  534. }());
  535. fgui.DragDropManager = DragDropManager;
  536. })(fgui || (fgui = {}));
  537. (function (fgui) {
  538. var ButtonMode;
  539. (function (ButtonMode) {
  540. ButtonMode[ButtonMode["Common"] = 0] = "Common";
  541. ButtonMode[ButtonMode["Check"] = 1] = "Check";
  542. ButtonMode[ButtonMode["Radio"] = 2] = "Radio";
  543. })(ButtonMode = fgui.ButtonMode || (fgui.ButtonMode = {}));
  544. var AutoSizeType;
  545. (function (AutoSizeType) {
  546. AutoSizeType[AutoSizeType["None"] = 0] = "None";
  547. AutoSizeType[AutoSizeType["Both"] = 1] = "Both";
  548. AutoSizeType[AutoSizeType["Height"] = 2] = "Height";
  549. AutoSizeType[AutoSizeType["Shrink"] = 3] = "Shrink";
  550. })(AutoSizeType = fgui.AutoSizeType || (fgui.AutoSizeType = {}));
  551. var AlignType;
  552. (function (AlignType) {
  553. AlignType[AlignType["Left"] = 0] = "Left";
  554. AlignType[AlignType["Center"] = 1] = "Center";
  555. AlignType[AlignType["Right"] = 2] = "Right";
  556. })(AlignType = fgui.AlignType || (fgui.AlignType = {}));
  557. var VertAlignType;
  558. (function (VertAlignType) {
  559. VertAlignType[VertAlignType["Top"] = 0] = "Top";
  560. VertAlignType[VertAlignType["Middle"] = 1] = "Middle";
  561. VertAlignType[VertAlignType["Bottom"] = 2] = "Bottom";
  562. })(VertAlignType = fgui.VertAlignType || (fgui.VertAlignType = {}));
  563. var LoaderFillType;
  564. (function (LoaderFillType) {
  565. LoaderFillType[LoaderFillType["None"] = 0] = "None";
  566. LoaderFillType[LoaderFillType["Scale"] = 1] = "Scale";
  567. LoaderFillType[LoaderFillType["ScaleMatchHeight"] = 2] = "ScaleMatchHeight";
  568. LoaderFillType[LoaderFillType["ScaleMatchWidth"] = 3] = "ScaleMatchWidth";
  569. LoaderFillType[LoaderFillType["ScaleFree"] = 4] = "ScaleFree";
  570. LoaderFillType[LoaderFillType["ScaleNoBorder"] = 5] = "ScaleNoBorder";
  571. })(LoaderFillType = fgui.LoaderFillType || (fgui.LoaderFillType = {}));
  572. var ListLayoutType;
  573. (function (ListLayoutType) {
  574. ListLayoutType[ListLayoutType["SingleColumn"] = 0] = "SingleColumn";
  575. ListLayoutType[ListLayoutType["SingleRow"] = 1] = "SingleRow";
  576. ListLayoutType[ListLayoutType["FlowHorizontal"] = 2] = "FlowHorizontal";
  577. ListLayoutType[ListLayoutType["FlowVertical"] = 3] = "FlowVertical";
  578. ListLayoutType[ListLayoutType["Pagination"] = 4] = "Pagination";
  579. })(ListLayoutType = fgui.ListLayoutType || (fgui.ListLayoutType = {}));
  580. var ListSelectionMode;
  581. (function (ListSelectionMode) {
  582. ListSelectionMode[ListSelectionMode["Single"] = 0] = "Single";
  583. ListSelectionMode[ListSelectionMode["Multiple"] = 1] = "Multiple";
  584. ListSelectionMode[ListSelectionMode["Multiple_SingleClick"] = 2] = "Multiple_SingleClick";
  585. ListSelectionMode[ListSelectionMode["None"] = 3] = "None";
  586. })(ListSelectionMode = fgui.ListSelectionMode || (fgui.ListSelectionMode = {}));
  587. var OverflowType;
  588. (function (OverflowType) {
  589. OverflowType[OverflowType["Visible"] = 0] = "Visible";
  590. OverflowType[OverflowType["Hidden"] = 1] = "Hidden";
  591. OverflowType[OverflowType["Scroll"] = 2] = "Scroll";
  592. })(OverflowType = fgui.OverflowType || (fgui.OverflowType = {}));
  593. var PackageItemType;
  594. (function (PackageItemType) {
  595. PackageItemType[PackageItemType["Image"] = 0] = "Image";
  596. PackageItemType[PackageItemType["MovieClip"] = 1] = "MovieClip";
  597. PackageItemType[PackageItemType["Sound"] = 2] = "Sound";
  598. PackageItemType[PackageItemType["Component"] = 3] = "Component";
  599. PackageItemType[PackageItemType["Atlas"] = 4] = "Atlas";
  600. PackageItemType[PackageItemType["Font"] = 5] = "Font";
  601. PackageItemType[PackageItemType["Swf"] = 6] = "Swf";
  602. PackageItemType[PackageItemType["Misc"] = 7] = "Misc";
  603. PackageItemType[PackageItemType["Unknown"] = 8] = "Unknown";
  604. PackageItemType[PackageItemType["Spine"] = 9] = "Spine";
  605. PackageItemType[PackageItemType["DragonBones"] = 10] = "DragonBones";
  606. })(PackageItemType = fgui.PackageItemType || (fgui.PackageItemType = {}));
  607. var ObjectType;
  608. (function (ObjectType) {
  609. ObjectType[ObjectType["Image"] = 0] = "Image";
  610. ObjectType[ObjectType["MovieClip"] = 1] = "MovieClip";
  611. ObjectType[ObjectType["Swf"] = 2] = "Swf";
  612. ObjectType[ObjectType["Graph"] = 3] = "Graph";
  613. ObjectType[ObjectType["Loader"] = 4] = "Loader";
  614. ObjectType[ObjectType["Group"] = 5] = "Group";
  615. ObjectType[ObjectType["Text"] = 6] = "Text";
  616. ObjectType[ObjectType["RichText"] = 7] = "RichText";
  617. ObjectType[ObjectType["InputText"] = 8] = "InputText";
  618. ObjectType[ObjectType["Component"] = 9] = "Component";
  619. ObjectType[ObjectType["List"] = 10] = "List";
  620. ObjectType[ObjectType["Label"] = 11] = "Label";
  621. ObjectType[ObjectType["Button"] = 12] = "Button";
  622. ObjectType[ObjectType["ComboBox"] = 13] = "ComboBox";
  623. ObjectType[ObjectType["ProgressBar"] = 14] = "ProgressBar";
  624. ObjectType[ObjectType["Slider"] = 15] = "Slider";
  625. ObjectType[ObjectType["ScrollBar"] = 16] = "ScrollBar";
  626. ObjectType[ObjectType["Tree"] = 17] = "Tree";
  627. ObjectType[ObjectType["Loader3D"] = 18] = "Loader3D";
  628. })(ObjectType = fgui.ObjectType || (fgui.ObjectType = {}));
  629. var ProgressTitleType;
  630. (function (ProgressTitleType) {
  631. ProgressTitleType[ProgressTitleType["Percent"] = 0] = "Percent";
  632. ProgressTitleType[ProgressTitleType["ValueAndMax"] = 1] = "ValueAndMax";
  633. ProgressTitleType[ProgressTitleType["Value"] = 2] = "Value";
  634. ProgressTitleType[ProgressTitleType["Max"] = 3] = "Max";
  635. })(ProgressTitleType = fgui.ProgressTitleType || (fgui.ProgressTitleType = {}));
  636. var ScrollBarDisplayType;
  637. (function (ScrollBarDisplayType) {
  638. ScrollBarDisplayType[ScrollBarDisplayType["Default"] = 0] = "Default";
  639. ScrollBarDisplayType[ScrollBarDisplayType["Visible"] = 1] = "Visible";
  640. ScrollBarDisplayType[ScrollBarDisplayType["Auto"] = 2] = "Auto";
  641. ScrollBarDisplayType[ScrollBarDisplayType["Hidden"] = 3] = "Hidden";
  642. })(ScrollBarDisplayType = fgui.ScrollBarDisplayType || (fgui.ScrollBarDisplayType = {}));
  643. var ScrollType;
  644. (function (ScrollType) {
  645. ScrollType[ScrollType["Horizontal"] = 0] = "Horizontal";
  646. ScrollType[ScrollType["Vertical"] = 1] = "Vertical";
  647. ScrollType[ScrollType["Both"] = 2] = "Both";
  648. })(ScrollType = fgui.ScrollType || (fgui.ScrollType = {}));
  649. var FlipType;
  650. (function (FlipType) {
  651. FlipType[FlipType["None"] = 0] = "None";
  652. FlipType[FlipType["Horizontal"] = 1] = "Horizontal";
  653. FlipType[FlipType["Vertical"] = 2] = "Vertical";
  654. FlipType[FlipType["Both"] = 3] = "Both";
  655. })(FlipType = fgui.FlipType || (fgui.FlipType = {}));
  656. var ChildrenRenderOrder;
  657. (function (ChildrenRenderOrder) {
  658. ChildrenRenderOrder[ChildrenRenderOrder["Ascent"] = 0] = "Ascent";
  659. ChildrenRenderOrder[ChildrenRenderOrder["Descent"] = 1] = "Descent";
  660. ChildrenRenderOrder[ChildrenRenderOrder["Arch"] = 2] = "Arch";
  661. })(ChildrenRenderOrder = fgui.ChildrenRenderOrder || (fgui.ChildrenRenderOrder = {}));
  662. var GroupLayoutType;
  663. (function (GroupLayoutType) {
  664. GroupLayoutType[GroupLayoutType["None"] = 0] = "None";
  665. GroupLayoutType[GroupLayoutType["Horizontal"] = 1] = "Horizontal";
  666. GroupLayoutType[GroupLayoutType["Vertical"] = 2] = "Vertical";
  667. })(GroupLayoutType = fgui.GroupLayoutType || (fgui.GroupLayoutType = {}));
  668. var PopupDirection;
  669. (function (PopupDirection) {
  670. PopupDirection[PopupDirection["Auto"] = 0] = "Auto";
  671. PopupDirection[PopupDirection["Up"] = 1] = "Up";
  672. PopupDirection[PopupDirection["Down"] = 2] = "Down";
  673. })(PopupDirection = fgui.PopupDirection || (fgui.PopupDirection = {}));
  674. var RelationType;
  675. (function (RelationType) {
  676. RelationType[RelationType["Left_Left"] = 0] = "Left_Left";
  677. RelationType[RelationType["Left_Center"] = 1] = "Left_Center";
  678. RelationType[RelationType["Left_Right"] = 2] = "Left_Right";
  679. RelationType[RelationType["Center_Center"] = 3] = "Center_Center";
  680. RelationType[RelationType["Right_Left"] = 4] = "Right_Left";
  681. RelationType[RelationType["Right_Center"] = 5] = "Right_Center";
  682. RelationType[RelationType["Right_Right"] = 6] = "Right_Right";
  683. RelationType[RelationType["Top_Top"] = 7] = "Top_Top";
  684. RelationType[RelationType["Top_Middle"] = 8] = "Top_Middle";
  685. RelationType[RelationType["Top_Bottom"] = 9] = "Top_Bottom";
  686. RelationType[RelationType["Middle_Middle"] = 10] = "Middle_Middle";
  687. RelationType[RelationType["Bottom_Top"] = 11] = "Bottom_Top";
  688. RelationType[RelationType["Bottom_Middle"] = 12] = "Bottom_Middle";
  689. RelationType[RelationType["Bottom_Bottom"] = 13] = "Bottom_Bottom";
  690. RelationType[RelationType["Width"] = 14] = "Width";
  691. RelationType[RelationType["Height"] = 15] = "Height";
  692. RelationType[RelationType["LeftExt_Left"] = 16] = "LeftExt_Left";
  693. RelationType[RelationType["LeftExt_Right"] = 17] = "LeftExt_Right";
  694. RelationType[RelationType["RightExt_Left"] = 18] = "RightExt_Left";
  695. RelationType[RelationType["RightExt_Right"] = 19] = "RightExt_Right";
  696. RelationType[RelationType["TopExt_Top"] = 20] = "TopExt_Top";
  697. RelationType[RelationType["TopExt_Bottom"] = 21] = "TopExt_Bottom";
  698. RelationType[RelationType["BottomExt_Top"] = 22] = "BottomExt_Top";
  699. RelationType[RelationType["BottomExt_Bottom"] = 23] = "BottomExt_Bottom";
  700. RelationType[RelationType["Size"] = 24] = "Size";
  701. })(RelationType = fgui.RelationType || (fgui.RelationType = {}));
  702. var FillMethod;
  703. (function (FillMethod) {
  704. FillMethod[FillMethod["None"] = 0] = "None";
  705. FillMethod[FillMethod["Horizontal"] = 1] = "Horizontal";
  706. FillMethod[FillMethod["Vertical"] = 2] = "Vertical";
  707. FillMethod[FillMethod["Radial90"] = 3] = "Radial90";
  708. FillMethod[FillMethod["Radial180"] = 4] = "Radial180";
  709. FillMethod[FillMethod["Radial360"] = 5] = "Radial360";
  710. })(FillMethod = fgui.FillMethod || (fgui.FillMethod = {}));
  711. var FillOrigin;
  712. (function (FillOrigin) {
  713. FillOrigin[FillOrigin["Top"] = 0] = "Top";
  714. FillOrigin[FillOrigin["Bottom"] = 1] = "Bottom";
  715. FillOrigin[FillOrigin["Left"] = 2] = "Left";
  716. FillOrigin[FillOrigin["Right"] = 3] = "Right";
  717. })(FillOrigin = fgui.FillOrigin || (fgui.FillOrigin = {}));
  718. var ObjectPropID;
  719. (function (ObjectPropID) {
  720. ObjectPropID[ObjectPropID["Text"] = 0] = "Text";
  721. ObjectPropID[ObjectPropID["Icon"] = 1] = "Icon";
  722. ObjectPropID[ObjectPropID["Color"] = 2] = "Color";
  723. ObjectPropID[ObjectPropID["OutlineColor"] = 3] = "OutlineColor";
  724. ObjectPropID[ObjectPropID["Playing"] = 4] = "Playing";
  725. ObjectPropID[ObjectPropID["Frame"] = 5] = "Frame";
  726. ObjectPropID[ObjectPropID["DeltaTime"] = 6] = "DeltaTime";
  727. ObjectPropID[ObjectPropID["TimeScale"] = 7] = "TimeScale";
  728. ObjectPropID[ObjectPropID["FontSize"] = 8] = "FontSize";
  729. ObjectPropID[ObjectPropID["Selected"] = 9] = "Selected";
  730. })(ObjectPropID = fgui.ObjectPropID || (fgui.ObjectPropID = {}));
  731. })(fgui || (fgui = {}));
  732. (function (fgui) {
  733. var GObject = (function () {
  734. function GObject() {
  735. this._x = 0;
  736. this._y = 0;
  737. this._alpha = 1;
  738. this._visible = true;
  739. this._touchable = true;
  740. this._skewX = 0;
  741. this._skewY = 0;
  742. this._sortingOrder = 0;
  743. this._internalVisible = true;
  744. this.sourceWidth = 0;
  745. this.sourceHeight = 0;
  746. this.initWidth = 0;
  747. this.initHeight = 0;
  748. this.minWidth = 0;
  749. this.minHeight = 0;
  750. this.maxWidth = 0;
  751. this.maxHeight = 0;
  752. this._width = 0;
  753. this._height = 0;
  754. this._rawWidth = 0;
  755. this._rawHeight = 0;
  756. this._sizePercentInGroup = 0;
  757. this._node = new cc.Node();
  758. if (GObject._defaultGroupIndex == -1) {
  759. GObject._defaultGroupIndex = 0;
  760. var groups = cc.game.groupList;
  761. var cnt = groups.length;
  762. for (var i = 0; i < cnt; i++) {
  763. if (groups[i].toLowerCase() == fgui.UIConfig.defaultUIGroup.toLowerCase()) {
  764. GObject._defaultGroupIndex = i;
  765. break;
  766. }
  767. }
  768. }
  769. this._node["$gobj"] = this;
  770. this._node.groupIndex = GObject._defaultGroupIndex;
  771. this._node.setAnchorPoint(0, 1);
  772. this._node.on(cc.Node.EventType.ANCHOR_CHANGED, this.handleAnchorChanged, this);
  773. this._id = this._node.uuid;
  774. this._name = "";
  775. this._relations = new fgui.Relations(this);
  776. this._gears = new Array(10);
  777. this._blendMode = fgui.BlendMode.Normal;
  778. this._partner = this._node.addComponent(GObjectPartner);
  779. }
  780. Object.defineProperty(GObject.prototype, "id", {
  781. get: function () {
  782. return this._id;
  783. },
  784. enumerable: false,
  785. configurable: true
  786. });
  787. Object.defineProperty(GObject.prototype, "name", {
  788. get: function () {
  789. return this._name;
  790. },
  791. set: function (value) {
  792. this._name = value;
  793. },
  794. enumerable: false,
  795. configurable: true
  796. });
  797. Object.defineProperty(GObject.prototype, "x", {
  798. get: function () {
  799. return this._x;
  800. },
  801. set: function (value) {
  802. this.setPosition(value, this._y);
  803. },
  804. enumerable: false,
  805. configurable: true
  806. });
  807. Object.defineProperty(GObject.prototype, "y", {
  808. get: function () {
  809. return this._y;
  810. },
  811. set: function (value) {
  812. this.setPosition(this._x, value);
  813. },
  814. enumerable: false,
  815. configurable: true
  816. });
  817. Object.defineProperty(GObject.prototype, "position", {
  818. get: function () {
  819. return cc.v3(this._x, this._y, 0);
  820. },
  821. set: function (value) {
  822. this.setPosition(value.x, value.y, value.z);
  823. },
  824. enumerable: false,
  825. configurable: true
  826. });
  827. GObject.prototype.setPosition = function (xv, yv) {
  828. if (this._x != xv || this._y != yv) {
  829. var dx = xv - this._x;
  830. var dy = yv - this._y;
  831. this._x = xv;
  832. this._y = yv;
  833. this.handlePositionChanged();
  834. if (this instanceof fgui.GGroup)
  835. this.moveChildren(dx, dy);
  836. this.updateGear(1);
  837. if (this._parent && !(this._parent instanceof fgui.GList)) {
  838. this._parent.setBoundsChangedFlag();
  839. if (this._group)
  840. this._group.setBoundsChangedFlag(true);
  841. this._node.emit(fgui.Event.XY_CHANGED, this);
  842. }
  843. if (GObject.draggingObject == this && !sUpdateInDragging)
  844. this.localToGlobalRect(0, 0, this._width, this._height, sGlobalRect);
  845. }
  846. };
  847. Object.defineProperty(GObject.prototype, "xMin", {
  848. get: function () {
  849. return this._pivotAsAnchor ? (this._x - this._width * this.node.anchorX) : this._x;
  850. },
  851. set: function (value) {
  852. if (this._pivotAsAnchor)
  853. this.setPosition(value + this._width * this.node.anchorX, this._y);
  854. else
  855. this.setPosition(value, this._y);
  856. },
  857. enumerable: false,
  858. configurable: true
  859. });
  860. Object.defineProperty(GObject.prototype, "yMin", {
  861. get: function () {
  862. return this._pivotAsAnchor ? (this._y - this._height * (1 - this.node.anchorY)) : this._y;
  863. },
  864. set: function (value) {
  865. if (this._pivotAsAnchor)
  866. this.setPosition(this._x, value + this._height * (1 - this.node.anchorY));
  867. else
  868. this.setPosition(this._x, value);
  869. },
  870. enumerable: false,
  871. configurable: true
  872. });
  873. Object.defineProperty(GObject.prototype, "pixelSnapping", {
  874. get: function () {
  875. return this._pixelSnapping;
  876. },
  877. set: function (value) {
  878. if (this._pixelSnapping != value) {
  879. this._pixelSnapping = value;
  880. this.handlePositionChanged();
  881. }
  882. },
  883. enumerable: false,
  884. configurable: true
  885. });
  886. GObject.prototype.center = function (restraint) {
  887. var r;
  888. if (this._parent)
  889. r = this.parent;
  890. else
  891. r = this.root;
  892. this.setPosition((r.width - this._width) / 2, (r.height - this._height) / 2);
  893. if (restraint) {
  894. this.addRelation(r, fgui.RelationType.Center_Center);
  895. this.addRelation(r, fgui.RelationType.Middle_Middle);
  896. }
  897. };
  898. Object.defineProperty(GObject.prototype, "width", {
  899. get: function () {
  900. this.ensureSizeCorrect();
  901. if (this._relations.sizeDirty)
  902. this._relations.ensureRelationsSizeCorrect();
  903. return this._width;
  904. },
  905. set: function (value) {
  906. this.setSize(value, this._rawHeight);
  907. },
  908. enumerable: false,
  909. configurable: true
  910. });
  911. Object.defineProperty(GObject.prototype, "height", {
  912. get: function () {
  913. this.ensureSizeCorrect();
  914. if (this._relations.sizeDirty)
  915. this._relations.ensureRelationsSizeCorrect();
  916. return this._height;
  917. },
  918. set: function (value) {
  919. this.setSize(this._rawWidth, value);
  920. },
  921. enumerable: false,
  922. configurable: true
  923. });
  924. GObject.prototype.setSize = function (wv, hv, ignorePivot) {
  925. if (this._rawWidth != wv || this._rawHeight != hv) {
  926. this._rawWidth = wv;
  927. this._rawHeight = hv;
  928. if (wv < this.minWidth)
  929. wv = this.minWidth;
  930. if (hv < this.minHeight)
  931. hv = this.minHeight;
  932. if (this.maxWidth > 0 && wv > this.maxWidth)
  933. wv = this.maxWidth;
  934. if (this.maxHeight > 0 && hv > this.maxHeight)
  935. hv = this.maxHeight;
  936. var dWidth = wv - this._width;
  937. var dHeight = hv - this._height;
  938. this._width = wv;
  939. this._height = hv;
  940. this.handleSizeChanged();
  941. if ((this.node.anchorX != 0 || this.node.anchorY != 1) && !this._pivotAsAnchor && !ignorePivot)
  942. this.setPosition(this.x - this.node.anchorX * dWidth, this.y - (1 - this.node.anchorY) * dHeight);
  943. else
  944. this.handlePositionChanged();
  945. if (this instanceof fgui.GGroup)
  946. this.resizeChildren(dWidth, dHeight);
  947. this.updateGear(2);
  948. if (this._parent) {
  949. this._relations.onOwnerSizeChanged(dWidth, dHeight, this._pivotAsAnchor || !ignorePivot);
  950. this._parent.setBoundsChangedFlag();
  951. if (this._group)
  952. this._group.setBoundsChangedFlag();
  953. }
  954. this._node.emit(fgui.Event.SIZE_CHANGED, this);
  955. }
  956. };
  957. GObject.prototype.makeFullScreen = function () {
  958. this.setSize(fgui.GRoot.inst.width, fgui.GRoot.inst.height);
  959. };
  960. GObject.prototype.ensureSizeCorrect = function () {
  961. };
  962. Object.defineProperty(GObject.prototype, "actualWidth", {
  963. get: function () {
  964. return this.width * Math.abs(this._node.scaleX);
  965. },
  966. enumerable: false,
  967. configurable: true
  968. });
  969. Object.defineProperty(GObject.prototype, "actualHeight", {
  970. get: function () {
  971. return this.height * Math.abs(this._node.scaleY);
  972. },
  973. enumerable: false,
  974. configurable: true
  975. });
  976. Object.defineProperty(GObject.prototype, "scaleX", {
  977. get: function () {
  978. return this._node.scaleX;
  979. },
  980. set: function (value) {
  981. this.setScale(value, this._node.scaleY);
  982. },
  983. enumerable: false,
  984. configurable: true
  985. });
  986. Object.defineProperty(GObject.prototype, "scaleY", {
  987. get: function () {
  988. return this._node.scaleY;
  989. },
  990. set: function (value) {
  991. this.setScale(this._node.scaleX, value);
  992. },
  993. enumerable: false,
  994. configurable: true
  995. });
  996. GObject.prototype.setScale = function (sx, sy) {
  997. if (this._node.scaleX != sx || this._node.scaleY != sy) {
  998. this._node.setScale(sx, sy);
  999. this.updateGear(2);
  1000. }
  1001. };
  1002. Object.defineProperty(GObject.prototype, "skewX", {
  1003. get: function () {
  1004. return this._skewX;
  1005. },
  1006. set: function (value) {
  1007. this.setSkew(value, this._skewY);
  1008. },
  1009. enumerable: false,
  1010. configurable: true
  1011. });
  1012. Object.defineProperty(GObject.prototype, "skewY", {
  1013. get: function () {
  1014. return this._skewY;
  1015. },
  1016. set: function (value) {
  1017. this.setSkew(this._skewX, value);
  1018. },
  1019. enumerable: false,
  1020. configurable: true
  1021. });
  1022. GObject.prototype.setSkew = function (xv, yv) {
  1023. if (this._skewX != xv || this._skewY != yv) {
  1024. this._skewX = xv;
  1025. this._skewY = yv;
  1026. this._node.skewX = xv;
  1027. this._node.skewY = yv;
  1028. }
  1029. };
  1030. Object.defineProperty(GObject.prototype, "pivotX", {
  1031. get: function () {
  1032. return this.node.anchorX;
  1033. },
  1034. set: function (value) {
  1035. this.node.anchorX = value;
  1036. },
  1037. enumerable: false,
  1038. configurable: true
  1039. });
  1040. Object.defineProperty(GObject.prototype, "pivotY", {
  1041. get: function () {
  1042. return 1 - this.node.anchorY;
  1043. },
  1044. set: function (value) {
  1045. this.node.anchorY = 1 - value;
  1046. },
  1047. enumerable: false,
  1048. configurable: true
  1049. });
  1050. GObject.prototype.setPivot = function (xv, yv, asAnchor) {
  1051. if (this.node.anchorX != xv || this.node.anchorY != 1 - yv) {
  1052. this._pivotAsAnchor = asAnchor;
  1053. this.node.setAnchorPoint(xv, 1 - yv);
  1054. }
  1055. else if (this._pivotAsAnchor != asAnchor) {
  1056. this._pivotAsAnchor = asAnchor;
  1057. this.handlePositionChanged();
  1058. }
  1059. };
  1060. Object.defineProperty(GObject.prototype, "pivotAsAnchor", {
  1061. get: function () {
  1062. return this._pivotAsAnchor;
  1063. },
  1064. enumerable: false,
  1065. configurable: true
  1066. });
  1067. Object.defineProperty(GObject.prototype, "touchable", {
  1068. get: function () {
  1069. return this._touchable;
  1070. },
  1071. set: function (value) {
  1072. if (this._touchable != value) {
  1073. this._touchable = value;
  1074. this.updateGear(3);
  1075. }
  1076. },
  1077. enumerable: false,
  1078. configurable: true
  1079. });
  1080. Object.defineProperty(GObject.prototype, "grayed", {
  1081. get: function () {
  1082. return this._grayed;
  1083. },
  1084. set: function (value) {
  1085. if (this._grayed != value) {
  1086. this._grayed = value;
  1087. this.handleGrayedChanged();
  1088. this.updateGear(3);
  1089. }
  1090. },
  1091. enumerable: false,
  1092. configurable: true
  1093. });
  1094. Object.defineProperty(GObject.prototype, "enabled", {
  1095. get: function () {
  1096. return !this._grayed && this._touchable;
  1097. },
  1098. set: function (value) {
  1099. this.grayed = !value;
  1100. this.touchable = value;
  1101. },
  1102. enumerable: false,
  1103. configurable: true
  1104. });
  1105. Object.defineProperty(GObject.prototype, "rotation", {
  1106. get: function () {
  1107. return -this._node.angle;
  1108. },
  1109. set: function (value) {
  1110. value = -value;
  1111. if (this._node.angle != value) {
  1112. this._node.angle = value;
  1113. this.updateGear(3);
  1114. }
  1115. },
  1116. enumerable: false,
  1117. configurable: true
  1118. });
  1119. Object.defineProperty(GObject.prototype, "alpha", {
  1120. get: function () {
  1121. return this._alpha;
  1122. },
  1123. set: function (value) {
  1124. if (this._alpha != value) {
  1125. this._alpha = value;
  1126. this._node.opacity = this._alpha * 255;
  1127. if (this instanceof fgui.GGroup)
  1128. this.handleAlphaChanged();
  1129. this.updateGear(3);
  1130. }
  1131. },
  1132. enumerable: false,
  1133. configurable: true
  1134. });
  1135. Object.defineProperty(GObject.prototype, "visible", {
  1136. get: function () {
  1137. return this._visible;
  1138. },
  1139. set: function (value) {
  1140. if (this._visible != value) {
  1141. this._visible = value;
  1142. this.handleVisibleChanged();
  1143. if (this._group && this._group.excludeInvisibles)
  1144. this._group.setBoundsChangedFlag();
  1145. }
  1146. },
  1147. enumerable: false,
  1148. configurable: true
  1149. });
  1150. Object.defineProperty(GObject.prototype, "_finalVisible", {
  1151. get: function () {
  1152. return this._visible && this._internalVisible && (!this._group || this._group._finalVisible);
  1153. },
  1154. enumerable: false,
  1155. configurable: true
  1156. });
  1157. Object.defineProperty(GObject.prototype, "internalVisible3", {
  1158. get: function () {
  1159. return this._visible && this._internalVisible;
  1160. },
  1161. enumerable: false,
  1162. configurable: true
  1163. });
  1164. Object.defineProperty(GObject.prototype, "sortingOrder", {
  1165. get: function () {
  1166. return this._sortingOrder;
  1167. },
  1168. set: function (value) {
  1169. if (value < 0)
  1170. value = 0;
  1171. if (this._sortingOrder != value) {
  1172. var old = this._sortingOrder;
  1173. this._sortingOrder = value;
  1174. if (this._parent)
  1175. this._parent.childSortingOrderChanged(this, old, this._sortingOrder);
  1176. }
  1177. },
  1178. enumerable: false,
  1179. configurable: true
  1180. });
  1181. GObject.prototype.requestFocus = function () {
  1182. };
  1183. Object.defineProperty(GObject.prototype, "tooltips", {
  1184. get: function () {
  1185. return this._tooltips;
  1186. },
  1187. set: function (value) {
  1188. if (this._tooltips) {
  1189. this._node.off(fgui.Event.ROLL_OVER, this.onRollOver, this);
  1190. this._node.off(fgui.Event.ROLL_OUT, this.onRollOut, this);
  1191. }
  1192. this._tooltips = value;
  1193. if (this._tooltips) {
  1194. this._node.on(fgui.Event.ROLL_OVER, this.onRollOver, this);
  1195. this._node.on(fgui.Event.ROLL_OUT, this.onRollOut, this);
  1196. }
  1197. },
  1198. enumerable: false,
  1199. configurable: true
  1200. });
  1201. Object.defineProperty(GObject.prototype, "blendMode", {
  1202. get: function () {
  1203. return this._blendMode;
  1204. },
  1205. set: function (value) {
  1206. if (this._blendMode != value) {
  1207. this._blendMode = value;
  1208. fgui.BlendModeUtils.apply(this._node, value);
  1209. }
  1210. },
  1211. enumerable: false,
  1212. configurable: true
  1213. });
  1214. Object.defineProperty(GObject.prototype, "onStage", {
  1215. get: function () {
  1216. return this._node && this._node.activeInHierarchy;
  1217. },
  1218. enumerable: false,
  1219. configurable: true
  1220. });
  1221. Object.defineProperty(GObject.prototype, "resourceURL", {
  1222. get: function () {
  1223. if (this.packageItem)
  1224. return "ui://" + this.packageItem.owner.id + this.packageItem.id;
  1225. else
  1226. return null;
  1227. },
  1228. enumerable: false,
  1229. configurable: true
  1230. });
  1231. Object.defineProperty(GObject.prototype, "group", {
  1232. get: function () {
  1233. return this._group;
  1234. },
  1235. set: function (value) {
  1236. if (this._group != value) {
  1237. if (this._group)
  1238. this._group.setBoundsChangedFlag();
  1239. this._group = value;
  1240. if (this._group)
  1241. this._group.setBoundsChangedFlag();
  1242. }
  1243. },
  1244. enumerable: false,
  1245. configurable: true
  1246. });
  1247. GObject.prototype.getGear = function (index) {
  1248. var gear = this._gears[index];
  1249. if (!gear)
  1250. this._gears[index] = gear = fgui.GearBase.create(this, index);
  1251. return gear;
  1252. };
  1253. GObject.prototype.updateGear = function (index) {
  1254. if (this._underConstruct || this._gearLocked)
  1255. return;
  1256. var gear = this._gears[index];
  1257. if (gear && gear.controller)
  1258. gear.updateState();
  1259. };
  1260. GObject.prototype.checkGearController = function (index, c) {
  1261. return this._gears[index] && this._gears[index].controller == c;
  1262. };
  1263. GObject.prototype.updateGearFromRelations = function (index, dx, dy) {
  1264. if (this._gears[index])
  1265. this._gears[index].updateFromRelations(dx, dy);
  1266. };
  1267. GObject.prototype.addDisplayLock = function () {
  1268. var gearDisplay = this._gears[0];
  1269. if (gearDisplay && gearDisplay.controller) {
  1270. var ret = gearDisplay.addLock();
  1271. this.checkGearDisplay();
  1272. return ret;
  1273. }
  1274. else
  1275. return 0;
  1276. };
  1277. GObject.prototype.releaseDisplayLock = function (token) {
  1278. var gearDisplay = this._gears[0];
  1279. if (gearDisplay && gearDisplay.controller) {
  1280. gearDisplay.releaseLock(token);
  1281. this.checkGearDisplay();
  1282. }
  1283. };
  1284. GObject.prototype.checkGearDisplay = function () {
  1285. if (this._handlingController)
  1286. return;
  1287. var connected = this._gears[0] == null || this._gears[0].connected;
  1288. if (this._gears[8])
  1289. connected = this._gears[8].evaluate(connected);
  1290. if (connected != this._internalVisible) {
  1291. this._internalVisible = connected;
  1292. this.handleVisibleChanged();
  1293. if (this._group && this._group.excludeInvisibles)
  1294. this._group.setBoundsChangedFlag();
  1295. }
  1296. };
  1297. Object.defineProperty(GObject.prototype, "gearXY", {
  1298. get: function () {
  1299. return this.getGear(1);
  1300. },
  1301. enumerable: false,
  1302. configurable: true
  1303. });
  1304. Object.defineProperty(GObject.prototype, "gearSize", {
  1305. get: function () {
  1306. return this.getGear(2);
  1307. },
  1308. enumerable: false,
  1309. configurable: true
  1310. });
  1311. Object.defineProperty(GObject.prototype, "gearLook", {
  1312. get: function () {
  1313. return this.getGear(3);
  1314. },
  1315. enumerable: false,
  1316. configurable: true
  1317. });
  1318. Object.defineProperty(GObject.prototype, "relations", {
  1319. get: function () {
  1320. return this._relations;
  1321. },
  1322. enumerable: false,
  1323. configurable: true
  1324. });
  1325. GObject.prototype.addRelation = function (target, relationType, usePercent) {
  1326. this._relations.add(target, relationType, usePercent);
  1327. };
  1328. GObject.prototype.removeRelation = function (target, relationType) {
  1329. this._relations.remove(target, relationType);
  1330. };
  1331. Object.defineProperty(GObject.prototype, "node", {
  1332. get: function () {
  1333. return this._node;
  1334. },
  1335. enumerable: false,
  1336. configurable: true
  1337. });
  1338. Object.defineProperty(GObject.prototype, "parent", {
  1339. get: function () {
  1340. return this._parent;
  1341. },
  1342. enumerable: false,
  1343. configurable: true
  1344. });
  1345. GObject.prototype.removeFromParent = function () {
  1346. if (this._parent)
  1347. this._parent.removeChild(this);
  1348. };
  1349. GObject.prototype.findParent = function () {
  1350. if (this._parent)
  1351. return this._parent;
  1352. var pn = this._node.parent;
  1353. while (pn) {
  1354. var gobj = pn["$gobj"];
  1355. if (gobj)
  1356. return gobj;
  1357. pn = pn.parent;
  1358. }
  1359. return null;
  1360. };
  1361. Object.defineProperty(GObject.prototype, "root", {
  1362. get: function () {
  1363. if (this instanceof fgui.GRoot)
  1364. return this;
  1365. var p = this._parent;
  1366. while (p) {
  1367. if (p instanceof fgui.GRoot)
  1368. return p;
  1369. p = p.parent;
  1370. }
  1371. return fgui.GRoot.inst;
  1372. },
  1373. enumerable: false,
  1374. configurable: true
  1375. });
  1376. Object.defineProperty(GObject.prototype, "asCom", {
  1377. get: function () {
  1378. return this;
  1379. },
  1380. enumerable: false,
  1381. configurable: true
  1382. });
  1383. Object.defineProperty(GObject.prototype, "asButton", {
  1384. get: function () {
  1385. return this;
  1386. },
  1387. enumerable: false,
  1388. configurable: true
  1389. });
  1390. Object.defineProperty(GObject.prototype, "asLabel", {
  1391. get: function () {
  1392. return this;
  1393. },
  1394. enumerable: false,
  1395. configurable: true
  1396. });
  1397. Object.defineProperty(GObject.prototype, "asProgress", {
  1398. get: function () {
  1399. return this;
  1400. },
  1401. enumerable: false,
  1402. configurable: true
  1403. });
  1404. Object.defineProperty(GObject.prototype, "asTextField", {
  1405. get: function () {
  1406. return this;
  1407. },
  1408. enumerable: false,
  1409. configurable: true
  1410. });
  1411. Object.defineProperty(GObject.prototype, "asRichTextField", {
  1412. get: function () {
  1413. return this;
  1414. },
  1415. enumerable: false,
  1416. configurable: true
  1417. });
  1418. Object.defineProperty(GObject.prototype, "asTextInput", {
  1419. get: function () {
  1420. return this;
  1421. },
  1422. enumerable: false,
  1423. configurable: true
  1424. });
  1425. Object.defineProperty(GObject.prototype, "asLoader", {
  1426. get: function () {
  1427. return this;
  1428. },
  1429. enumerable: false,
  1430. configurable: true
  1431. });
  1432. Object.defineProperty(GObject.prototype, "asList", {
  1433. get: function () {
  1434. return this;
  1435. },
  1436. enumerable: false,
  1437. configurable: true
  1438. });
  1439. Object.defineProperty(GObject.prototype, "asTree", {
  1440. get: function () {
  1441. return this;
  1442. },
  1443. enumerable: false,
  1444. configurable: true
  1445. });
  1446. Object.defineProperty(GObject.prototype, "asGraph", {
  1447. get: function () {
  1448. return this;
  1449. },
  1450. enumerable: false,
  1451. configurable: true
  1452. });
  1453. Object.defineProperty(GObject.prototype, "asGroup", {
  1454. get: function () {
  1455. return this;
  1456. },
  1457. enumerable: false,
  1458. configurable: true
  1459. });
  1460. Object.defineProperty(GObject.prototype, "asSlider", {
  1461. get: function () {
  1462. return this;
  1463. },
  1464. enumerable: false,
  1465. configurable: true
  1466. });
  1467. Object.defineProperty(GObject.prototype, "asComboBox", {
  1468. get: function () {
  1469. return this;
  1470. },
  1471. enumerable: false,
  1472. configurable: true
  1473. });
  1474. Object.defineProperty(GObject.prototype, "asImage", {
  1475. get: function () {
  1476. return this;
  1477. },
  1478. enumerable: false,
  1479. configurable: true
  1480. });
  1481. Object.defineProperty(GObject.prototype, "asMovieClip", {
  1482. get: function () {
  1483. return this;
  1484. },
  1485. enumerable: false,
  1486. configurable: true
  1487. });
  1488. GObject.cast = function (obj) {
  1489. return obj["$gobj"];
  1490. };
  1491. Object.defineProperty(GObject.prototype, "text", {
  1492. get: function () {
  1493. return null;
  1494. },
  1495. set: function (value) {
  1496. },
  1497. enumerable: false,
  1498. configurable: true
  1499. });
  1500. Object.defineProperty(GObject.prototype, "icon", {
  1501. get: function () {
  1502. return null;
  1503. },
  1504. set: function (value) {
  1505. },
  1506. enumerable: false,
  1507. configurable: true
  1508. });
  1509. Object.defineProperty(GObject.prototype, "treeNode", {
  1510. get: function () {
  1511. return this._treeNode;
  1512. },
  1513. enumerable: false,
  1514. configurable: true
  1515. });
  1516. GObject.prototype.dispose = function () {
  1517. var n = this._node;
  1518. if (!n)
  1519. return;
  1520. this.removeFromParent();
  1521. this._relations.dispose();
  1522. this._node = null;
  1523. n.destroy();
  1524. for (var i = 0; i < 10; i++) {
  1525. var gear = this._gears[i];
  1526. if (gear)
  1527. gear.dispose();
  1528. }
  1529. };
  1530. GObject.prototype.onEnable = function () {
  1531. };
  1532. GObject.prototype.onDisable = function () {
  1533. };
  1534. GObject.prototype.onUpdate = function () {
  1535. };
  1536. GObject.prototype.onDestroy = function () {
  1537. };
  1538. GObject.prototype.onClick = function (listener, target) {
  1539. this._node.on(fgui.Event.CLICK, listener, target);
  1540. };
  1541. GObject.prototype.onceClick = function (listener, target) {
  1542. this._node.once(fgui.Event.CLICK, listener, target);
  1543. };
  1544. GObject.prototype.offClick = function (listener, target) {
  1545. this._node.off(fgui.Event.CLICK, listener, target);
  1546. };
  1547. GObject.prototype.clearClick = function () {
  1548. this._node.off(fgui.Event.CLICK);
  1549. };
  1550. GObject.prototype.hasClickListener = function () {
  1551. return this._node.hasEventListener(fgui.Event.CLICK);
  1552. };
  1553. GObject.prototype.on = function (type, listener, target) {
  1554. if (type == fgui.Event.DISPLAY || type == fgui.Event.UNDISPLAY)
  1555. this._partner._emitDisplayEvents = true;
  1556. this._node.on(type, listener, target);
  1557. };
  1558. GObject.prototype.once = function (type, listener, target) {
  1559. if (type == fgui.Event.DISPLAY || type == fgui.Event.UNDISPLAY)
  1560. this._partner._emitDisplayEvents = true;
  1561. this._node.once(type, listener, target);
  1562. };
  1563. GObject.prototype.off = function (type, listener, target) {
  1564. this._node.off(type, listener, target);
  1565. };
  1566. Object.defineProperty(GObject.prototype, "draggable", {
  1567. get: function () {
  1568. return this._draggable;
  1569. },
  1570. set: function (value) {
  1571. if (this._draggable != value) {
  1572. this._draggable = value;
  1573. this.initDrag();
  1574. }
  1575. },
  1576. enumerable: false,
  1577. configurable: true
  1578. });
  1579. Object.defineProperty(GObject.prototype, "dragBounds", {
  1580. get: function () {
  1581. return this._dragBounds;
  1582. },
  1583. set: function (value) {
  1584. this._dragBounds = value;
  1585. },
  1586. enumerable: false,
  1587. configurable: true
  1588. });
  1589. GObject.prototype.startDrag = function (touchId) {
  1590. if (!this._node.activeInHierarchy)
  1591. return;
  1592. this.dragBegin(touchId);
  1593. };
  1594. GObject.prototype.stopDrag = function () {
  1595. this.dragEnd();
  1596. };
  1597. Object.defineProperty(GObject.prototype, "dragging", {
  1598. get: function () {
  1599. return GObject.draggingObject == this;
  1600. },
  1601. enumerable: false,
  1602. configurable: true
  1603. });
  1604. GObject.prototype.localToGlobal = function (ax, ay, result) {
  1605. ax = ax || 0;
  1606. ay = ay || 0;
  1607. result = result || new cc.Vec2();
  1608. result.x = ax;
  1609. result.y = ay;
  1610. result.y = -result.y;
  1611. if (!this._pivotAsAnchor) {
  1612. result.x -= this.node.anchorX * this._width;
  1613. result.y += (1 - this.node.anchorY) * this._height;
  1614. }
  1615. this._node.convertToWorldSpaceAR(result, result);
  1616. result.y = fgui.GRoot.inst.height - result.y;
  1617. return result;
  1618. };
  1619. GObject.prototype.globalToLocal = function (ax, ay, result) {
  1620. ax = ax || 0;
  1621. ay = ay || 0;
  1622. result = result || new cc.Vec2();
  1623. result.x = ax;
  1624. result.y = fgui.GRoot.inst.height - ay;
  1625. this._node.convertToNodeSpaceAR(result, result);
  1626. if (!this._pivotAsAnchor) {
  1627. result.x += this._node.anchorX * this._width;
  1628. result.y -= (1 - this._node.anchorY) * this._height;
  1629. }
  1630. result.y = -result.y;
  1631. return result;
  1632. };
  1633. GObject.prototype.localToGlobalRect = function (ax, ay, aw, ah, result) {
  1634. ax = ax || 0;
  1635. ay = ay || 0;
  1636. aw = aw || 0;
  1637. ah = ah || 0;
  1638. result = result || new cc.Rect();
  1639. var pt = this.localToGlobal(ax, ay);
  1640. result.x = pt.x;
  1641. result.y = pt.y;
  1642. pt = this.localToGlobal(ax + aw, ay + ah, pt);
  1643. result.xMax = pt.x;
  1644. result.yMax = pt.y;
  1645. return result;
  1646. };
  1647. GObject.prototype.globalToLocalRect = function (ax, ay, aw, ah, result) {
  1648. ax = ax || 0;
  1649. ay = ay || 0;
  1650. aw = aw || 0;
  1651. ah = ah || 0;
  1652. result = result || new cc.Rect();
  1653. var pt = this.globalToLocal(ax, ay);
  1654. result.x = pt.x;
  1655. result.y = pt.y;
  1656. pt = this.globalToLocal(ax + aw, ay + ah, pt);
  1657. result.xMax = pt.x;
  1658. result.yMax = pt.y;
  1659. return result;
  1660. };
  1661. GObject.prototype.handleControllerChanged = function (c) {
  1662. this._handlingController = true;
  1663. for (var i = 0; i < 10; i++) {
  1664. var gear = this._gears[i];
  1665. if (gear && gear.controller == c)
  1666. gear.apply();
  1667. }
  1668. this._handlingController = false;
  1669. this.checkGearDisplay();
  1670. };
  1671. GObject.prototype.handleAnchorChanged = function () {
  1672. this.handlePositionChanged();
  1673. };
  1674. GObject.prototype.handlePositionChanged = function () {
  1675. var xv = this._x;
  1676. var yv = -this._y;
  1677. if (!this._pivotAsAnchor) {
  1678. xv += this.node.anchorX * this._width;
  1679. yv -= (1 - this.node.anchorY) * this._height;
  1680. }
  1681. if (this._pixelSnapping) {
  1682. xv = Math.round(xv);
  1683. yv = Math.round(yv);
  1684. }
  1685. this._node.setPosition(xv, yv);
  1686. };
  1687. GObject.prototype.handleSizeChanged = function () {
  1688. this._node.setContentSize(this._width, this._height);
  1689. };
  1690. GObject.prototype.handleGrayedChanged = function () {
  1691. };
  1692. GObject.prototype.handleVisibleChanged = function () {
  1693. this._node.active = this._finalVisible;
  1694. if (this instanceof fgui.GGroup)
  1695. this.handleVisibleChanged();
  1696. if (this._parent)
  1697. this._parent.setBoundsChangedFlag();
  1698. };
  1699. GObject.prototype.hitTest = function (globalPt, forTouch) {
  1700. if (forTouch == null)
  1701. forTouch = true;
  1702. if (forTouch && (this._touchDisabled || !this._touchable || !this._node.activeInHierarchy))
  1703. return null;
  1704. if (!this._hitTestPt)
  1705. this._hitTestPt = new cc.Vec2();
  1706. this.globalToLocal(globalPt.x, globalPt.y, this._hitTestPt);
  1707. if (this._pivotAsAnchor) {
  1708. this._hitTestPt.x += this.node.anchorX * this._width;
  1709. this._hitTestPt.y += (1 - this.node.anchorY) * this._height;
  1710. }
  1711. return this._hitTest(this._hitTestPt, globalPt);
  1712. };
  1713. GObject.prototype._hitTest = function (pt, globalPt) {
  1714. if (pt.x >= 0 && pt.y >= 0 && pt.x < this._width && pt.y < this._height)
  1715. return this;
  1716. else
  1717. return null;
  1718. };
  1719. GObject.prototype.getProp = function (index) {
  1720. switch (index) {
  1721. case fgui.ObjectPropID.Text:
  1722. return this.text;
  1723. case fgui.ObjectPropID.Icon:
  1724. return this.icon;
  1725. case fgui.ObjectPropID.Color:
  1726. return null;
  1727. case fgui.ObjectPropID.OutlineColor:
  1728. return null;
  1729. case fgui.ObjectPropID.Playing:
  1730. return false;
  1731. case fgui.ObjectPropID.Frame:
  1732. return 0;
  1733. case fgui.ObjectPropID.DeltaTime:
  1734. return 0;
  1735. case fgui.ObjectPropID.TimeScale:
  1736. return 1;
  1737. case fgui.ObjectPropID.FontSize:
  1738. return 0;
  1739. case fgui.ObjectPropID.Selected:
  1740. return false;
  1741. default:
  1742. return undefined;
  1743. }
  1744. };
  1745. GObject.prototype.setProp = function (index, value) {
  1746. switch (index) {
  1747. case fgui.ObjectPropID.Text:
  1748. this.text = value;
  1749. break;
  1750. case fgui.ObjectPropID.Icon:
  1751. this.icon = value;
  1752. break;
  1753. }
  1754. };
  1755. GObject.prototype.constructFromResource = function () {
  1756. };
  1757. GObject.prototype.setup_beforeAdd = function (buffer, beginPos) {
  1758. buffer.seek(beginPos, 0);
  1759. buffer.skip(5);
  1760. var f1;
  1761. var f2;
  1762. this._id = buffer.readS();
  1763. this._name = buffer.readS();
  1764. f1 = buffer.readInt();
  1765. f2 = buffer.readInt();
  1766. this.setPosition(f1, f2);
  1767. if (buffer.readBool()) {
  1768. this.initWidth = buffer.readInt();
  1769. this.initHeight = buffer.readInt();
  1770. this.setSize(this.initWidth, this.initHeight, true);
  1771. }
  1772. if (buffer.readBool()) {
  1773. this.minWidth = buffer.readInt();
  1774. this.maxWidth = buffer.readInt();
  1775. this.minHeight = buffer.readInt();
  1776. this.maxHeight = buffer.readInt();
  1777. }
  1778. if (buffer.readBool()) {
  1779. f1 = buffer.readFloat();
  1780. f2 = buffer.readFloat();
  1781. this.setScale(f1, f2);
  1782. }
  1783. if (buffer.readBool()) {
  1784. f1 = buffer.readFloat();
  1785. f2 = buffer.readFloat();
  1786. this.setSkew(f1, f2);
  1787. }
  1788. if (buffer.readBool()) {
  1789. f1 = buffer.readFloat();
  1790. f2 = buffer.readFloat();
  1791. this.setPivot(f1, f2, buffer.readBool());
  1792. }
  1793. f1 = buffer.readFloat();
  1794. if (f1 != 1)
  1795. this.alpha = f1;
  1796. f1 = buffer.readFloat();
  1797. if (f1 != 0)
  1798. this.rotation = f1;
  1799. if (!buffer.readBool())
  1800. this.visible = false;
  1801. if (!buffer.readBool())
  1802. this.touchable = false;
  1803. if (buffer.readBool())
  1804. this.grayed = true;
  1805. this.blendMode = buffer.readByte();
  1806. var filter = buffer.readByte();
  1807. if (filter == 1) {
  1808. }
  1809. var str = buffer.readS();
  1810. if (str != null)
  1811. this.data = str;
  1812. };
  1813. GObject.prototype.setup_afterAdd = function (buffer, beginPos) {
  1814. buffer.seek(beginPos, 1);
  1815. var str = buffer.readS();
  1816. if (str != null)
  1817. this.tooltips = str;
  1818. var groupId = buffer.readShort();
  1819. if (groupId >= 0)
  1820. this.group = this.parent.getChildAt(groupId);
  1821. buffer.seek(beginPos, 2);
  1822. var cnt = buffer.readShort();
  1823. for (var i = 0; i < cnt; i++) {
  1824. var nextPos = buffer.readShort();
  1825. nextPos += buffer.position;
  1826. var gear = this.getGear(buffer.readByte());
  1827. gear.setup(buffer);
  1828. buffer.position = nextPos;
  1829. }
  1830. };
  1831. GObject.prototype.onRollOver = function () {
  1832. this.root.showTooltips(this.tooltips);
  1833. };
  1834. ;
  1835. GObject.prototype.onRollOut = function () {
  1836. this.root.hideTooltips();
  1837. };
  1838. ;
  1839. GObject.prototype.initDrag = function () {
  1840. if (this._draggable) {
  1841. this.on(fgui.Event.TOUCH_BEGIN, this.onTouchBegin_0, this);
  1842. this.on(fgui.Event.TOUCH_MOVE, this.onTouchMove_0, this);
  1843. this.on(fgui.Event.TOUCH_END, this.onTouchEnd_0, this);
  1844. }
  1845. else {
  1846. this.off(fgui.Event.TOUCH_BEGIN, this.onTouchBegin_0, this);
  1847. this.off(fgui.Event.TOUCH_MOVE, this.onTouchMove_0, this);
  1848. this.off(fgui.Event.TOUCH_END, this.onTouchEnd_0, this);
  1849. }
  1850. };
  1851. GObject.prototype.dragBegin = function (touchId) {
  1852. if (GObject.draggingObject) {
  1853. var tmp = GObject.draggingObject;
  1854. tmp.stopDrag();
  1855. GObject.draggingObject = null;
  1856. tmp._node.emit(fgui.Event.DRAG_END);
  1857. }
  1858. if (touchId == undefined)
  1859. touchId = fgui.GRoot.inst.inputProcessor.getAllTouches()[0];
  1860. sGlobalDragStart.set(fgui.GRoot.inst.getTouchPosition(touchId));
  1861. this.localToGlobalRect(0, 0, this._width, this._height, sGlobalRect);
  1862. GObject.draggingObject = this;
  1863. this._dragTesting = true;
  1864. fgui.GRoot.inst.inputProcessor.addTouchMonitor(touchId, this);
  1865. this.on(fgui.Event.TOUCH_MOVE, this.onTouchMove_0, this);
  1866. this.on(fgui.Event.TOUCH_END, this.onTouchEnd_0, this);
  1867. };
  1868. GObject.prototype.dragEnd = function () {
  1869. if (GObject.draggingObject == this) {
  1870. this._dragTesting = false;
  1871. GObject.draggingObject = null;
  1872. }
  1873. sDragQuery = false;
  1874. };
  1875. GObject.prototype.onTouchBegin_0 = function (evt) {
  1876. if (this._dragStartPos == null)
  1877. this._dragStartPos = new cc.Vec2();
  1878. this._dragStartPos.set(evt.pos);
  1879. this._dragTesting = true;
  1880. evt.captureTouch();
  1881. };
  1882. GObject.prototype.onTouchMove_0 = function (evt) {
  1883. if (GObject.draggingObject != this && this._draggable && this._dragTesting) {
  1884. var sensitivity = fgui.UIConfig.touchDragSensitivity;
  1885. if (this._dragStartPos
  1886. && Math.abs(this._dragStartPos.x - evt.pos.x) < sensitivity
  1887. && Math.abs(this._dragStartPos.y - evt.pos.y) < sensitivity)
  1888. return;
  1889. this._dragTesting = false;
  1890. sDragQuery = true;
  1891. this._node.emit(fgui.Event.DRAG_START, evt);
  1892. if (sDragQuery)
  1893. this.dragBegin(evt.touchId);
  1894. }
  1895. if (GObject.draggingObject == this) {
  1896. var xx = evt.pos.x - sGlobalDragStart.x + sGlobalRect.x;
  1897. var yy = evt.pos.y - sGlobalDragStart.y + sGlobalRect.y;
  1898. if (this._dragBounds) {
  1899. var rect = fgui.GRoot.inst.localToGlobalRect(this._dragBounds.x, this._dragBounds.y, this._dragBounds.width, this._dragBounds.height, sDragHelperRect);
  1900. if (xx < rect.x)
  1901. xx = rect.x;
  1902. else if (xx + sGlobalRect.width > rect.xMax) {
  1903. xx = rect.xMax - sGlobalRect.width;
  1904. if (xx < rect.x)
  1905. xx = rect.x;
  1906. }
  1907. if (yy < rect.y)
  1908. yy = rect.y;
  1909. else if (yy + sGlobalRect.height > rect.yMax) {
  1910. yy = rect.yMax - sGlobalRect.height;
  1911. if (yy < rect.y)
  1912. yy = rect.y;
  1913. }
  1914. }
  1915. sUpdateInDragging = true;
  1916. var pt = this.parent.globalToLocal(xx, yy, sHelperPoint);
  1917. this.setPosition(Math.round(pt.x), Math.round(pt.y));
  1918. sUpdateInDragging = false;
  1919. this._node.emit(fgui.Event.DRAG_MOVE, evt);
  1920. }
  1921. };
  1922. GObject.prototype.onTouchEnd_0 = function (evt) {
  1923. if (GObject.draggingObject == this) {
  1924. GObject.draggingObject = null;
  1925. this._node.emit(fgui.Event.DRAG_END, evt);
  1926. }
  1927. };
  1928. GObject._defaultGroupIndex = -1;
  1929. return GObject;
  1930. }());
  1931. fgui.GObject = GObject;
  1932. var sGlobalDragStart = new cc.Vec2();
  1933. var sGlobalRect = new cc.Rect();
  1934. var sHelperPoint = new cc.Vec2();
  1935. var sDragHelperRect = new cc.Rect();
  1936. var sUpdateInDragging;
  1937. var sDragQuery = false;
  1938. var GObjectPartner = (function (_super) {
  1939. __extends(GObjectPartner, _super);
  1940. function GObjectPartner() {
  1941. var _this = _super !== null && _super.apply(this, arguments) || this;
  1942. _this._emitDisplayEvents = false;
  1943. return _this;
  1944. }
  1945. GObjectPartner.prototype.callLater = function (callback, delay) {
  1946. if (!cc.director.getScheduler().isScheduled(callback, this))
  1947. this.scheduleOnce(callback, delay);
  1948. };
  1949. GObjectPartner.prototype.onClickLink = function (evt, text) {
  1950. this.node.emit(fgui.Event.LINK, text, evt);
  1951. };
  1952. GObjectPartner.prototype.onEnable = function () {
  1953. this.node["$gobj"].onEnable();
  1954. if (this._emitDisplayEvents)
  1955. this.node.emit(fgui.Event.DISPLAY);
  1956. };
  1957. GObjectPartner.prototype.onDisable = function () {
  1958. this.node["$gobj"].onDisable();
  1959. if (this._emitDisplayEvents)
  1960. this.node.emit(fgui.Event.UNDISPLAY);
  1961. };
  1962. GObjectPartner.prototype.update = function (dt) {
  1963. this.node["$gobj"].onUpdate(dt);
  1964. };
  1965. GObjectPartner.prototype.onDestroy = function () {
  1966. this.node["$gobj"].onDestroy();
  1967. };
  1968. return GObjectPartner;
  1969. }(cc.Component));
  1970. fgui.GObjectPartner = GObjectPartner;
  1971. })(fgui || (fgui = {}));
  1972. (function (fgui) {
  1973. var GComponent = (function (_super) {
  1974. __extends(GComponent, _super);
  1975. function GComponent() {
  1976. var _this = _super.call(this) || this;
  1977. _this._sortingChildCount = 0;
  1978. _this._childrenRenderOrder = fgui.ChildrenRenderOrder.Ascent;
  1979. _this._apexIndex = 0;
  1980. _this._node.name = "GComponent";
  1981. _this._children = new Array();
  1982. _this._controllers = new Array();
  1983. _this._transitions = new Array();
  1984. _this._margin = new fgui.Margin();
  1985. _this._alignOffset = new cc.Vec2();
  1986. _this._container = new cc.Node("Container");
  1987. _this._container.setAnchorPoint(0, 1);
  1988. _this._node.addChild(_this._container);
  1989. return _this;
  1990. }
  1991. GComponent.prototype.dispose = function () {
  1992. var i;
  1993. var cnt;
  1994. cnt = this._transitions.length;
  1995. for (i = 0; i < cnt; ++i) {
  1996. var trans = this._transitions[i];
  1997. trans.dispose();
  1998. }
  1999. cnt = this._controllers.length;
  2000. for (i = 0; i < cnt; ++i) {
  2001. var cc = this._controllers[i];
  2002. cc.dispose();
  2003. }
  2004. if (this._scrollPane)
  2005. this._scrollPane.destroy();
  2006. cnt = this._children.length;
  2007. for (i = cnt - 1; i >= 0; --i) {
  2008. var obj = this._children[i];
  2009. obj._parent = null;
  2010. obj.dispose();
  2011. }
  2012. this._boundsChanged = false;
  2013. _super.prototype.dispose.call(this);
  2014. };
  2015. Object.defineProperty(GComponent.prototype, "displayListContainer", {
  2016. get: function () {
  2017. return this._container;
  2018. },
  2019. enumerable: false,
  2020. configurable: true
  2021. });
  2022. GComponent.prototype.addChild = function (child) {
  2023. this.addChildAt(child, this._children.length);
  2024. return child;
  2025. };
  2026. GComponent.prototype.addChildAt = function (child, index) {
  2027. if (!child)
  2028. throw "child is null";
  2029. var numChildren = this._children.length;
  2030. if (index >= 0 && index <= numChildren) {
  2031. if (child.parent == this) {
  2032. this.setChildIndex(child, index);
  2033. }
  2034. else {
  2035. child.removeFromParent();
  2036. child._parent = this;
  2037. var cnt = this._children.length;
  2038. if (child.sortingOrder != 0) {
  2039. this._sortingChildCount++;
  2040. index = this.getInsertPosForSortingChild(child);
  2041. }
  2042. else if (this._sortingChildCount > 0) {
  2043. if (index > (cnt - this._sortingChildCount))
  2044. index = cnt - this._sortingChildCount;
  2045. }
  2046. if (index == cnt)
  2047. this._children.push(child);
  2048. else
  2049. this._children.splice(index, 0, child);
  2050. this.onChildAdd(child, index);
  2051. this.setBoundsChangedFlag();
  2052. }
  2053. return child;
  2054. }
  2055. else {
  2056. throw "Invalid child index";
  2057. }
  2058. };
  2059. GComponent.prototype.getInsertPosForSortingChild = function (target) {
  2060. var cnt = this._children.length;
  2061. var i = 0;
  2062. for (i = 0; i < cnt; i++) {
  2063. var child = this._children[i];
  2064. if (child == target)
  2065. continue;
  2066. if (target.sortingOrder < child.sortingOrder)
  2067. break;
  2068. }
  2069. return i;
  2070. };
  2071. GComponent.prototype.removeChild = function (child, dispose) {
  2072. var childIndex = this._children.indexOf(child);
  2073. if (childIndex != -1) {
  2074. this.removeChildAt(childIndex, dispose);
  2075. }
  2076. return child;
  2077. };
  2078. GComponent.prototype.removeChildAt = function (index, dispose) {
  2079. if (index >= 0 && index < this.numChildren) {
  2080. var child = this._children[index];
  2081. child._parent = null;
  2082. if (child.sortingOrder != 0)
  2083. this._sortingChildCount--;
  2084. this._children.splice(index, 1);
  2085. child.group = null;
  2086. this._container.removeChild(child.node);
  2087. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Arch)
  2088. this._partner.callLater(this.buildNativeDisplayList);
  2089. if (dispose)
  2090. child.dispose();
  2091. else
  2092. child.node.parent = null;
  2093. this.setBoundsChangedFlag();
  2094. return child;
  2095. }
  2096. else {
  2097. throw "Invalid child index";
  2098. }
  2099. };
  2100. GComponent.prototype.removeChildren = function (beginIndex, endIndex, dispose) {
  2101. if (beginIndex == undefined)
  2102. beginIndex = 0;
  2103. if (endIndex == undefined)
  2104. endIndex = -1;
  2105. if (endIndex < 0 || endIndex >= this.numChildren)
  2106. endIndex = this.numChildren - 1;
  2107. for (var i = beginIndex; i <= endIndex; ++i)
  2108. this.removeChildAt(beginIndex, dispose);
  2109. };
  2110. GComponent.prototype.getChildAt = function (index) {
  2111. if (index >= 0 && index < this.numChildren)
  2112. return this._children[index];
  2113. else
  2114. console.log(this);
  2115. throw "Invalid child index";
  2116. };
  2117. GComponent.prototype.getChild = function (name) {
  2118. var cnt = this._children.length;
  2119. for (var i = 0; i < cnt; ++i) {
  2120. if (this._children[i].name == name)
  2121. return this._children[i];
  2122. }
  2123. return null;
  2124. };
  2125. GComponent.prototype.getChildByPath = function (path) {
  2126. var arr = path.split(".");
  2127. var cnt = arr.length;
  2128. var gcom = this;
  2129. var obj;
  2130. for (var i = 0; i < cnt; ++i) {
  2131. obj = gcom.getChild(arr[i]);
  2132. if (!obj)
  2133. break;
  2134. if (i != cnt - 1) {
  2135. if (!(obj instanceof GComponent)) {
  2136. obj = null;
  2137. break;
  2138. }
  2139. else
  2140. gcom = obj;
  2141. }
  2142. }
  2143. return obj;
  2144. };
  2145. GComponent.prototype.getVisibleChild = function (name) {
  2146. var cnt = this._children.length;
  2147. for (var i = 0; i < cnt; ++i) {
  2148. var child = this._children[i];
  2149. if (child._finalVisible && child.name == name)
  2150. return child;
  2151. }
  2152. return null;
  2153. };
  2154. GComponent.prototype.getChildInGroup = function (name, group) {
  2155. var cnt = this._children.length;
  2156. for (var i = 0; i < cnt; ++i) {
  2157. var child = this._children[i];
  2158. if (child.group == group && child.name == name)
  2159. return child;
  2160. }
  2161. return null;
  2162. };
  2163. GComponent.prototype.getChildById = function (id) {
  2164. var cnt = this._children.length;
  2165. for (var i = 0; i < cnt; ++i) {
  2166. if (this._children[i]._id == id)
  2167. return this._children[i];
  2168. }
  2169. return null;
  2170. };
  2171. GComponent.prototype.getChildIndex = function (child) {
  2172. return this._children.indexOf(child);
  2173. };
  2174. GComponent.prototype.setChildIndex = function (child, index) {
  2175. var oldIndex = this._children.indexOf(child);
  2176. if (oldIndex == -1)
  2177. throw "Not a child of this container";
  2178. if (child.sortingOrder != 0)
  2179. return;
  2180. var cnt = this._children.length;
  2181. if (this._sortingChildCount > 0) {
  2182. if (index > (cnt - this._sortingChildCount - 1))
  2183. index = cnt - this._sortingChildCount - 1;
  2184. }
  2185. this._setChildIndex(child, oldIndex, index);
  2186. };
  2187. GComponent.prototype.setChildIndexBefore = function (child, index) {
  2188. var oldIndex = this._children.indexOf(child);
  2189. if (oldIndex == -1)
  2190. throw "Not a child of this container";
  2191. if (child.sortingOrder != 0)
  2192. return oldIndex;
  2193. var cnt = this._children.length;
  2194. if (this._sortingChildCount > 0) {
  2195. if (index > (cnt - this._sortingChildCount - 1))
  2196. index = cnt - this._sortingChildCount - 1;
  2197. }
  2198. if (oldIndex < index)
  2199. return this._setChildIndex(child, oldIndex, index - 1);
  2200. else
  2201. return this._setChildIndex(child, oldIndex, index);
  2202. };
  2203. GComponent.prototype._setChildIndex = function (child, oldIndex, index) {
  2204. var cnt = this._children.length;
  2205. if (index > cnt)
  2206. index = cnt;
  2207. if (oldIndex == index)
  2208. return oldIndex;
  2209. this._children.splice(oldIndex, 1);
  2210. this._children.splice(index, 0, child);
  2211. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Ascent)
  2212. child.node.setSiblingIndex(index);
  2213. else if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Descent)
  2214. child.node.setSiblingIndex(cnt - index);
  2215. else
  2216. this._partner.callLater(this.buildNativeDisplayList);
  2217. this.setBoundsChangedFlag();
  2218. return index;
  2219. };
  2220. GComponent.prototype.swapChildren = function (child1, child2) {
  2221. var index1 = this._children.indexOf(child1);
  2222. var index2 = this._children.indexOf(child2);
  2223. if (index1 == -1 || index2 == -1)
  2224. throw "Not a child of this container";
  2225. this.swapChildrenAt(index1, index2);
  2226. };
  2227. GComponent.prototype.swapChildrenAt = function (index1, index2) {
  2228. var child1 = this._children[index1];
  2229. var child2 = this._children[index2];
  2230. this.setChildIndex(child1, index2);
  2231. this.setChildIndex(child2, index1);
  2232. };
  2233. Object.defineProperty(GComponent.prototype, "numChildren", {
  2234. get: function () {
  2235. return this._children.length;
  2236. },
  2237. enumerable: false,
  2238. configurable: true
  2239. });
  2240. GComponent.prototype.isAncestorOf = function (child) {
  2241. if (child == null)
  2242. return false;
  2243. var p = child.parent;
  2244. while (p) {
  2245. if (p == this)
  2246. return true;
  2247. p = p.parent;
  2248. }
  2249. return false;
  2250. };
  2251. GComponent.prototype.addController = function (controller) {
  2252. this._controllers.push(controller);
  2253. controller.parent = this;
  2254. this.applyController(controller);
  2255. };
  2256. GComponent.prototype.getControllerAt = function (index) {
  2257. return this._controllers[index];
  2258. };
  2259. GComponent.prototype.getController = function (name) {
  2260. var cnt = this._controllers.length;
  2261. for (var i = 0; i < cnt; ++i) {
  2262. var c = this._controllers[i];
  2263. if (c.name == name)
  2264. return c;
  2265. }
  2266. return null;
  2267. };
  2268. GComponent.prototype.removeController = function (c) {
  2269. var index = this._controllers.indexOf(c);
  2270. if (index == -1)
  2271. throw "controller not exists";
  2272. c.parent = null;
  2273. this._controllers.splice(index, 1);
  2274. var length = this._children.length;
  2275. for (var i = 0; i < length; i++) {
  2276. var child = this._children[i];
  2277. child.handleControllerChanged(c);
  2278. }
  2279. };
  2280. Object.defineProperty(GComponent.prototype, "controllers", {
  2281. get: function () {
  2282. return this._controllers;
  2283. },
  2284. enumerable: false,
  2285. configurable: true
  2286. });
  2287. GComponent.prototype.onChildAdd = function (child, index) {
  2288. child.node.parent = this._container;
  2289. child.node.active = child._finalVisible;
  2290. if (this._buildingDisplayList)
  2291. return;
  2292. var cnt = this._children.length;
  2293. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Ascent)
  2294. child.node.setSiblingIndex(index);
  2295. else if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Descent)
  2296. child.node.setSiblingIndex(cnt - index);
  2297. else
  2298. this._partner.callLater(this.buildNativeDisplayList);
  2299. };
  2300. GComponent.prototype.buildNativeDisplayList = function (dt) {
  2301. if (!isNaN(dt)) {
  2302. var _t = (this.node["$gobj"]);
  2303. _t.buildNativeDisplayList();
  2304. return;
  2305. }
  2306. var cnt = this._children.length;
  2307. if (cnt == 0)
  2308. return;
  2309. var child;
  2310. switch (this._childrenRenderOrder) {
  2311. case fgui.ChildrenRenderOrder.Ascent:
  2312. {
  2313. var j = 0;
  2314. for (var i = 0; i < cnt; i++) {
  2315. child = this._children[i];
  2316. child.node.setSiblingIndex(j++);
  2317. }
  2318. }
  2319. break;
  2320. case fgui.ChildrenRenderOrder.Descent:
  2321. {
  2322. var j = 0;
  2323. for (var i = cnt - 1; i >= 0; i--) {
  2324. child = this._children[i];
  2325. child.node.setSiblingIndex(j++);
  2326. }
  2327. }
  2328. break;
  2329. case fgui.ChildrenRenderOrder.Arch:
  2330. {
  2331. var j = 0;
  2332. for (var i = 0; i < this._apexIndex; i++) {
  2333. child = this._children[i];
  2334. child.node.setSiblingIndex(j++);
  2335. }
  2336. for (var i = cnt - 1; i >= this._apexIndex; i--) {
  2337. child = this._children[i];
  2338. child.node.setSiblingIndex(j++);
  2339. }
  2340. }
  2341. break;
  2342. }
  2343. };
  2344. GComponent.prototype.applyController = function (c) {
  2345. this._applyingController = c;
  2346. var child;
  2347. var length = this._children.length;
  2348. for (var i = 0; i < length; i++) {
  2349. child = this._children[i];
  2350. child.handleControllerChanged(c);
  2351. }
  2352. this._applyingController = null;
  2353. c.runActions();
  2354. };
  2355. GComponent.prototype.applyAllControllers = function () {
  2356. var cnt = this._controllers.length;
  2357. for (var i = 0; i < cnt; ++i) {
  2358. this.applyController(this._controllers[i]);
  2359. }
  2360. };
  2361. GComponent.prototype.adjustRadioGroupDepth = function (obj, c) {
  2362. var cnt = this._children.length;
  2363. var i;
  2364. var child;
  2365. var myIndex = -1, maxIndex = -1;
  2366. for (i = 0; i < cnt; i++) {
  2367. child = this._children[i];
  2368. if (child == obj) {
  2369. myIndex = i;
  2370. }
  2371. else if ((child instanceof fgui.GButton) && child.relatedController == c) {
  2372. if (i > maxIndex)
  2373. maxIndex = i;
  2374. }
  2375. }
  2376. if (myIndex < maxIndex) {
  2377. if (this._applyingController)
  2378. this._children[maxIndex].handleControllerChanged(this._applyingController);
  2379. this.swapChildrenAt(myIndex, maxIndex);
  2380. }
  2381. };
  2382. GComponent.prototype.getTransitionAt = function (index) {
  2383. return this._transitions[index];
  2384. };
  2385. GComponent.prototype.getTransition = function (transName) {
  2386. var cnt = this._transitions.length;
  2387. for (var i = 0; i < cnt; ++i) {
  2388. var trans = this._transitions[i];
  2389. if (trans.name == transName)
  2390. return trans;
  2391. }
  2392. return null;
  2393. };
  2394. GComponent.prototype.isChildInView = function (child) {
  2395. if (this._rectMask) {
  2396. return child.x + child.width >= 0 && child.x <= this.width
  2397. && child.y + child.height >= 0 && child.y <= this.height;
  2398. }
  2399. else if (this._scrollPane) {
  2400. return this._scrollPane.isChildInView(child);
  2401. }
  2402. else
  2403. return true;
  2404. };
  2405. GComponent.prototype.getFirstChildInView = function () {
  2406. var cnt = this._children.length;
  2407. for (var i = 0; i < cnt; ++i) {
  2408. var child = this._children[i];
  2409. if (this.isChildInView(child))
  2410. return i;
  2411. }
  2412. return -1;
  2413. };
  2414. Object.defineProperty(GComponent.prototype, "scrollPane", {
  2415. get: function () {
  2416. return this._scrollPane;
  2417. },
  2418. enumerable: false,
  2419. configurable: true
  2420. });
  2421. Object.defineProperty(GComponent.prototype, "opaque", {
  2422. get: function () {
  2423. return this._opaque;
  2424. },
  2425. set: function (value) {
  2426. this._opaque = value;
  2427. },
  2428. enumerable: false,
  2429. configurable: true
  2430. });
  2431. Object.defineProperty(GComponent.prototype, "margin", {
  2432. get: function () {
  2433. return this._margin;
  2434. },
  2435. set: function (value) {
  2436. this._margin.copy(value);
  2437. this.handleSizeChanged();
  2438. },
  2439. enumerable: false,
  2440. configurable: true
  2441. });
  2442. Object.defineProperty(GComponent.prototype, "childrenRenderOrder", {
  2443. get: function () {
  2444. return this._childrenRenderOrder;
  2445. },
  2446. set: function (value) {
  2447. if (this._childrenRenderOrder != value) {
  2448. this._childrenRenderOrder = value;
  2449. this.buildNativeDisplayList();
  2450. }
  2451. },
  2452. enumerable: false,
  2453. configurable: true
  2454. });
  2455. Object.defineProperty(GComponent.prototype, "apexIndex", {
  2456. get: function () {
  2457. return this._apexIndex;
  2458. },
  2459. set: function (value) {
  2460. if (this._apexIndex != value) {
  2461. this._apexIndex = value;
  2462. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Arch)
  2463. this.buildNativeDisplayList();
  2464. }
  2465. },
  2466. enumerable: false,
  2467. configurable: true
  2468. });
  2469. Object.defineProperty(GComponent.prototype, "mask", {
  2470. get: function () {
  2471. return this._maskContent;
  2472. },
  2473. set: function (value) {
  2474. this.setMask(value, false);
  2475. },
  2476. enumerable: false,
  2477. configurable: true
  2478. });
  2479. GComponent.prototype.setMask = function (value, inverted) {
  2480. if (this._maskContent) {
  2481. this._maskContent.node.off(cc.Node.EventType.POSITION_CHANGED, this.onMaskContentChanged, this);
  2482. this._maskContent.node.off(cc.Node.EventType.SIZE_CHANGED, this.onMaskContentChanged, this);
  2483. this._maskContent.node.off(cc.Node.EventType.SCALE_CHANGED, this.onMaskContentChanged, this);
  2484. this._maskContent.node.off(cc.Node.EventType.ANCHOR_CHANGED, this.onMaskContentChanged, this);
  2485. this._maskContent.visible = true;
  2486. }
  2487. this._maskContent = value;
  2488. if (this._maskContent) {
  2489. if (!(value instanceof fgui.GImage) && !(value instanceof fgui.GGraph))
  2490. return;
  2491. if (!this._customMask) {
  2492. var maskNode = new cc.Node("Mask");
  2493. maskNode.parent = this._node;
  2494. if (this._scrollPane)
  2495. this._container.parent.parent = maskNode;
  2496. else
  2497. this._container.parent = maskNode;
  2498. this._customMask = maskNode.addComponent(cc.Mask);
  2499. }
  2500. value.visible = false;
  2501. value.node.on(cc.Node.EventType.POSITION_CHANGED, this.onMaskContentChanged, this);
  2502. value.node.on(cc.Node.EventType.SIZE_CHANGED, this.onMaskContentChanged, this);
  2503. value.node.on(cc.Node.EventType.SCALE_CHANGED, this.onMaskContentChanged, this);
  2504. value.node.on(cc.Node.EventType.ANCHOR_CHANGED, this.onMaskContentChanged, this);
  2505. this._customMask.inverted = inverted;
  2506. if (this._node.activeInHierarchy)
  2507. this.onMaskReady();
  2508. else
  2509. this.on(fgui.Event.DISPLAY, this.onMaskReady, this);
  2510. this.onMaskContentChanged();
  2511. if (this._scrollPane)
  2512. this._scrollPane.adjustMaskContainer();
  2513. else
  2514. this._container.setPosition(0, 0);
  2515. }
  2516. else if (this._customMask) {
  2517. if (this._scrollPane)
  2518. this._container.parent.parent = this._node;
  2519. else
  2520. this._container.parent = this._node;
  2521. this._customMask.node.destroy();
  2522. this._customMask = null;
  2523. if (this._scrollPane)
  2524. this._scrollPane.adjustMaskContainer();
  2525. else
  2526. this._container.setPosition(this._pivotCorrectX, this._pivotCorrectY);
  2527. }
  2528. };
  2529. GComponent.prototype.onMaskReady = function () {
  2530. this.off(fgui.Event.DISPLAY, this.onMaskReady, this);
  2531. if (this._maskContent instanceof fgui.GImage) {
  2532. this._customMask.type = cc.Mask.Type.IMAGE_STENCIL;
  2533. this._customMask.alphaThreshold = 0.0001;
  2534. this._customMask.spriteFrame = this._maskContent._content.spriteFrame;
  2535. }
  2536. else if (this._maskContent instanceof fgui.GGraph) {
  2537. if (this._maskContent.type == 2)
  2538. this._customMask.type = cc.Mask.Type.ELLIPSE;
  2539. else
  2540. this._customMask.type = cc.Mask.Type.RECT;
  2541. }
  2542. };
  2543. GComponent.prototype.onMaskContentChanged = function () {
  2544. var maskNode = this._customMask.node;
  2545. var contentNode = this._maskContent.node;
  2546. var w = contentNode.width * contentNode.scaleX;
  2547. var h = contentNode.height * contentNode.scaleY;
  2548. maskNode.setContentSize(w, h);
  2549. var left = contentNode.x - contentNode.anchorX * w;
  2550. var top = contentNode.y - contentNode.anchorY * h;
  2551. maskNode.setAnchorPoint(-left / maskNode.width, -top / maskNode.height);
  2552. maskNode.setPosition(this._pivotCorrectX, this._pivotCorrectY);
  2553. };
  2554. Object.defineProperty(GComponent.prototype, "_pivotCorrectX", {
  2555. get: function () {
  2556. return -this.pivotX * this._width + this._margin.left;
  2557. },
  2558. enumerable: false,
  2559. configurable: true
  2560. });
  2561. Object.defineProperty(GComponent.prototype, "_pivotCorrectY", {
  2562. get: function () {
  2563. return this.pivotY * this._height - this._margin.top;
  2564. },
  2565. enumerable: false,
  2566. configurable: true
  2567. });
  2568. Object.defineProperty(GComponent.prototype, "baseUserData", {
  2569. get: function () {
  2570. var buffer = this.packageItem.rawData;
  2571. buffer.seek(0, 4);
  2572. return buffer.readS();
  2573. },
  2574. enumerable: false,
  2575. configurable: true
  2576. });
  2577. GComponent.prototype.setupScroll = function (buffer) {
  2578. this._scrollPane = this._node.addComponent(fgui.ScrollPane);
  2579. this._scrollPane.setup(buffer);
  2580. };
  2581. GComponent.prototype.setupOverflow = function (overflow) {
  2582. if (overflow == fgui.OverflowType.Hidden)
  2583. this._rectMask = this._container.addComponent(cc.Mask);
  2584. if (!this._margin.isNone)
  2585. this.handleSizeChanged();
  2586. };
  2587. GComponent.prototype.handleAnchorChanged = function () {
  2588. _super.prototype.handleAnchorChanged.call(this);
  2589. if (this._customMask)
  2590. this._customMask.node.setPosition(this._pivotCorrectX, this._pivotCorrectY);
  2591. else if (this._scrollPane)
  2592. this._scrollPane.adjustMaskContainer();
  2593. else
  2594. this._container.setPosition(this._pivotCorrectX + this._alignOffset.x, this._pivotCorrectY - this._alignOffset.y);
  2595. };
  2596. GComponent.prototype.handleSizeChanged = function () {
  2597. _super.prototype.handleSizeChanged.call(this);
  2598. if (this._customMask)
  2599. this._customMask.node.setPosition(this._pivotCorrectX, this._pivotCorrectY);
  2600. else if (!this._scrollPane)
  2601. this._container.setPosition(this._pivotCorrectX, this._pivotCorrectY);
  2602. if (this._scrollPane)
  2603. this._scrollPane.onOwnerSizeChanged();
  2604. else
  2605. this._container.setContentSize(this.viewWidth, this.viewHeight);
  2606. };
  2607. GComponent.prototype.handleGrayedChanged = function () {
  2608. var c = this.getController("grayed");
  2609. if (c) {
  2610. c.selectedIndex = this.grayed ? 1 : 0;
  2611. return;
  2612. }
  2613. var v = this.grayed;
  2614. var cnt = this._children.length;
  2615. for (var i = 0; i < cnt; ++i) {
  2616. this._children[i].grayed = v;
  2617. }
  2618. };
  2619. GComponent.prototype.handleControllerChanged = function (c) {
  2620. _super.prototype.handleControllerChanged.call(this, c);
  2621. if (this._scrollPane)
  2622. this._scrollPane.handleControllerChanged(c);
  2623. };
  2624. GComponent.prototype._hitTest = function (pt, globalPt) {
  2625. if (this._customMask) {
  2626. s_vec2.set(globalPt);
  2627. s_vec2.y = fgui.GRoot.inst.height - globalPt.y;
  2628. var b = this._customMask["_hitTest"](s_vec2) || false;
  2629. if (!b)
  2630. return null;
  2631. }
  2632. if (this.hitArea) {
  2633. if (!this.hitArea.hitTest(pt, globalPt))
  2634. return null;
  2635. }
  2636. else if (this._rectMask) {
  2637. s_vec2.set(pt);
  2638. s_vec2.x += this._container.x;
  2639. s_vec2.y += this._container.y;
  2640. var clippingSize = this._container.getContentSize();
  2641. if (s_vec2.x < 0 || s_vec2.y < 0 || s_vec2.x >= clippingSize.width || s_vec2.y >= clippingSize.height)
  2642. return null;
  2643. }
  2644. if (this._scrollPane) {
  2645. var target_1 = this._scrollPane.hitTest(pt, globalPt);
  2646. if (!target_1)
  2647. return null;
  2648. if (target_1 != this)
  2649. return target_1;
  2650. }
  2651. var target = null;
  2652. var cnt = this._children.length;
  2653. for (var i = cnt - 1; i >= 0; i--) {
  2654. var child = this._children[i];
  2655. if (this._maskContent == child || child._touchDisabled)
  2656. continue;
  2657. target = child.hitTest(globalPt);
  2658. if (target)
  2659. break;
  2660. }
  2661. if (!target && this._opaque && (this.hitArea || pt.x >= 0 && pt.y >= 0 && pt.x < this._width && pt.y < this._height))
  2662. target = this;
  2663. return target;
  2664. };
  2665. GComponent.prototype.setBoundsChangedFlag = function () {
  2666. if (!this._scrollPane && !this._trackBounds)
  2667. return;
  2668. if (!this._boundsChanged) {
  2669. this._boundsChanged = true;
  2670. this._partner.callLater(this.refresh);
  2671. }
  2672. };
  2673. GComponent.prototype.refresh = function (dt) {
  2674. if (!isNaN(dt)) {
  2675. var _t = (this.node["$gobj"]);
  2676. _t.refresh();
  2677. return;
  2678. }
  2679. if (this._boundsChanged) {
  2680. var len = this._children.length;
  2681. if (len > 0) {
  2682. for (var i = 0; i < len; i++) {
  2683. var child = this._children[i];
  2684. child.ensureSizeCorrect();
  2685. }
  2686. }
  2687. this.updateBounds();
  2688. }
  2689. };
  2690. GComponent.prototype.ensureBoundsCorrect = function () {
  2691. var len = this._children.length;
  2692. if (len > 0) {
  2693. for (var i = 0; i < len; i++) {
  2694. var child = this._children[i];
  2695. child.ensureSizeCorrect();
  2696. }
  2697. }
  2698. if (this._boundsChanged)
  2699. this.updateBounds();
  2700. };
  2701. GComponent.prototype.updateBounds = function () {
  2702. var ax = 0, ay = 0, aw = 0, ah = 0;
  2703. var len = this._children.length;
  2704. if (len > 0) {
  2705. ax = Number.POSITIVE_INFINITY, ay = Number.POSITIVE_INFINITY;
  2706. var ar = Number.NEGATIVE_INFINITY, ab = Number.NEGATIVE_INFINITY;
  2707. var tmp = 0;
  2708. var i = 0;
  2709. for (var i = 0; i < len; i++) {
  2710. var child = this._children[i];
  2711. tmp = child.x;
  2712. if (tmp < ax)
  2713. ax = tmp;
  2714. tmp = child.y;
  2715. if (tmp < ay)
  2716. ay = tmp;
  2717. tmp = child.x + child.actualWidth;
  2718. if (tmp > ar)
  2719. ar = tmp;
  2720. tmp = child.y + child.actualHeight;
  2721. if (tmp > ab)
  2722. ab = tmp;
  2723. }
  2724. aw = ar - ax;
  2725. ah = ab - ay;
  2726. }
  2727. this.setBounds(ax, ay, aw, ah);
  2728. };
  2729. GComponent.prototype.setBounds = function (ax, ay, aw, ah) {
  2730. if (ah === void 0) { ah = 0; }
  2731. this._boundsChanged = false;
  2732. if (this._scrollPane)
  2733. this._scrollPane.setContentSize(Math.round(ax + aw), Math.round(ay + ah));
  2734. };
  2735. Object.defineProperty(GComponent.prototype, "viewWidth", {
  2736. get: function () {
  2737. if (this._scrollPane)
  2738. return this._scrollPane.viewWidth;
  2739. else
  2740. return this.width - this._margin.left - this._margin.right;
  2741. },
  2742. set: function (value) {
  2743. if (this._scrollPane)
  2744. this._scrollPane.viewWidth = value;
  2745. else
  2746. this.width = value + this._margin.left + this._margin.right;
  2747. },
  2748. enumerable: false,
  2749. configurable: true
  2750. });
  2751. Object.defineProperty(GComponent.prototype, "viewHeight", {
  2752. get: function () {
  2753. if (this._scrollPane)
  2754. return this._scrollPane.viewHeight;
  2755. else
  2756. return this.height - this._margin.top - this._margin.bottom;
  2757. },
  2758. set: function (value) {
  2759. if (this._scrollPane)
  2760. this._scrollPane.viewHeight = value;
  2761. else
  2762. this.height = value + this._margin.top + this._margin.bottom;
  2763. },
  2764. enumerable: false,
  2765. configurable: true
  2766. });
  2767. GComponent.prototype.getSnappingPosition = function (xValue, yValue, resultPoint) {
  2768. if (!resultPoint)
  2769. resultPoint = new cc.Vec2();
  2770. var cnt = this._children.length;
  2771. if (cnt == 0) {
  2772. resultPoint.x = 0;
  2773. resultPoint.y = 0;
  2774. return resultPoint;
  2775. }
  2776. this.ensureBoundsCorrect();
  2777. var obj = null;
  2778. var prev = null;
  2779. var i = 0;
  2780. if (yValue != 0) {
  2781. for (; i < cnt; i++) {
  2782. obj = this._children[i];
  2783. if (yValue < obj.y) {
  2784. if (i == 0) {
  2785. yValue = 0;
  2786. break;
  2787. }
  2788. else {
  2789. prev = this._children[i - 1];
  2790. if (yValue < prev.y + prev.actualHeight / 2)
  2791. yValue = prev.y;
  2792. else
  2793. yValue = obj.y;
  2794. break;
  2795. }
  2796. }
  2797. }
  2798. if (i == cnt)
  2799. yValue = obj.y;
  2800. }
  2801. if (xValue != 0) {
  2802. if (i > 0)
  2803. i--;
  2804. for (; i < cnt; i++) {
  2805. obj = this._children[i];
  2806. if (xValue < obj.x) {
  2807. if (i == 0) {
  2808. xValue = 0;
  2809. break;
  2810. }
  2811. else {
  2812. prev = this._children[i - 1];
  2813. if (xValue < prev.x + prev.actualWidth / 2)
  2814. xValue = prev.x;
  2815. else
  2816. xValue = obj.x;
  2817. break;
  2818. }
  2819. }
  2820. }
  2821. if (i == cnt)
  2822. xValue = obj.x;
  2823. }
  2824. resultPoint.x = xValue;
  2825. resultPoint.y = yValue;
  2826. return resultPoint;
  2827. };
  2828. GComponent.prototype.childSortingOrderChanged = function (child, oldValue, newValue) {
  2829. if (newValue === void 0) { newValue = 0; }
  2830. if (newValue == 0) {
  2831. this._sortingChildCount--;
  2832. this.setChildIndex(child, this._children.length);
  2833. }
  2834. else {
  2835. if (oldValue == 0)
  2836. this._sortingChildCount++;
  2837. var oldIndex = this._children.indexOf(child);
  2838. var index = this.getInsertPosForSortingChild(child);
  2839. if (oldIndex < index)
  2840. this._setChildIndex(child, oldIndex, index - 1);
  2841. else
  2842. this._setChildIndex(child, oldIndex, index);
  2843. }
  2844. };
  2845. GComponent.prototype.constructFromResource = function () {
  2846. this.constructFromResource2(null, 0);
  2847. };
  2848. GComponent.prototype.constructFromResource2 = function (objectPool, poolIndex) {
  2849. var contentItem = this.packageItem.getBranch();
  2850. if (!contentItem.decoded) {
  2851. contentItem.decoded = true;
  2852. fgui.TranslationHelper.translateComponent(contentItem);
  2853. }
  2854. var i;
  2855. var dataLen;
  2856. var curPos;
  2857. var nextPos;
  2858. var f1;
  2859. var f2;
  2860. var i1;
  2861. var i2;
  2862. var buffer = contentItem.rawData;
  2863. buffer.seek(0, 0);
  2864. this._underConstruct = true;
  2865. this.sourceWidth = buffer.readInt();
  2866. this.sourceHeight = buffer.readInt();
  2867. this.initWidth = this.sourceWidth;
  2868. this.initHeight = this.sourceHeight;
  2869. this.setSize(this.sourceWidth, this.sourceHeight);
  2870. if (buffer.readBool()) {
  2871. this.minWidth = buffer.readInt();
  2872. this.maxWidth = buffer.readInt();
  2873. this.minHeight = buffer.readInt();
  2874. this.maxHeight = buffer.readInt();
  2875. }
  2876. if (buffer.readBool()) {
  2877. f1 = buffer.readFloat();
  2878. f2 = buffer.readFloat();
  2879. this.setPivot(f1, f2, buffer.readBool());
  2880. }
  2881. if (buffer.readBool()) {
  2882. this._margin.top = buffer.readInt();
  2883. this._margin.bottom = buffer.readInt();
  2884. this._margin.left = buffer.readInt();
  2885. this._margin.right = buffer.readInt();
  2886. }
  2887. var overflow = buffer.readByte();
  2888. if (overflow == fgui.OverflowType.Scroll) {
  2889. var savedPos = buffer.position;
  2890. buffer.seek(0, 7);
  2891. this.setupScroll(buffer);
  2892. buffer.position = savedPos;
  2893. }
  2894. else
  2895. this.setupOverflow(overflow);
  2896. if (buffer.readBool())
  2897. buffer.skip(8);
  2898. this._buildingDisplayList = true;
  2899. buffer.seek(0, 1);
  2900. var controllerCount = buffer.readShort();
  2901. for (i = 0; i < controllerCount; i++) {
  2902. nextPos = buffer.readShort();
  2903. nextPos += buffer.position;
  2904. var controller = new fgui.Controller();
  2905. this._controllers.push(controller);
  2906. controller.parent = this;
  2907. controller.setup(buffer);
  2908. buffer.position = nextPos;
  2909. }
  2910. buffer.seek(0, 2);
  2911. var child;
  2912. var childCount = buffer.readShort();
  2913. for (i = 0; i < childCount; i++) {
  2914. dataLen = buffer.readShort();
  2915. curPos = buffer.position;
  2916. if (objectPool)
  2917. child = objectPool[poolIndex + i];
  2918. else {
  2919. buffer.seek(curPos, 0);
  2920. var type = buffer.readByte();
  2921. var src = buffer.readS();
  2922. var pkgId = buffer.readS();
  2923. var pi = null;
  2924. if (src != null) {
  2925. var pkg;
  2926. if (pkgId != null)
  2927. pkg = fgui.UIPackage.getById(pkgId);
  2928. else
  2929. pkg = contentItem.owner;
  2930. pi = pkg ? pkg.getItemById(src) : null;
  2931. }
  2932. if (pi) {
  2933. child = fgui.UIObjectFactory.newObject(pi);
  2934. child.constructFromResource();
  2935. }
  2936. else
  2937. child = fgui.UIObjectFactory.newObject(type);
  2938. }
  2939. child._underConstruct = true;
  2940. child.setup_beforeAdd(buffer, curPos);
  2941. child._parent = this;
  2942. child.node.parent = this._container;
  2943. this._children.push(child);
  2944. buffer.position = curPos + dataLen;
  2945. }
  2946. buffer.seek(0, 3);
  2947. this.relations.setup(buffer, true);
  2948. buffer.seek(0, 2);
  2949. buffer.skip(2);
  2950. for (i = 0; i < childCount; i++) {
  2951. nextPos = buffer.readShort();
  2952. nextPos += buffer.position;
  2953. buffer.seek(buffer.position, 3);
  2954. this._children[i].relations.setup(buffer, false);
  2955. buffer.position = nextPos;
  2956. }
  2957. buffer.seek(0, 2);
  2958. buffer.skip(2);
  2959. for (i = 0; i < childCount; i++) {
  2960. nextPos = buffer.readShort();
  2961. nextPos += buffer.position;
  2962. child = this._children[i];
  2963. child.setup_afterAdd(buffer, buffer.position);
  2964. child._underConstruct = false;
  2965. buffer.position = nextPos;
  2966. }
  2967. buffer.seek(0, 4);
  2968. buffer.skip(2);
  2969. this.opaque = buffer.readBool();
  2970. var maskId = buffer.readShort();
  2971. if (maskId != -1) {
  2972. this.setMask(this.getChildAt(maskId), buffer.readBool());
  2973. }
  2974. var hitTestId = buffer.readS();
  2975. i1 = buffer.readInt();
  2976. i2 = buffer.readInt();
  2977. if (hitTestId != null) {
  2978. pi = contentItem.owner.getItemById(hitTestId);
  2979. if (pi && pi.hitTestData)
  2980. this.hitArea = new fgui.PixelHitTest(pi.hitTestData, i1, i2);
  2981. }
  2982. else if (i1 != 0 && i2 != -1) {
  2983. this.hitArea = new fgui.ChildHitArea(this.getChildAt(i2));
  2984. }
  2985. buffer.seek(0, 5);
  2986. var transitionCount = buffer.readShort();
  2987. for (i = 0; i < transitionCount; i++) {
  2988. nextPos = buffer.readShort();
  2989. nextPos += buffer.position;
  2990. var trans = new fgui.Transition(this);
  2991. trans.setup(buffer);
  2992. this._transitions.push(trans);
  2993. buffer.position = nextPos;
  2994. }
  2995. this.applyAllControllers();
  2996. this._buildingDisplayList = false;
  2997. this._underConstruct = false;
  2998. this.buildNativeDisplayList();
  2999. this.setBoundsChangedFlag();
  3000. if (contentItem.objectType != fgui.ObjectType.Component)
  3001. this.constructExtension(buffer);
  3002. this.onConstruct();
  3003. };
  3004. GComponent.prototype.constructExtension = function (buffer) {
  3005. };
  3006. GComponent.prototype.onConstruct = function () {
  3007. };
  3008. GComponent.prototype.setup_afterAdd = function (buffer, beginPos) {
  3009. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  3010. buffer.seek(beginPos, 4);
  3011. var pageController = buffer.readShort();
  3012. if (pageController != -1 && this._scrollPane)
  3013. this._scrollPane.pageController = this._parent.getControllerAt(pageController);
  3014. var cnt = buffer.readShort();
  3015. for (var i = 0; i < cnt; i++) {
  3016. var cc = this.getController(buffer.readS());
  3017. var pageId = buffer.readS();
  3018. if (cc)
  3019. cc.selectedPageId = pageId;
  3020. }
  3021. if (buffer.version >= 2) {
  3022. cnt = buffer.readShort();
  3023. for (i = 0; i < cnt; i++) {
  3024. var target = buffer.readS();
  3025. var propertyId = buffer.readShort();
  3026. var value = buffer.readS();
  3027. var obj = this.getChildByPath(target);
  3028. if (obj)
  3029. obj.setProp(propertyId, value);
  3030. }
  3031. }
  3032. };
  3033. GComponent.prototype.onEnable = function () {
  3034. var cnt = this._transitions.length;
  3035. for (var i = 0; i < cnt; ++i)
  3036. this._transitions[i].onEnable();
  3037. };
  3038. GComponent.prototype.onDisable = function () {
  3039. var cnt = this._transitions.length;
  3040. for (var i = 0; i < cnt; ++i)
  3041. this._transitions[i].onDisable();
  3042. };
  3043. return GComponent;
  3044. }(fgui.GObject));
  3045. fgui.GComponent = GComponent;
  3046. var s_vec2 = new cc.Vec2();
  3047. })(fgui || (fgui = {}));
  3048. (function (fgui) {
  3049. var GButton = (function (_super) {
  3050. __extends(GButton, _super);
  3051. function GButton() {
  3052. var _this = _super.call(this) || this;
  3053. _this._node.name = "GButton";
  3054. _this._mode = fgui.ButtonMode.Common;
  3055. _this._title = "";
  3056. _this._icon = "";
  3057. _this._sound = fgui.UIConfig.buttonSound;
  3058. _this._soundVolumeScale = fgui.UIConfig.buttonSoundVolumeScale;
  3059. _this._changeStateOnClick = true;
  3060. _this._downEffect = 0;
  3061. _this._downEffectValue = 0.8;
  3062. return _this;
  3063. }
  3064. Object.defineProperty(GButton.prototype, "icon", {
  3065. get: function () {
  3066. return this._icon;
  3067. },
  3068. set: function (value) {
  3069. this._icon = value;
  3070. value = (this._selected && this._selectedIcon) ? this._selectedIcon : this._icon;
  3071. if (this._iconObject)
  3072. this._iconObject.icon = value;
  3073. this.updateGear(7);
  3074. },
  3075. enumerable: false,
  3076. configurable: true
  3077. });
  3078. Object.defineProperty(GButton.prototype, "selectedIcon", {
  3079. get: function () {
  3080. return this._selectedIcon;
  3081. },
  3082. set: function (value) {
  3083. this._selectedIcon = value;
  3084. value = (this._selected && this._selectedIcon) ? this._selectedIcon : this._icon;
  3085. if (this._iconObject)
  3086. this._iconObject.icon = value;
  3087. },
  3088. enumerable: false,
  3089. configurable: true
  3090. });
  3091. Object.defineProperty(GButton.prototype, "title", {
  3092. get: function () {
  3093. return this._title;
  3094. },
  3095. set: function (value) {
  3096. this._title = value;
  3097. if (this._titleObject)
  3098. this._titleObject.text = (this._selected && this._selectedTitle) ? this._selectedTitle : this._title;
  3099. this.updateGear(6);
  3100. },
  3101. enumerable: false,
  3102. configurable: true
  3103. });
  3104. Object.defineProperty(GButton.prototype, "text", {
  3105. get: function () {
  3106. return this.title;
  3107. },
  3108. set: function (value) {
  3109. this.title = value;
  3110. },
  3111. enumerable: false,
  3112. configurable: true
  3113. });
  3114. Object.defineProperty(GButton.prototype, "selectedTitle", {
  3115. get: function () {
  3116. return this._selectedTitle;
  3117. },
  3118. set: function (value) {
  3119. this._selectedTitle = value;
  3120. if (this._titleObject)
  3121. this._titleObject.text = (this._selected && this._selectedTitle) ? this._selectedTitle : this._title;
  3122. },
  3123. enumerable: false,
  3124. configurable: true
  3125. });
  3126. Object.defineProperty(GButton.prototype, "titleColor", {
  3127. get: function () {
  3128. var tf = this.getTextField();
  3129. if (tf)
  3130. return tf.color;
  3131. else
  3132. return cc.Color.BLACK;
  3133. },
  3134. set: function (value) {
  3135. var tf = this.getTextField();
  3136. if (tf)
  3137. tf.color = value;
  3138. },
  3139. enumerable: false,
  3140. configurable: true
  3141. });
  3142. Object.defineProperty(GButton.prototype, "titleFontSize", {
  3143. get: function () {
  3144. var tf = this.getTextField();
  3145. if (tf)
  3146. return tf.fontSize;
  3147. else
  3148. return 0;
  3149. },
  3150. set: function (value) {
  3151. var tf = this.getTextField();
  3152. if (tf)
  3153. tf.fontSize = value;
  3154. },
  3155. enumerable: false,
  3156. configurable: true
  3157. });
  3158. Object.defineProperty(GButton.prototype, "sound", {
  3159. get: function () {
  3160. return this._sound;
  3161. },
  3162. set: function (val) {
  3163. this._sound = val;
  3164. },
  3165. enumerable: false,
  3166. configurable: true
  3167. });
  3168. Object.defineProperty(GButton.prototype, "soundVolumeScale", {
  3169. get: function () {
  3170. return this._soundVolumeScale;
  3171. },
  3172. set: function (value) {
  3173. this._soundVolumeScale = value;
  3174. },
  3175. enumerable: false,
  3176. configurable: true
  3177. });
  3178. Object.defineProperty(GButton.prototype, "selected", {
  3179. get: function () {
  3180. return this._selected;
  3181. },
  3182. set: function (val) {
  3183. if (this._mode == fgui.ButtonMode.Common)
  3184. return;
  3185. if (this._selected != val) {
  3186. this._selected = val;
  3187. this.setCurrentState();
  3188. if (this._selectedTitle && this._titleObject)
  3189. this._titleObject.text = this._selected ? this._selectedTitle : this._title;
  3190. if (this._selectedIcon) {
  3191. var str = this._selected ? this._selectedIcon : this._icon;
  3192. if (this._iconObject)
  3193. this._iconObject.icon = str;
  3194. }
  3195. if (this._relatedController
  3196. && this._parent
  3197. && !this._parent._buildingDisplayList) {
  3198. if (this._selected) {
  3199. this._relatedController.selectedPageId = this._relatedPageId;
  3200. if (this._relatedController.autoRadioGroupDepth)
  3201. this._parent.adjustRadioGroupDepth(this, this._relatedController);
  3202. }
  3203. else if (this._mode == fgui.ButtonMode.Check && this._relatedController.selectedPageId == this._relatedPageId)
  3204. this._relatedController.oppositePageId = this._relatedPageId;
  3205. }
  3206. }
  3207. },
  3208. enumerable: false,
  3209. configurable: true
  3210. });
  3211. Object.defineProperty(GButton.prototype, "mode", {
  3212. get: function () {
  3213. return this._mode;
  3214. },
  3215. set: function (value) {
  3216. if (this._mode != value) {
  3217. if (value == fgui.ButtonMode.Common)
  3218. this.selected = false;
  3219. this._mode = value;
  3220. }
  3221. },
  3222. enumerable: false,
  3223. configurable: true
  3224. });
  3225. Object.defineProperty(GButton.prototype, "relatedController", {
  3226. get: function () {
  3227. return this._relatedController;
  3228. },
  3229. set: function (val) {
  3230. this._relatedController = val;
  3231. },
  3232. enumerable: false,
  3233. configurable: true
  3234. });
  3235. Object.defineProperty(GButton.prototype, "relatedPageId", {
  3236. get: function () {
  3237. return this._relatedPageId;
  3238. },
  3239. set: function (val) {
  3240. this._relatedPageId = val;
  3241. },
  3242. enumerable: false,
  3243. configurable: true
  3244. });
  3245. Object.defineProperty(GButton.prototype, "changeStateOnClick", {
  3246. get: function () {
  3247. return this._changeStateOnClick;
  3248. },
  3249. set: function (value) {
  3250. this._changeStateOnClick = value;
  3251. },
  3252. enumerable: false,
  3253. configurable: true
  3254. });
  3255. Object.defineProperty(GButton.prototype, "linkedPopup", {
  3256. get: function () {
  3257. return this._linkedPopup;
  3258. },
  3259. set: function (value) {
  3260. this._linkedPopup = value;
  3261. },
  3262. enumerable: false,
  3263. configurable: true
  3264. });
  3265. GButton.prototype.getTextField = function () {
  3266. if (this._titleObject instanceof fgui.GTextField)
  3267. return this._titleObject;
  3268. else if ((this._titleObject instanceof fgui.GLabel) || (this._titleObject instanceof GButton))
  3269. return this._titleObject.getTextField();
  3270. else
  3271. return null;
  3272. };
  3273. GButton.prototype.fireClick = function () {
  3274. fgui.GRoot.inst.inputProcessor.simulateClick(this);
  3275. };
  3276. GButton.prototype.setState = function (val) {
  3277. if (this._buttonController)
  3278. this._buttonController.selectedPage = val;
  3279. if (this._downEffect == 1) {
  3280. var cnt = this.numChildren;
  3281. if (val == GButton.DOWN || val == GButton.SELECTED_OVER || val == GButton.SELECTED_DISABLED) {
  3282. if (!this._downColor)
  3283. this._downColor = new cc.Color();
  3284. var r = this._downEffectValue * 255;
  3285. this._downColor.r = this._downColor.g = this._downColor.b = r;
  3286. for (var i = 0; i < cnt; i++) {
  3287. var obj = this.getChildAt(i);
  3288. if (obj["color"] != undefined && !(obj instanceof fgui.GTextField))
  3289. obj.color = this._downColor;
  3290. }
  3291. }
  3292. else {
  3293. for (var i = 0; i < cnt; i++) {
  3294. var obj = this.getChildAt(i);
  3295. if (obj["color"] != undefined && !(obj instanceof fgui.GTextField))
  3296. obj.color = cc.Color.WHITE;
  3297. }
  3298. }
  3299. }
  3300. else if (this._downEffect == 2) {
  3301. if (val == GButton.DOWN || val == GButton.SELECTED_OVER || val == GButton.SELECTED_DISABLED) {
  3302. if (!this._downScaled) {
  3303. this._downScaled = true;
  3304. this.setScale(this.scaleX * this._downEffectValue, this.scaleY * this._downEffectValue);
  3305. }
  3306. }
  3307. else {
  3308. if (this._downScaled) {
  3309. this._downScaled = false;
  3310. this.setScale(this.scaleX / this._downEffectValue, this.scaleY / this._downEffectValue);
  3311. }
  3312. }
  3313. }
  3314. };
  3315. GButton.prototype.setCurrentState = function () {
  3316. if (this.grayed && this._buttonController && this._buttonController.hasPage(GButton.DISABLED)) {
  3317. if (this._selected)
  3318. this.setState(GButton.SELECTED_DISABLED);
  3319. else
  3320. this.setState(GButton.DISABLED);
  3321. }
  3322. else {
  3323. if (this._selected)
  3324. this.setState(this._over ? GButton.SELECTED_OVER : GButton.DOWN);
  3325. else
  3326. this.setState(this._over ? GButton.OVER : GButton.UP);
  3327. }
  3328. };
  3329. GButton.prototype.handleControllerChanged = function (c) {
  3330. _super.prototype.handleControllerChanged.call(this, c);
  3331. if (this._relatedController == c)
  3332. this.selected = this._relatedPageId == c.selectedPageId;
  3333. };
  3334. GButton.prototype.handleGrayedChanged = function () {
  3335. if (this._buttonController && this._buttonController.hasPage(GButton.DISABLED)) {
  3336. if (this.grayed) {
  3337. if (this._selected && this._buttonController.hasPage(GButton.SELECTED_DISABLED))
  3338. this.setState(GButton.SELECTED_DISABLED);
  3339. else
  3340. this.setState(GButton.DISABLED);
  3341. }
  3342. else if (this._selected)
  3343. this.setState(GButton.DOWN);
  3344. else
  3345. this.setState(GButton.UP);
  3346. }
  3347. else
  3348. _super.prototype.handleGrayedChanged.call(this);
  3349. };
  3350. GButton.prototype.getProp = function (index) {
  3351. switch (index) {
  3352. case fgui.ObjectPropID.Color:
  3353. return this.titleColor;
  3354. case fgui.ObjectPropID.OutlineColor:
  3355. {
  3356. var tf = this.getTextField();
  3357. if (tf)
  3358. return tf.strokeColor;
  3359. else
  3360. return 0;
  3361. }
  3362. case fgui.ObjectPropID.FontSize:
  3363. return this.titleFontSize;
  3364. case fgui.ObjectPropID.Selected:
  3365. return this.selected;
  3366. default:
  3367. return _super.prototype.getProp.call(this, index);
  3368. }
  3369. };
  3370. GButton.prototype.setProp = function (index, value) {
  3371. switch (index) {
  3372. case fgui.ObjectPropID.Color:
  3373. this.titleColor = value;
  3374. break;
  3375. case fgui.ObjectPropID.OutlineColor:
  3376. {
  3377. var tf = this.getTextField();
  3378. if (tf)
  3379. tf.strokeColor = value;
  3380. }
  3381. break;
  3382. case fgui.ObjectPropID.FontSize:
  3383. this.titleFontSize = value;
  3384. break;
  3385. case fgui.ObjectPropID.Selected:
  3386. this.selected = value;
  3387. break;
  3388. default:
  3389. _super.prototype.setProp.call(this, index, value);
  3390. break;
  3391. }
  3392. };
  3393. GButton.prototype.constructExtension = function (buffer) {
  3394. buffer.seek(0, 6);
  3395. this._mode = buffer.readByte();
  3396. var str = buffer.readS();
  3397. if (str)
  3398. this._sound = str;
  3399. this._soundVolumeScale = buffer.readFloat();
  3400. this._downEffect = buffer.readByte();
  3401. this._downEffectValue = buffer.readFloat();
  3402. if (this._downEffect == 2)
  3403. this.setPivot(0.5, 0.5, this.pivotAsAnchor);
  3404. this._buttonController = this.getController("button");
  3405. this._titleObject = this.getChild("title");
  3406. this._iconObject = this.getChild("icon");
  3407. if (this._titleObject)
  3408. this._title = this._titleObject.text;
  3409. if (this._iconObject)
  3410. this._icon = this._iconObject.icon;
  3411. if (this._mode == fgui.ButtonMode.Common)
  3412. this.setState(GButton.UP);
  3413. this._node.on(fgui.Event.TOUCH_BEGIN, this.onTouchBegin_1, this);
  3414. this._node.on(fgui.Event.TOUCH_END, this.onTouchEnd_1, this);
  3415. this._node.on(fgui.Event.ROLL_OVER, this.onRollOver_1, this);
  3416. this._node.on(fgui.Event.ROLL_OUT, this.onRollOut_1, this);
  3417. this._node.on(fgui.Event.CLICK, this.onClick_1, this);
  3418. };
  3419. GButton.prototype.setup_afterAdd = function (buffer, beginPos) {
  3420. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  3421. if (!buffer.seek(beginPos, 6))
  3422. return;
  3423. if (buffer.readByte() != this.packageItem.objectType)
  3424. return;
  3425. var str;
  3426. var iv;
  3427. str = buffer.readS();
  3428. if (str != null)
  3429. this.title = str;
  3430. str = buffer.readS();
  3431. if (str != null)
  3432. this.selectedTitle = str;
  3433. str = buffer.readS();
  3434. if (str != null)
  3435. this.icon = str;
  3436. str = buffer.readS();
  3437. if (str != null)
  3438. this.selectedIcon = str;
  3439. if (buffer.readBool())
  3440. this.titleColor = buffer.readColor();
  3441. iv = buffer.readInt();
  3442. if (iv != 0)
  3443. this.titleFontSize = iv;
  3444. iv = buffer.readShort();
  3445. if (iv >= 0)
  3446. this._relatedController = this.parent.getControllerAt(iv);
  3447. this._relatedPageId = buffer.readS();
  3448. str = buffer.readS();
  3449. if (str != null)
  3450. this._sound = str;
  3451. if (buffer.readBool())
  3452. this._soundVolumeScale = buffer.readFloat();
  3453. this.selected = buffer.readBool();
  3454. };
  3455. GButton.prototype.onRollOver_1 = function () {
  3456. if (!this._buttonController || !this._buttonController.hasPage(GButton.OVER))
  3457. return;
  3458. this._over = true;
  3459. if (this._down)
  3460. return;
  3461. if (this.grayed && this._buttonController.hasPage(GButton.DISABLED))
  3462. return;
  3463. this.setState(this._selected ? GButton.SELECTED_OVER : GButton.OVER);
  3464. };
  3465. GButton.prototype.onRollOut_1 = function () {
  3466. if (!this._buttonController || !this._buttonController.hasPage(GButton.OVER))
  3467. return;
  3468. this._over = false;
  3469. if (this._down)
  3470. return;
  3471. if (this.grayed && this._buttonController.hasPage(GButton.DISABLED))
  3472. return;
  3473. this.setState(this._selected ? GButton.DOWN : GButton.UP);
  3474. };
  3475. GButton.prototype.onTouchBegin_1 = function (evt) {
  3476. if (evt.button != cc.Event.EventMouse.BUTTON_LEFT)
  3477. return;
  3478. this._down = true;
  3479. evt.captureTouch();
  3480. if (this._mode == fgui.ButtonMode.Common) {
  3481. if (this.grayed && this._buttonController && this._buttonController.hasPage(GButton.DISABLED))
  3482. this.setState(GButton.SELECTED_DISABLED);
  3483. else
  3484. this.setState(GButton.DOWN);
  3485. }
  3486. if (this._linkedPopup) {
  3487. if (this._linkedPopup instanceof fgui.Window)
  3488. this._linkedPopup.toggleStatus();
  3489. else
  3490. this.root.togglePopup(this._linkedPopup, this);
  3491. }
  3492. };
  3493. GButton.prototype.onTouchEnd_1 = function (evt) {
  3494. if (evt.button != cc.Event.EventMouse.BUTTON_LEFT)
  3495. return;
  3496. if (this._down) {
  3497. this._down = false;
  3498. if (this._node == null)
  3499. return;
  3500. if (this._mode == fgui.ButtonMode.Common) {
  3501. if (this.grayed && this._buttonController && this._buttonController.hasPage(GButton.DISABLED))
  3502. this.setState(GButton.DISABLED);
  3503. else if (this._over)
  3504. this.setState(GButton.OVER);
  3505. else
  3506. this.setState(GButton.UP);
  3507. }
  3508. else {
  3509. if (!this._over
  3510. && this._buttonController != null
  3511. && (this._buttonController.selectedPage == GButton.OVER
  3512. || this._buttonController.selectedPage == GButton.SELECTED_OVER)) {
  3513. this.setCurrentState();
  3514. }
  3515. }
  3516. }
  3517. };
  3518. GButton.prototype.onClick_1 = function () {
  3519. if (this._sound) {
  3520. var pi = fgui.UIPackage.getItemByURL(this._sound);
  3521. if (pi) {
  3522. var sound = pi.owner.getItemAsset(pi);
  3523. if (sound)
  3524. fgui.GRoot.inst.playOneShotSound(sound, this._soundVolumeScale);
  3525. }
  3526. }
  3527. if (this._mode == fgui.ButtonMode.Check) {
  3528. if (this._changeStateOnClick) {
  3529. this.selected = !this._selected;
  3530. this._node.emit(fgui.Event.STATUS_CHANGED, this);
  3531. }
  3532. }
  3533. else if (this._mode == fgui.ButtonMode.Radio) {
  3534. if (this._changeStateOnClick && !this._selected) {
  3535. this.selected = true;
  3536. this._node.emit(fgui.Event.STATUS_CHANGED, this);
  3537. }
  3538. }
  3539. else {
  3540. if (this._relatedController)
  3541. this._relatedController.selectedPageId = this._relatedPageId;
  3542. }
  3543. };
  3544. GButton.UP = "up";
  3545. GButton.DOWN = "down";
  3546. GButton.OVER = "over";
  3547. GButton.SELECTED_OVER = "selectedOver";
  3548. GButton.DISABLED = "disabled";
  3549. GButton.SELECTED_DISABLED = "selectedDisabled";
  3550. return GButton;
  3551. }(fgui.GComponent));
  3552. fgui.GButton = GButton;
  3553. })(fgui || (fgui = {}));
  3554. (function (fgui) {
  3555. var GComboBox = (function (_super) {
  3556. __extends(GComboBox, _super);
  3557. function GComboBox() {
  3558. var _this = _super.call(this) || this;
  3559. _this._visibleItemCount = 0;
  3560. _this._selectedIndex = 0;
  3561. _this._popupDirection = fgui.PopupDirection.Auto;
  3562. _this._node.name = "GComboBox";
  3563. _this._visibleItemCount = fgui.UIConfig.defaultComboBoxVisibleItemCount;
  3564. _this._itemsUpdated = true;
  3565. _this._selectedIndex = -1;
  3566. _this._items = [];
  3567. _this._values = [];
  3568. return _this;
  3569. }
  3570. Object.defineProperty(GComboBox.prototype, "text", {
  3571. get: function () {
  3572. if (this._titleObject)
  3573. return this._titleObject.text;
  3574. else
  3575. return null;
  3576. },
  3577. set: function (value) {
  3578. if (this._titleObject)
  3579. this._titleObject.text = value;
  3580. this.updateGear(6);
  3581. },
  3582. enumerable: false,
  3583. configurable: true
  3584. });
  3585. Object.defineProperty(GComboBox.prototype, "icon", {
  3586. get: function () {
  3587. if (this._iconObject)
  3588. return this._iconObject.icon;
  3589. else
  3590. return null;
  3591. },
  3592. set: function (value) {
  3593. if (this._iconObject)
  3594. this._iconObject.icon = value;
  3595. this.updateGear(7);
  3596. },
  3597. enumerable: false,
  3598. configurable: true
  3599. });
  3600. Object.defineProperty(GComboBox.prototype, "titleColor", {
  3601. get: function () {
  3602. var tf = this.getTextField();
  3603. if (tf)
  3604. return tf.color;
  3605. else
  3606. return cc.Color.BLACK;
  3607. },
  3608. set: function (value) {
  3609. var tf = this.getTextField();
  3610. if (tf)
  3611. tf.color = value;
  3612. },
  3613. enumerable: false,
  3614. configurable: true
  3615. });
  3616. Object.defineProperty(GComboBox.prototype, "titleFontSize", {
  3617. get: function () {
  3618. var tf = this.getTextField();
  3619. if (tf)
  3620. return tf.fontSize;
  3621. else
  3622. return 0;
  3623. },
  3624. set: function (value) {
  3625. var tf = this.getTextField();
  3626. if (tf)
  3627. tf.fontSize = value;
  3628. },
  3629. enumerable: false,
  3630. configurable: true
  3631. });
  3632. Object.defineProperty(GComboBox.prototype, "visibleItemCount", {
  3633. get: function () {
  3634. return this._visibleItemCount;
  3635. },
  3636. set: function (value) {
  3637. this._visibleItemCount = value;
  3638. },
  3639. enumerable: false,
  3640. configurable: true
  3641. });
  3642. Object.defineProperty(GComboBox.prototype, "popupDirection", {
  3643. get: function () {
  3644. return this._popupDirection;
  3645. },
  3646. set: function (value) {
  3647. this._popupDirection = value;
  3648. },
  3649. enumerable: false,
  3650. configurable: true
  3651. });
  3652. Object.defineProperty(GComboBox.prototype, "items", {
  3653. get: function () {
  3654. return this._items;
  3655. },
  3656. set: function (value) {
  3657. if (!value)
  3658. this._items.length = 0;
  3659. else
  3660. this._items = value.concat();
  3661. if (this._items.length > 0) {
  3662. if (this._selectedIndex >= this._items.length)
  3663. this._selectedIndex = this._items.length - 1;
  3664. else if (this._selectedIndex == -1)
  3665. this._selectedIndex = 0;
  3666. this.text = this._items[this._selectedIndex];
  3667. if (this._icons && this._selectedIndex < this._icons.length)
  3668. this.icon = this._icons[this._selectedIndex];
  3669. }
  3670. else {
  3671. this.text = "";
  3672. if (this._icons)
  3673. this.icon = null;
  3674. this._selectedIndex = -1;
  3675. }
  3676. this._itemsUpdated = true;
  3677. },
  3678. enumerable: false,
  3679. configurable: true
  3680. });
  3681. Object.defineProperty(GComboBox.prototype, "icons", {
  3682. get: function () {
  3683. return this._icons;
  3684. },
  3685. set: function (value) {
  3686. this._icons = value;
  3687. if (this._icons && this._selectedIndex != -1 && this._selectedIndex < this._icons.length)
  3688. this.icon = this._icons[this._selectedIndex];
  3689. },
  3690. enumerable: false,
  3691. configurable: true
  3692. });
  3693. Object.defineProperty(GComboBox.prototype, "values", {
  3694. get: function () {
  3695. return this._values;
  3696. },
  3697. set: function (value) {
  3698. if (!value)
  3699. this._values.length = 0;
  3700. else
  3701. this._values = value.concat();
  3702. },
  3703. enumerable: false,
  3704. configurable: true
  3705. });
  3706. Object.defineProperty(GComboBox.prototype, "selectedIndex", {
  3707. get: function () {
  3708. return this._selectedIndex;
  3709. },
  3710. set: function (val) {
  3711. if (this._selectedIndex == val)
  3712. return;
  3713. this._selectedIndex = val;
  3714. if (this._selectedIndex >= 0 && this._selectedIndex < this._items.length) {
  3715. this.text = this._items[this._selectedIndex];
  3716. if (this._icons && this._selectedIndex < this._icons.length)
  3717. this.icon = this._icons[this._selectedIndex];
  3718. }
  3719. else {
  3720. this.text = "";
  3721. if (this._icons)
  3722. this.icon = null;
  3723. }
  3724. this.updateSelectionController();
  3725. },
  3726. enumerable: false,
  3727. configurable: true
  3728. });
  3729. Object.defineProperty(GComboBox.prototype, "value", {
  3730. get: function () {
  3731. return this._values[this._selectedIndex];
  3732. },
  3733. set: function (val) {
  3734. var index = this._values.indexOf(val);
  3735. if (index == -1 && val == null)
  3736. index = this._values.indexOf("");
  3737. this.selectedIndex = index;
  3738. },
  3739. enumerable: false,
  3740. configurable: true
  3741. });
  3742. Object.defineProperty(GComboBox.prototype, "selectionController", {
  3743. get: function () {
  3744. return this._selectionController;
  3745. },
  3746. set: function (value) {
  3747. this._selectionController = value;
  3748. },
  3749. enumerable: false,
  3750. configurable: true
  3751. });
  3752. GComboBox.prototype.getTextField = function () {
  3753. if (this._titleObject instanceof fgui.GTextField)
  3754. return this._titleObject;
  3755. else if ((this._titleObject instanceof fgui.GLabel) || (this._titleObject instanceof fgui.GButton))
  3756. return this._titleObject.getTextField();
  3757. else
  3758. return null;
  3759. };
  3760. GComboBox.prototype.setState = function (val) {
  3761. if (this._buttonController)
  3762. this._buttonController.selectedPage = val;
  3763. };
  3764. GComboBox.prototype.getProp = function (index) {
  3765. switch (index) {
  3766. case fgui.ObjectPropID.Color:
  3767. return this.titleColor;
  3768. case fgui.ObjectPropID.OutlineColor:
  3769. {
  3770. var tf = this.getTextField();
  3771. if (tf)
  3772. return tf.strokeColor;
  3773. else
  3774. return 0;
  3775. }
  3776. case fgui.ObjectPropID.FontSize:
  3777. {
  3778. tf = this.getTextField();
  3779. if (tf)
  3780. return tf.fontSize;
  3781. else
  3782. return 0;
  3783. }
  3784. default:
  3785. return _super.prototype.getProp.call(this, index);
  3786. }
  3787. };
  3788. GComboBox.prototype.setProp = function (index, value) {
  3789. switch (index) {
  3790. case fgui.ObjectPropID.Color:
  3791. this.titleColor = value;
  3792. break;
  3793. case fgui.ObjectPropID.OutlineColor:
  3794. {
  3795. var tf = this.getTextField();
  3796. if (tf)
  3797. tf.strokeColor = value;
  3798. }
  3799. break;
  3800. case fgui.ObjectPropID.FontSize:
  3801. {
  3802. tf = this.getTextField();
  3803. if (tf)
  3804. tf.fontSize = value;
  3805. }
  3806. break;
  3807. default:
  3808. _super.prototype.setProp.call(this, index, value);
  3809. break;
  3810. }
  3811. };
  3812. GComboBox.prototype.constructExtension = function (buffer) {
  3813. var str;
  3814. this._buttonController = this.getController("button");
  3815. this._titleObject = this.getChild("title");
  3816. this._iconObject = this.getChild("icon");
  3817. str = buffer.readS();
  3818. if (str) {
  3819. var obj = fgui.UIPackage.createObjectFromURL(str);
  3820. if (!(obj instanceof fgui.GComponent)) {
  3821. console.error("下拉框必须为元件");
  3822. return;
  3823. }
  3824. this.dropdown = obj;
  3825. this.dropdown.name = "this.dropdown";
  3826. this._list = this.dropdown.getChild("list");
  3827. if (this._list == null) {
  3828. console.error(this.resourceURL + ": 下拉框的弹出元件里必须包含名为list的列表");
  3829. return;
  3830. }
  3831. this._list.on(fgui.Event.CLICK_ITEM, this.onClickItem, this);
  3832. this._list.addRelation(this.dropdown, fgui.RelationType.Width);
  3833. this._list.removeRelation(this.dropdown, fgui.RelationType.Height);
  3834. this.dropdown.addRelation(this._list, fgui.RelationType.Height);
  3835. this.dropdown.removeRelation(this._list, fgui.RelationType.Width);
  3836. this.dropdown.on(fgui.Event.UNDISPLAY, this.onPopupClosed, this);
  3837. }
  3838. this._node.on(fgui.Event.TOUCH_BEGIN, this.onTouchBegin_1, this);
  3839. this._node.on(fgui.Event.TOUCH_END, this.onTouchEnd_1, this);
  3840. this._node.on(fgui.Event.ROLL_OVER, this.onRollOver_1, this);
  3841. this._node.on(fgui.Event.ROLL_OUT, this.onRollOut_1, this);
  3842. };
  3843. GComboBox.prototype.handleControllerChanged = function (c) {
  3844. _super.prototype.handleControllerChanged.call(this, c);
  3845. if (this._selectionController == c)
  3846. this.selectedIndex = c.selectedIndex;
  3847. };
  3848. GComboBox.prototype.updateSelectionController = function () {
  3849. if (this._selectionController && !this._selectionController.changing
  3850. && this._selectedIndex < this._selectionController.pageCount) {
  3851. var c = this._selectionController;
  3852. this._selectionController = null;
  3853. c.selectedIndex = this._selectedIndex;
  3854. this._selectionController = c;
  3855. }
  3856. };
  3857. GComboBox.prototype.dispose = function () {
  3858. if (this.dropdown) {
  3859. this.dropdown.dispose();
  3860. this.dropdown = null;
  3861. }
  3862. _super.prototype.dispose.call(this);
  3863. };
  3864. GComboBox.prototype.setup_afterAdd = function (buffer, beginPos) {
  3865. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  3866. if (!buffer.seek(beginPos, 6))
  3867. return;
  3868. if (buffer.readByte() != this.packageItem.objectType)
  3869. return;
  3870. var i;
  3871. var iv;
  3872. var nextPos;
  3873. var str;
  3874. var itemCount = buffer.readShort();
  3875. for (i = 0; i < itemCount; i++) {
  3876. nextPos = buffer.readShort();
  3877. nextPos += buffer.position;
  3878. this._items[i] = buffer.readS();
  3879. this._values[i] = buffer.readS();
  3880. str = buffer.readS();
  3881. if (str != null) {
  3882. if (this._icons == null)
  3883. this._icons = new Array();
  3884. this._icons[i] = str;
  3885. }
  3886. buffer.position = nextPos;
  3887. }
  3888. str = buffer.readS();
  3889. if (str != null) {
  3890. this.text = str;
  3891. this._selectedIndex = this._items.indexOf(str);
  3892. }
  3893. else if (this._items.length > 0) {
  3894. this._selectedIndex = 0;
  3895. this.text = this._items[0];
  3896. }
  3897. else
  3898. this._selectedIndex = -1;
  3899. str = buffer.readS();
  3900. if (str != null)
  3901. this.icon = str;
  3902. if (buffer.readBool())
  3903. this.titleColor = buffer.readColor();
  3904. iv = buffer.readInt();
  3905. if (iv > 0)
  3906. this._visibleItemCount = iv;
  3907. this._popupDirection = buffer.readByte();
  3908. iv = buffer.readShort();
  3909. if (iv >= 0)
  3910. this._selectionController = this.parent.getControllerAt(iv);
  3911. };
  3912. GComboBox.prototype.showDropdown = function () {
  3913. if (this._itemsUpdated) {
  3914. this._itemsUpdated = false;
  3915. this._list.removeChildrenToPool();
  3916. var cnt = this._items.length;
  3917. for (var i = 0; i < cnt; i++) {
  3918. var item = this._list.addItemFromPool();
  3919. item.name = i < this._values.length ? this._values[i] : "";
  3920. item.text = this._items[i];
  3921. item.icon = (this._icons && i < this._icons.length) ? this._icons[i] : null;
  3922. }
  3923. this._list.resizeToFit(this._visibleItemCount);
  3924. }
  3925. this._list.selectedIndex = -1;
  3926. this.dropdown.width = this.width;
  3927. this._list.ensureBoundsCorrect();
  3928. this.root.togglePopup(this.dropdown, this, this._popupDirection);
  3929. if (this.dropdown.parent)
  3930. this.setState(fgui.GButton.DOWN);
  3931. };
  3932. GComboBox.prototype.onPopupClosed = function () {
  3933. if (this._over)
  3934. this.setState(fgui.GButton.OVER);
  3935. else
  3936. this.setState(fgui.GButton.UP);
  3937. };
  3938. GComboBox.prototype.onClickItem = function (itemObject) {
  3939. var _t = this;
  3940. var index = this._list.getChildIndex(itemObject);
  3941. this._partner.callLater(function (dt) {
  3942. _t.onClickItem2(index);
  3943. }, 0.1);
  3944. };
  3945. GComboBox.prototype.onClickItem2 = function (index) {
  3946. if (this.dropdown.parent instanceof fgui.GRoot)
  3947. this.dropdown.parent.hidePopup();
  3948. this._selectedIndex = -1;
  3949. this.selectedIndex = index;
  3950. this._node.emit(fgui.Event.STATUS_CHANGED, this);
  3951. };
  3952. GComboBox.prototype.onRollOver_1 = function () {
  3953. this._over = true;
  3954. if (this._down || this.dropdown && this.dropdown.parent)
  3955. return;
  3956. this.setState(fgui.GButton.OVER);
  3957. };
  3958. GComboBox.prototype.onRollOut_1 = function () {
  3959. this._over = false;
  3960. if (this._down || this.dropdown && this.dropdown.parent)
  3961. return;
  3962. this.setState(fgui.GButton.UP);
  3963. };
  3964. GComboBox.prototype.onTouchBegin_1 = function (evt) {
  3965. if (evt.button != cc.Event.EventMouse.BUTTON_LEFT)
  3966. return;
  3967. if ((evt.initiator instanceof fgui.GTextInput) && evt.initiator.editable)
  3968. return;
  3969. this._down = true;
  3970. evt.captureTouch();
  3971. if (this.dropdown)
  3972. this.showDropdown();
  3973. };
  3974. GComboBox.prototype.onTouchEnd_1 = function (evt) {
  3975. if (evt.button != cc.Event.EventMouse.BUTTON_LEFT)
  3976. return;
  3977. if (this._down) {
  3978. this._down = false;
  3979. if (this.dropdown && !this.dropdown.parent) {
  3980. if (this._over)
  3981. this.setState(fgui.GButton.OVER);
  3982. else
  3983. this.setState(fgui.GButton.UP);
  3984. }
  3985. }
  3986. };
  3987. return GComboBox;
  3988. }(fgui.GComponent));
  3989. fgui.GComboBox = GComboBox;
  3990. })(fgui || (fgui = {}));
  3991. (function (fgui) {
  3992. var GGraph = (function (_super) {
  3993. __extends(GGraph, _super);
  3994. function GGraph() {
  3995. var _this = _super.call(this) || this;
  3996. _this._type = 0;
  3997. _this._lineSize = 0;
  3998. _this._node.name = "GGraph";
  3999. _this._lineSize = 1;
  4000. _this._lineColor = new cc.Color();
  4001. _this._fillColor = new cc.Color(255, 255, 255, 255);
  4002. _this._content = _this._node.addComponent(cc.Graphics);
  4003. return _this;
  4004. }
  4005. GGraph.prototype.drawRect = function (lineSize, lineColor, fillColor, corner) {
  4006. this._type = 1;
  4007. this._lineSize = lineSize;
  4008. this._lineColor.set(lineColor);
  4009. this._fillColor.set(fillColor);
  4010. this._cornerRadius = corner;
  4011. this.updateGraph();
  4012. };
  4013. GGraph.prototype.drawEllipse = function (lineSize, lineColor, fillColor) {
  4014. this._type = 2;
  4015. this._lineSize = lineSize;
  4016. this._lineColor.set(lineColor);
  4017. this._fillColor.set(fillColor);
  4018. this.updateGraph();
  4019. };
  4020. GGraph.prototype.drawRegularPolygon = function (lineSize, lineColor, fillColor, sides, startAngle, distances) {
  4021. this._type = 4;
  4022. this._lineSize = lineSize;
  4023. this._lineColor.set(lineColor);
  4024. this._fillColor.set(fillColor);
  4025. this._sides = sides;
  4026. this._startAngle = startAngle || 0;
  4027. this._distances = distances;
  4028. this.updateGraph();
  4029. };
  4030. GGraph.prototype.drawPolygon = function (lineSize, lineColor, fillColor, points) {
  4031. this._type = 3;
  4032. this._lineSize = lineSize;
  4033. this._lineColor.set(lineColor);
  4034. this._fillColor.set(fillColor);
  4035. this._polygonPoints = points;
  4036. this.updateGraph();
  4037. };
  4038. Object.defineProperty(GGraph.prototype, "distances", {
  4039. get: function () {
  4040. return this._distances;
  4041. },
  4042. set: function (value) {
  4043. this._distances = value;
  4044. if (this._type == 3)
  4045. this.updateGraph();
  4046. },
  4047. enumerable: false,
  4048. configurable: true
  4049. });
  4050. GGraph.prototype.clearGraphics = function () {
  4051. this._type = 0;
  4052. if (this._hasContent) {
  4053. this._content.clear();
  4054. this._hasContent = false;
  4055. }
  4056. };
  4057. Object.defineProperty(GGraph.prototype, "type", {
  4058. get: function () {
  4059. return this._type;
  4060. },
  4061. enumerable: false,
  4062. configurable: true
  4063. });
  4064. Object.defineProperty(GGraph.prototype, "color", {
  4065. get: function () {
  4066. return this._fillColor;
  4067. },
  4068. set: function (value) {
  4069. this._fillColor.set(value);
  4070. if (this._type != 0)
  4071. this.updateGraph();
  4072. },
  4073. enumerable: false,
  4074. configurable: true
  4075. });
  4076. GGraph.prototype.updateGraph = function () {
  4077. var ctx = this._content;
  4078. if (this._hasContent) {
  4079. this._hasContent = false;
  4080. ctx.clear();
  4081. }
  4082. var w = this._width;
  4083. var h = this._height;
  4084. if (w == 0 || h == 0)
  4085. return;
  4086. var px = -this.pivotX * this._width;
  4087. var py = this.pivotY * this._height;
  4088. var ls = this._lineSize / 2;
  4089. ctx.lineWidth = this._lineSize;
  4090. ctx.strokeColor = this._lineColor;
  4091. ctx.fillColor = this._fillColor;
  4092. if (this._type == 1) {
  4093. if (this._cornerRadius) {
  4094. ctx.roundRect(px + ls, -h + py + ls, w - this._lineSize, h - this._lineSize, this._cornerRadius[0]);
  4095. }
  4096. else
  4097. ctx.rect(px + ls, -h + py + ls, w - this._lineSize, h - this._lineSize);
  4098. }
  4099. else if (this._type == 2) {
  4100. ctx.ellipse(w / 2 + px, -h / 2 + py, w / 2 - ls, h / 2 - ls);
  4101. }
  4102. else if (this._type == 3) {
  4103. this.drawPath(ctx, this._polygonPoints, px, py);
  4104. }
  4105. else if (this._type == 4) {
  4106. if (!this._polygonPoints)
  4107. this._polygonPoints = [];
  4108. var radius = Math.min(w, h) / 2 - ls;
  4109. this._polygonPoints.length = 0;
  4110. var angle = cc.misc.degreesToRadians(this._startAngle);
  4111. var deltaAngle = 2 * Math.PI / this._sides;
  4112. var dist;
  4113. for (var i = 0; i < this._sides; i++) {
  4114. if (this._distances) {
  4115. dist = this._distances[i];
  4116. if (isNaN(dist))
  4117. dist = 1;
  4118. }
  4119. else
  4120. dist = 1;
  4121. var xv = radius + radius * dist * Math.cos(angle);
  4122. var yv = radius + radius * dist * Math.sin(angle);
  4123. this._polygonPoints.push(xv, yv);
  4124. angle += deltaAngle;
  4125. }
  4126. this.drawPath(ctx, this._polygonPoints, px, py);
  4127. }
  4128. if (ls != 0)
  4129. ctx.stroke();
  4130. if (this._fillColor.a != 0)
  4131. ctx.fill();
  4132. this._hasContent = true;
  4133. };
  4134. GGraph.prototype.drawPath = function (ctx, points, px, py) {
  4135. var cnt = points.length;
  4136. ctx.moveTo(points[0] + px, -points[1] + py);
  4137. for (var i = 2; i < cnt; i += 2)
  4138. ctx.lineTo(points[i] + px, -points[i + 1] + py);
  4139. ctx.lineTo(points[0] + px, -points[1] + py);
  4140. };
  4141. GGraph.prototype.handleSizeChanged = function () {
  4142. _super.prototype.handleSizeChanged.call(this);
  4143. if (this._type != 0)
  4144. this.updateGraph();
  4145. };
  4146. GGraph.prototype.handleAnchorChanged = function () {
  4147. _super.prototype.handleAnchorChanged.call(this);
  4148. if (this._type != 0)
  4149. this.updateGraph();
  4150. };
  4151. GGraph.prototype.getProp = function (index) {
  4152. if (index == fgui.ObjectPropID.Color)
  4153. return this.color;
  4154. else
  4155. return _super.prototype.getProp.call(this, index);
  4156. };
  4157. GGraph.prototype.setProp = function (index, value) {
  4158. if (index == fgui.ObjectPropID.Color)
  4159. this.color = value;
  4160. else
  4161. _super.prototype.setProp.call(this, index, value);
  4162. };
  4163. GGraph.prototype._hitTest = function (pt) {
  4164. if (pt.x >= 0 && pt.y >= 0 && pt.x < this._width && pt.y < this._height) {
  4165. if (this._type == 3) {
  4166. var points = this._polygonPoints;
  4167. var len = points.length / 2;
  4168. var i = void 0;
  4169. var j = len - 1;
  4170. var oddNodes = false;
  4171. var w = this._width;
  4172. var h = this._height;
  4173. for (i = 0; i < len; ++i) {
  4174. var ix = points[i * 2];
  4175. var iy = points[i * 2 + 1];
  4176. var jx = points[j * 2];
  4177. var jy = points[j * 2 + 1];
  4178. if ((iy < pt.y && jy >= pt.y || jy < pt.y && iy >= pt.y) && (ix <= pt.x || jx <= pt.x)) {
  4179. if (ix + (pt.y - iy) / (jy - iy) * (jx - ix) < pt.x)
  4180. oddNodes = !oddNodes;
  4181. }
  4182. j = i;
  4183. }
  4184. return oddNodes ? this : null;
  4185. }
  4186. else
  4187. return this;
  4188. }
  4189. else
  4190. return null;
  4191. };
  4192. GGraph.prototype.setup_beforeAdd = function (buffer, beginPos) {
  4193. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  4194. buffer.seek(beginPos, 5);
  4195. this._type = buffer.readByte();
  4196. if (this._type != 0) {
  4197. var i;
  4198. var cnt;
  4199. this._lineSize = buffer.readInt();
  4200. this._lineColor.set(buffer.readColor(true));
  4201. this._fillColor.set(buffer.readColor(true));
  4202. if (buffer.readBool()) {
  4203. this._cornerRadius = new Array(4);
  4204. for (i = 0; i < 4; i++)
  4205. this._cornerRadius[i] = buffer.readFloat();
  4206. }
  4207. if (this._type == 3) {
  4208. cnt = buffer.readShort();
  4209. this._polygonPoints = [];
  4210. this._polygonPoints.length = cnt;
  4211. for (i = 0; i < cnt; i++)
  4212. this._polygonPoints[i] = buffer.readFloat();
  4213. }
  4214. else if (this._type == 4) {
  4215. this._sides = buffer.readShort();
  4216. this._startAngle = buffer.readFloat();
  4217. cnt = buffer.readShort();
  4218. if (cnt > 0) {
  4219. this._distances = [];
  4220. for (i = 0; i < cnt; i++)
  4221. this._distances[i] = buffer.readFloat();
  4222. }
  4223. }
  4224. this.updateGraph();
  4225. }
  4226. };
  4227. return GGraph;
  4228. }(fgui.GObject));
  4229. fgui.GGraph = GGraph;
  4230. })(fgui || (fgui = {}));
  4231. (function (fgui) {
  4232. var GGroup = (function (_super) {
  4233. __extends(GGroup, _super);
  4234. function GGroup() {
  4235. var _this = _super.call(this) || this;
  4236. _this._layout = 0;
  4237. _this._lineGap = 0;
  4238. _this._columnGap = 0;
  4239. _this._mainGridIndex = -1;
  4240. _this._mainGridMinSize = 50;
  4241. _this._mainChildIndex = -1;
  4242. _this._totalSize = 0;
  4243. _this._numChildren = 0;
  4244. _this._updating = 0;
  4245. _this._node.name = "GGroup";
  4246. _this._touchDisabled = true;
  4247. return _this;
  4248. }
  4249. GGroup.prototype.dispose = function () {
  4250. this._boundsChanged = false;
  4251. _super.prototype.dispose.call(this);
  4252. };
  4253. Object.defineProperty(GGroup.prototype, "layout", {
  4254. get: function () {
  4255. return this._layout;
  4256. },
  4257. set: function (value) {
  4258. if (this._layout != value) {
  4259. this._layout = value;
  4260. this.setBoundsChangedFlag();
  4261. }
  4262. },
  4263. enumerable: false,
  4264. configurable: true
  4265. });
  4266. Object.defineProperty(GGroup.prototype, "lineGap", {
  4267. get: function () {
  4268. return this._lineGap;
  4269. },
  4270. set: function (value) {
  4271. if (this._lineGap != value) {
  4272. this._lineGap = value;
  4273. this.setBoundsChangedFlag(true);
  4274. }
  4275. },
  4276. enumerable: false,
  4277. configurable: true
  4278. });
  4279. Object.defineProperty(GGroup.prototype, "columnGap", {
  4280. get: function () {
  4281. return this._columnGap;
  4282. },
  4283. set: function (value) {
  4284. if (this._columnGap != value) {
  4285. this._columnGap = value;
  4286. this.setBoundsChangedFlag(true);
  4287. }
  4288. },
  4289. enumerable: false,
  4290. configurable: true
  4291. });
  4292. Object.defineProperty(GGroup.prototype, "excludeInvisibles", {
  4293. get: function () {
  4294. return this._excludeInvisibles;
  4295. },
  4296. set: function (value) {
  4297. if (this._excludeInvisibles != value) {
  4298. this._excludeInvisibles = value;
  4299. this.setBoundsChangedFlag();
  4300. }
  4301. },
  4302. enumerable: false,
  4303. configurable: true
  4304. });
  4305. Object.defineProperty(GGroup.prototype, "autoSizeDisabled", {
  4306. get: function () {
  4307. return this._autoSizeDisabled;
  4308. },
  4309. set: function (value) {
  4310. this._autoSizeDisabled = value;
  4311. },
  4312. enumerable: false,
  4313. configurable: true
  4314. });
  4315. Object.defineProperty(GGroup.prototype, "mainGridMinSize", {
  4316. get: function () {
  4317. return this._mainGridMinSize;
  4318. },
  4319. set: function (value) {
  4320. if (this._mainGridMinSize != value) {
  4321. this._mainGridMinSize = value;
  4322. this.setBoundsChangedFlag();
  4323. }
  4324. },
  4325. enumerable: false,
  4326. configurable: true
  4327. });
  4328. Object.defineProperty(GGroup.prototype, "mainGridIndex", {
  4329. get: function () {
  4330. return this._mainGridIndex;
  4331. },
  4332. set: function (value) {
  4333. if (this._mainGridIndex != value) {
  4334. this._mainGridIndex = value;
  4335. this.setBoundsChangedFlag();
  4336. }
  4337. },
  4338. enumerable: false,
  4339. configurable: true
  4340. });
  4341. GGroup.prototype.setBoundsChangedFlag = function (positionChangedOnly) {
  4342. if (positionChangedOnly === void 0) { positionChangedOnly = false; }
  4343. if (this._updating == 0 && this._parent) {
  4344. if (!positionChangedOnly)
  4345. this._percentReady = false;
  4346. if (!this._boundsChanged) {
  4347. this._boundsChanged = true;
  4348. if (this._layout != fgui.GroupLayoutType.None)
  4349. this._partner.callLater(this._ensureBoundsCorrect);
  4350. }
  4351. }
  4352. };
  4353. GGroup.prototype._ensureBoundsCorrect = function () {
  4354. var _t = (this.node["$gobj"]);
  4355. _t.ensureBoundsCorrect();
  4356. };
  4357. GGroup.prototype.ensureSizeCorrect = function () {
  4358. if (this._parent == null || !this._boundsChanged || this._layout == 0)
  4359. return;
  4360. this._boundsChanged = false;
  4361. if (this._autoSizeDisabled)
  4362. this.resizeChildren(0, 0);
  4363. else {
  4364. this.handleLayout();
  4365. this.updateBounds();
  4366. }
  4367. };
  4368. GGroup.prototype.ensureBoundsCorrect = function () {
  4369. if (this._parent == null || !this._boundsChanged)
  4370. return;
  4371. this._boundsChanged = false;
  4372. if (this._layout == 0)
  4373. this.updateBounds();
  4374. else {
  4375. if (this._autoSizeDisabled)
  4376. this.resizeChildren(0, 0);
  4377. else {
  4378. this.handleLayout();
  4379. this.updateBounds();
  4380. }
  4381. }
  4382. };
  4383. GGroup.prototype.updateBounds = function () {
  4384. this._partner.unschedule(this._ensureBoundsCorrect);
  4385. var cnt = this._parent.numChildren;
  4386. var i;
  4387. var child;
  4388. var ax = Number.POSITIVE_INFINITY, ay = Number.POSITIVE_INFINITY;
  4389. var ar = Number.NEGATIVE_INFINITY, ab = Number.NEGATIVE_INFINITY;
  4390. var tmp;
  4391. var empty = true;
  4392. for (i = 0; i < cnt; i++) {
  4393. child = this._parent.getChildAt(i);
  4394. if (child.group != this || this._excludeInvisibles && !child.internalVisible3)
  4395. continue;
  4396. tmp = child.xMin;
  4397. if (tmp < ax)
  4398. ax = tmp;
  4399. tmp = child.yMin;
  4400. if (tmp < ay)
  4401. ay = tmp;
  4402. tmp = child.xMin + child.width;
  4403. if (tmp > ar)
  4404. ar = tmp;
  4405. tmp = child.yMin + child.height;
  4406. if (tmp > ab)
  4407. ab = tmp;
  4408. empty = false;
  4409. }
  4410. var w = 0, h = 0;
  4411. if (!empty) {
  4412. this._updating |= 1;
  4413. this.setPosition(ax, ay);
  4414. this._updating &= 2;
  4415. w = ar - ax;
  4416. h = ab - ay;
  4417. }
  4418. if ((this._updating & 2) == 0) {
  4419. this._updating |= 2;
  4420. this.setSize(w, h);
  4421. this._updating &= 1;
  4422. }
  4423. else {
  4424. this._updating &= 1;
  4425. this.resizeChildren(this._width - w, this._height - h);
  4426. }
  4427. };
  4428. GGroup.prototype.handleLayout = function () {
  4429. this._updating |= 1;
  4430. var child;
  4431. var i;
  4432. var cnt;
  4433. if (this._layout == fgui.GroupLayoutType.Horizontal) {
  4434. var curX = this.x;
  4435. cnt = this._parent.numChildren;
  4436. for (i = 0; i < cnt; i++) {
  4437. child = this._parent.getChildAt(i);
  4438. if (child.group != this)
  4439. continue;
  4440. if (this._excludeInvisibles && !child.internalVisible3)
  4441. continue;
  4442. child.xMin = curX;
  4443. if (child.width != 0)
  4444. curX += child.width + this._columnGap;
  4445. }
  4446. }
  4447. else if (this._layout == fgui.GroupLayoutType.Vertical) {
  4448. var curY = this.y;
  4449. cnt = this._parent.numChildren;
  4450. for (i = 0; i < cnt; i++) {
  4451. child = this._parent.getChildAt(i);
  4452. if (child.group != this)
  4453. continue;
  4454. if (this._excludeInvisibles && !child.internalVisible3)
  4455. continue;
  4456. child.yMin = curY;
  4457. if (child.height != 0)
  4458. curY += child.height + this._lineGap;
  4459. }
  4460. }
  4461. this._updating &= 2;
  4462. };
  4463. GGroup.prototype.moveChildren = function (dx, dy) {
  4464. if ((this._updating & 1) != 0 || this._parent == null)
  4465. return;
  4466. this._updating |= 1;
  4467. var cnt = this._parent.numChildren;
  4468. var i;
  4469. var child;
  4470. for (i = 0; i < cnt; i++) {
  4471. child = this._parent.getChildAt(i);
  4472. if (child.group == this) {
  4473. child.setPosition(child.x + dx, child.y + dy);
  4474. }
  4475. }
  4476. this._updating &= 2;
  4477. };
  4478. GGroup.prototype.resizeChildren = function (dw, dh) {
  4479. if (this._layout == fgui.GroupLayoutType.None || (this._updating & 2) != 0 || this._parent == null)
  4480. return;
  4481. this._updating |= 2;
  4482. if (this._boundsChanged) {
  4483. this._boundsChanged = false;
  4484. if (!this._autoSizeDisabled) {
  4485. this.updateBounds();
  4486. return;
  4487. }
  4488. }
  4489. var cnt = this._parent.numChildren;
  4490. var i;
  4491. var child;
  4492. if (!this._percentReady) {
  4493. this._percentReady = true;
  4494. this._numChildren = 0;
  4495. this._totalSize = 0;
  4496. this._mainChildIndex = -1;
  4497. var j = 0;
  4498. for (i = 0; i < cnt; i++) {
  4499. child = this._parent.getChildAt(i);
  4500. if (child.group != this)
  4501. continue;
  4502. if (!this._excludeInvisibles || child.internalVisible3) {
  4503. if (j == this._mainGridIndex)
  4504. this._mainChildIndex = i;
  4505. this._numChildren++;
  4506. if (this._layout == 1)
  4507. this._totalSize += child.width;
  4508. else
  4509. this._totalSize += child.height;
  4510. }
  4511. j++;
  4512. }
  4513. if (this._mainChildIndex != -1) {
  4514. if (this._layout == 1) {
  4515. child = this._parent.getChildAt(this._mainChildIndex);
  4516. this._totalSize += this._mainGridMinSize - child.width;
  4517. child._sizePercentInGroup = this._mainGridMinSize / this._totalSize;
  4518. }
  4519. else {
  4520. child = this._parent.getChildAt(this._mainChildIndex);
  4521. this._totalSize += this._mainGridMinSize - child.height;
  4522. child._sizePercentInGroup = this._mainGridMinSize / this._totalSize;
  4523. }
  4524. }
  4525. for (i = 0; i < cnt; i++) {
  4526. child = this._parent.getChildAt(i);
  4527. if (child.group != this)
  4528. continue;
  4529. if (i == this._mainChildIndex)
  4530. continue;
  4531. if (this._totalSize > 0)
  4532. child._sizePercentInGroup = (this._layout == 1 ? child.width : child.height) / this._totalSize;
  4533. else
  4534. child._sizePercentInGroup = 0;
  4535. }
  4536. }
  4537. var remainSize = 0;
  4538. var remainPercent = 1;
  4539. var priorHandled = false;
  4540. if (this._layout == 1) {
  4541. remainSize = this.width - (this._numChildren - 1) * this._columnGap;
  4542. if (this._mainChildIndex != -1 && remainSize >= this._totalSize) {
  4543. child = this._parent.getChildAt(this._mainChildIndex);
  4544. child.setSize(remainSize - (this._totalSize - this._mainGridMinSize), child._rawHeight + dh, true);
  4545. remainSize -= child.width;
  4546. remainPercent -= child._sizePercentInGroup;
  4547. priorHandled = true;
  4548. }
  4549. var curX = this.x;
  4550. for (i = 0; i < cnt; i++) {
  4551. child = this._parent.getChildAt(i);
  4552. if (child.group != this)
  4553. continue;
  4554. if (this._excludeInvisibles && !child.internalVisible3) {
  4555. child.setSize(child._rawWidth, child._rawHeight + dh, true);
  4556. continue;
  4557. }
  4558. if (!priorHandled || i != this._mainChildIndex) {
  4559. child.setSize(Math.round(child._sizePercentInGroup / remainPercent * remainSize), child._rawHeight + dh, true);
  4560. remainPercent -= child._sizePercentInGroup;
  4561. remainSize -= child.width;
  4562. }
  4563. child.xMin = curX;
  4564. if (child.width != 0)
  4565. curX += child.width + this._columnGap;
  4566. }
  4567. }
  4568. else {
  4569. remainSize = this.height - (this._numChildren - 1) * this._lineGap;
  4570. if (this._mainChildIndex != -1 && remainSize >= this._totalSize) {
  4571. child = this._parent.getChildAt(this._mainChildIndex);
  4572. child.setSize(child._rawWidth + dw, remainSize - (this._totalSize - this._mainGridMinSize), true);
  4573. remainSize -= child.height;
  4574. remainPercent -= child._sizePercentInGroup;
  4575. priorHandled = true;
  4576. }
  4577. var curY = this.y;
  4578. for (i = 0; i < cnt; i++) {
  4579. child = this._parent.getChildAt(i);
  4580. if (child.group != this)
  4581. continue;
  4582. if (this._excludeInvisibles && !child.internalVisible3) {
  4583. child.setSize(child._rawWidth + dw, child._rawHeight, true);
  4584. continue;
  4585. }
  4586. if (!priorHandled || i != this._mainChildIndex) {
  4587. child.setSize(child._rawWidth + dw, Math.round(child._sizePercentInGroup / remainPercent * remainSize), true);
  4588. remainPercent -= child._sizePercentInGroup;
  4589. remainSize -= child.height;
  4590. }
  4591. child.yMin = curY;
  4592. if (child.height != 0)
  4593. curY += child.height + this._lineGap;
  4594. }
  4595. }
  4596. this._updating &= 1;
  4597. };
  4598. GGroup.prototype.handleAlphaChanged = function () {
  4599. if (this._underConstruct)
  4600. return;
  4601. var cnt = this._parent.numChildren;
  4602. for (var i = 0; i < cnt; i++) {
  4603. var child = this._parent.getChildAt(i);
  4604. if (child.group == this)
  4605. child.alpha = this.alpha;
  4606. }
  4607. };
  4608. GGroup.prototype.handleVisibleChanged = function () {
  4609. if (!this._parent)
  4610. return;
  4611. var cnt = this._parent.numChildren;
  4612. for (var i = 0; i < cnt; i++) {
  4613. var child = this._parent.getChildAt(i);
  4614. if (child.group == this)
  4615. child.handleVisibleChanged();
  4616. }
  4617. };
  4618. GGroup.prototype.setup_beforeAdd = function (buffer, beginPos) {
  4619. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  4620. buffer.seek(beginPos, 5);
  4621. this._layout = buffer.readByte();
  4622. this._lineGap = buffer.readInt();
  4623. this._columnGap = buffer.readInt();
  4624. if (buffer.version >= 2) {
  4625. this._excludeInvisibles = buffer.readBool();
  4626. this._autoSizeDisabled = buffer.readBool();
  4627. this._mainGridIndex = buffer.readShort();
  4628. }
  4629. };
  4630. GGroup.prototype.setup_afterAdd = function (buffer, beginPos) {
  4631. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  4632. if (!this.visible)
  4633. this.handleVisibleChanged();
  4634. };
  4635. return GGroup;
  4636. }(fgui.GObject));
  4637. fgui.GGroup = GGroup;
  4638. })(fgui || (fgui = {}));
  4639. (function (fgui) {
  4640. var GImage = (function (_super) {
  4641. __extends(GImage, _super);
  4642. function GImage() {
  4643. var _this = _super.call(this) || this;
  4644. _this._node.name = "GImage";
  4645. _this._touchDisabled = true;
  4646. _this._content = _this._node.addComponent(fgui.Image);
  4647. _this._content.sizeMode = cc.Sprite.SizeMode.CUSTOM;
  4648. _this._content.trim = false;
  4649. return _this;
  4650. }
  4651. Object.defineProperty(GImage.prototype, "color", {
  4652. get: function () {
  4653. return this._node.color;
  4654. },
  4655. set: function (value) {
  4656. this._node.color = value;
  4657. this.updateGear(4);
  4658. },
  4659. enumerable: false,
  4660. configurable: true
  4661. });
  4662. Object.defineProperty(GImage.prototype, "flip", {
  4663. get: function () {
  4664. return this._content.flip;
  4665. },
  4666. set: function (value) {
  4667. this._content.flip = value;
  4668. },
  4669. enumerable: false,
  4670. configurable: true
  4671. });
  4672. Object.defineProperty(GImage.prototype, "fillMethod", {
  4673. get: function () {
  4674. return this._content.fillMethod;
  4675. },
  4676. set: function (value) {
  4677. this._content.fillMethod = value;
  4678. },
  4679. enumerable: false,
  4680. configurable: true
  4681. });
  4682. Object.defineProperty(GImage.prototype, "fillOrigin", {
  4683. get: function () {
  4684. return this._content.fillOrigin;
  4685. },
  4686. set: function (value) {
  4687. this._content.fillOrigin = value;
  4688. },
  4689. enumerable: false,
  4690. configurable: true
  4691. });
  4692. Object.defineProperty(GImage.prototype, "fillClockwise", {
  4693. get: function () {
  4694. return this._content.fillClockwise;
  4695. },
  4696. set: function (value) {
  4697. this._content.fillClockwise = value;
  4698. },
  4699. enumerable: false,
  4700. configurable: true
  4701. });
  4702. Object.defineProperty(GImage.prototype, "fillAmount", {
  4703. get: function () {
  4704. return this._content.fillAmount;
  4705. },
  4706. set: function (value) {
  4707. this._content.fillAmount = value;
  4708. },
  4709. enumerable: false,
  4710. configurable: true
  4711. });
  4712. GImage.prototype.constructFromResource = function () {
  4713. var contentItem = this.packageItem.getBranch();
  4714. this.sourceWidth = contentItem.width;
  4715. this.sourceHeight = contentItem.height;
  4716. this.initWidth = this.sourceWidth;
  4717. this.initHeight = this.sourceHeight;
  4718. this.setSize(this.sourceWidth, this.sourceHeight);
  4719. contentItem = contentItem.getHighResolution();
  4720. contentItem.load();
  4721. if (contentItem.scale9Grid)
  4722. this._content.type = cc.Sprite.Type.SLICED;
  4723. else if (contentItem.scaleByTile)
  4724. this._content.type = cc.Sprite.Type.TILED;
  4725. this._content.spriteFrame = contentItem.asset;
  4726. };
  4727. GImage.prototype.handleGrayedChanged = function () {
  4728. this._content.grayed = this._grayed;
  4729. };
  4730. GImage.prototype.getProp = function (index) {
  4731. if (index == fgui.ObjectPropID.Color)
  4732. return this.color;
  4733. else
  4734. return _super.prototype.getProp.call(this, index);
  4735. };
  4736. GImage.prototype.setProp = function (index, value) {
  4737. if (index == fgui.ObjectPropID.Color)
  4738. this.color = value;
  4739. else
  4740. _super.prototype.setProp.call(this, index, value);
  4741. };
  4742. GImage.prototype.setup_beforeAdd = function (buffer, beginPos) {
  4743. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  4744. buffer.seek(beginPos, 5);
  4745. if (buffer.readBool())
  4746. this.color = buffer.readColor();
  4747. this._content.flip = buffer.readByte();
  4748. this._content.fillMethod = buffer.readByte();
  4749. if (this._content.fillMethod != 0) {
  4750. this._content.fillOrigin = buffer.readByte();
  4751. this._content.fillClockwise = buffer.readBool();
  4752. this._content.fillAmount = buffer.readFloat();
  4753. }
  4754. };
  4755. return GImage;
  4756. }(fgui.GObject));
  4757. fgui.GImage = GImage;
  4758. })(fgui || (fgui = {}));
  4759. (function (fgui) {
  4760. var GLabel = (function (_super) {
  4761. __extends(GLabel, _super);
  4762. function GLabel() {
  4763. var _this = _super.call(this) || this;
  4764. _this._node.name = "GLabel";
  4765. return _this;
  4766. }
  4767. Object.defineProperty(GLabel.prototype, "icon", {
  4768. get: function () {
  4769. if (this._iconObject)
  4770. return this._iconObject.icon;
  4771. },
  4772. set: function (value) {
  4773. if (this._iconObject)
  4774. this._iconObject.icon = value;
  4775. this.updateGear(7);
  4776. },
  4777. enumerable: false,
  4778. configurable: true
  4779. });
  4780. Object.defineProperty(GLabel.prototype, "title", {
  4781. get: function () {
  4782. if (this._titleObject)
  4783. return this._titleObject.text;
  4784. else
  4785. return null;
  4786. },
  4787. set: function (value) {
  4788. if (this._titleObject)
  4789. this._titleObject.text = value;
  4790. this.updateGear(6);
  4791. },
  4792. enumerable: false,
  4793. configurable: true
  4794. });
  4795. Object.defineProperty(GLabel.prototype, "text", {
  4796. get: function () {
  4797. return this.title;
  4798. },
  4799. set: function (value) {
  4800. this.title = value;
  4801. },
  4802. enumerable: false,
  4803. configurable: true
  4804. });
  4805. Object.defineProperty(GLabel.prototype, "titleColor", {
  4806. get: function () {
  4807. var tf = this.getTextField();
  4808. if (tf)
  4809. return tf.color;
  4810. else
  4811. return cc.Color.WHITE;
  4812. },
  4813. set: function (value) {
  4814. var tf = this.getTextField();
  4815. if (tf)
  4816. tf.color = value;
  4817. this.updateGear(4);
  4818. },
  4819. enumerable: false,
  4820. configurable: true
  4821. });
  4822. Object.defineProperty(GLabel.prototype, "titleFontSize", {
  4823. get: function () {
  4824. var tf = this.getTextField();
  4825. if (tf)
  4826. return tf.fontSize;
  4827. else
  4828. return 0;
  4829. },
  4830. set: function (value) {
  4831. var tf = this.getTextField();
  4832. if (tf)
  4833. tf.fontSize = value;
  4834. },
  4835. enumerable: false,
  4836. configurable: true
  4837. });
  4838. Object.defineProperty(GLabel.prototype, "editable", {
  4839. get: function () {
  4840. if (this._titleObject && (this._titleObject instanceof fgui.GTextInput))
  4841. return this._titleObject.editable;
  4842. else
  4843. return false;
  4844. },
  4845. set: function (val) {
  4846. if (this._titleObject && (this._titleObject instanceof fgui.GTextInput))
  4847. this._titleObject.editable = val;
  4848. },
  4849. enumerable: false,
  4850. configurable: true
  4851. });
  4852. GLabel.prototype.getTextField = function () {
  4853. if (this._titleObject instanceof fgui.GTextField)
  4854. return this._titleObject;
  4855. else if ((this._titleObject instanceof GLabel) || (this._titleObject instanceof fgui.GButton))
  4856. return this._titleObject.getTextField();
  4857. else
  4858. return null;
  4859. };
  4860. GLabel.prototype.getProp = function (index) {
  4861. switch (index) {
  4862. case fgui.ObjectPropID.Color:
  4863. return this.titleColor;
  4864. case fgui.ObjectPropID.OutlineColor:
  4865. {
  4866. var tf = this.getTextField();
  4867. if (tf)
  4868. return tf.strokeColor;
  4869. else
  4870. return 0;
  4871. }
  4872. case fgui.ObjectPropID.FontSize:
  4873. return this.titleFontSize;
  4874. default:
  4875. return _super.prototype.getProp.call(this, index);
  4876. }
  4877. };
  4878. GLabel.prototype.setProp = function (index, value) {
  4879. switch (index) {
  4880. case fgui.ObjectPropID.Color:
  4881. this.titleColor = value;
  4882. break;
  4883. case fgui.ObjectPropID.OutlineColor:
  4884. {
  4885. var tf = this.getTextField();
  4886. if (tf)
  4887. tf.strokeColor = value;
  4888. }
  4889. break;
  4890. case fgui.ObjectPropID.FontSize:
  4891. this.titleFontSize = value;
  4892. break;
  4893. default:
  4894. _super.prototype.setProp.call(this, index, value);
  4895. break;
  4896. }
  4897. };
  4898. GLabel.prototype.constructExtension = function (buffer) {
  4899. this._titleObject = this.getChild("title");
  4900. this._iconObject = this.getChild("icon");
  4901. };
  4902. GLabel.prototype.setup_afterAdd = function (buffer, beginPos) {
  4903. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  4904. if (!buffer.seek(beginPos, 6))
  4905. return;
  4906. if (buffer.readByte() != this.packageItem.objectType)
  4907. return;
  4908. var str;
  4909. str = buffer.readS();
  4910. if (str != null)
  4911. this.title = str;
  4912. str = buffer.readS();
  4913. if (str != null)
  4914. this.icon = str;
  4915. if (buffer.readBool())
  4916. this.titleColor = buffer.readColor();
  4917. var iv = buffer.readInt();
  4918. if (iv != 0)
  4919. this.titleFontSize = iv;
  4920. if (buffer.readBool()) {
  4921. var input = this.getTextField();
  4922. if (input instanceof fgui.GTextInput) {
  4923. str = buffer.readS();
  4924. if (str != null)
  4925. input.promptText = str;
  4926. str = buffer.readS();
  4927. if (str != null)
  4928. input.restrict = str;
  4929. iv = buffer.readInt();
  4930. if (iv != 0)
  4931. input.maxLength = iv;
  4932. iv = buffer.readInt();
  4933. if (iv != 0) {
  4934. }
  4935. if (buffer.readBool())
  4936. input.password = true;
  4937. }
  4938. else
  4939. buffer.skip(13);
  4940. }
  4941. };
  4942. return GLabel;
  4943. }(fgui.GComponent));
  4944. fgui.GLabel = GLabel;
  4945. })(fgui || (fgui = {}));
  4946. (function (fgui) {
  4947. var GList = (function (_super) {
  4948. __extends(GList, _super);
  4949. function GList() {
  4950. var _this = _super.call(this) || this;
  4951. _this.scrollItemToViewOnClick = true;
  4952. _this.foldInvisibleItems = false;
  4953. _this._lineCount = 0;
  4954. _this._columnCount = 0;
  4955. _this._lineGap = 0;
  4956. _this._columnGap = 0;
  4957. _this._lastSelectedIndex = 0;
  4958. _this._numItems = 0;
  4959. _this._realNumItems = 0;
  4960. _this._firstIndex = 0;
  4961. _this._curLineItemCount = 0;
  4962. _this._curLineItemCount2 = 0;
  4963. _this._virtualListChanged = 0;
  4964. _this.itemInfoVer = 0;
  4965. _this._node.name = "GList";
  4966. _this._trackBounds = true;
  4967. _this._pool = new fgui.GObjectPool();
  4968. _this._layout = fgui.ListLayoutType.SingleColumn;
  4969. _this._autoResizeItem = true;
  4970. _this._lastSelectedIndex = -1;
  4971. _this._selectionMode = fgui.ListSelectionMode.Single;
  4972. _this.opaque = true;
  4973. _this._align = fgui.AlignType.Left;
  4974. _this._verticalAlign = fgui.VertAlignType.Top;
  4975. return _this;
  4976. }
  4977. GList.prototype.dispose = function () {
  4978. this._partner.unschedule(this._refreshVirtualList);
  4979. this._pool.clear();
  4980. _super.prototype.dispose.call(this);
  4981. };
  4982. Object.defineProperty(GList.prototype, "layout", {
  4983. get: function () {
  4984. return this._layout;
  4985. },
  4986. set: function (value) {
  4987. if (this._layout != value) {
  4988. this._layout = value;
  4989. this.setBoundsChangedFlag();
  4990. if (this._virtual)
  4991. this.setVirtualListChangedFlag(true);
  4992. }
  4993. },
  4994. enumerable: false,
  4995. configurable: true
  4996. });
  4997. Object.defineProperty(GList.prototype, "lineCount", {
  4998. get: function () {
  4999. return this._lineCount;
  5000. },
  5001. set: function (value) {
  5002. if (this._lineCount != value) {
  5003. this._lineCount = value;
  5004. this.setBoundsChangedFlag();
  5005. if (this._virtual)
  5006. this.setVirtualListChangedFlag(true);
  5007. }
  5008. },
  5009. enumerable: false,
  5010. configurable: true
  5011. });
  5012. Object.defineProperty(GList.prototype, "columnCount", {
  5013. get: function () {
  5014. return this._columnCount;
  5015. },
  5016. set: function (value) {
  5017. if (this._columnCount != value) {
  5018. this._columnCount = value;
  5019. this.setBoundsChangedFlag();
  5020. if (this._virtual)
  5021. this.setVirtualListChangedFlag(true);
  5022. }
  5023. },
  5024. enumerable: false,
  5025. configurable: true
  5026. });
  5027. Object.defineProperty(GList.prototype, "lineGap", {
  5028. get: function () {
  5029. return this._lineGap;
  5030. },
  5031. set: function (value) {
  5032. if (this._lineGap != value) {
  5033. this._lineGap = value;
  5034. this.setBoundsChangedFlag();
  5035. if (this._virtual)
  5036. this.setVirtualListChangedFlag(true);
  5037. }
  5038. },
  5039. enumerable: false,
  5040. configurable: true
  5041. });
  5042. Object.defineProperty(GList.prototype, "columnGap", {
  5043. get: function () {
  5044. return this._columnGap;
  5045. },
  5046. set: function (value) {
  5047. if (this._columnGap != value) {
  5048. this._columnGap = value;
  5049. this.setBoundsChangedFlag();
  5050. if (this._virtual)
  5051. this.setVirtualListChangedFlag(true);
  5052. }
  5053. },
  5054. enumerable: false,
  5055. configurable: true
  5056. });
  5057. Object.defineProperty(GList.prototype, "align", {
  5058. get: function () {
  5059. return this._align;
  5060. },
  5061. set: function (value) {
  5062. if (this._align != value) {
  5063. this._align = value;
  5064. this.setBoundsChangedFlag();
  5065. if (this._virtual)
  5066. this.setVirtualListChangedFlag(true);
  5067. }
  5068. },
  5069. enumerable: false,
  5070. configurable: true
  5071. });
  5072. Object.defineProperty(GList.prototype, "verticalAlign", {
  5073. get: function () {
  5074. return this._verticalAlign;
  5075. },
  5076. set: function (value) {
  5077. if (this._verticalAlign != value) {
  5078. this._verticalAlign = value;
  5079. this.setBoundsChangedFlag();
  5080. if (this._virtual)
  5081. this.setVirtualListChangedFlag(true);
  5082. }
  5083. },
  5084. enumerable: false,
  5085. configurable: true
  5086. });
  5087. Object.defineProperty(GList.prototype, "virtualItemSize", {
  5088. get: function () {
  5089. return this._itemSize;
  5090. },
  5091. set: function (value) {
  5092. if (this._virtual) {
  5093. if (this._itemSize == null)
  5094. this._itemSize = new cc.Size(0, 0);
  5095. this._itemSize.width = value.width;
  5096. this._itemSize.height = value.height;
  5097. this.setVirtualListChangedFlag(true);
  5098. }
  5099. },
  5100. enumerable: false,
  5101. configurable: true
  5102. });
  5103. Object.defineProperty(GList.prototype, "defaultItem", {
  5104. get: function () {
  5105. return this._defaultItem;
  5106. },
  5107. set: function (val) {
  5108. this._defaultItem = fgui.UIPackage.normalizeURL(val);
  5109. },
  5110. enumerable: false,
  5111. configurable: true
  5112. });
  5113. Object.defineProperty(GList.prototype, "autoResizeItem", {
  5114. get: function () {
  5115. return this._autoResizeItem;
  5116. },
  5117. set: function (value) {
  5118. if (this._autoResizeItem != value) {
  5119. this._autoResizeItem = value;
  5120. this.setBoundsChangedFlag();
  5121. if (this._virtual)
  5122. this.setVirtualListChangedFlag(true);
  5123. }
  5124. },
  5125. enumerable: false,
  5126. configurable: true
  5127. });
  5128. Object.defineProperty(GList.prototype, "selectionMode", {
  5129. get: function () {
  5130. return this._selectionMode;
  5131. },
  5132. set: function (value) {
  5133. this._selectionMode = value;
  5134. },
  5135. enumerable: false,
  5136. configurable: true
  5137. });
  5138. Object.defineProperty(GList.prototype, "selectionController", {
  5139. get: function () {
  5140. return this._selectionController;
  5141. },
  5142. set: function (value) {
  5143. this._selectionController = value;
  5144. },
  5145. enumerable: false,
  5146. configurable: true
  5147. });
  5148. Object.defineProperty(GList.prototype, "itemPool", {
  5149. get: function () {
  5150. return this._pool;
  5151. },
  5152. enumerable: false,
  5153. configurable: true
  5154. });
  5155. GList.prototype.getFromPool = function (url) {
  5156. if (!url)
  5157. url = this._defaultItem;
  5158. var obj = this._pool.getObject(url);
  5159. if (obj)
  5160. obj.visible = true;
  5161. return obj;
  5162. };
  5163. GList.prototype.returnToPool = function (obj) {
  5164. this._pool.returnObject(obj);
  5165. };
  5166. GList.prototype.addChildAt = function (child, index) {
  5167. _super.prototype.addChildAt.call(this, child, index);
  5168. if (child instanceof fgui.GButton) {
  5169. child.selected = false;
  5170. child.changeStateOnClick = false;
  5171. }
  5172. child.on(fgui.Event.CLICK, this.onClickItem, this);
  5173. return child;
  5174. };
  5175. GList.prototype.addItem = function (url) {
  5176. if (!url)
  5177. url = this._defaultItem;
  5178. return this.addChild(fgui.UIPackage.createObjectFromURL(url));
  5179. };
  5180. GList.prototype.addItemFromPool = function (url) {
  5181. return this.addChild(this.getFromPool(url));
  5182. };
  5183. GList.prototype.removeChildAt = function (index, dispose) {
  5184. var child = _super.prototype.removeChildAt.call(this, index, dispose);
  5185. if (!dispose)
  5186. child.off(fgui.Event.CLICK, this.onClickItem, this);
  5187. return child;
  5188. };
  5189. GList.prototype.removeChildToPoolAt = function (index) {
  5190. var child = _super.prototype.removeChildAt.call(this, index);
  5191. this.returnToPool(child);
  5192. };
  5193. GList.prototype.removeChildToPool = function (child) {
  5194. _super.prototype.removeChild.call(this, child);
  5195. this.returnToPool(child);
  5196. };
  5197. GList.prototype.removeChildrenToPool = function (beginIndex, endIndex) {
  5198. if (beginIndex == undefined)
  5199. beginIndex = 0;
  5200. if (endIndex == undefined)
  5201. endIndex = -1;
  5202. if (endIndex < 0 || endIndex >= this._children.length)
  5203. endIndex = this._children.length - 1;
  5204. for (var i = beginIndex; i <= endIndex; ++i)
  5205. this.removeChildToPoolAt(beginIndex);
  5206. };
  5207. Object.defineProperty(GList.prototype, "selectedIndex", {
  5208. get: function () {
  5209. var i;
  5210. if (this._virtual) {
  5211. for (i = 0; i < this._realNumItems; i++) {
  5212. var ii = this._virtualItems[i];
  5213. if ((ii.obj instanceof fgui.GButton) && ii.obj.selected || !ii.obj && ii.selected) {
  5214. if (this._loop)
  5215. return i % this._numItems;
  5216. else
  5217. return i;
  5218. }
  5219. }
  5220. }
  5221. else {
  5222. var cnt = this._children.length;
  5223. for (i = 0; i < cnt; i++) {
  5224. var obj = this._children[i];
  5225. if ((obj instanceof fgui.GButton) && obj.selected)
  5226. return i;
  5227. }
  5228. }
  5229. return -1;
  5230. },
  5231. set: function (value) {
  5232. if (value >= 0 && value < this.numItems) {
  5233. if (this._selectionMode != fgui.ListSelectionMode.Single)
  5234. this.clearSelection();
  5235. this.addSelection(value);
  5236. }
  5237. else
  5238. this.clearSelection();
  5239. },
  5240. enumerable: false,
  5241. configurable: true
  5242. });
  5243. GList.prototype.getSelection = function (result) {
  5244. if (!result)
  5245. result = new Array();
  5246. var i;
  5247. if (this._virtual) {
  5248. for (i = 0; i < this._realNumItems; i++) {
  5249. var ii = this._virtualItems[i];
  5250. if ((ii.obj instanceof fgui.GButton) && ii.obj.selected || !ii.obj && ii.selected) {
  5251. var j = i;
  5252. if (this._loop) {
  5253. j = i % this._numItems;
  5254. if (result.indexOf(j) != -1)
  5255. continue;
  5256. }
  5257. result.push(j);
  5258. }
  5259. }
  5260. }
  5261. else {
  5262. var cnt = this._children.length;
  5263. for (i = 0; i < cnt; i++) {
  5264. var obj = this._children[i];
  5265. if ((obj instanceof fgui.GButton) && obj.selected)
  5266. result.push(i);
  5267. }
  5268. }
  5269. return result;
  5270. };
  5271. GList.prototype.addSelection = function (index, scrollItToView) {
  5272. if (this._selectionMode == fgui.ListSelectionMode.None)
  5273. return;
  5274. this.checkVirtualList();
  5275. if (this._selectionMode == fgui.ListSelectionMode.Single)
  5276. this.clearSelection();
  5277. if (scrollItToView)
  5278. this.scrollToView(index);
  5279. this._lastSelectedIndex = index;
  5280. var obj;
  5281. if (this._virtual) {
  5282. var ii = this._virtualItems[index];
  5283. if (ii.obj)
  5284. obj = ii.obj;
  5285. ii.selected = true;
  5286. }
  5287. else
  5288. obj = this.getChildAt(index);
  5289. if ((obj instanceof fgui.GButton) && !obj.selected) {
  5290. obj.selected = true;
  5291. this.updateSelectionController(index);
  5292. }
  5293. };
  5294. GList.prototype.removeSelection = function (index) {
  5295. if (this._selectionMode == fgui.ListSelectionMode.None)
  5296. return;
  5297. var obj;
  5298. if (this._virtual) {
  5299. var ii = this._virtualItems[index];
  5300. if (ii.obj)
  5301. obj = ii.obj;
  5302. ii.selected = false;
  5303. }
  5304. else
  5305. obj = this.getChildAt(index);
  5306. if (obj instanceof fgui.GButton)
  5307. obj.selected = false;
  5308. };
  5309. GList.prototype.clearSelection = function () {
  5310. var i;
  5311. if (this._virtual) {
  5312. for (i = 0; i < this._realNumItems; i++) {
  5313. var ii = this._virtualItems[i];
  5314. if (ii.obj instanceof fgui.GButton)
  5315. ii.obj.selected = false;
  5316. ii.selected = false;
  5317. }
  5318. }
  5319. else {
  5320. var cnt = this._children.length;
  5321. for (i = 0; i < cnt; i++) {
  5322. var obj = this._children[i];
  5323. if (obj instanceof fgui.GButton)
  5324. obj.selected = false;
  5325. }
  5326. }
  5327. };
  5328. GList.prototype.clearSelectionExcept = function (g) {
  5329. var i;
  5330. if (this._virtual) {
  5331. for (i = 0; i < this._realNumItems; i++) {
  5332. var ii = this._virtualItems[i];
  5333. if (ii.obj != g) {
  5334. if (ii.obj instanceof fgui.GButton)
  5335. ii.obj.selected = false;
  5336. ii.selected = false;
  5337. }
  5338. }
  5339. }
  5340. else {
  5341. var cnt = this._children.length;
  5342. for (i = 0; i < cnt; i++) {
  5343. var obj = this._children[i];
  5344. if ((obj instanceof fgui.GButton) && obj != g)
  5345. obj.selected = false;
  5346. }
  5347. }
  5348. };
  5349. GList.prototype.selectAll = function () {
  5350. this.checkVirtualList();
  5351. var last = -1;
  5352. var i;
  5353. if (this._virtual) {
  5354. for (i = 0; i < this._realNumItems; i++) {
  5355. var ii = this._virtualItems[i];
  5356. if ((ii.obj instanceof fgui.GButton) && !ii.obj.selected) {
  5357. ii.obj.selected = true;
  5358. last = i;
  5359. }
  5360. ii.selected = true;
  5361. }
  5362. }
  5363. else {
  5364. var cnt = this._children.length;
  5365. for (i = 0; i < cnt; i++) {
  5366. var obj = this._children[i];
  5367. if ((obj instanceof fgui.GButton) && !obj.selected) {
  5368. obj.selected = true;
  5369. last = i;
  5370. }
  5371. }
  5372. }
  5373. if (last != -1)
  5374. this.updateSelectionController(last);
  5375. };
  5376. GList.prototype.selectNone = function () {
  5377. this.clearSelection();
  5378. };
  5379. GList.prototype.selectReverse = function () {
  5380. this.checkVirtualList();
  5381. var last = -1;
  5382. var i;
  5383. if (this._virtual) {
  5384. for (i = 0; i < this._realNumItems; i++) {
  5385. var ii = this._virtualItems[i];
  5386. if (ii.obj instanceof fgui.GButton) {
  5387. ii.obj.selected = !ii.obj.selected;
  5388. if (ii.obj.selected)
  5389. last = i;
  5390. }
  5391. ii.selected = !ii.selected;
  5392. }
  5393. }
  5394. else {
  5395. var cnt = this._children.length;
  5396. for (i = 0; i < cnt; i++) {
  5397. var obj = this._children[i];
  5398. if (obj instanceof fgui.GButton) {
  5399. obj.selected = !obj.selected;
  5400. if (obj.selected)
  5401. last = i;
  5402. }
  5403. }
  5404. }
  5405. if (last != -1)
  5406. this.updateSelectionController(last);
  5407. };
  5408. GList.prototype.handleArrowKey = function (dir) {
  5409. var index = this.selectedIndex;
  5410. if (index == -1)
  5411. return;
  5412. switch (dir) {
  5413. case 1:
  5414. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowVertical) {
  5415. index--;
  5416. if (index >= 0) {
  5417. this.clearSelection();
  5418. this.addSelection(index, true);
  5419. }
  5420. }
  5421. else if (this._layout == fgui.ListLayoutType.FlowHorizontal || this._layout == fgui.ListLayoutType.Pagination) {
  5422. var current = this._children[index];
  5423. var k = 0;
  5424. for (var i = index - 1; i >= 0; i--) {
  5425. var obj = this._children[i];
  5426. if (obj.y != current.y) {
  5427. current = obj;
  5428. break;
  5429. }
  5430. k++;
  5431. }
  5432. for (; i >= 0; i--) {
  5433. obj = this._children[i];
  5434. if (obj.y != current.y) {
  5435. this.clearSelection();
  5436. this.addSelection(i + k + 1, true);
  5437. break;
  5438. }
  5439. }
  5440. }
  5441. break;
  5442. case 3:
  5443. if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowHorizontal || this._layout == fgui.ListLayoutType.Pagination) {
  5444. index++;
  5445. if (index < this._children.length) {
  5446. this.clearSelection();
  5447. this.addSelection(index, true);
  5448. }
  5449. }
  5450. else if (this._layout == fgui.ListLayoutType.FlowVertical) {
  5451. current = this._children[index];
  5452. k = 0;
  5453. var cnt = this._children.length;
  5454. for (i = index + 1; i < cnt; i++) {
  5455. obj = this._children[i];
  5456. if (obj.x != current.x) {
  5457. current = obj;
  5458. break;
  5459. }
  5460. k++;
  5461. }
  5462. for (; i < cnt; i++) {
  5463. obj = this._children[i];
  5464. if (obj.x != current.x) {
  5465. this.clearSelection();
  5466. this.addSelection(i - k - 1, true);
  5467. break;
  5468. }
  5469. }
  5470. }
  5471. break;
  5472. case 5:
  5473. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowVertical) {
  5474. index++;
  5475. if (index < this._children.length) {
  5476. this.clearSelection();
  5477. this.addSelection(index, true);
  5478. }
  5479. }
  5480. else if (this._layout == fgui.ListLayoutType.FlowHorizontal || this._layout == fgui.ListLayoutType.Pagination) {
  5481. current = this._children[index];
  5482. k = 0;
  5483. cnt = this._children.length;
  5484. for (i = index + 1; i < cnt; i++) {
  5485. obj = this._children[i];
  5486. if (obj.y != current.y) {
  5487. current = obj;
  5488. break;
  5489. }
  5490. k++;
  5491. }
  5492. for (; i < cnt; i++) {
  5493. obj = this._children[i];
  5494. if (obj.y != current.y) {
  5495. this.clearSelection();
  5496. this.addSelection(i - k - 1, true);
  5497. break;
  5498. }
  5499. }
  5500. }
  5501. break;
  5502. case 7:
  5503. if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowHorizontal || this._layout == fgui.ListLayoutType.Pagination) {
  5504. index--;
  5505. if (index >= 0) {
  5506. this.clearSelection();
  5507. this.addSelection(index, true);
  5508. }
  5509. }
  5510. else if (this._layout == fgui.ListLayoutType.FlowVertical) {
  5511. current = this._children[index];
  5512. k = 0;
  5513. for (i = index - 1; i >= 0; i--) {
  5514. obj = this._children[i];
  5515. if (obj.x != current.x) {
  5516. current = obj;
  5517. break;
  5518. }
  5519. k++;
  5520. }
  5521. for (; i >= 0; i--) {
  5522. obj = this._children[i];
  5523. if (obj.x != current.x) {
  5524. this.clearSelection();
  5525. this.addSelection(i + k + 1, true);
  5526. break;
  5527. }
  5528. }
  5529. }
  5530. break;
  5531. }
  5532. };
  5533. GList.prototype.onClickItem = function (evt) {
  5534. if (this._scrollPane && this._scrollPane.isDragged)
  5535. return;
  5536. var item = fgui.GObject.cast(evt.currentTarget);
  5537. this.setSelectionOnEvent(item, evt);
  5538. if (this._scrollPane && this.scrollItemToViewOnClick)
  5539. this._scrollPane.scrollToView(item, true);
  5540. this.dispatchItemEvent(item, evt);
  5541. };
  5542. GList.prototype.dispatchItemEvent = function (item, evt) {
  5543. this._node.emit(fgui.Event.CLICK_ITEM, item, evt);
  5544. };
  5545. GList.prototype.setSelectionOnEvent = function (item, evt) {
  5546. if (!(item instanceof fgui.GButton) || this._selectionMode == fgui.ListSelectionMode.None)
  5547. return;
  5548. var dontChangeLastIndex = false;
  5549. var index = this.childIndexToItemIndex(this.getChildIndex(item));
  5550. if (this._selectionMode == fgui.ListSelectionMode.Single) {
  5551. if (!item.selected) {
  5552. this.clearSelectionExcept(item);
  5553. item.selected = true;
  5554. }
  5555. }
  5556. else {
  5557. if (evt.isShiftDown) {
  5558. if (!item.selected) {
  5559. if (this._lastSelectedIndex != -1) {
  5560. var min = Math.min(this._lastSelectedIndex, index);
  5561. var max = Math.max(this._lastSelectedIndex, index);
  5562. max = Math.min(max, this.numItems - 1);
  5563. var i;
  5564. if (this._virtual) {
  5565. for (i = min; i <= max; i++) {
  5566. var ii = this._virtualItems[i];
  5567. if (ii.obj instanceof fgui.GButton)
  5568. ii.obj.selected = true;
  5569. ii.selected = true;
  5570. }
  5571. }
  5572. else {
  5573. for (i = min; i <= max; i++) {
  5574. var obj = this.getChildAt(i);
  5575. if (obj instanceof fgui.GButton)
  5576. obj.selected = true;
  5577. }
  5578. }
  5579. dontChangeLastIndex = true;
  5580. }
  5581. else {
  5582. item.selected = true;
  5583. }
  5584. }
  5585. }
  5586. else if (evt.isCtrlDown || this._selectionMode == fgui.ListSelectionMode.Multiple_SingleClick) {
  5587. item.selected = !item.selected;
  5588. }
  5589. else {
  5590. if (!item.selected) {
  5591. this.clearSelectionExcept(item);
  5592. item.selected = true;
  5593. }
  5594. else
  5595. this.clearSelectionExcept(item);
  5596. }
  5597. }
  5598. if (!dontChangeLastIndex)
  5599. this._lastSelectedIndex = index;
  5600. if (item.selected)
  5601. this.updateSelectionController(index);
  5602. };
  5603. GList.prototype.resizeToFit = function (itemCount, minSize) {
  5604. if (itemCount === void 0) { itemCount = Number.POSITIVE_INFINITY; }
  5605. if (minSize === void 0) { minSize = 0; }
  5606. this.ensureBoundsCorrect();
  5607. var curCount = this.numItems;
  5608. if (itemCount > curCount)
  5609. itemCount = curCount;
  5610. if (this._virtual) {
  5611. var lineCount = Math.ceil(itemCount / this._curLineItemCount);
  5612. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal)
  5613. this.viewHeight = lineCount * this._itemSize.height + Math.max(0, lineCount - 1) * this._lineGap;
  5614. else
  5615. this.viewWidth = lineCount * this._itemSize.width + Math.max(0, lineCount - 1) * this._columnGap;
  5616. }
  5617. else if (itemCount == 0) {
  5618. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal)
  5619. this.viewHeight = minSize;
  5620. else
  5621. this.viewWidth = minSize;
  5622. }
  5623. else {
  5624. var i = itemCount - 1;
  5625. var obj = null;
  5626. while (i >= 0) {
  5627. obj = this.getChildAt(i);
  5628. if (!this.foldInvisibleItems || obj.visible)
  5629. break;
  5630. i--;
  5631. }
  5632. if (i < 0) {
  5633. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal)
  5634. this.viewHeight = minSize;
  5635. else
  5636. this.viewWidth = minSize;
  5637. }
  5638. else {
  5639. var size = 0;
  5640. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5641. size = obj.y + obj.height;
  5642. if (size < minSize)
  5643. size = minSize;
  5644. this.viewHeight = size;
  5645. }
  5646. else {
  5647. size = obj.x + obj.width;
  5648. if (size < minSize)
  5649. size = minSize;
  5650. this.viewWidth = size;
  5651. }
  5652. }
  5653. }
  5654. };
  5655. GList.prototype.getMaxItemWidth = function () {
  5656. var cnt = this._children.length;
  5657. var max = 0;
  5658. for (var i = 0; i < cnt; i++) {
  5659. var child = this.getChildAt(i);
  5660. if (child.width > max)
  5661. max = child.width;
  5662. }
  5663. return max;
  5664. };
  5665. GList.prototype.handleSizeChanged = function () {
  5666. _super.prototype.handleSizeChanged.call(this);
  5667. this.setBoundsChangedFlag();
  5668. if (this._virtual)
  5669. this.setVirtualListChangedFlag(true);
  5670. };
  5671. GList.prototype.handleControllerChanged = function (c) {
  5672. _super.prototype.handleControllerChanged.call(this, c);
  5673. if (this._selectionController == c)
  5674. this.selectedIndex = c.selectedIndex;
  5675. };
  5676. GList.prototype.updateSelectionController = function (index) {
  5677. if (this._selectionController && !this._selectionController.changing
  5678. && index < this._selectionController.pageCount) {
  5679. var c = this._selectionController;
  5680. this._selectionController = null;
  5681. c.selectedIndex = index;
  5682. this._selectionController = c;
  5683. }
  5684. };
  5685. GList.prototype.getSnappingPosition = function (xValue, yValue, resultPoint) {
  5686. if (this._virtual) {
  5687. resultPoint = resultPoint || new cc.Vec2();
  5688. var saved;
  5689. var index;
  5690. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5691. saved = yValue;
  5692. s_n = yValue;
  5693. index = this.getIndexOnPos1(false);
  5694. yValue = s_n;
  5695. if (index < this._virtualItems.length && saved - yValue > this._virtualItems[index].height / 2 && index < this._realNumItems)
  5696. yValue += this._virtualItems[index].height + this._lineGap;
  5697. }
  5698. else if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowVertical) {
  5699. saved = xValue;
  5700. s_n = xValue;
  5701. index = this.getIndexOnPos2(false);
  5702. xValue = s_n;
  5703. if (index < this._virtualItems.length && saved - xValue > this._virtualItems[index].width / 2 && index < this._realNumItems)
  5704. xValue += this._virtualItems[index].width + this._columnGap;
  5705. }
  5706. else {
  5707. saved = xValue;
  5708. s_n = xValue;
  5709. index = this.getIndexOnPos3(false);
  5710. xValue = s_n;
  5711. if (index < this._virtualItems.length && saved - xValue > this._virtualItems[index].width / 2 && index < this._realNumItems)
  5712. xValue += this._virtualItems[index].width + this._columnGap;
  5713. }
  5714. resultPoint.x = xValue;
  5715. resultPoint.y = yValue;
  5716. return resultPoint;
  5717. }
  5718. else {
  5719. return _super.prototype.getSnappingPosition.call(this, xValue, yValue, resultPoint);
  5720. }
  5721. };
  5722. GList.prototype.scrollToView = function (index, ani, setFirst) {
  5723. if (this._virtual) {
  5724. if (this._numItems == 0)
  5725. return;
  5726. this.checkVirtualList();
  5727. if (index >= this._virtualItems.length)
  5728. throw "Invalid child index: " + index + ">" + this._virtualItems.length;
  5729. if (this._loop)
  5730. index = Math.floor(this._firstIndex / this._numItems) * this._numItems + index;
  5731. var rect;
  5732. var ii = this._virtualItems[index];
  5733. var pos = 0;
  5734. var i;
  5735. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5736. for (i = this._curLineItemCount - 1; i < index; i += this._curLineItemCount)
  5737. pos += this._virtualItems[i].height + this._lineGap;
  5738. rect = new cc.Rect(0, pos, this._itemSize.width, ii.height);
  5739. }
  5740. else if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowVertical) {
  5741. for (i = this._curLineItemCount - 1; i < index; i += this._curLineItemCount)
  5742. pos += this._virtualItems[i].width + this._columnGap;
  5743. rect = new cc.Rect(pos, 0, ii.width, this._itemSize.height);
  5744. }
  5745. else {
  5746. var page = index / (this._curLineItemCount * this._curLineItemCount2);
  5747. rect = new cc.Rect(page * this.viewWidth + (index % this._curLineItemCount) * (ii.width + this._columnGap), (index / this._curLineItemCount) % this._curLineItemCount2 * (ii.height + this._lineGap), ii.width, ii.height);
  5748. }
  5749. if (this._scrollPane)
  5750. this._scrollPane.scrollToView(rect, ani, setFirst);
  5751. }
  5752. else {
  5753. var obj = this.getChildAt(index);
  5754. if (obj) {
  5755. if (this._scrollPane)
  5756. this._scrollPane.scrollToView(obj, ani, setFirst);
  5757. else if (this.parent && this.parent.scrollPane)
  5758. this.parent.scrollPane.scrollToView(obj, ani, setFirst);
  5759. }
  5760. }
  5761. };
  5762. GList.prototype.getFirstChildInView = function () {
  5763. return this.childIndexToItemIndex(_super.prototype.getFirstChildInView.call(this));
  5764. };
  5765. GList.prototype.childIndexToItemIndex = function (index) {
  5766. if (!this._virtual)
  5767. return index;
  5768. if (this._layout == fgui.ListLayoutType.Pagination) {
  5769. for (var i = this._firstIndex; i < this._realNumItems; i++) {
  5770. if (this._virtualItems[i].obj) {
  5771. index--;
  5772. if (index < 0)
  5773. return i;
  5774. }
  5775. }
  5776. return index;
  5777. }
  5778. else {
  5779. index += this._firstIndex;
  5780. if (this._loop && this._numItems > 0)
  5781. index = index % this._numItems;
  5782. return index;
  5783. }
  5784. };
  5785. GList.prototype.itemIndexToChildIndex = function (index) {
  5786. if (!this._virtual)
  5787. return index;
  5788. if (this._layout == fgui.ListLayoutType.Pagination) {
  5789. return this.getChildIndex(this._virtualItems[index].obj);
  5790. }
  5791. else {
  5792. if (this._loop && this._numItems > 0) {
  5793. var j = this._firstIndex % this._numItems;
  5794. if (index >= j)
  5795. index = index - j;
  5796. else
  5797. index = this._numItems - j + index;
  5798. }
  5799. else
  5800. index -= this._firstIndex;
  5801. return index;
  5802. }
  5803. };
  5804. GList.prototype.setVirtual = function () {
  5805. this._setVirtual(false);
  5806. };
  5807. GList.prototype.setVirtualAndLoop = function () {
  5808. this._setVirtual(true);
  5809. };
  5810. GList.prototype._setVirtual = function (loop) {
  5811. if (!this._virtual) {
  5812. if (!this._scrollPane)
  5813. throw "Virtual list must be scrollable!";
  5814. if (loop) {
  5815. if (this._layout == fgui.ListLayoutType.FlowHorizontal || this._layout == fgui.ListLayoutType.FlowVertical)
  5816. throw "Loop list is not supported for FlowHorizontal or FlowVertical layout!";
  5817. this._scrollPane.bouncebackEffect = false;
  5818. }
  5819. this._virtual = true;
  5820. this._loop = loop;
  5821. this._virtualItems = new Array();
  5822. this.removeChildrenToPool();
  5823. if (this._itemSize == null) {
  5824. this._itemSize = new cc.Size(0, 0);
  5825. var obj = this.getFromPool(null);
  5826. if (!obj) {
  5827. throw "Virtual List must have a default list item resource.";
  5828. }
  5829. else {
  5830. this._itemSize.width = obj.width;
  5831. this._itemSize.height = obj.height;
  5832. }
  5833. this.returnToPool(obj);
  5834. }
  5835. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5836. this._scrollPane.scrollStep = this._itemSize.height;
  5837. if (this._loop)
  5838. this._scrollPane._loop = 2;
  5839. }
  5840. else {
  5841. this._scrollPane.scrollStep = this._itemSize.width;
  5842. if (this._loop)
  5843. this._scrollPane._loop = 1;
  5844. }
  5845. this._node.on(fgui.Event.SCROLL, this.__scrolled, this);
  5846. this.setVirtualListChangedFlag(true);
  5847. }
  5848. };
  5849. Object.defineProperty(GList.prototype, "numItems", {
  5850. get: function () {
  5851. if (this._virtual)
  5852. return this._numItems;
  5853. else
  5854. return this._children.length;
  5855. },
  5856. set: function (value) {
  5857. if (this._virtual) {
  5858. if (this.itemRenderer == null)
  5859. throw "Set itemRenderer first!";
  5860. this._numItems = value;
  5861. if (this._loop)
  5862. this._realNumItems = this._numItems * 6;
  5863. else
  5864. this._realNumItems = this._numItems;
  5865. var oldCount = this._virtualItems.length;
  5866. if (this._realNumItems > oldCount) {
  5867. for (i = oldCount; i < this._realNumItems; i++) {
  5868. var ii = {
  5869. width: this._itemSize.width,
  5870. height: this._itemSize.height,
  5871. updateFlag: 0
  5872. };
  5873. this._virtualItems.push(ii);
  5874. }
  5875. }
  5876. else {
  5877. for (i = this._realNumItems; i < oldCount; i++)
  5878. this._virtualItems[i].selected = false;
  5879. }
  5880. if (this._virtualListChanged != 0)
  5881. this._partner.unschedule(this._refreshVirtualList);
  5882. this._refreshVirtualList();
  5883. }
  5884. else {
  5885. var cnt = this._children.length;
  5886. if (value > cnt) {
  5887. for (var i = cnt; i < value; i++) {
  5888. if (this.itemProvider == null)
  5889. this.addItemFromPool();
  5890. else
  5891. this.addItemFromPool(this.itemProvider(i));
  5892. }
  5893. }
  5894. else {
  5895. this.removeChildrenToPool(value, cnt);
  5896. }
  5897. if (this.itemRenderer != null) {
  5898. for (i = 0; i < value; i++)
  5899. this.itemRenderer(i, this.getChildAt(i));
  5900. }
  5901. }
  5902. },
  5903. enumerable: false,
  5904. configurable: true
  5905. });
  5906. GList.prototype.refreshVirtualList = function () {
  5907. this.setVirtualListChangedFlag(false);
  5908. };
  5909. GList.prototype.checkVirtualList = function () {
  5910. if (this._virtualListChanged != 0) {
  5911. this._refreshVirtualList();
  5912. this._partner.unschedule(this._refreshVirtualList);
  5913. }
  5914. };
  5915. GList.prototype.setVirtualListChangedFlag = function (layoutChanged) {
  5916. if (layoutChanged)
  5917. this._virtualListChanged = 2;
  5918. else if (this._virtualListChanged == 0)
  5919. this._virtualListChanged = 1;
  5920. this._partner.callLater(this._refreshVirtualList);
  5921. };
  5922. GList.prototype._refreshVirtualList = function (dt) {
  5923. if (!isNaN(dt)) {
  5924. var _t = (this.node["$gobj"]);
  5925. _t._refreshVirtualList();
  5926. return;
  5927. }
  5928. var layoutChanged = this._virtualListChanged == 2;
  5929. this._virtualListChanged = 0;
  5930. this._eventLocked = true;
  5931. if (layoutChanged) {
  5932. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.SingleRow)
  5933. this._curLineItemCount = 1;
  5934. else if (this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5935. if (this._columnCount > 0)
  5936. this._curLineItemCount = this._columnCount;
  5937. else {
  5938. this._curLineItemCount = Math.floor((this._scrollPane.viewWidth + this._columnGap) / (this._itemSize.width + this._columnGap));
  5939. if (this._curLineItemCount <= 0)
  5940. this._curLineItemCount = 1;
  5941. }
  5942. }
  5943. else if (this._layout == fgui.ListLayoutType.FlowVertical) {
  5944. if (this._lineCount > 0)
  5945. this._curLineItemCount = this._lineCount;
  5946. else {
  5947. this._curLineItemCount = Math.floor((this._scrollPane.viewHeight + this._lineGap) / (this._itemSize.height + this._lineGap));
  5948. if (this._curLineItemCount <= 0)
  5949. this._curLineItemCount = 1;
  5950. }
  5951. }
  5952. else {
  5953. if (this._columnCount > 0)
  5954. this._curLineItemCount = this._columnCount;
  5955. else {
  5956. this._curLineItemCount = Math.floor((this._scrollPane.viewWidth + this._columnGap) / (this._itemSize.width + this._columnGap));
  5957. if (this._curLineItemCount <= 0)
  5958. this._curLineItemCount = 1;
  5959. }
  5960. if (this._lineCount > 0)
  5961. this._curLineItemCount2 = this._lineCount;
  5962. else {
  5963. this._curLineItemCount2 = Math.floor((this._scrollPane.viewHeight + this._lineGap) / (this._itemSize.height + this._lineGap));
  5964. if (this._curLineItemCount2 <= 0)
  5965. this._curLineItemCount2 = 1;
  5966. }
  5967. }
  5968. }
  5969. var ch = 0, cw = 0;
  5970. if (this._realNumItems > 0) {
  5971. var i;
  5972. var len = Math.ceil(this._realNumItems / this._curLineItemCount) * this._curLineItemCount;
  5973. var len2 = Math.min(this._curLineItemCount, this._realNumItems);
  5974. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5975. for (i = 0; i < len; i += this._curLineItemCount)
  5976. ch += this._virtualItems[i].height + this._lineGap;
  5977. if (ch > 0)
  5978. ch -= this._lineGap;
  5979. if (this._autoResizeItem)
  5980. cw = this._scrollPane.viewWidth;
  5981. else {
  5982. for (i = 0; i < len2; i++)
  5983. cw += this._virtualItems[i].width + this._columnGap;
  5984. if (cw > 0)
  5985. cw -= this._columnGap;
  5986. }
  5987. }
  5988. else if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowVertical) {
  5989. for (i = 0; i < len; i += this._curLineItemCount)
  5990. cw += this._virtualItems[i].width + this._columnGap;
  5991. if (cw > 0)
  5992. cw -= this._columnGap;
  5993. if (this._autoResizeItem)
  5994. ch = this._scrollPane.viewHeight;
  5995. else {
  5996. for (i = 0; i < len2; i++)
  5997. ch += this._virtualItems[i].height + this._lineGap;
  5998. if (ch > 0)
  5999. ch -= this._lineGap;
  6000. }
  6001. }
  6002. else {
  6003. var pageCount = Math.ceil(len / (this._curLineItemCount * this._curLineItemCount2));
  6004. cw = pageCount * this.viewWidth;
  6005. ch = this.viewHeight;
  6006. }
  6007. }
  6008. this.handleAlign(cw, ch);
  6009. this._scrollPane.setContentSize(cw, ch);
  6010. this._eventLocked = false;
  6011. this.handleScroll(true);
  6012. };
  6013. GList.prototype.__scrolled = function (evt) {
  6014. this.handleScroll(false);
  6015. };
  6016. GList.prototype.getIndexOnPos1 = function (forceUpdate) {
  6017. if (this._realNumItems < this._curLineItemCount) {
  6018. s_n = 0;
  6019. return 0;
  6020. }
  6021. var i;
  6022. var pos2;
  6023. var pos3;
  6024. if (this.numChildren > 0 && !forceUpdate) {
  6025. pos2 = this.getChildAt(0).y;
  6026. if (pos2 > s_n) {
  6027. for (i = this._firstIndex - this._curLineItemCount; i >= 0; i -= this._curLineItemCount) {
  6028. pos2 -= (this._virtualItems[i].height + this._lineGap);
  6029. if (pos2 <= s_n) {
  6030. s_n = pos2;
  6031. return i;
  6032. }
  6033. }
  6034. s_n = 0;
  6035. return 0;
  6036. }
  6037. else {
  6038. for (i = this._firstIndex; i < this._realNumItems; i += this._curLineItemCount) {
  6039. pos3 = pos2 + this._virtualItems[i].height + this._lineGap;
  6040. if (pos3 > s_n) {
  6041. s_n = pos2;
  6042. return i;
  6043. }
  6044. pos2 = pos3;
  6045. }
  6046. s_n = pos2;
  6047. return this._realNumItems - this._curLineItemCount;
  6048. }
  6049. }
  6050. else {
  6051. pos2 = 0;
  6052. for (i = 0; i < this._realNumItems; i += this._curLineItemCount) {
  6053. pos3 = pos2 + this._virtualItems[i].height + this._lineGap;
  6054. if (pos3 > s_n) {
  6055. s_n = pos2;
  6056. return i;
  6057. }
  6058. pos2 = pos3;
  6059. }
  6060. s_n = pos2;
  6061. return this._realNumItems - this._curLineItemCount;
  6062. }
  6063. };
  6064. GList.prototype.getIndexOnPos2 = function (forceUpdate) {
  6065. if (this._realNumItems < this._curLineItemCount) {
  6066. s_n = 0;
  6067. return 0;
  6068. }
  6069. var i;
  6070. var pos2;
  6071. var pos3;
  6072. if (this.numChildren > 0 && !forceUpdate) {
  6073. pos2 = this.getChildAt(0).x;
  6074. if (pos2 > s_n) {
  6075. for (i = this._firstIndex - this._curLineItemCount; i >= 0; i -= this._curLineItemCount) {
  6076. pos2 -= (this._virtualItems[i].width + this._columnGap);
  6077. if (pos2 <= s_n) {
  6078. s_n = pos2;
  6079. return i;
  6080. }
  6081. }
  6082. s_n = 0;
  6083. return 0;
  6084. }
  6085. else {
  6086. for (i = this._firstIndex; i < this._realNumItems; i += this._curLineItemCount) {
  6087. pos3 = pos2 + this._virtualItems[i].width + this._columnGap;
  6088. if (pos3 > s_n) {
  6089. s_n = pos2;
  6090. return i;
  6091. }
  6092. pos2 = pos3;
  6093. }
  6094. s_n = pos2;
  6095. return this._realNumItems - this._curLineItemCount;
  6096. }
  6097. }
  6098. else {
  6099. pos2 = 0;
  6100. for (i = 0; i < this._realNumItems; i += this._curLineItemCount) {
  6101. pos3 = pos2 + this._virtualItems[i].width + this._columnGap;
  6102. if (pos3 > s_n) {
  6103. s_n = pos2;
  6104. return i;
  6105. }
  6106. pos2 = pos3;
  6107. }
  6108. s_n = pos2;
  6109. return this._realNumItems - this._curLineItemCount;
  6110. }
  6111. };
  6112. GList.prototype.getIndexOnPos3 = function (forceUpdate) {
  6113. if (this._realNumItems < this._curLineItemCount) {
  6114. s_n = 0;
  6115. return 0;
  6116. }
  6117. var viewWidth = this.viewWidth;
  6118. var page = Math.floor(s_n / viewWidth);
  6119. var startIndex = page * (this._curLineItemCount * this._curLineItemCount2);
  6120. var pos2 = page * viewWidth;
  6121. var i;
  6122. var pos3;
  6123. for (i = 0; i < this._curLineItemCount; i++) {
  6124. pos3 = pos2 + this._virtualItems[startIndex + i].width + this._columnGap;
  6125. if (pos3 > s_n) {
  6126. s_n = pos2;
  6127. return startIndex + i;
  6128. }
  6129. pos2 = pos3;
  6130. }
  6131. s_n = pos2;
  6132. return startIndex + this._curLineItemCount - 1;
  6133. };
  6134. GList.prototype.handleScroll = function (forceUpdate) {
  6135. if (this._eventLocked)
  6136. return;
  6137. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  6138. var enterCounter = 0;
  6139. while (this.handleScroll1(forceUpdate)) {
  6140. enterCounter++;
  6141. forceUpdate = false;
  6142. if (enterCounter > 20) {
  6143. console.log("FairyGUI: list will never be filled as the item renderer function always returns a different size.");
  6144. break;
  6145. }
  6146. }
  6147. this.handleArchOrder1();
  6148. }
  6149. else if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowVertical) {
  6150. enterCounter = 0;
  6151. while (this.handleScroll2(forceUpdate)) {
  6152. enterCounter++;
  6153. forceUpdate = false;
  6154. if (enterCounter > 20) {
  6155. console.log("FairyGUI: list will never be filled as the item renderer function always returns a different size.");
  6156. break;
  6157. }
  6158. }
  6159. this.handleArchOrder2();
  6160. }
  6161. else {
  6162. this.handleScroll3(forceUpdate);
  6163. }
  6164. this._boundsChanged = false;
  6165. };
  6166. GList.prototype.handleScroll1 = function (forceUpdate) {
  6167. var pos = this._scrollPane.scrollingPosY;
  6168. var max = pos + this._scrollPane.viewHeight;
  6169. var end = max == this._scrollPane.contentHeight;
  6170. s_n = pos;
  6171. var newFirstIndex = this.getIndexOnPos1(forceUpdate);
  6172. pos = s_n;
  6173. if (newFirstIndex == this._firstIndex && !forceUpdate) {
  6174. return false;
  6175. }
  6176. var oldFirstIndex = this._firstIndex;
  6177. this._firstIndex = newFirstIndex;
  6178. var curIndex = newFirstIndex;
  6179. var forward = oldFirstIndex > newFirstIndex;
  6180. var childCount = this.numChildren;
  6181. var lastIndex = oldFirstIndex + childCount - 1;
  6182. var reuseIndex = forward ? lastIndex : oldFirstIndex;
  6183. var curX = 0, curY = pos;
  6184. var needRender;
  6185. var deltaSize = 0;
  6186. var firstItemDeltaSize = 0;
  6187. var url = this._defaultItem;
  6188. var ii, ii2;
  6189. var i, j;
  6190. var partSize = (this._scrollPane.viewWidth - this._columnGap * (this._curLineItemCount - 1)) / this._curLineItemCount;
  6191. this.itemInfoVer++;
  6192. while (curIndex < this._realNumItems && (end || curY < max)) {
  6193. ii = this._virtualItems[curIndex];
  6194. if (!ii.obj || forceUpdate) {
  6195. if (this.itemProvider != null) {
  6196. url = this.itemProvider(curIndex % this._numItems);
  6197. if (url == null)
  6198. url = this._defaultItem;
  6199. url = fgui.UIPackage.normalizeURL(url);
  6200. }
  6201. if (ii.obj && ii.obj.resourceURL != url) {
  6202. if (ii.obj instanceof fgui.GButton)
  6203. ii.selected = ii.obj.selected;
  6204. this.removeChildToPool(ii.obj);
  6205. ii.obj = null;
  6206. }
  6207. }
  6208. if (!ii.obj) {
  6209. if (forward) {
  6210. for (j = reuseIndex; j >= oldFirstIndex; j--) {
  6211. ii2 = this._virtualItems[j];
  6212. if (ii2.obj && ii2.updateFlag != this.itemInfoVer && ii2.obj.resourceURL == url) {
  6213. if (ii2.obj instanceof fgui.GButton)
  6214. ii2.selected = ii2.obj.selected;
  6215. ii.obj = ii2.obj;
  6216. ii2.obj = null;
  6217. if (j == reuseIndex)
  6218. reuseIndex--;
  6219. break;
  6220. }
  6221. }
  6222. }
  6223. else {
  6224. for (j = reuseIndex; j <= lastIndex; j++) {
  6225. ii2 = this._virtualItems[j];
  6226. if (ii2.obj && ii2.updateFlag != this.itemInfoVer && ii2.obj.resourceURL == url) {
  6227. if (ii2.obj instanceof fgui.GButton)
  6228. ii2.selected = ii2.obj.selected;
  6229. ii.obj = ii2.obj;
  6230. ii2.obj = null;
  6231. if (j == reuseIndex)
  6232. reuseIndex++;
  6233. break;
  6234. }
  6235. }
  6236. }
  6237. if (ii.obj) {
  6238. this.setChildIndex(ii.obj, forward ? curIndex - newFirstIndex : this.numChildren);
  6239. }
  6240. else {
  6241. ii.obj = this._pool.getObject(url);
  6242. if (forward)
  6243. this.addChildAt(ii.obj, curIndex - newFirstIndex);
  6244. else
  6245. this.addChild(ii.obj);
  6246. }
  6247. if (ii.obj instanceof fgui.GButton)
  6248. ii.obj.selected = ii.selected;
  6249. needRender = true;
  6250. }
  6251. else
  6252. needRender = forceUpdate;
  6253. if (needRender) {
  6254. if (this._autoResizeItem && (this._layout == fgui.ListLayoutType.SingleColumn || this._columnCount > 0))
  6255. ii.obj.setSize(partSize, ii.obj.height, true);
  6256. this.itemRenderer(curIndex % this._numItems, ii.obj);
  6257. if (curIndex % this._curLineItemCount == 0) {
  6258. deltaSize += Math.ceil(ii.obj.height) - ii.height;
  6259. if (curIndex == newFirstIndex && oldFirstIndex > newFirstIndex) {
  6260. firstItemDeltaSize = Math.ceil(ii.obj.height) - ii.height;
  6261. }
  6262. }
  6263. ii.width = Math.ceil(ii.obj.width);
  6264. ii.height = Math.ceil(ii.obj.height);
  6265. }
  6266. ii.updateFlag = this.itemInfoVer;
  6267. ii.obj.setPosition(curX, curY);
  6268. if (curIndex == newFirstIndex)
  6269. max += ii.height;
  6270. curX += ii.width + this._columnGap;
  6271. if (curIndex % this._curLineItemCount == this._curLineItemCount - 1) {
  6272. curX = 0;
  6273. curY += ii.height + this._lineGap;
  6274. }
  6275. curIndex++;
  6276. }
  6277. for (i = 0; i < childCount; i++) {
  6278. ii = this._virtualItems[oldFirstIndex + i];
  6279. if (ii.updateFlag != this.itemInfoVer && ii.obj) {
  6280. if (ii.obj instanceof fgui.GButton)
  6281. ii.selected = ii.obj.selected;
  6282. this.removeChildToPool(ii.obj);
  6283. ii.obj = null;
  6284. }
  6285. }
  6286. childCount = this._children.length;
  6287. for (i = 0; i < childCount; i++) {
  6288. var obj = this._virtualItems[newFirstIndex + i].obj;
  6289. if (this._children[i] != obj)
  6290. this.setChildIndex(obj, i);
  6291. }
  6292. if (deltaSize != 0 || firstItemDeltaSize != 0)
  6293. this._scrollPane.changeContentSizeOnScrolling(0, deltaSize, 0, firstItemDeltaSize);
  6294. if (curIndex > 0 && this.numChildren > 0 && this._container.y <= 0 && this.getChildAt(0).y > -this._container.y)
  6295. return true;
  6296. else
  6297. return false;
  6298. };
  6299. GList.prototype.handleScroll2 = function (forceUpdate) {
  6300. var pos = this._scrollPane.scrollingPosX;
  6301. var max = pos + this._scrollPane.viewWidth;
  6302. var end = pos == this._scrollPane.contentWidth;
  6303. s_n = pos;
  6304. var newFirstIndex = this.getIndexOnPos2(forceUpdate);
  6305. pos = s_n;
  6306. if (newFirstIndex == this._firstIndex && !forceUpdate) {
  6307. return false;
  6308. }
  6309. var oldFirstIndex = this._firstIndex;
  6310. this._firstIndex = newFirstIndex;
  6311. var curIndex = newFirstIndex;
  6312. var forward = oldFirstIndex > newFirstIndex;
  6313. var childCount = this.numChildren;
  6314. var lastIndex = oldFirstIndex + childCount - 1;
  6315. var reuseIndex = forward ? lastIndex : oldFirstIndex;
  6316. var curX = pos, curY = 0;
  6317. var needRender;
  6318. var deltaSize = 0;
  6319. var firstItemDeltaSize = 0;
  6320. var url = this._defaultItem;
  6321. var ii, ii2;
  6322. var i, j;
  6323. var partSize = (this._scrollPane.viewHeight - this._lineGap * (this._curLineItemCount - 1)) / this._curLineItemCount;
  6324. this.itemInfoVer++;
  6325. while (curIndex < this._realNumItems && (end || curX < max)) {
  6326. ii = this._virtualItems[curIndex];
  6327. if (!ii.obj || forceUpdate) {
  6328. if (this.itemProvider != null) {
  6329. url = this.itemProvider(curIndex % this._numItems);
  6330. if (url == null)
  6331. url = this._defaultItem;
  6332. url = fgui.UIPackage.normalizeURL(url);
  6333. }
  6334. if (ii.obj && ii.obj.resourceURL != url) {
  6335. if (ii.obj instanceof fgui.GButton)
  6336. ii.selected = ii.obj.selected;
  6337. this.removeChildToPool(ii.obj);
  6338. ii.obj = null;
  6339. }
  6340. }
  6341. if (!ii.obj) {
  6342. if (forward) {
  6343. for (j = reuseIndex; j >= oldFirstIndex; j--) {
  6344. ii2 = this._virtualItems[j];
  6345. if (ii2.obj && ii2.updateFlag != this.itemInfoVer && ii2.obj.resourceURL == url) {
  6346. if (ii2.obj instanceof fgui.GButton)
  6347. ii2.selected = ii2.obj.selected;
  6348. ii.obj = ii2.obj;
  6349. ii2.obj = null;
  6350. if (j == reuseIndex)
  6351. reuseIndex--;
  6352. break;
  6353. }
  6354. }
  6355. }
  6356. else {
  6357. for (j = reuseIndex; j <= lastIndex; j++) {
  6358. ii2 = this._virtualItems[j];
  6359. if (ii2.obj && ii2.updateFlag != this.itemInfoVer && ii2.obj.resourceURL == url) {
  6360. if (ii2.obj instanceof fgui.GButton)
  6361. ii2.selected = ii2.obj.selected;
  6362. ii.obj = ii2.obj;
  6363. ii2.obj = null;
  6364. if (j == reuseIndex)
  6365. reuseIndex++;
  6366. break;
  6367. }
  6368. }
  6369. }
  6370. if (ii.obj) {
  6371. this.setChildIndex(ii.obj, forward ? curIndex - newFirstIndex : this.numChildren);
  6372. }
  6373. else {
  6374. ii.obj = this._pool.getObject(url);
  6375. if (forward)
  6376. this.addChildAt(ii.obj, curIndex - newFirstIndex);
  6377. else
  6378. this.addChild(ii.obj);
  6379. }
  6380. if (ii.obj instanceof fgui.GButton)
  6381. ii.obj.selected = ii.selected;
  6382. needRender = true;
  6383. }
  6384. else
  6385. needRender = forceUpdate;
  6386. if (needRender) {
  6387. if (this._autoResizeItem && (this._layout == fgui.ListLayoutType.SingleRow || this._lineCount > 0))
  6388. ii.obj.setSize(ii.obj.width, partSize, true);
  6389. this.itemRenderer(curIndex % this._numItems, ii.obj);
  6390. if (curIndex % this._curLineItemCount == 0) {
  6391. deltaSize += Math.ceil(ii.obj.width) - ii.width;
  6392. if (curIndex == newFirstIndex && oldFirstIndex > newFirstIndex) {
  6393. firstItemDeltaSize = Math.ceil(ii.obj.width) - ii.width;
  6394. }
  6395. }
  6396. ii.width = Math.ceil(ii.obj.width);
  6397. ii.height = Math.ceil(ii.obj.height);
  6398. }
  6399. ii.updateFlag = this.itemInfoVer;
  6400. ii.obj.setPosition(curX, curY);
  6401. if (curIndex == newFirstIndex)
  6402. max += ii.width;
  6403. curY += ii.height + this._lineGap;
  6404. if (curIndex % this._curLineItemCount == this._curLineItemCount - 1) {
  6405. curY = 0;
  6406. curX += ii.width + this._columnGap;
  6407. }
  6408. curIndex++;
  6409. }
  6410. for (i = 0; i < childCount; i++) {
  6411. ii = this._virtualItems[oldFirstIndex + i];
  6412. if (ii.updateFlag != this.itemInfoVer && ii.obj) {
  6413. if (ii.obj instanceof fgui.GButton)
  6414. ii.selected = ii.obj.selected;
  6415. this.removeChildToPool(ii.obj);
  6416. ii.obj = null;
  6417. }
  6418. }
  6419. childCount = this._children.length;
  6420. for (i = 0; i < childCount; i++) {
  6421. var obj = this._virtualItems[newFirstIndex + i].obj;
  6422. if (this._children[i] != obj)
  6423. this.setChildIndex(obj, i);
  6424. }
  6425. if (deltaSize != 0 || firstItemDeltaSize != 0)
  6426. this._scrollPane.changeContentSizeOnScrolling(deltaSize, 0, firstItemDeltaSize, 0);
  6427. if (curIndex > 0 && this.numChildren > 0 && this._container.x <= 0 && this.getChildAt(0).x > -this._container.x)
  6428. return true;
  6429. else
  6430. return false;
  6431. };
  6432. GList.prototype.handleScroll3 = function (forceUpdate) {
  6433. var pos = this._scrollPane.scrollingPosX;
  6434. s_n = pos;
  6435. var newFirstIndex = this.getIndexOnPos3(forceUpdate);
  6436. pos = s_n;
  6437. if (newFirstIndex == this._firstIndex && !forceUpdate)
  6438. return;
  6439. var oldFirstIndex = this._firstIndex;
  6440. this._firstIndex = newFirstIndex;
  6441. var reuseIndex = oldFirstIndex;
  6442. var virtualItemCount = this._virtualItems.length;
  6443. var pageSize = this._curLineItemCount * this._curLineItemCount2;
  6444. var startCol = newFirstIndex % this._curLineItemCount;
  6445. var viewWidth = this.viewWidth;
  6446. var page = Math.floor(newFirstIndex / pageSize);
  6447. var startIndex = page * pageSize;
  6448. var lastIndex = startIndex + pageSize * 2;
  6449. var needRender;
  6450. var i;
  6451. var ii, ii2;
  6452. var col;
  6453. var url = this._defaultItem;
  6454. var partWidth = (this._scrollPane.viewWidth - this._columnGap * (this._curLineItemCount - 1)) / this._curLineItemCount;
  6455. var partHeight = (this._scrollPane.viewHeight - this._lineGap * (this._curLineItemCount2 - 1)) / this._curLineItemCount2;
  6456. this.itemInfoVer++;
  6457. for (i = startIndex; i < lastIndex; i++) {
  6458. if (i >= this._realNumItems)
  6459. continue;
  6460. col = i % this._curLineItemCount;
  6461. if (i - startIndex < pageSize) {
  6462. if (col < startCol)
  6463. continue;
  6464. }
  6465. else {
  6466. if (col > startCol)
  6467. continue;
  6468. }
  6469. ii = this._virtualItems[i];
  6470. ii.updateFlag = this.itemInfoVer;
  6471. }
  6472. var lastObj = null;
  6473. var insertIndex = 0;
  6474. for (i = startIndex; i < lastIndex; i++) {
  6475. if (i >= this._realNumItems)
  6476. continue;
  6477. ii = this._virtualItems[i];
  6478. if (ii.updateFlag != this.itemInfoVer)
  6479. continue;
  6480. if (!ii.obj) {
  6481. while (reuseIndex < virtualItemCount) {
  6482. ii2 = this._virtualItems[reuseIndex];
  6483. if (ii2.obj && ii2.updateFlag != this.itemInfoVer) {
  6484. if (ii2.obj instanceof fgui.GButton)
  6485. ii2.selected = ii2.obj.selected;
  6486. ii.obj = ii2.obj;
  6487. ii2.obj = null;
  6488. break;
  6489. }
  6490. reuseIndex++;
  6491. }
  6492. if (insertIndex == -1)
  6493. insertIndex = this.getChildIndex(lastObj) + 1;
  6494. if (!ii.obj) {
  6495. if (this.itemProvider != null) {
  6496. url = this.itemProvider(i % this._numItems);
  6497. if (url == null)
  6498. url = this._defaultItem;
  6499. url = fgui.UIPackage.normalizeURL(url);
  6500. }
  6501. ii.obj = this._pool.getObject(url);
  6502. this.addChildAt(ii.obj, insertIndex);
  6503. }
  6504. else {
  6505. insertIndex = this.setChildIndexBefore(ii.obj, insertIndex);
  6506. }
  6507. insertIndex++;
  6508. if (ii.obj instanceof fgui.GButton)
  6509. ii.obj.selected = ii.selected;
  6510. needRender = true;
  6511. }
  6512. else {
  6513. needRender = forceUpdate;
  6514. insertIndex = -1;
  6515. lastObj = ii.obj;
  6516. }
  6517. if (needRender) {
  6518. if (this._autoResizeItem) {
  6519. if (this._curLineItemCount == this._columnCount && this._curLineItemCount2 == this._lineCount)
  6520. ii.obj.setSize(partWidth, partHeight, true);
  6521. else if (this._curLineItemCount == this._columnCount)
  6522. ii.obj.setSize(partWidth, ii.obj.height, true);
  6523. else if (this._curLineItemCount2 == this._lineCount)
  6524. ii.obj.setSize(ii.obj.width, partHeight, true);
  6525. }
  6526. this.itemRenderer(i % this._numItems, ii.obj);
  6527. ii.width = Math.ceil(ii.obj.width);
  6528. ii.height = Math.ceil(ii.obj.height);
  6529. }
  6530. }
  6531. var borderX = (startIndex / pageSize) * viewWidth;
  6532. var xx = borderX;
  6533. var yy = 0;
  6534. var lineHeight = 0;
  6535. for (i = startIndex; i < lastIndex; i++) {
  6536. if (i >= this._realNumItems)
  6537. continue;
  6538. ii = this._virtualItems[i];
  6539. if (ii.updateFlag == this.itemInfoVer)
  6540. ii.obj.setPosition(xx, yy);
  6541. if (ii.height > lineHeight)
  6542. lineHeight = ii.height;
  6543. if (i % this._curLineItemCount == this._curLineItemCount - 1) {
  6544. xx = borderX;
  6545. yy += lineHeight + this._lineGap;
  6546. lineHeight = 0;
  6547. if (i == startIndex + pageSize - 1) {
  6548. borderX += viewWidth;
  6549. xx = borderX;
  6550. yy = 0;
  6551. }
  6552. }
  6553. else
  6554. xx += ii.width + this._columnGap;
  6555. }
  6556. for (i = reuseIndex; i < virtualItemCount; i++) {
  6557. ii = this._virtualItems[i];
  6558. if (ii.updateFlag != this.itemInfoVer && ii.obj) {
  6559. if (ii.obj instanceof fgui.GButton)
  6560. ii.selected = ii.obj.selected;
  6561. this.removeChildToPool(ii.obj);
  6562. ii.obj = null;
  6563. }
  6564. }
  6565. };
  6566. GList.prototype.handleArchOrder1 = function () {
  6567. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Arch) {
  6568. var mid = this._scrollPane.posY + this.viewHeight / 2;
  6569. var minDist = Number.POSITIVE_INFINITY;
  6570. var dist = 0;
  6571. var apexIndex = 0;
  6572. var cnt = this.numChildren;
  6573. for (var i = 0; i < cnt; i++) {
  6574. var obj = this.getChildAt(i);
  6575. if (!this.foldInvisibleItems || obj.visible) {
  6576. dist = Math.abs(mid - obj.y - obj.height / 2);
  6577. if (dist < minDist) {
  6578. minDist = dist;
  6579. apexIndex = i;
  6580. }
  6581. }
  6582. }
  6583. this.apexIndex = apexIndex;
  6584. }
  6585. };
  6586. GList.prototype.handleArchOrder2 = function () {
  6587. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Arch) {
  6588. var mid = this._scrollPane.posX + this.viewWidth / 2;
  6589. var minDist = Number.POSITIVE_INFINITY;
  6590. var dist = 0;
  6591. var apexIndex = 0;
  6592. var cnt = this.numChildren;
  6593. for (var i = 0; i < cnt; i++) {
  6594. var obj = this.getChildAt(i);
  6595. if (!this.foldInvisibleItems || obj.visible) {
  6596. dist = Math.abs(mid - obj.x - obj.width / 2);
  6597. if (dist < minDist) {
  6598. minDist = dist;
  6599. apexIndex = i;
  6600. }
  6601. }
  6602. }
  6603. this.apexIndex = apexIndex;
  6604. }
  6605. };
  6606. GList.prototype.handleAlign = function (contentWidth, contentHeight) {
  6607. var newOffsetX = 0;
  6608. var newOffsetY = 0;
  6609. if (contentHeight < this.viewHeight) {
  6610. if (this._verticalAlign == fgui.VertAlignType.Middle)
  6611. newOffsetY = Math.floor((this.viewHeight - contentHeight) / 2);
  6612. else if (this._verticalAlign == fgui.VertAlignType.Bottom)
  6613. newOffsetY = this.viewHeight - contentHeight;
  6614. }
  6615. if (contentWidth < this.viewWidth) {
  6616. if (this._align == fgui.AlignType.Center)
  6617. newOffsetX = Math.floor((this.viewWidth - contentWidth) / 2);
  6618. else if (this._align == fgui.AlignType.Right)
  6619. newOffsetX = this.viewWidth - contentWidth;
  6620. }
  6621. if (newOffsetX != this._alignOffset.x || newOffsetY != this._alignOffset.y) {
  6622. this._alignOffset.x = newOffsetX;
  6623. this._alignOffset.y = newOffsetY;
  6624. if (this._scrollPane)
  6625. this._scrollPane.adjustMaskContainer();
  6626. else
  6627. this._container.setPosition(this._pivotCorrectX + this._alignOffset.x, this._pivotCorrectY - this._alignOffset.y);
  6628. }
  6629. };
  6630. GList.prototype.updateBounds = function () {
  6631. if (this._virtual)
  6632. return;
  6633. var i;
  6634. var child;
  6635. var curX = 0;
  6636. var curY = 0;
  6637. var maxWidth = 0;
  6638. var maxHeight = 0;
  6639. var cw = 0, ch = 0;
  6640. var j = 0;
  6641. var page = 0;
  6642. var k = 0;
  6643. var cnt = this._children.length;
  6644. var viewWidth = this.viewWidth;
  6645. var viewHeight = this.viewHeight;
  6646. var lineSize = 0;
  6647. var lineStart = 0;
  6648. var ratio = 0;
  6649. if (this._layout == fgui.ListLayoutType.SingleColumn) {
  6650. for (i = 0; i < cnt; i++) {
  6651. child = this.getChildAt(i);
  6652. if (this.foldInvisibleItems && !child.visible)
  6653. continue;
  6654. if (curY != 0)
  6655. curY += this._lineGap;
  6656. child.y = curY;
  6657. if (this._autoResizeItem)
  6658. child.setSize(viewWidth, child.height, true);
  6659. curY += Math.ceil(child.height);
  6660. if (child.width > maxWidth)
  6661. maxWidth = child.width;
  6662. }
  6663. ch = curY;
  6664. if (ch <= viewHeight && this._autoResizeItem && this._scrollPane && this._scrollPane._displayInDemand && this._scrollPane.vtScrollBar) {
  6665. viewWidth += this._scrollPane.vtScrollBar.width;
  6666. for (i = 0; i < cnt; i++) {
  6667. child = this.getChildAt(i);
  6668. if (this.foldInvisibleItems && !child.visible)
  6669. continue;
  6670. child.setSize(viewWidth, child.height, true);
  6671. if (child.width > maxWidth)
  6672. maxWidth = child.width;
  6673. }
  6674. }
  6675. cw = Math.ceil(maxWidth);
  6676. }
  6677. else if (this._layout == fgui.ListLayoutType.SingleRow) {
  6678. for (i = 0; i < cnt; i++) {
  6679. child = this.getChildAt(i);
  6680. if (this.foldInvisibleItems && !child.visible)
  6681. continue;
  6682. if (curX != 0)
  6683. curX += this._columnGap;
  6684. child.x = curX;
  6685. if (this._autoResizeItem)
  6686. child.setSize(child.width, viewHeight, true);
  6687. curX += Math.ceil(child.width);
  6688. if (child.height > maxHeight)
  6689. maxHeight = child.height;
  6690. }
  6691. cw = curX;
  6692. if (cw <= viewWidth && this._autoResizeItem && this._scrollPane && this._scrollPane._displayInDemand && this._scrollPane.hzScrollBar) {
  6693. viewHeight += this._scrollPane.hzScrollBar.height;
  6694. for (i = 0; i < cnt; i++) {
  6695. child = this.getChildAt(i);
  6696. if (this.foldInvisibleItems && !child.visible)
  6697. continue;
  6698. child.setSize(child.width, viewHeight, true);
  6699. if (child.height > maxHeight)
  6700. maxHeight = child.height;
  6701. }
  6702. }
  6703. ch = Math.ceil(maxHeight);
  6704. }
  6705. else if (this._layout == fgui.ListLayoutType.FlowHorizontal) {
  6706. if (this._autoResizeItem && this._columnCount > 0) {
  6707. for (i = 0; i < cnt; i++) {
  6708. child = this.getChildAt(i);
  6709. if (this.foldInvisibleItems && !child.visible)
  6710. continue;
  6711. lineSize += child.sourceWidth;
  6712. j++;
  6713. if (j == this._columnCount || i == cnt - 1) {
  6714. ratio = (viewWidth - lineSize - (j - 1) * this._columnGap) / lineSize;
  6715. curX = 0;
  6716. for (j = lineStart; j <= i; j++) {
  6717. child = this.getChildAt(j);
  6718. if (this.foldInvisibleItems && !child.visible)
  6719. continue;
  6720. child.setPosition(curX, curY);
  6721. if (j < i) {
  6722. child.setSize(child.sourceWidth + Math.round(child.sourceWidth * ratio), child.height, true);
  6723. curX += Math.ceil(child.width) + this._columnGap;
  6724. }
  6725. else {
  6726. child.setSize(viewWidth - curX, child.height, true);
  6727. }
  6728. if (child.height > maxHeight)
  6729. maxHeight = child.height;
  6730. }
  6731. curY += Math.ceil(maxHeight) + this._lineGap;
  6732. maxHeight = 0;
  6733. j = 0;
  6734. lineStart = i + 1;
  6735. lineSize = 0;
  6736. }
  6737. }
  6738. ch = curY + Math.ceil(maxHeight);
  6739. cw = viewWidth;
  6740. }
  6741. else {
  6742. for (i = 0; i < cnt; i++) {
  6743. child = this.getChildAt(i);
  6744. if (this.foldInvisibleItems && !child.visible)
  6745. continue;
  6746. if (curX != 0)
  6747. curX += this._columnGap;
  6748. if (this._columnCount != 0 && j >= this._columnCount
  6749. || this._columnCount == 0 && curX + child.width > viewWidth && maxHeight != 0) {
  6750. curX = 0;
  6751. curY += Math.ceil(maxHeight) + this._lineGap;
  6752. maxHeight = 0;
  6753. j = 0;
  6754. }
  6755. child.setPosition(curX, curY);
  6756. curX += Math.ceil(child.width);
  6757. if (curX > maxWidth)
  6758. maxWidth = curX;
  6759. if (child.height > maxHeight)
  6760. maxHeight = child.height;
  6761. j++;
  6762. }
  6763. ch = curY + Math.ceil(maxHeight);
  6764. cw = Math.ceil(maxWidth);
  6765. }
  6766. }
  6767. else if (this._layout == fgui.ListLayoutType.FlowVertical) {
  6768. if (this._autoResizeItem && this._lineCount > 0) {
  6769. for (i = 0; i < cnt; i++) {
  6770. child = this.getChildAt(i);
  6771. if (this.foldInvisibleItems && !child.visible)
  6772. continue;
  6773. lineSize += child.sourceHeight;
  6774. j++;
  6775. if (j == this._lineCount || i == cnt - 1) {
  6776. ratio = (viewHeight - lineSize - (j - 1) * this._lineGap) / lineSize;
  6777. curY = 0;
  6778. for (j = lineStart; j <= i; j++) {
  6779. child = this.getChildAt(j);
  6780. if (this.foldInvisibleItems && !child.visible)
  6781. continue;
  6782. child.setPosition(curX, curY);
  6783. if (j < i) {
  6784. child.setSize(child.width, child.sourceHeight + Math.round(child.sourceHeight * ratio), true);
  6785. curY += Math.ceil(child.height) + this._lineGap;
  6786. }
  6787. else {
  6788. child.setSize(child.width, viewHeight - curY, true);
  6789. }
  6790. if (child.width > maxWidth)
  6791. maxWidth = child.width;
  6792. }
  6793. curX += Math.ceil(maxWidth) + this._columnGap;
  6794. maxWidth = 0;
  6795. j = 0;
  6796. lineStart = i + 1;
  6797. lineSize = 0;
  6798. }
  6799. }
  6800. cw = curX + Math.ceil(maxWidth);
  6801. ch = viewHeight;
  6802. }
  6803. else {
  6804. for (i = 0; i < cnt; i++) {
  6805. child = this.getChildAt(i);
  6806. if (this.foldInvisibleItems && !child.visible)
  6807. continue;
  6808. if (curY != 0)
  6809. curY += this._lineGap;
  6810. if (this._lineCount != 0 && j >= this._lineCount
  6811. || this._lineCount == 0 && curY + child.height > viewHeight && maxWidth != 0) {
  6812. curY = 0;
  6813. curX += Math.ceil(maxWidth) + this._columnGap;
  6814. maxWidth = 0;
  6815. j = 0;
  6816. }
  6817. child.setPosition(curX, curY);
  6818. curY += Math.ceil(child.height);
  6819. if (curY > maxHeight)
  6820. maxHeight = curY;
  6821. if (child.width > maxWidth)
  6822. maxWidth = child.width;
  6823. j++;
  6824. }
  6825. cw = curX + Math.ceil(maxWidth);
  6826. ch = Math.ceil(maxHeight);
  6827. }
  6828. }
  6829. else {
  6830. var eachHeight;
  6831. if (this._autoResizeItem && this._lineCount > 0)
  6832. eachHeight = Math.floor((viewHeight - (this._lineCount - 1) * this._lineGap) / this._lineCount);
  6833. if (this._autoResizeItem && this._columnCount > 0) {
  6834. for (i = 0; i < cnt; i++) {
  6835. child = this.getChildAt(i);
  6836. if (this.foldInvisibleItems && !child.visible)
  6837. continue;
  6838. if (j == 0 && (this._lineCount != 0 && k >= this._lineCount
  6839. || this._lineCount == 0 && curY + (this._lineCount > 0 ? eachHeight : child.height) > viewHeight)) {
  6840. page++;
  6841. curY = 0;
  6842. k = 0;
  6843. }
  6844. lineSize += child.sourceWidth;
  6845. j++;
  6846. if (j == this._columnCount || i == cnt - 1) {
  6847. ratio = (viewWidth - lineSize - (j - 1) * this._columnGap) / lineSize;
  6848. curX = 0;
  6849. for (j = lineStart; j <= i; j++) {
  6850. child = this.getChildAt(j);
  6851. if (this.foldInvisibleItems && !child.visible)
  6852. continue;
  6853. child.setPosition(page * viewWidth + curX, curY);
  6854. if (j < i) {
  6855. child.setSize(child.sourceWidth + Math.round(child.sourceWidth * ratio), this._lineCount > 0 ? eachHeight : child.height, true);
  6856. curX += Math.ceil(child.width) + this._columnGap;
  6857. }
  6858. else {
  6859. child.setSize(viewWidth - curX, this._lineCount > 0 ? eachHeight : child.height, true);
  6860. }
  6861. if (child.height > maxHeight)
  6862. maxHeight = child.height;
  6863. }
  6864. curY += Math.ceil(maxHeight) + this._lineGap;
  6865. maxHeight = 0;
  6866. j = 0;
  6867. lineStart = i + 1;
  6868. lineSize = 0;
  6869. k++;
  6870. }
  6871. }
  6872. }
  6873. else {
  6874. for (i = 0; i < cnt; i++) {
  6875. child = this.getChildAt(i);
  6876. if (this.foldInvisibleItems && !child.visible)
  6877. continue;
  6878. if (curX != 0)
  6879. curX += this._columnGap;
  6880. if (this._autoResizeItem && this._lineCount > 0)
  6881. child.setSize(child.width, eachHeight, true);
  6882. if (this._columnCount != 0 && j >= this._columnCount
  6883. || this._columnCount == 0 && curX + child.width > viewWidth && maxHeight != 0) {
  6884. curX = 0;
  6885. curY += Math.ceil(maxHeight) + this._lineGap;
  6886. maxHeight = 0;
  6887. j = 0;
  6888. k++;
  6889. if (this._lineCount != 0 && k >= this._lineCount
  6890. || this._lineCount == 0 && curY + child.height > viewHeight && maxWidth != 0) {
  6891. page++;
  6892. curY = 0;
  6893. k = 0;
  6894. }
  6895. }
  6896. child.setPosition(page * viewWidth + curX, curY);
  6897. curX += Math.ceil(child.width);
  6898. if (curX > maxWidth)
  6899. maxWidth = curX;
  6900. if (child.height > maxHeight)
  6901. maxHeight = child.height;
  6902. j++;
  6903. }
  6904. }
  6905. ch = page > 0 ? viewHeight : curY + Math.ceil(maxHeight);
  6906. cw = (page + 1) * viewWidth;
  6907. }
  6908. this.handleAlign(cw, ch);
  6909. this.setBounds(0, 0, cw, ch);
  6910. };
  6911. GList.prototype.setup_beforeAdd = function (buffer, beginPos) {
  6912. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  6913. buffer.seek(beginPos, 5);
  6914. this._layout = buffer.readByte();
  6915. this._selectionMode = buffer.readByte();
  6916. this._align = buffer.readByte();
  6917. this._verticalAlign = buffer.readByte();
  6918. this._lineGap = buffer.readShort();
  6919. this._columnGap = buffer.readShort();
  6920. this._lineCount = buffer.readShort();
  6921. this._columnCount = buffer.readShort();
  6922. this._autoResizeItem = buffer.readBool();
  6923. this._childrenRenderOrder = buffer.readByte();
  6924. this._apexIndex = buffer.readShort();
  6925. if (buffer.readBool()) {
  6926. this._margin.top = buffer.readInt();
  6927. this._margin.bottom = buffer.readInt();
  6928. this._margin.left = buffer.readInt();
  6929. this._margin.right = buffer.readInt();
  6930. }
  6931. var overflow = buffer.readByte();
  6932. if (overflow == fgui.OverflowType.Scroll) {
  6933. var savedPos = buffer.position;
  6934. buffer.seek(beginPos, 7);
  6935. this.setupScroll(buffer);
  6936. buffer.position = savedPos;
  6937. }
  6938. else
  6939. this.setupOverflow(overflow);
  6940. if (buffer.readBool())
  6941. buffer.skip(8);
  6942. if (buffer.version >= 2) {
  6943. this.scrollItemToViewOnClick = buffer.readBool();
  6944. this.foldInvisibleItems = buffer.readBool();
  6945. }
  6946. buffer.seek(beginPos, 8);
  6947. this._defaultItem = buffer.readS();
  6948. this.readItems(buffer);
  6949. };
  6950. GList.prototype.readItems = function (buffer) {
  6951. var cnt;
  6952. var i;
  6953. var nextPos;
  6954. var str;
  6955. cnt = buffer.readShort();
  6956. for (i = 0; i < cnt; i++) {
  6957. nextPos = buffer.readShort();
  6958. nextPos += buffer.position;
  6959. str = buffer.readS();
  6960. if (str == null) {
  6961. str = this._defaultItem;
  6962. if (!str) {
  6963. buffer.position = nextPos;
  6964. continue;
  6965. }
  6966. }
  6967. var obj = this.getFromPool(str);
  6968. if (obj) {
  6969. this.addChild(obj);
  6970. this.setupItem(buffer, obj);
  6971. }
  6972. buffer.position = nextPos;
  6973. }
  6974. };
  6975. GList.prototype.setupItem = function (buffer, obj) {
  6976. var str;
  6977. str = buffer.readS();
  6978. if (str != null)
  6979. obj.text = str;
  6980. str = buffer.readS();
  6981. if (str != null && (obj instanceof fgui.GButton))
  6982. obj.selectedTitle = str;
  6983. str = buffer.readS();
  6984. if (str != null)
  6985. obj.icon = str;
  6986. str = buffer.readS();
  6987. if (str != null && (obj instanceof fgui.GButton))
  6988. obj.selectedIcon = str;
  6989. str = buffer.readS();
  6990. if (str != null)
  6991. obj.name = str;
  6992. var cnt;
  6993. var i;
  6994. if (obj instanceof fgui.GComponent) {
  6995. cnt = buffer.readShort();
  6996. for (i = 0; i < cnt; i++) {
  6997. var cc = obj.getController(buffer.readS());
  6998. str = buffer.readS();
  6999. if (cc)
  7000. cc.selectedPageId = str;
  7001. }
  7002. if (buffer.version >= 2) {
  7003. cnt = buffer.readShort();
  7004. for (i = 0; i < cnt; i++) {
  7005. var target = buffer.readS();
  7006. var propertyId = buffer.readShort();
  7007. var value = buffer.readS();
  7008. var obj2 = obj.getChildByPath(target);
  7009. if (obj2)
  7010. obj2.setProp(propertyId, value);
  7011. }
  7012. }
  7013. }
  7014. };
  7015. GList.prototype.setup_afterAdd = function (buffer, beginPos) {
  7016. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  7017. buffer.seek(beginPos, 6);
  7018. var i = buffer.readShort();
  7019. if (i != -1)
  7020. this._selectionController = this.parent.getControllerAt(i);
  7021. };
  7022. return GList;
  7023. }(fgui.GComponent));
  7024. fgui.GList = GList;
  7025. var s_n = 0;
  7026. })(fgui || (fgui = {}));
  7027. (function (fgui) {
  7028. var GObjectPool = (function () {
  7029. function GObjectPool() {
  7030. this._count = 0;
  7031. this._pool = {};
  7032. }
  7033. GObjectPool.prototype.clear = function () {
  7034. for (var i1 in this._pool) {
  7035. var arr = this._pool[i1];
  7036. var cnt = arr.length;
  7037. for (var i = 0; i < cnt; i++)
  7038. arr[i].dispose();
  7039. }
  7040. this._pool = {};
  7041. this._count = 0;
  7042. };
  7043. Object.defineProperty(GObjectPool.prototype, "count", {
  7044. get: function () {
  7045. return this._count;
  7046. },
  7047. enumerable: false,
  7048. configurable: true
  7049. });
  7050. GObjectPool.prototype.getObject = function (url) {
  7051. url = fgui.UIPackage.normalizeURL(url);
  7052. if (url == null)
  7053. return null;
  7054. var arr = this._pool[url];
  7055. if (arr && arr.length) {
  7056. this._count--;
  7057. return arr.shift();
  7058. }
  7059. var child = fgui.UIPackage.createObjectFromURL(url);
  7060. return child;
  7061. };
  7062. GObjectPool.prototype.returnObject = function (obj) {
  7063. var url = obj.resourceURL;
  7064. if (!url)
  7065. return;
  7066. var arr = this._pool[url];
  7067. if (arr == null) {
  7068. arr = new Array();
  7069. this._pool[url] = arr;
  7070. }
  7071. this._count++;
  7072. arr.push(obj);
  7073. };
  7074. return GObjectPool;
  7075. }());
  7076. fgui.GObjectPool = GObjectPool;
  7077. })(fgui || (fgui = {}));
  7078. (function (fgui) {
  7079. var GLoader = (function (_super) {
  7080. __extends(GLoader, _super);
  7081. function GLoader() {
  7082. var _this = _super.call(this) || this;
  7083. _this._frame = 0;
  7084. _this._node.name = "GLoader";
  7085. _this._playing = true;
  7086. _this._url = "";
  7087. _this._fill = fgui.LoaderFillType.None;
  7088. _this._align = fgui.AlignType.Left;
  7089. _this._verticalAlign = fgui.VertAlignType.Top;
  7090. _this._showErrorSign = true;
  7091. _this._color = new cc.Color(255, 255, 255, 255);
  7092. _this._container = new cc.Node("Image");
  7093. _this._container.setAnchorPoint(0, 1);
  7094. _this._node.addChild(_this._container);
  7095. _this._content = _this._container.addComponent(fgui.MovieClip);
  7096. _this._content.sizeMode = cc.Sprite.SizeMode.CUSTOM;
  7097. _this._content.trim = false;
  7098. _this._content.setPlaySettings();
  7099. return _this;
  7100. }
  7101. GLoader.prototype.dispose = function () {
  7102. if (this._contentItem == null) {
  7103. if (this._content.spriteFrame)
  7104. this.freeExternal(this._content.spriteFrame);
  7105. }
  7106. if (this._content2)
  7107. this._content2.dispose();
  7108. _super.prototype.dispose.call(this);
  7109. };
  7110. Object.defineProperty(GLoader.prototype, "url", {
  7111. get: function () {
  7112. return this._url;
  7113. },
  7114. set: function (value) {
  7115. if (this._url == value)
  7116. return;
  7117. this._url = value;
  7118. this.loadContent();
  7119. this.updateGear(7);
  7120. },
  7121. enumerable: false,
  7122. configurable: true
  7123. });
  7124. Object.defineProperty(GLoader.prototype, "icon", {
  7125. get: function () {
  7126. return this._url;
  7127. },
  7128. set: function (value) {
  7129. this.url = value;
  7130. },
  7131. enumerable: false,
  7132. configurable: true
  7133. });
  7134. Object.defineProperty(GLoader.prototype, "align", {
  7135. get: function () {
  7136. return this._align;
  7137. },
  7138. set: function (value) {
  7139. if (this._align != value) {
  7140. this._align = value;
  7141. this.updateLayout();
  7142. }
  7143. },
  7144. enumerable: false,
  7145. configurable: true
  7146. });
  7147. Object.defineProperty(GLoader.prototype, "verticalAlign", {
  7148. get: function () {
  7149. return this._verticalAlign;
  7150. },
  7151. set: function (value) {
  7152. if (this._verticalAlign != value) {
  7153. this._verticalAlign = value;
  7154. this.updateLayout();
  7155. }
  7156. },
  7157. enumerable: false,
  7158. configurable: true
  7159. });
  7160. Object.defineProperty(GLoader.prototype, "fill", {
  7161. get: function () {
  7162. return this._fill;
  7163. },
  7164. set: function (value) {
  7165. if (this._fill != value) {
  7166. this._fill = value;
  7167. this.updateLayout();
  7168. }
  7169. },
  7170. enumerable: false,
  7171. configurable: true
  7172. });
  7173. Object.defineProperty(GLoader.prototype, "shrinkOnly", {
  7174. get: function () {
  7175. return this._shrinkOnly;
  7176. },
  7177. set: function (value) {
  7178. if (this._shrinkOnly != value) {
  7179. this._shrinkOnly = value;
  7180. this.updateLayout();
  7181. }
  7182. },
  7183. enumerable: false,
  7184. configurable: true
  7185. });
  7186. Object.defineProperty(GLoader.prototype, "autoSize", {
  7187. get: function () {
  7188. return this._autoSize;
  7189. },
  7190. set: function (value) {
  7191. if (this._autoSize != value) {
  7192. this._autoSize = value;
  7193. this.updateLayout();
  7194. }
  7195. },
  7196. enumerable: false,
  7197. configurable: true
  7198. });
  7199. Object.defineProperty(GLoader.prototype, "playing", {
  7200. get: function () {
  7201. return this._playing;
  7202. },
  7203. set: function (value) {
  7204. if (this._playing != value) {
  7205. this._playing = value;
  7206. if (this._content instanceof fgui.MovieClip)
  7207. this._content.playing = value;
  7208. this.updateGear(5);
  7209. }
  7210. },
  7211. enumerable: false,
  7212. configurable: true
  7213. });
  7214. Object.defineProperty(GLoader.prototype, "frame", {
  7215. get: function () {
  7216. return this._frame;
  7217. },
  7218. set: function (value) {
  7219. if (this._frame != value) {
  7220. this._frame = value;
  7221. if (this._content instanceof fgui.MovieClip)
  7222. this._content.frame = value;
  7223. this.updateGear(5);
  7224. }
  7225. },
  7226. enumerable: false,
  7227. configurable: true
  7228. });
  7229. Object.defineProperty(GLoader.prototype, "color", {
  7230. get: function () {
  7231. return this._color;
  7232. },
  7233. set: function (value) {
  7234. this._color.set(value);
  7235. this.updateGear(4);
  7236. this._container.color = value;
  7237. },
  7238. enumerable: false,
  7239. configurable: true
  7240. });
  7241. Object.defineProperty(GLoader.prototype, "fillMethod", {
  7242. get: function () {
  7243. return this._content.fillMethod;
  7244. },
  7245. set: function (value) {
  7246. this._content.fillMethod = value;
  7247. },
  7248. enumerable: false,
  7249. configurable: true
  7250. });
  7251. Object.defineProperty(GLoader.prototype, "fillOrigin", {
  7252. get: function () {
  7253. return this._content.fillOrigin;
  7254. },
  7255. set: function (value) {
  7256. this._content.fillOrigin = value;
  7257. },
  7258. enumerable: false,
  7259. configurable: true
  7260. });
  7261. Object.defineProperty(GLoader.prototype, "fillClockwise", {
  7262. get: function () {
  7263. return this._content.fillClockwise;
  7264. },
  7265. set: function (value) {
  7266. this._content.fillClockwise = value;
  7267. },
  7268. enumerable: false,
  7269. configurable: true
  7270. });
  7271. Object.defineProperty(GLoader.prototype, "fillAmount", {
  7272. get: function () {
  7273. return this._content.fillAmount;
  7274. },
  7275. set: function (value) {
  7276. this._content.fillAmount = value;
  7277. },
  7278. enumerable: false,
  7279. configurable: true
  7280. });
  7281. Object.defineProperty(GLoader.prototype, "showErrorSign", {
  7282. get: function () {
  7283. return this._showErrorSign;
  7284. },
  7285. set: function (value) {
  7286. this._showErrorSign = value;
  7287. },
  7288. enumerable: false,
  7289. configurable: true
  7290. });
  7291. Object.defineProperty(GLoader.prototype, "component", {
  7292. get: function () {
  7293. return this._content2;
  7294. },
  7295. enumerable: false,
  7296. configurable: true
  7297. });
  7298. Object.defineProperty(GLoader.prototype, "texture", {
  7299. get: function () {
  7300. return this._content.spriteFrame;
  7301. },
  7302. set: function (value) {
  7303. this.url = null;
  7304. this._content.spriteFrame = value;
  7305. this._content.type = cc.Sprite.Type.SIMPLE;
  7306. if (value != null) {
  7307. this.sourceWidth = value.getRect().width;
  7308. this.sourceHeight = value.getRect().height;
  7309. }
  7310. else {
  7311. this.sourceWidth = this.sourceHeight = 0;
  7312. }
  7313. this.updateLayout();
  7314. },
  7315. enumerable: false,
  7316. configurable: true
  7317. });
  7318. GLoader.prototype.loadContent = function () {
  7319. this.clearContent();
  7320. if (!this._url)
  7321. return;
  7322. if (fgui.ToolSet.startsWith(this._url, "ui://"))
  7323. this.loadFromPackage(this._url);
  7324. else
  7325. this.loadExternal();
  7326. };
  7327. GLoader.prototype.loadFromPackage = function (itemURL) {
  7328. this._contentItem = fgui.UIPackage.getItemByURL(itemURL);
  7329. if (this._contentItem) {
  7330. this._contentItem = this._contentItem.getBranch();
  7331. this.sourceWidth = this._contentItem.width;
  7332. this.sourceHeight = this._contentItem.height;
  7333. this._contentItem = this._contentItem.getHighResolution();
  7334. this._contentItem.load();
  7335. if (this._autoSize)
  7336. this.setSize(this.sourceWidth, this.sourceHeight);
  7337. if (this._contentItem.type == fgui.PackageItemType.Image) {
  7338. if (!this._contentItem.asset) {
  7339. this.setErrorState();
  7340. }
  7341. else {
  7342. this._content.spriteFrame = this._contentItem.asset;
  7343. if (this._content.fillMethod == 0) {
  7344. if (this._contentItem.scale9Grid)
  7345. this._content.type = cc.Sprite.Type.SLICED;
  7346. else if (this._contentItem.scaleByTile)
  7347. this._content.type = cc.Sprite.Type.TILED;
  7348. else
  7349. this._content.type = cc.Sprite.Type.SIMPLE;
  7350. }
  7351. this.updateLayout();
  7352. }
  7353. }
  7354. else if (this._contentItem.type == fgui.PackageItemType.MovieClip) {
  7355. this._content.interval = this._contentItem.interval;
  7356. this._content.swing = this._contentItem.swing;
  7357. this._content.repeatDelay = this._contentItem.repeatDelay;
  7358. this._content.frames = this._contentItem.frames;
  7359. this.updateLayout();
  7360. }
  7361. else if (this._contentItem.type == fgui.PackageItemType.Component) {
  7362. var obj = fgui.UIPackage.createObjectFromURL(itemURL);
  7363. if (!obj)
  7364. this.setErrorState();
  7365. else if (!(obj instanceof fgui.GComponent)) {
  7366. obj.dispose();
  7367. this.setErrorState();
  7368. }
  7369. else {
  7370. this._content2 = obj;
  7371. this._container.addChild(this._content2.node);
  7372. this.updateLayout();
  7373. }
  7374. }
  7375. else
  7376. this.setErrorState();
  7377. }
  7378. else
  7379. this.setErrorState();
  7380. };
  7381. GLoader.prototype.loadExternal = function () {
  7382. var _this = this;
  7383. var url = this.url;
  7384. var callback = function (err, asset) {
  7385. if (_this._url != url || !cc.isValid(_this._node))
  7386. return;
  7387. if (err)
  7388. console.warn(err);
  7389. if (asset instanceof cc.SpriteFrame)
  7390. _this.onExternalLoadSuccess(asset);
  7391. else if (asset instanceof cc.Texture2D)
  7392. _this.onExternalLoadSuccess(new cc.SpriteFrame(asset));
  7393. };
  7394. if (fgui.ToolSet.startsWith(this._url, "http://")
  7395. || fgui.ToolSet.startsWith(this._url, "https://")
  7396. || fgui.ToolSet.startsWith(this._url, '/'))
  7397. cc.assetManager.loadRemote(this._url, callback);
  7398. else
  7399. cc.resources.load(this._url, cc.Asset, callback);
  7400. };
  7401. GLoader.prototype.freeExternal = function (texture) {
  7402. };
  7403. GLoader.prototype.onExternalLoadSuccess = function (texture) {
  7404. this._content.spriteFrame = texture;
  7405. this._content.type = cc.Sprite.Type.SIMPLE;
  7406. this.sourceWidth = texture.getRect().width;
  7407. this.sourceHeight = texture.getRect().height;
  7408. if (this._autoSize)
  7409. this.setSize(this.sourceWidth, this.sourceHeight);
  7410. this.updateLayout();
  7411. };
  7412. GLoader.prototype.onExternalLoadFailed = function () {
  7413. this.setErrorState();
  7414. };
  7415. GLoader.prototype.setErrorState = function () {
  7416. if (!this._showErrorSign)
  7417. return;
  7418. if (this._errorSign == null) {
  7419. if (fgui.UIConfig.loaderErrorSign != null) {
  7420. this._errorSign = GLoader._errorSignPool.getObject(fgui.UIConfig.loaderErrorSign);
  7421. }
  7422. }
  7423. if (this._errorSign) {
  7424. this._errorSign.setSize(this.width, this.height);
  7425. this._container.addChild(this._errorSign.node);
  7426. }
  7427. };
  7428. GLoader.prototype.clearErrorState = function () {
  7429. if (this._errorSign) {
  7430. this._container.removeChild(this._errorSign.node);
  7431. GLoader._errorSignPool.returnObject(this._errorSign);
  7432. this._errorSign = null;
  7433. }
  7434. };
  7435. GLoader.prototype.updateLayout = function () {
  7436. if (this._content2 == null && this._content == null) {
  7437. if (this._autoSize) {
  7438. this._updatingLayout = true;
  7439. this.setSize(50, 30);
  7440. this._updatingLayout = false;
  7441. }
  7442. return;
  7443. }
  7444. var cw = this.sourceWidth;
  7445. var ch = this.sourceHeight;
  7446. var pivotCorrectX = -this.pivotX * this._width;
  7447. var pivotCorrectY = this.pivotY * this._height;
  7448. if (this._autoSize) {
  7449. this._updatingLayout = true;
  7450. if (cw == 0)
  7451. cw = 50;
  7452. if (ch == 0)
  7453. ch = 30;
  7454. this.setSize(cw, ch);
  7455. this._updatingLayout = false;
  7456. this._container.setContentSize(this._width, this._height);
  7457. this._container.setPosition(pivotCorrectX, pivotCorrectY);
  7458. if (this._content2) {
  7459. this._content2.setPosition(pivotCorrectX + this._width * this.pivotX, pivotCorrectY - this._height * this.pivotY);
  7460. this._content2.setScale(1, 1);
  7461. }
  7462. if (cw == this._width && ch == this._height)
  7463. return;
  7464. }
  7465. var sx = 1, sy = 1;
  7466. if (this._fill != fgui.LoaderFillType.None) {
  7467. sx = this.width / this.sourceWidth;
  7468. sy = this.height / this.sourceHeight;
  7469. if (sx != 1 || sy != 1) {
  7470. if (this._fill == fgui.LoaderFillType.ScaleMatchHeight)
  7471. sx = sy;
  7472. else if (this._fill == fgui.LoaderFillType.ScaleMatchWidth)
  7473. sy = sx;
  7474. else if (this._fill == fgui.LoaderFillType.Scale) {
  7475. if (sx > sy)
  7476. sx = sy;
  7477. else
  7478. sy = sx;
  7479. }
  7480. else if (this._fill == fgui.LoaderFillType.ScaleNoBorder) {
  7481. if (sx > sy)
  7482. sy = sx;
  7483. else
  7484. sx = sy;
  7485. }
  7486. if (this._shrinkOnly) {
  7487. if (sx > 1)
  7488. sx = 1;
  7489. if (sy > 1)
  7490. sy = 1;
  7491. }
  7492. cw = this.sourceWidth * sx;
  7493. ch = this.sourceHeight * sy;
  7494. }
  7495. }
  7496. this._container.setContentSize(cw, ch);
  7497. if (this._content2) {
  7498. this._content2.setPosition(pivotCorrectX + this._width * this.pivotX, pivotCorrectY - this._height * this.pivotY);
  7499. this._content2.setScale(sx, sy);
  7500. }
  7501. var nx, ny;
  7502. if (this._align == fgui.AlignType.Left)
  7503. nx = 0;
  7504. else if (this._align == fgui.AlignType.Center)
  7505. nx = Math.floor((this._width - cw) / 2);
  7506. else
  7507. nx = this._width - cw;
  7508. if (this._verticalAlign == fgui.VertAlignType.Top)
  7509. ny = 0;
  7510. else if (this._verticalAlign == fgui.VertAlignType.Middle)
  7511. ny = Math.floor((this._height - ch) / 2);
  7512. else
  7513. ny = this._height - ch;
  7514. ny = -ny;
  7515. this._container.setPosition(pivotCorrectX + nx, pivotCorrectY + ny);
  7516. };
  7517. GLoader.prototype.clearContent = function () {
  7518. this.clearErrorState();
  7519. if (!this._contentItem) {
  7520. var texture = this._content.spriteFrame;
  7521. if (texture)
  7522. this.freeExternal(texture);
  7523. }
  7524. if (this._content2) {
  7525. this._container.removeChild(this._content2.node);
  7526. this._content2.dispose();
  7527. this._content2 = null;
  7528. }
  7529. this._content.frames = null;
  7530. this._content.spriteFrame = null;
  7531. this._contentItem = null;
  7532. };
  7533. GLoader.prototype.handleSizeChanged = function () {
  7534. _super.prototype.handleSizeChanged.call(this);
  7535. if (!this._updatingLayout)
  7536. this.updateLayout();
  7537. };
  7538. GLoader.prototype.handleAnchorChanged = function () {
  7539. _super.prototype.handleAnchorChanged.call(this);
  7540. if (!this._updatingLayout)
  7541. this.updateLayout();
  7542. };
  7543. GLoader.prototype.handleGrayedChanged = function () {
  7544. this._content.grayed = this._grayed;
  7545. };
  7546. GLoader.prototype._hitTest = function (pt, globalPt) {
  7547. if (this._content2) {
  7548. var obj = this._content2.hitTest(globalPt);
  7549. if (obj)
  7550. return obj;
  7551. }
  7552. if (pt.x >= 0 && pt.y >= 0 && pt.x < this._width && pt.y < this._height)
  7553. return this;
  7554. else
  7555. return null;
  7556. };
  7557. GLoader.prototype.getProp = function (index) {
  7558. switch (index) {
  7559. case fgui.ObjectPropID.Color:
  7560. return this.color;
  7561. case fgui.ObjectPropID.Playing:
  7562. return this.playing;
  7563. case fgui.ObjectPropID.Frame:
  7564. return this.frame;
  7565. case fgui.ObjectPropID.TimeScale:
  7566. return this._content.timeScale;
  7567. default:
  7568. return _super.prototype.getProp.call(this, index);
  7569. }
  7570. };
  7571. GLoader.prototype.setProp = function (index, value) {
  7572. switch (index) {
  7573. case fgui.ObjectPropID.Color:
  7574. this.color = value;
  7575. break;
  7576. case fgui.ObjectPropID.Playing:
  7577. this.playing = value;
  7578. break;
  7579. case fgui.ObjectPropID.Frame:
  7580. this.frame = value;
  7581. break;
  7582. case fgui.ObjectPropID.TimeScale:
  7583. this._content.timeScale = value;
  7584. break;
  7585. case fgui.ObjectPropID.DeltaTime:
  7586. this._content.advance(value);
  7587. break;
  7588. default:
  7589. _super.prototype.setProp.call(this, index, value);
  7590. break;
  7591. }
  7592. };
  7593. GLoader.prototype.setup_beforeAdd = function (buffer, beginPos) {
  7594. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  7595. buffer.seek(beginPos, 5);
  7596. this._url = buffer.readS();
  7597. this._align = buffer.readByte();
  7598. this._verticalAlign = buffer.readByte();
  7599. this._fill = buffer.readByte();
  7600. this._shrinkOnly = buffer.readBool();
  7601. this._autoSize = buffer.readBool();
  7602. this._showErrorSign = buffer.readBool();
  7603. this._playing = buffer.readBool();
  7604. this._frame = buffer.readInt();
  7605. if (buffer.readBool())
  7606. this.color = buffer.readColor();
  7607. this._content.fillMethod = buffer.readByte();
  7608. if (this._content.fillMethod != 0) {
  7609. this._content.fillOrigin = buffer.readByte();
  7610. this._content.fillClockwise = buffer.readBool();
  7611. this._content.fillAmount = buffer.readFloat();
  7612. }
  7613. if (this._url)
  7614. this.loadContent();
  7615. };
  7616. GLoader._errorSignPool = new fgui.GObjectPool();
  7617. return GLoader;
  7618. }(fgui.GObject));
  7619. fgui.GLoader = GLoader;
  7620. })(fgui || (fgui = {}));
  7621. (function (fgui) {
  7622. var GLoader3D = (function (_super) {
  7623. __extends(GLoader3D, _super);
  7624. function GLoader3D() {
  7625. var _this = _super.call(this) || this;
  7626. _this._frame = 0;
  7627. _this._node.name = "GLoader3D";
  7628. _this._playing = true;
  7629. _this._url = "";
  7630. _this._fill = fgui.LoaderFillType.None;
  7631. _this._align = fgui.AlignType.Left;
  7632. _this._verticalAlign = fgui.VertAlignType.Top;
  7633. _this._color = new cc.Color(255, 255, 255, 255);
  7634. _this._container = new cc.Node("Wrapper");
  7635. _this._container.setAnchorPoint(0, 1);
  7636. _this._node.addChild(_this._container);
  7637. return _this;
  7638. }
  7639. GLoader3D.prototype.dispose = function () {
  7640. _super.prototype.dispose.call(this);
  7641. };
  7642. Object.defineProperty(GLoader3D.prototype, "url", {
  7643. get: function () {
  7644. return this._url;
  7645. },
  7646. set: function (value) {
  7647. if (this._url == value)
  7648. return;
  7649. this._url = value;
  7650. this.loadContent();
  7651. this.updateGear(7);
  7652. },
  7653. enumerable: false,
  7654. configurable: true
  7655. });
  7656. Object.defineProperty(GLoader3D.prototype, "icon", {
  7657. get: function () {
  7658. return this._url;
  7659. },
  7660. set: function (value) {
  7661. this.url = value;
  7662. },
  7663. enumerable: false,
  7664. configurable: true
  7665. });
  7666. Object.defineProperty(GLoader3D.prototype, "align", {
  7667. get: function () {
  7668. return this._align;
  7669. },
  7670. set: function (value) {
  7671. if (this._align != value) {
  7672. this._align = value;
  7673. this.updateLayout();
  7674. }
  7675. },
  7676. enumerable: false,
  7677. configurable: true
  7678. });
  7679. Object.defineProperty(GLoader3D.prototype, "verticalAlign", {
  7680. get: function () {
  7681. return this._verticalAlign;
  7682. },
  7683. set: function (value) {
  7684. if (this._verticalAlign != value) {
  7685. this._verticalAlign = value;
  7686. this.updateLayout();
  7687. }
  7688. },
  7689. enumerable: false,
  7690. configurable: true
  7691. });
  7692. Object.defineProperty(GLoader3D.prototype, "fill", {
  7693. get: function () {
  7694. return this._fill;
  7695. },
  7696. set: function (value) {
  7697. if (this._fill != value) {
  7698. this._fill = value;
  7699. this.updateLayout();
  7700. }
  7701. },
  7702. enumerable: false,
  7703. configurable: true
  7704. });
  7705. Object.defineProperty(GLoader3D.prototype, "shrinkOnly", {
  7706. get: function () {
  7707. return this._shrinkOnly;
  7708. },
  7709. set: function (value) {
  7710. if (this._shrinkOnly != value) {
  7711. this._shrinkOnly = value;
  7712. this.updateLayout();
  7713. }
  7714. },
  7715. enumerable: false,
  7716. configurable: true
  7717. });
  7718. Object.defineProperty(GLoader3D.prototype, "autoSize", {
  7719. get: function () {
  7720. return this._autoSize;
  7721. },
  7722. set: function (value) {
  7723. if (this._autoSize != value) {
  7724. this._autoSize = value;
  7725. this.updateLayout();
  7726. }
  7727. },
  7728. enumerable: false,
  7729. configurable: true
  7730. });
  7731. Object.defineProperty(GLoader3D.prototype, "playing", {
  7732. get: function () {
  7733. return this._playing;
  7734. },
  7735. set: function (value) {
  7736. if (this._playing != value) {
  7737. this._playing = value;
  7738. this.updateGear(5);
  7739. this.onChange();
  7740. }
  7741. },
  7742. enumerable: false,
  7743. configurable: true
  7744. });
  7745. Object.defineProperty(GLoader3D.prototype, "frame", {
  7746. get: function () {
  7747. return this._frame;
  7748. },
  7749. set: function (value) {
  7750. if (this._frame != value) {
  7751. this._frame = value;
  7752. this.updateGear(5);
  7753. this.onChange();
  7754. }
  7755. },
  7756. enumerable: false,
  7757. configurable: true
  7758. });
  7759. Object.defineProperty(GLoader3D.prototype, "animationName", {
  7760. get: function () {
  7761. return this._animationName;
  7762. },
  7763. set: function (value) {
  7764. if (this._animationName != value) {
  7765. this._animationName = value;
  7766. this.onChange();
  7767. }
  7768. },
  7769. enumerable: false,
  7770. configurable: true
  7771. });
  7772. Object.defineProperty(GLoader3D.prototype, "skinName", {
  7773. get: function () {
  7774. return this._skinName;
  7775. },
  7776. set: function (value) {
  7777. if (this._skinName != value) {
  7778. this._skinName = value;
  7779. this.onChange();
  7780. }
  7781. },
  7782. enumerable: false,
  7783. configurable: true
  7784. });
  7785. Object.defineProperty(GLoader3D.prototype, "loop", {
  7786. get: function () {
  7787. return this._loop;
  7788. },
  7789. set: function (value) {
  7790. if (this._loop != value) {
  7791. this._loop = value;
  7792. this.onChange();
  7793. }
  7794. },
  7795. enumerable: false,
  7796. configurable: true
  7797. });
  7798. Object.defineProperty(GLoader3D.prototype, "color", {
  7799. get: function () {
  7800. return this._color;
  7801. },
  7802. set: function (value) {
  7803. this._color.set(value);
  7804. this.updateGear(4);
  7805. if (this._content)
  7806. this._content.node.color = value;
  7807. },
  7808. enumerable: false,
  7809. configurable: true
  7810. });
  7811. Object.defineProperty(GLoader3D.prototype, "content", {
  7812. get: function () {
  7813. return this._content;
  7814. },
  7815. enumerable: false,
  7816. configurable: true
  7817. });
  7818. GLoader3D.prototype.loadContent = function () {
  7819. this.clearContent();
  7820. if (!this._url)
  7821. return;
  7822. if (fgui.ToolSet.startsWith(this._url, "ui://"))
  7823. this.loadFromPackage(this._url);
  7824. else
  7825. this.loadExternal();
  7826. };
  7827. GLoader3D.prototype.loadFromPackage = function (itemURL) {
  7828. this._contentItem = fgui.UIPackage.getItemByURL(itemURL);
  7829. if (this._contentItem) {
  7830. this._contentItem = this._contentItem.getBranch();
  7831. this.sourceWidth = this._contentItem.width;
  7832. this.sourceHeight = this._contentItem.height;
  7833. this._contentItem = this._contentItem.getHighResolution();
  7834. if (this._autoSize)
  7835. this.setSize(this.sourceWidth, this.sourceHeight);
  7836. if (this._contentItem.type == fgui.PackageItemType.Spine || this._contentItem.type == fgui.PackageItemType.DragonBones)
  7837. this._contentItem.owner.getItemAssetAsync(this._contentItem, this.onLoaded.bind(this));
  7838. }
  7839. };
  7840. GLoader3D.prototype.onLoaded = function (err, item) {
  7841. if (this._contentItem != item)
  7842. return;
  7843. if (err)
  7844. console.warn(err);
  7845. if (!this._contentItem.asset)
  7846. return;
  7847. if (this._contentItem.type == fgui.PackageItemType.Spine)
  7848. this.setSpine(this._contentItem.asset, this._contentItem.skeletonAnchor);
  7849. else if (this._contentItem.type == fgui.PackageItemType.DragonBones)
  7850. this.setDragonBones(this._contentItem.asset, this._contentItem.atlasAsset, this._contentItem.skeletonAnchor);
  7851. };
  7852. GLoader3D.prototype.setSpine = function (asset, anchor, pma) {
  7853. this.url = null;
  7854. this.clearContent();
  7855. var node = new cc.Node();
  7856. node.color = this._color;
  7857. this._container.addChild(node);
  7858. node.setPosition(anchor.x, -anchor.y);
  7859. this._content = node.addComponent(sp.Skeleton);
  7860. this._content.premultipliedAlpha = pma;
  7861. this._content.skeletonData = asset;
  7862. this.onChangeSpine();
  7863. this.updateLayout();
  7864. };
  7865. GLoader3D.prototype.setDragonBones = function (asset, atlasAsset, anchor, pma) {
  7866. this.url = null;
  7867. this.clearContent();
  7868. var node = new cc.Node();
  7869. node.color = this._color;
  7870. this._container.addChild(node);
  7871. node.setPosition(anchor.x, -anchor.y);
  7872. this._content = node.addComponent(dragonBones.ArmatureDisplay);
  7873. this._content.premultipliedAlpha = pma;
  7874. this._content.dragonAsset = asset;
  7875. this._content.dragonAtlasAsset = atlasAsset;
  7876. var armatureKey = asset["init"](dragonBones.CCFactory.getInstance(), atlasAsset["_uuid"]);
  7877. var dragonBonesData = this._content["_factory"].getDragonBonesData(armatureKey);
  7878. this._content.armatureName = dragonBonesData.armatureNames[0];
  7879. this.onChangeDragonBones();
  7880. this.updateLayout();
  7881. };
  7882. GLoader3D.prototype.onChange = function () {
  7883. this.onChangeSpine();
  7884. this.onChangeDragonBones();
  7885. };
  7886. GLoader3D.prototype.onChangeSpine = function () {
  7887. if (!(this._content instanceof sp.Skeleton))
  7888. return;
  7889. if (this._animationName) {
  7890. var trackEntry = this._content.getCurrent(0);
  7891. if (!trackEntry || trackEntry.animation.name != this._animationName || trackEntry.isComplete() && !trackEntry.loop) {
  7892. this._content.defaultAnimation = this._animationName;
  7893. trackEntry = this._content.setAnimation(0, this._animationName, this._loop);
  7894. }
  7895. if (this._playing)
  7896. this._content.paused = false;
  7897. else {
  7898. this._content.paused = true;
  7899. trackEntry.trackTime = fgui.ToolSet.lerp(0, trackEntry.animationEnd - trackEntry.animationStart, this._frame / 100);
  7900. }
  7901. }
  7902. else
  7903. this._content.clearTrack(0);
  7904. var skin = this._skinName || this._content.skeletonData.getRuntimeData().skins[0].name;
  7905. if (this._content["_skeleton"].skin != skin)
  7906. this._content.setSkin(skin);
  7907. };
  7908. GLoader3D.prototype.onChangeDragonBones = function () {
  7909. if (!(this._content instanceof dragonBones.ArmatureDisplay))
  7910. return;
  7911. if (this._animationName) {
  7912. if (this._playing)
  7913. this._content.playAnimation(this._animationName, this._loop ? 0 : 1);
  7914. else
  7915. this._content.armature().animation.gotoAndStopByFrame(this._animationName, this._frame);
  7916. }
  7917. else
  7918. this._content.armature().animation.reset();
  7919. };
  7920. GLoader3D.prototype.loadExternal = function () {
  7921. if (fgui.ToolSet.startsWith(this._url, "http://")
  7922. || fgui.ToolSet.startsWith(this._url, "https://")
  7923. || fgui.ToolSet.startsWith(this._url, '/'))
  7924. cc.assetManager.loadRemote(this._url, sp.SkeletonData, this.onLoaded2.bind(this));
  7925. else
  7926. cc.resources.load(this._url, sp.SkeletonData, this.onLoaded2.bind(this));
  7927. };
  7928. GLoader3D.prototype.onLoaded2 = function (err, asset) {
  7929. if (!this._url || !cc.isValid(this._node))
  7930. return;
  7931. if (err)
  7932. console.warn(err);
  7933. };
  7934. GLoader3D.prototype.updateLayout = function () {
  7935. var cw = this.sourceWidth;
  7936. var ch = this.sourceHeight;
  7937. var pivotCorrectX = -this.pivotX * this._width;
  7938. var pivotCorrectY = this.pivotY * this._height;
  7939. if (this._autoSize) {
  7940. this._updatingLayout = true;
  7941. if (cw == 0)
  7942. cw = 50;
  7943. if (ch == 0)
  7944. ch = 30;
  7945. this.setSize(cw, ch);
  7946. this._updatingLayout = false;
  7947. if (cw == this._width && ch == this._height) {
  7948. this._container.setScale(1, 1);
  7949. this._container.setPosition(pivotCorrectX, pivotCorrectY);
  7950. return;
  7951. }
  7952. }
  7953. var sx = 1, sy = 1;
  7954. if (this._fill != fgui.LoaderFillType.None) {
  7955. sx = this.width / this.sourceWidth;
  7956. sy = this.height / this.sourceHeight;
  7957. if (sx != 1 || sy != 1) {
  7958. if (this._fill == fgui.LoaderFillType.ScaleMatchHeight)
  7959. sx = sy;
  7960. else if (this._fill == fgui.LoaderFillType.ScaleMatchWidth)
  7961. sy = sx;
  7962. else if (this._fill == fgui.LoaderFillType.Scale) {
  7963. if (sx > sy)
  7964. sx = sy;
  7965. else
  7966. sy = sx;
  7967. }
  7968. else if (this._fill == fgui.LoaderFillType.ScaleNoBorder) {
  7969. if (sx > sy)
  7970. sy = sx;
  7971. else
  7972. sx = sy;
  7973. }
  7974. if (this._shrinkOnly) {
  7975. if (sx > 1)
  7976. sx = 1;
  7977. if (sy > 1)
  7978. sy = 1;
  7979. }
  7980. cw = this.sourceWidth * sx;
  7981. ch = this.sourceHeight * sy;
  7982. }
  7983. }
  7984. this._container.setScale(sx, sy);
  7985. var nx, ny;
  7986. if (this._align == fgui.AlignType.Left)
  7987. nx = 0;
  7988. else if (this._align == fgui.AlignType.Center)
  7989. nx = Math.floor((this._width - cw) / 2);
  7990. else
  7991. nx = this._width - cw;
  7992. if (this._verticalAlign == fgui.VertAlignType.Top)
  7993. ny = 0;
  7994. else if (this._verticalAlign == fgui.VertAlignType.Middle)
  7995. ny = Math.floor((this._height - ch) / 2);
  7996. else
  7997. ny = this._height - ch;
  7998. ny = -ny;
  7999. this._container.setPosition(pivotCorrectX + nx, pivotCorrectY + ny);
  8000. };
  8001. GLoader3D.prototype.clearContent = function () {
  8002. this._contentItem = null;
  8003. if (this._content) {
  8004. this._content.node.destroy();
  8005. this._content = null;
  8006. }
  8007. };
  8008. GLoader3D.prototype.handleSizeChanged = function () {
  8009. _super.prototype.handleSizeChanged.call(this);
  8010. if (!this._updatingLayout)
  8011. this.updateLayout();
  8012. };
  8013. GLoader3D.prototype.handleAnchorChanged = function () {
  8014. _super.prototype.handleAnchorChanged.call(this);
  8015. if (!this._updatingLayout)
  8016. this.updateLayout();
  8017. };
  8018. GLoader3D.prototype.handleGrayedChanged = function () {
  8019. };
  8020. GLoader3D.prototype.getProp = function (index) {
  8021. switch (index) {
  8022. case fgui.ObjectPropID.Color:
  8023. return this.color;
  8024. case fgui.ObjectPropID.Playing:
  8025. return this.playing;
  8026. case fgui.ObjectPropID.Frame:
  8027. return this.frame;
  8028. case fgui.ObjectPropID.TimeScale:
  8029. return 1;
  8030. default:
  8031. return _super.prototype.getProp.call(this, index);
  8032. }
  8033. };
  8034. GLoader3D.prototype.setProp = function (index, value) {
  8035. switch (index) {
  8036. case fgui.ObjectPropID.Color:
  8037. this.color = value;
  8038. break;
  8039. case fgui.ObjectPropID.Playing:
  8040. this.playing = value;
  8041. break;
  8042. case fgui.ObjectPropID.Frame:
  8043. this.frame = value;
  8044. break;
  8045. case fgui.ObjectPropID.TimeScale:
  8046. break;
  8047. case fgui.ObjectPropID.DeltaTime:
  8048. break;
  8049. default:
  8050. _super.prototype.setProp.call(this, index, value);
  8051. break;
  8052. }
  8053. };
  8054. GLoader3D.prototype.setup_beforeAdd = function (buffer, beginPos) {
  8055. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  8056. buffer.seek(beginPos, 5);
  8057. this._url = buffer.readS();
  8058. this._align = buffer.readByte();
  8059. this._verticalAlign = buffer.readByte();
  8060. this._fill = buffer.readByte();
  8061. this._shrinkOnly = buffer.readBool();
  8062. this._autoSize = buffer.readBool();
  8063. this._animationName = buffer.readS();
  8064. this._skinName = buffer.readS();
  8065. this._playing = buffer.readBool();
  8066. this._frame = buffer.readInt();
  8067. this._loop = buffer.readBool();
  8068. if (buffer.readBool())
  8069. this.color = buffer.readColor();
  8070. if (this._url)
  8071. this.loadContent();
  8072. };
  8073. return GLoader3D;
  8074. }(fgui.GObject));
  8075. fgui.GLoader3D = GLoader3D;
  8076. })(fgui || (fgui = {}));
  8077. (function (fgui) {
  8078. var GMovieClip = (function (_super) {
  8079. __extends(GMovieClip, _super);
  8080. function GMovieClip() {
  8081. var _this = _super.call(this) || this;
  8082. _this._node.name = "GMovieClip";
  8083. _this._touchDisabled = true;
  8084. _this._content = _this._node.addComponent(fgui.MovieClip);
  8085. _this._content.sizeMode = cc.Sprite.SizeMode.CUSTOM;
  8086. _this._content.trim = false;
  8087. _this._content.setPlaySettings();
  8088. return _this;
  8089. }
  8090. Object.defineProperty(GMovieClip.prototype, "color", {
  8091. get: function () {
  8092. return this._node.color;
  8093. },
  8094. set: function (value) {
  8095. this._node.color = value;
  8096. this.updateGear(4);
  8097. },
  8098. enumerable: false,
  8099. configurable: true
  8100. });
  8101. Object.defineProperty(GMovieClip.prototype, "playing", {
  8102. get: function () {
  8103. return this._content.playing;
  8104. },
  8105. set: function (value) {
  8106. if (this._content.playing != value) {
  8107. this._content.playing = value;
  8108. this.updateGear(5);
  8109. }
  8110. },
  8111. enumerable: false,
  8112. configurable: true
  8113. });
  8114. Object.defineProperty(GMovieClip.prototype, "frame", {
  8115. get: function () {
  8116. return this._content.frame;
  8117. },
  8118. set: function (value) {
  8119. if (this._content.frame != value) {
  8120. this._content.frame = value;
  8121. this.updateGear(5);
  8122. }
  8123. },
  8124. enumerable: false,
  8125. configurable: true
  8126. });
  8127. Object.defineProperty(GMovieClip.prototype, "timeScale", {
  8128. get: function () {
  8129. return this._content.timeScale;
  8130. },
  8131. set: function (value) {
  8132. this._content.timeScale = value;
  8133. },
  8134. enumerable: false,
  8135. configurable: true
  8136. });
  8137. GMovieClip.prototype.rewind = function () {
  8138. this._content.rewind();
  8139. };
  8140. GMovieClip.prototype.syncStatus = function (anotherMc) {
  8141. this._content.syncStatus(anotherMc._content);
  8142. };
  8143. GMovieClip.prototype.advance = function (timeInSeconds) {
  8144. this._content.advance(timeInSeconds);
  8145. };
  8146. GMovieClip.prototype.setPlaySettings = function (start, end, times, endAt, endCallback, callbackObj) {
  8147. this._content.setPlaySettings(start, end, times, endAt, endCallback, callbackObj);
  8148. };
  8149. GMovieClip.prototype.handleGrayedChanged = function () {
  8150. this._content.grayed = this._grayed;
  8151. };
  8152. GMovieClip.prototype.handleSizeChanged = function () {
  8153. _super.prototype.handleSizeChanged.call(this);
  8154. this._content.sizeMode = cc.Sprite.SizeMode.CUSTOM;
  8155. };
  8156. GMovieClip.prototype.getProp = function (index) {
  8157. switch (index) {
  8158. case fgui.ObjectPropID.Color:
  8159. return this.color;
  8160. case fgui.ObjectPropID.Playing:
  8161. return this.playing;
  8162. case fgui.ObjectPropID.Frame:
  8163. return this.frame;
  8164. case fgui.ObjectPropID.TimeScale:
  8165. return this.timeScale;
  8166. default:
  8167. return _super.prototype.getProp.call(this, index);
  8168. }
  8169. };
  8170. GMovieClip.prototype.setProp = function (index, value) {
  8171. switch (index) {
  8172. case fgui.ObjectPropID.Color:
  8173. this.color = value;
  8174. break;
  8175. case fgui.ObjectPropID.Playing:
  8176. this.playing = value;
  8177. break;
  8178. case fgui.ObjectPropID.Frame:
  8179. this.frame = value;
  8180. break;
  8181. case fgui.ObjectPropID.TimeScale:
  8182. this.timeScale = value;
  8183. break;
  8184. case fgui.ObjectPropID.DeltaTime:
  8185. this.advance(value);
  8186. break;
  8187. default:
  8188. _super.prototype.setProp.call(this, index, value);
  8189. break;
  8190. }
  8191. };
  8192. GMovieClip.prototype.constructFromResource = function () {
  8193. var contentItem = this.packageItem.getBranch();
  8194. this.sourceWidth = contentItem.width;
  8195. this.sourceHeight = contentItem.height;
  8196. this.initWidth = this.sourceWidth;
  8197. this.initHeight = this.sourceHeight;
  8198. this.setSize(this.sourceWidth, this.sourceHeight);
  8199. contentItem = contentItem.getHighResolution();
  8200. contentItem.load();
  8201. this._content.interval = contentItem.interval;
  8202. this._content.swing = contentItem.swing;
  8203. this._content.repeatDelay = contentItem.repeatDelay;
  8204. this._content.frames = contentItem.frames;
  8205. this._content.smoothing = contentItem.smoothing;
  8206. };
  8207. GMovieClip.prototype.setup_beforeAdd = function (buffer, beginPos) {
  8208. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  8209. buffer.seek(beginPos, 5);
  8210. if (buffer.readBool())
  8211. this.color = buffer.readColor();
  8212. buffer.readByte();
  8213. this._content.frame = buffer.readInt();
  8214. this._content.playing = buffer.readBool();
  8215. };
  8216. return GMovieClip;
  8217. }(fgui.GObject));
  8218. fgui.GMovieClip = GMovieClip;
  8219. })(fgui || (fgui = {}));
  8220. (function (fgui) {
  8221. var GProgressBar = (function (_super) {
  8222. __extends(GProgressBar, _super);
  8223. function GProgressBar() {
  8224. var _this = _super.call(this) || this;
  8225. _this._min = 0;
  8226. _this._max = 0;
  8227. _this._value = 0;
  8228. _this._barMaxWidth = 0;
  8229. _this._barMaxHeight = 0;
  8230. _this._barMaxWidthDelta = 0;
  8231. _this._barMaxHeightDelta = 0;
  8232. _this._barStartX = 0;
  8233. _this._barStartY = 0;
  8234. _this._node.name = "GProgressBar";
  8235. _this._titleType = fgui.ProgressTitleType.Percent;
  8236. _this._value = 50;
  8237. _this._max = 100;
  8238. return _this;
  8239. }
  8240. Object.defineProperty(GProgressBar.prototype, "titleType", {
  8241. get: function () {
  8242. return this._titleType;
  8243. },
  8244. set: function (value) {
  8245. if (this._titleType != value) {
  8246. this._titleType = value;
  8247. this.update(this._value);
  8248. }
  8249. },
  8250. enumerable: false,
  8251. configurable: true
  8252. });
  8253. Object.defineProperty(GProgressBar.prototype, "min", {
  8254. get: function () {
  8255. return this._min;
  8256. },
  8257. set: function (value) {
  8258. if (this._min != value) {
  8259. this._min = value;
  8260. this.update(this._value);
  8261. }
  8262. },
  8263. enumerable: false,
  8264. configurable: true
  8265. });
  8266. Object.defineProperty(GProgressBar.prototype, "max", {
  8267. get: function () {
  8268. return this._max;
  8269. },
  8270. set: function (value) {
  8271. if (this._max != value) {
  8272. this._max = value;
  8273. this.update(this._value);
  8274. }
  8275. },
  8276. enumerable: false,
  8277. configurable: true
  8278. });
  8279. Object.defineProperty(GProgressBar.prototype, "value", {
  8280. get: function () {
  8281. return this._value;
  8282. },
  8283. set: function (value) {
  8284. if (this._value != value) {
  8285. fgui.GTween.kill(this, false, this.update);
  8286. this._value = value;
  8287. this.update(value);
  8288. }
  8289. },
  8290. enumerable: false,
  8291. configurable: true
  8292. });
  8293. GProgressBar.prototype.tweenValue = function (value, duration) {
  8294. var oldValule;
  8295. var tweener = fgui.GTween.getTween(this, this.update);
  8296. if (tweener) {
  8297. oldValule = tweener.value.x;
  8298. tweener.kill();
  8299. }
  8300. else
  8301. oldValule = this._value;
  8302. this._value = value;
  8303. return fgui.GTween.to(oldValule, this._value, duration).setTarget(this, this.update).setEase(fgui.EaseType.Linear);
  8304. };
  8305. GProgressBar.prototype.update = function (newValue) {
  8306. var percent = fgui.ToolSet.clamp01((newValue - this._min) / (this._max - this._min));
  8307. if (this._titleObject) {
  8308. switch (this._titleType) {
  8309. case fgui.ProgressTitleType.Percent:
  8310. this._titleObject.text = Math.floor(percent * 100) + "%";
  8311. break;
  8312. case fgui.ProgressTitleType.ValueAndMax:
  8313. this._titleObject.text = Math.floor(newValue) + "/" + Math.floor(this._max);
  8314. break;
  8315. case fgui.ProgressTitleType.Value:
  8316. this._titleObject.text = "" + Math.floor(newValue);
  8317. break;
  8318. case fgui.ProgressTitleType.Max:
  8319. this._titleObject.text = "" + Math.floor(this._max);
  8320. break;
  8321. }
  8322. }
  8323. var fullWidth = this.width - this._barMaxWidthDelta;
  8324. var fullHeight = this.height - this._barMaxHeightDelta;
  8325. if (!this._reverse) {
  8326. if (this._barObjectH) {
  8327. if (!this.setFillAmount(this._barObjectH, percent))
  8328. this._barObjectH.width = Math.round(fullWidth * percent);
  8329. }
  8330. if (this._barObjectV) {
  8331. if (!this.setFillAmount(this._barObjectV, percent))
  8332. this._barObjectV.height = Math.round(fullHeight * percent);
  8333. }
  8334. }
  8335. else {
  8336. if (this._barObjectH) {
  8337. if (!this.setFillAmount(this._barObjectH, 1 - percent)) {
  8338. this._barObjectH.width = Math.round(fullWidth * percent);
  8339. this._barObjectH.x = this._barStartX + (fullWidth - this._barObjectH.width);
  8340. }
  8341. }
  8342. if (this._barObjectV) {
  8343. if (!this.setFillAmount(this._barObjectV, 1 - percent)) {
  8344. this._barObjectV.height = Math.round(fullHeight * percent);
  8345. this._barObjectV.y = this._barStartY + (fullHeight - this._barObjectV.height);
  8346. }
  8347. }
  8348. }
  8349. if (this._aniObject)
  8350. this._aniObject.setProp(fgui.ObjectPropID.Frame, Math.floor(percent * 100));
  8351. };
  8352. GProgressBar.prototype.setFillAmount = function (bar, percent) {
  8353. if (((bar instanceof fgui.GImage) || (bar instanceof fgui.GLoader)) && bar.fillMethod != fgui.FillMethod.None) {
  8354. bar.fillAmount = percent;
  8355. return true;
  8356. }
  8357. else
  8358. return false;
  8359. };
  8360. GProgressBar.prototype.constructExtension = function (buffer) {
  8361. buffer.seek(0, 6);
  8362. this._titleType = buffer.readByte();
  8363. this._reverse = buffer.readBool();
  8364. this._titleObject = (this.getChild("title"));
  8365. this._barObjectH = this.getChild("bar");
  8366. this._barObjectV = this.getChild("bar_v");
  8367. this._aniObject = this.getChild("ani");
  8368. if (this._barObjectH) {
  8369. this._barMaxWidth = this._barObjectH.width;
  8370. this._barMaxWidthDelta = this.width - this._barMaxWidth;
  8371. this._barStartX = this._barObjectH.x;
  8372. }
  8373. if (this._barObjectV) {
  8374. this._barMaxHeight = this._barObjectV.height;
  8375. this._barMaxHeightDelta = this.height - this._barMaxHeight;
  8376. this._barStartY = this._barObjectV.y;
  8377. }
  8378. };
  8379. GProgressBar.prototype.handleSizeChanged = function () {
  8380. _super.prototype.handleSizeChanged.call(this);
  8381. if (this._barObjectH)
  8382. this._barMaxWidth = this.width - this._barMaxWidthDelta;
  8383. if (this._barObjectV)
  8384. this._barMaxHeight = this.height - this._barMaxHeightDelta;
  8385. if (!this._underConstruct)
  8386. this.update(this._value);
  8387. };
  8388. GProgressBar.prototype.setup_afterAdd = function (buffer, beginPos) {
  8389. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  8390. if (!buffer.seek(beginPos, 6)) {
  8391. this.update(this._value);
  8392. return;
  8393. }
  8394. if (buffer.readByte() != this.packageItem.objectType) {
  8395. this.update(this._value);
  8396. return;
  8397. }
  8398. this._value = buffer.readInt();
  8399. this._max = buffer.readInt();
  8400. if (buffer.version >= 2)
  8401. this._min = buffer.readInt();
  8402. this.update(this._value);
  8403. };
  8404. return GProgressBar;
  8405. }(fgui.GComponent));
  8406. fgui.GProgressBar = GProgressBar;
  8407. })(fgui || (fgui = {}));
  8408. (function (fgui) {
  8409. var GTextField = (function (_super) {
  8410. __extends(GTextField, _super);
  8411. function GTextField() {
  8412. var _this = _super.call(this) || this;
  8413. _this._fontSize = 0;
  8414. _this._leading = 0;
  8415. _this._node.name = "GTextField";
  8416. _this._touchDisabled = true;
  8417. _this._text = "";
  8418. _this._color = new cc.Color(255, 255, 255, 255);
  8419. _this.createRenderer();
  8420. _this.fontSize = 12;
  8421. _this.leading = 3;
  8422. _this.singleLine = false;
  8423. _this._sizeDirty = false;
  8424. _this._node.on(cc.Node.EventType.SIZE_CHANGED, _this.onLabelSizeChanged, _this);
  8425. return _this;
  8426. }
  8427. GTextField.prototype.createRenderer = function () {
  8428. this._label = this._node.addComponent(cc.Label);
  8429. this.autoSize = fgui.AutoSizeType.Both;
  8430. };
  8431. Object.defineProperty(GTextField.prototype, "text", {
  8432. get: function () {
  8433. return this._text;
  8434. },
  8435. set: function (value) {
  8436. this._text = value;
  8437. if (this._text == null)
  8438. this._text = "";
  8439. this.updateGear(6);
  8440. this.markSizeChanged();
  8441. this.updateText();
  8442. },
  8443. enumerable: false,
  8444. configurable: true
  8445. });
  8446. Object.defineProperty(GTextField.prototype, "font", {
  8447. get: function () {
  8448. return this._font;
  8449. },
  8450. set: function (value) {
  8451. if (this._font != value || !value) {
  8452. this._font = value;
  8453. this.markSizeChanged();
  8454. var newFont = value ? value : fgui.UIConfig.defaultFont;
  8455. if (fgui.ToolSet.startsWith(newFont, "ui://")) {
  8456. var pi = fgui.UIPackage.getItemByURL(newFont);
  8457. if (pi)
  8458. newFont = pi.owner.getItemAsset(pi);
  8459. else
  8460. newFont = fgui.UIConfig.defaultFont;
  8461. }
  8462. this._realFont = newFont;
  8463. this.updateFont();
  8464. }
  8465. },
  8466. enumerable: false,
  8467. configurable: true
  8468. });
  8469. Object.defineProperty(GTextField.prototype, "fontSize", {
  8470. get: function () {
  8471. return this._fontSize;
  8472. },
  8473. set: function (value) {
  8474. if (value < 0)
  8475. return;
  8476. if (this._fontSize != value) {
  8477. this._fontSize = value;
  8478. this.markSizeChanged();
  8479. this.updateFontSize();
  8480. }
  8481. },
  8482. enumerable: false,
  8483. configurable: true
  8484. });
  8485. Object.defineProperty(GTextField.prototype, "color", {
  8486. get: function () {
  8487. return this._color;
  8488. },
  8489. set: function (value) {
  8490. this._color.set(value);
  8491. this.updateGear(4);
  8492. this.updateFontColor();
  8493. },
  8494. enumerable: false,
  8495. configurable: true
  8496. });
  8497. Object.defineProperty(GTextField.prototype, "align", {
  8498. get: function () {
  8499. return this._label ? this._label.horizontalAlign : 0;
  8500. },
  8501. set: function (value) {
  8502. if (this._label)
  8503. this._label.horizontalAlign = value;
  8504. },
  8505. enumerable: false,
  8506. configurable: true
  8507. });
  8508. Object.defineProperty(GTextField.prototype, "verticalAlign", {
  8509. get: function () {
  8510. return this._label ? this._label.verticalAlign : 0;
  8511. },
  8512. set: function (value) {
  8513. if (this._label)
  8514. this._label.verticalAlign = value;
  8515. },
  8516. enumerable: false,
  8517. configurable: true
  8518. });
  8519. Object.defineProperty(GTextField.prototype, "leading", {
  8520. get: function () {
  8521. return this._leading;
  8522. },
  8523. set: function (value) {
  8524. if (this._leading != value) {
  8525. this._leading = value;
  8526. this.markSizeChanged();
  8527. this.updateFontSize();
  8528. }
  8529. },
  8530. enumerable: false,
  8531. configurable: true
  8532. });
  8533. Object.defineProperty(GTextField.prototype, "letterSpacing", {
  8534. get: function () {
  8535. return this._label ? this._label.spacingX : 0;
  8536. },
  8537. set: function (value) {
  8538. if (this._label && this._label.spacingX != value) {
  8539. this.markSizeChanged();
  8540. this._label.spacingX = value;
  8541. }
  8542. },
  8543. enumerable: false,
  8544. configurable: true
  8545. });
  8546. Object.defineProperty(GTextField.prototype, "underline", {
  8547. get: function () {
  8548. return this._label ? this._label.enableUnderline : false;
  8549. },
  8550. set: function (value) {
  8551. if (this._label)
  8552. this._label.enableUnderline = value;
  8553. },
  8554. enumerable: false,
  8555. configurable: true
  8556. });
  8557. Object.defineProperty(GTextField.prototype, "bold", {
  8558. get: function () {
  8559. return this._label ? this._label.enableBold : false;
  8560. },
  8561. set: function (value) {
  8562. if (this._label)
  8563. this._label.enableBold = value;
  8564. },
  8565. enumerable: false,
  8566. configurable: true
  8567. });
  8568. Object.defineProperty(GTextField.prototype, "italic", {
  8569. get: function () {
  8570. return this._label ? this._label.enableItalic : false;
  8571. },
  8572. set: function (value) {
  8573. if (this._label)
  8574. this._label.enableItalic = value;
  8575. },
  8576. enumerable: false,
  8577. configurable: true
  8578. });
  8579. Object.defineProperty(GTextField.prototype, "singleLine", {
  8580. get: function () {
  8581. return this._label ? !this._label.enableWrapText : false;
  8582. },
  8583. set: function (value) {
  8584. if (this._label)
  8585. this._label.enableWrapText = !value;
  8586. },
  8587. enumerable: false,
  8588. configurable: true
  8589. });
  8590. Object.defineProperty(GTextField.prototype, "stroke", {
  8591. get: function () {
  8592. return (this._outline && this._outline.enabled) ? this._outline.width : 0;
  8593. },
  8594. set: function (value) {
  8595. if (value == 0) {
  8596. if (this._outline)
  8597. this._outline.enabled = false;
  8598. }
  8599. else {
  8600. if (!this._outline) {
  8601. this._outline = this._node.addComponent(cc.LabelOutline);
  8602. this.updateStrokeColor();
  8603. }
  8604. else
  8605. this._outline.enabled = true;
  8606. this._outline.width = value;
  8607. }
  8608. },
  8609. enumerable: false,
  8610. configurable: true
  8611. });
  8612. Object.defineProperty(GTextField.prototype, "strokeColor", {
  8613. get: function () {
  8614. return this._strokeColor;
  8615. },
  8616. set: function (value) {
  8617. if (!this._strokeColor)
  8618. this._strokeColor = new cc.Color();
  8619. this._strokeColor.set(value);
  8620. this.updateGear(4);
  8621. this.updateStrokeColor();
  8622. },
  8623. enumerable: false,
  8624. configurable: true
  8625. });
  8626. Object.defineProperty(GTextField.prototype, "shadowOffset", {
  8627. get: function () {
  8628. return this._shadowOffset;
  8629. },
  8630. set: function (value) {
  8631. if (!this._shadowOffset)
  8632. this._shadowOffset = new cc.Vec2();
  8633. this._shadowOffset.set(value);
  8634. if (this._shadowOffset.x != 0 || this._shadowOffset.y != 0) {
  8635. if (!this._shadow) {
  8636. this._shadow = this._node.addComponent(cc.LabelShadow);
  8637. this.updateShadowColor();
  8638. }
  8639. else
  8640. this._shadow.enabled = true;
  8641. this._shadow.offset.x = value.x;
  8642. this._shadow.offset.y = -value.y;
  8643. }
  8644. else if (this._shadow)
  8645. this._shadow.enabled = false;
  8646. },
  8647. enumerable: false,
  8648. configurable: true
  8649. });
  8650. Object.defineProperty(GTextField.prototype, "shadowColor", {
  8651. get: function () {
  8652. return this._shadowColor;
  8653. },
  8654. set: function (value) {
  8655. if (!this._shadowColor)
  8656. this._shadowColor = new cc.Color();
  8657. this._shadowColor.set(value);
  8658. this.updateShadowColor();
  8659. },
  8660. enumerable: false,
  8661. configurable: true
  8662. });
  8663. Object.defineProperty(GTextField.prototype, "ubbEnabled", {
  8664. get: function () {
  8665. return this._ubbEnabled;
  8666. },
  8667. set: function (value) {
  8668. if (this._ubbEnabled != value) {
  8669. this._ubbEnabled = value;
  8670. this.markSizeChanged();
  8671. this.updateText();
  8672. }
  8673. },
  8674. enumerable: false,
  8675. configurable: true
  8676. });
  8677. Object.defineProperty(GTextField.prototype, "autoSize", {
  8678. get: function () {
  8679. return this._autoSize;
  8680. },
  8681. set: function (value) {
  8682. if (this._autoSize != value) {
  8683. this._autoSize = value;
  8684. this.markSizeChanged();
  8685. this.updateOverflow();
  8686. }
  8687. },
  8688. enumerable: false,
  8689. configurable: true
  8690. });
  8691. GTextField.prototype.parseTemplate = function (template) {
  8692. var pos1 = 0, pos2, pos3;
  8693. var tag;
  8694. var value;
  8695. var result = "";
  8696. while ((pos2 = template.indexOf("{", pos1)) != -1) {
  8697. if (pos2 > 0 && template.charCodeAt(pos2 - 1) == 92) {
  8698. result += template.substring(pos1, pos2 - 1);
  8699. result += "{";
  8700. pos1 = pos2 + 1;
  8701. continue;
  8702. }
  8703. result += template.substring(pos1, pos2);
  8704. pos1 = pos2;
  8705. pos2 = template.indexOf("}", pos1);
  8706. if (pos2 == -1)
  8707. break;
  8708. if (pos2 == pos1 + 1) {
  8709. result += template.substr(pos1, 2);
  8710. pos1 = pos2 + 1;
  8711. continue;
  8712. }
  8713. tag = template.substring(pos1 + 1, pos2);
  8714. pos3 = tag.indexOf("=");
  8715. if (pos3 != -1) {
  8716. value = this._templateVars[tag.substring(0, pos3)];
  8717. if (value == null)
  8718. result += tag.substring(pos3 + 1);
  8719. else
  8720. result += value;
  8721. }
  8722. else {
  8723. value = this._templateVars[tag];
  8724. if (value != null)
  8725. result += value;
  8726. }
  8727. pos1 = pos2 + 1;
  8728. }
  8729. if (pos1 < template.length)
  8730. result += template.substr(pos1);
  8731. return result;
  8732. };
  8733. Object.defineProperty(GTextField.prototype, "templateVars", {
  8734. get: function () {
  8735. return this._templateVars;
  8736. },
  8737. set: function (value) {
  8738. if (this._templateVars == null && value == null)
  8739. return;
  8740. this._templateVars = value;
  8741. this.flushVars();
  8742. },
  8743. enumerable: false,
  8744. configurable: true
  8745. });
  8746. GTextField.prototype.setVar = function (name, value) {
  8747. if (!this._templateVars)
  8748. this._templateVars = {};
  8749. this._templateVars[name] = value;
  8750. return this;
  8751. };
  8752. GTextField.prototype.flushVars = function () {
  8753. this.markSizeChanged();
  8754. this.updateText();
  8755. };
  8756. Object.defineProperty(GTextField.prototype, "textWidth", {
  8757. get: function () {
  8758. this.ensureSizeCorrect();
  8759. return this._node.width;
  8760. },
  8761. enumerable: false,
  8762. configurable: true
  8763. });
  8764. GTextField.prototype.ensureSizeCorrect = function () {
  8765. if (this._sizeDirty) {
  8766. if (this._label["_forceUpdateRenderData"])
  8767. this._label["_forceUpdateRenderData"]();
  8768. else
  8769. this._label["_updateRenderData"](true);
  8770. this._sizeDirty = false;
  8771. }
  8772. };
  8773. GTextField.prototype.updateText = function () {
  8774. var text2 = this._text;
  8775. if (this._templateVars)
  8776. text2 = this.parseTemplate(text2);
  8777. if (this._ubbEnabled)
  8778. text2 = fgui.UBBParser.inst.parse(text2, true);
  8779. this._label.string = text2;
  8780. };
  8781. GTextField.prototype.assignFont = function (label, value) {
  8782. if (value instanceof cc.Font)
  8783. label.font = value;
  8784. else {
  8785. var font = fgui.getFontByName(value);
  8786. if (!font) {
  8787. label.fontFamily = value;
  8788. label.useSystemFont = true;
  8789. }
  8790. else
  8791. label.font = font;
  8792. }
  8793. };
  8794. GTextField.prototype.assignFontColor = function (label, value) {
  8795. var font = label.font;
  8796. if ((font instanceof cc.BitmapFont) && !(font._fntConfig.canTint))
  8797. value = cc.Color.WHITE;
  8798. if (this._grayed)
  8799. value = fgui.ToolSet.toGrayed(value);
  8800. label.node.color = value;
  8801. };
  8802. GTextField.prototype.updateFont = function () {
  8803. this.assignFont(this._label, this._realFont);
  8804. };
  8805. GTextField.prototype.updateFontColor = function () {
  8806. this.assignFontColor(this._label, this._color);
  8807. };
  8808. GTextField.prototype.updateStrokeColor = function () {
  8809. if (!this._outline)
  8810. return;
  8811. if (!this._strokeColor)
  8812. this._strokeColor = new cc.Color();
  8813. if (this._grayed)
  8814. this._outline.color = fgui.ToolSet.toGrayed(this._strokeColor);
  8815. else
  8816. this._outline.color = this._strokeColor;
  8817. };
  8818. GTextField.prototype.updateShadowColor = function () {
  8819. if (!this._shadow)
  8820. return;
  8821. if (!this._shadowColor)
  8822. this._shadowColor = new cc.Color();
  8823. if (this._grayed)
  8824. this._shadow.color = fgui.ToolSet.toGrayed(this._shadowColor);
  8825. else
  8826. this._shadow.color = this._shadowColor;
  8827. };
  8828. GTextField.prototype.updateFontSize = function () {
  8829. var font = this._label.font;
  8830. if (font instanceof cc.BitmapFont) {
  8831. var fntConfig = font._fntConfig;
  8832. if (fntConfig.resizable)
  8833. this._label.fontSize = this._fontSize;
  8834. else
  8835. this._label.fontSize = fntConfig.fontSize;
  8836. this._label.lineHeight = fntConfig.fontSize + (this._leading + 4) * fntConfig.fontSize / this._label.fontSize;
  8837. }
  8838. else {
  8839. this._label.fontSize = this._fontSize;
  8840. this._label.lineHeight = this._fontSize + this._leading;
  8841. }
  8842. };
  8843. GTextField.prototype.updateOverflow = function () {
  8844. if (this._autoSize == fgui.AutoSizeType.Both)
  8845. this._label.overflow = cc.Label.Overflow.NONE;
  8846. else if (this._autoSize == fgui.AutoSizeType.Height) {
  8847. this._label.overflow = cc.Label.Overflow.RESIZE_HEIGHT;
  8848. this._node.width = this._width;
  8849. }
  8850. else if (this._autoSize == fgui.AutoSizeType.Shrink) {
  8851. this._label.overflow = cc.Label.Overflow.SHRINK;
  8852. this._node.setContentSize(this._width, this._height);
  8853. }
  8854. else {
  8855. this._label.overflow = cc.Label.Overflow.CLAMP;
  8856. this._node.setContentSize(this._width, this._height);
  8857. }
  8858. };
  8859. GTextField.prototype.markSizeChanged = function () {
  8860. if (this._underConstruct)
  8861. return;
  8862. if (this._autoSize == fgui.AutoSizeType.Both || this._autoSize == fgui.AutoSizeType.Height) {
  8863. if (!this._sizeDirty) {
  8864. this._node.emit(fgui.Event.SIZE_DELAY_CHANGE, this);
  8865. this._sizeDirty = true;
  8866. }
  8867. }
  8868. };
  8869. GTextField.prototype.onLabelSizeChanged = function () {
  8870. this._sizeDirty = false;
  8871. if (this._underConstruct)
  8872. return;
  8873. if (this._autoSize == fgui.AutoSizeType.Both || this._autoSize == fgui.AutoSizeType.Height) {
  8874. this._updatingSize = true;
  8875. this.setSize(this._node.width, this._node.height);
  8876. this._updatingSize = false;
  8877. }
  8878. };
  8879. GTextField.prototype.handleSizeChanged = function () {
  8880. if (this._updatingSize)
  8881. return;
  8882. if (this._autoSize == fgui.AutoSizeType.None || this._autoSize == fgui.AutoSizeType.Shrink) {
  8883. this._node.setContentSize(this._width, this._height);
  8884. }
  8885. else if (this._autoSize == fgui.AutoSizeType.Height)
  8886. this._node.width = this._width;
  8887. };
  8888. GTextField.prototype.handleGrayedChanged = function () {
  8889. this.updateFontColor();
  8890. this.updateStrokeColor();
  8891. };
  8892. GTextField.prototype.getProp = function (index) {
  8893. switch (index) {
  8894. case fgui.ObjectPropID.Color:
  8895. return this.color;
  8896. case fgui.ObjectPropID.OutlineColor:
  8897. return this.strokeColor;
  8898. case fgui.ObjectPropID.FontSize:
  8899. return this.fontSize;
  8900. default:
  8901. return _super.prototype.getProp.call(this, index);
  8902. }
  8903. };
  8904. GTextField.prototype.setProp = function (index, value) {
  8905. switch (index) {
  8906. case fgui.ObjectPropID.Color:
  8907. this.color = value;
  8908. break;
  8909. case fgui.ObjectPropID.OutlineColor:
  8910. this.strokeColor = value;
  8911. break;
  8912. case fgui.ObjectPropID.FontSize:
  8913. this.fontSize = value;
  8914. break;
  8915. default:
  8916. _super.prototype.setProp.call(this, index, value);
  8917. break;
  8918. }
  8919. };
  8920. GTextField.prototype.setup_beforeAdd = function (buffer, beginPos) {
  8921. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  8922. buffer.seek(beginPos, 5);
  8923. this.font = buffer.readS();
  8924. this.fontSize = buffer.readShort();
  8925. this.color = buffer.readColor();
  8926. this.align = buffer.readByte();
  8927. this.verticalAlign = buffer.readByte();
  8928. this.leading = buffer.readShort();
  8929. this.letterSpacing = buffer.readShort();
  8930. this._ubbEnabled = buffer.readBool();
  8931. this.autoSize = buffer.readByte();
  8932. this.underline = buffer.readBool();
  8933. this.italic = buffer.readBool();
  8934. this.bold = buffer.readBool();
  8935. this.singleLine = buffer.readBool();
  8936. if (buffer.readBool()) {
  8937. this.strokeColor = buffer.readColor();
  8938. this.stroke = buffer.readFloat();
  8939. }
  8940. if (buffer.readBool()) {
  8941. this.shadowColor = buffer.readColor();
  8942. var f1 = buffer.readFloat();
  8943. var f2 = buffer.readFloat();
  8944. this.shadowOffset = new cc.Vec2(f1, f2);
  8945. }
  8946. if (buffer.readBool())
  8947. this._templateVars = {};
  8948. };
  8949. GTextField.prototype.setup_afterAdd = function (buffer, beginPos) {
  8950. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  8951. buffer.seek(beginPos, 6);
  8952. var str = buffer.readS();
  8953. if (str != null)
  8954. this.text = str;
  8955. };
  8956. return GTextField;
  8957. }(fgui.GObject));
  8958. fgui.GTextField = GTextField;
  8959. })(fgui || (fgui = {}));
  8960. (function (fgui) {
  8961. var RichTextImageAtlas = (function (_super) {
  8962. __extends(RichTextImageAtlas, _super);
  8963. function RichTextImageAtlas() {
  8964. return _super !== null && _super.apply(this, arguments) || this;
  8965. }
  8966. RichTextImageAtlas.prototype.getSpriteFrame = function (key) {
  8967. var pi = fgui.UIPackage.getItemByURL(key);
  8968. if (pi) {
  8969. pi.load();
  8970. if (pi.type == fgui.PackageItemType.Image)
  8971. return pi.asset;
  8972. else if (pi.type == fgui.PackageItemType.MovieClip)
  8973. return pi.frames[0].texture;
  8974. }
  8975. return _super.prototype.getSpriteFrame.call(this, key);
  8976. };
  8977. return RichTextImageAtlas;
  8978. }(cc.SpriteAtlas));
  8979. fgui.RichTextImageAtlas = RichTextImageAtlas;
  8980. var imageAtlas = new RichTextImageAtlas();
  8981. var GRichTextField = (function (_super) {
  8982. __extends(GRichTextField, _super);
  8983. function GRichTextField() {
  8984. var _this = _super.call(this) || this;
  8985. _this._node.name = "GRichTextField";
  8986. _this._touchDisabled = false;
  8987. _this.linkUnderline = fgui.UIConfig.linkUnderline;
  8988. return _this;
  8989. }
  8990. GRichTextField.prototype.createRenderer = function () {
  8991. this._richText = this._node.addComponent(cc.RichText);
  8992. this._richText.handleTouchEvent = false;
  8993. this.autoSize = fgui.AutoSizeType.None;
  8994. this._richText.imageAtlas = imageAtlas;
  8995. };
  8996. Object.defineProperty(GRichTextField.prototype, "align", {
  8997. get: function () {
  8998. return this._richText.horizontalAlign;
  8999. },
  9000. set: function (value) {
  9001. this._richText.horizontalAlign = value;
  9002. },
  9003. enumerable: false,
  9004. configurable: true
  9005. });
  9006. Object.defineProperty(GRichTextField.prototype, "underline", {
  9007. get: function () {
  9008. return this._underline;
  9009. },
  9010. set: function (value) {
  9011. if (this._underline != value) {
  9012. this._underline = value;
  9013. this.updateText();
  9014. }
  9015. },
  9016. enumerable: false,
  9017. configurable: true
  9018. });
  9019. Object.defineProperty(GRichTextField.prototype, "bold", {
  9020. get: function () {
  9021. return this._bold;
  9022. },
  9023. set: function (value) {
  9024. if (this._bold != value) {
  9025. this._bold = value;
  9026. this.updateText();
  9027. }
  9028. },
  9029. enumerable: false,
  9030. configurable: true
  9031. });
  9032. Object.defineProperty(GRichTextField.prototype, "italic", {
  9033. get: function () {
  9034. return this._italics;
  9035. },
  9036. set: function (value) {
  9037. if (this._italics != value) {
  9038. this._italics = value;
  9039. this.updateText();
  9040. }
  9041. },
  9042. enumerable: false,
  9043. configurable: true
  9044. });
  9045. GRichTextField.prototype.markSizeChanged = function () {
  9046. };
  9047. GRichTextField.prototype.updateText = function () {
  9048. var text2 = this._text;
  9049. if (this._templateVars)
  9050. text2 = this.parseTemplate(text2);
  9051. if (this._ubbEnabled) {
  9052. fgui.UBBParser.inst.linkUnderline = this.linkUnderline;
  9053. fgui.UBBParser.inst.linkColor = this.linkColor;
  9054. text2 = fgui.UBBParser.inst.parse(text2);
  9055. }
  9056. if (this._bold)
  9057. text2 = "<b>" + text2 + "</b>";
  9058. if (this._italics)
  9059. text2 = "<i>" + text2 + "</i>";
  9060. if (this._underline)
  9061. text2 = "<u>" + text2 + "</u>";
  9062. var c = this._color;
  9063. if (this._grayed)
  9064. c = fgui.ToolSet.toGrayed(c);
  9065. text2 = "<color=" + c.toHEX("#rrggbb") + ">" + text2 + "</color>";
  9066. if (this._autoSize == fgui.AutoSizeType.Both) {
  9067. if (this._richText.maxWidth != 0)
  9068. this._richText.maxWidth = 0;
  9069. this._richText.string = text2;
  9070. if (this.maxWidth != 0 && this._node.width > this.maxWidth)
  9071. this._richText.maxWidth = this.maxWidth;
  9072. }
  9073. else
  9074. this._richText.string = text2;
  9075. };
  9076. GRichTextField.prototype.updateFont = function () {
  9077. this.assignFont(this._richText, this._realFont);
  9078. };
  9079. GRichTextField.prototype.updateFontColor = function () {
  9080. this.assignFontColor(this._richText, this._color);
  9081. };
  9082. GRichTextField.prototype.updateFontSize = function () {
  9083. var fontSize = this._fontSize;
  9084. var font = this._richText.font;
  9085. if (font instanceof cc.BitmapFont) {
  9086. if (!font._fntConfig.resizable)
  9087. fontSize = font._fntConfig.fontSize;
  9088. }
  9089. this._richText.fontSize = fontSize;
  9090. this._richText.lineHeight = fontSize + this._leading * 2;
  9091. };
  9092. GRichTextField.prototype.updateOverflow = function () {
  9093. if (this._autoSize == fgui.AutoSizeType.Both)
  9094. this._richText.maxWidth = 0;
  9095. else
  9096. this._richText.maxWidth = this._width;
  9097. };
  9098. GRichTextField.prototype.handleSizeChanged = function () {
  9099. if (this._updatingSize)
  9100. return;
  9101. if (this._autoSize != fgui.AutoSizeType.Both)
  9102. this._richText.maxWidth = this._width;
  9103. };
  9104. return GRichTextField;
  9105. }(fgui.GTextField));
  9106. fgui.GRichTextField = GRichTextField;
  9107. })(fgui || (fgui = {}));
  9108. (function (fgui) {
  9109. var GRoot = (function (_super) {
  9110. __extends(GRoot, _super);
  9111. function GRoot() {
  9112. var _this = _super.call(this) || this;
  9113. _this._node.name = "GRoot";
  9114. _this.opaque = false;
  9115. _this._volumeScale = 1;
  9116. _this._popupStack = new Array();
  9117. _this._justClosedPopups = new Array();
  9118. _this._modalLayer = new fgui.GGraph();
  9119. _this._modalLayer.setSize(_this.width, _this.height);
  9120. _this._modalLayer.drawRect(0, cc.Color.TRANSPARENT, fgui.UIConfig.modalLayerColor);
  9121. _this._modalLayer.addRelation(_this, fgui.RelationType.Size);
  9122. _this._thisOnResized = _this.onWinResize.bind(_this);
  9123. _this._inputProcessor = _this.node.addComponent(fgui.InputProcessor);
  9124. _this._inputProcessor._captureCallback = _this.onTouchBegin_1;
  9125. if (CC_EDITOR) {
  9126. cc.engine.on('design-resolution-changed', _this._thisOnResized);
  9127. }
  9128. else {
  9129. cc.view.on('canvas-resize', _this._thisOnResized);
  9130. }
  9131. _this.onWinResize();
  9132. return _this;
  9133. }
  9134. Object.defineProperty(GRoot, "inst", {
  9135. get: function () {
  9136. if (!GRoot._inst)
  9137. throw 'Call GRoot.create first!';
  9138. return GRoot._inst;
  9139. },
  9140. enumerable: false,
  9141. configurable: true
  9142. });
  9143. GRoot.create = function () {
  9144. GRoot._inst = new GRoot();
  9145. GRoot._inst.node.parent = cc.director.getScene();
  9146. return GRoot._inst;
  9147. };
  9148. GRoot.prototype.onDestroy = function () {
  9149. if (CC_EDITOR) {
  9150. cc.engine.off('design-resolution-changed', this._thisOnResized);
  9151. }
  9152. else {
  9153. cc.view.off('canvas-resize', this._thisOnResized);
  9154. }
  9155. if (this == GRoot._inst)
  9156. GRoot._inst = null;
  9157. };
  9158. GRoot.prototype.getTouchPosition = function (touchId) {
  9159. return this._inputProcessor.getTouchPosition(touchId);
  9160. };
  9161. Object.defineProperty(GRoot.prototype, "touchTarget", {
  9162. get: function () {
  9163. return this._inputProcessor.getTouchTarget();
  9164. },
  9165. enumerable: false,
  9166. configurable: true
  9167. });
  9168. Object.defineProperty(GRoot.prototype, "inputProcessor", {
  9169. get: function () {
  9170. return this._inputProcessor;
  9171. },
  9172. enumerable: false,
  9173. configurable: true
  9174. });
  9175. GRoot.prototype.showWindow = function (win) {
  9176. this.addChild(win);
  9177. win.requestFocus();
  9178. if (win.x > this.width)
  9179. win.x = this.width - win.width;
  9180. else if (win.x + win.width < 0)
  9181. win.x = 0;
  9182. if (win.y > this.height)
  9183. win.y = this.height - win.height;
  9184. else if (win.y + win.height < 0)
  9185. win.y = 0;
  9186. this.adjustModalLayer();
  9187. };
  9188. GRoot.prototype.hideWindow = function (win) {
  9189. win.hide();
  9190. };
  9191. GRoot.prototype.hideWindowImmediately = function (win) {
  9192. if (win.parent == this)
  9193. this.removeChild(win);
  9194. this.adjustModalLayer();
  9195. };
  9196. GRoot.prototype.bringToFront = function (win) {
  9197. var cnt = this.numChildren;
  9198. var i;
  9199. if (this._modalLayer.parent && !win.modal)
  9200. i = this.getChildIndex(this._modalLayer) - 1;
  9201. else
  9202. i = cnt - 1;
  9203. for (; i >= 0; i--) {
  9204. var g = this.getChildAt(i);
  9205. if (g == win)
  9206. return;
  9207. if (g instanceof fgui.Window)
  9208. break;
  9209. }
  9210. if (i >= 0)
  9211. this.setChildIndex(win, i);
  9212. };
  9213. GRoot.prototype.showModalWait = function (msg) {
  9214. if (fgui.UIConfig.globalModalWaiting != null) {
  9215. if (this._modalWaitPane == null)
  9216. this._modalWaitPane = fgui.UIPackage.createObjectFromURL(fgui.UIConfig.globalModalWaiting);
  9217. this._modalWaitPane.setSize(this.width, this.height);
  9218. this._modalWaitPane.addRelation(this, fgui.RelationType.Size);
  9219. this.addChild(this._modalWaitPane);
  9220. this._modalWaitPane.text = msg;
  9221. }
  9222. };
  9223. GRoot.prototype.closeModalWait = function () {
  9224. if (this._modalWaitPane && this._modalWaitPane.parent)
  9225. this.removeChild(this._modalWaitPane);
  9226. };
  9227. GRoot.prototype.closeAllExceptModals = function () {
  9228. var arr = this._children.slice();
  9229. var cnt = arr.length;
  9230. for (var i = 0; i < cnt; i++) {
  9231. var g = arr[i];
  9232. if ((g instanceof fgui.Window) && !g.modal)
  9233. g.hide();
  9234. }
  9235. };
  9236. GRoot.prototype.closeAllWindows = function () {
  9237. var arr = this._children.slice();
  9238. var cnt = arr.length;
  9239. for (var i = 0; i < cnt; i++) {
  9240. var g = arr[i];
  9241. if (g instanceof fgui.Window)
  9242. g.hide();
  9243. }
  9244. };
  9245. GRoot.prototype.getTopWindow = function () {
  9246. var cnt = this.numChildren;
  9247. for (var i = cnt - 1; i >= 0; i--) {
  9248. var g = this.getChildAt(i);
  9249. if (g instanceof fgui.Window) {
  9250. return g;
  9251. }
  9252. }
  9253. return null;
  9254. };
  9255. Object.defineProperty(GRoot.prototype, "modalLayer", {
  9256. get: function () {
  9257. return this._modalLayer;
  9258. },
  9259. enumerable: false,
  9260. configurable: true
  9261. });
  9262. Object.defineProperty(GRoot.prototype, "hasModalWindow", {
  9263. get: function () {
  9264. return this._modalLayer.parent != null;
  9265. },
  9266. enumerable: false,
  9267. configurable: true
  9268. });
  9269. Object.defineProperty(GRoot.prototype, "modalWaiting", {
  9270. get: function () {
  9271. return this._modalWaitPane && this._modalWaitPane.node.activeInHierarchy;
  9272. },
  9273. enumerable: false,
  9274. configurable: true
  9275. });
  9276. GRoot.prototype.getPopupPosition = function (popup, target, dir, result) {
  9277. var pos = result || new cc.Vec2();
  9278. var sizeW = 0, sizeH = 0;
  9279. if (target) {
  9280. pos = target.localToGlobal();
  9281. var pos2 = target.localToGlobal(target.width, target.height);
  9282. sizeW = pos2.x - pos.x;
  9283. sizeH = pos2.y - pos.y;
  9284. }
  9285. else {
  9286. pos = this.getTouchPosition();
  9287. pos = this.globalToLocal(pos.x, pos.y);
  9288. }
  9289. if (pos.x + popup.width > this.width)
  9290. pos.x = pos.x + sizeW - popup.width;
  9291. pos.y += sizeH;
  9292. if (((dir === undefined || dir === fgui.PopupDirection.Auto) && pos.y + popup.height > this.height)
  9293. || dir === false || dir === fgui.PopupDirection.Up) {
  9294. pos.y = pos.y - sizeH - popup.height - 1;
  9295. if (pos.y < 0) {
  9296. pos.y = 0;
  9297. pos.x += sizeW / 2;
  9298. }
  9299. }
  9300. return pos;
  9301. };
  9302. GRoot.prototype.showPopup = function (popup, target, dir) {
  9303. if (this._popupStack.length > 0) {
  9304. var k = this._popupStack.indexOf(popup);
  9305. if (k != -1) {
  9306. for (var i = this._popupStack.length - 1; i >= k; i--)
  9307. this.removeChild(this._popupStack.pop());
  9308. }
  9309. }
  9310. this._popupStack.push(popup);
  9311. if (target) {
  9312. var p = target;
  9313. while (p) {
  9314. if (p.parent == this) {
  9315. if (popup.sortingOrder < p.sortingOrder) {
  9316. popup.sortingOrder = p.sortingOrder;
  9317. }
  9318. break;
  9319. }
  9320. p = p.parent;
  9321. }
  9322. }
  9323. this.addChild(popup);
  9324. this.adjustModalLayer();
  9325. var pt = this.getPopupPosition(popup, target, dir);
  9326. popup.setPosition(pt.x, pt.y);
  9327. };
  9328. GRoot.prototype.togglePopup = function (popup, target, dir) {
  9329. if (this._justClosedPopups.indexOf(popup) != -1)
  9330. return;
  9331. this.showPopup(popup, target, dir);
  9332. };
  9333. GRoot.prototype.hidePopup = function (popup) {
  9334. if (popup) {
  9335. var k = this._popupStack.indexOf(popup);
  9336. if (k != -1) {
  9337. for (var i = this._popupStack.length - 1; i >= k; i--)
  9338. this.closePopup(this._popupStack.pop());
  9339. }
  9340. }
  9341. else {
  9342. var cnt = this._popupStack.length;
  9343. for (i = cnt - 1; i >= 0; i--)
  9344. this.closePopup(this._popupStack[i]);
  9345. this._popupStack.length = 0;
  9346. }
  9347. };
  9348. Object.defineProperty(GRoot.prototype, "hasAnyPopup", {
  9349. get: function () {
  9350. return this._popupStack.length != 0;
  9351. },
  9352. enumerable: false,
  9353. configurable: true
  9354. });
  9355. GRoot.prototype.closePopup = function (target) {
  9356. if (target.parent) {
  9357. if (target instanceof fgui.Window)
  9358. target.hide();
  9359. else
  9360. this.removeChild(target);
  9361. }
  9362. };
  9363. GRoot.prototype.showTooltips = function (msg) {
  9364. if (this._defaultTooltipWin == null) {
  9365. var resourceURL = fgui.UIConfig.tooltipsWin;
  9366. if (!resourceURL) {
  9367. console.error("UIConfig.tooltipsWin not defined");
  9368. return;
  9369. }
  9370. this._defaultTooltipWin = fgui.UIPackage.createObjectFromURL(resourceURL);
  9371. }
  9372. this._defaultTooltipWin.text = msg;
  9373. this.showTooltipsWin(this._defaultTooltipWin);
  9374. };
  9375. GRoot.prototype.showTooltipsWin = function (tooltipWin) {
  9376. this.hideTooltips();
  9377. this._tooltipWin = tooltipWin;
  9378. var pt = this.getTouchPosition();
  9379. pt.x += 10;
  9380. pt.y += 20;
  9381. this.globalToLocal(pt.x, pt.y, pt);
  9382. if (pt.x + this._tooltipWin.width > this.width) {
  9383. pt.x = pt.x - this._tooltipWin.width - 1;
  9384. if (pt.x < 0)
  9385. pt.x = 10;
  9386. }
  9387. if (pt.y + this._tooltipWin.height > this.height) {
  9388. pt.y = pt.y - this._tooltipWin.height - 1;
  9389. if (pt.y < 0)
  9390. pt.y = 10;
  9391. }
  9392. this._tooltipWin.setPosition(pt.x, pt.y);
  9393. this.addChild(this._tooltipWin);
  9394. };
  9395. GRoot.prototype.hideTooltips = function () {
  9396. if (this._tooltipWin) {
  9397. if (this._tooltipWin.parent)
  9398. this.removeChild(this._tooltipWin);
  9399. this._tooltipWin = null;
  9400. }
  9401. };
  9402. Object.defineProperty(GRoot.prototype, "volumeScale", {
  9403. get: function () {
  9404. return this._volumeScale;
  9405. },
  9406. set: function (value) {
  9407. this._volumeScale = value;
  9408. },
  9409. enumerable: false,
  9410. configurable: true
  9411. });
  9412. GRoot.prototype.playOneShotSound = function (clip, volumeScale) {
  9413. if (volumeScale === undefined)
  9414. volumeScale = 1;
  9415. cc.audioEngine.play(clip, false, this._volumeScale * volumeScale);
  9416. };
  9417. GRoot.prototype.adjustModalLayer = function () {
  9418. var cnt = this.numChildren;
  9419. if (this._modalWaitPane && this._modalWaitPane.parent)
  9420. this.setChildIndex(this._modalWaitPane, cnt - 1);
  9421. for (var i = cnt - 1; i >= 0; i--) {
  9422. var g = this.getChildAt(i);
  9423. if ((g instanceof fgui.Window) && g.modal) {
  9424. if (this._modalLayer.parent == null)
  9425. this.addChildAt(this._modalLayer, i);
  9426. else
  9427. this.setChildIndexBefore(this._modalLayer, i);
  9428. return;
  9429. }
  9430. }
  9431. if (this._modalLayer.parent)
  9432. this.removeChild(this._modalLayer);
  9433. };
  9434. GRoot.prototype.onTouchBegin_1 = function (evt) {
  9435. if (this._tooltipWin)
  9436. this.hideTooltips();
  9437. this._justClosedPopups.length = 0;
  9438. if (this._popupStack.length > 0) {
  9439. var mc = evt.initiator;
  9440. while (mc && mc != this) {
  9441. var pindex = this._popupStack.indexOf(mc);
  9442. if (pindex != -1) {
  9443. for (var i = this._popupStack.length - 1; i > pindex; i--) {
  9444. var popup = this._popupStack.pop();
  9445. this.closePopup(popup);
  9446. this._justClosedPopups.push(popup);
  9447. }
  9448. return;
  9449. }
  9450. mc = mc.findParent();
  9451. }
  9452. var cnt = this._popupStack.length;
  9453. for (var i = cnt - 1; i >= 0; i--) {
  9454. popup = this._popupStack[i];
  9455. this.closePopup(popup);
  9456. this._justClosedPopups.push(popup);
  9457. }
  9458. this._popupStack.length = 0;
  9459. }
  9460. };
  9461. GRoot.prototype.onWinResize = function () {
  9462. var size = cc.view.getCanvasSize();
  9463. size.width /= cc.view.getScaleX();
  9464. size.height /= cc.view.getScaleY();
  9465. var pos = cc.view.getViewportRect().origin;
  9466. pos.x = pos.x / cc.view.getScaleX();
  9467. pos.y = pos.y / cc.view.getScaleY();
  9468. this.setSize(size.width, size.height);
  9469. this._node.setPosition(-pos.x, this._height - pos.y);
  9470. this.updateContentScaleLevel();
  9471. };
  9472. GRoot.prototype.handlePositionChanged = function () {
  9473. };
  9474. GRoot.prototype.updateContentScaleLevel = function () {
  9475. var ss = Math.max(cc.view.getScaleX(), cc.view.getScaleY());
  9476. if (ss >= 3.5)
  9477. GRoot.contentScaleLevel = 3;
  9478. else if (ss >= 2.5)
  9479. GRoot.contentScaleLevel = 2;
  9480. else if (ss >= 1.5)
  9481. GRoot.contentScaleLevel = 1;
  9482. else
  9483. GRoot.contentScaleLevel = 0;
  9484. };
  9485. GRoot.contentScaleLevel = 0;
  9486. return GRoot;
  9487. }(fgui.GComponent));
  9488. fgui.GRoot = GRoot;
  9489. })(fgui || (fgui = {}));
  9490. (function (fgui) {
  9491. var GScrollBar = (function (_super) {
  9492. __extends(GScrollBar, _super);
  9493. function GScrollBar() {
  9494. var _this = _super.call(this) || this;
  9495. _this._node.name = "GScrollBar";
  9496. _this._dragOffset = new cc.Vec2();
  9497. _this._scrollPerc = 0;
  9498. return _this;
  9499. }
  9500. GScrollBar.prototype.setScrollPane = function (target, vertical) {
  9501. this._target = target;
  9502. this._vertical = vertical;
  9503. };
  9504. GScrollBar.prototype.setDisplayPerc = function (value) {
  9505. if (this._vertical) {
  9506. if (!this._fixedGripSize)
  9507. this._grip.height = Math.floor(value * this._bar.height);
  9508. this._grip.y = this._bar.y + (this._bar.height - this._grip.height) * this._scrollPerc;
  9509. }
  9510. else {
  9511. if (!this._fixedGripSize)
  9512. this._grip.width = Math.floor(value * this._bar.width);
  9513. this._grip.x = this._bar.x + (this._bar.width - this._grip.width) * this._scrollPerc;
  9514. }
  9515. this._grip.visible = value != 0 && value != 1;
  9516. };
  9517. GScrollBar.prototype.setScrollPerc = function (val) {
  9518. this._scrollPerc = val;
  9519. if (this._vertical)
  9520. this._grip.y = this._bar.y + (this._bar.height - this._grip.height) * this._scrollPerc;
  9521. else
  9522. this._grip.x = this._bar.x + (this._bar.width - this._grip.width) * this._scrollPerc;
  9523. };
  9524. Object.defineProperty(GScrollBar.prototype, "minSize", {
  9525. get: function () {
  9526. if (this._vertical)
  9527. return (this._arrowButton1 ? this._arrowButton1.height : 0) + (this._arrowButton2 ? this._arrowButton2.height : 0);
  9528. else
  9529. return (this._arrowButton1 ? this._arrowButton1.width : 0) + (this._arrowButton2 ? this._arrowButton2.width : 0);
  9530. },
  9531. enumerable: false,
  9532. configurable: true
  9533. });
  9534. Object.defineProperty(GScrollBar.prototype, "gripDragging", {
  9535. get: function () {
  9536. return this._gripDragging;
  9537. },
  9538. enumerable: false,
  9539. configurable: true
  9540. });
  9541. GScrollBar.prototype.constructExtension = function (buffer) {
  9542. buffer.seek(0, 6);
  9543. this._fixedGripSize = buffer.readBool();
  9544. this._grip = this.getChild("grip");
  9545. if (!this._grip) {
  9546. console.error("需要定义grip");
  9547. return;
  9548. }
  9549. this._bar = this.getChild("bar");
  9550. if (!this._bar) {
  9551. console.error("需要定义bar");
  9552. return;
  9553. }
  9554. this._arrowButton1 = this.getChild("arrow1");
  9555. this._arrowButton2 = this.getChild("arrow2");
  9556. this._grip.on(fgui.Event.TOUCH_BEGIN, this.onGripTouchDown, this);
  9557. this._grip.on(fgui.Event.TOUCH_MOVE, this.onGripTouchMove, this);
  9558. this._grip.on(fgui.Event.TOUCH_END, this.onGripTouchEnd, this);
  9559. if (this._arrowButton1)
  9560. this._arrowButton1.on(fgui.Event.TOUCH_BEGIN, this.onClickArrow1, this);
  9561. if (this._arrowButton2)
  9562. this._arrowButton2.on(fgui.Event.TOUCH_BEGIN, this.onClickArrow2, this);
  9563. this.on(fgui.Event.TOUCH_BEGIN, this.onBarTouchBegin, this);
  9564. };
  9565. GScrollBar.prototype.onGripTouchDown = function (evt) {
  9566. evt.stopPropagation();
  9567. evt.captureTouch();
  9568. this._gripDragging = true;
  9569. this._target.updateScrollBarVisible();
  9570. this.globalToLocal(evt.pos.x, evt.pos.y, this._dragOffset);
  9571. this._dragOffset.x -= this._grip.x;
  9572. this._dragOffset.y -= this._grip.y;
  9573. };
  9574. GScrollBar.prototype.onGripTouchMove = function (evt) {
  9575. if (!this.onStage)
  9576. return;
  9577. var pt = this.globalToLocal(evt.pos.x, evt.pos.y, s_vec2);
  9578. if (this._vertical) {
  9579. var curY = pt.y - this._dragOffset.y;
  9580. this._target.setPercY((curY - this._bar.y) / (this._bar.height - this._grip.height), false);
  9581. }
  9582. else {
  9583. var curX = pt.x - this._dragOffset.x;
  9584. this._target.setPercX((curX - this._bar.x) / (this._bar.width - this._grip.width), false);
  9585. }
  9586. };
  9587. GScrollBar.prototype.onGripTouchEnd = function (evt) {
  9588. if (!this.onStage)
  9589. return;
  9590. this._gripDragging = false;
  9591. this._target.updateScrollBarVisible();
  9592. };
  9593. GScrollBar.prototype.onClickArrow1 = function (evt) {
  9594. evt.stopPropagation();
  9595. if (this._vertical)
  9596. this._target.scrollUp();
  9597. else
  9598. this._target.scrollLeft();
  9599. };
  9600. GScrollBar.prototype.onClickArrow2 = function (evt) {
  9601. evt.stopPropagation();
  9602. if (this._vertical)
  9603. this._target.scrollDown();
  9604. else
  9605. this._target.scrollRight();
  9606. };
  9607. GScrollBar.prototype.onBarTouchBegin = function (evt) {
  9608. var pt = this._grip.globalToLocal(evt.pos.x, evt.pos.y, s_vec2);
  9609. if (this._vertical) {
  9610. if (pt.y < 0)
  9611. this._target.scrollUp(4);
  9612. else
  9613. this._target.scrollDown(4);
  9614. }
  9615. else {
  9616. if (pt.x < 0)
  9617. this._target.scrollLeft(4);
  9618. else
  9619. this._target.scrollRight(4);
  9620. }
  9621. };
  9622. return GScrollBar;
  9623. }(fgui.GComponent));
  9624. fgui.GScrollBar = GScrollBar;
  9625. var s_vec2 = new cc.Vec2();
  9626. })(fgui || (fgui = {}));
  9627. (function (fgui) {
  9628. var GSlider = (function (_super) {
  9629. __extends(GSlider, _super);
  9630. function GSlider() {
  9631. var _this = _super.call(this) || this;
  9632. _this._min = 0;
  9633. _this._max = 0;
  9634. _this._value = 0;
  9635. _this._barMaxWidth = 0;
  9636. _this._barMaxHeight = 0;
  9637. _this._barMaxWidthDelta = 0;
  9638. _this._barMaxHeightDelta = 0;
  9639. _this._clickPercent = 0;
  9640. _this._barStartX = 0;
  9641. _this._barStartY = 0;
  9642. _this.changeOnClick = true;
  9643. _this.canDrag = true;
  9644. _this._node.name = "GSlider";
  9645. _this._titleType = fgui.ProgressTitleType.Percent;
  9646. _this._value = 50;
  9647. _this._max = 100;
  9648. _this._clickPos = new cc.Vec2();
  9649. return _this;
  9650. }
  9651. Object.defineProperty(GSlider.prototype, "titleType", {
  9652. get: function () {
  9653. return this._titleType;
  9654. },
  9655. set: function (value) {
  9656. this._titleType = value;
  9657. },
  9658. enumerable: false,
  9659. configurable: true
  9660. });
  9661. Object.defineProperty(GSlider.prototype, "wholeNumbers", {
  9662. get: function () {
  9663. return this._wholeNumbers;
  9664. },
  9665. set: function (value) {
  9666. if (this._wholeNumbers != value) {
  9667. this._wholeNumbers = value;
  9668. this.update();
  9669. }
  9670. },
  9671. enumerable: false,
  9672. configurable: true
  9673. });
  9674. Object.defineProperty(GSlider.prototype, "min", {
  9675. get: function () {
  9676. return this._min;
  9677. },
  9678. set: function (value) {
  9679. if (this._min != value) {
  9680. this._min = value;
  9681. this.update();
  9682. }
  9683. },
  9684. enumerable: false,
  9685. configurable: true
  9686. });
  9687. Object.defineProperty(GSlider.prototype, "max", {
  9688. get: function () {
  9689. return this._max;
  9690. },
  9691. set: function (value) {
  9692. if (this._max != value) {
  9693. this._max = value;
  9694. this.update();
  9695. }
  9696. },
  9697. enumerable: false,
  9698. configurable: true
  9699. });
  9700. Object.defineProperty(GSlider.prototype, "value", {
  9701. get: function () {
  9702. return this._value;
  9703. },
  9704. set: function (value) {
  9705. if (this._value != value) {
  9706. this._value = value;
  9707. this.update();
  9708. }
  9709. },
  9710. enumerable: false,
  9711. configurable: true
  9712. });
  9713. GSlider.prototype.update = function () {
  9714. this.updateWithPercent((this._value - this._min) / (this._max - this._min));
  9715. };
  9716. GSlider.prototype.updateWithPercent = function (percent, manual) {
  9717. percent = fgui.ToolSet.clamp01(percent);
  9718. if (manual) {
  9719. var newValue = fgui.ToolSet.clamp(this._min + (this._max - this._min) * percent, this._min, this._max);
  9720. if (this._wholeNumbers) {
  9721. newValue = Math.round(newValue);
  9722. percent = fgui.ToolSet.clamp01((newValue - this._min) / (this._max - this._min));
  9723. }
  9724. if (newValue != this._value) {
  9725. this._value = newValue;
  9726. this._node.emit(fgui.Event.STATUS_CHANGED, this);
  9727. }
  9728. }
  9729. if (this._titleObject) {
  9730. switch (this._titleType) {
  9731. case fgui.ProgressTitleType.Percent:
  9732. this._titleObject.text = Math.floor(percent * 100) + "%";
  9733. break;
  9734. case fgui.ProgressTitleType.ValueAndMax:
  9735. this._titleObject.text = this._value + "/" + this._max;
  9736. break;
  9737. case fgui.ProgressTitleType.Value:
  9738. this._titleObject.text = "" + this._value;
  9739. break;
  9740. case fgui.ProgressTitleType.Max:
  9741. this._titleObject.text = "" + this._max;
  9742. break;
  9743. }
  9744. }
  9745. var fullWidth = this.width - this._barMaxWidthDelta;
  9746. var fullHeight = this.height - this._barMaxHeightDelta;
  9747. if (!this._reverse) {
  9748. if (this._barObjectH)
  9749. this._barObjectH.width = Math.round(fullWidth * percent);
  9750. if (this._barObjectV)
  9751. this._barObjectV.height = Math.round(fullHeight * percent);
  9752. }
  9753. else {
  9754. if (this._barObjectH) {
  9755. this._barObjectH.width = Math.round(fullWidth * percent);
  9756. this._barObjectH.x = this._barStartX + (fullWidth - this._barObjectH.width);
  9757. }
  9758. if (this._barObjectV) {
  9759. this._barObjectV.height = Math.round(fullHeight * percent);
  9760. this._barObjectV.y = this._barStartY + (fullHeight - this._barObjectV.height);
  9761. }
  9762. }
  9763. };
  9764. GSlider.prototype.constructExtension = function (buffer) {
  9765. buffer.seek(0, 6);
  9766. this._titleType = buffer.readByte();
  9767. this._reverse = buffer.readBool();
  9768. if (buffer.version >= 2) {
  9769. this._wholeNumbers = buffer.readBool();
  9770. this.changeOnClick = buffer.readBool();
  9771. }
  9772. this._titleObject = (this.getChild("title"));
  9773. this._barObjectH = this.getChild("bar");
  9774. this._barObjectV = this.getChild("bar_v");
  9775. this._gripObject = this.getChild("grip");
  9776. if (this._barObjectH) {
  9777. this._barMaxWidth = this._barObjectH.width;
  9778. this._barMaxWidthDelta = this.width - this._barMaxWidth;
  9779. this._barStartX = this._barObjectH.x;
  9780. }
  9781. if (this._barObjectV) {
  9782. this._barMaxHeight = this._barObjectV.height;
  9783. this._barMaxHeightDelta = this.height - this._barMaxHeight;
  9784. this._barStartY = this._barObjectV.y;
  9785. }
  9786. if (this._gripObject) {
  9787. this._gripObject.on(fgui.Event.TOUCH_BEGIN, this.onGripTouchBegin, this);
  9788. this._gripObject.on(fgui.Event.TOUCH_MOVE, this.onGripTouchMove, this);
  9789. }
  9790. this._node.on(fgui.Event.TOUCH_BEGIN, this.onBarTouchBegin, this);
  9791. };
  9792. GSlider.prototype.handleSizeChanged = function () {
  9793. _super.prototype.handleSizeChanged.call(this);
  9794. if (this._barObjectH)
  9795. this._barMaxWidth = this.width - this._barMaxWidthDelta;
  9796. if (this._barObjectV)
  9797. this._barMaxHeight = this.height - this._barMaxHeightDelta;
  9798. if (!this._underConstruct)
  9799. this.update();
  9800. };
  9801. GSlider.prototype.setup_afterAdd = function (buffer, beginPos) {
  9802. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  9803. if (!buffer.seek(beginPos, 6)) {
  9804. this.update();
  9805. return;
  9806. }
  9807. if (buffer.readByte() != this.packageItem.objectType) {
  9808. this.update();
  9809. return;
  9810. }
  9811. this._value = buffer.readInt();
  9812. this._max = buffer.readInt();
  9813. if (buffer.version >= 2)
  9814. this._min = buffer.readInt();
  9815. this.update();
  9816. };
  9817. GSlider.prototype.onGripTouchBegin = function (evt) {
  9818. this.canDrag = true;
  9819. evt.stopPropagation();
  9820. evt.captureTouch();
  9821. this._clickPos = this.globalToLocal(evt.pos.x, evt.pos.y);
  9822. this._clickPercent = fgui.ToolSet.clamp01((this._value - this._min) / (this._max - this._min));
  9823. };
  9824. GSlider.prototype.onGripTouchMove = function (evt) {
  9825. if (!this.canDrag) {
  9826. return;
  9827. }
  9828. var pt = this.globalToLocal(evt.pos.x, evt.pos.y, s_vec2);
  9829. var deltaX = pt.x - this._clickPos.x;
  9830. var deltaY = pt.y - this._clickPos.y;
  9831. if (this._reverse) {
  9832. deltaX = -deltaX;
  9833. deltaY = -deltaY;
  9834. }
  9835. var percent;
  9836. if (this._barObjectH)
  9837. percent = this._clickPercent + deltaX / this._barMaxWidth;
  9838. else
  9839. percent = this._clickPercent + deltaY / this._barMaxHeight;
  9840. this.updateWithPercent(percent, true);
  9841. };
  9842. GSlider.prototype.onBarTouchBegin = function (evt) {
  9843. if (!this.changeOnClick)
  9844. return;
  9845. var pt = this._gripObject.globalToLocal(evt.pos.x, evt.pos.y, s_vec2);
  9846. var percent = fgui.ToolSet.clamp01((this._value - this._min) / (this._max - this._min));
  9847. var delta = 0;
  9848. if (this._barObjectH != null)
  9849. delta = (pt.x - this._gripObject.width / 2) / this._barMaxWidth;
  9850. if (this._barObjectV != null)
  9851. delta = (pt.y - this._gripObject.height / 2) / this._barMaxHeight;
  9852. if (this._reverse)
  9853. percent -= delta;
  9854. else
  9855. percent += delta;
  9856. this.updateWithPercent(percent, true);
  9857. };
  9858. return GSlider;
  9859. }(fgui.GComponent));
  9860. fgui.GSlider = GSlider;
  9861. var s_vec2 = new cc.Vec2();
  9862. })(fgui || (fgui = {}));
  9863. (function (fgui) {
  9864. var GTextInput = (function (_super) {
  9865. __extends(GTextInput, _super);
  9866. function GTextInput() {
  9867. var _this = _super.call(this) || this;
  9868. _this._node.name = "GTextInput";
  9869. _this._touchDisabled = false;
  9870. return _this;
  9871. }
  9872. GTextInput.prototype.createRenderer = function () {
  9873. this._editBox = this._node.addComponent(MyEditBox);
  9874. this._editBox.maxLength = -1;
  9875. this._editBox["_updateTextLabel"]();
  9876. this._node.on('text-changed', this.onTextChanged, this);
  9877. this.on(fgui.Event.TOUCH_END, this.onTouchEnd1, this);
  9878. this.autoSize = fgui.AutoSizeType.None;
  9879. };
  9880. Object.defineProperty(GTextInput.prototype, "editable", {
  9881. get: function () {
  9882. return this._editBox.enabled;
  9883. },
  9884. set: function (val) {
  9885. this._editBox.enabled = val;
  9886. },
  9887. enumerable: false,
  9888. configurable: true
  9889. });
  9890. Object.defineProperty(GTextInput.prototype, "maxLength", {
  9891. get: function () {
  9892. return this._editBox.maxLength;
  9893. },
  9894. set: function (val) {
  9895. if (val == 0)
  9896. val = -1;
  9897. this._editBox.maxLength = val;
  9898. },
  9899. enumerable: false,
  9900. configurable: true
  9901. });
  9902. Object.defineProperty(GTextInput.prototype, "promptText", {
  9903. get: function () {
  9904. return this._promptText;
  9905. },
  9906. set: function (val) {
  9907. this._promptText = val;
  9908. var newCreate = !this._editBox.placeholderLabel;
  9909. this._editBox["_updatePlaceholderLabel"]();
  9910. if (newCreate)
  9911. this.assignFont(this._editBox.placeholderLabel, this._realFont);
  9912. this._editBox.placeholderLabel.string = fgui.UBBParser.inst.parse(this._promptText, true);
  9913. if (fgui.UBBParser.inst.lastColor) {
  9914. var c = this._editBox.placeholderLabel.node.color;
  9915. if (!c)
  9916. c = new cc.Color();
  9917. c.fromHEX(fgui.UBBParser.inst.lastColor);
  9918. this.assignFontColor(this._editBox.placeholderLabel, c);
  9919. }
  9920. else
  9921. this.assignFontColor(this._editBox.placeholderLabel, this._color);
  9922. if (fgui.UBBParser.inst.lastSize)
  9923. this._editBox.placeholderLabel.fontSize = parseInt(fgui.UBBParser.inst.lastSize);
  9924. else
  9925. this._editBox.placeholderLabel.fontSize = this._fontSize;
  9926. },
  9927. enumerable: false,
  9928. configurable: true
  9929. });
  9930. Object.defineProperty(GTextInput.prototype, "restrict", {
  9931. get: function () {
  9932. return "";
  9933. },
  9934. set: function (value) {
  9935. },
  9936. enumerable: false,
  9937. configurable: true
  9938. });
  9939. Object.defineProperty(GTextInput.prototype, "password", {
  9940. get: function () {
  9941. return this._editBox.inputFlag == cc.EditBox.InputFlag.PASSWORD;
  9942. ;
  9943. },
  9944. set: function (val) {
  9945. this._editBox.inputFlag = val ? cc.EditBox.InputFlag.PASSWORD : cc.EditBox.InputFlag.DEFAULT;
  9946. },
  9947. enumerable: false,
  9948. configurable: true
  9949. });
  9950. Object.defineProperty(GTextInput.prototype, "align", {
  9951. get: function () {
  9952. return this._editBox.textLabel.horizontalAlign;
  9953. },
  9954. set: function (value) {
  9955. this._editBox.textLabel.horizontalAlign = value;
  9956. if (this._editBox.placeholderLabel) {
  9957. this._editBox.placeholderLabel.horizontalAlign = value;
  9958. }
  9959. },
  9960. enumerable: false,
  9961. configurable: true
  9962. });
  9963. Object.defineProperty(GTextInput.prototype, "verticalAlign", {
  9964. get: function () {
  9965. return this._editBox.textLabel.verticalAlign;
  9966. },
  9967. set: function (value) {
  9968. this._editBox.textLabel.verticalAlign = value;
  9969. if (this._editBox.placeholderLabel) {
  9970. this._editBox.placeholderLabel.verticalAlign = value;
  9971. }
  9972. },
  9973. enumerable: false,
  9974. configurable: true
  9975. });
  9976. Object.defineProperty(GTextInput.prototype, "singleLine", {
  9977. get: function () {
  9978. return this._editBox.inputMode != cc.EditBox.InputMode.ANY;
  9979. },
  9980. set: function (value) {
  9981. this._editBox.inputMode = value ? cc.EditBox.InputMode.SINGLE_LINE : cc.EditBox.InputMode.ANY;
  9982. },
  9983. enumerable: false,
  9984. configurable: true
  9985. });
  9986. GTextInput.prototype.requestFocus = function () {
  9987. this._editBox.focus();
  9988. };
  9989. GTextInput.prototype.markSizeChanged = function () {
  9990. };
  9991. GTextInput.prototype.updateText = function () {
  9992. var text2 = this._text;
  9993. if (this._templateVars)
  9994. text2 = this.parseTemplate(text2);
  9995. if (this._ubbEnabled)
  9996. text2 = fgui.UBBParser.inst.parse(fgui.ToolSet.encodeHTML(text2), true);
  9997. this._editBox.string = text2;
  9998. };
  9999. GTextInput.prototype.updateFont = function () {
  10000. this.assignFont(this._editBox.textLabel, this._realFont);
  10001. if (this._editBox.placeholderLabel)
  10002. this.assignFont(this._editBox.placeholderLabel, this._realFont);
  10003. };
  10004. GTextInput.prototype.updateFontColor = function () {
  10005. this.assignFontColor(this._editBox.textLabel, this._color);
  10006. };
  10007. GTextInput.prototype.updateFontSize = function () {
  10008. this._editBox.textLabel.fontSize = this._fontSize;
  10009. this._editBox.textLabel.lineHeight = this._fontSize + this._leading;
  10010. if (this._editBox.placeholderLabel)
  10011. this._editBox.placeholderLabel.fontSize = this._editBox.textLabel.fontSize;
  10012. };
  10013. GTextInput.prototype.updateOverflow = function () {
  10014. };
  10015. GTextInput.prototype.onTextChanged = function () {
  10016. this._text = this._editBox.string;
  10017. };
  10018. GTextInput.prototype.onTouchEnd1 = function (evt) {
  10019. this._editBox.openKeyboard(evt.touch);
  10020. };
  10021. GTextInput.prototype.setup_beforeAdd = function (buffer, beginPos) {
  10022. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  10023. buffer.seek(beginPos, 4);
  10024. var str = buffer.readS();
  10025. if (str != null)
  10026. this.promptText = str;
  10027. str = buffer.readS();
  10028. if (str != null)
  10029. this.restrict = str;
  10030. var iv = buffer.readInt();
  10031. if (iv != 0)
  10032. this.maxLength = iv;
  10033. iv = buffer.readInt();
  10034. if (iv != 0) {
  10035. }
  10036. if (buffer.readBool())
  10037. this.password = true;
  10038. if (this._editBox.placeholderLabel) {
  10039. var hAlign = this._editBox.textLabel.horizontalAlign;
  10040. this._editBox.placeholderLabel.horizontalAlign = hAlign;
  10041. var vAlign = this._editBox.textLabel.verticalAlign;
  10042. this._editBox.placeholderLabel.verticalAlign = vAlign;
  10043. }
  10044. };
  10045. return GTextInput;
  10046. }(fgui.GTextField));
  10047. fgui.GTextInput = GTextInput;
  10048. var MyEditBox = (function (_super) {
  10049. __extends(MyEditBox, _super);
  10050. function MyEditBox() {
  10051. return _super !== null && _super.apply(this, arguments) || this;
  10052. }
  10053. MyEditBox.prototype._registerEvent = function () {
  10054. };
  10055. MyEditBox.prototype._syncSize = function () {
  10056. var size = this.node.getContentSize();
  10057. var impl = this["_impl"];
  10058. impl.setSize(size.width, size.height);
  10059. if (this.textLabel)
  10060. this.textLabel.node.setContentSize(size.width, size.height);
  10061. if (this.placeholderLabel)
  10062. this.placeholderLabel.node.setContentSize(size.width, size.height);
  10063. };
  10064. MyEditBox.prototype.openKeyboard = function (touch) {
  10065. var impl = this["_impl"];
  10066. if (impl) {
  10067. impl.beginEditing();
  10068. }
  10069. };
  10070. return MyEditBox;
  10071. }(cc.EditBox));
  10072. })(fgui || (fgui = {}));
  10073. (function (fgui) {
  10074. var GTree = (function (_super) {
  10075. __extends(GTree, _super);
  10076. function GTree() {
  10077. var _this = _super.call(this) || this;
  10078. _this._indent = 15;
  10079. _this._rootNode = new fgui.GTreeNode(true);
  10080. _this._rootNode._setTree(_this);
  10081. _this._rootNode.expanded = true;
  10082. return _this;
  10083. }
  10084. Object.defineProperty(GTree.prototype, "rootNode", {
  10085. get: function () {
  10086. return this._rootNode;
  10087. },
  10088. enumerable: false,
  10089. configurable: true
  10090. });
  10091. Object.defineProperty(GTree.prototype, "indent", {
  10092. get: function () {
  10093. return this._indent;
  10094. },
  10095. set: function (value) {
  10096. this._indent = value;
  10097. },
  10098. enumerable: false,
  10099. configurable: true
  10100. });
  10101. Object.defineProperty(GTree.prototype, "clickToExpand", {
  10102. get: function () {
  10103. return this._clickToExpand;
  10104. },
  10105. set: function (value) {
  10106. this._clickToExpand = value;
  10107. },
  10108. enumerable: false,
  10109. configurable: true
  10110. });
  10111. GTree.prototype.getSelectedNode = function () {
  10112. if (this.selectedIndex != -1)
  10113. return this.getChildAt(this.selectedIndex)._treeNode;
  10114. else
  10115. return null;
  10116. };
  10117. GTree.prototype.getSelectedNodes = function (result) {
  10118. if (!result)
  10119. result = new Array();
  10120. s_list.length = 0;
  10121. _super.prototype.getSelection.call(this, s_list);
  10122. var cnt = s_list.length;
  10123. var ret = new Array();
  10124. for (var i = 0; i < cnt; i++) {
  10125. var node = this.getChildAt(s_list[i])._treeNode;
  10126. ret.push(node);
  10127. }
  10128. return ret;
  10129. };
  10130. GTree.prototype.selectNode = function (node, scrollItToView) {
  10131. var parentNode = node.parent;
  10132. while (parentNode && parentNode != this._rootNode) {
  10133. parentNode.expanded = true;
  10134. parentNode = parentNode.parent;
  10135. }
  10136. if (!node._cell)
  10137. return;
  10138. this.addSelection(this.getChildIndex(node._cell), scrollItToView);
  10139. };
  10140. GTree.prototype.unselectNode = function (node) {
  10141. if (!node._cell)
  10142. return;
  10143. this.removeSelection(this.getChildIndex(node._cell));
  10144. };
  10145. GTree.prototype.expandAll = function (folderNode) {
  10146. if (!folderNode)
  10147. folderNode = this._rootNode;
  10148. folderNode.expanded = true;
  10149. var cnt = folderNode.numChildren;
  10150. for (var i = 0; i < cnt; i++) {
  10151. var node = folderNode.getChildAt(i);
  10152. if (node.isFolder)
  10153. this.expandAll(node);
  10154. }
  10155. };
  10156. GTree.prototype.collapseAll = function (folderNode) {
  10157. if (!folderNode)
  10158. folderNode = this._rootNode;
  10159. if (folderNode != this._rootNode)
  10160. folderNode.expanded = false;
  10161. var cnt = folderNode.numChildren;
  10162. for (var i = 0; i < cnt; i++) {
  10163. var node = folderNode.getChildAt(i);
  10164. if (node.isFolder)
  10165. this.collapseAll(node);
  10166. }
  10167. };
  10168. GTree.prototype.createCell = function (node) {
  10169. var child = this.getFromPool(node._resURL);
  10170. if (!(child instanceof fgui.GComponent))
  10171. throw new Error("cannot create tree node object.");
  10172. child._treeNode = node;
  10173. node._cell = child;
  10174. var indentObj = child.getChild("indent");
  10175. if (indentObj)
  10176. indentObj.width = (node.level - 1) * this._indent;
  10177. var cc;
  10178. cc = child.getController("expanded");
  10179. if (cc) {
  10180. cc.on(fgui.Event.STATUS_CHANGED, this.__expandedStateChanged, this);
  10181. cc.selectedIndex = node.expanded ? 1 : 0;
  10182. }
  10183. cc = child.getController("leaf");
  10184. if (cc)
  10185. cc.selectedIndex = node.isFolder ? 0 : 1;
  10186. if (node.isFolder)
  10187. node._cell.on(fgui.Event.TOUCH_BEGIN, this.__cellMouseDown, this);
  10188. if (this.treeNodeRender)
  10189. this.treeNodeRender(node, child);
  10190. };
  10191. GTree.prototype._afterInserted = function (node) {
  10192. if (!node._cell)
  10193. this.createCell(node);
  10194. var index = this.getInsertIndexForNode(node);
  10195. this.addChildAt(node._cell, index);
  10196. if (this.treeNodeRender)
  10197. this.treeNodeRender(node, node._cell);
  10198. if (node.isFolder && node.expanded)
  10199. this.checkChildren(node, index);
  10200. };
  10201. GTree.prototype.getInsertIndexForNode = function (node) {
  10202. var prevNode = node.getPrevSibling();
  10203. if (prevNode == null)
  10204. prevNode = node.parent;
  10205. var insertIndex = this.getChildIndex(prevNode._cell) + 1;
  10206. var myLevel = node.level;
  10207. var cnt = this.numChildren;
  10208. for (var i = insertIndex; i < cnt; i++) {
  10209. var testNode = this.getChildAt(i)._treeNode;
  10210. if (testNode.level <= myLevel)
  10211. break;
  10212. insertIndex++;
  10213. }
  10214. return insertIndex;
  10215. };
  10216. GTree.prototype._afterRemoved = function (node) {
  10217. this.removeNode(node);
  10218. };
  10219. GTree.prototype._afterExpanded = function (node) {
  10220. if (node == this._rootNode) {
  10221. this.checkChildren(this._rootNode, 0);
  10222. return;
  10223. }
  10224. if (this.treeNodeWillExpand != null)
  10225. this.treeNodeWillExpand(node, true);
  10226. if (node._cell == null)
  10227. return;
  10228. if (this.treeNodeRender)
  10229. this.treeNodeRender(node, node._cell);
  10230. var cc = node._cell.getController("expanded");
  10231. if (cc)
  10232. cc.selectedIndex = 1;
  10233. if (node._cell.parent)
  10234. this.checkChildren(node, this.getChildIndex(node._cell));
  10235. };
  10236. GTree.prototype._afterCollapsed = function (node) {
  10237. if (node == this._rootNode) {
  10238. this.checkChildren(this._rootNode, 0);
  10239. return;
  10240. }
  10241. if (this.treeNodeWillExpand)
  10242. this.treeNodeWillExpand(node, false);
  10243. if (node._cell == null)
  10244. return;
  10245. if (this.treeNodeRender)
  10246. this.treeNodeRender(node, node._cell);
  10247. var cc = node._cell.getController("expanded");
  10248. if (cc)
  10249. cc.selectedIndex = 0;
  10250. if (node._cell.parent)
  10251. this.hideFolderNode(node);
  10252. };
  10253. GTree.prototype._afterMoved = function (node) {
  10254. var startIndex = this.getChildIndex(node._cell);
  10255. var endIndex;
  10256. if (node.isFolder)
  10257. endIndex = this.getFolderEndIndex(startIndex, node.level);
  10258. else
  10259. endIndex = startIndex + 1;
  10260. var insertIndex = this.getInsertIndexForNode(node);
  10261. var i;
  10262. var cnt = endIndex - startIndex;
  10263. var obj;
  10264. if (insertIndex < startIndex) {
  10265. for (i = 0; i < cnt; i++) {
  10266. obj = this.getChildAt(startIndex + i);
  10267. this.setChildIndex(obj, insertIndex + i);
  10268. }
  10269. }
  10270. else {
  10271. for (i = 0; i < cnt; i++) {
  10272. obj = this.getChildAt(startIndex);
  10273. this.setChildIndex(obj, insertIndex);
  10274. }
  10275. }
  10276. };
  10277. GTree.prototype.getFolderEndIndex = function (startIndex, level) {
  10278. var cnt = this.numChildren;
  10279. for (var i = startIndex + 1; i < cnt; i++) {
  10280. var node = this.getChildAt(i)._treeNode;
  10281. if (node.level <= level)
  10282. return i;
  10283. }
  10284. return cnt;
  10285. };
  10286. GTree.prototype.checkChildren = function (folderNode, index) {
  10287. var cnt = folderNode.numChildren;
  10288. for (var i = 0; i < cnt; i++) {
  10289. index++;
  10290. var node = folderNode.getChildAt(i);
  10291. if (node._cell == null)
  10292. this.createCell(node);
  10293. if (!node._cell.parent)
  10294. this.addChildAt(node._cell, index);
  10295. if (node.isFolder && node.expanded)
  10296. index = this.checkChildren(node, index);
  10297. }
  10298. return index;
  10299. };
  10300. GTree.prototype.hideFolderNode = function (folderNode) {
  10301. var cnt = folderNode.numChildren;
  10302. for (var i = 0; i < cnt; i++) {
  10303. var node = folderNode.getChildAt(i);
  10304. if (node._cell)
  10305. this.removeChild(node._cell);
  10306. if (node.isFolder && node.expanded)
  10307. this.hideFolderNode(node);
  10308. }
  10309. };
  10310. GTree.prototype.removeNode = function (node) {
  10311. if (node._cell) {
  10312. if (node._cell.parent)
  10313. this.removeChild(node._cell);
  10314. this.returnToPool(node._cell);
  10315. node._cell._treeNode = null;
  10316. node._cell = null;
  10317. }
  10318. if (node.isFolder) {
  10319. var cnt = node.numChildren;
  10320. for (var i = 0; i < cnt; i++) {
  10321. var node2 = node.getChildAt(i);
  10322. this.removeNode(node2);
  10323. }
  10324. }
  10325. };
  10326. GTree.prototype.__cellMouseDown = function (evt) {
  10327. var node = fgui.GObject.cast(evt.currentTarget)._treeNode;
  10328. this._expandedStatusInEvt = node.expanded;
  10329. };
  10330. GTree.prototype.__expandedStateChanged = function (cc) {
  10331. var node = cc.parent._treeNode;
  10332. node.expanded = cc.selectedIndex == 1;
  10333. };
  10334. GTree.prototype.dispatchItemEvent = function (item, evt) {
  10335. if (this._clickToExpand != 0) {
  10336. var node = item._treeNode;
  10337. if (node && this._expandedStatusInEvt == node.expanded) {
  10338. if (this._clickToExpand == 2) {
  10339. }
  10340. else
  10341. node.expanded = !node.expanded;
  10342. }
  10343. }
  10344. _super.prototype.dispatchItemEvent.call(this, item, evt);
  10345. };
  10346. GTree.prototype.setup_beforeAdd = function (buffer, beginPos) {
  10347. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  10348. buffer.seek(beginPos, 9);
  10349. this._indent = buffer.readInt();
  10350. this._clickToExpand = buffer.readByte();
  10351. };
  10352. GTree.prototype.readItems = function (buffer) {
  10353. var cnt;
  10354. var i;
  10355. var nextPos;
  10356. var str;
  10357. var isFolder;
  10358. var lastNode;
  10359. var level;
  10360. var prevLevel = 0;
  10361. cnt = buffer.readShort();
  10362. for (i = 0; i < cnt; i++) {
  10363. nextPos = buffer.readShort();
  10364. nextPos += buffer.position;
  10365. str = buffer.readS();
  10366. if (str == null) {
  10367. str = this.defaultItem;
  10368. if (!str) {
  10369. buffer.position = nextPos;
  10370. continue;
  10371. }
  10372. }
  10373. isFolder = buffer.readBool();
  10374. level = buffer.readByte();
  10375. var node = new fgui.GTreeNode(isFolder, str);
  10376. node.expanded = true;
  10377. if (i == 0)
  10378. this._rootNode.addChild(node);
  10379. else {
  10380. if (level > prevLevel)
  10381. lastNode.addChild(node);
  10382. else if (level < prevLevel) {
  10383. for (var j = level; j <= prevLevel; j++)
  10384. lastNode = lastNode.parent;
  10385. lastNode.addChild(node);
  10386. }
  10387. else
  10388. lastNode.parent.addChild(node);
  10389. }
  10390. lastNode = node;
  10391. prevLevel = level;
  10392. this.setupItem(buffer, node.cell);
  10393. buffer.position = nextPos;
  10394. }
  10395. };
  10396. return GTree;
  10397. }(fgui.GList));
  10398. fgui.GTree = GTree;
  10399. var s_list = new Array();
  10400. })(fgui || (fgui = {}));
  10401. (function (fgui) {
  10402. var GTreeNode = (function () {
  10403. function GTreeNode(hasChild, resURL) {
  10404. this._level = 0;
  10405. this._resURL = resURL;
  10406. if (hasChild)
  10407. this._children = new Array();
  10408. }
  10409. Object.defineProperty(GTreeNode.prototype, "expanded", {
  10410. get: function () {
  10411. return this._expanded;
  10412. },
  10413. set: function (value) {
  10414. if (this._children == null)
  10415. return;
  10416. if (this._expanded != value) {
  10417. this._expanded = value;
  10418. if (this._tree) {
  10419. if (this._expanded)
  10420. this._tree._afterExpanded(this);
  10421. else
  10422. this._tree._afterCollapsed(this);
  10423. }
  10424. }
  10425. },
  10426. enumerable: false,
  10427. configurable: true
  10428. });
  10429. Object.defineProperty(GTreeNode.prototype, "isFolder", {
  10430. get: function () {
  10431. return this._children != null;
  10432. },
  10433. enumerable: false,
  10434. configurable: true
  10435. });
  10436. Object.defineProperty(GTreeNode.prototype, "parent", {
  10437. get: function () {
  10438. return this._parent;
  10439. },
  10440. enumerable: false,
  10441. configurable: true
  10442. });
  10443. Object.defineProperty(GTreeNode.prototype, "text", {
  10444. get: function () {
  10445. if (this._cell)
  10446. return this._cell.text;
  10447. else
  10448. return null;
  10449. },
  10450. set: function (value) {
  10451. if (this._cell)
  10452. this._cell.text = value;
  10453. },
  10454. enumerable: false,
  10455. configurable: true
  10456. });
  10457. Object.defineProperty(GTreeNode.prototype, "icon", {
  10458. get: function () {
  10459. if (this._cell)
  10460. return this._cell.icon;
  10461. else
  10462. return null;
  10463. },
  10464. set: function (value) {
  10465. if (this._cell)
  10466. this._cell.icon = value;
  10467. },
  10468. enumerable: false,
  10469. configurable: true
  10470. });
  10471. Object.defineProperty(GTreeNode.prototype, "cell", {
  10472. get: function () {
  10473. return this._cell;
  10474. },
  10475. enumerable: false,
  10476. configurable: true
  10477. });
  10478. Object.defineProperty(GTreeNode.prototype, "level", {
  10479. get: function () {
  10480. return this._level;
  10481. },
  10482. enumerable: false,
  10483. configurable: true
  10484. });
  10485. GTreeNode.prototype._setLevel = function (value) {
  10486. this._level = value;
  10487. };
  10488. GTreeNode.prototype.addChild = function (child) {
  10489. this.addChildAt(child, this._children.length);
  10490. return child;
  10491. };
  10492. GTreeNode.prototype.addChildAt = function (child, index) {
  10493. if (!child)
  10494. throw new Error("child is null");
  10495. var numChildren = this._children.length;
  10496. if (index >= 0 && index <= numChildren) {
  10497. if (child._parent == this) {
  10498. this.setChildIndex(child, index);
  10499. }
  10500. else {
  10501. if (child._parent)
  10502. child._parent.removeChild(child);
  10503. var cnt = this._children.length;
  10504. if (index == cnt)
  10505. this._children.push(child);
  10506. else
  10507. this._children.splice(index, 0, child);
  10508. child._parent = this;
  10509. child._level = this._level + 1;
  10510. child._setTree(this._tree);
  10511. if (this._tree && this == this._tree.rootNode || this._cell && this._cell.parent && this._expanded)
  10512. this._tree._afterInserted(child);
  10513. }
  10514. return child;
  10515. }
  10516. else {
  10517. throw new RangeError("Invalid child index");
  10518. }
  10519. };
  10520. GTreeNode.prototype.removeChild = function (child) {
  10521. var childIndex = this._children.indexOf(child);
  10522. if (childIndex != -1) {
  10523. this.removeChildAt(childIndex);
  10524. }
  10525. return child;
  10526. };
  10527. GTreeNode.prototype.removeChildAt = function (index) {
  10528. if (index >= 0 && index < this.numChildren) {
  10529. var child = this._children[index];
  10530. this._children.splice(index, 1);
  10531. child._parent = null;
  10532. if (this._tree) {
  10533. child._setTree(null);
  10534. this._tree._afterRemoved(child);
  10535. }
  10536. return child;
  10537. }
  10538. else {
  10539. throw "Invalid child index";
  10540. }
  10541. };
  10542. GTreeNode.prototype.removeChildren = function (beginIndex, endIndex) {
  10543. beginIndex = beginIndex || 0;
  10544. if (endIndex == null)
  10545. endIndex = -1;
  10546. if (endIndex < 0 || endIndex >= this.numChildren)
  10547. endIndex = this.numChildren - 1;
  10548. for (var i = beginIndex; i <= endIndex; ++i)
  10549. this.removeChildAt(beginIndex);
  10550. };
  10551. GTreeNode.prototype.getChildAt = function (index) {
  10552. if (index >= 0 && index < this.numChildren)
  10553. return this._children[index];
  10554. else
  10555. throw "Invalid child index";
  10556. };
  10557. GTreeNode.prototype.getChildIndex = function (child) {
  10558. return this._children.indexOf(child);
  10559. };
  10560. GTreeNode.prototype.getPrevSibling = function () {
  10561. if (this._parent == null)
  10562. return null;
  10563. var i = this._parent._children.indexOf(this);
  10564. if (i <= 0)
  10565. return null;
  10566. return this._parent._children[i - 1];
  10567. };
  10568. GTreeNode.prototype.getNextSibling = function () {
  10569. if (this._parent == null)
  10570. return null;
  10571. var i = this._parent._children.indexOf(this);
  10572. if (i < 0 || i >= this._parent._children.length - 1)
  10573. return null;
  10574. return this._parent._children[i + 1];
  10575. };
  10576. GTreeNode.prototype.setChildIndex = function (child, index) {
  10577. var oldIndex = this._children.indexOf(child);
  10578. if (oldIndex == -1)
  10579. throw "Not a child of this container";
  10580. var cnt = this._children.length;
  10581. if (index < 0)
  10582. index = 0;
  10583. else if (index > cnt)
  10584. index = cnt;
  10585. if (oldIndex == index)
  10586. return;
  10587. this._children.splice(oldIndex, 1);
  10588. this._children.splice(index, 0, child);
  10589. if (this._tree && this == this._tree.rootNode || this._cell && this._cell.parent && this._expanded)
  10590. this._tree._afterMoved(child);
  10591. };
  10592. GTreeNode.prototype.swapChildren = function (child1, child2) {
  10593. var index1 = this._children.indexOf(child1);
  10594. var index2 = this._children.indexOf(child2);
  10595. if (index1 == -1 || index2 == -1)
  10596. throw "Not a child of this container";
  10597. this.swapChildrenAt(index1, index2);
  10598. };
  10599. GTreeNode.prototype.swapChildrenAt = function (index1, index2) {
  10600. var child1 = this._children[index1];
  10601. var child2 = this._children[index2];
  10602. this.setChildIndex(child1, index2);
  10603. this.setChildIndex(child2, index1);
  10604. };
  10605. Object.defineProperty(GTreeNode.prototype, "numChildren", {
  10606. get: function () {
  10607. return this._children.length;
  10608. },
  10609. enumerable: false,
  10610. configurable: true
  10611. });
  10612. GTreeNode.prototype.expandToRoot = function () {
  10613. var p = this;
  10614. while (p) {
  10615. p.expanded = true;
  10616. p = p.parent;
  10617. }
  10618. };
  10619. Object.defineProperty(GTreeNode.prototype, "tree", {
  10620. get: function () {
  10621. return this._tree;
  10622. },
  10623. enumerable: false,
  10624. configurable: true
  10625. });
  10626. GTreeNode.prototype._setTree = function (value) {
  10627. this._tree = value;
  10628. if (this._tree && this._tree.treeNodeWillExpand && this._expanded)
  10629. this._tree.treeNodeWillExpand(this, true);
  10630. if (this._children) {
  10631. var cnt = this._children.length;
  10632. for (var i = 0; i < cnt; i++) {
  10633. var node = this._children[i];
  10634. node._level = this._level + 1;
  10635. node._setTree(value);
  10636. }
  10637. }
  10638. };
  10639. return GTreeNode;
  10640. }());
  10641. fgui.GTreeNode = GTreeNode;
  10642. })(fgui || (fgui = {}));
  10643. (function (fgui) {
  10644. var Margin = (function () {
  10645. function Margin() {
  10646. this.left = 0;
  10647. this.right = 0;
  10648. this.top = 0;
  10649. this.bottom = 0;
  10650. }
  10651. Margin.prototype.copy = function (source) {
  10652. this.top = source.top;
  10653. this.bottom = source.bottom;
  10654. this.left = source.left;
  10655. this.right = source.right;
  10656. };
  10657. Margin.prototype.isNone = function () {
  10658. return this.left == 0 && this.right == 0 && this.top == 0 && this.bottom == 0;
  10659. };
  10660. return Margin;
  10661. }());
  10662. fgui.Margin = Margin;
  10663. })(fgui || (fgui = {}));
  10664. (function (fgui) {
  10665. var PackageItem = (function () {
  10666. function PackageItem() {
  10667. this.width = 0;
  10668. this.height = 0;
  10669. }
  10670. PackageItem.prototype.load = function () {
  10671. return this.owner.getItemAsset(this);
  10672. };
  10673. PackageItem.prototype.getBranch = function () {
  10674. if (this.branches && this.owner._branchIndex != -1) {
  10675. var itemId = this.branches[this.owner._branchIndex];
  10676. if (itemId)
  10677. return this.owner.getItemById(itemId);
  10678. }
  10679. return this;
  10680. };
  10681. PackageItem.prototype.getHighResolution = function () {
  10682. if (this.highResolution && fgui.GRoot.contentScaleLevel > 0) {
  10683. var itemId = this.highResolution[fgui.GRoot.contentScaleLevel - 1];
  10684. if (itemId)
  10685. return this.owner.getItemById(itemId);
  10686. }
  10687. return this;
  10688. };
  10689. PackageItem.prototype.toString = function () {
  10690. return this.name;
  10691. };
  10692. return PackageItem;
  10693. }());
  10694. fgui.PackageItem = PackageItem;
  10695. })(fgui || (fgui = {}));
  10696. (function (fgui) {
  10697. var PopupMenu = (function () {
  10698. function PopupMenu(url) {
  10699. if (!url) {
  10700. url = fgui.UIConfig.popupMenu;
  10701. if (!url)
  10702. throw "UIConfig.popupMenu not defined";
  10703. }
  10704. this._contentPane = fgui.UIPackage.createObjectFromURL(url);
  10705. this._contentPane.on(fgui.Event.DISPLAY, this.onDisplay, this);
  10706. this._list = (this._contentPane.getChild("list"));
  10707. this._list.removeChildrenToPool();
  10708. this._list.addRelation(this._contentPane, fgui.RelationType.Width);
  10709. this._list.removeRelation(this._contentPane, fgui.RelationType.Height);
  10710. this._contentPane.addRelation(this._list, fgui.RelationType.Height);
  10711. this._list.on(fgui.Event.CLICK_ITEM, this.onClickItem, this);
  10712. }
  10713. PopupMenu.prototype.dispose = function () {
  10714. this._contentPane.dispose();
  10715. };
  10716. PopupMenu.prototype.addItem = function (caption, callback) {
  10717. var item = this._list.addItemFromPool();
  10718. item.title = caption;
  10719. item.data = callback;
  10720. item.grayed = false;
  10721. var c = item.getController("checked");
  10722. if (c)
  10723. c.selectedIndex = 0;
  10724. return item;
  10725. };
  10726. PopupMenu.prototype.addItemAt = function (caption, index, callback) {
  10727. var item = this._list.getFromPool();
  10728. this._list.addChildAt(item, index);
  10729. item.title = caption;
  10730. item.data = callback;
  10731. item.grayed = false;
  10732. var c = item.getController("checked");
  10733. if (c)
  10734. c.selectedIndex = 0;
  10735. return item;
  10736. };
  10737. PopupMenu.prototype.addSeperator = function () {
  10738. if (fgui.UIConfig.popupMenu_seperator == null)
  10739. throw "UIConfig.popupMenu_seperator not defined";
  10740. this.list.addItemFromPool(fgui.UIConfig.popupMenu_seperator);
  10741. };
  10742. PopupMenu.prototype.getItemName = function (index) {
  10743. var item = this._list.getChildAt(index);
  10744. return item.name;
  10745. };
  10746. PopupMenu.prototype.setItemText = function (name, caption) {
  10747. var item = this._list.getChild(name);
  10748. item.title = caption;
  10749. };
  10750. PopupMenu.prototype.setItemVisible = function (name, visible) {
  10751. var item = this._list.getChild(name);
  10752. if (item.visible != visible) {
  10753. item.visible = visible;
  10754. this._list.setBoundsChangedFlag();
  10755. }
  10756. };
  10757. PopupMenu.prototype.setItemGrayed = function (name, grayed) {
  10758. var item = this._list.getChild(name);
  10759. item.grayed = grayed;
  10760. };
  10761. PopupMenu.prototype.setItemCheckable = function (name, checkable) {
  10762. var item = this._list.getChild(name);
  10763. var c = item.getController("checked");
  10764. if (c) {
  10765. if (checkable) {
  10766. if (c.selectedIndex == 0)
  10767. c.selectedIndex = 1;
  10768. }
  10769. else
  10770. c.selectedIndex = 0;
  10771. }
  10772. };
  10773. PopupMenu.prototype.setItemChecked = function (name, checked) {
  10774. var item = this._list.getChild(name);
  10775. var c = item.getController("checked");
  10776. if (c)
  10777. c.selectedIndex = checked ? 2 : 1;
  10778. };
  10779. PopupMenu.prototype.isItemChecked = function (name) {
  10780. var item = this._list.getChild(name);
  10781. var c = item.getController("checked");
  10782. if (c)
  10783. return c.selectedIndex == 2;
  10784. else
  10785. return false;
  10786. };
  10787. PopupMenu.prototype.removeItem = function (name) {
  10788. var item = this._list.getChild(name);
  10789. if (item) {
  10790. var index = this._list.getChildIndex(item);
  10791. this._list.removeChildToPoolAt(index);
  10792. return true;
  10793. }
  10794. else
  10795. return false;
  10796. };
  10797. PopupMenu.prototype.clearItems = function () {
  10798. this._list.removeChildrenToPool();
  10799. };
  10800. Object.defineProperty(PopupMenu.prototype, "itemCount", {
  10801. get: function () {
  10802. return this._list.numChildren;
  10803. },
  10804. enumerable: false,
  10805. configurable: true
  10806. });
  10807. Object.defineProperty(PopupMenu.prototype, "contentPane", {
  10808. get: function () {
  10809. return this._contentPane;
  10810. },
  10811. enumerable: false,
  10812. configurable: true
  10813. });
  10814. Object.defineProperty(PopupMenu.prototype, "list", {
  10815. get: function () {
  10816. return this._list;
  10817. },
  10818. enumerable: false,
  10819. configurable: true
  10820. });
  10821. PopupMenu.prototype.show = function (target, dir) {
  10822. if (target === void 0) { target = null; }
  10823. var r = target != null ? target.root : fgui.GRoot.inst;
  10824. r.showPopup(this.contentPane, (target instanceof fgui.GRoot) ? null : target, dir);
  10825. };
  10826. PopupMenu.prototype.onClickItem = function (item, evt) {
  10827. var _this = this;
  10828. this._list._partner.callLater(function (dt) {
  10829. _this.onClickItem2(item, evt);
  10830. }, 0.1);
  10831. };
  10832. PopupMenu.prototype.onClickItem2 = function (item, evt) {
  10833. if (!(item instanceof fgui.GButton))
  10834. return;
  10835. if (item.grayed) {
  10836. this._list.selectedIndex = -1;
  10837. return;
  10838. }
  10839. var c = item.getController("checked");
  10840. if (c && c.selectedIndex != 0) {
  10841. if (c.selectedIndex == 1)
  10842. c.selectedIndex = 2;
  10843. else
  10844. c.selectedIndex = 1;
  10845. }
  10846. var r = (this._contentPane.parent);
  10847. r.hidePopup(this.contentPane);
  10848. if (item.data instanceof Function)
  10849. item.data(item, evt);
  10850. };
  10851. PopupMenu.prototype.onDisplay = function () {
  10852. this._list.selectedIndex = -1;
  10853. this._list.resizeToFit(100000, 10);
  10854. };
  10855. return PopupMenu;
  10856. }());
  10857. fgui.PopupMenu = PopupMenu;
  10858. })(fgui || (fgui = {}));
  10859. (function (fgui) {
  10860. var RelationItem = (function () {
  10861. function RelationItem(owner) {
  10862. this._owner = owner;
  10863. this._defs = new Array();
  10864. }
  10865. Object.defineProperty(RelationItem.prototype, "owner", {
  10866. get: function () {
  10867. return this._owner;
  10868. },
  10869. enumerable: false,
  10870. configurable: true
  10871. });
  10872. Object.defineProperty(RelationItem.prototype, "target", {
  10873. get: function () {
  10874. return this._target;
  10875. },
  10876. set: function (value) {
  10877. if (this._target != value) {
  10878. if (this._target)
  10879. this.releaseRefTarget(this._target);
  10880. this._target = value;
  10881. if (this._target)
  10882. this.addRefTarget(this._target);
  10883. }
  10884. },
  10885. enumerable: false,
  10886. configurable: true
  10887. });
  10888. RelationItem.prototype.add = function (relationType, usePercent) {
  10889. if (relationType == fgui.RelationType.Size) {
  10890. this.add(fgui.RelationType.Width, usePercent);
  10891. this.add(fgui.RelationType.Height, usePercent);
  10892. return;
  10893. }
  10894. var length = this._defs.length;
  10895. for (var i = 0; i < length; i++) {
  10896. var def = this._defs[i];
  10897. if (def.type == relationType)
  10898. return;
  10899. }
  10900. this.internalAdd(relationType, usePercent);
  10901. };
  10902. RelationItem.prototype.internalAdd = function (relationType, usePercent) {
  10903. if (relationType == fgui.RelationType.Size) {
  10904. this.internalAdd(fgui.RelationType.Width, usePercent);
  10905. this.internalAdd(fgui.RelationType.Height, usePercent);
  10906. return;
  10907. }
  10908. var info = new RelationDef();
  10909. info.percent = usePercent;
  10910. info.type = relationType;
  10911. info.axis = (relationType <= fgui.RelationType.Right_Right || relationType == fgui.RelationType.Width || relationType >= fgui.RelationType.LeftExt_Left && relationType <= fgui.RelationType.RightExt_Right) ? 0 : 1;
  10912. this._defs.push(info);
  10913. };
  10914. RelationItem.prototype.remove = function (relationType) {
  10915. if (relationType == fgui.RelationType.Size) {
  10916. this.remove(fgui.RelationType.Width);
  10917. this.remove(fgui.RelationType.Height);
  10918. return;
  10919. }
  10920. var dc = this._defs.length;
  10921. for (var k = 0; k < dc; k++) {
  10922. if (this._defs[k].type == relationType) {
  10923. this._defs.splice(k, 1);
  10924. break;
  10925. }
  10926. }
  10927. };
  10928. RelationItem.prototype.copyFrom = function (source) {
  10929. this.target = source.target;
  10930. this._defs.length = 0;
  10931. var length = source._defs.length;
  10932. for (var i = 0; i < length; i++) {
  10933. var info = source._defs[i];
  10934. var info2 = new RelationDef();
  10935. info2.copyFrom(info);
  10936. this._defs.push(info2);
  10937. }
  10938. };
  10939. RelationItem.prototype.dispose = function () {
  10940. if (this._target) {
  10941. this.releaseRefTarget(this._target);
  10942. this._target = null;
  10943. }
  10944. };
  10945. Object.defineProperty(RelationItem.prototype, "isEmpty", {
  10946. get: function () {
  10947. return this._defs.length == 0;
  10948. },
  10949. enumerable: false,
  10950. configurable: true
  10951. });
  10952. RelationItem.prototype.applyOnSelfResized = function (dWidth, dHeight, applyPivot) {
  10953. var ox = this._owner.x;
  10954. var oy = this._owner.y;
  10955. var length = this._defs.length;
  10956. for (var i = 0; i < length; i++) {
  10957. var info = this._defs[i];
  10958. switch (info.type) {
  10959. case fgui.RelationType.Center_Center:
  10960. this._owner.x -= (0.5 - (applyPivot ? this._owner.pivotX : 0)) * dWidth;
  10961. break;
  10962. case fgui.RelationType.Right_Center:
  10963. case fgui.RelationType.Right_Left:
  10964. case fgui.RelationType.Right_Right:
  10965. this._owner.x -= (1 - (applyPivot ? this._owner.pivotX : 0)) * dWidth;
  10966. break;
  10967. case fgui.RelationType.Middle_Middle:
  10968. this._owner.y -= (0.5 - (applyPivot ? this._owner.pivotY : 0)) * dHeight;
  10969. break;
  10970. case fgui.RelationType.Bottom_Middle:
  10971. case fgui.RelationType.Bottom_Top:
  10972. case fgui.RelationType.Bottom_Bottom:
  10973. this._owner.y -= (1 - (applyPivot ? this._owner.pivotY : 0)) * dHeight;
  10974. break;
  10975. }
  10976. }
  10977. if (ox != this._owner.x || oy != this._owner.y) {
  10978. ox = this._owner.x - ox;
  10979. oy = this._owner.y - oy;
  10980. this._owner.updateGearFromRelations(1, ox, oy);
  10981. if (this._owner.parent) {
  10982. var len = this._owner.parent._transitions.length;
  10983. if (len > 0) {
  10984. for (var i = 0; i < len; ++i) {
  10985. this._owner.parent._transitions[i].updateFromRelations(this._owner.id, ox, oy);
  10986. }
  10987. }
  10988. }
  10989. }
  10990. };
  10991. RelationItem.prototype.applyOnXYChanged = function (info, dx, dy) {
  10992. var tmp;
  10993. switch (info.type) {
  10994. case fgui.RelationType.Left_Left:
  10995. case fgui.RelationType.Left_Center:
  10996. case fgui.RelationType.Left_Right:
  10997. case fgui.RelationType.Center_Center:
  10998. case fgui.RelationType.Right_Left:
  10999. case fgui.RelationType.Right_Center:
  11000. case fgui.RelationType.Right_Right:
  11001. this._owner.x += dx;
  11002. break;
  11003. case fgui.RelationType.Top_Top:
  11004. case fgui.RelationType.Top_Middle:
  11005. case fgui.RelationType.Top_Bottom:
  11006. case fgui.RelationType.Middle_Middle:
  11007. case fgui.RelationType.Bottom_Top:
  11008. case fgui.RelationType.Bottom_Middle:
  11009. case fgui.RelationType.Bottom_Bottom:
  11010. this._owner.y += dy;
  11011. break;
  11012. case fgui.RelationType.Width:
  11013. case fgui.RelationType.Height:
  11014. break;
  11015. case fgui.RelationType.LeftExt_Left:
  11016. case fgui.RelationType.LeftExt_Right:
  11017. if (this._owner != this._target.parent) {
  11018. tmp = this._owner.xMin;
  11019. this._owner.width = this._owner._rawWidth - dx;
  11020. this._owner.xMin = tmp + dx;
  11021. }
  11022. else
  11023. this._owner.width = this._owner._rawWidth - dx;
  11024. break;
  11025. case fgui.RelationType.RightExt_Left:
  11026. case fgui.RelationType.RightExt_Right:
  11027. if (this._owner != this._target.parent) {
  11028. tmp = this._owner.xMin;
  11029. this._owner.width = this._owner._rawWidth + dx;
  11030. this._owner.xMin = tmp;
  11031. }
  11032. else
  11033. this._owner.width = this._owner._rawWidth + dx;
  11034. break;
  11035. case fgui.RelationType.TopExt_Top:
  11036. case fgui.RelationType.TopExt_Bottom:
  11037. if (this._owner != this._target.parent) {
  11038. tmp = this._owner.yMin;
  11039. this._owner.height = this._owner._rawHeight - dy;
  11040. this._owner.yMin = tmp + dy;
  11041. }
  11042. else
  11043. this._owner.height = this._owner._rawHeight - dy;
  11044. break;
  11045. case fgui.RelationType.BottomExt_Top:
  11046. case fgui.RelationType.BottomExt_Bottom:
  11047. if (this._owner != this._target.parent) {
  11048. tmp = this._owner.yMin;
  11049. this._owner.height = this._owner._rawHeight + dy;
  11050. this._owner.yMin = tmp;
  11051. }
  11052. else
  11053. this._owner.height = this._owner._rawHeight + dy;
  11054. break;
  11055. }
  11056. };
  11057. RelationItem.prototype.applyOnSizeChanged = function (info) {
  11058. var pos = 0, pivot = 0, delta = 0;
  11059. var v, tmp;
  11060. if (info.axis == 0) {
  11061. if (this._target != this._owner.parent) {
  11062. pos = this._target.x;
  11063. if (this._target.pivotAsAnchor)
  11064. pivot = this._target.pivotX;
  11065. }
  11066. if (info.percent) {
  11067. if (this._targetWidth != 0)
  11068. delta = this._target._width / this._targetWidth;
  11069. }
  11070. else
  11071. delta = this._target._width - this._targetWidth;
  11072. }
  11073. else {
  11074. if (this._target != this._owner.parent) {
  11075. pos = this._target.y;
  11076. if (this._target.pivotAsAnchor)
  11077. pivot = this._target.pivotY;
  11078. }
  11079. if (info.percent) {
  11080. if (this._targetHeight != 0)
  11081. delta = this._target._height / this._targetHeight;
  11082. }
  11083. else
  11084. delta = this._target._height - this._targetHeight;
  11085. }
  11086. switch (info.type) {
  11087. case fgui.RelationType.Left_Left:
  11088. if (info.percent)
  11089. this._owner.xMin = pos + (this._owner.xMin - pos) * delta;
  11090. else if (pivot != 0)
  11091. this._owner.x += delta * (-pivot);
  11092. break;
  11093. case fgui.RelationType.Left_Center:
  11094. if (info.percent)
  11095. this._owner.xMin = pos + (this._owner.xMin - pos) * delta;
  11096. else
  11097. this._owner.x += delta * (0.5 - pivot);
  11098. break;
  11099. case fgui.RelationType.Left_Right:
  11100. if (info.percent)
  11101. this._owner.xMin = pos + (this._owner.xMin - pos) * delta;
  11102. else
  11103. this._owner.x += delta * (1 - pivot);
  11104. break;
  11105. case fgui.RelationType.Center_Center:
  11106. if (info.percent)
  11107. this._owner.xMin = pos + (this._owner.xMin + this._owner._rawWidth * 0.5 - pos) * delta - this._owner._rawWidth * 0.5;
  11108. else
  11109. this._owner.x += delta * (0.5 - pivot);
  11110. break;
  11111. case fgui.RelationType.Right_Left:
  11112. if (info.percent)
  11113. this._owner.xMin = pos + (this._owner.xMin + this._owner._rawWidth - pos) * delta - this._owner._rawWidth;
  11114. else if (pivot != 0)
  11115. this._owner.x += delta * (-pivot);
  11116. break;
  11117. case fgui.RelationType.Right_Center:
  11118. if (info.percent)
  11119. this._owner.xMin = pos + (this._owner.xMin + this._owner._rawWidth - pos) * delta - this._owner._rawWidth;
  11120. else
  11121. this._owner.x += delta * (0.5 - pivot);
  11122. break;
  11123. case fgui.RelationType.Right_Right:
  11124. if (info.percent)
  11125. this._owner.xMin = pos + (this._owner.xMin + this._owner._rawWidth - pos) * delta - this._owner._rawWidth;
  11126. else
  11127. this._owner.x += delta * (1 - pivot);
  11128. break;
  11129. case fgui.RelationType.Top_Top:
  11130. if (info.percent)
  11131. this._owner.yMin = pos + (this._owner.yMin - pos) * delta;
  11132. else if (pivot != 0)
  11133. this._owner.y += delta * (-pivot);
  11134. break;
  11135. case fgui.RelationType.Top_Middle:
  11136. if (info.percent)
  11137. this._owner.yMin = pos + (this._owner.yMin - pos) * delta;
  11138. else
  11139. this._owner.y += delta * (0.5 - pivot);
  11140. break;
  11141. case fgui.RelationType.Top_Bottom:
  11142. if (info.percent)
  11143. this._owner.yMin = pos + (this._owner.yMin - pos) * delta;
  11144. else
  11145. this._owner.y += delta * (1 - pivot);
  11146. break;
  11147. case fgui.RelationType.Middle_Middle:
  11148. if (info.percent)
  11149. this._owner.yMin = pos + (this._owner.yMin + this._owner._rawHeight * 0.5 - pos) * delta - this._owner._rawHeight * 0.5;
  11150. else
  11151. this._owner.y += delta * (0.5 - pivot);
  11152. break;
  11153. case fgui.RelationType.Bottom_Top:
  11154. if (info.percent)
  11155. this._owner.yMin = pos + (this._owner.yMin + this._owner._rawHeight - pos) * delta - this._owner._rawHeight;
  11156. else if (pivot != 0)
  11157. this._owner.y += delta * (-pivot);
  11158. break;
  11159. case fgui.RelationType.Bottom_Middle:
  11160. if (info.percent)
  11161. this._owner.yMin = pos + (this._owner.yMin + this._owner._rawHeight - pos) * delta - this._owner._rawHeight;
  11162. else
  11163. this._owner.y += delta * (0.5 - pivot);
  11164. break;
  11165. case fgui.RelationType.Bottom_Bottom:
  11166. if (info.percent)
  11167. this._owner.yMin = pos + (this._owner.yMin + this._owner._rawHeight - pos) * delta - this._owner._rawHeight;
  11168. else
  11169. this._owner.y += delta * (1 - pivot);
  11170. break;
  11171. case fgui.RelationType.Width:
  11172. if (this._owner._underConstruct && this._owner == this._target.parent)
  11173. v = this._owner.sourceWidth - this._target.initWidth;
  11174. else
  11175. v = this._owner._rawWidth - this._targetWidth;
  11176. if (info.percent)
  11177. v = v * delta;
  11178. if (this._target == this._owner.parent) {
  11179. if (this._owner.pivotAsAnchor) {
  11180. tmp = this._owner.xMin;
  11181. this._owner.setSize(this._target._width + v, this._owner._rawHeight, true);
  11182. this._owner.xMin = tmp;
  11183. }
  11184. else
  11185. this._owner.setSize(this._target._width + v, this._owner._rawHeight, true);
  11186. }
  11187. else
  11188. this._owner.width = this._target._width + v;
  11189. break;
  11190. case fgui.RelationType.Height:
  11191. if (this._owner._underConstruct && this._owner == this._target.parent)
  11192. v = this._owner.sourceHeight - this._target.initHeight;
  11193. else
  11194. v = this._owner._rawHeight - this._targetHeight;
  11195. if (info.percent)
  11196. v = v * delta;
  11197. if (this._target == this._owner.parent) {
  11198. if (this._owner.pivotAsAnchor) {
  11199. tmp = this._owner.yMin;
  11200. this._owner.setSize(this._owner._rawWidth, this._target._height + v, true);
  11201. this._owner.yMin = tmp;
  11202. }
  11203. else
  11204. this._owner.setSize(this._owner._rawWidth, this._target._height + v, true);
  11205. }
  11206. else
  11207. this._owner.height = this._target._height + v;
  11208. break;
  11209. case fgui.RelationType.LeftExt_Left:
  11210. tmp = this._owner.xMin;
  11211. if (info.percent)
  11212. v = pos + (tmp - pos) * delta - tmp;
  11213. else
  11214. v = delta * (-pivot);
  11215. this._owner.width = this._owner._rawWidth - v;
  11216. this._owner.xMin = tmp + v;
  11217. break;
  11218. case fgui.RelationType.LeftExt_Right:
  11219. tmp = this._owner.xMin;
  11220. if (info.percent)
  11221. v = pos + (tmp - pos) * delta - tmp;
  11222. else
  11223. v = delta * (1 - pivot);
  11224. this._owner.width = this._owner._rawWidth - v;
  11225. this._owner.xMin = tmp + v;
  11226. break;
  11227. case fgui.RelationType.RightExt_Left:
  11228. tmp = this._owner.xMin;
  11229. if (info.percent)
  11230. v = pos + (tmp + this._owner._rawWidth - pos) * delta - (tmp + this._owner._rawWidth);
  11231. else
  11232. v = delta * (-pivot);
  11233. this._owner.width = this._owner._rawWidth + v;
  11234. this._owner.xMin = tmp;
  11235. break;
  11236. case fgui.RelationType.RightExt_Right:
  11237. tmp = this._owner.xMin;
  11238. if (info.percent) {
  11239. if (this._owner == this._target.parent) {
  11240. if (this._owner._underConstruct)
  11241. this._owner.width = pos + this._target._width - this._target._width * pivot +
  11242. (this._owner.sourceWidth - pos - this._target.initWidth + this._target.initWidth * pivot) * delta;
  11243. else
  11244. this._owner.width = pos + (this._owner._rawWidth - pos) * delta;
  11245. }
  11246. else {
  11247. v = pos + (tmp + this._owner._rawWidth - pos) * delta - (tmp + this._owner._rawWidth);
  11248. this._owner.width = this._owner._rawWidth + v;
  11249. this._owner.xMin = tmp;
  11250. }
  11251. }
  11252. else {
  11253. if (this._owner == this._target.parent) {
  11254. if (this._owner._underConstruct)
  11255. this._owner.width = this._owner.sourceWidth + (this._target._width - this._target.initWidth) * (1 - pivot);
  11256. else
  11257. this._owner.width = this._owner._rawWidth + delta * (1 - pivot);
  11258. }
  11259. else {
  11260. v = delta * (1 - pivot);
  11261. this._owner.width = this._owner._rawWidth + v;
  11262. this._owner.xMin = tmp;
  11263. }
  11264. }
  11265. break;
  11266. case fgui.RelationType.TopExt_Top:
  11267. tmp = this._owner.yMin;
  11268. if (info.percent)
  11269. v = pos + (tmp - pos) * delta - tmp;
  11270. else
  11271. v = delta * (-pivot);
  11272. this._owner.height = this._owner._rawHeight - v;
  11273. this._owner.yMin = tmp + v;
  11274. break;
  11275. case fgui.RelationType.TopExt_Bottom:
  11276. tmp = this._owner.yMin;
  11277. if (info.percent)
  11278. v = pos + (tmp - pos) * delta - tmp;
  11279. else
  11280. v = delta * (1 - pivot);
  11281. this._owner.height = this._owner._rawHeight - v;
  11282. this._owner.yMin = tmp + v;
  11283. break;
  11284. case fgui.RelationType.BottomExt_Top:
  11285. tmp = this._owner.yMin;
  11286. if (info.percent)
  11287. v = pos + (tmp + this._owner._rawHeight - pos) * delta - (tmp + this._owner._rawHeight);
  11288. else
  11289. v = delta * (-pivot);
  11290. this._owner.height = this._owner._rawHeight + v;
  11291. this._owner.yMin = tmp;
  11292. break;
  11293. case fgui.RelationType.BottomExt_Bottom:
  11294. tmp = this._owner.yMin;
  11295. if (info.percent) {
  11296. if (this._owner == this._target.parent) {
  11297. if (this._owner._underConstruct)
  11298. this._owner.height = pos + this._target._height - this._target._height * pivot +
  11299. (this._owner.sourceHeight - pos - this._target.initHeight + this._target.initHeight * pivot) * delta;
  11300. else
  11301. this._owner.height = pos + (this._owner._rawHeight - pos) * delta;
  11302. }
  11303. else {
  11304. v = pos + (tmp + this._owner._rawHeight - pos) * delta - (tmp + this._owner._rawHeight);
  11305. this._owner.height = this._owner._rawHeight + v;
  11306. this._owner.yMin = tmp;
  11307. }
  11308. }
  11309. else {
  11310. if (this._owner == this._target.parent) {
  11311. if (this._owner._underConstruct)
  11312. this._owner.height = this._owner.sourceHeight + (this._target._height - this._target.initHeight) * (1 - pivot);
  11313. else
  11314. this._owner.height = this._owner._rawHeight + delta * (1 - pivot);
  11315. }
  11316. else {
  11317. v = delta * (1 - pivot);
  11318. this._owner.height = this._owner._rawHeight + v;
  11319. this._owner.yMin = tmp;
  11320. }
  11321. }
  11322. break;
  11323. }
  11324. };
  11325. RelationItem.prototype.addRefTarget = function (target) {
  11326. if (target != this._owner.parent)
  11327. target.on(fgui.Event.XY_CHANGED, this.__targetXYChanged, this);
  11328. target.on(fgui.Event.SIZE_CHANGED, this.__targetSizeChanged, this);
  11329. target.on(fgui.Event.SIZE_DELAY_CHANGE, this.__targetSizeWillChange, this);
  11330. this._targetX = this._target.x;
  11331. this._targetY = this._target.y;
  11332. this._targetWidth = this._target._width;
  11333. this._targetHeight = this._target._height;
  11334. };
  11335. RelationItem.prototype.releaseRefTarget = function (target) {
  11336. if (!target.node)
  11337. return;
  11338. target.off(fgui.Event.XY_CHANGED, this.__targetXYChanged, this);
  11339. target.off(fgui.Event.SIZE_CHANGED, this.__targetSizeChanged, this);
  11340. target.off(fgui.Event.SIZE_DELAY_CHANGE, this.__targetSizeWillChange, this);
  11341. };
  11342. RelationItem.prototype.__targetXYChanged = function (evt) {
  11343. if (this._owner.relations.handling != null || this._owner.group != null && this._owner.group._updating) {
  11344. this._targetX = this._target.x;
  11345. this._targetY = this._target.y;
  11346. return;
  11347. }
  11348. this._owner.relations.handling = this._target;
  11349. var ox = this._owner.x;
  11350. var oy = this._owner.y;
  11351. var dx = this._target.x - this._targetX;
  11352. var dy = this._target.y - this._targetY;
  11353. var length = this._defs.length;
  11354. for (var i = 0; i < length; i++) {
  11355. var info = this._defs[i];
  11356. this.applyOnXYChanged(info, dx, dy);
  11357. }
  11358. this._targetX = this._target.x;
  11359. this._targetY = this._target.y;
  11360. if (ox != this._owner.x || oy != this._owner.y) {
  11361. ox = this._owner.x - ox;
  11362. oy = this._owner.y - oy;
  11363. this._owner.updateGearFromRelations(1, ox, oy);
  11364. if (this._owner.parent) {
  11365. var len = this._owner.parent._transitions.length;
  11366. if (len > 0) {
  11367. for (var i = 0; i < len; ++i) {
  11368. this._owner.parent._transitions[i].updateFromRelations(this._owner.id, ox, oy);
  11369. }
  11370. }
  11371. }
  11372. }
  11373. this._owner.relations.handling = null;
  11374. };
  11375. RelationItem.prototype.__targetSizeChanged = function (evt) {
  11376. if (this._owner.relations.handling != null)
  11377. return;
  11378. this._owner.relations.handling = this._target;
  11379. var ox = this._owner.x;
  11380. var oy = this._owner.y;
  11381. var ow = this._owner._rawWidth;
  11382. var oh = this._owner._rawHeight;
  11383. var length = this._defs.length;
  11384. for (var i = 0; i < length; i++) {
  11385. var info = this._defs[i];
  11386. this.applyOnSizeChanged(info);
  11387. }
  11388. this._targetWidth = this._target._width;
  11389. this._targetHeight = this._target._height;
  11390. if (ox != this._owner.x || oy != this._owner.y) {
  11391. ox = this._owner.x - ox;
  11392. oy = this._owner.y - oy;
  11393. this._owner.updateGearFromRelations(1, ox, oy);
  11394. if (this._owner.parent) {
  11395. var len = this._owner.parent._transitions.length;
  11396. if (len > 0) {
  11397. for (var i = 0; i < len; ++i) {
  11398. this._owner.parent._transitions[i].updateFromRelations(this._owner.id, ox, oy);
  11399. }
  11400. }
  11401. }
  11402. }
  11403. if (ow != this._owner._rawWidth || oh != this._owner._rawHeight) {
  11404. ow = this._owner._rawWidth - ow;
  11405. oh = this._owner._rawHeight - oh;
  11406. this._owner.updateGearFromRelations(2, ow, oh);
  11407. }
  11408. this._owner.relations.handling = null;
  11409. };
  11410. RelationItem.prototype.__targetSizeWillChange = function (evt) {
  11411. this._owner.relations.sizeDirty = true;
  11412. };
  11413. return RelationItem;
  11414. }());
  11415. fgui.RelationItem = RelationItem;
  11416. var RelationDef = (function () {
  11417. function RelationDef() {
  11418. }
  11419. RelationDef.prototype.copyFrom = function (source) {
  11420. this.percent = source.percent;
  11421. this.type = source.type;
  11422. this.axis = source.axis;
  11423. };
  11424. return RelationDef;
  11425. }());
  11426. fgui.RelationDef = RelationDef;
  11427. })(fgui || (fgui = {}));
  11428. (function (fgui) {
  11429. var Relations = (function () {
  11430. function Relations(owner) {
  11431. this._owner = owner;
  11432. this._items = new Array();
  11433. }
  11434. Relations.prototype.add = function (target, relationType, usePercent) {
  11435. var length = this._items.length;
  11436. for (var i = 0; i < length; i++) {
  11437. var item = this._items[i];
  11438. if (item.target == target) {
  11439. item.add(relationType, usePercent);
  11440. return;
  11441. }
  11442. }
  11443. var newItem = new fgui.RelationItem(this._owner);
  11444. newItem.target = target;
  11445. newItem.add(relationType, usePercent);
  11446. this._items.push(newItem);
  11447. };
  11448. Relations.prototype.remove = function (target, relationType) {
  11449. relationType = relationType || 0;
  11450. var cnt = this._items.length;
  11451. var i = 0;
  11452. while (i < cnt) {
  11453. var item = this._items[i];
  11454. if (item.target == target) {
  11455. item.remove(relationType);
  11456. if (item.isEmpty) {
  11457. item.dispose();
  11458. this._items.splice(i, 1);
  11459. cnt--;
  11460. }
  11461. else
  11462. i++;
  11463. }
  11464. else
  11465. i++;
  11466. }
  11467. };
  11468. Relations.prototype.contains = function (target) {
  11469. var length = this._items.length;
  11470. for (var i = 0; i < length; i++) {
  11471. var item = this._items[i];
  11472. if (item.target == target)
  11473. return true;
  11474. }
  11475. return false;
  11476. };
  11477. Relations.prototype.clearFor = function (target) {
  11478. var cnt = this._items.length;
  11479. var i = 0;
  11480. while (i < cnt) {
  11481. var item = this._items[i];
  11482. if (item.target == target) {
  11483. item.dispose();
  11484. this._items.splice(i, 1);
  11485. cnt--;
  11486. }
  11487. else
  11488. i++;
  11489. }
  11490. };
  11491. Relations.prototype.clearAll = function () {
  11492. var length = this._items.length;
  11493. for (var i = 0; i < length; i++) {
  11494. var item = this._items[i];
  11495. item.dispose();
  11496. }
  11497. this._items.length = 0;
  11498. };
  11499. Relations.prototype.copyFrom = function (source) {
  11500. this.clearAll();
  11501. var arr = source._items;
  11502. var length = arr.length;
  11503. for (var i = 0; i < length; i++) {
  11504. var ri = arr[i];
  11505. var item = new fgui.RelationItem(this._owner);
  11506. item.copyFrom(ri);
  11507. this._items.push(item);
  11508. }
  11509. };
  11510. Relations.prototype.dispose = function () {
  11511. this.clearAll();
  11512. };
  11513. Relations.prototype.onOwnerSizeChanged = function (dWidth, dHeight, applyPivot) {
  11514. if (this._items.length == 0)
  11515. return;
  11516. var length = this._items.length;
  11517. for (var i = 0; i < length; i++) {
  11518. var item = this._items[i];
  11519. item.applyOnSelfResized(dWidth, dHeight, applyPivot);
  11520. }
  11521. };
  11522. Relations.prototype.ensureRelationsSizeCorrect = function () {
  11523. if (this._items.length == 0)
  11524. return;
  11525. this.sizeDirty = false;
  11526. var length = this._items.length;
  11527. for (var i = 0; i < length; i++) {
  11528. var item = this._items[i];
  11529. item.target.ensureSizeCorrect();
  11530. }
  11531. };
  11532. Object.defineProperty(Relations.prototype, "empty", {
  11533. get: function () {
  11534. return this._items.length == 0;
  11535. },
  11536. enumerable: false,
  11537. configurable: true
  11538. });
  11539. Relations.prototype.setup = function (buffer, parentToChild) {
  11540. var cnt = buffer.readByte();
  11541. var target;
  11542. for (var i = 0; i < cnt; i++) {
  11543. var targetIndex = buffer.readShort();
  11544. if (targetIndex == -1)
  11545. target = this._owner.parent;
  11546. else if (parentToChild)
  11547. target = this._owner.getChildAt(targetIndex);
  11548. else
  11549. target = this._owner.parent.getChildAt(targetIndex);
  11550. var newItem = new fgui.RelationItem(this._owner);
  11551. newItem.target = target;
  11552. this._items.push(newItem);
  11553. var cnt2 = buffer.readByte();
  11554. for (var j = 0; j < cnt2; j++) {
  11555. var rt = buffer.readByte();
  11556. var usePercent = buffer.readBool();
  11557. newItem.internalAdd(rt, usePercent);
  11558. }
  11559. }
  11560. };
  11561. return Relations;
  11562. }());
  11563. fgui.Relations = Relations;
  11564. })(fgui || (fgui = {}));
  11565. (function (fgui) {
  11566. var ScrollPane = (function (_super) {
  11567. __extends(ScrollPane, _super);
  11568. function ScrollPane() {
  11569. var _this = _super !== null && _super.apply(this, arguments) || this;
  11570. _this._aniFlag = 0;
  11571. return _this;
  11572. }
  11573. ScrollPane.prototype.setup = function (buffer) {
  11574. var o = this._owner = (this.node["$gobj"]);
  11575. this._maskContainer = new cc.Node("ScrollPane");
  11576. this._maskContainer.setAnchorPoint(0, 1);
  11577. this._maskContainer.parent = o.node;
  11578. this._container = o._container;
  11579. this._container.parent = this._maskContainer;
  11580. this._scrollBarMargin = new fgui.Margin();
  11581. this._mouseWheelEnabled = true;
  11582. this._xPos = 0;
  11583. this._yPos = 0;
  11584. this._aniFlag = 0;
  11585. this._tweening = 0;
  11586. this._footerLockedSize = 0;
  11587. this._headerLockedSize = 0;
  11588. this._viewSize = new cc.Vec2();
  11589. this._contentSize = new cc.Vec2();
  11590. this._pageSize = new cc.Vec2(1, 1);
  11591. this._overlapSize = new cc.Vec2();
  11592. this._tweenTime = new cc.Vec2();
  11593. this._tweenStart = new cc.Vec2();
  11594. this._tweenDuration = new cc.Vec2();
  11595. this._tweenChange = new cc.Vec2();
  11596. this._velocity = new cc.Vec2();
  11597. this._containerPos = new cc.Vec2();
  11598. this._beginTouchPos = new cc.Vec2();
  11599. this._lastTouchPos = new cc.Vec2();
  11600. this._lastTouchGlobalPos = new cc.Vec2();
  11601. this._scrollStep = fgui.UIConfig.defaultScrollStep;
  11602. this._mouseWheelStep = this._scrollStep * 2;
  11603. this._decelerationRate = fgui.UIConfig.defaultScrollDecelerationRate;
  11604. this._snappingPolicy = 0;
  11605. o.on(fgui.Event.TOUCH_BEGIN, this.onTouchBegin, this);
  11606. o.on(fgui.Event.TOUCH_MOVE, this.onTouchMove, this);
  11607. o.on(fgui.Event.TOUCH_END, this.onTouchEnd, this);
  11608. o.on(fgui.Event.MOUSE_WHEEL, this.onMouseWheel, this);
  11609. this._scrollType = buffer.readByte();
  11610. var scrollBarDisplay = buffer.readByte();
  11611. var flags = buffer.readInt();
  11612. if (buffer.readBool()) {
  11613. this._scrollBarMargin.top = buffer.readInt();
  11614. this._scrollBarMargin.bottom = buffer.readInt();
  11615. this._scrollBarMargin.left = buffer.readInt();
  11616. this._scrollBarMargin.right = buffer.readInt();
  11617. }
  11618. var vtScrollBarRes = buffer.readS();
  11619. var hzScrollBarRes = buffer.readS();
  11620. var headerRes = buffer.readS();
  11621. var footerRes = buffer.readS();
  11622. if ((flags & 1) != 0)
  11623. this._displayOnLeft = true;
  11624. if ((flags & 2) != 0)
  11625. this._snapToItem = true;
  11626. if ((flags & 4) != 0)
  11627. this._displayInDemand = true;
  11628. if ((flags & 8) != 0)
  11629. this._pageMode = true;
  11630. if (flags & 16)
  11631. this._touchEffect = true;
  11632. else if (flags & 32)
  11633. this._touchEffect = false;
  11634. else
  11635. this._touchEffect = fgui.UIConfig.defaultScrollTouchEffect;
  11636. if (flags & 64)
  11637. this._bouncebackEffect = true;
  11638. else if (flags & 128)
  11639. this._bouncebackEffect = false;
  11640. else
  11641. this._bouncebackEffect = fgui.UIConfig.defaultScrollBounceEffect;
  11642. if ((flags & 256) != 0)
  11643. this._inertiaDisabled = true;
  11644. if ((flags & 512) == 0)
  11645. this._maskContainer.addComponent(cc.Mask);
  11646. if ((flags & 1024) != 0)
  11647. this._floating = true;
  11648. if ((flags & 2048) != 0)
  11649. this._dontClipMargin = true;
  11650. if (scrollBarDisplay == fgui.ScrollBarDisplayType.Default)
  11651. scrollBarDisplay = fgui.UIConfig.defaultScrollBarDisplay;
  11652. if (scrollBarDisplay != fgui.ScrollBarDisplayType.Hidden) {
  11653. if (this._scrollType == fgui.ScrollType.Both || this._scrollType == fgui.ScrollType.Vertical) {
  11654. var res = vtScrollBarRes ? vtScrollBarRes : fgui.UIConfig.verticalScrollBar;
  11655. if (res) {
  11656. this._vtScrollBar = (fgui.UIPackage.createObjectFromURL(res));
  11657. if (!this._vtScrollBar)
  11658. throw "cannot create scrollbar from " + res;
  11659. this._vtScrollBar.setScrollPane(this, true);
  11660. this._vtScrollBar.node.parent = o.node;
  11661. }
  11662. }
  11663. if (this._scrollType == fgui.ScrollType.Both || this._scrollType == fgui.ScrollType.Horizontal) {
  11664. var res = hzScrollBarRes ? hzScrollBarRes : fgui.UIConfig.horizontalScrollBar;
  11665. if (res) {
  11666. this._hzScrollBar = (fgui.UIPackage.createObjectFromURL(res));
  11667. if (!this._hzScrollBar)
  11668. throw "cannot create scrollbar from " + res;
  11669. this._hzScrollBar.setScrollPane(this, false);
  11670. this._hzScrollBar.node.parent = o.node;
  11671. }
  11672. }
  11673. if (scrollBarDisplay == fgui.ScrollBarDisplayType.Auto)
  11674. this._scrollBarDisplayAuto = true;
  11675. if (this._scrollBarDisplayAuto) {
  11676. if (this._vtScrollBar)
  11677. this._vtScrollBar.node.active = false;
  11678. if (this._hzScrollBar)
  11679. this._hzScrollBar.node.active = false;
  11680. o.on(fgui.Event.ROLL_OVER, this.onRollOver, this);
  11681. o.on(fgui.Event.ROLL_OUT, this.onRollOut, this);
  11682. }
  11683. }
  11684. if (headerRes) {
  11685. this._header = (fgui.UIPackage.createObjectFromURL(headerRes));
  11686. if (this._header == null)
  11687. throw "cannot create scrollPane header from " + headerRes;
  11688. else
  11689. this._maskContainer.insertChild(this._header.node, 0);
  11690. }
  11691. if (footerRes) {
  11692. this._footer = (fgui.UIPackage.createObjectFromURL(footerRes));
  11693. if (this._footer == null)
  11694. throw "cannot create scrollPane footer from " + footerRes;
  11695. else
  11696. this._maskContainer.insertChild(this._footer.node, 0);
  11697. }
  11698. this._refreshBarAxis = (this._scrollType == fgui.ScrollType.Both || this._scrollType == fgui.ScrollType.Vertical) ? "y" : "x";
  11699. this.setSize(o.width, o.height);
  11700. };
  11701. ScrollPane.prototype.onDestroy = function () {
  11702. delete this._pageController;
  11703. if (this._hzScrollBar)
  11704. this._hzScrollBar.dispose();
  11705. if (this._vtScrollBar)
  11706. this._vtScrollBar.dispose();
  11707. if (this._header)
  11708. this._header.dispose();
  11709. if (this._footer)
  11710. this._footer.dispose();
  11711. };
  11712. ScrollPane.prototype.hitTest = function (pt, globalPt) {
  11713. var target;
  11714. if (this._vtScrollBar) {
  11715. target = this._vtScrollBar.hitTest(globalPt);
  11716. if (target)
  11717. return target;
  11718. }
  11719. if (this._hzScrollBar) {
  11720. target = this._hzScrollBar.hitTest(globalPt);
  11721. if (target)
  11722. return target;
  11723. }
  11724. if (this._header && this._header.node.activeInHierarchy) {
  11725. target = this._header.hitTest(globalPt);
  11726. if (target)
  11727. return target;
  11728. }
  11729. if (this._footer && this._footer.node.activeInHierarchy) {
  11730. target = this._footer.hitTest(globalPt);
  11731. if (target)
  11732. return target;
  11733. }
  11734. if (pt.x >= this._owner.margin.left && pt.y >= this._owner.margin.top
  11735. && pt.x < this._owner.margin.left + this._viewSize.x && pt.y < this._owner.margin.top + this._viewSize.y)
  11736. return this._owner;
  11737. else
  11738. return null;
  11739. };
  11740. Object.defineProperty(ScrollPane.prototype, "owner", {
  11741. get: function () {
  11742. return this._owner;
  11743. },
  11744. enumerable: false,
  11745. configurable: true
  11746. });
  11747. Object.defineProperty(ScrollPane.prototype, "hzScrollBar", {
  11748. get: function () {
  11749. return this._hzScrollBar;
  11750. },
  11751. enumerable: false,
  11752. configurable: true
  11753. });
  11754. Object.defineProperty(ScrollPane.prototype, "vtScrollBar", {
  11755. get: function () {
  11756. return this._vtScrollBar;
  11757. },
  11758. enumerable: false,
  11759. configurable: true
  11760. });
  11761. Object.defineProperty(ScrollPane.prototype, "header", {
  11762. get: function () {
  11763. return this._header;
  11764. },
  11765. enumerable: false,
  11766. configurable: true
  11767. });
  11768. Object.defineProperty(ScrollPane.prototype, "footer", {
  11769. get: function () {
  11770. return this._footer;
  11771. },
  11772. enumerable: false,
  11773. configurable: true
  11774. });
  11775. Object.defineProperty(ScrollPane.prototype, "bouncebackEffect", {
  11776. get: function () {
  11777. return this._bouncebackEffect;
  11778. },
  11779. set: function (sc) {
  11780. this._bouncebackEffect = sc;
  11781. },
  11782. enumerable: false,
  11783. configurable: true
  11784. });
  11785. Object.defineProperty(ScrollPane.prototype, "touchEffect", {
  11786. get: function () {
  11787. return this._touchEffect;
  11788. },
  11789. set: function (sc) {
  11790. this._touchEffect = sc;
  11791. },
  11792. enumerable: false,
  11793. configurable: true
  11794. });
  11795. Object.defineProperty(ScrollPane.prototype, "scrollStep", {
  11796. get: function () {
  11797. return this._scrollStep;
  11798. },
  11799. set: function (val) {
  11800. this._scrollStep = val;
  11801. if (this._scrollStep == 0)
  11802. this._scrollStep = fgui.UIConfig.defaultScrollStep;
  11803. this._mouseWheelStep = this._scrollStep * 2;
  11804. },
  11805. enumerable: false,
  11806. configurable: true
  11807. });
  11808. Object.defineProperty(ScrollPane.prototype, "decelerationRate", {
  11809. get: function () {
  11810. return this._decelerationRate;
  11811. },
  11812. set: function (val) {
  11813. this._decelerationRate = val;
  11814. },
  11815. enumerable: false,
  11816. configurable: true
  11817. });
  11818. Object.defineProperty(ScrollPane.prototype, "snapToItem", {
  11819. get: function () {
  11820. return this._snapToItem;
  11821. },
  11822. set: function (value) {
  11823. this._snapToItem = value;
  11824. },
  11825. enumerable: false,
  11826. configurable: true
  11827. });
  11828. Object.defineProperty(ScrollPane.prototype, "snappingPolicy", {
  11829. get: function () {
  11830. return this._snappingPolicy;
  11831. },
  11832. set: function (value) {
  11833. this._snappingPolicy = value;
  11834. },
  11835. enumerable: false,
  11836. configurable: true
  11837. });
  11838. Object.defineProperty(ScrollPane.prototype, "mouseWheelEnabled", {
  11839. get: function () {
  11840. return this._mouseWheelEnabled;
  11841. },
  11842. set: function (value) {
  11843. this._mouseWheelEnabled = value;
  11844. },
  11845. enumerable: false,
  11846. configurable: true
  11847. });
  11848. Object.defineProperty(ScrollPane.prototype, "isDragged", {
  11849. get: function () {
  11850. return this._dragged;
  11851. },
  11852. enumerable: false,
  11853. configurable: true
  11854. });
  11855. Object.defineProperty(ScrollPane.prototype, "percX", {
  11856. get: function () {
  11857. return this._overlapSize.x == 0 ? 0 : this._xPos / this._overlapSize.x;
  11858. },
  11859. set: function (value) {
  11860. this.setPercX(value, false);
  11861. },
  11862. enumerable: false,
  11863. configurable: true
  11864. });
  11865. ScrollPane.prototype.setPercX = function (value, ani) {
  11866. this._owner.ensureBoundsCorrect();
  11867. this.setPosX(this._overlapSize.x * fgui.ToolSet.clamp01(value), ani);
  11868. };
  11869. Object.defineProperty(ScrollPane.prototype, "percY", {
  11870. get: function () {
  11871. return this._overlapSize.y == 0 ? 0 : this._yPos / this._overlapSize.y;
  11872. },
  11873. set: function (value) {
  11874. this.setPercY(value, false);
  11875. },
  11876. enumerable: false,
  11877. configurable: true
  11878. });
  11879. ScrollPane.prototype.setPercY = function (value, ani) {
  11880. this._owner.ensureBoundsCorrect();
  11881. this.setPosY(this._overlapSize.y * fgui.ToolSet.clamp01(value), ani);
  11882. };
  11883. Object.defineProperty(ScrollPane.prototype, "posX", {
  11884. get: function () {
  11885. return this._xPos;
  11886. },
  11887. set: function (value) {
  11888. this.setPosX(value, false);
  11889. },
  11890. enumerable: false,
  11891. configurable: true
  11892. });
  11893. ScrollPane.prototype.setPosX = function (value, ani) {
  11894. this._owner.ensureBoundsCorrect();
  11895. if (this._loop == 1)
  11896. value = this.loopCheckingNewPos(value, "x");
  11897. value = fgui.ToolSet.clamp(value, 0, this._overlapSize.x);
  11898. if (value != this._xPos) {
  11899. this._xPos = value;
  11900. this.posChanged(ani);
  11901. }
  11902. };
  11903. Object.defineProperty(ScrollPane.prototype, "posY", {
  11904. get: function () {
  11905. return this._yPos;
  11906. },
  11907. set: function (value) {
  11908. this.setPosY(value, false);
  11909. },
  11910. enumerable: false,
  11911. configurable: true
  11912. });
  11913. ScrollPane.prototype.setPosY = function (value, ani) {
  11914. this._owner.ensureBoundsCorrect();
  11915. if (this._loop == 1)
  11916. value = this.loopCheckingNewPos(value, "y");
  11917. value = fgui.ToolSet.clamp(value, 0, this._overlapSize.y);
  11918. if (value != this._yPos) {
  11919. this._yPos = value;
  11920. this.posChanged(ani);
  11921. }
  11922. };
  11923. Object.defineProperty(ScrollPane.prototype, "contentWidth", {
  11924. get: function () {
  11925. return this._contentSize.x;
  11926. },
  11927. enumerable: false,
  11928. configurable: true
  11929. });
  11930. Object.defineProperty(ScrollPane.prototype, "contentHeight", {
  11931. get: function () {
  11932. return this._contentSize.y;
  11933. },
  11934. enumerable: false,
  11935. configurable: true
  11936. });
  11937. Object.defineProperty(ScrollPane.prototype, "viewWidth", {
  11938. get: function () {
  11939. return this._viewSize.x;
  11940. },
  11941. set: function (value) {
  11942. value = value + this._owner.margin.left + this._owner.margin.right;
  11943. if (this._vtScrollBar && !this._floating)
  11944. value += this._vtScrollBar.width;
  11945. this._owner.width = value;
  11946. },
  11947. enumerable: false,
  11948. configurable: true
  11949. });
  11950. Object.defineProperty(ScrollPane.prototype, "viewHeight", {
  11951. get: function () {
  11952. return this._viewSize.y;
  11953. },
  11954. set: function (value) {
  11955. value = value + this._owner.margin.top + this._owner.margin.bottom;
  11956. if (this._hzScrollBar && !this._floating)
  11957. value += this._hzScrollBar.height;
  11958. this._owner.height = value;
  11959. },
  11960. enumerable: false,
  11961. configurable: true
  11962. });
  11963. Object.defineProperty(ScrollPane.prototype, "currentPageX", {
  11964. get: function () {
  11965. if (!this._pageMode)
  11966. return 0;
  11967. var page = Math.floor(this._xPos / this._pageSize.x);
  11968. if (this._xPos - page * this._pageSize.x > this._pageSize.x * 0.5)
  11969. page++;
  11970. return page;
  11971. },
  11972. set: function (value) {
  11973. this.setCurrentPageX(value, false);
  11974. },
  11975. enumerable: false,
  11976. configurable: true
  11977. });
  11978. Object.defineProperty(ScrollPane.prototype, "currentPageY", {
  11979. get: function () {
  11980. if (!this._pageMode)
  11981. return 0;
  11982. var page = Math.floor(this._yPos / this._pageSize.y);
  11983. if (this._yPos - page * this._pageSize.y > this._pageSize.y * 0.5)
  11984. page++;
  11985. return page;
  11986. },
  11987. set: function (value) {
  11988. this.setCurrentPageY(value, false);
  11989. },
  11990. enumerable: false,
  11991. configurable: true
  11992. });
  11993. ScrollPane.prototype.setCurrentPageX = function (value, ani) {
  11994. if (!this._pageMode)
  11995. return;
  11996. this._owner.ensureBoundsCorrect();
  11997. if (this._overlapSize.x > 0)
  11998. this.setPosX(value * this._pageSize.x, ani);
  11999. };
  12000. ScrollPane.prototype.setCurrentPageY = function (value, ani) {
  12001. if (!this._pageMode)
  12002. return;
  12003. this._owner.ensureBoundsCorrect();
  12004. if (this._overlapSize.y > 0)
  12005. this.setPosY(value * this._pageSize.y, ani);
  12006. };
  12007. Object.defineProperty(ScrollPane.prototype, "isBottomMost", {
  12008. get: function () {
  12009. return this._yPos == this._overlapSize.y || this._overlapSize.y == 0;
  12010. },
  12011. enumerable: false,
  12012. configurable: true
  12013. });
  12014. Object.defineProperty(ScrollPane.prototype, "isRightMost", {
  12015. get: function () {
  12016. return this._xPos == this._overlapSize.x || this._overlapSize.x == 0;
  12017. },
  12018. enumerable: false,
  12019. configurable: true
  12020. });
  12021. Object.defineProperty(ScrollPane.prototype, "pageController", {
  12022. get: function () {
  12023. return this._pageController;
  12024. },
  12025. set: function (value) {
  12026. this._pageController = value;
  12027. },
  12028. enumerable: false,
  12029. configurable: true
  12030. });
  12031. Object.defineProperty(ScrollPane.prototype, "scrollingPosX", {
  12032. get: function () {
  12033. return fgui.ToolSet.clamp(-this._container.x, 0, this._overlapSize.x);
  12034. },
  12035. enumerable: false,
  12036. configurable: true
  12037. });
  12038. Object.defineProperty(ScrollPane.prototype, "scrollingPosY", {
  12039. get: function () {
  12040. return fgui.ToolSet.clamp(-(-this._container.y), 0, this._overlapSize.y);
  12041. },
  12042. enumerable: false,
  12043. configurable: true
  12044. });
  12045. ScrollPane.prototype.scrollTop = function (ani) {
  12046. this.setPercY(0, ani);
  12047. };
  12048. ScrollPane.prototype.scrollBottom = function (ani) {
  12049. this.setPercY(1, ani);
  12050. };
  12051. ScrollPane.prototype.scrollUp = function (ratio, ani) {
  12052. if (ratio == undefined)
  12053. ratio = 1;
  12054. if (this._pageMode)
  12055. this.setPosY(this._yPos - this._pageSize.y * ratio, ani);
  12056. else
  12057. this.setPosY(this._yPos - this._scrollStep * ratio, ani);
  12058. ;
  12059. };
  12060. ScrollPane.prototype.scrollDown = function (ratio, ani) {
  12061. if (ratio == undefined)
  12062. ratio = 1;
  12063. if (this._pageMode)
  12064. this.setPosY(this._yPos + this._pageSize.y * ratio, ani);
  12065. else
  12066. this.setPosY(this._yPos + this._scrollStep * ratio, ani);
  12067. };
  12068. ScrollPane.prototype.scrollLeft = function (ratio, ani) {
  12069. if (ratio == undefined)
  12070. ratio = 1;
  12071. if (this._pageMode)
  12072. this.setPosX(this._xPos - this._pageSize.x * ratio, ani);
  12073. else
  12074. this.setPosX(this._xPos - this._scrollStep * ratio, ani);
  12075. };
  12076. ScrollPane.prototype.scrollRight = function (ratio, ani) {
  12077. if (ratio == undefined)
  12078. ratio = 1;
  12079. if (this._pageMode)
  12080. this.setPosX(this._xPos + this._pageSize.x * ratio, ani);
  12081. else
  12082. this.setPosX(this._xPos + this._scrollStep * ratio, ani);
  12083. };
  12084. ScrollPane.prototype.scrollToView = function (target, ani, setFirst) {
  12085. this._owner.ensureBoundsCorrect();
  12086. if (this._needRefresh)
  12087. this.refresh();
  12088. var rect;
  12089. if (target instanceof fgui.GObject) {
  12090. if (target.parent != this._owner) {
  12091. target.parent.localToGlobalRect(target.x, target.y, target.width, target.height, s_rect);
  12092. rect = this._owner.globalToLocalRect(s_rect.x, s_rect.y, s_rect.width, s_rect.height, s_rect);
  12093. }
  12094. else {
  12095. rect = s_rect;
  12096. rect.x = target.x;
  12097. rect.y = target.y;
  12098. rect.width = target.width;
  12099. rect.height = target.height;
  12100. }
  12101. }
  12102. else
  12103. rect = target;
  12104. if (this._overlapSize.y > 0) {
  12105. var bottom = this._yPos + this._viewSize.y;
  12106. if (setFirst || rect.y <= this._yPos || rect.height >= this._viewSize.y) {
  12107. if (this._pageMode)
  12108. this.setPosY(Math.floor(rect.y / this._pageSize.y) * this._pageSize.y, ani);
  12109. else
  12110. this.setPosY(rect.y, ani);
  12111. }
  12112. else if (rect.y + rect.height > bottom) {
  12113. if (this._pageMode)
  12114. this.setPosY(Math.floor(rect.y / this._pageSize.y) * this._pageSize.y, ani);
  12115. else if (rect.height <= this._viewSize.y / 2)
  12116. this.setPosY(rect.y + rect.height * 2 - this._viewSize.y, ani);
  12117. else
  12118. this.setPosY(rect.y + rect.height - this._viewSize.y, ani);
  12119. }
  12120. }
  12121. if (this._overlapSize.x > 0) {
  12122. var right = this._xPos + this._viewSize.x;
  12123. if (setFirst || rect.x <= this._xPos || rect.width >= this._viewSize.x) {
  12124. if (this._pageMode)
  12125. this.setPosX(Math.floor(rect.x / this._pageSize.x) * this._pageSize.x, ani);
  12126. else
  12127. this.setPosX(rect.x, ani);
  12128. }
  12129. else if (rect.x + rect.width > right) {
  12130. if (this._pageMode)
  12131. this.setPosX(Math.floor(rect.x / this._pageSize.x) * this._pageSize.x, ani);
  12132. else if (rect.width <= this._viewSize.x / 2)
  12133. this.setPosX(rect.x + rect.width * 2 - this._viewSize.x, ani);
  12134. else
  12135. this.setPosX(rect.x + rect.width - this._viewSize.x, ani);
  12136. }
  12137. }
  12138. if (!ani && this._needRefresh)
  12139. this.refresh();
  12140. };
  12141. ScrollPane.prototype.isChildInView = function (obj) {
  12142. if (this._overlapSize.y > 0) {
  12143. var dist = obj.y + (-this._container.y);
  12144. if (dist < -obj.height || dist > this._viewSize.y)
  12145. return false;
  12146. }
  12147. if (this._overlapSize.x > 0) {
  12148. dist = obj.x + this._container.x;
  12149. if (dist < -obj.width || dist > this._viewSize.x)
  12150. return false;
  12151. }
  12152. return true;
  12153. };
  12154. ScrollPane.prototype.cancelDragging = function () {
  12155. if (ScrollPane.draggingPane == this)
  12156. ScrollPane.draggingPane = null;
  12157. _gestureFlag = 0;
  12158. this._dragged = false;
  12159. };
  12160. ScrollPane.prototype.lockHeader = function (size) {
  12161. if (this._headerLockedSize == size)
  12162. return;
  12163. var cx = this._container.x;
  12164. var cy = -this._container.y;
  12165. var cr = this._refreshBarAxis == "x" ? cx : cy;
  12166. this._headerLockedSize = size;
  12167. if (!this._refreshEventDispatching && cr >= 0) {
  12168. this._tweenStart.x = cx;
  12169. this._tweenStart.y = cy;
  12170. this._tweenChange.set(cc.Vec2.ZERO);
  12171. this._tweenChange[this._refreshBarAxis] = this._headerLockedSize - this._tweenStart[this._refreshBarAxis];
  12172. this._tweenDuration.x = this._tweenDuration.y = TWEEN_TIME_DEFAULT;
  12173. this.startTween(2);
  12174. }
  12175. };
  12176. ScrollPane.prototype.lockFooter = function (size) {
  12177. if (this._footerLockedSize == size)
  12178. return;
  12179. var cx = this._container.x;
  12180. var cy = -this._container.y;
  12181. var cr = this._refreshBarAxis == "x" ? cx : cy;
  12182. this._footerLockedSize = size;
  12183. if (!this._refreshEventDispatching && cr <= -this._overlapSize[this._refreshBarAxis]) {
  12184. this._tweenStart.x = cx;
  12185. this._tweenStart.y = cy;
  12186. this._tweenChange.set(cc.Vec2.ZERO);
  12187. var max = this._overlapSize[this._refreshBarAxis];
  12188. if (max == 0)
  12189. max = Math.max(this._contentSize[this._refreshBarAxis] + this._footerLockedSize - this._viewSize[this._refreshBarAxis], 0);
  12190. else
  12191. max += this._footerLockedSize;
  12192. this._tweenChange[this._refreshBarAxis] = -max - this._tweenStart[this._refreshBarAxis];
  12193. this._tweenDuration.x = this._tweenDuration.y = TWEEN_TIME_DEFAULT;
  12194. this.startTween(2);
  12195. }
  12196. };
  12197. ScrollPane.prototype.onOwnerSizeChanged = function () {
  12198. this.setSize(this._owner.width, this._owner.height);
  12199. this.posChanged(false);
  12200. };
  12201. ScrollPane.prototype.handleControllerChanged = function (c) {
  12202. if (this._pageController == c) {
  12203. if (this._scrollType == fgui.ScrollType.Horizontal)
  12204. this.setCurrentPageX(c.selectedIndex, true);
  12205. else
  12206. this.setCurrentPageY(c.selectedIndex, true);
  12207. }
  12208. };
  12209. ScrollPane.prototype.updatePageController = function () {
  12210. if (this._pageController && !this._pageController.changing) {
  12211. var index;
  12212. if (this._scrollType == fgui.ScrollType.Horizontal)
  12213. index = this.currentPageX;
  12214. else
  12215. index = this.currentPageY;
  12216. if (index < this._pageController.pageCount) {
  12217. var c = this._pageController;
  12218. this._pageController = null;
  12219. c.selectedIndex = index;
  12220. this._pageController = c;
  12221. }
  12222. }
  12223. };
  12224. ScrollPane.prototype.adjustMaskContainer = function () {
  12225. var mx = 0;
  12226. if (this._displayOnLeft && this._vtScrollBar && !this._floating)
  12227. mx = this._vtScrollBar.width;
  12228. var o = this._owner;
  12229. if (this._dontClipMargin)
  12230. this._maskContainer.setAnchorPoint((o.margin.left + o._alignOffset.x) / o.width, 1 - (o.margin.top + o._alignOffset.y) / o.height);
  12231. else
  12232. this._maskContainer.setAnchorPoint(o._alignOffset.x / this._viewSize.x, 1 - o._alignOffset.y / this._viewSize.y);
  12233. if (o._customMask)
  12234. this._maskContainer.setPosition(mx + o._alignOffset.x, -o._alignOffset.y);
  12235. else
  12236. this._maskContainer.setPosition(o._pivotCorrectX + mx + o._alignOffset.x, o._pivotCorrectY - o._alignOffset.y);
  12237. };
  12238. ScrollPane.prototype.setSize = function (aWidth, aHeight) {
  12239. if (this._hzScrollBar) {
  12240. this._hzScrollBar.y = aHeight - this._hzScrollBar.height;
  12241. if (this._vtScrollBar) {
  12242. this._hzScrollBar.width = aWidth - this._vtScrollBar.width - this._scrollBarMargin.left - this._scrollBarMargin.right;
  12243. if (this._displayOnLeft)
  12244. this._hzScrollBar.x = this._scrollBarMargin.left + this._vtScrollBar.width;
  12245. else
  12246. this._hzScrollBar.x = this._scrollBarMargin.left;
  12247. }
  12248. else {
  12249. this._hzScrollBar.width = aWidth - this._scrollBarMargin.left - this._scrollBarMargin.right;
  12250. this._hzScrollBar.x = this._scrollBarMargin.left;
  12251. }
  12252. }
  12253. if (this._vtScrollBar) {
  12254. if (!this._displayOnLeft)
  12255. this._vtScrollBar.x = aWidth - this._vtScrollBar.width;
  12256. if (this._hzScrollBar)
  12257. this._vtScrollBar.height = aHeight - this._hzScrollBar.height - this._scrollBarMargin.top - this._scrollBarMargin.bottom;
  12258. else
  12259. this._vtScrollBar.height = aHeight - this._scrollBarMargin.top - this._scrollBarMargin.bottom;
  12260. this._vtScrollBar.y = this._scrollBarMargin.top;
  12261. }
  12262. this._viewSize.x = aWidth;
  12263. this._viewSize.y = aHeight;
  12264. if (this._hzScrollBar && !this._floating)
  12265. this._viewSize.y -= this._hzScrollBar.height;
  12266. if (this._vtScrollBar && !this._floating)
  12267. this._viewSize.x -= this._vtScrollBar.width;
  12268. this._viewSize.x -= (this._owner.margin.left + this._owner.margin.right);
  12269. this._viewSize.y -= (this._owner.margin.top + this._owner.margin.bottom);
  12270. this._viewSize.x = Math.max(1, this._viewSize.x);
  12271. this._viewSize.y = Math.max(1, this._viewSize.y);
  12272. this._pageSize.x = this._viewSize.x;
  12273. this._pageSize.y = this._viewSize.y;
  12274. this.adjustMaskContainer();
  12275. this.handleSizeChanged();
  12276. };
  12277. ScrollPane.prototype.setContentSize = function (aWidth, aHeight) {
  12278. if (this._contentSize.x == aWidth && this._contentSize.y == aHeight)
  12279. return;
  12280. this._contentSize.x = aWidth;
  12281. this._contentSize.y = aHeight;
  12282. this.handleSizeChanged();
  12283. if (this._snapToItem && this._snappingPolicy != 0 && this._xPos == 0 && this._yPos == 0)
  12284. this.posChanged(false);
  12285. };
  12286. ScrollPane.prototype.changeContentSizeOnScrolling = function (deltaWidth, deltaHeight, deltaPosX, deltaPosY) {
  12287. var isRightmost = this._xPos == this._overlapSize.x;
  12288. var isBottom = this._yPos == this._overlapSize.y;
  12289. this._contentSize.x += deltaWidth;
  12290. this._contentSize.y += deltaHeight;
  12291. this.handleSizeChanged();
  12292. if (this._tweening == 1) {
  12293. if (deltaWidth != 0 && isRightmost && this._tweenChange.x < 0) {
  12294. this._xPos = this._overlapSize.x;
  12295. this._tweenChange.x = -this._xPos - this._tweenStart.x;
  12296. }
  12297. if (deltaHeight != 0 && isBottom && this._tweenChange.y < 0) {
  12298. this._yPos = this._overlapSize.y;
  12299. this._tweenChange.y = -this._yPos - this._tweenStart.y;
  12300. }
  12301. }
  12302. else if (this._tweening == 2) {
  12303. if (deltaPosX != 0) {
  12304. this._container.x -= deltaPosX;
  12305. this._tweenStart.x -= deltaPosX;
  12306. this._xPos = -this._container.x;
  12307. }
  12308. if (deltaPosY != 0) {
  12309. this._container.y += deltaPosY;
  12310. this._tweenStart.y -= deltaPosY;
  12311. this._yPos = -(-this._container.y);
  12312. }
  12313. }
  12314. else if (this._dragged) {
  12315. if (deltaPosX != 0) {
  12316. this._container.x -= deltaPosX;
  12317. this._containerPos.x -= deltaPosX;
  12318. this._xPos = -this._container.x;
  12319. }
  12320. if (deltaPosY != 0) {
  12321. this._container.y += deltaPosY;
  12322. this._containerPos.y -= deltaPosY;
  12323. this._yPos = -(-this._container.y);
  12324. }
  12325. }
  12326. else {
  12327. if (deltaWidth != 0 && isRightmost) {
  12328. this._xPos = this._overlapSize.x;
  12329. this._container.x = -this._xPos;
  12330. }
  12331. if (deltaHeight != 0 && isBottom) {
  12332. this._yPos = this._overlapSize.y;
  12333. this._container.y = this._yPos;
  12334. }
  12335. }
  12336. if (this._pageMode)
  12337. this.updatePageController();
  12338. };
  12339. ScrollPane.prototype.handleSizeChanged = function () {
  12340. if (this._displayInDemand) {
  12341. this._vScrollNone = this._contentSize.y <= this._viewSize.y;
  12342. this._hScrollNone = this._contentSize.x <= this._viewSize.x;
  12343. }
  12344. if (this._vtScrollBar) {
  12345. if (this._contentSize.y == 0)
  12346. this._vtScrollBar.setDisplayPerc(0);
  12347. else
  12348. this._vtScrollBar.setDisplayPerc(Math.min(1, this._viewSize.y / this._contentSize.y));
  12349. }
  12350. if (this._hzScrollBar) {
  12351. if (this._contentSize.x == 0)
  12352. this._hzScrollBar.setDisplayPerc(0);
  12353. else
  12354. this._hzScrollBar.setDisplayPerc(Math.min(1, this._viewSize.x / this._contentSize.x));
  12355. }
  12356. this.updateScrollBarVisible();
  12357. var maskWidth = this._viewSize.x;
  12358. var maskHeight = this._viewSize.y;
  12359. if (this._vScrollNone && this._vtScrollBar)
  12360. maskWidth += this._vtScrollBar.width;
  12361. if (this._hScrollNone && this._hzScrollBar)
  12362. maskHeight += this._hzScrollBar.height;
  12363. if (this._dontClipMargin) {
  12364. maskWidth += (this._owner.margin.left + this._owner.margin.right);
  12365. maskHeight += (this._owner.margin.top + this._owner.margin.bottom);
  12366. }
  12367. this._maskContainer.setContentSize(maskWidth, maskHeight);
  12368. if (this._vtScrollBar)
  12369. this._vtScrollBar.handlePositionChanged();
  12370. if (this._hzScrollBar)
  12371. this._hzScrollBar.handlePositionChanged();
  12372. if (this._header)
  12373. this._header.handlePositionChanged();
  12374. if (this._footer)
  12375. this._footer.handlePositionChanged();
  12376. if (this._scrollType == fgui.ScrollType.Horizontal || this._scrollType == fgui.ScrollType.Both)
  12377. this._overlapSize.x = Math.ceil(Math.max(0, this._contentSize.x - this._viewSize.x));
  12378. else
  12379. this._overlapSize.x = 0;
  12380. if (this._scrollType == fgui.ScrollType.Vertical || this._scrollType == fgui.ScrollType.Both)
  12381. this._overlapSize.y = Math.ceil(Math.max(0, this._contentSize.y - this._viewSize.y));
  12382. else
  12383. this._overlapSize.y = 0;
  12384. this._xPos = fgui.ToolSet.clamp(this._xPos, 0, this._overlapSize.x);
  12385. this._yPos = fgui.ToolSet.clamp(this._yPos, 0, this._overlapSize.y);
  12386. var max = this._overlapSize[this._refreshBarAxis];
  12387. if (max == 0)
  12388. max = Math.max(this._contentSize[this._refreshBarAxis] + this._footerLockedSize - this._viewSize[this._refreshBarAxis], 0);
  12389. else
  12390. max += this._footerLockedSize;
  12391. if (this._refreshBarAxis == "x")
  12392. this._container.setPosition(fgui.ToolSet.clamp(this._container.x, -max, this._headerLockedSize), -fgui.ToolSet.clamp((-this._container.y), -this._overlapSize.y, 0));
  12393. else
  12394. this._container.setPosition(fgui.ToolSet.clamp(this._container.x, -this._overlapSize.x, 0), -fgui.ToolSet.clamp((-this._container.y), -max, this._headerLockedSize));
  12395. if (this._header) {
  12396. if (this._refreshBarAxis == "x")
  12397. this._header.height = this._viewSize.y;
  12398. else
  12399. this._header.width = this._viewSize.x;
  12400. }
  12401. if (this._footer) {
  12402. if (this._refreshBarAxis == "y")
  12403. this._footer.height = this._viewSize.y;
  12404. else
  12405. this._footer.width = this._viewSize.x;
  12406. }
  12407. this.updateScrollBarPos();
  12408. if (this._pageMode)
  12409. this.updatePageController();
  12410. };
  12411. ScrollPane.prototype.posChanged = function (ani) {
  12412. if (this._aniFlag == 0)
  12413. this._aniFlag = ani ? 1 : -1;
  12414. else if (this._aniFlag == 1 && !ani)
  12415. this._aniFlag = -1;
  12416. this._needRefresh = true;
  12417. if (!cc.director.getScheduler().isScheduled(this.refresh, this))
  12418. this.scheduleOnce(this.refresh);
  12419. };
  12420. ScrollPane.prototype.refresh = function (dt) {
  12421. this._needRefresh = false;
  12422. this.unschedule(this.refresh);
  12423. if (this._pageMode || this._snapToItem) {
  12424. sEndPos.x = -this._xPos;
  12425. sEndPos.y = -this._yPos;
  12426. this.alignPosition(sEndPos, false);
  12427. this._xPos = -sEndPos.x;
  12428. this._yPos = -sEndPos.y;
  12429. }
  12430. this.refresh2();
  12431. this._owner.node.emit(fgui.Event.SCROLL, this._owner);
  12432. if (this._needRefresh) {
  12433. this._needRefresh = false;
  12434. this.unschedule(this.refresh);
  12435. this.refresh2();
  12436. }
  12437. this.updateScrollBarPos();
  12438. this._aniFlag = 0;
  12439. };
  12440. ScrollPane.prototype.refresh2 = function () {
  12441. if (this._aniFlag == 1 && !this._dragged) {
  12442. var posX;
  12443. var posY;
  12444. if (this._overlapSize.x > 0)
  12445. posX = -Math.floor(this._xPos);
  12446. else {
  12447. if (this._container.x != 0)
  12448. this._container.x = 0;
  12449. posX = 0;
  12450. }
  12451. if (this._overlapSize.y > 0)
  12452. posY = -Math.floor(this._yPos);
  12453. else {
  12454. if (this._container.y != 0)
  12455. this._container.y = 0;
  12456. posY = 0;
  12457. }
  12458. if (posX != this._container.x || posY != (-this._container.y)) {
  12459. this._tweenDuration.x = this._tweenDuration.y = TWEEN_TIME_GO;
  12460. this._tweenStart.x = this._container.x;
  12461. this._tweenStart.y = (-this._container.y);
  12462. this._tweenChange.x = posX - this._tweenStart.x;
  12463. this._tweenChange.y = posY - this._tweenStart.y;
  12464. this.startTween(1);
  12465. }
  12466. else if (this._tweening != 0)
  12467. this.killTween();
  12468. }
  12469. else {
  12470. if (this._tweening != 0)
  12471. this.killTween();
  12472. this._container.setPosition(Math.floor(-this._xPos), -Math.floor(-this._yPos));
  12473. this.loopCheckingCurrent();
  12474. }
  12475. if (this._pageMode)
  12476. this.updatePageController();
  12477. };
  12478. ScrollPane.prototype.onTouchBegin = function (evt) {
  12479. if (!this._touchEffect)
  12480. return;
  12481. evt.captureTouch();
  12482. if (this._tweening != 0) {
  12483. this.killTween();
  12484. fgui.GRoot.inst.inputProcessor.cancelClick(evt.touchId);
  12485. this._dragged = true;
  12486. }
  12487. else
  12488. this._dragged = false;
  12489. var pt = this._owner.globalToLocal(evt.pos.x, evt.pos.y, s_vec2);
  12490. this._containerPos.x = this._container.x;
  12491. this._containerPos.y = -this._container.y;
  12492. this._beginTouchPos.set(pt);
  12493. this._lastTouchPos.set(pt);
  12494. this._lastTouchGlobalPos.set(evt.pos);
  12495. this._isHoldAreaDone = false;
  12496. this._velocity.set(cc.Vec2.ZERO);
  12497. ;
  12498. this._velocityScale = 1;
  12499. this._lastMoveTime = fgui.ToolSet.getTime();
  12500. };
  12501. ScrollPane.prototype.onTouchMove = function (evt) {
  12502. if (!cc.isValid(this._owner.node))
  12503. return;
  12504. if (!this._touchEffect)
  12505. return;
  12506. if (fgui.GObject.draggingObject && fgui.GObject.draggingObject.onStage)
  12507. return;
  12508. if (ScrollPane.draggingPane && ScrollPane.draggingPane != this && ScrollPane.draggingPane._owner.onStage)
  12509. return;
  12510. var pt = this._owner.globalToLocal(evt.pos.x, evt.pos.y, s_vec2);
  12511. var sensitivity = fgui.UIConfig.touchScrollSensitivity;
  12512. var diff, diff2;
  12513. var sv, sh, st;
  12514. if (this._scrollType == fgui.ScrollType.Vertical) {
  12515. if (!this._isHoldAreaDone) {
  12516. _gestureFlag |= 1;
  12517. diff = Math.abs(this._beginTouchPos.y - pt.y);
  12518. if (diff < sensitivity)
  12519. return;
  12520. if ((_gestureFlag & 2) != 0) {
  12521. diff2 = Math.abs(this._beginTouchPos.x - pt.x);
  12522. if (diff < diff2)
  12523. return;
  12524. }
  12525. }
  12526. sv = true;
  12527. }
  12528. else if (this._scrollType == fgui.ScrollType.Horizontal) {
  12529. if (!this._isHoldAreaDone) {
  12530. _gestureFlag |= 2;
  12531. diff = Math.abs(this._beginTouchPos.x - pt.x);
  12532. if (diff < sensitivity)
  12533. return;
  12534. if ((_gestureFlag & 1) != 0) {
  12535. diff2 = Math.abs(this._beginTouchPos.y - pt.y);
  12536. if (diff < diff2)
  12537. return;
  12538. }
  12539. }
  12540. sh = true;
  12541. }
  12542. else {
  12543. _gestureFlag = 3;
  12544. if (!this._isHoldAreaDone) {
  12545. diff = Math.abs(this._beginTouchPos.y - pt.y);
  12546. if (diff < sensitivity) {
  12547. diff = Math.abs(this._beginTouchPos.x - pt.x);
  12548. if (diff < sensitivity)
  12549. return;
  12550. }
  12551. }
  12552. sv = sh = true;
  12553. }
  12554. var newPosX = Math.floor(this._containerPos.x + pt.x - this._beginTouchPos.x);
  12555. var newPosY = Math.floor(this._containerPos.y + pt.y - this._beginTouchPos.y);
  12556. if (sv) {
  12557. if (newPosY > 0) {
  12558. if (!this._bouncebackEffect)
  12559. this._container.y = 0;
  12560. else if (this._header && this._header.maxHeight != 0)
  12561. this._container.y = -Math.floor(Math.min(newPosY * 0.5, this._header.maxHeight));
  12562. else
  12563. this._container.y = -Math.floor(Math.min(newPosY * 0.5, this._viewSize.y * PULL_RATIO));
  12564. }
  12565. else if (newPosY < -this._overlapSize.y) {
  12566. if (!this._bouncebackEffect)
  12567. this._container.y = this._overlapSize.y;
  12568. else if (this._footer && this._footer.maxHeight > 0)
  12569. this._container.y = -Math.floor(Math.max((newPosY + this._overlapSize.y) * 0.5, -this._footer.maxHeight) - this._overlapSize.y);
  12570. else
  12571. this._container.y = -Math.floor(Math.max((newPosY + this._overlapSize.y) * 0.5, -this._viewSize.y * PULL_RATIO) - this._overlapSize.y);
  12572. }
  12573. else
  12574. this._container.y = -newPosY;
  12575. }
  12576. if (sh) {
  12577. if (newPosX > 0) {
  12578. if (!this._bouncebackEffect)
  12579. this._container.x = 0;
  12580. else if (this._header && this._header.maxWidth != 0)
  12581. this._container.x = Math.floor(Math.min(newPosX * 0.5, this._header.maxWidth));
  12582. else
  12583. this._container.x = Math.floor(Math.min(newPosX * 0.5, this._viewSize.x * PULL_RATIO));
  12584. }
  12585. else if (newPosX < 0 - this._overlapSize.x) {
  12586. if (!this._bouncebackEffect)
  12587. this._container.x = -this._overlapSize.x;
  12588. else if (this._footer && this._footer.maxWidth > 0)
  12589. this._container.x = Math.floor(Math.max((newPosX + this._overlapSize.x) * 0.5, -this._footer.maxWidth) - this._overlapSize.x);
  12590. else
  12591. this._container.x = Math.floor(Math.max((newPosX + this._overlapSize.x) * 0.5, -this._viewSize.x * PULL_RATIO) - this._overlapSize.x);
  12592. }
  12593. else
  12594. this._container.x = newPosX;
  12595. }
  12596. var now = fgui.ToolSet.getTime();
  12597. var deltaTime = Math.max(now - this._lastMoveTime, 1 / 60);
  12598. var deltaPositionX = pt.x - this._lastTouchPos.x;
  12599. var deltaPositionY = pt.y - this._lastTouchPos.y;
  12600. if (!sh)
  12601. deltaPositionX = 0;
  12602. if (!sv)
  12603. deltaPositionY = 0;
  12604. if (deltaTime != 0) {
  12605. var frameRate = 60;
  12606. var elapsed = deltaTime * frameRate - 1;
  12607. if (elapsed > 1) {
  12608. var factor = Math.pow(0.833, elapsed);
  12609. this._velocity.x = this._velocity.x * factor;
  12610. this._velocity.y = this._velocity.y * factor;
  12611. }
  12612. this._velocity.x = fgui.ToolSet.lerp(this._velocity.x, deltaPositionX * 60 / frameRate / deltaTime, deltaTime * 10);
  12613. this._velocity.y = fgui.ToolSet.lerp(this._velocity.y, deltaPositionY * 60 / frameRate / deltaTime, deltaTime * 10);
  12614. }
  12615. var deltaGlobalPositionX = this._lastTouchGlobalPos.x - evt.pos.x;
  12616. var deltaGlobalPositionY = this._lastTouchGlobalPos.y - evt.pos.y;
  12617. if (deltaPositionX != 0)
  12618. this._velocityScale = Math.abs(deltaGlobalPositionX / deltaPositionX);
  12619. else if (deltaPositionY != 0)
  12620. this._velocityScale = Math.abs(deltaGlobalPositionY / deltaPositionY);
  12621. this._lastTouchPos.set(pt);
  12622. this._lastTouchGlobalPos.x = evt.pos.x;
  12623. this._lastTouchGlobalPos.y = evt.pos.y;
  12624. this._lastMoveTime = now;
  12625. if (this._overlapSize.x > 0)
  12626. this._xPos = fgui.ToolSet.clamp(-this._container.x, 0, this._overlapSize.x);
  12627. if (this._overlapSize.y > 0)
  12628. this._yPos = fgui.ToolSet.clamp(-(-this._container.y), 0, this._overlapSize.y);
  12629. if (this._loop != 0) {
  12630. newPosX = this._container.x;
  12631. newPosY = (-this._container.y);
  12632. if (this.loopCheckingCurrent()) {
  12633. this._containerPos.x += this._container.x - newPosX;
  12634. this._containerPos.y += (-this._container.y) - newPosY;
  12635. }
  12636. }
  12637. ScrollPane.draggingPane = this;
  12638. this._isHoldAreaDone = true;
  12639. this._dragged = true;
  12640. this.updateScrollBarPos();
  12641. this.updateScrollBarVisible();
  12642. if (this._pageMode)
  12643. this.updatePageController();
  12644. this._owner.node.emit(fgui.Event.SCROLL), this._owner;
  12645. };
  12646. ScrollPane.prototype.onTouchEnd = function (evt) {
  12647. if (ScrollPane.draggingPane == this)
  12648. ScrollPane.draggingPane = null;
  12649. _gestureFlag = 0;
  12650. if (!this._dragged || !this._touchEffect || !this._owner.node.activeInHierarchy) {
  12651. this._dragged = false;
  12652. return;
  12653. }
  12654. this._dragged = false;
  12655. this._tweenStart.x = this._container.x;
  12656. this._tweenStart.y = -this._container.y;
  12657. sEndPos.set(this._tweenStart);
  12658. var flag = false;
  12659. if (this._container.x > 0) {
  12660. sEndPos.x = 0;
  12661. flag = true;
  12662. }
  12663. else if (this._container.x < -this._overlapSize.x) {
  12664. sEndPos.x = -this._overlapSize.x;
  12665. flag = true;
  12666. }
  12667. if ((-this._container.y) > 0) {
  12668. sEndPos.y = 0;
  12669. flag = true;
  12670. }
  12671. else if ((-this._container.y) < -this._overlapSize.y) {
  12672. sEndPos.y = -this._overlapSize.y;
  12673. flag = true;
  12674. }
  12675. if (flag) {
  12676. this._tweenChange.x = sEndPos.x - this._tweenStart.x;
  12677. this._tweenChange.y = sEndPos.y - this._tweenStart.y;
  12678. if (this._tweenChange.x < -fgui.UIConfig.touchDragSensitivity || this._tweenChange.y < -fgui.UIConfig.touchDragSensitivity) {
  12679. this._refreshEventDispatching = true;
  12680. this._owner.node.emit(fgui.Event.PULL_DOWN_RELEASE), this._owner;
  12681. this._refreshEventDispatching = false;
  12682. }
  12683. else if (this._tweenChange.x > fgui.UIConfig.touchDragSensitivity || this._tweenChange.y > fgui.UIConfig.touchDragSensitivity) {
  12684. this._refreshEventDispatching = true;
  12685. this._owner.node.emit(fgui.Event.PULL_UP_RELEASE, this._owner);
  12686. this._refreshEventDispatching = false;
  12687. }
  12688. if (this._headerLockedSize > 0 && sEndPos[this._refreshBarAxis] == 0) {
  12689. sEndPos[this._refreshBarAxis] = this._headerLockedSize;
  12690. this._tweenChange.x = sEndPos.x - this._tweenStart.x;
  12691. this._tweenChange.y = sEndPos.y - this._tweenStart.y;
  12692. }
  12693. else if (this._footerLockedSize > 0 && sEndPos[this._refreshBarAxis] == -this._overlapSize[this._refreshBarAxis]) {
  12694. var max = this._overlapSize[this._refreshBarAxis];
  12695. if (max == 0)
  12696. max = Math.max(this._contentSize[this._refreshBarAxis] + this._footerLockedSize - this._viewSize[this._refreshBarAxis], 0);
  12697. else
  12698. max += this._footerLockedSize;
  12699. sEndPos[this._refreshBarAxis] = -max;
  12700. this._tweenChange.x = sEndPos.x - this._tweenStart.x;
  12701. this._tweenChange.y = sEndPos.y - this._tweenStart.y;
  12702. }
  12703. this._tweenDuration.x = this._tweenDuration.y = TWEEN_TIME_DEFAULT;
  12704. }
  12705. else {
  12706. if (!this._inertiaDisabled) {
  12707. var frameRate = 60;
  12708. var elapsed = (fgui.ToolSet.getTime() - this._lastMoveTime) * frameRate - 1;
  12709. if (elapsed > 1) {
  12710. var factor = Math.pow(0.833, elapsed);
  12711. this._velocity.x = this._velocity.x * factor;
  12712. this._velocity.y = this._velocity.y * factor;
  12713. }
  12714. this.updateTargetAndDuration(this._tweenStart, sEndPos);
  12715. }
  12716. else
  12717. this._tweenDuration.x = this._tweenDuration.y = TWEEN_TIME_DEFAULT;
  12718. sOldChange.x = sEndPos.x - this._tweenStart.x;
  12719. sOldChange.y = sEndPos.y - this._tweenStart.y;
  12720. this.loopCheckingTarget(sEndPos);
  12721. if (this._pageMode || this._snapToItem)
  12722. this.alignPosition(sEndPos, true);
  12723. this._tweenChange.x = sEndPos.x - this._tweenStart.x;
  12724. this._tweenChange.y = sEndPos.y - this._tweenStart.y;
  12725. if (this._tweenChange.x == 0 && this._tweenChange.y == 0) {
  12726. this.updateScrollBarVisible();
  12727. return;
  12728. }
  12729. if (this._pageMode || this._snapToItem) {
  12730. this.fixDuration("x", sOldChange.x);
  12731. this.fixDuration("y", sOldChange.y);
  12732. }
  12733. }
  12734. this.startTween(2);
  12735. };
  12736. ScrollPane.prototype.onRollOver = function () {
  12737. this._hover = true;
  12738. this.updateScrollBarVisible();
  12739. };
  12740. ScrollPane.prototype.onRollOut = function () {
  12741. this._hover = false;
  12742. this.updateScrollBarVisible();
  12743. };
  12744. ScrollPane.prototype.onMouseWheel = function (evt) {
  12745. if (!this._mouseWheelEnabled)
  12746. return;
  12747. var delta = evt.mouseWheelDelta > 0 ? -1 : 1;
  12748. if (this._overlapSize.x > 0 && this._overlapSize.y == 0) {
  12749. if (this._pageMode)
  12750. this.setPosX(this._xPos + this._pageSize.x * delta, false);
  12751. else
  12752. this.setPosX(this._xPos + this._mouseWheelStep * delta, false);
  12753. }
  12754. else {
  12755. if (this._pageMode)
  12756. this.setPosY(this._yPos + this._pageSize.y * delta, false);
  12757. else
  12758. this.setPosY(this._yPos + this._mouseWheelStep * delta, false);
  12759. }
  12760. };
  12761. ScrollPane.prototype.updateScrollBarPos = function () {
  12762. if (this._vtScrollBar)
  12763. this._vtScrollBar.setScrollPerc(this._overlapSize.y == 0 ? 0 : fgui.ToolSet.clamp(this._container.y, 0, this._overlapSize.y) / this._overlapSize.y);
  12764. if (this._hzScrollBar)
  12765. this._hzScrollBar.setScrollPerc(this._overlapSize.x == 0 ? 0 : fgui.ToolSet.clamp(-this._container.x, 0, this._overlapSize.x) / this._overlapSize.x);
  12766. this.checkRefreshBar();
  12767. };
  12768. ScrollPane.prototype.updateScrollBarVisible = function () {
  12769. if (this._vtScrollBar) {
  12770. if (this._viewSize.y <= this._vtScrollBar.minSize || this._vScrollNone)
  12771. this._vtScrollBar.node.active = false;
  12772. else
  12773. this.updateScrollBarVisible2(this._vtScrollBar);
  12774. }
  12775. if (this._hzScrollBar) {
  12776. if (this._viewSize.x <= this._hzScrollBar.minSize || this._hScrollNone)
  12777. this._hzScrollBar.node.active = false;
  12778. else
  12779. this.updateScrollBarVisible2(this._hzScrollBar);
  12780. }
  12781. };
  12782. ScrollPane.prototype.updateScrollBarVisible2 = function (bar) {
  12783. if (this._scrollBarDisplayAuto)
  12784. fgui.GTween.kill(bar, false, "alpha");
  12785. if (this._scrollBarDisplayAuto && !this._hover && this._tweening == 0 && !this._dragged && !bar.gripDragging) {
  12786. if (bar.node.active)
  12787. fgui.GTween.to(1, 0, 0.5).setDelay(0.5).onComplete(this.__barTweenComplete, this).setTarget(bar, "alpha");
  12788. }
  12789. else {
  12790. bar.alpha = 1;
  12791. bar.node.active = true;
  12792. }
  12793. };
  12794. ScrollPane.prototype.__barTweenComplete = function (tweener) {
  12795. var bar = (tweener.target);
  12796. bar.alpha = 1;
  12797. bar.node.active = false;
  12798. };
  12799. ScrollPane.prototype.getLoopPartSize = function (division, axis) {
  12800. return (this._contentSize[axis] + (axis == "x" ? this._owner.columnGap : this._owner.lineGap)) / division;
  12801. };
  12802. ScrollPane.prototype.loopCheckingCurrent = function () {
  12803. var changed = false;
  12804. if (this._loop == 1 && this._overlapSize.x > 0) {
  12805. if (this._xPos < 0.001) {
  12806. this._xPos += this.getLoopPartSize(2, "x");
  12807. changed = true;
  12808. }
  12809. else if (this._xPos >= this._overlapSize.x) {
  12810. this._xPos -= this.getLoopPartSize(2, "x");
  12811. changed = true;
  12812. }
  12813. }
  12814. else if (this._loop == 2 && this._overlapSize.y > 0) {
  12815. if (this._yPos < 0.001) {
  12816. this._yPos += this.getLoopPartSize(2, "y");
  12817. changed = true;
  12818. }
  12819. else if (this._yPos >= this._overlapSize.y) {
  12820. this._yPos -= this.getLoopPartSize(2, "y");
  12821. changed = true;
  12822. }
  12823. }
  12824. if (changed) {
  12825. this._container.setPosition(Math.floor(-this._xPos), -Math.floor(-this._yPos));
  12826. }
  12827. return changed;
  12828. };
  12829. ScrollPane.prototype.loopCheckingTarget = function (endPos) {
  12830. if (this._loop == 1)
  12831. this.loopCheckingTarget2(endPos, "x");
  12832. if (this._loop == 2)
  12833. this.loopCheckingTarget2(endPos, "y");
  12834. };
  12835. ScrollPane.prototype.loopCheckingTarget2 = function (endPos, axis) {
  12836. var halfSize;
  12837. var tmp;
  12838. if (endPos[axis] > 0) {
  12839. halfSize = this.getLoopPartSize(2, axis);
  12840. tmp = this._tweenStart[axis] - halfSize;
  12841. if (tmp <= 0 && tmp >= -this._overlapSize[axis]) {
  12842. endPos[axis] -= halfSize;
  12843. this._tweenStart[axis] = tmp;
  12844. }
  12845. }
  12846. else if (endPos[axis] < -this._overlapSize[axis]) {
  12847. halfSize = this.getLoopPartSize(2, axis);
  12848. tmp = this._tweenStart[axis] + halfSize;
  12849. if (tmp <= 0 && tmp >= -this._overlapSize[axis]) {
  12850. endPos[axis] += halfSize;
  12851. this._tweenStart[axis] = tmp;
  12852. }
  12853. }
  12854. };
  12855. ScrollPane.prototype.loopCheckingNewPos = function (value, axis) {
  12856. if (this._overlapSize[axis] == 0)
  12857. return value;
  12858. var pos = axis == "x" ? this._xPos : this._yPos;
  12859. var changed = false;
  12860. var v;
  12861. if (value < 0.001) {
  12862. value += this.getLoopPartSize(2, axis);
  12863. if (value > pos) {
  12864. v = this.getLoopPartSize(6, axis);
  12865. v = Math.ceil((value - pos) / v) * v;
  12866. pos = fgui.ToolSet.clamp(pos + v, 0, this._overlapSize[axis]);
  12867. changed = true;
  12868. }
  12869. }
  12870. else if (value >= this._overlapSize[axis]) {
  12871. value -= this.getLoopPartSize(2, axis);
  12872. if (value < pos) {
  12873. v = this.getLoopPartSize(6, axis);
  12874. v = Math.ceil((pos - value) / v) * v;
  12875. pos = fgui.ToolSet.clamp(pos - v, 0, this._overlapSize[axis]);
  12876. changed = true;
  12877. }
  12878. }
  12879. if (changed) {
  12880. if (axis == "x")
  12881. this._container.x = -Math.floor(pos);
  12882. else
  12883. this._container.y = Math.floor(pos);
  12884. }
  12885. return value;
  12886. };
  12887. ScrollPane.prototype.alignPosition = function (pos, inertialScrolling) {
  12888. var ax = 0, ay = 0;
  12889. if (this._snappingPolicy == 1) {
  12890. if (this._owner.numChildren > 0) {
  12891. var obj = this._owner.getChildAt(0);
  12892. ax = Math.floor(this._viewSize.x * 0.5 - obj.width * 0.5);
  12893. ay = Math.floor(this._viewSize.y * 0.5 - obj.height * 0.5);
  12894. }
  12895. }
  12896. else if (this._snappingPolicy == 2) {
  12897. if (this._owner.numChildren > 0) {
  12898. var obj = this._owner.getChildAt(0);
  12899. ax = Math.floor(this._viewSize.x - obj.width);
  12900. ay = Math.floor(this._viewSize.y - obj.height);
  12901. }
  12902. }
  12903. pos.x -= ax;
  12904. pos.y -= ay;
  12905. if (this._pageMode) {
  12906. pos.x = this.alignByPage(pos.x, "x", inertialScrolling);
  12907. pos.y = this.alignByPage(pos.y, "y", inertialScrolling);
  12908. }
  12909. else if (this._snapToItem) {
  12910. var pt = this._owner.getSnappingPosition(-pos.x, -pos.y, s_vec2);
  12911. if (pos.x < 0 && pos.x > -this._overlapSize.x)
  12912. pos.x = -pt.x;
  12913. if (pos.y < 0 && pos.y > -this._overlapSize.y)
  12914. pos.y = -pt.y;
  12915. }
  12916. pos.x += ax;
  12917. pos.y += ay;
  12918. };
  12919. ScrollPane.prototype.alignByPage = function (pos, axis, inertialScrolling) {
  12920. var page;
  12921. if (pos > 0)
  12922. page = 0;
  12923. else if (pos < -this._overlapSize[axis])
  12924. page = Math.ceil(this._contentSize[axis] / this._pageSize[axis]) - 1;
  12925. else {
  12926. page = Math.floor(-pos / this._pageSize[axis]);
  12927. var change = inertialScrolling ? (pos - this._containerPos[axis]) : (pos - (axis == "x" ? this._container.x : (-this._container.y)));
  12928. var testPageSize = Math.min(this._pageSize[axis], this._contentSize[axis] - (page + 1) * this._pageSize[axis]);
  12929. var delta = -pos - page * this._pageSize[axis];
  12930. if (Math.abs(change) > this._pageSize[axis]) {
  12931. if (delta > testPageSize * 0.5)
  12932. page++;
  12933. }
  12934. else {
  12935. if (delta > testPageSize * (change < 0 ? 0.3 : 0.7))
  12936. page++;
  12937. }
  12938. pos = -page * this._pageSize[axis];
  12939. if (pos < -this._overlapSize[axis])
  12940. pos = -this._overlapSize[axis];
  12941. }
  12942. if (inertialScrolling) {
  12943. var oldPos = this._tweenStart[axis];
  12944. var oldPage;
  12945. if (oldPos > 0)
  12946. oldPage = 0;
  12947. else if (oldPos < -this._overlapSize[axis])
  12948. oldPage = Math.ceil(this._contentSize[axis] / this._pageSize[axis]) - 1;
  12949. else
  12950. oldPage = Math.floor(-oldPos / this._pageSize[axis]);
  12951. var startPage = Math.floor(-this._containerPos[axis] / this._pageSize[axis]);
  12952. if (Math.abs(page - startPage) > 1 && Math.abs(oldPage - startPage) <= 1) {
  12953. if (page > startPage)
  12954. page = startPage + 1;
  12955. else
  12956. page = startPage - 1;
  12957. pos = -page * this._pageSize[axis];
  12958. }
  12959. }
  12960. return pos;
  12961. };
  12962. ScrollPane.prototype.updateTargetAndDuration = function (orignPos, resultPos) {
  12963. resultPos.x = this.updateTargetAndDuration2(orignPos.x, "x");
  12964. resultPos.y = this.updateTargetAndDuration2(orignPos.y, "y");
  12965. };
  12966. ScrollPane.prototype.updateTargetAndDuration2 = function (pos, axis) {
  12967. var v = this._velocity[axis];
  12968. var duration = 0;
  12969. if (pos > 0)
  12970. pos = 0;
  12971. else if (pos < -this._overlapSize[axis])
  12972. pos = -this._overlapSize[axis];
  12973. else {
  12974. var isMobile = cc.sys.isMobile;
  12975. var v2 = Math.abs(v) * this._velocityScale;
  12976. if (isMobile)
  12977. v2 *= 1136 / Math.max(cc.winSize.width, cc.winSize.height);
  12978. var ratio = 0;
  12979. if (this._pageMode || !isMobile) {
  12980. if (v2 > 500)
  12981. ratio = Math.pow((v2 - 500) / 500, 2);
  12982. }
  12983. else {
  12984. if (v2 > 1000)
  12985. ratio = Math.pow((v2 - 1000) / 1000, 2);
  12986. }
  12987. if (ratio != 0) {
  12988. if (ratio > 1)
  12989. ratio = 1;
  12990. v2 *= ratio;
  12991. v *= ratio;
  12992. this._velocity[axis] = v;
  12993. duration = Math.log(60 / v2) / Math.log(this._decelerationRate) / 60;
  12994. var change = Math.floor(v * duration * 0.4);
  12995. pos += change;
  12996. }
  12997. }
  12998. if (duration < TWEEN_TIME_DEFAULT)
  12999. duration = TWEEN_TIME_DEFAULT;
  13000. this._tweenDuration[axis] = duration;
  13001. return pos;
  13002. };
  13003. ScrollPane.prototype.fixDuration = function (axis, oldChange) {
  13004. if (this._tweenChange[axis] == 0 || Math.abs(this._tweenChange[axis]) >= Math.abs(oldChange))
  13005. return;
  13006. var newDuration = Math.abs(this._tweenChange[axis] / oldChange) * this._tweenDuration[axis];
  13007. if (newDuration < TWEEN_TIME_DEFAULT)
  13008. newDuration = TWEEN_TIME_DEFAULT;
  13009. this._tweenDuration[axis] = newDuration;
  13010. };
  13011. ScrollPane.prototype.startTween = function (type) {
  13012. this._tweenTime.set(cc.Vec2.ZERO);
  13013. this._tweening = type;
  13014. this.updateScrollBarVisible();
  13015. };
  13016. ScrollPane.prototype.killTween = function () {
  13017. if (this._tweening == 1) {
  13018. this._container.setPosition(this._tweenStart.x + this._tweenChange.x, -(this._tweenStart.y + this._tweenChange.y));
  13019. this._owner.node.emit(fgui.Event.SCROLL, this._owner);
  13020. }
  13021. this._tweening = 0;
  13022. this.updateScrollBarVisible();
  13023. this._owner.node.emit(fgui.Event.SCROLL_END, this._owner);
  13024. };
  13025. ScrollPane.prototype.checkRefreshBar = function () {
  13026. if (this._header == null && this._footer == null)
  13027. return;
  13028. var pos = (this._refreshBarAxis == "x" ? this._container.x : (-this._container.y));
  13029. if (this._header) {
  13030. if (pos > 0) {
  13031. this._header.node.active = true;
  13032. var pt = s_vec2;
  13033. pt.x = this._header.width;
  13034. pt.y = this._header.height;
  13035. pt[this._refreshBarAxis] = pos;
  13036. this._header.setSize(pt.x, pt.y);
  13037. }
  13038. else {
  13039. this._header.node.active = false;
  13040. }
  13041. }
  13042. if (this._footer) {
  13043. var max = this._overlapSize[this._refreshBarAxis];
  13044. if (pos < -max || max == 0 && this._footerLockedSize > 0) {
  13045. this._footer.node.active = true;
  13046. pt = s_vec2;
  13047. pt.x = this._footer.x;
  13048. pt.y = this._footer.y;
  13049. if (max > 0)
  13050. pt[this._refreshBarAxis] = pos + this._contentSize[this._refreshBarAxis];
  13051. else
  13052. pt[this._refreshBarAxis] = Math.max(Math.min(pos + this._viewSize[this._refreshBarAxis], this._viewSize[this._refreshBarAxis] - this._footerLockedSize), this._viewSize[this._refreshBarAxis] - this._contentSize[this._refreshBarAxis]);
  13053. this._footer.setPosition(pt.x, pt.y);
  13054. pt.x = this._footer.width;
  13055. pt.y = this._footer.height;
  13056. if (max > 0)
  13057. pt[this._refreshBarAxis] = -max - pos;
  13058. else
  13059. pt[this._refreshBarAxis] = this._viewSize[this._refreshBarAxis] - this._footer[this._refreshBarAxis];
  13060. this._footer.setSize(pt.x, pt.y);
  13061. }
  13062. else {
  13063. this._footer.node.active = false;
  13064. }
  13065. }
  13066. };
  13067. ScrollPane.prototype.update = function (dt) {
  13068. if (this._tweening == 0)
  13069. return;
  13070. var nx = this.runTween("x", dt);
  13071. var ny = this.runTween("y", dt);
  13072. this._container.setPosition(nx, -ny);
  13073. if (this._tweening == 2) {
  13074. if (this._overlapSize.x > 0)
  13075. this._xPos = fgui.ToolSet.clamp(-nx, 0, this._overlapSize.x);
  13076. if (this._overlapSize.y > 0)
  13077. this._yPos = fgui.ToolSet.clamp(-ny, 0, this._overlapSize.y);
  13078. if (this._pageMode)
  13079. this.updatePageController();
  13080. }
  13081. if (this._tweenChange.x == 0 && this._tweenChange.y == 0) {
  13082. this._tweening = 0;
  13083. this.loopCheckingCurrent();
  13084. this.updateScrollBarPos();
  13085. this.updateScrollBarVisible();
  13086. this._owner.node.emit(fgui.Event.SCROLL, this._owner);
  13087. this._owner.node.emit(fgui.Event.SCROLL_END, this._owner);
  13088. }
  13089. else {
  13090. this.updateScrollBarPos();
  13091. this._owner.node.emit(fgui.Event.SCROLL, this._owner);
  13092. }
  13093. return true;
  13094. };
  13095. ScrollPane.prototype.runTween = function (axis, dt) {
  13096. var newValue;
  13097. if (this._tweenChange[axis] != 0) {
  13098. this._tweenTime[axis] += dt;
  13099. if (this._tweenTime[axis] >= this._tweenDuration[axis]) {
  13100. newValue = this._tweenStart[axis] + this._tweenChange[axis];
  13101. this._tweenChange[axis] = 0;
  13102. }
  13103. else {
  13104. var ratio = easeFunc(this._tweenTime[axis], this._tweenDuration[axis]);
  13105. newValue = this._tweenStart[axis] + Math.floor(this._tweenChange[axis] * ratio);
  13106. }
  13107. var threshold1 = 0;
  13108. var threshold2 = -this._overlapSize[axis];
  13109. if (this._headerLockedSize > 0 && this._refreshBarAxis == axis)
  13110. threshold1 = this._headerLockedSize;
  13111. if (this._footerLockedSize > 0 && this._refreshBarAxis == axis) {
  13112. var max = this._overlapSize[this._refreshBarAxis];
  13113. if (max == 0)
  13114. max = Math.max(this._contentSize[this._refreshBarAxis] + this._footerLockedSize - this._viewSize[this._refreshBarAxis], 0);
  13115. else
  13116. max += this._footerLockedSize;
  13117. threshold2 = -max;
  13118. }
  13119. if (this._tweening == 2 && this._bouncebackEffect) {
  13120. if (newValue > 20 + threshold1 && this._tweenChange[axis] > 0
  13121. || newValue > threshold1 && this._tweenChange[axis] == 0) {
  13122. this._tweenTime[axis] = 0;
  13123. this._tweenDuration[axis] = TWEEN_TIME_DEFAULT;
  13124. this._tweenChange[axis] = -newValue + threshold1;
  13125. this._tweenStart[axis] = newValue;
  13126. }
  13127. else if (newValue < threshold2 - 20 && this._tweenChange[axis] < 0
  13128. || newValue < threshold2 && this._tweenChange[axis] == 0) {
  13129. this._tweenTime[axis] = 0;
  13130. this._tweenDuration[axis] = TWEEN_TIME_DEFAULT;
  13131. this._tweenChange[axis] = threshold2 - newValue;
  13132. this._tweenStart[axis] = newValue;
  13133. }
  13134. }
  13135. else {
  13136. if (newValue > threshold1) {
  13137. newValue = threshold1;
  13138. this._tweenChange[axis] = 0;
  13139. }
  13140. else if (newValue < threshold2) {
  13141. newValue = threshold2;
  13142. this._tweenChange[axis] = 0;
  13143. }
  13144. }
  13145. }
  13146. else
  13147. newValue = (axis == "x" ? this._container.x : (-this._container.y));
  13148. return newValue;
  13149. };
  13150. return ScrollPane;
  13151. }(cc.Component));
  13152. fgui.ScrollPane = ScrollPane;
  13153. var _gestureFlag = 0;
  13154. var TWEEN_TIME_GO = 0.5;
  13155. var TWEEN_TIME_DEFAULT = 0.3;
  13156. var PULL_RATIO = 0.5;
  13157. var s_vec2 = new cc.Vec2();
  13158. var s_rect = new cc.Rect();
  13159. var sEndPos = new cc.Vec2();
  13160. var sOldChange = new cc.Vec2();
  13161. function easeFunc(t, d) {
  13162. return (t = t / d - 1) * t * t + 1;
  13163. }
  13164. })(fgui || (fgui = {}));
  13165. (function (fgui) {
  13166. var Transition = (function () {
  13167. function Transition(owner) {
  13168. this._ownerBaseX = 0;
  13169. this._ownerBaseY = 0;
  13170. this._totalTimes = 0;
  13171. this._totalTasks = 0;
  13172. this._options = 0;
  13173. this._totalDuration = 0;
  13174. this._autoPlayTimes = 1;
  13175. this._autoPlayDelay = 0;
  13176. this._timeScale = 1;
  13177. this._startTime = 0;
  13178. this._endTime = 0;
  13179. this._owner = owner;
  13180. this._items = new Array();
  13181. }
  13182. Transition.prototype.play = function (onComplete, times, delay, startTime, endTime) {
  13183. this._play(onComplete, times, delay, startTime, endTime, false);
  13184. };
  13185. Transition.prototype.playReverse = function (onComplete, times, delay) {
  13186. this._play(onComplete, times, delay, 0, -1, true);
  13187. };
  13188. Transition.prototype.changePlayTimes = function (value) {
  13189. this._totalTimes = value;
  13190. };
  13191. Transition.prototype.setAutoPlay = function (value, times, delay) {
  13192. if (times == undefined)
  13193. times = -1;
  13194. if (delay == undefined)
  13195. delay = 0;
  13196. if (this._autoPlay != value) {
  13197. this._autoPlay = value;
  13198. this._autoPlayTimes = times;
  13199. this._autoPlayDelay = delay;
  13200. if (this._autoPlay) {
  13201. if (this._owner.onStage)
  13202. this.play(null, this._autoPlayTimes, this._autoPlayDelay);
  13203. }
  13204. else {
  13205. if (!this._owner.onStage)
  13206. this.stop(false, true);
  13207. }
  13208. }
  13209. };
  13210. Transition.prototype._play = function (onComplete, times, delay, startTime, endTime, reversed) {
  13211. if (times == undefined)
  13212. times = 1;
  13213. if (delay == undefined)
  13214. delay = 0;
  13215. if (startTime == undefined)
  13216. startTime = 0;
  13217. if (endTime == undefined)
  13218. endTime = -1;
  13219. this.stop(true, true);
  13220. this._totalTimes = times;
  13221. this._reversed = reversed;
  13222. this._startTime = startTime;
  13223. this._endTime = endTime;
  13224. this._playing = true;
  13225. this._paused = false;
  13226. this._onComplete = onComplete;
  13227. var cnt = this._items.length;
  13228. for (var i = 0; i < cnt; i++) {
  13229. var item = this._items[i];
  13230. if (item.target == null) {
  13231. if (item.targetId)
  13232. item.target = this._owner.getChildById(item.targetId);
  13233. else
  13234. item.target = this._owner;
  13235. }
  13236. else if (item.target != this._owner && item.target.parent != this._owner)
  13237. item.target = null;
  13238. if (item.target && item.type == ActionType.Transition) {
  13239. var trans = item.target.getTransition(item.value.transName);
  13240. if (trans == this)
  13241. trans = null;
  13242. if (trans) {
  13243. if (item.value.playTimes == 0) {
  13244. var j;
  13245. for (j = i - 1; j >= 0; j--) {
  13246. var item2 = this._items[j];
  13247. if (item2.type == ActionType.Transition) {
  13248. if (item2.value.trans == trans) {
  13249. item2.value.stopTime = item.time - item2.time;
  13250. break;
  13251. }
  13252. }
  13253. }
  13254. if (j < 0)
  13255. item.value.stopTime = 0;
  13256. else
  13257. trans = null;
  13258. }
  13259. else
  13260. item.value.stopTime = -1;
  13261. }
  13262. item.value.trans = trans;
  13263. }
  13264. }
  13265. if (delay == 0)
  13266. this.onDelayedPlay();
  13267. else
  13268. fgui.GTween.delayedCall(delay).setTarget(this).onComplete(this.onDelayedPlay, this);
  13269. };
  13270. Transition.prototype.stop = function (setToComplete, processCallback) {
  13271. if (setToComplete == undefined)
  13272. setToComplete = true;
  13273. if (!this._playing)
  13274. return;
  13275. this._playing = false;
  13276. this._totalTasks = 0;
  13277. this._totalTimes = 0;
  13278. var func = this._onComplete;
  13279. this._onComplete = null;
  13280. fgui.GTween.kill(this);
  13281. var cnt = this._items.length;
  13282. if (this._reversed) {
  13283. for (var i = cnt - 1; i >= 0; i--) {
  13284. var item = this._items[i];
  13285. if (item.target == null)
  13286. continue;
  13287. this.stopItem(item, setToComplete);
  13288. }
  13289. }
  13290. else {
  13291. for (i = 0; i < cnt; i++) {
  13292. item = this._items[i];
  13293. if (item.target == null)
  13294. continue;
  13295. this.stopItem(item, setToComplete);
  13296. }
  13297. }
  13298. if (processCallback && func != null) {
  13299. func();
  13300. }
  13301. };
  13302. Transition.prototype.stopItem = function (item, setToComplete) {
  13303. if (item.displayLockToken != 0) {
  13304. item.target.releaseDisplayLock(item.displayLockToken);
  13305. item.displayLockToken = 0;
  13306. }
  13307. if (item.tweener) {
  13308. item.tweener.kill(setToComplete);
  13309. item.tweener = null;
  13310. if (item.type == ActionType.Shake && !setToComplete) {
  13311. item.target._gearLocked = true;
  13312. item.target.setPosition(item.target.x - item.value.lastOffsetX, item.target.y - item.value.lastOffsetY);
  13313. item.target._gearLocked = false;
  13314. }
  13315. }
  13316. if (item.type == ActionType.Transition) {
  13317. var trans = item.value.trans;
  13318. if (trans)
  13319. trans.stop(setToComplete, false);
  13320. }
  13321. };
  13322. Transition.prototype.setPaused = function (paused) {
  13323. if (!this._playing || this._paused == paused)
  13324. return;
  13325. this._paused = paused;
  13326. var tweener = fgui.GTween.getTween(this);
  13327. if (tweener)
  13328. tweener.setPaused(paused);
  13329. var cnt = this._items.length;
  13330. for (var i = 0; i < cnt; i++) {
  13331. var item = this._items[i];
  13332. if (item.target == null)
  13333. continue;
  13334. if (item.type == ActionType.Transition) {
  13335. if (item.value.trans)
  13336. item.value.trans.setPaused(paused);
  13337. }
  13338. else if (item.type == ActionType.Animation) {
  13339. if (paused) {
  13340. item.value.flag = item.target.getProp(fgui.ObjectPropID.Playing);
  13341. item.target.setProp(fgui.ObjectPropID.Playing, false);
  13342. }
  13343. else
  13344. item.target.setProp(fgui.ObjectPropID.Playing, item.value.flag);
  13345. }
  13346. if (item.tweener)
  13347. item.tweener.setPaused(paused);
  13348. }
  13349. };
  13350. Transition.prototype.dispose = function () {
  13351. if (this._playing)
  13352. fgui.GTween.kill(this);
  13353. var cnt = this._items.length;
  13354. for (var i = 0; i < cnt; i++) {
  13355. var item = this._items[i];
  13356. if (item.tweener) {
  13357. item.tweener.kill();
  13358. item.tweener = null;
  13359. }
  13360. item.target = null;
  13361. item.hook = null;
  13362. if (item.tweenConfig)
  13363. item.tweenConfig.endHook = null;
  13364. }
  13365. this._items.length = 0;
  13366. this._playing = false;
  13367. this._onComplete = null;
  13368. };
  13369. Object.defineProperty(Transition.prototype, "playing", {
  13370. get: function () {
  13371. return this._playing;
  13372. },
  13373. enumerable: false,
  13374. configurable: true
  13375. });
  13376. Transition.prototype.setValue = function (label) {
  13377. var args = [];
  13378. for (var _i = 1; _i < arguments.length; _i++) {
  13379. args[_i - 1] = arguments[_i];
  13380. }
  13381. var cnt = this._items.length;
  13382. var value;
  13383. for (var i = 0; i < cnt; i++) {
  13384. var item = this._items[i];
  13385. if (item.label == label) {
  13386. if (item.tweenConfig)
  13387. value = item.tweenConfig.startValue;
  13388. else
  13389. value = item.value;
  13390. }
  13391. else if (item.tweenConfig && item.tweenConfig.endLabel == label) {
  13392. value = item.tweenConfig.endValue;
  13393. }
  13394. else
  13395. continue;
  13396. switch (item.type) {
  13397. case ActionType.XY:
  13398. case ActionType.Size:
  13399. case ActionType.Pivot:
  13400. case ActionType.Scale:
  13401. case ActionType.Skew:
  13402. value.b1 = true;
  13403. value.b2 = true;
  13404. value.f1 = parseFloat(args[0]);
  13405. value.f2 = parseFloat(args[1]);
  13406. break;
  13407. case ActionType.Alpha:
  13408. value.f1 = parseFloat(args[0]);
  13409. break;
  13410. case ActionType.Rotation:
  13411. value.f1 = parseFloat(args[0]);
  13412. break;
  13413. case ActionType.Color:
  13414. value.f1 = parseFloat(args[0]);
  13415. break;
  13416. case ActionType.Animation:
  13417. value.frame = parseInt(args[0]);
  13418. if (args.length > 1)
  13419. value.playing = args[1];
  13420. break;
  13421. case ActionType.Visible:
  13422. value.visible = args[0];
  13423. break;
  13424. case ActionType.Sound:
  13425. value.sound = args[0];
  13426. if (args.length > 1)
  13427. value.volume = parseFloat(args[1]);
  13428. break;
  13429. case ActionType.Transition:
  13430. value.transName = args[0];
  13431. if (args.length > 1)
  13432. value.playTimes = parseInt(args[1]);
  13433. break;
  13434. case ActionType.Shake:
  13435. value.amplitude = parseFloat(args[0]);
  13436. if (args.length > 1)
  13437. value.duration = parseFloat(args[1]);
  13438. break;
  13439. case ActionType.ColorFilter:
  13440. value.f1 = parseFloat(args[0]);
  13441. value.f2 = parseFloat(args[1]);
  13442. value.f3 = parseFloat(args[2]);
  13443. value.f4 = parseFloat(args[3]);
  13444. break;
  13445. case ActionType.Text:
  13446. case ActionType.Icon:
  13447. value.text = args[0];
  13448. break;
  13449. }
  13450. }
  13451. };
  13452. Transition.prototype.setHook = function (label, callback) {
  13453. var cnt = this._items.length;
  13454. for (var i = 0; i < cnt; i++) {
  13455. var item = this._items[i];
  13456. if (item.label == label) {
  13457. item.hook = callback;
  13458. break;
  13459. }
  13460. else if (item.tweenConfig && item.tweenConfig.endLabel == label) {
  13461. item.tweenConfig.endHook = callback;
  13462. break;
  13463. }
  13464. }
  13465. };
  13466. Transition.prototype.clearHooks = function () {
  13467. var cnt = this._items.length;
  13468. for (var i = 0; i < cnt; i++) {
  13469. var item = this._items[i];
  13470. item.hook = null;
  13471. if (item.tweenConfig)
  13472. item.tweenConfig.endHook = null;
  13473. }
  13474. };
  13475. Transition.prototype.setTarget = function (label, newTarget) {
  13476. var cnt = this._items.length;
  13477. for (var i = 0; i < cnt; i++) {
  13478. var item = this._items[i];
  13479. if (item.label == label) {
  13480. item.targetId = newTarget.id;
  13481. item.target = null;
  13482. }
  13483. }
  13484. };
  13485. Transition.prototype.setDuration = function (label, value) {
  13486. var cnt = this._items.length;
  13487. for (var i = 0; i < cnt; i++) {
  13488. var item = this._items[i];
  13489. if (item.tweenConfig && item.label == label)
  13490. item.tweenConfig.duration = value;
  13491. }
  13492. };
  13493. Transition.prototype.getLabelTime = function (label) {
  13494. var cnt = this._items.length;
  13495. for (var i = 0; i < cnt; i++) {
  13496. var item = this._items[i];
  13497. if (item.label == label)
  13498. return item.time;
  13499. else if (item.tweenConfig && item.tweenConfig.endLabel == label)
  13500. return item.time + item.tweenConfig.duration;
  13501. }
  13502. return Number.NaN;
  13503. };
  13504. Object.defineProperty(Transition.prototype, "timeScale", {
  13505. get: function () {
  13506. return this._timeScale;
  13507. },
  13508. set: function (value) {
  13509. if (this._timeScale != value) {
  13510. this._timeScale = value;
  13511. if (this._playing) {
  13512. var cnt = this._items.length;
  13513. for (var i = 0; i < cnt; i++) {
  13514. var item = this._items[i];
  13515. if (item.tweener)
  13516. item.tweener.setTimeScale(value);
  13517. else if (item.type == ActionType.Transition) {
  13518. if (item.value.trans)
  13519. item.value.trans.timeScale = value;
  13520. }
  13521. else if (item.type == ActionType.Animation) {
  13522. if (item.target)
  13523. item.target.setProp(fgui.ObjectPropID.TimeScale, value);
  13524. }
  13525. }
  13526. }
  13527. }
  13528. },
  13529. enumerable: false,
  13530. configurable: true
  13531. });
  13532. Transition.prototype.updateFromRelations = function (targetId, dx, dy) {
  13533. var cnt = this._items.length;
  13534. if (cnt == 0)
  13535. return;
  13536. for (var i = 0; i < cnt; i++) {
  13537. var item = this._items[i];
  13538. if (item.type == ActionType.XY && item.targetId == targetId) {
  13539. if (item.tweenConfig) {
  13540. item.tweenConfig.startValue.f1 += dx;
  13541. item.tweenConfig.startValue.f2 += dy;
  13542. item.tweenConfig.endValue.f1 += dx;
  13543. item.tweenConfig.endValue.f2 += dy;
  13544. }
  13545. else {
  13546. item.value.f1 += dx;
  13547. item.value.f2 += dy;
  13548. }
  13549. }
  13550. }
  13551. };
  13552. Transition.prototype.onEnable = function () {
  13553. if (this._autoPlay && !this._playing)
  13554. this.play(null, this._autoPlayTimes, this._autoPlayDelay);
  13555. };
  13556. Transition.prototype.onDisable = function () {
  13557. if ((this._options & OPTION_AUTO_STOP_DISABLED) == 0)
  13558. this.stop((this._options & OPTION_AUTO_STOP_AT_END) != 0 ? true : false, false);
  13559. };
  13560. Transition.prototype.onDelayedPlay = function () {
  13561. this.internalPlay();
  13562. this._playing = this._totalTasks > 0;
  13563. if (this._playing) {
  13564. if ((this._options & OPTION_IGNORE_DISPLAY_CONTROLLER) != 0) {
  13565. var cnt = this._items.length;
  13566. for (var i = 0; i < cnt; i++) {
  13567. var item = this._items[i];
  13568. if (item.target && item.target != this._owner)
  13569. item.displayLockToken = item.target.addDisplayLock();
  13570. }
  13571. }
  13572. }
  13573. else if (this._onComplete != null) {
  13574. var func = this._onComplete;
  13575. this._onComplete = null;
  13576. func();
  13577. }
  13578. };
  13579. Transition.prototype.internalPlay = function () {
  13580. this._ownerBaseX = this._owner.x;
  13581. this._ownerBaseY = this._owner.y;
  13582. this._totalTasks = 1;
  13583. var cnt = this._items.length;
  13584. var item;
  13585. var needSkipAnimations = false;
  13586. var i;
  13587. if (!this._reversed) {
  13588. for (i = 0; i < cnt; i++) {
  13589. item = this._items[i];
  13590. if (item.target == null)
  13591. continue;
  13592. if (item.type == ActionType.Animation && this._startTime != 0 && item.time <= this._startTime) {
  13593. needSkipAnimations = true;
  13594. item.value.flag = false;
  13595. }
  13596. else
  13597. this.playItem(item);
  13598. }
  13599. }
  13600. else {
  13601. for (i = cnt - 1; i >= 0; i--) {
  13602. item = this._items[i];
  13603. if (item.target == null)
  13604. continue;
  13605. this.playItem(item);
  13606. }
  13607. }
  13608. if (needSkipAnimations)
  13609. this.skipAnimations();
  13610. this._totalTasks--;
  13611. };
  13612. Transition.prototype.playItem = function (item) {
  13613. var time;
  13614. if (item.tweenConfig) {
  13615. if (this._reversed)
  13616. time = (this._totalDuration - item.time - item.tweenConfig.duration);
  13617. else
  13618. time = item.time;
  13619. if (this._endTime == -1 || time <= this._endTime) {
  13620. var startValue;
  13621. var endValue;
  13622. if (this._reversed) {
  13623. startValue = item.tweenConfig.endValue;
  13624. endValue = item.tweenConfig.startValue;
  13625. }
  13626. else {
  13627. startValue = item.tweenConfig.startValue;
  13628. endValue = item.tweenConfig.endValue;
  13629. }
  13630. item.value.b1 = startValue.b1 || endValue.b1;
  13631. item.value.b2 = startValue.b2 || endValue.b2;
  13632. switch (item.type) {
  13633. case ActionType.XY:
  13634. case ActionType.Size:
  13635. case ActionType.Scale:
  13636. case ActionType.Skew:
  13637. item.tweener = fgui.GTween.to2(startValue.f1, startValue.f2, endValue.f1, endValue.f2, item.tweenConfig.duration);
  13638. break;
  13639. case ActionType.Alpha:
  13640. case ActionType.Rotation:
  13641. item.tweener = fgui.GTween.to(startValue.f1, endValue.f1, item.tweenConfig.duration);
  13642. break;
  13643. case ActionType.Color:
  13644. item.tweener = fgui.GTween.toColor(startValue.f1, endValue.f1, item.tweenConfig.duration);
  13645. break;
  13646. case ActionType.ColorFilter:
  13647. item.tweener = fgui.GTween.to4(startValue.f1, startValue.f2, startValue.f3, startValue.f4, endValue.f1, endValue.f2, endValue.f3, endValue.f4, item.tweenConfig.duration);
  13648. break;
  13649. }
  13650. item.tweener.setDelay(time)
  13651. .setEase(item.tweenConfig.easeType)
  13652. .setRepeat(item.tweenConfig.repeat, item.tweenConfig.yoyo)
  13653. .setTimeScale(this._timeScale)
  13654. .setTarget(item)
  13655. .onStart(this.onTweenStart, this)
  13656. .onUpdate(this.onTweenUpdate, this)
  13657. .onComplete(this.onTweenComplete, this);
  13658. if (this._endTime >= 0)
  13659. item.tweener.setBreakpoint(this._endTime - time);
  13660. this._totalTasks++;
  13661. }
  13662. }
  13663. else if (item.type == ActionType.Shake) {
  13664. if (this._reversed)
  13665. time = (this._totalDuration - item.time - item.value.duration);
  13666. else
  13667. time = item.time;
  13668. item.value.offsetX = item.value.offsetY = 0;
  13669. item.value.lastOffsetX = item.value.lastOffsetY = 0;
  13670. item.tweener = fgui.GTween.shake(0, 0, item.value.amplitude, item.value.duration)
  13671. .setDelay(time)
  13672. .setTimeScale(this._timeScale)
  13673. .setTarget(item)
  13674. .onUpdate(this.onTweenUpdate, this)
  13675. .onComplete(this.onTweenComplete, this);
  13676. if (this._endTime >= 0)
  13677. item.tweener.setBreakpoint(this._endTime - item.time);
  13678. this._totalTasks++;
  13679. }
  13680. else {
  13681. if (this._reversed)
  13682. time = (this._totalDuration - item.time);
  13683. else
  13684. time = item.time;
  13685. if (time <= this._startTime) {
  13686. this.applyValue(item);
  13687. this.callHook(item, false);
  13688. }
  13689. else if (this._endTime == -1 || time <= this._endTime) {
  13690. this._totalTasks++;
  13691. item.tweener = fgui.GTween.delayedCall(time)
  13692. .setTimeScale(this._timeScale)
  13693. .setTarget(item)
  13694. .onComplete(this.onDelayedPlayItem, this);
  13695. }
  13696. }
  13697. if (item.tweener)
  13698. item.tweener.seek(this._startTime);
  13699. };
  13700. Transition.prototype.skipAnimations = function () {
  13701. var frame;
  13702. var playStartTime;
  13703. var playTotalTime;
  13704. var value;
  13705. var target;
  13706. var item;
  13707. var cnt = this._items.length;
  13708. for (var i = 0; i < cnt; i++) {
  13709. item = this._items[i];
  13710. if (item.type != ActionType.Animation || item.time > this._startTime)
  13711. continue;
  13712. value = item.value;
  13713. if (value.flag)
  13714. continue;
  13715. target = item.target;
  13716. frame = target.getProp(fgui.ObjectPropID.Frame);
  13717. playStartTime = target.getProp(fgui.ObjectPropID.Playing) ? 0 : -1;
  13718. playTotalTime = 0;
  13719. for (var j = i; j < cnt; j++) {
  13720. item = this._items[j];
  13721. if (item.type != ActionType.Animation || item.target != target || item.time > this._startTime)
  13722. continue;
  13723. value = item.value;
  13724. value.flag = true;
  13725. if (value.frame != -1) {
  13726. frame = value.frame;
  13727. if (value.playing)
  13728. playStartTime = item.time;
  13729. else
  13730. playStartTime = -1;
  13731. playTotalTime = 0;
  13732. }
  13733. else {
  13734. if (value.playing) {
  13735. if (playStartTime < 0)
  13736. playStartTime = item.time;
  13737. }
  13738. else {
  13739. if (playStartTime >= 0)
  13740. playTotalTime += (item.time - playStartTime);
  13741. playStartTime = -1;
  13742. }
  13743. }
  13744. this.callHook(item, false);
  13745. }
  13746. if (playStartTime >= 0)
  13747. playTotalTime += (this._startTime - playStartTime);
  13748. target.setProp(fgui.ObjectPropID.Playing, playStartTime >= 0);
  13749. target.setProp(fgui.ObjectPropID.Frame, frame);
  13750. if (playTotalTime > 0)
  13751. target.setProp(fgui.ObjectPropID.DeltaTime, playTotalTime);
  13752. }
  13753. };
  13754. Transition.prototype.onDelayedPlayItem = function (tweener) {
  13755. var item = tweener.target;
  13756. item.tweener = null;
  13757. this._totalTasks--;
  13758. this.applyValue(item);
  13759. this.callHook(item, false);
  13760. this.checkAllComplete();
  13761. };
  13762. Transition.prototype.onTweenStart = function (tweener) {
  13763. var item = tweener.target;
  13764. if (item.type == ActionType.XY || item.type == ActionType.Size) {
  13765. var startValue;
  13766. var endValue;
  13767. if (this._reversed) {
  13768. startValue = item.tweenConfig.endValue;
  13769. endValue = item.tweenConfig.startValue;
  13770. }
  13771. else {
  13772. startValue = item.tweenConfig.startValue;
  13773. endValue = item.tweenConfig.endValue;
  13774. }
  13775. if (item.type == ActionType.XY) {
  13776. if (item.target != this._owner) {
  13777. if (!startValue.b1)
  13778. tweener.startValue.x = item.target.x;
  13779. else if (startValue.b3)
  13780. tweener.startValue.x = startValue.f1 * this._owner.width;
  13781. if (!startValue.b2)
  13782. tweener.startValue.y = item.target.y;
  13783. else if (startValue.b3)
  13784. tweener.startValue.y = startValue.f2 * this._owner.height;
  13785. if (!endValue.b1)
  13786. tweener.endValue.x = tweener.startValue.x;
  13787. else if (endValue.b3)
  13788. tweener.endValue.x = endValue.f1 * this._owner.width;
  13789. if (!endValue.b2)
  13790. tweener.endValue.y = tweener.startValue.y;
  13791. else if (endValue.b3)
  13792. tweener.endValue.y = endValue.f2 * this._owner.height;
  13793. }
  13794. else {
  13795. if (!startValue.b1)
  13796. tweener.startValue.x = item.target.x - this._ownerBaseX;
  13797. if (!startValue.b2)
  13798. tweener.startValue.y = item.target.y - this._ownerBaseY;
  13799. if (!endValue.b1)
  13800. tweener.endValue.x = tweener.startValue.x;
  13801. if (!endValue.b2)
  13802. tweener.endValue.y = tweener.startValue.y;
  13803. }
  13804. }
  13805. else {
  13806. if (!startValue.b1)
  13807. tweener.startValue.x = item.target.width;
  13808. if (!startValue.b2)
  13809. tweener.startValue.y = item.target.height;
  13810. if (!endValue.b1)
  13811. tweener.endValue.x = tweener.startValue.x;
  13812. if (!endValue.b2)
  13813. tweener.endValue.y = tweener.startValue.y;
  13814. }
  13815. if (item.tweenConfig.path) {
  13816. item.value.b1 = item.value.b2 = true;
  13817. tweener.setPath(item.tweenConfig.path);
  13818. }
  13819. }
  13820. this.callHook(item, false);
  13821. };
  13822. Transition.prototype.onTweenUpdate = function (tweener) {
  13823. var item = tweener.target;
  13824. switch (item.type) {
  13825. case ActionType.XY:
  13826. case ActionType.Size:
  13827. case ActionType.Scale:
  13828. case ActionType.Skew:
  13829. item.value.f1 = tweener.value.x;
  13830. item.value.f2 = tweener.value.y;
  13831. if (item.tweenConfig.path) {
  13832. item.value.f1 += tweener.startValue.x;
  13833. item.value.f2 += tweener.startValue.y;
  13834. }
  13835. break;
  13836. case ActionType.Alpha:
  13837. case ActionType.Rotation:
  13838. item.value.f1 = tweener.value.x;
  13839. break;
  13840. case ActionType.Color:
  13841. item.value.f1 = tweener.value.color;
  13842. break;
  13843. case ActionType.ColorFilter:
  13844. item.value.f1 = tweener.value.x;
  13845. item.value.f2 = tweener.value.y;
  13846. item.value.f3 = tweener.value.z;
  13847. item.value.f4 = tweener.value.w;
  13848. break;
  13849. case ActionType.Shake:
  13850. item.value.offsetX = tweener.deltaValue.x;
  13851. item.value.offsetY = tweener.deltaValue.y;
  13852. break;
  13853. }
  13854. this.applyValue(item);
  13855. };
  13856. Transition.prototype.onTweenComplete = function (tweener) {
  13857. var item = tweener.target;
  13858. item.tweener = null;
  13859. this._totalTasks--;
  13860. if (tweener.allCompleted)
  13861. this.callHook(item, true);
  13862. this.checkAllComplete();
  13863. };
  13864. Transition.prototype.onPlayTransCompleted = function (item) {
  13865. this._totalTasks--;
  13866. this.checkAllComplete();
  13867. };
  13868. Transition.prototype.callHook = function (item, tweenEnd) {
  13869. if (tweenEnd) {
  13870. if (item.tweenConfig && item.tweenConfig.endHook != null)
  13871. item.tweenConfig.endHook(item.label);
  13872. }
  13873. else {
  13874. if (item.time >= this._startTime && item.hook != null)
  13875. item.hook(item.label);
  13876. }
  13877. };
  13878. Transition.prototype.checkAllComplete = function () {
  13879. if (this._playing && this._totalTasks == 0) {
  13880. if (this._totalTimes < 0) {
  13881. this.internalPlay();
  13882. if (this._totalTasks == 0)
  13883. fgui.GTween.delayedCall(0).setTarget(this).onComplete(this.checkAllComplete, this);
  13884. }
  13885. else {
  13886. this._totalTimes--;
  13887. if (this._totalTimes > 0) {
  13888. this.internalPlay();
  13889. if (this._totalTasks == 0)
  13890. fgui.GTween.delayedCall(0).setTarget(this).onComplete(this.checkAllComplete, this);
  13891. }
  13892. else {
  13893. this._playing = false;
  13894. var cnt = this._items.length;
  13895. for (var i = 0; i < cnt; i++) {
  13896. var item = this._items[i];
  13897. if (item.target && item.displayLockToken != 0) {
  13898. item.target.releaseDisplayLock(item.displayLockToken);
  13899. item.displayLockToken = 0;
  13900. }
  13901. }
  13902. if (this._onComplete != null) {
  13903. var func = this._onComplete;
  13904. this._onComplete = null;
  13905. func();
  13906. }
  13907. }
  13908. }
  13909. }
  13910. };
  13911. Transition.prototype.applyValue = function (item) {
  13912. item.target._gearLocked = true;
  13913. var value = item.value;
  13914. switch (item.type) {
  13915. case ActionType.XY:
  13916. if (item.target == this._owner) {
  13917. if (value.b1 && value.b2)
  13918. item.target.setPosition(value.f1 + this._ownerBaseX, value.f2 + this._ownerBaseY);
  13919. else if (value.b1)
  13920. item.target.x = value.f1 + this._ownerBaseX;
  13921. else
  13922. item.target.y = value.f2 + this._ownerBaseY;
  13923. }
  13924. else {
  13925. if (value.b3) {
  13926. if (value.b1 && value.b2)
  13927. item.target.setPosition(value.f1 * this._owner.width, value.f2 * this._owner.height);
  13928. else if (value.b1)
  13929. item.target.x = value.f1 * this._owner.width;
  13930. else if (value.b2)
  13931. item.target.y = value.f2 * this._owner.height;
  13932. }
  13933. else {
  13934. if (value.b1 && value.b2)
  13935. item.target.setPosition(value.f1, value.f2);
  13936. else if (value.b1)
  13937. item.target.x = value.f1;
  13938. else if (value.b2)
  13939. item.target.y = value.f2;
  13940. }
  13941. }
  13942. break;
  13943. case ActionType.Size:
  13944. if (!value.b1)
  13945. value.f1 = item.target.width;
  13946. if (!value.b2)
  13947. value.f2 = item.target.height;
  13948. item.target.setSize(value.f1, value.f2);
  13949. break;
  13950. case ActionType.Pivot:
  13951. item.target.setPivot(value.f1, value.f2, item.target.pivotAsAnchor);
  13952. break;
  13953. case ActionType.Alpha:
  13954. item.target.alpha = value.f1;
  13955. break;
  13956. case ActionType.Rotation:
  13957. item.target.rotation = value.f1;
  13958. break;
  13959. case ActionType.Scale:
  13960. item.target.setScale(value.f1, value.f2);
  13961. break;
  13962. case ActionType.Skew:
  13963. item.target.setSkew(value.f1, value.f2);
  13964. break;
  13965. case ActionType.Color:
  13966. var color = item.target.getProp(fgui.ObjectPropID.Color);
  13967. if (color instanceof cc.Color) {
  13968. var i = Math.floor(value.f1);
  13969. color.setR((i >> 16) & 0xFF).setG((i >> 8) & 0xFF).setB(i & 0xFF);
  13970. item.target.setProp(fgui.ObjectPropID.Color, color);
  13971. }
  13972. break;
  13973. case ActionType.Animation:
  13974. if (value.frame >= 0)
  13975. item.target.setProp(fgui.ObjectPropID.Frame, value.frame);
  13976. item.target.setProp(fgui.ObjectPropID.Playing, value.playing);
  13977. item.target.setProp(fgui.ObjectPropID.TimeScale, this._timeScale);
  13978. break;
  13979. case ActionType.Visible:
  13980. item.target.visible = value.visible;
  13981. break;
  13982. case ActionType.Transition:
  13983. if (this._playing) {
  13984. var trans = value.trans;
  13985. if (trans) {
  13986. this._totalTasks++;
  13987. var startTime = this._startTime > item.time ? (this._startTime - item.time) : 0;
  13988. var endTime = this._endTime >= 0 ? (this._endTime - item.time) : -1;
  13989. if (value.stopTime >= 0 && (endTime < 0 || endTime > value.stopTime))
  13990. endTime = value.stopTime;
  13991. trans.timeScale = this._timeScale;
  13992. trans._play(function () { this.onPlayTransCompleted(item); }.bind(this), value.playTimes, 0, startTime, endTime, this._reversed);
  13993. }
  13994. }
  13995. break;
  13996. case ActionType.Sound:
  13997. if (this._playing && item.time >= this._startTime) {
  13998. if (value.audioClip == null) {
  13999. var pi = fgui.UIPackage.getItemByURL(value.sound);
  14000. if (pi)
  14001. value.audioClip = pi.owner.getItemAsset(pi);
  14002. }
  14003. if (value.audioClip)
  14004. fgui.GRoot.inst.playOneShotSound(value.audioClip, value.volume);
  14005. }
  14006. break;
  14007. case ActionType.Shake:
  14008. item.target.setPosition(item.target.x - value.lastOffsetX + value.offsetX, item.target.y - value.lastOffsetY + value.offsetY);
  14009. value.lastOffsetX = value.offsetX;
  14010. value.lastOffsetY = value.offsetY;
  14011. break;
  14012. case ActionType.ColorFilter:
  14013. {
  14014. break;
  14015. }
  14016. case ActionType.Text:
  14017. item.target.text = value.text;
  14018. break;
  14019. case ActionType.Icon:
  14020. item.target.icon = value.text;
  14021. break;
  14022. }
  14023. item.target._gearLocked = false;
  14024. };
  14025. Transition.prototype.setup = function (buffer) {
  14026. this.name = buffer.readS();
  14027. this._options = buffer.readInt();
  14028. this._autoPlay = buffer.readBool();
  14029. this._autoPlayTimes = buffer.readInt();
  14030. this._autoPlayDelay = buffer.readFloat();
  14031. var cnt = buffer.readShort();
  14032. for (var i = 0; i < cnt; i++) {
  14033. var dataLen = buffer.readShort();
  14034. var curPos = buffer.position;
  14035. buffer.seek(curPos, 0);
  14036. var item = new Item(buffer.readByte());
  14037. this._items[i] = item;
  14038. item.time = buffer.readFloat();
  14039. var targetId = buffer.readShort();
  14040. if (targetId < 0)
  14041. item.targetId = "";
  14042. else
  14043. item.targetId = this._owner.getChildAt(targetId).id;
  14044. item.label = buffer.readS();
  14045. if (buffer.readBool()) {
  14046. buffer.seek(curPos, 1);
  14047. item.tweenConfig = new TweenConfig();
  14048. item.tweenConfig.duration = buffer.readFloat();
  14049. if (item.time + item.tweenConfig.duration > this._totalDuration)
  14050. this._totalDuration = item.time + item.tweenConfig.duration;
  14051. item.tweenConfig.easeType = buffer.readByte();
  14052. item.tweenConfig.repeat = buffer.readInt();
  14053. item.tweenConfig.yoyo = buffer.readBool();
  14054. item.tweenConfig.endLabel = buffer.readS();
  14055. buffer.seek(curPos, 2);
  14056. this.decodeValue(item, buffer, item.tweenConfig.startValue);
  14057. buffer.seek(curPos, 3);
  14058. this.decodeValue(item, buffer, item.tweenConfig.endValue);
  14059. if (buffer.version >= 2) {
  14060. var pathLen = buffer.readInt();
  14061. if (pathLen > 0) {
  14062. item.tweenConfig.path = new fgui.GPath();
  14063. var pts = new Array();
  14064. for (var j = 0; j < pathLen; j++) {
  14065. var curveType = buffer.readByte();
  14066. switch (curveType) {
  14067. case fgui.CurveType.Bezier:
  14068. pts.push(fgui.GPathPoint.newBezierPoint(buffer.readFloat(), buffer.readFloat(), buffer.readFloat(), buffer.readFloat()));
  14069. break;
  14070. case fgui.CurveType.CubicBezier:
  14071. pts.push(fgui.GPathPoint.newCubicBezierPoint(buffer.readFloat(), buffer.readFloat(), buffer.readFloat(), buffer.readFloat(), buffer.readFloat(), buffer.readFloat()));
  14072. break;
  14073. default:
  14074. pts.push(fgui.GPathPoint.newPoint(buffer.readFloat(), buffer.readFloat(), curveType));
  14075. break;
  14076. }
  14077. }
  14078. item.tweenConfig.path.create(pts);
  14079. }
  14080. }
  14081. }
  14082. else {
  14083. if (item.time > this._totalDuration)
  14084. this._totalDuration = item.time;
  14085. buffer.seek(curPos, 2);
  14086. this.decodeValue(item, buffer, item.value);
  14087. }
  14088. buffer.position = curPos + dataLen;
  14089. }
  14090. };
  14091. Transition.prototype.decodeValue = function (item, buffer, value) {
  14092. switch (item.type) {
  14093. case ActionType.XY:
  14094. case ActionType.Size:
  14095. case ActionType.Pivot:
  14096. case ActionType.Skew:
  14097. value.b1 = buffer.readBool();
  14098. value.b2 = buffer.readBool();
  14099. value.f1 = buffer.readFloat();
  14100. value.f2 = buffer.readFloat();
  14101. if (buffer.version >= 2 && item.type == ActionType.XY)
  14102. value.b3 = buffer.readBool();
  14103. break;
  14104. case ActionType.Alpha:
  14105. case ActionType.Rotation:
  14106. value.f1 = buffer.readFloat();
  14107. break;
  14108. case ActionType.Scale:
  14109. value.f1 = buffer.readFloat();
  14110. value.f2 = buffer.readFloat();
  14111. break;
  14112. case ActionType.Color:
  14113. var color = buffer.readColor();
  14114. value.f1 = (color.getR() << 16) + (color.getG() << 8) + color.getB();
  14115. break;
  14116. case ActionType.Animation:
  14117. value.playing = buffer.readBool();
  14118. value.frame = buffer.readInt();
  14119. break;
  14120. case ActionType.Visible:
  14121. value.visible = buffer.readBool();
  14122. break;
  14123. case ActionType.Sound:
  14124. value.sound = buffer.readS();
  14125. value.volume = buffer.readFloat();
  14126. break;
  14127. case ActionType.Transition:
  14128. value.transName = buffer.readS();
  14129. value.playTimes = buffer.readInt();
  14130. break;
  14131. case ActionType.Shake:
  14132. value.amplitude = buffer.readFloat();
  14133. value.duration = buffer.readFloat();
  14134. break;
  14135. case ActionType.ColorFilter:
  14136. value.f1 = buffer.readFloat();
  14137. value.f2 = buffer.readFloat();
  14138. value.f3 = buffer.readFloat();
  14139. value.f4 = buffer.readFloat();
  14140. break;
  14141. case ActionType.Text:
  14142. case ActionType.Icon:
  14143. value.text = buffer.readS();
  14144. break;
  14145. }
  14146. };
  14147. return Transition;
  14148. }());
  14149. fgui.Transition = Transition;
  14150. var OPTION_IGNORE_DISPLAY_CONTROLLER = 1;
  14151. var OPTION_AUTO_STOP_DISABLED = 2;
  14152. var OPTION_AUTO_STOP_AT_END = 4;
  14153. var ActionType;
  14154. (function (ActionType) {
  14155. ActionType[ActionType["XY"] = 0] = "XY";
  14156. ActionType[ActionType["Size"] = 1] = "Size";
  14157. ActionType[ActionType["Scale"] = 2] = "Scale";
  14158. ActionType[ActionType["Pivot"] = 3] = "Pivot";
  14159. ActionType[ActionType["Alpha"] = 4] = "Alpha";
  14160. ActionType[ActionType["Rotation"] = 5] = "Rotation";
  14161. ActionType[ActionType["Color"] = 6] = "Color";
  14162. ActionType[ActionType["Animation"] = 7] = "Animation";
  14163. ActionType[ActionType["Visible"] = 8] = "Visible";
  14164. ActionType[ActionType["Sound"] = 9] = "Sound";
  14165. ActionType[ActionType["Transition"] = 10] = "Transition";
  14166. ActionType[ActionType["Shake"] = 11] = "Shake";
  14167. ActionType[ActionType["ColorFilter"] = 12] = "ColorFilter";
  14168. ActionType[ActionType["Skew"] = 13] = "Skew";
  14169. ActionType[ActionType["Text"] = 14] = "Text";
  14170. ActionType[ActionType["Icon"] = 15] = "Icon";
  14171. ActionType[ActionType["Unknown"] = 16] = "Unknown";
  14172. })(ActionType || (ActionType = {}));
  14173. var Item = (function () {
  14174. function Item(type) {
  14175. this.type = type;
  14176. this.value = {};
  14177. this.displayLockToken = 0;
  14178. }
  14179. return Item;
  14180. }());
  14181. var TweenConfig = (function () {
  14182. function TweenConfig() {
  14183. this.easeType = fgui.EaseType.QuadOut;
  14184. this.startValue = { b1: true, b2: true };
  14185. this.endValue = { b1: true, b2: true };
  14186. }
  14187. return TweenConfig;
  14188. }());
  14189. })(fgui || (fgui = {}));
  14190. (function (fgui) {
  14191. var TranslationHelper = (function () {
  14192. function TranslationHelper() {
  14193. }
  14194. TranslationHelper.loadFromXML = function (source) {
  14195. var strings = {};
  14196. TranslationHelper.strings = strings;
  14197. var xml = new cc["SAXParser"]().parse(source).documentElement;
  14198. var nodes = xml.childNodes;
  14199. var length1 = nodes.length;
  14200. for (var i1 = 0; i1 < length1; i1++) {
  14201. var cxml = nodes[i1];
  14202. if (cxml.tagName == "string") {
  14203. var key = cxml.getAttribute("name");
  14204. var text = cxml.childNodes.length > 0 ? cxml.firstChild.nodeValue : "";
  14205. var i = key.indexOf("-");
  14206. if (i == -1)
  14207. continue;
  14208. var key2 = key.substr(0, i);
  14209. var key3 = key.substr(i + 1);
  14210. var col = strings[key2];
  14211. if (!col) {
  14212. col = {};
  14213. strings[key2] = col;
  14214. }
  14215. col[key3] = text;
  14216. }
  14217. }
  14218. };
  14219. TranslationHelper.translateComponent = function (item) {
  14220. if (TranslationHelper.strings == null)
  14221. return;
  14222. var compStrings = TranslationHelper.strings[item.owner.id + item.id];
  14223. if (compStrings == null)
  14224. return;
  14225. var elementId, value;
  14226. var buffer = item.rawData;
  14227. var nextPos;
  14228. var itemCount;
  14229. var i, j, k;
  14230. var dataLen;
  14231. var curPos;
  14232. var valueCnt;
  14233. var page;
  14234. buffer.seek(0, 2);
  14235. var childCount = buffer.readShort();
  14236. for (i = 0; i < childCount; i++) {
  14237. dataLen = buffer.readShort();
  14238. curPos = buffer.position;
  14239. buffer.seek(curPos, 0);
  14240. var baseType = buffer.readByte();
  14241. var type = baseType;
  14242. buffer.skip(4);
  14243. elementId = buffer.readS();
  14244. if (type == fgui.ObjectType.Component) {
  14245. if (buffer.seek(curPos, 6))
  14246. type = buffer.readByte();
  14247. }
  14248. buffer.seek(curPos, 1);
  14249. if ((value = compStrings[elementId + "-tips"]) != null)
  14250. buffer.writeS(value);
  14251. buffer.seek(curPos, 2);
  14252. var gearCnt = buffer.readShort();
  14253. for (j = 0; j < gearCnt; j++) {
  14254. nextPos = buffer.readShort();
  14255. nextPos += buffer.position;
  14256. if (buffer.readByte() == 6) {
  14257. buffer.skip(2);
  14258. valueCnt = buffer.readShort();
  14259. for (k = 0; k < valueCnt; k++) {
  14260. page = buffer.readS();
  14261. if (page != null) {
  14262. if ((value = compStrings[elementId + "-texts_" + k]) != null)
  14263. buffer.writeS(value);
  14264. else
  14265. buffer.skip(2);
  14266. }
  14267. }
  14268. if (buffer.readBool() && (value = compStrings[elementId + "-texts_def"]) != null)
  14269. buffer.writeS(value);
  14270. }
  14271. buffer.position = nextPos;
  14272. }
  14273. if (baseType == fgui.ObjectType.Component && buffer.version >= 2) {
  14274. buffer.seek(curPos, 4);
  14275. buffer.skip(2);
  14276. buffer.skip(4 * buffer.readShort());
  14277. var cpCount = buffer.readShort();
  14278. for (var k = 0; k < cpCount; k++) {
  14279. var target = buffer.readS();
  14280. var propertyId = buffer.readShort();
  14281. if (propertyId == 0 && (value = compStrings[elementId + "-cp-" + target]) != null)
  14282. buffer.writeS(value);
  14283. else
  14284. buffer.skip(2);
  14285. }
  14286. }
  14287. switch (type) {
  14288. case fgui.ObjectType.Text:
  14289. case fgui.ObjectType.RichText:
  14290. case fgui.ObjectType.InputText:
  14291. {
  14292. if ((value = compStrings[elementId]) != null) {
  14293. buffer.seek(curPos, 6);
  14294. buffer.writeS(value);
  14295. }
  14296. if ((value = compStrings[elementId + "-prompt"]) != null) {
  14297. buffer.seek(curPos, 4);
  14298. buffer.writeS(value);
  14299. }
  14300. break;
  14301. }
  14302. case fgui.ObjectType.List:
  14303. case fgui.ObjectType.Tree:
  14304. {
  14305. buffer.seek(curPos, 8);
  14306. buffer.skip(2);
  14307. itemCount = buffer.readShort();
  14308. for (j = 0; j < itemCount; j++) {
  14309. nextPos = buffer.readShort();
  14310. nextPos += buffer.position;
  14311. buffer.skip(2);
  14312. if (type == fgui.ObjectType.Tree)
  14313. buffer.skip(2);
  14314. if ((value = compStrings[elementId + "-" + j]) != null)
  14315. buffer.writeS(value);
  14316. else
  14317. buffer.skip(2);
  14318. if ((value = compStrings[elementId + "-" + j + "-0"]) != null)
  14319. buffer.writeS(value);
  14320. else
  14321. buffer.skip(2);
  14322. if (buffer.version >= 2) {
  14323. buffer.skip(6);
  14324. buffer.skip(buffer.readUshort() * 4);
  14325. var cpCount = buffer.readUshort();
  14326. for (var k = 0; k < cpCount; k++) {
  14327. var target = buffer.readS();
  14328. var propertyId = buffer.readUshort();
  14329. if (propertyId == 0 && (value = compStrings[elementId + "-" + j + "-" + target]) != null)
  14330. buffer.writeS(value);
  14331. else
  14332. buffer.skip(2);
  14333. }
  14334. }
  14335. buffer.position = nextPos;
  14336. }
  14337. break;
  14338. }
  14339. case fgui.ObjectType.Label:
  14340. {
  14341. if (buffer.seek(curPos, 6) && buffer.readByte() == type) {
  14342. if ((value = compStrings[elementId]) != null)
  14343. buffer.writeS(value);
  14344. else
  14345. buffer.skip(2);
  14346. buffer.skip(2);
  14347. if (buffer.readBool())
  14348. buffer.skip(4);
  14349. buffer.skip(4);
  14350. if (buffer.readBool() && (value = compStrings[elementId + "-prompt"]) != null)
  14351. buffer.writeS(value);
  14352. }
  14353. break;
  14354. }
  14355. case fgui.ObjectType.Button:
  14356. {
  14357. if (buffer.seek(curPos, 6) && buffer.readByte() == type) {
  14358. if ((value = compStrings[elementId]) != null)
  14359. buffer.writeS(value);
  14360. else
  14361. buffer.skip(2);
  14362. if ((value = compStrings[elementId + "-0"]) != null)
  14363. buffer.writeS(value);
  14364. }
  14365. break;
  14366. }
  14367. case fgui.ObjectType.ComboBox:
  14368. {
  14369. if (buffer.seek(curPos, 6) && buffer.readByte() == type) {
  14370. itemCount = buffer.readShort();
  14371. for (j = 0; j < itemCount; j++) {
  14372. nextPos = buffer.readShort();
  14373. nextPos += buffer.position;
  14374. if ((value = compStrings[elementId + "-" + j]) != null)
  14375. buffer.writeS(value);
  14376. buffer.position = nextPos;
  14377. }
  14378. if ((value = compStrings[elementId]) != null)
  14379. buffer.writeS(value);
  14380. }
  14381. break;
  14382. }
  14383. }
  14384. buffer.position = curPos + dataLen;
  14385. }
  14386. };
  14387. return TranslationHelper;
  14388. }());
  14389. fgui.TranslationHelper = TranslationHelper;
  14390. })(fgui || (fgui = {}));
  14391. (function (fgui) {
  14392. var UIConfig = (function () {
  14393. function UIConfig() {
  14394. }
  14395. UIConfig.defaultFont = "Arial";
  14396. UIConfig.modalLayerColor = new cc.Color(0x33, 0x33, 0x33, 0x33);
  14397. UIConfig.buttonSoundVolumeScale = 1;
  14398. UIConfig.defaultScrollStep = 25;
  14399. UIConfig.defaultScrollDecelerationRate = 0.967;
  14400. UIConfig.defaultScrollBarDisplay = fgui.ScrollBarDisplayType.Visible;
  14401. UIConfig.defaultScrollTouchEffect = true;
  14402. UIConfig.defaultScrollBounceEffect = true;
  14403. UIConfig.defaultComboBoxVisibleItemCount = 10;
  14404. UIConfig.touchScrollSensitivity = 20;
  14405. UIConfig.touchDragSensitivity = 10;
  14406. UIConfig.clickDragSensitivity = 2;
  14407. UIConfig.bringWindowToFrontOnClick = true;
  14408. UIConfig.frameTimeForAsyncUIConstruction = 0.002;
  14409. UIConfig.linkUnderline = true;
  14410. UIConfig.defaultUIGroup = "UI";
  14411. return UIConfig;
  14412. }());
  14413. fgui.UIConfig = UIConfig;
  14414. function addLoadHandler(ext) {
  14415. }
  14416. fgui.addLoadHandler = addLoadHandler;
  14417. ;
  14418. var _fontRegistry = {};
  14419. function registerFont(name, font) {
  14420. if (font instanceof cc.Font)
  14421. _fontRegistry[name] = font;
  14422. else
  14423. _fontRegistry[name] = cc.loader.getRes(name, cc.Font);
  14424. }
  14425. fgui.registerFont = registerFont;
  14426. ;
  14427. function getFontByName(name) {
  14428. return _fontRegistry[name];
  14429. }
  14430. fgui.getFontByName = getFontByName;
  14431. })(fgui || (fgui = {}));
  14432. (function (fgui) {
  14433. var UIObjectFactory = (function () {
  14434. function UIObjectFactory() {
  14435. }
  14436. UIObjectFactory.setExtension = function (url, type) {
  14437. if (url == null)
  14438. throw new Error("Invaild url: " + url);
  14439. var pi = fgui.UIPackage.getItemByURL(url);
  14440. if (pi)
  14441. pi.extensionType = type;
  14442. UIObjectFactory.extensions[url] = type;
  14443. };
  14444. UIObjectFactory.setLoaderExtension = function (type) {
  14445. UIObjectFactory.loaderType = type;
  14446. };
  14447. UIObjectFactory.resolveExtension = function (pi) {
  14448. var extensionType = UIObjectFactory.extensions["ui://" + pi.owner.id + pi.id];
  14449. if (!extensionType)
  14450. extensionType = UIObjectFactory.extensions["ui://" + pi.owner.name + "/" + pi.name];
  14451. if (extensionType)
  14452. pi.extensionType = extensionType;
  14453. };
  14454. UIObjectFactory.newObject = function (type, userClass) {
  14455. var obj;
  14456. UIObjectFactory.counter++;
  14457. if (typeof type === 'number') {
  14458. switch (type) {
  14459. case fgui.ObjectType.Image:
  14460. return new fgui.GImage();
  14461. case fgui.ObjectType.MovieClip:
  14462. return new fgui.GMovieClip();
  14463. case fgui.ObjectType.Component:
  14464. return new fgui.GComponent();
  14465. case fgui.ObjectType.Text:
  14466. return new fgui.GTextField();
  14467. case fgui.ObjectType.RichText:
  14468. return new fgui.GRichTextField();
  14469. case fgui.ObjectType.InputText:
  14470. return new fgui.GTextInput();
  14471. case fgui.ObjectType.Group:
  14472. return new fgui.GGroup();
  14473. case fgui.ObjectType.List:
  14474. return new fgui.GList();
  14475. case fgui.ObjectType.Graph:
  14476. return new fgui.GGraph();
  14477. case fgui.ObjectType.Loader:
  14478. if (UIObjectFactory.loaderType)
  14479. return new UIObjectFactory.loaderType();
  14480. else
  14481. return new fgui.GLoader();
  14482. case fgui.ObjectType.Button:
  14483. return new fgui.GButton();
  14484. case fgui.ObjectType.Label:
  14485. return new fgui.GLabel();
  14486. case fgui.ObjectType.ProgressBar:
  14487. return new fgui.GProgressBar();
  14488. case fgui.ObjectType.Slider:
  14489. return new fgui.GSlider();
  14490. case fgui.ObjectType.ScrollBar:
  14491. return new fgui.GScrollBar();
  14492. case fgui.ObjectType.ComboBox:
  14493. return new fgui.GComboBox();
  14494. case fgui.ObjectType.Tree:
  14495. return new fgui.GTree();
  14496. case fgui.ObjectType.Loader3D:
  14497. return new fgui.GLoader3D();
  14498. default:
  14499. return null;
  14500. }
  14501. }
  14502. else {
  14503. if (type.type == fgui.PackageItemType.Component) {
  14504. if (userClass)
  14505. obj = new userClass();
  14506. else if (type.extensionType)
  14507. obj = new type.extensionType();
  14508. else
  14509. obj = UIObjectFactory.newObject(type.objectType);
  14510. }
  14511. else
  14512. obj = UIObjectFactory.newObject(type.objectType);
  14513. if (obj)
  14514. obj.packageItem = type;
  14515. }
  14516. return obj;
  14517. };
  14518. UIObjectFactory.counter = 0;
  14519. UIObjectFactory.extensions = {};
  14520. return UIObjectFactory;
  14521. }());
  14522. fgui.UIObjectFactory = UIObjectFactory;
  14523. })(fgui || (fgui = {}));
  14524. (function (fgui) {
  14525. var _a;
  14526. var UIPackage = (function () {
  14527. function UIPackage() {
  14528. this._items = [];
  14529. this._itemsById = {};
  14530. this._itemsByName = {};
  14531. this._sprites = {};
  14532. this._dependencies = [];
  14533. this._branches = [];
  14534. this._branchIndex = -1;
  14535. }
  14536. Object.defineProperty(UIPackage, "branch", {
  14537. get: function () {
  14538. return UIPackage._branch;
  14539. },
  14540. set: function (value) {
  14541. UIPackage._branch = value;
  14542. for (var pkgId in UIPackage._instById) {
  14543. var pkg = UIPackage._instById[pkgId];
  14544. if (pkg._branches) {
  14545. pkg._branchIndex = pkg._branches.indexOf(value);
  14546. }
  14547. }
  14548. },
  14549. enumerable: false,
  14550. configurable: true
  14551. });
  14552. UIPackage.getVar = function (key) {
  14553. return UIPackage._vars[key];
  14554. };
  14555. UIPackage.setVar = function (key, value) {
  14556. UIPackage._vars[key] = value;
  14557. };
  14558. UIPackage.getById = function (id) {
  14559. return UIPackage._instById[id];
  14560. };
  14561. UIPackage.getByName = function (name) {
  14562. return UIPackage._instByName[name];
  14563. };
  14564. UIPackage.addPackage = function (path) {
  14565. var pkg = UIPackage._instById[path];
  14566. if (pkg)
  14567. return pkg;
  14568. var asset = cc.resources.get(path, cc.BufferAsset);
  14569. if (!asset)
  14570. throw "Resource '" + path + "' not ready";
  14571. if (!asset._buffer)
  14572. throw "Missing asset data.";
  14573. pkg = new UIPackage();
  14574. pkg._bundle = cc.resources;
  14575. pkg.loadPackage(new fgui.ByteBuffer(asset._buffer), path);
  14576. UIPackage._instById[pkg.id] = pkg;
  14577. UIPackage._instByName[pkg.name] = pkg;
  14578. UIPackage._instById[pkg._path] = pkg;
  14579. return pkg;
  14580. };
  14581. UIPackage.loadPackage = function () {
  14582. var args = [];
  14583. for (var _i = 0; _i < arguments.length; _i++) {
  14584. args[_i] = arguments[_i];
  14585. }
  14586. var path;
  14587. var onProgress;
  14588. var onComplete;
  14589. var bundle;
  14590. if (args[0] instanceof cc.AssetManager.Bundle) {
  14591. bundle = args[0];
  14592. path = args[1];
  14593. if (args.length > 3) {
  14594. onProgress = args[2];
  14595. onComplete = args[3];
  14596. }
  14597. else
  14598. onComplete = args[2];
  14599. }
  14600. else {
  14601. path = args[0];
  14602. if (args.length > 2) {
  14603. onProgress = args[1];
  14604. onComplete = args[2];
  14605. }
  14606. else
  14607. onComplete = args[1];
  14608. }
  14609. bundle = bundle || cc.resources;
  14610. bundle.load(path, cc.BufferAsset, onProgress, function (err, asset) {
  14611. if (err) {
  14612. if (onComplete != null)
  14613. onComplete(err, null);
  14614. return;
  14615. }
  14616. var pkg = new UIPackage();
  14617. pkg._bundle = bundle;
  14618. pkg.loadPackage(new fgui.ByteBuffer(asset._buffer), path);
  14619. var cnt = pkg._items.length;
  14620. var urls = [];
  14621. var types = [];
  14622. for (var i = 0; i < cnt; i++) {
  14623. var pi = pkg._items[i];
  14624. if (pi.type == fgui.PackageItemType.Atlas || pi.type == fgui.PackageItemType.Sound) {
  14625. var assetType = ItemTypeToAssetType[pi.type];
  14626. urls.push(pi.file);
  14627. types.push(assetType);
  14628. }
  14629. }
  14630. var total = urls.length;
  14631. var lastErr;
  14632. var taskComplete = function (err) {
  14633. total--;
  14634. if (err)
  14635. lastErr = err;
  14636. if (total <= 0) {
  14637. UIPackage._instById[pkg.id] = pkg;
  14638. UIPackage._instByName[pkg.name] = pkg;
  14639. if (pkg._path)
  14640. UIPackage._instById[pkg._path] = pkg;
  14641. if (onComplete != null)
  14642. onComplete(lastErr, pkg);
  14643. }
  14644. };
  14645. if (total > 0) {
  14646. urls.forEach(function (url, index) {
  14647. bundle.load(url, types[index], onProgress, taskComplete);
  14648. });
  14649. }
  14650. else
  14651. taskComplete();
  14652. });
  14653. };
  14654. UIPackage.removePackage = function (packageIdOrName) {
  14655. var pkg = UIPackage._instById[packageIdOrName];
  14656. if (!pkg)
  14657. pkg = UIPackage._instByName[packageIdOrName];
  14658. if (!pkg)
  14659. throw "No package found: " + packageIdOrName;
  14660. pkg.dispose();
  14661. delete UIPackage._instById[pkg.id];
  14662. delete UIPackage._instByName[pkg.name];
  14663. if (pkg._path)
  14664. delete UIPackage._instById[pkg._path];
  14665. };
  14666. UIPackage.createObject = function (pkgName, resName, userClass) {
  14667. var pkg = UIPackage.getByName(pkgName);
  14668. if (pkg)
  14669. return pkg.createObject(resName, userClass);
  14670. else
  14671. return null;
  14672. };
  14673. UIPackage.createObjectFromURL = function (url, userClass) {
  14674. var pi = UIPackage.getItemByURL(url);
  14675. if (pi)
  14676. return pi.owner.internalCreateObject(pi, userClass);
  14677. else
  14678. return null;
  14679. };
  14680. UIPackage.getItemURL = function (pkgName, resName) {
  14681. var pkg = UIPackage.getByName(pkgName);
  14682. if (!pkg)
  14683. return null;
  14684. var pi = pkg._itemsByName[resName];
  14685. if (!pi)
  14686. return null;
  14687. return "ui://" + pkg.id + pi.id;
  14688. };
  14689. UIPackage.getItemByURL = function (url) {
  14690. var pos1 = url.indexOf("//");
  14691. if (pos1 == -1)
  14692. return null;
  14693. var pos2 = url.indexOf("/", pos1 + 2);
  14694. if (pos2 == -1) {
  14695. if (url.length > 13) {
  14696. var pkgId = url.substr(5, 8);
  14697. var pkg = UIPackage.getById(pkgId);
  14698. if (pkg != null) {
  14699. var srcId = url.substr(13);
  14700. return pkg.getItemById(srcId);
  14701. }
  14702. }
  14703. }
  14704. else {
  14705. var pkgName = url.substr(pos1 + 2, pos2 - pos1 - 2);
  14706. pkg = UIPackage.getByName(pkgName);
  14707. if (pkg != null) {
  14708. var srcName = url.substr(pos2 + 1);
  14709. return pkg.getItemByName(srcName);
  14710. }
  14711. }
  14712. return null;
  14713. };
  14714. UIPackage.normalizeURL = function (url) {
  14715. if (url == null)
  14716. return null;
  14717. var pos1 = url.indexOf("//");
  14718. if (pos1 == -1)
  14719. return null;
  14720. var pos2 = url.indexOf("/", pos1 + 2);
  14721. if (pos2 == -1)
  14722. return url;
  14723. var pkgName = url.substr(pos1 + 2, pos2 - pos1 - 2);
  14724. var srcName = url.substr(pos2 + 1);
  14725. return UIPackage.getItemURL(pkgName, srcName);
  14726. };
  14727. UIPackage.setStringsSource = function (source) {
  14728. fgui.TranslationHelper.loadFromXML(source);
  14729. };
  14730. UIPackage.prototype.loadPackage = function (buffer, path) {
  14731. if (buffer.readUint() != 0x46475549)
  14732. throw "FairyGUI: old package format found in '" + path + "'";
  14733. this._path = path;
  14734. buffer.version = buffer.readInt();
  14735. var ver2 = buffer.version >= 2;
  14736. var compressed = buffer.readBool();
  14737. this._id = buffer.readString();
  14738. this._name = buffer.readString();
  14739. buffer.skip(20);
  14740. var indexTablePos = buffer.position;
  14741. var cnt;
  14742. var i;
  14743. var nextPos;
  14744. var str;
  14745. var branchIncluded;
  14746. buffer.seek(indexTablePos, 4);
  14747. cnt = buffer.readInt();
  14748. var stringTable = new Array(cnt);
  14749. buffer.stringTable = stringTable;
  14750. for (i = 0; i < cnt; i++)
  14751. stringTable[i] = buffer.readString();
  14752. if (buffer.seek(indexTablePos, 5)) {
  14753. cnt = buffer.readInt();
  14754. for (i = 0; i < cnt; i++) {
  14755. var index = buffer.readUshort();
  14756. var len = buffer.readInt();
  14757. stringTable[index] = buffer.readString(len);
  14758. }
  14759. }
  14760. buffer.seek(indexTablePos, 0);
  14761. cnt = buffer.readShort();
  14762. for (i = 0; i < cnt; i++)
  14763. this._dependencies.push({ id: buffer.readS(), name: buffer.readS() });
  14764. if (ver2) {
  14765. cnt = buffer.readShort();
  14766. if (cnt > 0) {
  14767. this._branches = buffer.readSArray(cnt);
  14768. if (UIPackage._branch)
  14769. this._branchIndex = this._branches.indexOf(UIPackage._branch);
  14770. }
  14771. branchIncluded = cnt > 0;
  14772. }
  14773. buffer.seek(indexTablePos, 1);
  14774. var pi;
  14775. var pos = path.lastIndexOf('/');
  14776. var shortPath = pos == -1 ? "" : path.substr(0, pos + 1);
  14777. path = path + "_";
  14778. cnt = buffer.readShort();
  14779. for (i = 0; i < cnt; i++) {
  14780. nextPos = buffer.readInt();
  14781. nextPos += buffer.position;
  14782. pi = new fgui.PackageItem();
  14783. pi.owner = this;
  14784. pi.type = buffer.readByte();
  14785. pi.id = buffer.readS();
  14786. pi.name = buffer.readS();
  14787. buffer.readS();
  14788. pi.file = buffer.readS();
  14789. buffer.readBool();
  14790. pi.width = buffer.readInt();
  14791. pi.height = buffer.readInt();
  14792. switch (pi.type) {
  14793. case fgui.PackageItemType.Image:
  14794. {
  14795. pi.objectType = fgui.ObjectType.Image;
  14796. var scaleOption = buffer.readByte();
  14797. if (scaleOption == 1) {
  14798. pi.scale9Grid = new cc.Rect();
  14799. pi.scale9Grid.x = buffer.readInt();
  14800. pi.scale9Grid.y = buffer.readInt();
  14801. pi.scale9Grid.width = buffer.readInt();
  14802. pi.scale9Grid.height = buffer.readInt();
  14803. pi.tileGridIndice = buffer.readInt();
  14804. }
  14805. else if (scaleOption == 2)
  14806. pi.scaleByTile = true;
  14807. pi.smoothing = buffer.readBool();
  14808. break;
  14809. }
  14810. case fgui.PackageItemType.MovieClip:
  14811. {
  14812. pi.smoothing = buffer.readBool();
  14813. pi.objectType = fgui.ObjectType.MovieClip;
  14814. pi.rawData = buffer.readBuffer();
  14815. break;
  14816. }
  14817. case fgui.PackageItemType.Font:
  14818. {
  14819. pi.rawData = buffer.readBuffer();
  14820. break;
  14821. }
  14822. case fgui.PackageItemType.Component:
  14823. {
  14824. var extension = buffer.readByte();
  14825. if (extension > 0)
  14826. pi.objectType = extension;
  14827. else
  14828. pi.objectType = fgui.ObjectType.Component;
  14829. pi.rawData = buffer.readBuffer();
  14830. fgui.UIObjectFactory.resolveExtension(pi);
  14831. break;
  14832. }
  14833. case fgui.PackageItemType.Atlas:
  14834. case fgui.PackageItemType.Sound:
  14835. case fgui.PackageItemType.Misc:
  14836. {
  14837. pi.file = path + cc.path.mainFileName(pi.file);
  14838. break;
  14839. }
  14840. case fgui.PackageItemType.Spine:
  14841. case fgui.PackageItemType.DragonBones:
  14842. {
  14843. pi.file = shortPath + cc.path.mainFileName(pi.file);
  14844. pi.skeletonAnchor = new cc.Vec2();
  14845. pi.skeletonAnchor.x = buffer.readFloat();
  14846. pi.skeletonAnchor.y = buffer.readFloat();
  14847. break;
  14848. }
  14849. }
  14850. if (ver2) {
  14851. str = buffer.readS();
  14852. if (str)
  14853. pi.name = str + "/" + pi.name;
  14854. var branchCnt = buffer.readUbyte();
  14855. if (branchCnt > 0) {
  14856. if (branchIncluded)
  14857. pi.branches = buffer.readSArray(branchCnt);
  14858. else
  14859. this._itemsById[buffer.readS()] = pi;
  14860. }
  14861. var highResCnt = buffer.readUbyte();
  14862. if (highResCnt > 0)
  14863. pi.highResolution = buffer.readSArray(highResCnt);
  14864. }
  14865. this._items.push(pi);
  14866. this._itemsById[pi.id] = pi;
  14867. if (pi.name != null)
  14868. this._itemsByName[pi.name] = pi;
  14869. buffer.position = nextPos;
  14870. }
  14871. buffer.seek(indexTablePos, 2);
  14872. cnt = buffer.readShort();
  14873. for (i = 0; i < cnt; i++) {
  14874. nextPos = buffer.readShort();
  14875. nextPos += buffer.position;
  14876. var itemId = buffer.readS();
  14877. pi = this._itemsById[buffer.readS()];
  14878. var rect = new cc.Rect();
  14879. rect.x = buffer.readInt();
  14880. rect.y = buffer.readInt();
  14881. rect.width = buffer.readInt();
  14882. rect.height = buffer.readInt();
  14883. var sprite = { atlas: pi, rect: rect, offset: new cc.Vec2(), originalSize: new cc.Size(0, 0) };
  14884. sprite.rotated = buffer.readBool();
  14885. if (ver2 && buffer.readBool()) {
  14886. sprite.offset.x = buffer.readInt();
  14887. sprite.offset.y = buffer.readInt();
  14888. sprite.originalSize.width = buffer.readInt();
  14889. sprite.originalSize.height = buffer.readInt();
  14890. }
  14891. else {
  14892. sprite.originalSize.width = sprite.rect.width;
  14893. sprite.originalSize.height = sprite.rect.height;
  14894. }
  14895. this._sprites[itemId] = sprite;
  14896. buffer.position = nextPos;
  14897. }
  14898. if (buffer.seek(indexTablePos, 3)) {
  14899. cnt = buffer.readShort();
  14900. for (i = 0; i < cnt; i++) {
  14901. nextPos = buffer.readInt();
  14902. nextPos += buffer.position;
  14903. pi = this._itemsById[buffer.readS()];
  14904. if (pi && pi.type == fgui.PackageItemType.Image)
  14905. pi.hitTestData = new fgui.PixelHitTestData(buffer);
  14906. buffer.position = nextPos;
  14907. }
  14908. }
  14909. };
  14910. UIPackage.prototype.dispose = function () {
  14911. var cnt = this._items.length;
  14912. for (var i = 0; i < cnt; i++) {
  14913. var pi = this._items[i];
  14914. if (pi.asset)
  14915. cc.assetManager.releaseAsset(pi.asset);
  14916. }
  14917. };
  14918. Object.defineProperty(UIPackage.prototype, "id", {
  14919. get: function () {
  14920. return this._id;
  14921. },
  14922. enumerable: false,
  14923. configurable: true
  14924. });
  14925. Object.defineProperty(UIPackage.prototype, "name", {
  14926. get: function () {
  14927. return this._name;
  14928. },
  14929. enumerable: false,
  14930. configurable: true
  14931. });
  14932. Object.defineProperty(UIPackage.prototype, "path", {
  14933. get: function () {
  14934. return this._path;
  14935. },
  14936. enumerable: false,
  14937. configurable: true
  14938. });
  14939. Object.defineProperty(UIPackage.prototype, "dependencies", {
  14940. get: function () {
  14941. return this._dependencies;
  14942. },
  14943. enumerable: false,
  14944. configurable: true
  14945. });
  14946. UIPackage.prototype.createObject = function (resName, userClass) {
  14947. var pi = this._itemsByName[resName];
  14948. if (pi)
  14949. return this.internalCreateObject(pi, userClass);
  14950. else
  14951. return null;
  14952. };
  14953. UIPackage.prototype.internalCreateObject = function (item, userClass) {
  14954. var g = fgui.UIObjectFactory.newObject(item, userClass);
  14955. if (g == null)
  14956. return null;
  14957. UIPackage._constructing++;
  14958. g.constructFromResource();
  14959. UIPackage._constructing--;
  14960. return g;
  14961. };
  14962. UIPackage.prototype.getItemById = function (itemId) {
  14963. return this._itemsById[itemId];
  14964. };
  14965. UIPackage.prototype.getItemByName = function (resName) {
  14966. return this._itemsByName[resName];
  14967. };
  14968. UIPackage.prototype.getItemAssetByName = function (resName) {
  14969. var pi = this._itemsByName[resName];
  14970. if (pi == null) {
  14971. throw "Resource not found -" + resName;
  14972. }
  14973. return this.getItemAsset(pi);
  14974. };
  14975. UIPackage.prototype.getItemAsset = function (item) {
  14976. switch (item.type) {
  14977. case fgui.PackageItemType.Image:
  14978. if (!item.decoded) {
  14979. item.decoded = true;
  14980. var sprite = this._sprites[item.id];
  14981. if (sprite) {
  14982. var atlasTexture = this.getItemAsset(sprite.atlas);
  14983. if (atlasTexture) {
  14984. var sf = new cc.SpriteFrame(atlasTexture, sprite.rect, sprite.rotated, new cc.Vec2(sprite.offset.x - (sprite.originalSize.width - sprite.rect.width) / 2, -(sprite.offset.y - (sprite.originalSize.height - sprite.rect.height) / 2)), sprite.originalSize);
  14985. if (item.scale9Grid) {
  14986. sf.insetLeft = item.scale9Grid.x;
  14987. sf.insetTop = item.scale9Grid.y;
  14988. sf.insetRight = item.width - item.scale9Grid.xMax;
  14989. sf.insetBottom = item.height - item.scale9Grid.yMax;
  14990. }
  14991. item.asset = sf;
  14992. }
  14993. }
  14994. }
  14995. break;
  14996. case fgui.PackageItemType.Atlas:
  14997. case fgui.PackageItemType.Sound:
  14998. if (!item.decoded) {
  14999. item.decoded = true;
  15000. item.asset = this._bundle.get(item.file, ItemTypeToAssetType[item.type]);
  15001. if (!item.asset)
  15002. console.log("Resource '" + item.file + "' not found");
  15003. }
  15004. break;
  15005. case fgui.PackageItemType.Font:
  15006. if (!item.decoded) {
  15007. item.decoded = true;
  15008. this.loadFont(item);
  15009. }
  15010. break;
  15011. case fgui.PackageItemType.MovieClip:
  15012. if (!item.decoded) {
  15013. item.decoded = true;
  15014. this.loadMovieClip(item);
  15015. }
  15016. break;
  15017. default:
  15018. break;
  15019. }
  15020. return item.asset;
  15021. };
  15022. UIPackage.prototype.getItemAssetAsync = function (item, onComplete) {
  15023. if (item.decoded) {
  15024. onComplete(null, item);
  15025. return;
  15026. }
  15027. if (item.loading) {
  15028. item.loading.push(onComplete);
  15029. return;
  15030. }
  15031. switch (item.type) {
  15032. case fgui.PackageItemType.Spine:
  15033. item.loading = [onComplete];
  15034. this.loadSpine(item);
  15035. break;
  15036. case fgui.PackageItemType.DragonBones:
  15037. item.loading = [onComplete];
  15038. this.loadDragonBones(item);
  15039. break;
  15040. default:
  15041. this.getItemAsset(item);
  15042. onComplete(null, item);
  15043. break;
  15044. }
  15045. };
  15046. UIPackage.prototype.loadAllAssets = function () {
  15047. var cnt = this._items.length;
  15048. for (var i = 0; i < cnt; i++) {
  15049. var pi = this._items[i];
  15050. this.getItemAsset(pi);
  15051. }
  15052. };
  15053. UIPackage.prototype.loadMovieClip = function (item) {
  15054. var buffer = item.rawData;
  15055. buffer.seek(0, 0);
  15056. item.interval = buffer.readInt() / 1000;
  15057. item.swing = buffer.readBool();
  15058. item.repeatDelay = buffer.readInt() / 1000;
  15059. buffer.seek(0, 1);
  15060. var frameCount = buffer.readShort();
  15061. item.frames = Array(frameCount);
  15062. var spriteId;
  15063. var sprite;
  15064. for (var i = 0; i < frameCount; i++) {
  15065. var nextPos = buffer.readShort();
  15066. nextPos += buffer.position;
  15067. var rect = new cc.Rect();
  15068. rect.x = buffer.readInt();
  15069. rect.y = buffer.readInt();
  15070. rect.width = buffer.readInt();
  15071. rect.height = buffer.readInt();
  15072. var addDelay = buffer.readInt() / 1000;
  15073. var frame = { rect: rect, addDelay: addDelay };
  15074. spriteId = buffer.readS();
  15075. if (spriteId != null && (sprite = this._sprites[spriteId]) != null) {
  15076. var atlasTexture = this.getItemAsset(sprite.atlas);
  15077. if (atlasTexture) {
  15078. var sx = item.width / frame.rect.width;
  15079. frame.texture = new cc.SpriteFrame(atlasTexture, sprite.rect, sprite.rotated, new cc.Vec2(frame.rect.x - (item.width - frame.rect.width) / 2, -(frame.rect.y - (item.height - frame.rect.height) / 2)), new cc.Size(item.width, item.height));
  15080. }
  15081. }
  15082. item.frames[i] = frame;
  15083. buffer.position = nextPos;
  15084. }
  15085. };
  15086. UIPackage.prototype.loadFont = function (item) {
  15087. var font = new cc.LabelAtlas();
  15088. item.asset = font;
  15089. font._fntConfig = {
  15090. commonHeight: 0,
  15091. fontSize: 0,
  15092. kerningDict: {},
  15093. fontDefDictionary: {}
  15094. };
  15095. var dict = font._fntConfig.fontDefDictionary;
  15096. var buffer = item.rawData;
  15097. buffer.seek(0, 0);
  15098. var ttf = buffer.readBool();
  15099. var canTint = buffer.readBool();
  15100. var resizable = buffer.readBool();
  15101. buffer.readBool();
  15102. var fontSize = buffer.readInt();
  15103. var xadvance = buffer.readInt();
  15104. var lineHeight = buffer.readInt();
  15105. var mainTexture;
  15106. var mainSprite = this._sprites[item.id];
  15107. if (mainSprite)
  15108. mainTexture = (this.getItemAsset(mainSprite.atlas));
  15109. buffer.seek(0, 1);
  15110. var bg;
  15111. var cnt = buffer.readInt();
  15112. for (var i = 0; i < cnt; i++) {
  15113. var nextPos = buffer.readShort();
  15114. nextPos += buffer.position;
  15115. bg = {};
  15116. var ch = buffer.readUshort();
  15117. dict[ch] = bg;
  15118. var rect = new cc.Rect();
  15119. bg.rect = rect;
  15120. var img = buffer.readS();
  15121. rect.x = buffer.readInt();
  15122. rect.y = buffer.readInt();
  15123. bg.xOffset = buffer.readInt();
  15124. bg.yOffset = buffer.readInt();
  15125. rect.width = buffer.readInt();
  15126. rect.height = buffer.readInt();
  15127. bg.xAdvance = buffer.readInt();
  15128. bg.channel = buffer.readByte();
  15129. if (bg.channel == 1)
  15130. bg.channel = 3;
  15131. else if (bg.channel == 2)
  15132. bg.channel = 2;
  15133. else if (bg.channel == 3)
  15134. bg.channel = 1;
  15135. if (ttf) {
  15136. rect.x += mainSprite.rect.x;
  15137. rect.y += mainSprite.rect.y;
  15138. }
  15139. else {
  15140. var sprite = this._sprites[img];
  15141. if (sprite) {
  15142. rect.set(sprite.rect);
  15143. bg.xOffset += sprite.offset.x;
  15144. bg.yOffset += sprite.offset.y;
  15145. if (fontSize == 0)
  15146. fontSize = sprite.originalSize.height;
  15147. if (!mainTexture) {
  15148. sprite.atlas.load();
  15149. mainTexture = sprite.atlas.asset;
  15150. }
  15151. }
  15152. if (bg.xAdvance == 0) {
  15153. if (xadvance == 0)
  15154. bg.xAdvance = bg.xOffset + bg.rect.width;
  15155. else
  15156. bg.xAdvance = xadvance;
  15157. }
  15158. }
  15159. buffer.position = nextPos;
  15160. }
  15161. font.fontSize = fontSize;
  15162. font._fntConfig.fontSize = fontSize;
  15163. font._fntConfig.commonHeight = lineHeight == 0 ? fontSize : lineHeight;
  15164. font._fntConfig.resizable = resizable;
  15165. font._fntConfig.canTint = canTint;
  15166. var spriteFrame = new cc.SpriteFrame();
  15167. spriteFrame.setTexture(mainTexture);
  15168. font.spriteFrame = spriteFrame;
  15169. font.onLoad();
  15170. };
  15171. UIPackage.prototype.loadSpine = function (item) {
  15172. this._bundle.load(item.file, sp.SkeletonData, function (err, asset) {
  15173. item.decoded = true;
  15174. item.asset = asset;
  15175. var arr = item.loading;
  15176. delete item.loading;
  15177. arr.forEach(function (e) { return e(err, item); });
  15178. });
  15179. };
  15180. UIPackage.prototype.loadDragonBones = function (item) {
  15181. var _this = this;
  15182. this._bundle.load(item.file, dragonBones.DragonBonesAsset, function (err, asset) {
  15183. if (err) {
  15184. item.decoded = true;
  15185. var arr = item.loading;
  15186. delete item.loading;
  15187. arr.forEach(function (e) { return e(err, item); });
  15188. return;
  15189. }
  15190. item.asset = asset;
  15191. var atlasFile = item.file.replace("_ske", "_tex");
  15192. var pos = atlasFile.lastIndexOf('.');
  15193. if (pos != -1)
  15194. atlasFile = atlasFile.substr(0, pos + 1) + "json";
  15195. _this._bundle.load(atlasFile, dragonBones.DragonBonesAtlasAsset, function (err, asset) {
  15196. item.decoded = true;
  15197. item.atlasAsset = asset;
  15198. var arr = item.loading;
  15199. delete item.loading;
  15200. arr.forEach(function (e) { return e(err, item); });
  15201. });
  15202. });
  15203. };
  15204. UIPackage._constructing = 0;
  15205. UIPackage._instById = {};
  15206. UIPackage._instByName = {};
  15207. UIPackage._branch = "";
  15208. UIPackage._vars = {};
  15209. return UIPackage;
  15210. }());
  15211. fgui.UIPackage = UIPackage;
  15212. var ItemTypeToAssetType = (_a = {},
  15213. _a[fgui.PackageItemType.Atlas] = cc.Texture2D,
  15214. _a[fgui.PackageItemType.Sound] = cc.AudioClip,
  15215. _a);
  15216. })(fgui || (fgui = {}));
  15217. (function (fgui) {
  15218. var Window = (function (_super) {
  15219. __extends(Window, _super);
  15220. function Window() {
  15221. var _this = _super.call(this) || this;
  15222. _this._requestingCmd = 0;
  15223. _this._uiSources = new Array();
  15224. _this.bringToFontOnClick = fgui.UIConfig.bringWindowToFrontOnClick;
  15225. _this._node.on(fgui.Event.TOUCH_BEGIN, _this.onTouchBegin_1, _this, true);
  15226. return _this;
  15227. }
  15228. Window.prototype.addUISource = function (source) {
  15229. this._uiSources.push(source);
  15230. };
  15231. Object.defineProperty(Window.prototype, "contentPane", {
  15232. get: function () {
  15233. return this._contentPane;
  15234. },
  15235. set: function (val) {
  15236. if (this._contentPane != val) {
  15237. if (this._contentPane)
  15238. this.removeChild(this._contentPane);
  15239. this._contentPane = val;
  15240. if (this._contentPane) {
  15241. this.addChild(this._contentPane);
  15242. this.setSize(this._contentPane.width, this._contentPane.height);
  15243. this._contentPane.addRelation(this, fgui.RelationType.Size);
  15244. this._frame = (this._contentPane.getChild("frame"));
  15245. if (this._frame) {
  15246. this.closeButton = this._frame.getChild("closeButton");
  15247. this.dragArea = this._frame.getChild("dragArea");
  15248. this.contentArea = this._frame.getChild("contentArea");
  15249. }
  15250. }
  15251. }
  15252. },
  15253. enumerable: false,
  15254. configurable: true
  15255. });
  15256. Object.defineProperty(Window.prototype, "frame", {
  15257. get: function () {
  15258. return this._frame;
  15259. },
  15260. enumerable: false,
  15261. configurable: true
  15262. });
  15263. Object.defineProperty(Window.prototype, "closeButton", {
  15264. get: function () {
  15265. return this._closeButton;
  15266. },
  15267. set: function (value) {
  15268. if (this._closeButton)
  15269. this._closeButton.offClick(this.closeEventHandler, this);
  15270. this._closeButton = value;
  15271. if (this._closeButton)
  15272. this._closeButton.onClick(this.closeEventHandler, this);
  15273. },
  15274. enumerable: false,
  15275. configurable: true
  15276. });
  15277. Object.defineProperty(Window.prototype, "dragArea", {
  15278. get: function () {
  15279. return this._dragArea;
  15280. },
  15281. set: function (value) {
  15282. if (this._dragArea != value) {
  15283. if (this._dragArea) {
  15284. this._dragArea.draggable = false;
  15285. this._dragArea.off(fgui.Event.DRAG_START, this.onDragStart_1, this);
  15286. }
  15287. this._dragArea = value;
  15288. if (this._dragArea) {
  15289. this._dragArea.draggable = true;
  15290. this._dragArea.on(fgui.Event.DRAG_START, this.onDragStart_1, this);
  15291. }
  15292. }
  15293. },
  15294. enumerable: false,
  15295. configurable: true
  15296. });
  15297. Object.defineProperty(Window.prototype, "contentArea", {
  15298. get: function () {
  15299. return this._contentArea;
  15300. },
  15301. set: function (value) {
  15302. this._contentArea = value;
  15303. },
  15304. enumerable: false,
  15305. configurable: true
  15306. });
  15307. Window.prototype.show = function () {
  15308. fgui.GRoot.inst.showWindow(this);
  15309. };
  15310. Window.prototype.showOn = function (root) {
  15311. root.showWindow(this);
  15312. };
  15313. Window.prototype.hide = function () {
  15314. if (this.isShowing)
  15315. this.doHideAnimation();
  15316. };
  15317. Window.prototype.hideImmediately = function () {
  15318. var r = (this.parent instanceof fgui.GRoot) ? this.parent : null;
  15319. if (!r)
  15320. r = fgui.GRoot.inst;
  15321. r.hideWindowImmediately(this);
  15322. };
  15323. Window.prototype.centerOn = function (r, restraint) {
  15324. this.setPosition(Math.round((r.width - this.width) / 2), Math.round((r.height - this.height) / 2));
  15325. if (restraint) {
  15326. this.addRelation(r, fgui.RelationType.Center_Center);
  15327. this.addRelation(r, fgui.RelationType.Middle_Middle);
  15328. }
  15329. };
  15330. Window.prototype.toggleStatus = function () {
  15331. if (this.isTop)
  15332. this.hide();
  15333. else
  15334. this.show();
  15335. };
  15336. Object.defineProperty(Window.prototype, "isShowing", {
  15337. get: function () {
  15338. return this.parent != null;
  15339. },
  15340. enumerable: false,
  15341. configurable: true
  15342. });
  15343. Object.defineProperty(Window.prototype, "isTop", {
  15344. get: function () {
  15345. return this.parent && this.parent.getChildIndex(this) == this.parent.numChildren - 1;
  15346. },
  15347. enumerable: false,
  15348. configurable: true
  15349. });
  15350. Object.defineProperty(Window.prototype, "modal", {
  15351. get: function () {
  15352. return this._modal;
  15353. },
  15354. set: function (val) {
  15355. this._modal = val;
  15356. },
  15357. enumerable: false,
  15358. configurable: true
  15359. });
  15360. Window.prototype.bringToFront = function () {
  15361. this.root.bringToFront(this);
  15362. };
  15363. Window.prototype.showModalWait = function (requestingCmd) {
  15364. if (requestingCmd != null)
  15365. this._requestingCmd = requestingCmd;
  15366. if (fgui.UIConfig.windowModalWaiting) {
  15367. if (!this._modalWaitPane)
  15368. this._modalWaitPane = fgui.UIPackage.createObjectFromURL(fgui.UIConfig.windowModalWaiting);
  15369. this.layoutModalWaitPane();
  15370. this.addChild(this._modalWaitPane);
  15371. }
  15372. };
  15373. Window.prototype.layoutModalWaitPane = function () {
  15374. if (this._contentArea) {
  15375. var pt = this._frame.localToGlobal();
  15376. pt = this.globalToLocal(pt.x, pt.y, pt);
  15377. this._modalWaitPane.setPosition(pt.x + this._contentArea.x, pt.y + this._contentArea.y);
  15378. this._modalWaitPane.setSize(this._contentArea.width, this._contentArea.height);
  15379. }
  15380. else
  15381. this._modalWaitPane.setSize(this.width, this.height);
  15382. };
  15383. Window.prototype.closeModalWait = function (requestingCmd) {
  15384. if (requestingCmd != null) {
  15385. if (this._requestingCmd != requestingCmd)
  15386. return false;
  15387. }
  15388. this._requestingCmd = 0;
  15389. if (this._modalWaitPane && this._modalWaitPane.parent)
  15390. this.removeChild(this._modalWaitPane);
  15391. return true;
  15392. };
  15393. Object.defineProperty(Window.prototype, "modalWaiting", {
  15394. get: function () {
  15395. return this._modalWaitPane && this._modalWaitPane.parent != null;
  15396. },
  15397. enumerable: false,
  15398. configurable: true
  15399. });
  15400. Window.prototype.init = function () {
  15401. if (this._inited || this._loading)
  15402. return;
  15403. if (this._uiSources.length > 0) {
  15404. this._loading = false;
  15405. var cnt = this._uiSources.length;
  15406. for (var i = 0; i < cnt; i++) {
  15407. var lib = this._uiSources[i];
  15408. if (!lib.loaded) {
  15409. lib.load(this.__uiLoadComplete, this);
  15410. this._loading = true;
  15411. }
  15412. }
  15413. if (!this._loading)
  15414. this._init();
  15415. }
  15416. else
  15417. this._init();
  15418. };
  15419. Window.prototype.onInit = function () {
  15420. };
  15421. Window.prototype.onShown = function () {
  15422. };
  15423. Window.prototype.onHide = function () {
  15424. };
  15425. Window.prototype.doShowAnimation = function () {
  15426. this.onShown();
  15427. };
  15428. Window.prototype.doHideAnimation = function () {
  15429. this.hideImmediately();
  15430. };
  15431. Window.prototype.__uiLoadComplete = function () {
  15432. var cnt = this._uiSources.length;
  15433. for (var i = 0; i < cnt; i++) {
  15434. var lib = this._uiSources[i];
  15435. if (!lib.loaded)
  15436. return;
  15437. }
  15438. this._loading = false;
  15439. this._init();
  15440. };
  15441. Window.prototype._init = function () {
  15442. this._inited = true;
  15443. this.onInit();
  15444. if (this.isShowing)
  15445. this.doShowAnimation();
  15446. };
  15447. Window.prototype.dispose = function () {
  15448. if (this.parent)
  15449. this.hideImmediately();
  15450. _super.prototype.dispose.call(this);
  15451. };
  15452. Window.prototype.closeEventHandler = function (evt) {
  15453. this.hide();
  15454. };
  15455. Window.prototype.onEnable = function () {
  15456. _super.prototype.onEnable.call(this);
  15457. if (!this._inited)
  15458. this.init();
  15459. else
  15460. this.doShowAnimation();
  15461. };
  15462. Window.prototype.onDisable = function () {
  15463. _super.prototype.onDisable.call(this);
  15464. this.closeModalWait();
  15465. this.onHide();
  15466. };
  15467. Window.prototype.onTouchBegin_1 = function (evt) {
  15468. if (this.isShowing && this.bringToFontOnClick)
  15469. this.bringToFront();
  15470. };
  15471. Window.prototype.onDragStart_1 = function (evt) {
  15472. var original = fgui.GObject.cast(evt.currentTarget);
  15473. original.stopDrag();
  15474. this.startDrag(evt.touchId);
  15475. };
  15476. return Window;
  15477. }(fgui.GComponent));
  15478. fgui.Window = Window;
  15479. })(fgui || (fgui = {}));
  15480. (function (fgui) {
  15481. var ControllerAction = (function () {
  15482. function ControllerAction() {
  15483. }
  15484. ControllerAction.createAction = function (type) {
  15485. switch (type) {
  15486. case 0:
  15487. return new fgui.PlayTransitionAction();
  15488. case 1:
  15489. return new fgui.ChangePageAction();
  15490. }
  15491. return null;
  15492. };
  15493. ControllerAction.prototype.run = function (controller, prevPage, curPage) {
  15494. if ((this.fromPage == null || this.fromPage.length == 0 || this.fromPage.indexOf(prevPage) != -1)
  15495. && (this.toPage == null || this.toPage.length == 0 || this.toPage.indexOf(curPage) != -1))
  15496. this.enter(controller);
  15497. else
  15498. this.leave(controller);
  15499. };
  15500. ControllerAction.prototype.enter = function (controller) {
  15501. };
  15502. ControllerAction.prototype.leave = function (controller) {
  15503. };
  15504. ControllerAction.prototype.setup = function (buffer) {
  15505. var cnt;
  15506. var i;
  15507. cnt = buffer.readShort();
  15508. this.fromPage = [];
  15509. for (i = 0; i < cnt; i++)
  15510. this.fromPage[i] = buffer.readS();
  15511. cnt = buffer.readShort();
  15512. this.toPage = [];
  15513. for (i = 0; i < cnt; i++)
  15514. this.toPage[i] = buffer.readS();
  15515. };
  15516. return ControllerAction;
  15517. }());
  15518. fgui.ControllerAction = ControllerAction;
  15519. })(fgui || (fgui = {}));
  15520. (function (fgui) {
  15521. var ChangePageAction = (function (_super) {
  15522. __extends(ChangePageAction, _super);
  15523. function ChangePageAction() {
  15524. return _super.call(this) || this;
  15525. }
  15526. ChangePageAction.prototype.enter = function (controller) {
  15527. if (!this.controllerName)
  15528. return;
  15529. var gcom;
  15530. if (this.objectId) {
  15531. var obj = controller.parent.getChildById(this.objectId);
  15532. if (obj instanceof fgui.GComponent)
  15533. gcom = obj;
  15534. else
  15535. return;
  15536. }
  15537. else
  15538. gcom = controller.parent;
  15539. if (gcom) {
  15540. var cc = gcom.getController(this.controllerName);
  15541. if (cc && cc != controller && !cc.changing) {
  15542. if (this.targetPage == "~1") {
  15543. if (controller.selectedIndex < cc.pageCount)
  15544. cc.selectedIndex = controller.selectedIndex;
  15545. }
  15546. else if (this.targetPage == "~2")
  15547. cc.selectedPage = controller.selectedPage;
  15548. else
  15549. cc.selectedPageId = this.targetPage;
  15550. }
  15551. }
  15552. };
  15553. ChangePageAction.prototype.setup = function (buffer) {
  15554. _super.prototype.setup.call(this, buffer);
  15555. this.objectId = buffer.readS();
  15556. this.controllerName = buffer.readS();
  15557. this.targetPage = buffer.readS();
  15558. };
  15559. return ChangePageAction;
  15560. }(fgui.ControllerAction));
  15561. fgui.ChangePageAction = ChangePageAction;
  15562. })(fgui || (fgui = {}));
  15563. (function (fgui) {
  15564. var PlayTransitionAction = (function (_super) {
  15565. __extends(PlayTransitionAction, _super);
  15566. function PlayTransitionAction() {
  15567. var _this = _super.call(this) || this;
  15568. _this.playTimes = 1;
  15569. _this.delay = 0;
  15570. _this.stopOnExit = false;
  15571. return _this;
  15572. }
  15573. PlayTransitionAction.prototype.enter = function (controller) {
  15574. var trans = controller.parent.getTransition(this.transitionName);
  15575. if (trans) {
  15576. if (this._currentTransition && this._currentTransition.playing)
  15577. trans.changePlayTimes(this.playTimes);
  15578. else
  15579. trans.play(null, this.playTimes, this.delay);
  15580. this._currentTransition = trans;
  15581. }
  15582. };
  15583. PlayTransitionAction.prototype.leave = function (controller) {
  15584. if (this.stopOnExit && this._currentTransition) {
  15585. this._currentTransition.stop();
  15586. this._currentTransition = null;
  15587. }
  15588. };
  15589. PlayTransitionAction.prototype.setup = function (buffer) {
  15590. _super.prototype.setup.call(this, buffer);
  15591. this.transitionName = buffer.readS();
  15592. this.playTimes = buffer.readInt();
  15593. this.delay = buffer.readFloat();
  15594. this.stopOnExit = buffer.readBool();
  15595. };
  15596. return PlayTransitionAction;
  15597. }(fgui.ControllerAction));
  15598. fgui.PlayTransitionAction = PlayTransitionAction;
  15599. })(fgui || (fgui = {}));
  15600. (function (fgui) {
  15601. var BlendMode;
  15602. (function (BlendMode) {
  15603. BlendMode[BlendMode["Normal"] = 0] = "Normal";
  15604. BlendMode[BlendMode["None"] = 1] = "None";
  15605. BlendMode[BlendMode["Add"] = 2] = "Add";
  15606. BlendMode[BlendMode["Multiply"] = 3] = "Multiply";
  15607. BlendMode[BlendMode["Screen"] = 4] = "Screen";
  15608. BlendMode[BlendMode["Erase"] = 5] = "Erase";
  15609. BlendMode[BlendMode["Mask"] = 6] = "Mask";
  15610. BlendMode[BlendMode["Below"] = 7] = "Below";
  15611. BlendMode[BlendMode["Off"] = 8] = "Off";
  15612. BlendMode[BlendMode["Custom1"] = 9] = "Custom1";
  15613. BlendMode[BlendMode["Custom2"] = 10] = "Custom2";
  15614. BlendMode[BlendMode["Custom3"] = 11] = "Custom3";
  15615. })(BlendMode = fgui.BlendMode || (fgui.BlendMode = {}));
  15616. var BlendModeUtils = (function () {
  15617. function BlendModeUtils() {
  15618. }
  15619. BlendModeUtils.apply = function (node, blendMode) {
  15620. var f = factors[blendMode];
  15621. var renderers = node.getComponentsInChildren(cc.RenderComponent);
  15622. renderers.forEach(function (element) {
  15623. element.srcBlendFactor = f[0];
  15624. element.dstBlendFactor = f[1];
  15625. });
  15626. };
  15627. BlendModeUtils.override = function (blendMode, srcFactor, dstFactor) {
  15628. factors[blendMode][0] = srcFactor;
  15629. factors[blendMode][1] = dstFactor;
  15630. };
  15631. return BlendModeUtils;
  15632. }());
  15633. fgui.BlendModeUtils = BlendModeUtils;
  15634. var factors = [
  15635. [cc.macro.SRC_ALPHA, cc.macro.ONE_MINUS_SRC_ALPHA],
  15636. [cc.macro.ONE, cc.macro.ONE],
  15637. [cc.macro.SRC_ALPHA, cc.macro.ONE],
  15638. [cc.macro.DST_COLOR, cc.macro.ONE_MINUS_SRC_ALPHA],
  15639. [cc.macro.ONE, cc.macro.ONE_MINUS_SRC_COLOR],
  15640. [cc.macro.ZERO, cc.macro.ONE_MINUS_SRC_ALPHA],
  15641. [cc.macro.ZERO, cc.macro.SRC_ALPHA],
  15642. [cc.macro.ONE_MINUS_DST_ALPHA, cc.macro.DST_ALPHA],
  15643. [cc.macro.ONE, cc.macro.ZERO],
  15644. [cc.macro.SRC_ALPHA, cc.macro.ONE_MINUS_SRC_ALPHA],
  15645. [cc.macro.SRC_ALPHA, cc.macro.ONE_MINUS_SRC_ALPHA],
  15646. [cc.macro.SRC_ALPHA, cc.macro.ONE_MINUS_SRC_ALPHA],
  15647. ];
  15648. })(fgui || (fgui = {}));
  15649. (function (fgui) {
  15650. var Image = (function (_super) {
  15651. __extends(Image, _super);
  15652. function Image() {
  15653. var _this = _super.call(this) || this;
  15654. _this._flip = fgui.FlipType.None;
  15655. _this._fillMethod = fgui.FillMethod.None;
  15656. _this._fillOrigin = fgui.FillOrigin.Left;
  15657. _this._fillAmount = 0;
  15658. return _this;
  15659. }
  15660. Object.defineProperty(Image.prototype, "flip", {
  15661. get: function () {
  15662. return this._flip;
  15663. },
  15664. set: function (value) {
  15665. if (this._flip != value) {
  15666. this._flip = value;
  15667. var sx = 1, sy = 1;
  15668. if (this._flip == fgui.FlipType.Horizontal || this._flip == fgui.FlipType.Both)
  15669. sx = -1;
  15670. if (this._flip == fgui.FlipType.Vertical || this._flip == fgui.FlipType.Both)
  15671. sy = -1;
  15672. if (sx != 1 || sy != 1)
  15673. this.node.setAnchorPoint(0.5, 0.5);
  15674. this.node.setScale(sx, sy);
  15675. }
  15676. },
  15677. enumerable: false,
  15678. configurable: true
  15679. });
  15680. Object.defineProperty(Image.prototype, "fillMethod", {
  15681. get: function () {
  15682. return this._fillMethod;
  15683. },
  15684. set: function (value) {
  15685. if (this._fillMethod != value) {
  15686. this._fillMethod = value;
  15687. if (this._fillMethod != 0) {
  15688. this.type = cc.Sprite.Type.FILLED;
  15689. if (this._fillMethod <= 3)
  15690. this.fillType = this._fillMethod - 1;
  15691. else
  15692. this.fillType = cc.Sprite.FillType.RADIAL;
  15693. this.fillCenter = new cc.Vec2(0.5, 0.5);
  15694. this.setupFill();
  15695. }
  15696. else {
  15697. this.type = cc.Sprite.Type.SIMPLE;
  15698. }
  15699. }
  15700. },
  15701. enumerable: false,
  15702. configurable: true
  15703. });
  15704. Object.defineProperty(Image.prototype, "fillOrigin", {
  15705. get: function () {
  15706. return this._fillOrigin;
  15707. },
  15708. set: function (value) {
  15709. if (this._fillOrigin != value) {
  15710. this._fillOrigin = value;
  15711. if (this._fillMethod != 0)
  15712. this.setupFill();
  15713. }
  15714. },
  15715. enumerable: false,
  15716. configurable: true
  15717. });
  15718. Object.defineProperty(Image.prototype, "fillClockwise", {
  15719. get: function () {
  15720. return this._fillClockwise;
  15721. },
  15722. set: function (value) {
  15723. if (this._fillClockwise != value) {
  15724. this._fillClockwise = value;
  15725. if (this._fillMethod != 0)
  15726. this.setupFill();
  15727. }
  15728. },
  15729. enumerable: false,
  15730. configurable: true
  15731. });
  15732. Object.defineProperty(Image.prototype, "fillAmount", {
  15733. get: function () {
  15734. return this._fillAmount;
  15735. },
  15736. set: function (value) {
  15737. if (this._fillAmount != value) {
  15738. this._fillAmount = value;
  15739. if (this._fillMethod != 0) {
  15740. if (this._fillClockwise)
  15741. this.fillRange = -this._fillAmount;
  15742. else
  15743. this.fillRange = this._fillAmount;
  15744. }
  15745. }
  15746. },
  15747. enumerable: false,
  15748. configurable: true
  15749. });
  15750. Image.prototype.setupFill = function () {
  15751. if (this._fillMethod == fgui.FillMethod.Horizontal) {
  15752. this._fillClockwise = this._fillOrigin == fgui.FillOrigin.Right || this._fillOrigin == fgui.FillOrigin.Bottom;
  15753. this.fillStart = this._fillClockwise ? 1 : 0;
  15754. }
  15755. else if (this._fillMethod == fgui.FillMethod.Vertical) {
  15756. this._fillClockwise = this._fillOrigin == fgui.FillOrigin.Left || this._fillOrigin == fgui.FillOrigin.Top;
  15757. this.fillStart = this._fillClockwise ? 1 : 0;
  15758. }
  15759. else {
  15760. switch (this._fillOrigin) {
  15761. case fgui.FillOrigin.Right:
  15762. this.fillOrigin = 0;
  15763. break;
  15764. case fgui.FillOrigin.Top:
  15765. this.fillStart = 0.25;
  15766. break;
  15767. case fgui.FillOrigin.Left:
  15768. this.fillStart = 0.5;
  15769. break;
  15770. case fgui.FillOrigin.Bottom:
  15771. this.fillStart = 0.75;
  15772. break;
  15773. }
  15774. }
  15775. };
  15776. Object.defineProperty(Image.prototype, "grayed", {
  15777. get: function () {
  15778. return this._grayed;
  15779. },
  15780. set: function (value) {
  15781. if (this._grayed == value)
  15782. return;
  15783. this._grayed = value;
  15784. var material;
  15785. if (value) {
  15786. material = this._graySpriteMaterial;
  15787. if (!material)
  15788. material = cc.Material.getBuiltinMaterial('2d-gray-sprite');
  15789. material = this._graySpriteMaterial = cc.MaterialVariant.create(material, this);
  15790. }
  15791. else {
  15792. material = this._spriteMaterial;
  15793. if (!material)
  15794. material = cc.Material.getBuiltinMaterial('2d-sprite', this);
  15795. material = this._spriteMaterial = cc.MaterialVariant.create(material, this);
  15796. }
  15797. this.setMaterial(0, material);
  15798. },
  15799. enumerable: false,
  15800. configurable: true
  15801. });
  15802. ;
  15803. return Image;
  15804. }(cc.Sprite));
  15805. fgui.Image = Image;
  15806. })(fgui || (fgui = {}));
  15807. (function (fgui) {
  15808. var MovieClip = (function (_super) {
  15809. __extends(MovieClip, _super);
  15810. function MovieClip() {
  15811. var _this = _super.call(this) || this;
  15812. _this.interval = 0;
  15813. _this.repeatDelay = 0;
  15814. _this.timeScale = 1;
  15815. _this._playing = true;
  15816. _this._frameCount = 0;
  15817. _this._frame = 0;
  15818. _this._start = 0;
  15819. _this._end = 0;
  15820. _this._times = 0;
  15821. _this._endAt = 0;
  15822. _this._status = 0;
  15823. _this._smoothing = true;
  15824. _this._frameElapsed = 0;
  15825. _this._reversed = false;
  15826. _this._repeatedCount = 0;
  15827. return _this;
  15828. }
  15829. Object.defineProperty(MovieClip.prototype, "frames", {
  15830. get: function () {
  15831. return this._frames;
  15832. },
  15833. set: function (value) {
  15834. this._frames = value;
  15835. if (this._frames) {
  15836. this._frameCount = this._frames.length;
  15837. if (this._end == -1 || this._end > this._frameCount - 1)
  15838. this._end = this._frameCount - 1;
  15839. if (this._endAt == -1 || this._endAt > this._frameCount - 1)
  15840. this._endAt = this._frameCount - 1;
  15841. if (this._frame < 0 || this._frame > this._frameCount - 1)
  15842. this._frame = this._frameCount - 1;
  15843. this.type = cc.Sprite.Type.SIMPLE;
  15844. this.drawFrame();
  15845. this._frameElapsed = 0;
  15846. this._repeatedCount = 0;
  15847. this._reversed = false;
  15848. }
  15849. else {
  15850. this._frameCount = 0;
  15851. }
  15852. },
  15853. enumerable: false,
  15854. configurable: true
  15855. });
  15856. Object.defineProperty(MovieClip.prototype, "frameCount", {
  15857. get: function () {
  15858. return this._frameCount;
  15859. },
  15860. enumerable: false,
  15861. configurable: true
  15862. });
  15863. Object.defineProperty(MovieClip.prototype, "frame", {
  15864. get: function () {
  15865. return this._frame;
  15866. },
  15867. set: function (value) {
  15868. if (this._frame != value) {
  15869. if (this._frames && value >= this._frameCount)
  15870. value = this._frameCount - 1;
  15871. this._frame = value;
  15872. this._frameElapsed = 0;
  15873. this.drawFrame();
  15874. }
  15875. },
  15876. enumerable: false,
  15877. configurable: true
  15878. });
  15879. Object.defineProperty(MovieClip.prototype, "playing", {
  15880. get: function () {
  15881. return this._playing;
  15882. },
  15883. set: function (value) {
  15884. if (this._playing != value) {
  15885. this._playing = value;
  15886. }
  15887. },
  15888. enumerable: false,
  15889. configurable: true
  15890. });
  15891. Object.defineProperty(MovieClip.prototype, "smoothing", {
  15892. get: function () {
  15893. return this._smoothing;
  15894. },
  15895. set: function (value) {
  15896. this._smoothing = value;
  15897. },
  15898. enumerable: false,
  15899. configurable: true
  15900. });
  15901. MovieClip.prototype.rewind = function () {
  15902. this._frame = 0;
  15903. this._frameElapsed = 0;
  15904. this._reversed = false;
  15905. this._repeatedCount = 0;
  15906. this.drawFrame();
  15907. };
  15908. MovieClip.prototype.syncStatus = function (anotherMc) {
  15909. this._frame = anotherMc._frame;
  15910. this._frameElapsed = anotherMc._frameElapsed;
  15911. this._reversed = anotherMc._reversed;
  15912. this._repeatedCount = anotherMc._repeatedCount;
  15913. this.drawFrame();
  15914. };
  15915. MovieClip.prototype.advance = function (timeInSeconds) {
  15916. var beginFrame = this._frame;
  15917. var beginReversed = this._reversed;
  15918. var backupTime = timeInSeconds;
  15919. while (true) {
  15920. var tt = this.interval + this._frames[this._frame].addDelay;
  15921. if (this._frame == 0 && this._repeatedCount > 0)
  15922. tt += this.repeatDelay;
  15923. if (timeInSeconds < tt) {
  15924. this._frameElapsed = 0;
  15925. break;
  15926. }
  15927. timeInSeconds -= tt;
  15928. if (this.swing) {
  15929. if (this._reversed) {
  15930. this._frame--;
  15931. if (this._frame <= 0) {
  15932. this._frame = 0;
  15933. this._repeatedCount++;
  15934. this._reversed = !this._reversed;
  15935. }
  15936. }
  15937. else {
  15938. this._frame++;
  15939. if (this._frame > this._frameCount - 1) {
  15940. this._frame = Math.max(0, this._frameCount - 2);
  15941. this._repeatedCount++;
  15942. this._reversed = !this._reversed;
  15943. }
  15944. }
  15945. }
  15946. else {
  15947. this._frame++;
  15948. if (this._frame > this._frameCount - 1) {
  15949. this._frame = 0;
  15950. this._repeatedCount++;
  15951. }
  15952. }
  15953. if (this._frame == beginFrame && this._reversed == beginReversed) {
  15954. var roundTime = backupTime - timeInSeconds;
  15955. timeInSeconds -= Math.floor(timeInSeconds / roundTime) * roundTime;
  15956. }
  15957. }
  15958. this.drawFrame();
  15959. };
  15960. MovieClip.prototype.setPlaySettings = function (start, end, times, endAt, endCallback, callbackObj) {
  15961. if (start == undefined)
  15962. start = 0;
  15963. if (end == undefined)
  15964. end = -1;
  15965. if (times == undefined)
  15966. times = 0;
  15967. if (endAt == undefined)
  15968. endAt = -1;
  15969. this._start = start;
  15970. this._end = end;
  15971. if (this._end == -1 || this._end > this._frameCount - 1)
  15972. this._end = this._frameCount - 1;
  15973. this._times = times;
  15974. this._endAt = endAt;
  15975. if (this._endAt == -1)
  15976. this._endAt = this._end;
  15977. this._status = 0;
  15978. this._callback = endCallback;
  15979. this._callbackObj = callbackObj;
  15980. this.frame = start;
  15981. };
  15982. MovieClip.prototype.update = function (dt) {
  15983. if (!this._playing || this._frameCount == 0 || this._status == 3)
  15984. return;
  15985. if (this.timeScale != 1)
  15986. dt *= this.timeScale;
  15987. this._frameElapsed += dt;
  15988. var tt = this.interval + this._frames[this._frame].addDelay;
  15989. if (this._frame == 0 && this._repeatedCount > 0)
  15990. tt += this.repeatDelay;
  15991. if (this._frameElapsed < tt)
  15992. return;
  15993. this._frameElapsed -= tt;
  15994. if (this._frameElapsed > this.interval)
  15995. this._frameElapsed = this.interval;
  15996. if (this.swing) {
  15997. if (this._reversed) {
  15998. this._frame--;
  15999. if (this._frame <= 0) {
  16000. this._frame = 0;
  16001. this._repeatedCount++;
  16002. this._reversed = !this._reversed;
  16003. }
  16004. }
  16005. else {
  16006. this._frame++;
  16007. if (this._frame > this._frameCount - 1) {
  16008. this._frame = Math.max(0, this._frameCount - 2);
  16009. this._repeatedCount++;
  16010. this._reversed = !this._reversed;
  16011. }
  16012. }
  16013. }
  16014. else {
  16015. this._frame++;
  16016. if (this._frame > this._frameCount - 1) {
  16017. this._frame = 0;
  16018. this._repeatedCount++;
  16019. }
  16020. }
  16021. if (this._status == 1) {
  16022. this._frame = this._start;
  16023. this._frameElapsed = 0;
  16024. this._status = 0;
  16025. }
  16026. else if (this._status == 2) {
  16027. this._frame = this._endAt;
  16028. this._frameElapsed = 0;
  16029. this._status = 3;
  16030. if (this._callback != null) {
  16031. var callback = this._callback;
  16032. var caller = this._callbackObj;
  16033. this._callback = null;
  16034. this._callbackObj = null;
  16035. callback.call(caller);
  16036. }
  16037. }
  16038. else {
  16039. if (this._frame == this._end) {
  16040. if (this._times > 0) {
  16041. this._times--;
  16042. if (this._times == 0)
  16043. this._status = 2;
  16044. else
  16045. this._status = 1;
  16046. }
  16047. else if (this._start != 0)
  16048. this._status = 1;
  16049. }
  16050. }
  16051. this.drawFrame();
  16052. };
  16053. MovieClip.prototype.drawFrame = function () {
  16054. if (this._frameCount > 0 && this._frame < this._frames.length) {
  16055. var frame = this._frames[this._frame];
  16056. this.spriteFrame = frame.texture;
  16057. }
  16058. };
  16059. return MovieClip;
  16060. }(fgui.Image));
  16061. fgui.MovieClip = MovieClip;
  16062. })(fgui || (fgui = {}));
  16063. (function (fgui) {
  16064. var Event = (function (_super) {
  16065. __extends(Event, _super);
  16066. function Event(type, bubbles) {
  16067. var _this = _super.call(this, type, bubbles) || this;
  16068. _this.pos = new cc.Vec2();
  16069. _this.touchId = 0;
  16070. _this.clickCount = 0;
  16071. _this.button = 0;
  16072. _this.keyModifiers = 0;
  16073. _this.mouseWheelDelta = 0;
  16074. return _this;
  16075. }
  16076. Object.defineProperty(Event.prototype, "isShiftDown", {
  16077. get: function () {
  16078. return false;
  16079. },
  16080. enumerable: false,
  16081. configurable: true
  16082. });
  16083. Object.defineProperty(Event.prototype, "isCtrlDown", {
  16084. get: function () {
  16085. return false;
  16086. },
  16087. enumerable: false,
  16088. configurable: true
  16089. });
  16090. Event.prototype.captureTouch = function () {
  16091. var obj = fgui.GObject.cast(this.currentTarget);
  16092. if (obj)
  16093. this._processor.addTouchMonitor(this.touchId, obj);
  16094. };
  16095. Event._borrow = function (type, bubbles) {
  16096. var evt;
  16097. if (eventPool.length) {
  16098. evt = eventPool.pop();
  16099. evt.type = type;
  16100. evt.bubbles = bubbles;
  16101. }
  16102. else {
  16103. evt = new Event(type, bubbles);
  16104. }
  16105. return evt;
  16106. };
  16107. Event._return = function (evt) {
  16108. evt.initiator = null;
  16109. evt.touch = null;
  16110. evt.unuse();
  16111. eventPool.push(evt);
  16112. };
  16113. Event.TOUCH_BEGIN = "fui_touch_begin";
  16114. Event.TOUCH_MOVE = "fui_touch_move";
  16115. Event.TOUCH_END = "fui_touch_end";
  16116. Event.CLICK = "fui_click";
  16117. Event.ROLL_OVER = "fui_roll_over";
  16118. Event.ROLL_OUT = "fui_roll_out";
  16119. Event.MOUSE_WHEEL = "fui_mouse_wheel";
  16120. Event.DISPLAY = "fui_display";
  16121. Event.UNDISPLAY = "fui_undisplay";
  16122. Event.GEAR_STOP = "fui_gear_stop";
  16123. Event.LINK = "fui_text_link";
  16124. Event.Submit = "editing-return";
  16125. Event.TEXT_CHANGE = "text-changed";
  16126. Event.STATUS_CHANGED = "fui_status_changed";
  16127. Event.XY_CHANGED = "fui_xy_changed";
  16128. Event.SIZE_CHANGED = "fui_size_changed";
  16129. Event.SIZE_DELAY_CHANGE = "fui_size_delay_change";
  16130. Event.DRAG_START = "fui_drag_start";
  16131. Event.DRAG_MOVE = "fui_drag_move";
  16132. Event.DRAG_END = "fui_drag_end";
  16133. Event.DROP = "fui_drop";
  16134. Event.SCROLL = "fui_scroll";
  16135. Event.SCROLL_END = "fui_scroll_end";
  16136. Event.PULL_DOWN_RELEASE = "fui_pull_down_release";
  16137. Event.PULL_UP_RELEASE = "fui_pull_up_release";
  16138. Event.CLICK_ITEM = "fui_click_item";
  16139. return Event;
  16140. }(cc.Event));
  16141. fgui.Event = Event;
  16142. var eventPool = new Array();
  16143. })(fgui || (fgui = {}));
  16144. (function (fgui) {
  16145. var PixelHitTest = (function () {
  16146. function PixelHitTest(data, offsetX, offsetY) {
  16147. this._data = data;
  16148. this.offsetX = offsetX == undefined ? 0 : offsetX;
  16149. this.offsetY = offsetY == undefined ? 0 : offsetY;
  16150. this.scaleX = 1;
  16151. this.scaleY = 1;
  16152. }
  16153. PixelHitTest.prototype.hitTest = function (pt) {
  16154. var x = Math.floor((pt.x / this.scaleX - this.offsetX) * this._data.scale);
  16155. var y = Math.floor((pt.y / this.scaleY - this.offsetY) * this._data.scale);
  16156. if (x < 0 || y < 0 || x >= this._data.pixelWidth)
  16157. return false;
  16158. var pos = y * this._data.pixelWidth + x;
  16159. var pos2 = Math.floor(pos / 8);
  16160. var pos3 = pos % 8;
  16161. if (pos2 >= 0 && pos2 < this._data.pixels.length)
  16162. return ((this._data.pixels[pos2] >> pos3) & 0x1) == 1;
  16163. else
  16164. return false;
  16165. };
  16166. return PixelHitTest;
  16167. }());
  16168. fgui.PixelHitTest = PixelHitTest;
  16169. var PixelHitTestData = (function () {
  16170. function PixelHitTestData(ba) {
  16171. ba.readInt();
  16172. this.pixelWidth = ba.readInt();
  16173. this.scale = 1 / ba.readByte();
  16174. this.pixels = ba.readBuffer().data;
  16175. }
  16176. return PixelHitTestData;
  16177. }());
  16178. fgui.PixelHitTestData = PixelHitTestData;
  16179. var ChildHitArea = (function () {
  16180. function ChildHitArea(child) {
  16181. this._child = child;
  16182. }
  16183. ChildHitArea.prototype.hitTest = function (pt, globalPt) {
  16184. return this._child.hitTest(globalPt, false) != null;
  16185. };
  16186. return ChildHitArea;
  16187. }());
  16188. fgui.ChildHitArea = ChildHitArea;
  16189. })(fgui || (fgui = {}));
  16190. (function (fgui) {
  16191. var InputProcessor = (function (_super) {
  16192. __extends(InputProcessor, _super);
  16193. function InputProcessor() {
  16194. var _this = _super.call(this) || this;
  16195. _this._touches = new Array();
  16196. _this._rollOutChain = new Array();
  16197. _this._rollOverChain = new Array();
  16198. _this._touchPos = new cc.Vec2();
  16199. return _this;
  16200. }
  16201. InputProcessor.prototype.onLoad = function () {
  16202. this._owner = this.node["$gobj"];
  16203. };
  16204. InputProcessor.prototype.onEnable = function () {
  16205. var node = this.node;
  16206. node.on(cc.Node.EventType.TOUCH_START, this.touchBeginHandler, this);
  16207. node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoveHandler, this);
  16208. node.on(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this);
  16209. node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchCancelHandler, this);
  16210. node.on(cc.Node.EventType.MOUSE_DOWN, this.mouseDownHandler, this);
  16211. node.on(cc.Node.EventType.MOUSE_MOVE, this.mouseMoveHandler, this);
  16212. node.on(cc.Node.EventType.MOUSE_UP, this.mouseUpHandler, this);
  16213. node.on(cc.Node.EventType.MOUSE_WHEEL, this.mouseWheelHandler, this);
  16214. this._touchListener = this.node["_touchListener"];
  16215. };
  16216. InputProcessor.prototype.onDisable = function () {
  16217. var node = this.node;
  16218. node.off(cc.Node.EventType.TOUCH_START, this.touchBeginHandler, this);
  16219. node.off(cc.Node.EventType.TOUCH_MOVE, this.touchMoveHandler, this);
  16220. node.off(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this);
  16221. node.off(cc.Node.EventType.TOUCH_CANCEL, this.touchCancelHandler, this);
  16222. node.off(cc.Node.EventType.MOUSE_DOWN, this.mouseDownHandler, this);
  16223. node.off(cc.Node.EventType.MOUSE_MOVE, this.mouseMoveHandler, this);
  16224. node.off(cc.Node.EventType.MOUSE_UP, this.mouseUpHandler, this);
  16225. node.off(cc.Node.EventType.MOUSE_WHEEL, this.mouseWheelHandler, this);
  16226. this._touchListener = null;
  16227. };
  16228. InputProcessor.prototype.getAllTouches = function (touchIds) {
  16229. touchIds = touchIds || new Array();
  16230. var cnt = this._touches.length;
  16231. for (var i = 0; i < cnt; i++) {
  16232. var ti = this._touches[i];
  16233. if (ti.touchId != -1)
  16234. touchIds.push(ti.touchId);
  16235. }
  16236. return touchIds;
  16237. };
  16238. InputProcessor.prototype.getTouchPosition = function (touchId) {
  16239. if (touchId === undefined)
  16240. touchId = -1;
  16241. var cnt = this._touches.length;
  16242. for (var i = 0; i < cnt; i++) {
  16243. var ti = this._touches[i];
  16244. if (ti.touchId != -1 && (touchId == -1 || ti.touchId == touchId))
  16245. return ti.pos;
  16246. }
  16247. return cc.Vec2.ZERO;
  16248. };
  16249. InputProcessor.prototype.getTouchTarget = function () {
  16250. var cnt = this._touches.length;
  16251. for (var i = 0; i < cnt; i++) {
  16252. var ti = this._touches[i];
  16253. if (ti.touchId != -1)
  16254. return ti.target;
  16255. }
  16256. return null;
  16257. };
  16258. InputProcessor.prototype.addTouchMonitor = function (touchId, target) {
  16259. var ti = this.getInfo(touchId, false);
  16260. if (!ti)
  16261. return;
  16262. var index = ti.touchMonitors.indexOf(target);
  16263. if (index == -1)
  16264. ti.touchMonitors.push(target);
  16265. };
  16266. InputProcessor.prototype.removeTouchMonitor = function (target) {
  16267. var cnt = this._touches.length;
  16268. for (var i = 0; i < cnt; i++) {
  16269. var ti = this._touches[i];
  16270. var index = ti.touchMonitors.indexOf(target);
  16271. if (index != -1)
  16272. ti.touchMonitors.splice(index, 1);
  16273. }
  16274. };
  16275. InputProcessor.prototype.cancelClick = function (touchId) {
  16276. var ti = this.getInfo(touchId, false);
  16277. if (ti)
  16278. ti.clickCancelled = true;
  16279. };
  16280. InputProcessor.prototype.simulateClick = function (target) {
  16281. var evt;
  16282. evt = fgui.Event._borrow(fgui.Event.TOUCH_BEGIN, true);
  16283. evt.initiator = target;
  16284. evt.pos.set(target.localToGlobal());
  16285. evt.touchId = 0;
  16286. evt.clickCount = 1;
  16287. evt.button = 0;
  16288. evt._processor = this;
  16289. if (this._captureCallback)
  16290. this._captureCallback.call(this._owner, evt);
  16291. target.node.dispatchEvent(evt);
  16292. evt.unuse();
  16293. evt.type = fgui.Event.TOUCH_END;
  16294. evt.bubbles = true;
  16295. target.node.dispatchEvent(evt);
  16296. evt.unuse();
  16297. evt.type = fgui.Event.CLICK;
  16298. evt.bubbles = true;
  16299. target.node.dispatchEvent(evt);
  16300. fgui.Event._return(evt);
  16301. };
  16302. InputProcessor.prototype.touchBeginHandler = function (touch, evt) {
  16303. var ti = this.updateInfo(touch.getID(), touch.getLocation(), touch);
  16304. this._touchListener.setSwallowTouches(ti.target != this._owner);
  16305. this.setBegin(ti);
  16306. var evt2 = this.getEvent(ti, ti.target, fgui.Event.TOUCH_BEGIN, true);
  16307. if (this._captureCallback)
  16308. this._captureCallback.call(this._owner, evt2);
  16309. ti.target.node.dispatchEvent(evt2);
  16310. this.handleRollOver(ti, ti.target);
  16311. return true;
  16312. };
  16313. InputProcessor.prototype.touchMoveHandler = function (touch, evt) {
  16314. var ti = this.updateInfo(touch.getID(), touch.getLocation(), touch);
  16315. this.handleRollOver(ti, ti.target);
  16316. if (ti.began) {
  16317. var evt2 = this.getEvent(ti, ti.target, fgui.Event.TOUCH_MOVE, false);
  16318. var done = false;
  16319. var cnt = ti.touchMonitors.length;
  16320. for (var i = 0; i < cnt; i++) {
  16321. var mm = ti.touchMonitors[i];
  16322. if (mm.node == null || !mm.node.activeInHierarchy)
  16323. continue;
  16324. evt2.unuse();
  16325. evt2.type = fgui.Event.TOUCH_MOVE;
  16326. mm.node.dispatchEvent(evt2);
  16327. if (mm == this._owner)
  16328. done = true;
  16329. }
  16330. if (!done && this.node) {
  16331. evt2.unuse();
  16332. evt2.type = fgui.Event.TOUCH_MOVE;
  16333. this.node.dispatchEvent(evt2);
  16334. }
  16335. fgui.Event._return(evt2);
  16336. }
  16337. };
  16338. InputProcessor.prototype.touchEndHandler = function (touch, evt) {
  16339. var ti = this.updateInfo(touch.getID(), touch.getLocation(), touch);
  16340. this.setEnd(ti);
  16341. var evt2 = this.getEvent(ti, ti.target, fgui.Event.TOUCH_END, false);
  16342. var cnt = ti.touchMonitors.length;
  16343. for (var i = 0; i < cnt; i++) {
  16344. var mm = ti.touchMonitors[i];
  16345. if (mm == ti.target || mm.node == null || !mm.node.activeInHierarchy
  16346. || (mm instanceof fgui.GComponent) && mm.isAncestorOf(ti.target))
  16347. continue;
  16348. evt2.unuse();
  16349. evt2.type = fgui.Event.TOUCH_END;
  16350. mm.node.dispatchEvent(evt2);
  16351. }
  16352. ti.touchMonitors.length = 0;
  16353. if (ti.target && ti.target.node) {
  16354. if (ti.target instanceof fgui.GRichTextField)
  16355. ti.target.node.getComponent(cc.RichText)["_onTouchEnded"](evt2);
  16356. evt2.unuse();
  16357. evt2.type = fgui.Event.TOUCH_END;
  16358. evt2.bubbles = true;
  16359. ti.target.node.dispatchEvent(evt2);
  16360. }
  16361. fgui.Event._return(evt2);
  16362. ti.target = this.clickTest(ti);
  16363. if (ti.target) {
  16364. evt2 = this.getEvent(ti, ti.target, fgui.Event.CLICK, true);
  16365. ti.target.node.dispatchEvent(evt2);
  16366. fgui.Event._return(evt2);
  16367. }
  16368. if (cc.sys.isMobile)
  16369. this.handleRollOver(ti, null);
  16370. else
  16371. this.handleRollOver(ti, ti.target);
  16372. ti.target = null;
  16373. ti.touchId = -1;
  16374. ti.button = -1;
  16375. };
  16376. InputProcessor.prototype.touchCancelHandler = function (touch, evt) {
  16377. var ti = this.updateInfo(touch.getID(), touch.getLocation(), touch);
  16378. var evt2 = this.getEvent(ti, ti.target, fgui.Event.TOUCH_END, false);
  16379. var cnt = ti.touchMonitors.length;
  16380. for (var i = 0; i < cnt; i++) {
  16381. var mm = ti.touchMonitors[i];
  16382. if (mm == ti.target || mm.node == null || !mm.node.activeInHierarchy
  16383. || (mm instanceof fgui.GComponent) && mm.isAncestorOf(ti.target))
  16384. continue;
  16385. evt2.initiator = mm;
  16386. mm.node.dispatchEvent(evt2);
  16387. }
  16388. ti.touchMonitors.length = 0;
  16389. if (ti.target && ti.target.node) {
  16390. evt2.bubbles = true;
  16391. ti.target.node.dispatchEvent(evt2);
  16392. }
  16393. fgui.Event._return(evt2);
  16394. this.handleRollOver(ti, null);
  16395. ti.target = null;
  16396. ti.touchId = -1;
  16397. ti.button = -1;
  16398. };
  16399. InputProcessor.prototype.mouseDownHandler = function (evt) {
  16400. var ti = this.getInfo(0, true);
  16401. ti.button = evt.getButton();
  16402. };
  16403. InputProcessor.prototype.mouseUpHandler = function (evt) {
  16404. var ti = this.getInfo(0, true);
  16405. ti.button = evt.getButton();
  16406. };
  16407. InputProcessor.prototype.mouseMoveHandler = function (evt) {
  16408. var ti = this.getInfo(0, false);
  16409. if (ti
  16410. && Math.abs(ti.pos.x - evt.getLocationX()) < 1
  16411. && Math.abs(ti.pos.y - (fgui.GRoot.inst.height - evt.getLocationY())) < 1)
  16412. return;
  16413. ti = this.updateInfo(0, evt.getLocation());
  16414. this.handleRollOver(ti, ti.target);
  16415. if (ti.began) {
  16416. var evt2 = this.getEvent(ti, ti.target, fgui.Event.TOUCH_MOVE, false);
  16417. var done = false;
  16418. var cnt = ti.touchMonitors.length;
  16419. for (var i = 0; i < cnt; i++) {
  16420. var mm = ti.touchMonitors[i];
  16421. if (mm.node == null || !mm.node.activeInHierarchy)
  16422. continue;
  16423. evt2.initiator = mm;
  16424. mm.node.dispatchEvent(evt2);
  16425. if (mm == this._owner)
  16426. done = true;
  16427. }
  16428. if (!done && this.node) {
  16429. evt2.initiator = this._owner;
  16430. this.node.dispatchEvent(evt2);
  16431. fgui.Event._return(evt2);
  16432. }
  16433. fgui.Event._return(evt2);
  16434. }
  16435. };
  16436. InputProcessor.prototype.mouseWheelHandler = function (evt) {
  16437. var ti = this.updateInfo(0, evt.getLocation());
  16438. ti.mouseWheelDelta = Math.max(evt.getScrollX(), evt.getScrollY());
  16439. var evt2 = this.getEvent(ti, ti.target, fgui.Event.MOUSE_WHEEL, true);
  16440. ti.target.node.dispatchEvent(evt2);
  16441. fgui.Event._return(evt2);
  16442. };
  16443. InputProcessor.prototype.updateInfo = function (touchId, pos, touch) {
  16444. var camera = cc.Camera.findCamera(this.node);
  16445. if (camera)
  16446. camera.getScreenToWorldPoint(pos, this._touchPos);
  16447. else
  16448. this._touchPos.set(pos);
  16449. this._touchPos.y = fgui.GRoot.inst.height - this._touchPos.y;
  16450. var target = this._owner.hitTest(this._touchPos);
  16451. if (!target)
  16452. target = this._owner;
  16453. var ti = this.getInfo(touchId);
  16454. ti.target = target;
  16455. ti.pos.set(this._touchPos);
  16456. ti.button = cc.Event.EventMouse.BUTTON_LEFT;
  16457. ti.touch = touch;
  16458. return ti;
  16459. };
  16460. InputProcessor.prototype.getInfo = function (touchId, createIfNotExisits) {
  16461. if (createIfNotExisits === undefined)
  16462. createIfNotExisits = true;
  16463. var ret = null;
  16464. var cnt = this._touches.length;
  16465. for (var i = 0; i < cnt; i++) {
  16466. var ti = this._touches[i];
  16467. if (ti.touchId == touchId)
  16468. return ti;
  16469. else if (ti.touchId == -1)
  16470. ret = ti;
  16471. }
  16472. if (!ret) {
  16473. if (!createIfNotExisits)
  16474. return null;
  16475. ret = new TouchInfo();
  16476. this._touches.push(ret);
  16477. }
  16478. ret.touchId = touchId;
  16479. return ret;
  16480. };
  16481. InputProcessor.prototype.setBegin = function (ti) {
  16482. ti.began = true;
  16483. ti.clickCancelled = false;
  16484. ti.downPos.set(ti.pos);
  16485. ti.downTargets.length = 0;
  16486. var obj = ti.target;
  16487. while (obj) {
  16488. ti.downTargets.push(obj);
  16489. obj = obj.findParent();
  16490. }
  16491. };
  16492. InputProcessor.prototype.setEnd = function (ti) {
  16493. ti.began = false;
  16494. var now = fgui.ToolSet.getTime();
  16495. var elapsed = now - ti.lastClickTime;
  16496. if (elapsed < 0.45) {
  16497. if (ti.clickCount == 2)
  16498. ti.clickCount = 1;
  16499. else
  16500. ti.clickCount++;
  16501. }
  16502. else
  16503. ti.clickCount = 1;
  16504. ti.lastClickTime = now;
  16505. };
  16506. InputProcessor.prototype.clickTest = function (ti) {
  16507. if (ti.downTargets.length == 0
  16508. || ti.clickCancelled
  16509. || Math.abs(ti.pos.x - ti.downPos.x) > 50 || Math.abs(ti.pos.y - ti.downPos.y) > 50)
  16510. return null;
  16511. var obj = ti.downTargets[0];
  16512. if (obj && obj.node && obj.node.activeInHierarchy)
  16513. return obj;
  16514. obj = ti.target;
  16515. while (obj) {
  16516. var index = ti.downTargets.indexOf(obj);
  16517. if (index != -1 && obj.node && obj.node.activeInHierarchy)
  16518. break;
  16519. obj = obj.findParent();
  16520. }
  16521. return obj;
  16522. };
  16523. InputProcessor.prototype.handleRollOver = function (ti, target) {
  16524. if (ti.lastRollOver == target)
  16525. return;
  16526. var element = ti.lastRollOver;
  16527. while (element && element.node) {
  16528. this._rollOutChain.push(element);
  16529. element = element.findParent();
  16530. }
  16531. element = target;
  16532. while (element && element.node) {
  16533. var i = this._rollOutChain.indexOf(element);
  16534. if (i != -1) {
  16535. this._rollOutChain.length = i;
  16536. break;
  16537. }
  16538. this._rollOverChain.push(element);
  16539. element = element.findParent();
  16540. }
  16541. ti.lastRollOver = target;
  16542. var cnt = this._rollOutChain.length;
  16543. for (var i = 0; i < cnt; i++) {
  16544. element = this._rollOutChain[i];
  16545. if (element.node && element.node.activeInHierarchy) {
  16546. var evt = this.getEvent(ti, element, fgui.Event.ROLL_OUT, false);
  16547. element.node.dispatchEvent(evt);
  16548. fgui.Event._return(evt);
  16549. }
  16550. }
  16551. cnt = this._rollOverChain.length;
  16552. for (var i = 0; i < cnt; i++) {
  16553. element = this._rollOverChain[i];
  16554. if (element.node && element.node.activeInHierarchy) {
  16555. var evt = this.getEvent(ti, element, fgui.Event.ROLL_OVER, false);
  16556. element.node.dispatchEvent(evt);
  16557. fgui.Event._return(evt);
  16558. }
  16559. }
  16560. this._rollOutChain.length = 0;
  16561. this._rollOverChain.length = 0;
  16562. };
  16563. InputProcessor.prototype.getEvent = function (ti, target, type, bubbles) {
  16564. var evt = fgui.Event._borrow(type, bubbles);
  16565. evt.initiator = target;
  16566. evt.touch = ti.touch;
  16567. evt.pos.set(ti.pos);
  16568. evt.touchId = ti.touch ? ti.touch.getID() : 0;
  16569. evt.clickCount = ti.clickCount;
  16570. evt.button = ti.button;
  16571. evt.mouseWheelDelta = ti.mouseWheelDelta;
  16572. evt._processor = this;
  16573. return evt;
  16574. };
  16575. return InputProcessor;
  16576. }(cc.Component));
  16577. fgui.InputProcessor = InputProcessor;
  16578. var TouchInfo = (function () {
  16579. function TouchInfo() {
  16580. this.pos = new cc.Vec2();
  16581. this.touchId = 0;
  16582. this.clickCount = 0;
  16583. this.mouseWheelDelta = 0;
  16584. this.button = -1;
  16585. this.downPos = new cc.Vec2();
  16586. this.began = false;
  16587. this.clickCancelled = false;
  16588. this.lastClickTime = 0;
  16589. this.downTargets = new Array();
  16590. this.touchMonitors = new Array();
  16591. }
  16592. return TouchInfo;
  16593. }());
  16594. ;
  16595. })(fgui || (fgui = {}));
  16596. (function (fgui) {
  16597. var GearBase = (function () {
  16598. function GearBase(owner) {
  16599. this._owner = owner;
  16600. }
  16601. GearBase.create = function (owner, index) {
  16602. if (!Classes)
  16603. Classes = [
  16604. fgui.GearDisplay, fgui.GearXY, fgui.GearSize, fgui.GearLook, fgui.GearColor,
  16605. fgui.GearAnimation, fgui.GearText, fgui.GearIcon, fgui.GearDisplay2, fgui.GearFontSize
  16606. ];
  16607. return new (Classes[index])(owner);
  16608. };
  16609. GearBase.prototype.dispose = function () {
  16610. if (this._tweenConfig && this._tweenConfig._tweener) {
  16611. this._tweenConfig._tweener.kill();
  16612. this._tweenConfig._tweener = null;
  16613. }
  16614. };
  16615. Object.defineProperty(GearBase.prototype, "controller", {
  16616. get: function () {
  16617. return this._controller;
  16618. },
  16619. set: function (val) {
  16620. if (val != this._controller) {
  16621. this._controller = val;
  16622. if (this._controller)
  16623. this.init();
  16624. }
  16625. },
  16626. enumerable: false,
  16627. configurable: true
  16628. });
  16629. Object.defineProperty(GearBase.prototype, "tweenConfig", {
  16630. get: function () {
  16631. if (!this._tweenConfig)
  16632. this._tweenConfig = new GearTweenConfig();
  16633. return this._tweenConfig;
  16634. },
  16635. enumerable: false,
  16636. configurable: true
  16637. });
  16638. GearBase.prototype.setup = function (buffer) {
  16639. this._controller = this._owner.parent.getControllerAt(buffer.readShort());
  16640. this.init();
  16641. var i;
  16642. var page;
  16643. var cnt = buffer.readShort();
  16644. if (this instanceof fgui.GearDisplay) {
  16645. this.pages = buffer.readSArray(cnt);
  16646. }
  16647. else if (this instanceof fgui.GearDisplay2) {
  16648. this.pages = buffer.readSArray(cnt);
  16649. }
  16650. else {
  16651. for (i = 0; i < cnt; i++) {
  16652. page = buffer.readS();
  16653. if (page == null)
  16654. continue;
  16655. this.addStatus(page, buffer);
  16656. }
  16657. if (buffer.readBool())
  16658. this.addStatus(null, buffer);
  16659. }
  16660. if (buffer.readBool()) {
  16661. this._tweenConfig = new GearTweenConfig();
  16662. this._tweenConfig.easeType = buffer.readByte();
  16663. this._tweenConfig.duration = buffer.readFloat();
  16664. this._tweenConfig.delay = buffer.readFloat();
  16665. }
  16666. if (buffer.version >= 2) {
  16667. if (this instanceof fgui.GearXY) {
  16668. if (buffer.readBool()) {
  16669. this.positionsInPercent = true;
  16670. for (i = 0; i < cnt; i++) {
  16671. page = buffer.readS();
  16672. if (page == null)
  16673. continue;
  16674. this.addExtStatus(page, buffer);
  16675. }
  16676. if (buffer.readBool())
  16677. this.addExtStatus(null, buffer);
  16678. }
  16679. }
  16680. else if (this instanceof fgui.GearDisplay2)
  16681. this.condition = buffer.readByte();
  16682. }
  16683. };
  16684. GearBase.prototype.updateFromRelations = function (dx, dy) {
  16685. };
  16686. GearBase.prototype.addStatus = function (pageId, buffer) {
  16687. };
  16688. GearBase.prototype.init = function () {
  16689. };
  16690. GearBase.prototype.apply = function () {
  16691. };
  16692. GearBase.prototype.updateState = function () {
  16693. };
  16694. return GearBase;
  16695. }());
  16696. fgui.GearBase = GearBase;
  16697. var Classes;
  16698. var GearTweenConfig = (function () {
  16699. function GearTweenConfig() {
  16700. this.tween = true;
  16701. this.easeType = fgui.EaseType.QuadOut;
  16702. this.duration = 0.3;
  16703. this.delay = 0;
  16704. }
  16705. return GearTweenConfig;
  16706. }());
  16707. fgui.GearTweenConfig = GearTweenConfig;
  16708. })(fgui || (fgui = {}));
  16709. (function (fgui) {
  16710. var GearAnimation = (function (_super) {
  16711. __extends(GearAnimation, _super);
  16712. function GearAnimation(owner) {
  16713. return _super.call(this, owner) || this;
  16714. }
  16715. GearAnimation.prototype.init = function () {
  16716. this._default = {
  16717. playing: this._owner.getProp(fgui.ObjectPropID.Playing),
  16718. frame: this._owner.getProp(fgui.ObjectPropID.Frame)
  16719. };
  16720. this._storage = {};
  16721. };
  16722. GearAnimation.prototype.addStatus = function (pageId, buffer) {
  16723. var gv;
  16724. if (pageId == null)
  16725. gv = this._default;
  16726. else
  16727. this._storage[pageId] = gv = {};
  16728. gv.playing = buffer.readBool();
  16729. gv.frame = buffer.readInt();
  16730. };
  16731. GearAnimation.prototype.apply = function () {
  16732. this._owner._gearLocked = true;
  16733. var gv = this._storage[this._controller.selectedPageId];
  16734. if (!gv)
  16735. gv = this._default;
  16736. this._owner.setProp(fgui.ObjectPropID.Playing, gv.playing);
  16737. this._owner.setProp(fgui.ObjectPropID.Frame, gv.frame);
  16738. this._owner._gearLocked = false;
  16739. };
  16740. GearAnimation.prototype.updateState = function () {
  16741. var gv = this._storage[this._controller.selectedPageId];
  16742. if (!gv)
  16743. this._storage[this._controller.selectedPageId] = gv = {};
  16744. gv.playing = this._owner.getProp(fgui.ObjectPropID.Playing);
  16745. gv.frame = this._owner.getProp(fgui.ObjectPropID.Frame);
  16746. };
  16747. return GearAnimation;
  16748. }(fgui.GearBase));
  16749. fgui.GearAnimation = GearAnimation;
  16750. })(fgui || (fgui = {}));
  16751. (function (fgui) {
  16752. var GearColor = (function (_super) {
  16753. __extends(GearColor, _super);
  16754. function GearColor(owner) {
  16755. return _super.call(this, owner) || this;
  16756. }
  16757. GearColor.prototype.init = function () {
  16758. this._default = {
  16759. color: this._owner.getProp(fgui.ObjectPropID.Color),
  16760. strokeColor: this._owner.getProp(fgui.ObjectPropID.OutlineColor)
  16761. };
  16762. this._storage = {};
  16763. };
  16764. GearColor.prototype.addStatus = function (pageId, buffer) {
  16765. var gv;
  16766. if (pageId == null)
  16767. gv = this._default;
  16768. else
  16769. this._storage[pageId] = gv = {};
  16770. gv.color = buffer.readColor();
  16771. gv.strokeColor = buffer.readColor();
  16772. };
  16773. GearColor.prototype.apply = function () {
  16774. this._owner._gearLocked = true;
  16775. var gv = this._storage[this._controller.selectedPageId];
  16776. if (!gv)
  16777. gv = this._default;
  16778. this._owner.setProp(fgui.ObjectPropID.Color, gv.color);
  16779. this._owner.setProp(fgui.ObjectPropID.OutlineColor, gv.strokeColor);
  16780. this._owner._gearLocked = false;
  16781. };
  16782. GearColor.prototype.updateState = function () {
  16783. var gv = this._storage[this._controller.selectedPageId];
  16784. if (!gv)
  16785. this._storage[this._controller.selectedPageId] = gv = {};
  16786. gv.color = this._owner.getProp(fgui.ObjectPropID.Color);
  16787. gv.strokeColor = this._owner.getProp(fgui.ObjectPropID.OutlineColor);
  16788. };
  16789. return GearColor;
  16790. }(fgui.GearBase));
  16791. fgui.GearColor = GearColor;
  16792. })(fgui || (fgui = {}));
  16793. (function (fgui) {
  16794. var GearDisplay = (function (_super) {
  16795. __extends(GearDisplay, _super);
  16796. function GearDisplay(owner) {
  16797. var _this = _super.call(this, owner) || this;
  16798. _this._displayLockToken = 1;
  16799. _this._visible = 0;
  16800. return _this;
  16801. }
  16802. GearDisplay.prototype.init = function () {
  16803. this.pages = null;
  16804. };
  16805. GearDisplay.prototype.apply = function () {
  16806. this._displayLockToken++;
  16807. if (this._displayLockToken == 0)
  16808. this._displayLockToken = 1;
  16809. if (this.pages == null || this.pages.length == 0
  16810. || this.pages.indexOf(this._controller.selectedPageId) != -1)
  16811. this._visible = 1;
  16812. else
  16813. this._visible = 0;
  16814. };
  16815. GearDisplay.prototype.addLock = function () {
  16816. this._visible++;
  16817. return this._displayLockToken;
  16818. };
  16819. GearDisplay.prototype.releaseLock = function (token) {
  16820. if (token == this._displayLockToken)
  16821. this._visible--;
  16822. };
  16823. Object.defineProperty(GearDisplay.prototype, "connected", {
  16824. get: function () {
  16825. return this._controller == null || this._visible > 0;
  16826. },
  16827. enumerable: false,
  16828. configurable: true
  16829. });
  16830. return GearDisplay;
  16831. }(fgui.GearBase));
  16832. fgui.GearDisplay = GearDisplay;
  16833. })(fgui || (fgui = {}));
  16834. (function (fgui) {
  16835. var GearDisplay2 = (function (_super) {
  16836. __extends(GearDisplay2, _super);
  16837. function GearDisplay2(owner) {
  16838. var _this = _super.call(this, owner) || this;
  16839. _this._visible = 0;
  16840. return _this;
  16841. }
  16842. GearDisplay2.prototype.init = function () {
  16843. this.pages = null;
  16844. };
  16845. GearDisplay2.prototype.apply = function () {
  16846. if (this.pages == null || this.pages.length == 0
  16847. || this.pages.indexOf(this._controller.selectedPageId) != -1)
  16848. this._visible = 1;
  16849. else
  16850. this._visible = 0;
  16851. };
  16852. GearDisplay2.prototype.evaluate = function (connected) {
  16853. var v = this._controller == null || this._visible > 0;
  16854. if (this.condition == 0)
  16855. v = v && connected;
  16856. else
  16857. v = v || connected;
  16858. return v;
  16859. };
  16860. return GearDisplay2;
  16861. }(fgui.GearBase));
  16862. fgui.GearDisplay2 = GearDisplay2;
  16863. })(fgui || (fgui = {}));
  16864. (function (fgui) {
  16865. var GearFontSize = (function (_super) {
  16866. __extends(GearFontSize, _super);
  16867. function GearFontSize(owner) {
  16868. var _this = _super.call(this, owner) || this;
  16869. _this._default = 0;
  16870. return _this;
  16871. }
  16872. GearFontSize.prototype.init = function () {
  16873. this._default = this._owner.getProp(fgui.ObjectPropID.FontSize);
  16874. this._storage = {};
  16875. };
  16876. GearFontSize.prototype.addStatus = function (pageId, buffer) {
  16877. if (pageId == null)
  16878. this._default = buffer.readInt();
  16879. else
  16880. this._storage[pageId] = buffer.readInt();
  16881. };
  16882. GearFontSize.prototype.apply = function () {
  16883. this._owner._gearLocked = true;
  16884. var data = this._storage[this._controller.selectedPageId];
  16885. if (data != undefined)
  16886. this._owner.setProp(fgui.ObjectPropID.FontSize, data);
  16887. else
  16888. this._owner.setProp(fgui.ObjectPropID.FontSize, this._default);
  16889. this._owner._gearLocked = false;
  16890. };
  16891. GearFontSize.prototype.updateState = function () {
  16892. this._storage[this._controller.selectedPageId] = this._owner.getProp(fgui.ObjectPropID.FontSize);
  16893. };
  16894. return GearFontSize;
  16895. }(fgui.GearBase));
  16896. fgui.GearFontSize = GearFontSize;
  16897. })(fgui || (fgui = {}));
  16898. (function (fgui) {
  16899. var GearIcon = (function (_super) {
  16900. __extends(GearIcon, _super);
  16901. function GearIcon(owner) {
  16902. return _super.call(this, owner) || this;
  16903. }
  16904. GearIcon.prototype.init = function () {
  16905. this._default = this._owner.icon;
  16906. this._storage = {};
  16907. };
  16908. GearIcon.prototype.addStatus = function (pageId, buffer) {
  16909. if (pageId == null)
  16910. this._default = buffer.readS();
  16911. else
  16912. this._storage[pageId] = buffer.readS();
  16913. };
  16914. GearIcon.prototype.apply = function () {
  16915. this._owner._gearLocked = true;
  16916. var data = this._storage[this._controller.selectedPageId];
  16917. if (data !== undefined)
  16918. this._owner.icon = data;
  16919. else
  16920. this._owner.icon = this._default;
  16921. this._owner._gearLocked = false;
  16922. };
  16923. GearIcon.prototype.updateState = function () {
  16924. this._storage[this._controller.selectedPageId] = this._owner.icon;
  16925. };
  16926. return GearIcon;
  16927. }(fgui.GearBase));
  16928. fgui.GearIcon = GearIcon;
  16929. })(fgui || (fgui = {}));
  16930. (function (fgui) {
  16931. var GearLook = (function (_super) {
  16932. __extends(GearLook, _super);
  16933. function GearLook(owner) {
  16934. return _super.call(this, owner) || this;
  16935. }
  16936. GearLook.prototype.init = function () {
  16937. this._default = {
  16938. alpha: this._owner.alpha,
  16939. rotation: this._owner.rotation,
  16940. grayed: this._owner.grayed,
  16941. touchable: this._owner.touchable
  16942. };
  16943. this._storage = {};
  16944. };
  16945. GearLook.prototype.addStatus = function (pageId, buffer) {
  16946. var gv;
  16947. if (pageId == null)
  16948. gv = this._default;
  16949. else
  16950. this._storage[pageId] = gv = {};
  16951. gv.alpha = buffer.readFloat();
  16952. gv.rotation = buffer.readFloat();
  16953. gv.grayed = buffer.readBool();
  16954. gv.touchable = buffer.readBool();
  16955. };
  16956. GearLook.prototype.apply = function () {
  16957. var gv = this._storage[this._controller.selectedPageId];
  16958. if (!gv)
  16959. gv = this._default;
  16960. if (this._tweenConfig && this._tweenConfig.tween && !fgui.UIPackage._constructing && !fgui.GearBase.disableAllTweenEffect) {
  16961. this._owner._gearLocked = true;
  16962. this._owner.grayed = gv.grayed;
  16963. this._owner.touchable = gv.touchable;
  16964. this._owner._gearLocked = false;
  16965. if (this._tweenConfig._tweener) {
  16966. if (this._tweenConfig._tweener.endValue.x != gv.alpha || this._tweenConfig._tweener.endValue.y != gv.rotation) {
  16967. this._tweenConfig._tweener.kill(true);
  16968. this._tweenConfig._tweener = null;
  16969. }
  16970. else
  16971. return;
  16972. }
  16973. var a = gv.alpha != this._owner.alpha;
  16974. var b = gv.rotation != this._owner.rotation;
  16975. if (a || b) {
  16976. if (this._owner.checkGearController(0, this._controller))
  16977. this._tweenConfig._displayLockToken = this._owner.addDisplayLock();
  16978. this._tweenConfig._tweener = fgui.GTween.to2(this._owner.alpha, this._owner.rotation, gv.alpha, gv.rotation, this._tweenConfig.duration)
  16979. .setDelay(this._tweenConfig.delay)
  16980. .setEase(this._tweenConfig.easeType)
  16981. .setUserData((a ? 1 : 0) + (b ? 2 : 0))
  16982. .setTarget(this)
  16983. .onUpdate(this.__tweenUpdate, this)
  16984. .onComplete(this.__tweenComplete, this);
  16985. }
  16986. }
  16987. else {
  16988. this._owner._gearLocked = true;
  16989. this._owner.grayed = gv.grayed;
  16990. this._owner.touchable = gv.touchable;
  16991. this._owner.alpha = gv.alpha;
  16992. this._owner.rotation = gv.rotation;
  16993. this._owner._gearLocked = false;
  16994. }
  16995. };
  16996. GearLook.prototype.__tweenUpdate = function (tweener) {
  16997. var flag = tweener.userData;
  16998. this._owner._gearLocked = true;
  16999. if ((flag & 1) != 0)
  17000. this._owner.alpha = tweener.value.x;
  17001. if ((flag & 2) != 0)
  17002. this._owner.rotation = tweener.value.y;
  17003. this._owner._gearLocked = false;
  17004. };
  17005. GearLook.prototype.__tweenComplete = function () {
  17006. if (this._tweenConfig._displayLockToken != 0) {
  17007. this._owner.releaseDisplayLock(this._tweenConfig._displayLockToken);
  17008. this._tweenConfig._displayLockToken = 0;
  17009. }
  17010. this._tweenConfig._tweener = null;
  17011. };
  17012. GearLook.prototype.updateState = function () {
  17013. var gv = this._storage[this._controller.selectedPageId];
  17014. if (!gv)
  17015. this._storage[this._controller.selectedPageId] = gv = {};
  17016. gv.alpha = this._owner.alpha;
  17017. gv.rotation = this._owner.rotation;
  17018. gv.grayed = this._owner.grayed;
  17019. gv.touchable = this._owner.touchable;
  17020. };
  17021. return GearLook;
  17022. }(fgui.GearBase));
  17023. fgui.GearLook = GearLook;
  17024. })(fgui || (fgui = {}));
  17025. (function (fgui) {
  17026. var GearSize = (function (_super) {
  17027. __extends(GearSize, _super);
  17028. function GearSize(owner) {
  17029. return _super.call(this, owner) || this;
  17030. }
  17031. GearSize.prototype.init = function () {
  17032. this._default = {
  17033. width: this._owner.width,
  17034. height: this._owner.height,
  17035. scaleX: this._owner.scaleX,
  17036. scaleY: this._owner.scaleY
  17037. };
  17038. this._storage = {};
  17039. };
  17040. GearSize.prototype.addStatus = function (pageId, buffer) {
  17041. var gv;
  17042. if (pageId == null)
  17043. gv = this._default;
  17044. else
  17045. this._storage[pageId] = gv = {};
  17046. gv.width = buffer.readInt();
  17047. gv.height = buffer.readInt();
  17048. gv.scaleX = buffer.readFloat();
  17049. gv.scaleY = buffer.readFloat();
  17050. };
  17051. GearSize.prototype.apply = function () {
  17052. var gv = this._storage[this._controller.selectedPageId];
  17053. if (!gv)
  17054. gv = this._default;
  17055. if (this._tweenConfig && this._tweenConfig.tween && !fgui.UIPackage._constructing && !fgui.GearBase.disableAllTweenEffect) {
  17056. if (this._tweenConfig._tweener) {
  17057. if (this._tweenConfig._tweener.endValue.x != gv.width || this._tweenConfig._tweener.endValue.y != gv.height
  17058. || this._tweenConfig._tweener.endValue.z != gv.scaleX || this._tweenConfig._tweener.endValue.w != gv.scaleY) {
  17059. this._tweenConfig._tweener.kill(true);
  17060. this._tweenConfig._tweener = null;
  17061. }
  17062. else
  17063. return;
  17064. }
  17065. var a = gv.width != this._owner.width || gv.height != this._owner.height;
  17066. var b = gv.scaleX != this._owner.scaleX || gv.scaleY != this._owner.scaleY;
  17067. if (a || b) {
  17068. if (this._owner.checkGearController(0, this._controller))
  17069. this._tweenConfig._displayLockToken = this._owner.addDisplayLock();
  17070. this._tweenConfig._tweener = fgui.GTween.to4(this._owner.width, this._owner.height, this._owner.scaleX, this._owner.scaleY, gv.width, gv.height, gv.scaleX, gv.scaleY, this._tweenConfig.duration)
  17071. .setDelay(this._tweenConfig.delay)
  17072. .setEase(this._tweenConfig.easeType)
  17073. .setUserData((a ? 1 : 0) + (b ? 2 : 0))
  17074. .setTarget(this)
  17075. .onUpdate(this.__tweenUpdate, this)
  17076. .onComplete(this.__tweenComplete, this);
  17077. }
  17078. }
  17079. else {
  17080. this._owner._gearLocked = true;
  17081. this._owner.setSize(gv.width, gv.height, this._owner.gearXY.controller == this._controller);
  17082. this._owner.setScale(gv.scaleX, gv.scaleY);
  17083. this._owner._gearLocked = false;
  17084. }
  17085. };
  17086. GearSize.prototype.__tweenUpdate = function (tweener) {
  17087. var flag = tweener.userData;
  17088. this._owner._gearLocked = true;
  17089. if ((flag & 1) != 0)
  17090. this._owner.setSize(tweener.value.x, tweener.value.y, this._owner.checkGearController(1, this._controller));
  17091. if ((flag & 2) != 0)
  17092. this._owner.setScale(tweener.value.z, tweener.value.w);
  17093. this._owner._gearLocked = false;
  17094. };
  17095. GearSize.prototype.__tweenComplete = function () {
  17096. if (this._tweenConfig._displayLockToken != 0) {
  17097. this._owner.releaseDisplayLock(this._tweenConfig._displayLockToken);
  17098. this._tweenConfig._displayLockToken = 0;
  17099. }
  17100. this._tweenConfig._tweener = null;
  17101. };
  17102. GearSize.prototype.updateState = function () {
  17103. var gv = this._storage[this._controller.selectedPageId];
  17104. if (!gv)
  17105. this._storage[this._controller.selectedPageId] = gv = {};
  17106. gv.width = this._owner.width;
  17107. gv.height = this._owner.height;
  17108. gv.scaleX = this._owner.scaleX;
  17109. gv.scaleY = this._owner.scaleY;
  17110. };
  17111. GearSize.prototype.updateFromRelations = function (dx, dy) {
  17112. if (this._controller == null || this._storage == null)
  17113. return;
  17114. for (var key in this._storage) {
  17115. var gv = this._storage[key];
  17116. gv.width += dx;
  17117. gv.height += dy;
  17118. }
  17119. this._default.width += dx;
  17120. this._default.height += dy;
  17121. this.updateState();
  17122. };
  17123. return GearSize;
  17124. }(fgui.GearBase));
  17125. fgui.GearSize = GearSize;
  17126. })(fgui || (fgui = {}));
  17127. (function (fgui) {
  17128. var GearText = (function (_super) {
  17129. __extends(GearText, _super);
  17130. function GearText(owner) {
  17131. return _super.call(this, owner) || this;
  17132. }
  17133. GearText.prototype.init = function () {
  17134. this._default = this._owner.text;
  17135. this._storage = {};
  17136. };
  17137. GearText.prototype.addStatus = function (pageId, buffer) {
  17138. if (pageId == null)
  17139. this._default = buffer.readS();
  17140. else
  17141. this._storage[pageId] = buffer.readS();
  17142. };
  17143. GearText.prototype.apply = function () {
  17144. this._owner._gearLocked = true;
  17145. var data = this._storage[this._controller.selectedPageId];
  17146. if (data !== undefined)
  17147. this._owner.text = data;
  17148. else
  17149. this._owner.text = this._default;
  17150. this._owner._gearLocked = false;
  17151. };
  17152. GearText.prototype.updateState = function () {
  17153. this._storage[this._controller.selectedPageId] = this._owner.text;
  17154. };
  17155. return GearText;
  17156. }(fgui.GearBase));
  17157. fgui.GearText = GearText;
  17158. })(fgui || (fgui = {}));
  17159. (function (fgui) {
  17160. var GearXY = (function (_super) {
  17161. __extends(GearXY, _super);
  17162. function GearXY(owner) {
  17163. return _super.call(this, owner) || this;
  17164. }
  17165. GearXY.prototype.init = function () {
  17166. this._default = {
  17167. x: this._owner.x,
  17168. y: this._owner.y,
  17169. px: this._owner.x / this._owner.parent.width,
  17170. py: this._owner.y / this._owner.parent.height
  17171. };
  17172. this._storage = {};
  17173. };
  17174. GearXY.prototype.addStatus = function (pageId, buffer) {
  17175. var gv;
  17176. if (pageId == null)
  17177. gv = this._default;
  17178. else
  17179. this._storage[pageId] = gv = {};
  17180. gv.x = buffer.readInt();
  17181. gv.y = buffer.readInt();
  17182. };
  17183. GearXY.prototype.addExtStatus = function (pageId, buffer) {
  17184. var gv;
  17185. if (pageId == null)
  17186. gv = this._default;
  17187. else
  17188. gv = this._storage[pageId];
  17189. gv.px = buffer.readFloat();
  17190. gv.py = buffer.readFloat();
  17191. };
  17192. GearXY.prototype.apply = function () {
  17193. var gv = this._storage[this._controller.selectedPageId];
  17194. if (!gv)
  17195. gv = this._default;
  17196. var ex;
  17197. var ey;
  17198. if (this.positionsInPercent && this._owner.parent) {
  17199. ex = gv.px * this._owner.parent.width;
  17200. ey = gv.py * this._owner.parent.height;
  17201. }
  17202. else {
  17203. ex = gv.x;
  17204. ey = gv.y;
  17205. }
  17206. if (this._tweenConfig && this._tweenConfig.tween && !fgui.UIPackage._constructing && !fgui.GearBase.disableAllTweenEffect) {
  17207. if (this._tweenConfig._tweener) {
  17208. if (this._tweenConfig._tweener.endValue.x != ex || this._tweenConfig._tweener.endValue.y != ey) {
  17209. this._tweenConfig._tweener.kill(true);
  17210. this._tweenConfig._tweener = null;
  17211. }
  17212. else
  17213. return;
  17214. }
  17215. var ox = this._owner.x;
  17216. var oy = this._owner.y;
  17217. if (ox != ex || oy != ey) {
  17218. if (this._owner.checkGearController(0, this._controller))
  17219. this._tweenConfig._displayLockToken = this._owner.addDisplayLock();
  17220. this._tweenConfig._tweener = fgui.GTween.to2(ox, oy, ex, ey, this._tweenConfig.duration)
  17221. .setDelay(this._tweenConfig.delay)
  17222. .setEase(this._tweenConfig.easeType)
  17223. .setTarget(this)
  17224. .onUpdate(this.__tweenUpdate, this)
  17225. .onComplete(this.__tweenComplete, this);
  17226. }
  17227. }
  17228. else {
  17229. this._owner._gearLocked = true;
  17230. this._owner.setPosition(ex, ey);
  17231. this._owner._gearLocked = false;
  17232. }
  17233. };
  17234. GearXY.prototype.__tweenUpdate = function (tweener) {
  17235. this._owner._gearLocked = true;
  17236. this._owner.setPosition(tweener.value.x, tweener.value.y);
  17237. this._owner._gearLocked = false;
  17238. };
  17239. GearXY.prototype.__tweenComplete = function () {
  17240. if (this._tweenConfig._displayLockToken != 0) {
  17241. this._owner.releaseDisplayLock(this._tweenConfig._displayLockToken);
  17242. this._tweenConfig._displayLockToken = 0;
  17243. }
  17244. this._tweenConfig._tweener = null;
  17245. };
  17246. GearXY.prototype.updateState = function () {
  17247. var gv = this._storage[this._controller.selectedPageId];
  17248. if (!gv)
  17249. this._storage[this._controller.selectedPageId] = gv = {};
  17250. gv.x = this._owner.x;
  17251. gv.y = this._owner.y;
  17252. gv.px = this._owner.x / this._owner.parent.width;
  17253. gv.py = this._owner.y / this._owner.parent.height;
  17254. };
  17255. GearXY.prototype.updateFromRelations = function (dx, dy) {
  17256. if (this._controller == null || this._storage == null || this.positionsInPercent)
  17257. return;
  17258. for (var key in this._storage) {
  17259. var pt = this._storage[key];
  17260. pt.x += dx;
  17261. pt.y += dy;
  17262. }
  17263. this._default.x += dx;
  17264. this._default.y += dy;
  17265. this.updateState();
  17266. };
  17267. return GearXY;
  17268. }(fgui.GearBase));
  17269. fgui.GearXY = GearXY;
  17270. })(fgui || (fgui = {}));
  17271. (function (fgui) {
  17272. var _PiOver2 = Math.PI * 0.5;
  17273. var _TwoPi = Math.PI * 2;
  17274. function evaluateEase(easeType, time, duration, overshootOrAmplitude, period) {
  17275. switch (easeType) {
  17276. case fgui.EaseType.Linear:
  17277. return time / duration;
  17278. case fgui.EaseType.SineIn:
  17279. return -Math.cos(time / duration * _PiOver2) + 1;
  17280. case fgui.EaseType.SineOut:
  17281. return Math.sin(time / duration * _PiOver2);
  17282. case fgui.EaseType.SineInOut:
  17283. return -0.5 * (Math.cos(Math.PI * time / duration) - 1);
  17284. case fgui.EaseType.QuadIn:
  17285. return (time /= duration) * time;
  17286. case fgui.EaseType.QuadOut:
  17287. return -(time /= duration) * (time - 2);
  17288. case fgui.EaseType.QuadInOut:
  17289. if ((time /= duration * 0.5) < 1)
  17290. return 0.5 * time * time;
  17291. return -0.5 * ((--time) * (time - 2) - 1);
  17292. case fgui.EaseType.CubicIn:
  17293. return (time /= duration) * time * time;
  17294. case fgui.EaseType.CubicOut:
  17295. return ((time = time / duration - 1) * time * time + 1);
  17296. case fgui.EaseType.CubicInOut:
  17297. if ((time /= duration * 0.5) < 1)
  17298. return 0.5 * time * time * time;
  17299. return 0.5 * ((time -= 2) * time * time + 2);
  17300. case fgui.EaseType.QuartIn:
  17301. return (time /= duration) * time * time * time;
  17302. case fgui.EaseType.QuartOut:
  17303. return -((time = time / duration - 1) * time * time * time - 1);
  17304. case fgui.EaseType.QuartInOut:
  17305. if ((time /= duration * 0.5) < 1)
  17306. return 0.5 * time * time * time * time;
  17307. return -0.5 * ((time -= 2) * time * time * time - 2);
  17308. case fgui.EaseType.QuintIn:
  17309. return (time /= duration) * time * time * time * time;
  17310. case fgui.EaseType.QuintOut:
  17311. return ((time = time / duration - 1) * time * time * time * time + 1);
  17312. case fgui.EaseType.QuintInOut:
  17313. if ((time /= duration * 0.5) < 1)
  17314. return 0.5 * time * time * time * time * time;
  17315. return 0.5 * ((time -= 2) * time * time * time * time + 2);
  17316. case fgui.EaseType.ExpoIn:
  17317. return (time == 0) ? 0 : Math.pow(2, 10 * (time / duration - 1));
  17318. case fgui.EaseType.ExpoOut:
  17319. if (time == duration)
  17320. return 1;
  17321. return (-Math.pow(2, -10 * time / duration) + 1);
  17322. case fgui.EaseType.ExpoInOut:
  17323. if (time == 0)
  17324. return 0;
  17325. if (time == duration)
  17326. return 1;
  17327. if ((time /= duration * 0.5) < 1)
  17328. return 0.5 * Math.pow(2, 10 * (time - 1));
  17329. return 0.5 * (-Math.pow(2, -10 * --time) + 2);
  17330. case fgui.EaseType.CircIn:
  17331. return -(Math.sqrt(1 - (time /= duration) * time) - 1);
  17332. case fgui.EaseType.CircOut:
  17333. return Math.sqrt(1 - (time = time / duration - 1) * time);
  17334. case fgui.EaseType.CircInOut:
  17335. if ((time /= duration * 0.5) < 1)
  17336. return -0.5 * (Math.sqrt(1 - time * time) - 1);
  17337. return 0.5 * (Math.sqrt(1 - (time -= 2) * time) + 1);
  17338. case fgui.EaseType.ElasticIn:
  17339. var s0;
  17340. if (time == 0)
  17341. return 0;
  17342. if ((time /= duration) == 1)
  17343. return 1;
  17344. if (period == 0)
  17345. period = duration * 0.3;
  17346. if (overshootOrAmplitude < 1) {
  17347. overshootOrAmplitude = 1;
  17348. s0 = period / 4;
  17349. }
  17350. else
  17351. s0 = period / _TwoPi * Math.asin(1 / overshootOrAmplitude);
  17352. return -(overshootOrAmplitude * Math.pow(2, 10 * (time -= 1)) * Math.sin((time * duration - s0) * _TwoPi / period));
  17353. case fgui.EaseType.ElasticOut:
  17354. var s1;
  17355. if (time == 0)
  17356. return 0;
  17357. if ((time /= duration) == 1)
  17358. return 1;
  17359. if (period == 0)
  17360. period = duration * 0.3;
  17361. if (overshootOrAmplitude < 1) {
  17362. overshootOrAmplitude = 1;
  17363. s1 = period / 4;
  17364. }
  17365. else
  17366. s1 = period / _TwoPi * Math.asin(1 / overshootOrAmplitude);
  17367. return (overshootOrAmplitude * Math.pow(2, -10 * time) * Math.sin((time * duration - s1) * _TwoPi / period) + 1);
  17368. case fgui.EaseType.ElasticInOut:
  17369. var s;
  17370. if (time == 0)
  17371. return 0;
  17372. if ((time /= duration * 0.5) == 2)
  17373. return 1;
  17374. if (period == 0)
  17375. period = duration * (0.3 * 1.5);
  17376. if (overshootOrAmplitude < 1) {
  17377. overshootOrAmplitude = 1;
  17378. s = period / 4;
  17379. }
  17380. else
  17381. s = period / _TwoPi * Math.asin(1 / overshootOrAmplitude);
  17382. if (time < 1)
  17383. return -0.5 * (overshootOrAmplitude * Math.pow(2, 10 * (time -= 1)) * Math.sin((time * duration - s) * _TwoPi / period));
  17384. return overshootOrAmplitude * Math.pow(2, -10 * (time -= 1)) * Math.sin((time * duration - s) * _TwoPi / period) * 0.5 + 1;
  17385. case fgui.EaseType.BackIn:
  17386. return (time /= duration) * time * ((overshootOrAmplitude + 1) * time - overshootOrAmplitude);
  17387. case fgui.EaseType.BackOut:
  17388. return ((time = time / duration - 1) * time * ((overshootOrAmplitude + 1) * time + overshootOrAmplitude) + 1);
  17389. case fgui.EaseType.BackInOut:
  17390. if ((time /= duration * 0.5) < 1)
  17391. return 0.5 * (time * time * (((overshootOrAmplitude *= (1.525)) + 1) * time - overshootOrAmplitude));
  17392. return 0.5 * ((time -= 2) * time * (((overshootOrAmplitude *= (1.525)) + 1) * time + overshootOrAmplitude) + 2);
  17393. case fgui.EaseType.BounceIn:
  17394. return bounce_easeIn(time, duration);
  17395. case fgui.EaseType.BounceOut:
  17396. return bounce_easeOut(time, duration);
  17397. case fgui.EaseType.BounceInOut:
  17398. return bounce_easeInOut(time, duration);
  17399. default:
  17400. return -(time /= duration) * (time - 2);
  17401. }
  17402. }
  17403. fgui.evaluateEase = evaluateEase;
  17404. function bounce_easeIn(time, duration) {
  17405. return 1 - bounce_easeOut(duration - time, duration);
  17406. }
  17407. function bounce_easeOut(time, duration) {
  17408. if ((time /= duration) < (1 / 2.75)) {
  17409. return (7.5625 * time * time);
  17410. }
  17411. if (time < (2 / 2.75)) {
  17412. return (7.5625 * (time -= (1.5 / 2.75)) * time + 0.75);
  17413. }
  17414. if (time < (2.5 / 2.75)) {
  17415. return (7.5625 * (time -= (2.25 / 2.75)) * time + 0.9375);
  17416. }
  17417. return (7.5625 * (time -= (2.625 / 2.75)) * time + 0.984375);
  17418. }
  17419. function bounce_easeInOut(time, duration) {
  17420. if (time < duration * 0.5) {
  17421. return bounce_easeIn(time * 2, duration) * 0.5;
  17422. }
  17423. return bounce_easeOut(time * 2 - duration, duration) * 0.5 + 0.5;
  17424. }
  17425. })(fgui || (fgui = {}));
  17426. (function (fgui) {
  17427. var EaseType = (function () {
  17428. function EaseType() {
  17429. }
  17430. EaseType.Linear = 0;
  17431. EaseType.SineIn = 1;
  17432. EaseType.SineOut = 2;
  17433. EaseType.SineInOut = 3;
  17434. EaseType.QuadIn = 4;
  17435. EaseType.QuadOut = 5;
  17436. EaseType.QuadInOut = 6;
  17437. EaseType.CubicIn = 7;
  17438. EaseType.CubicOut = 8;
  17439. EaseType.CubicInOut = 9;
  17440. EaseType.QuartIn = 10;
  17441. EaseType.QuartOut = 11;
  17442. EaseType.QuartInOut = 12;
  17443. EaseType.QuintIn = 13;
  17444. EaseType.QuintOut = 14;
  17445. EaseType.QuintInOut = 15;
  17446. EaseType.ExpoIn = 16;
  17447. EaseType.ExpoOut = 17;
  17448. EaseType.ExpoInOut = 18;
  17449. EaseType.CircIn = 19;
  17450. EaseType.CircOut = 20;
  17451. EaseType.CircInOut = 21;
  17452. EaseType.ElasticIn = 22;
  17453. EaseType.ElasticOut = 23;
  17454. EaseType.ElasticInOut = 24;
  17455. EaseType.BackIn = 25;
  17456. EaseType.BackOut = 26;
  17457. EaseType.BackInOut = 27;
  17458. EaseType.BounceIn = 28;
  17459. EaseType.BounceOut = 29;
  17460. EaseType.BounceInOut = 30;
  17461. EaseType.Custom = 31;
  17462. return EaseType;
  17463. }());
  17464. fgui.EaseType = EaseType;
  17465. })(fgui || (fgui = {}));
  17466. (function (fgui) {
  17467. var GPath = (function () {
  17468. function GPath() {
  17469. this._segments = new Array();
  17470. this._points = new Array();
  17471. }
  17472. Object.defineProperty(GPath.prototype, "length", {
  17473. get: function () {
  17474. return this._fullLength;
  17475. },
  17476. enumerable: false,
  17477. configurable: true
  17478. });
  17479. GPath.prototype.create = function (pt1, pt2, pt3, pt4) {
  17480. var points;
  17481. if (Array.isArray(pt1))
  17482. points = pt1;
  17483. else {
  17484. points = new Array();
  17485. points.push(pt1);
  17486. points.push(pt2);
  17487. if (pt3)
  17488. points.push(pt3);
  17489. if (pt4)
  17490. points.push(pt4);
  17491. }
  17492. this._segments.length = 0;
  17493. this._points.length = 0;
  17494. this._fullLength = 0;
  17495. var cnt = points.length;
  17496. if (cnt == 0)
  17497. return;
  17498. var splinePoints = s_points;
  17499. splinePoints.length = 0;
  17500. var prev = points[0];
  17501. if (prev.curveType == fgui.CurveType.CRSpline)
  17502. splinePoints.push(new cc.Vec2(prev.x, prev.y));
  17503. for (var i = 1; i < cnt; i++) {
  17504. var current = points[i];
  17505. if (prev.curveType != fgui.CurveType.CRSpline) {
  17506. var seg = {};
  17507. seg.type = prev.curveType;
  17508. seg.ptStart = this._points.length;
  17509. if (prev.curveType == fgui.CurveType.Straight) {
  17510. seg.ptCount = 2;
  17511. this._points.push(new cc.Vec2(prev.x, prev.y));
  17512. this._points.push(new cc.Vec2(current.x, current.y));
  17513. }
  17514. else if (prev.curveType == fgui.CurveType.Bezier) {
  17515. seg.ptCount = 3;
  17516. this._points.push(new cc.Vec2(prev.x, prev.y));
  17517. this._points.push(new cc.Vec2(current.x, current.y));
  17518. this._points.push(new cc.Vec2(prev.control1_x, prev.control1_y));
  17519. }
  17520. else if (prev.curveType == fgui.CurveType.CubicBezier) {
  17521. seg.ptCount = 4;
  17522. this._points.push(new cc.Vec2(prev.x, prev.y));
  17523. this._points.push(new cc.Vec2(current.x, current.y));
  17524. this._points.push(new cc.Vec2(prev.control1_x, prev.control1_y));
  17525. this._points.push(new cc.Vec2(prev.control2_x, prev.control2_y));
  17526. }
  17527. seg.length = fgui.ToolSet.distance(prev.x, prev.y, current.x, current.y);
  17528. this._fullLength += seg.length;
  17529. this._segments.push(seg);
  17530. }
  17531. if (current.curveType != fgui.CurveType.CRSpline) {
  17532. if (splinePoints.length > 0) {
  17533. splinePoints.push(new cc.Vec2(current.x, current.y));
  17534. this.createSplineSegment();
  17535. }
  17536. }
  17537. else
  17538. splinePoints.push(new cc.Vec2(current.x, current.y));
  17539. prev = current;
  17540. }
  17541. if (splinePoints.length > 1)
  17542. this.createSplineSegment();
  17543. };
  17544. GPath.prototype.createSplineSegment = function () {
  17545. var splinePoints = s_points;
  17546. var cnt = splinePoints.length;
  17547. splinePoints.splice(0, 0, splinePoints[0]);
  17548. splinePoints.push(splinePoints[cnt]);
  17549. splinePoints.push(splinePoints[cnt]);
  17550. cnt += 3;
  17551. var seg = {};
  17552. seg.type = fgui.CurveType.CRSpline;
  17553. seg.ptStart = this._points.length;
  17554. seg.ptCount = cnt;
  17555. this._points = this._points.concat(splinePoints);
  17556. seg.length = 0;
  17557. for (var i = 1; i < cnt; i++) {
  17558. seg.length += fgui.ToolSet.distance(splinePoints[i - 1].x, splinePoints[i - 1].y, splinePoints[i].x, splinePoints[i].y);
  17559. }
  17560. this._fullLength += seg.length;
  17561. this._segments.push(seg);
  17562. splinePoints.length = 0;
  17563. };
  17564. GPath.prototype.clear = function () {
  17565. this._segments.length = 0;
  17566. this._points.length = 0;
  17567. };
  17568. GPath.prototype.getPointAt = function (t, result) {
  17569. if (!result)
  17570. result = new cc.Vec2();
  17571. else
  17572. result.x = result.y = 0;
  17573. t = fgui.ToolSet.clamp01(t);
  17574. var cnt = this._segments.length;
  17575. if (cnt == 0) {
  17576. return result;
  17577. }
  17578. var seg;
  17579. if (t == 1) {
  17580. seg = this._segments[cnt - 1];
  17581. if (seg.type == fgui.CurveType.Straight) {
  17582. result.x = fgui.ToolSet.lerp(this._points[seg.ptStart].x, this._points[seg.ptStart + 1].x, t);
  17583. result.y = fgui.ToolSet.lerp(this._points[seg.ptStart].y, this._points[seg.ptStart + 1].y, t);
  17584. return result;
  17585. }
  17586. else if (seg.type == fgui.CurveType.Bezier || seg.type == fgui.CurveType.CubicBezier)
  17587. return this.onBezierCurve(seg.ptStart, seg.ptCount, t, result);
  17588. else
  17589. return this.onCRSplineCurve(seg.ptStart, seg.ptCount, t, result);
  17590. }
  17591. var len = t * this._fullLength;
  17592. for (var i = 0; i < cnt; i++) {
  17593. seg = this._segments[i];
  17594. len -= seg.length;
  17595. if (len < 0) {
  17596. t = 1 + len / seg.length;
  17597. if (seg.type == fgui.CurveType.Straight) {
  17598. result.x = fgui.ToolSet.lerp(this._points[seg.ptStart].x, this._points[seg.ptStart + 1].x, t);
  17599. result.y = fgui.ToolSet.lerp(this._points[seg.ptStart].y, this._points[seg.ptStart + 1].y, t);
  17600. }
  17601. else if (seg.type == fgui.CurveType.Bezier || seg.type == fgui.CurveType.CubicBezier)
  17602. result = this.onBezierCurve(seg.ptStart, seg.ptCount, t, result);
  17603. else
  17604. result = this.onCRSplineCurve(seg.ptStart, seg.ptCount, t, result);
  17605. break;
  17606. }
  17607. }
  17608. return result;
  17609. };
  17610. Object.defineProperty(GPath.prototype, "segmentCount", {
  17611. get: function () {
  17612. return this._segments.length;
  17613. },
  17614. enumerable: false,
  17615. configurable: true
  17616. });
  17617. GPath.prototype.getAnchorsInSegment = function (segmentIndex, points) {
  17618. if (points == null)
  17619. points = new Array();
  17620. var seg = this._segments[segmentIndex];
  17621. for (var i = 0; i < seg.ptCount; i++)
  17622. points.push(new cc.Vec2(this._points[seg.ptStart + i].x, this._points[seg.ptStart + i].y));
  17623. return points;
  17624. };
  17625. GPath.prototype.getPointsInSegment = function (segmentIndex, t0, t1, points, ts, pointDensity) {
  17626. if (points == null)
  17627. points = new Array();
  17628. if (!pointDensity || isNaN(pointDensity))
  17629. pointDensity = 0.1;
  17630. if (ts)
  17631. ts.push(t0);
  17632. var seg = this._segments[segmentIndex];
  17633. if (seg.type == fgui.CurveType.Straight) {
  17634. points.push(new cc.Vec2(fgui.ToolSet.lerp(this._points[seg.ptStart].x, this._points[seg.ptStart + 1].x, t0), fgui.ToolSet.lerp(this._points[seg.ptStart].y, this._points[seg.ptStart + 1].y, t0)));
  17635. points.push(new cc.Vec2(fgui.ToolSet.lerp(this._points[seg.ptStart].x, this._points[seg.ptStart + 1].x, t1), fgui.ToolSet.lerp(this._points[seg.ptStart].y, this._points[seg.ptStart + 1].y, t1)));
  17636. }
  17637. else {
  17638. var func;
  17639. if (seg.type == fgui.CurveType.Bezier || seg.type == fgui.CurveType.CubicBezier)
  17640. func = this.onBezierCurve;
  17641. else
  17642. func = this.onCRSplineCurve;
  17643. points.push(func.call(this, seg.ptStart, seg.ptCount, t0, new cc.Vec2()));
  17644. var SmoothAmount = Math.min(seg.length * pointDensity, 50);
  17645. for (var j = 0; j <= SmoothAmount; j++) {
  17646. var t = j / SmoothAmount;
  17647. if (t > t0 && t < t1) {
  17648. points.push(func.call(this, seg.ptStart, seg.ptCount, t, new cc.Vec2()));
  17649. if (ts != null)
  17650. ts.push(t);
  17651. }
  17652. }
  17653. points.push(func.call(this, seg.ptStart, seg.ptCount, t1, new cc.Vec2()));
  17654. }
  17655. if (ts != null)
  17656. ts.push(t1);
  17657. return points;
  17658. };
  17659. GPath.prototype.getAllPoints = function (points, ts, pointDensity) {
  17660. if (points == null)
  17661. points = new Array();
  17662. if (!pointDensity || isNaN(pointDensity))
  17663. pointDensity = 0.1;
  17664. var cnt = this._segments.length;
  17665. for (var i = 0; i < cnt; i++)
  17666. this.getPointsInSegment(i, 0, 1, points, ts, pointDensity);
  17667. return points;
  17668. };
  17669. GPath.prototype.onCRSplineCurve = function (ptStart, ptCount, t, result) {
  17670. var adjustedIndex = Math.floor(t * (ptCount - 4)) + ptStart;
  17671. var p0x = this._points[adjustedIndex].x;
  17672. var p0y = this._points[adjustedIndex].y;
  17673. var p1x = this._points[adjustedIndex + 1].x;
  17674. var p1y = this._points[adjustedIndex + 1].y;
  17675. var p2x = this._points[adjustedIndex + 2].x;
  17676. var p2y = this._points[adjustedIndex + 2].y;
  17677. var p3x = this._points[adjustedIndex + 3].x;
  17678. var p3y = this._points[adjustedIndex + 3].y;
  17679. var adjustedT = (t == 1) ? 1 : fgui.ToolSet.repeat(t * (ptCount - 4), 1);
  17680. var t0 = ((-adjustedT + 2) * adjustedT - 1) * adjustedT * 0.5;
  17681. var t1 = (((3 * adjustedT - 5) * adjustedT) * adjustedT + 2) * 0.5;
  17682. var t2 = ((-3 * adjustedT + 4) * adjustedT + 1) * adjustedT * 0.5;
  17683. var t3 = ((adjustedT - 1) * adjustedT * adjustedT) * 0.5;
  17684. result.x = p0x * t0 + p1x * t1 + p2x * t2 + p3x * t3;
  17685. result.y = p0y * t0 + p1y * t1 + p2y * t2 + p3y * t3;
  17686. return result;
  17687. };
  17688. GPath.prototype.onBezierCurve = function (ptStart, ptCount, t, result) {
  17689. var t2 = 1 - t;
  17690. var p0x = this._points[ptStart].x;
  17691. var p0y = this._points[ptStart].y;
  17692. var p1x = this._points[ptStart + 1].x;
  17693. var p1y = this._points[ptStart + 1].y;
  17694. var cp0x = this._points[ptStart + 2].x;
  17695. var cp0y = this._points[ptStart + 2].y;
  17696. if (ptCount == 4) {
  17697. var cp1x = this._points[ptStart + 3].x;
  17698. var cp1y = this._points[ptStart + 3].y;
  17699. result.x = t2 * t2 * t2 * p0x + 3 * t2 * t2 * t * cp0x + 3 * t2 * t * t * cp1x + t * t * t * p1x;
  17700. result.y = t2 * t2 * t2 * p0y + 3 * t2 * t2 * t * cp0y + 3 * t2 * t * t * cp1y + t * t * t * p1y;
  17701. }
  17702. else {
  17703. result.x = t2 * t2 * p0x + 2 * t2 * t * cp0x + t * t * p1x;
  17704. result.y = t2 * t2 * p0y + 2 * t2 * t * cp0y + t * t * p1y;
  17705. }
  17706. return result;
  17707. };
  17708. return GPath;
  17709. }());
  17710. fgui.GPath = GPath;
  17711. var s_points = new Array();
  17712. })(fgui || (fgui = {}));
  17713. (function (fgui) {
  17714. var CurveType;
  17715. (function (CurveType) {
  17716. CurveType[CurveType["CRSpline"] = 0] = "CRSpline";
  17717. CurveType[CurveType["Bezier"] = 1] = "Bezier";
  17718. CurveType[CurveType["CubicBezier"] = 2] = "CubicBezier";
  17719. CurveType[CurveType["Straight"] = 3] = "Straight";
  17720. })(CurveType = fgui.CurveType || (fgui.CurveType = {}));
  17721. var GPathPoint = (function () {
  17722. function GPathPoint() {
  17723. this.x = 0;
  17724. this.y = 0;
  17725. this.control1_x = 0;
  17726. this.control1_y = 0;
  17727. this.control2_x = 0;
  17728. this.control2_y = 0;
  17729. this.curveType = 0;
  17730. }
  17731. GPathPoint.newPoint = function (x, y, curveType) {
  17732. if (x === void 0) { x = 0; }
  17733. if (y === void 0) { y = 0; }
  17734. if (curveType === void 0) { curveType = 0; }
  17735. var pt = new GPathPoint();
  17736. pt.x = x;
  17737. pt.y = y;
  17738. pt.control1_x = 0;
  17739. pt.control1_y = 0;
  17740. pt.control2_x = 0;
  17741. pt.control2_y = 0;
  17742. pt.curveType = curveType;
  17743. return pt;
  17744. };
  17745. GPathPoint.newBezierPoint = function (x, y, control1_x, control1_y) {
  17746. if (x === void 0) { x = 0; }
  17747. if (y === void 0) { y = 0; }
  17748. if (control1_x === void 0) { control1_x = 0; }
  17749. if (control1_y === void 0) { control1_y = 0; }
  17750. var pt = new GPathPoint();
  17751. pt.x = x;
  17752. pt.y = y;
  17753. pt.control1_x = control1_x;
  17754. pt.control1_y = control1_y;
  17755. pt.control2_x = 0;
  17756. pt.control2_y = 0;
  17757. pt.curveType = CurveType.Bezier;
  17758. return pt;
  17759. };
  17760. GPathPoint.newCubicBezierPoint = function (x, y, control1_x, control1_y, control2_x, control2_y) {
  17761. if (x === void 0) { x = 0; }
  17762. if (y === void 0) { y = 0; }
  17763. if (control1_x === void 0) { control1_x = 0; }
  17764. if (control1_y === void 0) { control1_y = 0; }
  17765. if (control2_x === void 0) { control2_x = 0; }
  17766. if (control2_y === void 0) { control2_y = 0; }
  17767. var pt = new GPathPoint();
  17768. pt.x = x;
  17769. pt.y = y;
  17770. pt.control1_x = control1_x;
  17771. pt.control1_y = control1_y;
  17772. pt.control2_x = control2_x;
  17773. pt.control2_y = control2_y;
  17774. pt.curveType = CurveType.CubicBezier;
  17775. return pt;
  17776. };
  17777. GPathPoint.prototype.clone = function () {
  17778. var ret = new GPathPoint();
  17779. ret.x = this.x;
  17780. ret.y = this.y;
  17781. ret.control1_x = this.control1_x;
  17782. ret.control1_y = this.control1_y;
  17783. ret.control2_x = this.control2_x;
  17784. ret.control2_y = this.control2_y;
  17785. ret.curveType = this.curveType;
  17786. return ret;
  17787. };
  17788. return GPathPoint;
  17789. }());
  17790. fgui.GPathPoint = GPathPoint;
  17791. })(fgui || (fgui = {}));
  17792. (function (fgui) {
  17793. var GTween = (function () {
  17794. function GTween() {
  17795. }
  17796. GTween.to = function (start, end, duration) {
  17797. return fgui.TweenManager.createTween()._to(start, end, duration);
  17798. };
  17799. GTween.to2 = function (start, start2, end, end2, duration) {
  17800. return fgui.TweenManager.createTween()._to2(start, start2, end, end2, duration);
  17801. };
  17802. GTween.to3 = function (start, start2, start3, end, end2, end3, duration) {
  17803. return fgui.TweenManager.createTween()._to3(start, start2, start3, end, end2, end3, duration);
  17804. };
  17805. GTween.to4 = function (start, start2, start3, start4, end, end2, end3, end4, duration) {
  17806. return fgui.TweenManager.createTween()._to4(start, start2, start3, start4, end, end2, end3, end4, duration);
  17807. };
  17808. GTween.toColor = function (start, end, duration) {
  17809. return fgui.TweenManager.createTween()._toColor(start, end, duration);
  17810. };
  17811. GTween.delayedCall = function (delay) {
  17812. return fgui.TweenManager.createTween().setDelay(delay);
  17813. };
  17814. GTween.shake = function (startX, startY, amplitude, duration) {
  17815. return fgui.TweenManager.createTween()._shake(startX, startY, amplitude, duration);
  17816. };
  17817. GTween.isTweening = function (target, propType) {
  17818. return fgui.TweenManager.isTweening(target, propType);
  17819. };
  17820. GTween.kill = function (target, complete, propType) {
  17821. fgui.TweenManager.killTweens(target, complete, propType);
  17822. };
  17823. GTween.getTween = function (target, propType) {
  17824. return fgui.TweenManager.getTween(target, propType);
  17825. };
  17826. GTween.catchCallbackExceptions = true;
  17827. return GTween;
  17828. }());
  17829. fgui.GTween = GTween;
  17830. })(fgui || (fgui = {}));
  17831. (function (fgui) {
  17832. var GTweener = (function () {
  17833. function GTweener() {
  17834. this._startValue = new fgui.TweenValue();
  17835. this._endValue = new fgui.TweenValue();
  17836. this._value = new fgui.TweenValue();
  17837. this._deltaValue = new fgui.TweenValue();
  17838. this._reset();
  17839. }
  17840. GTweener.prototype.setDelay = function (value) {
  17841. this._delay = value;
  17842. return this;
  17843. };
  17844. Object.defineProperty(GTweener.prototype, "delay", {
  17845. get: function () {
  17846. return this._delay;
  17847. },
  17848. enumerable: false,
  17849. configurable: true
  17850. });
  17851. GTweener.prototype.setDuration = function (value) {
  17852. this._duration = value;
  17853. return this;
  17854. };
  17855. Object.defineProperty(GTweener.prototype, "duration", {
  17856. get: function () {
  17857. return this._duration;
  17858. },
  17859. enumerable: false,
  17860. configurable: true
  17861. });
  17862. GTweener.prototype.setBreakpoint = function (value) {
  17863. this._breakpoint = value;
  17864. return this;
  17865. };
  17866. GTweener.prototype.setEase = function (value) {
  17867. this._easeType = value;
  17868. return this;
  17869. };
  17870. GTweener.prototype.setEasePeriod = function (value) {
  17871. this._easePeriod = value;
  17872. return this;
  17873. };
  17874. GTweener.prototype.setEaseOvershootOrAmplitude = function (value) {
  17875. this._easeOvershootOrAmplitude = value;
  17876. return this;
  17877. };
  17878. GTweener.prototype.setRepeat = function (repeat, yoyo) {
  17879. this._repeat = repeat;
  17880. this._yoyo = yoyo;
  17881. return this;
  17882. };
  17883. Object.defineProperty(GTweener.prototype, "repeat", {
  17884. get: function () {
  17885. return this._repeat;
  17886. },
  17887. enumerable: false,
  17888. configurable: true
  17889. });
  17890. GTweener.prototype.setTimeScale = function (value) {
  17891. this._timeScale = value;
  17892. return this;
  17893. };
  17894. GTweener.prototype.setSnapping = function (value) {
  17895. this._snapping = value;
  17896. return this;
  17897. };
  17898. GTweener.prototype.setTarget = function (value, propType) {
  17899. this._target = value;
  17900. this._propType = propType;
  17901. if (value instanceof fgui.GObject)
  17902. this._node = value.node;
  17903. else if (value instanceof cc.Node)
  17904. this._node = value;
  17905. return this;
  17906. };
  17907. Object.defineProperty(GTweener.prototype, "target", {
  17908. get: function () {
  17909. return this._target;
  17910. },
  17911. enumerable: false,
  17912. configurable: true
  17913. });
  17914. GTweener.prototype.setPath = function (value) {
  17915. this._path = value;
  17916. return this;
  17917. };
  17918. GTweener.prototype.setUserData = function (value) {
  17919. this._userData = value;
  17920. return this;
  17921. };
  17922. Object.defineProperty(GTweener.prototype, "userData", {
  17923. get: function () {
  17924. return this._userData;
  17925. },
  17926. enumerable: false,
  17927. configurable: true
  17928. });
  17929. GTweener.prototype.onUpdate = function (callback, target) {
  17930. this._onUpdate = callback;
  17931. this._onUpdateCaller = target;
  17932. return this;
  17933. };
  17934. GTweener.prototype.onStart = function (callback, target) {
  17935. this._onStart = callback;
  17936. this._onStartCaller = target;
  17937. return this;
  17938. };
  17939. GTweener.prototype.onComplete = function (callback, target) {
  17940. this._onComplete = callback;
  17941. this._onCompleteCaller = target;
  17942. return this;
  17943. };
  17944. Object.defineProperty(GTweener.prototype, "startValue", {
  17945. get: function () {
  17946. return this._startValue;
  17947. },
  17948. enumerable: false,
  17949. configurable: true
  17950. });
  17951. Object.defineProperty(GTweener.prototype, "endValue", {
  17952. get: function () {
  17953. return this._endValue;
  17954. },
  17955. enumerable: false,
  17956. configurable: true
  17957. });
  17958. Object.defineProperty(GTweener.prototype, "value", {
  17959. get: function () {
  17960. return this._value;
  17961. },
  17962. enumerable: false,
  17963. configurable: true
  17964. });
  17965. Object.defineProperty(GTweener.prototype, "deltaValue", {
  17966. get: function () {
  17967. return this._deltaValue;
  17968. },
  17969. enumerable: false,
  17970. configurable: true
  17971. });
  17972. Object.defineProperty(GTweener.prototype, "normalizedTime", {
  17973. get: function () {
  17974. return this._normalizedTime;
  17975. },
  17976. enumerable: false,
  17977. configurable: true
  17978. });
  17979. Object.defineProperty(GTweener.prototype, "completed", {
  17980. get: function () {
  17981. return this._ended != 0;
  17982. },
  17983. enumerable: false,
  17984. configurable: true
  17985. });
  17986. Object.defineProperty(GTweener.prototype, "allCompleted", {
  17987. get: function () {
  17988. return this._ended == 1;
  17989. },
  17990. enumerable: false,
  17991. configurable: true
  17992. });
  17993. GTweener.prototype.setPaused = function (paused) {
  17994. this._paused = paused;
  17995. return this;
  17996. };
  17997. GTweener.prototype.seek = function (time) {
  17998. if (this._killed)
  17999. return;
  18000. this._elapsedTime = time;
  18001. if (this._elapsedTime < this._delay) {
  18002. if (this._started)
  18003. this._elapsedTime = this._delay;
  18004. else
  18005. return;
  18006. }
  18007. this.update();
  18008. };
  18009. GTweener.prototype.kill = function (complete) {
  18010. if (this._killed)
  18011. return;
  18012. if (complete) {
  18013. if (this._ended == 0) {
  18014. if (this._breakpoint >= 0)
  18015. this._elapsedTime = this._delay + this._breakpoint;
  18016. else if (this._repeat >= 0)
  18017. this._elapsedTime = this._delay + this._duration * (this._repeat + 1);
  18018. else
  18019. this._elapsedTime = this._delay + this._duration * 2;
  18020. this.update();
  18021. }
  18022. this.callCompleteCallback();
  18023. }
  18024. this._killed = true;
  18025. };
  18026. GTweener.prototype._to = function (start, end, duration) {
  18027. this._valueSize = 1;
  18028. this._startValue.x = start;
  18029. this._endValue.x = end;
  18030. this._duration = duration;
  18031. return this;
  18032. };
  18033. GTweener.prototype._to2 = function (start, start2, end, end2, duration) {
  18034. this._valueSize = 2;
  18035. this._startValue.x = start;
  18036. this._endValue.x = end;
  18037. this._startValue.y = start2;
  18038. this._endValue.y = end2;
  18039. this._duration = duration;
  18040. return this;
  18041. };
  18042. GTweener.prototype._to3 = function (start, start2, start3, end, end2, end3, duration) {
  18043. this._valueSize = 3;
  18044. this._startValue.x = start;
  18045. this._endValue.x = end;
  18046. this._startValue.y = start2;
  18047. this._endValue.y = end2;
  18048. this._startValue.z = start3;
  18049. this._endValue.z = end3;
  18050. this._duration = duration;
  18051. return this;
  18052. };
  18053. GTweener.prototype._to4 = function (start, start2, start3, start4, end, end2, end3, end4, duration) {
  18054. this._valueSize = 4;
  18055. this._startValue.x = start;
  18056. this._endValue.x = end;
  18057. this._startValue.y = start2;
  18058. this._endValue.y = end2;
  18059. this._startValue.z = start3;
  18060. this._endValue.z = end3;
  18061. this._startValue.w = start4;
  18062. this._endValue.w = end4;
  18063. this._duration = duration;
  18064. return this;
  18065. };
  18066. GTweener.prototype._toColor = function (start, end, duration) {
  18067. this._valueSize = 5;
  18068. this._startValue.color = start;
  18069. this._endValue.color = end;
  18070. this._duration = duration;
  18071. return this;
  18072. };
  18073. GTweener.prototype._shake = function (startX, startY, amplitude, duration) {
  18074. this._valueSize = 6;
  18075. this._startValue.x = startX;
  18076. this._startValue.y = startY;
  18077. this._startValue.w = amplitude;
  18078. this._duration = duration;
  18079. return this;
  18080. };
  18081. GTweener.prototype._init = function () {
  18082. this._delay = 0;
  18083. this._duration = 0;
  18084. this._breakpoint = -1;
  18085. this._easeType = fgui.EaseType.QuadOut;
  18086. this._timeScale = 1;
  18087. this._easePeriod = 0;
  18088. this._easeOvershootOrAmplitude = 1.70158;
  18089. this._snapping = false;
  18090. this._repeat = 0;
  18091. this._yoyo = false;
  18092. this._valueSize = 0;
  18093. this._started = false;
  18094. this._paused = false;
  18095. this._killed = false;
  18096. this._elapsedTime = 0;
  18097. this._normalizedTime = 0;
  18098. this._ended = 0;
  18099. };
  18100. GTweener.prototype._reset = function () {
  18101. this._target = null;
  18102. this._propType = null;
  18103. this._userData = null;
  18104. this._node = null;
  18105. this._path = null;
  18106. this._onStart = this._onUpdate = this._onComplete = null;
  18107. this._onStartCaller = this._onUpdateCaller = this._onCompleteCaller = null;
  18108. };
  18109. GTweener.prototype._update = function (dt) {
  18110. if (this._node && !cc.isValid(this._node)) {
  18111. this._killed = true;
  18112. return;
  18113. }
  18114. if (this._timeScale != 1)
  18115. dt *= this._timeScale;
  18116. if (dt == 0)
  18117. return;
  18118. if (this._ended != 0) {
  18119. this.callCompleteCallback();
  18120. this._killed = true;
  18121. return;
  18122. }
  18123. this._elapsedTime += dt;
  18124. this.update();
  18125. if (this._ended != 0) {
  18126. if (!this._killed) {
  18127. this.callCompleteCallback();
  18128. this._killed = true;
  18129. }
  18130. }
  18131. };
  18132. GTweener.prototype.update = function () {
  18133. this._ended = 0;
  18134. if (this._valueSize == 0) {
  18135. if (this._elapsedTime >= this._delay + this._duration)
  18136. this._ended = 1;
  18137. return;
  18138. }
  18139. if (!this._started) {
  18140. if (this._elapsedTime < this._delay)
  18141. return;
  18142. this._started = true;
  18143. this.callStartCallback();
  18144. if (this._killed)
  18145. return;
  18146. }
  18147. var reversed = false;
  18148. var tt = this._elapsedTime - this._delay;
  18149. if (this._breakpoint >= 0 && tt >= this._breakpoint) {
  18150. tt = this._breakpoint;
  18151. this._ended = 2;
  18152. }
  18153. if (this._repeat != 0) {
  18154. var round = Math.floor(tt / this._duration);
  18155. tt -= this._duration * round;
  18156. if (this._yoyo)
  18157. reversed = round % 2 == 1;
  18158. if (this._repeat > 0 && this._repeat - round < 0) {
  18159. if (this._yoyo)
  18160. reversed = this._repeat % 2 == 1;
  18161. tt = this._duration;
  18162. this._ended = 1;
  18163. }
  18164. }
  18165. else if (tt >= this._duration) {
  18166. tt = this._duration;
  18167. this._ended = 1;
  18168. }
  18169. this._normalizedTime = fgui.evaluateEase(this._easeType, reversed ? (this._duration - tt) : tt, this._duration, this._easeOvershootOrAmplitude, this._easePeriod);
  18170. this._value.setZero();
  18171. this._deltaValue.setZero();
  18172. if (this._valueSize == 6) {
  18173. if (this._ended == 0) {
  18174. var r = this._startValue.w * (1 - this._normalizedTime);
  18175. var rx = r * (Math.random() > 0.5 ? 1 : -1);
  18176. var ry = r * (Math.random() > 0.5 ? 1 : -1);
  18177. this._deltaValue.x = rx;
  18178. this._deltaValue.y = ry;
  18179. this._value.x = this._startValue.x + rx;
  18180. this._value.y = this._startValue.y + ry;
  18181. }
  18182. else {
  18183. this._value.x = this._startValue.x;
  18184. this._value.y = this._startValue.y;
  18185. }
  18186. }
  18187. else if (this._path) {
  18188. var pt = s_vec2;
  18189. this._path.getPointAt(this._normalizedTime, pt);
  18190. if (this._snapping) {
  18191. pt.x = Math.round(pt.x);
  18192. pt.y = Math.round(pt.y);
  18193. }
  18194. this._deltaValue.x = pt.x - this._value.x;
  18195. this._deltaValue.y = pt.y - this._value.y;
  18196. this._value.x = pt.x;
  18197. this._value.y = pt.y;
  18198. }
  18199. else {
  18200. var cnt = Math.min(this._valueSize, 4);
  18201. for (var i = 0; i < cnt; i++) {
  18202. var n1 = this._startValue.getField(i);
  18203. var n2 = this._endValue.getField(i);
  18204. var f = n1 + (n2 - n1) * this._normalizedTime;
  18205. if (this._snapping)
  18206. f = Math.round(f);
  18207. this._deltaValue.setField(i, f - this._value.getField(i));
  18208. this._value.setField(i, f);
  18209. }
  18210. }
  18211. if (this._target != null && this._propType != null) {
  18212. if (this._propType instanceof Function) {
  18213. switch (this._valueSize) {
  18214. case 1:
  18215. this._propType.call(this._target, this._value.x);
  18216. break;
  18217. case 2:
  18218. this._propType.call(this._target, this._value.x, this._value.y);
  18219. break;
  18220. case 3:
  18221. this._propType.call(this._target, this._value.x, this._value.y, this._value.z);
  18222. break;
  18223. case 4:
  18224. this._propType.call(this._target, this._value.x, this._value.y, this._value.z, this._value.w);
  18225. break;
  18226. case 5:
  18227. this._propType.call(this._target, this._value.color);
  18228. break;
  18229. case 6:
  18230. this._propType.call(this._target, this._value.x, this._value.y);
  18231. break;
  18232. }
  18233. }
  18234. else {
  18235. if (this._valueSize == 5)
  18236. this._target[this._propType] = this._value.color;
  18237. else
  18238. this._target[this._propType] = this._value.x;
  18239. }
  18240. }
  18241. this.callUpdateCallback();
  18242. };
  18243. GTweener.prototype.callStartCallback = function () {
  18244. if (this._onStart != null) {
  18245. try {
  18246. this._onStart.call(this._onStartCaller, this);
  18247. }
  18248. catch (err) {
  18249. console.log("FairyGUI: error in start callback > " + err);
  18250. }
  18251. }
  18252. };
  18253. GTweener.prototype.callUpdateCallback = function () {
  18254. if (this._onUpdate != null) {
  18255. try {
  18256. this._onUpdate.call(this._onUpdateCaller, this);
  18257. }
  18258. catch (err) {
  18259. console.log("FairyGUI: error in update callback > " + err);
  18260. }
  18261. }
  18262. };
  18263. GTweener.prototype.callCompleteCallback = function () {
  18264. if (this._onComplete != null) {
  18265. try {
  18266. this._onComplete.call(this._onCompleteCaller, this);
  18267. }
  18268. catch (err) {
  18269. console.log("FairyGUI: error in complete callback > " + err);
  18270. }
  18271. }
  18272. };
  18273. return GTweener;
  18274. }());
  18275. fgui.GTweener = GTweener;
  18276. var s_vec2 = new cc.Vec2();
  18277. })(fgui || (fgui = {}));
  18278. (function (fgui) {
  18279. var _activeTweens = new Array(30);
  18280. var _tweenerPool = new Array();
  18281. var _totalActiveTweens = 0;
  18282. var _root;
  18283. var TweenManager = (function () {
  18284. function TweenManager() {
  18285. }
  18286. TweenManager.createTween = function () {
  18287. if (!_root) {
  18288. _root = new cc.Node("[TweenManager]");
  18289. cc.game["addPersistRootNode"](_root);
  18290. cc.director.getScheduler().schedule(TweenManager.update, _root, 0, false);
  18291. }
  18292. var tweener;
  18293. var cnt = _tweenerPool.length;
  18294. if (cnt > 0) {
  18295. tweener = _tweenerPool.pop();
  18296. }
  18297. else
  18298. tweener = new fgui.GTweener();
  18299. tweener._init();
  18300. _activeTweens[_totalActiveTweens++] = tweener;
  18301. if (_totalActiveTweens == _activeTweens.length)
  18302. _activeTweens.length = _activeTweens.length + Math.ceil(_activeTweens.length * 0.5);
  18303. return tweener;
  18304. };
  18305. TweenManager.isTweening = function (target, propType) {
  18306. if (target == null)
  18307. return false;
  18308. var anyType = propType == null || propType == undefined;
  18309. for (var i = 0; i < _totalActiveTweens; i++) {
  18310. var tweener = _activeTweens[i];
  18311. if (tweener && tweener.target == target && !tweener._killed
  18312. && (anyType || tweener._propType == propType))
  18313. return true;
  18314. }
  18315. return false;
  18316. };
  18317. TweenManager.killTweens = function (target, completed, propType) {
  18318. if (target == null)
  18319. return false;
  18320. var flag = false;
  18321. var cnt = _totalActiveTweens;
  18322. var anyType = propType == null || propType == undefined;
  18323. for (var i = 0; i < cnt; i++) {
  18324. var tweener = _activeTweens[i];
  18325. if (tweener && tweener.target == target && !tweener._killed
  18326. && (anyType || tweener._propType == propType)) {
  18327. tweener.kill(completed);
  18328. flag = true;
  18329. }
  18330. }
  18331. return flag;
  18332. };
  18333. TweenManager.getTween = function (target, propType) {
  18334. if (target == null)
  18335. return null;
  18336. var cnt = _totalActiveTweens;
  18337. var anyType = propType == null || propType == undefined;
  18338. for (var i = 0; i < cnt; i++) {
  18339. var tweener = _activeTweens[i];
  18340. if (tweener && tweener.target == target && !tweener._killed
  18341. && (anyType || tweener._propType == propType)) {
  18342. return tweener;
  18343. }
  18344. }
  18345. return null;
  18346. };
  18347. TweenManager.update = function (dt) {
  18348. var tweens = _activeTweens;
  18349. var cnt = _totalActiveTweens;
  18350. var freePosStart = -1;
  18351. for (var i = 0; i < cnt; i++) {
  18352. var tweener = tweens[i];
  18353. if (tweener == null) {
  18354. if (freePosStart == -1)
  18355. freePosStart = i;
  18356. }
  18357. else if (tweener._killed) {
  18358. tweener._reset();
  18359. _tweenerPool.push(tweener);
  18360. tweens[i] = null;
  18361. if (freePosStart == -1)
  18362. freePosStart = i;
  18363. }
  18364. else {
  18365. if ((tweener._target instanceof fgui.GObject) && tweener._target.node == null)
  18366. tweener._killed = true;
  18367. else if (!tweener._paused)
  18368. tweener._update(dt);
  18369. if (freePosStart != -1) {
  18370. tweens[freePosStart] = tweener;
  18371. tweens[i] = null;
  18372. freePosStart++;
  18373. }
  18374. }
  18375. }
  18376. if (freePosStart >= 0) {
  18377. if (_totalActiveTweens != cnt) {
  18378. var j = cnt;
  18379. cnt = _totalActiveTweens - cnt;
  18380. for (i = 0; i < cnt; i++)
  18381. tweens[freePosStart++] = tweens[j++];
  18382. }
  18383. _totalActiveTweens = freePosStart;
  18384. }
  18385. return false;
  18386. };
  18387. return TweenManager;
  18388. }());
  18389. fgui.TweenManager = TweenManager;
  18390. })(fgui || (fgui = {}));
  18391. (function (fgui) {
  18392. var TweenValue = (function () {
  18393. function TweenValue() {
  18394. this.x = this.y = this.z = this.w = 0;
  18395. }
  18396. Object.defineProperty(TweenValue.prototype, "color", {
  18397. get: function () {
  18398. return (this.w << 24) + (this.x << 16) + (this.y << 8) + this.z;
  18399. },
  18400. set: function (value) {
  18401. this.x = (value & 0xFF0000) >> 16;
  18402. this.y = (value & 0x00FF00) >> 8;
  18403. this.z = (value & 0x0000FF);
  18404. this.w = (value & 0xFF000000) >> 24;
  18405. },
  18406. enumerable: false,
  18407. configurable: true
  18408. });
  18409. TweenValue.prototype.getField = function (index) {
  18410. switch (index) {
  18411. case 0:
  18412. return this.x;
  18413. case 1:
  18414. return this.y;
  18415. case 2:
  18416. return this.z;
  18417. case 3:
  18418. return this.w;
  18419. default:
  18420. throw new Error("Index out of bounds: " + index);
  18421. }
  18422. };
  18423. TweenValue.prototype.setField = function (index, value) {
  18424. switch (index) {
  18425. case 0:
  18426. this.x = value;
  18427. break;
  18428. case 1:
  18429. this.y = value;
  18430. break;
  18431. case 2:
  18432. this.z = value;
  18433. break;
  18434. case 3:
  18435. this.w = value;
  18436. break;
  18437. default:
  18438. throw new Error("Index out of bounds: " + index);
  18439. }
  18440. };
  18441. TweenValue.prototype.setZero = function () {
  18442. this.x = this.y = this.z = this.w = 0;
  18443. };
  18444. return TweenValue;
  18445. }());
  18446. fgui.TweenValue = TweenValue;
  18447. })(fgui || (fgui = {}));
  18448. (function (fgui) {
  18449. var ByteBuffer = (function () {
  18450. function ByteBuffer(buffer, offset, length) {
  18451. if (offset === void 0) { offset = 0; }
  18452. if (length === void 0) { length = -1; }
  18453. this.version = 0;
  18454. if (length == -1)
  18455. length = buffer.byteLength - offset;
  18456. this._bytes = new Uint8Array(buffer, offset, length);
  18457. this._view = new DataView(this._bytes.buffer, offset, length);
  18458. this._pos = 0;
  18459. this._length = length;
  18460. }
  18461. Object.defineProperty(ByteBuffer.prototype, "data", {
  18462. get: function () {
  18463. return this._bytes;
  18464. },
  18465. enumerable: false,
  18466. configurable: true
  18467. });
  18468. Object.defineProperty(ByteBuffer.prototype, "position", {
  18469. get: function () {
  18470. return this._pos;
  18471. },
  18472. set: function (value) {
  18473. if (value > this._length)
  18474. throw "Out of bounds";
  18475. this._pos = value;
  18476. },
  18477. enumerable: false,
  18478. configurable: true
  18479. });
  18480. ByteBuffer.prototype.skip = function (count) {
  18481. this._pos += count;
  18482. };
  18483. ByteBuffer.prototype.validate = function (forward) {
  18484. if (this._pos + forward > this._length)
  18485. throw "Out of bounds";
  18486. };
  18487. ByteBuffer.prototype.readByte = function () {
  18488. this.validate(1);
  18489. return this._view.getInt8(this._pos++);
  18490. };
  18491. ByteBuffer.prototype.readUbyte = function () {
  18492. return this._bytes[this._pos++];
  18493. };
  18494. ByteBuffer.prototype.readBool = function () {
  18495. return this.readByte() == 1;
  18496. };
  18497. ByteBuffer.prototype.readShort = function () {
  18498. this.validate(2);
  18499. var ret = this._view.getInt16(this._pos, this.littleEndian);
  18500. this._pos += 2;
  18501. return ret;
  18502. };
  18503. ByteBuffer.prototype.readUshort = function () {
  18504. this.validate(2);
  18505. var ret = this._view.getUint16(this._pos, this.littleEndian);
  18506. this._pos += 2;
  18507. return ret;
  18508. };
  18509. ByteBuffer.prototype.readInt = function () {
  18510. this.validate(4);
  18511. var ret = this._view.getInt32(this._pos, this.littleEndian);
  18512. this._pos += 4;
  18513. return ret;
  18514. };
  18515. ByteBuffer.prototype.readUint = function () {
  18516. this.validate(4);
  18517. var ret = this._view.getUint32(this._pos, this.littleEndian);
  18518. this._pos += 4;
  18519. return ret;
  18520. };
  18521. ByteBuffer.prototype.readFloat = function () {
  18522. this.validate(4);
  18523. var ret = this._view.getFloat32(this._pos, this.littleEndian);
  18524. this._pos += 4;
  18525. return ret;
  18526. };
  18527. ByteBuffer.prototype.readString = function (len) {
  18528. if (len == undefined)
  18529. len = this.readUshort();
  18530. this.validate(len);
  18531. var v = "", max = this._pos + len, c = 0, c2 = 0, c3 = 0, f = String.fromCharCode;
  18532. var u = this._bytes, i = 0;
  18533. var pos = this._pos;
  18534. while (pos < max) {
  18535. c = u[pos++];
  18536. if (c < 0x80) {
  18537. if (c != 0) {
  18538. v += f(c);
  18539. }
  18540. }
  18541. else if (c < 0xE0) {
  18542. v += f(((c & 0x3F) << 6) | (u[pos++] & 0x7F));
  18543. }
  18544. else if (c < 0xF0) {
  18545. c2 = u[pos++];
  18546. v += f(((c & 0x1F) << 12) | ((c2 & 0x7F) << 6) | (u[pos++] & 0x7F));
  18547. }
  18548. else {
  18549. c2 = u[pos++];
  18550. c3 = u[pos++];
  18551. v += f(((c & 0x0F) << 18) | ((c2 & 0x7F) << 12) | ((c3 << 6) & 0x7F) | (u[pos++] & 0x7F));
  18552. }
  18553. i++;
  18554. }
  18555. this._pos += len;
  18556. return v;
  18557. };
  18558. ByteBuffer.prototype.readS = function () {
  18559. var index = this.readUshort();
  18560. if (index == 65534)
  18561. return null;
  18562. else if (index == 65533)
  18563. return "";
  18564. else
  18565. return this.stringTable[index];
  18566. };
  18567. ByteBuffer.prototype.readSArray = function (cnt) {
  18568. var ret = new Array(cnt);
  18569. for (var i = 0; i < cnt; i++)
  18570. ret[i] = this.readS();
  18571. return ret;
  18572. };
  18573. ByteBuffer.prototype.writeS = function (value) {
  18574. var index = this.readUshort();
  18575. if (index != 65534 && index != 65533)
  18576. this.stringTable[index] = value;
  18577. };
  18578. ByteBuffer.prototype.readColor = function (hasAlpha) {
  18579. var r = this.readUbyte();
  18580. var g = this.readUbyte();
  18581. var b = this.readUbyte();
  18582. var a = this.readUbyte();
  18583. return new cc.Color(r, g, b, (hasAlpha ? a : 255));
  18584. };
  18585. ByteBuffer.prototype.readChar = function () {
  18586. var i = this.readUshort();
  18587. return String.fromCharCode(i);
  18588. };
  18589. ByteBuffer.prototype.readBuffer = function () {
  18590. var count = this.readUint();
  18591. this.validate(count);
  18592. var ba = new ByteBuffer(this._bytes.buffer, this._bytes.byteOffset + this._pos, count);
  18593. ba.stringTable = this.stringTable;
  18594. ba.version = this.version;
  18595. this._pos += count;
  18596. return ba;
  18597. };
  18598. ByteBuffer.prototype.seek = function (indexTablePos, blockIndex) {
  18599. var tmp = this._pos;
  18600. this._pos = indexTablePos;
  18601. var segCount = this.readByte();
  18602. if (blockIndex < segCount) {
  18603. var useShort = this.readByte() == 1;
  18604. var newPos;
  18605. if (useShort) {
  18606. this._pos += 2 * blockIndex;
  18607. newPos = this.readUshort();
  18608. }
  18609. else {
  18610. this._pos += 4 * blockIndex;
  18611. newPos = this.readUint();
  18612. }
  18613. if (newPos > 0) {
  18614. this._pos = indexTablePos + newPos;
  18615. return true;
  18616. }
  18617. else {
  18618. this._pos = tmp;
  18619. return false;
  18620. }
  18621. }
  18622. else {
  18623. this._pos = tmp;
  18624. return false;
  18625. }
  18626. };
  18627. return ByteBuffer;
  18628. }());
  18629. fgui.ByteBuffer = ByteBuffer;
  18630. })(fgui || (fgui = {}));
  18631. (function (fgui) {
  18632. var ColorMatrix = (function () {
  18633. function ColorMatrix(p_brightness, p_contrast, p_saturation, p_hue) {
  18634. this.matrix = new Array(LENGTH);
  18635. this.reset();
  18636. if (p_brightness !== undefined || p_contrast !== undefined || p_saturation !== undefined || p_hue !== undefined)
  18637. this.adjustColor(p_brightness, p_contrast, p_saturation, p_hue);
  18638. }
  18639. ColorMatrix.prototype.reset = function () {
  18640. for (var i = 0; i < LENGTH; i++) {
  18641. this.matrix[i] = IDENTITY_MATRIX[i];
  18642. }
  18643. };
  18644. ColorMatrix.prototype.invert = function () {
  18645. this.multiplyMatrix([-1, 0, 0, 0, 255,
  18646. 0, -1, 0, 0, 255,
  18647. 0, 0, -1, 0, 255,
  18648. 0, 0, 0, 1, 0]);
  18649. };
  18650. ColorMatrix.prototype.adjustColor = function (p_brightness, p_contrast, p_saturation, p_hue) {
  18651. this.adjustHue(p_hue || 0);
  18652. this.adjustContrast(p_contrast || 0);
  18653. this.adjustBrightness(p_brightness || 0);
  18654. this.adjustSaturation(p_saturation || 0);
  18655. };
  18656. ColorMatrix.prototype.adjustBrightness = function (p_val) {
  18657. p_val = this.cleanValue(p_val, 1) * 255;
  18658. this.multiplyMatrix([
  18659. 1, 0, 0, 0, p_val,
  18660. 0, 1, 0, 0, p_val,
  18661. 0, 0, 1, 0, p_val,
  18662. 0, 0, 0, 1, 0
  18663. ]);
  18664. };
  18665. ColorMatrix.prototype.adjustContrast = function (p_val) {
  18666. p_val = this.cleanValue(p_val, 1);
  18667. var s = p_val + 1;
  18668. var o = 128 * (1 - s);
  18669. this.multiplyMatrix([
  18670. s, 0, 0, 0, o,
  18671. 0, s, 0, 0, o,
  18672. 0, 0, s, 0, o,
  18673. 0, 0, 0, 1, 0
  18674. ]);
  18675. };
  18676. ColorMatrix.prototype.adjustSaturation = function (p_val) {
  18677. p_val = this.cleanValue(p_val, 1);
  18678. p_val += 1;
  18679. var invSat = 1 - p_val;
  18680. var invLumR = invSat * LUMA_R;
  18681. var invLumG = invSat * LUMA_G;
  18682. var invLumB = invSat * LUMA_B;
  18683. this.multiplyMatrix([
  18684. (invLumR + p_val), invLumG, invLumB, 0, 0,
  18685. invLumR, (invLumG + p_val), invLumB, 0, 0,
  18686. invLumR, invLumG, (invLumB + p_val), 0, 0,
  18687. 0, 0, 0, 1, 0
  18688. ]);
  18689. };
  18690. ColorMatrix.prototype.adjustHue = function (p_val) {
  18691. p_val = this.cleanValue(p_val, 1);
  18692. p_val *= Math.PI;
  18693. var cos = Math.cos(p_val);
  18694. var sin = Math.sin(p_val);
  18695. this.multiplyMatrix([
  18696. ((LUMA_R + (cos * (1 - LUMA_R))) + (sin * -(LUMA_R))), ((LUMA_G + (cos * -(LUMA_G))) + (sin * -(LUMA_G))), ((LUMA_B + (cos * -(LUMA_B))) + (sin * (1 - LUMA_B))), 0, 0,
  18697. ((LUMA_R + (cos * -(LUMA_R))) + (sin * 0.143)), ((LUMA_G + (cos * (1 - LUMA_G))) + (sin * 0.14)), ((LUMA_B + (cos * -(LUMA_B))) + (sin * -0.283)), 0, 0,
  18698. ((LUMA_R + (cos * -(LUMA_R))) + (sin * -((1 - LUMA_R)))), ((LUMA_G + (cos * -(LUMA_G))) + (sin * LUMA_G)), ((LUMA_B + (cos * (1 - LUMA_B))) + (sin * LUMA_B)), 0, 0,
  18699. 0, 0, 0, 1, 0
  18700. ]);
  18701. };
  18702. ColorMatrix.prototype.concat = function (p_matrix) {
  18703. if (p_matrix.length != LENGTH) {
  18704. return;
  18705. }
  18706. this.multiplyMatrix(p_matrix);
  18707. };
  18708. ColorMatrix.prototype.clone = function () {
  18709. var result = new ColorMatrix();
  18710. result.copyMatrix(this.matrix);
  18711. return result;
  18712. };
  18713. ColorMatrix.prototype.copyMatrix = function (p_matrix) {
  18714. var l = LENGTH;
  18715. for (var i = 0; i < l; i++) {
  18716. this.matrix[i] = p_matrix[i];
  18717. }
  18718. };
  18719. ColorMatrix.prototype.multiplyMatrix = function (p_matrix) {
  18720. var col = [];
  18721. var i = 0;
  18722. for (var y = 0; y < 4; ++y) {
  18723. for (var x = 0; x < 5; ++x) {
  18724. col[i + x] = p_matrix[i] * this.matrix[x] +
  18725. p_matrix[i + 1] * this.matrix[x + 5] +
  18726. p_matrix[i + 2] * this.matrix[x + 10] +
  18727. p_matrix[i + 3] * this.matrix[x + 15] +
  18728. (x == 4 ? p_matrix[i + 4] : 0);
  18729. }
  18730. i += 5;
  18731. }
  18732. this.copyMatrix(col);
  18733. };
  18734. ColorMatrix.prototype.cleanValue = function (p_val, p_limit) {
  18735. return Math.min(p_limit, Math.max(-p_limit, p_val));
  18736. };
  18737. return ColorMatrix;
  18738. }());
  18739. fgui.ColorMatrix = ColorMatrix;
  18740. var IDENTITY_MATRIX = [
  18741. 1, 0, 0, 0, 0,
  18742. 0, 1, 0, 0, 0,
  18743. 0, 0, 1, 0, 0,
  18744. 0, 0, 0, 1, 0
  18745. ];
  18746. var LENGTH = IDENTITY_MATRIX.length;
  18747. var LUMA_R = 0.299;
  18748. var LUMA_G = 0.587;
  18749. var LUMA_B = 0.114;
  18750. })(fgui || (fgui = {}));
  18751. (function (fgui) {
  18752. var UBBParser = (function () {
  18753. function UBBParser() {
  18754. this._readPos = 0;
  18755. this._handlers = {};
  18756. this._handlers["url"] = this.onTag_URL;
  18757. this._handlers["img"] = this.onTag_IMG;
  18758. this._handlers["b"] = this.onTag_Simple;
  18759. this._handlers["i"] = this.onTag_Simple;
  18760. this._handlers["u"] = this.onTag_Simple;
  18761. this._handlers["color"] = this.onTag_COLOR;
  18762. this._handlers["size"] = this.onTag_SIZE;
  18763. }
  18764. UBBParser.prototype.onTag_URL = function (tagName, end, attr) {
  18765. if (!end) {
  18766. var ret = void 0;
  18767. if (attr != null)
  18768. ret = "<on click=\"onClickLink\" param=\"" + attr + "\">";
  18769. else {
  18770. var href = this.getTagText();
  18771. ret = "<on click=\"onClickLink\" param=\"" + href + "\">";
  18772. }
  18773. if (this.linkUnderline)
  18774. ret += "<u>";
  18775. if (this.linkColor)
  18776. ret += "<color=" + this.linkColor + ">";
  18777. return ret;
  18778. }
  18779. else {
  18780. var ret = "";
  18781. if (this.linkColor)
  18782. ret += "</color>";
  18783. if (this.linkUnderline)
  18784. ret += "</u>";
  18785. ret += "</on>";
  18786. return ret;
  18787. }
  18788. };
  18789. UBBParser.prototype.onTag_IMG = function (tagName, end, attr) {
  18790. if (!end) {
  18791. var src = this.getTagText(true);
  18792. if (!src)
  18793. return null;
  18794. return "<img src=\"" + src + "\"/>";
  18795. }
  18796. else
  18797. return null;
  18798. };
  18799. UBBParser.prototype.onTag_Simple = function (tagName, end, attr) {
  18800. return end ? ("</" + tagName + ">") : ("<" + tagName + ">");
  18801. };
  18802. UBBParser.prototype.onTag_COLOR = function (tagName, end, attr) {
  18803. if (!end) {
  18804. this.lastColor = attr;
  18805. return "<color=" + attr + ">";
  18806. }
  18807. else
  18808. return "</color>";
  18809. };
  18810. UBBParser.prototype.onTag_FONT = function (tagName, end, attr) {
  18811. if (!end)
  18812. return "<font face=\"" + attr + "\">";
  18813. else
  18814. return "</font>";
  18815. };
  18816. UBBParser.prototype.onTag_SIZE = function (tagName, end, attr) {
  18817. if (!end) {
  18818. this.lastSize = attr;
  18819. return "<size=" + attr + ">";
  18820. }
  18821. else
  18822. return "</size>";
  18823. };
  18824. UBBParser.prototype.getTagText = function (remove) {
  18825. var pos1 = this._readPos;
  18826. var pos2;
  18827. var result = "";
  18828. while ((pos2 = this._text.indexOf("[", pos1)) != -1) {
  18829. if (this._text.charCodeAt(pos2 - 1) == 92) {
  18830. result += this._text.substring(pos1, pos2 - 1);
  18831. result += "[";
  18832. pos1 = pos2 + 1;
  18833. }
  18834. else {
  18835. result += this._text.substring(pos1, pos2);
  18836. break;
  18837. }
  18838. }
  18839. if (pos2 == -1)
  18840. return null;
  18841. if (remove)
  18842. this._readPos = pos2;
  18843. return result;
  18844. };
  18845. UBBParser.prototype.parse = function (text, remove) {
  18846. this._text = text;
  18847. this.lastColor = null;
  18848. this.lastSize = null;
  18849. var pos1 = 0, pos2, pos3;
  18850. var end;
  18851. var tag, attr;
  18852. var repl;
  18853. var func;
  18854. var result = "";
  18855. while ((pos2 = this._text.indexOf("[", pos1)) != -1) {
  18856. if (pos2 > 0 && this._text.charCodeAt(pos2 - 1) == 92) {
  18857. result += this._text.substring(pos1, pos2 - 1);
  18858. result += "[";
  18859. pos1 = pos2 + 1;
  18860. continue;
  18861. }
  18862. result += this._text.substring(pos1, pos2);
  18863. pos1 = pos2;
  18864. pos2 = this._text.indexOf("]", pos1);
  18865. if (pos2 == -1)
  18866. break;
  18867. end = this._text.charAt(pos1 + 1) == '/';
  18868. tag = this._text.substring(end ? pos1 + 2 : pos1 + 1, pos2);
  18869. this._readPos = pos2 + 1;
  18870. attr = null;
  18871. repl = null;
  18872. pos3 = tag.indexOf("=");
  18873. if (pos3 != -1) {
  18874. attr = tag.substring(pos3 + 1);
  18875. tag = tag.substring(0, pos3);
  18876. }
  18877. tag = tag.toLowerCase();
  18878. func = this._handlers[tag];
  18879. if (func != null) {
  18880. repl = func.call(this, tag, end, attr);
  18881. if (repl != null && !remove)
  18882. result += repl;
  18883. }
  18884. else
  18885. result += this._text.substring(pos1, this._readPos);
  18886. pos1 = this._readPos;
  18887. }
  18888. if (pos1 < this._text.length)
  18889. result += this._text.substr(pos1);
  18890. this._text = null;
  18891. return result;
  18892. };
  18893. UBBParser.inst = new UBBParser();
  18894. return UBBParser;
  18895. }());
  18896. fgui.UBBParser = UBBParser;
  18897. })(fgui || (fgui = {}));
  18898. (function (fgui) {
  18899. var ToolSet = (function () {
  18900. function ToolSet() {
  18901. }
  18902. ToolSet.startsWith = function (source, str, ignoreCase) {
  18903. if (!source)
  18904. return false;
  18905. else if (source.length < str.length)
  18906. return false;
  18907. else {
  18908. source = source.substring(0, str.length);
  18909. if (!ignoreCase)
  18910. return source == str;
  18911. else
  18912. return source.toLowerCase() == str.toLowerCase();
  18913. }
  18914. };
  18915. ToolSet.encodeHTML = function (str) {
  18916. if (!str)
  18917. return "";
  18918. else
  18919. return str.replace(/&/g, "&amp;").replace(/</g, "&lt;")
  18920. .replace(/>/g, "&gt;").replace(/'/g, "&apos;").replace(/"/g, "&quot;");
  18921. };
  18922. ToolSet.clamp = function (value, min, max) {
  18923. if (value < min)
  18924. value = min;
  18925. else if (value > max)
  18926. value = max;
  18927. return value;
  18928. };
  18929. ToolSet.clamp01 = function (value) {
  18930. if (value > 1)
  18931. value = 1;
  18932. else if (value < 0)
  18933. value = 0;
  18934. return value;
  18935. };
  18936. ToolSet.lerp = function (start, end, percent) {
  18937. return (start + percent * (end - start));
  18938. };
  18939. ToolSet.getTime = function () {
  18940. var currentTime = new Date();
  18941. return currentTime.getMilliseconds() / 1000;
  18942. };
  18943. ToolSet.toGrayed = function (c) {
  18944. var v = c.getR() * 0.299 + c.getG() * 0.587 + c.getB() * 0.114;
  18945. return new cc.Color(v, v, v, c.getA());
  18946. };
  18947. ToolSet.repeat = function (t, length) {
  18948. return t - Math.floor(t / length) * length;
  18949. };
  18950. ToolSet.distance = function (x1, y1, x2, y2) {
  18951. return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
  18952. };
  18953. return ToolSet;
  18954. }());
  18955. fgui.ToolSet = ToolSet;
  18956. })(fgui || (fgui = {}));