fairygui.js 765 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971
  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. GObject.prototype.setPosition = function (xv, yv) {
  818. if (this._x != xv || this._y != yv) {
  819. var dx = xv - this._x;
  820. var dy = yv - this._y;
  821. this._x = xv;
  822. this._y = yv;
  823. this.handlePositionChanged();
  824. if (this instanceof fgui.GGroup)
  825. this.moveChildren(dx, dy);
  826. this.updateGear(1);
  827. if (this._parent && !(this._parent instanceof fgui.GList)) {
  828. this._parent.setBoundsChangedFlag();
  829. if (this._group)
  830. this._group.setBoundsChangedFlag(true);
  831. this._node.emit(fgui.Event.XY_CHANGED, this);
  832. }
  833. if (GObject.draggingObject == this && !sUpdateInDragging)
  834. this.localToGlobalRect(0, 0, this._width, this._height, sGlobalRect);
  835. }
  836. };
  837. Object.defineProperty(GObject.prototype, "xMin", {
  838. get: function () {
  839. return this._pivotAsAnchor ? (this._x - this._width * this.node.anchorX) : this._x;
  840. },
  841. set: function (value) {
  842. if (this._pivotAsAnchor)
  843. this.setPosition(value + this._width * this.node.anchorX, this._y);
  844. else
  845. this.setPosition(value, this._y);
  846. },
  847. enumerable: false,
  848. configurable: true
  849. });
  850. Object.defineProperty(GObject.prototype, "yMin", {
  851. get: function () {
  852. return this._pivotAsAnchor ? (this._y - this._height * (1 - this.node.anchorY)) : this._y;
  853. },
  854. set: function (value) {
  855. if (this._pivotAsAnchor)
  856. this.setPosition(this._x, value + this._height * (1 - this.node.anchorY));
  857. else
  858. this.setPosition(this._x, value);
  859. },
  860. enumerable: false,
  861. configurable: true
  862. });
  863. Object.defineProperty(GObject.prototype, "pixelSnapping", {
  864. get: function () {
  865. return this._pixelSnapping;
  866. },
  867. set: function (value) {
  868. if (this._pixelSnapping != value) {
  869. this._pixelSnapping = value;
  870. this.handlePositionChanged();
  871. }
  872. },
  873. enumerable: false,
  874. configurable: true
  875. });
  876. GObject.prototype.center = function (restraint) {
  877. var r;
  878. if (this._parent)
  879. r = this.parent;
  880. else
  881. r = this.root;
  882. this.setPosition((r.width - this._width) / 2, (r.height - this._height) / 2);
  883. if (restraint) {
  884. this.addRelation(r, fgui.RelationType.Center_Center);
  885. this.addRelation(r, fgui.RelationType.Middle_Middle);
  886. }
  887. };
  888. Object.defineProperty(GObject.prototype, "width", {
  889. get: function () {
  890. this.ensureSizeCorrect();
  891. if (this._relations.sizeDirty)
  892. this._relations.ensureRelationsSizeCorrect();
  893. return this._width;
  894. },
  895. set: function (value) {
  896. this.setSize(value, this._rawHeight);
  897. },
  898. enumerable: false,
  899. configurable: true
  900. });
  901. Object.defineProperty(GObject.prototype, "height", {
  902. get: function () {
  903. this.ensureSizeCorrect();
  904. if (this._relations.sizeDirty)
  905. this._relations.ensureRelationsSizeCorrect();
  906. return this._height;
  907. },
  908. set: function (value) {
  909. this.setSize(this._rawWidth, value);
  910. },
  911. enumerable: false,
  912. configurable: true
  913. });
  914. GObject.prototype.setSize = function (wv, hv, ignorePivot) {
  915. if (this._rawWidth != wv || this._rawHeight != hv) {
  916. this._rawWidth = wv;
  917. this._rawHeight = hv;
  918. if (wv < this.minWidth)
  919. wv = this.minWidth;
  920. if (hv < this.minHeight)
  921. hv = this.minHeight;
  922. if (this.maxWidth > 0 && wv > this.maxWidth)
  923. wv = this.maxWidth;
  924. if (this.maxHeight > 0 && hv > this.maxHeight)
  925. hv = this.maxHeight;
  926. var dWidth = wv - this._width;
  927. var dHeight = hv - this._height;
  928. this._width = wv;
  929. this._height = hv;
  930. this.handleSizeChanged();
  931. if ((this.node.anchorX != 0 || this.node.anchorY != 1) && !this._pivotAsAnchor && !ignorePivot)
  932. this.setPosition(this.x - this.node.anchorX * dWidth, this.y - (1 - this.node.anchorY) * dHeight);
  933. else
  934. this.handlePositionChanged();
  935. if (this instanceof fgui.GGroup)
  936. this.resizeChildren(dWidth, dHeight);
  937. this.updateGear(2);
  938. if (this._parent) {
  939. this._relations.onOwnerSizeChanged(dWidth, dHeight, this._pivotAsAnchor || !ignorePivot);
  940. this._parent.setBoundsChangedFlag();
  941. if (this._group)
  942. this._group.setBoundsChangedFlag();
  943. }
  944. this._node.emit(fgui.Event.SIZE_CHANGED, this);
  945. }
  946. };
  947. GObject.prototype.makeFullScreen = function () {
  948. this.setSize(fgui.GRoot.inst.width, fgui.GRoot.inst.height);
  949. };
  950. GObject.prototype.ensureSizeCorrect = function () {
  951. };
  952. Object.defineProperty(GObject.prototype, "actualWidth", {
  953. get: function () {
  954. return this.width * Math.abs(this._node.scaleX);
  955. },
  956. enumerable: false,
  957. configurable: true
  958. });
  959. Object.defineProperty(GObject.prototype, "actualHeight", {
  960. get: function () {
  961. return this.height * Math.abs(this._node.scaleY);
  962. },
  963. enumerable: false,
  964. configurable: true
  965. });
  966. Object.defineProperty(GObject.prototype, "scaleX", {
  967. get: function () {
  968. return this._node.scaleX;
  969. },
  970. set: function (value) {
  971. this.setScale(value, this._node.scaleY);
  972. },
  973. enumerable: false,
  974. configurable: true
  975. });
  976. Object.defineProperty(GObject.prototype, "scaleY", {
  977. get: function () {
  978. return this._node.scaleY;
  979. },
  980. set: function (value) {
  981. this.setScale(this._node.scaleX, value);
  982. },
  983. enumerable: false,
  984. configurable: true
  985. });
  986. GObject.prototype.setScale = function (sx, sy) {
  987. if (this._node.scaleX != sx || this._node.scaleY != sy) {
  988. this._node.setScale(sx, sy);
  989. this.updateGear(2);
  990. }
  991. };
  992. Object.defineProperty(GObject.prototype, "skewX", {
  993. get: function () {
  994. return this._skewX;
  995. },
  996. set: function (value) {
  997. this.setSkew(value, this._skewY);
  998. },
  999. enumerable: false,
  1000. configurable: true
  1001. });
  1002. Object.defineProperty(GObject.prototype, "skewY", {
  1003. get: function () {
  1004. return this._skewY;
  1005. },
  1006. set: function (value) {
  1007. this.setSkew(this._skewX, value);
  1008. },
  1009. enumerable: false,
  1010. configurable: true
  1011. });
  1012. GObject.prototype.setSkew = function (xv, yv) {
  1013. if (this._skewX != xv || this._skewY != yv) {
  1014. this._skewX = xv;
  1015. this._skewY = yv;
  1016. this._node.skewX = xv;
  1017. this._node.skewY = yv;
  1018. }
  1019. };
  1020. Object.defineProperty(GObject.prototype, "pivotX", {
  1021. get: function () {
  1022. return this.node.anchorX;
  1023. },
  1024. set: function (value) {
  1025. this.node.anchorX = value;
  1026. },
  1027. enumerable: false,
  1028. configurable: true
  1029. });
  1030. Object.defineProperty(GObject.prototype, "pivotY", {
  1031. get: function () {
  1032. return 1 - this.node.anchorY;
  1033. },
  1034. set: function (value) {
  1035. this.node.anchorY = 1 - value;
  1036. },
  1037. enumerable: false,
  1038. configurable: true
  1039. });
  1040. GObject.prototype.setPivot = function (xv, yv, asAnchor) {
  1041. if (this.node.anchorX != xv || this.node.anchorY != 1 - yv) {
  1042. this._pivotAsAnchor = asAnchor;
  1043. this.node.setAnchorPoint(xv, 1 - yv);
  1044. }
  1045. else if (this._pivotAsAnchor != asAnchor) {
  1046. this._pivotAsAnchor = asAnchor;
  1047. this.handlePositionChanged();
  1048. }
  1049. };
  1050. Object.defineProperty(GObject.prototype, "pivotAsAnchor", {
  1051. get: function () {
  1052. return this._pivotAsAnchor;
  1053. },
  1054. enumerable: false,
  1055. configurable: true
  1056. });
  1057. Object.defineProperty(GObject.prototype, "touchable", {
  1058. get: function () {
  1059. return this._touchable;
  1060. },
  1061. set: function (value) {
  1062. if (this._touchable != value) {
  1063. this._touchable = value;
  1064. this.updateGear(3);
  1065. }
  1066. },
  1067. enumerable: false,
  1068. configurable: true
  1069. });
  1070. Object.defineProperty(GObject.prototype, "grayed", {
  1071. get: function () {
  1072. return this._grayed;
  1073. },
  1074. set: function (value) {
  1075. if (this._grayed != value) {
  1076. this._grayed = value;
  1077. this.handleGrayedChanged();
  1078. this.updateGear(3);
  1079. }
  1080. },
  1081. enumerable: false,
  1082. configurable: true
  1083. });
  1084. Object.defineProperty(GObject.prototype, "enabled", {
  1085. get: function () {
  1086. return !this._grayed && this._touchable;
  1087. },
  1088. set: function (value) {
  1089. this.grayed = !value;
  1090. this.touchable = value;
  1091. },
  1092. enumerable: false,
  1093. configurable: true
  1094. });
  1095. Object.defineProperty(GObject.prototype, "rotation", {
  1096. get: function () {
  1097. return -this._node.angle;
  1098. },
  1099. set: function (value) {
  1100. value = -value;
  1101. if (this._node.angle != value) {
  1102. this._node.angle = value;
  1103. this.updateGear(3);
  1104. }
  1105. },
  1106. enumerable: false,
  1107. configurable: true
  1108. });
  1109. Object.defineProperty(GObject.prototype, "alpha", {
  1110. get: function () {
  1111. return this._alpha;
  1112. },
  1113. set: function (value) {
  1114. if (this._alpha != value) {
  1115. this._alpha = value;
  1116. this._node.opacity = this._alpha * 255;
  1117. if (this instanceof fgui.GGroup)
  1118. this.handleAlphaChanged();
  1119. this.updateGear(3);
  1120. }
  1121. },
  1122. enumerable: false,
  1123. configurable: true
  1124. });
  1125. Object.defineProperty(GObject.prototype, "visible", {
  1126. get: function () {
  1127. return this._visible;
  1128. },
  1129. set: function (value) {
  1130. if (this._visible != value) {
  1131. this._visible = value;
  1132. this.handleVisibleChanged();
  1133. if (this._group && this._group.excludeInvisibles)
  1134. this._group.setBoundsChangedFlag();
  1135. }
  1136. },
  1137. enumerable: false,
  1138. configurable: true
  1139. });
  1140. Object.defineProperty(GObject.prototype, "_finalVisible", {
  1141. get: function () {
  1142. return this._visible && this._internalVisible && (!this._group || this._group._finalVisible);
  1143. },
  1144. enumerable: false,
  1145. configurable: true
  1146. });
  1147. Object.defineProperty(GObject.prototype, "internalVisible3", {
  1148. get: function () {
  1149. return this._visible && this._internalVisible;
  1150. },
  1151. enumerable: false,
  1152. configurable: true
  1153. });
  1154. Object.defineProperty(GObject.prototype, "sortingOrder", {
  1155. get: function () {
  1156. return this._sortingOrder;
  1157. },
  1158. set: function (value) {
  1159. if (value < 0)
  1160. value = 0;
  1161. if (this._sortingOrder != value) {
  1162. var old = this._sortingOrder;
  1163. this._sortingOrder = value;
  1164. if (this._parent)
  1165. this._parent.childSortingOrderChanged(this, old, this._sortingOrder);
  1166. }
  1167. },
  1168. enumerable: false,
  1169. configurable: true
  1170. });
  1171. GObject.prototype.requestFocus = function () {
  1172. };
  1173. Object.defineProperty(GObject.prototype, "tooltips", {
  1174. get: function () {
  1175. return this._tooltips;
  1176. },
  1177. set: function (value) {
  1178. if (this._tooltips) {
  1179. this._node.off(fgui.Event.ROLL_OVER, this.onRollOver, this);
  1180. this._node.off(fgui.Event.ROLL_OUT, this.onRollOut, this);
  1181. }
  1182. this._tooltips = value;
  1183. if (this._tooltips) {
  1184. this._node.on(fgui.Event.ROLL_OVER, this.onRollOver, this);
  1185. this._node.on(fgui.Event.ROLL_OUT, this.onRollOut, this);
  1186. }
  1187. },
  1188. enumerable: false,
  1189. configurable: true
  1190. });
  1191. Object.defineProperty(GObject.prototype, "blendMode", {
  1192. get: function () {
  1193. return this._blendMode;
  1194. },
  1195. set: function (value) {
  1196. if (this._blendMode != value) {
  1197. this._blendMode = value;
  1198. fgui.BlendModeUtils.apply(this._node, value);
  1199. }
  1200. },
  1201. enumerable: false,
  1202. configurable: true
  1203. });
  1204. Object.defineProperty(GObject.prototype, "onStage", {
  1205. get: function () {
  1206. return this._node && this._node.activeInHierarchy;
  1207. },
  1208. enumerable: false,
  1209. configurable: true
  1210. });
  1211. Object.defineProperty(GObject.prototype, "resourceURL", {
  1212. get: function () {
  1213. if (this.packageItem)
  1214. return "ui://" + this.packageItem.owner.id + this.packageItem.id;
  1215. else
  1216. return null;
  1217. },
  1218. enumerable: false,
  1219. configurable: true
  1220. });
  1221. Object.defineProperty(GObject.prototype, "group", {
  1222. get: function () {
  1223. return this._group;
  1224. },
  1225. set: function (value) {
  1226. if (this._group != value) {
  1227. if (this._group)
  1228. this._group.setBoundsChangedFlag();
  1229. this._group = value;
  1230. if (this._group)
  1231. this._group.setBoundsChangedFlag();
  1232. }
  1233. },
  1234. enumerable: false,
  1235. configurable: true
  1236. });
  1237. GObject.prototype.getGear = function (index) {
  1238. var gear = this._gears[index];
  1239. if (!gear)
  1240. this._gears[index] = gear = fgui.GearBase.create(this, index);
  1241. return gear;
  1242. };
  1243. GObject.prototype.updateGear = function (index) {
  1244. if (this._underConstruct || this._gearLocked)
  1245. return;
  1246. var gear = this._gears[index];
  1247. if (gear && gear.controller)
  1248. gear.updateState();
  1249. };
  1250. GObject.prototype.checkGearController = function (index, c) {
  1251. return this._gears[index] && this._gears[index].controller == c;
  1252. };
  1253. GObject.prototype.updateGearFromRelations = function (index, dx, dy) {
  1254. if (this._gears[index])
  1255. this._gears[index].updateFromRelations(dx, dy);
  1256. };
  1257. GObject.prototype.addDisplayLock = function () {
  1258. var gearDisplay = this._gears[0];
  1259. if (gearDisplay && gearDisplay.controller) {
  1260. var ret = gearDisplay.addLock();
  1261. this.checkGearDisplay();
  1262. return ret;
  1263. }
  1264. else
  1265. return 0;
  1266. };
  1267. GObject.prototype.releaseDisplayLock = function (token) {
  1268. var gearDisplay = this._gears[0];
  1269. if (gearDisplay && gearDisplay.controller) {
  1270. gearDisplay.releaseLock(token);
  1271. this.checkGearDisplay();
  1272. }
  1273. };
  1274. GObject.prototype.checkGearDisplay = function () {
  1275. if (this._handlingController)
  1276. return;
  1277. var connected = this._gears[0] == null || this._gears[0].connected;
  1278. if (this._gears[8])
  1279. connected = this._gears[8].evaluate(connected);
  1280. if (connected != this._internalVisible) {
  1281. this._internalVisible = connected;
  1282. this.handleVisibleChanged();
  1283. if (this._group && this._group.excludeInvisibles)
  1284. this._group.setBoundsChangedFlag();
  1285. }
  1286. };
  1287. Object.defineProperty(GObject.prototype, "gearXY", {
  1288. get: function () {
  1289. return this.getGear(1);
  1290. },
  1291. enumerable: false,
  1292. configurable: true
  1293. });
  1294. Object.defineProperty(GObject.prototype, "gearSize", {
  1295. get: function () {
  1296. return this.getGear(2);
  1297. },
  1298. enumerable: false,
  1299. configurable: true
  1300. });
  1301. Object.defineProperty(GObject.prototype, "gearLook", {
  1302. get: function () {
  1303. return this.getGear(3);
  1304. },
  1305. enumerable: false,
  1306. configurable: true
  1307. });
  1308. Object.defineProperty(GObject.prototype, "relations", {
  1309. get: function () {
  1310. return this._relations;
  1311. },
  1312. enumerable: false,
  1313. configurable: true
  1314. });
  1315. GObject.prototype.addRelation = function (target, relationType, usePercent) {
  1316. this._relations.add(target, relationType, usePercent);
  1317. };
  1318. GObject.prototype.removeRelation = function (target, relationType) {
  1319. this._relations.remove(target, relationType);
  1320. };
  1321. Object.defineProperty(GObject.prototype, "node", {
  1322. get: function () {
  1323. return this._node;
  1324. },
  1325. enumerable: false,
  1326. configurable: true
  1327. });
  1328. Object.defineProperty(GObject.prototype, "parent", {
  1329. get: function () {
  1330. return this._parent;
  1331. },
  1332. enumerable: false,
  1333. configurable: true
  1334. });
  1335. GObject.prototype.removeFromParent = function () {
  1336. if (this._parent)
  1337. this._parent.removeChild(this);
  1338. };
  1339. GObject.prototype.findParent = function () {
  1340. if (this._parent)
  1341. return this._parent;
  1342. var pn = this._node.parent;
  1343. while (pn) {
  1344. var gobj = pn["$gobj"];
  1345. if (gobj)
  1346. return gobj;
  1347. pn = pn.parent;
  1348. }
  1349. return null;
  1350. };
  1351. Object.defineProperty(GObject.prototype, "root", {
  1352. get: function () {
  1353. if (this instanceof fgui.GRoot)
  1354. return this;
  1355. var p = this._parent;
  1356. while (p) {
  1357. if (p instanceof fgui.GRoot)
  1358. return p;
  1359. p = p.parent;
  1360. }
  1361. return fgui.GRoot.inst;
  1362. },
  1363. enumerable: false,
  1364. configurable: true
  1365. });
  1366. Object.defineProperty(GObject.prototype, "asCom", {
  1367. get: function () {
  1368. return this;
  1369. },
  1370. enumerable: false,
  1371. configurable: true
  1372. });
  1373. Object.defineProperty(GObject.prototype, "asButton", {
  1374. get: function () {
  1375. return this;
  1376. },
  1377. enumerable: false,
  1378. configurable: true
  1379. });
  1380. Object.defineProperty(GObject.prototype, "asLabel", {
  1381. get: function () {
  1382. return this;
  1383. },
  1384. enumerable: false,
  1385. configurable: true
  1386. });
  1387. Object.defineProperty(GObject.prototype, "asProgress", {
  1388. get: function () {
  1389. return this;
  1390. },
  1391. enumerable: false,
  1392. configurable: true
  1393. });
  1394. Object.defineProperty(GObject.prototype, "asTextField", {
  1395. get: function () {
  1396. return this;
  1397. },
  1398. enumerable: false,
  1399. configurable: true
  1400. });
  1401. Object.defineProperty(GObject.prototype, "asRichTextField", {
  1402. get: function () {
  1403. return this;
  1404. },
  1405. enumerable: false,
  1406. configurable: true
  1407. });
  1408. Object.defineProperty(GObject.prototype, "asTextInput", {
  1409. get: function () {
  1410. return this;
  1411. },
  1412. enumerable: false,
  1413. configurable: true
  1414. });
  1415. Object.defineProperty(GObject.prototype, "asLoader", {
  1416. get: function () {
  1417. return this;
  1418. },
  1419. enumerable: false,
  1420. configurable: true
  1421. });
  1422. Object.defineProperty(GObject.prototype, "asList", {
  1423. get: function () {
  1424. return this;
  1425. },
  1426. enumerable: false,
  1427. configurable: true
  1428. });
  1429. Object.defineProperty(GObject.prototype, "asTree", {
  1430. get: function () {
  1431. return this;
  1432. },
  1433. enumerable: false,
  1434. configurable: true
  1435. });
  1436. Object.defineProperty(GObject.prototype, "asGraph", {
  1437. get: function () {
  1438. return this;
  1439. },
  1440. enumerable: false,
  1441. configurable: true
  1442. });
  1443. Object.defineProperty(GObject.prototype, "asGroup", {
  1444. get: function () {
  1445. return this;
  1446. },
  1447. enumerable: false,
  1448. configurable: true
  1449. });
  1450. Object.defineProperty(GObject.prototype, "asSlider", {
  1451. get: function () {
  1452. return this;
  1453. },
  1454. enumerable: false,
  1455. configurable: true
  1456. });
  1457. Object.defineProperty(GObject.prototype, "asComboBox", {
  1458. get: function () {
  1459. return this;
  1460. },
  1461. enumerable: false,
  1462. configurable: true
  1463. });
  1464. Object.defineProperty(GObject.prototype, "asImage", {
  1465. get: function () {
  1466. return this;
  1467. },
  1468. enumerable: false,
  1469. configurable: true
  1470. });
  1471. Object.defineProperty(GObject.prototype, "asMovieClip", {
  1472. get: function () {
  1473. return this;
  1474. },
  1475. enumerable: false,
  1476. configurable: true
  1477. });
  1478. GObject.cast = function (obj) {
  1479. return obj["$gobj"];
  1480. };
  1481. Object.defineProperty(GObject.prototype, "text", {
  1482. get: function () {
  1483. return null;
  1484. },
  1485. set: function (value) {
  1486. },
  1487. enumerable: false,
  1488. configurable: true
  1489. });
  1490. Object.defineProperty(GObject.prototype, "icon", {
  1491. get: function () {
  1492. return null;
  1493. },
  1494. set: function (value) {
  1495. },
  1496. enumerable: false,
  1497. configurable: true
  1498. });
  1499. Object.defineProperty(GObject.prototype, "treeNode", {
  1500. get: function () {
  1501. return this._treeNode;
  1502. },
  1503. enumerable: false,
  1504. configurable: true
  1505. });
  1506. GObject.prototype.dispose = function () {
  1507. var n = this._node;
  1508. if (!n)
  1509. return;
  1510. this.removeFromParent();
  1511. this._relations.dispose();
  1512. this._node = null;
  1513. n.destroy();
  1514. for (var i = 0; i < 10; i++) {
  1515. var gear = this._gears[i];
  1516. if (gear)
  1517. gear.dispose();
  1518. }
  1519. };
  1520. GObject.prototype.onEnable = function () {
  1521. };
  1522. GObject.prototype.onDisable = function () {
  1523. };
  1524. GObject.prototype.onUpdate = function () {
  1525. };
  1526. GObject.prototype.onDestroy = function () {
  1527. };
  1528. GObject.prototype.onClick = function (listener, target) {
  1529. this._node.on(fgui.Event.CLICK, listener, target);
  1530. };
  1531. GObject.prototype.offClick = function (listener, target) {
  1532. this._node.off(fgui.Event.CLICK, listener, target);
  1533. };
  1534. GObject.prototype.clearClick = function () {
  1535. this._node.off(fgui.Event.CLICK);
  1536. };
  1537. GObject.prototype.hasClickListener = function () {
  1538. return this._node.hasEventListener(fgui.Event.CLICK);
  1539. };
  1540. GObject.prototype.on = function (type, listener, target) {
  1541. if (type == fgui.Event.DISPLAY || type == fgui.Event.UNDISPLAY)
  1542. this._partner._emitDisplayEvents = true;
  1543. this._node.on(type, listener, target);
  1544. };
  1545. GObject.prototype.off = function (type, listener, target) {
  1546. this._node.off(type, listener, target);
  1547. };
  1548. Object.defineProperty(GObject.prototype, "draggable", {
  1549. get: function () {
  1550. return this._draggable;
  1551. },
  1552. set: function (value) {
  1553. if (this._draggable != value) {
  1554. this._draggable = value;
  1555. this.initDrag();
  1556. }
  1557. },
  1558. enumerable: false,
  1559. configurable: true
  1560. });
  1561. Object.defineProperty(GObject.prototype, "dragBounds", {
  1562. get: function () {
  1563. return this._dragBounds;
  1564. },
  1565. set: function (value) {
  1566. this._dragBounds = value;
  1567. },
  1568. enumerable: false,
  1569. configurable: true
  1570. });
  1571. GObject.prototype.startDrag = function (touchId) {
  1572. if (!this._node.activeInHierarchy)
  1573. return;
  1574. this.dragBegin(touchId);
  1575. };
  1576. GObject.prototype.stopDrag = function () {
  1577. this.dragEnd();
  1578. };
  1579. Object.defineProperty(GObject.prototype, "dragging", {
  1580. get: function () {
  1581. return GObject.draggingObject == this;
  1582. },
  1583. enumerable: false,
  1584. configurable: true
  1585. });
  1586. GObject.prototype.localToGlobal = function (ax, ay, result) {
  1587. ax = ax || 0;
  1588. ay = ay || 0;
  1589. result = result || new cc.Vec2();
  1590. result.x = ax;
  1591. result.y = ay;
  1592. result.y = -result.y;
  1593. if (!this._pivotAsAnchor) {
  1594. result.x -= this.node.anchorX * this._width;
  1595. result.y += (1 - this.node.anchorY) * this._height;
  1596. }
  1597. this._node.convertToWorldSpaceAR(result, result);
  1598. result.y = fgui.GRoot.inst.height - result.y;
  1599. return result;
  1600. };
  1601. GObject.prototype.globalToLocal = function (ax, ay, result) {
  1602. ax = ax || 0;
  1603. ay = ay || 0;
  1604. result = result || new cc.Vec2();
  1605. result.x = ax;
  1606. result.y = fgui.GRoot.inst.height - ay;
  1607. this._node.convertToNodeSpaceAR(result, result);
  1608. if (!this._pivotAsAnchor) {
  1609. result.x += this._node.anchorX * this._width;
  1610. result.y -= (1 - this._node.anchorY) * this._height;
  1611. }
  1612. result.y = -result.y;
  1613. return result;
  1614. };
  1615. GObject.prototype.localToGlobalRect = function (ax, ay, aw, ah, result) {
  1616. ax = ax || 0;
  1617. ay = ay || 0;
  1618. aw = aw || 0;
  1619. ah = ah || 0;
  1620. result = result || new cc.Rect();
  1621. var pt = this.localToGlobal(ax, ay);
  1622. result.x = pt.x;
  1623. result.y = pt.y;
  1624. pt = this.localToGlobal(ax + aw, ay + ah, pt);
  1625. result.xMax = pt.x;
  1626. result.yMax = pt.y;
  1627. return result;
  1628. };
  1629. GObject.prototype.globalToLocalRect = function (ax, ay, aw, ah, result) {
  1630. ax = ax || 0;
  1631. ay = ay || 0;
  1632. aw = aw || 0;
  1633. ah = ah || 0;
  1634. result = result || new cc.Rect();
  1635. var pt = this.globalToLocal(ax, ay);
  1636. result.x = pt.x;
  1637. result.y = pt.y;
  1638. pt = this.globalToLocal(ax + aw, ay + ah, pt);
  1639. result.xMax = pt.x;
  1640. result.yMax = pt.y;
  1641. return result;
  1642. };
  1643. GObject.prototype.handleControllerChanged = function (c) {
  1644. this._handlingController = true;
  1645. for (var i = 0; i < 10; i++) {
  1646. var gear = this._gears[i];
  1647. if (gear && gear.controller == c)
  1648. gear.apply();
  1649. }
  1650. this._handlingController = false;
  1651. this.checkGearDisplay();
  1652. };
  1653. GObject.prototype.handleAnchorChanged = function () {
  1654. this.handlePositionChanged();
  1655. };
  1656. GObject.prototype.handlePositionChanged = function () {
  1657. var xv = this._x;
  1658. var yv = -this._y;
  1659. if (!this._pivotAsAnchor) {
  1660. xv += this.node.anchorX * this._width;
  1661. yv -= (1 - this.node.anchorY) * this._height;
  1662. }
  1663. if (this._pixelSnapping) {
  1664. xv = Math.round(xv);
  1665. yv = Math.round(yv);
  1666. }
  1667. this._node.setPosition(xv, yv);
  1668. };
  1669. GObject.prototype.handleSizeChanged = function () {
  1670. this._node.setContentSize(this._width, this._height);
  1671. };
  1672. GObject.prototype.handleGrayedChanged = function () {
  1673. };
  1674. GObject.prototype.handleVisibleChanged = function () {
  1675. this._node.active = this._finalVisible;
  1676. if (this instanceof fgui.GGroup)
  1677. this.handleVisibleChanged();
  1678. if (this._parent)
  1679. this._parent.setBoundsChangedFlag();
  1680. };
  1681. GObject.prototype.hitTest = function (globalPt, forTouch) {
  1682. if (forTouch == null)
  1683. forTouch = true;
  1684. if (forTouch && (this._touchDisabled || !this._touchable || !this._node.activeInHierarchy))
  1685. return null;
  1686. if (!this._hitTestPt)
  1687. this._hitTestPt = new cc.Vec2();
  1688. this.globalToLocal(globalPt.x, globalPt.y, this._hitTestPt);
  1689. if (this._pivotAsAnchor) {
  1690. this._hitTestPt.x += this.node.anchorX * this._width;
  1691. this._hitTestPt.y += (1 - this.node.anchorY) * this._height;
  1692. }
  1693. return this._hitTest(this._hitTestPt, globalPt);
  1694. };
  1695. GObject.prototype._hitTest = function (pt, globalPt) {
  1696. if (pt.x >= 0 && pt.y >= 0 && pt.x < this._width && pt.y < this._height)
  1697. return this;
  1698. else
  1699. return null;
  1700. };
  1701. GObject.prototype.getProp = function (index) {
  1702. switch (index) {
  1703. case fgui.ObjectPropID.Text:
  1704. return this.text;
  1705. case fgui.ObjectPropID.Icon:
  1706. return this.icon;
  1707. case fgui.ObjectPropID.Color:
  1708. return null;
  1709. case fgui.ObjectPropID.OutlineColor:
  1710. return null;
  1711. case fgui.ObjectPropID.Playing:
  1712. return false;
  1713. case fgui.ObjectPropID.Frame:
  1714. return 0;
  1715. case fgui.ObjectPropID.DeltaTime:
  1716. return 0;
  1717. case fgui.ObjectPropID.TimeScale:
  1718. return 1;
  1719. case fgui.ObjectPropID.FontSize:
  1720. return 0;
  1721. case fgui.ObjectPropID.Selected:
  1722. return false;
  1723. default:
  1724. return undefined;
  1725. }
  1726. };
  1727. GObject.prototype.setProp = function (index, value) {
  1728. switch (index) {
  1729. case fgui.ObjectPropID.Text:
  1730. this.text = value;
  1731. break;
  1732. case fgui.ObjectPropID.Icon:
  1733. this.icon = value;
  1734. break;
  1735. }
  1736. };
  1737. GObject.prototype.constructFromResource = function () {
  1738. };
  1739. GObject.prototype.setup_beforeAdd = function (buffer, beginPos) {
  1740. buffer.seek(beginPos, 0);
  1741. buffer.skip(5);
  1742. var f1;
  1743. var f2;
  1744. this._id = buffer.readS();
  1745. this._name = buffer.readS();
  1746. f1 = buffer.readInt();
  1747. f2 = buffer.readInt();
  1748. this.setPosition(f1, f2);
  1749. if (buffer.readBool()) {
  1750. this.initWidth = buffer.readInt();
  1751. this.initHeight = buffer.readInt();
  1752. this.setSize(this.initWidth, this.initHeight, true);
  1753. }
  1754. if (buffer.readBool()) {
  1755. this.minWidth = buffer.readInt();
  1756. this.maxWidth = buffer.readInt();
  1757. this.minHeight = buffer.readInt();
  1758. this.maxHeight = buffer.readInt();
  1759. }
  1760. if (buffer.readBool()) {
  1761. f1 = buffer.readFloat();
  1762. f2 = buffer.readFloat();
  1763. this.setScale(f1, f2);
  1764. }
  1765. if (buffer.readBool()) {
  1766. f1 = buffer.readFloat();
  1767. f2 = buffer.readFloat();
  1768. this.setSkew(f1, f2);
  1769. }
  1770. if (buffer.readBool()) {
  1771. f1 = buffer.readFloat();
  1772. f2 = buffer.readFloat();
  1773. this.setPivot(f1, f2, buffer.readBool());
  1774. }
  1775. f1 = buffer.readFloat();
  1776. if (f1 != 1)
  1777. this.alpha = f1;
  1778. f1 = buffer.readFloat();
  1779. if (f1 != 0)
  1780. this.rotation = f1;
  1781. if (!buffer.readBool())
  1782. this.visible = false;
  1783. if (!buffer.readBool())
  1784. this.touchable = false;
  1785. if (buffer.readBool())
  1786. this.grayed = true;
  1787. this.blendMode = buffer.readByte();
  1788. var filter = buffer.readByte();
  1789. if (filter == 1) {
  1790. }
  1791. var str = buffer.readS();
  1792. if (str != null)
  1793. this.data = str;
  1794. };
  1795. GObject.prototype.setup_afterAdd = function (buffer, beginPos) {
  1796. buffer.seek(beginPos, 1);
  1797. var str = buffer.readS();
  1798. if (str != null)
  1799. this.tooltips = str;
  1800. var groupId = buffer.readShort();
  1801. if (groupId >= 0)
  1802. this.group = this.parent.getChildAt(groupId);
  1803. buffer.seek(beginPos, 2);
  1804. var cnt = buffer.readShort();
  1805. for (var i = 0; i < cnt; i++) {
  1806. var nextPos = buffer.readShort();
  1807. nextPos += buffer.position;
  1808. var gear = this.getGear(buffer.readByte());
  1809. gear.setup(buffer);
  1810. buffer.position = nextPos;
  1811. }
  1812. };
  1813. GObject.prototype.onRollOver = function () {
  1814. this.root.showTooltips(this.tooltips);
  1815. };
  1816. ;
  1817. GObject.prototype.onRollOut = function () {
  1818. this.root.hideTooltips();
  1819. };
  1820. ;
  1821. GObject.prototype.initDrag = function () {
  1822. if (this._draggable) {
  1823. this.on(fgui.Event.TOUCH_BEGIN, this.onTouchBegin_0, this);
  1824. this.on(fgui.Event.TOUCH_MOVE, this.onTouchMove_0, this);
  1825. this.on(fgui.Event.TOUCH_END, this.onTouchEnd_0, this);
  1826. }
  1827. else {
  1828. this.off(fgui.Event.TOUCH_BEGIN, this.onTouchBegin_0, this);
  1829. this.off(fgui.Event.TOUCH_MOVE, this.onTouchMove_0, this);
  1830. this.off(fgui.Event.TOUCH_END, this.onTouchEnd_0, this);
  1831. }
  1832. };
  1833. GObject.prototype.dragBegin = function (touchId) {
  1834. if (GObject.draggingObject) {
  1835. var tmp = GObject.draggingObject;
  1836. tmp.stopDrag();
  1837. GObject.draggingObject = null;
  1838. tmp._node.emit(fgui.Event.DRAG_END);
  1839. }
  1840. if (touchId == undefined)
  1841. touchId = fgui.GRoot.inst.inputProcessor.getAllTouches()[0];
  1842. sGlobalDragStart.set(fgui.GRoot.inst.getTouchPosition(touchId));
  1843. this.localToGlobalRect(0, 0, this._width, this._height, sGlobalRect);
  1844. GObject.draggingObject = this;
  1845. this._dragTesting = true;
  1846. fgui.GRoot.inst.inputProcessor.addTouchMonitor(touchId, this);
  1847. this.on(fgui.Event.TOUCH_MOVE, this.onTouchMove_0, this);
  1848. this.on(fgui.Event.TOUCH_END, this.onTouchEnd_0, this);
  1849. };
  1850. GObject.prototype.dragEnd = function () {
  1851. if (GObject.draggingObject == this) {
  1852. this._dragTesting = false;
  1853. GObject.draggingObject = null;
  1854. }
  1855. sDragQuery = false;
  1856. };
  1857. GObject.prototype.onTouchBegin_0 = function (evt) {
  1858. if (this._dragStartPos == null)
  1859. this._dragStartPos = new cc.Vec2();
  1860. this._dragStartPos.set(evt.pos);
  1861. this._dragTesting = true;
  1862. evt.captureTouch();
  1863. };
  1864. GObject.prototype.onTouchMove_0 = function (evt) {
  1865. if (GObject.draggingObject != this && this._draggable && this._dragTesting) {
  1866. var sensitivity = fgui.UIConfig.touchDragSensitivity;
  1867. if (this._dragStartPos
  1868. && Math.abs(this._dragStartPos.x - evt.pos.x) < sensitivity
  1869. && Math.abs(this._dragStartPos.y - evt.pos.y) < sensitivity)
  1870. return;
  1871. this._dragTesting = false;
  1872. sDragQuery = true;
  1873. this._node.emit(fgui.Event.DRAG_START, evt);
  1874. if (sDragQuery)
  1875. this.dragBegin(evt.touchId);
  1876. }
  1877. if (GObject.draggingObject == this) {
  1878. var xx = evt.pos.x - sGlobalDragStart.x + sGlobalRect.x;
  1879. var yy = evt.pos.y - sGlobalDragStart.y + sGlobalRect.y;
  1880. if (this._dragBounds) {
  1881. var rect = fgui.GRoot.inst.localToGlobalRect(this._dragBounds.x, this._dragBounds.y, this._dragBounds.width, this._dragBounds.height, sDragHelperRect);
  1882. if (xx < rect.x)
  1883. xx = rect.x;
  1884. else if (xx + sGlobalRect.width > rect.xMax) {
  1885. xx = rect.xMax - sGlobalRect.width;
  1886. if (xx < rect.x)
  1887. xx = rect.x;
  1888. }
  1889. if (yy < rect.y)
  1890. yy = rect.y;
  1891. else if (yy + sGlobalRect.height > rect.yMax) {
  1892. yy = rect.yMax - sGlobalRect.height;
  1893. if (yy < rect.y)
  1894. yy = rect.y;
  1895. }
  1896. }
  1897. sUpdateInDragging = true;
  1898. var pt = this.parent.globalToLocal(xx, yy, sHelperPoint);
  1899. this.setPosition(Math.round(pt.x), Math.round(pt.y));
  1900. sUpdateInDragging = false;
  1901. this._node.emit(fgui.Event.DRAG_MOVE, evt);
  1902. }
  1903. };
  1904. GObject.prototype.onTouchEnd_0 = function (evt) {
  1905. if (GObject.draggingObject == this) {
  1906. GObject.draggingObject = null;
  1907. this._node.emit(fgui.Event.DRAG_END, evt);
  1908. }
  1909. };
  1910. GObject._defaultGroupIndex = -1;
  1911. return GObject;
  1912. }());
  1913. fgui.GObject = GObject;
  1914. var sGlobalDragStart = new cc.Vec2();
  1915. var sGlobalRect = new cc.Rect();
  1916. var sHelperPoint = new cc.Vec2();
  1917. var sDragHelperRect = new cc.Rect();
  1918. var sUpdateInDragging;
  1919. var sDragQuery = false;
  1920. var GObjectPartner = (function (_super) {
  1921. __extends(GObjectPartner, _super);
  1922. function GObjectPartner() {
  1923. var _this = _super !== null && _super.apply(this, arguments) || this;
  1924. _this._emitDisplayEvents = false;
  1925. return _this;
  1926. }
  1927. GObjectPartner.prototype.callLater = function (callback, delay) {
  1928. if (!cc.director.getScheduler().isScheduled(callback, this))
  1929. this.scheduleOnce(callback, delay);
  1930. };
  1931. GObjectPartner.prototype.onClickLink = function (evt, text) {
  1932. this.node.emit(fgui.Event.LINK, text, evt);
  1933. };
  1934. GObjectPartner.prototype.onEnable = function () {
  1935. this.node["$gobj"].onEnable();
  1936. if (this._emitDisplayEvents)
  1937. this.node.emit(fgui.Event.DISPLAY);
  1938. };
  1939. GObjectPartner.prototype.onDisable = function () {
  1940. this.node["$gobj"].onDisable();
  1941. if (this._emitDisplayEvents)
  1942. this.node.emit(fgui.Event.UNDISPLAY);
  1943. };
  1944. GObjectPartner.prototype.update = function (dt) {
  1945. this.node["$gobj"].onUpdate(dt);
  1946. };
  1947. GObjectPartner.prototype.onDestroy = function () {
  1948. this.node["$gobj"].onDestroy();
  1949. };
  1950. return GObjectPartner;
  1951. }(cc.Component));
  1952. fgui.GObjectPartner = GObjectPartner;
  1953. })(fgui || (fgui = {}));
  1954. (function (fgui) {
  1955. var GComponent = (function (_super) {
  1956. __extends(GComponent, _super);
  1957. function GComponent() {
  1958. var _this = _super.call(this) || this;
  1959. _this._sortingChildCount = 0;
  1960. _this._childrenRenderOrder = fgui.ChildrenRenderOrder.Ascent;
  1961. _this._apexIndex = 0;
  1962. _this._node.name = "GComponent";
  1963. _this._children = new Array();
  1964. _this._controllers = new Array();
  1965. _this._transitions = new Array();
  1966. _this._margin = new fgui.Margin();
  1967. _this._alignOffset = new cc.Vec2();
  1968. _this._container = new cc.Node("Container");
  1969. _this._container.setAnchorPoint(0, 1);
  1970. _this._node.addChild(_this._container);
  1971. return _this;
  1972. }
  1973. GComponent.prototype.dispose = function () {
  1974. var i;
  1975. var cnt;
  1976. cnt = this._transitions.length;
  1977. for (i = 0; i < cnt; ++i) {
  1978. var trans = this._transitions[i];
  1979. trans.dispose();
  1980. }
  1981. cnt = this._controllers.length;
  1982. for (i = 0; i < cnt; ++i) {
  1983. var cc = this._controllers[i];
  1984. cc.dispose();
  1985. }
  1986. if (this._scrollPane)
  1987. this._scrollPane.destroy();
  1988. cnt = this._children.length;
  1989. for (i = cnt - 1; i >= 0; --i) {
  1990. var obj = this._children[i];
  1991. obj._parent = null;
  1992. obj.dispose();
  1993. }
  1994. this._boundsChanged = false;
  1995. _super.prototype.dispose.call(this);
  1996. };
  1997. Object.defineProperty(GComponent.prototype, "displayListContainer", {
  1998. get: function () {
  1999. return this._container;
  2000. },
  2001. enumerable: false,
  2002. configurable: true
  2003. });
  2004. GComponent.prototype.addChild = function (child) {
  2005. this.addChildAt(child, this._children.length);
  2006. return child;
  2007. };
  2008. GComponent.prototype.addChildAt = function (child, index) {
  2009. if (!child)
  2010. throw "child is null";
  2011. var numChildren = this._children.length;
  2012. if (index >= 0 && index <= numChildren) {
  2013. if (child.parent == this) {
  2014. this.setChildIndex(child, index);
  2015. }
  2016. else {
  2017. child.removeFromParent();
  2018. child._parent = this;
  2019. var cnt = this._children.length;
  2020. if (child.sortingOrder != 0) {
  2021. this._sortingChildCount++;
  2022. index = this.getInsertPosForSortingChild(child);
  2023. }
  2024. else if (this._sortingChildCount > 0) {
  2025. if (index > (cnt - this._sortingChildCount))
  2026. index = cnt - this._sortingChildCount;
  2027. }
  2028. if (index == cnt)
  2029. this._children.push(child);
  2030. else
  2031. this._children.splice(index, 0, child);
  2032. this.onChildAdd(child, index);
  2033. this.setBoundsChangedFlag();
  2034. }
  2035. return child;
  2036. }
  2037. else {
  2038. throw "Invalid child index";
  2039. }
  2040. };
  2041. GComponent.prototype.getInsertPosForSortingChild = function (target) {
  2042. var cnt = this._children.length;
  2043. var i = 0;
  2044. for (i = 0; i < cnt; i++) {
  2045. var child = this._children[i];
  2046. if (child == target)
  2047. continue;
  2048. if (target.sortingOrder < child.sortingOrder)
  2049. break;
  2050. }
  2051. return i;
  2052. };
  2053. GComponent.prototype.removeChild = function (child, dispose) {
  2054. var childIndex = this._children.indexOf(child);
  2055. if (childIndex != -1) {
  2056. this.removeChildAt(childIndex, dispose);
  2057. }
  2058. return child;
  2059. };
  2060. GComponent.prototype.removeChildAt = function (index, dispose) {
  2061. if (index >= 0 && index < this.numChildren) {
  2062. var child = this._children[index];
  2063. child._parent = null;
  2064. if (child.sortingOrder != 0)
  2065. this._sortingChildCount--;
  2066. this._children.splice(index, 1);
  2067. child.group = null;
  2068. this._container.removeChild(child.node);
  2069. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Arch)
  2070. this._partner.callLater(this.buildNativeDisplayList);
  2071. if (dispose)
  2072. child.dispose();
  2073. else
  2074. child.node.parent = null;
  2075. this.setBoundsChangedFlag();
  2076. return child;
  2077. }
  2078. else {
  2079. throw "Invalid child index";
  2080. }
  2081. };
  2082. GComponent.prototype.removeChildren = function (beginIndex, endIndex, dispose) {
  2083. if (beginIndex == undefined)
  2084. beginIndex = 0;
  2085. if (endIndex == undefined)
  2086. endIndex = -1;
  2087. if (endIndex < 0 || endIndex >= this.numChildren)
  2088. endIndex = this.numChildren - 1;
  2089. for (var i = beginIndex; i <= endIndex; ++i)
  2090. this.removeChildAt(beginIndex, dispose);
  2091. };
  2092. GComponent.prototype.getChildAt = function (index) {
  2093. if (index >= 0 && index < this.numChildren)
  2094. return this._children[index];
  2095. else
  2096. throw "Invalid child index";
  2097. };
  2098. GComponent.prototype.getChild = function (name) {
  2099. var cnt = this._children.length;
  2100. for (var i = 0; i < cnt; ++i) {
  2101. if (this._children[i].name == name)
  2102. return this._children[i];
  2103. }
  2104. return null;
  2105. };
  2106. GComponent.prototype.getChildByPath = function (path) {
  2107. var arr = path.split(".");
  2108. var cnt = arr.length;
  2109. var gcom = this;
  2110. var obj;
  2111. for (var i = 0; i < cnt; ++i) {
  2112. obj = gcom.getChild(arr[i]);
  2113. if (!obj)
  2114. break;
  2115. if (i != cnt - 1) {
  2116. if (!(obj instanceof GComponent)) {
  2117. obj = null;
  2118. break;
  2119. }
  2120. else
  2121. gcom = obj;
  2122. }
  2123. }
  2124. return obj;
  2125. };
  2126. GComponent.prototype.getVisibleChild = function (name) {
  2127. var cnt = this._children.length;
  2128. for (var i = 0; i < cnt; ++i) {
  2129. var child = this._children[i];
  2130. if (child._finalVisible && child.name == name)
  2131. return child;
  2132. }
  2133. return null;
  2134. };
  2135. GComponent.prototype.getChildInGroup = function (name, group) {
  2136. var cnt = this._children.length;
  2137. for (var i = 0; i < cnt; ++i) {
  2138. var child = this._children[i];
  2139. if (child.group == group && child.name == name)
  2140. return child;
  2141. }
  2142. return null;
  2143. };
  2144. GComponent.prototype.getChildById = function (id) {
  2145. var cnt = this._children.length;
  2146. for (var i = 0; i < cnt; ++i) {
  2147. if (this._children[i]._id == id)
  2148. return this._children[i];
  2149. }
  2150. return null;
  2151. };
  2152. GComponent.prototype.getChildIndex = function (child) {
  2153. return this._children.indexOf(child);
  2154. };
  2155. GComponent.prototype.setChildIndex = function (child, index) {
  2156. var oldIndex = this._children.indexOf(child);
  2157. if (oldIndex == -1)
  2158. throw "Not a child of this container";
  2159. if (child.sortingOrder != 0)
  2160. return;
  2161. var cnt = this._children.length;
  2162. if (this._sortingChildCount > 0) {
  2163. if (index > (cnt - this._sortingChildCount - 1))
  2164. index = cnt - this._sortingChildCount - 1;
  2165. }
  2166. this._setChildIndex(child, oldIndex, index);
  2167. };
  2168. GComponent.prototype.setChildIndexBefore = function (child, index) {
  2169. var oldIndex = this._children.indexOf(child);
  2170. if (oldIndex == -1)
  2171. throw "Not a child of this container";
  2172. if (child.sortingOrder != 0)
  2173. return oldIndex;
  2174. var cnt = this._children.length;
  2175. if (this._sortingChildCount > 0) {
  2176. if (index > (cnt - this._sortingChildCount - 1))
  2177. index = cnt - this._sortingChildCount - 1;
  2178. }
  2179. if (oldIndex < index)
  2180. return this._setChildIndex(child, oldIndex, index - 1);
  2181. else
  2182. return this._setChildIndex(child, oldIndex, index);
  2183. };
  2184. GComponent.prototype._setChildIndex = function (child, oldIndex, index) {
  2185. var cnt = this._children.length;
  2186. if (index > cnt)
  2187. index = cnt;
  2188. if (oldIndex == index)
  2189. return oldIndex;
  2190. this._children.splice(oldIndex, 1);
  2191. this._children.splice(index, 0, child);
  2192. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Ascent)
  2193. child.node.setSiblingIndex(index);
  2194. else if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Descent)
  2195. child.node.setSiblingIndex(cnt - index);
  2196. else
  2197. this._partner.callLater(this.buildNativeDisplayList);
  2198. this.setBoundsChangedFlag();
  2199. return index;
  2200. };
  2201. GComponent.prototype.swapChildren = function (child1, child2) {
  2202. var index1 = this._children.indexOf(child1);
  2203. var index2 = this._children.indexOf(child2);
  2204. if (index1 == -1 || index2 == -1)
  2205. throw "Not a child of this container";
  2206. this.swapChildrenAt(index1, index2);
  2207. };
  2208. GComponent.prototype.swapChildrenAt = function (index1, index2) {
  2209. var child1 = this._children[index1];
  2210. var child2 = this._children[index2];
  2211. this.setChildIndex(child1, index2);
  2212. this.setChildIndex(child2, index1);
  2213. };
  2214. Object.defineProperty(GComponent.prototype, "numChildren", {
  2215. get: function () {
  2216. return this._children.length;
  2217. },
  2218. enumerable: false,
  2219. configurable: true
  2220. });
  2221. GComponent.prototype.isAncestorOf = function (child) {
  2222. if (child == null)
  2223. return false;
  2224. var p = child.parent;
  2225. while (p) {
  2226. if (p == this)
  2227. return true;
  2228. p = p.parent;
  2229. }
  2230. return false;
  2231. };
  2232. GComponent.prototype.addController = function (controller) {
  2233. this._controllers.push(controller);
  2234. controller.parent = this;
  2235. this.applyController(controller);
  2236. };
  2237. GComponent.prototype.getControllerAt = function (index) {
  2238. return this._controllers[index];
  2239. };
  2240. GComponent.prototype.getController = function (name) {
  2241. var cnt = this._controllers.length;
  2242. for (var i = 0; i < cnt; ++i) {
  2243. var c = this._controllers[i];
  2244. if (c.name == name)
  2245. return c;
  2246. }
  2247. return null;
  2248. };
  2249. GComponent.prototype.removeController = function (c) {
  2250. var index = this._controllers.indexOf(c);
  2251. if (index == -1)
  2252. throw "controller not exists";
  2253. c.parent = null;
  2254. this._controllers.splice(index, 1);
  2255. var length = this._children.length;
  2256. for (var i = 0; i < length; i++) {
  2257. var child = this._children[i];
  2258. child.handleControllerChanged(c);
  2259. }
  2260. };
  2261. Object.defineProperty(GComponent.prototype, "controllers", {
  2262. get: function () {
  2263. return this._controllers;
  2264. },
  2265. enumerable: false,
  2266. configurable: true
  2267. });
  2268. GComponent.prototype.onChildAdd = function (child, index) {
  2269. child.node.parent = this._container;
  2270. child.node.active = child._finalVisible;
  2271. if (this._buildingDisplayList)
  2272. return;
  2273. var cnt = this._children.length;
  2274. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Ascent)
  2275. child.node.setSiblingIndex(index);
  2276. else if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Descent)
  2277. child.node.setSiblingIndex(cnt - index);
  2278. else
  2279. this._partner.callLater(this.buildNativeDisplayList);
  2280. };
  2281. GComponent.prototype.buildNativeDisplayList = function (dt) {
  2282. if (!isNaN(dt)) {
  2283. var _t = (this.node["$gobj"]);
  2284. _t.buildNativeDisplayList();
  2285. return;
  2286. }
  2287. var cnt = this._children.length;
  2288. if (cnt == 0)
  2289. return;
  2290. var child;
  2291. switch (this._childrenRenderOrder) {
  2292. case fgui.ChildrenRenderOrder.Ascent:
  2293. {
  2294. var j = 0;
  2295. for (var i = 0; i < cnt; i++) {
  2296. child = this._children[i];
  2297. child.node.setSiblingIndex(j++);
  2298. }
  2299. }
  2300. break;
  2301. case fgui.ChildrenRenderOrder.Descent:
  2302. {
  2303. var j = 0;
  2304. for (var i = cnt - 1; i >= 0; i--) {
  2305. child = this._children[i];
  2306. child.node.setSiblingIndex(j++);
  2307. }
  2308. }
  2309. break;
  2310. case fgui.ChildrenRenderOrder.Arch:
  2311. {
  2312. var j = 0;
  2313. for (var i = 0; i < this._apexIndex; i++) {
  2314. child = this._children[i];
  2315. child.node.setSiblingIndex(j++);
  2316. }
  2317. for (var i = cnt - 1; i >= this._apexIndex; i--) {
  2318. child = this._children[i];
  2319. child.node.setSiblingIndex(j++);
  2320. }
  2321. }
  2322. break;
  2323. }
  2324. };
  2325. GComponent.prototype.applyController = function (c) {
  2326. this._applyingController = c;
  2327. var child;
  2328. var length = this._children.length;
  2329. for (var i = 0; i < length; i++) {
  2330. child = this._children[i];
  2331. child.handleControllerChanged(c);
  2332. }
  2333. this._applyingController = null;
  2334. c.runActions();
  2335. };
  2336. GComponent.prototype.applyAllControllers = function () {
  2337. var cnt = this._controllers.length;
  2338. for (var i = 0; i < cnt; ++i) {
  2339. this.applyController(this._controllers[i]);
  2340. }
  2341. };
  2342. GComponent.prototype.adjustRadioGroupDepth = function (obj, c) {
  2343. var cnt = this._children.length;
  2344. var i;
  2345. var child;
  2346. var myIndex = -1, maxIndex = -1;
  2347. for (i = 0; i < cnt; i++) {
  2348. child = this._children[i];
  2349. if (child == obj) {
  2350. myIndex = i;
  2351. }
  2352. else if ((child instanceof fgui.GButton) && child.relatedController == c) {
  2353. if (i > maxIndex)
  2354. maxIndex = i;
  2355. }
  2356. }
  2357. if (myIndex < maxIndex) {
  2358. if (this._applyingController)
  2359. this._children[maxIndex].handleControllerChanged(this._applyingController);
  2360. this.swapChildrenAt(myIndex, maxIndex);
  2361. }
  2362. };
  2363. GComponent.prototype.getTransitionAt = function (index) {
  2364. return this._transitions[index];
  2365. };
  2366. GComponent.prototype.getTransition = function (transName) {
  2367. var cnt = this._transitions.length;
  2368. for (var i = 0; i < cnt; ++i) {
  2369. var trans = this._transitions[i];
  2370. if (trans.name == transName)
  2371. return trans;
  2372. }
  2373. return null;
  2374. };
  2375. GComponent.prototype.isChildInView = function (child) {
  2376. if (this._rectMask) {
  2377. return child.x + child.width >= 0 && child.x <= this.width
  2378. && child.y + child.height >= 0 && child.y <= this.height;
  2379. }
  2380. else if (this._scrollPane) {
  2381. return this._scrollPane.isChildInView(child);
  2382. }
  2383. else
  2384. return true;
  2385. };
  2386. GComponent.prototype.getFirstChildInView = function () {
  2387. var cnt = this._children.length;
  2388. for (var i = 0; i < cnt; ++i) {
  2389. var child = this._children[i];
  2390. if (this.isChildInView(child))
  2391. return i;
  2392. }
  2393. return -1;
  2394. };
  2395. Object.defineProperty(GComponent.prototype, "scrollPane", {
  2396. get: function () {
  2397. return this._scrollPane;
  2398. },
  2399. enumerable: false,
  2400. configurable: true
  2401. });
  2402. Object.defineProperty(GComponent.prototype, "opaque", {
  2403. get: function () {
  2404. return this._opaque;
  2405. },
  2406. set: function (value) {
  2407. this._opaque = value;
  2408. },
  2409. enumerable: false,
  2410. configurable: true
  2411. });
  2412. Object.defineProperty(GComponent.prototype, "margin", {
  2413. get: function () {
  2414. return this._margin;
  2415. },
  2416. set: function (value) {
  2417. this._margin.copy(value);
  2418. this.handleSizeChanged();
  2419. },
  2420. enumerable: false,
  2421. configurable: true
  2422. });
  2423. Object.defineProperty(GComponent.prototype, "childrenRenderOrder", {
  2424. get: function () {
  2425. return this._childrenRenderOrder;
  2426. },
  2427. set: function (value) {
  2428. if (this._childrenRenderOrder != value) {
  2429. this._childrenRenderOrder = value;
  2430. this.buildNativeDisplayList();
  2431. }
  2432. },
  2433. enumerable: false,
  2434. configurable: true
  2435. });
  2436. Object.defineProperty(GComponent.prototype, "apexIndex", {
  2437. get: function () {
  2438. return this._apexIndex;
  2439. },
  2440. set: function (value) {
  2441. if (this._apexIndex != value) {
  2442. this._apexIndex = value;
  2443. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Arch)
  2444. this.buildNativeDisplayList();
  2445. }
  2446. },
  2447. enumerable: false,
  2448. configurable: true
  2449. });
  2450. Object.defineProperty(GComponent.prototype, "mask", {
  2451. get: function () {
  2452. return this._maskContent;
  2453. },
  2454. set: function (value) {
  2455. this.setMask(value, false);
  2456. },
  2457. enumerable: false,
  2458. configurable: true
  2459. });
  2460. GComponent.prototype.setMask = function (value, inverted) {
  2461. if (this._maskContent) {
  2462. this._maskContent.node.off(cc.Node.EventType.POSITION_CHANGED, this.onMaskContentChanged, this);
  2463. this._maskContent.node.off(cc.Node.EventType.SIZE_CHANGED, this.onMaskContentChanged, this);
  2464. this._maskContent.node.off(cc.Node.EventType.SCALE_CHANGED, this.onMaskContentChanged, this);
  2465. this._maskContent.node.off(cc.Node.EventType.ANCHOR_CHANGED, this.onMaskContentChanged, this);
  2466. this._maskContent.visible = true;
  2467. }
  2468. this._maskContent = value;
  2469. if (this._maskContent) {
  2470. if (!(value instanceof fgui.GImage) && !(value instanceof fgui.GGraph))
  2471. return;
  2472. if (!this._customMask) {
  2473. var maskNode = new cc.Node("Mask");
  2474. maskNode.parent = this._node;
  2475. if (this._scrollPane)
  2476. this._container.parent.parent = maskNode;
  2477. else
  2478. this._container.parent = maskNode;
  2479. this._customMask = maskNode.addComponent(cc.Mask);
  2480. }
  2481. value.visible = false;
  2482. value.node.on(cc.Node.EventType.POSITION_CHANGED, this.onMaskContentChanged, this);
  2483. value.node.on(cc.Node.EventType.SIZE_CHANGED, this.onMaskContentChanged, this);
  2484. value.node.on(cc.Node.EventType.SCALE_CHANGED, this.onMaskContentChanged, this);
  2485. value.node.on(cc.Node.EventType.ANCHOR_CHANGED, this.onMaskContentChanged, this);
  2486. this._customMask.inverted = inverted;
  2487. if (this._node.activeInHierarchy)
  2488. this.onMaskReady();
  2489. else
  2490. this.on(fgui.Event.DISPLAY, this.onMaskReady, this);
  2491. this.onMaskContentChanged();
  2492. if (this._scrollPane)
  2493. this._scrollPane.adjustMaskContainer();
  2494. else
  2495. this._container.setPosition(0, 0);
  2496. }
  2497. else if (this._customMask) {
  2498. if (this._scrollPane)
  2499. this._container.parent.parent = this._node;
  2500. else
  2501. this._container.parent = this._node;
  2502. this._customMask.node.destroy();
  2503. this._customMask = null;
  2504. if (this._scrollPane)
  2505. this._scrollPane.adjustMaskContainer();
  2506. else
  2507. this._container.setPosition(this._pivotCorrectX, this._pivotCorrectY);
  2508. }
  2509. };
  2510. GComponent.prototype.onMaskReady = function () {
  2511. this.off(fgui.Event.DISPLAY, this.onMaskReady, this);
  2512. if (this._maskContent instanceof fgui.GImage) {
  2513. this._customMask.type = cc.Mask.Type.IMAGE_STENCIL;
  2514. this._customMask.alphaThreshold = 0.0001;
  2515. this._customMask.spriteFrame = this._maskContent._content.spriteFrame;
  2516. }
  2517. else if (this._maskContent instanceof fgui.GGraph) {
  2518. if (this._maskContent.type == 2)
  2519. this._customMask.type = cc.Mask.Type.ELLIPSE;
  2520. else
  2521. this._customMask.type = cc.Mask.Type.RECT;
  2522. }
  2523. };
  2524. GComponent.prototype.onMaskContentChanged = function () {
  2525. var maskNode = this._customMask.node;
  2526. var contentNode = this._maskContent.node;
  2527. var w = contentNode.width * contentNode.scaleX;
  2528. var h = contentNode.height * contentNode.scaleY;
  2529. maskNode.setContentSize(w, h);
  2530. var left = contentNode.x - contentNode.anchorX * w;
  2531. var top = contentNode.y - contentNode.anchorY * h;
  2532. maskNode.setAnchorPoint(-left / maskNode.width, -top / maskNode.height);
  2533. maskNode.setPosition(this._pivotCorrectX, this._pivotCorrectY);
  2534. };
  2535. Object.defineProperty(GComponent.prototype, "_pivotCorrectX", {
  2536. get: function () {
  2537. return -this.pivotX * this._width + this._margin.left;
  2538. },
  2539. enumerable: false,
  2540. configurable: true
  2541. });
  2542. Object.defineProperty(GComponent.prototype, "_pivotCorrectY", {
  2543. get: function () {
  2544. return this.pivotY * this._height - this._margin.top;
  2545. },
  2546. enumerable: false,
  2547. configurable: true
  2548. });
  2549. Object.defineProperty(GComponent.prototype, "baseUserData", {
  2550. get: function () {
  2551. var buffer = this.packageItem.rawData;
  2552. buffer.seek(0, 4);
  2553. return buffer.readS();
  2554. },
  2555. enumerable: false,
  2556. configurable: true
  2557. });
  2558. GComponent.prototype.setupScroll = function (buffer) {
  2559. this._scrollPane = this._node.addComponent(fgui.ScrollPane);
  2560. this._scrollPane.setup(buffer);
  2561. };
  2562. GComponent.prototype.setupOverflow = function (overflow) {
  2563. if (overflow == fgui.OverflowType.Hidden)
  2564. this._rectMask = this._container.addComponent(cc.Mask);
  2565. if (!this._margin.isNone)
  2566. this.handleSizeChanged();
  2567. };
  2568. GComponent.prototype.handleAnchorChanged = function () {
  2569. _super.prototype.handleAnchorChanged.call(this);
  2570. if (this._customMask)
  2571. this._customMask.node.setPosition(this._pivotCorrectX, this._pivotCorrectY);
  2572. else if (this._scrollPane)
  2573. this._scrollPane.adjustMaskContainer();
  2574. else
  2575. this._container.setPosition(this._pivotCorrectX + this._alignOffset.x, this._pivotCorrectY - this._alignOffset.y);
  2576. };
  2577. GComponent.prototype.handleSizeChanged = function () {
  2578. _super.prototype.handleSizeChanged.call(this);
  2579. if (this._customMask)
  2580. this._customMask.node.setPosition(this._pivotCorrectX, this._pivotCorrectY);
  2581. else if (!this._scrollPane)
  2582. this._container.setPosition(this._pivotCorrectX, this._pivotCorrectY);
  2583. if (this._scrollPane)
  2584. this._scrollPane.onOwnerSizeChanged();
  2585. else
  2586. this._container.setContentSize(this.viewWidth, this.viewHeight);
  2587. };
  2588. GComponent.prototype.handleGrayedChanged = function () {
  2589. var c = this.getController("grayed");
  2590. if (c) {
  2591. c.selectedIndex = this.grayed ? 1 : 0;
  2592. return;
  2593. }
  2594. var v = this.grayed;
  2595. var cnt = this._children.length;
  2596. for (var i = 0; i < cnt; ++i) {
  2597. this._children[i].grayed = v;
  2598. }
  2599. };
  2600. GComponent.prototype.handleControllerChanged = function (c) {
  2601. _super.prototype.handleControllerChanged.call(this, c);
  2602. if (this._scrollPane)
  2603. this._scrollPane.handleControllerChanged(c);
  2604. };
  2605. GComponent.prototype._hitTest = function (pt, globalPt) {
  2606. if (this._customMask) {
  2607. s_vec2.set(globalPt);
  2608. s_vec2.y = fgui.GRoot.inst.height - globalPt.y;
  2609. var b = this._customMask["_hitTest"](s_vec2) || false;
  2610. if (!b)
  2611. return null;
  2612. }
  2613. if (this.hitArea) {
  2614. if (!this.hitArea.hitTest(pt, globalPt))
  2615. return null;
  2616. }
  2617. else if (this._rectMask) {
  2618. s_vec2.set(pt);
  2619. s_vec2.x += this._container.x;
  2620. s_vec2.y += this._container.y;
  2621. var clippingSize = this._container.getContentSize();
  2622. if (s_vec2.x < 0 || s_vec2.y < 0 || s_vec2.x >= clippingSize.width || s_vec2.y >= clippingSize.height)
  2623. return null;
  2624. }
  2625. if (this._scrollPane) {
  2626. var target_1 = this._scrollPane.hitTest(pt, globalPt);
  2627. if (!target_1)
  2628. return null;
  2629. if (target_1 != this)
  2630. return target_1;
  2631. }
  2632. var target = null;
  2633. var cnt = this._children.length;
  2634. for (var i = cnt - 1; i >= 0; i--) {
  2635. var child = this._children[i];
  2636. if (this._maskContent == child || child._touchDisabled)
  2637. continue;
  2638. target = child.hitTest(globalPt);
  2639. if (target)
  2640. break;
  2641. }
  2642. if (!target && this._opaque && (this.hitArea || pt.x >= 0 && pt.y >= 0 && pt.x < this._width && pt.y < this._height))
  2643. target = this;
  2644. return target;
  2645. };
  2646. GComponent.prototype.setBoundsChangedFlag = function () {
  2647. if (!this._scrollPane && !this._trackBounds)
  2648. return;
  2649. if (!this._boundsChanged) {
  2650. this._boundsChanged = true;
  2651. this._partner.callLater(this.refresh);
  2652. }
  2653. };
  2654. GComponent.prototype.refresh = function (dt) {
  2655. if (!isNaN(dt)) {
  2656. var _t = (this.node["$gobj"]);
  2657. _t.refresh();
  2658. return;
  2659. }
  2660. if (this._boundsChanged) {
  2661. var len = this._children.length;
  2662. if (len > 0) {
  2663. for (var i = 0; i < len; i++) {
  2664. var child = this._children[i];
  2665. child.ensureSizeCorrect();
  2666. }
  2667. }
  2668. this.updateBounds();
  2669. }
  2670. };
  2671. GComponent.prototype.ensureBoundsCorrect = function () {
  2672. var len = this._children.length;
  2673. if (len > 0) {
  2674. for (var i = 0; i < len; i++) {
  2675. var child = this._children[i];
  2676. child.ensureSizeCorrect();
  2677. }
  2678. }
  2679. if (this._boundsChanged)
  2680. this.updateBounds();
  2681. };
  2682. GComponent.prototype.updateBounds = function () {
  2683. var ax = 0, ay = 0, aw = 0, ah = 0;
  2684. var len = this._children.length;
  2685. if (len > 0) {
  2686. ax = Number.POSITIVE_INFINITY, ay = Number.POSITIVE_INFINITY;
  2687. var ar = Number.NEGATIVE_INFINITY, ab = Number.NEGATIVE_INFINITY;
  2688. var tmp = 0;
  2689. var i = 0;
  2690. for (var i = 0; i < len; i++) {
  2691. var child = this._children[i];
  2692. tmp = child.x;
  2693. if (tmp < ax)
  2694. ax = tmp;
  2695. tmp = child.y;
  2696. if (tmp < ay)
  2697. ay = tmp;
  2698. tmp = child.x + child.actualWidth;
  2699. if (tmp > ar)
  2700. ar = tmp;
  2701. tmp = child.y + child.actualHeight;
  2702. if (tmp > ab)
  2703. ab = tmp;
  2704. }
  2705. aw = ar - ax;
  2706. ah = ab - ay;
  2707. }
  2708. this.setBounds(ax, ay, aw, ah);
  2709. };
  2710. GComponent.prototype.setBounds = function (ax, ay, aw, ah) {
  2711. if (ah === void 0) { ah = 0; }
  2712. this._boundsChanged = false;
  2713. if (this._scrollPane)
  2714. this._scrollPane.setContentSize(Math.round(ax + aw), Math.round(ay + ah));
  2715. };
  2716. Object.defineProperty(GComponent.prototype, "viewWidth", {
  2717. get: function () {
  2718. if (this._scrollPane)
  2719. return this._scrollPane.viewWidth;
  2720. else
  2721. return this.width - this._margin.left - this._margin.right;
  2722. },
  2723. set: function (value) {
  2724. if (this._scrollPane)
  2725. this._scrollPane.viewWidth = value;
  2726. else
  2727. this.width = value + this._margin.left + this._margin.right;
  2728. },
  2729. enumerable: false,
  2730. configurable: true
  2731. });
  2732. Object.defineProperty(GComponent.prototype, "viewHeight", {
  2733. get: function () {
  2734. if (this._scrollPane)
  2735. return this._scrollPane.viewHeight;
  2736. else
  2737. return this.height - this._margin.top - this._margin.bottom;
  2738. },
  2739. set: function (value) {
  2740. if (this._scrollPane)
  2741. this._scrollPane.viewHeight = value;
  2742. else
  2743. this.height = value + this._margin.top + this._margin.bottom;
  2744. },
  2745. enumerable: false,
  2746. configurable: true
  2747. });
  2748. GComponent.prototype.getSnappingPosition = function (xValue, yValue, resultPoint) {
  2749. if (!resultPoint)
  2750. resultPoint = new cc.Vec2();
  2751. var cnt = this._children.length;
  2752. if (cnt == 0) {
  2753. resultPoint.x = 0;
  2754. resultPoint.y = 0;
  2755. return resultPoint;
  2756. }
  2757. this.ensureBoundsCorrect();
  2758. var obj = null;
  2759. var prev = null;
  2760. var i = 0;
  2761. if (yValue != 0) {
  2762. for (; i < cnt; i++) {
  2763. obj = this._children[i];
  2764. if (yValue < obj.y) {
  2765. if (i == 0) {
  2766. yValue = 0;
  2767. break;
  2768. }
  2769. else {
  2770. prev = this._children[i - 1];
  2771. if (yValue < prev.y + prev.actualHeight / 2)
  2772. yValue = prev.y;
  2773. else
  2774. yValue = obj.y;
  2775. break;
  2776. }
  2777. }
  2778. }
  2779. if (i == cnt)
  2780. yValue = obj.y;
  2781. }
  2782. if (xValue != 0) {
  2783. if (i > 0)
  2784. i--;
  2785. for (; i < cnt; i++) {
  2786. obj = this._children[i];
  2787. if (xValue < obj.x) {
  2788. if (i == 0) {
  2789. xValue = 0;
  2790. break;
  2791. }
  2792. else {
  2793. prev = this._children[i - 1];
  2794. if (xValue < prev.x + prev.actualWidth / 2)
  2795. xValue = prev.x;
  2796. else
  2797. xValue = obj.x;
  2798. break;
  2799. }
  2800. }
  2801. }
  2802. if (i == cnt)
  2803. xValue = obj.x;
  2804. }
  2805. resultPoint.x = xValue;
  2806. resultPoint.y = yValue;
  2807. return resultPoint;
  2808. };
  2809. GComponent.prototype.childSortingOrderChanged = function (child, oldValue, newValue) {
  2810. if (newValue === void 0) { newValue = 0; }
  2811. if (newValue == 0) {
  2812. this._sortingChildCount--;
  2813. this.setChildIndex(child, this._children.length);
  2814. }
  2815. else {
  2816. if (oldValue == 0)
  2817. this._sortingChildCount++;
  2818. var oldIndex = this._children.indexOf(child);
  2819. var index = this.getInsertPosForSortingChild(child);
  2820. if (oldIndex < index)
  2821. this._setChildIndex(child, oldIndex, index - 1);
  2822. else
  2823. this._setChildIndex(child, oldIndex, index);
  2824. }
  2825. };
  2826. GComponent.prototype.constructFromResource = function () {
  2827. this.constructFromResource2(null, 0);
  2828. };
  2829. GComponent.prototype.constructFromResource2 = function (objectPool, poolIndex) {
  2830. var contentItem = this.packageItem.getBranch();
  2831. if (!contentItem.decoded) {
  2832. contentItem.decoded = true;
  2833. fgui.TranslationHelper.translateComponent(contentItem);
  2834. }
  2835. var i;
  2836. var dataLen;
  2837. var curPos;
  2838. var nextPos;
  2839. var f1;
  2840. var f2;
  2841. var i1;
  2842. var i2;
  2843. var buffer = contentItem.rawData;
  2844. buffer.seek(0, 0);
  2845. this._underConstruct = true;
  2846. this.sourceWidth = buffer.readInt();
  2847. this.sourceHeight = buffer.readInt();
  2848. this.initWidth = this.sourceWidth;
  2849. this.initHeight = this.sourceHeight;
  2850. this.setSize(this.sourceWidth, this.sourceHeight);
  2851. if (buffer.readBool()) {
  2852. this.minWidth = buffer.readInt();
  2853. this.maxWidth = buffer.readInt();
  2854. this.minHeight = buffer.readInt();
  2855. this.maxHeight = buffer.readInt();
  2856. }
  2857. if (buffer.readBool()) {
  2858. f1 = buffer.readFloat();
  2859. f2 = buffer.readFloat();
  2860. this.setPivot(f1, f2, buffer.readBool());
  2861. }
  2862. if (buffer.readBool()) {
  2863. this._margin.top = buffer.readInt();
  2864. this._margin.bottom = buffer.readInt();
  2865. this._margin.left = buffer.readInt();
  2866. this._margin.right = buffer.readInt();
  2867. }
  2868. var overflow = buffer.readByte();
  2869. if (overflow == fgui.OverflowType.Scroll) {
  2870. var savedPos = buffer.position;
  2871. buffer.seek(0, 7);
  2872. this.setupScroll(buffer);
  2873. buffer.position = savedPos;
  2874. }
  2875. else
  2876. this.setupOverflow(overflow);
  2877. if (buffer.readBool())
  2878. buffer.skip(8);
  2879. this._buildingDisplayList = true;
  2880. buffer.seek(0, 1);
  2881. var controllerCount = buffer.readShort();
  2882. for (i = 0; i < controllerCount; i++) {
  2883. nextPos = buffer.readShort();
  2884. nextPos += buffer.position;
  2885. var controller = new fgui.Controller();
  2886. this._controllers.push(controller);
  2887. controller.parent = this;
  2888. controller.setup(buffer);
  2889. buffer.position = nextPos;
  2890. }
  2891. buffer.seek(0, 2);
  2892. var child;
  2893. var childCount = buffer.readShort();
  2894. for (i = 0; i < childCount; i++) {
  2895. dataLen = buffer.readShort();
  2896. curPos = buffer.position;
  2897. if (objectPool)
  2898. child = objectPool[poolIndex + i];
  2899. else {
  2900. buffer.seek(curPos, 0);
  2901. var type = buffer.readByte();
  2902. var src = buffer.readS();
  2903. var pkgId = buffer.readS();
  2904. var pi = null;
  2905. if (src != null) {
  2906. var pkg;
  2907. if (pkgId != null)
  2908. pkg = fgui.UIPackage.getById(pkgId);
  2909. else
  2910. pkg = contentItem.owner;
  2911. pi = pkg ? pkg.getItemById(src) : null;
  2912. }
  2913. if (pi) {
  2914. child = fgui.UIObjectFactory.newObject(pi);
  2915. child.constructFromResource();
  2916. }
  2917. else
  2918. child = fgui.UIObjectFactory.newObject(type);
  2919. }
  2920. child._underConstruct = true;
  2921. child.setup_beforeAdd(buffer, curPos);
  2922. child._parent = this;
  2923. child.node.parent = this._container;
  2924. this._children.push(child);
  2925. buffer.position = curPos + dataLen;
  2926. }
  2927. buffer.seek(0, 3);
  2928. this.relations.setup(buffer, true);
  2929. buffer.seek(0, 2);
  2930. buffer.skip(2);
  2931. for (i = 0; i < childCount; i++) {
  2932. nextPos = buffer.readShort();
  2933. nextPos += buffer.position;
  2934. buffer.seek(buffer.position, 3);
  2935. this._children[i].relations.setup(buffer, false);
  2936. buffer.position = nextPos;
  2937. }
  2938. buffer.seek(0, 2);
  2939. buffer.skip(2);
  2940. for (i = 0; i < childCount; i++) {
  2941. nextPos = buffer.readShort();
  2942. nextPos += buffer.position;
  2943. child = this._children[i];
  2944. child.setup_afterAdd(buffer, buffer.position);
  2945. child._underConstruct = false;
  2946. buffer.position = nextPos;
  2947. }
  2948. buffer.seek(0, 4);
  2949. buffer.skip(2);
  2950. this.opaque = buffer.readBool();
  2951. var maskId = buffer.readShort();
  2952. if (maskId != -1) {
  2953. this.setMask(this.getChildAt(maskId), buffer.readBool());
  2954. }
  2955. var hitTestId = buffer.readS();
  2956. i1 = buffer.readInt();
  2957. i2 = buffer.readInt();
  2958. if (hitTestId != null) {
  2959. pi = contentItem.owner.getItemById(hitTestId);
  2960. if (pi && pi.hitTestData)
  2961. this.hitArea = new fgui.PixelHitTest(pi.hitTestData, i1, i2);
  2962. }
  2963. else if (i1 != 0 && i2 != -1) {
  2964. this.hitArea = new fgui.ChildHitArea(this.getChildAt(i2));
  2965. }
  2966. buffer.seek(0, 5);
  2967. var transitionCount = buffer.readShort();
  2968. for (i = 0; i < transitionCount; i++) {
  2969. nextPos = buffer.readShort();
  2970. nextPos += buffer.position;
  2971. var trans = new fgui.Transition(this);
  2972. trans.setup(buffer);
  2973. this._transitions.push(trans);
  2974. buffer.position = nextPos;
  2975. }
  2976. this.applyAllControllers();
  2977. this._buildingDisplayList = false;
  2978. this._underConstruct = false;
  2979. this.buildNativeDisplayList();
  2980. this.setBoundsChangedFlag();
  2981. if (contentItem.objectType != fgui.ObjectType.Component)
  2982. this.constructExtension(buffer);
  2983. this.onConstruct();
  2984. };
  2985. GComponent.prototype.constructExtension = function (buffer) {
  2986. };
  2987. GComponent.prototype.onConstruct = function () {
  2988. };
  2989. GComponent.prototype.setup_afterAdd = function (buffer, beginPos) {
  2990. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  2991. buffer.seek(beginPos, 4);
  2992. var pageController = buffer.readShort();
  2993. if (pageController != -1 && this._scrollPane)
  2994. this._scrollPane.pageController = this._parent.getControllerAt(pageController);
  2995. var cnt = buffer.readShort();
  2996. for (var i = 0; i < cnt; i++) {
  2997. var cc = this.getController(buffer.readS());
  2998. var pageId = buffer.readS();
  2999. if (cc)
  3000. cc.selectedPageId = pageId;
  3001. }
  3002. if (buffer.version >= 2) {
  3003. cnt = buffer.readShort();
  3004. for (i = 0; i < cnt; i++) {
  3005. var target = buffer.readS();
  3006. var propertyId = buffer.readShort();
  3007. var value = buffer.readS();
  3008. var obj = this.getChildByPath(target);
  3009. if (obj)
  3010. obj.setProp(propertyId, value);
  3011. }
  3012. }
  3013. };
  3014. GComponent.prototype.onEnable = function () {
  3015. var cnt = this._transitions.length;
  3016. for (var i = 0; i < cnt; ++i)
  3017. this._transitions[i].onEnable();
  3018. };
  3019. GComponent.prototype.onDisable = function () {
  3020. var cnt = this._transitions.length;
  3021. for (var i = 0; i < cnt; ++i)
  3022. this._transitions[i].onDisable();
  3023. };
  3024. return GComponent;
  3025. }(fgui.GObject));
  3026. fgui.GComponent = GComponent;
  3027. var s_vec2 = new cc.Vec2();
  3028. })(fgui || (fgui = {}));
  3029. (function (fgui) {
  3030. var GButton = (function (_super) {
  3031. __extends(GButton, _super);
  3032. function GButton() {
  3033. var _this = _super.call(this) || this;
  3034. _this._node.name = "GButton";
  3035. _this._mode = fgui.ButtonMode.Common;
  3036. _this._title = "";
  3037. _this._icon = "";
  3038. _this._sound = fgui.UIConfig.buttonSound;
  3039. _this._soundVolumeScale = fgui.UIConfig.buttonSoundVolumeScale;
  3040. _this._changeStateOnClick = true;
  3041. _this._downEffect = 0;
  3042. _this._downEffectValue = 0.8;
  3043. return _this;
  3044. }
  3045. Object.defineProperty(GButton.prototype, "icon", {
  3046. get: function () {
  3047. return this._icon;
  3048. },
  3049. set: function (value) {
  3050. this._icon = value;
  3051. value = (this._selected && this._selectedIcon) ? this._selectedIcon : this._icon;
  3052. if (this._iconObject)
  3053. this._iconObject.icon = value;
  3054. this.updateGear(7);
  3055. },
  3056. enumerable: false,
  3057. configurable: true
  3058. });
  3059. Object.defineProperty(GButton.prototype, "selectedIcon", {
  3060. get: function () {
  3061. return this._selectedIcon;
  3062. },
  3063. set: function (value) {
  3064. this._selectedIcon = value;
  3065. value = (this._selected && this._selectedIcon) ? this._selectedIcon : this._icon;
  3066. if (this._iconObject)
  3067. this._iconObject.icon = value;
  3068. },
  3069. enumerable: false,
  3070. configurable: true
  3071. });
  3072. Object.defineProperty(GButton.prototype, "title", {
  3073. get: function () {
  3074. return this._title;
  3075. },
  3076. set: function (value) {
  3077. this._title = value;
  3078. if (this._titleObject)
  3079. this._titleObject.text = (this._selected && this._selectedTitle) ? this._selectedTitle : this._title;
  3080. this.updateGear(6);
  3081. },
  3082. enumerable: false,
  3083. configurable: true
  3084. });
  3085. Object.defineProperty(GButton.prototype, "text", {
  3086. get: function () {
  3087. return this.title;
  3088. },
  3089. set: function (value) {
  3090. this.title = value;
  3091. },
  3092. enumerable: false,
  3093. configurable: true
  3094. });
  3095. Object.defineProperty(GButton.prototype, "selectedTitle", {
  3096. get: function () {
  3097. return this._selectedTitle;
  3098. },
  3099. set: function (value) {
  3100. this._selectedTitle = value;
  3101. if (this._titleObject)
  3102. this._titleObject.text = (this._selected && this._selectedTitle) ? this._selectedTitle : this._title;
  3103. },
  3104. enumerable: false,
  3105. configurable: true
  3106. });
  3107. Object.defineProperty(GButton.prototype, "titleColor", {
  3108. get: function () {
  3109. var tf = this.getTextField();
  3110. if (tf)
  3111. return tf.color;
  3112. else
  3113. return cc.Color.BLACK;
  3114. },
  3115. set: function (value) {
  3116. var tf = this.getTextField();
  3117. if (tf)
  3118. tf.color = value;
  3119. },
  3120. enumerable: false,
  3121. configurable: true
  3122. });
  3123. Object.defineProperty(GButton.prototype, "titleFontSize", {
  3124. get: function () {
  3125. var tf = this.getTextField();
  3126. if (tf)
  3127. return tf.fontSize;
  3128. else
  3129. return 0;
  3130. },
  3131. set: function (value) {
  3132. var tf = this.getTextField();
  3133. if (tf)
  3134. tf.fontSize = value;
  3135. },
  3136. enumerable: false,
  3137. configurable: true
  3138. });
  3139. Object.defineProperty(GButton.prototype, "sound", {
  3140. get: function () {
  3141. return this._sound;
  3142. },
  3143. set: function (val) {
  3144. this._sound = val;
  3145. },
  3146. enumerable: false,
  3147. configurable: true
  3148. });
  3149. Object.defineProperty(GButton.prototype, "soundVolumeScale", {
  3150. get: function () {
  3151. return this._soundVolumeScale;
  3152. },
  3153. set: function (value) {
  3154. this._soundVolumeScale = value;
  3155. },
  3156. enumerable: false,
  3157. configurable: true
  3158. });
  3159. Object.defineProperty(GButton.prototype, "selected", {
  3160. get: function () {
  3161. return this._selected;
  3162. },
  3163. set: function (val) {
  3164. if (this._mode == fgui.ButtonMode.Common)
  3165. return;
  3166. if (this._selected != val) {
  3167. this._selected = val;
  3168. this.setCurrentState();
  3169. if (this._selectedTitle && this._titleObject)
  3170. this._titleObject.text = this._selected ? this._selectedTitle : this._title;
  3171. if (this._selectedIcon) {
  3172. var str = this._selected ? this._selectedIcon : this._icon;
  3173. if (this._iconObject)
  3174. this._iconObject.icon = str;
  3175. }
  3176. if (this._relatedController
  3177. && this._parent
  3178. && !this._parent._buildingDisplayList) {
  3179. if (this._selected) {
  3180. this._relatedController.selectedPageId = this._relatedPageId;
  3181. if (this._relatedController.autoRadioGroupDepth)
  3182. this._parent.adjustRadioGroupDepth(this, this._relatedController);
  3183. }
  3184. else if (this._mode == fgui.ButtonMode.Check && this._relatedController.selectedPageId == this._relatedPageId)
  3185. this._relatedController.oppositePageId = this._relatedPageId;
  3186. }
  3187. }
  3188. },
  3189. enumerable: false,
  3190. configurable: true
  3191. });
  3192. Object.defineProperty(GButton.prototype, "mode", {
  3193. get: function () {
  3194. return this._mode;
  3195. },
  3196. set: function (value) {
  3197. if (this._mode != value) {
  3198. if (value == fgui.ButtonMode.Common)
  3199. this.selected = false;
  3200. this._mode = value;
  3201. }
  3202. },
  3203. enumerable: false,
  3204. configurable: true
  3205. });
  3206. Object.defineProperty(GButton.prototype, "relatedController", {
  3207. get: function () {
  3208. return this._relatedController;
  3209. },
  3210. set: function (val) {
  3211. this._relatedController = val;
  3212. },
  3213. enumerable: false,
  3214. configurable: true
  3215. });
  3216. Object.defineProperty(GButton.prototype, "relatedPageId", {
  3217. get: function () {
  3218. return this._relatedPageId;
  3219. },
  3220. set: function (val) {
  3221. this._relatedPageId = val;
  3222. },
  3223. enumerable: false,
  3224. configurable: true
  3225. });
  3226. Object.defineProperty(GButton.prototype, "changeStateOnClick", {
  3227. get: function () {
  3228. return this._changeStateOnClick;
  3229. },
  3230. set: function (value) {
  3231. this._changeStateOnClick = value;
  3232. },
  3233. enumerable: false,
  3234. configurable: true
  3235. });
  3236. Object.defineProperty(GButton.prototype, "linkedPopup", {
  3237. get: function () {
  3238. return this._linkedPopup;
  3239. },
  3240. set: function (value) {
  3241. this._linkedPopup = value;
  3242. },
  3243. enumerable: false,
  3244. configurable: true
  3245. });
  3246. GButton.prototype.getTextField = function () {
  3247. if (this._titleObject instanceof fgui.GTextField)
  3248. return this._titleObject;
  3249. else if ((this._titleObject instanceof fgui.GLabel) || (this._titleObject instanceof GButton))
  3250. return this._titleObject.getTextField();
  3251. else
  3252. return null;
  3253. };
  3254. GButton.prototype.fireClick = function () {
  3255. fgui.GRoot.inst.inputProcessor.simulateClick(this);
  3256. };
  3257. GButton.prototype.setState = function (val) {
  3258. if (this._buttonController)
  3259. this._buttonController.selectedPage = val;
  3260. if (this._downEffect == 1) {
  3261. var cnt = this.numChildren;
  3262. if (val == GButton.DOWN || val == GButton.SELECTED_OVER || val == GButton.SELECTED_DISABLED) {
  3263. if (!this._downColor)
  3264. this._downColor = new cc.Color();
  3265. var r = this._downEffectValue * 255;
  3266. this._downColor.r = this._downColor.g = this._downColor.b = r;
  3267. for (var i = 0; i < cnt; i++) {
  3268. var obj = this.getChildAt(i);
  3269. if (obj["color"] != undefined && !(obj instanceof fgui.GTextField))
  3270. obj.color = this._downColor;
  3271. }
  3272. }
  3273. else {
  3274. for (var i = 0; i < cnt; i++) {
  3275. var obj = this.getChildAt(i);
  3276. if (obj["color"] != undefined && !(obj instanceof fgui.GTextField))
  3277. obj.color = cc.Color.WHITE;
  3278. }
  3279. }
  3280. }
  3281. else if (this._downEffect == 2) {
  3282. if (val == GButton.DOWN || val == GButton.SELECTED_OVER || val == GButton.SELECTED_DISABLED) {
  3283. if (!this._downScaled) {
  3284. this._downScaled = true;
  3285. this.setScale(this.scaleX * this._downEffectValue, this.scaleY * this._downEffectValue);
  3286. }
  3287. }
  3288. else {
  3289. if (this._downScaled) {
  3290. this._downScaled = false;
  3291. this.setScale(this.scaleX / this._downEffectValue, this.scaleY / this._downEffectValue);
  3292. }
  3293. }
  3294. }
  3295. };
  3296. GButton.prototype.setCurrentState = function () {
  3297. if (this.grayed && this._buttonController && this._buttonController.hasPage(GButton.DISABLED)) {
  3298. if (this._selected)
  3299. this.setState(GButton.SELECTED_DISABLED);
  3300. else
  3301. this.setState(GButton.DISABLED);
  3302. }
  3303. else {
  3304. if (this._selected)
  3305. this.setState(this._over ? GButton.SELECTED_OVER : GButton.DOWN);
  3306. else
  3307. this.setState(this._over ? GButton.OVER : GButton.UP);
  3308. }
  3309. };
  3310. GButton.prototype.handleControllerChanged = function (c) {
  3311. _super.prototype.handleControllerChanged.call(this, c);
  3312. if (this._relatedController == c)
  3313. this.selected = this._relatedPageId == c.selectedPageId;
  3314. };
  3315. GButton.prototype.handleGrayedChanged = function () {
  3316. if (this._buttonController && this._buttonController.hasPage(GButton.DISABLED)) {
  3317. if (this.grayed) {
  3318. if (this._selected && this._buttonController.hasPage(GButton.SELECTED_DISABLED))
  3319. this.setState(GButton.SELECTED_DISABLED);
  3320. else
  3321. this.setState(GButton.DISABLED);
  3322. }
  3323. else if (this._selected)
  3324. this.setState(GButton.DOWN);
  3325. else
  3326. this.setState(GButton.UP);
  3327. }
  3328. else
  3329. _super.prototype.handleGrayedChanged.call(this);
  3330. };
  3331. GButton.prototype.getProp = function (index) {
  3332. switch (index) {
  3333. case fgui.ObjectPropID.Color:
  3334. return this.titleColor;
  3335. case fgui.ObjectPropID.OutlineColor:
  3336. {
  3337. var tf = this.getTextField();
  3338. if (tf)
  3339. return tf.strokeColor;
  3340. else
  3341. return 0;
  3342. }
  3343. case fgui.ObjectPropID.FontSize:
  3344. return this.titleFontSize;
  3345. case fgui.ObjectPropID.Selected:
  3346. return this.selected;
  3347. default:
  3348. return _super.prototype.getProp.call(this, index);
  3349. }
  3350. };
  3351. GButton.prototype.setProp = function (index, value) {
  3352. switch (index) {
  3353. case fgui.ObjectPropID.Color:
  3354. this.titleColor = value;
  3355. break;
  3356. case fgui.ObjectPropID.OutlineColor:
  3357. {
  3358. var tf = this.getTextField();
  3359. if (tf)
  3360. tf.strokeColor = value;
  3361. }
  3362. break;
  3363. case fgui.ObjectPropID.FontSize:
  3364. this.titleFontSize = value;
  3365. break;
  3366. case fgui.ObjectPropID.Selected:
  3367. this.selected = value;
  3368. break;
  3369. default:
  3370. _super.prototype.setProp.call(this, index, value);
  3371. break;
  3372. }
  3373. };
  3374. GButton.prototype.constructExtension = function (buffer) {
  3375. buffer.seek(0, 6);
  3376. this._mode = buffer.readByte();
  3377. var str = buffer.readS();
  3378. if (str)
  3379. this._sound = str;
  3380. this._soundVolumeScale = buffer.readFloat();
  3381. this._downEffect = buffer.readByte();
  3382. this._downEffectValue = buffer.readFloat();
  3383. if (this._downEffect == 2)
  3384. this.setPivot(0.5, 0.5, this.pivotAsAnchor);
  3385. this._buttonController = this.getController("button");
  3386. this._titleObject = this.getChild("title");
  3387. this._iconObject = this.getChild("icon");
  3388. if (this._titleObject)
  3389. this._title = this._titleObject.text;
  3390. if (this._iconObject)
  3391. this._icon = this._iconObject.icon;
  3392. if (this._mode == fgui.ButtonMode.Common)
  3393. this.setState(GButton.UP);
  3394. this._node.on(fgui.Event.TOUCH_BEGIN, this.onTouchBegin_1, this);
  3395. this._node.on(fgui.Event.TOUCH_END, this.onTouchEnd_1, this);
  3396. this._node.on(fgui.Event.ROLL_OVER, this.onRollOver_1, this);
  3397. this._node.on(fgui.Event.ROLL_OUT, this.onRollOut_1, this);
  3398. this._node.on(fgui.Event.CLICK, this.onClick_1, this);
  3399. };
  3400. GButton.prototype.setup_afterAdd = function (buffer, beginPos) {
  3401. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  3402. if (!buffer.seek(beginPos, 6))
  3403. return;
  3404. if (buffer.readByte() != this.packageItem.objectType)
  3405. return;
  3406. var str;
  3407. var iv;
  3408. str = buffer.readS();
  3409. if (str != null)
  3410. this.title = str;
  3411. str = buffer.readS();
  3412. if (str != null)
  3413. this.selectedTitle = str;
  3414. str = buffer.readS();
  3415. if (str != null)
  3416. this.icon = str;
  3417. str = buffer.readS();
  3418. if (str != null)
  3419. this.selectedIcon = str;
  3420. if (buffer.readBool())
  3421. this.titleColor = buffer.readColor();
  3422. iv = buffer.readInt();
  3423. if (iv != 0)
  3424. this.titleFontSize = iv;
  3425. iv = buffer.readShort();
  3426. if (iv >= 0)
  3427. this._relatedController = this.parent.getControllerAt(iv);
  3428. this._relatedPageId = buffer.readS();
  3429. str = buffer.readS();
  3430. if (str != null)
  3431. this._sound = str;
  3432. if (buffer.readBool())
  3433. this._soundVolumeScale = buffer.readFloat();
  3434. this.selected = buffer.readBool();
  3435. };
  3436. GButton.prototype.onRollOver_1 = function () {
  3437. if (!this._buttonController || !this._buttonController.hasPage(GButton.OVER))
  3438. return;
  3439. this._over = true;
  3440. if (this._down)
  3441. return;
  3442. if (this.grayed && this._buttonController.hasPage(GButton.DISABLED))
  3443. return;
  3444. this.setState(this._selected ? GButton.SELECTED_OVER : GButton.OVER);
  3445. };
  3446. GButton.prototype.onRollOut_1 = function () {
  3447. if (!this._buttonController || !this._buttonController.hasPage(GButton.OVER))
  3448. return;
  3449. this._over = false;
  3450. if (this._down)
  3451. return;
  3452. if (this.grayed && this._buttonController.hasPage(GButton.DISABLED))
  3453. return;
  3454. this.setState(this._selected ? GButton.DOWN : GButton.UP);
  3455. };
  3456. GButton.prototype.onTouchBegin_1 = function (evt) {
  3457. if (evt.button != cc.Event.EventMouse.BUTTON_LEFT)
  3458. return;
  3459. this._down = true;
  3460. evt.captureTouch();
  3461. if (this._mode == fgui.ButtonMode.Common) {
  3462. if (this.grayed && this._buttonController && this._buttonController.hasPage(GButton.DISABLED))
  3463. this.setState(GButton.SELECTED_DISABLED);
  3464. else
  3465. this.setState(GButton.DOWN);
  3466. }
  3467. if (this._linkedPopup) {
  3468. if (this._linkedPopup instanceof fgui.Window)
  3469. this._linkedPopup.toggleStatus();
  3470. else
  3471. this.root.togglePopup(this._linkedPopup, this);
  3472. }
  3473. };
  3474. GButton.prototype.onTouchEnd_1 = function (evt) {
  3475. if (evt.button != cc.Event.EventMouse.BUTTON_LEFT)
  3476. return;
  3477. if (this._down) {
  3478. this._down = false;
  3479. if (this._node == null)
  3480. return;
  3481. if (this._mode == fgui.ButtonMode.Common) {
  3482. if (this.grayed && this._buttonController && this._buttonController.hasPage(GButton.DISABLED))
  3483. this.setState(GButton.DISABLED);
  3484. else if (this._over)
  3485. this.setState(GButton.OVER);
  3486. else
  3487. this.setState(GButton.UP);
  3488. }
  3489. else {
  3490. if (!this._over
  3491. && this._buttonController != null
  3492. && (this._buttonController.selectedPage == GButton.OVER
  3493. || this._buttonController.selectedPage == GButton.SELECTED_OVER)) {
  3494. this.setCurrentState();
  3495. }
  3496. }
  3497. }
  3498. };
  3499. GButton.prototype.onClick_1 = function () {
  3500. if (this._sound) {
  3501. var pi = fgui.UIPackage.getItemByURL(this._sound);
  3502. if (pi) {
  3503. var sound = pi.owner.getItemAsset(pi);
  3504. if (sound)
  3505. fgui.GRoot.inst.playOneShotSound(sound, this._soundVolumeScale);
  3506. }
  3507. }
  3508. if (this._mode == fgui.ButtonMode.Check) {
  3509. if (this._changeStateOnClick) {
  3510. this.selected = !this._selected;
  3511. this._node.emit(fgui.Event.STATUS_CHANGED, this);
  3512. }
  3513. }
  3514. else if (this._mode == fgui.ButtonMode.Radio) {
  3515. if (this._changeStateOnClick && !this._selected) {
  3516. this.selected = true;
  3517. this._node.emit(fgui.Event.STATUS_CHANGED, this);
  3518. }
  3519. }
  3520. else {
  3521. if (this._relatedController)
  3522. this._relatedController.selectedPageId = this._relatedPageId;
  3523. }
  3524. };
  3525. GButton.UP = "up";
  3526. GButton.DOWN = "down";
  3527. GButton.OVER = "over";
  3528. GButton.SELECTED_OVER = "selectedOver";
  3529. GButton.DISABLED = "disabled";
  3530. GButton.SELECTED_DISABLED = "selectedDisabled";
  3531. return GButton;
  3532. }(fgui.GComponent));
  3533. fgui.GButton = GButton;
  3534. })(fgui || (fgui = {}));
  3535. (function (fgui) {
  3536. var GComboBox = (function (_super) {
  3537. __extends(GComboBox, _super);
  3538. function GComboBox() {
  3539. var _this = _super.call(this) || this;
  3540. _this._visibleItemCount = 0;
  3541. _this._selectedIndex = 0;
  3542. _this._popupDirection = fgui.PopupDirection.Auto;
  3543. _this._node.name = "GComboBox";
  3544. _this._visibleItemCount = fgui.UIConfig.defaultComboBoxVisibleItemCount;
  3545. _this._itemsUpdated = true;
  3546. _this._selectedIndex = -1;
  3547. _this._items = [];
  3548. _this._values = [];
  3549. return _this;
  3550. }
  3551. Object.defineProperty(GComboBox.prototype, "text", {
  3552. get: function () {
  3553. if (this._titleObject)
  3554. return this._titleObject.text;
  3555. else
  3556. return null;
  3557. },
  3558. set: function (value) {
  3559. if (this._titleObject)
  3560. this._titleObject.text = value;
  3561. this.updateGear(6);
  3562. },
  3563. enumerable: false,
  3564. configurable: true
  3565. });
  3566. Object.defineProperty(GComboBox.prototype, "icon", {
  3567. get: function () {
  3568. if (this._iconObject)
  3569. return this._iconObject.icon;
  3570. else
  3571. return null;
  3572. },
  3573. set: function (value) {
  3574. if (this._iconObject)
  3575. this._iconObject.icon = value;
  3576. this.updateGear(7);
  3577. },
  3578. enumerable: false,
  3579. configurable: true
  3580. });
  3581. Object.defineProperty(GComboBox.prototype, "titleColor", {
  3582. get: function () {
  3583. var tf = this.getTextField();
  3584. if (tf)
  3585. return tf.color;
  3586. else
  3587. return cc.Color.BLACK;
  3588. },
  3589. set: function (value) {
  3590. var tf = this.getTextField();
  3591. if (tf)
  3592. tf.color = value;
  3593. },
  3594. enumerable: false,
  3595. configurable: true
  3596. });
  3597. Object.defineProperty(GComboBox.prototype, "titleFontSize", {
  3598. get: function () {
  3599. var tf = this.getTextField();
  3600. if (tf)
  3601. return tf.fontSize;
  3602. else
  3603. return 0;
  3604. },
  3605. set: function (value) {
  3606. var tf = this.getTextField();
  3607. if (tf)
  3608. tf.fontSize = value;
  3609. },
  3610. enumerable: false,
  3611. configurable: true
  3612. });
  3613. Object.defineProperty(GComboBox.prototype, "visibleItemCount", {
  3614. get: function () {
  3615. return this._visibleItemCount;
  3616. },
  3617. set: function (value) {
  3618. this._visibleItemCount = value;
  3619. },
  3620. enumerable: false,
  3621. configurable: true
  3622. });
  3623. Object.defineProperty(GComboBox.prototype, "popupDirection", {
  3624. get: function () {
  3625. return this._popupDirection;
  3626. },
  3627. set: function (value) {
  3628. this._popupDirection = value;
  3629. },
  3630. enumerable: false,
  3631. configurable: true
  3632. });
  3633. Object.defineProperty(GComboBox.prototype, "items", {
  3634. get: function () {
  3635. return this._items;
  3636. },
  3637. set: function (value) {
  3638. if (!value)
  3639. this._items.length = 0;
  3640. else
  3641. this._items = value.concat();
  3642. if (this._items.length > 0) {
  3643. if (this._selectedIndex >= this._items.length)
  3644. this._selectedIndex = this._items.length - 1;
  3645. else if (this._selectedIndex == -1)
  3646. this._selectedIndex = 0;
  3647. this.text = this._items[this._selectedIndex];
  3648. if (this._icons && this._selectedIndex < this._icons.length)
  3649. this.icon = this._icons[this._selectedIndex];
  3650. }
  3651. else {
  3652. this.text = "";
  3653. if (this._icons)
  3654. this.icon = null;
  3655. this._selectedIndex = -1;
  3656. }
  3657. this._itemsUpdated = true;
  3658. },
  3659. enumerable: false,
  3660. configurable: true
  3661. });
  3662. Object.defineProperty(GComboBox.prototype, "icons", {
  3663. get: function () {
  3664. return this._icons;
  3665. },
  3666. set: function (value) {
  3667. this._icons = value;
  3668. if (this._icons && this._selectedIndex != -1 && this._selectedIndex < this._icons.length)
  3669. this.icon = this._icons[this._selectedIndex];
  3670. },
  3671. enumerable: false,
  3672. configurable: true
  3673. });
  3674. Object.defineProperty(GComboBox.prototype, "values", {
  3675. get: function () {
  3676. return this._values;
  3677. },
  3678. set: function (value) {
  3679. if (!value)
  3680. this._values.length = 0;
  3681. else
  3682. this._values = value.concat();
  3683. },
  3684. enumerable: false,
  3685. configurable: true
  3686. });
  3687. Object.defineProperty(GComboBox.prototype, "selectedIndex", {
  3688. get: function () {
  3689. return this._selectedIndex;
  3690. },
  3691. set: function (val) {
  3692. if (this._selectedIndex == val)
  3693. return;
  3694. this._selectedIndex = val;
  3695. if (this._selectedIndex >= 0 && this._selectedIndex < this._items.length) {
  3696. this.text = this._items[this._selectedIndex];
  3697. if (this._icons && this._selectedIndex < this._icons.length)
  3698. this.icon = this._icons[this._selectedIndex];
  3699. }
  3700. else {
  3701. this.text = "";
  3702. if (this._icons)
  3703. this.icon = null;
  3704. }
  3705. this.updateSelectionController();
  3706. },
  3707. enumerable: false,
  3708. configurable: true
  3709. });
  3710. Object.defineProperty(GComboBox.prototype, "value", {
  3711. get: function () {
  3712. return this._values[this._selectedIndex];
  3713. },
  3714. set: function (val) {
  3715. var index = this._values.indexOf(val);
  3716. if (index == -1 && val == null)
  3717. index = this._values.indexOf("");
  3718. this.selectedIndex = index;
  3719. },
  3720. enumerable: false,
  3721. configurable: true
  3722. });
  3723. Object.defineProperty(GComboBox.prototype, "selectionController", {
  3724. get: function () {
  3725. return this._selectionController;
  3726. },
  3727. set: function (value) {
  3728. this._selectionController = value;
  3729. },
  3730. enumerable: false,
  3731. configurable: true
  3732. });
  3733. GComboBox.prototype.getTextField = function () {
  3734. if (this._titleObject instanceof fgui.GTextField)
  3735. return this._titleObject;
  3736. else if ((this._titleObject instanceof fgui.GLabel) || (this._titleObject instanceof fgui.GButton))
  3737. return this._titleObject.getTextField();
  3738. else
  3739. return null;
  3740. };
  3741. GComboBox.prototype.setState = function (val) {
  3742. if (this._buttonController)
  3743. this._buttonController.selectedPage = val;
  3744. };
  3745. GComboBox.prototype.getProp = function (index) {
  3746. switch (index) {
  3747. case fgui.ObjectPropID.Color:
  3748. return this.titleColor;
  3749. case fgui.ObjectPropID.OutlineColor:
  3750. {
  3751. var tf = this.getTextField();
  3752. if (tf)
  3753. return tf.strokeColor;
  3754. else
  3755. return 0;
  3756. }
  3757. case fgui.ObjectPropID.FontSize:
  3758. {
  3759. tf = this.getTextField();
  3760. if (tf)
  3761. return tf.fontSize;
  3762. else
  3763. return 0;
  3764. }
  3765. default:
  3766. return _super.prototype.getProp.call(this, index);
  3767. }
  3768. };
  3769. GComboBox.prototype.setProp = function (index, value) {
  3770. switch (index) {
  3771. case fgui.ObjectPropID.Color:
  3772. this.titleColor = value;
  3773. break;
  3774. case fgui.ObjectPropID.OutlineColor:
  3775. {
  3776. var tf = this.getTextField();
  3777. if (tf)
  3778. tf.strokeColor = value;
  3779. }
  3780. break;
  3781. case fgui.ObjectPropID.FontSize:
  3782. {
  3783. tf = this.getTextField();
  3784. if (tf)
  3785. tf.fontSize = value;
  3786. }
  3787. break;
  3788. default:
  3789. _super.prototype.setProp.call(this, index, value);
  3790. break;
  3791. }
  3792. };
  3793. GComboBox.prototype.constructExtension = function (buffer) {
  3794. var str;
  3795. this._buttonController = this.getController("button");
  3796. this._titleObject = this.getChild("title");
  3797. this._iconObject = this.getChild("icon");
  3798. str = buffer.readS();
  3799. if (str) {
  3800. var obj = fgui.UIPackage.createObjectFromURL(str);
  3801. if (!(obj instanceof fgui.GComponent)) {
  3802. console.error("下拉框必须为元件");
  3803. return;
  3804. }
  3805. this.dropdown = obj;
  3806. this.dropdown.name = "this.dropdown";
  3807. this._list = this.dropdown.getChild("list");
  3808. if (this._list == null) {
  3809. console.error(this.resourceURL + ": 下拉框的弹出元件里必须包含名为list的列表");
  3810. return;
  3811. }
  3812. this._list.on(fgui.Event.CLICK_ITEM, this.onClickItem, this);
  3813. this._list.addRelation(this.dropdown, fgui.RelationType.Width);
  3814. this._list.removeRelation(this.dropdown, fgui.RelationType.Height);
  3815. this.dropdown.addRelation(this._list, fgui.RelationType.Height);
  3816. this.dropdown.removeRelation(this._list, fgui.RelationType.Width);
  3817. this.dropdown.on(fgui.Event.UNDISPLAY, this.onPopupClosed, this);
  3818. }
  3819. this._node.on(fgui.Event.TOUCH_BEGIN, this.onTouchBegin_1, this);
  3820. this._node.on(fgui.Event.TOUCH_END, this.onTouchEnd_1, this);
  3821. this._node.on(fgui.Event.ROLL_OVER, this.onRollOver_1, this);
  3822. this._node.on(fgui.Event.ROLL_OUT, this.onRollOut_1, this);
  3823. };
  3824. GComboBox.prototype.handleControllerChanged = function (c) {
  3825. _super.prototype.handleControllerChanged.call(this, c);
  3826. if (this._selectionController == c)
  3827. this.selectedIndex = c.selectedIndex;
  3828. };
  3829. GComboBox.prototype.updateSelectionController = function () {
  3830. if (this._selectionController && !this._selectionController.changing
  3831. && this._selectedIndex < this._selectionController.pageCount) {
  3832. var c = this._selectionController;
  3833. this._selectionController = null;
  3834. c.selectedIndex = this._selectedIndex;
  3835. this._selectionController = c;
  3836. }
  3837. };
  3838. GComboBox.prototype.dispose = function () {
  3839. if (this.dropdown) {
  3840. this.dropdown.dispose();
  3841. this.dropdown = null;
  3842. }
  3843. _super.prototype.dispose.call(this);
  3844. };
  3845. GComboBox.prototype.setup_afterAdd = function (buffer, beginPos) {
  3846. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  3847. if (!buffer.seek(beginPos, 6))
  3848. return;
  3849. if (buffer.readByte() != this.packageItem.objectType)
  3850. return;
  3851. var i;
  3852. var iv;
  3853. var nextPos;
  3854. var str;
  3855. var itemCount = buffer.readShort();
  3856. for (i = 0; i < itemCount; i++) {
  3857. nextPos = buffer.readShort();
  3858. nextPos += buffer.position;
  3859. this._items[i] = buffer.readS();
  3860. this._values[i] = buffer.readS();
  3861. str = buffer.readS();
  3862. if (str != null) {
  3863. if (this._icons == null)
  3864. this._icons = new Array();
  3865. this._icons[i] = str;
  3866. }
  3867. buffer.position = nextPos;
  3868. }
  3869. str = buffer.readS();
  3870. if (str != null) {
  3871. this.text = str;
  3872. this._selectedIndex = this._items.indexOf(str);
  3873. }
  3874. else if (this._items.length > 0) {
  3875. this._selectedIndex = 0;
  3876. this.text = this._items[0];
  3877. }
  3878. else
  3879. this._selectedIndex = -1;
  3880. str = buffer.readS();
  3881. if (str != null)
  3882. this.icon = str;
  3883. if (buffer.readBool())
  3884. this.titleColor = buffer.readColor();
  3885. iv = buffer.readInt();
  3886. if (iv > 0)
  3887. this._visibleItemCount = iv;
  3888. this._popupDirection = buffer.readByte();
  3889. iv = buffer.readShort();
  3890. if (iv >= 0)
  3891. this._selectionController = this.parent.getControllerAt(iv);
  3892. };
  3893. GComboBox.prototype.showDropdown = function () {
  3894. if (this._itemsUpdated) {
  3895. this._itemsUpdated = false;
  3896. this._list.removeChildrenToPool();
  3897. var cnt = this._items.length;
  3898. for (var i = 0; i < cnt; i++) {
  3899. var item = this._list.addItemFromPool();
  3900. item.name = i < this._values.length ? this._values[i] : "";
  3901. item.text = this._items[i];
  3902. item.icon = (this._icons && i < this._icons.length) ? this._icons[i] : null;
  3903. }
  3904. this._list.resizeToFit(this._visibleItemCount);
  3905. }
  3906. this._list.selectedIndex = -1;
  3907. this.dropdown.width = this.width;
  3908. this._list.ensureBoundsCorrect();
  3909. this.root.togglePopup(this.dropdown, this, this._popupDirection);
  3910. if (this.dropdown.parent)
  3911. this.setState(fgui.GButton.DOWN);
  3912. };
  3913. GComboBox.prototype.onPopupClosed = function () {
  3914. if (this._over)
  3915. this.setState(fgui.GButton.OVER);
  3916. else
  3917. this.setState(fgui.GButton.UP);
  3918. };
  3919. GComboBox.prototype.onClickItem = function (itemObject) {
  3920. var _t = this;
  3921. var index = this._list.getChildIndex(itemObject);
  3922. this._partner.callLater(function (dt) {
  3923. _t.onClickItem2(index);
  3924. }, 0.1);
  3925. };
  3926. GComboBox.prototype.onClickItem2 = function (index) {
  3927. if (this.dropdown.parent instanceof fgui.GRoot)
  3928. this.dropdown.parent.hidePopup();
  3929. this._selectedIndex = -1;
  3930. this.selectedIndex = index;
  3931. this._node.emit(fgui.Event.STATUS_CHANGED, this);
  3932. };
  3933. GComboBox.prototype.onRollOver_1 = function () {
  3934. this._over = true;
  3935. if (this._down || this.dropdown && this.dropdown.parent)
  3936. return;
  3937. this.setState(fgui.GButton.OVER);
  3938. };
  3939. GComboBox.prototype.onRollOut_1 = function () {
  3940. this._over = false;
  3941. if (this._down || this.dropdown && this.dropdown.parent)
  3942. return;
  3943. this.setState(fgui.GButton.UP);
  3944. };
  3945. GComboBox.prototype.onTouchBegin_1 = function (evt) {
  3946. if (evt.button != cc.Event.EventMouse.BUTTON_LEFT)
  3947. return;
  3948. if ((evt.initiator instanceof fgui.GTextInput) && evt.initiator.editable)
  3949. return;
  3950. this._down = true;
  3951. evt.captureTouch();
  3952. if (this.dropdown)
  3953. this.showDropdown();
  3954. };
  3955. GComboBox.prototype.onTouchEnd_1 = function (evt) {
  3956. if (evt.button != cc.Event.EventMouse.BUTTON_LEFT)
  3957. return;
  3958. if (this._down) {
  3959. this._down = false;
  3960. if (this.dropdown && !this.dropdown.parent) {
  3961. if (this._over)
  3962. this.setState(fgui.GButton.OVER);
  3963. else
  3964. this.setState(fgui.GButton.UP);
  3965. }
  3966. }
  3967. };
  3968. return GComboBox;
  3969. }(fgui.GComponent));
  3970. fgui.GComboBox = GComboBox;
  3971. })(fgui || (fgui = {}));
  3972. (function (fgui) {
  3973. var GGraph = (function (_super) {
  3974. __extends(GGraph, _super);
  3975. function GGraph() {
  3976. var _this = _super.call(this) || this;
  3977. _this._type = 0;
  3978. _this._lineSize = 0;
  3979. _this._node.name = "GGraph";
  3980. _this._lineSize = 1;
  3981. _this._lineColor = new cc.Color();
  3982. _this._fillColor = new cc.Color(255, 255, 255, 255);
  3983. _this._content = _this._node.addComponent(cc.Graphics);
  3984. return _this;
  3985. }
  3986. GGraph.prototype.drawRect = function (lineSize, lineColor, fillColor, corner) {
  3987. this._type = 1;
  3988. this._lineSize = lineSize;
  3989. this._lineColor.set(lineColor);
  3990. this._fillColor.set(fillColor);
  3991. this._cornerRadius = corner;
  3992. this.updateGraph();
  3993. };
  3994. GGraph.prototype.drawEllipse = function (lineSize, lineColor, fillColor) {
  3995. this._type = 2;
  3996. this._lineSize = lineSize;
  3997. this._lineColor.set(lineColor);
  3998. this._fillColor.set(fillColor);
  3999. this.updateGraph();
  4000. };
  4001. GGraph.prototype.drawRegularPolygon = function (lineSize, lineColor, fillColor, sides, startAngle, distances) {
  4002. this._type = 4;
  4003. this._lineSize = lineSize;
  4004. this._lineColor.set(lineColor);
  4005. this._fillColor.set(fillColor);
  4006. this._sides = sides;
  4007. this._startAngle = startAngle || 0;
  4008. this._distances = distances;
  4009. this.updateGraph();
  4010. };
  4011. GGraph.prototype.drawPolygon = function (lineSize, lineColor, fillColor, points) {
  4012. this._type = 3;
  4013. this._lineSize = lineSize;
  4014. this._lineColor.set(lineColor);
  4015. this._fillColor.set(fillColor);
  4016. this._polygonPoints = points;
  4017. this.updateGraph();
  4018. };
  4019. Object.defineProperty(GGraph.prototype, "distances", {
  4020. get: function () {
  4021. return this._distances;
  4022. },
  4023. set: function (value) {
  4024. this._distances = value;
  4025. if (this._type == 3)
  4026. this.updateGraph();
  4027. },
  4028. enumerable: false,
  4029. configurable: true
  4030. });
  4031. GGraph.prototype.clearGraphics = function () {
  4032. this._type = 0;
  4033. if (this._hasContent) {
  4034. this._content.clear();
  4035. this._hasContent = false;
  4036. }
  4037. };
  4038. Object.defineProperty(GGraph.prototype, "type", {
  4039. get: function () {
  4040. return this._type;
  4041. },
  4042. enumerable: false,
  4043. configurable: true
  4044. });
  4045. Object.defineProperty(GGraph.prototype, "color", {
  4046. get: function () {
  4047. return this._fillColor;
  4048. },
  4049. set: function (value) {
  4050. this._fillColor.set(value);
  4051. if (this._type != 0)
  4052. this.updateGraph();
  4053. },
  4054. enumerable: false,
  4055. configurable: true
  4056. });
  4057. GGraph.prototype.updateGraph = function () {
  4058. var ctx = this._content;
  4059. if (this._hasContent) {
  4060. this._hasContent = false;
  4061. ctx.clear();
  4062. }
  4063. var w = this._width;
  4064. var h = this._height;
  4065. if (w == 0 || h == 0)
  4066. return;
  4067. var px = -this.pivotX * this._width;
  4068. var py = this.pivotY * this._height;
  4069. var ls = this._lineSize / 2;
  4070. ctx.lineWidth = this._lineSize;
  4071. ctx.strokeColor = this._lineColor;
  4072. ctx.fillColor = this._fillColor;
  4073. if (this._type == 1) {
  4074. if (this._cornerRadius) {
  4075. ctx.roundRect(px + ls, -h + py + ls, w - this._lineSize, h - this._lineSize, this._cornerRadius[0]);
  4076. }
  4077. else
  4078. ctx.rect(px + ls, -h + py + ls, w - this._lineSize, h - this._lineSize);
  4079. }
  4080. else if (this._type == 2) {
  4081. ctx.ellipse(w / 2 + px, -h / 2 + py, w / 2 - ls, h / 2 - ls);
  4082. }
  4083. else if (this._type == 3) {
  4084. this.drawPath(ctx, this._polygonPoints, px, py);
  4085. }
  4086. else if (this._type == 4) {
  4087. if (!this._polygonPoints)
  4088. this._polygonPoints = [];
  4089. var radius = Math.min(w, h) / 2 - ls;
  4090. this._polygonPoints.length = 0;
  4091. var angle = cc.misc.degreesToRadians(this._startAngle);
  4092. var deltaAngle = 2 * Math.PI / this._sides;
  4093. var dist;
  4094. for (var i = 0; i < this._sides; i++) {
  4095. if (this._distances) {
  4096. dist = this._distances[i];
  4097. if (isNaN(dist))
  4098. dist = 1;
  4099. }
  4100. else
  4101. dist = 1;
  4102. var xv = radius + radius * dist * Math.cos(angle);
  4103. var yv = radius + radius * dist * Math.sin(angle);
  4104. this._polygonPoints.push(xv, yv);
  4105. angle += deltaAngle;
  4106. }
  4107. this.drawPath(ctx, this._polygonPoints, px, py);
  4108. }
  4109. if (ls != 0)
  4110. ctx.stroke();
  4111. if (this._fillColor.a != 0)
  4112. ctx.fill();
  4113. this._hasContent = true;
  4114. };
  4115. GGraph.prototype.drawPath = function (ctx, points, px, py) {
  4116. var cnt = points.length;
  4117. ctx.moveTo(points[0] + px, -points[1] + py);
  4118. for (var i = 2; i < cnt; i += 2)
  4119. ctx.lineTo(points[i] + px, -points[i + 1] + py);
  4120. ctx.lineTo(points[0] + px, -points[1] + py);
  4121. };
  4122. GGraph.prototype.handleSizeChanged = function () {
  4123. _super.prototype.handleSizeChanged.call(this);
  4124. if (this._type != 0)
  4125. this.updateGraph();
  4126. };
  4127. GGraph.prototype.handleAnchorChanged = function () {
  4128. _super.prototype.handleAnchorChanged.call(this);
  4129. if (this._type != 0)
  4130. this.updateGraph();
  4131. };
  4132. GGraph.prototype.getProp = function (index) {
  4133. if (index == fgui.ObjectPropID.Color)
  4134. return this.color;
  4135. else
  4136. return _super.prototype.getProp.call(this, index);
  4137. };
  4138. GGraph.prototype.setProp = function (index, value) {
  4139. if (index == fgui.ObjectPropID.Color)
  4140. this.color = value;
  4141. else
  4142. _super.prototype.setProp.call(this, index, value);
  4143. };
  4144. GGraph.prototype._hitTest = function (pt) {
  4145. if (pt.x >= 0 && pt.y >= 0 && pt.x < this._width && pt.y < this._height) {
  4146. if (this._type == 3) {
  4147. var points = this._polygonPoints;
  4148. var len = points.length / 2;
  4149. var i = void 0;
  4150. var j = len - 1;
  4151. var oddNodes = false;
  4152. var w = this._width;
  4153. var h = this._height;
  4154. for (i = 0; i < len; ++i) {
  4155. var ix = points[i * 2];
  4156. var iy = points[i * 2 + 1];
  4157. var jx = points[j * 2];
  4158. var jy = points[j * 2 + 1];
  4159. if ((iy < pt.y && jy >= pt.y || jy < pt.y && iy >= pt.y) && (ix <= pt.x || jx <= pt.x)) {
  4160. if (ix + (pt.y - iy) / (jy - iy) * (jx - ix) < pt.x)
  4161. oddNodes = !oddNodes;
  4162. }
  4163. j = i;
  4164. }
  4165. return oddNodes ? this : null;
  4166. }
  4167. else
  4168. return this;
  4169. }
  4170. else
  4171. return null;
  4172. };
  4173. GGraph.prototype.setup_beforeAdd = function (buffer, beginPos) {
  4174. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  4175. buffer.seek(beginPos, 5);
  4176. this._type = buffer.readByte();
  4177. if (this._type != 0) {
  4178. var i;
  4179. var cnt;
  4180. this._lineSize = buffer.readInt();
  4181. this._lineColor.set(buffer.readColor(true));
  4182. this._fillColor.set(buffer.readColor(true));
  4183. if (buffer.readBool()) {
  4184. this._cornerRadius = new Array(4);
  4185. for (i = 0; i < 4; i++)
  4186. this._cornerRadius[i] = buffer.readFloat();
  4187. }
  4188. if (this._type == 3) {
  4189. cnt = buffer.readShort();
  4190. this._polygonPoints = [];
  4191. this._polygonPoints.length = cnt;
  4192. for (i = 0; i < cnt; i++)
  4193. this._polygonPoints[i] = buffer.readFloat();
  4194. }
  4195. else if (this._type == 4) {
  4196. this._sides = buffer.readShort();
  4197. this._startAngle = buffer.readFloat();
  4198. cnt = buffer.readShort();
  4199. if (cnt > 0) {
  4200. this._distances = [];
  4201. for (i = 0; i < cnt; i++)
  4202. this._distances[i] = buffer.readFloat();
  4203. }
  4204. }
  4205. this.updateGraph();
  4206. }
  4207. };
  4208. return GGraph;
  4209. }(fgui.GObject));
  4210. fgui.GGraph = GGraph;
  4211. })(fgui || (fgui = {}));
  4212. (function (fgui) {
  4213. var GGroup = (function (_super) {
  4214. __extends(GGroup, _super);
  4215. function GGroup() {
  4216. var _this = _super.call(this) || this;
  4217. _this._layout = 0;
  4218. _this._lineGap = 0;
  4219. _this._columnGap = 0;
  4220. _this._mainGridIndex = -1;
  4221. _this._mainGridMinSize = 50;
  4222. _this._mainChildIndex = -1;
  4223. _this._totalSize = 0;
  4224. _this._numChildren = 0;
  4225. _this._updating = 0;
  4226. _this._node.name = "GGroup";
  4227. _this._touchDisabled = true;
  4228. return _this;
  4229. }
  4230. GGroup.prototype.dispose = function () {
  4231. this._boundsChanged = false;
  4232. _super.prototype.dispose.call(this);
  4233. };
  4234. Object.defineProperty(GGroup.prototype, "layout", {
  4235. get: function () {
  4236. return this._layout;
  4237. },
  4238. set: function (value) {
  4239. if (this._layout != value) {
  4240. this._layout = value;
  4241. this.setBoundsChangedFlag();
  4242. }
  4243. },
  4244. enumerable: false,
  4245. configurable: true
  4246. });
  4247. Object.defineProperty(GGroup.prototype, "lineGap", {
  4248. get: function () {
  4249. return this._lineGap;
  4250. },
  4251. set: function (value) {
  4252. if (this._lineGap != value) {
  4253. this._lineGap = value;
  4254. this.setBoundsChangedFlag(true);
  4255. }
  4256. },
  4257. enumerable: false,
  4258. configurable: true
  4259. });
  4260. Object.defineProperty(GGroup.prototype, "columnGap", {
  4261. get: function () {
  4262. return this._columnGap;
  4263. },
  4264. set: function (value) {
  4265. if (this._columnGap != value) {
  4266. this._columnGap = value;
  4267. this.setBoundsChangedFlag(true);
  4268. }
  4269. },
  4270. enumerable: false,
  4271. configurable: true
  4272. });
  4273. Object.defineProperty(GGroup.prototype, "excludeInvisibles", {
  4274. get: function () {
  4275. return this._excludeInvisibles;
  4276. },
  4277. set: function (value) {
  4278. if (this._excludeInvisibles != value) {
  4279. this._excludeInvisibles = value;
  4280. this.setBoundsChangedFlag();
  4281. }
  4282. },
  4283. enumerable: false,
  4284. configurable: true
  4285. });
  4286. Object.defineProperty(GGroup.prototype, "autoSizeDisabled", {
  4287. get: function () {
  4288. return this._autoSizeDisabled;
  4289. },
  4290. set: function (value) {
  4291. this._autoSizeDisabled = value;
  4292. },
  4293. enumerable: false,
  4294. configurable: true
  4295. });
  4296. Object.defineProperty(GGroup.prototype, "mainGridMinSize", {
  4297. get: function () {
  4298. return this._mainGridMinSize;
  4299. },
  4300. set: function (value) {
  4301. if (this._mainGridMinSize != value) {
  4302. this._mainGridMinSize = value;
  4303. this.setBoundsChangedFlag();
  4304. }
  4305. },
  4306. enumerable: false,
  4307. configurable: true
  4308. });
  4309. Object.defineProperty(GGroup.prototype, "mainGridIndex", {
  4310. get: function () {
  4311. return this._mainGridIndex;
  4312. },
  4313. set: function (value) {
  4314. if (this._mainGridIndex != value) {
  4315. this._mainGridIndex = value;
  4316. this.setBoundsChangedFlag();
  4317. }
  4318. },
  4319. enumerable: false,
  4320. configurable: true
  4321. });
  4322. GGroup.prototype.setBoundsChangedFlag = function (positionChangedOnly) {
  4323. if (positionChangedOnly === void 0) { positionChangedOnly = false; }
  4324. if (this._updating == 0 && this._parent) {
  4325. if (!positionChangedOnly)
  4326. this._percentReady = false;
  4327. if (!this._boundsChanged) {
  4328. this._boundsChanged = true;
  4329. if (this._layout != fgui.GroupLayoutType.None)
  4330. this._partner.callLater(this._ensureBoundsCorrect);
  4331. }
  4332. }
  4333. };
  4334. GGroup.prototype._ensureBoundsCorrect = function () {
  4335. var _t = (this.node["$gobj"]);
  4336. _t.ensureBoundsCorrect();
  4337. };
  4338. GGroup.prototype.ensureSizeCorrect = function () {
  4339. if (this._parent == null || !this._boundsChanged || this._layout == 0)
  4340. return;
  4341. this._boundsChanged = false;
  4342. if (this._autoSizeDisabled)
  4343. this.resizeChildren(0, 0);
  4344. else {
  4345. this.handleLayout();
  4346. this.updateBounds();
  4347. }
  4348. };
  4349. GGroup.prototype.ensureBoundsCorrect = function () {
  4350. if (this._parent == null || !this._boundsChanged)
  4351. return;
  4352. this._boundsChanged = false;
  4353. if (this._layout == 0)
  4354. this.updateBounds();
  4355. else {
  4356. if (this._autoSizeDisabled)
  4357. this.resizeChildren(0, 0);
  4358. else {
  4359. this.handleLayout();
  4360. this.updateBounds();
  4361. }
  4362. }
  4363. };
  4364. GGroup.prototype.updateBounds = function () {
  4365. this._partner.unschedule(this._ensureBoundsCorrect);
  4366. var cnt = this._parent.numChildren;
  4367. var i;
  4368. var child;
  4369. var ax = Number.POSITIVE_INFINITY, ay = Number.POSITIVE_INFINITY;
  4370. var ar = Number.NEGATIVE_INFINITY, ab = Number.NEGATIVE_INFINITY;
  4371. var tmp;
  4372. var empty = true;
  4373. for (i = 0; i < cnt; i++) {
  4374. child = this._parent.getChildAt(i);
  4375. if (child.group != this || this._excludeInvisibles && !child.internalVisible3)
  4376. continue;
  4377. tmp = child.xMin;
  4378. if (tmp < ax)
  4379. ax = tmp;
  4380. tmp = child.yMin;
  4381. if (tmp < ay)
  4382. ay = tmp;
  4383. tmp = child.xMin + child.width;
  4384. if (tmp > ar)
  4385. ar = tmp;
  4386. tmp = child.yMin + child.height;
  4387. if (tmp > ab)
  4388. ab = tmp;
  4389. empty = false;
  4390. }
  4391. var w = 0, h = 0;
  4392. if (!empty) {
  4393. this._updating |= 1;
  4394. this.setPosition(ax, ay);
  4395. this._updating &= 2;
  4396. w = ar - ax;
  4397. h = ab - ay;
  4398. }
  4399. if ((this._updating & 2) == 0) {
  4400. this._updating |= 2;
  4401. this.setSize(w, h);
  4402. this._updating &= 1;
  4403. }
  4404. else {
  4405. this._updating &= 1;
  4406. this.resizeChildren(this._width - w, this._height - h);
  4407. }
  4408. };
  4409. GGroup.prototype.handleLayout = function () {
  4410. this._updating |= 1;
  4411. var child;
  4412. var i;
  4413. var cnt;
  4414. if (this._layout == fgui.GroupLayoutType.Horizontal) {
  4415. var curX = this.x;
  4416. cnt = this._parent.numChildren;
  4417. for (i = 0; i < cnt; i++) {
  4418. child = this._parent.getChildAt(i);
  4419. if (child.group != this)
  4420. continue;
  4421. if (this._excludeInvisibles && !child.internalVisible3)
  4422. continue;
  4423. child.xMin = curX;
  4424. if (child.width != 0)
  4425. curX += child.width + this._columnGap;
  4426. }
  4427. }
  4428. else if (this._layout == fgui.GroupLayoutType.Vertical) {
  4429. var curY = this.y;
  4430. cnt = this._parent.numChildren;
  4431. for (i = 0; i < cnt; i++) {
  4432. child = this._parent.getChildAt(i);
  4433. if (child.group != this)
  4434. continue;
  4435. if (this._excludeInvisibles && !child.internalVisible3)
  4436. continue;
  4437. child.yMin = curY;
  4438. if (child.height != 0)
  4439. curY += child.height + this._lineGap;
  4440. }
  4441. }
  4442. this._updating &= 2;
  4443. };
  4444. GGroup.prototype.moveChildren = function (dx, dy) {
  4445. if ((this._updating & 1) != 0 || this._parent == null)
  4446. return;
  4447. this._updating |= 1;
  4448. var cnt = this._parent.numChildren;
  4449. var i;
  4450. var child;
  4451. for (i = 0; i < cnt; i++) {
  4452. child = this._parent.getChildAt(i);
  4453. if (child.group == this) {
  4454. child.setPosition(child.x + dx, child.y + dy);
  4455. }
  4456. }
  4457. this._updating &= 2;
  4458. };
  4459. GGroup.prototype.resizeChildren = function (dw, dh) {
  4460. if (this._layout == fgui.GroupLayoutType.None || (this._updating & 2) != 0 || this._parent == null)
  4461. return;
  4462. this._updating |= 2;
  4463. if (this._boundsChanged) {
  4464. this._boundsChanged = false;
  4465. if (!this._autoSizeDisabled) {
  4466. this.updateBounds();
  4467. return;
  4468. }
  4469. }
  4470. var cnt = this._parent.numChildren;
  4471. var i;
  4472. var child;
  4473. if (!this._percentReady) {
  4474. this._percentReady = true;
  4475. this._numChildren = 0;
  4476. this._totalSize = 0;
  4477. this._mainChildIndex = -1;
  4478. var j = 0;
  4479. for (i = 0; i < cnt; i++) {
  4480. child = this._parent.getChildAt(i);
  4481. if (child.group != this)
  4482. continue;
  4483. if (!this._excludeInvisibles || child.internalVisible3) {
  4484. if (j == this._mainGridIndex)
  4485. this._mainChildIndex = i;
  4486. this._numChildren++;
  4487. if (this._layout == 1)
  4488. this._totalSize += child.width;
  4489. else
  4490. this._totalSize += child.height;
  4491. }
  4492. j++;
  4493. }
  4494. if (this._mainChildIndex != -1) {
  4495. if (this._layout == 1) {
  4496. child = this._parent.getChildAt(this._mainChildIndex);
  4497. this._totalSize += this._mainGridMinSize - child.width;
  4498. child._sizePercentInGroup = this._mainGridMinSize / this._totalSize;
  4499. }
  4500. else {
  4501. child = this._parent.getChildAt(this._mainChildIndex);
  4502. this._totalSize += this._mainGridMinSize - child.height;
  4503. child._sizePercentInGroup = this._mainGridMinSize / this._totalSize;
  4504. }
  4505. }
  4506. for (i = 0; i < cnt; i++) {
  4507. child = this._parent.getChildAt(i);
  4508. if (child.group != this)
  4509. continue;
  4510. if (i == this._mainChildIndex)
  4511. continue;
  4512. if (this._totalSize > 0)
  4513. child._sizePercentInGroup = (this._layout == 1 ? child.width : child.height) / this._totalSize;
  4514. else
  4515. child._sizePercentInGroup = 0;
  4516. }
  4517. }
  4518. var remainSize = 0;
  4519. var remainPercent = 1;
  4520. var priorHandled = false;
  4521. if (this._layout == 1) {
  4522. remainSize = this.width - (this._numChildren - 1) * this._columnGap;
  4523. if (this._mainChildIndex != -1 && remainSize >= this._totalSize) {
  4524. child = this._parent.getChildAt(this._mainChildIndex);
  4525. child.setSize(remainSize - (this._totalSize - this._mainGridMinSize), child._rawHeight + dh, true);
  4526. remainSize -= child.width;
  4527. remainPercent -= child._sizePercentInGroup;
  4528. priorHandled = true;
  4529. }
  4530. var curX = this.x;
  4531. for (i = 0; i < cnt; i++) {
  4532. child = this._parent.getChildAt(i);
  4533. if (child.group != this)
  4534. continue;
  4535. if (this._excludeInvisibles && !child.internalVisible3) {
  4536. child.setSize(child._rawWidth, child._rawHeight + dh, true);
  4537. continue;
  4538. }
  4539. if (!priorHandled || i != this._mainChildIndex) {
  4540. child.setSize(Math.round(child._sizePercentInGroup / remainPercent * remainSize), child._rawHeight + dh, true);
  4541. remainPercent -= child._sizePercentInGroup;
  4542. remainSize -= child.width;
  4543. }
  4544. child.xMin = curX;
  4545. if (child.width != 0)
  4546. curX += child.width + this._columnGap;
  4547. }
  4548. }
  4549. else {
  4550. remainSize = this.height - (this._numChildren - 1) * this._lineGap;
  4551. if (this._mainChildIndex != -1 && remainSize >= this._totalSize) {
  4552. child = this._parent.getChildAt(this._mainChildIndex);
  4553. child.setSize(child._rawWidth + dw, remainSize - (this._totalSize - this._mainGridMinSize), true);
  4554. remainSize -= child.height;
  4555. remainPercent -= child._sizePercentInGroup;
  4556. priorHandled = true;
  4557. }
  4558. var curY = this.y;
  4559. for (i = 0; i < cnt; i++) {
  4560. child = this._parent.getChildAt(i);
  4561. if (child.group != this)
  4562. continue;
  4563. if (this._excludeInvisibles && !child.internalVisible3) {
  4564. child.setSize(child._rawWidth + dw, child._rawHeight, true);
  4565. continue;
  4566. }
  4567. if (!priorHandled || i != this._mainChildIndex) {
  4568. child.setSize(child._rawWidth + dw, Math.round(child._sizePercentInGroup / remainPercent * remainSize), true);
  4569. remainPercent -= child._sizePercentInGroup;
  4570. remainSize -= child.height;
  4571. }
  4572. child.yMin = curY;
  4573. if (child.height != 0)
  4574. curY += child.height + this._lineGap;
  4575. }
  4576. }
  4577. this._updating &= 1;
  4578. };
  4579. GGroup.prototype.handleAlphaChanged = function () {
  4580. if (this._underConstruct)
  4581. return;
  4582. var cnt = this._parent.numChildren;
  4583. for (var i = 0; i < cnt; i++) {
  4584. var child = this._parent.getChildAt(i);
  4585. if (child.group == this)
  4586. child.alpha = this.alpha;
  4587. }
  4588. };
  4589. GGroup.prototype.handleVisibleChanged = function () {
  4590. if (!this._parent)
  4591. return;
  4592. var cnt = this._parent.numChildren;
  4593. for (var i = 0; i < cnt; i++) {
  4594. var child = this._parent.getChildAt(i);
  4595. if (child.group == this)
  4596. child.handleVisibleChanged();
  4597. }
  4598. };
  4599. GGroup.prototype.setup_beforeAdd = function (buffer, beginPos) {
  4600. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  4601. buffer.seek(beginPos, 5);
  4602. this._layout = buffer.readByte();
  4603. this._lineGap = buffer.readInt();
  4604. this._columnGap = buffer.readInt();
  4605. if (buffer.version >= 2) {
  4606. this._excludeInvisibles = buffer.readBool();
  4607. this._autoSizeDisabled = buffer.readBool();
  4608. this._mainChildIndex = buffer.readInt();
  4609. }
  4610. };
  4611. GGroup.prototype.setup_afterAdd = function (buffer, beginPos) {
  4612. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  4613. if (!this.visible)
  4614. this.handleVisibleChanged();
  4615. };
  4616. return GGroup;
  4617. }(fgui.GObject));
  4618. fgui.GGroup = GGroup;
  4619. })(fgui || (fgui = {}));
  4620. (function (fgui) {
  4621. var GImage = (function (_super) {
  4622. __extends(GImage, _super);
  4623. function GImage() {
  4624. var _this = _super.call(this) || this;
  4625. _this._node.name = "GImage";
  4626. _this._touchDisabled = true;
  4627. _this._content = _this._node.addComponent(fgui.Image);
  4628. _this._content.sizeMode = cc.Sprite.SizeMode.CUSTOM;
  4629. _this._content.trim = false;
  4630. return _this;
  4631. }
  4632. Object.defineProperty(GImage.prototype, "color", {
  4633. get: function () {
  4634. return this._node.color;
  4635. },
  4636. set: function (value) {
  4637. this._node.color = value;
  4638. this.updateGear(4);
  4639. },
  4640. enumerable: false,
  4641. configurable: true
  4642. });
  4643. Object.defineProperty(GImage.prototype, "flip", {
  4644. get: function () {
  4645. return this._content.flip;
  4646. },
  4647. set: function (value) {
  4648. this._content.flip = value;
  4649. },
  4650. enumerable: false,
  4651. configurable: true
  4652. });
  4653. Object.defineProperty(GImage.prototype, "fillMethod", {
  4654. get: function () {
  4655. return this._content.fillMethod;
  4656. },
  4657. set: function (value) {
  4658. this._content.fillMethod = value;
  4659. },
  4660. enumerable: false,
  4661. configurable: true
  4662. });
  4663. Object.defineProperty(GImage.prototype, "fillOrigin", {
  4664. get: function () {
  4665. return this._content.fillOrigin;
  4666. },
  4667. set: function (value) {
  4668. this._content.fillOrigin = value;
  4669. },
  4670. enumerable: false,
  4671. configurable: true
  4672. });
  4673. Object.defineProperty(GImage.prototype, "fillClockwise", {
  4674. get: function () {
  4675. return this._content.fillClockwise;
  4676. },
  4677. set: function (value) {
  4678. this._content.fillClockwise = value;
  4679. },
  4680. enumerable: false,
  4681. configurable: true
  4682. });
  4683. Object.defineProperty(GImage.prototype, "fillAmount", {
  4684. get: function () {
  4685. return this._content.fillAmount;
  4686. },
  4687. set: function (value) {
  4688. this._content.fillAmount = value;
  4689. },
  4690. enumerable: false,
  4691. configurable: true
  4692. });
  4693. GImage.prototype.constructFromResource = function () {
  4694. var contentItem = this.packageItem.getBranch();
  4695. this.sourceWidth = contentItem.width;
  4696. this.sourceHeight = contentItem.height;
  4697. this.initWidth = this.sourceWidth;
  4698. this.initHeight = this.sourceHeight;
  4699. this.setSize(this.sourceWidth, this.sourceHeight);
  4700. contentItem = contentItem.getHighResolution();
  4701. contentItem.load();
  4702. if (contentItem.scale9Grid)
  4703. this._content.type = cc.Sprite.Type.SLICED;
  4704. else if (contentItem.scaleByTile)
  4705. this._content.type = cc.Sprite.Type.TILED;
  4706. this._content.spriteFrame = contentItem.asset;
  4707. };
  4708. GImage.prototype.handleGrayedChanged = function () {
  4709. this._content.grayed = this._grayed;
  4710. };
  4711. GImage.prototype.getProp = function (index) {
  4712. if (index == fgui.ObjectPropID.Color)
  4713. return this.color;
  4714. else
  4715. return _super.prototype.getProp.call(this, index);
  4716. };
  4717. GImage.prototype.setProp = function (index, value) {
  4718. if (index == fgui.ObjectPropID.Color)
  4719. this.color = value;
  4720. else
  4721. _super.prototype.setProp.call(this, index, value);
  4722. };
  4723. GImage.prototype.setup_beforeAdd = function (buffer, beginPos) {
  4724. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  4725. buffer.seek(beginPos, 5);
  4726. if (buffer.readBool())
  4727. this.color = buffer.readColor();
  4728. this._content.flip = buffer.readByte();
  4729. this._content.fillMethod = buffer.readByte();
  4730. if (this._content.fillMethod != 0) {
  4731. this._content.fillOrigin = buffer.readByte();
  4732. this._content.fillClockwise = buffer.readBool();
  4733. this._content.fillAmount = buffer.readFloat();
  4734. }
  4735. };
  4736. return GImage;
  4737. }(fgui.GObject));
  4738. fgui.GImage = GImage;
  4739. })(fgui || (fgui = {}));
  4740. (function (fgui) {
  4741. var GLabel = (function (_super) {
  4742. __extends(GLabel, _super);
  4743. function GLabel() {
  4744. var _this = _super.call(this) || this;
  4745. _this._node.name = "GLabel";
  4746. return _this;
  4747. }
  4748. Object.defineProperty(GLabel.prototype, "icon", {
  4749. get: function () {
  4750. if (this._iconObject)
  4751. return this._iconObject.icon;
  4752. },
  4753. set: function (value) {
  4754. if (this._iconObject)
  4755. this._iconObject.icon = value;
  4756. this.updateGear(7);
  4757. },
  4758. enumerable: false,
  4759. configurable: true
  4760. });
  4761. Object.defineProperty(GLabel.prototype, "title", {
  4762. get: function () {
  4763. if (this._titleObject)
  4764. return this._titleObject.text;
  4765. else
  4766. return null;
  4767. },
  4768. set: function (value) {
  4769. if (this._titleObject)
  4770. this._titleObject.text = value;
  4771. this.updateGear(6);
  4772. },
  4773. enumerable: false,
  4774. configurable: true
  4775. });
  4776. Object.defineProperty(GLabel.prototype, "text", {
  4777. get: function () {
  4778. return this.title;
  4779. },
  4780. set: function (value) {
  4781. this.title = value;
  4782. },
  4783. enumerable: false,
  4784. configurable: true
  4785. });
  4786. Object.defineProperty(GLabel.prototype, "titleColor", {
  4787. get: function () {
  4788. var tf = this.getTextField();
  4789. if (tf)
  4790. return tf.color;
  4791. else
  4792. return cc.Color.WHITE;
  4793. },
  4794. set: function (value) {
  4795. var tf = this.getTextField();
  4796. if (tf)
  4797. tf.color = value;
  4798. this.updateGear(4);
  4799. },
  4800. enumerable: false,
  4801. configurable: true
  4802. });
  4803. Object.defineProperty(GLabel.prototype, "titleFontSize", {
  4804. get: function () {
  4805. var tf = this.getTextField();
  4806. if (tf)
  4807. return tf.fontSize;
  4808. else
  4809. return 0;
  4810. },
  4811. set: function (value) {
  4812. var tf = this.getTextField();
  4813. if (tf)
  4814. tf.fontSize = value;
  4815. },
  4816. enumerable: false,
  4817. configurable: true
  4818. });
  4819. Object.defineProperty(GLabel.prototype, "editable", {
  4820. get: function () {
  4821. if (this._titleObject && (this._titleObject instanceof fgui.GTextInput))
  4822. return this._titleObject.editable;
  4823. else
  4824. return false;
  4825. },
  4826. set: function (val) {
  4827. if (this._titleObject && (this._titleObject instanceof fgui.GTextInput))
  4828. this._titleObject.editable = val;
  4829. },
  4830. enumerable: false,
  4831. configurable: true
  4832. });
  4833. GLabel.prototype.getTextField = function () {
  4834. if (this._titleObject instanceof fgui.GTextField)
  4835. return this._titleObject;
  4836. else if ((this._titleObject instanceof GLabel) || (this._titleObject instanceof fgui.GButton))
  4837. return this._titleObject.getTextField();
  4838. else
  4839. return null;
  4840. };
  4841. GLabel.prototype.getProp = function (index) {
  4842. switch (index) {
  4843. case fgui.ObjectPropID.Color:
  4844. return this.titleColor;
  4845. case fgui.ObjectPropID.OutlineColor:
  4846. {
  4847. var tf = this.getTextField();
  4848. if (tf)
  4849. return tf.strokeColor;
  4850. else
  4851. return 0;
  4852. }
  4853. case fgui.ObjectPropID.FontSize:
  4854. return this.titleFontSize;
  4855. default:
  4856. return _super.prototype.getProp.call(this, index);
  4857. }
  4858. };
  4859. GLabel.prototype.setProp = function (index, value) {
  4860. switch (index) {
  4861. case fgui.ObjectPropID.Color:
  4862. this.titleColor = value;
  4863. break;
  4864. case fgui.ObjectPropID.OutlineColor:
  4865. {
  4866. var tf = this.getTextField();
  4867. if (tf)
  4868. tf.strokeColor = value;
  4869. }
  4870. break;
  4871. case fgui.ObjectPropID.FontSize:
  4872. this.titleFontSize = value;
  4873. break;
  4874. default:
  4875. _super.prototype.setProp.call(this, index, value);
  4876. break;
  4877. }
  4878. };
  4879. GLabel.prototype.constructExtension = function (buffer) {
  4880. this._titleObject = this.getChild("title");
  4881. this._iconObject = this.getChild("icon");
  4882. };
  4883. GLabel.prototype.setup_afterAdd = function (buffer, beginPos) {
  4884. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  4885. if (!buffer.seek(beginPos, 6))
  4886. return;
  4887. if (buffer.readByte() != this.packageItem.objectType)
  4888. return;
  4889. var str;
  4890. str = buffer.readS();
  4891. if (str != null)
  4892. this.title = str;
  4893. str = buffer.readS();
  4894. if (str != null)
  4895. this.icon = str;
  4896. if (buffer.readBool())
  4897. this.titleColor = buffer.readColor();
  4898. var iv = buffer.readInt();
  4899. if (iv != 0)
  4900. this.titleFontSize = iv;
  4901. if (buffer.readBool()) {
  4902. var input = this.getTextField();
  4903. if (input instanceof fgui.GTextInput) {
  4904. str = buffer.readS();
  4905. if (str != null)
  4906. input.promptText = str;
  4907. str = buffer.readS();
  4908. if (str != null)
  4909. input.restrict = str;
  4910. iv = buffer.readInt();
  4911. if (iv != 0)
  4912. input.maxLength = iv;
  4913. iv = buffer.readInt();
  4914. if (iv != 0) {
  4915. }
  4916. if (buffer.readBool())
  4917. input.password = true;
  4918. }
  4919. else
  4920. buffer.skip(13);
  4921. }
  4922. };
  4923. return GLabel;
  4924. }(fgui.GComponent));
  4925. fgui.GLabel = GLabel;
  4926. })(fgui || (fgui = {}));
  4927. (function (fgui) {
  4928. var GList = (function (_super) {
  4929. __extends(GList, _super);
  4930. function GList() {
  4931. var _this = _super.call(this) || this;
  4932. _this.scrollItemToViewOnClick = true;
  4933. _this.foldInvisibleItems = false;
  4934. _this._lineCount = 0;
  4935. _this._columnCount = 0;
  4936. _this._lineGap = 0;
  4937. _this._columnGap = 0;
  4938. _this._lastSelectedIndex = 0;
  4939. _this._numItems = 0;
  4940. _this._realNumItems = 0;
  4941. _this._firstIndex = 0;
  4942. _this._curLineItemCount = 0;
  4943. _this._curLineItemCount2 = 0;
  4944. _this._virtualListChanged = 0;
  4945. _this.itemInfoVer = 0;
  4946. _this._node.name = "GList";
  4947. _this._trackBounds = true;
  4948. _this._pool = new fgui.GObjectPool();
  4949. _this._layout = fgui.ListLayoutType.SingleColumn;
  4950. _this._autoResizeItem = true;
  4951. _this._lastSelectedIndex = -1;
  4952. _this._selectionMode = fgui.ListSelectionMode.Single;
  4953. _this.opaque = true;
  4954. _this._align = fgui.AlignType.Left;
  4955. _this._verticalAlign = fgui.VertAlignType.Top;
  4956. return _this;
  4957. }
  4958. GList.prototype.dispose = function () {
  4959. this._pool.clear();
  4960. _super.prototype.dispose.call(this);
  4961. };
  4962. Object.defineProperty(GList.prototype, "layout", {
  4963. get: function () {
  4964. return this._layout;
  4965. },
  4966. set: function (value) {
  4967. if (this._layout != value) {
  4968. this._layout = value;
  4969. this.setBoundsChangedFlag();
  4970. if (this._virtual)
  4971. this.setVirtualListChangedFlag(true);
  4972. }
  4973. },
  4974. enumerable: false,
  4975. configurable: true
  4976. });
  4977. Object.defineProperty(GList.prototype, "lineCount", {
  4978. get: function () {
  4979. return this._lineCount;
  4980. },
  4981. set: function (value) {
  4982. if (this._lineCount != value) {
  4983. this._lineCount = value;
  4984. this.setBoundsChangedFlag();
  4985. if (this._virtual)
  4986. this.setVirtualListChangedFlag(true);
  4987. }
  4988. },
  4989. enumerable: false,
  4990. configurable: true
  4991. });
  4992. Object.defineProperty(GList.prototype, "columnCount", {
  4993. get: function () {
  4994. return this._columnCount;
  4995. },
  4996. set: function (value) {
  4997. if (this._columnCount != value) {
  4998. this._columnCount = value;
  4999. this.setBoundsChangedFlag();
  5000. if (this._virtual)
  5001. this.setVirtualListChangedFlag(true);
  5002. }
  5003. },
  5004. enumerable: false,
  5005. configurable: true
  5006. });
  5007. Object.defineProperty(GList.prototype, "lineGap", {
  5008. get: function () {
  5009. return this._lineGap;
  5010. },
  5011. set: function (value) {
  5012. if (this._lineGap != value) {
  5013. this._lineGap = value;
  5014. this.setBoundsChangedFlag();
  5015. if (this._virtual)
  5016. this.setVirtualListChangedFlag(true);
  5017. }
  5018. },
  5019. enumerable: false,
  5020. configurable: true
  5021. });
  5022. Object.defineProperty(GList.prototype, "columnGap", {
  5023. get: function () {
  5024. return this._columnGap;
  5025. },
  5026. set: function (value) {
  5027. if (this._columnGap != value) {
  5028. this._columnGap = value;
  5029. this.setBoundsChangedFlag();
  5030. if (this._virtual)
  5031. this.setVirtualListChangedFlag(true);
  5032. }
  5033. },
  5034. enumerable: false,
  5035. configurable: true
  5036. });
  5037. Object.defineProperty(GList.prototype, "align", {
  5038. get: function () {
  5039. return this._align;
  5040. },
  5041. set: function (value) {
  5042. if (this._align != value) {
  5043. this._align = value;
  5044. this.setBoundsChangedFlag();
  5045. if (this._virtual)
  5046. this.setVirtualListChangedFlag(true);
  5047. }
  5048. },
  5049. enumerable: false,
  5050. configurable: true
  5051. });
  5052. Object.defineProperty(GList.prototype, "verticalAlign", {
  5053. get: function () {
  5054. return this._verticalAlign;
  5055. },
  5056. set: function (value) {
  5057. if (this._verticalAlign != value) {
  5058. this._verticalAlign = value;
  5059. this.setBoundsChangedFlag();
  5060. if (this._virtual)
  5061. this.setVirtualListChangedFlag(true);
  5062. }
  5063. },
  5064. enumerable: false,
  5065. configurable: true
  5066. });
  5067. Object.defineProperty(GList.prototype, "virtualItemSize", {
  5068. get: function () {
  5069. return this._itemSize;
  5070. },
  5071. set: function (value) {
  5072. if (this._virtual) {
  5073. if (this._itemSize == null)
  5074. this._itemSize = new cc.Size(0, 0);
  5075. this._itemSize.width = value.width;
  5076. this._itemSize.height = value.height;
  5077. this.setVirtualListChangedFlag(true);
  5078. }
  5079. },
  5080. enumerable: false,
  5081. configurable: true
  5082. });
  5083. Object.defineProperty(GList.prototype, "defaultItem", {
  5084. get: function () {
  5085. return this._defaultItem;
  5086. },
  5087. set: function (val) {
  5088. this._defaultItem = val;
  5089. },
  5090. enumerable: false,
  5091. configurable: true
  5092. });
  5093. Object.defineProperty(GList.prototype, "autoResizeItem", {
  5094. get: function () {
  5095. return this._autoResizeItem;
  5096. },
  5097. set: function (value) {
  5098. if (this._autoResizeItem != value) {
  5099. this._autoResizeItem = value;
  5100. this.setBoundsChangedFlag();
  5101. if (this._virtual)
  5102. this.setVirtualListChangedFlag(true);
  5103. }
  5104. },
  5105. enumerable: false,
  5106. configurable: true
  5107. });
  5108. Object.defineProperty(GList.prototype, "selectionMode", {
  5109. get: function () {
  5110. return this._selectionMode;
  5111. },
  5112. set: function (value) {
  5113. this._selectionMode = value;
  5114. },
  5115. enumerable: false,
  5116. configurable: true
  5117. });
  5118. Object.defineProperty(GList.prototype, "selectionController", {
  5119. get: function () {
  5120. return this._selectionController;
  5121. },
  5122. set: function (value) {
  5123. this._selectionController = value;
  5124. },
  5125. enumerable: false,
  5126. configurable: true
  5127. });
  5128. Object.defineProperty(GList.prototype, "itemPool", {
  5129. get: function () {
  5130. return this._pool;
  5131. },
  5132. enumerable: false,
  5133. configurable: true
  5134. });
  5135. GList.prototype.getFromPool = function (url) {
  5136. if (!url)
  5137. url = this._defaultItem;
  5138. var obj = this._pool.getObject(url);
  5139. if (obj)
  5140. obj.visible = true;
  5141. return obj;
  5142. };
  5143. GList.prototype.returnToPool = function (obj) {
  5144. this._pool.returnObject(obj);
  5145. };
  5146. GList.prototype.addChildAt = function (child, index) {
  5147. _super.prototype.addChildAt.call(this, child, index);
  5148. if (child instanceof fgui.GButton) {
  5149. child.selected = false;
  5150. child.changeStateOnClick = false;
  5151. }
  5152. child.on(fgui.Event.CLICK, this.onClickItem, this);
  5153. return child;
  5154. };
  5155. GList.prototype.addItem = function (url) {
  5156. if (!url)
  5157. url = this._defaultItem;
  5158. return this.addChild(fgui.UIPackage.createObjectFromURL(url));
  5159. };
  5160. GList.prototype.addItemFromPool = function (url) {
  5161. return this.addChild(this.getFromPool(url));
  5162. };
  5163. GList.prototype.removeChildAt = function (index, dispose) {
  5164. var child = _super.prototype.removeChildAt.call(this, index, dispose);
  5165. child.off(fgui.Event.CLICK, this.onClickItem, this);
  5166. return child;
  5167. };
  5168. GList.prototype.removeChildToPoolAt = function (index) {
  5169. var child = _super.prototype.removeChildAt.call(this, index);
  5170. this.returnToPool(child);
  5171. };
  5172. GList.prototype.removeChildToPool = function (child) {
  5173. _super.prototype.removeChild.call(this, child);
  5174. this.returnToPool(child);
  5175. };
  5176. GList.prototype.removeChildrenToPool = function (beginIndex, endIndex) {
  5177. if (beginIndex == undefined)
  5178. beginIndex = 0;
  5179. if (endIndex == undefined)
  5180. endIndex = -1;
  5181. if (endIndex < 0 || endIndex >= this._children.length)
  5182. endIndex = this._children.length - 1;
  5183. for (var i = beginIndex; i <= endIndex; ++i)
  5184. this.removeChildToPoolAt(beginIndex);
  5185. };
  5186. Object.defineProperty(GList.prototype, "selectedIndex", {
  5187. get: function () {
  5188. var i;
  5189. if (this._virtual) {
  5190. for (i = 0; i < this._realNumItems; i++) {
  5191. var ii = this._virtualItems[i];
  5192. if ((ii.obj instanceof fgui.GButton) && ii.obj.selected || !ii.obj && ii.selected) {
  5193. if (this._loop)
  5194. return i % this._numItems;
  5195. else
  5196. return i;
  5197. }
  5198. }
  5199. }
  5200. else {
  5201. var cnt = this._children.length;
  5202. for (i = 0; i < cnt; i++) {
  5203. var obj = this._children[i];
  5204. if ((obj instanceof fgui.GButton) && obj.selected)
  5205. return i;
  5206. }
  5207. }
  5208. return -1;
  5209. },
  5210. set: function (value) {
  5211. if (value >= 0 && value < this.numItems) {
  5212. if (this._selectionMode != fgui.ListSelectionMode.Single)
  5213. this.clearSelection();
  5214. this.addSelection(value);
  5215. }
  5216. else
  5217. this.clearSelection();
  5218. },
  5219. enumerable: false,
  5220. configurable: true
  5221. });
  5222. GList.prototype.getSelection = function (result) {
  5223. if (!result)
  5224. result = new Array();
  5225. var i;
  5226. if (this._virtual) {
  5227. for (i = 0; i < this._realNumItems; i++) {
  5228. var ii = this._virtualItems[i];
  5229. if ((ii.obj instanceof fgui.GButton) && ii.obj.selected || !ii.obj && ii.selected) {
  5230. var j = i;
  5231. if (this._loop) {
  5232. j = i % this._numItems;
  5233. if (result.indexOf(j) != -1)
  5234. continue;
  5235. }
  5236. result.push(j);
  5237. }
  5238. }
  5239. }
  5240. else {
  5241. var cnt = this._children.length;
  5242. for (i = 0; i < cnt; i++) {
  5243. var obj = this._children[i];
  5244. if ((obj instanceof fgui.GButton) && obj.selected)
  5245. result.push(i);
  5246. }
  5247. }
  5248. return result;
  5249. };
  5250. GList.prototype.addSelection = function (index, scrollItToView) {
  5251. if (this._selectionMode == fgui.ListSelectionMode.None)
  5252. return;
  5253. this.checkVirtualList();
  5254. if (this._selectionMode == fgui.ListSelectionMode.Single)
  5255. this.clearSelection();
  5256. if (scrollItToView)
  5257. this.scrollToView(index);
  5258. this._lastSelectedIndex = index;
  5259. var obj;
  5260. if (this._virtual) {
  5261. var ii = this._virtualItems[index];
  5262. if (ii.obj)
  5263. obj = ii.obj;
  5264. ii.selected = true;
  5265. }
  5266. else
  5267. obj = this.getChildAt(index);
  5268. if ((obj instanceof fgui.GButton) && !obj.selected) {
  5269. obj.selected = true;
  5270. this.updateSelectionController(index);
  5271. }
  5272. };
  5273. GList.prototype.removeSelection = function (index) {
  5274. if (this._selectionMode == fgui.ListSelectionMode.None)
  5275. return;
  5276. var obj;
  5277. if (this._virtual) {
  5278. var ii = this._virtualItems[index];
  5279. if (ii.obj)
  5280. obj = ii.obj;
  5281. ii.selected = false;
  5282. }
  5283. else
  5284. obj = this.getChildAt(index);
  5285. if (obj instanceof fgui.GButton)
  5286. obj.selected = false;
  5287. };
  5288. GList.prototype.clearSelection = function () {
  5289. var i;
  5290. if (this._virtual) {
  5291. for (i = 0; i < this._realNumItems; i++) {
  5292. var ii = this._virtualItems[i];
  5293. if (ii.obj instanceof fgui.GButton)
  5294. ii.obj.selected = false;
  5295. ii.selected = false;
  5296. }
  5297. }
  5298. else {
  5299. var cnt = this._children.length;
  5300. for (i = 0; i < cnt; i++) {
  5301. var obj = this._children[i];
  5302. if (obj instanceof fgui.GButton)
  5303. obj.selected = false;
  5304. }
  5305. }
  5306. };
  5307. GList.prototype.clearSelectionExcept = function (g) {
  5308. var i;
  5309. if (this._virtual) {
  5310. for (i = 0; i < this._realNumItems; i++) {
  5311. var ii = this._virtualItems[i];
  5312. if (ii.obj != g) {
  5313. if (ii.obj instanceof fgui.GButton)
  5314. ii.obj.selected = false;
  5315. ii.selected = false;
  5316. }
  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) && obj != g)
  5324. obj.selected = false;
  5325. }
  5326. }
  5327. };
  5328. GList.prototype.selectAll = function () {
  5329. this.checkVirtualList();
  5330. var last = -1;
  5331. var i;
  5332. if (this._virtual) {
  5333. for (i = 0; i < this._realNumItems; i++) {
  5334. var ii = this._virtualItems[i];
  5335. if ((ii.obj instanceof fgui.GButton) && !ii.obj.selected) {
  5336. ii.obj.selected = true;
  5337. last = i;
  5338. }
  5339. ii.selected = true;
  5340. }
  5341. }
  5342. else {
  5343. var cnt = this._children.length;
  5344. for (i = 0; i < cnt; i++) {
  5345. var obj = this._children[i];
  5346. if ((obj instanceof fgui.GButton) && !obj.selected) {
  5347. obj.selected = true;
  5348. last = i;
  5349. }
  5350. }
  5351. }
  5352. if (last != -1)
  5353. this.updateSelectionController(last);
  5354. };
  5355. GList.prototype.selectNone = function () {
  5356. this.clearSelection();
  5357. };
  5358. GList.prototype.selectReverse = function () {
  5359. this.checkVirtualList();
  5360. var last = -1;
  5361. var i;
  5362. if (this._virtual) {
  5363. for (i = 0; i < this._realNumItems; i++) {
  5364. var ii = this._virtualItems[i];
  5365. if (ii.obj instanceof fgui.GButton) {
  5366. ii.obj.selected = !ii.obj.selected;
  5367. if (ii.obj.selected)
  5368. last = i;
  5369. }
  5370. ii.selected = !ii.selected;
  5371. }
  5372. }
  5373. else {
  5374. var cnt = this._children.length;
  5375. for (i = 0; i < cnt; i++) {
  5376. var obj = this._children[i];
  5377. if (obj instanceof fgui.GButton) {
  5378. obj.selected = !obj.selected;
  5379. if (obj.selected)
  5380. last = i;
  5381. }
  5382. }
  5383. }
  5384. if (last != -1)
  5385. this.updateSelectionController(last);
  5386. };
  5387. GList.prototype.handleArrowKey = function (dir) {
  5388. var index = this.selectedIndex;
  5389. if (index == -1)
  5390. return;
  5391. switch (dir) {
  5392. case 1:
  5393. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowVertical) {
  5394. index--;
  5395. if (index >= 0) {
  5396. this.clearSelection();
  5397. this.addSelection(index, true);
  5398. }
  5399. }
  5400. else if (this._layout == fgui.ListLayoutType.FlowHorizontal || this._layout == fgui.ListLayoutType.Pagination) {
  5401. var current = this._children[index];
  5402. var k = 0;
  5403. for (var i = index - 1; i >= 0; i--) {
  5404. var obj = this._children[i];
  5405. if (obj.y != current.y) {
  5406. current = obj;
  5407. break;
  5408. }
  5409. k++;
  5410. }
  5411. for (; i >= 0; i--) {
  5412. obj = this._children[i];
  5413. if (obj.y != current.y) {
  5414. this.clearSelection();
  5415. this.addSelection(i + k + 1, true);
  5416. break;
  5417. }
  5418. }
  5419. }
  5420. break;
  5421. case 3:
  5422. if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowHorizontal || this._layout == fgui.ListLayoutType.Pagination) {
  5423. index++;
  5424. if (index < this._children.length) {
  5425. this.clearSelection();
  5426. this.addSelection(index, true);
  5427. }
  5428. }
  5429. else if (this._layout == fgui.ListLayoutType.FlowVertical) {
  5430. current = this._children[index];
  5431. k = 0;
  5432. var cnt = this._children.length;
  5433. for (i = index + 1; i < cnt; i++) {
  5434. obj = this._children[i];
  5435. if (obj.x != current.x) {
  5436. current = obj;
  5437. break;
  5438. }
  5439. k++;
  5440. }
  5441. for (; i < cnt; i++) {
  5442. obj = this._children[i];
  5443. if (obj.x != current.x) {
  5444. this.clearSelection();
  5445. this.addSelection(i - k - 1, true);
  5446. break;
  5447. }
  5448. }
  5449. }
  5450. break;
  5451. case 5:
  5452. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowVertical) {
  5453. index++;
  5454. if (index < this._children.length) {
  5455. this.clearSelection();
  5456. this.addSelection(index, true);
  5457. }
  5458. }
  5459. else if (this._layout == fgui.ListLayoutType.FlowHorizontal || this._layout == fgui.ListLayoutType.Pagination) {
  5460. current = this._children[index];
  5461. k = 0;
  5462. cnt = this._children.length;
  5463. for (i = index + 1; i < cnt; i++) {
  5464. obj = this._children[i];
  5465. if (obj.y != current.y) {
  5466. current = obj;
  5467. break;
  5468. }
  5469. k++;
  5470. }
  5471. for (; i < cnt; i++) {
  5472. obj = this._children[i];
  5473. if (obj.y != current.y) {
  5474. this.clearSelection();
  5475. this.addSelection(i - k - 1, true);
  5476. break;
  5477. }
  5478. }
  5479. }
  5480. break;
  5481. case 7:
  5482. if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowHorizontal || this._layout == fgui.ListLayoutType.Pagination) {
  5483. index--;
  5484. if (index >= 0) {
  5485. this.clearSelection();
  5486. this.addSelection(index, true);
  5487. }
  5488. }
  5489. else if (this._layout == fgui.ListLayoutType.FlowVertical) {
  5490. current = this._children[index];
  5491. k = 0;
  5492. for (i = index - 1; i >= 0; i--) {
  5493. obj = this._children[i];
  5494. if (obj.x != current.x) {
  5495. current = obj;
  5496. break;
  5497. }
  5498. k++;
  5499. }
  5500. for (; i >= 0; i--) {
  5501. obj = this._children[i];
  5502. if (obj.x != current.x) {
  5503. this.clearSelection();
  5504. this.addSelection(i + k + 1, true);
  5505. break;
  5506. }
  5507. }
  5508. }
  5509. break;
  5510. }
  5511. };
  5512. GList.prototype.onClickItem = function (evt) {
  5513. if (this._scrollPane && this._scrollPane.isDragged)
  5514. return;
  5515. var item = fgui.GObject.cast(evt.currentTarget);
  5516. this.setSelectionOnEvent(item, evt);
  5517. if (this._scrollPane && this.scrollItemToViewOnClick)
  5518. this._scrollPane.scrollToView(item, true);
  5519. this.dispatchItemEvent(item, evt);
  5520. };
  5521. GList.prototype.dispatchItemEvent = function (item, evt) {
  5522. this._node.emit(fgui.Event.CLICK_ITEM, item, evt);
  5523. };
  5524. GList.prototype.setSelectionOnEvent = function (item, evt) {
  5525. if (!(item instanceof fgui.GButton) || this._selectionMode == fgui.ListSelectionMode.None)
  5526. return;
  5527. var dontChangeLastIndex = false;
  5528. var index = this.childIndexToItemIndex(this.getChildIndex(item));
  5529. if (this._selectionMode == fgui.ListSelectionMode.Single) {
  5530. if (!item.selected) {
  5531. this.clearSelectionExcept(item);
  5532. item.selected = true;
  5533. }
  5534. }
  5535. else {
  5536. if (evt.isShiftDown) {
  5537. if (!item.selected) {
  5538. if (this._lastSelectedIndex != -1) {
  5539. var min = Math.min(this._lastSelectedIndex, index);
  5540. var max = Math.max(this._lastSelectedIndex, index);
  5541. max = Math.min(max, this.numItems - 1);
  5542. var i;
  5543. if (this._virtual) {
  5544. for (i = min; i <= max; i++) {
  5545. var ii = this._virtualItems[i];
  5546. if (ii.obj instanceof fgui.GButton)
  5547. ii.obj.selected = true;
  5548. ii.selected = true;
  5549. }
  5550. }
  5551. else {
  5552. for (i = min; i <= max; i++) {
  5553. var obj = this.getChildAt(i);
  5554. if (obj instanceof fgui.GButton)
  5555. obj.selected = true;
  5556. }
  5557. }
  5558. dontChangeLastIndex = true;
  5559. }
  5560. else {
  5561. item.selected = true;
  5562. }
  5563. }
  5564. }
  5565. else if (evt.isCtrlDown || this._selectionMode == fgui.ListSelectionMode.Multiple_SingleClick) {
  5566. item.selected = !item.selected;
  5567. }
  5568. else {
  5569. if (!item.selected) {
  5570. this.clearSelectionExcept(item);
  5571. item.selected = true;
  5572. }
  5573. else
  5574. this.clearSelectionExcept(item);
  5575. }
  5576. }
  5577. if (!dontChangeLastIndex)
  5578. this._lastSelectedIndex = index;
  5579. if (item.selected)
  5580. this.updateSelectionController(index);
  5581. };
  5582. GList.prototype.resizeToFit = function (itemCount, minSize) {
  5583. if (itemCount === void 0) { itemCount = Number.POSITIVE_INFINITY; }
  5584. if (minSize === void 0) { minSize = 0; }
  5585. this.ensureBoundsCorrect();
  5586. var curCount = this.numItems;
  5587. if (itemCount > curCount)
  5588. itemCount = curCount;
  5589. if (this._virtual) {
  5590. var lineCount = Math.ceil(itemCount / this._curLineItemCount);
  5591. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal)
  5592. this.viewHeight = lineCount * this._itemSize.height + Math.max(0, lineCount - 1) * this._lineGap;
  5593. else
  5594. this.viewWidth = lineCount * this._itemSize.width + Math.max(0, lineCount - 1) * this._columnGap;
  5595. }
  5596. else if (itemCount == 0) {
  5597. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal)
  5598. this.viewHeight = minSize;
  5599. else
  5600. this.viewWidth = minSize;
  5601. }
  5602. else {
  5603. var i = itemCount - 1;
  5604. var obj = null;
  5605. while (i >= 0) {
  5606. obj = this.getChildAt(i);
  5607. if (!this.foldInvisibleItems || obj.visible)
  5608. break;
  5609. i--;
  5610. }
  5611. if (i < 0) {
  5612. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal)
  5613. this.viewHeight = minSize;
  5614. else
  5615. this.viewWidth = minSize;
  5616. }
  5617. else {
  5618. var size = 0;
  5619. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5620. size = obj.y + obj.height;
  5621. if (size < minSize)
  5622. size = minSize;
  5623. this.viewHeight = size;
  5624. }
  5625. else {
  5626. size = obj.x + obj.width;
  5627. if (size < minSize)
  5628. size = minSize;
  5629. this.viewWidth = size;
  5630. }
  5631. }
  5632. }
  5633. };
  5634. GList.prototype.getMaxItemWidth = function () {
  5635. var cnt = this._children.length;
  5636. var max = 0;
  5637. for (var i = 0; i < cnt; i++) {
  5638. var child = this.getChildAt(i);
  5639. if (child.width > max)
  5640. max = child.width;
  5641. }
  5642. return max;
  5643. };
  5644. GList.prototype.handleSizeChanged = function () {
  5645. _super.prototype.handleSizeChanged.call(this);
  5646. this.setBoundsChangedFlag();
  5647. if (this._virtual)
  5648. this.setVirtualListChangedFlag(true);
  5649. };
  5650. GList.prototype.handleControllerChanged = function (c) {
  5651. _super.prototype.handleControllerChanged.call(this, c);
  5652. if (this._selectionController == c)
  5653. this.selectedIndex = c.selectedIndex;
  5654. };
  5655. GList.prototype.updateSelectionController = function (index) {
  5656. if (this._selectionController && !this._selectionController.changing
  5657. && index < this._selectionController.pageCount) {
  5658. var c = this._selectionController;
  5659. this._selectionController = null;
  5660. c.selectedIndex = index;
  5661. this._selectionController = c;
  5662. }
  5663. };
  5664. GList.prototype.getSnappingPosition = function (xValue, yValue, resultPoint) {
  5665. if (this._virtual) {
  5666. resultPoint = resultPoint || new cc.Vec2();
  5667. var saved;
  5668. var index;
  5669. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5670. saved = yValue;
  5671. s_n = yValue;
  5672. index = this.getIndexOnPos1(false);
  5673. yValue = s_n;
  5674. if (index < this._virtualItems.length && saved - yValue > this._virtualItems[index].height / 2 && index < this._realNumItems)
  5675. yValue += this._virtualItems[index].height + this._lineGap;
  5676. }
  5677. else if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowVertical) {
  5678. saved = xValue;
  5679. s_n = xValue;
  5680. index = this.getIndexOnPos2(false);
  5681. xValue = s_n;
  5682. if (index < this._virtualItems.length && saved - xValue > this._virtualItems[index].width / 2 && index < this._realNumItems)
  5683. xValue += this._virtualItems[index].width + this._columnGap;
  5684. }
  5685. else {
  5686. saved = xValue;
  5687. s_n = xValue;
  5688. index = this.getIndexOnPos3(false);
  5689. xValue = s_n;
  5690. if (index < this._virtualItems.length && saved - xValue > this._virtualItems[index].width / 2 && index < this._realNumItems)
  5691. xValue += this._virtualItems[index].width + this._columnGap;
  5692. }
  5693. resultPoint.x = xValue;
  5694. resultPoint.y = yValue;
  5695. return resultPoint;
  5696. }
  5697. else {
  5698. return _super.prototype.getSnappingPosition.call(this, xValue, yValue, resultPoint);
  5699. }
  5700. };
  5701. GList.prototype.scrollToView = function (index, ani, setFirst) {
  5702. if (this._virtual) {
  5703. if (this._numItems == 0)
  5704. return;
  5705. this.checkVirtualList();
  5706. if (index >= this._virtualItems.length)
  5707. throw "Invalid child index: " + index + ">" + this._virtualItems.length;
  5708. if (this._loop)
  5709. index = Math.floor(this._firstIndex / this._numItems) * this._numItems + index;
  5710. var rect;
  5711. var ii = this._virtualItems[index];
  5712. var pos = 0;
  5713. var i;
  5714. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5715. for (i = this._curLineItemCount - 1; i < index; i += this._curLineItemCount)
  5716. pos += this._virtualItems[i].height + this._lineGap;
  5717. rect = new cc.Rect(0, pos, this._itemSize.width, ii.height);
  5718. }
  5719. else if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowVertical) {
  5720. for (i = this._curLineItemCount - 1; i < index; i += this._curLineItemCount)
  5721. pos += this._virtualItems[i].width + this._columnGap;
  5722. rect = new cc.Rect(pos, 0, ii.width, this._itemSize.height);
  5723. }
  5724. else {
  5725. var page = index / (this._curLineItemCount * this._curLineItemCount2);
  5726. 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);
  5727. }
  5728. if (this._scrollPane)
  5729. this._scrollPane.scrollToView(rect, ani, setFirst);
  5730. }
  5731. else {
  5732. var obj = this.getChildAt(index);
  5733. if (obj) {
  5734. if (this._scrollPane)
  5735. this._scrollPane.scrollToView(obj, ani, setFirst);
  5736. else if (this.parent && this.parent.scrollPane)
  5737. this.parent.scrollPane.scrollToView(obj, ani, setFirst);
  5738. }
  5739. }
  5740. };
  5741. GList.prototype.getFirstChildInView = function () {
  5742. return this.childIndexToItemIndex(_super.prototype.getFirstChildInView.call(this));
  5743. };
  5744. GList.prototype.childIndexToItemIndex = function (index) {
  5745. if (!this._virtual)
  5746. return index;
  5747. if (this._layout == fgui.ListLayoutType.Pagination) {
  5748. for (var i = this._firstIndex; i < this._realNumItems; i++) {
  5749. if (this._virtualItems[i].obj) {
  5750. index--;
  5751. if (index < 0)
  5752. return i;
  5753. }
  5754. }
  5755. return index;
  5756. }
  5757. else {
  5758. index += this._firstIndex;
  5759. if (this._loop && this._numItems > 0)
  5760. index = index % this._numItems;
  5761. return index;
  5762. }
  5763. };
  5764. GList.prototype.itemIndexToChildIndex = function (index) {
  5765. if (!this._virtual)
  5766. return index;
  5767. if (this._layout == fgui.ListLayoutType.Pagination) {
  5768. return this.getChildIndex(this._virtualItems[index].obj);
  5769. }
  5770. else {
  5771. if (this._loop && this._numItems > 0) {
  5772. var j = this._firstIndex % this._numItems;
  5773. if (index >= j)
  5774. index = index - j;
  5775. else
  5776. index = this._numItems - j + index;
  5777. }
  5778. else
  5779. index -= this._firstIndex;
  5780. return index;
  5781. }
  5782. };
  5783. GList.prototype.setVirtual = function () {
  5784. this._setVirtual(false);
  5785. };
  5786. GList.prototype.setVirtualAndLoop = function () {
  5787. this._setVirtual(true);
  5788. };
  5789. GList.prototype._setVirtual = function (loop) {
  5790. if (!this._virtual) {
  5791. if (!this._scrollPane)
  5792. throw "Virtual list must be scrollable!";
  5793. if (loop) {
  5794. if (this._layout == fgui.ListLayoutType.FlowHorizontal || this._layout == fgui.ListLayoutType.FlowVertical)
  5795. throw "Loop list is not supported for FlowHorizontal or FlowVertical layout!";
  5796. this._scrollPane.bouncebackEffect = false;
  5797. }
  5798. this._virtual = true;
  5799. this._loop = loop;
  5800. this._virtualItems = new Array();
  5801. this.removeChildrenToPool();
  5802. if (this._itemSize == null) {
  5803. this._itemSize = new cc.Size(0, 0);
  5804. var obj = this.getFromPool(null);
  5805. if (!obj) {
  5806. throw "Virtual List must have a default list item resource.";
  5807. }
  5808. else {
  5809. this._itemSize.width = obj.width;
  5810. this._itemSize.height = obj.height;
  5811. }
  5812. this.returnToPool(obj);
  5813. }
  5814. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5815. this._scrollPane.scrollStep = this._itemSize.height;
  5816. if (this._loop)
  5817. this._scrollPane._loop = 2;
  5818. }
  5819. else {
  5820. this._scrollPane.scrollStep = this._itemSize.width;
  5821. if (this._loop)
  5822. this._scrollPane._loop = 1;
  5823. }
  5824. this._node.on(fgui.Event.SCROLL, this.__scrolled, this);
  5825. this.setVirtualListChangedFlag(true);
  5826. }
  5827. };
  5828. Object.defineProperty(GList.prototype, "numItems", {
  5829. get: function () {
  5830. if (this._virtual)
  5831. return this._numItems;
  5832. else
  5833. return this._children.length;
  5834. },
  5835. set: function (value) {
  5836. if (this._virtual) {
  5837. if (this.itemRenderer == null)
  5838. throw "Set itemRenderer first!";
  5839. this._numItems = value;
  5840. if (this._loop)
  5841. this._realNumItems = this._numItems * 6;
  5842. else
  5843. this._realNumItems = this._numItems;
  5844. var oldCount = this._virtualItems.length;
  5845. if (this._realNumItems > oldCount) {
  5846. for (i = oldCount; i < this._realNumItems; i++) {
  5847. var ii = {
  5848. width: this._itemSize.width,
  5849. height: this._itemSize.height,
  5850. updateFlag: 0
  5851. };
  5852. this._virtualItems.push(ii);
  5853. }
  5854. }
  5855. else {
  5856. for (i = this._realNumItems; i < oldCount; i++)
  5857. this._virtualItems[i].selected = false;
  5858. }
  5859. if (this._virtualListChanged != 0)
  5860. this._partner.unschedule(this._refreshVirtualList);
  5861. this._refreshVirtualList();
  5862. }
  5863. else {
  5864. var cnt = this._children.length;
  5865. if (value > cnt) {
  5866. for (var i = cnt; i < value; i++) {
  5867. if (this.itemProvider == null)
  5868. this.addItemFromPool();
  5869. else
  5870. this.addItemFromPool(this.itemProvider(i));
  5871. }
  5872. }
  5873. else {
  5874. this.removeChildrenToPool(value, cnt);
  5875. }
  5876. if (this.itemRenderer != null) {
  5877. for (i = 0; i < value; i++)
  5878. this.itemRenderer(i, this.getChildAt(i));
  5879. }
  5880. }
  5881. },
  5882. enumerable: false,
  5883. configurable: true
  5884. });
  5885. GList.prototype.refreshVirtualList = function () {
  5886. this.setVirtualListChangedFlag(false);
  5887. };
  5888. GList.prototype.checkVirtualList = function () {
  5889. if (this._virtualListChanged != 0) {
  5890. this._refreshVirtualList();
  5891. this._partner.unschedule(this._refreshVirtualList);
  5892. }
  5893. };
  5894. GList.prototype.setVirtualListChangedFlag = function (layoutChanged) {
  5895. if (layoutChanged)
  5896. this._virtualListChanged = 2;
  5897. else if (this._virtualListChanged == 0)
  5898. this._virtualListChanged = 1;
  5899. this._partner.callLater(this._refreshVirtualList);
  5900. };
  5901. GList.prototype._refreshVirtualList = function (dt) {
  5902. if (!isNaN(dt)) {
  5903. var _t = (this.node["$gobj"]);
  5904. _t._refreshVirtualList();
  5905. return;
  5906. }
  5907. var layoutChanged = this._virtualListChanged == 2;
  5908. this._virtualListChanged = 0;
  5909. this._eventLocked = true;
  5910. if (layoutChanged) {
  5911. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.SingleRow)
  5912. this._curLineItemCount = 1;
  5913. else if (this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5914. if (this._columnCount > 0)
  5915. this._curLineItemCount = this._columnCount;
  5916. else {
  5917. this._curLineItemCount = Math.floor((this._scrollPane.viewWidth + this._columnGap) / (this._itemSize.width + this._columnGap));
  5918. if (this._curLineItemCount <= 0)
  5919. this._curLineItemCount = 1;
  5920. }
  5921. }
  5922. else if (this._layout == fgui.ListLayoutType.FlowVertical) {
  5923. if (this._lineCount > 0)
  5924. this._curLineItemCount = this._lineCount;
  5925. else {
  5926. this._curLineItemCount = Math.floor((this._scrollPane.viewHeight + this._lineGap) / (this._itemSize.height + this._lineGap));
  5927. if (this._curLineItemCount <= 0)
  5928. this._curLineItemCount = 1;
  5929. }
  5930. }
  5931. else {
  5932. if (this._columnCount > 0)
  5933. this._curLineItemCount = this._columnCount;
  5934. else {
  5935. this._curLineItemCount = Math.floor((this._scrollPane.viewWidth + this._columnGap) / (this._itemSize.width + this._columnGap));
  5936. if (this._curLineItemCount <= 0)
  5937. this._curLineItemCount = 1;
  5938. }
  5939. if (this._lineCount > 0)
  5940. this._curLineItemCount2 = this._lineCount;
  5941. else {
  5942. this._curLineItemCount2 = Math.floor((this._scrollPane.viewHeight + this._lineGap) / (this._itemSize.height + this._lineGap));
  5943. if (this._curLineItemCount2 <= 0)
  5944. this._curLineItemCount2 = 1;
  5945. }
  5946. }
  5947. }
  5948. var ch = 0, cw = 0;
  5949. if (this._realNumItems > 0) {
  5950. var i;
  5951. var len = Math.ceil(this._realNumItems / this._curLineItemCount) * this._curLineItemCount;
  5952. var len2 = Math.min(this._curLineItemCount, this._realNumItems);
  5953. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  5954. for (i = 0; i < len; i += this._curLineItemCount)
  5955. ch += this._virtualItems[i].height + this._lineGap;
  5956. if (ch > 0)
  5957. ch -= this._lineGap;
  5958. if (this._autoResizeItem)
  5959. cw = this._scrollPane.viewWidth;
  5960. else {
  5961. for (i = 0; i < len2; i++)
  5962. cw += this._virtualItems[i].width + this._columnGap;
  5963. if (cw > 0)
  5964. cw -= this._columnGap;
  5965. }
  5966. }
  5967. else if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowVertical) {
  5968. for (i = 0; i < len; i += this._curLineItemCount)
  5969. cw += this._virtualItems[i].width + this._columnGap;
  5970. if (cw > 0)
  5971. cw -= this._columnGap;
  5972. if (this._autoResizeItem)
  5973. ch = this._scrollPane.viewHeight;
  5974. else {
  5975. for (i = 0; i < len2; i++)
  5976. ch += this._virtualItems[i].height + this._lineGap;
  5977. if (ch > 0)
  5978. ch -= this._lineGap;
  5979. }
  5980. }
  5981. else {
  5982. var pageCount = Math.ceil(len / (this._curLineItemCount * this._curLineItemCount2));
  5983. cw = pageCount * this.viewWidth;
  5984. ch = this.viewHeight;
  5985. }
  5986. }
  5987. this.handleAlign(cw, ch);
  5988. this._scrollPane.setContentSize(cw, ch);
  5989. this._eventLocked = false;
  5990. this.handleScroll(true);
  5991. };
  5992. GList.prototype.__scrolled = function (evt) {
  5993. this.handleScroll(false);
  5994. };
  5995. GList.prototype.getIndexOnPos1 = function (forceUpdate) {
  5996. if (this._realNumItems < this._curLineItemCount) {
  5997. s_n = 0;
  5998. return 0;
  5999. }
  6000. var i;
  6001. var pos2;
  6002. var pos3;
  6003. if (this.numChildren > 0 && !forceUpdate) {
  6004. pos2 = this.getChildAt(0).y;
  6005. if (pos2 > s_n) {
  6006. for (i = this._firstIndex - this._curLineItemCount; i >= 0; i -= this._curLineItemCount) {
  6007. pos2 -= (this._virtualItems[i].height + this._lineGap);
  6008. if (pos2 <= s_n) {
  6009. s_n = pos2;
  6010. return i;
  6011. }
  6012. }
  6013. s_n = 0;
  6014. return 0;
  6015. }
  6016. else {
  6017. for (i = this._firstIndex; i < this._realNumItems; i += this._curLineItemCount) {
  6018. pos3 = pos2 + this._virtualItems[i].height + this._lineGap;
  6019. if (pos3 > s_n) {
  6020. s_n = pos2;
  6021. return i;
  6022. }
  6023. pos2 = pos3;
  6024. }
  6025. s_n = pos2;
  6026. return this._realNumItems - this._curLineItemCount;
  6027. }
  6028. }
  6029. else {
  6030. pos2 = 0;
  6031. for (i = 0; i < this._realNumItems; i += this._curLineItemCount) {
  6032. pos3 = pos2 + this._virtualItems[i].height + this._lineGap;
  6033. if (pos3 > s_n) {
  6034. s_n = pos2;
  6035. return i;
  6036. }
  6037. pos2 = pos3;
  6038. }
  6039. s_n = pos2;
  6040. return this._realNumItems - this._curLineItemCount;
  6041. }
  6042. };
  6043. GList.prototype.getIndexOnPos2 = function (forceUpdate) {
  6044. if (this._realNumItems < this._curLineItemCount) {
  6045. s_n = 0;
  6046. return 0;
  6047. }
  6048. var i;
  6049. var pos2;
  6050. var pos3;
  6051. if (this.numChildren > 0 && !forceUpdate) {
  6052. pos2 = this.getChildAt(0).x;
  6053. if (pos2 > s_n) {
  6054. for (i = this._firstIndex - this._curLineItemCount; i >= 0; i -= this._curLineItemCount) {
  6055. pos2 -= (this._virtualItems[i].width + this._columnGap);
  6056. if (pos2 <= s_n) {
  6057. s_n = pos2;
  6058. return i;
  6059. }
  6060. }
  6061. s_n = 0;
  6062. return 0;
  6063. }
  6064. else {
  6065. for (i = this._firstIndex; i < this._realNumItems; i += this._curLineItemCount) {
  6066. pos3 = pos2 + this._virtualItems[i].width + this._columnGap;
  6067. if (pos3 > s_n) {
  6068. s_n = pos2;
  6069. return i;
  6070. }
  6071. pos2 = pos3;
  6072. }
  6073. s_n = pos2;
  6074. return this._realNumItems - this._curLineItemCount;
  6075. }
  6076. }
  6077. else {
  6078. pos2 = 0;
  6079. for (i = 0; i < this._realNumItems; i += this._curLineItemCount) {
  6080. pos3 = pos2 + this._virtualItems[i].width + this._columnGap;
  6081. if (pos3 > s_n) {
  6082. s_n = pos2;
  6083. return i;
  6084. }
  6085. pos2 = pos3;
  6086. }
  6087. s_n = pos2;
  6088. return this._realNumItems - this._curLineItemCount;
  6089. }
  6090. };
  6091. GList.prototype.getIndexOnPos3 = function (forceUpdate) {
  6092. if (this._realNumItems < this._curLineItemCount) {
  6093. s_n = 0;
  6094. return 0;
  6095. }
  6096. var viewWidth = this.viewWidth;
  6097. var page = Math.floor(s_n / viewWidth);
  6098. var startIndex = page * (this._curLineItemCount * this._curLineItemCount2);
  6099. var pos2 = page * viewWidth;
  6100. var i;
  6101. var pos3;
  6102. for (i = 0; i < this._curLineItemCount; i++) {
  6103. pos3 = pos2 + this._virtualItems[startIndex + i].width + this._columnGap;
  6104. if (pos3 > s_n) {
  6105. s_n = pos2;
  6106. return startIndex + i;
  6107. }
  6108. pos2 = pos3;
  6109. }
  6110. s_n = pos2;
  6111. return startIndex + this._curLineItemCount - 1;
  6112. };
  6113. GList.prototype.handleScroll = function (forceUpdate) {
  6114. if (this._eventLocked)
  6115. return;
  6116. if (this._layout == fgui.ListLayoutType.SingleColumn || this._layout == fgui.ListLayoutType.FlowHorizontal) {
  6117. var enterCounter = 0;
  6118. while (this.handleScroll1(forceUpdate)) {
  6119. enterCounter++;
  6120. forceUpdate = false;
  6121. if (enterCounter > 20) {
  6122. console.log("FairyGUI: list will never be filled as the item renderer function always returns a different size.");
  6123. break;
  6124. }
  6125. }
  6126. this.handleArchOrder1();
  6127. }
  6128. else if (this._layout == fgui.ListLayoutType.SingleRow || this._layout == fgui.ListLayoutType.FlowVertical) {
  6129. enterCounter = 0;
  6130. while (this.handleScroll2(forceUpdate)) {
  6131. enterCounter++;
  6132. forceUpdate = false;
  6133. if (enterCounter > 20) {
  6134. console.log("FairyGUI: list will never be filled as the item renderer function always returns a different size.");
  6135. break;
  6136. }
  6137. }
  6138. this.handleArchOrder2();
  6139. }
  6140. else {
  6141. this.handleScroll3(forceUpdate);
  6142. }
  6143. this._boundsChanged = false;
  6144. };
  6145. GList.prototype.handleScroll1 = function (forceUpdate) {
  6146. var pos = this._scrollPane.scrollingPosY;
  6147. var max = pos + this._scrollPane.viewHeight;
  6148. var end = max == this._scrollPane.contentHeight;
  6149. s_n = pos;
  6150. var newFirstIndex = this.getIndexOnPos1(forceUpdate);
  6151. pos = s_n;
  6152. if (newFirstIndex == this._firstIndex && !forceUpdate) {
  6153. return false;
  6154. }
  6155. var oldFirstIndex = this._firstIndex;
  6156. this._firstIndex = newFirstIndex;
  6157. var curIndex = newFirstIndex;
  6158. var forward = oldFirstIndex > newFirstIndex;
  6159. var childCount = this.numChildren;
  6160. var lastIndex = oldFirstIndex + childCount - 1;
  6161. var reuseIndex = forward ? lastIndex : oldFirstIndex;
  6162. var curX = 0, curY = pos;
  6163. var needRender;
  6164. var deltaSize = 0;
  6165. var firstItemDeltaSize = 0;
  6166. var url = this.defaultItem;
  6167. var ii, ii2;
  6168. var i, j;
  6169. var partSize = (this._scrollPane.viewWidth - this._columnGap * (this._curLineItemCount - 1)) / this._curLineItemCount;
  6170. this.itemInfoVer++;
  6171. while (curIndex < this._realNumItems && (end || curY < max)) {
  6172. ii = this._virtualItems[curIndex];
  6173. if (!ii.obj || forceUpdate) {
  6174. if (this.itemProvider != null) {
  6175. url = this.itemProvider(curIndex % this._numItems);
  6176. if (url == null)
  6177. url = this._defaultItem;
  6178. url = fgui.UIPackage.normalizeURL(url);
  6179. }
  6180. if (ii.obj && ii.obj.resourceURL != url) {
  6181. if (ii.obj instanceof fgui.GButton)
  6182. ii.selected = ii.obj.selected;
  6183. this.removeChildToPool(ii.obj);
  6184. ii.obj = null;
  6185. }
  6186. }
  6187. if (!ii.obj) {
  6188. if (forward) {
  6189. for (j = reuseIndex; j >= oldFirstIndex; j--) {
  6190. ii2 = this._virtualItems[j];
  6191. if (ii2.obj && ii2.updateFlag != this.itemInfoVer && ii2.obj.resourceURL == url) {
  6192. if (ii2.obj instanceof fgui.GButton)
  6193. ii2.selected = ii2.obj.selected;
  6194. ii.obj = ii2.obj;
  6195. ii2.obj = null;
  6196. if (j == reuseIndex)
  6197. reuseIndex--;
  6198. break;
  6199. }
  6200. }
  6201. }
  6202. else {
  6203. for (j = reuseIndex; j <= lastIndex; j++) {
  6204. ii2 = this._virtualItems[j];
  6205. if (ii2.obj && ii2.updateFlag != this.itemInfoVer && ii2.obj.resourceURL == url) {
  6206. if (ii2.obj instanceof fgui.GButton)
  6207. ii2.selected = ii2.obj.selected;
  6208. ii.obj = ii2.obj;
  6209. ii2.obj = null;
  6210. if (j == reuseIndex)
  6211. reuseIndex++;
  6212. break;
  6213. }
  6214. }
  6215. }
  6216. if (ii.obj) {
  6217. this.setChildIndex(ii.obj, forward ? curIndex - newFirstIndex : this.numChildren);
  6218. }
  6219. else {
  6220. ii.obj = this._pool.getObject(url);
  6221. if (forward)
  6222. this.addChildAt(ii.obj, curIndex - newFirstIndex);
  6223. else
  6224. this.addChild(ii.obj);
  6225. }
  6226. if (ii.obj instanceof fgui.GButton)
  6227. ii.obj.selected = ii.selected;
  6228. needRender = true;
  6229. }
  6230. else
  6231. needRender = forceUpdate;
  6232. if (needRender) {
  6233. if (this._autoResizeItem && (this._layout == fgui.ListLayoutType.SingleColumn || this._columnCount > 0))
  6234. ii.obj.setSize(partSize, ii.obj.height, true);
  6235. this.itemRenderer(curIndex % this._numItems, ii.obj);
  6236. if (curIndex % this._curLineItemCount == 0) {
  6237. deltaSize += Math.ceil(ii.obj.height) - ii.height;
  6238. if (curIndex == newFirstIndex && oldFirstIndex > newFirstIndex) {
  6239. firstItemDeltaSize = Math.ceil(ii.obj.height) - ii.height;
  6240. }
  6241. }
  6242. ii.width = Math.ceil(ii.obj.width);
  6243. ii.height = Math.ceil(ii.obj.height);
  6244. }
  6245. ii.updateFlag = this.itemInfoVer;
  6246. ii.obj.setPosition(curX, curY);
  6247. if (curIndex == newFirstIndex)
  6248. max += ii.height;
  6249. curX += ii.width + this._columnGap;
  6250. if (curIndex % this._curLineItemCount == this._curLineItemCount - 1) {
  6251. curX = 0;
  6252. curY += ii.height + this._lineGap;
  6253. }
  6254. curIndex++;
  6255. }
  6256. for (i = 0; i < childCount; i++) {
  6257. ii = this._virtualItems[oldFirstIndex + i];
  6258. if (ii.updateFlag != this.itemInfoVer && ii.obj) {
  6259. if (ii.obj instanceof fgui.GButton)
  6260. ii.selected = ii.obj.selected;
  6261. this.removeChildToPool(ii.obj);
  6262. ii.obj = null;
  6263. }
  6264. }
  6265. childCount = this._children.length;
  6266. for (i = 0; i < childCount; i++) {
  6267. var obj = this._virtualItems[newFirstIndex + i].obj;
  6268. if (this._children[i] != obj)
  6269. this.setChildIndex(obj, i);
  6270. }
  6271. if (deltaSize != 0 || firstItemDeltaSize != 0)
  6272. this._scrollPane.changeContentSizeOnScrolling(0, deltaSize, 0, firstItemDeltaSize);
  6273. if (curIndex > 0 && this.numChildren > 0 && this._container.y <= 0 && this.getChildAt(0).y > -this._container.y)
  6274. return true;
  6275. else
  6276. return false;
  6277. };
  6278. GList.prototype.handleScroll2 = function (forceUpdate) {
  6279. var pos = this._scrollPane.scrollingPosX;
  6280. var max = pos + this._scrollPane.viewWidth;
  6281. var end = pos == this._scrollPane.contentWidth;
  6282. s_n = pos;
  6283. var newFirstIndex = this.getIndexOnPos2(forceUpdate);
  6284. pos = s_n;
  6285. if (newFirstIndex == this._firstIndex && !forceUpdate) {
  6286. return false;
  6287. }
  6288. var oldFirstIndex = this._firstIndex;
  6289. this._firstIndex = newFirstIndex;
  6290. var curIndex = newFirstIndex;
  6291. var forward = oldFirstIndex > newFirstIndex;
  6292. var childCount = this.numChildren;
  6293. var lastIndex = oldFirstIndex + childCount - 1;
  6294. var reuseIndex = forward ? lastIndex : oldFirstIndex;
  6295. var curX = pos, curY = 0;
  6296. var needRender;
  6297. var deltaSize = 0;
  6298. var firstItemDeltaSize = 0;
  6299. var url = this.defaultItem;
  6300. var ii, ii2;
  6301. var i, j;
  6302. var partSize = (this._scrollPane.viewHeight - this._lineGap * (this._curLineItemCount - 1)) / this._curLineItemCount;
  6303. this.itemInfoVer++;
  6304. while (curIndex < this._realNumItems && (end || curX < max)) {
  6305. ii = this._virtualItems[curIndex];
  6306. if (!ii.obj || forceUpdate) {
  6307. if (this.itemProvider != null) {
  6308. url = this.itemProvider(curIndex % this._numItems);
  6309. if (url == null)
  6310. url = this._defaultItem;
  6311. url = fgui.UIPackage.normalizeURL(url);
  6312. }
  6313. if (ii.obj && ii.obj.resourceURL != url) {
  6314. if (ii.obj instanceof fgui.GButton)
  6315. ii.selected = ii.obj.selected;
  6316. this.removeChildToPool(ii.obj);
  6317. ii.obj = null;
  6318. }
  6319. }
  6320. if (!ii.obj) {
  6321. if (forward) {
  6322. for (j = reuseIndex; j >= oldFirstIndex; j--) {
  6323. ii2 = this._virtualItems[j];
  6324. if (ii2.obj && ii2.updateFlag != this.itemInfoVer && ii2.obj.resourceURL == url) {
  6325. if (ii2.obj instanceof fgui.GButton)
  6326. ii2.selected = ii2.obj.selected;
  6327. ii.obj = ii2.obj;
  6328. ii2.obj = null;
  6329. if (j == reuseIndex)
  6330. reuseIndex--;
  6331. break;
  6332. }
  6333. }
  6334. }
  6335. else {
  6336. for (j = reuseIndex; j <= lastIndex; j++) {
  6337. ii2 = this._virtualItems[j];
  6338. if (ii2.obj && ii2.updateFlag != this.itemInfoVer && ii2.obj.resourceURL == url) {
  6339. if (ii2.obj instanceof fgui.GButton)
  6340. ii2.selected = ii2.obj.selected;
  6341. ii.obj = ii2.obj;
  6342. ii2.obj = null;
  6343. if (j == reuseIndex)
  6344. reuseIndex++;
  6345. break;
  6346. }
  6347. }
  6348. }
  6349. if (ii.obj) {
  6350. this.setChildIndex(ii.obj, forward ? curIndex - newFirstIndex : this.numChildren);
  6351. }
  6352. else {
  6353. ii.obj = this._pool.getObject(url);
  6354. if (forward)
  6355. this.addChildAt(ii.obj, curIndex - newFirstIndex);
  6356. else
  6357. this.addChild(ii.obj);
  6358. }
  6359. if (ii.obj instanceof fgui.GButton)
  6360. ii.obj.selected = ii.selected;
  6361. needRender = true;
  6362. }
  6363. else
  6364. needRender = forceUpdate;
  6365. if (needRender) {
  6366. if (this._autoResizeItem && (this._layout == fgui.ListLayoutType.SingleRow || this._lineCount > 0))
  6367. ii.obj.setSize(ii.obj.width, partSize, true);
  6368. this.itemRenderer(curIndex % this._numItems, ii.obj);
  6369. if (curIndex % this._curLineItemCount == 0) {
  6370. deltaSize += Math.ceil(ii.obj.width) - ii.width;
  6371. if (curIndex == newFirstIndex && oldFirstIndex > newFirstIndex) {
  6372. firstItemDeltaSize = Math.ceil(ii.obj.width) - ii.width;
  6373. }
  6374. }
  6375. ii.width = Math.ceil(ii.obj.width);
  6376. ii.height = Math.ceil(ii.obj.height);
  6377. }
  6378. ii.updateFlag = this.itemInfoVer;
  6379. ii.obj.setPosition(curX, curY);
  6380. if (curIndex == newFirstIndex)
  6381. max += ii.width;
  6382. curY += ii.height + this._lineGap;
  6383. if (curIndex % this._curLineItemCount == this._curLineItemCount - 1) {
  6384. curY = 0;
  6385. curX += ii.width + this._columnGap;
  6386. }
  6387. curIndex++;
  6388. }
  6389. for (i = 0; i < childCount; i++) {
  6390. ii = this._virtualItems[oldFirstIndex + i];
  6391. if (ii.updateFlag != this.itemInfoVer && ii.obj) {
  6392. if (ii.obj instanceof fgui.GButton)
  6393. ii.selected = ii.obj.selected;
  6394. this.removeChildToPool(ii.obj);
  6395. ii.obj = null;
  6396. }
  6397. }
  6398. childCount = this._children.length;
  6399. for (i = 0; i < childCount; i++) {
  6400. var obj = this._virtualItems[newFirstIndex + i].obj;
  6401. if (this._children[i] != obj)
  6402. this.setChildIndex(obj, i);
  6403. }
  6404. if (deltaSize != 0 || firstItemDeltaSize != 0)
  6405. this._scrollPane.changeContentSizeOnScrolling(deltaSize, 0, firstItemDeltaSize, 0);
  6406. if (curIndex > 0 && this.numChildren > 0 && this._container.x <= 0 && this.getChildAt(0).x > -this._container.x)
  6407. return true;
  6408. else
  6409. return false;
  6410. };
  6411. GList.prototype.handleScroll3 = function (forceUpdate) {
  6412. var pos = this._scrollPane.scrollingPosX;
  6413. s_n = pos;
  6414. var newFirstIndex = this.getIndexOnPos3(forceUpdate);
  6415. pos = s_n;
  6416. if (newFirstIndex == this._firstIndex && !forceUpdate)
  6417. return;
  6418. var oldFirstIndex = this._firstIndex;
  6419. this._firstIndex = newFirstIndex;
  6420. var reuseIndex = oldFirstIndex;
  6421. var virtualItemCount = this._virtualItems.length;
  6422. var pageSize = this._curLineItemCount * this._curLineItemCount2;
  6423. var startCol = newFirstIndex % this._curLineItemCount;
  6424. var viewWidth = this.viewWidth;
  6425. var page = Math.floor(newFirstIndex / pageSize);
  6426. var startIndex = page * pageSize;
  6427. var lastIndex = startIndex + pageSize * 2;
  6428. var needRender;
  6429. var i;
  6430. var ii, ii2;
  6431. var col;
  6432. var url = this._defaultItem;
  6433. var partWidth = (this._scrollPane.viewWidth - this._columnGap * (this._curLineItemCount - 1)) / this._curLineItemCount;
  6434. var partHeight = (this._scrollPane.viewHeight - this._lineGap * (this._curLineItemCount2 - 1)) / this._curLineItemCount2;
  6435. this.itemInfoVer++;
  6436. for (i = startIndex; i < lastIndex; i++) {
  6437. if (i >= this._realNumItems)
  6438. continue;
  6439. col = i % this._curLineItemCount;
  6440. if (i - startIndex < pageSize) {
  6441. if (col < startCol)
  6442. continue;
  6443. }
  6444. else {
  6445. if (col > startCol)
  6446. continue;
  6447. }
  6448. ii = this._virtualItems[i];
  6449. ii.updateFlag = this.itemInfoVer;
  6450. }
  6451. var lastObj = null;
  6452. var insertIndex = 0;
  6453. for (i = startIndex; i < lastIndex; i++) {
  6454. if (i >= this._realNumItems)
  6455. continue;
  6456. ii = this._virtualItems[i];
  6457. if (ii.updateFlag != this.itemInfoVer)
  6458. continue;
  6459. if (!ii.obj) {
  6460. while (reuseIndex < virtualItemCount) {
  6461. ii2 = this._virtualItems[reuseIndex];
  6462. if (ii2.obj && ii2.updateFlag != this.itemInfoVer) {
  6463. if (ii2.obj instanceof fgui.GButton)
  6464. ii2.selected = ii2.obj.selected;
  6465. ii.obj = ii2.obj;
  6466. ii2.obj = null;
  6467. break;
  6468. }
  6469. reuseIndex++;
  6470. }
  6471. if (insertIndex == -1)
  6472. insertIndex = this.getChildIndex(lastObj) + 1;
  6473. if (!ii.obj) {
  6474. if (this.itemProvider != null) {
  6475. url = this.itemProvider(i % this._numItems);
  6476. if (url == null)
  6477. url = this._defaultItem;
  6478. url = fgui.UIPackage.normalizeURL(url);
  6479. }
  6480. ii.obj = this._pool.getObject(url);
  6481. this.addChildAt(ii.obj, insertIndex);
  6482. }
  6483. else {
  6484. insertIndex = this.setChildIndexBefore(ii.obj, insertIndex);
  6485. }
  6486. insertIndex++;
  6487. if (ii.obj instanceof fgui.GButton)
  6488. ii.obj.selected = ii.selected;
  6489. needRender = true;
  6490. }
  6491. else {
  6492. needRender = forceUpdate;
  6493. insertIndex = -1;
  6494. lastObj = ii.obj;
  6495. }
  6496. if (needRender) {
  6497. if (this._autoResizeItem) {
  6498. if (this._curLineItemCount == this._columnCount && this._curLineItemCount2 == this._lineCount)
  6499. ii.obj.setSize(partWidth, partHeight, true);
  6500. else if (this._curLineItemCount == this._columnCount)
  6501. ii.obj.setSize(partWidth, ii.obj.height, true);
  6502. else if (this._curLineItemCount2 == this._lineCount)
  6503. ii.obj.setSize(ii.obj.width, partHeight, true);
  6504. }
  6505. this.itemRenderer(i % this._numItems, ii.obj);
  6506. ii.width = Math.ceil(ii.obj.width);
  6507. ii.height = Math.ceil(ii.obj.height);
  6508. }
  6509. }
  6510. var borderX = (startIndex / pageSize) * viewWidth;
  6511. var xx = borderX;
  6512. var yy = 0;
  6513. var lineHeight = 0;
  6514. for (i = startIndex; i < lastIndex; i++) {
  6515. if (i >= this._realNumItems)
  6516. continue;
  6517. ii = this._virtualItems[i];
  6518. if (ii.updateFlag == this.itemInfoVer)
  6519. ii.obj.setPosition(xx, yy);
  6520. if (ii.height > lineHeight)
  6521. lineHeight = ii.height;
  6522. if (i % this._curLineItemCount == this._curLineItemCount - 1) {
  6523. xx = borderX;
  6524. yy += lineHeight + this._lineGap;
  6525. lineHeight = 0;
  6526. if (i == startIndex + pageSize - 1) {
  6527. borderX += viewWidth;
  6528. xx = borderX;
  6529. yy = 0;
  6530. }
  6531. }
  6532. else
  6533. xx += ii.width + this._columnGap;
  6534. }
  6535. for (i = reuseIndex; i < virtualItemCount; i++) {
  6536. ii = this._virtualItems[i];
  6537. if (ii.updateFlag != this.itemInfoVer && ii.obj) {
  6538. if (ii.obj instanceof fgui.GButton)
  6539. ii.selected = ii.obj.selected;
  6540. this.removeChildToPool(ii.obj);
  6541. ii.obj = null;
  6542. }
  6543. }
  6544. };
  6545. GList.prototype.handleArchOrder1 = function () {
  6546. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Arch) {
  6547. var mid = this._scrollPane.posY + this.viewHeight / 2;
  6548. var minDist = Number.POSITIVE_INFINITY;
  6549. var dist = 0;
  6550. var apexIndex = 0;
  6551. var cnt = this.numChildren;
  6552. for (var i = 0; i < cnt; i++) {
  6553. var obj = this.getChildAt(i);
  6554. if (!this.foldInvisibleItems || obj.visible) {
  6555. dist = Math.abs(mid - obj.y - obj.height / 2);
  6556. if (dist < minDist) {
  6557. minDist = dist;
  6558. apexIndex = i;
  6559. }
  6560. }
  6561. }
  6562. this.apexIndex = apexIndex;
  6563. }
  6564. };
  6565. GList.prototype.handleArchOrder2 = function () {
  6566. if (this._childrenRenderOrder == fgui.ChildrenRenderOrder.Arch) {
  6567. var mid = this._scrollPane.posX + this.viewWidth / 2;
  6568. var minDist = Number.POSITIVE_INFINITY;
  6569. var dist = 0;
  6570. var apexIndex = 0;
  6571. var cnt = this.numChildren;
  6572. for (var i = 0; i < cnt; i++) {
  6573. var obj = this.getChildAt(i);
  6574. if (!this.foldInvisibleItems || obj.visible) {
  6575. dist = Math.abs(mid - obj.x - obj.width / 2);
  6576. if (dist < minDist) {
  6577. minDist = dist;
  6578. apexIndex = i;
  6579. }
  6580. }
  6581. }
  6582. this.apexIndex = apexIndex;
  6583. }
  6584. };
  6585. GList.prototype.handleAlign = function (contentWidth, contentHeight) {
  6586. var newOffsetX = 0;
  6587. var newOffsetY = 0;
  6588. if (contentHeight < this.viewHeight) {
  6589. if (this._verticalAlign == fgui.VertAlignType.Middle)
  6590. newOffsetY = Math.floor((this.viewHeight - contentHeight) / 2);
  6591. else if (this._verticalAlign == fgui.VertAlignType.Bottom)
  6592. newOffsetY = this.viewHeight - contentHeight;
  6593. }
  6594. if (contentWidth < this.viewWidth) {
  6595. if (this._align == fgui.AlignType.Center)
  6596. newOffsetX = Math.floor((this.viewWidth - contentWidth) / 2);
  6597. else if (this._align == fgui.AlignType.Right)
  6598. newOffsetX = this.viewWidth - contentWidth;
  6599. }
  6600. if (newOffsetX != this._alignOffset.x || newOffsetY != this._alignOffset.y) {
  6601. this._alignOffset.x = newOffsetX;
  6602. this._alignOffset.y = newOffsetY;
  6603. if (this._scrollPane)
  6604. this._scrollPane.adjustMaskContainer();
  6605. else
  6606. this._container.setPosition(this._pivotCorrectX + this._alignOffset.x, this._pivotCorrectY - this._alignOffset.y);
  6607. }
  6608. };
  6609. GList.prototype.updateBounds = function () {
  6610. if (this._virtual)
  6611. return;
  6612. var i;
  6613. var child;
  6614. var curX = 0;
  6615. var curY = 0;
  6616. var maxWidth = 0;
  6617. var maxHeight = 0;
  6618. var cw = 0, ch = 0;
  6619. var j = 0;
  6620. var page = 0;
  6621. var k = 0;
  6622. var cnt = this._children.length;
  6623. var viewWidth = this.viewWidth;
  6624. var viewHeight = this.viewHeight;
  6625. var lineSize = 0;
  6626. var lineStart = 0;
  6627. var ratio = 0;
  6628. if (this._layout == fgui.ListLayoutType.SingleColumn) {
  6629. for (i = 0; i < cnt; i++) {
  6630. child = this.getChildAt(i);
  6631. if (this.foldInvisibleItems && !child.visible)
  6632. continue;
  6633. if (curY != 0)
  6634. curY += this._lineGap;
  6635. child.y = curY;
  6636. if (this._autoResizeItem)
  6637. child.setSize(viewWidth, child.height, true);
  6638. curY += Math.ceil(child.height);
  6639. if (child.width > maxWidth)
  6640. maxWidth = child.width;
  6641. }
  6642. ch = curY;
  6643. if (ch <= viewHeight && this._autoResizeItem && this._scrollPane && this._scrollPane._displayInDemand && this._scrollPane.vtScrollBar) {
  6644. viewWidth += this._scrollPane.vtScrollBar.width;
  6645. for (i = 0; i < cnt; i++) {
  6646. child = this.getChildAt(i);
  6647. if (this.foldInvisibleItems && !child.visible)
  6648. continue;
  6649. child.setSize(viewWidth, child.height, true);
  6650. if (child.width > maxWidth)
  6651. maxWidth = child.width;
  6652. }
  6653. }
  6654. cw = Math.ceil(maxWidth);
  6655. }
  6656. else if (this._layout == fgui.ListLayoutType.SingleRow) {
  6657. for (i = 0; i < cnt; i++) {
  6658. child = this.getChildAt(i);
  6659. if (this.foldInvisibleItems && !child.visible)
  6660. continue;
  6661. if (curX != 0)
  6662. curX += this._columnGap;
  6663. child.x = curX;
  6664. if (this._autoResizeItem)
  6665. child.setSize(child.width, viewHeight, true);
  6666. curX += Math.ceil(child.width);
  6667. if (child.height > maxHeight)
  6668. maxHeight = child.height;
  6669. }
  6670. cw = curX;
  6671. if (cw <= viewWidth && this._autoResizeItem && this._scrollPane && this._scrollPane._displayInDemand && this._scrollPane.hzScrollBar) {
  6672. viewHeight += this._scrollPane.hzScrollBar.height;
  6673. for (i = 0; i < cnt; i++) {
  6674. child = this.getChildAt(i);
  6675. if (this.foldInvisibleItems && !child.visible)
  6676. continue;
  6677. child.setSize(child.width, viewHeight, true);
  6678. if (child.height > maxHeight)
  6679. maxHeight = child.height;
  6680. }
  6681. }
  6682. ch = Math.ceil(maxHeight);
  6683. }
  6684. else if (this._layout == fgui.ListLayoutType.FlowHorizontal) {
  6685. if (this._autoResizeItem && this._columnCount > 0) {
  6686. for (i = 0; i < cnt; i++) {
  6687. child = this.getChildAt(i);
  6688. if (this.foldInvisibleItems && !child.visible)
  6689. continue;
  6690. lineSize += child.sourceWidth;
  6691. j++;
  6692. if (j == this._columnCount || i == cnt - 1) {
  6693. ratio = (viewWidth - lineSize - (j - 1) * this._columnGap) / lineSize;
  6694. curX = 0;
  6695. for (j = lineStart; j <= i; j++) {
  6696. child = this.getChildAt(j);
  6697. if (this.foldInvisibleItems && !child.visible)
  6698. continue;
  6699. child.setPosition(curX, curY);
  6700. if (j < i) {
  6701. child.setSize(child.sourceWidth + Math.round(child.sourceWidth * ratio), child.height, true);
  6702. curX += Math.ceil(child.width) + this._columnGap;
  6703. }
  6704. else {
  6705. child.setSize(viewWidth - curX, child.height, true);
  6706. }
  6707. if (child.height > maxHeight)
  6708. maxHeight = child.height;
  6709. }
  6710. curY += Math.ceil(maxHeight) + this._lineGap;
  6711. maxHeight = 0;
  6712. j = 0;
  6713. lineStart = i + 1;
  6714. lineSize = 0;
  6715. }
  6716. }
  6717. ch = curY + Math.ceil(maxHeight);
  6718. cw = viewWidth;
  6719. }
  6720. else {
  6721. for (i = 0; i < cnt; i++) {
  6722. child = this.getChildAt(i);
  6723. if (this.foldInvisibleItems && !child.visible)
  6724. continue;
  6725. if (curX != 0)
  6726. curX += this._columnGap;
  6727. if (this._columnCount != 0 && j >= this._columnCount
  6728. || this._columnCount == 0 && curX + child.width > viewWidth && maxHeight != 0) {
  6729. curX = 0;
  6730. curY += Math.ceil(maxHeight) + this._lineGap;
  6731. maxHeight = 0;
  6732. j = 0;
  6733. }
  6734. child.setPosition(curX, curY);
  6735. curX += Math.ceil(child.width);
  6736. if (curX > maxWidth)
  6737. maxWidth = curX;
  6738. if (child.height > maxHeight)
  6739. maxHeight = child.height;
  6740. j++;
  6741. }
  6742. ch = curY + Math.ceil(maxHeight);
  6743. cw = Math.ceil(maxWidth);
  6744. }
  6745. }
  6746. else if (this._layout == fgui.ListLayoutType.FlowVertical) {
  6747. if (this._autoResizeItem && this._lineCount > 0) {
  6748. for (i = 0; i < cnt; i++) {
  6749. child = this.getChildAt(i);
  6750. if (this.foldInvisibleItems && !child.visible)
  6751. continue;
  6752. lineSize += child.sourceHeight;
  6753. j++;
  6754. if (j == this._lineCount || i == cnt - 1) {
  6755. ratio = (viewHeight - lineSize - (j - 1) * this._lineGap) / lineSize;
  6756. curY = 0;
  6757. for (j = lineStart; j <= i; j++) {
  6758. child = this.getChildAt(j);
  6759. if (this.foldInvisibleItems && !child.visible)
  6760. continue;
  6761. child.setPosition(curX, curY);
  6762. if (j < i) {
  6763. child.setSize(child.width, child.sourceHeight + Math.round(child.sourceHeight * ratio), true);
  6764. curY += Math.ceil(child.height) + this._lineGap;
  6765. }
  6766. else {
  6767. child.setSize(child.width, viewHeight - curY, true);
  6768. }
  6769. if (child.width > maxWidth)
  6770. maxWidth = child.width;
  6771. }
  6772. curX += Math.ceil(maxWidth) + this._columnGap;
  6773. maxWidth = 0;
  6774. j = 0;
  6775. lineStart = i + 1;
  6776. lineSize = 0;
  6777. }
  6778. }
  6779. cw = curX + Math.ceil(maxWidth);
  6780. ch = viewHeight;
  6781. }
  6782. else {
  6783. for (i = 0; i < cnt; i++) {
  6784. child = this.getChildAt(i);
  6785. if (this.foldInvisibleItems && !child.visible)
  6786. continue;
  6787. if (curY != 0)
  6788. curY += this._lineGap;
  6789. if (this._lineCount != 0 && j >= this._lineCount
  6790. || this._lineCount == 0 && curY + child.height > viewHeight && maxWidth != 0) {
  6791. curY = 0;
  6792. curX += Math.ceil(maxWidth) + this._columnGap;
  6793. maxWidth = 0;
  6794. j = 0;
  6795. }
  6796. child.setPosition(curX, curY);
  6797. curY += Math.ceil(child.height);
  6798. if (curY > maxHeight)
  6799. maxHeight = curY;
  6800. if (child.width > maxWidth)
  6801. maxWidth = child.width;
  6802. j++;
  6803. }
  6804. cw = curX + Math.ceil(maxWidth);
  6805. ch = Math.ceil(maxHeight);
  6806. }
  6807. }
  6808. else {
  6809. var eachHeight;
  6810. if (this._autoResizeItem && this._lineCount > 0)
  6811. eachHeight = Math.floor((viewHeight - (this._lineCount - 1) * this._lineGap) / this._lineCount);
  6812. if (this._autoResizeItem && this._columnCount > 0) {
  6813. for (i = 0; i < cnt; i++) {
  6814. child = this.getChildAt(i);
  6815. if (this.foldInvisibleItems && !child.visible)
  6816. continue;
  6817. if (j == 0 && (this._lineCount != 0 && k >= this._lineCount
  6818. || this._lineCount == 0 && curY + (this._lineCount > 0 ? eachHeight : child.height) > viewHeight)) {
  6819. page++;
  6820. curY = 0;
  6821. k = 0;
  6822. }
  6823. lineSize += child.sourceWidth;
  6824. j++;
  6825. if (j == this._columnCount || i == cnt - 1) {
  6826. ratio = (viewWidth - lineSize - (j - 1) * this._columnGap) / lineSize;
  6827. curX = 0;
  6828. for (j = lineStart; j <= i; j++) {
  6829. child = this.getChildAt(j);
  6830. if (this.foldInvisibleItems && !child.visible)
  6831. continue;
  6832. child.setPosition(page * viewWidth + curX, curY);
  6833. if (j < i) {
  6834. child.setSize(child.sourceWidth + Math.round(child.sourceWidth * ratio), this._lineCount > 0 ? eachHeight : child.height, true);
  6835. curX += Math.ceil(child.width) + this._columnGap;
  6836. }
  6837. else {
  6838. child.setSize(viewWidth - curX, this._lineCount > 0 ? eachHeight : child.height, true);
  6839. }
  6840. if (child.height > maxHeight)
  6841. maxHeight = child.height;
  6842. }
  6843. curY += Math.ceil(maxHeight) + this._lineGap;
  6844. maxHeight = 0;
  6845. j = 0;
  6846. lineStart = i + 1;
  6847. lineSize = 0;
  6848. k++;
  6849. }
  6850. }
  6851. }
  6852. else {
  6853. for (i = 0; i < cnt; i++) {
  6854. child = this.getChildAt(i);
  6855. if (this.foldInvisibleItems && !child.visible)
  6856. continue;
  6857. if (curX != 0)
  6858. curX += this._columnGap;
  6859. if (this._autoResizeItem && this._lineCount > 0)
  6860. child.setSize(child.width, eachHeight, true);
  6861. if (this._columnCount != 0 && j >= this._columnCount
  6862. || this._columnCount == 0 && curX + child.width > viewWidth && maxHeight != 0) {
  6863. curX = 0;
  6864. curY += Math.ceil(maxHeight) + this._lineGap;
  6865. maxHeight = 0;
  6866. j = 0;
  6867. k++;
  6868. if (this._lineCount != 0 && k >= this._lineCount
  6869. || this._lineCount == 0 && curY + child.height > viewHeight && maxWidth != 0) {
  6870. page++;
  6871. curY = 0;
  6872. k = 0;
  6873. }
  6874. }
  6875. child.setPosition(page * viewWidth + curX, curY);
  6876. curX += Math.ceil(child.width);
  6877. if (curX > maxWidth)
  6878. maxWidth = curX;
  6879. if (child.height > maxHeight)
  6880. maxHeight = child.height;
  6881. j++;
  6882. }
  6883. }
  6884. ch = page > 0 ? viewHeight : curY + Math.ceil(maxHeight);
  6885. cw = (page + 1) * viewWidth;
  6886. }
  6887. this.handleAlign(cw, ch);
  6888. this.setBounds(0, 0, cw, ch);
  6889. };
  6890. GList.prototype.setup_beforeAdd = function (buffer, beginPos) {
  6891. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  6892. buffer.seek(beginPos, 5);
  6893. this._layout = buffer.readByte();
  6894. this._selectionMode = buffer.readByte();
  6895. this._align = buffer.readByte();
  6896. this._verticalAlign = buffer.readByte();
  6897. this._lineGap = buffer.readShort();
  6898. this._columnGap = buffer.readShort();
  6899. this._lineCount = buffer.readShort();
  6900. this._columnCount = buffer.readShort();
  6901. this._autoResizeItem = buffer.readBool();
  6902. this._childrenRenderOrder = buffer.readByte();
  6903. this._apexIndex = buffer.readShort();
  6904. if (buffer.readBool()) {
  6905. this._margin.top = buffer.readInt();
  6906. this._margin.bottom = buffer.readInt();
  6907. this._margin.left = buffer.readInt();
  6908. this._margin.right = buffer.readInt();
  6909. }
  6910. var overflow = buffer.readByte();
  6911. if (overflow == fgui.OverflowType.Scroll) {
  6912. var savedPos = buffer.position;
  6913. buffer.seek(beginPos, 7);
  6914. this.setupScroll(buffer);
  6915. buffer.position = savedPos;
  6916. }
  6917. else
  6918. this.setupOverflow(overflow);
  6919. if (buffer.readBool())
  6920. buffer.skip(8);
  6921. if (buffer.version >= 2) {
  6922. this.scrollItemToViewOnClick = buffer.readBool();
  6923. this.foldInvisibleItems = buffer.readBool();
  6924. }
  6925. buffer.seek(beginPos, 8);
  6926. this._defaultItem = buffer.readS();
  6927. this.readItems(buffer);
  6928. };
  6929. GList.prototype.readItems = function (buffer) {
  6930. var cnt;
  6931. var i;
  6932. var nextPos;
  6933. var str;
  6934. cnt = buffer.readShort();
  6935. for (i = 0; i < cnt; i++) {
  6936. nextPos = buffer.readShort();
  6937. nextPos += buffer.position;
  6938. str = buffer.readS();
  6939. if (str == null) {
  6940. str = this.defaultItem;
  6941. if (!str) {
  6942. buffer.position = nextPos;
  6943. continue;
  6944. }
  6945. }
  6946. var obj = this.getFromPool(str);
  6947. if (obj) {
  6948. this.addChild(obj);
  6949. this.setupItem(buffer, obj);
  6950. }
  6951. buffer.position = nextPos;
  6952. }
  6953. };
  6954. GList.prototype.setupItem = function (buffer, obj) {
  6955. var str;
  6956. str = buffer.readS();
  6957. if (str != null)
  6958. obj.text = str;
  6959. str = buffer.readS();
  6960. if (str != null && (obj instanceof fgui.GButton))
  6961. obj.selectedTitle = str;
  6962. str = buffer.readS();
  6963. if (str != null)
  6964. obj.icon = str;
  6965. str = buffer.readS();
  6966. if (str != null && (obj instanceof fgui.GButton))
  6967. obj.selectedIcon = str;
  6968. str = buffer.readS();
  6969. if (str != null)
  6970. obj.name = str;
  6971. var cnt;
  6972. var i;
  6973. if (obj instanceof fgui.GComponent) {
  6974. cnt = buffer.readShort();
  6975. for (i = 0; i < cnt; i++) {
  6976. var cc = obj.getController(buffer.readS());
  6977. str = buffer.readS();
  6978. if (cc)
  6979. cc.selectedPageId = str;
  6980. }
  6981. if (buffer.version >= 2) {
  6982. cnt = buffer.readShort();
  6983. for (i = 0; i < cnt; i++) {
  6984. var target = buffer.readS();
  6985. var propertyId = buffer.readShort();
  6986. var value = buffer.readS();
  6987. var obj2 = obj.getChildByPath(target);
  6988. if (obj2)
  6989. obj2.setProp(propertyId, value);
  6990. }
  6991. }
  6992. }
  6993. };
  6994. GList.prototype.setup_afterAdd = function (buffer, beginPos) {
  6995. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  6996. buffer.seek(beginPos, 6);
  6997. var i = buffer.readShort();
  6998. if (i != -1)
  6999. this._selectionController = this.parent.getControllerAt(i);
  7000. };
  7001. return GList;
  7002. }(fgui.GComponent));
  7003. fgui.GList = GList;
  7004. var s_n = 0;
  7005. })(fgui || (fgui = {}));
  7006. (function (fgui) {
  7007. var GObjectPool = (function () {
  7008. function GObjectPool() {
  7009. this._count = 0;
  7010. this._pool = {};
  7011. }
  7012. GObjectPool.prototype.clear = function () {
  7013. for (var i1 in this._pool) {
  7014. var arr = this._pool[i1];
  7015. var cnt = arr.length;
  7016. for (var i = 0; i < cnt; i++)
  7017. arr[i].dispose();
  7018. }
  7019. this._pool = {};
  7020. this._count = 0;
  7021. };
  7022. Object.defineProperty(GObjectPool.prototype, "count", {
  7023. get: function () {
  7024. return this._count;
  7025. },
  7026. enumerable: false,
  7027. configurable: true
  7028. });
  7029. GObjectPool.prototype.getObject = function (url) {
  7030. url = fgui.UIPackage.normalizeURL(url);
  7031. if (url == null)
  7032. return null;
  7033. var arr = this._pool[url];
  7034. if (arr && arr.length) {
  7035. this._count--;
  7036. return arr.shift();
  7037. }
  7038. var child = fgui.UIPackage.createObjectFromURL(url);
  7039. return child;
  7040. };
  7041. GObjectPool.prototype.returnObject = function (obj) {
  7042. var url = obj.resourceURL;
  7043. if (!url)
  7044. return;
  7045. var arr = this._pool[url];
  7046. if (arr == null) {
  7047. arr = new Array();
  7048. this._pool[url] = arr;
  7049. }
  7050. this._count++;
  7051. arr.push(obj);
  7052. };
  7053. return GObjectPool;
  7054. }());
  7055. fgui.GObjectPool = GObjectPool;
  7056. })(fgui || (fgui = {}));
  7057. (function (fgui) {
  7058. var GLoader = (function (_super) {
  7059. __extends(GLoader, _super);
  7060. function GLoader() {
  7061. var _this = _super.call(this) || this;
  7062. _this._frame = 0;
  7063. _this._node.name = "GLoader";
  7064. _this._playing = true;
  7065. _this._url = "";
  7066. _this._fill = fgui.LoaderFillType.None;
  7067. _this._align = fgui.AlignType.Left;
  7068. _this._verticalAlign = fgui.VertAlignType.Top;
  7069. _this._showErrorSign = true;
  7070. _this._color = new cc.Color(255, 255, 255, 255);
  7071. _this._container = new cc.Node("Image");
  7072. _this._container.setAnchorPoint(0, 1);
  7073. _this._node.addChild(_this._container);
  7074. _this._content = _this._container.addComponent(fgui.MovieClip);
  7075. _this._content.sizeMode = cc.Sprite.SizeMode.CUSTOM;
  7076. _this._content.trim = false;
  7077. _this._content.setPlaySettings();
  7078. return _this;
  7079. }
  7080. GLoader.prototype.dispose = function () {
  7081. if (this._contentItem == null) {
  7082. if (this._content.spriteFrame)
  7083. this.freeExternal(this._content.spriteFrame);
  7084. }
  7085. if (this._content2)
  7086. this._content2.dispose();
  7087. _super.prototype.dispose.call(this);
  7088. };
  7089. Object.defineProperty(GLoader.prototype, "url", {
  7090. get: function () {
  7091. return this._url;
  7092. },
  7093. set: function (value) {
  7094. if (this._url == value)
  7095. return;
  7096. this._url = value;
  7097. this.loadContent();
  7098. this.updateGear(7);
  7099. },
  7100. enumerable: false,
  7101. configurable: true
  7102. });
  7103. Object.defineProperty(GLoader.prototype, "icon", {
  7104. get: function () {
  7105. return this._url;
  7106. },
  7107. set: function (value) {
  7108. this.url = value;
  7109. },
  7110. enumerable: false,
  7111. configurable: true
  7112. });
  7113. Object.defineProperty(GLoader.prototype, "align", {
  7114. get: function () {
  7115. return this._align;
  7116. },
  7117. set: function (value) {
  7118. if (this._align != value) {
  7119. this._align = value;
  7120. this.updateLayout();
  7121. }
  7122. },
  7123. enumerable: false,
  7124. configurable: true
  7125. });
  7126. Object.defineProperty(GLoader.prototype, "verticalAlign", {
  7127. get: function () {
  7128. return this._verticalAlign;
  7129. },
  7130. set: function (value) {
  7131. if (this._verticalAlign != value) {
  7132. this._verticalAlign = value;
  7133. this.updateLayout();
  7134. }
  7135. },
  7136. enumerable: false,
  7137. configurable: true
  7138. });
  7139. Object.defineProperty(GLoader.prototype, "fill", {
  7140. get: function () {
  7141. return this._fill;
  7142. },
  7143. set: function (value) {
  7144. if (this._fill != value) {
  7145. this._fill = value;
  7146. this.updateLayout();
  7147. }
  7148. },
  7149. enumerable: false,
  7150. configurable: true
  7151. });
  7152. Object.defineProperty(GLoader.prototype, "shrinkOnly", {
  7153. get: function () {
  7154. return this._shrinkOnly;
  7155. },
  7156. set: function (value) {
  7157. if (this._shrinkOnly != value) {
  7158. this._shrinkOnly = value;
  7159. this.updateLayout();
  7160. }
  7161. },
  7162. enumerable: false,
  7163. configurable: true
  7164. });
  7165. Object.defineProperty(GLoader.prototype, "autoSize", {
  7166. get: function () {
  7167. return this._autoSize;
  7168. },
  7169. set: function (value) {
  7170. if (this._autoSize != value) {
  7171. this._autoSize = value;
  7172. this.updateLayout();
  7173. }
  7174. },
  7175. enumerable: false,
  7176. configurable: true
  7177. });
  7178. Object.defineProperty(GLoader.prototype, "playing", {
  7179. get: function () {
  7180. return this._playing;
  7181. },
  7182. set: function (value) {
  7183. if (this._playing != value) {
  7184. this._playing = value;
  7185. if (this._content instanceof fgui.MovieClip)
  7186. this._content.playing = value;
  7187. this.updateGear(5);
  7188. }
  7189. },
  7190. enumerable: false,
  7191. configurable: true
  7192. });
  7193. Object.defineProperty(GLoader.prototype, "frame", {
  7194. get: function () {
  7195. return this._frame;
  7196. },
  7197. set: function (value) {
  7198. if (this._frame != value) {
  7199. this._frame = value;
  7200. if (this._content instanceof fgui.MovieClip)
  7201. this._content.frame = value;
  7202. this.updateGear(5);
  7203. }
  7204. },
  7205. enumerable: false,
  7206. configurable: true
  7207. });
  7208. Object.defineProperty(GLoader.prototype, "color", {
  7209. get: function () {
  7210. return this._color;
  7211. },
  7212. set: function (value) {
  7213. this._color.set(value);
  7214. this.updateGear(4);
  7215. this._container.color = value;
  7216. },
  7217. enumerable: false,
  7218. configurable: true
  7219. });
  7220. Object.defineProperty(GLoader.prototype, "fillMethod", {
  7221. get: function () {
  7222. return this._content.fillMethod;
  7223. },
  7224. set: function (value) {
  7225. this._content.fillMethod = value;
  7226. },
  7227. enumerable: false,
  7228. configurable: true
  7229. });
  7230. Object.defineProperty(GLoader.prototype, "fillOrigin", {
  7231. get: function () {
  7232. return this._content.fillOrigin;
  7233. },
  7234. set: function (value) {
  7235. this._content.fillOrigin = value;
  7236. },
  7237. enumerable: false,
  7238. configurable: true
  7239. });
  7240. Object.defineProperty(GLoader.prototype, "fillClockwise", {
  7241. get: function () {
  7242. return this._content.fillClockwise;
  7243. },
  7244. set: function (value) {
  7245. this._content.fillClockwise = value;
  7246. },
  7247. enumerable: false,
  7248. configurable: true
  7249. });
  7250. Object.defineProperty(GLoader.prototype, "fillAmount", {
  7251. get: function () {
  7252. return this._content.fillAmount;
  7253. },
  7254. set: function (value) {
  7255. this._content.fillAmount = value;
  7256. },
  7257. enumerable: false,
  7258. configurable: true
  7259. });
  7260. Object.defineProperty(GLoader.prototype, "showErrorSign", {
  7261. get: function () {
  7262. return this._showErrorSign;
  7263. },
  7264. set: function (value) {
  7265. this._showErrorSign = value;
  7266. },
  7267. enumerable: false,
  7268. configurable: true
  7269. });
  7270. Object.defineProperty(GLoader.prototype, "component", {
  7271. get: function () {
  7272. return this._content2;
  7273. },
  7274. enumerable: false,
  7275. configurable: true
  7276. });
  7277. Object.defineProperty(GLoader.prototype, "texture", {
  7278. get: function () {
  7279. return this._content.spriteFrame;
  7280. },
  7281. set: function (value) {
  7282. this.url = null;
  7283. this._content.spriteFrame = value;
  7284. this._content.type = cc.Sprite.Type.SIMPLE;
  7285. if (value != null) {
  7286. this.sourceWidth = value.getRect().width;
  7287. this.sourceHeight = value.getRect().height;
  7288. }
  7289. else {
  7290. this.sourceWidth = this.sourceHeight = 0;
  7291. }
  7292. this.updateLayout();
  7293. },
  7294. enumerable: false,
  7295. configurable: true
  7296. });
  7297. GLoader.prototype.loadContent = function () {
  7298. this.clearContent();
  7299. if (!this._url)
  7300. return;
  7301. if (fgui.ToolSet.startsWith(this._url, "ui://"))
  7302. this.loadFromPackage(this._url);
  7303. else
  7304. this.loadExternal();
  7305. };
  7306. GLoader.prototype.loadFromPackage = function (itemURL) {
  7307. this._contentItem = fgui.UIPackage.getItemByURL(itemURL);
  7308. if (this._contentItem) {
  7309. this._contentItem = this._contentItem.getBranch();
  7310. this.sourceWidth = this._contentItem.width;
  7311. this.sourceHeight = this._contentItem.height;
  7312. this._contentItem = this._contentItem.getHighResolution();
  7313. this._contentItem.load();
  7314. if (this._autoSize)
  7315. this.setSize(this.sourceWidth, this.sourceHeight);
  7316. if (this._contentItem.type == fgui.PackageItemType.Image) {
  7317. if (!this._contentItem.asset) {
  7318. this.setErrorState();
  7319. }
  7320. else {
  7321. this._content.spriteFrame = this._contentItem.asset;
  7322. if (this._content.fillMethod == 0) {
  7323. if (this._contentItem.scale9Grid)
  7324. this._content.type = cc.Sprite.Type.SLICED;
  7325. else if (this._contentItem.scaleByTile)
  7326. this._content.type = cc.Sprite.Type.TILED;
  7327. else
  7328. this._content.type = cc.Sprite.Type.SIMPLE;
  7329. }
  7330. this.updateLayout();
  7331. }
  7332. }
  7333. else if (this._contentItem.type == fgui.PackageItemType.MovieClip) {
  7334. this._content.interval = this._contentItem.interval;
  7335. this._content.swing = this._contentItem.swing;
  7336. this._content.repeatDelay = this._contentItem.repeatDelay;
  7337. this._content.frames = this._contentItem.frames;
  7338. this.updateLayout();
  7339. }
  7340. else if (this._contentItem.type == fgui.PackageItemType.Component) {
  7341. var obj = fgui.UIPackage.createObjectFromURL(itemURL);
  7342. if (!obj)
  7343. this.setErrorState();
  7344. else if (!(obj instanceof fgui.GComponent)) {
  7345. obj.dispose();
  7346. this.setErrorState();
  7347. }
  7348. else {
  7349. this._content2 = obj;
  7350. this._container.addChild(this._content2.node);
  7351. this.updateLayout();
  7352. }
  7353. }
  7354. else
  7355. this.setErrorState();
  7356. }
  7357. else
  7358. this.setErrorState();
  7359. };
  7360. GLoader.prototype.loadExternal = function () {
  7361. if (fgui.ToolSet.startsWith(this._url, "http://")
  7362. || fgui.ToolSet.startsWith(this._url, "https://")
  7363. || fgui.ToolSet.startsWith(this._url, '/'))
  7364. cc.assetManager.loadRemote(this._url, this.onLoaded.bind(this));
  7365. else
  7366. cc.resources.load(this._url, cc.Asset, this.onLoaded.bind(this));
  7367. };
  7368. GLoader.prototype.onLoaded = function (err, asset) {
  7369. if (!this._url || !cc.isValid(this._node))
  7370. return;
  7371. if (err)
  7372. console.warn(err);
  7373. if (asset instanceof cc.SpriteFrame)
  7374. this.onExternalLoadSuccess(asset);
  7375. else if (asset instanceof cc.Texture2D)
  7376. this.onExternalLoadSuccess(new cc.SpriteFrame(asset));
  7377. };
  7378. GLoader.prototype.freeExternal = function (texture) {
  7379. };
  7380. GLoader.prototype.onExternalLoadSuccess = function (texture) {
  7381. this._content.spriteFrame = texture;
  7382. this._content.type = cc.Sprite.Type.SIMPLE;
  7383. this.sourceWidth = texture.getRect().width;
  7384. this.sourceHeight = texture.getRect().height;
  7385. if (this._autoSize)
  7386. this.setSize(this.sourceWidth, this.sourceHeight);
  7387. this.updateLayout();
  7388. };
  7389. GLoader.prototype.onExternalLoadFailed = function () {
  7390. this.setErrorState();
  7391. };
  7392. GLoader.prototype.setErrorState = function () {
  7393. if (!this._showErrorSign)
  7394. return;
  7395. if (this._errorSign == null) {
  7396. if (fgui.UIConfig.loaderErrorSign != null) {
  7397. this._errorSign = GLoader._errorSignPool.getObject(fgui.UIConfig.loaderErrorSign);
  7398. }
  7399. }
  7400. if (this._errorSign) {
  7401. this._errorSign.setSize(this.width, this.height);
  7402. this._container.addChild(this._errorSign.node);
  7403. }
  7404. };
  7405. GLoader.prototype.clearErrorState = function () {
  7406. if (this._errorSign) {
  7407. this._container.removeChild(this._errorSign.node);
  7408. GLoader._errorSignPool.returnObject(this._errorSign);
  7409. this._errorSign = null;
  7410. }
  7411. };
  7412. GLoader.prototype.updateLayout = function () {
  7413. if (this._content2 == null && this._content == null) {
  7414. if (this._autoSize) {
  7415. this._updatingLayout = true;
  7416. this.setSize(50, 30);
  7417. this._updatingLayout = false;
  7418. }
  7419. return;
  7420. }
  7421. var cw = this.sourceWidth;
  7422. var ch = this.sourceHeight;
  7423. var pivotCorrectX = -this.pivotX * this._width;
  7424. var pivotCorrectY = this.pivotY * this._height;
  7425. if (this._autoSize) {
  7426. this._updatingLayout = true;
  7427. if (cw == 0)
  7428. cw = 50;
  7429. if (ch == 0)
  7430. ch = 30;
  7431. this.setSize(cw, ch);
  7432. this._updatingLayout = false;
  7433. this._container.setContentSize(this._width, this._height);
  7434. this._container.setPosition(pivotCorrectX, pivotCorrectY);
  7435. if (this._content2) {
  7436. this._content2.setPosition(pivotCorrectX + this._width * this.pivotX, pivotCorrectY - this._height * this.pivotY);
  7437. this._content2.setScale(1, 1);
  7438. }
  7439. if (cw == this._width && ch == this._height)
  7440. return;
  7441. }
  7442. var sx = 1, sy = 1;
  7443. if (this._fill != fgui.LoaderFillType.None) {
  7444. sx = this.width / this.sourceWidth;
  7445. sy = this.height / this.sourceHeight;
  7446. if (sx != 1 || sy != 1) {
  7447. if (this._fill == fgui.LoaderFillType.ScaleMatchHeight)
  7448. sx = sy;
  7449. else if (this._fill == fgui.LoaderFillType.ScaleMatchWidth)
  7450. sy = sx;
  7451. else if (this._fill == fgui.LoaderFillType.Scale) {
  7452. if (sx > sy)
  7453. sx = sy;
  7454. else
  7455. sy = sx;
  7456. }
  7457. else if (this._fill == fgui.LoaderFillType.ScaleNoBorder) {
  7458. if (sx > sy)
  7459. sy = sx;
  7460. else
  7461. sx = sy;
  7462. }
  7463. if (this._shrinkOnly) {
  7464. if (sx > 1)
  7465. sx = 1;
  7466. if (sy > 1)
  7467. sy = 1;
  7468. }
  7469. cw = this.sourceWidth * sx;
  7470. ch = this.sourceHeight * sy;
  7471. }
  7472. }
  7473. this._container.setContentSize(cw, ch);
  7474. if (this._content2) {
  7475. this._content2.setPosition(pivotCorrectX + this._width * this.pivotX, pivotCorrectY - this._height * this.pivotY);
  7476. this._content2.setScale(sx, sy);
  7477. }
  7478. var nx, ny;
  7479. if (this._align == fgui.AlignType.Left)
  7480. nx = 0;
  7481. else if (this._align == fgui.AlignType.Center)
  7482. nx = Math.floor((this._width - cw) / 2);
  7483. else
  7484. nx = this._width - cw;
  7485. if (this._verticalAlign == fgui.VertAlignType.Top)
  7486. ny = 0;
  7487. else if (this._verticalAlign == fgui.VertAlignType.Middle)
  7488. ny = Math.floor((this._height - ch) / 2);
  7489. else
  7490. ny = this._height - ch;
  7491. ny = -ny;
  7492. this._container.setPosition(pivotCorrectX + nx, pivotCorrectY + ny);
  7493. };
  7494. GLoader.prototype.clearContent = function () {
  7495. this.clearErrorState();
  7496. if (!this._contentItem) {
  7497. var texture = this._content.spriteFrame;
  7498. if (texture)
  7499. this.freeExternal(texture);
  7500. }
  7501. if (this._content2) {
  7502. this._container.removeChild(this._content2.node);
  7503. this._content2.dispose();
  7504. this._content2 = null;
  7505. }
  7506. this._content.frames = null;
  7507. this._content.spriteFrame = null;
  7508. this._contentItem = null;
  7509. };
  7510. GLoader.prototype.handleSizeChanged = function () {
  7511. _super.prototype.handleSizeChanged.call(this);
  7512. if (!this._updatingLayout)
  7513. this.updateLayout();
  7514. };
  7515. GLoader.prototype.handleAnchorChanged = function () {
  7516. _super.prototype.handleAnchorChanged.call(this);
  7517. if (!this._updatingLayout)
  7518. this.updateLayout();
  7519. };
  7520. GLoader.prototype.handleGrayedChanged = function () {
  7521. this._content.grayed = this._grayed;
  7522. };
  7523. GLoader.prototype._hitTest = function (pt, globalPt) {
  7524. if (this._content2) {
  7525. var obj = this._content2.hitTest(globalPt);
  7526. if (obj)
  7527. return obj;
  7528. }
  7529. if (pt.x >= 0 && pt.y >= 0 && pt.x < this._width && pt.y < this._height)
  7530. return this;
  7531. else
  7532. return null;
  7533. };
  7534. GLoader.prototype.getProp = function (index) {
  7535. switch (index) {
  7536. case fgui.ObjectPropID.Color:
  7537. return this.color;
  7538. case fgui.ObjectPropID.Playing:
  7539. return this.playing;
  7540. case fgui.ObjectPropID.Frame:
  7541. return this.frame;
  7542. case fgui.ObjectPropID.TimeScale:
  7543. return this._content.timeScale;
  7544. default:
  7545. return _super.prototype.getProp.call(this, index);
  7546. }
  7547. };
  7548. GLoader.prototype.setProp = function (index, value) {
  7549. switch (index) {
  7550. case fgui.ObjectPropID.Color:
  7551. this.color = value;
  7552. break;
  7553. case fgui.ObjectPropID.Playing:
  7554. this.playing = value;
  7555. break;
  7556. case fgui.ObjectPropID.Frame:
  7557. this.frame = value;
  7558. break;
  7559. case fgui.ObjectPropID.TimeScale:
  7560. this._content.timeScale = value;
  7561. break;
  7562. case fgui.ObjectPropID.DeltaTime:
  7563. this._content.advance(value);
  7564. break;
  7565. default:
  7566. _super.prototype.setProp.call(this, index, value);
  7567. break;
  7568. }
  7569. };
  7570. GLoader.prototype.setup_beforeAdd = function (buffer, beginPos) {
  7571. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  7572. buffer.seek(beginPos, 5);
  7573. this._url = buffer.readS();
  7574. this._align = buffer.readByte();
  7575. this._verticalAlign = buffer.readByte();
  7576. this._fill = buffer.readByte();
  7577. this._shrinkOnly = buffer.readBool();
  7578. this._autoSize = buffer.readBool();
  7579. this._showErrorSign = buffer.readBool();
  7580. this._playing = buffer.readBool();
  7581. this._frame = buffer.readInt();
  7582. if (buffer.readBool())
  7583. this.color = buffer.readColor();
  7584. this._content.fillMethod = buffer.readByte();
  7585. if (this._content.fillMethod != 0) {
  7586. this._content.fillOrigin = buffer.readByte();
  7587. this._content.fillClockwise = buffer.readBool();
  7588. this._content.fillAmount = buffer.readFloat();
  7589. }
  7590. if (this._url)
  7591. this.loadContent();
  7592. };
  7593. GLoader._errorSignPool = new fgui.GObjectPool();
  7594. return GLoader;
  7595. }(fgui.GObject));
  7596. fgui.GLoader = GLoader;
  7597. })(fgui || (fgui = {}));
  7598. (function (fgui) {
  7599. var GLoader3D = (function (_super) {
  7600. __extends(GLoader3D, _super);
  7601. function GLoader3D() {
  7602. var _this = _super.call(this) || this;
  7603. _this._frame = 0;
  7604. _this._node.name = "GLoader3D";
  7605. _this._playing = true;
  7606. _this._url = "";
  7607. _this._fill = fgui.LoaderFillType.None;
  7608. _this._align = fgui.AlignType.Left;
  7609. _this._verticalAlign = fgui.VertAlignType.Top;
  7610. _this._color = new cc.Color(255, 255, 255, 255);
  7611. _this._container = new cc.Node("Wrapper");
  7612. _this._container.setAnchorPoint(0, 1);
  7613. _this._node.addChild(_this._container);
  7614. return _this;
  7615. }
  7616. GLoader3D.prototype.dispose = function () {
  7617. _super.prototype.dispose.call(this);
  7618. };
  7619. Object.defineProperty(GLoader3D.prototype, "url", {
  7620. get: function () {
  7621. return this._url;
  7622. },
  7623. set: function (value) {
  7624. if (this._url == value)
  7625. return;
  7626. this._url = value;
  7627. this.loadContent();
  7628. this.updateGear(7);
  7629. },
  7630. enumerable: false,
  7631. configurable: true
  7632. });
  7633. Object.defineProperty(GLoader3D.prototype, "icon", {
  7634. get: function () {
  7635. return this._url;
  7636. },
  7637. set: function (value) {
  7638. this.url = value;
  7639. },
  7640. enumerable: false,
  7641. configurable: true
  7642. });
  7643. Object.defineProperty(GLoader3D.prototype, "align", {
  7644. get: function () {
  7645. return this._align;
  7646. },
  7647. set: function (value) {
  7648. if (this._align != value) {
  7649. this._align = value;
  7650. this.updateLayout();
  7651. }
  7652. },
  7653. enumerable: false,
  7654. configurable: true
  7655. });
  7656. Object.defineProperty(GLoader3D.prototype, "verticalAlign", {
  7657. get: function () {
  7658. return this._verticalAlign;
  7659. },
  7660. set: function (value) {
  7661. if (this._verticalAlign != value) {
  7662. this._verticalAlign = value;
  7663. this.updateLayout();
  7664. }
  7665. },
  7666. enumerable: false,
  7667. configurable: true
  7668. });
  7669. Object.defineProperty(GLoader3D.prototype, "fill", {
  7670. get: function () {
  7671. return this._fill;
  7672. },
  7673. set: function (value) {
  7674. if (this._fill != value) {
  7675. this._fill = value;
  7676. this.updateLayout();
  7677. }
  7678. },
  7679. enumerable: false,
  7680. configurable: true
  7681. });
  7682. Object.defineProperty(GLoader3D.prototype, "shrinkOnly", {
  7683. get: function () {
  7684. return this._shrinkOnly;
  7685. },
  7686. set: function (value) {
  7687. if (this._shrinkOnly != value) {
  7688. this._shrinkOnly = value;
  7689. this.updateLayout();
  7690. }
  7691. },
  7692. enumerable: false,
  7693. configurable: true
  7694. });
  7695. Object.defineProperty(GLoader3D.prototype, "autoSize", {
  7696. get: function () {
  7697. return this._autoSize;
  7698. },
  7699. set: function (value) {
  7700. if (this._autoSize != value) {
  7701. this._autoSize = value;
  7702. this.updateLayout();
  7703. }
  7704. },
  7705. enumerable: false,
  7706. configurable: true
  7707. });
  7708. Object.defineProperty(GLoader3D.prototype, "playing", {
  7709. get: function () {
  7710. return this._playing;
  7711. },
  7712. set: function (value) {
  7713. if (this._playing != value) {
  7714. this._playing = value;
  7715. this.updateGear(5);
  7716. this.onChange();
  7717. }
  7718. },
  7719. enumerable: false,
  7720. configurable: true
  7721. });
  7722. Object.defineProperty(GLoader3D.prototype, "frame", {
  7723. get: function () {
  7724. return this._frame;
  7725. },
  7726. set: function (value) {
  7727. if (this._frame != value) {
  7728. this._frame = value;
  7729. this.updateGear(5);
  7730. this.onChange();
  7731. }
  7732. },
  7733. enumerable: false,
  7734. configurable: true
  7735. });
  7736. Object.defineProperty(GLoader3D.prototype, "animationName", {
  7737. get: function () {
  7738. return this._animationName;
  7739. },
  7740. set: function (value) {
  7741. if (this._animationName != value) {
  7742. this._animationName = value;
  7743. this.onChange();
  7744. }
  7745. },
  7746. enumerable: false,
  7747. configurable: true
  7748. });
  7749. Object.defineProperty(GLoader3D.prototype, "skinName", {
  7750. get: function () {
  7751. return this._skinName;
  7752. },
  7753. set: function (value) {
  7754. if (this._skinName != value) {
  7755. this._skinName = value;
  7756. this.onChange();
  7757. }
  7758. },
  7759. enumerable: false,
  7760. configurable: true
  7761. });
  7762. Object.defineProperty(GLoader3D.prototype, "loop", {
  7763. get: function () {
  7764. return this._loop;
  7765. },
  7766. set: function (value) {
  7767. if (this._loop != value) {
  7768. this._loop = value;
  7769. this.onChange();
  7770. }
  7771. },
  7772. enumerable: false,
  7773. configurable: true
  7774. });
  7775. Object.defineProperty(GLoader3D.prototype, "color", {
  7776. get: function () {
  7777. return this._color;
  7778. },
  7779. set: function (value) {
  7780. this._color.set(value);
  7781. this.updateGear(4);
  7782. if (this._content)
  7783. this._content.node.color = value;
  7784. },
  7785. enumerable: false,
  7786. configurable: true
  7787. });
  7788. Object.defineProperty(GLoader3D.prototype, "content", {
  7789. get: function () {
  7790. return;
  7791. },
  7792. enumerable: false,
  7793. configurable: true
  7794. });
  7795. GLoader3D.prototype.loadContent = function () {
  7796. this.clearContent();
  7797. if (!this._url)
  7798. return;
  7799. if (fgui.ToolSet.startsWith(this._url, "ui://"))
  7800. this.loadFromPackage(this._url);
  7801. else
  7802. this.loadExternal();
  7803. };
  7804. GLoader3D.prototype.loadFromPackage = function (itemURL) {
  7805. this._contentItem = fgui.UIPackage.getItemByURL(itemURL);
  7806. if (this._contentItem) {
  7807. this._contentItem = this._contentItem.getBranch();
  7808. this.sourceWidth = this._contentItem.width;
  7809. this.sourceHeight = this._contentItem.height;
  7810. this._contentItem = this._contentItem.getHighResolution();
  7811. if (this._autoSize)
  7812. this.setSize(this.sourceWidth, this.sourceHeight);
  7813. if (this._contentItem.type == fgui.PackageItemType.Spine || this._contentItem.type == fgui.PackageItemType.DragonBones)
  7814. this._contentItem.owner.getItemAssetAsync(this._contentItem, this.onLoaded.bind(this));
  7815. }
  7816. };
  7817. GLoader3D.prototype.onLoaded = function (err, item) {
  7818. if (this._contentItem != item)
  7819. return;
  7820. if (err)
  7821. console.warn(err);
  7822. if (!this._contentItem.asset)
  7823. return;
  7824. if (this._contentItem.type == fgui.PackageItemType.Spine)
  7825. this.setSpine(this._contentItem.asset, this._contentItem.skeletonAnchor);
  7826. else if (this._contentItem.type == fgui.PackageItemType.DragonBones)
  7827. this.setDragonBones(this._contentItem.asset, this._contentItem.atlasAsset, this._contentItem.skeletonAnchor);
  7828. };
  7829. GLoader3D.prototype.setSpine = function (asset, anchor, pma) {
  7830. this.url = null;
  7831. this.clearContent();
  7832. var node = new cc.Node();
  7833. node.color = this._color;
  7834. this._container.addChild(node);
  7835. node.setPosition(anchor.x, -anchor.y);
  7836. this._content = node.addComponent(sp.Skeleton);
  7837. this._content.premultipliedAlpha = pma;
  7838. this._content.skeletonData = asset;
  7839. this.onChangeSpine();
  7840. this.updateLayout();
  7841. };
  7842. GLoader3D.prototype.setDragonBones = function (asset, atlasAsset, anchor, pma) {
  7843. this.url = null;
  7844. this.clearContent();
  7845. var node = new cc.Node();
  7846. node.color = this._color;
  7847. this._container.addChild(node);
  7848. node.setPosition(anchor.x, -anchor.y);
  7849. this._content = node.addComponent(dragonBones.ArmatureDisplay);
  7850. this._content.premultipliedAlpha = pma;
  7851. this._content.dragonAsset = asset;
  7852. this._content.dragonAtlasAsset = atlasAsset;
  7853. var armatureKey = asset["init"](dragonBones.CCFactory.getInstance(), atlasAsset["_uuid"]);
  7854. var dragonBonesData = this._content["_factory"].getDragonBonesData(armatureKey);
  7855. this._content.armatureName = dragonBonesData.armatureNames[0];
  7856. this.onChangeDragonBones();
  7857. this.updateLayout();
  7858. };
  7859. GLoader3D.prototype.onChange = function () {
  7860. this.onChangeSpine();
  7861. this.onChangeDragonBones();
  7862. };
  7863. GLoader3D.prototype.onChangeSpine = function () {
  7864. if (!(this._content instanceof sp.Skeleton))
  7865. return;
  7866. if (this._animationName) {
  7867. var trackEntry = this._content.getCurrent(0);
  7868. if (!trackEntry || trackEntry.animation.name != this._animationName || trackEntry.isComplete() && !trackEntry.loop) {
  7869. this._content.defaultAnimation = this._animationName;
  7870. trackEntry = this._content.setAnimation(0, this._animationName, this._loop);
  7871. }
  7872. if (this._playing)
  7873. this._content.paused = false;
  7874. else {
  7875. this._content.paused = true;
  7876. trackEntry.trackTime = fgui.ToolSet.lerp(0, trackEntry.animationEnd - trackEntry.animationStart, this._frame / 100);
  7877. }
  7878. }
  7879. else
  7880. this._content.clearTrack(0);
  7881. var skin = this._skinName || this._content.skeletonData.getRuntimeData().skins[0].name;
  7882. if (this._content["_skeleton"].skin != skin)
  7883. this._content.setSkin(skin);
  7884. };
  7885. GLoader3D.prototype.onChangeDragonBones = function () {
  7886. if (!(this._content instanceof dragonBones.ArmatureDisplay))
  7887. return;
  7888. if (this._animationName) {
  7889. if (this._playing)
  7890. this._content.playAnimation(this._animationName, this._loop ? 0 : 1);
  7891. else
  7892. this._content.armature().animation.gotoAndStopByFrame(this._animationName, this._frame);
  7893. }
  7894. else
  7895. this._content.armature().animation.reset();
  7896. };
  7897. GLoader3D.prototype.loadExternal = function () {
  7898. if (fgui.ToolSet.startsWith(this._url, "http://")
  7899. || fgui.ToolSet.startsWith(this._url, "https://")
  7900. || fgui.ToolSet.startsWith(this._url, '/'))
  7901. cc.assetManager.loadRemote(this._url, sp.SkeletonData, this.onLoaded2.bind(this));
  7902. else
  7903. cc.resources.load(this._url, sp.SkeletonData, this.onLoaded2.bind(this));
  7904. };
  7905. GLoader3D.prototype.onLoaded2 = function (err, asset) {
  7906. if (!this._url || !cc.isValid(this._node))
  7907. return;
  7908. if (err)
  7909. console.warn(err);
  7910. };
  7911. GLoader3D.prototype.updateLayout = function () {
  7912. var cw = this.sourceWidth;
  7913. var ch = this.sourceHeight;
  7914. var pivotCorrectX = -this.pivotX * this._width;
  7915. var pivotCorrectY = this.pivotY * this._height;
  7916. if (this._autoSize) {
  7917. this._updatingLayout = true;
  7918. if (cw == 0)
  7919. cw = 50;
  7920. if (ch == 0)
  7921. ch = 30;
  7922. this.setSize(cw, ch);
  7923. this._updatingLayout = false;
  7924. if (cw == this._width && ch == this._height) {
  7925. this._container.setScale(1, 1);
  7926. this._container.setPosition(pivotCorrectX, pivotCorrectY);
  7927. return;
  7928. }
  7929. }
  7930. var sx = 1, sy = 1;
  7931. if (this._fill != fgui.LoaderFillType.None) {
  7932. sx = this.width / this.sourceWidth;
  7933. sy = this.height / this.sourceHeight;
  7934. if (sx != 1 || sy != 1) {
  7935. if (this._fill == fgui.LoaderFillType.ScaleMatchHeight)
  7936. sx = sy;
  7937. else if (this._fill == fgui.LoaderFillType.ScaleMatchWidth)
  7938. sy = sx;
  7939. else if (this._fill == fgui.LoaderFillType.Scale) {
  7940. if (sx > sy)
  7941. sx = sy;
  7942. else
  7943. sy = sx;
  7944. }
  7945. else if (this._fill == fgui.LoaderFillType.ScaleNoBorder) {
  7946. if (sx > sy)
  7947. sy = sx;
  7948. else
  7949. sx = sy;
  7950. }
  7951. if (this._shrinkOnly) {
  7952. if (sx > 1)
  7953. sx = 1;
  7954. if (sy > 1)
  7955. sy = 1;
  7956. }
  7957. cw = this.sourceWidth * sx;
  7958. ch = this.sourceHeight * sy;
  7959. }
  7960. }
  7961. this._container.setScale(sx, sy);
  7962. var nx, ny;
  7963. if (this._align == fgui.AlignType.Left)
  7964. nx = 0;
  7965. else if (this._align == fgui.AlignType.Center)
  7966. nx = Math.floor((this._width - cw) / 2);
  7967. else
  7968. nx = this._width - cw;
  7969. if (this._verticalAlign == fgui.VertAlignType.Top)
  7970. ny = 0;
  7971. else if (this._verticalAlign == fgui.VertAlignType.Middle)
  7972. ny = Math.floor((this._height - ch) / 2);
  7973. else
  7974. ny = this._height - ch;
  7975. ny = -ny;
  7976. this._container.setPosition(pivotCorrectX + nx, pivotCorrectY + ny);
  7977. };
  7978. GLoader3D.prototype.clearContent = function () {
  7979. this._contentItem = null;
  7980. if (this._content) {
  7981. this._content.node.destroy();
  7982. this._content = null;
  7983. }
  7984. };
  7985. GLoader3D.prototype.handleSizeChanged = function () {
  7986. _super.prototype.handleSizeChanged.call(this);
  7987. if (!this._updatingLayout)
  7988. this.updateLayout();
  7989. };
  7990. GLoader3D.prototype.handleAnchorChanged = function () {
  7991. _super.prototype.handleAnchorChanged.call(this);
  7992. if (!this._updatingLayout)
  7993. this.updateLayout();
  7994. };
  7995. GLoader3D.prototype.handleGrayedChanged = function () {
  7996. };
  7997. GLoader3D.prototype.getProp = function (index) {
  7998. switch (index) {
  7999. case fgui.ObjectPropID.Color:
  8000. return this.color;
  8001. case fgui.ObjectPropID.Playing:
  8002. return this.playing;
  8003. case fgui.ObjectPropID.Frame:
  8004. return this.frame;
  8005. case fgui.ObjectPropID.TimeScale:
  8006. return 1;
  8007. default:
  8008. return _super.prototype.getProp.call(this, index);
  8009. }
  8010. };
  8011. GLoader3D.prototype.setProp = function (index, value) {
  8012. switch (index) {
  8013. case fgui.ObjectPropID.Color:
  8014. this.color = value;
  8015. break;
  8016. case fgui.ObjectPropID.Playing:
  8017. this.playing = value;
  8018. break;
  8019. case fgui.ObjectPropID.Frame:
  8020. this.frame = value;
  8021. break;
  8022. case fgui.ObjectPropID.TimeScale:
  8023. break;
  8024. case fgui.ObjectPropID.DeltaTime:
  8025. break;
  8026. default:
  8027. _super.prototype.setProp.call(this, index, value);
  8028. break;
  8029. }
  8030. };
  8031. GLoader3D.prototype.setup_beforeAdd = function (buffer, beginPos) {
  8032. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  8033. buffer.seek(beginPos, 5);
  8034. this._url = buffer.readS();
  8035. this._align = buffer.readByte();
  8036. this._verticalAlign = buffer.readByte();
  8037. this._fill = buffer.readByte();
  8038. this._shrinkOnly = buffer.readBool();
  8039. this._autoSize = buffer.readBool();
  8040. this._animationName = buffer.readS();
  8041. this._skinName = buffer.readS();
  8042. this._playing = buffer.readBool();
  8043. this._frame = buffer.readInt();
  8044. this._loop = buffer.readBool();
  8045. if (buffer.readBool())
  8046. this.color = buffer.readColor();
  8047. if (this._url)
  8048. this.loadContent();
  8049. };
  8050. return GLoader3D;
  8051. }(fgui.GObject));
  8052. fgui.GLoader3D = GLoader3D;
  8053. })(fgui || (fgui = {}));
  8054. (function (fgui) {
  8055. var GMovieClip = (function (_super) {
  8056. __extends(GMovieClip, _super);
  8057. function GMovieClip() {
  8058. var _this = _super.call(this) || this;
  8059. _this._node.name = "GMovieClip";
  8060. _this._touchDisabled = true;
  8061. _this._content = _this._node.addComponent(fgui.MovieClip);
  8062. _this._content.sizeMode = cc.Sprite.SizeMode.CUSTOM;
  8063. _this._content.trim = false;
  8064. _this._content.setPlaySettings();
  8065. return _this;
  8066. }
  8067. Object.defineProperty(GMovieClip.prototype, "color", {
  8068. get: function () {
  8069. return this._node.color;
  8070. },
  8071. set: function (value) {
  8072. this._node.color = value;
  8073. this.updateGear(4);
  8074. },
  8075. enumerable: false,
  8076. configurable: true
  8077. });
  8078. Object.defineProperty(GMovieClip.prototype, "playing", {
  8079. get: function () {
  8080. return this._content.playing;
  8081. },
  8082. set: function (value) {
  8083. if (this._content.playing != value) {
  8084. this._content.playing = value;
  8085. this.updateGear(5);
  8086. }
  8087. },
  8088. enumerable: false,
  8089. configurable: true
  8090. });
  8091. Object.defineProperty(GMovieClip.prototype, "frame", {
  8092. get: function () {
  8093. return this._content.frame;
  8094. },
  8095. set: function (value) {
  8096. if (this._content.frame != value) {
  8097. this._content.frame = value;
  8098. this.updateGear(5);
  8099. }
  8100. },
  8101. enumerable: false,
  8102. configurable: true
  8103. });
  8104. Object.defineProperty(GMovieClip.prototype, "timeScale", {
  8105. get: function () {
  8106. return this._content.timeScale;
  8107. },
  8108. set: function (value) {
  8109. this._content.timeScale = value;
  8110. },
  8111. enumerable: false,
  8112. configurable: true
  8113. });
  8114. GMovieClip.prototype.rewind = function () {
  8115. this._content.rewind();
  8116. };
  8117. GMovieClip.prototype.syncStatus = function (anotherMc) {
  8118. this._content.syncStatus(anotherMc._content);
  8119. };
  8120. GMovieClip.prototype.advance = function (timeInMiniseconds) {
  8121. this._content.advance(timeInMiniseconds);
  8122. };
  8123. GMovieClip.prototype.setPlaySettings = function (start, end, times, endAt, endCallback, callbackObj) {
  8124. this._content.setPlaySettings(start, end, times, endAt, endCallback, callbackObj);
  8125. };
  8126. GMovieClip.prototype.handleGrayedChanged = function () {
  8127. this._content.grayed = this._grayed;
  8128. };
  8129. GMovieClip.prototype.handleSizeChanged = function () {
  8130. _super.prototype.handleSizeChanged.call(this);
  8131. this._content.sizeMode = cc.Sprite.SizeMode.CUSTOM;
  8132. };
  8133. GMovieClip.prototype.getProp = function (index) {
  8134. switch (index) {
  8135. case fgui.ObjectPropID.Color:
  8136. return this.color;
  8137. case fgui.ObjectPropID.Playing:
  8138. return this.playing;
  8139. case fgui.ObjectPropID.Frame:
  8140. return this.frame;
  8141. case fgui.ObjectPropID.TimeScale:
  8142. return this.timeScale;
  8143. default:
  8144. return _super.prototype.getProp.call(this, index);
  8145. }
  8146. };
  8147. GMovieClip.prototype.setProp = function (index, value) {
  8148. switch (index) {
  8149. case fgui.ObjectPropID.Color:
  8150. this.color = value;
  8151. break;
  8152. case fgui.ObjectPropID.Playing:
  8153. this.playing = value;
  8154. break;
  8155. case fgui.ObjectPropID.Frame:
  8156. this.frame = value;
  8157. break;
  8158. case fgui.ObjectPropID.TimeScale:
  8159. this.timeScale = value;
  8160. break;
  8161. case fgui.ObjectPropID.DeltaTime:
  8162. this.advance(value);
  8163. break;
  8164. default:
  8165. _super.prototype.setProp.call(this, index, value);
  8166. break;
  8167. }
  8168. };
  8169. GMovieClip.prototype.constructFromResource = function () {
  8170. var contentItem = this.packageItem.getBranch();
  8171. this.sourceWidth = contentItem.width;
  8172. this.sourceHeight = contentItem.height;
  8173. this.initWidth = this.sourceWidth;
  8174. this.initHeight = this.sourceHeight;
  8175. this.setSize(this.sourceWidth, this.sourceHeight);
  8176. contentItem = contentItem.getHighResolution();
  8177. contentItem.load();
  8178. this._content.interval = contentItem.interval;
  8179. this._content.swing = contentItem.swing;
  8180. this._content.repeatDelay = contentItem.repeatDelay;
  8181. this._content.frames = contentItem.frames;
  8182. this._content.smoothing = contentItem.smoothing;
  8183. };
  8184. GMovieClip.prototype.setup_beforeAdd = function (buffer, beginPos) {
  8185. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  8186. buffer.seek(beginPos, 5);
  8187. if (buffer.readBool())
  8188. this.color = buffer.readColor();
  8189. buffer.readByte();
  8190. this._content.frame = buffer.readInt();
  8191. this._content.playing = buffer.readBool();
  8192. };
  8193. return GMovieClip;
  8194. }(fgui.GObject));
  8195. fgui.GMovieClip = GMovieClip;
  8196. })(fgui || (fgui = {}));
  8197. (function (fgui) {
  8198. var GProgressBar = (function (_super) {
  8199. __extends(GProgressBar, _super);
  8200. function GProgressBar() {
  8201. var _this = _super.call(this) || this;
  8202. _this._min = 0;
  8203. _this._max = 0;
  8204. _this._value = 0;
  8205. _this._barMaxWidth = 0;
  8206. _this._barMaxHeight = 0;
  8207. _this._barMaxWidthDelta = 0;
  8208. _this._barMaxHeightDelta = 0;
  8209. _this._barStartX = 0;
  8210. _this._barStartY = 0;
  8211. _this._node.name = "GProgressBar";
  8212. _this._titleType = fgui.ProgressTitleType.Percent;
  8213. _this._value = 50;
  8214. _this._max = 100;
  8215. return _this;
  8216. }
  8217. Object.defineProperty(GProgressBar.prototype, "titleType", {
  8218. get: function () {
  8219. return this._titleType;
  8220. },
  8221. set: function (value) {
  8222. if (this._titleType != value) {
  8223. this._titleType = value;
  8224. this.update(this._value);
  8225. }
  8226. },
  8227. enumerable: false,
  8228. configurable: true
  8229. });
  8230. Object.defineProperty(GProgressBar.prototype, "min", {
  8231. get: function () {
  8232. return this._min;
  8233. },
  8234. set: function (value) {
  8235. if (this._min != value) {
  8236. this._min = value;
  8237. this.update(this._value);
  8238. }
  8239. },
  8240. enumerable: false,
  8241. configurable: true
  8242. });
  8243. Object.defineProperty(GProgressBar.prototype, "max", {
  8244. get: function () {
  8245. return this._max;
  8246. },
  8247. set: function (value) {
  8248. if (this._max != value) {
  8249. this._max = value;
  8250. this.update(this._value);
  8251. }
  8252. },
  8253. enumerable: false,
  8254. configurable: true
  8255. });
  8256. Object.defineProperty(GProgressBar.prototype, "value", {
  8257. get: function () {
  8258. return this._value;
  8259. },
  8260. set: function (value) {
  8261. if (this._value != value) {
  8262. fgui.GTween.kill(this, false, this.update);
  8263. this._value = value;
  8264. this.update(value);
  8265. }
  8266. },
  8267. enumerable: false,
  8268. configurable: true
  8269. });
  8270. GProgressBar.prototype.tweenValue = function (value, duration) {
  8271. var oldValule;
  8272. var tweener = fgui.GTween.getTween(this, this.update);
  8273. if (tweener) {
  8274. oldValule = tweener.value.x;
  8275. tweener.kill();
  8276. }
  8277. else
  8278. oldValule = this._value;
  8279. this._value = value;
  8280. return fgui.GTween.to(oldValule, this._value, duration).setTarget(this, this.update).setEase(fgui.EaseType.Linear);
  8281. };
  8282. GProgressBar.prototype.update = function (newValue) {
  8283. var percent = fgui.ToolSet.clamp01((newValue - this._min) / (this._max - this._min));
  8284. if (this._titleObject) {
  8285. switch (this._titleType) {
  8286. case fgui.ProgressTitleType.Percent:
  8287. this._titleObject.text = Math.floor(percent * 100) + "%";
  8288. break;
  8289. case fgui.ProgressTitleType.ValueAndMax:
  8290. this._titleObject.text = Math.floor(newValue) + "/" + Math.floor(this._max);
  8291. break;
  8292. case fgui.ProgressTitleType.Value:
  8293. this._titleObject.text = "" + Math.floor(newValue);
  8294. break;
  8295. case fgui.ProgressTitleType.Max:
  8296. this._titleObject.text = "" + Math.floor(this._max);
  8297. break;
  8298. }
  8299. }
  8300. var fullWidth = this.width - this._barMaxWidthDelta;
  8301. var fullHeight = this.height - this._barMaxHeightDelta;
  8302. if (!this._reverse) {
  8303. if (this._barObjectH) {
  8304. if (!this.setFillAmount(this._barObjectH, percent))
  8305. this._barObjectH.width = Math.round(fullWidth * percent);
  8306. }
  8307. if (this._barObjectV) {
  8308. if (!this.setFillAmount(this._barObjectV, percent))
  8309. this._barObjectV.height = Math.round(fullHeight * percent);
  8310. }
  8311. }
  8312. else {
  8313. if (this._barObjectH) {
  8314. if (!this.setFillAmount(this._barObjectH, 1 - percent)) {
  8315. this._barObjectH.width = Math.round(fullWidth * percent);
  8316. this._barObjectH.x = this._barStartX + (fullWidth - this._barObjectH.width);
  8317. }
  8318. }
  8319. if (this._barObjectV) {
  8320. if (!this.setFillAmount(this._barObjectV, 1 - percent)) {
  8321. this._barObjectV.height = Math.round(fullHeight * percent);
  8322. this._barObjectV.y = this._barStartY + (fullHeight - this._barObjectV.height);
  8323. }
  8324. }
  8325. }
  8326. if (this._aniObject)
  8327. this._aniObject.setProp(fgui.ObjectPropID.Frame, Math.floor(percent * 100));
  8328. };
  8329. GProgressBar.prototype.setFillAmount = function (bar, percent) {
  8330. if (((bar instanceof fgui.GImage) || (bar instanceof fgui.GLoader)) && bar.fillMethod != fgui.FillMethod.None) {
  8331. bar.fillAmount = percent;
  8332. return true;
  8333. }
  8334. else
  8335. return false;
  8336. };
  8337. GProgressBar.prototype.constructExtension = function (buffer) {
  8338. buffer.seek(0, 6);
  8339. this._titleType = buffer.readByte();
  8340. this._reverse = buffer.readBool();
  8341. this._titleObject = (this.getChild("title"));
  8342. this._barObjectH = this.getChild("bar");
  8343. this._barObjectV = this.getChild("bar_v");
  8344. this._aniObject = this.getChild("ani");
  8345. if (this._barObjectH) {
  8346. this._barMaxWidth = this._barObjectH.width;
  8347. this._barMaxWidthDelta = this.width - this._barMaxWidth;
  8348. this._barStartX = this._barObjectH.x;
  8349. }
  8350. if (this._barObjectV) {
  8351. this._barMaxHeight = this._barObjectV.height;
  8352. this._barMaxHeightDelta = this.height - this._barMaxHeight;
  8353. this._barStartY = this._barObjectV.y;
  8354. }
  8355. };
  8356. GProgressBar.prototype.handleSizeChanged = function () {
  8357. _super.prototype.handleSizeChanged.call(this);
  8358. if (this._barObjectH)
  8359. this._barMaxWidth = this.width - this._barMaxWidthDelta;
  8360. if (this._barObjectV)
  8361. this._barMaxHeight = this.height - this._barMaxHeightDelta;
  8362. if (!this._underConstruct)
  8363. this.update(this._value);
  8364. };
  8365. GProgressBar.prototype.setup_afterAdd = function (buffer, beginPos) {
  8366. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  8367. if (!buffer.seek(beginPos, 6)) {
  8368. this.update(this._value);
  8369. return;
  8370. }
  8371. if (buffer.readByte() != this.packageItem.objectType) {
  8372. this.update(this._value);
  8373. return;
  8374. }
  8375. this._value = buffer.readInt();
  8376. this._max = buffer.readInt();
  8377. if (buffer.version >= 2)
  8378. this._min = buffer.readInt();
  8379. this.update(this._value);
  8380. };
  8381. return GProgressBar;
  8382. }(fgui.GComponent));
  8383. fgui.GProgressBar = GProgressBar;
  8384. })(fgui || (fgui = {}));
  8385. (function (fgui) {
  8386. var GTextField = (function (_super) {
  8387. __extends(GTextField, _super);
  8388. function GTextField() {
  8389. var _this = _super.call(this) || this;
  8390. _this._fontSize = 0;
  8391. _this._leading = 0;
  8392. _this._node.name = "GTextField";
  8393. _this._touchDisabled = true;
  8394. _this._text = "";
  8395. _this._color = new cc.Color(255, 255, 255, 255);
  8396. _this.createRenderer();
  8397. _this.fontSize = 12;
  8398. _this.leading = 3;
  8399. _this.singleLine = false;
  8400. _this._sizeDirty = false;
  8401. _this._node.on(cc.Node.EventType.SIZE_CHANGED, _this.onLabelSizeChanged, _this);
  8402. return _this;
  8403. }
  8404. GTextField.prototype.createRenderer = function () {
  8405. this._label = this._node.addComponent(cc.Label);
  8406. this.autoSize = fgui.AutoSizeType.Both;
  8407. };
  8408. Object.defineProperty(GTextField.prototype, "text", {
  8409. get: function () {
  8410. return this._text;
  8411. },
  8412. set: function (value) {
  8413. this._text = value;
  8414. if (this._text == null)
  8415. this._text = "";
  8416. this.updateGear(6);
  8417. this.markSizeChanged();
  8418. this.updateText();
  8419. },
  8420. enumerable: false,
  8421. configurable: true
  8422. });
  8423. Object.defineProperty(GTextField.prototype, "font", {
  8424. get: function () {
  8425. return this._font;
  8426. },
  8427. set: function (value) {
  8428. if (this._font != value || !value) {
  8429. this._font = value;
  8430. this.markSizeChanged();
  8431. var newFont = value ? value : fgui.UIConfig.defaultFont;
  8432. if (fgui.ToolSet.startsWith(newFont, "ui://")) {
  8433. var pi = fgui.UIPackage.getItemByURL(newFont);
  8434. if (pi)
  8435. newFont = pi.owner.getItemAsset(pi);
  8436. else
  8437. newFont = fgui.UIConfig.defaultFont;
  8438. }
  8439. this._realFont = newFont;
  8440. this.updateFont();
  8441. }
  8442. },
  8443. enumerable: false,
  8444. configurable: true
  8445. });
  8446. Object.defineProperty(GTextField.prototype, "fontSize", {
  8447. get: function () {
  8448. return this._fontSize;
  8449. },
  8450. set: function (value) {
  8451. if (value < 0)
  8452. return;
  8453. if (this._fontSize != value) {
  8454. this._fontSize = value;
  8455. this.markSizeChanged();
  8456. this.updateFontSize();
  8457. }
  8458. },
  8459. enumerable: false,
  8460. configurable: true
  8461. });
  8462. Object.defineProperty(GTextField.prototype, "color", {
  8463. get: function () {
  8464. return this._color;
  8465. },
  8466. set: function (value) {
  8467. this._color.set(value);
  8468. this.updateGear(4);
  8469. this.updateFontColor();
  8470. },
  8471. enumerable: false,
  8472. configurable: true
  8473. });
  8474. Object.defineProperty(GTextField.prototype, "align", {
  8475. get: function () {
  8476. return this._label ? this._label.horizontalAlign : 0;
  8477. },
  8478. set: function (value) {
  8479. if (this._label)
  8480. this._label.horizontalAlign = value;
  8481. },
  8482. enumerable: false,
  8483. configurable: true
  8484. });
  8485. Object.defineProperty(GTextField.prototype, "verticalAlign", {
  8486. get: function () {
  8487. return this._label ? this._label.verticalAlign : 0;
  8488. },
  8489. set: function (value) {
  8490. if (this._label)
  8491. this._label.verticalAlign = value;
  8492. },
  8493. enumerable: false,
  8494. configurable: true
  8495. });
  8496. Object.defineProperty(GTextField.prototype, "leading", {
  8497. get: function () {
  8498. return this._leading;
  8499. },
  8500. set: function (value) {
  8501. if (this._leading != value) {
  8502. this._leading = value;
  8503. this.markSizeChanged();
  8504. this.updateFontSize();
  8505. }
  8506. },
  8507. enumerable: false,
  8508. configurable: true
  8509. });
  8510. Object.defineProperty(GTextField.prototype, "letterSpacing", {
  8511. get: function () {
  8512. return this._label ? this._label.spacingX : 0;
  8513. },
  8514. set: function (value) {
  8515. if (this._label && this._label.spacingX != value) {
  8516. this.markSizeChanged();
  8517. this._label.spacingX = value;
  8518. }
  8519. },
  8520. enumerable: false,
  8521. configurable: true
  8522. });
  8523. Object.defineProperty(GTextField.prototype, "underline", {
  8524. get: function () {
  8525. return this._label ? this._label.enableUnderline : false;
  8526. },
  8527. set: function (value) {
  8528. if (this._label)
  8529. this._label.enableUnderline = value;
  8530. },
  8531. enumerable: false,
  8532. configurable: true
  8533. });
  8534. Object.defineProperty(GTextField.prototype, "bold", {
  8535. get: function () {
  8536. return this._label ? this._label.enableBold : false;
  8537. },
  8538. set: function (value) {
  8539. if (this._label)
  8540. this._label.enableBold = value;
  8541. },
  8542. enumerable: false,
  8543. configurable: true
  8544. });
  8545. Object.defineProperty(GTextField.prototype, "italic", {
  8546. get: function () {
  8547. return this._label ? this._label.enableItalic : false;
  8548. },
  8549. set: function (value) {
  8550. if (this._label)
  8551. this._label.enableItalic = value;
  8552. },
  8553. enumerable: false,
  8554. configurable: true
  8555. });
  8556. Object.defineProperty(GTextField.prototype, "singleLine", {
  8557. get: function () {
  8558. return this._label ? !this._label.enableWrapText : false;
  8559. },
  8560. set: function (value) {
  8561. if (this._label)
  8562. this._label.enableWrapText = !value;
  8563. },
  8564. enumerable: false,
  8565. configurable: true
  8566. });
  8567. Object.defineProperty(GTextField.prototype, "stroke", {
  8568. get: function () {
  8569. return (this._outline && this._outline.enabled) ? this._outline.width : 0;
  8570. },
  8571. set: function (value) {
  8572. if (value == 0) {
  8573. if (this._outline)
  8574. this._outline.enabled = false;
  8575. }
  8576. else {
  8577. if (!this._outline) {
  8578. this._outline = this._node.addComponent(cc.LabelOutline);
  8579. this.updateStrokeColor();
  8580. }
  8581. else
  8582. this._outline.enabled = true;
  8583. this._outline.width = value;
  8584. }
  8585. },
  8586. enumerable: false,
  8587. configurable: true
  8588. });
  8589. Object.defineProperty(GTextField.prototype, "strokeColor", {
  8590. get: function () {
  8591. return this._strokeColor;
  8592. },
  8593. set: function (value) {
  8594. if (!this._strokeColor)
  8595. this._strokeColor = new cc.Color();
  8596. this._strokeColor.set(value);
  8597. this.updateGear(4);
  8598. this.updateStrokeColor();
  8599. },
  8600. enumerable: false,
  8601. configurable: true
  8602. });
  8603. Object.defineProperty(GTextField.prototype, "shadowOffset", {
  8604. get: function () {
  8605. return this._shadowOffset;
  8606. },
  8607. set: function (value) {
  8608. if (!this._shadowOffset)
  8609. this._shadowOffset = new cc.Vec2();
  8610. this._shadowOffset.set(value);
  8611. if (this._shadowOffset.x != 0 || this._shadowOffset.y != 0) {
  8612. if (!this._shadow) {
  8613. this._shadow = this._node.addComponent(cc.LabelShadow);
  8614. this.updateShadowColor();
  8615. }
  8616. else
  8617. this._shadow.enabled = true;
  8618. this._shadow.offset.x = value.x;
  8619. this._shadow.offset.y = -value.y;
  8620. }
  8621. else if (this._shadow)
  8622. this._shadow.enabled = false;
  8623. },
  8624. enumerable: false,
  8625. configurable: true
  8626. });
  8627. Object.defineProperty(GTextField.prototype, "shadowColor", {
  8628. get: function () {
  8629. return this._shadowColor;
  8630. },
  8631. set: function (value) {
  8632. if (!this._shadowColor)
  8633. this._shadowColor = new cc.Color();
  8634. this._shadowColor.set(value);
  8635. this.updateShadowColor();
  8636. },
  8637. enumerable: false,
  8638. configurable: true
  8639. });
  8640. Object.defineProperty(GTextField.prototype, "ubbEnabled", {
  8641. get: function () {
  8642. return this._ubbEnabled;
  8643. },
  8644. set: function (value) {
  8645. if (this._ubbEnabled != value) {
  8646. this._ubbEnabled = value;
  8647. this.markSizeChanged();
  8648. this.updateText();
  8649. }
  8650. },
  8651. enumerable: false,
  8652. configurable: true
  8653. });
  8654. Object.defineProperty(GTextField.prototype, "autoSize", {
  8655. get: function () {
  8656. return this._autoSize;
  8657. },
  8658. set: function (value) {
  8659. if (this._autoSize != value) {
  8660. this._autoSize = value;
  8661. this.markSizeChanged();
  8662. this.updateOverflow();
  8663. }
  8664. },
  8665. enumerable: false,
  8666. configurable: true
  8667. });
  8668. GTextField.prototype.parseTemplate = function (template) {
  8669. var pos1 = 0, pos2, pos3;
  8670. var tag;
  8671. var value;
  8672. var result = "";
  8673. while ((pos2 = template.indexOf("{", pos1)) != -1) {
  8674. if (pos2 > 0 && template.charCodeAt(pos2 - 1) == 92) {
  8675. result += template.substring(pos1, pos2 - 1);
  8676. result += "{";
  8677. pos1 = pos2 + 1;
  8678. continue;
  8679. }
  8680. result += template.substring(pos1, pos2);
  8681. pos1 = pos2;
  8682. pos2 = template.indexOf("}", pos1);
  8683. if (pos2 == -1)
  8684. break;
  8685. if (pos2 == pos1 + 1) {
  8686. result += template.substr(pos1, 2);
  8687. pos1 = pos2 + 1;
  8688. continue;
  8689. }
  8690. tag = template.substring(pos1 + 1, pos2);
  8691. pos3 = tag.indexOf("=");
  8692. if (pos3 != -1) {
  8693. value = this._templateVars[tag.substring(0, pos3)];
  8694. if (value == null)
  8695. result += tag.substring(pos3 + 1);
  8696. else
  8697. result += value;
  8698. }
  8699. else {
  8700. value = this._templateVars[tag];
  8701. if (value != null)
  8702. result += value;
  8703. }
  8704. pos1 = pos2 + 1;
  8705. }
  8706. if (pos1 < template.length)
  8707. result += template.substr(pos1);
  8708. return result;
  8709. };
  8710. Object.defineProperty(GTextField.prototype, "templateVars", {
  8711. get: function () {
  8712. return this._templateVars;
  8713. },
  8714. set: function (value) {
  8715. if (this._templateVars == null && value == null)
  8716. return;
  8717. this._templateVars = value;
  8718. this.flushVars();
  8719. },
  8720. enumerable: false,
  8721. configurable: true
  8722. });
  8723. GTextField.prototype.setVar = function (name, value) {
  8724. if (!this._templateVars)
  8725. this._templateVars = {};
  8726. this._templateVars[name] = value;
  8727. return this;
  8728. };
  8729. GTextField.prototype.flushVars = function () {
  8730. this.markSizeChanged();
  8731. this.updateText();
  8732. };
  8733. Object.defineProperty(GTextField.prototype, "textWidth", {
  8734. get: function () {
  8735. this.ensureSizeCorrect();
  8736. return this._node.width;
  8737. },
  8738. enumerable: false,
  8739. configurable: true
  8740. });
  8741. GTextField.prototype.ensureSizeCorrect = function () {
  8742. if (this._sizeDirty) {
  8743. if (this._label["_forceUpdateRenderData"])
  8744. this._label["_forceUpdateRenderData"]();
  8745. else
  8746. this._label["_updateRenderData"](true);
  8747. this._sizeDirty = false;
  8748. }
  8749. };
  8750. GTextField.prototype.updateText = function () {
  8751. var text2 = this._text;
  8752. if (this._templateVars)
  8753. text2 = this.parseTemplate(text2);
  8754. if (this._ubbEnabled)
  8755. text2 = fgui.UBBParser.inst.parse(text2, true);
  8756. this._label.string = text2;
  8757. };
  8758. GTextField.prototype.assignFont = function (label, value) {
  8759. if (value instanceof cc.Font)
  8760. label.font = value;
  8761. else {
  8762. var font = fgui.getFontByName(value);
  8763. if (!font) {
  8764. label.fontFamily = value;
  8765. label.useSystemFont = true;
  8766. }
  8767. else
  8768. label.font = font;
  8769. }
  8770. };
  8771. GTextField.prototype.assignFontColor = function (label, value) {
  8772. var font = label.font;
  8773. if ((font instanceof cc.BitmapFont) && !(font._fntConfig.canTint))
  8774. value = cc.Color.WHITE;
  8775. if (this._grayed)
  8776. value = fgui.ToolSet.toGrayed(value);
  8777. label.node.color = value;
  8778. };
  8779. GTextField.prototype.updateFont = function () {
  8780. this.assignFont(this._label, this._realFont);
  8781. };
  8782. GTextField.prototype.updateFontColor = function () {
  8783. this.assignFontColor(this._label, this._color);
  8784. };
  8785. GTextField.prototype.updateStrokeColor = function () {
  8786. if (!this._outline)
  8787. return;
  8788. if (!this._strokeColor)
  8789. this._strokeColor = new cc.Color();
  8790. if (this._grayed)
  8791. this._outline.color = fgui.ToolSet.toGrayed(this._strokeColor);
  8792. else
  8793. this._outline.color = this._strokeColor;
  8794. };
  8795. GTextField.prototype.updateShadowColor = function () {
  8796. if (!this._shadow)
  8797. return;
  8798. if (!this._shadowColor)
  8799. this._shadowColor = new cc.Color();
  8800. if (this._grayed)
  8801. this._shadow.color = fgui.ToolSet.toGrayed(this._shadowColor);
  8802. else
  8803. this._shadow.color = this._shadowColor;
  8804. };
  8805. GTextField.prototype.updateFontSize = function () {
  8806. var font = this._label.font;
  8807. if (font instanceof cc.BitmapFont) {
  8808. var fntConfig = font._fntConfig;
  8809. if (fntConfig.resizable)
  8810. this._label.fontSize = this._fontSize;
  8811. else
  8812. this._label.fontSize = fntConfig.fontSize;
  8813. this._label.lineHeight = fntConfig.fontSize + (this._leading + 4) * fntConfig.fontSize / this._label.fontSize;
  8814. }
  8815. else {
  8816. this._label.fontSize = this._fontSize;
  8817. this._label.lineHeight = this._fontSize + this._leading;
  8818. }
  8819. };
  8820. GTextField.prototype.updateOverflow = function () {
  8821. if (this._autoSize == fgui.AutoSizeType.Both)
  8822. this._label.overflow = cc.Label.Overflow.NONE;
  8823. else if (this._autoSize == fgui.AutoSizeType.Height) {
  8824. this._label.overflow = cc.Label.Overflow.RESIZE_HEIGHT;
  8825. this._node.width = this._width;
  8826. }
  8827. else if (this._autoSize == fgui.AutoSizeType.Shrink) {
  8828. this._label.overflow = cc.Label.Overflow.SHRINK;
  8829. this._node.setContentSize(this._width, this._height);
  8830. }
  8831. else {
  8832. this._label.overflow = cc.Label.Overflow.CLAMP;
  8833. this._node.setContentSize(this._width, this._height);
  8834. }
  8835. };
  8836. GTextField.prototype.markSizeChanged = function () {
  8837. if (this._underConstruct)
  8838. return;
  8839. if (this._autoSize == fgui.AutoSizeType.Both || this._autoSize == fgui.AutoSizeType.Height) {
  8840. if (!this._sizeDirty) {
  8841. this._node.emit(fgui.Event.SIZE_DELAY_CHANGE, this);
  8842. this._sizeDirty = true;
  8843. }
  8844. }
  8845. };
  8846. GTextField.prototype.onLabelSizeChanged = function () {
  8847. this._sizeDirty = false;
  8848. if (this._underConstruct)
  8849. return;
  8850. if (this._autoSize == fgui.AutoSizeType.Both || this._autoSize == fgui.AutoSizeType.Height) {
  8851. this._updatingSize = true;
  8852. this.setSize(this._node.width, this._node.height);
  8853. this._updatingSize = false;
  8854. }
  8855. };
  8856. GTextField.prototype.handleSizeChanged = function () {
  8857. if (this._updatingSize)
  8858. return;
  8859. if (this._autoSize == fgui.AutoSizeType.None || this._autoSize == fgui.AutoSizeType.Shrink) {
  8860. this._node.setContentSize(this._width, this._height);
  8861. }
  8862. else if (this._autoSize == fgui.AutoSizeType.Height)
  8863. this._node.width = this._width;
  8864. };
  8865. GTextField.prototype.handleGrayedChanged = function () {
  8866. this.updateFontColor();
  8867. this.updateStrokeColor();
  8868. };
  8869. GTextField.prototype.getProp = function (index) {
  8870. switch (index) {
  8871. case fgui.ObjectPropID.Color:
  8872. return this.color;
  8873. case fgui.ObjectPropID.OutlineColor:
  8874. return this.strokeColor;
  8875. case fgui.ObjectPropID.FontSize:
  8876. return this.fontSize;
  8877. default:
  8878. return _super.prototype.getProp.call(this, index);
  8879. }
  8880. };
  8881. GTextField.prototype.setProp = function (index, value) {
  8882. switch (index) {
  8883. case fgui.ObjectPropID.Color:
  8884. this.color = value;
  8885. break;
  8886. case fgui.ObjectPropID.OutlineColor:
  8887. this.strokeColor = value;
  8888. break;
  8889. case fgui.ObjectPropID.FontSize:
  8890. this.fontSize = value;
  8891. break;
  8892. default:
  8893. _super.prototype.setProp.call(this, index, value);
  8894. break;
  8895. }
  8896. };
  8897. GTextField.prototype.setup_beforeAdd = function (buffer, beginPos) {
  8898. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  8899. buffer.seek(beginPos, 5);
  8900. this.font = buffer.readS();
  8901. this.fontSize = buffer.readShort();
  8902. this.color = buffer.readColor();
  8903. this.align = buffer.readByte();
  8904. this.verticalAlign = buffer.readByte();
  8905. this.leading = buffer.readShort();
  8906. this.letterSpacing = buffer.readShort();
  8907. this._ubbEnabled = buffer.readBool();
  8908. this.autoSize = buffer.readByte();
  8909. this.underline = buffer.readBool();
  8910. this.italic = buffer.readBool();
  8911. this.bold = buffer.readBool();
  8912. this.singleLine = buffer.readBool();
  8913. if (buffer.readBool()) {
  8914. this.strokeColor = buffer.readColor();
  8915. this.stroke = buffer.readFloat();
  8916. }
  8917. if (buffer.readBool()) {
  8918. this.shadowColor = buffer.readColor();
  8919. var f1 = buffer.readFloat();
  8920. var f2 = buffer.readFloat();
  8921. this.shadowOffset = new cc.Vec2(f1, f2);
  8922. }
  8923. if (buffer.readBool())
  8924. this._templateVars = {};
  8925. };
  8926. GTextField.prototype.setup_afterAdd = function (buffer, beginPos) {
  8927. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  8928. buffer.seek(beginPos, 6);
  8929. var str = buffer.readS();
  8930. if (str != null)
  8931. this.text = str;
  8932. };
  8933. return GTextField;
  8934. }(fgui.GObject));
  8935. fgui.GTextField = GTextField;
  8936. })(fgui || (fgui = {}));
  8937. (function (fgui) {
  8938. var RichTextImageAtlas = (function (_super) {
  8939. __extends(RichTextImageAtlas, _super);
  8940. function RichTextImageAtlas() {
  8941. return _super !== null && _super.apply(this, arguments) || this;
  8942. }
  8943. RichTextImageAtlas.prototype.getSpriteFrame = function (key) {
  8944. var pi = fgui.UIPackage.getItemByURL(key);
  8945. if (pi) {
  8946. pi.load();
  8947. if (pi.type == fgui.PackageItemType.Image)
  8948. return pi.asset;
  8949. else if (pi.type == fgui.PackageItemType.MovieClip)
  8950. return pi.frames[0].texture;
  8951. }
  8952. return _super.prototype.getSpriteFrame.call(this, key);
  8953. };
  8954. return RichTextImageAtlas;
  8955. }(cc.SpriteAtlas));
  8956. fgui.RichTextImageAtlas = RichTextImageAtlas;
  8957. var GRichTextField = (function (_super) {
  8958. __extends(GRichTextField, _super);
  8959. function GRichTextField() {
  8960. var _this = _super.call(this) || this;
  8961. _this._node.name = "GRichTextField";
  8962. _this._touchDisabled = false;
  8963. _this.linkUnderline = fgui.UIConfig.linkUnderline;
  8964. return _this;
  8965. }
  8966. GRichTextField.prototype.createRenderer = function () {
  8967. this._richText = this._node.addComponent(cc.RichText);
  8968. this._richText.handleTouchEvent = false;
  8969. this.autoSize = fgui.AutoSizeType.None;
  8970. this._richText.imageAtlas = GRichTextField.imageAtlas;
  8971. };
  8972. Object.defineProperty(GRichTextField.prototype, "align", {
  8973. get: function () {
  8974. return this._richText.horizontalAlign;
  8975. },
  8976. set: function (value) {
  8977. this._richText.horizontalAlign = value;
  8978. },
  8979. enumerable: false,
  8980. configurable: true
  8981. });
  8982. Object.defineProperty(GRichTextField.prototype, "underline", {
  8983. get: function () {
  8984. return this._underline;
  8985. },
  8986. set: function (value) {
  8987. if (this._underline != value) {
  8988. this._underline = value;
  8989. this.updateText();
  8990. }
  8991. },
  8992. enumerable: false,
  8993. configurable: true
  8994. });
  8995. Object.defineProperty(GRichTextField.prototype, "bold", {
  8996. get: function () {
  8997. return this._bold;
  8998. },
  8999. set: function (value) {
  9000. if (this._bold != value) {
  9001. this._bold = value;
  9002. this.updateText();
  9003. }
  9004. },
  9005. enumerable: false,
  9006. configurable: true
  9007. });
  9008. Object.defineProperty(GRichTextField.prototype, "italic", {
  9009. get: function () {
  9010. return this._italics;
  9011. },
  9012. set: function (value) {
  9013. if (this._italics != value) {
  9014. this._italics = value;
  9015. this.updateText();
  9016. }
  9017. },
  9018. enumerable: false,
  9019. configurable: true
  9020. });
  9021. GRichTextField.prototype.markSizeChanged = function () {
  9022. };
  9023. GRichTextField.prototype.updateText = function () {
  9024. var text2 = this._text;
  9025. if (this._templateVars)
  9026. text2 = this.parseTemplate(text2);
  9027. if (this._ubbEnabled) {
  9028. fgui.UBBParser.inst.linkUnderline = this.linkUnderline;
  9029. fgui.UBBParser.inst.linkColor = this.linkColor;
  9030. text2 = fgui.UBBParser.inst.parse(text2);
  9031. }
  9032. if (this._bold)
  9033. text2 = "<b>" + text2 + "</b>";
  9034. if (this._italics)
  9035. text2 = "<i>" + text2 + "</i>";
  9036. if (this._underline)
  9037. text2 = "<u>" + text2 + "</u>";
  9038. var c = this._color;
  9039. if (this._grayed)
  9040. c = fgui.ToolSet.toGrayed(c);
  9041. text2 = "<color=" + c.toHEX("#rrggbb") + ">" + text2 + "</color>";
  9042. if (this._autoSize == fgui.AutoSizeType.Both) {
  9043. if (this._richText.maxWidth != 0)
  9044. this._richText.maxWidth = 0;
  9045. this._richText.string = text2;
  9046. if (this.maxWidth != 0 && this._node.width > this.maxWidth)
  9047. this._richText.maxWidth = this.maxWidth;
  9048. }
  9049. else
  9050. this._richText.string = text2;
  9051. };
  9052. GRichTextField.prototype.updateFont = function () {
  9053. this.assignFont(this._richText, this._realFont);
  9054. };
  9055. GRichTextField.prototype.updateFontColor = function () {
  9056. this.assignFontColor(this._richText, this._color);
  9057. };
  9058. GRichTextField.prototype.updateFontSize = function () {
  9059. var fontSize = this._fontSize;
  9060. var font = this._richText.font;
  9061. if (font instanceof cc.BitmapFont) {
  9062. if (!font._fntConfig.resizable)
  9063. fontSize = font._fntConfig.fontSize;
  9064. }
  9065. this._richText.fontSize = fontSize;
  9066. this._richText.lineHeight = fontSize + this._leading;
  9067. };
  9068. GRichTextField.prototype.updateOverflow = function () {
  9069. if (this._autoSize == fgui.AutoSizeType.Both)
  9070. this._richText.maxWidth = 0;
  9071. else
  9072. this._richText.maxWidth = this._width;
  9073. };
  9074. GRichTextField.prototype.handleSizeChanged = function () {
  9075. if (this._updatingSize)
  9076. return;
  9077. if (this._autoSize != fgui.AutoSizeType.Both)
  9078. this._richText.maxWidth = this._width;
  9079. };
  9080. GRichTextField.imageAtlas = new RichTextImageAtlas();
  9081. return GRichTextField;
  9082. }(fgui.GTextField));
  9083. fgui.GRichTextField = GRichTextField;
  9084. })(fgui || (fgui = {}));
  9085. (function (fgui) {
  9086. var GRoot = (function (_super) {
  9087. __extends(GRoot, _super);
  9088. function GRoot() {
  9089. var _this = _super.call(this) || this;
  9090. _this._node.name = "GRoot";
  9091. _this.opaque = false;
  9092. _this._volumeScale = 1;
  9093. _this._popupStack = new Array();
  9094. _this._justClosedPopups = new Array();
  9095. _this._modalLayer = new fgui.GGraph();
  9096. _this._modalLayer.setSize(_this.width, _this.height);
  9097. _this._modalLayer.drawRect(0, cc.Color.TRANSPARENT, fgui.UIConfig.modalLayerColor);
  9098. _this._modalLayer.addRelation(_this, fgui.RelationType.Size);
  9099. _this._thisOnResized = _this.onWinResize.bind(_this);
  9100. _this._inputProcessor = _this.node.addComponent(fgui.InputProcessor);
  9101. _this._inputProcessor._captureCallback = _this.onTouchBegin_1;
  9102. if (CC_EDITOR) {
  9103. cc.engine.on('design-resolution-changed', _this._thisOnResized);
  9104. }
  9105. else {
  9106. cc.view.on('canvas-resize', _this._thisOnResized);
  9107. }
  9108. _this.onWinResize();
  9109. return _this;
  9110. }
  9111. Object.defineProperty(GRoot, "inst", {
  9112. get: function () {
  9113. if (!GRoot._inst)
  9114. throw 'Call GRoot.create first!';
  9115. return GRoot._inst;
  9116. },
  9117. enumerable: false,
  9118. configurable: true
  9119. });
  9120. GRoot.create = function (root) {
  9121. GRoot._inst = new GRoot();
  9122. if(root==null){
  9123. root=cc.director.getScene();
  9124. }
  9125. GRoot._inst.node.parent = root;
  9126. return GRoot._inst;
  9127. };
  9128. GRoot.prototype.onDestroy = function () {
  9129. if (CC_EDITOR) {
  9130. cc.engine.off('design-resolution-changed', this._thisOnResized);
  9131. }
  9132. else {
  9133. cc.view.off('canvas-resize', this._thisOnResized);
  9134. }
  9135. if (this == GRoot._inst)
  9136. GRoot._inst = null;
  9137. };
  9138. GRoot.prototype.getTouchPosition = function (touchId) {
  9139. return this._inputProcessor.getTouchPosition(touchId);
  9140. };
  9141. Object.defineProperty(GRoot.prototype, "touchTarget", {
  9142. get: function () {
  9143. return this._inputProcessor.getTouchTarget();
  9144. },
  9145. enumerable: false,
  9146. configurable: true
  9147. });
  9148. Object.defineProperty(GRoot.prototype, "inputProcessor", {
  9149. get: function () {
  9150. return this._inputProcessor;
  9151. },
  9152. enumerable: false,
  9153. configurable: true
  9154. });
  9155. GRoot.prototype.showWindow = function (win) {
  9156. this.addChild(win);
  9157. win.requestFocus();
  9158. if (win.x > this.width)
  9159. win.x = this.width - win.width;
  9160. else if (win.x + win.width < 0)
  9161. win.x = 0;
  9162. if (win.y > this.height)
  9163. win.y = this.height - win.height;
  9164. else if (win.y + win.height < 0)
  9165. win.y = 0;
  9166. this.adjustModalLayer();
  9167. };
  9168. GRoot.prototype.hideWindow = function (win) {
  9169. win.hide();
  9170. };
  9171. GRoot.prototype.hideWindowImmediately = function (win) {
  9172. if (win.parent == this)
  9173. this.removeChild(win);
  9174. this.adjustModalLayer();
  9175. };
  9176. GRoot.prototype.bringToFront = function (win) {
  9177. var cnt = this.numChildren;
  9178. var i;
  9179. if (this._modalLayer.parent && !win.modal)
  9180. i = this.getChildIndex(this._modalLayer) - 1;
  9181. else
  9182. i = cnt - 1;
  9183. for (; i >= 0; i--) {
  9184. var g = this.getChildAt(i);
  9185. if (g == win)
  9186. return;
  9187. if (g instanceof fgui.Window)
  9188. break;
  9189. }
  9190. if (i >= 0)
  9191. this.setChildIndex(win, i);
  9192. };
  9193. GRoot.prototype.showModalWait = function (msg) {
  9194. if (fgui.UIConfig.globalModalWaiting != null) {
  9195. if (this._modalWaitPane == null)
  9196. this._modalWaitPane = fgui.UIPackage.createObjectFromURL(fgui.UIConfig.globalModalWaiting);
  9197. this._modalWaitPane.setSize(this.width, this.height);
  9198. this._modalWaitPane.addRelation(this, fgui.RelationType.Size);
  9199. this.addChild(this._modalWaitPane);
  9200. this._modalWaitPane.text = msg;
  9201. }
  9202. };
  9203. GRoot.prototype.closeModalWait = function () {
  9204. if (this._modalWaitPane && this._modalWaitPane.parent)
  9205. this.removeChild(this._modalWaitPane);
  9206. };
  9207. GRoot.prototype.closeAllExceptModals = function () {
  9208. var arr = this._children.slice();
  9209. var cnt = arr.length;
  9210. for (var i = 0; i < cnt; i++) {
  9211. var g = arr[i];
  9212. if ((g instanceof fgui.Window) && !g.modal)
  9213. g.hide();
  9214. }
  9215. };
  9216. GRoot.prototype.closeAllWindows = function () {
  9217. var arr = this._children.slice();
  9218. var cnt = arr.length;
  9219. for (var i = 0; i < cnt; i++) {
  9220. var g = arr[i];
  9221. if (g instanceof fgui.Window)
  9222. g.hide();
  9223. }
  9224. };
  9225. GRoot.prototype.getTopWindow = function () {
  9226. var cnt = this.numChildren;
  9227. for (var i = cnt - 1; i >= 0; i--) {
  9228. var g = this.getChildAt(i);
  9229. if (g instanceof fgui.Window) {
  9230. return g;
  9231. }
  9232. }
  9233. return null;
  9234. };
  9235. Object.defineProperty(GRoot.prototype, "modalLayer", {
  9236. get: function () {
  9237. return this._modalLayer;
  9238. },
  9239. enumerable: false,
  9240. configurable: true
  9241. });
  9242. Object.defineProperty(GRoot.prototype, "hasModalWindow", {
  9243. get: function () {
  9244. return this._modalLayer.parent != null;
  9245. },
  9246. enumerable: false,
  9247. configurable: true
  9248. });
  9249. Object.defineProperty(GRoot.prototype, "modalWaiting", {
  9250. get: function () {
  9251. return this._modalWaitPane && this._modalWaitPane.node.activeInHierarchy;
  9252. },
  9253. enumerable: false,
  9254. configurable: true
  9255. });
  9256. GRoot.prototype.getPopupPosition = function (popup, target, dir, result) {
  9257. var pos = result || new cc.Vec2();
  9258. var sizeW = 0, sizeH = 0;
  9259. if (target) {
  9260. pos = target.localToGlobal();
  9261. var pos2 = target.localToGlobal(target.width, target.height);
  9262. sizeW = pos2.x - pos.x;
  9263. sizeH = pos2.y - pos.y;
  9264. }
  9265. else {
  9266. pos = this.getTouchPosition();
  9267. pos = this.globalToLocal(pos.x, pos.y);
  9268. }
  9269. if (pos.x + popup.width > this.width)
  9270. pos.x = pos.x + sizeW - popup.width;
  9271. pos.y += sizeH;
  9272. if (((dir === undefined || dir === fgui.PopupDirection.Auto) && pos.y + popup.height > this.height)
  9273. || dir === false || dir === fgui.PopupDirection.Up) {
  9274. pos.y = pos.y - sizeH - popup.height - 1;
  9275. if (pos.y < 0) {
  9276. pos.y = 0;
  9277. pos.x += sizeW / 2;
  9278. }
  9279. }
  9280. return pos;
  9281. };
  9282. GRoot.prototype.showPopup = function (popup, target, dir) {
  9283. if (this._popupStack.length > 0) {
  9284. var k = this._popupStack.indexOf(popup);
  9285. if (k != -1) {
  9286. for (var i = this._popupStack.length - 1; i >= k; i--)
  9287. this.removeChild(this._popupStack.pop());
  9288. }
  9289. }
  9290. this._popupStack.push(popup);
  9291. if (target) {
  9292. var p = target;
  9293. while (p) {
  9294. if (p.parent == this) {
  9295. if (popup.sortingOrder < p.sortingOrder) {
  9296. popup.sortingOrder = p.sortingOrder;
  9297. }
  9298. break;
  9299. }
  9300. p = p.parent;
  9301. }
  9302. }
  9303. this.addChild(popup);
  9304. this.adjustModalLayer();
  9305. var pt = this.getPopupPosition(popup, target, dir);
  9306. popup.setPosition(pt.x, pt.y);
  9307. };
  9308. GRoot.prototype.togglePopup = function (popup, target, dir) {
  9309. if (this._justClosedPopups.indexOf(popup) != -1)
  9310. return;
  9311. this.showPopup(popup, target, dir);
  9312. };
  9313. GRoot.prototype.hidePopup = function (popup) {
  9314. if (popup) {
  9315. var k = this._popupStack.indexOf(popup);
  9316. if (k != -1) {
  9317. for (var i = this._popupStack.length - 1; i >= k; i--)
  9318. this.closePopup(this._popupStack.pop());
  9319. }
  9320. }
  9321. else {
  9322. var cnt = this._popupStack.length;
  9323. for (i = cnt - 1; i >= 0; i--)
  9324. this.closePopup(this._popupStack[i]);
  9325. this._popupStack.length = 0;
  9326. }
  9327. };
  9328. Object.defineProperty(GRoot.prototype, "hasAnyPopup", {
  9329. get: function () {
  9330. return this._popupStack.length != 0;
  9331. },
  9332. enumerable: false,
  9333. configurable: true
  9334. });
  9335. GRoot.prototype.closePopup = function (target) {
  9336. if (target.parent) {
  9337. if (target instanceof fgui.Window)
  9338. target.hide();
  9339. else
  9340. this.removeChild(target);
  9341. }
  9342. };
  9343. GRoot.prototype.showTooltips = function (msg) {
  9344. if (this._defaultTooltipWin == null) {
  9345. var resourceURL = fgui.UIConfig.tooltipsWin;
  9346. if (!resourceURL) {
  9347. console.error("UIConfig.tooltipsWin not defined");
  9348. return;
  9349. }
  9350. this._defaultTooltipWin = fgui.UIPackage.createObjectFromURL(resourceURL);
  9351. }
  9352. this._defaultTooltipWin.text = msg;
  9353. this.showTooltipsWin(this._defaultTooltipWin);
  9354. };
  9355. GRoot.prototype.showTooltipsWin = function (tooltipWin) {
  9356. this.hideTooltips();
  9357. this._tooltipWin = tooltipWin;
  9358. var pt = this.getTouchPosition();
  9359. pt.x += 10;
  9360. pt.y += 20;
  9361. this.globalToLocal(pt.x, pt.y, pt);
  9362. if (pt.x + this._tooltipWin.width > this.width) {
  9363. pt.x = pt.x - this._tooltipWin.width - 1;
  9364. if (pt.x < 0)
  9365. pt.x = 10;
  9366. }
  9367. if (pt.y + this._tooltipWin.height > this.height) {
  9368. pt.y = pt.y - this._tooltipWin.height - 1;
  9369. if (pt.y < 0)
  9370. pt.y = 10;
  9371. }
  9372. this._tooltipWin.setPosition(pt.x, pt.y);
  9373. this.addChild(this._tooltipWin);
  9374. };
  9375. GRoot.prototype.hideTooltips = function () {
  9376. if (this._tooltipWin) {
  9377. if (this._tooltipWin.parent)
  9378. this.removeChild(this._tooltipWin);
  9379. this._tooltipWin = null;
  9380. }
  9381. };
  9382. Object.defineProperty(GRoot.prototype, "volumeScale", {
  9383. get: function () {
  9384. return this._volumeScale;
  9385. },
  9386. set: function (value) {
  9387. this._volumeScale = value;
  9388. },
  9389. enumerable: false,
  9390. configurable: true
  9391. });
  9392. GRoot.prototype.playOneShotSound = function (clip, volumeScale) {
  9393. if (volumeScale === undefined)
  9394. volumeScale = 1;
  9395. cc.audioEngine.play(clip, false, this._volumeScale * volumeScale);
  9396. };
  9397. GRoot.prototype.adjustModalLayer = function () {
  9398. var cnt = this.numChildren;
  9399. if (this._modalWaitPane && this._modalWaitPane.parent)
  9400. this.setChildIndex(this._modalWaitPane, cnt - 1);
  9401. for (var i = cnt - 1; i >= 0; i--) {
  9402. var g = this.getChildAt(i);
  9403. if ((g instanceof fgui.Window) && g.modal) {
  9404. if (this._modalLayer.parent == null)
  9405. this.addChildAt(this._modalLayer, i);
  9406. else
  9407. this.setChildIndexBefore(this._modalLayer, i);
  9408. return;
  9409. }
  9410. }
  9411. if (this._modalLayer.parent)
  9412. this.removeChild(this._modalLayer);
  9413. };
  9414. GRoot.prototype.onTouchBegin_1 = function (evt) {
  9415. if (this._tooltipWin)
  9416. this.hideTooltips();
  9417. this._justClosedPopups.length = 0;
  9418. if (this._popupStack.length > 0) {
  9419. var mc = evt.initiator;
  9420. while (mc && mc != this) {
  9421. var pindex = this._popupStack.indexOf(mc);
  9422. if (pindex != -1) {
  9423. for (var i = this._popupStack.length - 1; i > pindex; i--) {
  9424. var popup = this._popupStack.pop();
  9425. this.closePopup(popup);
  9426. this._justClosedPopups.push(popup);
  9427. }
  9428. return;
  9429. }
  9430. mc = mc.findParent();
  9431. }
  9432. var cnt = this._popupStack.length;
  9433. for (var i = cnt - 1; i >= 0; i--) {
  9434. popup = this._popupStack[i];
  9435. this.closePopup(popup);
  9436. this._justClosedPopups.push(popup);
  9437. }
  9438. this._popupStack.length = 0;
  9439. }
  9440. };
  9441. GRoot.prototype.onWinResize = function () {
  9442. var size = cc.view.getCanvasSize();
  9443. size.width /= cc.view.getScaleX();
  9444. size.height /= cc.view.getScaleY();
  9445. var pos = cc.view.getViewportRect().origin;
  9446. pos.x = pos.x / cc.view.getScaleX();
  9447. pos.y = pos.y / cc.view.getScaleY();
  9448. this.setSize(size.width, size.height);
  9449. this._node.setPosition(-pos.x, this._height - pos.y);
  9450. this.updateContentScaleLevel();
  9451. };
  9452. GRoot.prototype.handlePositionChanged = function () {
  9453. };
  9454. GRoot.prototype.updateContentScaleLevel = function () {
  9455. var ss = Math.max(cc.view.getScaleX(), cc.view.getScaleY());
  9456. if (ss >= 3.5)
  9457. GRoot.contentScaleLevel = 3;
  9458. else if (ss >= 2.5)
  9459. GRoot.contentScaleLevel = 2;
  9460. else if (ss >= 1.5)
  9461. GRoot.contentScaleLevel = 1;
  9462. else
  9463. GRoot.contentScaleLevel = 0;
  9464. };
  9465. GRoot.contentScaleLevel = 0;
  9466. return GRoot;
  9467. }(fgui.GComponent));
  9468. fgui.GRoot = GRoot;
  9469. })(fgui || (fgui = {}));
  9470. (function (fgui) {
  9471. var GScrollBar = (function (_super) {
  9472. __extends(GScrollBar, _super);
  9473. function GScrollBar() {
  9474. var _this = _super.call(this) || this;
  9475. _this._node.name = "GScrollBar";
  9476. _this._dragOffset = new cc.Vec2();
  9477. _this._scrollPerc = 0;
  9478. return _this;
  9479. }
  9480. GScrollBar.prototype.setScrollPane = function (target, vertical) {
  9481. this._target = target;
  9482. this._vertical = vertical;
  9483. };
  9484. GScrollBar.prototype.setDisplayPerc = function (value) {
  9485. if (this._vertical) {
  9486. if (!this._fixedGripSize)
  9487. this._grip.height = Math.floor(value * this._bar.height);
  9488. this._grip.y = this._bar.y + (this._bar.height - this._grip.height) * this._scrollPerc;
  9489. }
  9490. else {
  9491. if (!this._fixedGripSize)
  9492. this._grip.width = Math.floor(value * this._bar.width);
  9493. this._grip.x = this._bar.x + (this._bar.width - this._grip.width) * this._scrollPerc;
  9494. }
  9495. this._grip.visible = value != 0 && value != 1;
  9496. };
  9497. GScrollBar.prototype.setScrollPerc = function (val) {
  9498. this._scrollPerc = val;
  9499. if (this._vertical)
  9500. this._grip.y = this._bar.y + (this._bar.height - this._grip.height) * this._scrollPerc;
  9501. else
  9502. this._grip.x = this._bar.x + (this._bar.width - this._grip.width) * this._scrollPerc;
  9503. };
  9504. Object.defineProperty(GScrollBar.prototype, "minSize", {
  9505. get: function () {
  9506. if (this._vertical)
  9507. return (this._arrowButton1 ? this._arrowButton1.height : 0) + (this._arrowButton2 ? this._arrowButton2.height : 0);
  9508. else
  9509. return (this._arrowButton1 ? this._arrowButton1.width : 0) + (this._arrowButton2 ? this._arrowButton2.width : 0);
  9510. },
  9511. enumerable: false,
  9512. configurable: true
  9513. });
  9514. Object.defineProperty(GScrollBar.prototype, "gripDragging", {
  9515. get: function () {
  9516. return this._gripDragging;
  9517. },
  9518. enumerable: false,
  9519. configurable: true
  9520. });
  9521. GScrollBar.prototype.constructExtension = function (buffer) {
  9522. buffer.seek(0, 6);
  9523. this._fixedGripSize = buffer.readBool();
  9524. this._grip = this.getChild("grip");
  9525. if (!this._grip) {
  9526. console.error("需要定义grip");
  9527. return;
  9528. }
  9529. this._bar = this.getChild("bar");
  9530. if (!this._bar) {
  9531. console.error("需要定义bar");
  9532. return;
  9533. }
  9534. this._arrowButton1 = this.getChild("arrow1");
  9535. this._arrowButton2 = this.getChild("arrow2");
  9536. this._grip.on(fgui.Event.TOUCH_BEGIN, this.onGripTouchDown, this);
  9537. this._grip.on(fgui.Event.TOUCH_MOVE, this.onGripTouchMove, this);
  9538. this._grip.on(fgui.Event.TOUCH_END, this.onGripTouchEnd, this);
  9539. if (this._arrowButton1)
  9540. this._arrowButton1.on(fgui.Event.TOUCH_BEGIN, this.onClickArrow1, this);
  9541. if (this._arrowButton2)
  9542. this._arrowButton2.on(fgui.Event.TOUCH_BEGIN, this.onClickArrow2, this);
  9543. this.on(fgui.Event.TOUCH_BEGIN, this.onBarTouchBegin, this);
  9544. };
  9545. GScrollBar.prototype.onGripTouchDown = function (evt) {
  9546. evt.stopPropagation();
  9547. evt.captureTouch();
  9548. this._gripDragging = true;
  9549. this._target.updateScrollBarVisible();
  9550. this.globalToLocal(evt.pos.x, evt.pos.y, this._dragOffset);
  9551. this._dragOffset.x -= this._grip.x;
  9552. this._dragOffset.y -= this._grip.y;
  9553. };
  9554. GScrollBar.prototype.onGripTouchMove = function (evt) {
  9555. if (!this.onStage)
  9556. return;
  9557. var pt = this.globalToLocal(evt.pos.x, evt.pos.y, s_vec2);
  9558. if (this._vertical) {
  9559. var curY = pt.y - this._dragOffset.y;
  9560. this._target.setPercY((curY - this._bar.y) / (this._bar.height - this._grip.height), false);
  9561. }
  9562. else {
  9563. var curX = pt.x - this._dragOffset.x;
  9564. this._target.setPercX((curX - this._bar.x) / (this._bar.width - this._grip.width), false);
  9565. }
  9566. };
  9567. GScrollBar.prototype.onGripTouchEnd = function (evt) {
  9568. if (!this.onStage)
  9569. return;
  9570. this._gripDragging = false;
  9571. this._target.updateScrollBarVisible();
  9572. };
  9573. GScrollBar.prototype.onClickArrow1 = function (evt) {
  9574. evt.stopPropagation();
  9575. if (this._vertical)
  9576. this._target.scrollUp();
  9577. else
  9578. this._target.scrollLeft();
  9579. };
  9580. GScrollBar.prototype.onClickArrow2 = function (evt) {
  9581. evt.stopPropagation();
  9582. if (this._vertical)
  9583. this._target.scrollDown();
  9584. else
  9585. this._target.scrollRight();
  9586. };
  9587. GScrollBar.prototype.onBarTouchBegin = function (evt) {
  9588. var pt = this._grip.globalToLocal(evt.pos.x, evt.pos.y, s_vec2);
  9589. if (this._vertical) {
  9590. if (pt.y < 0)
  9591. this._target.scrollUp(4);
  9592. else
  9593. this._target.scrollDown(4);
  9594. }
  9595. else {
  9596. if (pt.x < 0)
  9597. this._target.scrollLeft(4);
  9598. else
  9599. this._target.scrollRight(4);
  9600. }
  9601. };
  9602. return GScrollBar;
  9603. }(fgui.GComponent));
  9604. fgui.GScrollBar = GScrollBar;
  9605. var s_vec2 = new cc.Vec2();
  9606. })(fgui || (fgui = {}));
  9607. (function (fgui) {
  9608. var GSlider = (function (_super) {
  9609. __extends(GSlider, _super);
  9610. function GSlider() {
  9611. var _this = _super.call(this) || this;
  9612. _this._min = 0;
  9613. _this._max = 0;
  9614. _this._value = 0;
  9615. _this._barMaxWidth = 0;
  9616. _this._barMaxHeight = 0;
  9617. _this._barMaxWidthDelta = 0;
  9618. _this._barMaxHeightDelta = 0;
  9619. _this._clickPercent = 0;
  9620. _this._barStartX = 0;
  9621. _this._barStartY = 0;
  9622. _this.changeOnClick = true;
  9623. _this.canDrag = true;
  9624. _this._node.name = "GSlider";
  9625. _this._titleType = fgui.ProgressTitleType.Percent;
  9626. _this._value = 50;
  9627. _this._max = 100;
  9628. _this._clickPos = new cc.Vec2();
  9629. return _this;
  9630. }
  9631. Object.defineProperty(GSlider.prototype, "titleType", {
  9632. get: function () {
  9633. return this._titleType;
  9634. },
  9635. set: function (value) {
  9636. this._titleType = value;
  9637. },
  9638. enumerable: false,
  9639. configurable: true
  9640. });
  9641. Object.defineProperty(GSlider.prototype, "wholeNumbers", {
  9642. get: function () {
  9643. return this._wholeNumbers;
  9644. },
  9645. set: function (value) {
  9646. if (this._wholeNumbers != value) {
  9647. this._wholeNumbers = value;
  9648. this.update();
  9649. }
  9650. },
  9651. enumerable: false,
  9652. configurable: true
  9653. });
  9654. Object.defineProperty(GSlider.prototype, "min", {
  9655. get: function () {
  9656. return this._min;
  9657. },
  9658. set: function (value) {
  9659. if (this._min != value) {
  9660. this._min = value;
  9661. this.update();
  9662. }
  9663. },
  9664. enumerable: false,
  9665. configurable: true
  9666. });
  9667. Object.defineProperty(GSlider.prototype, "max", {
  9668. get: function () {
  9669. return this._max;
  9670. },
  9671. set: function (value) {
  9672. if (this._max != value) {
  9673. this._max = value;
  9674. this.update();
  9675. }
  9676. },
  9677. enumerable: false,
  9678. configurable: true
  9679. });
  9680. Object.defineProperty(GSlider.prototype, "value", {
  9681. get: function () {
  9682. return this._value;
  9683. },
  9684. set: function (value) {
  9685. if (this._value != value) {
  9686. this._value = value;
  9687. this.update();
  9688. }
  9689. },
  9690. enumerable: false,
  9691. configurable: true
  9692. });
  9693. GSlider.prototype.update = function () {
  9694. this.updateWithPercent((this._value - this._min) / (this._max - this._min));
  9695. };
  9696. GSlider.prototype.updateWithPercent = function (percent, manual) {
  9697. percent = fgui.ToolSet.clamp01(percent);
  9698. if (manual) {
  9699. var newValue = fgui.ToolSet.clamp(this._min + (this._max - this._min) * percent, this._min, this._max);
  9700. if (this._wholeNumbers) {
  9701. newValue = Math.round(newValue);
  9702. percent = fgui.ToolSet.clamp01((newValue - this._min) / (this._max - this._min));
  9703. }
  9704. if (newValue != this._value) {
  9705. this._value = newValue;
  9706. this._node.emit(fgui.Event.STATUS_CHANGED, this);
  9707. }
  9708. }
  9709. if (this._titleObject) {
  9710. switch (this._titleType) {
  9711. case fgui.ProgressTitleType.Percent:
  9712. this._titleObject.text = Math.floor(percent * 100) + "%";
  9713. break;
  9714. case fgui.ProgressTitleType.ValueAndMax:
  9715. this._titleObject.text = this._value + "/" + this._max;
  9716. break;
  9717. case fgui.ProgressTitleType.Value:
  9718. this._titleObject.text = "" + this._value;
  9719. break;
  9720. case fgui.ProgressTitleType.Max:
  9721. this._titleObject.text = "" + this._max;
  9722. break;
  9723. }
  9724. }
  9725. var fullWidth = this.width - this._barMaxWidthDelta;
  9726. var fullHeight = this.height - this._barMaxHeightDelta;
  9727. if (!this._reverse) {
  9728. if (this._barObjectH)
  9729. this._barObjectH.width = Math.round(fullWidth * percent);
  9730. if (this._barObjectV)
  9731. this._barObjectV.height = Math.round(fullHeight * percent);
  9732. }
  9733. else {
  9734. if (this._barObjectH) {
  9735. this._barObjectH.width = Math.round(fullWidth * percent);
  9736. this._barObjectH.x = this._barStartX + (fullWidth - this._barObjectH.width);
  9737. }
  9738. if (this._barObjectV) {
  9739. this._barObjectV.height = Math.round(fullHeight * percent);
  9740. this._barObjectV.y = this._barStartY + (fullHeight - this._barObjectV.height);
  9741. }
  9742. }
  9743. };
  9744. GSlider.prototype.constructExtension = function (buffer) {
  9745. buffer.seek(0, 6);
  9746. this._titleType = buffer.readByte();
  9747. this._reverse = buffer.readBool();
  9748. if (buffer.version >= 2) {
  9749. this._wholeNumbers = buffer.readBool();
  9750. this.changeOnClick = buffer.readBool();
  9751. }
  9752. this._titleObject = (this.getChild("title"));
  9753. this._barObjectH = this.getChild("bar");
  9754. this._barObjectV = this.getChild("bar_v");
  9755. this._gripObject = this.getChild("grip");
  9756. if (this._barObjectH) {
  9757. this._barMaxWidth = this._barObjectH.width;
  9758. this._barMaxWidthDelta = this.width - this._barMaxWidth;
  9759. this._barStartX = this._barObjectH.x;
  9760. }
  9761. if (this._barObjectV) {
  9762. this._barMaxHeight = this._barObjectV.height;
  9763. this._barMaxHeightDelta = this.height - this._barMaxHeight;
  9764. this._barStartY = this._barObjectV.y;
  9765. }
  9766. if (this._gripObject) {
  9767. this._gripObject.on(fgui.Event.TOUCH_BEGIN, this.onGripTouchBegin, this);
  9768. this._gripObject.on(fgui.Event.TOUCH_MOVE, this.onGripTouchMove, this);
  9769. }
  9770. this._node.on(fgui.Event.TOUCH_BEGIN, this.onBarTouchBegin, this);
  9771. };
  9772. GSlider.prototype.handleSizeChanged = function () {
  9773. _super.prototype.handleSizeChanged.call(this);
  9774. if (this._barObjectH)
  9775. this._barMaxWidth = this.width - this._barMaxWidthDelta;
  9776. if (this._barObjectV)
  9777. this._barMaxHeight = this.height - this._barMaxHeightDelta;
  9778. if (!this._underConstruct)
  9779. this.update();
  9780. };
  9781. GSlider.prototype.setup_afterAdd = function (buffer, beginPos) {
  9782. _super.prototype.setup_afterAdd.call(this, buffer, beginPos);
  9783. if (!buffer.seek(beginPos, 6)) {
  9784. this.update();
  9785. return;
  9786. }
  9787. if (buffer.readByte() != this.packageItem.objectType) {
  9788. this.update();
  9789. return;
  9790. }
  9791. this._value = buffer.readInt();
  9792. this._max = buffer.readInt();
  9793. if (buffer.version >= 2)
  9794. this._min = buffer.readInt();
  9795. this.update();
  9796. };
  9797. GSlider.prototype.onGripTouchBegin = function (evt) {
  9798. this.canDrag = true;
  9799. evt.stopPropagation();
  9800. evt.captureTouch();
  9801. this._clickPos = this.globalToLocal(evt.pos.x, evt.pos.y);
  9802. this._clickPercent = fgui.ToolSet.clamp01((this._value - this._min) / (this._max - this._min));
  9803. };
  9804. GSlider.prototype.onGripTouchMove = function (evt) {
  9805. if (!this.canDrag) {
  9806. return;
  9807. }
  9808. var pt = this.globalToLocal(evt.pos.x, evt.pos.y, s_vec2);
  9809. var deltaX = pt.x - this._clickPos.x;
  9810. var deltaY = pt.y - this._clickPos.y;
  9811. if (this._reverse) {
  9812. deltaX = -deltaX;
  9813. deltaY = -deltaY;
  9814. }
  9815. var percent;
  9816. if (this._barObjectH)
  9817. percent = this._clickPercent + deltaX / this._barMaxWidth;
  9818. else
  9819. percent = this._clickPercent + deltaY / this._barMaxHeight;
  9820. this.updateWithPercent(percent, true);
  9821. };
  9822. GSlider.prototype.onBarTouchBegin = function (evt) {
  9823. if (!this.changeOnClick)
  9824. return;
  9825. var pt = this._gripObject.globalToLocal(evt.pos.x, evt.pos.y, s_vec2);
  9826. var percent = fgui.ToolSet.clamp01((this._value - this._min) / (this._max - this._min));
  9827. var delta = 0;
  9828. if (this._barObjectH != null)
  9829. delta = (pt.x - this._gripObject.width / 2) / this._barMaxWidth;
  9830. if (this._barObjectV != null)
  9831. delta = (pt.y - this._gripObject.height / 2) / this._barMaxHeight;
  9832. if (this._reverse)
  9833. percent -= delta;
  9834. else
  9835. percent += delta;
  9836. this.updateWithPercent(percent, true);
  9837. };
  9838. return GSlider;
  9839. }(fgui.GComponent));
  9840. fgui.GSlider = GSlider;
  9841. var s_vec2 = new cc.Vec2();
  9842. })(fgui || (fgui = {}));
  9843. (function (fgui) {
  9844. var GTextInput = (function (_super) {
  9845. __extends(GTextInput, _super);
  9846. function GTextInput() {
  9847. var _this = _super.call(this) || this;
  9848. _this._node.name = "GTextInput";
  9849. _this._touchDisabled = false;
  9850. return _this;
  9851. }
  9852. GTextInput.prototype.createRenderer = function () {
  9853. this._editBox = this._node.addComponent(MyEditBox);
  9854. this._editBox.maxLength = -1;
  9855. this._editBox["_updateTextLabel"]();
  9856. this._node.on('text-changed', this.onTextChanged, this);
  9857. this.on(fgui.Event.TOUCH_END, this.onTouchEnd1, this);
  9858. this.autoSize = fgui.AutoSizeType.None;
  9859. };
  9860. Object.defineProperty(GTextInput.prototype, "editable", {
  9861. get: function () {
  9862. return this._editBox.enabled;
  9863. },
  9864. set: function (val) {
  9865. this._editBox.enabled = val;
  9866. },
  9867. enumerable: false,
  9868. configurable: true
  9869. });
  9870. Object.defineProperty(GTextInput.prototype, "maxLength", {
  9871. get: function () {
  9872. return this._editBox.maxLength;
  9873. },
  9874. set: function (val) {
  9875. if (val == 0)
  9876. val = -1;
  9877. this._editBox.maxLength = val;
  9878. },
  9879. enumerable: false,
  9880. configurable: true
  9881. });
  9882. Object.defineProperty(GTextInput.prototype, "promptText", {
  9883. get: function () {
  9884. return this._promptText;
  9885. },
  9886. set: function (val) {
  9887. this._promptText = val;
  9888. var newCreate = !this._editBox.placeholderLabel;
  9889. this._editBox["_updatePlaceholderLabel"]();
  9890. if (newCreate)
  9891. this.assignFont(this._editBox.placeholderLabel, this._realFont);
  9892. this._editBox.placeholderLabel.string = fgui.UBBParser.inst.parse(this._promptText, true);
  9893. if (fgui.UBBParser.inst.lastColor) {
  9894. var c = this._editBox.placeholderLabel.node.color;
  9895. if (!c)
  9896. c = new cc.Color();
  9897. c.fromHEX(fgui.UBBParser.inst.lastColor);
  9898. this.assignFontColor(this._editBox.placeholderLabel, c);
  9899. }
  9900. else
  9901. this.assignFontColor(this._editBox.placeholderLabel, this._color);
  9902. if (fgui.UBBParser.inst.lastSize)
  9903. this._editBox.placeholderLabel.fontSize = parseInt(fgui.UBBParser.inst.lastSize);
  9904. else
  9905. this._editBox.placeholderLabel.fontSize = this._fontSize;
  9906. },
  9907. enumerable: false,
  9908. configurable: true
  9909. });
  9910. Object.defineProperty(GTextInput.prototype, "restrict", {
  9911. get: function () {
  9912. return "";
  9913. },
  9914. set: function (value) {
  9915. },
  9916. enumerable: false,
  9917. configurable: true
  9918. });
  9919. Object.defineProperty(GTextInput.prototype, "password", {
  9920. get: function () {
  9921. return this._editBox.inputFlag == cc.EditBox.InputFlag.PASSWORD;
  9922. ;
  9923. },
  9924. set: function (val) {
  9925. this._editBox.inputFlag = val ? cc.EditBox.InputFlag.PASSWORD : cc.EditBox.InputFlag.DEFAULT;
  9926. },
  9927. enumerable: false,
  9928. configurable: true
  9929. });
  9930. Object.defineProperty(GTextInput.prototype, "align", {
  9931. get: function () {
  9932. return this._editBox.textLabel.horizontalAlign;
  9933. },
  9934. set: function (value) {
  9935. this._editBox.textLabel.horizontalAlign = value;
  9936. if (this._editBox.placeholderLabel) {
  9937. this._editBox.placeholderLabel.horizontalAlign = value;
  9938. }
  9939. },
  9940. enumerable: false,
  9941. configurable: true
  9942. });
  9943. Object.defineProperty(GTextInput.prototype, "verticalAlign", {
  9944. get: function () {
  9945. return this._editBox.textLabel.verticalAlign;
  9946. },
  9947. set: function (value) {
  9948. this._editBox.textLabel.verticalAlign = value;
  9949. if (this._editBox.placeholderLabel) {
  9950. this._editBox.placeholderLabel.verticalAlign = value;
  9951. }
  9952. },
  9953. enumerable: false,
  9954. configurable: true
  9955. });
  9956. Object.defineProperty(GTextInput.prototype, "singleLine", {
  9957. get: function () {
  9958. return this._editBox.inputMode != cc.EditBox.InputMode.ANY;
  9959. },
  9960. set: function (value) {
  9961. this._editBox.inputMode = value ? cc.EditBox.InputMode.SINGLE_LINE : cc.EditBox.InputMode.ANY;
  9962. },
  9963. enumerable: false,
  9964. configurable: true
  9965. });
  9966. GTextInput.prototype.requestFocus = function () {
  9967. this._editBox.focus();
  9968. };
  9969. GTextInput.prototype.markSizeChanged = function () {
  9970. };
  9971. GTextInput.prototype.updateText = function () {
  9972. var text2 = this._text;
  9973. if (this._templateVars)
  9974. text2 = this.parseTemplate(text2);
  9975. if (this._ubbEnabled)
  9976. text2 = fgui.UBBParser.inst.parse(fgui.ToolSet.encodeHTML(text2), true);
  9977. this._editBox.string = text2;
  9978. };
  9979. GTextInput.prototype.updateFont = function () {
  9980. this.assignFont(this._editBox.textLabel, this._realFont);
  9981. if (this._editBox.placeholderLabel)
  9982. this.assignFont(this._editBox.placeholderLabel, this._realFont);
  9983. };
  9984. GTextInput.prototype.updateFontColor = function () {
  9985. this.assignFontColor(this._editBox.textLabel, this._color);
  9986. };
  9987. GTextInput.prototype.updateFontSize = function () {
  9988. this._editBox.textLabel.fontSize = this._fontSize;
  9989. this._editBox.textLabel.lineHeight = this._fontSize + this._leading;
  9990. if (this._editBox.placeholderLabel)
  9991. this._editBox.placeholderLabel.fontSize = this._editBox.textLabel.fontSize;
  9992. };
  9993. GTextInput.prototype.updateOverflow = function () {
  9994. };
  9995. GTextInput.prototype.onTextChanged = function () {
  9996. this._text = this._editBox.string;
  9997. };
  9998. GTextInput.prototype.onTouchEnd1 = function (evt) {
  9999. this._editBox.openKeyboard(evt.touch);
  10000. };
  10001. GTextInput.prototype.setup_beforeAdd = function (buffer, beginPos) {
  10002. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  10003. buffer.seek(beginPos, 4);
  10004. var str = buffer.readS();
  10005. if (str != null)
  10006. this.promptText = str;
  10007. str = buffer.readS();
  10008. if (str != null)
  10009. this.restrict = str;
  10010. var iv = buffer.readInt();
  10011. if (iv != 0)
  10012. this.maxLength = iv;
  10013. iv = buffer.readInt();
  10014. if (iv != 0) {
  10015. }
  10016. if (buffer.readBool())
  10017. this.password = true;
  10018. if (this._editBox.placeholderLabel) {
  10019. var hAlign = this._editBox.textLabel.horizontalAlign;
  10020. this._editBox.placeholderLabel.horizontalAlign = hAlign;
  10021. var vAlign = this._editBox.textLabel.verticalAlign;
  10022. this._editBox.placeholderLabel.verticalAlign = vAlign;
  10023. }
  10024. };
  10025. return GTextInput;
  10026. }(fgui.GTextField));
  10027. fgui.GTextInput = GTextInput;
  10028. var MyEditBox = (function (_super) {
  10029. __extends(MyEditBox, _super);
  10030. function MyEditBox() {
  10031. return _super !== null && _super.apply(this, arguments) || this;
  10032. }
  10033. MyEditBox.prototype._registerEvent = function () {
  10034. };
  10035. MyEditBox.prototype._syncSize = function () {
  10036. var size = this.node.getContentSize();
  10037. var impl = this["_impl"];
  10038. impl.setSize(size.width, size.height);
  10039. if (this.textLabel)
  10040. this.textLabel.node.setContentSize(size.width, size.height);
  10041. if (this.placeholderLabel)
  10042. this.placeholderLabel.node.setContentSize(size.width, size.height);
  10043. };
  10044. MyEditBox.prototype.openKeyboard = function (touch) {
  10045. var impl = this["_impl"];
  10046. if (impl) {
  10047. impl.beginEditing();
  10048. }
  10049. };
  10050. return MyEditBox;
  10051. }(cc.EditBox));
  10052. })(fgui || (fgui = {}));
  10053. (function (fgui) {
  10054. var GTree = (function (_super) {
  10055. __extends(GTree, _super);
  10056. function GTree() {
  10057. var _this = _super.call(this) || this;
  10058. _this._indent = 15;
  10059. _this._rootNode = new fgui.GTreeNode(true);
  10060. _this._rootNode._setTree(_this);
  10061. _this._rootNode.expanded = true;
  10062. return _this;
  10063. }
  10064. Object.defineProperty(GTree.prototype, "rootNode", {
  10065. get: function () {
  10066. return this._rootNode;
  10067. },
  10068. enumerable: false,
  10069. configurable: true
  10070. });
  10071. Object.defineProperty(GTree.prototype, "indent", {
  10072. get: function () {
  10073. return this._indent;
  10074. },
  10075. set: function (value) {
  10076. this._indent = value;
  10077. },
  10078. enumerable: false,
  10079. configurable: true
  10080. });
  10081. Object.defineProperty(GTree.prototype, "clickToExpand", {
  10082. get: function () {
  10083. return this._clickToExpand;
  10084. },
  10085. set: function (value) {
  10086. this._clickToExpand = value;
  10087. },
  10088. enumerable: false,
  10089. configurable: true
  10090. });
  10091. GTree.prototype.getSelectedNode = function () {
  10092. if (this.selectedIndex != -1)
  10093. return this.getChildAt(this.selectedIndex)._treeNode;
  10094. else
  10095. return null;
  10096. };
  10097. GTree.prototype.getSelectedNodes = function (result) {
  10098. if (!result)
  10099. result = new Array();
  10100. s_list.length = 0;
  10101. _super.prototype.getSelection.call(this, s_list);
  10102. var cnt = s_list.length;
  10103. var ret = new Array();
  10104. for (var i = 0; i < cnt; i++) {
  10105. var node = this.getChildAt(s_list[i])._treeNode;
  10106. ret.push(node);
  10107. }
  10108. return ret;
  10109. };
  10110. GTree.prototype.selectNode = function (node, scrollItToView) {
  10111. var parentNode = node.parent;
  10112. while (parentNode && parentNode != this._rootNode) {
  10113. parentNode.expanded = true;
  10114. parentNode = parentNode.parent;
  10115. }
  10116. if (!node._cell)
  10117. return;
  10118. this.addSelection(this.getChildIndex(node._cell), scrollItToView);
  10119. };
  10120. GTree.prototype.unselectNode = function (node) {
  10121. if (!node._cell)
  10122. return;
  10123. this.removeSelection(this.getChildIndex(node._cell));
  10124. };
  10125. GTree.prototype.expandAll = function (folderNode) {
  10126. if (!folderNode)
  10127. folderNode = this._rootNode;
  10128. folderNode.expanded = true;
  10129. var cnt = folderNode.numChildren;
  10130. for (var i = 0; i < cnt; i++) {
  10131. var node = folderNode.getChildAt(i);
  10132. if (node.isFolder)
  10133. this.expandAll(node);
  10134. }
  10135. };
  10136. GTree.prototype.collapseAll = function (folderNode) {
  10137. if (!folderNode)
  10138. folderNode = this._rootNode;
  10139. if (folderNode != this._rootNode)
  10140. folderNode.expanded = false;
  10141. var cnt = folderNode.numChildren;
  10142. for (var i = 0; i < cnt; i++) {
  10143. var node = folderNode.getChildAt(i);
  10144. if (node.isFolder)
  10145. this.collapseAll(node);
  10146. }
  10147. };
  10148. GTree.prototype.createCell = function (node) {
  10149. var child = this.getFromPool(node._resURL);
  10150. if (!(child instanceof fgui.GComponent))
  10151. throw new Error("cannot create tree node object.");
  10152. child._treeNode = node;
  10153. node._cell = child;
  10154. var indentObj = child.getChild("indent");
  10155. if (indentObj)
  10156. indentObj.width = (node.level - 1) * this._indent;
  10157. var cc;
  10158. cc = child.getController("expanded");
  10159. if (cc) {
  10160. cc.on(fgui.Event.STATUS_CHANGED, this.__expandedStateChanged, this);
  10161. cc.selectedIndex = node.expanded ? 1 : 0;
  10162. }
  10163. cc = child.getController("leaf");
  10164. if (cc)
  10165. cc.selectedIndex = node.isFolder ? 0 : 1;
  10166. if (node.isFolder)
  10167. node._cell.on(fgui.Event.TOUCH_BEGIN, this.__cellMouseDown, this);
  10168. if (this.treeNodeRender)
  10169. this.treeNodeRender(node, child);
  10170. };
  10171. GTree.prototype._afterInserted = function (node) {
  10172. if (!node._cell)
  10173. this.createCell(node);
  10174. var index = this.getInsertIndexForNode(node);
  10175. this.addChildAt(node._cell, index);
  10176. if (this.treeNodeRender)
  10177. this.treeNodeRender(node, node._cell);
  10178. if (node.isFolder && node.expanded)
  10179. this.checkChildren(node, index);
  10180. };
  10181. GTree.prototype.getInsertIndexForNode = function (node) {
  10182. var prevNode = node.getPrevSibling();
  10183. if (prevNode == null)
  10184. prevNode = node.parent;
  10185. var insertIndex = this.getChildIndex(prevNode._cell) + 1;
  10186. var myLevel = node.level;
  10187. var cnt = this.numChildren;
  10188. for (var i = insertIndex; i < cnt; i++) {
  10189. var testNode = this.getChildAt(i)._treeNode;
  10190. if (testNode.level <= myLevel)
  10191. break;
  10192. insertIndex++;
  10193. }
  10194. return insertIndex;
  10195. };
  10196. GTree.prototype._afterRemoved = function (node) {
  10197. this.removeNode(node);
  10198. };
  10199. GTree.prototype._afterExpanded = function (node) {
  10200. if (node == this._rootNode) {
  10201. this.checkChildren(this._rootNode, 0);
  10202. return;
  10203. }
  10204. if (this.treeNodeWillExpand != null)
  10205. this.treeNodeWillExpand(node, true);
  10206. if (node._cell == null)
  10207. return;
  10208. if (this.treeNodeRender)
  10209. this.treeNodeRender(node, node._cell);
  10210. var cc = node._cell.getController("expanded");
  10211. if (cc)
  10212. cc.selectedIndex = 1;
  10213. if (node._cell.parent)
  10214. this.checkChildren(node, this.getChildIndex(node._cell));
  10215. };
  10216. GTree.prototype._afterCollapsed = function (node) {
  10217. if (node == this._rootNode) {
  10218. this.checkChildren(this._rootNode, 0);
  10219. return;
  10220. }
  10221. if (this.treeNodeWillExpand)
  10222. this.treeNodeWillExpand(node, false);
  10223. if (node._cell == null)
  10224. return;
  10225. if (this.treeNodeRender)
  10226. this.treeNodeRender(node, node._cell);
  10227. var cc = node._cell.getController("expanded");
  10228. if (cc)
  10229. cc.selectedIndex = 0;
  10230. if (node._cell.parent)
  10231. this.hideFolderNode(node);
  10232. };
  10233. GTree.prototype._afterMoved = function (node) {
  10234. var startIndex = this.getChildIndex(node._cell);
  10235. var endIndex;
  10236. if (node.isFolder)
  10237. endIndex = this.getFolderEndIndex(startIndex, node.level);
  10238. else
  10239. endIndex = startIndex + 1;
  10240. var insertIndex = this.getInsertIndexForNode(node);
  10241. var i;
  10242. var cnt = endIndex - startIndex;
  10243. var obj;
  10244. if (insertIndex < startIndex) {
  10245. for (i = 0; i < cnt; i++) {
  10246. obj = this.getChildAt(startIndex + i);
  10247. this.setChildIndex(obj, insertIndex + i);
  10248. }
  10249. }
  10250. else {
  10251. for (i = 0; i < cnt; i++) {
  10252. obj = this.getChildAt(startIndex);
  10253. this.setChildIndex(obj, insertIndex);
  10254. }
  10255. }
  10256. };
  10257. GTree.prototype.getFolderEndIndex = function (startIndex, level) {
  10258. var cnt = this.numChildren;
  10259. for (var i = startIndex + 1; i < cnt; i++) {
  10260. var node = this.getChildAt(i)._treeNode;
  10261. if (node.level <= level)
  10262. return i;
  10263. }
  10264. return cnt;
  10265. };
  10266. GTree.prototype.checkChildren = function (folderNode, index) {
  10267. var cnt = folderNode.numChildren;
  10268. for (var i = 0; i < cnt; i++) {
  10269. index++;
  10270. var node = folderNode.getChildAt(i);
  10271. if (node._cell == null)
  10272. this.createCell(node);
  10273. if (!node._cell.parent)
  10274. this.addChildAt(node._cell, index);
  10275. if (node.isFolder && node.expanded)
  10276. index = this.checkChildren(node, index);
  10277. }
  10278. return index;
  10279. };
  10280. GTree.prototype.hideFolderNode = function (folderNode) {
  10281. var cnt = folderNode.numChildren;
  10282. for (var i = 0; i < cnt; i++) {
  10283. var node = folderNode.getChildAt(i);
  10284. if (node._cell)
  10285. this.removeChild(node._cell);
  10286. if (node.isFolder && node.expanded)
  10287. this.hideFolderNode(node);
  10288. }
  10289. };
  10290. GTree.prototype.removeNode = function (node) {
  10291. if (node._cell) {
  10292. if (node._cell.parent)
  10293. this.removeChild(node._cell);
  10294. this.returnToPool(node._cell);
  10295. node._cell._treeNode = null;
  10296. node._cell = null;
  10297. }
  10298. if (node.isFolder) {
  10299. var cnt = node.numChildren;
  10300. for (var i = 0; i < cnt; i++) {
  10301. var node2 = node.getChildAt(i);
  10302. this.removeNode(node2);
  10303. }
  10304. }
  10305. };
  10306. GTree.prototype.__cellMouseDown = function (evt) {
  10307. var node = fgui.GObject.cast(evt.currentTarget)._treeNode;
  10308. this._expandedStatusInEvt = node.expanded;
  10309. };
  10310. GTree.prototype.__expandedStateChanged = function (cc) {
  10311. var node = cc.parent._treeNode;
  10312. node.expanded = cc.selectedIndex == 1;
  10313. };
  10314. GTree.prototype.dispatchItemEvent = function (item, evt) {
  10315. if (this._clickToExpand != 0) {
  10316. var node = item._treeNode;
  10317. if (node && this._expandedStatusInEvt == node.expanded) {
  10318. if (this._clickToExpand == 2) {
  10319. }
  10320. else
  10321. node.expanded = !node.expanded;
  10322. }
  10323. }
  10324. _super.prototype.dispatchItemEvent.call(this, item, evt);
  10325. };
  10326. GTree.prototype.setup_beforeAdd = function (buffer, beginPos) {
  10327. _super.prototype.setup_beforeAdd.call(this, buffer, beginPos);
  10328. buffer.seek(beginPos, 9);
  10329. this._indent = buffer.readInt();
  10330. this._clickToExpand = buffer.readByte();
  10331. };
  10332. GTree.prototype.readItems = function (buffer) {
  10333. var cnt;
  10334. var i;
  10335. var nextPos;
  10336. var str;
  10337. var isFolder;
  10338. var lastNode;
  10339. var level;
  10340. var prevLevel = 0;
  10341. cnt = buffer.readShort();
  10342. for (i = 0; i < cnt; i++) {
  10343. nextPos = buffer.readShort();
  10344. nextPos += buffer.position;
  10345. str = buffer.readS();
  10346. if (str == null) {
  10347. str = this.defaultItem;
  10348. if (!str) {
  10349. buffer.position = nextPos;
  10350. continue;
  10351. }
  10352. }
  10353. isFolder = buffer.readBool();
  10354. level = buffer.readByte();
  10355. var node = new fgui.GTreeNode(isFolder, str);
  10356. node.expanded = true;
  10357. if (i == 0)
  10358. this._rootNode.addChild(node);
  10359. else {
  10360. if (level > prevLevel)
  10361. lastNode.addChild(node);
  10362. else if (level < prevLevel) {
  10363. for (var j = level; j <= prevLevel; j++)
  10364. lastNode = lastNode.parent;
  10365. lastNode.addChild(node);
  10366. }
  10367. else
  10368. lastNode.parent.addChild(node);
  10369. }
  10370. lastNode = node;
  10371. prevLevel = level;
  10372. this.setupItem(buffer, node.cell);
  10373. buffer.position = nextPos;
  10374. }
  10375. };
  10376. return GTree;
  10377. }(fgui.GList));
  10378. fgui.GTree = GTree;
  10379. var s_list = new Array();
  10380. })(fgui || (fgui = {}));
  10381. (function (fgui) {
  10382. var GTreeNode = (function () {
  10383. function GTreeNode(hasChild, resURL) {
  10384. this._level = 0;
  10385. this._resURL = resURL;
  10386. if (hasChild)
  10387. this._children = new Array();
  10388. }
  10389. Object.defineProperty(GTreeNode.prototype, "expanded", {
  10390. get: function () {
  10391. return this._expanded;
  10392. },
  10393. set: function (value) {
  10394. if (this._children == null)
  10395. return;
  10396. if (this._expanded != value) {
  10397. this._expanded = value;
  10398. if (this._tree) {
  10399. if (this._expanded)
  10400. this._tree._afterExpanded(this);
  10401. else
  10402. this._tree._afterCollapsed(this);
  10403. }
  10404. }
  10405. },
  10406. enumerable: false,
  10407. configurable: true
  10408. });
  10409. Object.defineProperty(GTreeNode.prototype, "isFolder", {
  10410. get: function () {
  10411. return this._children != null;
  10412. },
  10413. enumerable: false,
  10414. configurable: true
  10415. });
  10416. Object.defineProperty(GTreeNode.prototype, "parent", {
  10417. get: function () {
  10418. return this._parent;
  10419. },
  10420. enumerable: false,
  10421. configurable: true
  10422. });
  10423. Object.defineProperty(GTreeNode.prototype, "text", {
  10424. get: function () {
  10425. if (this._cell)
  10426. return this._cell.text;
  10427. else
  10428. return null;
  10429. },
  10430. set: function (value) {
  10431. if (this._cell)
  10432. this._cell.text = value;
  10433. },
  10434. enumerable: false,
  10435. configurable: true
  10436. });
  10437. Object.defineProperty(GTreeNode.prototype, "icon", {
  10438. get: function () {
  10439. if (this._cell)
  10440. return this._cell.icon;
  10441. else
  10442. return null;
  10443. },
  10444. set: function (value) {
  10445. if (this._cell)
  10446. this._cell.icon = value;
  10447. },
  10448. enumerable: false,
  10449. configurable: true
  10450. });
  10451. Object.defineProperty(GTreeNode.prototype, "cell", {
  10452. get: function () {
  10453. return this._cell;
  10454. },
  10455. enumerable: false,
  10456. configurable: true
  10457. });
  10458. Object.defineProperty(GTreeNode.prototype, "level", {
  10459. get: function () {
  10460. return this._level;
  10461. },
  10462. enumerable: false,
  10463. configurable: true
  10464. });
  10465. GTreeNode.prototype._setLevel = function (value) {
  10466. this._level = value;
  10467. };
  10468. GTreeNode.prototype.addChild = function (child) {
  10469. this.addChildAt(child, this._children.length);
  10470. return child;
  10471. };
  10472. GTreeNode.prototype.addChildAt = function (child, index) {
  10473. if (!child)
  10474. throw new Error("child is null");
  10475. var numChildren = this._children.length;
  10476. if (index >= 0 && index <= numChildren) {
  10477. if (child._parent == this) {
  10478. this.setChildIndex(child, index);
  10479. }
  10480. else {
  10481. if (child._parent)
  10482. child._parent.removeChild(child);
  10483. var cnt = this._children.length;
  10484. if (index == cnt)
  10485. this._children.push(child);
  10486. else
  10487. this._children.splice(index, 0, child);
  10488. child._parent = this;
  10489. child._level = this._level + 1;
  10490. child._setTree(this._tree);
  10491. if (this._tree && this == this._tree.rootNode || this._cell && this._cell.parent && this._expanded)
  10492. this._tree._afterInserted(child);
  10493. }
  10494. return child;
  10495. }
  10496. else {
  10497. throw new RangeError("Invalid child index");
  10498. }
  10499. };
  10500. GTreeNode.prototype.removeChild = function (child) {
  10501. var childIndex = this._children.indexOf(child);
  10502. if (childIndex != -1) {
  10503. this.removeChildAt(childIndex);
  10504. }
  10505. return child;
  10506. };
  10507. GTreeNode.prototype.removeChildAt = function (index) {
  10508. if (index >= 0 && index < this.numChildren) {
  10509. var child = this._children[index];
  10510. this._children.splice(index, 1);
  10511. child._parent = null;
  10512. if (this._tree) {
  10513. child._setTree(null);
  10514. this._tree._afterRemoved(child);
  10515. }
  10516. return child;
  10517. }
  10518. else {
  10519. throw "Invalid child index";
  10520. }
  10521. };
  10522. GTreeNode.prototype.removeChildren = function (beginIndex, endIndex) {
  10523. beginIndex = beginIndex || 0;
  10524. if (endIndex == null)
  10525. endIndex = -1;
  10526. if (endIndex < 0 || endIndex >= this.numChildren)
  10527. endIndex = this.numChildren - 1;
  10528. for (var i = beginIndex; i <= endIndex; ++i)
  10529. this.removeChildAt(beginIndex);
  10530. };
  10531. GTreeNode.prototype.getChildAt = function (index) {
  10532. if (index >= 0 && index < this.numChildren)
  10533. return this._children[index];
  10534. else
  10535. throw "Invalid child index";
  10536. };
  10537. GTreeNode.prototype.getChildIndex = function (child) {
  10538. return this._children.indexOf(child);
  10539. };
  10540. GTreeNode.prototype.getPrevSibling = function () {
  10541. if (this._parent == null)
  10542. return null;
  10543. var i = this._parent._children.indexOf(this);
  10544. if (i <= 0)
  10545. return null;
  10546. return this._parent._children[i - 1];
  10547. };
  10548. GTreeNode.prototype.getNextSibling = function () {
  10549. if (this._parent == null)
  10550. return null;
  10551. var i = this._parent._children.indexOf(this);
  10552. if (i < 0 || i >= this._parent._children.length - 1)
  10553. return null;
  10554. return this._parent._children[i + 1];
  10555. };
  10556. GTreeNode.prototype.setChildIndex = function (child, index) {
  10557. var oldIndex = this._children.indexOf(child);
  10558. if (oldIndex == -1)
  10559. throw "Not a child of this container";
  10560. var cnt = this._children.length;
  10561. if (index < 0)
  10562. index = 0;
  10563. else if (index > cnt)
  10564. index = cnt;
  10565. if (oldIndex == index)
  10566. return;
  10567. this._children.splice(oldIndex, 1);
  10568. this._children.splice(index, 0, child);
  10569. if (this._tree && this == this._tree.rootNode || this._cell && this._cell.parent && this._expanded)
  10570. this._tree._afterMoved(child);
  10571. };
  10572. GTreeNode.prototype.swapChildren = function (child1, child2) {
  10573. var index1 = this._children.indexOf(child1);
  10574. var index2 = this._children.indexOf(child2);
  10575. if (index1 == -1 || index2 == -1)
  10576. throw "Not a child of this container";
  10577. this.swapChildrenAt(index1, index2);
  10578. };
  10579. GTreeNode.prototype.swapChildrenAt = function (index1, index2) {
  10580. var child1 = this._children[index1];
  10581. var child2 = this._children[index2];
  10582. this.setChildIndex(child1, index2);
  10583. this.setChildIndex(child2, index1);
  10584. };
  10585. Object.defineProperty(GTreeNode.prototype, "numChildren", {
  10586. get: function () {
  10587. return this._children.length;
  10588. },
  10589. enumerable: false,
  10590. configurable: true
  10591. });
  10592. GTreeNode.prototype.expandToRoot = function () {
  10593. var p = this;
  10594. while (p) {
  10595. p.expanded = true;
  10596. p = p.parent;
  10597. }
  10598. };
  10599. Object.defineProperty(GTreeNode.prototype, "tree", {
  10600. get: function () {
  10601. return this._tree;
  10602. },
  10603. enumerable: false,
  10604. configurable: true
  10605. });
  10606. GTreeNode.prototype._setTree = function (value) {
  10607. this._tree = value;
  10608. if (this._tree && this._tree.treeNodeWillExpand && this._expanded)
  10609. this._tree.treeNodeWillExpand(this, true);
  10610. if (this._children) {
  10611. var cnt = this._children.length;
  10612. for (var i = 0; i < cnt; i++) {
  10613. var node = this._children[i];
  10614. node._level = this._level + 1;
  10615. node._setTree(value);
  10616. }
  10617. }
  10618. };
  10619. return GTreeNode;
  10620. }());
  10621. fgui.GTreeNode = GTreeNode;
  10622. })(fgui || (fgui = {}));
  10623. (function (fgui) {
  10624. var Margin = (function () {
  10625. function Margin() {
  10626. this.left = 0;
  10627. this.right = 0;
  10628. this.top = 0;
  10629. this.bottom = 0;
  10630. }
  10631. Margin.prototype.copy = function (source) {
  10632. this.top = source.top;
  10633. this.bottom = source.bottom;
  10634. this.left = source.left;
  10635. this.right = source.right;
  10636. };
  10637. Margin.prototype.isNone = function () {
  10638. return this.left == 0 && this.right == 0 && this.top == 0 && this.bottom == 0;
  10639. };
  10640. return Margin;
  10641. }());
  10642. fgui.Margin = Margin;
  10643. })(fgui || (fgui = {}));
  10644. (function (fgui) {
  10645. var PackageItem = (function () {
  10646. function PackageItem() {
  10647. this.width = 0;
  10648. this.height = 0;
  10649. }
  10650. PackageItem.prototype.load = function () {
  10651. return this.owner.getItemAsset(this);
  10652. };
  10653. PackageItem.prototype.getBranch = function () {
  10654. if (this.branches && this.owner._branchIndex != -1) {
  10655. var itemId = this.branches[this.owner._branchIndex];
  10656. if (itemId)
  10657. return this.owner.getItemById(itemId);
  10658. }
  10659. return this;
  10660. };
  10661. PackageItem.prototype.getHighResolution = function () {
  10662. if (this.highResolution && fgui.GRoot.contentScaleLevel > 0) {
  10663. var itemId = this.highResolution[fgui.GRoot.contentScaleLevel - 1];
  10664. if (itemId)
  10665. return this.owner.getItemById(itemId);
  10666. }
  10667. return this;
  10668. };
  10669. PackageItem.prototype.toString = function () {
  10670. return this.name;
  10671. };
  10672. return PackageItem;
  10673. }());
  10674. fgui.PackageItem = PackageItem;
  10675. })(fgui || (fgui = {}));
  10676. (function (fgui) {
  10677. var PopupMenu = (function () {
  10678. function PopupMenu(url) {
  10679. if (!url) {
  10680. url = fgui.UIConfig.popupMenu;
  10681. if (!url)
  10682. throw "UIConfig.popupMenu not defined";
  10683. }
  10684. this._contentPane = fgui.UIPackage.createObjectFromURL(url);
  10685. this._contentPane.on(fgui.Event.DISPLAY, this.onDisplay, this);
  10686. this._list = (this._contentPane.getChild("list"));
  10687. this._list.removeChildrenToPool();
  10688. this._list.addRelation(this._contentPane, fgui.RelationType.Width);
  10689. this._list.removeRelation(this._contentPane, fgui.RelationType.Height);
  10690. this._contentPane.addRelation(this._list, fgui.RelationType.Height);
  10691. this._list.on(fgui.Event.CLICK_ITEM, this.onClickItem, this);
  10692. }
  10693. PopupMenu.prototype.dispose = function () {
  10694. this._contentPane.dispose();
  10695. };
  10696. PopupMenu.prototype.addItem = function (caption, callback) {
  10697. var item = this._list.addItemFromPool();
  10698. item.title = caption;
  10699. item.data = callback;
  10700. item.grayed = false;
  10701. var c = item.getController("checked");
  10702. if (c)
  10703. c.selectedIndex = 0;
  10704. return item;
  10705. };
  10706. PopupMenu.prototype.addItemAt = function (caption, index, callback) {
  10707. var item = this._list.getFromPool();
  10708. this._list.addChildAt(item, index);
  10709. item.title = caption;
  10710. item.data = callback;
  10711. item.grayed = false;
  10712. var c = item.getController("checked");
  10713. if (c)
  10714. c.selectedIndex = 0;
  10715. return item;
  10716. };
  10717. PopupMenu.prototype.addSeperator = function () {
  10718. if (fgui.UIConfig.popupMenu_seperator == null)
  10719. throw "UIConfig.popupMenu_seperator not defined";
  10720. this.list.addItemFromPool(fgui.UIConfig.popupMenu_seperator);
  10721. };
  10722. PopupMenu.prototype.getItemName = function (index) {
  10723. var item = this._list.getChildAt(index);
  10724. return item.name;
  10725. };
  10726. PopupMenu.prototype.setItemText = function (name, caption) {
  10727. var item = this._list.getChild(name);
  10728. item.title = caption;
  10729. };
  10730. PopupMenu.prototype.setItemVisible = function (name, visible) {
  10731. var item = this._list.getChild(name);
  10732. if (item.visible != visible) {
  10733. item.visible = visible;
  10734. this._list.setBoundsChangedFlag();
  10735. }
  10736. };
  10737. PopupMenu.prototype.setItemGrayed = function (name, grayed) {
  10738. var item = this._list.getChild(name);
  10739. item.grayed = grayed;
  10740. };
  10741. PopupMenu.prototype.setItemCheckable = function (name, checkable) {
  10742. var item = this._list.getChild(name);
  10743. var c = item.getController("checked");
  10744. if (c) {
  10745. if (checkable) {
  10746. if (c.selectedIndex == 0)
  10747. c.selectedIndex = 1;
  10748. }
  10749. else
  10750. c.selectedIndex = 0;
  10751. }
  10752. };
  10753. PopupMenu.prototype.setItemChecked = function (name, checked) {
  10754. var item = this._list.getChild(name);
  10755. var c = item.getController("checked");
  10756. if (c)
  10757. c.selectedIndex = checked ? 2 : 1;
  10758. };
  10759. PopupMenu.prototype.isItemChecked = function (name) {
  10760. var item = this._list.getChild(name);
  10761. var c = item.getController("checked");
  10762. if (c)
  10763. return c.selectedIndex == 2;
  10764. else
  10765. return false;
  10766. };
  10767. PopupMenu.prototype.removeItem = function (name) {
  10768. var item = this._list.getChild(name);
  10769. if (item) {
  10770. var index = this._list.getChildIndex(item);
  10771. this._list.removeChildToPoolAt(index);
  10772. return true;
  10773. }
  10774. else
  10775. return false;
  10776. };
  10777. PopupMenu.prototype.clearItems = function () {
  10778. this._list.removeChildrenToPool();
  10779. };
  10780. Object.defineProperty(PopupMenu.prototype, "itemCount", {
  10781. get: function () {
  10782. return this._list.numChildren;
  10783. },
  10784. enumerable: false,
  10785. configurable: true
  10786. });
  10787. Object.defineProperty(PopupMenu.prototype, "contentPane", {
  10788. get: function () {
  10789. return this._contentPane;
  10790. },
  10791. enumerable: false,
  10792. configurable: true
  10793. });
  10794. Object.defineProperty(PopupMenu.prototype, "list", {
  10795. get: function () {
  10796. return this._list;
  10797. },
  10798. enumerable: false,
  10799. configurable: true
  10800. });
  10801. PopupMenu.prototype.show = function (target, dir) {
  10802. if (target === void 0) { target = null; }
  10803. var r = target != null ? target.root : fgui.GRoot.inst;
  10804. r.showPopup(this.contentPane, (target instanceof fgui.GRoot) ? null : target, dir);
  10805. };
  10806. PopupMenu.prototype.onClickItem = function (item, evt) {
  10807. var _this = this;
  10808. this._list._partner.callLater(function (dt) {
  10809. _this.onClickItem2(item, evt);
  10810. }, 0.1);
  10811. };
  10812. PopupMenu.prototype.onClickItem2 = function (item, evt) {
  10813. if (!(item instanceof fgui.GButton))
  10814. return;
  10815. if (item.grayed) {
  10816. this._list.selectedIndex = -1;
  10817. return;
  10818. }
  10819. var c = item.getController("checked");
  10820. if (c && c.selectedIndex != 0) {
  10821. if (c.selectedIndex == 1)
  10822. c.selectedIndex = 2;
  10823. else
  10824. c.selectedIndex = 1;
  10825. }
  10826. var r = (this._contentPane.parent);
  10827. r.hidePopup(this.contentPane);
  10828. if (item.data instanceof Function)
  10829. item.data(item, evt);
  10830. };
  10831. PopupMenu.prototype.onDisplay = function () {
  10832. this._list.selectedIndex = -1;
  10833. this._list.resizeToFit(100000, 10);
  10834. };
  10835. return PopupMenu;
  10836. }());
  10837. fgui.PopupMenu = PopupMenu;
  10838. })(fgui || (fgui = {}));
  10839. (function (fgui) {
  10840. var RelationItem = (function () {
  10841. function RelationItem(owner) {
  10842. this._owner = owner;
  10843. this._defs = new Array();
  10844. }
  10845. Object.defineProperty(RelationItem.prototype, "owner", {
  10846. get: function () {
  10847. return this._owner;
  10848. },
  10849. enumerable: false,
  10850. configurable: true
  10851. });
  10852. Object.defineProperty(RelationItem.prototype, "target", {
  10853. get: function () {
  10854. return this._target;
  10855. },
  10856. set: function (value) {
  10857. if (this._target != value) {
  10858. if (this._target)
  10859. this.releaseRefTarget(this._target);
  10860. this._target = value;
  10861. if (this._target)
  10862. this.addRefTarget(this._target);
  10863. }
  10864. },
  10865. enumerable: false,
  10866. configurable: true
  10867. });
  10868. RelationItem.prototype.add = function (relationType, usePercent) {
  10869. if (relationType == fgui.RelationType.Size) {
  10870. this.add(fgui.RelationType.Width, usePercent);
  10871. this.add(fgui.RelationType.Height, usePercent);
  10872. return;
  10873. }
  10874. var length = this._defs.length;
  10875. for (var i = 0; i < length; i++) {
  10876. var def = this._defs[i];
  10877. if (def.type == relationType)
  10878. return;
  10879. }
  10880. this.internalAdd(relationType, usePercent);
  10881. };
  10882. RelationItem.prototype.internalAdd = function (relationType, usePercent) {
  10883. if (relationType == fgui.RelationType.Size) {
  10884. this.internalAdd(fgui.RelationType.Width, usePercent);
  10885. this.internalAdd(fgui.RelationType.Height, usePercent);
  10886. return;
  10887. }
  10888. var info = new RelationDef();
  10889. info.percent = usePercent;
  10890. info.type = relationType;
  10891. info.axis = (relationType <= fgui.RelationType.Right_Right || relationType == fgui.RelationType.Width || relationType >= fgui.RelationType.LeftExt_Left && relationType <= fgui.RelationType.RightExt_Right) ? 0 : 1;
  10892. this._defs.push(info);
  10893. };
  10894. RelationItem.prototype.remove = function (relationType) {
  10895. if (relationType == fgui.RelationType.Size) {
  10896. this.remove(fgui.RelationType.Width);
  10897. this.remove(fgui.RelationType.Height);
  10898. return;
  10899. }
  10900. var dc = this._defs.length;
  10901. for (var k = 0; k < dc; k++) {
  10902. if (this._defs[k].type == relationType) {
  10903. this._defs.splice(k, 1);
  10904. break;
  10905. }
  10906. }
  10907. };
  10908. RelationItem.prototype.copyFrom = function (source) {
  10909. this.target = source.target;
  10910. this._defs.length = 0;
  10911. var length = source._defs.length;
  10912. for (var i = 0; i < length; i++) {
  10913. var info = source._defs[i];
  10914. var info2 = new RelationDef();
  10915. info2.copyFrom(info);
  10916. this._defs.push(info2);
  10917. }
  10918. };
  10919. RelationItem.prototype.dispose = function () {
  10920. if (this._target) {
  10921. this.releaseRefTarget(this._target);
  10922. this._target = null;
  10923. }
  10924. };
  10925. Object.defineProperty(RelationItem.prototype, "isEmpty", {
  10926. get: function () {
  10927. return this._defs.length == 0;
  10928. },
  10929. enumerable: false,
  10930. configurable: true
  10931. });
  10932. RelationItem.prototype.applyOnSelfResized = function (dWidth, dHeight, applyPivot) {
  10933. var ox = this._owner.x;
  10934. var oy = this._owner.y;
  10935. var length = this._defs.length;
  10936. for (var i = 0; i < length; i++) {
  10937. var info = this._defs[i];
  10938. switch (info.type) {
  10939. case fgui.RelationType.Center_Center:
  10940. this._owner.x -= (0.5 - (applyPivot ? this._owner.pivotX : 0)) * dWidth;
  10941. break;
  10942. case fgui.RelationType.Right_Center:
  10943. case fgui.RelationType.Right_Left:
  10944. case fgui.RelationType.Right_Right:
  10945. this._owner.x -= (1 - (applyPivot ? this._owner.pivotX : 0)) * dWidth;
  10946. break;
  10947. case fgui.RelationType.Middle_Middle:
  10948. this._owner.y -= (0.5 - (applyPivot ? this._owner.pivotY : 0)) * dHeight;
  10949. break;
  10950. case fgui.RelationType.Bottom_Middle:
  10951. case fgui.RelationType.Bottom_Top:
  10952. case fgui.RelationType.Bottom_Bottom:
  10953. this._owner.y -= (1 - (applyPivot ? this._owner.pivotY : 0)) * dHeight;
  10954. break;
  10955. }
  10956. }
  10957. if (ox != this._owner.x || oy != this._owner.y) {
  10958. ox = this._owner.x - ox;
  10959. oy = this._owner.y - oy;
  10960. this._owner.updateGearFromRelations(1, ox, oy);
  10961. if (this._owner.parent) {
  10962. var len = this._owner.parent._transitions.length;
  10963. if (len > 0) {
  10964. for (var i = 0; i < len; ++i) {
  10965. this._owner.parent._transitions[i].updateFromRelations(this._owner.id, ox, oy);
  10966. }
  10967. }
  10968. }
  10969. }
  10970. };
  10971. RelationItem.prototype.applyOnXYChanged = function (info, dx, dy) {
  10972. var tmp;
  10973. switch (info.type) {
  10974. case fgui.RelationType.Left_Left:
  10975. case fgui.RelationType.Left_Center:
  10976. case fgui.RelationType.Left_Right:
  10977. case fgui.RelationType.Center_Center:
  10978. case fgui.RelationType.Right_Left:
  10979. case fgui.RelationType.Right_Center:
  10980. case fgui.RelationType.Right_Right:
  10981. this._owner.x += dx;
  10982. break;
  10983. case fgui.RelationType.Top_Top:
  10984. case fgui.RelationType.Top_Middle:
  10985. case fgui.RelationType.Top_Bottom:
  10986. case fgui.RelationType.Middle_Middle:
  10987. case fgui.RelationType.Bottom_Top:
  10988. case fgui.RelationType.Bottom_Middle:
  10989. case fgui.RelationType.Bottom_Bottom:
  10990. this._owner.y += dy;
  10991. break;
  10992. case fgui.RelationType.Width:
  10993. case fgui.RelationType.Height:
  10994. break;
  10995. case fgui.RelationType.LeftExt_Left:
  10996. case fgui.RelationType.LeftExt_Right:
  10997. if (this._owner != this._target.parent) {
  10998. tmp = this._owner.xMin;
  10999. this._owner.width = this._owner._rawWidth - dx;
  11000. this._owner.xMin = tmp + dx;
  11001. }
  11002. else
  11003. this._owner.width = this._owner._rawWidth - dx;
  11004. break;
  11005. case fgui.RelationType.RightExt_Left:
  11006. case fgui.RelationType.RightExt_Right:
  11007. if (this._owner != this._target.parent) {
  11008. tmp = this._owner.xMin;
  11009. this._owner.width = this._owner._rawWidth + dx;
  11010. this._owner.xMin = tmp;
  11011. }
  11012. else
  11013. this._owner.width = this._owner._rawWidth + dx;
  11014. break;
  11015. case fgui.RelationType.TopExt_Top:
  11016. case fgui.RelationType.TopExt_Bottom:
  11017. if (this._owner != this._target.parent) {
  11018. tmp = this._owner.yMin;
  11019. this._owner.height = this._owner._rawHeight - dy;
  11020. this._owner.yMin = tmp + dy;
  11021. }
  11022. else
  11023. this._owner.height = this._owner._rawHeight - dy;
  11024. break;
  11025. case fgui.RelationType.BottomExt_Top:
  11026. case fgui.RelationType.BottomExt_Bottom:
  11027. if (this._owner != this._target.parent) {
  11028. tmp = this._owner.yMin;
  11029. this._owner.height = this._owner._rawHeight + dy;
  11030. this._owner.yMin = tmp;
  11031. }
  11032. else
  11033. this._owner.height = this._owner._rawHeight + dy;
  11034. break;
  11035. }
  11036. };
  11037. RelationItem.prototype.applyOnSizeChanged = function (info) {
  11038. var pos = 0, pivot = 0, delta = 0;
  11039. var v, tmp;
  11040. if (info.axis == 0) {
  11041. if (this._target != this._owner.parent) {
  11042. pos = this._target.x;
  11043. if (this._target.pivotAsAnchor)
  11044. pivot = this._target.pivotX;
  11045. }
  11046. if (info.percent) {
  11047. if (this._targetWidth != 0)
  11048. delta = this._target._width / this._targetWidth;
  11049. }
  11050. else
  11051. delta = this._target._width - this._targetWidth;
  11052. }
  11053. else {
  11054. if (this._target != this._owner.parent) {
  11055. pos = this._target.y;
  11056. if (this._target.pivotAsAnchor)
  11057. pivot = this._target.pivotY;
  11058. }
  11059. if (info.percent) {
  11060. if (this._targetHeight != 0)
  11061. delta = this._target._height / this._targetHeight;
  11062. }
  11063. else
  11064. delta = this._target._height - this._targetHeight;
  11065. }
  11066. switch (info.type) {
  11067. case fgui.RelationType.Left_Left:
  11068. if (info.percent)
  11069. this._owner.xMin = pos + (this._owner.xMin - pos) * delta;
  11070. else if (pivot != 0)
  11071. this._owner.x += delta * (-pivot);
  11072. break;
  11073. case fgui.RelationType.Left_Center:
  11074. if (info.percent)
  11075. this._owner.xMin = pos + (this._owner.xMin - pos) * delta;
  11076. else
  11077. this._owner.x += delta * (0.5 - pivot);
  11078. break;
  11079. case fgui.RelationType.Left_Right:
  11080. if (info.percent)
  11081. this._owner.xMin = pos + (this._owner.xMin - pos) * delta;
  11082. else
  11083. this._owner.x += delta * (1 - pivot);
  11084. break;
  11085. case fgui.RelationType.Center_Center:
  11086. if (info.percent)
  11087. this._owner.xMin = pos + (this._owner.xMin + this._owner._rawWidth * 0.5 - pos) * delta - this._owner._rawWidth * 0.5;
  11088. else
  11089. this._owner.x += delta * (0.5 - pivot);
  11090. break;
  11091. case fgui.RelationType.Right_Left:
  11092. if (info.percent)
  11093. this._owner.xMin = pos + (this._owner.xMin + this._owner._rawWidth - pos) * delta - this._owner._rawWidth;
  11094. else if (pivot != 0)
  11095. this._owner.x += delta * (-pivot);
  11096. break;
  11097. case fgui.RelationType.Right_Center:
  11098. if (info.percent)
  11099. this._owner.xMin = pos + (this._owner.xMin + this._owner._rawWidth - pos) * delta - this._owner._rawWidth;
  11100. else
  11101. this._owner.x += delta * (0.5 - pivot);
  11102. break;
  11103. case fgui.RelationType.Right_Right:
  11104. if (info.percent)
  11105. this._owner.xMin = pos + (this._owner.xMin + this._owner._rawWidth - pos) * delta - this._owner._rawWidth;
  11106. else
  11107. this._owner.x += delta * (1 - pivot);
  11108. break;
  11109. case fgui.RelationType.Top_Top:
  11110. if (info.percent)
  11111. this._owner.yMin = pos + (this._owner.yMin - pos) * delta;
  11112. else if (pivot != 0)
  11113. this._owner.y += delta * (-pivot);
  11114. break;
  11115. case fgui.RelationType.Top_Middle:
  11116. if (info.percent)
  11117. this._owner.yMin = pos + (this._owner.yMin - pos) * delta;
  11118. else
  11119. this._owner.y += delta * (0.5 - pivot);
  11120. break;
  11121. case fgui.RelationType.Top_Bottom:
  11122. if (info.percent)
  11123. this._owner.yMin = pos + (this._owner.yMin - pos) * delta;
  11124. else
  11125. this._owner.y += delta * (1 - pivot);
  11126. break;
  11127. case fgui.RelationType.Middle_Middle:
  11128. if (info.percent)
  11129. this._owner.yMin = pos + (this._owner.yMin + this._owner._rawHeight * 0.5 - pos) * delta - this._owner._rawHeight * 0.5;
  11130. else
  11131. this._owner.y += delta * (0.5 - pivot);
  11132. break;
  11133. case fgui.RelationType.Bottom_Top:
  11134. if (info.percent)
  11135. this._owner.yMin = pos + (this._owner.yMin + this._owner._rawHeight - pos) * delta - this._owner._rawHeight;
  11136. else if (pivot != 0)
  11137. this._owner.y += delta * (-pivot);
  11138. break;
  11139. case fgui.RelationType.Bottom_Middle:
  11140. if (info.percent)
  11141. this._owner.yMin = pos + (this._owner.yMin + this._owner._rawHeight - pos) * delta - this._owner._rawHeight;
  11142. else
  11143. this._owner.y += delta * (0.5 - pivot);
  11144. break;
  11145. case fgui.RelationType.Bottom_Bottom:
  11146. if (info.percent)
  11147. this._owner.yMin = pos + (this._owner.yMin + this._owner._rawHeight - pos) * delta - this._owner._rawHeight;
  11148. else
  11149. this._owner.y += delta * (1 - pivot);
  11150. break;
  11151. case fgui.RelationType.Width:
  11152. if (this._owner._underConstruct && this._owner == this._target.parent)
  11153. v = this._owner.sourceWidth - this._target.initWidth;
  11154. else
  11155. v = this._owner._rawWidth - this._targetWidth;
  11156. if (info.percent)
  11157. v = v * delta;
  11158. if (this._target == this._owner.parent) {
  11159. if (this._owner.pivotAsAnchor) {
  11160. tmp = this._owner.xMin;
  11161. this._owner.setSize(this._target._width + v, this._owner._rawHeight, true);
  11162. this._owner.xMin = tmp;
  11163. }
  11164. else
  11165. this._owner.setSize(this._target._width + v, this._owner._rawHeight, true);
  11166. }
  11167. else
  11168. this._owner.width = this._target._width + v;
  11169. break;
  11170. case fgui.RelationType.Height:
  11171. if (this._owner._underConstruct && this._owner == this._target.parent)
  11172. v = this._owner.sourceHeight - this._target.initHeight;
  11173. else
  11174. v = this._owner._rawHeight - this._targetHeight;
  11175. if (info.percent)
  11176. v = v * delta;
  11177. if (this._target == this._owner.parent) {
  11178. if (this._owner.pivotAsAnchor) {
  11179. tmp = this._owner.yMin;
  11180. this._owner.setSize(this._owner._rawWidth, this._target._height + v, true);
  11181. this._owner.yMin = tmp;
  11182. }
  11183. else
  11184. this._owner.setSize(this._owner._rawWidth, this._target._height + v, true);
  11185. }
  11186. else
  11187. this._owner.height = this._target._height + v;
  11188. break;
  11189. case fgui.RelationType.LeftExt_Left:
  11190. tmp = this._owner.xMin;
  11191. if (info.percent)
  11192. v = pos + (tmp - pos) * delta - tmp;
  11193. else
  11194. v = delta * (-pivot);
  11195. this._owner.width = this._owner._rawWidth - v;
  11196. this._owner.xMin = tmp + v;
  11197. break;
  11198. case fgui.RelationType.LeftExt_Right:
  11199. tmp = this._owner.xMin;
  11200. if (info.percent)
  11201. v = pos + (tmp - pos) * delta - tmp;
  11202. else
  11203. v = delta * (1 - pivot);
  11204. this._owner.width = this._owner._rawWidth - v;
  11205. this._owner.xMin = tmp + v;
  11206. break;
  11207. case fgui.RelationType.RightExt_Left:
  11208. tmp = this._owner.xMin;
  11209. if (info.percent)
  11210. v = pos + (tmp + this._owner._rawWidth - pos) * delta - (tmp + this._owner._rawWidth);
  11211. else
  11212. v = delta * (-pivot);
  11213. this._owner.width = this._owner._rawWidth + v;
  11214. this._owner.xMin = tmp;
  11215. break;
  11216. case fgui.RelationType.RightExt_Right:
  11217. tmp = this._owner.xMin;
  11218. if (info.percent) {
  11219. if (this._owner == this._target.parent) {
  11220. if (this._owner._underConstruct)
  11221. this._owner.width = pos + this._target._width - this._target._width * pivot +
  11222. (this._owner.sourceWidth - pos - this._target.initWidth + this._target.initWidth * pivot) * delta;
  11223. else
  11224. this._owner.width = pos + (this._owner._rawWidth - pos) * delta;
  11225. }
  11226. else {
  11227. v = pos + (tmp + this._owner._rawWidth - pos) * delta - (tmp + this._owner._rawWidth);
  11228. this._owner.width = this._owner._rawWidth + v;
  11229. this._owner.xMin = tmp;
  11230. }
  11231. }
  11232. else {
  11233. if (this._owner == this._target.parent) {
  11234. if (this._owner._underConstruct)
  11235. this._owner.width = this._owner.sourceWidth + (this._target._width - this._target.initWidth) * (1 - pivot);
  11236. else
  11237. this._owner.width = this._owner._rawWidth + delta * (1 - pivot);
  11238. }
  11239. else {
  11240. v = delta * (1 - pivot);
  11241. this._owner.width = this._owner._rawWidth + v;
  11242. this._owner.xMin = tmp;
  11243. }
  11244. }
  11245. break;
  11246. case fgui.RelationType.TopExt_Top:
  11247. tmp = this._owner.yMin;
  11248. if (info.percent)
  11249. v = pos + (tmp - pos) * delta - tmp;
  11250. else
  11251. v = delta * (-pivot);
  11252. this._owner.height = this._owner._rawHeight - v;
  11253. this._owner.yMin = tmp + v;
  11254. break;
  11255. case fgui.RelationType.TopExt_Bottom:
  11256. tmp = this._owner.yMin;
  11257. if (info.percent)
  11258. v = pos + (tmp - pos) * delta - tmp;
  11259. else
  11260. v = delta * (1 - pivot);
  11261. this._owner.height = this._owner._rawHeight - v;
  11262. this._owner.yMin = tmp + v;
  11263. break;
  11264. case fgui.RelationType.BottomExt_Top:
  11265. tmp = this._owner.yMin;
  11266. if (info.percent)
  11267. v = pos + (tmp + this._owner._rawHeight - pos) * delta - (tmp + this._owner._rawHeight);
  11268. else
  11269. v = delta * (-pivot);
  11270. this._owner.height = this._owner._rawHeight + v;
  11271. this._owner.yMin = tmp;
  11272. break;
  11273. case fgui.RelationType.BottomExt_Bottom:
  11274. tmp = this._owner.yMin;
  11275. if (info.percent) {
  11276. if (this._owner == this._target.parent) {
  11277. if (this._owner._underConstruct)
  11278. this._owner.height = pos + this._target._height - this._target._height * pivot +
  11279. (this._owner.sourceHeight - pos - this._target.initHeight + this._target.initHeight * pivot) * delta;
  11280. else
  11281. this._owner.height = pos + (this._owner._rawHeight - pos) * delta;
  11282. }
  11283. else {
  11284. v = pos + (tmp + this._owner._rawHeight - pos) * delta - (tmp + this._owner._rawHeight);
  11285. this._owner.height = this._owner._rawHeight + v;
  11286. this._owner.yMin = tmp;
  11287. }
  11288. }
  11289. else {
  11290. if (this._owner == this._target.parent) {
  11291. if (this._owner._underConstruct)
  11292. this._owner.height = this._owner.sourceHeight + (this._target._height - this._target.initHeight) * (1 - pivot);
  11293. else
  11294. this._owner.height = this._owner._rawHeight + delta * (1 - pivot);
  11295. }
  11296. else {
  11297. v = delta * (1 - pivot);
  11298. this._owner.height = this._owner._rawHeight + v;
  11299. this._owner.yMin = tmp;
  11300. }
  11301. }
  11302. break;
  11303. }
  11304. };
  11305. RelationItem.prototype.addRefTarget = function (target) {
  11306. if (target != this._owner.parent)
  11307. target.on(fgui.Event.XY_CHANGED, this.__targetXYChanged, this);
  11308. target.on(fgui.Event.SIZE_CHANGED, this.__targetSizeChanged, this);
  11309. target.on(fgui.Event.SIZE_DELAY_CHANGE, this.__targetSizeWillChange, this);
  11310. this._targetX = this._target.x;
  11311. this._targetY = this._target.y;
  11312. this._targetWidth = this._target._width;
  11313. this._targetHeight = this._target._height;
  11314. };
  11315. RelationItem.prototype.releaseRefTarget = function (target) {
  11316. if (!target.node)
  11317. return;
  11318. target.off(fgui.Event.XY_CHANGED, this.__targetXYChanged, this);
  11319. target.off(fgui.Event.SIZE_CHANGED, this.__targetSizeChanged, this);
  11320. target.off(fgui.Event.SIZE_DELAY_CHANGE, this.__targetSizeWillChange, this);
  11321. };
  11322. RelationItem.prototype.__targetXYChanged = function (evt) {
  11323. if (this._owner.relations.handling != null || this._owner.group != null && this._owner.group._updating) {
  11324. this._targetX = this._target.x;
  11325. this._targetY = this._target.y;
  11326. return;
  11327. }
  11328. this._owner.relations.handling = this._target;
  11329. var ox = this._owner.x;
  11330. var oy = this._owner.y;
  11331. var dx = this._target.x - this._targetX;
  11332. var dy = this._target.y - this._targetY;
  11333. var length = this._defs.length;
  11334. for (var i = 0; i < length; i++) {
  11335. var info = this._defs[i];
  11336. this.applyOnXYChanged(info, dx, dy);
  11337. }
  11338. this._targetX = this._target.x;
  11339. this._targetY = this._target.y;
  11340. if (ox != this._owner.x || oy != this._owner.y) {
  11341. ox = this._owner.x - ox;
  11342. oy = this._owner.y - oy;
  11343. this._owner.updateGearFromRelations(1, ox, oy);
  11344. if (this._owner.parent) {
  11345. var len = this._owner.parent._transitions.length;
  11346. if (len > 0) {
  11347. for (var i = 0; i < len; ++i) {
  11348. this._owner.parent._transitions[i].updateFromRelations(this._owner.id, ox, oy);
  11349. }
  11350. }
  11351. }
  11352. }
  11353. this._owner.relations.handling = null;
  11354. };
  11355. RelationItem.prototype.__targetSizeChanged = function (evt) {
  11356. if (this._owner.relations.handling != null)
  11357. return;
  11358. this._owner.relations.handling = this._target;
  11359. var ox = this._owner.x;
  11360. var oy = this._owner.y;
  11361. var ow = this._owner._rawWidth;
  11362. var oh = this._owner._rawHeight;
  11363. var length = this._defs.length;
  11364. for (var i = 0; i < length; i++) {
  11365. var info = this._defs[i];
  11366. this.applyOnSizeChanged(info);
  11367. }
  11368. this._targetWidth = this._target._width;
  11369. this._targetHeight = this._target._height;
  11370. if (ox != this._owner.x || oy != this._owner.y) {
  11371. ox = this._owner.x - ox;
  11372. oy = this._owner.y - oy;
  11373. this._owner.updateGearFromRelations(1, ox, oy);
  11374. if (this._owner.parent) {
  11375. var len = this._owner.parent._transitions.length;
  11376. if (len > 0) {
  11377. for (var i = 0; i < len; ++i) {
  11378. this._owner.parent._transitions[i].updateFromRelations(this._owner.id, ox, oy);
  11379. }
  11380. }
  11381. }
  11382. }
  11383. if (ow != this._owner._rawWidth || oh != this._owner._rawHeight) {
  11384. ow = this._owner._rawWidth - ow;
  11385. oh = this._owner._rawHeight - oh;
  11386. this._owner.updateGearFromRelations(2, ow, oh);
  11387. }
  11388. this._owner.relations.handling = null;
  11389. };
  11390. RelationItem.prototype.__targetSizeWillChange = function (evt) {
  11391. this._owner.relations.sizeDirty = true;
  11392. };
  11393. return RelationItem;
  11394. }());
  11395. fgui.RelationItem = RelationItem;
  11396. var RelationDef = (function () {
  11397. function RelationDef() {
  11398. }
  11399. RelationDef.prototype.copyFrom = function (source) {
  11400. this.percent = source.percent;
  11401. this.type = source.type;
  11402. this.axis = source.axis;
  11403. };
  11404. return RelationDef;
  11405. }());
  11406. fgui.RelationDef = RelationDef;
  11407. })(fgui || (fgui = {}));
  11408. (function (fgui) {
  11409. var Relations = (function () {
  11410. function Relations(owner) {
  11411. this._owner = owner;
  11412. this._items = new Array();
  11413. }
  11414. Relations.prototype.add = function (target, relationType, usePercent) {
  11415. var length = this._items.length;
  11416. for (var i = 0; i < length; i++) {
  11417. var item = this._items[i];
  11418. if (item.target == target) {
  11419. item.add(relationType, usePercent);
  11420. return;
  11421. }
  11422. }
  11423. var newItem = new fgui.RelationItem(this._owner);
  11424. newItem.target = target;
  11425. newItem.add(relationType, usePercent);
  11426. this._items.push(newItem);
  11427. };
  11428. Relations.prototype.remove = function (target, relationType) {
  11429. relationType = relationType || 0;
  11430. var cnt = this._items.length;
  11431. var i = 0;
  11432. while (i < cnt) {
  11433. var item = this._items[i];
  11434. if (item.target == target) {
  11435. item.remove(relationType);
  11436. if (item.isEmpty) {
  11437. item.dispose();
  11438. this._items.splice(i, 1);
  11439. cnt--;
  11440. }
  11441. else
  11442. i++;
  11443. }
  11444. else
  11445. i++;
  11446. }
  11447. };
  11448. Relations.prototype.contains = function (target) {
  11449. var length = this._items.length;
  11450. for (var i = 0; i < length; i++) {
  11451. var item = this._items[i];
  11452. if (item.target == target)
  11453. return true;
  11454. }
  11455. return false;
  11456. };
  11457. Relations.prototype.clearFor = function (target) {
  11458. var cnt = this._items.length;
  11459. var i = 0;
  11460. while (i < cnt) {
  11461. var item = this._items[i];
  11462. if (item.target == target) {
  11463. item.dispose();
  11464. this._items.splice(i, 1);
  11465. cnt--;
  11466. }
  11467. else
  11468. i++;
  11469. }
  11470. };
  11471. Relations.prototype.clearAll = function () {
  11472. var length = this._items.length;
  11473. for (var i = 0; i < length; i++) {
  11474. var item = this._items[i];
  11475. item.dispose();
  11476. }
  11477. this._items.length = 0;
  11478. };
  11479. Relations.prototype.copyFrom = function (source) {
  11480. this.clearAll();
  11481. var arr = source._items;
  11482. var length = arr.length;
  11483. for (var i = 0; i < length; i++) {
  11484. var ri = arr[i];
  11485. var item = new fgui.RelationItem(this._owner);
  11486. item.copyFrom(ri);
  11487. this._items.push(item);
  11488. }
  11489. };
  11490. Relations.prototype.dispose = function () {
  11491. this.clearAll();
  11492. };
  11493. Relations.prototype.onOwnerSizeChanged = function (dWidth, dHeight, applyPivot) {
  11494. if (this._items.length == 0)
  11495. return;
  11496. var length = this._items.length;
  11497. for (var i = 0; i < length; i++) {
  11498. var item = this._items[i];
  11499. item.applyOnSelfResized(dWidth, dHeight, applyPivot);
  11500. }
  11501. };
  11502. Relations.prototype.ensureRelationsSizeCorrect = function () {
  11503. if (this._items.length == 0)
  11504. return;
  11505. this.sizeDirty = false;
  11506. var length = this._items.length;
  11507. for (var i = 0; i < length; i++) {
  11508. var item = this._items[i];
  11509. item.target.ensureSizeCorrect();
  11510. }
  11511. };
  11512. Object.defineProperty(Relations.prototype, "empty", {
  11513. get: function () {
  11514. return this._items.length == 0;
  11515. },
  11516. enumerable: false,
  11517. configurable: true
  11518. });
  11519. Relations.prototype.setup = function (buffer, parentToChild) {
  11520. var cnt = buffer.readByte();
  11521. var target;
  11522. for (var i = 0; i < cnt; i++) {
  11523. var targetIndex = buffer.readShort();
  11524. if (targetIndex == -1)
  11525. target = this._owner.parent;
  11526. else if (parentToChild)
  11527. target = this._owner.getChildAt(targetIndex);
  11528. else
  11529. target = this._owner.parent.getChildAt(targetIndex);
  11530. var newItem = new fgui.RelationItem(this._owner);
  11531. newItem.target = target;
  11532. this._items.push(newItem);
  11533. var cnt2 = buffer.readByte();
  11534. for (var j = 0; j < cnt2; j++) {
  11535. var rt = buffer.readByte();
  11536. var usePercent = buffer.readBool();
  11537. newItem.internalAdd(rt, usePercent);
  11538. }
  11539. }
  11540. };
  11541. return Relations;
  11542. }());
  11543. fgui.Relations = Relations;
  11544. })(fgui || (fgui = {}));
  11545. (function (fgui) {
  11546. var ScrollPane = (function (_super) {
  11547. __extends(ScrollPane, _super);
  11548. function ScrollPane() {
  11549. var _this = _super !== null && _super.apply(this, arguments) || this;
  11550. _this._aniFlag = 0;
  11551. return _this;
  11552. }
  11553. ScrollPane.prototype.setup = function (buffer) {
  11554. var o = this._owner = (this.node["$gobj"]);
  11555. this._maskContainer = new cc.Node("ScrollPane");
  11556. this._maskContainer.setAnchorPoint(0, 1);
  11557. this._maskContainer.parent = o.node;
  11558. this._container = o._container;
  11559. this._container.parent = this._maskContainer;
  11560. this._scrollBarMargin = new fgui.Margin();
  11561. this._mouseWheelEnabled = true;
  11562. this._xPos = 0;
  11563. this._yPos = 0;
  11564. this._aniFlag = 0;
  11565. this._tweening = 0;
  11566. this._footerLockedSize = 0;
  11567. this._headerLockedSize = 0;
  11568. this._viewSize = new cc.Vec2();
  11569. this._contentSize = new cc.Vec2();
  11570. this._pageSize = new cc.Vec2(1, 1);
  11571. this._overlapSize = new cc.Vec2();
  11572. this._tweenTime = new cc.Vec2();
  11573. this._tweenStart = new cc.Vec2();
  11574. this._tweenDuration = new cc.Vec2();
  11575. this._tweenChange = new cc.Vec2();
  11576. this._velocity = new cc.Vec2();
  11577. this._containerPos = new cc.Vec2();
  11578. this._beginTouchPos = new cc.Vec2();
  11579. this._lastTouchPos = new cc.Vec2();
  11580. this._lastTouchGlobalPos = new cc.Vec2();
  11581. this._scrollStep = fgui.UIConfig.defaultScrollStep;
  11582. this._mouseWheelStep = this._scrollStep * 2;
  11583. this._decelerationRate = fgui.UIConfig.defaultScrollDecelerationRate;
  11584. o.on(fgui.Event.TOUCH_BEGIN, this.onTouchBegin, this);
  11585. o.on(fgui.Event.TOUCH_MOVE, this.onTouchMove, this);
  11586. o.on(fgui.Event.TOUCH_END, this.onTouchEnd, this);
  11587. o.on(fgui.Event.MOUSE_WHEEL, this.onMouseWheel, this);
  11588. this._scrollType = buffer.readByte();
  11589. var scrollBarDisplay = buffer.readByte();
  11590. var flags = buffer.readInt();
  11591. if (buffer.readBool()) {
  11592. this._scrollBarMargin.top = buffer.readInt();
  11593. this._scrollBarMargin.bottom = buffer.readInt();
  11594. this._scrollBarMargin.left = buffer.readInt();
  11595. this._scrollBarMargin.right = buffer.readInt();
  11596. }
  11597. var vtScrollBarRes = buffer.readS();
  11598. var hzScrollBarRes = buffer.readS();
  11599. var headerRes = buffer.readS();
  11600. var footerRes = buffer.readS();
  11601. if ((flags & 1) != 0)
  11602. this._displayOnLeft = true;
  11603. if ((flags & 2) != 0)
  11604. this._snapToItem = true;
  11605. if ((flags & 4) != 0)
  11606. this._displayInDemand = true;
  11607. if ((flags & 8) != 0)
  11608. this._pageMode = true;
  11609. if (flags & 16)
  11610. this._touchEffect = true;
  11611. else if (flags & 32)
  11612. this._touchEffect = false;
  11613. else
  11614. this._touchEffect = fgui.UIConfig.defaultScrollTouchEffect;
  11615. if (flags & 64)
  11616. this._bouncebackEffect = true;
  11617. else if (flags & 128)
  11618. this._bouncebackEffect = false;
  11619. else
  11620. this._bouncebackEffect = fgui.UIConfig.defaultScrollBounceEffect;
  11621. if ((flags & 256) != 0)
  11622. this._inertiaDisabled = true;
  11623. if ((flags & 512) == 0)
  11624. this._maskContainer.addComponent(cc.Mask);
  11625. if ((flags & 1024) != 0)
  11626. this._floating = true;
  11627. if ((flags & 2048) != 0)
  11628. this._dontClipMargin = true;
  11629. if (scrollBarDisplay == fgui.ScrollBarDisplayType.Default)
  11630. scrollBarDisplay = fgui.UIConfig.defaultScrollBarDisplay;
  11631. if (scrollBarDisplay != fgui.ScrollBarDisplayType.Hidden) {
  11632. if (this._scrollType == fgui.ScrollType.Both || this._scrollType == fgui.ScrollType.Vertical) {
  11633. var res = vtScrollBarRes ? vtScrollBarRes : fgui.UIConfig.verticalScrollBar;
  11634. if (res) {
  11635. this._vtScrollBar = (fgui.UIPackage.createObjectFromURL(res));
  11636. if (!this._vtScrollBar)
  11637. throw "cannot create scrollbar from " + res;
  11638. this._vtScrollBar.setScrollPane(this, true);
  11639. this._vtScrollBar.node.parent = o.node;
  11640. }
  11641. }
  11642. if (this._scrollType == fgui.ScrollType.Both || this._scrollType == fgui.ScrollType.Horizontal) {
  11643. var res = hzScrollBarRes ? hzScrollBarRes : fgui.UIConfig.horizontalScrollBar;
  11644. if (res) {
  11645. this._hzScrollBar = (fgui.UIPackage.createObjectFromURL(res));
  11646. if (!this._hzScrollBar)
  11647. throw "cannot create scrollbar from " + res;
  11648. this._hzScrollBar.setScrollPane(this, false);
  11649. this._hzScrollBar.node.parent = o.node;
  11650. }
  11651. }
  11652. if (scrollBarDisplay == fgui.ScrollBarDisplayType.Auto)
  11653. this._scrollBarDisplayAuto = true;
  11654. if (this._scrollBarDisplayAuto) {
  11655. if (this._vtScrollBar)
  11656. this._vtScrollBar.node.active = false;
  11657. if (this._hzScrollBar)
  11658. this._hzScrollBar.node.active = false;
  11659. o.on(fgui.Event.ROLL_OVER, this.onRollOver, this);
  11660. o.on(fgui.Event.ROLL_OUT, this.onRollOut, this);
  11661. }
  11662. }
  11663. if (headerRes) {
  11664. this._header = (fgui.UIPackage.createObjectFromURL(headerRes));
  11665. if (this._header == null)
  11666. throw "cannot create scrollPane header from " + headerRes;
  11667. else
  11668. this._maskContainer.insertChild(this._header.node, 0);
  11669. }
  11670. if (footerRes) {
  11671. this._footer = (fgui.UIPackage.createObjectFromURL(footerRes));
  11672. if (this._footer == null)
  11673. throw "cannot create scrollPane footer from " + footerRes;
  11674. else
  11675. this._maskContainer.insertChild(this._footer.node, 0);
  11676. }
  11677. this._refreshBarAxis = (this._scrollType == fgui.ScrollType.Both || this._scrollType == fgui.ScrollType.Vertical) ? "y" : "x";
  11678. this.setSize(o.width, o.height);
  11679. };
  11680. ScrollPane.prototype.onDestroy = function () {
  11681. delete this._pageController;
  11682. if (this._hzScrollBar)
  11683. this._hzScrollBar.dispose();
  11684. if (this._vtScrollBar)
  11685. this._vtScrollBar.dispose();
  11686. if (this._header)
  11687. this._header.dispose();
  11688. if (this._footer)
  11689. this._footer.dispose();
  11690. };
  11691. ScrollPane.prototype.hitTest = function (pt, globalPt) {
  11692. var target;
  11693. if (this._vtScrollBar) {
  11694. target = this._vtScrollBar.hitTest(globalPt);
  11695. if (target)
  11696. return target;
  11697. }
  11698. if (this._hzScrollBar) {
  11699. target = this._hzScrollBar.hitTest(globalPt);
  11700. if (target)
  11701. return target;
  11702. }
  11703. if (this._header && this._header.node.activeInHierarchy) {
  11704. target = this._header.hitTest(globalPt);
  11705. if (target)
  11706. return target;
  11707. }
  11708. if (this._footer && this._footer.node.activeInHierarchy) {
  11709. target = this._footer.hitTest(globalPt);
  11710. if (target)
  11711. return target;
  11712. }
  11713. if (pt.x >= this._owner.margin.left && pt.y >= this._owner.margin.top
  11714. && pt.x < this._owner.margin.left + this._viewSize.x && pt.y < this._owner.margin.top + this._viewSize.y)
  11715. return this._owner;
  11716. else
  11717. return null;
  11718. };
  11719. Object.defineProperty(ScrollPane.prototype, "owner", {
  11720. get: function () {
  11721. return this._owner;
  11722. },
  11723. enumerable: false,
  11724. configurable: true
  11725. });
  11726. Object.defineProperty(ScrollPane.prototype, "hzScrollBar", {
  11727. get: function () {
  11728. return this._hzScrollBar;
  11729. },
  11730. enumerable: false,
  11731. configurable: true
  11732. });
  11733. Object.defineProperty(ScrollPane.prototype, "vtScrollBar", {
  11734. get: function () {
  11735. return this._vtScrollBar;
  11736. },
  11737. enumerable: false,
  11738. configurable: true
  11739. });
  11740. Object.defineProperty(ScrollPane.prototype, "header", {
  11741. get: function () {
  11742. return this._header;
  11743. },
  11744. enumerable: false,
  11745. configurable: true
  11746. });
  11747. Object.defineProperty(ScrollPane.prototype, "footer", {
  11748. get: function () {
  11749. return this._footer;
  11750. },
  11751. enumerable: false,
  11752. configurable: true
  11753. });
  11754. Object.defineProperty(ScrollPane.prototype, "bouncebackEffect", {
  11755. get: function () {
  11756. return this._bouncebackEffect;
  11757. },
  11758. set: function (sc) {
  11759. this._bouncebackEffect = sc;
  11760. },
  11761. enumerable: false,
  11762. configurable: true
  11763. });
  11764. Object.defineProperty(ScrollPane.prototype, "touchEffect", {
  11765. get: function () {
  11766. return this._touchEffect;
  11767. },
  11768. set: function (sc) {
  11769. this._touchEffect = sc;
  11770. },
  11771. enumerable: false,
  11772. configurable: true
  11773. });
  11774. Object.defineProperty(ScrollPane.prototype, "scrollStep", {
  11775. get: function () {
  11776. return this._scrollStep;
  11777. },
  11778. set: function (val) {
  11779. this._scrollStep = val;
  11780. if (this._scrollStep == 0)
  11781. this._scrollStep = fgui.UIConfig.defaultScrollStep;
  11782. this._mouseWheelStep = this._scrollStep * 2;
  11783. },
  11784. enumerable: false,
  11785. configurable: true
  11786. });
  11787. Object.defineProperty(ScrollPane.prototype, "decelerationRate", {
  11788. get: function () {
  11789. return this._decelerationRate;
  11790. },
  11791. set: function (val) {
  11792. this._decelerationRate = val;
  11793. },
  11794. enumerable: false,
  11795. configurable: true
  11796. });
  11797. Object.defineProperty(ScrollPane.prototype, "snapToItem", {
  11798. get: function () {
  11799. return this._snapToItem;
  11800. },
  11801. set: function (value) {
  11802. this._snapToItem = value;
  11803. },
  11804. enumerable: false,
  11805. configurable: true
  11806. });
  11807. Object.defineProperty(ScrollPane.prototype, "mouseWheelEnabled", {
  11808. get: function () {
  11809. return this._mouseWheelEnabled;
  11810. },
  11811. set: function (value) {
  11812. this._mouseWheelEnabled = value;
  11813. },
  11814. enumerable: false,
  11815. configurable: true
  11816. });
  11817. Object.defineProperty(ScrollPane.prototype, "isDragged", {
  11818. get: function () {
  11819. return this._dragged;
  11820. },
  11821. enumerable: false,
  11822. configurable: true
  11823. });
  11824. Object.defineProperty(ScrollPane.prototype, "percX", {
  11825. get: function () {
  11826. return this._overlapSize.x == 0 ? 0 : this._xPos / this._overlapSize.x;
  11827. },
  11828. set: function (value) {
  11829. this.setPercX(value, false);
  11830. },
  11831. enumerable: false,
  11832. configurable: true
  11833. });
  11834. ScrollPane.prototype.setPercX = function (value, ani) {
  11835. this._owner.ensureBoundsCorrect();
  11836. this.setPosX(this._overlapSize.x * fgui.ToolSet.clamp01(value), ani);
  11837. };
  11838. Object.defineProperty(ScrollPane.prototype, "percY", {
  11839. get: function () {
  11840. return this._overlapSize.y == 0 ? 0 : this._yPos / this._overlapSize.y;
  11841. },
  11842. set: function (value) {
  11843. this.setPercY(value, false);
  11844. },
  11845. enumerable: false,
  11846. configurable: true
  11847. });
  11848. ScrollPane.prototype.setPercY = function (value, ani) {
  11849. this._owner.ensureBoundsCorrect();
  11850. this.setPosY(this._overlapSize.y * fgui.ToolSet.clamp01(value), ani);
  11851. };
  11852. Object.defineProperty(ScrollPane.prototype, "posX", {
  11853. get: function () {
  11854. return this._xPos;
  11855. },
  11856. set: function (value) {
  11857. this.setPosX(value, false);
  11858. },
  11859. enumerable: false,
  11860. configurable: true
  11861. });
  11862. ScrollPane.prototype.setPosX = function (value, ani) {
  11863. this._owner.ensureBoundsCorrect();
  11864. if (this._loop == 1)
  11865. value = this.loopCheckingNewPos(value, "x");
  11866. value = fgui.ToolSet.clamp(value, 0, this._overlapSize.x);
  11867. if (value != this._xPos) {
  11868. this._xPos = value;
  11869. this.posChanged(ani);
  11870. }
  11871. };
  11872. Object.defineProperty(ScrollPane.prototype, "posY", {
  11873. get: function () {
  11874. return this._yPos;
  11875. },
  11876. set: function (value) {
  11877. this.setPosY(value, false);
  11878. },
  11879. enumerable: false,
  11880. configurable: true
  11881. });
  11882. ScrollPane.prototype.setPosY = function (value, ani) {
  11883. this._owner.ensureBoundsCorrect();
  11884. if (this._loop == 1)
  11885. value = this.loopCheckingNewPos(value, "y");
  11886. value = fgui.ToolSet.clamp(value, 0, this._overlapSize.y);
  11887. if (value != this._yPos) {
  11888. this._yPos = value;
  11889. this.posChanged(ani);
  11890. }
  11891. };
  11892. Object.defineProperty(ScrollPane.prototype, "contentWidth", {
  11893. get: function () {
  11894. return this._contentSize.x;
  11895. },
  11896. enumerable: false,
  11897. configurable: true
  11898. });
  11899. Object.defineProperty(ScrollPane.prototype, "contentHeight", {
  11900. get: function () {
  11901. return this._contentSize.y;
  11902. },
  11903. enumerable: false,
  11904. configurable: true
  11905. });
  11906. Object.defineProperty(ScrollPane.prototype, "viewWidth", {
  11907. get: function () {
  11908. return this._viewSize.x;
  11909. },
  11910. set: function (value) {
  11911. value = value + this._owner.margin.left + this._owner.margin.right;
  11912. if (this._vtScrollBar && !this._floating)
  11913. value += this._vtScrollBar.width;
  11914. this._owner.width = value;
  11915. },
  11916. enumerable: false,
  11917. configurable: true
  11918. });
  11919. Object.defineProperty(ScrollPane.prototype, "viewHeight", {
  11920. get: function () {
  11921. return this._viewSize.y;
  11922. },
  11923. set: function (value) {
  11924. value = value + this._owner.margin.top + this._owner.margin.bottom;
  11925. if (this._hzScrollBar && !this._floating)
  11926. value += this._hzScrollBar.height;
  11927. this._owner.height = value;
  11928. },
  11929. enumerable: false,
  11930. configurable: true
  11931. });
  11932. Object.defineProperty(ScrollPane.prototype, "currentPageX", {
  11933. get: function () {
  11934. if (!this._pageMode)
  11935. return 0;
  11936. var page = Math.floor(this._xPos / this._pageSize.x);
  11937. if (this._xPos - page * this._pageSize.x > this._pageSize.x * 0.5)
  11938. page++;
  11939. return page;
  11940. },
  11941. set: function (value) {
  11942. this.setCurrentPageX(value, false);
  11943. },
  11944. enumerable: false,
  11945. configurable: true
  11946. });
  11947. Object.defineProperty(ScrollPane.prototype, "currentPageY", {
  11948. get: function () {
  11949. if (!this._pageMode)
  11950. return 0;
  11951. var page = Math.floor(this._yPos / this._pageSize.y);
  11952. if (this._yPos - page * this._pageSize.y > this._pageSize.y * 0.5)
  11953. page++;
  11954. return page;
  11955. },
  11956. set: function (value) {
  11957. this.setCurrentPageY(value, false);
  11958. },
  11959. enumerable: false,
  11960. configurable: true
  11961. });
  11962. ScrollPane.prototype.setCurrentPageX = function (value, ani) {
  11963. if (!this._pageMode)
  11964. return;
  11965. this._owner.ensureBoundsCorrect();
  11966. if (this._overlapSize.x > 0)
  11967. this.setPosX(value * this._pageSize.x, ani);
  11968. };
  11969. ScrollPane.prototype.setCurrentPageY = function (value, ani) {
  11970. if (!this._pageMode)
  11971. return;
  11972. this._owner.ensureBoundsCorrect();
  11973. if (this._overlapSize.y > 0)
  11974. this.setPosY(value * this._pageSize.y, ani);
  11975. };
  11976. Object.defineProperty(ScrollPane.prototype, "isBottomMost", {
  11977. get: function () {
  11978. return this._yPos == this._overlapSize.y || this._overlapSize.y == 0;
  11979. },
  11980. enumerable: false,
  11981. configurable: true
  11982. });
  11983. Object.defineProperty(ScrollPane.prototype, "isRightMost", {
  11984. get: function () {
  11985. return this._xPos == this._overlapSize.x || this._overlapSize.x == 0;
  11986. },
  11987. enumerable: false,
  11988. configurable: true
  11989. });
  11990. Object.defineProperty(ScrollPane.prototype, "pageController", {
  11991. get: function () {
  11992. return this._pageController;
  11993. },
  11994. set: function (value) {
  11995. this._pageController = value;
  11996. },
  11997. enumerable: false,
  11998. configurable: true
  11999. });
  12000. Object.defineProperty(ScrollPane.prototype, "scrollingPosX", {
  12001. get: function () {
  12002. return fgui.ToolSet.clamp(-this._container.x, 0, this._overlapSize.x);
  12003. },
  12004. enumerable: false,
  12005. configurable: true
  12006. });
  12007. Object.defineProperty(ScrollPane.prototype, "scrollingPosY", {
  12008. get: function () {
  12009. return fgui.ToolSet.clamp(-(-this._container.y), 0, this._overlapSize.y);
  12010. },
  12011. enumerable: false,
  12012. configurable: true
  12013. });
  12014. ScrollPane.prototype.scrollTop = function (ani) {
  12015. this.setPercY(0, ani);
  12016. };
  12017. ScrollPane.prototype.scrollBottom = function (ani) {
  12018. this.setPercY(1, ani);
  12019. };
  12020. ScrollPane.prototype.scrollUp = function (ratio, ani) {
  12021. if (ratio == undefined)
  12022. ratio = 1;
  12023. if (this._pageMode)
  12024. this.setPosY(this._yPos - this._pageSize.y * ratio, ani);
  12025. else
  12026. this.setPosY(this._yPos - this._scrollStep * ratio, ani);
  12027. ;
  12028. };
  12029. ScrollPane.prototype.scrollDown = function (ratio, ani) {
  12030. if (ratio == undefined)
  12031. ratio = 1;
  12032. if (this._pageMode)
  12033. this.setPosY(this._yPos + this._pageSize.y * ratio, ani);
  12034. else
  12035. this.setPosY(this._yPos + this._scrollStep * ratio, ani);
  12036. };
  12037. ScrollPane.prototype.scrollLeft = function (ratio, ani) {
  12038. if (ratio == undefined)
  12039. ratio = 1;
  12040. if (this._pageMode)
  12041. this.setPosX(this._xPos - this._pageSize.x * ratio, ani);
  12042. else
  12043. this.setPosX(this._xPos - this._scrollStep * ratio, ani);
  12044. };
  12045. ScrollPane.prototype.scrollRight = function (ratio, ani) {
  12046. if (ratio == undefined)
  12047. ratio = 1;
  12048. if (this._pageMode)
  12049. this.setPosX(this._xPos + this._pageSize.x * ratio, ani);
  12050. else
  12051. this.setPosX(this._xPos + this._scrollStep * ratio, ani);
  12052. };
  12053. ScrollPane.prototype.scrollToView = function (target, ani, setFirst) {
  12054. this._owner.ensureBoundsCorrect();
  12055. if (this._needRefresh)
  12056. this.refresh();
  12057. var rect;
  12058. if (target instanceof fgui.GObject) {
  12059. if (target.parent != this._owner) {
  12060. target.parent.localToGlobalRect(target.x, target.y, target.width, target.height, s_rect);
  12061. rect = this._owner.globalToLocalRect(s_rect.x, s_rect.y, s_rect.width, s_rect.height, s_rect);
  12062. }
  12063. else {
  12064. rect = s_rect;
  12065. rect.x = target.x;
  12066. rect.y = target.y;
  12067. rect.width = target.width;
  12068. rect.height = target.height;
  12069. }
  12070. }
  12071. else
  12072. rect = target;
  12073. if (this._overlapSize.y > 0) {
  12074. var bottom = this._yPos + this._viewSize.y;
  12075. if (setFirst || rect.y <= this._yPos || rect.height >= this._viewSize.y) {
  12076. if (this._pageMode)
  12077. this.setPosY(Math.floor(rect.y / this._pageSize.y) * this._pageSize.y, ani);
  12078. else
  12079. this.setPosY(rect.y, ani);
  12080. }
  12081. else if (rect.y + rect.height > bottom) {
  12082. if (this._pageMode)
  12083. this.setPosY(Math.floor(rect.y / this._pageSize.y) * this._pageSize.y, ani);
  12084. else if (rect.height <= this._viewSize.y / 2)
  12085. this.setPosY(rect.y + rect.height * 2 - this._viewSize.y, ani);
  12086. else
  12087. this.setPosY(rect.y + rect.height - this._viewSize.y, ani);
  12088. }
  12089. }
  12090. if (this._overlapSize.x > 0) {
  12091. var right = this._xPos + this._viewSize.x;
  12092. if (setFirst || rect.x <= this._xPos || rect.width >= this._viewSize.x) {
  12093. if (this._pageMode)
  12094. this.setPosX(Math.floor(rect.x / this._pageSize.x) * this._pageSize.x, ani);
  12095. else
  12096. this.setPosX(rect.x, ani);
  12097. }
  12098. else if (rect.x + rect.width > right) {
  12099. if (this._pageMode)
  12100. this.setPosX(Math.floor(rect.x / this._pageSize.x) * this._pageSize.x, ani);
  12101. else if (rect.width <= this._viewSize.x / 2)
  12102. this.setPosX(rect.x + rect.width * 2 - this._viewSize.x, ani);
  12103. else
  12104. this.setPosX(rect.x + rect.width - this._viewSize.x, ani);
  12105. }
  12106. }
  12107. if (!ani && this._needRefresh)
  12108. this.refresh();
  12109. };
  12110. ScrollPane.prototype.isChildInView = function (obj) {
  12111. if (this._overlapSize.y > 0) {
  12112. var dist = obj.y + (-this._container.y);
  12113. if (dist < -obj.height || dist > this._viewSize.y)
  12114. return false;
  12115. }
  12116. if (this._overlapSize.x > 0) {
  12117. dist = obj.x + this._container.x;
  12118. if (dist < -obj.width || dist > this._viewSize.x)
  12119. return false;
  12120. }
  12121. return true;
  12122. };
  12123. ScrollPane.prototype.cancelDragging = function () {
  12124. if (ScrollPane.draggingPane == this)
  12125. ScrollPane.draggingPane = null;
  12126. _gestureFlag = 0;
  12127. this._dragged = false;
  12128. };
  12129. ScrollPane.prototype.lockHeader = function (size) {
  12130. if (this._headerLockedSize == size)
  12131. return;
  12132. var cx = this._container.x;
  12133. var cy = -this._container.y;
  12134. var cr = this._refreshBarAxis == "x" ? cx : cy;
  12135. this._headerLockedSize = size;
  12136. if (!this._refreshEventDispatching && cr >= 0) {
  12137. this._tweenStart.x = cx;
  12138. this._tweenStart.y = cy;
  12139. this._tweenChange.set(cc.Vec2.ZERO);
  12140. this._tweenChange[this._refreshBarAxis] = this._headerLockedSize - this._tweenStart[this._refreshBarAxis];
  12141. this._tweenDuration.x = this._tweenDuration.y = TWEEN_TIME_DEFAULT;
  12142. this.startTween(2);
  12143. }
  12144. };
  12145. ScrollPane.prototype.lockFooter = function (size) {
  12146. if (this._footerLockedSize == size)
  12147. return;
  12148. var cx = this._container.x;
  12149. var cy = -this._container.y;
  12150. var cr = this._refreshBarAxis == "x" ? cx : cy;
  12151. this._footerLockedSize = size;
  12152. if (!this._refreshEventDispatching && cr <= -this._overlapSize[this._refreshBarAxis]) {
  12153. this._tweenStart.x = cx;
  12154. this._tweenStart.y = cy;
  12155. this._tweenChange.set(cc.Vec2.ZERO);
  12156. var max = this._overlapSize[this._refreshBarAxis];
  12157. if (max == 0)
  12158. max = Math.max(this._contentSize[this._refreshBarAxis] + this._footerLockedSize - this._viewSize[this._refreshBarAxis], 0);
  12159. else
  12160. max += this._footerLockedSize;
  12161. this._tweenChange[this._refreshBarAxis] = -max - this._tweenStart[this._refreshBarAxis];
  12162. this._tweenDuration.x = this._tweenDuration.y = TWEEN_TIME_DEFAULT;
  12163. this.startTween(2);
  12164. }
  12165. };
  12166. ScrollPane.prototype.onOwnerSizeChanged = function () {
  12167. this.setSize(this._owner.width, this._owner.height);
  12168. this.posChanged(false);
  12169. };
  12170. ScrollPane.prototype.handleControllerChanged = function (c) {
  12171. if (this._pageController == c) {
  12172. if (this._scrollType == fgui.ScrollType.Horizontal)
  12173. this.setCurrentPageX(c.selectedIndex, true);
  12174. else
  12175. this.setCurrentPageY(c.selectedIndex, true);
  12176. }
  12177. };
  12178. ScrollPane.prototype.updatePageController = function () {
  12179. if (this._pageController && !this._pageController.changing) {
  12180. var index;
  12181. if (this._scrollType == fgui.ScrollType.Horizontal)
  12182. index = this.currentPageX;
  12183. else
  12184. index = this.currentPageY;
  12185. if (index < this._pageController.pageCount) {
  12186. var c = this._pageController;
  12187. this._pageController = null;
  12188. c.selectedIndex = index;
  12189. this._pageController = c;
  12190. }
  12191. }
  12192. };
  12193. ScrollPane.prototype.adjustMaskContainer = function () {
  12194. var mx = 0;
  12195. if (this._displayOnLeft && this._vtScrollBar && !this._floating)
  12196. mx = this._vtScrollBar.width;
  12197. var o = this._owner;
  12198. if (this._dontClipMargin)
  12199. this._maskContainer.setAnchorPoint((o.margin.left + o._alignOffset.x) / o.width, 1 - (o.margin.top + o._alignOffset.y) / o.height);
  12200. else
  12201. this._maskContainer.setAnchorPoint(o._alignOffset.x / this._viewSize.x, 1 - o._alignOffset.y / this._viewSize.y);
  12202. if (o._customMask)
  12203. this._maskContainer.setPosition(mx + o._alignOffset.x, -o._alignOffset.y);
  12204. else
  12205. this._maskContainer.setPosition(o._pivotCorrectX + mx + o._alignOffset.x, o._pivotCorrectY - o._alignOffset.y);
  12206. };
  12207. ScrollPane.prototype.setSize = function (aWidth, aHeight) {
  12208. if (this._hzScrollBar) {
  12209. this._hzScrollBar.y = aHeight - this._hzScrollBar.height;
  12210. if (this._vtScrollBar) {
  12211. this._hzScrollBar.width = aWidth - this._vtScrollBar.width - this._scrollBarMargin.left - this._scrollBarMargin.right;
  12212. if (this._displayOnLeft)
  12213. this._hzScrollBar.x = this._scrollBarMargin.left + this._vtScrollBar.width;
  12214. else
  12215. this._hzScrollBar.x = this._scrollBarMargin.left;
  12216. }
  12217. else {
  12218. this._hzScrollBar.width = aWidth - this._scrollBarMargin.left - this._scrollBarMargin.right;
  12219. this._hzScrollBar.x = this._scrollBarMargin.left;
  12220. }
  12221. }
  12222. if (this._vtScrollBar) {
  12223. if (!this._displayOnLeft)
  12224. this._vtScrollBar.x = aWidth - this._vtScrollBar.width;
  12225. if (this._hzScrollBar)
  12226. this._vtScrollBar.height = aHeight - this._hzScrollBar.height - this._scrollBarMargin.top - this._scrollBarMargin.bottom;
  12227. else
  12228. this._vtScrollBar.height = aHeight - this._scrollBarMargin.top - this._scrollBarMargin.bottom;
  12229. this._vtScrollBar.y = this._scrollBarMargin.top;
  12230. }
  12231. this._viewSize.x = aWidth;
  12232. this._viewSize.y = aHeight;
  12233. if (this._hzScrollBar && !this._floating)
  12234. this._viewSize.y -= this._hzScrollBar.height;
  12235. if (this._vtScrollBar && !this._floating)
  12236. this._viewSize.x -= this._vtScrollBar.width;
  12237. this._viewSize.x -= (this._owner.margin.left + this._owner.margin.right);
  12238. this._viewSize.y -= (this._owner.margin.top + this._owner.margin.bottom);
  12239. this._viewSize.x = Math.max(1, this._viewSize.x);
  12240. this._viewSize.y = Math.max(1, this._viewSize.y);
  12241. this._pageSize.x = this._viewSize.x;
  12242. this._pageSize.y = this._viewSize.y;
  12243. this.adjustMaskContainer();
  12244. this.handleSizeChanged();
  12245. };
  12246. ScrollPane.prototype.setContentSize = function (aWidth, aHeight) {
  12247. if (this._contentSize.x == aWidth && this._contentSize.y == aHeight)
  12248. return;
  12249. this._contentSize.x = aWidth;
  12250. this._contentSize.y = aHeight;
  12251. this.handleSizeChanged();
  12252. };
  12253. ScrollPane.prototype.changeContentSizeOnScrolling = function (deltaWidth, deltaHeight, deltaPosX, deltaPosY) {
  12254. var isRightmost = this._xPos == this._overlapSize.x;
  12255. var isBottom = this._yPos == this._overlapSize.y;
  12256. this._contentSize.x += deltaWidth;
  12257. this._contentSize.y += deltaHeight;
  12258. this.handleSizeChanged();
  12259. if (this._tweening == 1) {
  12260. if (deltaWidth != 0 && isRightmost && this._tweenChange.x < 0) {
  12261. this._xPos = this._overlapSize.x;
  12262. this._tweenChange.x = -this._xPos - this._tweenStart.x;
  12263. }
  12264. if (deltaHeight != 0 && isBottom && this._tweenChange.y < 0) {
  12265. this._yPos = this._overlapSize.y;
  12266. this._tweenChange.y = -this._yPos - this._tweenStart.y;
  12267. }
  12268. }
  12269. else if (this._tweening == 2) {
  12270. if (deltaPosX != 0) {
  12271. this._container.x -= deltaPosX;
  12272. this._tweenStart.x -= deltaPosX;
  12273. this._xPos = -this._container.x;
  12274. }
  12275. if (deltaPosY != 0) {
  12276. this._container.y += deltaPosY;
  12277. this._tweenStart.y -= deltaPosY;
  12278. this._yPos = -(-this._container.y);
  12279. }
  12280. }
  12281. else if (this._dragged) {
  12282. if (deltaPosX != 0) {
  12283. this._container.x -= deltaPosX;
  12284. this._containerPos.x -= deltaPosX;
  12285. this._xPos = -this._container.x;
  12286. }
  12287. if (deltaPosY != 0) {
  12288. this._container.y += deltaPosY;
  12289. this._containerPos.y -= deltaPosY;
  12290. this._yPos = -(-this._container.y);
  12291. }
  12292. }
  12293. else {
  12294. if (deltaWidth != 0 && isRightmost) {
  12295. this._xPos = this._overlapSize.x;
  12296. this._container.x = -this._xPos;
  12297. }
  12298. if (deltaHeight != 0 && isBottom) {
  12299. this._yPos = this._overlapSize.y;
  12300. this._container.y = this._yPos;
  12301. }
  12302. }
  12303. if (this._pageMode)
  12304. this.updatePageController();
  12305. };
  12306. ScrollPane.prototype.handleSizeChanged = function () {
  12307. if (this._displayInDemand) {
  12308. this._vScrollNone = this._contentSize.y <= this._viewSize.y;
  12309. this._hScrollNone = this._contentSize.x <= this._viewSize.x;
  12310. }
  12311. if (this._vtScrollBar) {
  12312. if (this._contentSize.y == 0)
  12313. this._vtScrollBar.setDisplayPerc(0);
  12314. else
  12315. this._vtScrollBar.setDisplayPerc(Math.min(1, this._viewSize.y / this._contentSize.y));
  12316. }
  12317. if (this._hzScrollBar) {
  12318. if (this._contentSize.x == 0)
  12319. this._hzScrollBar.setDisplayPerc(0);
  12320. else
  12321. this._hzScrollBar.setDisplayPerc(Math.min(1, this._viewSize.x / this._contentSize.x));
  12322. }
  12323. this.updateScrollBarVisible();
  12324. var maskWidth = this._viewSize.x;
  12325. var maskHeight = this._viewSize.y;
  12326. if (this._vScrollNone && this._vtScrollBar)
  12327. maskWidth += this._vtScrollBar.width;
  12328. if (this._hScrollNone && this._hzScrollBar)
  12329. maskHeight += this._hzScrollBar.height;
  12330. if (this._dontClipMargin) {
  12331. maskWidth += (this._owner.margin.left + this._owner.margin.right);
  12332. maskHeight += (this._owner.margin.top + this._owner.margin.bottom);
  12333. }
  12334. this._maskContainer.setContentSize(maskWidth, maskHeight);
  12335. if (this._vtScrollBar)
  12336. this._vtScrollBar.handlePositionChanged();
  12337. if (this._hzScrollBar)
  12338. this._hzScrollBar.handlePositionChanged();
  12339. if (this._header)
  12340. this._header.handlePositionChanged();
  12341. if (this._footer)
  12342. this._footer.handlePositionChanged();
  12343. if (this._scrollType == fgui.ScrollType.Horizontal || this._scrollType == fgui.ScrollType.Both)
  12344. this._overlapSize.x = Math.ceil(Math.max(0, this._contentSize.x - this._viewSize.x));
  12345. else
  12346. this._overlapSize.x = 0;
  12347. if (this._scrollType == fgui.ScrollType.Vertical || this._scrollType == fgui.ScrollType.Both)
  12348. this._overlapSize.y = Math.ceil(Math.max(0, this._contentSize.y - this._viewSize.y));
  12349. else
  12350. this._overlapSize.y = 0;
  12351. this._xPos = fgui.ToolSet.clamp(this._xPos, 0, this._overlapSize.x);
  12352. this._yPos = fgui.ToolSet.clamp(this._yPos, 0, this._overlapSize.y);
  12353. var max = this._overlapSize[this._refreshBarAxis];
  12354. if (max == 0)
  12355. max = Math.max(this._contentSize[this._refreshBarAxis] + this._footerLockedSize - this._viewSize[this._refreshBarAxis], 0);
  12356. else
  12357. max += this._footerLockedSize;
  12358. if (this._refreshBarAxis == "x")
  12359. this._container.setPosition(fgui.ToolSet.clamp(this._container.x, -max, this._headerLockedSize), -fgui.ToolSet.clamp((-this._container.y), -this._overlapSize.y, 0));
  12360. else
  12361. this._container.setPosition(fgui.ToolSet.clamp(this._container.x, -this._overlapSize.x, 0), -fgui.ToolSet.clamp((-this._container.y), -max, this._headerLockedSize));
  12362. if (this._header) {
  12363. if (this._refreshBarAxis == "x")
  12364. this._header.height = this._viewSize.y;
  12365. else
  12366. this._header.width = this._viewSize.x;
  12367. }
  12368. if (this._footer) {
  12369. if (this._refreshBarAxis == "y")
  12370. this._footer.height = this._viewSize.y;
  12371. else
  12372. this._footer.width = this._viewSize.x;
  12373. }
  12374. this.updateScrollBarPos();
  12375. if (this._pageMode)
  12376. this.updatePageController();
  12377. };
  12378. ScrollPane.prototype.posChanged = function (ani) {
  12379. if (this._aniFlag == 0)
  12380. this._aniFlag = ani ? 1 : -1;
  12381. else if (this._aniFlag == 1 && !ani)
  12382. this._aniFlag = -1;
  12383. this._needRefresh = true;
  12384. if (!cc.director.getScheduler().isScheduled(this.refresh, this))
  12385. this.scheduleOnce(this.refresh);
  12386. };
  12387. ScrollPane.prototype.refresh = function (dt) {
  12388. this._needRefresh = false;
  12389. this.unschedule(this.refresh);
  12390. if (this._pageMode || this._snapToItem) {
  12391. sEndPos.x = -this._xPos;
  12392. sEndPos.y = -this._yPos;
  12393. this.alignPosition(sEndPos, false);
  12394. this._xPos = -sEndPos.x;
  12395. this._yPos = -sEndPos.y;
  12396. }
  12397. this.refresh2();
  12398. this._owner.node.emit(fgui.Event.SCROLL, this._owner);
  12399. if (this._needRefresh) {
  12400. this._needRefresh = false;
  12401. this.unschedule(this.refresh);
  12402. this.refresh2();
  12403. }
  12404. this.updateScrollBarPos();
  12405. this._aniFlag = 0;
  12406. };
  12407. ScrollPane.prototype.refresh2 = function () {
  12408. if (this._aniFlag == 1 && !this._dragged) {
  12409. var posX;
  12410. var posY;
  12411. if (this._overlapSize.x > 0)
  12412. posX = -Math.floor(this._xPos);
  12413. else {
  12414. if (this._container.x != 0)
  12415. this._container.x = 0;
  12416. posX = 0;
  12417. }
  12418. if (this._overlapSize.y > 0)
  12419. posY = -Math.floor(this._yPos);
  12420. else {
  12421. if (this._container.y != 0)
  12422. this._container.y = 0;
  12423. posY = 0;
  12424. }
  12425. if (posX != this._container.x || posY != (-this._container.y)) {
  12426. this._tweenDuration.x = this._tweenDuration.y = TWEEN_TIME_GO;
  12427. this._tweenStart.x = this._container.x;
  12428. this._tweenStart.y = (-this._container.y);
  12429. this._tweenChange.x = posX - this._tweenStart.x;
  12430. this._tweenChange.y = posY - this._tweenStart.y;
  12431. this.startTween(1);
  12432. }
  12433. else if (this._tweening != 0)
  12434. this.killTween();
  12435. }
  12436. else {
  12437. if (this._tweening != 0)
  12438. this.killTween();
  12439. this._container.setPosition(Math.floor(-this._xPos), -Math.floor(-this._yPos));
  12440. this.loopCheckingCurrent();
  12441. }
  12442. if (this._pageMode)
  12443. this.updatePageController();
  12444. };
  12445. ScrollPane.prototype.onTouchBegin = function (evt) {
  12446. if (!this._touchEffect)
  12447. return;
  12448. evt.captureTouch();
  12449. if (this._tweening != 0) {
  12450. this.killTween();
  12451. fgui.GRoot.inst.inputProcessor.cancelClick(evt.touchId);
  12452. this._dragged = true;
  12453. }
  12454. else
  12455. this._dragged = false;
  12456. var pt = this._owner.globalToLocal(evt.pos.x, evt.pos.y, s_vec2);
  12457. this._containerPos.x = this._container.x;
  12458. this._containerPos.y = -this._container.y;
  12459. this._beginTouchPos.set(pt);
  12460. this._lastTouchPos.set(pt);
  12461. this._lastTouchGlobalPos.set(evt.pos);
  12462. this._isHoldAreaDone = false;
  12463. this._velocity.set(cc.Vec2.ZERO);
  12464. ;
  12465. this._velocityScale = 1;
  12466. this._lastMoveTime = fgui.ToolSet.getTime();
  12467. };
  12468. ScrollPane.prototype.onTouchMove = function (evt) {
  12469. if (!cc.isValid(this._owner.node))
  12470. return;
  12471. if (!this._touchEffect)
  12472. return;
  12473. if (fgui.GObject.draggingObject && fgui.GObject.draggingObject.onStage)
  12474. return;
  12475. if (ScrollPane.draggingPane && ScrollPane.draggingPane != this && ScrollPane.draggingPane._owner.onStage)
  12476. return;
  12477. var pt = this._owner.globalToLocal(evt.pos.x, evt.pos.y, s_vec2);
  12478. var sensitivity = fgui.UIConfig.touchScrollSensitivity;
  12479. var diff, diff2;
  12480. var sv, sh, st;
  12481. if (this._scrollType == fgui.ScrollType.Vertical) {
  12482. if (!this._isHoldAreaDone) {
  12483. _gestureFlag |= 1;
  12484. diff = Math.abs(this._beginTouchPos.y - pt.y);
  12485. if (diff < sensitivity)
  12486. return;
  12487. if ((_gestureFlag & 2) != 0) {
  12488. diff2 = Math.abs(this._beginTouchPos.x - pt.x);
  12489. if (diff < diff2)
  12490. return;
  12491. }
  12492. }
  12493. sv = true;
  12494. }
  12495. else if (this._scrollType == fgui.ScrollType.Horizontal) {
  12496. if (!this._isHoldAreaDone) {
  12497. _gestureFlag |= 2;
  12498. diff = Math.abs(this._beginTouchPos.x - pt.x);
  12499. if (diff < sensitivity)
  12500. return;
  12501. if ((_gestureFlag & 1) != 0) {
  12502. diff2 = Math.abs(this._beginTouchPos.y - pt.y);
  12503. if (diff < diff2)
  12504. return;
  12505. }
  12506. }
  12507. sh = true;
  12508. }
  12509. else {
  12510. _gestureFlag = 3;
  12511. if (!this._isHoldAreaDone) {
  12512. diff = Math.abs(this._beginTouchPos.y - pt.y);
  12513. if (diff < sensitivity) {
  12514. diff = Math.abs(this._beginTouchPos.x - pt.x);
  12515. if (diff < sensitivity)
  12516. return;
  12517. }
  12518. }
  12519. sv = sh = true;
  12520. }
  12521. var newPosX = Math.floor(this._containerPos.x + pt.x - this._beginTouchPos.x);
  12522. var newPosY = Math.floor(this._containerPos.y + pt.y - this._beginTouchPos.y);
  12523. if (sv) {
  12524. if (newPosY > 0) {
  12525. if (!this._bouncebackEffect)
  12526. this._container.y = 0;
  12527. else if (this._header && this._header.maxHeight != 0)
  12528. this._container.y = -Math.floor(Math.min(newPosY * 0.5, this._header.maxHeight));
  12529. else
  12530. this._container.y = -Math.floor(Math.min(newPosY * 0.5, this._viewSize.y * PULL_RATIO));
  12531. }
  12532. else if (newPosY < -this._overlapSize.y) {
  12533. if (!this._bouncebackEffect)
  12534. this._container.y = this._overlapSize.y;
  12535. else if (this._footer && this._footer.maxHeight > 0)
  12536. this._container.y = -Math.floor(Math.max((newPosY + this._overlapSize.y) * 0.5, -this._footer.maxHeight) - this._overlapSize.y);
  12537. else
  12538. this._container.y = -Math.floor(Math.max((newPosY + this._overlapSize.y) * 0.5, -this._viewSize.y * PULL_RATIO) - this._overlapSize.y);
  12539. }
  12540. else
  12541. this._container.y = -newPosY;
  12542. }
  12543. if (sh) {
  12544. if (newPosX > 0) {
  12545. if (!this._bouncebackEffect)
  12546. this._container.x = 0;
  12547. else if (this._header && this._header.maxWidth != 0)
  12548. this._container.x = Math.floor(Math.min(newPosX * 0.5, this._header.maxWidth));
  12549. else
  12550. this._container.x = Math.floor(Math.min(newPosX * 0.5, this._viewSize.x * PULL_RATIO));
  12551. }
  12552. else if (newPosX < 0 - this._overlapSize.x) {
  12553. if (!this._bouncebackEffect)
  12554. this._container.x = -this._overlapSize.x;
  12555. else if (this._footer && this._footer.maxWidth > 0)
  12556. this._container.x = Math.floor(Math.max((newPosX + this._overlapSize.x) * 0.5, -this._footer.maxWidth) - this._overlapSize.x);
  12557. else
  12558. this._container.x = Math.floor(Math.max((newPosX + this._overlapSize.x) * 0.5, -this._viewSize.x * PULL_RATIO) - this._overlapSize.x);
  12559. }
  12560. else
  12561. this._container.x = newPosX;
  12562. }
  12563. var now = fgui.ToolSet.getTime();
  12564. var deltaTime = Math.max(now - this._lastMoveTime, 1 / 60);
  12565. var deltaPositionX = pt.x - this._lastTouchPos.x;
  12566. var deltaPositionY = pt.y - this._lastTouchPos.y;
  12567. if (!sh)
  12568. deltaPositionX = 0;
  12569. if (!sv)
  12570. deltaPositionY = 0;
  12571. if (deltaTime != 0) {
  12572. var frameRate = 60;
  12573. var elapsed = deltaTime * frameRate - 1;
  12574. if (elapsed > 1) {
  12575. var factor = Math.pow(0.833, elapsed);
  12576. this._velocity.x = this._velocity.x * factor;
  12577. this._velocity.y = this._velocity.y * factor;
  12578. }
  12579. this._velocity.x = fgui.ToolSet.lerp(this._velocity.x, deltaPositionX * 60 / frameRate / deltaTime, deltaTime * 10);
  12580. this._velocity.y = fgui.ToolSet.lerp(this._velocity.y, deltaPositionY * 60 / frameRate / deltaTime, deltaTime * 10);
  12581. }
  12582. var deltaGlobalPositionX = this._lastTouchGlobalPos.x - evt.pos.x;
  12583. var deltaGlobalPositionY = this._lastTouchGlobalPos.y - evt.pos.y;
  12584. if (deltaPositionX != 0)
  12585. this._velocityScale = Math.abs(deltaGlobalPositionX / deltaPositionX);
  12586. else if (deltaPositionY != 0)
  12587. this._velocityScale = Math.abs(deltaGlobalPositionY / deltaPositionY);
  12588. this._lastTouchPos.set(pt);
  12589. this._lastTouchGlobalPos.x = evt.pos.x;
  12590. this._lastTouchGlobalPos.y = evt.pos.y;
  12591. this._lastMoveTime = now;
  12592. if (this._overlapSize.x > 0)
  12593. this._xPos = fgui.ToolSet.clamp(-this._container.x, 0, this._overlapSize.x);
  12594. if (this._overlapSize.y > 0)
  12595. this._yPos = fgui.ToolSet.clamp(-(-this._container.y), 0, this._overlapSize.y);
  12596. if (this._loop != 0) {
  12597. newPosX = this._container.x;
  12598. newPosY = (-this._container.y);
  12599. if (this.loopCheckingCurrent()) {
  12600. this._containerPos.x += this._container.x - newPosX;
  12601. this._containerPos.y += (-this._container.y) - newPosY;
  12602. }
  12603. }
  12604. ScrollPane.draggingPane = this;
  12605. this._isHoldAreaDone = true;
  12606. this._dragged = true;
  12607. this.updateScrollBarPos();
  12608. this.updateScrollBarVisible();
  12609. if (this._pageMode)
  12610. this.updatePageController();
  12611. this._owner.node.emit(fgui.Event.SCROLL), this._owner;
  12612. };
  12613. ScrollPane.prototype.onTouchEnd = function (evt) {
  12614. if (ScrollPane.draggingPane == this)
  12615. ScrollPane.draggingPane = null;
  12616. _gestureFlag = 0;
  12617. if (!this._dragged || !this._touchEffect || !this._owner.node.activeInHierarchy) {
  12618. this._dragged = false;
  12619. return;
  12620. }
  12621. this._dragged = false;
  12622. this._tweenStart.x = this._container.x;
  12623. this._tweenStart.y = -this._container.y;
  12624. sEndPos.set(this._tweenStart);
  12625. var flag = false;
  12626. if (this._container.x > 0) {
  12627. sEndPos.x = 0;
  12628. flag = true;
  12629. }
  12630. else if (this._container.x < -this._overlapSize.x) {
  12631. sEndPos.x = -this._overlapSize.x;
  12632. flag = true;
  12633. }
  12634. if ((-this._container.y) > 0) {
  12635. sEndPos.y = 0;
  12636. flag = true;
  12637. }
  12638. else if ((-this._container.y) < -this._overlapSize.y) {
  12639. sEndPos.y = -this._overlapSize.y;
  12640. flag = true;
  12641. }
  12642. if (flag) {
  12643. this._tweenChange.x = sEndPos.x - this._tweenStart.x;
  12644. this._tweenChange.y = sEndPos.y - this._tweenStart.y;
  12645. if (this._tweenChange.x < -fgui.UIConfig.touchDragSensitivity || this._tweenChange.y < -fgui.UIConfig.touchDragSensitivity) {
  12646. this._refreshEventDispatching = true;
  12647. this._owner.node.emit(fgui.Event.PULL_DOWN_RELEASE), this._owner;
  12648. this._refreshEventDispatching = false;
  12649. }
  12650. else if (this._tweenChange.x > fgui.UIConfig.touchDragSensitivity || this._tweenChange.y > fgui.UIConfig.touchDragSensitivity) {
  12651. this._refreshEventDispatching = true;
  12652. this._owner.node.emit(fgui.Event.PULL_UP_RELEASE, this._owner);
  12653. this._refreshEventDispatching = false;
  12654. }
  12655. if (this._headerLockedSize > 0 && sEndPos[this._refreshBarAxis] == 0) {
  12656. sEndPos[this._refreshBarAxis] = this._headerLockedSize;
  12657. this._tweenChange.x = sEndPos.x - this._tweenStart.x;
  12658. this._tweenChange.y = sEndPos.y - this._tweenStart.y;
  12659. }
  12660. else if (this._footerLockedSize > 0 && sEndPos[this._refreshBarAxis] == -this._overlapSize[this._refreshBarAxis]) {
  12661. var max = this._overlapSize[this._refreshBarAxis];
  12662. if (max == 0)
  12663. max = Math.max(this._contentSize[this._refreshBarAxis] + this._footerLockedSize - this._viewSize[this._refreshBarAxis], 0);
  12664. else
  12665. max += this._footerLockedSize;
  12666. sEndPos[this._refreshBarAxis] = -max;
  12667. this._tweenChange.x = sEndPos.x - this._tweenStart.x;
  12668. this._tweenChange.y = sEndPos.y - this._tweenStart.y;
  12669. }
  12670. this._tweenDuration.x = this._tweenDuration.y = TWEEN_TIME_DEFAULT;
  12671. }
  12672. else {
  12673. if (!this._inertiaDisabled) {
  12674. var frameRate = 60;
  12675. var elapsed = (fgui.ToolSet.getTime() - this._lastMoveTime) * frameRate - 1;
  12676. if (elapsed > 1) {
  12677. var factor = Math.pow(0.833, elapsed);
  12678. this._velocity.x = this._velocity.x * factor;
  12679. this._velocity.y = this._velocity.y * factor;
  12680. }
  12681. this.updateTargetAndDuration(this._tweenStart, sEndPos);
  12682. }
  12683. else
  12684. this._tweenDuration.x = this._tweenDuration.y = TWEEN_TIME_DEFAULT;
  12685. sOldChange.x = sEndPos.x - this._tweenStart.x;
  12686. sOldChange.y = sEndPos.y - this._tweenStart.y;
  12687. this.loopCheckingTarget(sEndPos);
  12688. if (this._pageMode || this._snapToItem)
  12689. this.alignPosition(sEndPos, true);
  12690. this._tweenChange.x = sEndPos.x - this._tweenStart.x;
  12691. this._tweenChange.y = sEndPos.y - this._tweenStart.y;
  12692. if (this._tweenChange.x == 0 && this._tweenChange.y == 0) {
  12693. this.updateScrollBarVisible();
  12694. return;
  12695. }
  12696. if (this._pageMode || this._snapToItem) {
  12697. this.fixDuration("x", sOldChange.x);
  12698. this.fixDuration("y", sOldChange.y);
  12699. }
  12700. }
  12701. this.startTween(2);
  12702. };
  12703. ScrollPane.prototype.onRollOver = function () {
  12704. this._hover = true;
  12705. this.updateScrollBarVisible();
  12706. };
  12707. ScrollPane.prototype.onRollOut = function () {
  12708. this._hover = false;
  12709. this.updateScrollBarVisible();
  12710. };
  12711. ScrollPane.prototype.onMouseWheel = function (evt) {
  12712. if (!this._mouseWheelEnabled)
  12713. return;
  12714. var delta = evt.mouseWheelDelta > 0 ? -1 : 1;
  12715. if (this._overlapSize.x > 0 && this._overlapSize.y == 0) {
  12716. if (this._pageMode)
  12717. this.setPosX(this._xPos + this._pageSize.x * delta, false);
  12718. else
  12719. this.setPosX(this._xPos + this._mouseWheelStep * delta, false);
  12720. }
  12721. else {
  12722. if (this._pageMode)
  12723. this.setPosY(this._yPos + this._pageSize.y * delta, false);
  12724. else
  12725. this.setPosY(this._yPos + this._mouseWheelStep * delta, false);
  12726. }
  12727. };
  12728. ScrollPane.prototype.updateScrollBarPos = function () {
  12729. if (this._vtScrollBar)
  12730. this._vtScrollBar.setScrollPerc(this._overlapSize.y == 0 ? 0 : fgui.ToolSet.clamp(this._container.y, 0, this._overlapSize.y) / this._overlapSize.y);
  12731. if (this._hzScrollBar)
  12732. this._hzScrollBar.setScrollPerc(this._overlapSize.x == 0 ? 0 : fgui.ToolSet.clamp(-this._container.x, 0, this._overlapSize.x) / this._overlapSize.x);
  12733. this.checkRefreshBar();
  12734. };
  12735. ScrollPane.prototype.updateScrollBarVisible = function () {
  12736. if (this._vtScrollBar) {
  12737. if (this._viewSize.y <= this._vtScrollBar.minSize || this._vScrollNone)
  12738. this._vtScrollBar.node.active = false;
  12739. else
  12740. this.updateScrollBarVisible2(this._vtScrollBar);
  12741. }
  12742. if (this._hzScrollBar) {
  12743. if (this._viewSize.x <= this._hzScrollBar.minSize || this._hScrollNone)
  12744. this._hzScrollBar.node.active = false;
  12745. else
  12746. this.updateScrollBarVisible2(this._hzScrollBar);
  12747. }
  12748. };
  12749. ScrollPane.prototype.updateScrollBarVisible2 = function (bar) {
  12750. if (this._scrollBarDisplayAuto)
  12751. fgui.GTween.kill(bar, false, "alpha");
  12752. if (this._scrollBarDisplayAuto && !this._hover && this._tweening == 0 && !this._dragged && !bar.gripDragging) {
  12753. if (bar.node.active)
  12754. fgui.GTween.to(1, 0, 0.5).setDelay(0.5).onComplete(this.__barTweenComplete, this).setTarget(bar, "alpha");
  12755. }
  12756. else {
  12757. bar.alpha = 1;
  12758. bar.node.active = true;
  12759. }
  12760. };
  12761. ScrollPane.prototype.__barTweenComplete = function (tweener) {
  12762. var bar = (tweener.target);
  12763. bar.alpha = 1;
  12764. bar.node.active = false;
  12765. };
  12766. ScrollPane.prototype.getLoopPartSize = function (division, axis) {
  12767. return (this._contentSize[axis] + (axis == "x" ? this._owner.columnGap : this._owner.lineGap)) / division;
  12768. };
  12769. ScrollPane.prototype.loopCheckingCurrent = function () {
  12770. var changed = false;
  12771. if (this._loop == 1 && this._overlapSize.x > 0) {
  12772. if (this._xPos < 0.001) {
  12773. this._xPos += this.getLoopPartSize(2, "x");
  12774. changed = true;
  12775. }
  12776. else if (this._xPos >= this._overlapSize.x) {
  12777. this._xPos -= this.getLoopPartSize(2, "x");
  12778. changed = true;
  12779. }
  12780. }
  12781. else if (this._loop == 2 && this._overlapSize.y > 0) {
  12782. if (this._yPos < 0.001) {
  12783. this._yPos += this.getLoopPartSize(2, "y");
  12784. changed = true;
  12785. }
  12786. else if (this._yPos >= this._overlapSize.y) {
  12787. this._yPos -= this.getLoopPartSize(2, "y");
  12788. changed = true;
  12789. }
  12790. }
  12791. if (changed) {
  12792. this._container.setPosition(Math.floor(-this._xPos), -Math.floor(-this._yPos));
  12793. }
  12794. return changed;
  12795. };
  12796. ScrollPane.prototype.loopCheckingTarget = function (endPos) {
  12797. if (this._loop == 1)
  12798. this.loopCheckingTarget2(endPos, "x");
  12799. if (this._loop == 2)
  12800. this.loopCheckingTarget2(endPos, "y");
  12801. };
  12802. ScrollPane.prototype.loopCheckingTarget2 = function (endPos, axis) {
  12803. var halfSize;
  12804. var tmp;
  12805. if (endPos[axis] > 0) {
  12806. halfSize = this.getLoopPartSize(2, axis);
  12807. tmp = this._tweenStart[axis] - halfSize;
  12808. if (tmp <= 0 && tmp >= -this._overlapSize[axis]) {
  12809. endPos[axis] -= halfSize;
  12810. this._tweenStart[axis] = tmp;
  12811. }
  12812. }
  12813. else if (endPos[axis] < -this._overlapSize[axis]) {
  12814. halfSize = this.getLoopPartSize(2, axis);
  12815. tmp = this._tweenStart[axis] + halfSize;
  12816. if (tmp <= 0 && tmp >= -this._overlapSize[axis]) {
  12817. endPos[axis] += halfSize;
  12818. this._tweenStart[axis] = tmp;
  12819. }
  12820. }
  12821. };
  12822. ScrollPane.prototype.loopCheckingNewPos = function (value, axis) {
  12823. if (this._overlapSize[axis] == 0)
  12824. return value;
  12825. var pos = axis == "x" ? this._xPos : this._yPos;
  12826. var changed = false;
  12827. var v;
  12828. if (value < 0.001) {
  12829. value += this.getLoopPartSize(2, axis);
  12830. if (value > pos) {
  12831. v = this.getLoopPartSize(6, axis);
  12832. v = Math.ceil((value - pos) / v) * v;
  12833. pos = fgui.ToolSet.clamp(pos + v, 0, this._overlapSize[axis]);
  12834. changed = true;
  12835. }
  12836. }
  12837. else if (value >= this._overlapSize[axis]) {
  12838. value -= this.getLoopPartSize(2, axis);
  12839. if (value < pos) {
  12840. v = this.getLoopPartSize(6, axis);
  12841. v = Math.ceil((pos - value) / v) * v;
  12842. pos = fgui.ToolSet.clamp(pos - v, 0, this._overlapSize[axis]);
  12843. changed = true;
  12844. }
  12845. }
  12846. if (changed) {
  12847. if (axis == "x")
  12848. this._container.x = -Math.floor(pos);
  12849. else
  12850. this._container.y = Math.floor(pos);
  12851. }
  12852. return value;
  12853. };
  12854. ScrollPane.prototype.alignPosition = function (pos, inertialScrolling) {
  12855. if (this._pageMode) {
  12856. pos.x = this.alignByPage(pos.x, "x", inertialScrolling);
  12857. pos.y = this.alignByPage(pos.y, "y", inertialScrolling);
  12858. }
  12859. else if (this._snapToItem) {
  12860. var pt = this._owner.getSnappingPosition(-pos.x, -pos.y, s_vec2);
  12861. if (pos.x < 0 && pos.x > -this._overlapSize.x)
  12862. pos.x = -pt.x;
  12863. if (pos.y < 0 && pos.y > -this._overlapSize.y)
  12864. pos.y = -pt.y;
  12865. }
  12866. };
  12867. ScrollPane.prototype.alignByPage = function (pos, axis, inertialScrolling) {
  12868. var page;
  12869. if (pos > 0)
  12870. page = 0;
  12871. else if (pos < -this._overlapSize[axis])
  12872. page = Math.ceil(this._contentSize[axis] / this._pageSize[axis]) - 1;
  12873. else {
  12874. page = Math.floor(-pos / this._pageSize[axis]);
  12875. var change = inertialScrolling ? (pos - this._containerPos[axis]) : (pos - (axis == "x" ? this._container.x : (-this._container.y)));
  12876. var testPageSize = Math.min(this._pageSize[axis], this._contentSize[axis] - (page + 1) * this._pageSize[axis]);
  12877. var delta = -pos - page * this._pageSize[axis];
  12878. if (Math.abs(change) > this._pageSize[axis]) {
  12879. if (delta > testPageSize * 0.5)
  12880. page++;
  12881. }
  12882. else {
  12883. if (delta > testPageSize * (change < 0 ? 0.3 : 0.7))
  12884. page++;
  12885. }
  12886. pos = -page * this._pageSize[axis];
  12887. if (pos < -this._overlapSize[axis])
  12888. pos = -this._overlapSize[axis];
  12889. }
  12890. if (inertialScrolling) {
  12891. var oldPos = this._tweenStart[axis];
  12892. var oldPage;
  12893. if (oldPos > 0)
  12894. oldPage = 0;
  12895. else if (oldPos < -this._overlapSize[axis])
  12896. oldPage = Math.ceil(this._contentSize[axis] / this._pageSize[axis]) - 1;
  12897. else
  12898. oldPage = Math.floor(-oldPos / this._pageSize[axis]);
  12899. var startPage = Math.floor(-this._containerPos[axis] / this._pageSize[axis]);
  12900. if (Math.abs(page - startPage) > 1 && Math.abs(oldPage - startPage) <= 1) {
  12901. if (page > startPage)
  12902. page = startPage + 1;
  12903. else
  12904. page = startPage - 1;
  12905. pos = -page * this._pageSize[axis];
  12906. }
  12907. }
  12908. return pos;
  12909. };
  12910. ScrollPane.prototype.updateTargetAndDuration = function (orignPos, resultPos) {
  12911. resultPos.x = this.updateTargetAndDuration2(orignPos.x, "x");
  12912. resultPos.y = this.updateTargetAndDuration2(orignPos.y, "y");
  12913. };
  12914. ScrollPane.prototype.updateTargetAndDuration2 = function (pos, axis) {
  12915. var v = this._velocity[axis];
  12916. var duration = 0;
  12917. if (pos > 0)
  12918. pos = 0;
  12919. else if (pos < -this._overlapSize[axis])
  12920. pos = -this._overlapSize[axis];
  12921. else {
  12922. var isMobile = cc.sys.isMobile;
  12923. var v2 = Math.abs(v) * this._velocityScale;
  12924. if (isMobile)
  12925. v2 *= 1136 / Math.max(cc.winSize.width, cc.winSize.height);
  12926. var ratio = 0;
  12927. if (this._pageMode || !isMobile) {
  12928. if (v2 > 500)
  12929. ratio = Math.pow((v2 - 500) / 500, 2);
  12930. }
  12931. else {
  12932. if (v2 > 1000)
  12933. ratio = Math.pow((v2 - 1000) / 1000, 2);
  12934. }
  12935. if (ratio != 0) {
  12936. if (ratio > 1)
  12937. ratio = 1;
  12938. v2 *= ratio;
  12939. v *= ratio;
  12940. this._velocity[axis] = v;
  12941. duration = Math.log(60 / v2) / Math.log(this._decelerationRate) / 60;
  12942. var change = Math.floor(v * duration * 0.4);
  12943. pos += change;
  12944. }
  12945. }
  12946. if (duration < TWEEN_TIME_DEFAULT)
  12947. duration = TWEEN_TIME_DEFAULT;
  12948. this._tweenDuration[axis] = duration;
  12949. return pos;
  12950. };
  12951. ScrollPane.prototype.fixDuration = function (axis, oldChange) {
  12952. if (this._tweenChange[axis] == 0 || Math.abs(this._tweenChange[axis]) >= Math.abs(oldChange))
  12953. return;
  12954. var newDuration = Math.abs(this._tweenChange[axis] / oldChange) * this._tweenDuration[axis];
  12955. if (newDuration < TWEEN_TIME_DEFAULT)
  12956. newDuration = TWEEN_TIME_DEFAULT;
  12957. this._tweenDuration[axis] = newDuration;
  12958. };
  12959. ScrollPane.prototype.startTween = function (type) {
  12960. this._tweenTime.set(cc.Vec2.ZERO);
  12961. this._tweening = type;
  12962. this.updateScrollBarVisible();
  12963. };
  12964. ScrollPane.prototype.killTween = function () {
  12965. if (this._tweening == 1) {
  12966. this._container.setPosition(this._tweenStart.x + this._tweenChange.x, -(this._tweenStart.y + this._tweenChange.y));
  12967. this._owner.node.emit(fgui.Event.SCROLL, this._owner);
  12968. }
  12969. this._tweening = 0;
  12970. this.updateScrollBarVisible();
  12971. this._owner.node.emit(fgui.Event.SCROLL_END, this._owner);
  12972. };
  12973. ScrollPane.prototype.checkRefreshBar = function () {
  12974. if (this._header == null && this._footer == null)
  12975. return;
  12976. var pos = (this._refreshBarAxis == "x" ? this._container.x : (-this._container.y));
  12977. if (this._header) {
  12978. if (pos > 0) {
  12979. this._header.node.active = true;
  12980. var pt = s_vec2;
  12981. pt.x = this._header.width;
  12982. pt.y = this._header.height;
  12983. pt[this._refreshBarAxis] = pos;
  12984. this._header.setSize(pt.x, pt.y);
  12985. }
  12986. else {
  12987. this._header.node.active = false;
  12988. }
  12989. }
  12990. if (this._footer) {
  12991. var max = this._overlapSize[this._refreshBarAxis];
  12992. if (pos < -max || max == 0 && this._footerLockedSize > 0) {
  12993. this._footer.node.active = true;
  12994. pt = s_vec2;
  12995. pt.x = this._footer.x;
  12996. pt.y = this._footer.y;
  12997. if (max > 0)
  12998. pt[this._refreshBarAxis] = pos + this._contentSize[this._refreshBarAxis];
  12999. else
  13000. 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]);
  13001. this._footer.setPosition(pt.x, pt.y);
  13002. pt.x = this._footer.width;
  13003. pt.y = this._footer.height;
  13004. if (max > 0)
  13005. pt[this._refreshBarAxis] = -max - pos;
  13006. else
  13007. pt[this._refreshBarAxis] = this._viewSize[this._refreshBarAxis] - this._footer[this._refreshBarAxis];
  13008. this._footer.setSize(pt.x, pt.y);
  13009. }
  13010. else {
  13011. this._footer.node.active = false;
  13012. }
  13013. }
  13014. };
  13015. ScrollPane.prototype.update = function (dt) {
  13016. if (this._tweening == 0)
  13017. return;
  13018. var nx = this.runTween("x", dt);
  13019. var ny = this.runTween("y", dt);
  13020. this._container.setPosition(nx, -ny);
  13021. if (this._tweening == 2) {
  13022. if (this._overlapSize.x > 0)
  13023. this._xPos = fgui.ToolSet.clamp(-nx, 0, this._overlapSize.x);
  13024. if (this._overlapSize.y > 0)
  13025. this._yPos = fgui.ToolSet.clamp(-ny, 0, this._overlapSize.y);
  13026. if (this._pageMode)
  13027. this.updatePageController();
  13028. }
  13029. if (this._tweenChange.x == 0 && this._tweenChange.y == 0) {
  13030. this._tweening = 0;
  13031. this.loopCheckingCurrent();
  13032. this.updateScrollBarPos();
  13033. this.updateScrollBarVisible();
  13034. this._owner.node.emit(fgui.Event.SCROLL, this._owner);
  13035. this._owner.node.emit(fgui.Event.SCROLL_END, this._owner);
  13036. }
  13037. else {
  13038. this.updateScrollBarPos();
  13039. this._owner.node.emit(fgui.Event.SCROLL, this._owner);
  13040. }
  13041. return true;
  13042. };
  13043. ScrollPane.prototype.runTween = function (axis, dt) {
  13044. var newValue;
  13045. if (this._tweenChange[axis] != 0) {
  13046. this._tweenTime[axis] += dt;
  13047. if (this._tweenTime[axis] >= this._tweenDuration[axis]) {
  13048. newValue = this._tweenStart[axis] + this._tweenChange[axis];
  13049. this._tweenChange[axis] = 0;
  13050. }
  13051. else {
  13052. var ratio = easeFunc(this._tweenTime[axis], this._tweenDuration[axis]);
  13053. newValue = this._tweenStart[axis] + Math.floor(this._tweenChange[axis] * ratio);
  13054. }
  13055. var threshold1 = 0;
  13056. var threshold2 = -this._overlapSize[axis];
  13057. if (this._headerLockedSize > 0 && this._refreshBarAxis == axis)
  13058. threshold1 = this._headerLockedSize;
  13059. if (this._footerLockedSize > 0 && this._refreshBarAxis == axis) {
  13060. var max = this._overlapSize[this._refreshBarAxis];
  13061. if (max == 0)
  13062. max = Math.max(this._contentSize[this._refreshBarAxis] + this._footerLockedSize - this._viewSize[this._refreshBarAxis], 0);
  13063. else
  13064. max += this._footerLockedSize;
  13065. threshold2 = -max;
  13066. }
  13067. if (this._tweening == 2 && this._bouncebackEffect) {
  13068. if (newValue > 20 + threshold1 && this._tweenChange[axis] > 0
  13069. || newValue > threshold1 && this._tweenChange[axis] == 0) {
  13070. this._tweenTime[axis] = 0;
  13071. this._tweenDuration[axis] = TWEEN_TIME_DEFAULT;
  13072. this._tweenChange[axis] = -newValue + threshold1;
  13073. this._tweenStart[axis] = newValue;
  13074. }
  13075. else if (newValue < threshold2 - 20 && this._tweenChange[axis] < 0
  13076. || newValue < threshold2 && this._tweenChange[axis] == 0) {
  13077. this._tweenTime[axis] = 0;
  13078. this._tweenDuration[axis] = TWEEN_TIME_DEFAULT;
  13079. this._tweenChange[axis] = threshold2 - newValue;
  13080. this._tweenStart[axis] = newValue;
  13081. }
  13082. }
  13083. else {
  13084. if (newValue > threshold1) {
  13085. newValue = threshold1;
  13086. this._tweenChange[axis] = 0;
  13087. }
  13088. else if (newValue < threshold2) {
  13089. newValue = threshold2;
  13090. this._tweenChange[axis] = 0;
  13091. }
  13092. }
  13093. }
  13094. else
  13095. newValue = (axis == "x" ? this._container.x : (-this._container.y));
  13096. return newValue;
  13097. };
  13098. return ScrollPane;
  13099. }(cc.Component));
  13100. fgui.ScrollPane = ScrollPane;
  13101. var _gestureFlag = 0;
  13102. var TWEEN_TIME_GO = 0.5;
  13103. var TWEEN_TIME_DEFAULT = 0.3;
  13104. var PULL_RATIO = 0.5;
  13105. var s_vec2 = new cc.Vec2();
  13106. var s_rect = new cc.Rect();
  13107. var sEndPos = new cc.Vec2();
  13108. var sOldChange = new cc.Vec2();
  13109. function easeFunc(t, d) {
  13110. return (t = t / d - 1) * t * t + 1;
  13111. }
  13112. })(fgui || (fgui = {}));
  13113. (function (fgui) {
  13114. var Transition = (function () {
  13115. function Transition(owner) {
  13116. this._ownerBaseX = 0;
  13117. this._ownerBaseY = 0;
  13118. this._totalTimes = 0;
  13119. this._totalTasks = 0;
  13120. this._options = 0;
  13121. this._totalDuration = 0;
  13122. this._autoPlayTimes = 1;
  13123. this._autoPlayDelay = 0;
  13124. this._timeScale = 1;
  13125. this._startTime = 0;
  13126. this._endTime = 0;
  13127. this._owner = owner;
  13128. this._items = new Array();
  13129. }
  13130. Transition.prototype.play = function (onComplete, times, delay, startTime, endTime) {
  13131. this._play(onComplete, times, delay, startTime, endTime, false);
  13132. };
  13133. Transition.prototype.playReverse = function (onComplete, times, delay) {
  13134. this._play(onComplete, times, delay, 0, -1, true);
  13135. };
  13136. Transition.prototype.changePlayTimes = function (value) {
  13137. this._totalTimes = value;
  13138. };
  13139. Transition.prototype.setAutoPlay = function (value, times, delay) {
  13140. if (times == undefined)
  13141. times = -1;
  13142. if (delay == undefined)
  13143. delay = 0;
  13144. if (this._autoPlay != value) {
  13145. this._autoPlay = value;
  13146. this._autoPlayTimes = times;
  13147. this._autoPlayDelay = delay;
  13148. if (this._autoPlay) {
  13149. if (this._owner.onStage)
  13150. this.play(null, this._autoPlayTimes, this._autoPlayDelay);
  13151. }
  13152. else {
  13153. if (!this._owner.onStage)
  13154. this.stop(false, true);
  13155. }
  13156. }
  13157. };
  13158. Transition.prototype._play = function (onComplete, times, delay, startTime, endTime, reversed) {
  13159. if (times == undefined)
  13160. times = 1;
  13161. if (delay == undefined)
  13162. delay = 0;
  13163. if (startTime == undefined)
  13164. startTime = 0;
  13165. if (endTime == undefined)
  13166. endTime = -1;
  13167. this.stop(true, true);
  13168. this._totalTimes = times;
  13169. this._reversed = reversed;
  13170. this._startTime = startTime;
  13171. this._endTime = endTime;
  13172. this._playing = true;
  13173. this._paused = false;
  13174. this._onComplete = onComplete;
  13175. var cnt = this._items.length;
  13176. for (var i = 0; i < cnt; i++) {
  13177. var item = this._items[i];
  13178. if (item.target == null) {
  13179. if (item.targetId)
  13180. item.target = this._owner.getChildById(item.targetId);
  13181. else
  13182. item.target = this._owner;
  13183. }
  13184. else if (item.target != this._owner && item.target.parent != this._owner)
  13185. item.target = null;
  13186. if (item.target && item.type == ActionType.Transition) {
  13187. var trans = item.target.getTransition(item.value.transName);
  13188. if (trans == this)
  13189. trans = null;
  13190. if (trans) {
  13191. if (item.value.playTimes == 0) {
  13192. var j;
  13193. for (j = i - 1; j >= 0; j--) {
  13194. var item2 = this._items[j];
  13195. if (item2.type == ActionType.Transition) {
  13196. if (item2.value.trans == trans) {
  13197. item2.value.stopTime = item.time - item2.time;
  13198. break;
  13199. }
  13200. }
  13201. }
  13202. if (j < 0)
  13203. item.value.stopTime = 0;
  13204. else
  13205. trans = null;
  13206. }
  13207. else
  13208. item.value.stopTime = -1;
  13209. }
  13210. item.value.trans = trans;
  13211. }
  13212. }
  13213. if (delay == 0)
  13214. this.onDelayedPlay();
  13215. else
  13216. fgui.GTween.delayedCall(delay).setTarget(this).onComplete(this.onDelayedPlay, this);
  13217. };
  13218. Transition.prototype.stop = function (setToComplete, processCallback) {
  13219. if (setToComplete == undefined)
  13220. setToComplete = true;
  13221. if (!this._playing)
  13222. return;
  13223. this._playing = false;
  13224. this._totalTasks = 0;
  13225. this._totalTimes = 0;
  13226. var func = this._onComplete;
  13227. this._onComplete = null;
  13228. fgui.GTween.kill(this);
  13229. var cnt = this._items.length;
  13230. if (this._reversed) {
  13231. for (var i = cnt - 1; i >= 0; i--) {
  13232. var item = this._items[i];
  13233. if (item.target == null)
  13234. continue;
  13235. this.stopItem(item, setToComplete);
  13236. }
  13237. }
  13238. else {
  13239. for (i = 0; i < cnt; i++) {
  13240. item = this._items[i];
  13241. if (item.target == null)
  13242. continue;
  13243. this.stopItem(item, setToComplete);
  13244. }
  13245. }
  13246. if (processCallback && func != null) {
  13247. func();
  13248. }
  13249. };
  13250. Transition.prototype.stopItem = function (item, setToComplete) {
  13251. if (item.displayLockToken != 0) {
  13252. item.target.releaseDisplayLock(item.displayLockToken);
  13253. item.displayLockToken = 0;
  13254. }
  13255. if (item.tweener) {
  13256. item.tweener.kill(setToComplete);
  13257. item.tweener = null;
  13258. if (item.type == ActionType.Shake && !setToComplete) {
  13259. item.target._gearLocked = true;
  13260. item.target.setPosition(item.target.x - item.value.lastOffsetX, item.target.y - item.value.lastOffsetY);
  13261. item.target._gearLocked = false;
  13262. }
  13263. }
  13264. if (item.type == ActionType.Transition) {
  13265. var trans = item.value.trans;
  13266. if (trans)
  13267. trans.stop(setToComplete, false);
  13268. }
  13269. };
  13270. Transition.prototype.setPaused = function (paused) {
  13271. if (!this._playing || this._paused == paused)
  13272. return;
  13273. this._paused = paused;
  13274. var tweener = fgui.GTween.getTween(this);
  13275. if (tweener)
  13276. tweener.setPaused(paused);
  13277. var cnt = this._items.length;
  13278. for (var i = 0; i < cnt; i++) {
  13279. var item = this._items[i];
  13280. if (item.target == null)
  13281. continue;
  13282. if (item.type == ActionType.Transition) {
  13283. if (item.value.trans)
  13284. item.value.trans.setPaused(paused);
  13285. }
  13286. else if (item.type == ActionType.Animation) {
  13287. if (paused) {
  13288. item.value.flag = item.target.getProp(fgui.ObjectPropID.Playing);
  13289. item.target.setProp(fgui.ObjectPropID.Playing, false);
  13290. }
  13291. else
  13292. item.target.setProp(fgui.ObjectPropID.Playing, item.value.flag);
  13293. }
  13294. if (item.tweener)
  13295. item.tweener.setPaused(paused);
  13296. }
  13297. };
  13298. Transition.prototype.dispose = function () {
  13299. if (this._playing)
  13300. fgui.GTween.kill(this);
  13301. var cnt = this._items.length;
  13302. for (var i = 0; i < cnt; i++) {
  13303. var item = this._items[i];
  13304. if (item.tweener) {
  13305. item.tweener.kill();
  13306. item.tweener = null;
  13307. }
  13308. item.target = null;
  13309. item.hook = null;
  13310. if (item.tweenConfig)
  13311. item.tweenConfig.endHook = null;
  13312. }
  13313. this._items.length = 0;
  13314. this._playing = false;
  13315. this._onComplete = null;
  13316. };
  13317. Object.defineProperty(Transition.prototype, "playing", {
  13318. get: function () {
  13319. return this._playing;
  13320. },
  13321. enumerable: false,
  13322. configurable: true
  13323. });
  13324. Transition.prototype.setValue = function (label) {
  13325. var args = [];
  13326. for (var _i = 1; _i < arguments.length; _i++) {
  13327. args[_i - 1] = arguments[_i];
  13328. }
  13329. var cnt = this._items.length;
  13330. var value;
  13331. for (var i = 0; i < cnt; i++) {
  13332. var item = this._items[i];
  13333. if (item.label == label) {
  13334. if (item.tweenConfig)
  13335. value = item.tweenConfig.startValue;
  13336. else
  13337. value = item.value;
  13338. }
  13339. else if (item.tweenConfig && item.tweenConfig.endLabel == label) {
  13340. value = item.tweenConfig.endValue;
  13341. }
  13342. else
  13343. continue;
  13344. switch (item.type) {
  13345. case ActionType.XY:
  13346. case ActionType.Size:
  13347. case ActionType.Pivot:
  13348. case ActionType.Scale:
  13349. case ActionType.Skew:
  13350. value.b1 = true;
  13351. value.b2 = true;
  13352. value.f1 = parseFloat(args[0]);
  13353. value.f2 = parseFloat(args[1]);
  13354. break;
  13355. case ActionType.Alpha:
  13356. value.f1 = parseFloat(args[0]);
  13357. break;
  13358. case ActionType.Rotation:
  13359. value.f1 = parseFloat(args[0]);
  13360. break;
  13361. case ActionType.Color:
  13362. value.f1 = parseFloat(args[0]);
  13363. break;
  13364. case ActionType.Animation:
  13365. value.frame = parseInt(args[0]);
  13366. if (args.length > 1)
  13367. value.playing = args[1];
  13368. break;
  13369. case ActionType.Visible:
  13370. value.visible = args[0];
  13371. break;
  13372. case ActionType.Sound:
  13373. value.sound = args[0];
  13374. if (args.length > 1)
  13375. value.volume = parseFloat(args[1]);
  13376. break;
  13377. case ActionType.Transition:
  13378. value.transName = args[0];
  13379. if (args.length > 1)
  13380. value.playTimes = parseInt(args[1]);
  13381. break;
  13382. case ActionType.Shake:
  13383. value.amplitude = parseFloat(args[0]);
  13384. if (args.length > 1)
  13385. value.duration = parseFloat(args[1]);
  13386. break;
  13387. case ActionType.ColorFilter:
  13388. value.f1 = parseFloat(args[0]);
  13389. value.f2 = parseFloat(args[1]);
  13390. value.f3 = parseFloat(args[2]);
  13391. value.f4 = parseFloat(args[3]);
  13392. break;
  13393. case ActionType.Text:
  13394. case ActionType.Icon:
  13395. value.text = args[0];
  13396. break;
  13397. }
  13398. }
  13399. };
  13400. Transition.prototype.setHook = function (label, callback) {
  13401. var cnt = this._items.length;
  13402. for (var i = 0; i < cnt; i++) {
  13403. var item = this._items[i];
  13404. if (item.label == label) {
  13405. item.hook = callback;
  13406. break;
  13407. }
  13408. else if (item.tweenConfig && item.tweenConfig.endLabel == label) {
  13409. item.tweenConfig.endHook = callback;
  13410. break;
  13411. }
  13412. }
  13413. };
  13414. Transition.prototype.clearHooks = function () {
  13415. var cnt = this._items.length;
  13416. for (var i = 0; i < cnt; i++) {
  13417. var item = this._items[i];
  13418. item.hook = null;
  13419. if (item.tweenConfig)
  13420. item.tweenConfig.endHook = null;
  13421. }
  13422. };
  13423. Transition.prototype.setTarget = function (label, newTarget) {
  13424. var cnt = this._items.length;
  13425. for (var i = 0; i < cnt; i++) {
  13426. var item = this._items[i];
  13427. if (item.label == label) {
  13428. item.targetId = newTarget.id;
  13429. item.target = null;
  13430. }
  13431. }
  13432. };
  13433. Transition.prototype.setDuration = function (label, value) {
  13434. var cnt = this._items.length;
  13435. for (var i = 0; i < cnt; i++) {
  13436. var item = this._items[i];
  13437. if (item.tweenConfig && item.label == label)
  13438. item.tweenConfig.duration = value;
  13439. }
  13440. };
  13441. Transition.prototype.getLabelTime = function (label) {
  13442. var cnt = this._items.length;
  13443. for (var i = 0; i < cnt; i++) {
  13444. var item = this._items[i];
  13445. if (item.label == label)
  13446. return item.time;
  13447. else if (item.tweenConfig && item.tweenConfig.endLabel == label)
  13448. return item.time + item.tweenConfig.duration;
  13449. }
  13450. return Number.NaN;
  13451. };
  13452. Object.defineProperty(Transition.prototype, "timeScale", {
  13453. get: function () {
  13454. return this._timeScale;
  13455. },
  13456. set: function (value) {
  13457. if (this._timeScale != value) {
  13458. this._timeScale = value;
  13459. if (this._playing) {
  13460. var cnt = this._items.length;
  13461. for (var i = 0; i < cnt; i++) {
  13462. var item = this._items[i];
  13463. if (item.tweener)
  13464. item.tweener.setTimeScale(value);
  13465. else if (item.type == ActionType.Transition) {
  13466. if (item.value.trans)
  13467. item.value.trans.timeScale = value;
  13468. }
  13469. else if (item.type == ActionType.Animation) {
  13470. if (item.target)
  13471. item.target.setProp(fgui.ObjectPropID.TimeScale, value);
  13472. }
  13473. }
  13474. }
  13475. }
  13476. },
  13477. enumerable: false,
  13478. configurable: true
  13479. });
  13480. Transition.prototype.updateFromRelations = function (targetId, dx, dy) {
  13481. var cnt = this._items.length;
  13482. if (cnt == 0)
  13483. return;
  13484. for (var i = 0; i < cnt; i++) {
  13485. var item = this._items[i];
  13486. if (item.type == ActionType.XY && item.targetId == targetId) {
  13487. if (item.tweenConfig) {
  13488. item.tweenConfig.startValue.f1 += dx;
  13489. item.tweenConfig.startValue.f2 += dy;
  13490. item.tweenConfig.endValue.f1 += dx;
  13491. item.tweenConfig.endValue.f2 += dy;
  13492. }
  13493. else {
  13494. item.value.f1 += dx;
  13495. item.value.f2 += dy;
  13496. }
  13497. }
  13498. }
  13499. };
  13500. Transition.prototype.onEnable = function () {
  13501. if (this._autoPlay && !this._playing)
  13502. this.play(null, this._autoPlayTimes, this._autoPlayDelay);
  13503. };
  13504. Transition.prototype.onDisable = function () {
  13505. if ((this._options & OPTION_AUTO_STOP_DISABLED) == 0)
  13506. this.stop((this._options & OPTION_AUTO_STOP_AT_END) != 0 ? true : false, false);
  13507. };
  13508. Transition.prototype.onDelayedPlay = function () {
  13509. this.internalPlay();
  13510. this._playing = this._totalTasks > 0;
  13511. if (this._playing) {
  13512. if ((this._options & OPTION_IGNORE_DISPLAY_CONTROLLER) != 0) {
  13513. var cnt = this._items.length;
  13514. for (var i = 0; i < cnt; i++) {
  13515. var item = this._items[i];
  13516. if (item.target && item.target != this._owner)
  13517. item.displayLockToken = item.target.addDisplayLock();
  13518. }
  13519. }
  13520. }
  13521. else if (this._onComplete != null) {
  13522. var func = this._onComplete;
  13523. this._onComplete = null;
  13524. func();
  13525. }
  13526. };
  13527. Transition.prototype.internalPlay = function () {
  13528. this._ownerBaseX = this._owner.x;
  13529. this._ownerBaseY = this._owner.y;
  13530. this._totalTasks = 1;
  13531. var cnt = this._items.length;
  13532. var item;
  13533. var needSkipAnimations = false;
  13534. var i;
  13535. if (!this._reversed) {
  13536. for (i = 0; i < cnt; i++) {
  13537. item = this._items[i];
  13538. if (item.target == null)
  13539. continue;
  13540. if (item.type == ActionType.Animation && this._startTime != 0 && item.time <= this._startTime) {
  13541. needSkipAnimations = true;
  13542. item.value.flag = false;
  13543. }
  13544. else
  13545. this.playItem(item);
  13546. }
  13547. }
  13548. else {
  13549. for (i = cnt - 1; i >= 0; i--) {
  13550. item = this._items[i];
  13551. if (item.target == null)
  13552. continue;
  13553. this.playItem(item);
  13554. }
  13555. }
  13556. if (needSkipAnimations)
  13557. this.skipAnimations();
  13558. this._totalTasks--;
  13559. };
  13560. Transition.prototype.playItem = function (item) {
  13561. var time;
  13562. if (item.tweenConfig) {
  13563. if (this._reversed)
  13564. time = (this._totalDuration - item.time - item.tweenConfig.duration);
  13565. else
  13566. time = item.time;
  13567. if (this._endTime == -1 || time <= this._endTime) {
  13568. var startValue;
  13569. var endValue;
  13570. if (this._reversed) {
  13571. startValue = item.tweenConfig.endValue;
  13572. endValue = item.tweenConfig.startValue;
  13573. }
  13574. else {
  13575. startValue = item.tweenConfig.startValue;
  13576. endValue = item.tweenConfig.endValue;
  13577. }
  13578. item.value.b1 = startValue.b1 || endValue.b1;
  13579. item.value.b2 = startValue.b2 || endValue.b2;
  13580. switch (item.type) {
  13581. case ActionType.XY:
  13582. case ActionType.Size:
  13583. case ActionType.Scale:
  13584. case ActionType.Skew:
  13585. item.tweener = fgui.GTween.to2(startValue.f1, startValue.f2, endValue.f1, endValue.f2, item.tweenConfig.duration);
  13586. break;
  13587. case ActionType.Alpha:
  13588. case ActionType.Rotation:
  13589. item.tweener = fgui.GTween.to(startValue.f1, endValue.f1, item.tweenConfig.duration);
  13590. break;
  13591. case ActionType.Color:
  13592. item.tweener = fgui.GTween.toColor(startValue.f1, endValue.f1, item.tweenConfig.duration);
  13593. break;
  13594. case ActionType.ColorFilter:
  13595. item.tweener = fgui.GTween.to4(startValue.f1, startValue.f2, startValue.f3, startValue.f4, endValue.f1, endValue.f2, endValue.f3, endValue.f4, item.tweenConfig.duration);
  13596. break;
  13597. }
  13598. item.tweener.setDelay(time)
  13599. .setEase(item.tweenConfig.easeType)
  13600. .setRepeat(item.tweenConfig.repeat, item.tweenConfig.yoyo)
  13601. .setTimeScale(this._timeScale)
  13602. .setTarget(item)
  13603. .onStart(this.onTweenStart, this)
  13604. .onUpdate(this.onTweenUpdate, this)
  13605. .onComplete(this.onTweenComplete, this);
  13606. if (this._endTime >= 0)
  13607. item.tweener.setBreakpoint(this._endTime - time);
  13608. this._totalTasks++;
  13609. }
  13610. }
  13611. else if (item.type == ActionType.Shake) {
  13612. if (this._reversed)
  13613. time = (this._totalDuration - item.time - item.value.duration);
  13614. else
  13615. time = item.time;
  13616. item.value.offsetX = item.value.offsetY = 0;
  13617. item.value.lastOffsetX = item.value.lastOffsetY = 0;
  13618. item.tweener = fgui.GTween.shake(0, 0, item.value.amplitude, item.value.duration)
  13619. .setDelay(time)
  13620. .setTimeScale(this._timeScale)
  13621. .setTarget(item)
  13622. .onUpdate(this.onTweenUpdate, this)
  13623. .onComplete(this.onTweenComplete, this);
  13624. if (this._endTime >= 0)
  13625. item.tweener.setBreakpoint(this._endTime - item.time);
  13626. this._totalTasks++;
  13627. }
  13628. else {
  13629. if (this._reversed)
  13630. time = (this._totalDuration - item.time);
  13631. else
  13632. time = item.time;
  13633. if (time <= this._startTime) {
  13634. this.applyValue(item);
  13635. this.callHook(item, false);
  13636. }
  13637. else if (this._endTime == -1 || time <= this._endTime) {
  13638. this._totalTasks++;
  13639. item.tweener = fgui.GTween.delayedCall(time)
  13640. .setTimeScale(this._timeScale)
  13641. .setTarget(item)
  13642. .onComplete(this.onDelayedPlayItem, this);
  13643. }
  13644. }
  13645. if (item.tweener)
  13646. item.tweener.seek(this._startTime);
  13647. };
  13648. Transition.prototype.skipAnimations = function () {
  13649. var frame;
  13650. var playStartTime;
  13651. var playTotalTime;
  13652. var value;
  13653. var target;
  13654. var item;
  13655. var cnt = this._items.length;
  13656. for (var i = 0; i < cnt; i++) {
  13657. item = this._items[i];
  13658. if (item.type != ActionType.Animation || item.time > this._startTime)
  13659. continue;
  13660. value = item.value;
  13661. if (value.flag)
  13662. continue;
  13663. target = item.target;
  13664. frame = target.getProp(fgui.ObjectPropID.Frame);
  13665. playStartTime = target.getProp(fgui.ObjectPropID.Playing) ? 0 : -1;
  13666. playTotalTime = 0;
  13667. for (var j = i; j < cnt; j++) {
  13668. item = this._items[j];
  13669. if (item.type != ActionType.Animation || item.target != target || item.time > this._startTime)
  13670. continue;
  13671. value = item.value;
  13672. value.flag = true;
  13673. if (value.frame != -1) {
  13674. frame = value.frame;
  13675. if (value.playing)
  13676. playStartTime = item.time;
  13677. else
  13678. playStartTime = -1;
  13679. playTotalTime = 0;
  13680. }
  13681. else {
  13682. if (value.playing) {
  13683. if (playStartTime < 0)
  13684. playStartTime = item.time;
  13685. }
  13686. else {
  13687. if (playStartTime >= 0)
  13688. playTotalTime += (item.time - playStartTime);
  13689. playStartTime = -1;
  13690. }
  13691. }
  13692. this.callHook(item, false);
  13693. }
  13694. if (playStartTime >= 0)
  13695. playTotalTime += (this._startTime - playStartTime);
  13696. target.setProp(fgui.ObjectPropID.Playing, playStartTime >= 0);
  13697. target.setProp(fgui.ObjectPropID.Frame, frame);
  13698. if (playTotalTime > 0)
  13699. target.setProp(fgui.ObjectPropID.DeltaTime, playTotalTime * 1000);
  13700. }
  13701. };
  13702. Transition.prototype.onDelayedPlayItem = function (tweener) {
  13703. var item = tweener.target;
  13704. item.tweener = null;
  13705. this._totalTasks--;
  13706. this.applyValue(item);
  13707. this.callHook(item, false);
  13708. this.checkAllComplete();
  13709. };
  13710. Transition.prototype.onTweenStart = function (tweener) {
  13711. var item = tweener.target;
  13712. if (item.type == ActionType.XY || item.type == ActionType.Size) {
  13713. var startValue;
  13714. var endValue;
  13715. if (this._reversed) {
  13716. startValue = item.tweenConfig.endValue;
  13717. endValue = item.tweenConfig.startValue;
  13718. }
  13719. else {
  13720. startValue = item.tweenConfig.startValue;
  13721. endValue = item.tweenConfig.endValue;
  13722. }
  13723. if (item.type == ActionType.XY) {
  13724. if (item.target != this._owner) {
  13725. if (!startValue.b1)
  13726. tweener.startValue.x = item.target.x;
  13727. else if (startValue.b3)
  13728. tweener.startValue.x = startValue.f1 * this._owner.width;
  13729. if (!startValue.b2)
  13730. tweener.startValue.y = item.target.y;
  13731. else if (startValue.b3)
  13732. tweener.startValue.y = startValue.f2 * this._owner.height;
  13733. if (!endValue.b1)
  13734. tweener.endValue.x = tweener.startValue.x;
  13735. else if (endValue.b3)
  13736. tweener.endValue.x = endValue.f1 * this._owner.width;
  13737. if (!endValue.b2)
  13738. tweener.endValue.y = tweener.startValue.y;
  13739. else if (endValue.b3)
  13740. tweener.endValue.y = endValue.f2 * this._owner.height;
  13741. }
  13742. else {
  13743. if (!startValue.b1)
  13744. tweener.startValue.x = item.target.x - this._ownerBaseX;
  13745. if (!startValue.b2)
  13746. tweener.startValue.y = item.target.y - this._ownerBaseY;
  13747. if (!endValue.b1)
  13748. tweener.endValue.x = tweener.startValue.x;
  13749. if (!endValue.b2)
  13750. tweener.endValue.y = tweener.startValue.y;
  13751. }
  13752. }
  13753. else {
  13754. if (!startValue.b1)
  13755. tweener.startValue.x = item.target.width;
  13756. if (!startValue.b2)
  13757. tweener.startValue.y = item.target.height;
  13758. if (!endValue.b1)
  13759. tweener.endValue.x = tweener.startValue.x;
  13760. if (!endValue.b2)
  13761. tweener.endValue.y = tweener.startValue.y;
  13762. }
  13763. if (item.tweenConfig.path) {
  13764. item.value.b1 = item.value.b2 = true;
  13765. tweener.setPath(item.tweenConfig.path);
  13766. }
  13767. }
  13768. this.callHook(item, false);
  13769. };
  13770. Transition.prototype.onTweenUpdate = function (tweener) {
  13771. var item = tweener.target;
  13772. switch (item.type) {
  13773. case ActionType.XY:
  13774. case ActionType.Size:
  13775. case ActionType.Scale:
  13776. case ActionType.Skew:
  13777. item.value.f1 = tweener.value.x;
  13778. item.value.f2 = tweener.value.y;
  13779. if (item.tweenConfig.path) {
  13780. item.value.f1 += tweener.startValue.x;
  13781. item.value.f2 += tweener.startValue.y;
  13782. }
  13783. break;
  13784. case ActionType.Alpha:
  13785. case ActionType.Rotation:
  13786. item.value.f1 = tweener.value.x;
  13787. break;
  13788. case ActionType.Color:
  13789. item.value.f1 = tweener.value.color;
  13790. break;
  13791. case ActionType.ColorFilter:
  13792. item.value.f1 = tweener.value.x;
  13793. item.value.f2 = tweener.value.y;
  13794. item.value.f3 = tweener.value.z;
  13795. item.value.f4 = tweener.value.w;
  13796. break;
  13797. case ActionType.Shake:
  13798. item.value.offsetX = tweener.deltaValue.x;
  13799. item.value.offsetY = tweener.deltaValue.y;
  13800. break;
  13801. }
  13802. this.applyValue(item);
  13803. };
  13804. Transition.prototype.onTweenComplete = function (tweener) {
  13805. var item = tweener.target;
  13806. item.tweener = null;
  13807. this._totalTasks--;
  13808. if (tweener.allCompleted)
  13809. this.callHook(item, true);
  13810. this.checkAllComplete();
  13811. };
  13812. Transition.prototype.onPlayTransCompleted = function (item) {
  13813. this._totalTasks--;
  13814. this.checkAllComplete();
  13815. };
  13816. Transition.prototype.callHook = function (item, tweenEnd) {
  13817. if (tweenEnd) {
  13818. if (item.tweenConfig && item.tweenConfig.endHook != null)
  13819. item.tweenConfig.endHook(item.label);
  13820. }
  13821. else {
  13822. if (item.time >= this._startTime && item.hook != null)
  13823. item.hook(item.label);
  13824. }
  13825. };
  13826. Transition.prototype.checkAllComplete = function () {
  13827. if (this._playing && this._totalTasks == 0) {
  13828. if (this._totalTimes < 0) {
  13829. this.internalPlay();
  13830. if (this._totalTasks == 0)
  13831. fgui.GTween.delayedCall(0).setTarget(this).onComplete(this.checkAllComplete, this);
  13832. }
  13833. else {
  13834. this._totalTimes--;
  13835. if (this._totalTimes > 0) {
  13836. this.internalPlay();
  13837. if (this._totalTasks == 0)
  13838. fgui.GTween.delayedCall(0).setTarget(this).onComplete(this.checkAllComplete, this);
  13839. }
  13840. else {
  13841. this._playing = false;
  13842. var cnt = this._items.length;
  13843. for (var i = 0; i < cnt; i++) {
  13844. var item = this._items[i];
  13845. if (item.target && item.displayLockToken != 0) {
  13846. item.target.releaseDisplayLock(item.displayLockToken);
  13847. item.displayLockToken = 0;
  13848. }
  13849. }
  13850. if (this._onComplete != null) {
  13851. var func = this._onComplete;
  13852. this._onComplete = null;
  13853. func();
  13854. }
  13855. }
  13856. }
  13857. }
  13858. };
  13859. Transition.prototype.applyValue = function (item) {
  13860. item.target._gearLocked = true;
  13861. var value = item.value;
  13862. switch (item.type) {
  13863. case ActionType.XY:
  13864. if (item.target == this._owner) {
  13865. if (value.b1 && value.b2)
  13866. item.target.setPosition(value.f1 + this._ownerBaseX, value.f2 + this._ownerBaseY);
  13867. else if (value.b1)
  13868. item.target.x = value.f1 + this._ownerBaseX;
  13869. else
  13870. item.target.y = value.f2 + this._ownerBaseY;
  13871. }
  13872. else {
  13873. if (value.b3) {
  13874. if (value.b1 && value.b2)
  13875. item.target.setPosition(value.f1 * this._owner.width, value.f2 * this._owner.height);
  13876. else if (value.b1)
  13877. item.target.x = value.f1 * this._owner.width;
  13878. else if (value.b2)
  13879. item.target.y = value.f2 * this._owner.height;
  13880. }
  13881. else {
  13882. if (value.b1 && value.b2)
  13883. item.target.setPosition(value.f1, value.f2);
  13884. else if (value.b1)
  13885. item.target.x = value.f1;
  13886. else if (value.b2)
  13887. item.target.y = value.f2;
  13888. }
  13889. }
  13890. break;
  13891. case ActionType.Size:
  13892. if (!value.b1)
  13893. value.f1 = item.target.width;
  13894. if (!value.b2)
  13895. value.f2 = item.target.height;
  13896. item.target.setSize(value.f1, value.f2);
  13897. break;
  13898. case ActionType.Pivot:
  13899. item.target.setPivot(value.f1, value.f2, item.target.pivotAsAnchor);
  13900. break;
  13901. case ActionType.Alpha:
  13902. item.target.alpha = value.f1;
  13903. break;
  13904. case ActionType.Rotation:
  13905. item.target.rotation = value.f1;
  13906. break;
  13907. case ActionType.Scale:
  13908. item.target.setScale(value.f1, value.f2);
  13909. break;
  13910. case ActionType.Skew:
  13911. item.target.setSkew(value.f1, value.f2);
  13912. break;
  13913. case ActionType.Color:
  13914. var color = item.target.getProp(fgui.ObjectPropID.Color);
  13915. if (color instanceof cc.Color) {
  13916. var i = Math.floor(value.f1);
  13917. color.setR((i >> 16) & 0xFF).setG((i >> 8) & 0xFF).setB(i & 0xFF);
  13918. item.target.setProp(fgui.ObjectPropID.Color, color);
  13919. }
  13920. break;
  13921. case ActionType.Animation:
  13922. if (value.frame >= 0)
  13923. item.target.setProp(fgui.ObjectPropID.Frame, value.frame);
  13924. item.target.setProp(fgui.ObjectPropID.Playing, value.playing);
  13925. item.target.setProp(fgui.ObjectPropID.TimeScale, this._timeScale);
  13926. break;
  13927. case ActionType.Visible:
  13928. item.target.visible = value.visible;
  13929. break;
  13930. case ActionType.Transition:
  13931. if (this._playing) {
  13932. var trans = value.trans;
  13933. if (trans) {
  13934. this._totalTasks++;
  13935. var startTime = this._startTime > item.time ? (this._startTime - item.time) : 0;
  13936. var endTime = this._endTime >= 0 ? (this._endTime - item.time) : -1;
  13937. if (value.stopTime >= 0 && (endTime < 0 || endTime > value.stopTime))
  13938. endTime = value.stopTime;
  13939. trans.timeScale = this._timeScale;
  13940. trans._play(function () { this.onPlayTransCompleted(item); }.bind(this), value.playTimes, 0, startTime, endTime, this._reversed);
  13941. }
  13942. }
  13943. break;
  13944. case ActionType.Sound:
  13945. if (this._playing && item.time >= this._startTime) {
  13946. if (value.audioClip == null) {
  13947. var pi = fgui.UIPackage.getItemByURL(value.sound);
  13948. if (pi)
  13949. value.audioClip = pi.owner.getItemAsset(pi);
  13950. }
  13951. if (value.audioClip)
  13952. fgui.GRoot.inst.playOneShotSound(value.audioClip, value.volume);
  13953. }
  13954. break;
  13955. case ActionType.Shake:
  13956. item.target.setPosition(item.target.x - value.lastOffsetX + value.offsetX, item.target.y - value.lastOffsetY + value.offsetY);
  13957. value.lastOffsetX = value.offsetX;
  13958. value.lastOffsetY = value.offsetY;
  13959. break;
  13960. case ActionType.ColorFilter:
  13961. {
  13962. break;
  13963. }
  13964. case ActionType.Text:
  13965. item.target.text = value.text;
  13966. break;
  13967. case ActionType.Icon:
  13968. item.target.icon = value.text;
  13969. break;
  13970. }
  13971. item.target._gearLocked = false;
  13972. };
  13973. Transition.prototype.setup = function (buffer) {
  13974. this.name = buffer.readS();
  13975. this._options = buffer.readInt();
  13976. this._autoPlay = buffer.readBool();
  13977. this._autoPlayTimes = buffer.readInt();
  13978. this._autoPlayDelay = buffer.readFloat();
  13979. var cnt = buffer.readShort();
  13980. for (var i = 0; i < cnt; i++) {
  13981. var dataLen = buffer.readShort();
  13982. var curPos = buffer.position;
  13983. buffer.seek(curPos, 0);
  13984. var item = new Item(buffer.readByte());
  13985. this._items[i] = item;
  13986. item.time = buffer.readFloat();
  13987. var targetId = buffer.readShort();
  13988. if (targetId < 0)
  13989. item.targetId = "";
  13990. else
  13991. item.targetId = this._owner.getChildAt(targetId).id;
  13992. item.label = buffer.readS();
  13993. if (buffer.readBool()) {
  13994. buffer.seek(curPos, 1);
  13995. item.tweenConfig = new TweenConfig();
  13996. item.tweenConfig.duration = buffer.readFloat();
  13997. if (item.time + item.tweenConfig.duration > this._totalDuration)
  13998. this._totalDuration = item.time + item.tweenConfig.duration;
  13999. item.tweenConfig.easeType = buffer.readByte();
  14000. item.tweenConfig.repeat = buffer.readInt();
  14001. item.tweenConfig.yoyo = buffer.readBool();
  14002. item.tweenConfig.endLabel = buffer.readS();
  14003. buffer.seek(curPos, 2);
  14004. this.decodeValue(item, buffer, item.tweenConfig.startValue);
  14005. buffer.seek(curPos, 3);
  14006. this.decodeValue(item, buffer, item.tweenConfig.endValue);
  14007. if (buffer.version >= 2) {
  14008. var pathLen = buffer.readInt();
  14009. if (pathLen > 0) {
  14010. item.tweenConfig.path = new fgui.GPath();
  14011. var pts = new Array();
  14012. for (var j = 0; j < pathLen; j++) {
  14013. var curveType = buffer.readByte();
  14014. switch (curveType) {
  14015. case fgui.CurveType.Bezier:
  14016. pts.push(fgui.GPathPoint.newBezierPoint(buffer.readFloat(), buffer.readFloat(), buffer.readFloat(), buffer.readFloat()));
  14017. break;
  14018. case fgui.CurveType.CubicBezier:
  14019. pts.push(fgui.GPathPoint.newCubicBezierPoint(buffer.readFloat(), buffer.readFloat(), buffer.readFloat(), buffer.readFloat(), buffer.readFloat(), buffer.readFloat()));
  14020. break;
  14021. default:
  14022. pts.push(fgui.GPathPoint.newPoint(buffer.readFloat(), buffer.readFloat(), curveType));
  14023. break;
  14024. }
  14025. }
  14026. item.tweenConfig.path.create(pts);
  14027. }
  14028. }
  14029. }
  14030. else {
  14031. if (item.time > this._totalDuration)
  14032. this._totalDuration = item.time;
  14033. buffer.seek(curPos, 2);
  14034. this.decodeValue(item, buffer, item.value);
  14035. }
  14036. buffer.position = curPos + dataLen;
  14037. }
  14038. };
  14039. Transition.prototype.decodeValue = function (item, buffer, value) {
  14040. switch (item.type) {
  14041. case ActionType.XY:
  14042. case ActionType.Size:
  14043. case ActionType.Pivot:
  14044. case ActionType.Skew:
  14045. value.b1 = buffer.readBool();
  14046. value.b2 = buffer.readBool();
  14047. value.f1 = buffer.readFloat();
  14048. value.f2 = buffer.readFloat();
  14049. if (buffer.version >= 2 && item.type == ActionType.XY)
  14050. value.b3 = buffer.readBool();
  14051. break;
  14052. case ActionType.Alpha:
  14053. case ActionType.Rotation:
  14054. value.f1 = buffer.readFloat();
  14055. break;
  14056. case ActionType.Scale:
  14057. value.f1 = buffer.readFloat();
  14058. value.f2 = buffer.readFloat();
  14059. break;
  14060. case ActionType.Color:
  14061. var color = buffer.readColor();
  14062. value.f1 = (color.getR() << 16) + (color.getG() << 8) + color.getB();
  14063. break;
  14064. case ActionType.Animation:
  14065. value.playing = buffer.readBool();
  14066. value.frame = buffer.readInt();
  14067. break;
  14068. case ActionType.Visible:
  14069. value.visible = buffer.readBool();
  14070. break;
  14071. case ActionType.Sound:
  14072. value.sound = buffer.readS();
  14073. value.volume = buffer.readFloat();
  14074. break;
  14075. case ActionType.Transition:
  14076. value.transName = buffer.readS();
  14077. value.playTimes = buffer.readInt();
  14078. break;
  14079. case ActionType.Shake:
  14080. value.amplitude = buffer.readFloat();
  14081. value.duration = buffer.readFloat();
  14082. break;
  14083. case ActionType.ColorFilter:
  14084. value.f1 = buffer.readFloat();
  14085. value.f2 = buffer.readFloat();
  14086. value.f3 = buffer.readFloat();
  14087. value.f4 = buffer.readFloat();
  14088. break;
  14089. case ActionType.Text:
  14090. case ActionType.Icon:
  14091. value.text = buffer.readS();
  14092. break;
  14093. }
  14094. };
  14095. return Transition;
  14096. }());
  14097. fgui.Transition = Transition;
  14098. var OPTION_IGNORE_DISPLAY_CONTROLLER = 1;
  14099. var OPTION_AUTO_STOP_DISABLED = 2;
  14100. var OPTION_AUTO_STOP_AT_END = 4;
  14101. var ActionType;
  14102. (function (ActionType) {
  14103. ActionType[ActionType["XY"] = 0] = "XY";
  14104. ActionType[ActionType["Size"] = 1] = "Size";
  14105. ActionType[ActionType["Scale"] = 2] = "Scale";
  14106. ActionType[ActionType["Pivot"] = 3] = "Pivot";
  14107. ActionType[ActionType["Alpha"] = 4] = "Alpha";
  14108. ActionType[ActionType["Rotation"] = 5] = "Rotation";
  14109. ActionType[ActionType["Color"] = 6] = "Color";
  14110. ActionType[ActionType["Animation"] = 7] = "Animation";
  14111. ActionType[ActionType["Visible"] = 8] = "Visible";
  14112. ActionType[ActionType["Sound"] = 9] = "Sound";
  14113. ActionType[ActionType["Transition"] = 10] = "Transition";
  14114. ActionType[ActionType["Shake"] = 11] = "Shake";
  14115. ActionType[ActionType["ColorFilter"] = 12] = "ColorFilter";
  14116. ActionType[ActionType["Skew"] = 13] = "Skew";
  14117. ActionType[ActionType["Text"] = 14] = "Text";
  14118. ActionType[ActionType["Icon"] = 15] = "Icon";
  14119. ActionType[ActionType["Unknown"] = 16] = "Unknown";
  14120. })(ActionType || (ActionType = {}));
  14121. var Item = (function () {
  14122. function Item(type) {
  14123. this.type = type;
  14124. this.value = {};
  14125. this.displayLockToken = 0;
  14126. }
  14127. return Item;
  14128. }());
  14129. var TweenConfig = (function () {
  14130. function TweenConfig() {
  14131. this.easeType = fgui.EaseType.QuadOut;
  14132. this.startValue = { b1: true, b2: true };
  14133. this.endValue = { b1: true, b2: true };
  14134. }
  14135. return TweenConfig;
  14136. }());
  14137. })(fgui || (fgui = {}));
  14138. (function (fgui) {
  14139. var TranslationHelper = (function () {
  14140. function TranslationHelper() {
  14141. }
  14142. TranslationHelper.loadFromXML = function (source) {
  14143. var strings = {};
  14144. TranslationHelper.strings = strings;
  14145. var xml = new cc["SAXParser"]().parse(source).documentElement;
  14146. var nodes = xml.childNodes;
  14147. var length1 = nodes.length;
  14148. for (var i1 = 0; i1 < length1; i1++) {
  14149. var cxml = nodes[i1];
  14150. if (cxml.tagName == "string") {
  14151. var key = cxml.getAttribute("name");
  14152. var text = cxml.childNodes.length > 0 ? cxml.firstChild.nodeValue : "";
  14153. var i = key.indexOf("-");
  14154. if (i == -1)
  14155. continue;
  14156. var key2 = key.substr(0, i);
  14157. var key3 = key.substr(i + 1);
  14158. var col = strings[key2];
  14159. if (!col) {
  14160. col = {};
  14161. strings[key2] = col;
  14162. }
  14163. col[key3] = text;
  14164. }
  14165. }
  14166. };
  14167. TranslationHelper.translateComponent = function (item) {
  14168. if (TranslationHelper.strings == null)
  14169. return;
  14170. var compStrings = TranslationHelper.strings[item.owner.id + item.id];
  14171. if (compStrings == null)
  14172. return;
  14173. var elementId, value;
  14174. var buffer = item.rawData;
  14175. var nextPos;
  14176. var itemCount;
  14177. var i, j, k;
  14178. var dataLen;
  14179. var curPos;
  14180. var valueCnt;
  14181. var page;
  14182. buffer.seek(0, 2);
  14183. var childCount = buffer.readShort();
  14184. for (i = 0; i < childCount; i++) {
  14185. dataLen = buffer.readShort();
  14186. curPos = buffer.position;
  14187. buffer.seek(curPos, 0);
  14188. var baseType = buffer.readByte();
  14189. var type = baseType;
  14190. buffer.skip(4);
  14191. elementId = buffer.readS();
  14192. if (type == fgui.ObjectType.Component) {
  14193. if (buffer.seek(curPos, 6))
  14194. type = buffer.readByte();
  14195. }
  14196. buffer.seek(curPos, 1);
  14197. if ((value = compStrings[elementId + "-tips"]) != null)
  14198. buffer.writeS(value);
  14199. buffer.seek(curPos, 2);
  14200. var gearCnt = buffer.readShort();
  14201. for (j = 0; j < gearCnt; j++) {
  14202. nextPos = buffer.readShort();
  14203. nextPos += buffer.position;
  14204. if (buffer.readByte() == 6) {
  14205. buffer.skip(2);
  14206. valueCnt = buffer.readShort();
  14207. for (k = 0; k < valueCnt; k++) {
  14208. page = buffer.readS();
  14209. if (page != null) {
  14210. if ((value = compStrings[elementId + "-texts_" + k]) != null)
  14211. buffer.writeS(value);
  14212. else
  14213. buffer.skip(2);
  14214. }
  14215. }
  14216. if (buffer.readBool() && (value = compStrings[elementId + "-texts_def"]) != null)
  14217. buffer.writeS(value);
  14218. }
  14219. if (baseType == fgui.ObjectType.Component && buffer.version >= 2) {
  14220. buffer.seek(curPos, 4);
  14221. buffer.skip(2);
  14222. buffer.skip(4 * buffer.readShort());
  14223. var cpCount = buffer.readShort();
  14224. for (var k = 0; k < cpCount; k++) {
  14225. var target = buffer.readS();
  14226. var propertyId = buffer.readShort();
  14227. if (propertyId == 0 && (value = compStrings[elementId + "-cp-" + target]) != null)
  14228. buffer.writeS(value);
  14229. else
  14230. buffer.skip(2);
  14231. }
  14232. }
  14233. buffer.position = nextPos;
  14234. }
  14235. switch (type) {
  14236. case fgui.ObjectType.Text:
  14237. case fgui.ObjectType.RichText:
  14238. case fgui.ObjectType.InputText:
  14239. {
  14240. if ((value = compStrings[elementId]) != null) {
  14241. buffer.seek(curPos, 6);
  14242. buffer.writeS(value);
  14243. }
  14244. if ((value = compStrings[elementId + "-prompt"]) != null) {
  14245. buffer.seek(curPos, 4);
  14246. buffer.writeS(value);
  14247. }
  14248. break;
  14249. }
  14250. case fgui.ObjectType.List:
  14251. case fgui.ObjectType.Tree:
  14252. {
  14253. buffer.seek(curPos, 8);
  14254. buffer.skip(2);
  14255. itemCount = buffer.readShort();
  14256. for (j = 0; j < itemCount; j++) {
  14257. nextPos = buffer.readShort();
  14258. nextPos += buffer.position;
  14259. buffer.skip(2);
  14260. if (type == fgui.ObjectType.Tree)
  14261. buffer.skip(2);
  14262. if ((value = compStrings[elementId + "-" + j]) != null)
  14263. buffer.writeS(value);
  14264. else
  14265. buffer.skip(2);
  14266. if ((value = compStrings[elementId + "-" + j + "-0"]) != null)
  14267. buffer.writeS(value);
  14268. else
  14269. buffer.skip(2);
  14270. if (buffer.version >= 2) {
  14271. buffer.skip(6);
  14272. buffer.skip(buffer.readUshort() * 4);
  14273. var cpCount = buffer.readUshort();
  14274. for (var k = 0; k < cpCount; k++) {
  14275. var target = buffer.readS();
  14276. var propertyId = buffer.readUshort();
  14277. if (propertyId == 0 && (value = compStrings[elementId + "-" + j + "-" + target]) != null)
  14278. buffer.writeS(value);
  14279. else
  14280. buffer.skip(2);
  14281. }
  14282. }
  14283. buffer.position = nextPos;
  14284. }
  14285. break;
  14286. }
  14287. case fgui.ObjectType.Label:
  14288. {
  14289. if (buffer.seek(curPos, 6) && buffer.readByte() == type) {
  14290. if ((value = compStrings[elementId]) != null)
  14291. buffer.writeS(value);
  14292. else
  14293. buffer.skip(2);
  14294. buffer.skip(2);
  14295. if (buffer.readBool())
  14296. buffer.skip(4);
  14297. buffer.skip(4);
  14298. if (buffer.readBool() && (value = compStrings[elementId + "-prompt"]) != null)
  14299. buffer.writeS(value);
  14300. }
  14301. break;
  14302. }
  14303. case fgui.ObjectType.Button:
  14304. {
  14305. if (buffer.seek(curPos, 6) && buffer.readByte() == type) {
  14306. if ((value = compStrings[elementId]) != null)
  14307. buffer.writeS(value);
  14308. else
  14309. buffer.skip(2);
  14310. if ((value = compStrings[elementId + "-0"]) != null)
  14311. buffer.writeS(value);
  14312. }
  14313. break;
  14314. }
  14315. case fgui.ObjectType.ComboBox:
  14316. {
  14317. if (buffer.seek(curPos, 6) && buffer.readByte() == type) {
  14318. itemCount = buffer.readShort();
  14319. for (j = 0; j < itemCount; j++) {
  14320. nextPos = buffer.readShort();
  14321. nextPos += buffer.position;
  14322. if ((value = compStrings[elementId + "-" + j]) != null)
  14323. buffer.writeS(value);
  14324. buffer.position = nextPos;
  14325. }
  14326. if ((value = compStrings[elementId]) != null)
  14327. buffer.writeS(value);
  14328. }
  14329. break;
  14330. }
  14331. }
  14332. buffer.position = curPos + dataLen;
  14333. }
  14334. };
  14335. return TranslationHelper;
  14336. }());
  14337. fgui.TranslationHelper = TranslationHelper;
  14338. })(fgui || (fgui = {}));
  14339. (function (fgui) {
  14340. var UIConfig = (function () {
  14341. function UIConfig() {
  14342. }
  14343. UIConfig.defaultFont = "Arial";
  14344. UIConfig.modalLayerColor = new cc.Color(0x33, 0x33, 0x33, 0x33);
  14345. UIConfig.buttonSoundVolumeScale = 1;
  14346. UIConfig.defaultScrollStep = 25;
  14347. UIConfig.defaultScrollDecelerationRate = 0.967;
  14348. UIConfig.defaultScrollBarDisplay = fgui.ScrollBarDisplayType.Visible;
  14349. UIConfig.defaultScrollTouchEffect = true;
  14350. UIConfig.defaultScrollBounceEffect = true;
  14351. UIConfig.defaultComboBoxVisibleItemCount = 10;
  14352. UIConfig.touchScrollSensitivity = 20;
  14353. UIConfig.touchDragSensitivity = 10;
  14354. UIConfig.clickDragSensitivity = 2;
  14355. UIConfig.bringWindowToFrontOnClick = true;
  14356. UIConfig.frameTimeForAsyncUIConstruction = 0.002;
  14357. UIConfig.linkUnderline = true;
  14358. UIConfig.defaultUIGroup = "UI";
  14359. return UIConfig;
  14360. }());
  14361. fgui.UIConfig = UIConfig;
  14362. function addLoadHandler(ext) {
  14363. }
  14364. fgui.addLoadHandler = addLoadHandler;
  14365. ;
  14366. var _fontRegistry = {};
  14367. function registerFont(name, font) {
  14368. if (font instanceof cc.Font)
  14369. _fontRegistry[name] = font;
  14370. else
  14371. _fontRegistry[name] = cc.loader.getRes(name, cc.Font);
  14372. }
  14373. fgui.registerFont = registerFont;
  14374. ;
  14375. function getFontByName(name) {
  14376. return _fontRegistry[name];
  14377. }
  14378. fgui.getFontByName = getFontByName;
  14379. })(fgui || (fgui = {}));
  14380. (function (fgui) {
  14381. var UIObjectFactory = (function () {
  14382. function UIObjectFactory() {
  14383. }
  14384. UIObjectFactory.setExtension = function (url, type) {
  14385. if (url == null)
  14386. throw new Error("Invaild url: " + url);
  14387. var pi = fgui.UIPackage.getItemByURL(url);
  14388. if (pi)
  14389. pi.extensionType = type;
  14390. UIObjectFactory.extensions[url] = type;
  14391. };
  14392. UIObjectFactory.setLoaderExtension = function (type) {
  14393. UIObjectFactory.loaderType = type;
  14394. };
  14395. UIObjectFactory.resolveExtension = function (pi) {
  14396. var extensionType = UIObjectFactory.extensions["ui://" + pi.owner.id + pi.id];
  14397. if (!extensionType)
  14398. extensionType = UIObjectFactory.extensions["ui://" + pi.owner.name + "/" + pi.name];
  14399. if (extensionType)
  14400. pi.extensionType = extensionType;
  14401. };
  14402. UIObjectFactory.newObject = function (type, userClass) {
  14403. var obj;
  14404. UIObjectFactory.counter++;
  14405. if (typeof type === 'number') {
  14406. switch (type) {
  14407. case fgui.ObjectType.Image:
  14408. return new fgui.GImage();
  14409. case fgui.ObjectType.MovieClip:
  14410. return new fgui.GMovieClip();
  14411. case fgui.ObjectType.Component:
  14412. return new fgui.GComponent();
  14413. case fgui.ObjectType.Text:
  14414. return new fgui.GTextField();
  14415. case fgui.ObjectType.RichText:
  14416. return new fgui.GRichTextField();
  14417. case fgui.ObjectType.InputText:
  14418. return new fgui.GTextInput();
  14419. case fgui.ObjectType.Group:
  14420. return new fgui.GGroup();
  14421. case fgui.ObjectType.List:
  14422. return new fgui.GList();
  14423. case fgui.ObjectType.Graph:
  14424. return new fgui.GGraph();
  14425. case fgui.ObjectType.Loader:
  14426. if (UIObjectFactory.loaderType)
  14427. return new UIObjectFactory.loaderType();
  14428. else
  14429. return new fgui.GLoader();
  14430. case fgui.ObjectType.Button:
  14431. return new fgui.GButton();
  14432. case fgui.ObjectType.Label:
  14433. return new fgui.GLabel();
  14434. case fgui.ObjectType.ProgressBar:
  14435. return new fgui.GProgressBar();
  14436. case fgui.ObjectType.Slider:
  14437. return new fgui.GSlider();
  14438. case fgui.ObjectType.ScrollBar:
  14439. return new fgui.GScrollBar();
  14440. case fgui.ObjectType.ComboBox:
  14441. return new fgui.GComboBox();
  14442. case fgui.ObjectType.Tree:
  14443. return new fgui.GTree();
  14444. case fgui.ObjectType.Loader3D:
  14445. return new fgui.GLoader3D();
  14446. default:
  14447. return null;
  14448. }
  14449. }
  14450. else {
  14451. if (type.type == fgui.PackageItemType.Component) {
  14452. if (userClass)
  14453. obj = new userClass();
  14454. else if (type.extensionType)
  14455. obj = new type.extensionType();
  14456. else
  14457. obj = UIObjectFactory.newObject(type.objectType);
  14458. }
  14459. else
  14460. obj = UIObjectFactory.newObject(type.objectType);
  14461. if (obj)
  14462. obj.packageItem = type;
  14463. }
  14464. return obj;
  14465. };
  14466. UIObjectFactory.counter = 0;
  14467. UIObjectFactory.extensions = {};
  14468. return UIObjectFactory;
  14469. }());
  14470. fgui.UIObjectFactory = UIObjectFactory;
  14471. })(fgui || (fgui = {}));
  14472. (function (fgui) {
  14473. var _a;
  14474. var UIPackage = (function () {
  14475. function UIPackage() {
  14476. this._items = [];
  14477. this._itemsById = {};
  14478. this._itemsByName = {};
  14479. this._sprites = {};
  14480. this._dependencies = [];
  14481. this._branches = [];
  14482. this._branchIndex = -1;
  14483. }
  14484. Object.defineProperty(UIPackage, "branch", {
  14485. get: function () {
  14486. return UIPackage._branch;
  14487. },
  14488. set: function (value) {
  14489. UIPackage._branch = value;
  14490. for (var pkgId in UIPackage._instById) {
  14491. var pkg = UIPackage._instById[pkgId];
  14492. if (pkg._branches) {
  14493. pkg._branchIndex = pkg._branches.indexOf(value);
  14494. }
  14495. }
  14496. },
  14497. enumerable: false,
  14498. configurable: true
  14499. });
  14500. UIPackage.getVar = function (key) {
  14501. return UIPackage._vars[key];
  14502. };
  14503. UIPackage.setVar = function (key, value) {
  14504. UIPackage._vars[key] = value;
  14505. };
  14506. UIPackage.getById = function (id) {
  14507. return UIPackage._instById[id];
  14508. };
  14509. UIPackage.getByName = function (name) {
  14510. return UIPackage._instByName[name];
  14511. };
  14512. UIPackage.addPackage = function (path) {
  14513. var pkg = UIPackage._instById[path];
  14514. if (pkg)
  14515. return pkg;
  14516. var asset = cc.resources.get(path, cc.BufferAsset);
  14517. if (!asset)
  14518. throw "Resource '" + path + "' not ready";
  14519. if (!asset._buffer)
  14520. throw "Missing asset data.";
  14521. pkg = new UIPackage();
  14522. pkg._bundle = cc.resources;
  14523. pkg.loadPackage(new fgui.ByteBuffer(asset._buffer), path);
  14524. UIPackage._instById[pkg.id] = pkg;
  14525. UIPackage._instByName[pkg.name] = pkg;
  14526. UIPackage._instById[pkg._path] = pkg;
  14527. return pkg;
  14528. };
  14529. UIPackage.loadPackage = function () {
  14530. var args = [];
  14531. for (var _i = 0; _i < arguments.length; _i++) {
  14532. args[_i] = arguments[_i];
  14533. }
  14534. var path;
  14535. var onProgress;
  14536. var onComplete;
  14537. var bundle;
  14538. if (args[0] instanceof cc.AssetManager.Bundle) {
  14539. bundle = args[0];
  14540. path = args[1];
  14541. if (args.length > 3) {
  14542. onProgress = args[2];
  14543. onComplete = args[3];
  14544. }
  14545. else
  14546. onComplete = args[2];
  14547. }
  14548. else {
  14549. path = args[0];
  14550. if (args.length > 2) {
  14551. onProgress = args[1];
  14552. onComplete = args[2];
  14553. }
  14554. else
  14555. onComplete = args[1];
  14556. }
  14557. bundle = bundle || cc.resources;
  14558. bundle.load(path, cc.BufferAsset, onProgress, function (err, asset) {
  14559. if (err) {
  14560. if (onComplete != null)
  14561. onComplete(err, null);
  14562. return;
  14563. }
  14564. var pkg = new UIPackage();
  14565. pkg._bundle = bundle;
  14566. pkg.loadPackage(new fgui.ByteBuffer(asset._buffer), path);
  14567. var cnt = pkg._items.length;
  14568. var urls = [];
  14569. var types = [];
  14570. for (var i = 0; i < cnt; i++) {
  14571. var pi = pkg._items[i];
  14572. if (pi.type == fgui.PackageItemType.Atlas || pi.type == fgui.PackageItemType.Sound) {
  14573. var assetType = ItemTypeToAssetType[pi.type];
  14574. urls.push(pi.file);
  14575. types.push(assetType);
  14576. }
  14577. }
  14578. var total = urls.length;
  14579. var lastErr;
  14580. var taskComplete = function (err) {
  14581. total--;
  14582. if (err)
  14583. lastErr = err;
  14584. if (total <= 0) {
  14585. UIPackage._instById[pkg.id] = pkg;
  14586. UIPackage._instByName[pkg.name] = pkg;
  14587. if (pkg._path)
  14588. UIPackage._instByName[pkg._path] = pkg;
  14589. if (onComplete != null)
  14590. onComplete(lastErr, pkg);
  14591. }
  14592. };
  14593. if (total > 0) {
  14594. urls.forEach(function (url, index) {
  14595. bundle.load(url, types[index], onProgress, taskComplete);
  14596. });
  14597. }
  14598. else
  14599. taskComplete();
  14600. });
  14601. };
  14602. UIPackage.removePackage = function (packageIdOrName) {
  14603. var pkg = UIPackage._instById[packageIdOrName];
  14604. if (!pkg)
  14605. pkg = UIPackage._instByName[packageIdOrName];
  14606. if (!pkg)
  14607. throw "No package found: " + packageIdOrName;
  14608. pkg.dispose();
  14609. delete UIPackage._instById[pkg.id];
  14610. delete UIPackage._instByName[pkg.name];
  14611. if (pkg._path)
  14612. delete UIPackage._instById[pkg._path];
  14613. };
  14614. UIPackage.createObject = function (pkgName, resName, userClass) {
  14615. var pkg = UIPackage.getByName(pkgName);
  14616. if (pkg)
  14617. return pkg.createObject(resName, userClass);
  14618. else
  14619. return null;
  14620. };
  14621. UIPackage.createObjectFromURL = function (url, userClass) {
  14622. var pi = UIPackage.getItemByURL(url);
  14623. if (pi)
  14624. return pi.owner.internalCreateObject(pi, userClass);
  14625. else
  14626. return null;
  14627. };
  14628. UIPackage.getItemURL = function (pkgName, resName) {
  14629. var pkg = UIPackage.getByName(pkgName);
  14630. if (!pkg)
  14631. return null;
  14632. var pi = pkg._itemsByName[resName];
  14633. if (!pi)
  14634. return null;
  14635. return "ui://" + pkg.id + pi.id;
  14636. };
  14637. UIPackage.getItemByURL = function (url) {
  14638. var pos1 = url.indexOf("//");
  14639. if (pos1 == -1)
  14640. return null;
  14641. var pos2 = url.indexOf("/", pos1 + 2);
  14642. if (pos2 == -1) {
  14643. if (url.length > 13) {
  14644. var pkgId = url.substr(5, 8);
  14645. var pkg = UIPackage.getById(pkgId);
  14646. if (pkg != null) {
  14647. var srcId = url.substr(13);
  14648. return pkg.getItemById(srcId);
  14649. }
  14650. }
  14651. }
  14652. else {
  14653. var pkgName = url.substr(pos1 + 2, pos2 - pos1 - 2);
  14654. pkg = UIPackage.getByName(pkgName);
  14655. if (pkg != null) {
  14656. var srcName = url.substr(pos2 + 1);
  14657. return pkg.getItemByName(srcName);
  14658. }
  14659. }
  14660. return null;
  14661. };
  14662. UIPackage.normalizeURL = function (url) {
  14663. if (url == null)
  14664. return null;
  14665. var pos1 = url.indexOf("//");
  14666. if (pos1 == -1)
  14667. return null;
  14668. var pos2 = url.indexOf("/", pos1 + 2);
  14669. if (pos2 == -1)
  14670. return url;
  14671. var pkgName = url.substr(pos1 + 2, pos2 - pos1 - 2);
  14672. var srcName = url.substr(pos2 + 1);
  14673. return UIPackage.getItemURL(pkgName, srcName);
  14674. };
  14675. UIPackage.setStringsSource = function (source) {
  14676. fgui.TranslationHelper.loadFromXML(source);
  14677. };
  14678. UIPackage.prototype.loadPackage = function (buffer, path) {
  14679. if (buffer.readUint() != 0x46475549)
  14680. throw "FairyGUI: old package format found in '" + path + "'";
  14681. this._path = path;
  14682. buffer.version = buffer.readInt();
  14683. var ver2 = buffer.version >= 2;
  14684. var compressed = buffer.readBool();
  14685. this._id = buffer.readString();
  14686. this._name = buffer.readString();
  14687. buffer.skip(20);
  14688. var indexTablePos = buffer.position;
  14689. var cnt;
  14690. var i;
  14691. var nextPos;
  14692. var str;
  14693. var branchIncluded;
  14694. buffer.seek(indexTablePos, 4);
  14695. cnt = buffer.readInt();
  14696. var stringTable = new Array(cnt);
  14697. buffer.stringTable = stringTable;
  14698. for (i = 0; i < cnt; i++)
  14699. stringTable[i] = buffer.readString();
  14700. if (buffer.seek(indexTablePos, 5)) {
  14701. cnt = buffer.readInt();
  14702. for (i = 0; i < cnt; i++) {
  14703. var index = buffer.readUshort();
  14704. var len = buffer.readInt();
  14705. stringTable[index] = buffer.readString(len);
  14706. }
  14707. }
  14708. buffer.seek(indexTablePos, 0);
  14709. cnt = buffer.readShort();
  14710. for (i = 0; i < cnt; i++)
  14711. this._dependencies.push({ id: buffer.readS(), name: buffer.readS() });
  14712. if (ver2) {
  14713. cnt = buffer.readShort();
  14714. if (cnt > 0) {
  14715. this._branches = buffer.readSArray(cnt);
  14716. if (UIPackage._branch)
  14717. this._branchIndex = this._branches.indexOf(UIPackage._branch);
  14718. }
  14719. branchIncluded = cnt > 0;
  14720. }
  14721. buffer.seek(indexTablePos, 1);
  14722. var pi;
  14723. var pos = path.lastIndexOf('/');
  14724. var shortPath = pos == -1 ? "" : path.substr(0, pos + 1);
  14725. path = path + "_";
  14726. cnt = buffer.readShort();
  14727. for (i = 0; i < cnt; i++) {
  14728. nextPos = buffer.readInt();
  14729. nextPos += buffer.position;
  14730. pi = new fgui.PackageItem();
  14731. pi.owner = this;
  14732. pi.type = buffer.readByte();
  14733. pi.id = buffer.readS();
  14734. pi.name = buffer.readS();
  14735. buffer.readS();
  14736. pi.file = buffer.readS();
  14737. buffer.readBool();
  14738. pi.width = buffer.readInt();
  14739. pi.height = buffer.readInt();
  14740. switch (pi.type) {
  14741. case fgui.PackageItemType.Image:
  14742. {
  14743. pi.objectType = fgui.ObjectType.Image;
  14744. var scaleOption = buffer.readByte();
  14745. if (scaleOption == 1) {
  14746. pi.scale9Grid = new cc.Rect();
  14747. pi.scale9Grid.x = buffer.readInt();
  14748. pi.scale9Grid.y = buffer.readInt();
  14749. pi.scale9Grid.width = buffer.readInt();
  14750. pi.scale9Grid.height = buffer.readInt();
  14751. pi.tileGridIndice = buffer.readInt();
  14752. }
  14753. else if (scaleOption == 2)
  14754. pi.scaleByTile = true;
  14755. pi.smoothing = buffer.readBool();
  14756. break;
  14757. }
  14758. case fgui.PackageItemType.MovieClip:
  14759. {
  14760. pi.smoothing = buffer.readBool();
  14761. pi.objectType = fgui.ObjectType.MovieClip;
  14762. pi.rawData = buffer.readBuffer();
  14763. break;
  14764. }
  14765. case fgui.PackageItemType.Font:
  14766. {
  14767. pi.rawData = buffer.readBuffer();
  14768. break;
  14769. }
  14770. case fgui.PackageItemType.Component:
  14771. {
  14772. var extension = buffer.readByte();
  14773. if (extension > 0)
  14774. pi.objectType = extension;
  14775. else
  14776. pi.objectType = fgui.ObjectType.Component;
  14777. pi.rawData = buffer.readBuffer();
  14778. fgui.UIObjectFactory.resolveExtension(pi);
  14779. break;
  14780. }
  14781. case fgui.PackageItemType.Atlas:
  14782. case fgui.PackageItemType.Sound:
  14783. case fgui.PackageItemType.Misc:
  14784. {
  14785. pi.file = path + cc.path.mainFileName(pi.file);
  14786. break;
  14787. }
  14788. case fgui.PackageItemType.Spine:
  14789. case fgui.PackageItemType.DragonBones:
  14790. {
  14791. pi.file = shortPath + cc.path.mainFileName(pi.file);
  14792. pi.skeletonAnchor = new cc.Vec2();
  14793. pi.skeletonAnchor.x = buffer.readFloat();
  14794. pi.skeletonAnchor.y = buffer.readFloat();
  14795. break;
  14796. }
  14797. }
  14798. if (ver2) {
  14799. str = buffer.readS();
  14800. if (str)
  14801. pi.name = str + "/" + pi.name;
  14802. var branchCnt = buffer.readUbyte();
  14803. if (branchCnt > 0) {
  14804. if (branchIncluded)
  14805. pi.branches = buffer.readSArray(branchCnt);
  14806. else
  14807. this._itemsById[buffer.readS()] = pi;
  14808. }
  14809. var highResCnt = buffer.readUbyte();
  14810. if (highResCnt > 0)
  14811. pi.highResolution = buffer.readSArray(highResCnt);
  14812. }
  14813. this._items.push(pi);
  14814. this._itemsById[pi.id] = pi;
  14815. if (pi.name != null)
  14816. this._itemsByName[pi.name] = pi;
  14817. buffer.position = nextPos;
  14818. }
  14819. buffer.seek(indexTablePos, 2);
  14820. cnt = buffer.readShort();
  14821. for (i = 0; i < cnt; i++) {
  14822. nextPos = buffer.readShort();
  14823. nextPos += buffer.position;
  14824. var itemId = buffer.readS();
  14825. pi = this._itemsById[buffer.readS()];
  14826. var rect = new cc.Rect();
  14827. rect.x = buffer.readInt();
  14828. rect.y = buffer.readInt();
  14829. rect.width = buffer.readInt();
  14830. rect.height = buffer.readInt();
  14831. var sprite = { atlas: pi, rect: rect, offset: new cc.Vec2(), originalSize: new cc.Size(0, 0) };
  14832. sprite.rotated = buffer.readBool();
  14833. if (ver2 && buffer.readBool()) {
  14834. sprite.offset.x = buffer.readInt();
  14835. sprite.offset.y = buffer.readInt();
  14836. sprite.originalSize.width = buffer.readInt();
  14837. sprite.originalSize.height = buffer.readInt();
  14838. }
  14839. else {
  14840. sprite.originalSize.width = sprite.rect.width;
  14841. sprite.originalSize.height = sprite.rect.height;
  14842. }
  14843. this._sprites[itemId] = sprite;
  14844. buffer.position = nextPos;
  14845. }
  14846. if (buffer.seek(indexTablePos, 3)) {
  14847. cnt = buffer.readShort();
  14848. for (i = 0; i < cnt; i++) {
  14849. nextPos = buffer.readInt();
  14850. nextPos += buffer.position;
  14851. pi = this._itemsById[buffer.readS()];
  14852. if (pi && pi.type == fgui.PackageItemType.Image)
  14853. pi.hitTestData = new fgui.PixelHitTestData(buffer);
  14854. buffer.position = nextPos;
  14855. }
  14856. }
  14857. };
  14858. UIPackage.prototype.dispose = function () {
  14859. var cnt = this._items.length;
  14860. for (var i = 0; i < cnt; i++) {
  14861. var pi = this._items[i];
  14862. if (pi.asset)
  14863. cc.assetManager.releaseAsset(pi.asset);
  14864. }
  14865. };
  14866. Object.defineProperty(UIPackage.prototype, "id", {
  14867. get: function () {
  14868. return this._id;
  14869. },
  14870. enumerable: false,
  14871. configurable: true
  14872. });
  14873. Object.defineProperty(UIPackage.prototype, "name", {
  14874. get: function () {
  14875. return this._name;
  14876. },
  14877. enumerable: false,
  14878. configurable: true
  14879. });
  14880. Object.defineProperty(UIPackage.prototype, "path", {
  14881. get: function () {
  14882. return this._path;
  14883. },
  14884. enumerable: false,
  14885. configurable: true
  14886. });
  14887. Object.defineProperty(UIPackage.prototype, "dependencies", {
  14888. get: function () {
  14889. return this._dependencies;
  14890. },
  14891. enumerable: false,
  14892. configurable: true
  14893. });
  14894. UIPackage.prototype.createObject = function (resName, userClass) {
  14895. var pi = this._itemsByName[resName];
  14896. if (pi)
  14897. return this.internalCreateObject(pi, userClass);
  14898. else
  14899. return null;
  14900. };
  14901. UIPackage.prototype.internalCreateObject = function (item, userClass) {
  14902. var g = fgui.UIObjectFactory.newObject(item, userClass);
  14903. if (g == null)
  14904. return null;
  14905. UIPackage._constructing++;
  14906. g.constructFromResource();
  14907. UIPackage._constructing--;
  14908. return g;
  14909. };
  14910. UIPackage.prototype.getItemById = function (itemId) {
  14911. return this._itemsById[itemId];
  14912. };
  14913. UIPackage.prototype.getItemByName = function (resName) {
  14914. return this._itemsByName[resName];
  14915. };
  14916. UIPackage.prototype.getItemAssetByName = function (resName) {
  14917. var pi = this._itemsByName[resName];
  14918. if (pi == null) {
  14919. throw "Resource not found -" + resName;
  14920. }
  14921. return this.getItemAsset(pi);
  14922. };
  14923. UIPackage.prototype.getItemAsset = function (item) {
  14924. switch (item.type) {
  14925. case fgui.PackageItemType.Image:
  14926. if (!item.decoded) {
  14927. item.decoded = true;
  14928. var sprite = this._sprites[item.id];
  14929. if (sprite) {
  14930. var atlasTexture = this.getItemAsset(sprite.atlas);
  14931. if (atlasTexture) {
  14932. 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);
  14933. if (item.scale9Grid) {
  14934. sf.insetLeft = item.scale9Grid.x;
  14935. sf.insetTop = item.scale9Grid.y;
  14936. sf.insetRight = item.width - item.scale9Grid.xMax;
  14937. sf.insetBottom = item.height - item.scale9Grid.yMax;
  14938. }
  14939. item.asset = sf;
  14940. }
  14941. }
  14942. }
  14943. break;
  14944. case fgui.PackageItemType.Atlas:
  14945. case fgui.PackageItemType.Sound:
  14946. if (!item.decoded) {
  14947. item.decoded = true;
  14948. item.asset = this._bundle.get(item.file, ItemTypeToAssetType[item.type]);
  14949. if (!item.asset)
  14950. console.log("Resource '" + item.file + "' not found");
  14951. }
  14952. break;
  14953. case fgui.PackageItemType.Font:
  14954. if (!item.decoded) {
  14955. item.decoded = true;
  14956. this.loadFont(item);
  14957. }
  14958. break;
  14959. case fgui.PackageItemType.MovieClip:
  14960. if (!item.decoded) {
  14961. item.decoded = true;
  14962. this.loadMovieClip(item);
  14963. }
  14964. break;
  14965. default:
  14966. break;
  14967. }
  14968. return item.asset;
  14969. };
  14970. UIPackage.prototype.getItemAssetAsync = function (item, onComplete) {
  14971. if (item.decoded) {
  14972. onComplete(null, item);
  14973. return;
  14974. }
  14975. if (item.loading) {
  14976. item.loading.push(onComplete);
  14977. return;
  14978. }
  14979. switch (item.type) {
  14980. case fgui.PackageItemType.Spine:
  14981. item.loading = [onComplete];
  14982. this.loadSpine(item);
  14983. break;
  14984. case fgui.PackageItemType.DragonBones:
  14985. item.loading = [onComplete];
  14986. this.loadDragonBones(item);
  14987. break;
  14988. default:
  14989. this.getItemAsset(item);
  14990. onComplete(null, item);
  14991. break;
  14992. }
  14993. };
  14994. UIPackage.prototype.loadAllAssets = function () {
  14995. var cnt = this._items.length;
  14996. for (var i = 0; i < cnt; i++) {
  14997. var pi = this._items[i];
  14998. this.getItemAsset(pi);
  14999. }
  15000. };
  15001. UIPackage.prototype.loadMovieClip = function (item) {
  15002. var buffer = item.rawData;
  15003. buffer.seek(0, 0);
  15004. item.interval = buffer.readInt() / 1000;
  15005. item.swing = buffer.readBool();
  15006. item.repeatDelay = buffer.readInt() / 1000;
  15007. buffer.seek(0, 1);
  15008. var frameCount = buffer.readShort();
  15009. item.frames = Array(frameCount);
  15010. var spriteId;
  15011. var sprite;
  15012. for (var i = 0; i < frameCount; i++) {
  15013. var nextPos = buffer.readShort();
  15014. nextPos += buffer.position;
  15015. var rect = new cc.Rect();
  15016. rect.x = buffer.readInt();
  15017. rect.y = buffer.readInt();
  15018. rect.width = buffer.readInt();
  15019. rect.height = buffer.readInt();
  15020. var addDelay = buffer.readInt() / 1000;
  15021. var frame = { rect: rect, addDelay: addDelay };
  15022. spriteId = buffer.readS();
  15023. if (spriteId != null && (sprite = this._sprites[spriteId]) != null) {
  15024. var atlasTexture = this.getItemAsset(sprite.atlas);
  15025. if (atlasTexture) {
  15026. var sx = item.width / frame.rect.width;
  15027. 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));
  15028. }
  15029. }
  15030. item.frames[i] = frame;
  15031. buffer.position = nextPos;
  15032. }
  15033. };
  15034. UIPackage.prototype.loadFont = function (item) {
  15035. var font = new cc.LabelAtlas();
  15036. item.asset = font;
  15037. font._fntConfig = {
  15038. commonHeight: 0,
  15039. fontSize: 0,
  15040. kerningDict: {},
  15041. fontDefDictionary: {}
  15042. };
  15043. var dict = font._fntConfig.fontDefDictionary;
  15044. var buffer = item.rawData;
  15045. buffer.seek(0, 0);
  15046. var ttf = buffer.readBool();
  15047. var canTint = buffer.readBool();
  15048. var resizable = buffer.readBool();
  15049. buffer.readBool();
  15050. var fontSize = buffer.readInt();
  15051. var xadvance = buffer.readInt();
  15052. var lineHeight = buffer.readInt();
  15053. var mainTexture;
  15054. var mainSprite = this._sprites[item.id];
  15055. if (mainSprite)
  15056. mainTexture = (this.getItemAsset(mainSprite.atlas));
  15057. buffer.seek(0, 1);
  15058. var bg;
  15059. var cnt = buffer.readInt();
  15060. for (var i = 0; i < cnt; i++) {
  15061. var nextPos = buffer.readShort();
  15062. nextPos += buffer.position;
  15063. bg = {};
  15064. var ch = buffer.readUshort();
  15065. dict[ch] = bg;
  15066. var rect = new cc.Rect();
  15067. bg.rect = rect;
  15068. var img = buffer.readS();
  15069. rect.x = buffer.readInt();
  15070. rect.y = buffer.readInt();
  15071. bg.xOffset = buffer.readInt();
  15072. bg.yOffset = buffer.readInt();
  15073. rect.width = buffer.readInt();
  15074. rect.height = buffer.readInt();
  15075. bg.xAdvance = buffer.readInt();
  15076. bg.channel = buffer.readByte();
  15077. if (bg.channel == 1)
  15078. bg.channel = 3;
  15079. else if (bg.channel == 2)
  15080. bg.channel = 2;
  15081. else if (bg.channel == 3)
  15082. bg.channel = 1;
  15083. if (ttf) {
  15084. rect.x += mainSprite.rect.x;
  15085. rect.y += mainSprite.rect.y;
  15086. }
  15087. else {
  15088. var sprite = this._sprites[img];
  15089. if (sprite) {
  15090. rect.set(sprite.rect);
  15091. bg.xOffset += sprite.offset.x;
  15092. bg.yOffset += sprite.offset.y;
  15093. if (fontSize == 0)
  15094. fontSize = sprite.originalSize.height;
  15095. if (!mainTexture) {
  15096. sprite.atlas.load();
  15097. mainTexture = sprite.atlas.asset;
  15098. }
  15099. }
  15100. if (bg.xAdvance == 0) {
  15101. if (xadvance == 0)
  15102. bg.xAdvance = bg.xOffset + bg.rect.width;
  15103. else
  15104. bg.xAdvance = xadvance;
  15105. }
  15106. }
  15107. buffer.position = nextPos;
  15108. }
  15109. font.fontSize = fontSize;
  15110. font._fntConfig.fontSize = fontSize;
  15111. font._fntConfig.commonHeight = lineHeight == 0 ? fontSize : lineHeight;
  15112. font._fntConfig.resizable = resizable;
  15113. font._fntConfig.canTint = canTint;
  15114. var spriteFrame = new cc.SpriteFrame();
  15115. spriteFrame.setTexture(mainTexture);
  15116. font.spriteFrame = spriteFrame;
  15117. font.onLoad();
  15118. };
  15119. UIPackage.prototype.loadSpine = function (item) {
  15120. this._bundle.load(item.file, sp.SkeletonData, function (err, asset) {
  15121. item.decoded = true;
  15122. item.asset = asset;
  15123. var arr = item.loading;
  15124. delete item.loading;
  15125. arr.forEach(function (e) { return e(err, item); });
  15126. });
  15127. };
  15128. UIPackage.prototype.loadDragonBones = function (item) {
  15129. var _this = this;
  15130. this._bundle.load(item.file, dragonBones.DragonBonesAsset, function (err, asset) {
  15131. if (err) {
  15132. item.decoded = true;
  15133. var arr = item.loading;
  15134. delete item.loading;
  15135. arr.forEach(function (e) { return e(err, item); });
  15136. return;
  15137. }
  15138. item.asset = asset;
  15139. var atlasFile = item.file.replace("_ske", "_tex");
  15140. var pos = atlasFile.lastIndexOf('.');
  15141. if (pos != -1)
  15142. atlasFile = atlasFile.substr(0, pos + 1) + "json";
  15143. _this._bundle.load(atlasFile, dragonBones.DragonBonesAtlasAsset, function (err, asset) {
  15144. item.decoded = true;
  15145. item.atlasAsset = asset;
  15146. var arr = item.loading;
  15147. delete item.loading;
  15148. arr.forEach(function (e) { return e(err, item); });
  15149. });
  15150. });
  15151. };
  15152. UIPackage._constructing = 0;
  15153. UIPackage._instById = {};
  15154. UIPackage._instByName = {};
  15155. UIPackage._branch = "";
  15156. UIPackage._vars = {};
  15157. return UIPackage;
  15158. }());
  15159. fgui.UIPackage = UIPackage;
  15160. var ItemTypeToAssetType = (_a = {},
  15161. _a[fgui.PackageItemType.Atlas] = cc.Texture2D,
  15162. _a[fgui.PackageItemType.Sound] = cc.AudioClip,
  15163. _a);
  15164. })(fgui || (fgui = {}));
  15165. (function (fgui) {
  15166. var Window = (function (_super) {
  15167. __extends(Window, _super);
  15168. function Window() {
  15169. var _this = _super.call(this) || this;
  15170. _this._requestingCmd = 0;
  15171. _this._uiSources = new Array();
  15172. _this.bringToFontOnClick = fgui.UIConfig.bringWindowToFrontOnClick;
  15173. _this._node.on(fgui.Event.TOUCH_BEGIN, _this.onTouchBegin_1, _this, true);
  15174. return _this;
  15175. }
  15176. Window.prototype.addUISource = function (source) {
  15177. this._uiSources.push(source);
  15178. };
  15179. Object.defineProperty(Window.prototype, "contentPane", {
  15180. get: function () {
  15181. return this._contentPane;
  15182. },
  15183. set: function (val) {
  15184. if (this._contentPane != val) {
  15185. if (this._contentPane)
  15186. this.removeChild(this._contentPane);
  15187. this._contentPane = val;
  15188. if (this._contentPane) {
  15189. this.addChild(this._contentPane);
  15190. this.setSize(this._contentPane.width, this._contentPane.height);
  15191. this._contentPane.addRelation(this, fgui.RelationType.Size);
  15192. this._frame = (this._contentPane.getChild("frame"));
  15193. if (this._frame) {
  15194. this.closeButton = this._frame.getChild("closeButton");
  15195. this.dragArea = this._frame.getChild("dragArea");
  15196. this.contentArea = this._frame.getChild("contentArea");
  15197. }
  15198. }
  15199. }
  15200. },
  15201. enumerable: false,
  15202. configurable: true
  15203. });
  15204. Object.defineProperty(Window.prototype, "frame", {
  15205. get: function () {
  15206. return this._frame;
  15207. },
  15208. enumerable: false,
  15209. configurable: true
  15210. });
  15211. Object.defineProperty(Window.prototype, "closeButton", {
  15212. get: function () {
  15213. return this._closeButton;
  15214. },
  15215. set: function (value) {
  15216. if (this._closeButton)
  15217. this._closeButton.offClick(this.closeEventHandler, this);
  15218. this._closeButton = value;
  15219. if (this._closeButton)
  15220. this._closeButton.onClick(this.closeEventHandler, this);
  15221. },
  15222. enumerable: false,
  15223. configurable: true
  15224. });
  15225. Object.defineProperty(Window.prototype, "dragArea", {
  15226. get: function () {
  15227. return this._dragArea;
  15228. },
  15229. set: function (value) {
  15230. if (this._dragArea != value) {
  15231. if (this._dragArea) {
  15232. this._dragArea.draggable = false;
  15233. this._dragArea.off(fgui.Event.DRAG_START, this.onDragStart_1, this);
  15234. }
  15235. this._dragArea = value;
  15236. if (this._dragArea) {
  15237. this._dragArea.draggable = true;
  15238. this._dragArea.on(fgui.Event.DRAG_START, this.onDragStart_1, this);
  15239. }
  15240. }
  15241. },
  15242. enumerable: false,
  15243. configurable: true
  15244. });
  15245. Object.defineProperty(Window.prototype, "contentArea", {
  15246. get: function () {
  15247. return this._contentArea;
  15248. },
  15249. set: function (value) {
  15250. this._contentArea = value;
  15251. },
  15252. enumerable: false,
  15253. configurable: true
  15254. });
  15255. Window.prototype.show = function () {
  15256. fgui.GRoot.inst.showWindow(this);
  15257. };
  15258. Window.prototype.showOn = function (root) {
  15259. root.showWindow(this);
  15260. };
  15261. Window.prototype.hide = function () {
  15262. if (this.isShowing)
  15263. this.doHideAnimation();
  15264. };
  15265. Window.prototype.hideImmediately = function () {
  15266. var r = (this.parent instanceof fgui.GRoot) ? this.parent : null;
  15267. if (!r)
  15268. r = fgui.GRoot.inst;
  15269. r.hideWindowImmediately(this);
  15270. };
  15271. Window.prototype.centerOn = function (r, restraint) {
  15272. this.setPosition(Math.round((r.width - this.width) / 2), Math.round((r.height - this.height) / 2));
  15273. if (restraint) {
  15274. this.addRelation(r, fgui.RelationType.Center_Center);
  15275. this.addRelation(r, fgui.RelationType.Middle_Middle);
  15276. }
  15277. };
  15278. Window.prototype.toggleStatus = function () {
  15279. if (this.isTop)
  15280. this.hide();
  15281. else
  15282. this.show();
  15283. };
  15284. Object.defineProperty(Window.prototype, "isShowing", {
  15285. get: function () {
  15286. return this.parent != null;
  15287. },
  15288. enumerable: false,
  15289. configurable: true
  15290. });
  15291. Object.defineProperty(Window.prototype, "isTop", {
  15292. get: function () {
  15293. return this.parent && this.parent.getChildIndex(this) == this.parent.numChildren - 1;
  15294. },
  15295. enumerable: false,
  15296. configurable: true
  15297. });
  15298. Object.defineProperty(Window.prototype, "modal", {
  15299. get: function () {
  15300. return this._modal;
  15301. },
  15302. set: function (val) {
  15303. this._modal = val;
  15304. },
  15305. enumerable: false,
  15306. configurable: true
  15307. });
  15308. Window.prototype.bringToFront = function () {
  15309. this.root.bringToFront(this);
  15310. };
  15311. Window.prototype.showModalWait = function (requestingCmd) {
  15312. if (requestingCmd != null)
  15313. this._requestingCmd = requestingCmd;
  15314. if (fgui.UIConfig.windowModalWaiting) {
  15315. if (!this._modalWaitPane)
  15316. this._modalWaitPane = fgui.UIPackage.createObjectFromURL(fgui.UIConfig.windowModalWaiting);
  15317. this.layoutModalWaitPane();
  15318. this.addChild(this._modalWaitPane);
  15319. }
  15320. };
  15321. Window.prototype.layoutModalWaitPane = function () {
  15322. if (this._contentArea) {
  15323. var pt = this._frame.localToGlobal();
  15324. pt = this.globalToLocal(pt.x, pt.y, pt);
  15325. this._modalWaitPane.setPosition(pt.x + this._contentArea.x, pt.y + this._contentArea.y);
  15326. this._modalWaitPane.setSize(this._contentArea.width, this._contentArea.height);
  15327. }
  15328. else
  15329. this._modalWaitPane.setSize(this.width, this.height);
  15330. };
  15331. Window.prototype.closeModalWait = function (requestingCmd) {
  15332. if (requestingCmd != null) {
  15333. if (this._requestingCmd != requestingCmd)
  15334. return false;
  15335. }
  15336. this._requestingCmd = 0;
  15337. if (this._modalWaitPane && this._modalWaitPane.parent)
  15338. this.removeChild(this._modalWaitPane);
  15339. return true;
  15340. };
  15341. Object.defineProperty(Window.prototype, "modalWaiting", {
  15342. get: function () {
  15343. return this._modalWaitPane && this._modalWaitPane.parent != null;
  15344. },
  15345. enumerable: false,
  15346. configurable: true
  15347. });
  15348. Window.prototype.init = function () {
  15349. if (this._inited || this._loading)
  15350. return;
  15351. if (this._uiSources.length > 0) {
  15352. this._loading = false;
  15353. var cnt = this._uiSources.length;
  15354. for (var i = 0; i < cnt; i++) {
  15355. var lib = this._uiSources[i];
  15356. if (!lib.loaded) {
  15357. lib.load(this.__uiLoadComplete, this);
  15358. this._loading = true;
  15359. }
  15360. }
  15361. if (!this._loading)
  15362. this._init();
  15363. }
  15364. else
  15365. this._init();
  15366. };
  15367. Window.prototype.onInit = function () {
  15368. };
  15369. Window.prototype.onShown = function () {
  15370. };
  15371. Window.prototype.onHide = function () {
  15372. };
  15373. Window.prototype.doShowAnimation = function () {
  15374. this.onShown();
  15375. };
  15376. Window.prototype.doHideAnimation = function () {
  15377. this.hideImmediately();
  15378. };
  15379. Window.prototype.__uiLoadComplete = function () {
  15380. var cnt = this._uiSources.length;
  15381. for (var i = 0; i < cnt; i++) {
  15382. var lib = this._uiSources[i];
  15383. if (!lib.loaded)
  15384. return;
  15385. }
  15386. this._loading = false;
  15387. this._init();
  15388. };
  15389. Window.prototype._init = function () {
  15390. this._inited = true;
  15391. this.onInit();
  15392. if (this.isShowing)
  15393. this.doShowAnimation();
  15394. };
  15395. Window.prototype.dispose = function () {
  15396. if (this.parent)
  15397. this.hideImmediately();
  15398. _super.prototype.dispose.call(this);
  15399. };
  15400. Window.prototype.closeEventHandler = function (evt) {
  15401. this.hide();
  15402. };
  15403. Window.prototype.onEnable = function () {
  15404. _super.prototype.onEnable.call(this);
  15405. if (!this._inited)
  15406. this.init();
  15407. else
  15408. this.doShowAnimation();
  15409. };
  15410. Window.prototype.onDisable = function () {
  15411. _super.prototype.onDisable.call(this);
  15412. this.closeModalWait();
  15413. this.onHide();
  15414. };
  15415. Window.prototype.onTouchBegin_1 = function (evt) {
  15416. if (this.isShowing && this.bringToFontOnClick)
  15417. this.bringToFront();
  15418. };
  15419. Window.prototype.onDragStart_1 = function (evt) {
  15420. var original = fgui.GObject.cast(evt.currentTarget);
  15421. original.stopDrag();
  15422. this.startDrag(evt.touchId);
  15423. };
  15424. return Window;
  15425. }(fgui.GComponent));
  15426. fgui.Window = Window;
  15427. })(fgui || (fgui = {}));
  15428. (function (fgui) {
  15429. var ControllerAction = (function () {
  15430. function ControllerAction() {
  15431. }
  15432. ControllerAction.createAction = function (type) {
  15433. switch (type) {
  15434. case 0:
  15435. return new fgui.PlayTransitionAction();
  15436. case 1:
  15437. return new fgui.ChangePageAction();
  15438. }
  15439. return null;
  15440. };
  15441. ControllerAction.prototype.run = function (controller, prevPage, curPage) {
  15442. if ((this.fromPage == null || this.fromPage.length == 0 || this.fromPage.indexOf(prevPage) != -1)
  15443. && (this.toPage == null || this.toPage.length == 0 || this.toPage.indexOf(curPage) != -1))
  15444. this.enter(controller);
  15445. else
  15446. this.leave(controller);
  15447. };
  15448. ControllerAction.prototype.enter = function (controller) {
  15449. };
  15450. ControllerAction.prototype.leave = function (controller) {
  15451. };
  15452. ControllerAction.prototype.setup = function (buffer) {
  15453. var cnt;
  15454. var i;
  15455. cnt = buffer.readShort();
  15456. this.fromPage = [];
  15457. for (i = 0; i < cnt; i++)
  15458. this.fromPage[i] = buffer.readS();
  15459. cnt = buffer.readShort();
  15460. this.toPage = [];
  15461. for (i = 0; i < cnt; i++)
  15462. this.toPage[i] = buffer.readS();
  15463. };
  15464. return ControllerAction;
  15465. }());
  15466. fgui.ControllerAction = ControllerAction;
  15467. })(fgui || (fgui = {}));
  15468. (function (fgui) {
  15469. var ChangePageAction = (function (_super) {
  15470. __extends(ChangePageAction, _super);
  15471. function ChangePageAction() {
  15472. return _super.call(this) || this;
  15473. }
  15474. ChangePageAction.prototype.enter = function (controller) {
  15475. if (!this.controllerName)
  15476. return;
  15477. var gcom;
  15478. if (this.objectId) {
  15479. var obj = controller.parent.getChildById(this.objectId);
  15480. if (obj instanceof fgui.GComponent)
  15481. gcom = obj;
  15482. else
  15483. return;
  15484. }
  15485. else
  15486. gcom = controller.parent;
  15487. if (gcom) {
  15488. var cc = gcom.getController(this.controllerName);
  15489. if (cc && cc != controller && !cc.changing) {
  15490. if (this.targetPage == "~1") {
  15491. if (controller.selectedIndex < cc.pageCount)
  15492. cc.selectedIndex = controller.selectedIndex;
  15493. }
  15494. else if (this.targetPage == "~2")
  15495. cc.selectedPage = controller.selectedPage;
  15496. else
  15497. cc.selectedPageId = this.targetPage;
  15498. }
  15499. }
  15500. };
  15501. ChangePageAction.prototype.setup = function (buffer) {
  15502. _super.prototype.setup.call(this, buffer);
  15503. this.objectId = buffer.readS();
  15504. this.controllerName = buffer.readS();
  15505. this.targetPage = buffer.readS();
  15506. };
  15507. return ChangePageAction;
  15508. }(fgui.ControllerAction));
  15509. fgui.ChangePageAction = ChangePageAction;
  15510. })(fgui || (fgui = {}));
  15511. (function (fgui) {
  15512. var PlayTransitionAction = (function (_super) {
  15513. __extends(PlayTransitionAction, _super);
  15514. function PlayTransitionAction() {
  15515. var _this = _super.call(this) || this;
  15516. _this.playTimes = 1;
  15517. _this.delay = 0;
  15518. _this.stopOnExit = false;
  15519. return _this;
  15520. }
  15521. PlayTransitionAction.prototype.enter = function (controller) {
  15522. var trans = controller.parent.getTransition(this.transitionName);
  15523. if (trans) {
  15524. if (this._currentTransition && this._currentTransition.playing)
  15525. trans.changePlayTimes(this.playTimes);
  15526. else
  15527. trans.play(null, this.playTimes, this.delay);
  15528. this._currentTransition = trans;
  15529. }
  15530. };
  15531. PlayTransitionAction.prototype.leave = function (controller) {
  15532. if (this.stopOnExit && this._currentTransition) {
  15533. this._currentTransition.stop();
  15534. this._currentTransition = null;
  15535. }
  15536. };
  15537. PlayTransitionAction.prototype.setup = function (buffer) {
  15538. _super.prototype.setup.call(this, buffer);
  15539. this.transitionName = buffer.readS();
  15540. this.playTimes = buffer.readInt();
  15541. this.delay = buffer.readFloat();
  15542. this.stopOnExit = buffer.readBool();
  15543. };
  15544. return PlayTransitionAction;
  15545. }(fgui.ControllerAction));
  15546. fgui.PlayTransitionAction = PlayTransitionAction;
  15547. })(fgui || (fgui = {}));
  15548. (function (fgui) {
  15549. var BlendMode;
  15550. (function (BlendMode) {
  15551. BlendMode[BlendMode["Normal"] = 0] = "Normal";
  15552. BlendMode[BlendMode["None"] = 1] = "None";
  15553. BlendMode[BlendMode["Add"] = 2] = "Add";
  15554. BlendMode[BlendMode["Multiply"] = 3] = "Multiply";
  15555. BlendMode[BlendMode["Screen"] = 4] = "Screen";
  15556. BlendMode[BlendMode["Erase"] = 5] = "Erase";
  15557. BlendMode[BlendMode["Mask"] = 6] = "Mask";
  15558. BlendMode[BlendMode["Below"] = 7] = "Below";
  15559. BlendMode[BlendMode["Off"] = 8] = "Off";
  15560. BlendMode[BlendMode["Custom1"] = 9] = "Custom1";
  15561. BlendMode[BlendMode["Custom2"] = 10] = "Custom2";
  15562. BlendMode[BlendMode["Custom3"] = 11] = "Custom3";
  15563. })(BlendMode = fgui.BlendMode || (fgui.BlendMode = {}));
  15564. var BlendModeUtils = (function () {
  15565. function BlendModeUtils() {
  15566. }
  15567. BlendModeUtils.apply = function (node, blendMode) {
  15568. var f = factors[blendMode];
  15569. var renderers = node.getComponentsInChildren(cc.RenderComponent);
  15570. renderers.forEach(function (element) {
  15571. element.srcBlendFactor = f[0];
  15572. element.dstBlendFactor = f[1];
  15573. });
  15574. };
  15575. BlendModeUtils.override = function (blendMode, srcFactor, dstFactor) {
  15576. factors[blendMode][0] = srcFactor;
  15577. factors[blendMode][1] = dstFactor;
  15578. };
  15579. return BlendModeUtils;
  15580. }());
  15581. fgui.BlendModeUtils = BlendModeUtils;
  15582. var factors = [
  15583. [cc.macro.SRC_ALPHA, cc.macro.ONE_MINUS_SRC_ALPHA],
  15584. [cc.macro.ONE, cc.macro.ONE],
  15585. [cc.macro.SRC_ALPHA, cc.macro.ONE],
  15586. [cc.macro.DST_COLOR, cc.macro.ONE_MINUS_SRC_ALPHA],
  15587. [cc.macro.ONE, cc.macro.ONE_MINUS_SRC_COLOR],
  15588. [cc.macro.ZERO, cc.macro.ONE_MINUS_SRC_ALPHA],
  15589. [cc.macro.ZERO, cc.macro.SRC_ALPHA],
  15590. [cc.macro.ONE_MINUS_DST_ALPHA, cc.macro.DST_ALPHA],
  15591. [cc.macro.ONE, cc.macro.ZERO],
  15592. [cc.macro.SRC_ALPHA, cc.macro.ONE_MINUS_SRC_ALPHA],
  15593. [cc.macro.SRC_ALPHA, cc.macro.ONE_MINUS_SRC_ALPHA],
  15594. [cc.macro.SRC_ALPHA, cc.macro.ONE_MINUS_SRC_ALPHA],
  15595. ];
  15596. })(fgui || (fgui = {}));
  15597. (function (fgui) {
  15598. var Image = (function (_super) {
  15599. __extends(Image, _super);
  15600. function Image() {
  15601. var _this = _super.call(this) || this;
  15602. _this._flip = fgui.FlipType.None;
  15603. _this._fillMethod = fgui.FillMethod.None;
  15604. _this._fillOrigin = fgui.FillOrigin.Left;
  15605. _this._fillAmount = 0;
  15606. return _this;
  15607. }
  15608. Object.defineProperty(Image.prototype, "flip", {
  15609. get: function () {
  15610. return this._flip;
  15611. },
  15612. set: function (value) {
  15613. if (this._flip != value) {
  15614. this._flip = value;
  15615. var sx = 1, sy = 1;
  15616. if (this._flip == fgui.FlipType.Horizontal || this._flip == fgui.FlipType.Both)
  15617. sx = -1;
  15618. if (this._flip == fgui.FlipType.Vertical || this._flip == fgui.FlipType.Both)
  15619. sy = -1;
  15620. if (sx != 1 || sy != 1)
  15621. this.node.setAnchorPoint(0.5, 0.5);
  15622. this.node.setScale(sx, sy);
  15623. }
  15624. },
  15625. enumerable: false,
  15626. configurable: true
  15627. });
  15628. Object.defineProperty(Image.prototype, "fillMethod", {
  15629. get: function () {
  15630. return this._fillMethod;
  15631. },
  15632. set: function (value) {
  15633. if (this._fillMethod != value) {
  15634. this._fillMethod = value;
  15635. if (this._fillMethod != 0) {
  15636. this.type = cc.Sprite.Type.FILLED;
  15637. if (this._fillMethod <= 3)
  15638. this.fillType = this._fillMethod - 1;
  15639. else
  15640. this.fillType = cc.Sprite.FillType.RADIAL;
  15641. this.fillCenter = new cc.Vec2(0.5, 0.5);
  15642. this.setupFill();
  15643. }
  15644. else {
  15645. this.type = cc.Sprite.Type.SIMPLE;
  15646. }
  15647. }
  15648. },
  15649. enumerable: false,
  15650. configurable: true
  15651. });
  15652. Object.defineProperty(Image.prototype, "fillOrigin", {
  15653. get: function () {
  15654. return this._fillOrigin;
  15655. },
  15656. set: function (value) {
  15657. if (this._fillOrigin != value) {
  15658. this._fillOrigin = value;
  15659. if (this._fillMethod != 0)
  15660. this.setupFill();
  15661. }
  15662. },
  15663. enumerable: false,
  15664. configurable: true
  15665. });
  15666. Object.defineProperty(Image.prototype, "fillClockwise", {
  15667. get: function () {
  15668. return this._fillClockwise;
  15669. },
  15670. set: function (value) {
  15671. if (this._fillClockwise != value) {
  15672. this._fillClockwise = value;
  15673. if (this._fillMethod != 0)
  15674. this.setupFill();
  15675. }
  15676. },
  15677. enumerable: false,
  15678. configurable: true
  15679. });
  15680. Object.defineProperty(Image.prototype, "fillAmount", {
  15681. get: function () {
  15682. return this._fillAmount;
  15683. },
  15684. set: function (value) {
  15685. if (this._fillAmount != value) {
  15686. this._fillAmount = value;
  15687. if (this._fillMethod != 0) {
  15688. if (this._fillClockwise)
  15689. this.fillRange = -this._fillAmount;
  15690. else
  15691. this.fillRange = this._fillAmount;
  15692. }
  15693. }
  15694. },
  15695. enumerable: false,
  15696. configurable: true
  15697. });
  15698. Image.prototype.setupFill = function () {
  15699. if (this._fillMethod == fgui.FillMethod.Horizontal) {
  15700. this._fillClockwise = this._fillOrigin == fgui.FillOrigin.Right || this._fillOrigin == fgui.FillOrigin.Bottom;
  15701. this.fillStart = this._fillClockwise ? 1 : 0;
  15702. }
  15703. else if (this._fillMethod == fgui.FillMethod.Vertical) {
  15704. this._fillClockwise = this._fillOrigin == fgui.FillOrigin.Left || this._fillOrigin == fgui.FillOrigin.Top;
  15705. this.fillStart = this._fillClockwise ? 1 : 0;
  15706. }
  15707. else {
  15708. switch (this._fillOrigin) {
  15709. case fgui.FillOrigin.Right:
  15710. this.fillOrigin = 0;
  15711. break;
  15712. case fgui.FillOrigin.Top:
  15713. this.fillStart = 0.25;
  15714. break;
  15715. case fgui.FillOrigin.Left:
  15716. this.fillStart = 0.5;
  15717. break;
  15718. case fgui.FillOrigin.Bottom:
  15719. this.fillStart = 0.75;
  15720. break;
  15721. }
  15722. }
  15723. };
  15724. Object.defineProperty(Image.prototype, "grayed", {
  15725. get: function () {
  15726. return this._grayed;
  15727. },
  15728. set: function (value) {
  15729. if (this._grayed == value)
  15730. return;
  15731. this._grayed = value;
  15732. var material;
  15733. if (value) {
  15734. material = this._graySpriteMaterial;
  15735. if (!material)
  15736. material = cc.Material.getBuiltinMaterial('2d-gray-sprite');
  15737. material = this._graySpriteMaterial = cc.MaterialVariant.create(material, this);
  15738. }
  15739. else {
  15740. material = this._spriteMaterial;
  15741. if (!material)
  15742. material = cc.Material.getBuiltinMaterial('2d-sprite', this);
  15743. material = this._spriteMaterial = cc.MaterialVariant.create(material, this);
  15744. }
  15745. this.setMaterial(0, material);
  15746. },
  15747. enumerable: false,
  15748. configurable: true
  15749. });
  15750. ;
  15751. return Image;
  15752. }(cc.Sprite));
  15753. fgui.Image = Image;
  15754. })(fgui || (fgui = {}));
  15755. (function (fgui) {
  15756. var MovieClip = (function (_super) {
  15757. __extends(MovieClip, _super);
  15758. function MovieClip() {
  15759. var _this = _super.call(this) || this;
  15760. _this.interval = 0;
  15761. _this.repeatDelay = 0;
  15762. _this.timeScale = 1;
  15763. _this._playing = true;
  15764. _this._frameCount = 0;
  15765. _this._frame = 0;
  15766. _this._start = 0;
  15767. _this._end = 0;
  15768. _this._times = 0;
  15769. _this._endAt = 0;
  15770. _this._status = 0;
  15771. _this._smoothing = true;
  15772. _this._frameElapsed = 0;
  15773. _this._reversed = false;
  15774. _this._repeatedCount = 0;
  15775. return _this;
  15776. }
  15777. Object.defineProperty(MovieClip.prototype, "frames", {
  15778. get: function () {
  15779. return this._frames;
  15780. },
  15781. set: function (value) {
  15782. this._frames = value;
  15783. if (this._frames) {
  15784. this._frameCount = this._frames.length;
  15785. if (this._end == -1 || this._end > this._frameCount - 1)
  15786. this._end = this._frameCount - 1;
  15787. if (this._endAt == -1 || this._endAt > this._frameCount - 1)
  15788. this._endAt = this._frameCount - 1;
  15789. if (this._frame < 0 || this._frame > this._frameCount - 1)
  15790. this._frame = this._frameCount - 1;
  15791. this.type = cc.Sprite.Type.SIMPLE;
  15792. this.drawFrame();
  15793. this._frameElapsed = 0;
  15794. this._repeatedCount = 0;
  15795. this._reversed = false;
  15796. }
  15797. else {
  15798. this._frameCount = 0;
  15799. }
  15800. },
  15801. enumerable: false,
  15802. configurable: true
  15803. });
  15804. Object.defineProperty(MovieClip.prototype, "frameCount", {
  15805. get: function () {
  15806. return this._frameCount;
  15807. },
  15808. enumerable: false,
  15809. configurable: true
  15810. });
  15811. Object.defineProperty(MovieClip.prototype, "frame", {
  15812. get: function () {
  15813. return this._frame;
  15814. },
  15815. set: function (value) {
  15816. if (this._frame != value) {
  15817. if (this._frames && value >= this._frameCount)
  15818. value = this._frameCount - 1;
  15819. this._frame = value;
  15820. this._frameElapsed = 0;
  15821. this.drawFrame();
  15822. }
  15823. },
  15824. enumerable: false,
  15825. configurable: true
  15826. });
  15827. Object.defineProperty(MovieClip.prototype, "playing", {
  15828. get: function () {
  15829. return this._playing;
  15830. },
  15831. set: function (value) {
  15832. if (this._playing != value) {
  15833. this._playing = value;
  15834. }
  15835. },
  15836. enumerable: false,
  15837. configurable: true
  15838. });
  15839. Object.defineProperty(MovieClip.prototype, "smoothing", {
  15840. get: function () {
  15841. return this._smoothing;
  15842. },
  15843. set: function (value) {
  15844. this._smoothing = value;
  15845. },
  15846. enumerable: false,
  15847. configurable: true
  15848. });
  15849. MovieClip.prototype.rewind = function () {
  15850. this._frame = 0;
  15851. this._frameElapsed = 0;
  15852. this._reversed = false;
  15853. this._repeatedCount = 0;
  15854. this.drawFrame();
  15855. };
  15856. MovieClip.prototype.syncStatus = function (anotherMc) {
  15857. this._frame = anotherMc._frame;
  15858. this._frameElapsed = anotherMc._frameElapsed;
  15859. this._reversed = anotherMc._reversed;
  15860. this._repeatedCount = anotherMc._repeatedCount;
  15861. this.drawFrame();
  15862. };
  15863. MovieClip.prototype.advance = function (timeInMiniseconds) {
  15864. var beginFrame = this._frame;
  15865. var beginReversed = this._reversed;
  15866. var backupTime = timeInMiniseconds;
  15867. while (true) {
  15868. var tt = this.interval + this._frames[this._frame].addDelay;
  15869. if (this._frame == 0 && this._repeatedCount > 0)
  15870. tt += this.repeatDelay;
  15871. if (timeInMiniseconds < tt) {
  15872. this._frameElapsed = 0;
  15873. break;
  15874. }
  15875. timeInMiniseconds -= tt;
  15876. if (this.swing) {
  15877. if (this._reversed) {
  15878. this._frame--;
  15879. if (this._frame <= 0) {
  15880. this._frame = 0;
  15881. this._repeatedCount++;
  15882. this._reversed = !this._reversed;
  15883. }
  15884. }
  15885. else {
  15886. this._frame++;
  15887. if (this._frame > this._frameCount - 1) {
  15888. this._frame = Math.max(0, this._frameCount - 2);
  15889. this._repeatedCount++;
  15890. this._reversed = !this._reversed;
  15891. }
  15892. }
  15893. }
  15894. else {
  15895. this._frame++;
  15896. if (this._frame > this._frameCount - 1) {
  15897. this._frame = 0;
  15898. this._repeatedCount++;
  15899. }
  15900. }
  15901. if (this._frame == beginFrame && this._reversed == beginReversed) {
  15902. var roundTime = backupTime - timeInMiniseconds;
  15903. timeInMiniseconds -= Math.floor(timeInMiniseconds / roundTime) * roundTime;
  15904. }
  15905. }
  15906. this.drawFrame();
  15907. };
  15908. MovieClip.prototype.setPlaySettings = function (start, end, times, endAt, endCallback, callbackObj) {
  15909. if (start == undefined)
  15910. start = 0;
  15911. if (end == undefined)
  15912. end = -1;
  15913. if (times == undefined)
  15914. times = 0;
  15915. if (endAt == undefined)
  15916. endAt = -1;
  15917. this._start = start;
  15918. this._end = end;
  15919. if (this._end == -1 || this._end > this._frameCount - 1)
  15920. this._end = this._frameCount - 1;
  15921. this._times = times;
  15922. this._endAt = endAt;
  15923. if (this._endAt == -1)
  15924. this._endAt = this._end;
  15925. this._status = 0;
  15926. this._callback = endCallback;
  15927. this._callbackObj = callbackObj;
  15928. this.frame = start;
  15929. };
  15930. MovieClip.prototype.update = function (dt) {
  15931. if (!this._playing || this._frameCount == 0 || this._status == 3)
  15932. return;
  15933. if (this.timeScale != 1)
  15934. dt *= this.timeScale;
  15935. this._frameElapsed += dt;
  15936. var tt = this.interval + this._frames[this._frame].addDelay;
  15937. if (this._frame == 0 && this._repeatedCount > 0)
  15938. tt += this.repeatDelay;
  15939. if (this._frameElapsed < tt)
  15940. return;
  15941. this._frameElapsed -= tt;
  15942. if (this._frameElapsed > this.interval)
  15943. this._frameElapsed = this.interval;
  15944. if (this.swing) {
  15945. if (this._reversed) {
  15946. this._frame--;
  15947. if (this._frame <= 0) {
  15948. this._frame = 0;
  15949. this._repeatedCount++;
  15950. this._reversed = !this._reversed;
  15951. }
  15952. }
  15953. else {
  15954. this._frame++;
  15955. if (this._frame > this._frameCount - 1) {
  15956. this._frame = Math.max(0, this._frameCount - 2);
  15957. this._repeatedCount++;
  15958. this._reversed = !this._reversed;
  15959. }
  15960. }
  15961. }
  15962. else {
  15963. this._frame++;
  15964. if (this._frame > this._frameCount - 1) {
  15965. this._frame = 0;
  15966. this._repeatedCount++;
  15967. }
  15968. }
  15969. if (this._status == 1) {
  15970. this._frame = this._start;
  15971. this._frameElapsed = 0;
  15972. this._status = 0;
  15973. }
  15974. else if (this._status == 2) {
  15975. this._frame = this._endAt;
  15976. this._frameElapsed = 0;
  15977. this._status = 3;
  15978. if (this._callback != null) {
  15979. var callback = this._callback;
  15980. var caller = this._callbackObj;
  15981. this._callback = null;
  15982. this._callbackObj = null;
  15983. callback.call(caller);
  15984. }
  15985. }
  15986. else {
  15987. if (this._frame == this._end) {
  15988. if (this._times > 0) {
  15989. this._times--;
  15990. if (this._times == 0)
  15991. this._status = 2;
  15992. else
  15993. this._status = 1;
  15994. }
  15995. else if (this._start != 0)
  15996. this._status = 1;
  15997. }
  15998. }
  15999. this.drawFrame();
  16000. };
  16001. MovieClip.prototype.drawFrame = function () {
  16002. if (this._frameCount > 0 && this._frame < this._frames.length) {
  16003. var frame = this._frames[this._frame];
  16004. this.spriteFrame = frame.texture;
  16005. }
  16006. };
  16007. return MovieClip;
  16008. }(fgui.Image));
  16009. fgui.MovieClip = MovieClip;
  16010. })(fgui || (fgui = {}));
  16011. (function (fgui) {
  16012. var Event = (function (_super) {
  16013. __extends(Event, _super);
  16014. function Event(type, bubbles) {
  16015. var _this = _super.call(this, type, bubbles) || this;
  16016. _this.pos = new cc.Vec2();
  16017. _this.touchId = 0;
  16018. _this.clickCount = 0;
  16019. _this.button = 0;
  16020. _this.keyModifiers = 0;
  16021. _this.mouseWheelDelta = 0;
  16022. return _this;
  16023. }
  16024. Object.defineProperty(Event.prototype, "isShiftDown", {
  16025. get: function () {
  16026. return false;
  16027. },
  16028. enumerable: false,
  16029. configurable: true
  16030. });
  16031. Object.defineProperty(Event.prototype, "isCtrlDown", {
  16032. get: function () {
  16033. return false;
  16034. },
  16035. enumerable: false,
  16036. configurable: true
  16037. });
  16038. Event.prototype.captureTouch = function () {
  16039. var obj = fgui.GObject.cast(this.currentTarget);
  16040. if (obj)
  16041. this._processor.addTouchMonitor(this.touchId, obj);
  16042. };
  16043. Event._borrow = function (type, bubbles) {
  16044. var evt;
  16045. if (eventPool.length) {
  16046. evt = eventPool.pop();
  16047. evt.type = type;
  16048. evt.bubbles = bubbles;
  16049. }
  16050. else {
  16051. evt = new Event(type, bubbles);
  16052. }
  16053. return evt;
  16054. };
  16055. Event._return = function (evt) {
  16056. evt.initiator = null;
  16057. evt.touch = null;
  16058. evt.unuse();
  16059. eventPool.push(evt);
  16060. };
  16061. Event.TOUCH_BEGIN = "fui_touch_begin";
  16062. Event.TOUCH_MOVE = "fui_touch_move";
  16063. Event.TOUCH_END = "fui_touch_end";
  16064. Event.CLICK = "fui_click";
  16065. Event.ROLL_OVER = "fui_roll_over";
  16066. Event.ROLL_OUT = "fui_roll_out";
  16067. Event.MOUSE_WHEEL = "fui_mouse_wheel";
  16068. Event.DISPLAY = "fui_display";
  16069. Event.UNDISPLAY = "fui_undisplay";
  16070. Event.GEAR_STOP = "fui_gear_stop";
  16071. Event.LINK = "fui_text_link";
  16072. Event.Submit = "editing-return";
  16073. Event.TEXT_CHANGE = "text-changed";
  16074. Event.STATUS_CHANGED = "fui_status_changed";
  16075. Event.XY_CHANGED = "fui_xy_changed";
  16076. Event.SIZE_CHANGED = "fui_size_changed";
  16077. Event.SIZE_DELAY_CHANGE = "fui_size_delay_change";
  16078. Event.DRAG_START = "fui_drag_start";
  16079. Event.DRAG_MOVE = "fui_drag_move";
  16080. Event.DRAG_END = "fui_drag_end";
  16081. Event.DROP = "fui_drop";
  16082. Event.SCROLL = "fui_scroll";
  16083. Event.SCROLL_END = "fui_scroll_end";
  16084. Event.PULL_DOWN_RELEASE = "fui_pull_down_release";
  16085. Event.PULL_UP_RELEASE = "fui_pull_up_release";
  16086. Event.CLICK_ITEM = "fui_click_item";
  16087. return Event;
  16088. }(cc.Event));
  16089. fgui.Event = Event;
  16090. var eventPool = new Array();
  16091. })(fgui || (fgui = {}));
  16092. (function (fgui) {
  16093. var PixelHitTest = (function () {
  16094. function PixelHitTest(data, offsetX, offsetY) {
  16095. this._data = data;
  16096. this.offsetX = offsetX == undefined ? 0 : offsetX;
  16097. this.offsetY = offsetY == undefined ? 0 : offsetY;
  16098. this.scaleX = 1;
  16099. this.scaleY = 1;
  16100. }
  16101. PixelHitTest.prototype.hitTest = function (pt) {
  16102. var x = Math.floor((pt.x / this.scaleX - this.offsetX) * this._data.scale);
  16103. var y = Math.floor((pt.y / this.scaleY - this.offsetY) * this._data.scale);
  16104. if (x < 0 || y < 0 || x >= this._data.pixelWidth)
  16105. return false;
  16106. var pos = y * this._data.pixelWidth + x;
  16107. var pos2 = Math.floor(pos / 8);
  16108. var pos3 = pos % 8;
  16109. if (pos2 >= 0 && pos2 < this._data.pixels.length)
  16110. return ((this._data.pixels[pos2] >> pos3) & 0x1) == 1;
  16111. else
  16112. return false;
  16113. };
  16114. return PixelHitTest;
  16115. }());
  16116. fgui.PixelHitTest = PixelHitTest;
  16117. var PixelHitTestData = (function () {
  16118. function PixelHitTestData(ba) {
  16119. ba.readInt();
  16120. this.pixelWidth = ba.readInt();
  16121. this.scale = 1 / ba.readByte();
  16122. this.pixels = ba.readBuffer().data;
  16123. }
  16124. return PixelHitTestData;
  16125. }());
  16126. fgui.PixelHitTestData = PixelHitTestData;
  16127. var ChildHitArea = (function () {
  16128. function ChildHitArea(child) {
  16129. this._child = child;
  16130. }
  16131. ChildHitArea.prototype.hitTest = function (pt, globalPt) {
  16132. return this._child.hitTest(globalPt, false) != null;
  16133. };
  16134. return ChildHitArea;
  16135. }());
  16136. fgui.ChildHitArea = ChildHitArea;
  16137. })(fgui || (fgui = {}));
  16138. (function (fgui) {
  16139. var InputProcessor = (function (_super) {
  16140. __extends(InputProcessor, _super);
  16141. function InputProcessor() {
  16142. var _this = _super.call(this) || this;
  16143. _this._touches = new Array();
  16144. _this._rollOutChain = new Array();
  16145. _this._rollOverChain = new Array();
  16146. _this._touchPos = new cc.Vec2();
  16147. return _this;
  16148. }
  16149. InputProcessor.prototype.onLoad = function () {
  16150. this._owner = this.node["$gobj"];
  16151. };
  16152. InputProcessor.prototype.onEnable = function () {
  16153. var node = this.node;
  16154. node.on(cc.Node.EventType.TOUCH_START, this.touchBeginHandler, this);
  16155. node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoveHandler, this);
  16156. node.on(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this);
  16157. node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchCancelHandler, this);
  16158. node.on(cc.Node.EventType.MOUSE_DOWN, this.mouseDownHandler, this);
  16159. node.on(cc.Node.EventType.MOUSE_MOVE, this.mouseMoveHandler, this);
  16160. node.on(cc.Node.EventType.MOUSE_UP, this.mouseUpHandler, this);
  16161. node.on(cc.Node.EventType.MOUSE_WHEEL, this.mouseWheelHandler, this);
  16162. this._touchListener = this.node["_touchListener"];
  16163. };
  16164. InputProcessor.prototype.onDisable = function () {
  16165. var node = this.node;
  16166. node.off(cc.Node.EventType.TOUCH_START, this.touchBeginHandler, this);
  16167. node.off(cc.Node.EventType.TOUCH_MOVE, this.touchMoveHandler, this);
  16168. node.off(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this);
  16169. node.off(cc.Node.EventType.TOUCH_CANCEL, this.touchCancelHandler, this);
  16170. node.off(cc.Node.EventType.MOUSE_DOWN, this.mouseDownHandler, this);
  16171. node.off(cc.Node.EventType.MOUSE_MOVE, this.mouseMoveHandler, this);
  16172. node.off(cc.Node.EventType.MOUSE_UP, this.mouseUpHandler, this);
  16173. node.off(cc.Node.EventType.MOUSE_WHEEL, this.mouseWheelHandler, this);
  16174. this._touchListener = null;
  16175. };
  16176. InputProcessor.prototype.getAllTouches = function (touchIds) {
  16177. touchIds = touchIds || new Array();
  16178. var cnt = this._touches.length;
  16179. for (var i = 0; i < cnt; i++) {
  16180. var ti = this._touches[i];
  16181. if (ti.touchId != -1)
  16182. touchIds.push(ti.touchId);
  16183. }
  16184. return touchIds;
  16185. };
  16186. InputProcessor.prototype.getTouchPosition = function (touchId) {
  16187. if (touchId === undefined)
  16188. touchId = -1;
  16189. var cnt = this._touches.length;
  16190. for (var i = 0; i < cnt; i++) {
  16191. var ti = this._touches[i];
  16192. if (ti.touchId != -1 && (touchId == -1 || ti.touchId == touchId))
  16193. return ti.pos;
  16194. }
  16195. return cc.Vec2.ZERO;
  16196. };
  16197. InputProcessor.prototype.getTouchTarget = function () {
  16198. var cnt = this._touches.length;
  16199. for (var i = 0; i < cnt; i++) {
  16200. var ti = this._touches[i];
  16201. if (ti.touchId != -1)
  16202. return ti.target;
  16203. }
  16204. return null;
  16205. };
  16206. InputProcessor.prototype.addTouchMonitor = function (touchId, target) {
  16207. var ti = this.getInfo(touchId, false);
  16208. if (!ti)
  16209. return;
  16210. var index = ti.touchMonitors.indexOf(target);
  16211. if (index == -1)
  16212. ti.touchMonitors.push(target);
  16213. };
  16214. InputProcessor.prototype.removeTouchMonitor = function (target) {
  16215. var cnt = this._touches.length;
  16216. for (var i = 0; i < cnt; i++) {
  16217. var ti = this._touches[i];
  16218. var index = ti.touchMonitors.indexOf(target);
  16219. if (index != -1)
  16220. ti.touchMonitors.splice(index, 1);
  16221. }
  16222. };
  16223. InputProcessor.prototype.cancelClick = function (touchId) {
  16224. var ti = this.getInfo(touchId, false);
  16225. if (ti)
  16226. ti.clickCancelled = true;
  16227. };
  16228. InputProcessor.prototype.simulateClick = function (target) {
  16229. var evt;
  16230. evt = fgui.Event._borrow(fgui.Event.TOUCH_BEGIN, true);
  16231. evt.initiator = target;
  16232. evt.pos.set(target.localToGlobal());
  16233. evt.touchId = 0;
  16234. evt.clickCount = 1;
  16235. evt.button = 0;
  16236. evt._processor = this;
  16237. if (this._captureCallback)
  16238. this._captureCallback.call(this._owner, evt);
  16239. target.node.dispatchEvent(evt);
  16240. evt.unuse();
  16241. evt.type = fgui.Event.TOUCH_END;
  16242. evt.bubbles = true;
  16243. target.node.dispatchEvent(evt);
  16244. evt.unuse();
  16245. evt.type = fgui.Event.CLICK;
  16246. evt.bubbles = true;
  16247. target.node.dispatchEvent(evt);
  16248. fgui.Event._return(evt);
  16249. };
  16250. InputProcessor.prototype.touchBeginHandler = function (touch, evt) {
  16251. var ti = this.updateInfo(touch.getID(), touch.getLocation(), touch);
  16252. this._touchListener.setSwallowTouches(ti.target != this._owner);
  16253. this.setBegin(ti);
  16254. var evt2 = this.getEvent(ti, ti.target, fgui.Event.TOUCH_BEGIN, true);
  16255. if (this._captureCallback)
  16256. this._captureCallback.call(this._owner, evt2);
  16257. ti.target.node.dispatchEvent(evt2);
  16258. this.handleRollOver(ti, ti.target);
  16259. return true;
  16260. };
  16261. InputProcessor.prototype.touchMoveHandler = function (touch, evt) {
  16262. var ti = this.updateInfo(touch.getID(), touch.getLocation(), touch);
  16263. this.handleRollOver(ti, ti.target);
  16264. if (ti.began) {
  16265. var evt2 = this.getEvent(ti, ti.target, fgui.Event.TOUCH_MOVE, false);
  16266. var done = false;
  16267. var cnt = ti.touchMonitors.length;
  16268. for (var i = 0; i < cnt; i++) {
  16269. var mm = ti.touchMonitors[i];
  16270. if (mm.node == null || !mm.node.activeInHierarchy)
  16271. continue;
  16272. evt2.unuse();
  16273. evt2.type = fgui.Event.TOUCH_MOVE;
  16274. mm.node.dispatchEvent(evt2);
  16275. if (mm == this._owner)
  16276. done = true;
  16277. }
  16278. if (!done && this.node) {
  16279. evt2.unuse();
  16280. evt2.type = fgui.Event.TOUCH_MOVE;
  16281. this.node.dispatchEvent(evt2);
  16282. }
  16283. fgui.Event._return(evt2);
  16284. }
  16285. };
  16286. InputProcessor.prototype.touchEndHandler = function (touch, evt) {
  16287. var ti = this.updateInfo(touch.getID(), touch.getLocation(), touch);
  16288. this.setEnd(ti);
  16289. var evt2 = this.getEvent(ti, ti.target, fgui.Event.TOUCH_END, false);
  16290. var cnt = ti.touchMonitors.length;
  16291. for (var i = 0; i < cnt; i++) {
  16292. var mm = ti.touchMonitors[i];
  16293. if (mm == ti.target || mm.node == null || !mm.node.activeInHierarchy
  16294. || (mm instanceof fgui.GComponent) && mm.isAncestorOf(ti.target))
  16295. continue;
  16296. evt2.unuse();
  16297. evt2.type = fgui.Event.TOUCH_END;
  16298. mm.node.dispatchEvent(evt2);
  16299. }
  16300. ti.touchMonitors.length = 0;
  16301. if (ti.target && ti.target.node) {
  16302. if (ti.target instanceof fgui.GRichTextField)
  16303. ti.target.node.getComponent(cc.RichText)["_onTouchEnded"](evt2);
  16304. evt2.unuse();
  16305. evt2.type = fgui.Event.TOUCH_END;
  16306. evt2.bubbles = true;
  16307. ti.target.node.dispatchEvent(evt2);
  16308. }
  16309. fgui.Event._return(evt2);
  16310. ti.target = this.clickTest(ti);
  16311. if (ti.target) {
  16312. evt2 = this.getEvent(ti, ti.target, fgui.Event.CLICK, true);
  16313. ti.target.node.dispatchEvent(evt2);
  16314. fgui.Event._return(evt2);
  16315. }
  16316. if (cc.sys.isMobile)
  16317. this.handleRollOver(ti, null);
  16318. else
  16319. this.handleRollOver(ti, ti.target);
  16320. ti.target = null;
  16321. ti.touchId = -1;
  16322. ti.button = -1;
  16323. };
  16324. InputProcessor.prototype.touchCancelHandler = function (touch, evt) {
  16325. var ti = this.updateInfo(touch.getID(), touch.getLocation(), touch);
  16326. var evt2 = this.getEvent(ti, ti.target, fgui.Event.TOUCH_END, false);
  16327. var cnt = ti.touchMonitors.length;
  16328. for (var i = 0; i < cnt; i++) {
  16329. var mm = ti.touchMonitors[i];
  16330. if (mm == ti.target || mm.node == null || !mm.node.activeInHierarchy
  16331. || (mm instanceof fgui.GComponent) && mm.isAncestorOf(ti.target))
  16332. continue;
  16333. evt2.initiator = mm;
  16334. mm.node.dispatchEvent(evt2);
  16335. }
  16336. ti.touchMonitors.length = 0;
  16337. if (ti.target && ti.target.node) {
  16338. evt2.bubbles = true;
  16339. ti.target.node.dispatchEvent(evt2);
  16340. }
  16341. fgui.Event._return(evt2);
  16342. this.handleRollOver(ti, null);
  16343. ti.target = null;
  16344. ti.touchId = -1;
  16345. ti.button = -1;
  16346. };
  16347. InputProcessor.prototype.mouseDownHandler = function (evt) {
  16348. var ti = this.getInfo(0, true);
  16349. ti.button = evt.getButton();
  16350. };
  16351. InputProcessor.prototype.mouseUpHandler = function (evt) {
  16352. var ti = this.getInfo(0, true);
  16353. ti.button = evt.getButton();
  16354. };
  16355. InputProcessor.prototype.mouseMoveHandler = function (evt) {
  16356. var ti = this.getInfo(0, false);
  16357. if (ti
  16358. && Math.abs(ti.pos.x - evt.getLocationX()) < 1
  16359. && Math.abs(ti.pos.y - (fgui.GRoot.inst.height - evt.getLocationY())) < 1)
  16360. return;
  16361. ti = this.updateInfo(0, evt.getLocation());
  16362. this.handleRollOver(ti, ti.target);
  16363. if (ti.began) {
  16364. var evt2 = this.getEvent(ti, ti.target, fgui.Event.TOUCH_MOVE, false);
  16365. var done = false;
  16366. var cnt = ti.touchMonitors.length;
  16367. for (var i = 0; i < cnt; i++) {
  16368. var mm = ti.touchMonitors[i];
  16369. if (mm.node == null || !mm.node.activeInHierarchy)
  16370. continue;
  16371. evt2.initiator = mm;
  16372. mm.node.dispatchEvent(evt2);
  16373. if (mm == this._owner)
  16374. done = true;
  16375. }
  16376. if (!done && this.node) {
  16377. evt2.initiator = this._owner;
  16378. this.node.dispatchEvent(evt2);
  16379. fgui.Event._return(evt2);
  16380. }
  16381. fgui.Event._return(evt2);
  16382. }
  16383. };
  16384. InputProcessor.prototype.mouseWheelHandler = function (evt) {
  16385. var ti = this.updateInfo(0, evt.getLocation());
  16386. ti.mouseWheelDelta = Math.max(evt.getScrollX(), evt.getScrollY());
  16387. var evt2 = this.getEvent(ti, ti.target, fgui.Event.MOUSE_WHEEL, true);
  16388. ti.target.node.dispatchEvent(evt2);
  16389. fgui.Event._return(evt2);
  16390. };
  16391. InputProcessor.prototype.updateInfo = function (touchId, pos, touch) {
  16392. var camera = cc.Camera.findCamera(this.node);
  16393. if (camera)
  16394. camera.getScreenToWorldPoint(pos, this._touchPos);
  16395. else
  16396. this._touchPos.set(pos);
  16397. this._touchPos.y = fgui.GRoot.inst.height - this._touchPos.y;
  16398. var target = this._owner.hitTest(this._touchPos);
  16399. if (!target)
  16400. target = this._owner;
  16401. var ti = this.getInfo(touchId);
  16402. ti.target = target;
  16403. ti.pos.set(this._touchPos);
  16404. ti.button = cc.Event.EventMouse.BUTTON_LEFT;
  16405. ti.touch = touch;
  16406. return ti;
  16407. };
  16408. InputProcessor.prototype.getInfo = function (touchId, createIfNotExisits) {
  16409. if (createIfNotExisits === undefined)
  16410. createIfNotExisits = true;
  16411. var ret = null;
  16412. var cnt = this._touches.length;
  16413. for (var i = 0; i < cnt; i++) {
  16414. var ti = this._touches[i];
  16415. if (ti.touchId == touchId)
  16416. return ti;
  16417. else if (ti.touchId == -1)
  16418. ret = ti;
  16419. }
  16420. if (!ret) {
  16421. if (!createIfNotExisits)
  16422. return null;
  16423. ret = new TouchInfo();
  16424. this._touches.push(ret);
  16425. }
  16426. ret.touchId = touchId;
  16427. return ret;
  16428. };
  16429. InputProcessor.prototype.setBegin = function (ti) {
  16430. ti.began = true;
  16431. ti.clickCancelled = false;
  16432. ti.downPos.set(ti.pos);
  16433. ti.downTargets.length = 0;
  16434. var obj = ti.target;
  16435. while (obj) {
  16436. ti.downTargets.push(obj);
  16437. obj = obj.findParent();
  16438. }
  16439. };
  16440. InputProcessor.prototype.setEnd = function (ti) {
  16441. ti.began = false;
  16442. var now = fgui.ToolSet.getTime();
  16443. var elapsed = now - ti.lastClickTime;
  16444. if (elapsed < 0.45) {
  16445. if (ti.clickCount == 2)
  16446. ti.clickCount = 1;
  16447. else
  16448. ti.clickCount++;
  16449. }
  16450. else
  16451. ti.clickCount = 1;
  16452. ti.lastClickTime = now;
  16453. };
  16454. InputProcessor.prototype.clickTest = function (ti) {
  16455. if (ti.downTargets.length == 0
  16456. || ti.clickCancelled
  16457. || Math.abs(ti.pos.x - ti.downPos.x) > 50 || Math.abs(ti.pos.y - ti.downPos.y) > 50)
  16458. return null;
  16459. var obj = ti.downTargets[0];
  16460. if (obj && obj.node && obj.node.activeInHierarchy)
  16461. return obj;
  16462. obj = ti.target;
  16463. while (obj) {
  16464. var index = ti.downTargets.indexOf(obj);
  16465. if (index != -1 && obj.node && obj.node.activeInHierarchy)
  16466. break;
  16467. obj = obj.findParent();
  16468. }
  16469. return obj;
  16470. };
  16471. InputProcessor.prototype.handleRollOver = function (ti, target) {
  16472. if (ti.lastRollOver == target)
  16473. return;
  16474. var element = ti.lastRollOver;
  16475. while (element && element.node) {
  16476. this._rollOutChain.push(element);
  16477. element = element.findParent();
  16478. }
  16479. element = target;
  16480. while (element && element.node) {
  16481. var i = this._rollOutChain.indexOf(element);
  16482. if (i != -1) {
  16483. this._rollOutChain.length = i;
  16484. break;
  16485. }
  16486. this._rollOverChain.push(element);
  16487. element = element.findParent();
  16488. }
  16489. ti.lastRollOver = target;
  16490. var cnt = this._rollOutChain.length;
  16491. for (var i = 0; i < cnt; i++) {
  16492. element = this._rollOutChain[i];
  16493. if (element.node && element.node.activeInHierarchy) {
  16494. var evt = this.getEvent(ti, element, fgui.Event.ROLL_OUT, false);
  16495. element.node.dispatchEvent(evt);
  16496. fgui.Event._return(evt);
  16497. }
  16498. }
  16499. cnt = this._rollOverChain.length;
  16500. for (var i = 0; i < cnt; i++) {
  16501. element = this._rollOverChain[i];
  16502. if (element.node && element.node.activeInHierarchy) {
  16503. var evt = this.getEvent(ti, element, fgui.Event.ROLL_OVER, false);
  16504. element.node.dispatchEvent(evt);
  16505. fgui.Event._return(evt);
  16506. }
  16507. }
  16508. this._rollOutChain.length = 0;
  16509. this._rollOverChain.length = 0;
  16510. };
  16511. InputProcessor.prototype.getEvent = function (ti, target, type, bubbles) {
  16512. var evt = fgui.Event._borrow(type, bubbles);
  16513. evt.initiator = target;
  16514. evt.touch = ti.touch;
  16515. evt.pos.set(ti.pos);
  16516. evt.touchId = ti.touch ? ti.touch.getID() : 0;
  16517. evt.clickCount = ti.clickCount;
  16518. evt.button = ti.button;
  16519. evt.mouseWheelDelta = ti.mouseWheelDelta;
  16520. evt._processor = this;
  16521. return evt;
  16522. };
  16523. return InputProcessor;
  16524. }(cc.Component));
  16525. fgui.InputProcessor = InputProcessor;
  16526. var TouchInfo = (function () {
  16527. function TouchInfo() {
  16528. this.pos = new cc.Vec2();
  16529. this.touchId = 0;
  16530. this.clickCount = 0;
  16531. this.mouseWheelDelta = 0;
  16532. this.button = -1;
  16533. this.downPos = new cc.Vec2();
  16534. this.began = false;
  16535. this.clickCancelled = false;
  16536. this.lastClickTime = 0;
  16537. this.downTargets = new Array();
  16538. this.touchMonitors = new Array();
  16539. }
  16540. return TouchInfo;
  16541. }());
  16542. ;
  16543. })(fgui || (fgui = {}));
  16544. (function (fgui) {
  16545. var GearBase = (function () {
  16546. function GearBase(owner) {
  16547. this._owner = owner;
  16548. }
  16549. GearBase.create = function (owner, index) {
  16550. if (!Classes)
  16551. Classes = [
  16552. fgui.GearDisplay, fgui.GearXY, fgui.GearSize, fgui.GearLook, fgui.GearColor,
  16553. fgui.GearAnimation, fgui.GearText, fgui.GearIcon, fgui.GearDisplay2, fgui.GearFontSize
  16554. ];
  16555. return new (Classes[index])(owner);
  16556. };
  16557. GearBase.prototype.dispose = function () {
  16558. if (this._tweenConfig && this._tweenConfig._tweener) {
  16559. this._tweenConfig._tweener.kill();
  16560. this._tweenConfig._tweener = null;
  16561. }
  16562. };
  16563. Object.defineProperty(GearBase.prototype, "controller", {
  16564. get: function () {
  16565. return this._controller;
  16566. },
  16567. set: function (val) {
  16568. if (val != this._controller) {
  16569. this._controller = val;
  16570. if (this._controller)
  16571. this.init();
  16572. }
  16573. },
  16574. enumerable: false,
  16575. configurable: true
  16576. });
  16577. Object.defineProperty(GearBase.prototype, "tweenConfig", {
  16578. get: function () {
  16579. if (!this._tweenConfig)
  16580. this._tweenConfig = new GearTweenConfig();
  16581. return this._tweenConfig;
  16582. },
  16583. enumerable: false,
  16584. configurable: true
  16585. });
  16586. GearBase.prototype.setup = function (buffer) {
  16587. this._controller = this._owner.parent.getControllerAt(buffer.readShort());
  16588. this.init();
  16589. var i;
  16590. var page;
  16591. var cnt = buffer.readShort();
  16592. if (this instanceof fgui.GearDisplay) {
  16593. this.pages = buffer.readSArray(cnt);
  16594. }
  16595. else if (this instanceof fgui.GearDisplay2) {
  16596. this.pages = buffer.readSArray(cnt);
  16597. }
  16598. else {
  16599. for (i = 0; i < cnt; i++) {
  16600. page = buffer.readS();
  16601. if (page == null)
  16602. continue;
  16603. this.addStatus(page, buffer);
  16604. }
  16605. if (buffer.readBool())
  16606. this.addStatus(null, buffer);
  16607. }
  16608. if (buffer.readBool()) {
  16609. this._tweenConfig = new GearTweenConfig();
  16610. this._tweenConfig.easeType = buffer.readByte();
  16611. this._tweenConfig.duration = buffer.readFloat();
  16612. this._tweenConfig.delay = buffer.readFloat();
  16613. }
  16614. if (buffer.version >= 2) {
  16615. if (this instanceof fgui.GearXY) {
  16616. if (buffer.readBool()) {
  16617. this.positionsInPercent = true;
  16618. for (i = 0; i < cnt; i++) {
  16619. page = buffer.readS();
  16620. if (page == null)
  16621. continue;
  16622. this.addExtStatus(page, buffer);
  16623. }
  16624. if (buffer.readBool())
  16625. this.addExtStatus(null, buffer);
  16626. }
  16627. }
  16628. else if (this instanceof fgui.GearDisplay2)
  16629. this.condition = buffer.readByte();
  16630. }
  16631. };
  16632. GearBase.prototype.updateFromRelations = function (dx, dy) {
  16633. };
  16634. GearBase.prototype.addStatus = function (pageId, buffer) {
  16635. };
  16636. GearBase.prototype.init = function () {
  16637. };
  16638. GearBase.prototype.apply = function () {
  16639. };
  16640. GearBase.prototype.updateState = function () {
  16641. };
  16642. return GearBase;
  16643. }());
  16644. fgui.GearBase = GearBase;
  16645. var Classes;
  16646. var GearTweenConfig = (function () {
  16647. function GearTweenConfig() {
  16648. this.tween = true;
  16649. this.easeType = fgui.EaseType.QuadOut;
  16650. this.duration = 0.3;
  16651. this.delay = 0;
  16652. }
  16653. return GearTweenConfig;
  16654. }());
  16655. fgui.GearTweenConfig = GearTweenConfig;
  16656. })(fgui || (fgui = {}));
  16657. (function (fgui) {
  16658. var GearAnimation = (function (_super) {
  16659. __extends(GearAnimation, _super);
  16660. function GearAnimation(owner) {
  16661. return _super.call(this, owner) || this;
  16662. }
  16663. GearAnimation.prototype.init = function () {
  16664. this._default = {
  16665. playing: this._owner.getProp(fgui.ObjectPropID.Playing),
  16666. frame: this._owner.getProp(fgui.ObjectPropID.Frame)
  16667. };
  16668. this._storage = {};
  16669. };
  16670. GearAnimation.prototype.addStatus = function (pageId, buffer) {
  16671. var gv;
  16672. if (pageId == null)
  16673. gv = this._default;
  16674. else
  16675. this._storage[pageId] = gv = {};
  16676. gv.playing = buffer.readBool();
  16677. gv.frame = buffer.readInt();
  16678. };
  16679. GearAnimation.prototype.apply = function () {
  16680. this._owner._gearLocked = true;
  16681. var gv = this._storage[this._controller.selectedPageId];
  16682. if (!gv)
  16683. gv = this._default;
  16684. this._owner.setProp(fgui.ObjectPropID.Playing, gv.playing);
  16685. this._owner.setProp(fgui.ObjectPropID.Frame, gv.frame);
  16686. this._owner._gearLocked = false;
  16687. };
  16688. GearAnimation.prototype.updateState = function () {
  16689. var gv = this._storage[this._controller.selectedPageId];
  16690. if (!gv)
  16691. this._storage[this._controller.selectedPageId] = gv = {};
  16692. gv.playing = this._owner.getProp(fgui.ObjectPropID.Playing);
  16693. gv.frame = this._owner.getProp(fgui.ObjectPropID.Frame);
  16694. };
  16695. return GearAnimation;
  16696. }(fgui.GearBase));
  16697. fgui.GearAnimation = GearAnimation;
  16698. })(fgui || (fgui = {}));
  16699. (function (fgui) {
  16700. var GearColor = (function (_super) {
  16701. __extends(GearColor, _super);
  16702. function GearColor(owner) {
  16703. return _super.call(this, owner) || this;
  16704. }
  16705. GearColor.prototype.init = function () {
  16706. this._default = {
  16707. color: this._owner.getProp(fgui.ObjectPropID.Color),
  16708. strokeColor: this._owner.getProp(fgui.ObjectPropID.OutlineColor)
  16709. };
  16710. this._storage = {};
  16711. };
  16712. GearColor.prototype.addStatus = function (pageId, buffer) {
  16713. var gv;
  16714. if (pageId == null)
  16715. gv = this._default;
  16716. else
  16717. this._storage[pageId] = gv = {};
  16718. gv.color = buffer.readColor();
  16719. gv.strokeColor = buffer.readColor();
  16720. };
  16721. GearColor.prototype.apply = function () {
  16722. this._owner._gearLocked = true;
  16723. var gv = this._storage[this._controller.selectedPageId];
  16724. if (!gv)
  16725. gv = this._default;
  16726. this._owner.setProp(fgui.ObjectPropID.Color, gv.color);
  16727. this._owner.setProp(fgui.ObjectPropID.OutlineColor, gv.strokeColor);
  16728. this._owner._gearLocked = false;
  16729. };
  16730. GearColor.prototype.updateState = function () {
  16731. var gv = this._storage[this._controller.selectedPageId];
  16732. if (!gv)
  16733. this._storage[this._controller.selectedPageId] = gv = {};
  16734. gv.color = this._owner.getProp(fgui.ObjectPropID.Color);
  16735. gv.strokeColor = this._owner.getProp(fgui.ObjectPropID.OutlineColor);
  16736. };
  16737. return GearColor;
  16738. }(fgui.GearBase));
  16739. fgui.GearColor = GearColor;
  16740. })(fgui || (fgui = {}));
  16741. (function (fgui) {
  16742. var GearDisplay = (function (_super) {
  16743. __extends(GearDisplay, _super);
  16744. function GearDisplay(owner) {
  16745. var _this = _super.call(this, owner) || this;
  16746. _this._displayLockToken = 1;
  16747. _this._visible = 0;
  16748. return _this;
  16749. }
  16750. GearDisplay.prototype.init = function () {
  16751. this.pages = null;
  16752. };
  16753. GearDisplay.prototype.apply = function () {
  16754. this._displayLockToken++;
  16755. if (this._displayLockToken == 0)
  16756. this._displayLockToken = 1;
  16757. if (this.pages == null || this.pages.length == 0
  16758. || this.pages.indexOf(this._controller.selectedPageId) != -1)
  16759. this._visible = 1;
  16760. else
  16761. this._visible = 0;
  16762. };
  16763. GearDisplay.prototype.addLock = function () {
  16764. this._visible++;
  16765. return this._displayLockToken;
  16766. };
  16767. GearDisplay.prototype.releaseLock = function (token) {
  16768. if (token == this._displayLockToken)
  16769. this._visible--;
  16770. };
  16771. Object.defineProperty(GearDisplay.prototype, "connected", {
  16772. get: function () {
  16773. return this._controller == null || this._visible > 0;
  16774. },
  16775. enumerable: false,
  16776. configurable: true
  16777. });
  16778. return GearDisplay;
  16779. }(fgui.GearBase));
  16780. fgui.GearDisplay = GearDisplay;
  16781. })(fgui || (fgui = {}));
  16782. (function (fgui) {
  16783. var GearDisplay2 = (function (_super) {
  16784. __extends(GearDisplay2, _super);
  16785. function GearDisplay2(owner) {
  16786. var _this = _super.call(this, owner) || this;
  16787. _this._visible = 0;
  16788. return _this;
  16789. }
  16790. GearDisplay2.prototype.init = function () {
  16791. this.pages = null;
  16792. };
  16793. GearDisplay2.prototype.apply = function () {
  16794. if (this.pages == null || this.pages.length == 0
  16795. || this.pages.indexOf(this._controller.selectedPageId) != -1)
  16796. this._visible = 1;
  16797. else
  16798. this._visible = 0;
  16799. };
  16800. GearDisplay2.prototype.evaluate = function (connected) {
  16801. var v = this._controller == null || this._visible > 0;
  16802. if (this.condition == 0)
  16803. v = v && connected;
  16804. else
  16805. v = v || connected;
  16806. return v;
  16807. };
  16808. return GearDisplay2;
  16809. }(fgui.GearBase));
  16810. fgui.GearDisplay2 = GearDisplay2;
  16811. })(fgui || (fgui = {}));
  16812. (function (fgui) {
  16813. var GearFontSize = (function (_super) {
  16814. __extends(GearFontSize, _super);
  16815. function GearFontSize(owner) {
  16816. var _this = _super.call(this, owner) || this;
  16817. _this._default = 0;
  16818. return _this;
  16819. }
  16820. GearFontSize.prototype.init = function () {
  16821. this._default = this._owner.getProp(fgui.ObjectPropID.FontSize);
  16822. this._storage = {};
  16823. };
  16824. GearFontSize.prototype.addStatus = function (pageId, buffer) {
  16825. if (pageId == null)
  16826. this._default = buffer.readInt();
  16827. else
  16828. this._storage[pageId] = buffer.readInt();
  16829. };
  16830. GearFontSize.prototype.apply = function () {
  16831. this._owner._gearLocked = true;
  16832. var data = this._storage[this._controller.selectedPageId];
  16833. if (data != undefined)
  16834. this._owner.setProp(fgui.ObjectPropID.FontSize, data);
  16835. else
  16836. this._owner.setProp(fgui.ObjectPropID.FontSize, this._default);
  16837. this._owner._gearLocked = false;
  16838. };
  16839. GearFontSize.prototype.updateState = function () {
  16840. this._storage[this._controller.selectedPageId] = this._owner.getProp(fgui.ObjectPropID.FontSize);
  16841. };
  16842. return GearFontSize;
  16843. }(fgui.GearBase));
  16844. fgui.GearFontSize = GearFontSize;
  16845. })(fgui || (fgui = {}));
  16846. (function (fgui) {
  16847. var GearIcon = (function (_super) {
  16848. __extends(GearIcon, _super);
  16849. function GearIcon(owner) {
  16850. return _super.call(this, owner) || this;
  16851. }
  16852. GearIcon.prototype.init = function () {
  16853. this._default = this._owner.icon;
  16854. this._storage = {};
  16855. };
  16856. GearIcon.prototype.addStatus = function (pageId, buffer) {
  16857. if (pageId == null)
  16858. this._default = buffer.readS();
  16859. else
  16860. this._storage[pageId] = buffer.readS();
  16861. };
  16862. GearIcon.prototype.apply = function () {
  16863. this._owner._gearLocked = true;
  16864. var data = this._storage[this._controller.selectedPageId];
  16865. if (data !== undefined)
  16866. this._owner.icon = data;
  16867. else
  16868. this._owner.icon = this._default;
  16869. this._owner._gearLocked = false;
  16870. };
  16871. GearIcon.prototype.updateState = function () {
  16872. this._storage[this._controller.selectedPageId] = this._owner.icon;
  16873. };
  16874. return GearIcon;
  16875. }(fgui.GearBase));
  16876. fgui.GearIcon = GearIcon;
  16877. })(fgui || (fgui = {}));
  16878. (function (fgui) {
  16879. var GearLook = (function (_super) {
  16880. __extends(GearLook, _super);
  16881. function GearLook(owner) {
  16882. return _super.call(this, owner) || this;
  16883. }
  16884. GearLook.prototype.init = function () {
  16885. this._default = {
  16886. alpha: this._owner.alpha,
  16887. rotation: this._owner.rotation,
  16888. grayed: this._owner.grayed,
  16889. touchable: this._owner.touchable
  16890. };
  16891. this._storage = {};
  16892. };
  16893. GearLook.prototype.addStatus = function (pageId, buffer) {
  16894. var gv;
  16895. if (pageId == null)
  16896. gv = this._default;
  16897. else
  16898. this._storage[pageId] = gv = {};
  16899. gv.alpha = buffer.readFloat();
  16900. gv.rotation = buffer.readFloat();
  16901. gv.grayed = buffer.readBool();
  16902. gv.touchable = buffer.readBool();
  16903. };
  16904. GearLook.prototype.apply = function () {
  16905. var gv = this._storage[this._controller.selectedPageId];
  16906. if (!gv)
  16907. gv = this._default;
  16908. if (this._tweenConfig && this._tweenConfig.tween && !fgui.UIPackage._constructing && !fgui.GearBase.disableAllTweenEffect) {
  16909. this._owner._gearLocked = true;
  16910. this._owner.grayed = gv.grayed;
  16911. this._owner.touchable = gv.touchable;
  16912. this._owner._gearLocked = false;
  16913. if (this._tweenConfig._tweener) {
  16914. if (this._tweenConfig._tweener.endValue.x != gv.alpha || this._tweenConfig._tweener.endValue.y != gv.rotation) {
  16915. this._tweenConfig._tweener.kill(true);
  16916. this._tweenConfig._tweener = null;
  16917. }
  16918. else
  16919. return;
  16920. }
  16921. var a = gv.alpha != this._owner.alpha;
  16922. var b = gv.rotation != this._owner.rotation;
  16923. if (a || b) {
  16924. if (this._owner.checkGearController(0, this._controller))
  16925. this._tweenConfig._displayLockToken = this._owner.addDisplayLock();
  16926. this._tweenConfig._tweener = fgui.GTween.to2(this._owner.alpha, this._owner.rotation, gv.alpha, gv.rotation, this._tweenConfig.duration)
  16927. .setDelay(this._tweenConfig.delay)
  16928. .setEase(this._tweenConfig.easeType)
  16929. .setUserData((a ? 1 : 0) + (b ? 2 : 0))
  16930. .setTarget(this)
  16931. .onUpdate(this.__tweenUpdate, this)
  16932. .onComplete(this.__tweenComplete, this);
  16933. }
  16934. }
  16935. else {
  16936. this._owner._gearLocked = true;
  16937. this._owner.grayed = gv.grayed;
  16938. this._owner.touchable = gv.touchable;
  16939. this._owner.alpha = gv.alpha;
  16940. this._owner.rotation = gv.rotation;
  16941. this._owner._gearLocked = false;
  16942. }
  16943. };
  16944. GearLook.prototype.__tweenUpdate = function (tweener) {
  16945. var flag = tweener.userData;
  16946. this._owner._gearLocked = true;
  16947. if ((flag & 1) != 0)
  16948. this._owner.alpha = tweener.value.x;
  16949. if ((flag & 2) != 0)
  16950. this._owner.rotation = tweener.value.y;
  16951. this._owner._gearLocked = false;
  16952. };
  16953. GearLook.prototype.__tweenComplete = function () {
  16954. if (this._tweenConfig._displayLockToken != 0) {
  16955. this._owner.releaseDisplayLock(this._tweenConfig._displayLockToken);
  16956. this._tweenConfig._displayLockToken = 0;
  16957. }
  16958. this._tweenConfig._tweener = null;
  16959. };
  16960. GearLook.prototype.updateState = function () {
  16961. var gv = this._storage[this._controller.selectedPageId];
  16962. if (!gv)
  16963. this._storage[this._controller.selectedPageId] = gv = {};
  16964. gv.alpha = this._owner.alpha;
  16965. gv.rotation = this._owner.rotation;
  16966. gv.grayed = this._owner.grayed;
  16967. gv.touchable = this._owner.touchable;
  16968. };
  16969. return GearLook;
  16970. }(fgui.GearBase));
  16971. fgui.GearLook = GearLook;
  16972. })(fgui || (fgui = {}));
  16973. (function (fgui) {
  16974. var GearSize = (function (_super) {
  16975. __extends(GearSize, _super);
  16976. function GearSize(owner) {
  16977. return _super.call(this, owner) || this;
  16978. }
  16979. GearSize.prototype.init = function () {
  16980. this._default = {
  16981. width: this._owner.width,
  16982. height: this._owner.height,
  16983. scaleX: this._owner.scaleX,
  16984. scaleY: this._owner.scaleY
  16985. };
  16986. this._storage = {};
  16987. };
  16988. GearSize.prototype.addStatus = function (pageId, buffer) {
  16989. var gv;
  16990. if (pageId == null)
  16991. gv = this._default;
  16992. else
  16993. this._storage[pageId] = gv = {};
  16994. gv.width = buffer.readInt();
  16995. gv.height = buffer.readInt();
  16996. gv.scaleX = buffer.readFloat();
  16997. gv.scaleY = buffer.readFloat();
  16998. };
  16999. GearSize.prototype.apply = function () {
  17000. var gv = this._storage[this._controller.selectedPageId];
  17001. if (!gv)
  17002. gv = this._default;
  17003. if (this._tweenConfig && this._tweenConfig.tween && !fgui.UIPackage._constructing && !fgui.GearBase.disableAllTweenEffect) {
  17004. if (this._tweenConfig._tweener) {
  17005. if (this._tweenConfig._tweener.endValue.x != gv.width || this._tweenConfig._tweener.endValue.y != gv.height
  17006. || this._tweenConfig._tweener.endValue.z != gv.scaleX || this._tweenConfig._tweener.endValue.w != gv.scaleY) {
  17007. this._tweenConfig._tweener.kill(true);
  17008. this._tweenConfig._tweener = null;
  17009. }
  17010. else
  17011. return;
  17012. }
  17013. var a = gv.width != this._owner.width || gv.height != this._owner.height;
  17014. var b = gv.scaleX != this._owner.scaleX || gv.scaleY != this._owner.scaleY;
  17015. if (a || b) {
  17016. if (this._owner.checkGearController(0, this._controller))
  17017. this._tweenConfig._displayLockToken = this._owner.addDisplayLock();
  17018. 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)
  17019. .setDelay(this._tweenConfig.delay)
  17020. .setEase(this._tweenConfig.easeType)
  17021. .setUserData((a ? 1 : 0) + (b ? 2 : 0))
  17022. .setTarget(this)
  17023. .onUpdate(this.__tweenUpdate, this)
  17024. .onComplete(this.__tweenComplete, this);
  17025. }
  17026. }
  17027. else {
  17028. this._owner._gearLocked = true;
  17029. this._owner.setSize(gv.width, gv.height, this._owner.gearXY.controller == this._controller);
  17030. this._owner.setScale(gv.scaleX, gv.scaleY);
  17031. this._owner._gearLocked = false;
  17032. }
  17033. };
  17034. GearSize.prototype.__tweenUpdate = function (tweener) {
  17035. var flag = tweener.userData;
  17036. this._owner._gearLocked = true;
  17037. if ((flag & 1) != 0)
  17038. this._owner.setSize(tweener.value.x, tweener.value.y, this._owner.checkGearController(1, this._controller));
  17039. if ((flag & 2) != 0)
  17040. this._owner.setScale(tweener.value.z, tweener.value.w);
  17041. this._owner._gearLocked = false;
  17042. };
  17043. GearSize.prototype.__tweenComplete = function () {
  17044. if (this._tweenConfig._displayLockToken != 0) {
  17045. this._owner.releaseDisplayLock(this._tweenConfig._displayLockToken);
  17046. this._tweenConfig._displayLockToken = 0;
  17047. }
  17048. this._tweenConfig._tweener = null;
  17049. };
  17050. GearSize.prototype.updateState = function () {
  17051. var gv = this._storage[this._controller.selectedPageId];
  17052. if (!gv)
  17053. this._storage[this._controller.selectedPageId] = gv = {};
  17054. gv.width = this._owner.width;
  17055. gv.height = this._owner.height;
  17056. gv.scaleX = this._owner.scaleX;
  17057. gv.scaleY = this._owner.scaleY;
  17058. };
  17059. GearSize.prototype.updateFromRelations = function (dx, dy) {
  17060. if (this._controller == null || this._storage == null)
  17061. return;
  17062. for (var key in this._storage) {
  17063. var gv = this._storage[key];
  17064. gv.width += dx;
  17065. gv.height += dy;
  17066. }
  17067. this._default.width += dx;
  17068. this._default.height += dy;
  17069. this.updateState();
  17070. };
  17071. return GearSize;
  17072. }(fgui.GearBase));
  17073. fgui.GearSize = GearSize;
  17074. })(fgui || (fgui = {}));
  17075. (function (fgui) {
  17076. var GearText = (function (_super) {
  17077. __extends(GearText, _super);
  17078. function GearText(owner) {
  17079. return _super.call(this, owner) || this;
  17080. }
  17081. GearText.prototype.init = function () {
  17082. this._default = this._owner.text;
  17083. this._storage = {};
  17084. };
  17085. GearText.prototype.addStatus = function (pageId, buffer) {
  17086. if (pageId == null)
  17087. this._default = buffer.readS();
  17088. else
  17089. this._storage[pageId] = buffer.readS();
  17090. };
  17091. GearText.prototype.apply = function () {
  17092. this._owner._gearLocked = true;
  17093. var data = this._storage[this._controller.selectedPageId];
  17094. if (data !== undefined)
  17095. this._owner.text = data;
  17096. else
  17097. this._owner.text = this._default;
  17098. this._owner._gearLocked = false;
  17099. };
  17100. GearText.prototype.updateState = function () {
  17101. this._storage[this._controller.selectedPageId] = this._owner.text;
  17102. };
  17103. return GearText;
  17104. }(fgui.GearBase));
  17105. fgui.GearText = GearText;
  17106. })(fgui || (fgui = {}));
  17107. (function (fgui) {
  17108. var GearXY = (function (_super) {
  17109. __extends(GearXY, _super);
  17110. function GearXY(owner) {
  17111. return _super.call(this, owner) || this;
  17112. }
  17113. GearXY.prototype.init = function () {
  17114. this._default = {
  17115. x: this._owner.x,
  17116. y: this._owner.y,
  17117. px: this._owner.x / this._owner.parent.width,
  17118. py: this._owner.y / this._owner.parent.height
  17119. };
  17120. this._storage = {};
  17121. };
  17122. GearXY.prototype.addStatus = function (pageId, buffer) {
  17123. var gv;
  17124. if (pageId == null)
  17125. gv = this._default;
  17126. else
  17127. this._storage[pageId] = gv = {};
  17128. gv.x = buffer.readInt();
  17129. gv.y = buffer.readInt();
  17130. };
  17131. GearXY.prototype.addExtStatus = function (pageId, buffer) {
  17132. var gv;
  17133. if (pageId == null)
  17134. gv = this._default;
  17135. else
  17136. gv = this._storage[pageId];
  17137. gv.px = buffer.readFloat();
  17138. gv.py = buffer.readFloat();
  17139. };
  17140. GearXY.prototype.apply = function () {
  17141. var gv = this._storage[this._controller.selectedPageId];
  17142. if (!gv)
  17143. gv = this._default;
  17144. var ex;
  17145. var ey;
  17146. if (this.positionsInPercent && this._owner.parent) {
  17147. ex = gv.px * this._owner.parent.width;
  17148. ey = gv.py * this._owner.parent.height;
  17149. }
  17150. else {
  17151. ex = gv.x;
  17152. ey = gv.y;
  17153. }
  17154. if (this._tweenConfig && this._tweenConfig.tween && !fgui.UIPackage._constructing && !fgui.GearBase.disableAllTweenEffect) {
  17155. if (this._tweenConfig._tweener) {
  17156. if (this._tweenConfig._tweener.endValue.x != ex || this._tweenConfig._tweener.endValue.y != ey) {
  17157. this._tweenConfig._tweener.kill(true);
  17158. this._tweenConfig._tweener = null;
  17159. }
  17160. else
  17161. return;
  17162. }
  17163. var ox = this._owner.x;
  17164. var oy = this._owner.y;
  17165. if (ox != ex || oy != ey) {
  17166. if (this._owner.checkGearController(0, this._controller))
  17167. this._tweenConfig._displayLockToken = this._owner.addDisplayLock();
  17168. this._tweenConfig._tweener = fgui.GTween.to2(ox, oy, ex, ey, this._tweenConfig.duration)
  17169. .setDelay(this._tweenConfig.delay)
  17170. .setEase(this._tweenConfig.easeType)
  17171. .setTarget(this)
  17172. .onUpdate(this.__tweenUpdate, this)
  17173. .onComplete(this.__tweenComplete, this);
  17174. }
  17175. }
  17176. else {
  17177. this._owner._gearLocked = true;
  17178. this._owner.setPosition(ex, ey);
  17179. this._owner._gearLocked = false;
  17180. }
  17181. };
  17182. GearXY.prototype.__tweenUpdate = function (tweener) {
  17183. this._owner._gearLocked = true;
  17184. this._owner.setPosition(tweener.value.x, tweener.value.y);
  17185. this._owner._gearLocked = false;
  17186. };
  17187. GearXY.prototype.__tweenComplete = function () {
  17188. if (this._tweenConfig._displayLockToken != 0) {
  17189. this._owner.releaseDisplayLock(this._tweenConfig._displayLockToken);
  17190. this._tweenConfig._displayLockToken = 0;
  17191. }
  17192. this._tweenConfig._tweener = null;
  17193. };
  17194. GearXY.prototype.updateState = function () {
  17195. var gv = this._storage[this._controller.selectedPageId];
  17196. if (!gv)
  17197. this._storage[this._controller.selectedPageId] = gv = {};
  17198. gv.x = this._owner.x;
  17199. gv.y = this._owner.y;
  17200. gv.px = this._owner.x / this._owner.parent.width;
  17201. gv.py = this._owner.y / this._owner.parent.height;
  17202. };
  17203. GearXY.prototype.updateFromRelations = function (dx, dy) {
  17204. if (this._controller == null || this._storage == null || this.positionsInPercent)
  17205. return;
  17206. for (var key in this._storage) {
  17207. var pt = this._storage[key];
  17208. pt.x += dx;
  17209. pt.y += dy;
  17210. }
  17211. this._default.x += dx;
  17212. this._default.y += dy;
  17213. this.updateState();
  17214. };
  17215. return GearXY;
  17216. }(fgui.GearBase));
  17217. fgui.GearXY = GearXY;
  17218. })(fgui || (fgui = {}));
  17219. (function (fgui) {
  17220. var _PiOver2 = Math.PI * 0.5;
  17221. var _TwoPi = Math.PI * 2;
  17222. function evaluateEase(easeType, time, duration, overshootOrAmplitude, period) {
  17223. switch (easeType) {
  17224. case fgui.EaseType.Linear:
  17225. return time / duration;
  17226. case fgui.EaseType.SineIn:
  17227. return -Math.cos(time / duration * _PiOver2) + 1;
  17228. case fgui.EaseType.SineOut:
  17229. return Math.sin(time / duration * _PiOver2);
  17230. case fgui.EaseType.SineInOut:
  17231. return -0.5 * (Math.cos(Math.PI * time / duration) - 1);
  17232. case fgui.EaseType.QuadIn:
  17233. return (time /= duration) * time;
  17234. case fgui.EaseType.QuadOut:
  17235. return -(time /= duration) * (time - 2);
  17236. case fgui.EaseType.QuadInOut:
  17237. if ((time /= duration * 0.5) < 1)
  17238. return 0.5 * time * time;
  17239. return -0.5 * ((--time) * (time - 2) - 1);
  17240. case fgui.EaseType.CubicIn:
  17241. return (time /= duration) * time * time;
  17242. case fgui.EaseType.CubicOut:
  17243. return ((time = time / duration - 1) * time * time + 1);
  17244. case fgui.EaseType.CubicInOut:
  17245. if ((time /= duration * 0.5) < 1)
  17246. return 0.5 * time * time * time;
  17247. return 0.5 * ((time -= 2) * time * time + 2);
  17248. case fgui.EaseType.QuartIn:
  17249. return (time /= duration) * time * time * time;
  17250. case fgui.EaseType.QuartOut:
  17251. return -((time = time / duration - 1) * time * time * time - 1);
  17252. case fgui.EaseType.QuartInOut:
  17253. if ((time /= duration * 0.5) < 1)
  17254. return 0.5 * time * time * time * time;
  17255. return -0.5 * ((time -= 2) * time * time * time - 2);
  17256. case fgui.EaseType.QuintIn:
  17257. return (time /= duration) * time * time * time * time;
  17258. case fgui.EaseType.QuintOut:
  17259. return ((time = time / duration - 1) * time * time * time * time + 1);
  17260. case fgui.EaseType.QuintInOut:
  17261. if ((time /= duration * 0.5) < 1)
  17262. return 0.5 * time * time * time * time * time;
  17263. return 0.5 * ((time -= 2) * time * time * time * time + 2);
  17264. case fgui.EaseType.ExpoIn:
  17265. return (time == 0) ? 0 : Math.pow(2, 10 * (time / duration - 1));
  17266. case fgui.EaseType.ExpoOut:
  17267. if (time == duration)
  17268. return 1;
  17269. return (-Math.pow(2, -10 * time / duration) + 1);
  17270. case fgui.EaseType.ExpoInOut:
  17271. if (time == 0)
  17272. return 0;
  17273. if (time == duration)
  17274. return 1;
  17275. if ((time /= duration * 0.5) < 1)
  17276. return 0.5 * Math.pow(2, 10 * (time - 1));
  17277. return 0.5 * (-Math.pow(2, -10 * --time) + 2);
  17278. case fgui.EaseType.CircIn:
  17279. return -(Math.sqrt(1 - (time /= duration) * time) - 1);
  17280. case fgui.EaseType.CircOut:
  17281. return Math.sqrt(1 - (time = time / duration - 1) * time);
  17282. case fgui.EaseType.CircInOut:
  17283. if ((time /= duration * 0.5) < 1)
  17284. return -0.5 * (Math.sqrt(1 - time * time) - 1);
  17285. return 0.5 * (Math.sqrt(1 - (time -= 2) * time) + 1);
  17286. case fgui.EaseType.ElasticIn:
  17287. var s0;
  17288. if (time == 0)
  17289. return 0;
  17290. if ((time /= duration) == 1)
  17291. return 1;
  17292. if (period == 0)
  17293. period = duration * 0.3;
  17294. if (overshootOrAmplitude < 1) {
  17295. overshootOrAmplitude = 1;
  17296. s0 = period / 4;
  17297. }
  17298. else
  17299. s0 = period / _TwoPi * Math.asin(1 / overshootOrAmplitude);
  17300. return -(overshootOrAmplitude * Math.pow(2, 10 * (time -= 1)) * Math.sin((time * duration - s0) * _TwoPi / period));
  17301. case fgui.EaseType.ElasticOut:
  17302. var s1;
  17303. if (time == 0)
  17304. return 0;
  17305. if ((time /= duration) == 1)
  17306. return 1;
  17307. if (period == 0)
  17308. period = duration * 0.3;
  17309. if (overshootOrAmplitude < 1) {
  17310. overshootOrAmplitude = 1;
  17311. s1 = period / 4;
  17312. }
  17313. else
  17314. s1 = period / _TwoPi * Math.asin(1 / overshootOrAmplitude);
  17315. return (overshootOrAmplitude * Math.pow(2, -10 * time) * Math.sin((time * duration - s1) * _TwoPi / period) + 1);
  17316. case fgui.EaseType.ElasticInOut:
  17317. var s;
  17318. if (time == 0)
  17319. return 0;
  17320. if ((time /= duration * 0.5) == 2)
  17321. return 1;
  17322. if (period == 0)
  17323. period = duration * (0.3 * 1.5);
  17324. if (overshootOrAmplitude < 1) {
  17325. overshootOrAmplitude = 1;
  17326. s = period / 4;
  17327. }
  17328. else
  17329. s = period / _TwoPi * Math.asin(1 / overshootOrAmplitude);
  17330. if (time < 1)
  17331. return -0.5 * (overshootOrAmplitude * Math.pow(2, 10 * (time -= 1)) * Math.sin((time * duration - s) * _TwoPi / period));
  17332. return overshootOrAmplitude * Math.pow(2, -10 * (time -= 1)) * Math.sin((time * duration - s) * _TwoPi / period) * 0.5 + 1;
  17333. case fgui.EaseType.BackIn:
  17334. return (time /= duration) * time * ((overshootOrAmplitude + 1) * time - overshootOrAmplitude);
  17335. case fgui.EaseType.BackOut:
  17336. return ((time = time / duration - 1) * time * ((overshootOrAmplitude + 1) * time + overshootOrAmplitude) + 1);
  17337. case fgui.EaseType.BackInOut:
  17338. if ((time /= duration * 0.5) < 1)
  17339. return 0.5 * (time * time * (((overshootOrAmplitude *= (1.525)) + 1) * time - overshootOrAmplitude));
  17340. return 0.5 * ((time -= 2) * time * (((overshootOrAmplitude *= (1.525)) + 1) * time + overshootOrAmplitude) + 2);
  17341. case fgui.EaseType.BounceIn:
  17342. return bounce_easeIn(time, duration);
  17343. case fgui.EaseType.BounceOut:
  17344. return bounce_easeOut(time, duration);
  17345. case fgui.EaseType.BounceInOut:
  17346. return bounce_easeInOut(time, duration);
  17347. default:
  17348. return -(time /= duration) * (time - 2);
  17349. }
  17350. }
  17351. fgui.evaluateEase = evaluateEase;
  17352. function bounce_easeIn(time, duration) {
  17353. return 1 - bounce_easeOut(duration - time, duration);
  17354. }
  17355. function bounce_easeOut(time, duration) {
  17356. if ((time /= duration) < (1 / 2.75)) {
  17357. return (7.5625 * time * time);
  17358. }
  17359. if (time < (2 / 2.75)) {
  17360. return (7.5625 * (time -= (1.5 / 2.75)) * time + 0.75);
  17361. }
  17362. if (time < (2.5 / 2.75)) {
  17363. return (7.5625 * (time -= (2.25 / 2.75)) * time + 0.9375);
  17364. }
  17365. return (7.5625 * (time -= (2.625 / 2.75)) * time + 0.984375);
  17366. }
  17367. function bounce_easeInOut(time, duration) {
  17368. if (time < duration * 0.5) {
  17369. return bounce_easeIn(time * 2, duration) * 0.5;
  17370. }
  17371. return bounce_easeOut(time * 2 - duration, duration) * 0.5 + 0.5;
  17372. }
  17373. })(fgui || (fgui = {}));
  17374. (function (fgui) {
  17375. var EaseType = (function () {
  17376. function EaseType() {
  17377. }
  17378. EaseType.Linear = 0;
  17379. EaseType.SineIn = 1;
  17380. EaseType.SineOut = 2;
  17381. EaseType.SineInOut = 3;
  17382. EaseType.QuadIn = 4;
  17383. EaseType.QuadOut = 5;
  17384. EaseType.QuadInOut = 6;
  17385. EaseType.CubicIn = 7;
  17386. EaseType.CubicOut = 8;
  17387. EaseType.CubicInOut = 9;
  17388. EaseType.QuartIn = 10;
  17389. EaseType.QuartOut = 11;
  17390. EaseType.QuartInOut = 12;
  17391. EaseType.QuintIn = 13;
  17392. EaseType.QuintOut = 14;
  17393. EaseType.QuintInOut = 15;
  17394. EaseType.ExpoIn = 16;
  17395. EaseType.ExpoOut = 17;
  17396. EaseType.ExpoInOut = 18;
  17397. EaseType.CircIn = 19;
  17398. EaseType.CircOut = 20;
  17399. EaseType.CircInOut = 21;
  17400. EaseType.ElasticIn = 22;
  17401. EaseType.ElasticOut = 23;
  17402. EaseType.ElasticInOut = 24;
  17403. EaseType.BackIn = 25;
  17404. EaseType.BackOut = 26;
  17405. EaseType.BackInOut = 27;
  17406. EaseType.BounceIn = 28;
  17407. EaseType.BounceOut = 29;
  17408. EaseType.BounceInOut = 30;
  17409. EaseType.Custom = 31;
  17410. return EaseType;
  17411. }());
  17412. fgui.EaseType = EaseType;
  17413. })(fgui || (fgui = {}));
  17414. (function (fgui) {
  17415. var GPath = (function () {
  17416. function GPath() {
  17417. this._segments = new Array();
  17418. this._points = new Array();
  17419. }
  17420. Object.defineProperty(GPath.prototype, "length", {
  17421. get: function () {
  17422. return this._fullLength;
  17423. },
  17424. enumerable: false,
  17425. configurable: true
  17426. });
  17427. GPath.prototype.create = function (pt1, pt2, pt3, pt4) {
  17428. var points;
  17429. if (Array.isArray(pt1))
  17430. points = pt1;
  17431. else {
  17432. points = new Array();
  17433. points.push(pt1);
  17434. points.push(pt2);
  17435. if (pt3)
  17436. points.push(pt3);
  17437. if (pt4)
  17438. points.push(pt4);
  17439. }
  17440. this._segments.length = 0;
  17441. this._points.length = 0;
  17442. this._fullLength = 0;
  17443. var cnt = points.length;
  17444. if (cnt == 0)
  17445. return;
  17446. var splinePoints = s_points;
  17447. splinePoints.length = 0;
  17448. var prev = points[0];
  17449. if (prev.curveType == fgui.CurveType.CRSpline)
  17450. splinePoints.push(new cc.Vec2(prev.x, prev.y));
  17451. for (var i = 1; i < cnt; i++) {
  17452. var current = points[i];
  17453. if (prev.curveType != fgui.CurveType.CRSpline) {
  17454. var seg = {};
  17455. seg.type = prev.curveType;
  17456. seg.ptStart = this._points.length;
  17457. if (prev.curveType == fgui.CurveType.Straight) {
  17458. seg.ptCount = 2;
  17459. this._points.push(new cc.Vec2(prev.x, prev.y));
  17460. this._points.push(new cc.Vec2(current.x, current.y));
  17461. }
  17462. else if (prev.curveType == fgui.CurveType.Bezier) {
  17463. seg.ptCount = 3;
  17464. this._points.push(new cc.Vec2(prev.x, prev.y));
  17465. this._points.push(new cc.Vec2(current.x, current.y));
  17466. this._points.push(new cc.Vec2(prev.control1_x, prev.control1_y));
  17467. }
  17468. else if (prev.curveType == fgui.CurveType.CubicBezier) {
  17469. seg.ptCount = 4;
  17470. this._points.push(new cc.Vec2(prev.x, prev.y));
  17471. this._points.push(new cc.Vec2(current.x, current.y));
  17472. this._points.push(new cc.Vec2(prev.control1_x, prev.control1_y));
  17473. this._points.push(new cc.Vec2(prev.control2_x, prev.control2_y));
  17474. }
  17475. seg.length = fgui.ToolSet.distance(prev.x, prev.y, current.x, current.y);
  17476. this._fullLength += seg.length;
  17477. this._segments.push(seg);
  17478. }
  17479. if (current.curveType != fgui.CurveType.CRSpline) {
  17480. if (splinePoints.length > 0) {
  17481. splinePoints.push(new cc.Vec2(current.x, current.y));
  17482. this.createSplineSegment();
  17483. }
  17484. }
  17485. else
  17486. splinePoints.push(new cc.Vec2(current.x, current.y));
  17487. prev = current;
  17488. }
  17489. if (splinePoints.length > 1)
  17490. this.createSplineSegment();
  17491. };
  17492. GPath.prototype.createSplineSegment = function () {
  17493. var splinePoints = s_points;
  17494. var cnt = splinePoints.length;
  17495. splinePoints.splice(0, 0, splinePoints[0]);
  17496. splinePoints.push(splinePoints[cnt]);
  17497. splinePoints.push(splinePoints[cnt]);
  17498. cnt += 3;
  17499. var seg = {};
  17500. seg.type = fgui.CurveType.CRSpline;
  17501. seg.ptStart = this._points.length;
  17502. seg.ptCount = cnt;
  17503. this._points = this._points.concat(splinePoints);
  17504. seg.length = 0;
  17505. for (var i = 1; i < cnt; i++) {
  17506. seg.length += fgui.ToolSet.distance(splinePoints[i - 1].x, splinePoints[i - 1].y, splinePoints[i].x, splinePoints[i].y);
  17507. }
  17508. this._fullLength += seg.length;
  17509. this._segments.push(seg);
  17510. splinePoints.length = 0;
  17511. };
  17512. GPath.prototype.clear = function () {
  17513. this._segments.length = 0;
  17514. this._points.length = 0;
  17515. };
  17516. GPath.prototype.getPointAt = function (t, result) {
  17517. if (!result)
  17518. result = new cc.Vec2();
  17519. else
  17520. result.x = result.y = 0;
  17521. t = fgui.ToolSet.clamp01(t);
  17522. var cnt = this._segments.length;
  17523. if (cnt == 0) {
  17524. return result;
  17525. }
  17526. var seg;
  17527. if (t == 1) {
  17528. seg = this._segments[cnt - 1];
  17529. if (seg.type == fgui.CurveType.Straight) {
  17530. result.x = fgui.ToolSet.lerp(this._points[seg.ptStart].x, this._points[seg.ptStart + 1].x, t);
  17531. result.y = fgui.ToolSet.lerp(this._points[seg.ptStart].y, this._points[seg.ptStart + 1].y, t);
  17532. return result;
  17533. }
  17534. else if (seg.type == fgui.CurveType.Bezier || seg.type == fgui.CurveType.CubicBezier)
  17535. return this.onBezierCurve(seg.ptStart, seg.ptCount, t, result);
  17536. else
  17537. return this.onCRSplineCurve(seg.ptStart, seg.ptCount, t, result);
  17538. }
  17539. var len = t * this._fullLength;
  17540. for (var i = 0; i < cnt; i++) {
  17541. seg = this._segments[i];
  17542. len -= seg.length;
  17543. if (len < 0) {
  17544. t = 1 + len / seg.length;
  17545. if (seg.type == fgui.CurveType.Straight) {
  17546. result.x = fgui.ToolSet.lerp(this._points[seg.ptStart].x, this._points[seg.ptStart + 1].x, t);
  17547. result.y = fgui.ToolSet.lerp(this._points[seg.ptStart].y, this._points[seg.ptStart + 1].y, t);
  17548. }
  17549. else if (seg.type == fgui.CurveType.Bezier || seg.type == fgui.CurveType.CubicBezier)
  17550. result = this.onBezierCurve(seg.ptStart, seg.ptCount, t, result);
  17551. else
  17552. result = this.onCRSplineCurve(seg.ptStart, seg.ptCount, t, result);
  17553. break;
  17554. }
  17555. }
  17556. return result;
  17557. };
  17558. Object.defineProperty(GPath.prototype, "segmentCount", {
  17559. get: function () {
  17560. return this._segments.length;
  17561. },
  17562. enumerable: false,
  17563. configurable: true
  17564. });
  17565. GPath.prototype.getAnchorsInSegment = function (segmentIndex, points) {
  17566. if (points == null)
  17567. points = new Array();
  17568. var seg = this._segments[segmentIndex];
  17569. for (var i = 0; i < seg.ptCount; i++)
  17570. points.push(new cc.Vec2(this._points[seg.ptStart + i].x, this._points[seg.ptStart + i].y));
  17571. return points;
  17572. };
  17573. GPath.prototype.getPointsInSegment = function (segmentIndex, t0, t1, points, ts, pointDensity) {
  17574. if (points == null)
  17575. points = new Array();
  17576. if (!pointDensity || isNaN(pointDensity))
  17577. pointDensity = 0.1;
  17578. if (ts)
  17579. ts.push(t0);
  17580. var seg = this._segments[segmentIndex];
  17581. if (seg.type == fgui.CurveType.Straight) {
  17582. 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)));
  17583. 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)));
  17584. }
  17585. else {
  17586. var func;
  17587. if (seg.type == fgui.CurveType.Bezier || seg.type == fgui.CurveType.CubicBezier)
  17588. func = this.onBezierCurve;
  17589. else
  17590. func = this.onCRSplineCurve;
  17591. points.push(func.call(this, seg.ptStart, seg.ptCount, t0, new cc.Vec2()));
  17592. var SmoothAmount = Math.min(seg.length * pointDensity, 50);
  17593. for (var j = 0; j <= SmoothAmount; j++) {
  17594. var t = j / SmoothAmount;
  17595. if (t > t0 && t < t1) {
  17596. points.push(func.call(this, seg.ptStart, seg.ptCount, t, new cc.Vec2()));
  17597. if (ts != null)
  17598. ts.push(t);
  17599. }
  17600. }
  17601. points.push(func.call(this, seg.ptStart, seg.ptCount, t1, new cc.Vec2()));
  17602. }
  17603. if (ts != null)
  17604. ts.push(t1);
  17605. return points;
  17606. };
  17607. GPath.prototype.getAllPoints = function (points, ts, pointDensity) {
  17608. if (points == null)
  17609. points = new Array();
  17610. if (!pointDensity || isNaN(pointDensity))
  17611. pointDensity = 0.1;
  17612. var cnt = this._segments.length;
  17613. for (var i = 0; i < cnt; i++)
  17614. this.getPointsInSegment(i, 0, 1, points, ts, pointDensity);
  17615. return points;
  17616. };
  17617. GPath.prototype.onCRSplineCurve = function (ptStart, ptCount, t, result) {
  17618. var adjustedIndex = Math.floor(t * (ptCount - 4)) + ptStart;
  17619. var p0x = this._points[adjustedIndex].x;
  17620. var p0y = this._points[adjustedIndex].y;
  17621. var p1x = this._points[adjustedIndex + 1].x;
  17622. var p1y = this._points[adjustedIndex + 1].y;
  17623. var p2x = this._points[adjustedIndex + 2].x;
  17624. var p2y = this._points[adjustedIndex + 2].y;
  17625. var p3x = this._points[adjustedIndex + 3].x;
  17626. var p3y = this._points[adjustedIndex + 3].y;
  17627. var adjustedT = (t == 1) ? 1 : fgui.ToolSet.repeat(t * (ptCount - 4), 1);
  17628. var t0 = ((-adjustedT + 2) * adjustedT - 1) * adjustedT * 0.5;
  17629. var t1 = (((3 * adjustedT - 5) * adjustedT) * adjustedT + 2) * 0.5;
  17630. var t2 = ((-3 * adjustedT + 4) * adjustedT + 1) * adjustedT * 0.5;
  17631. var t3 = ((adjustedT - 1) * adjustedT * adjustedT) * 0.5;
  17632. result.x = p0x * t0 + p1x * t1 + p2x * t2 + p3x * t3;
  17633. result.y = p0y * t0 + p1y * t1 + p2y * t2 + p3y * t3;
  17634. return result;
  17635. };
  17636. GPath.prototype.onBezierCurve = function (ptStart, ptCount, t, result) {
  17637. var t2 = 1 - t;
  17638. var p0x = this._points[ptStart].x;
  17639. var p0y = this._points[ptStart].y;
  17640. var p1x = this._points[ptStart + 1].x;
  17641. var p1y = this._points[ptStart + 1].y;
  17642. var cp0x = this._points[ptStart + 2].x;
  17643. var cp0y = this._points[ptStart + 2].y;
  17644. if (ptCount == 4) {
  17645. var cp1x = this._points[ptStart + 3].x;
  17646. var cp1y = this._points[ptStart + 3].y;
  17647. result.x = t2 * t2 * t2 * p0x + 3 * t2 * t2 * t * cp0x + 3 * t2 * t * t * cp1x + t * t * t * p1x;
  17648. result.y = t2 * t2 * t2 * p0y + 3 * t2 * t2 * t * cp0y + 3 * t2 * t * t * cp1y + t * t * t * p1y;
  17649. }
  17650. else {
  17651. result.x = t2 * t2 * p0x + 2 * t2 * t * cp0x + t * t * p1x;
  17652. result.y = t2 * t2 * p0y + 2 * t2 * t * cp0y + t * t * p1y;
  17653. }
  17654. return result;
  17655. };
  17656. return GPath;
  17657. }());
  17658. fgui.GPath = GPath;
  17659. var s_points = new Array();
  17660. })(fgui || (fgui = {}));
  17661. (function (fgui) {
  17662. var CurveType;
  17663. (function (CurveType) {
  17664. CurveType[CurveType["CRSpline"] = 0] = "CRSpline";
  17665. CurveType[CurveType["Bezier"] = 1] = "Bezier";
  17666. CurveType[CurveType["CubicBezier"] = 2] = "CubicBezier";
  17667. CurveType[CurveType["Straight"] = 3] = "Straight";
  17668. })(CurveType = fgui.CurveType || (fgui.CurveType = {}));
  17669. var GPathPoint = (function () {
  17670. function GPathPoint() {
  17671. this.x = 0;
  17672. this.y = 0;
  17673. this.control1_x = 0;
  17674. this.control1_y = 0;
  17675. this.control2_x = 0;
  17676. this.control2_y = 0;
  17677. this.curveType = 0;
  17678. }
  17679. GPathPoint.newPoint = function (x, y, curveType) {
  17680. if (x === void 0) { x = 0; }
  17681. if (y === void 0) { y = 0; }
  17682. if (curveType === void 0) { curveType = 0; }
  17683. var pt = new GPathPoint();
  17684. pt.x = x;
  17685. pt.y = y;
  17686. pt.control1_x = 0;
  17687. pt.control1_y = 0;
  17688. pt.control2_x = 0;
  17689. pt.control2_y = 0;
  17690. pt.curveType = curveType;
  17691. return pt;
  17692. };
  17693. GPathPoint.newBezierPoint = function (x, y, control1_x, control1_y) {
  17694. if (x === void 0) { x = 0; }
  17695. if (y === void 0) { y = 0; }
  17696. if (control1_x === void 0) { control1_x = 0; }
  17697. if (control1_y === void 0) { control1_y = 0; }
  17698. var pt = new GPathPoint();
  17699. pt.x = x;
  17700. pt.y = y;
  17701. pt.control1_x = control1_x;
  17702. pt.control1_y = control1_y;
  17703. pt.control2_x = 0;
  17704. pt.control2_y = 0;
  17705. pt.curveType = CurveType.Bezier;
  17706. return pt;
  17707. };
  17708. GPathPoint.newCubicBezierPoint = function (x, y, control1_x, control1_y, control2_x, control2_y) {
  17709. if (x === void 0) { x = 0; }
  17710. if (y === void 0) { y = 0; }
  17711. if (control1_x === void 0) { control1_x = 0; }
  17712. if (control1_y === void 0) { control1_y = 0; }
  17713. if (control2_x === void 0) { control2_x = 0; }
  17714. if (control2_y === void 0) { control2_y = 0; }
  17715. var pt = new GPathPoint();
  17716. pt.x = x;
  17717. pt.y = y;
  17718. pt.control1_x = control1_x;
  17719. pt.control1_y = control1_y;
  17720. pt.control2_x = control2_x;
  17721. pt.control2_y = control2_y;
  17722. pt.curveType = CurveType.CubicBezier;
  17723. return pt;
  17724. };
  17725. GPathPoint.prototype.clone = function () {
  17726. var ret = new GPathPoint();
  17727. ret.x = this.x;
  17728. ret.y = this.y;
  17729. ret.control1_x = this.control1_x;
  17730. ret.control1_y = this.control1_y;
  17731. ret.control2_x = this.control2_x;
  17732. ret.control2_y = this.control2_y;
  17733. ret.curveType = this.curveType;
  17734. return ret;
  17735. };
  17736. return GPathPoint;
  17737. }());
  17738. fgui.GPathPoint = GPathPoint;
  17739. })(fgui || (fgui = {}));
  17740. (function (fgui) {
  17741. var GTween = (function () {
  17742. function GTween() {
  17743. }
  17744. GTween.to = function (start, end, duration) {
  17745. return fgui.TweenManager.createTween()._to(start, end, duration);
  17746. };
  17747. GTween.to2 = function (start, start2, end, end2, duration) {
  17748. return fgui.TweenManager.createTween()._to2(start, start2, end, end2, duration);
  17749. };
  17750. GTween.to3 = function (start, start2, start3, end, end2, end3, duration) {
  17751. return fgui.TweenManager.createTween()._to3(start, start2, start3, end, end2, end3, duration);
  17752. };
  17753. GTween.to4 = function (start, start2, start3, start4, end, end2, end3, end4, duration) {
  17754. return fgui.TweenManager.createTween()._to4(start, start2, start3, start4, end, end2, end3, end4, duration);
  17755. };
  17756. GTween.toColor = function (start, end, duration) {
  17757. return fgui.TweenManager.createTween()._toColor(start, end, duration);
  17758. };
  17759. GTween.delayedCall = function (delay) {
  17760. return fgui.TweenManager.createTween().setDelay(delay);
  17761. };
  17762. GTween.shake = function (startX, startY, amplitude, duration) {
  17763. return fgui.TweenManager.createTween()._shake(startX, startY, amplitude, duration);
  17764. };
  17765. GTween.isTweening = function (target, propType) {
  17766. return fgui.TweenManager.isTweening(target, propType);
  17767. };
  17768. GTween.kill = function (target, complete, propType) {
  17769. fgui.TweenManager.killTweens(target, complete, propType);
  17770. };
  17771. GTween.getTween = function (target, propType) {
  17772. return fgui.TweenManager.getTween(target, propType);
  17773. };
  17774. GTween.catchCallbackExceptions = true;
  17775. return GTween;
  17776. }());
  17777. fgui.GTween = GTween;
  17778. })(fgui || (fgui = {}));
  17779. (function (fgui) {
  17780. var GTweener = (function () {
  17781. function GTweener() {
  17782. this._startValue = new fgui.TweenValue();
  17783. this._endValue = new fgui.TweenValue();
  17784. this._value = new fgui.TweenValue();
  17785. this._deltaValue = new fgui.TweenValue();
  17786. this._reset();
  17787. }
  17788. GTweener.prototype.setDelay = function (value) {
  17789. this._delay = value;
  17790. return this;
  17791. };
  17792. Object.defineProperty(GTweener.prototype, "delay", {
  17793. get: function () {
  17794. return this._delay;
  17795. },
  17796. enumerable: false,
  17797. configurable: true
  17798. });
  17799. GTweener.prototype.setDuration = function (value) {
  17800. this._duration = value;
  17801. return this;
  17802. };
  17803. Object.defineProperty(GTweener.prototype, "duration", {
  17804. get: function () {
  17805. return this._duration;
  17806. },
  17807. enumerable: false,
  17808. configurable: true
  17809. });
  17810. GTweener.prototype.setBreakpoint = function (value) {
  17811. this._breakpoint = value;
  17812. return this;
  17813. };
  17814. GTweener.prototype.setEase = function (value) {
  17815. this._easeType = value;
  17816. return this;
  17817. };
  17818. GTweener.prototype.setEasePeriod = function (value) {
  17819. this._easePeriod = value;
  17820. return this;
  17821. };
  17822. GTweener.prototype.setEaseOvershootOrAmplitude = function (value) {
  17823. this._easeOvershootOrAmplitude = value;
  17824. return this;
  17825. };
  17826. GTweener.prototype.setRepeat = function (repeat, yoyo) {
  17827. this._repeat = repeat;
  17828. this._yoyo = yoyo;
  17829. return this;
  17830. };
  17831. Object.defineProperty(GTweener.prototype, "repeat", {
  17832. get: function () {
  17833. return this._repeat;
  17834. },
  17835. enumerable: false,
  17836. configurable: true
  17837. });
  17838. GTweener.prototype.setTimeScale = function (value) {
  17839. this._timeScale = value;
  17840. return this;
  17841. };
  17842. GTweener.prototype.setSnapping = function (value) {
  17843. this._snapping = value;
  17844. return this;
  17845. };
  17846. GTweener.prototype.setTarget = function (value, propType) {
  17847. this._target = value;
  17848. this._propType = propType;
  17849. if (value instanceof fgui.GObject)
  17850. this._node = value.node;
  17851. else if (value instanceof cc.Node)
  17852. this._node = value;
  17853. return this;
  17854. };
  17855. Object.defineProperty(GTweener.prototype, "target", {
  17856. get: function () {
  17857. return this._target;
  17858. },
  17859. enumerable: false,
  17860. configurable: true
  17861. });
  17862. GTweener.prototype.setPath = function (value) {
  17863. this._path = value;
  17864. return this;
  17865. };
  17866. GTweener.prototype.setUserData = function (value) {
  17867. this._userData = value;
  17868. return this;
  17869. };
  17870. Object.defineProperty(GTweener.prototype, "userData", {
  17871. get: function () {
  17872. return this._userData;
  17873. },
  17874. enumerable: false,
  17875. configurable: true
  17876. });
  17877. GTweener.prototype.onUpdate = function (callback, target) {
  17878. this._onUpdate = callback;
  17879. this._onUpdateCaller = target;
  17880. return this;
  17881. };
  17882. GTweener.prototype.onStart = function (callback, target) {
  17883. this._onStart = callback;
  17884. this._onStartCaller = target;
  17885. return this;
  17886. };
  17887. GTweener.prototype.onComplete = function (callback, target) {
  17888. this._onComplete = callback;
  17889. this._onCompleteCaller = target;
  17890. return this;
  17891. };
  17892. Object.defineProperty(GTweener.prototype, "startValue", {
  17893. get: function () {
  17894. return this._startValue;
  17895. },
  17896. enumerable: false,
  17897. configurable: true
  17898. });
  17899. Object.defineProperty(GTweener.prototype, "endValue", {
  17900. get: function () {
  17901. return this._endValue;
  17902. },
  17903. enumerable: false,
  17904. configurable: true
  17905. });
  17906. Object.defineProperty(GTweener.prototype, "value", {
  17907. get: function () {
  17908. return this._value;
  17909. },
  17910. enumerable: false,
  17911. configurable: true
  17912. });
  17913. Object.defineProperty(GTweener.prototype, "deltaValue", {
  17914. get: function () {
  17915. return this._deltaValue;
  17916. },
  17917. enumerable: false,
  17918. configurable: true
  17919. });
  17920. Object.defineProperty(GTweener.prototype, "normalizedTime", {
  17921. get: function () {
  17922. return this._normalizedTime;
  17923. },
  17924. enumerable: false,
  17925. configurable: true
  17926. });
  17927. Object.defineProperty(GTweener.prototype, "completed", {
  17928. get: function () {
  17929. return this._ended != 0;
  17930. },
  17931. enumerable: false,
  17932. configurable: true
  17933. });
  17934. Object.defineProperty(GTweener.prototype, "allCompleted", {
  17935. get: function () {
  17936. return this._ended == 1;
  17937. },
  17938. enumerable: false,
  17939. configurable: true
  17940. });
  17941. GTweener.prototype.setPaused = function (paused) {
  17942. this._paused = paused;
  17943. return this;
  17944. };
  17945. GTweener.prototype.seek = function (time) {
  17946. if (this._killed)
  17947. return;
  17948. this._elapsedTime = time;
  17949. if (this._elapsedTime < this._delay) {
  17950. if (this._started)
  17951. this._elapsedTime = this._delay;
  17952. else
  17953. return;
  17954. }
  17955. this.update();
  17956. };
  17957. GTweener.prototype.kill = function (complete) {
  17958. if (this._killed)
  17959. return;
  17960. if (complete) {
  17961. if (this._ended == 0) {
  17962. if (this._breakpoint >= 0)
  17963. this._elapsedTime = this._delay + this._breakpoint;
  17964. else if (this._repeat >= 0)
  17965. this._elapsedTime = this._delay + this._duration * (this._repeat + 1);
  17966. else
  17967. this._elapsedTime = this._delay + this._duration * 2;
  17968. this.update();
  17969. }
  17970. this.callCompleteCallback();
  17971. }
  17972. this._killed = true;
  17973. };
  17974. GTweener.prototype._to = function (start, end, duration) {
  17975. this._valueSize = 1;
  17976. this._startValue.x = start;
  17977. this._endValue.x = end;
  17978. this._duration = duration;
  17979. return this;
  17980. };
  17981. GTweener.prototype._to2 = function (start, start2, end, end2, duration) {
  17982. this._valueSize = 2;
  17983. this._startValue.x = start;
  17984. this._endValue.x = end;
  17985. this._startValue.y = start2;
  17986. this._endValue.y = end2;
  17987. this._duration = duration;
  17988. return this;
  17989. };
  17990. GTweener.prototype._to3 = function (start, start2, start3, end, end2, end3, duration) {
  17991. this._valueSize = 3;
  17992. this._startValue.x = start;
  17993. this._endValue.x = end;
  17994. this._startValue.y = start2;
  17995. this._endValue.y = end2;
  17996. this._startValue.z = start3;
  17997. this._endValue.z = end3;
  17998. this._duration = duration;
  17999. return this;
  18000. };
  18001. GTweener.prototype._to4 = function (start, start2, start3, start4, end, end2, end3, end4, duration) {
  18002. this._valueSize = 4;
  18003. this._startValue.x = start;
  18004. this._endValue.x = end;
  18005. this._startValue.y = start2;
  18006. this._endValue.y = end2;
  18007. this._startValue.z = start3;
  18008. this._endValue.z = end3;
  18009. this._startValue.w = start4;
  18010. this._endValue.w = end4;
  18011. this._duration = duration;
  18012. return this;
  18013. };
  18014. GTweener.prototype._toColor = function (start, end, duration) {
  18015. this._valueSize = 4;
  18016. this._startValue.color = start;
  18017. this._endValue.color = end;
  18018. this._duration = duration;
  18019. return this;
  18020. };
  18021. GTweener.prototype._shake = function (startX, startY, amplitude, duration) {
  18022. this._valueSize = 5;
  18023. this._startValue.x = startX;
  18024. this._startValue.y = startY;
  18025. this._startValue.w = amplitude;
  18026. this._duration = duration;
  18027. return this;
  18028. };
  18029. GTweener.prototype._init = function () {
  18030. this._delay = 0;
  18031. this._duration = 0;
  18032. this._breakpoint = -1;
  18033. this._easeType = fgui.EaseType.QuadOut;
  18034. this._timeScale = 1;
  18035. this._easePeriod = 0;
  18036. this._easeOvershootOrAmplitude = 1.70158;
  18037. this._snapping = false;
  18038. this._repeat = 0;
  18039. this._yoyo = false;
  18040. this._valueSize = 0;
  18041. this._started = false;
  18042. this._paused = false;
  18043. this._killed = false;
  18044. this._elapsedTime = 0;
  18045. this._normalizedTime = 0;
  18046. this._ended = 0;
  18047. };
  18048. GTweener.prototype._reset = function () {
  18049. this._target = null;
  18050. this._propType = null;
  18051. this._userData = null;
  18052. this._node = null;
  18053. this._path = null;
  18054. this._onStart = this._onUpdate = this._onComplete = null;
  18055. this._onStartCaller = this._onUpdateCaller = this._onCompleteCaller = null;
  18056. };
  18057. GTweener.prototype._update = function (dt) {
  18058. if (this._node && !cc.isValid(this._node)) {
  18059. this._killed = true;
  18060. return;
  18061. }
  18062. if (this._timeScale != 1)
  18063. dt *= this._timeScale;
  18064. if (dt == 0)
  18065. return;
  18066. if (this._ended != 0) {
  18067. this.callCompleteCallback();
  18068. this._killed = true;
  18069. return;
  18070. }
  18071. this._elapsedTime += dt;
  18072. this.update();
  18073. if (this._ended != 0) {
  18074. if (!this._killed) {
  18075. this.callCompleteCallback();
  18076. this._killed = true;
  18077. }
  18078. }
  18079. };
  18080. GTweener.prototype.update = function () {
  18081. this._ended = 0;
  18082. if (this._valueSize == 0) {
  18083. if (this._elapsedTime >= this._delay + this._duration)
  18084. this._ended = 1;
  18085. return;
  18086. }
  18087. if (!this._started) {
  18088. if (this._elapsedTime < this._delay)
  18089. return;
  18090. this._started = true;
  18091. this.callStartCallback();
  18092. if (this._killed)
  18093. return;
  18094. }
  18095. var reversed = false;
  18096. var tt = this._elapsedTime - this._delay;
  18097. if (this._breakpoint >= 0 && tt >= this._breakpoint) {
  18098. tt = this._breakpoint;
  18099. this._ended = 2;
  18100. }
  18101. if (this._repeat != 0) {
  18102. var round = Math.floor(tt / this._duration);
  18103. tt -= this._duration * round;
  18104. if (this._yoyo)
  18105. reversed = round % 2 == 1;
  18106. if (this._repeat > 0 && this._repeat - round < 0) {
  18107. if (this._yoyo)
  18108. reversed = this._repeat % 2 == 1;
  18109. tt = this._duration;
  18110. this._ended = 1;
  18111. }
  18112. }
  18113. else if (tt >= this._duration) {
  18114. tt = this._duration;
  18115. this._ended = 1;
  18116. }
  18117. this._normalizedTime = fgui.evaluateEase(this._easeType, reversed ? (this._duration - tt) : tt, this._duration, this._easeOvershootOrAmplitude, this._easePeriod);
  18118. this._value.setZero();
  18119. this._deltaValue.setZero();
  18120. if (this._valueSize == 5) {
  18121. if (this._ended == 0) {
  18122. var r = this._startValue.w * (1 - this._normalizedTime);
  18123. var rx = r * (Math.random() > 0.5 ? 1 : -1);
  18124. var ry = r * (Math.random() > 0.5 ? 1 : -1);
  18125. this._deltaValue.x = rx;
  18126. this._deltaValue.y = ry;
  18127. this._value.x = this._startValue.x + rx;
  18128. this._value.y = this._startValue.y + ry;
  18129. }
  18130. else {
  18131. this._value.x = this._startValue.x;
  18132. this._value.y = this._startValue.y;
  18133. }
  18134. }
  18135. else if (this._path) {
  18136. var pt = s_vec2;
  18137. this._path.getPointAt(this._normalizedTime, pt);
  18138. if (this._snapping) {
  18139. pt.x = Math.round(pt.x);
  18140. pt.y = Math.round(pt.y);
  18141. }
  18142. this._deltaValue.x = pt.x - this._value.x;
  18143. this._deltaValue.y = pt.y - this._value.y;
  18144. this._value.x = pt.x;
  18145. this._value.y = pt.y;
  18146. }
  18147. else {
  18148. for (var i = 0; i < this._valueSize; i++) {
  18149. var n1 = this._startValue.getField(i);
  18150. var n2 = this._endValue.getField(i);
  18151. var f = n1 + (n2 - n1) * this._normalizedTime;
  18152. if (this._snapping)
  18153. f = Math.round(f);
  18154. this._deltaValue.setField(i, f - this._value.getField(i));
  18155. this._value.setField(i, f);
  18156. }
  18157. }
  18158. if (this._target != null && this._propType != null) {
  18159. if (this._propType instanceof Function) {
  18160. switch (this._valueSize) {
  18161. case 1:
  18162. this._propType.call(this._target, this._value.x);
  18163. break;
  18164. case 2:
  18165. this._propType.call(this._target, this._value.x, this._value.y);
  18166. break;
  18167. case 3:
  18168. this._propType.call(this._target, this._value.x, this._value.y, this._value.z);
  18169. break;
  18170. case 4:
  18171. this._propType.call(this._target, this._value.x, this._value.y, this._value.z, this._value.w);
  18172. break;
  18173. case 5:
  18174. this._propType.call(this._target, this._value.color);
  18175. break;
  18176. case 6:
  18177. this._propType.call(this._target, this._value.x, this._value.y);
  18178. break;
  18179. }
  18180. }
  18181. else {
  18182. if (this._valueSize == 5)
  18183. this._target[this._propType] = this._value.color;
  18184. else
  18185. this._target[this._propType] = this._value.x;
  18186. }
  18187. }
  18188. this.callUpdateCallback();
  18189. };
  18190. GTweener.prototype.callStartCallback = function () {
  18191. if (this._onStart != null) {
  18192. try {
  18193. this._onStart.call(this._onStartCaller, this);
  18194. }
  18195. catch (err) {
  18196. console.log("FairyGUI: error in start callback > " + err);
  18197. }
  18198. }
  18199. };
  18200. GTweener.prototype.callUpdateCallback = function () {
  18201. if (this._onUpdate != null) {
  18202. try {
  18203. this._onUpdate.call(this._onUpdateCaller, this);
  18204. }
  18205. catch (err) {
  18206. console.log("FairyGUI: error in update callback > " + err);
  18207. }
  18208. }
  18209. };
  18210. GTweener.prototype.callCompleteCallback = function () {
  18211. if (this._onComplete != null) {
  18212. try {
  18213. this._onComplete.call(this._onCompleteCaller, this);
  18214. }
  18215. catch (err) {
  18216. console.log("FairyGUI: error in complete callback > " + err);
  18217. }
  18218. }
  18219. };
  18220. return GTweener;
  18221. }());
  18222. fgui.GTweener = GTweener;
  18223. var s_vec2 = new cc.Vec2();
  18224. })(fgui || (fgui = {}));
  18225. (function (fgui) {
  18226. var _activeTweens = new Array(30);
  18227. var _tweenerPool = new Array();
  18228. var _totalActiveTweens = 0;
  18229. var _root;
  18230. var TweenManager = (function () {
  18231. function TweenManager() {
  18232. }
  18233. TweenManager.createTween = function () {
  18234. if (!_root) {
  18235. _root = new cc.Node("[TweenManager]");
  18236. cc.game["addPersistRootNode"](_root);
  18237. cc.director.getScheduler().schedule(TweenManager.update, _root, 0, false);
  18238. }
  18239. var tweener;
  18240. var cnt = _tweenerPool.length;
  18241. if (cnt > 0) {
  18242. tweener = _tweenerPool.pop();
  18243. }
  18244. else
  18245. tweener = new fgui.GTweener();
  18246. tweener._init();
  18247. _activeTweens[_totalActiveTweens++] = tweener;
  18248. if (_totalActiveTweens == _activeTweens.length)
  18249. _activeTweens.length = _activeTweens.length + Math.ceil(_activeTweens.length * 0.5);
  18250. return tweener;
  18251. };
  18252. TweenManager.isTweening = function (target, propType) {
  18253. if (target == null)
  18254. return false;
  18255. var anyType = propType == null || propType == undefined;
  18256. for (var i = 0; i < _totalActiveTweens; i++) {
  18257. var tweener = _activeTweens[i];
  18258. if (tweener && tweener.target == target && !tweener._killed
  18259. && (anyType || tweener._propType == propType))
  18260. return true;
  18261. }
  18262. return false;
  18263. };
  18264. TweenManager.killTweens = function (target, completed, propType) {
  18265. if (target == null)
  18266. return false;
  18267. var flag = false;
  18268. var cnt = _totalActiveTweens;
  18269. var anyType = propType == null || propType == undefined;
  18270. for (var i = 0; i < cnt; i++) {
  18271. var tweener = _activeTweens[i];
  18272. if (tweener && tweener.target == target && !tweener._killed
  18273. && (anyType || tweener._propType == propType)) {
  18274. tweener.kill(completed);
  18275. flag = true;
  18276. }
  18277. }
  18278. return flag;
  18279. };
  18280. TweenManager.getTween = function (target, propType) {
  18281. if (target == null)
  18282. return null;
  18283. var cnt = _totalActiveTweens;
  18284. var anyType = propType == null || propType == undefined;
  18285. for (var i = 0; i < cnt; i++) {
  18286. var tweener = _activeTweens[i];
  18287. if (tweener && tweener.target == target && !tweener._killed
  18288. && (anyType || tweener._propType == propType)) {
  18289. return tweener;
  18290. }
  18291. }
  18292. return null;
  18293. };
  18294. TweenManager.update = function (dt) {
  18295. var tweens = _activeTweens;
  18296. var cnt = _totalActiveTweens;
  18297. var freePosStart = -1;
  18298. for (var i = 0; i < cnt; i++) {
  18299. var tweener = tweens[i];
  18300. if (tweener == null) {
  18301. if (freePosStart == -1)
  18302. freePosStart = i;
  18303. }
  18304. else if (tweener._killed) {
  18305. tweener._reset();
  18306. _tweenerPool.push(tweener);
  18307. tweens[i] = null;
  18308. if (freePosStart == -1)
  18309. freePosStart = i;
  18310. }
  18311. else {
  18312. if (!tweener._paused)
  18313. tweener._update(dt);
  18314. if (freePosStart != -1) {
  18315. tweens[freePosStart] = tweener;
  18316. tweens[i] = null;
  18317. freePosStart++;
  18318. }
  18319. }
  18320. }
  18321. if (freePosStart >= 0) {
  18322. if (_totalActiveTweens != cnt) {
  18323. var j = cnt;
  18324. cnt = _totalActiveTweens - cnt;
  18325. for (i = 0; i < cnt; i++)
  18326. tweens[freePosStart++] = tweens[j++];
  18327. }
  18328. _totalActiveTweens = freePosStart;
  18329. }
  18330. return false;
  18331. };
  18332. return TweenManager;
  18333. }());
  18334. fgui.TweenManager = TweenManager;
  18335. })(fgui || (fgui = {}));
  18336. (function (fgui) {
  18337. var TweenValue = (function () {
  18338. function TweenValue() {
  18339. this.x = this.y = this.z = this.w = 0;
  18340. }
  18341. Object.defineProperty(TweenValue.prototype, "color", {
  18342. get: function () {
  18343. return (this.w << 24) + (this.x << 16) + (this.y << 8) + this.z;
  18344. },
  18345. set: function (value) {
  18346. this.x = (value & 0xFF0000) >> 16;
  18347. this.y = (value & 0x00FF00) >> 8;
  18348. this.z = (value & 0x0000FF);
  18349. this.w = (value & 0xFF000000) >> 24;
  18350. },
  18351. enumerable: false,
  18352. configurable: true
  18353. });
  18354. TweenValue.prototype.getField = function (index) {
  18355. switch (index) {
  18356. case 0:
  18357. return this.x;
  18358. case 1:
  18359. return this.y;
  18360. case 2:
  18361. return this.z;
  18362. case 3:
  18363. return this.w;
  18364. default:
  18365. throw new Error("Index out of bounds: " + index);
  18366. }
  18367. };
  18368. TweenValue.prototype.setField = function (index, value) {
  18369. switch (index) {
  18370. case 0:
  18371. this.x = value;
  18372. break;
  18373. case 1:
  18374. this.y = value;
  18375. break;
  18376. case 2:
  18377. this.z = value;
  18378. break;
  18379. case 3:
  18380. this.w = value;
  18381. break;
  18382. default:
  18383. throw new Error("Index out of bounds: " + index);
  18384. }
  18385. };
  18386. TweenValue.prototype.setZero = function () {
  18387. this.x = this.y = this.z = this.w = 0;
  18388. };
  18389. return TweenValue;
  18390. }());
  18391. fgui.TweenValue = TweenValue;
  18392. })(fgui || (fgui = {}));
  18393. (function (fgui) {
  18394. var ByteBuffer = (function () {
  18395. function ByteBuffer(buffer, offset, length) {
  18396. if (offset === void 0) { offset = 0; }
  18397. if (length === void 0) { length = -1; }
  18398. this.version = 0;
  18399. if (length == -1)
  18400. length = buffer.byteLength - offset;
  18401. this._bytes = new Uint8Array(buffer, offset, length);
  18402. this._view = new DataView(this._bytes.buffer, offset, length);
  18403. this._pos = 0;
  18404. this._length = length;
  18405. }
  18406. Object.defineProperty(ByteBuffer.prototype, "data", {
  18407. get: function () {
  18408. return this._bytes;
  18409. },
  18410. enumerable: false,
  18411. configurable: true
  18412. });
  18413. Object.defineProperty(ByteBuffer.prototype, "position", {
  18414. get: function () {
  18415. return this._pos;
  18416. },
  18417. set: function (value) {
  18418. if (value > this._length)
  18419. throw "Out of bounds";
  18420. this._pos = value;
  18421. },
  18422. enumerable: false,
  18423. configurable: true
  18424. });
  18425. ByteBuffer.prototype.skip = function (count) {
  18426. this._pos += count;
  18427. };
  18428. ByteBuffer.prototype.validate = function (forward) {
  18429. if (this._pos + forward > this._length)
  18430. throw "Out of bounds";
  18431. };
  18432. ByteBuffer.prototype.readByte = function () {
  18433. this.validate(1);
  18434. return this._view.getInt8(this._pos++);
  18435. };
  18436. ByteBuffer.prototype.readUbyte = function () {
  18437. return this._bytes[this._pos++];
  18438. };
  18439. ByteBuffer.prototype.readBool = function () {
  18440. return this.readByte() == 1;
  18441. };
  18442. ByteBuffer.prototype.readShort = function () {
  18443. this.validate(2);
  18444. var ret = this._view.getInt16(this._pos, this.littleEndian);
  18445. this._pos += 2;
  18446. return ret;
  18447. };
  18448. ByteBuffer.prototype.readUshort = function () {
  18449. this.validate(2);
  18450. var ret = this._view.getUint16(this._pos, this.littleEndian);
  18451. this._pos += 2;
  18452. return ret;
  18453. };
  18454. ByteBuffer.prototype.readInt = function () {
  18455. this.validate(4);
  18456. var ret = this._view.getInt32(this._pos, this.littleEndian);
  18457. this._pos += 4;
  18458. return ret;
  18459. };
  18460. ByteBuffer.prototype.readUint = function () {
  18461. this.validate(4);
  18462. var ret = this._view.getUint32(this._pos, this.littleEndian);
  18463. this._pos += 4;
  18464. return ret;
  18465. };
  18466. ByteBuffer.prototype.readFloat = function () {
  18467. this.validate(4);
  18468. var ret = this._view.getFloat32(this._pos, this.littleEndian);
  18469. this._pos += 4;
  18470. return ret;
  18471. };
  18472. ByteBuffer.prototype.readString = function (len) {
  18473. if (len == undefined)
  18474. len = this.readUshort();
  18475. this.validate(len);
  18476. var v = "", max = this._pos + len, c = 0, c2 = 0, c3 = 0, f = String.fromCharCode;
  18477. var u = this._bytes, i = 0;
  18478. var pos = this._pos;
  18479. while (pos < max) {
  18480. c = u[pos++];
  18481. if (c < 0x80) {
  18482. if (c != 0) {
  18483. v += f(c);
  18484. }
  18485. }
  18486. else if (c < 0xE0) {
  18487. v += f(((c & 0x3F) << 6) | (u[pos++] & 0x7F));
  18488. }
  18489. else if (c < 0xF0) {
  18490. c2 = u[pos++];
  18491. v += f(((c & 0x1F) << 12) | ((c2 & 0x7F) << 6) | (u[pos++] & 0x7F));
  18492. }
  18493. else {
  18494. c2 = u[pos++];
  18495. c3 = u[pos++];
  18496. v += f(((c & 0x0F) << 18) | ((c2 & 0x7F) << 12) | ((c3 << 6) & 0x7F) | (u[pos++] & 0x7F));
  18497. }
  18498. i++;
  18499. }
  18500. this._pos += len;
  18501. return v;
  18502. };
  18503. ByteBuffer.prototype.readS = function () {
  18504. var index = this.readUshort();
  18505. if (index == 65534)
  18506. return null;
  18507. else if (index == 65533)
  18508. return "";
  18509. else
  18510. return this.stringTable[index];
  18511. };
  18512. ByteBuffer.prototype.readSArray = function (cnt) {
  18513. var ret = new Array(cnt);
  18514. for (var i = 0; i < cnt; i++)
  18515. ret[i] = this.readS();
  18516. return ret;
  18517. };
  18518. ByteBuffer.prototype.writeS = function (value) {
  18519. var index = this.readUshort();
  18520. if (index != 65534 && index != 65533)
  18521. this.stringTable[index] = value;
  18522. };
  18523. ByteBuffer.prototype.readColor = function (hasAlpha) {
  18524. var r = this.readUbyte();
  18525. var g = this.readUbyte();
  18526. var b = this.readUbyte();
  18527. var a = this.readUbyte();
  18528. return new cc.Color(r, g, b, (hasAlpha ? a : 255));
  18529. };
  18530. ByteBuffer.prototype.readChar = function () {
  18531. var i = this.readUshort();
  18532. return String.fromCharCode(i);
  18533. };
  18534. ByteBuffer.prototype.readBuffer = function () {
  18535. var count = this.readUint();
  18536. this.validate(count);
  18537. var ba = new ByteBuffer(this._bytes.buffer, this._bytes.byteOffset + this._pos, count);
  18538. ba.stringTable = this.stringTable;
  18539. ba.version = this.version;
  18540. this._pos += count;
  18541. return ba;
  18542. };
  18543. ByteBuffer.prototype.seek = function (indexTablePos, blockIndex) {
  18544. var tmp = this._pos;
  18545. this._pos = indexTablePos;
  18546. var segCount = this.readByte();
  18547. if (blockIndex < segCount) {
  18548. var useShort = this.readByte() == 1;
  18549. var newPos;
  18550. if (useShort) {
  18551. this._pos += 2 * blockIndex;
  18552. newPos = this.readUshort();
  18553. }
  18554. else {
  18555. this._pos += 4 * blockIndex;
  18556. newPos = this.readUint();
  18557. }
  18558. if (newPos > 0) {
  18559. this._pos = indexTablePos + newPos;
  18560. return true;
  18561. }
  18562. else {
  18563. this._pos = tmp;
  18564. return false;
  18565. }
  18566. }
  18567. else {
  18568. this._pos = tmp;
  18569. return false;
  18570. }
  18571. };
  18572. return ByteBuffer;
  18573. }());
  18574. fgui.ByteBuffer = ByteBuffer;
  18575. })(fgui || (fgui = {}));
  18576. (function (fgui) {
  18577. var ColorMatrix = (function () {
  18578. function ColorMatrix(p_brightness, p_contrast, p_saturation, p_hue) {
  18579. this.matrix = new Array(LENGTH);
  18580. this.reset();
  18581. if (p_brightness !== undefined || p_contrast !== undefined || p_saturation !== undefined || p_hue !== undefined)
  18582. this.adjustColor(p_brightness, p_contrast, p_saturation, p_hue);
  18583. }
  18584. ColorMatrix.prototype.reset = function () {
  18585. for (var i = 0; i < LENGTH; i++) {
  18586. this.matrix[i] = IDENTITY_MATRIX[i];
  18587. }
  18588. };
  18589. ColorMatrix.prototype.invert = function () {
  18590. this.multiplyMatrix([-1, 0, 0, 0, 255,
  18591. 0, -1, 0, 0, 255,
  18592. 0, 0, -1, 0, 255,
  18593. 0, 0, 0, 1, 0]);
  18594. };
  18595. ColorMatrix.prototype.adjustColor = function (p_brightness, p_contrast, p_saturation, p_hue) {
  18596. this.adjustHue(p_hue || 0);
  18597. this.adjustContrast(p_contrast || 0);
  18598. this.adjustBrightness(p_brightness || 0);
  18599. this.adjustSaturation(p_saturation || 0);
  18600. };
  18601. ColorMatrix.prototype.adjustBrightness = function (p_val) {
  18602. p_val = this.cleanValue(p_val, 1) * 255;
  18603. this.multiplyMatrix([
  18604. 1, 0, 0, 0, p_val,
  18605. 0, 1, 0, 0, p_val,
  18606. 0, 0, 1, 0, p_val,
  18607. 0, 0, 0, 1, 0
  18608. ]);
  18609. };
  18610. ColorMatrix.prototype.adjustContrast = function (p_val) {
  18611. p_val = this.cleanValue(p_val, 1);
  18612. var s = p_val + 1;
  18613. var o = 128 * (1 - s);
  18614. this.multiplyMatrix([
  18615. s, 0, 0, 0, o,
  18616. 0, s, 0, 0, o,
  18617. 0, 0, s, 0, o,
  18618. 0, 0, 0, 1, 0
  18619. ]);
  18620. };
  18621. ColorMatrix.prototype.adjustSaturation = function (p_val) {
  18622. p_val = this.cleanValue(p_val, 1);
  18623. p_val += 1;
  18624. var invSat = 1 - p_val;
  18625. var invLumR = invSat * LUMA_R;
  18626. var invLumG = invSat * LUMA_G;
  18627. var invLumB = invSat * LUMA_B;
  18628. this.multiplyMatrix([
  18629. (invLumR + p_val), invLumG, invLumB, 0, 0,
  18630. invLumR, (invLumG + p_val), invLumB, 0, 0,
  18631. invLumR, invLumG, (invLumB + p_val), 0, 0,
  18632. 0, 0, 0, 1, 0
  18633. ]);
  18634. };
  18635. ColorMatrix.prototype.adjustHue = function (p_val) {
  18636. p_val = this.cleanValue(p_val, 1);
  18637. p_val *= Math.PI;
  18638. var cos = Math.cos(p_val);
  18639. var sin = Math.sin(p_val);
  18640. this.multiplyMatrix([
  18641. ((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,
  18642. ((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,
  18643. ((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,
  18644. 0, 0, 0, 1, 0
  18645. ]);
  18646. };
  18647. ColorMatrix.prototype.concat = function (p_matrix) {
  18648. if (p_matrix.length != LENGTH) {
  18649. return;
  18650. }
  18651. this.multiplyMatrix(p_matrix);
  18652. };
  18653. ColorMatrix.prototype.clone = function () {
  18654. var result = new ColorMatrix();
  18655. result.copyMatrix(this.matrix);
  18656. return result;
  18657. };
  18658. ColorMatrix.prototype.copyMatrix = function (p_matrix) {
  18659. var l = LENGTH;
  18660. for (var i = 0; i < l; i++) {
  18661. this.matrix[i] = p_matrix[i];
  18662. }
  18663. };
  18664. ColorMatrix.prototype.multiplyMatrix = function (p_matrix) {
  18665. var col = [];
  18666. var i = 0;
  18667. for (var y = 0; y < 4; ++y) {
  18668. for (var x = 0; x < 5; ++x) {
  18669. col[i + x] = p_matrix[i] * this.matrix[x] +
  18670. p_matrix[i + 1] * this.matrix[x + 5] +
  18671. p_matrix[i + 2] * this.matrix[x + 10] +
  18672. p_matrix[i + 3] * this.matrix[x + 15] +
  18673. (x == 4 ? p_matrix[i + 4] : 0);
  18674. }
  18675. i += 5;
  18676. }
  18677. this.copyMatrix(col);
  18678. };
  18679. ColorMatrix.prototype.cleanValue = function (p_val, p_limit) {
  18680. return Math.min(p_limit, Math.max(-p_limit, p_val));
  18681. };
  18682. return ColorMatrix;
  18683. }());
  18684. fgui.ColorMatrix = ColorMatrix;
  18685. var IDENTITY_MATRIX = [
  18686. 1, 0, 0, 0, 0,
  18687. 0, 1, 0, 0, 0,
  18688. 0, 0, 1, 0, 0,
  18689. 0, 0, 0, 1, 0
  18690. ];
  18691. var LENGTH = IDENTITY_MATRIX.length;
  18692. var LUMA_R = 0.299;
  18693. var LUMA_G = 0.587;
  18694. var LUMA_B = 0.114;
  18695. })(fgui || (fgui = {}));
  18696. (function (fgui) {
  18697. var UBBParser = (function () {
  18698. function UBBParser() {
  18699. this._readPos = 0;
  18700. this._handlers = {};
  18701. this._handlers["url"] = this.onTag_URL;
  18702. this._handlers["img"] = this.onTag_IMG;
  18703. this._handlers["b"] = this.onTag_Simple;
  18704. this._handlers["i"] = this.onTag_Simple;
  18705. this._handlers["u"] = this.onTag_Simple;
  18706. this._handlers["color"] = this.onTag_COLOR;
  18707. this._handlers["size"] = this.onTag_SIZE;
  18708. }
  18709. UBBParser.prototype.onTag_URL = function (tagName, end, attr) {
  18710. if (!end) {
  18711. var ret = void 0;
  18712. if (attr != null)
  18713. ret = "<on click=\"onClickLink\" param=\"" + attr + "\">";
  18714. else {
  18715. var href = this.getTagText();
  18716. ret = "<on click=\"onClickLink\" param=\"" + href + "\">";
  18717. }
  18718. if (this.linkUnderline)
  18719. ret += "<u>";
  18720. if (this.linkColor)
  18721. ret += "<color=" + this.linkColor + ">";
  18722. return ret;
  18723. }
  18724. else {
  18725. var ret = "";
  18726. if (this.linkColor)
  18727. ret += "</color>";
  18728. if (this.linkUnderline)
  18729. ret += "</u>";
  18730. ret += "</on>";
  18731. return ret;
  18732. }
  18733. };
  18734. UBBParser.prototype.onTag_IMG = function (tagName, end, attr) {
  18735. if (!end) {
  18736. var src = this.getTagText(true);
  18737. if (!src)
  18738. return null;
  18739. return "<img src=\"" + src + "\"/>";
  18740. }
  18741. else
  18742. return null;
  18743. };
  18744. UBBParser.prototype.onTag_Simple = function (tagName, end, attr) {
  18745. return end ? ("</" + tagName + ">") : ("<" + tagName + ">");
  18746. };
  18747. UBBParser.prototype.onTag_COLOR = function (tagName, end, attr) {
  18748. if (!end) {
  18749. this.lastColor = attr;
  18750. return "<color=" + attr + ">";
  18751. }
  18752. else
  18753. return "</color>";
  18754. };
  18755. UBBParser.prototype.onTag_FONT = function (tagName, end, attr) {
  18756. if (!end)
  18757. return "<font face=\"" + attr + "\">";
  18758. else
  18759. return "</font>";
  18760. };
  18761. UBBParser.prototype.onTag_SIZE = function (tagName, end, attr) {
  18762. if (!end) {
  18763. this.lastSize = attr;
  18764. return "<size=" + attr + ">";
  18765. }
  18766. else
  18767. return "</size>";
  18768. };
  18769. UBBParser.prototype.getTagText = function (remove) {
  18770. var pos1 = this._readPos;
  18771. var pos2;
  18772. var result = "";
  18773. while ((pos2 = this._text.indexOf("[", pos1)) != -1) {
  18774. if (this._text.charCodeAt(pos2 - 1) == 92) {
  18775. result += this._text.substring(pos1, pos2 - 1);
  18776. result += "[";
  18777. pos1 = pos2 + 1;
  18778. }
  18779. else {
  18780. result += this._text.substring(pos1, pos2);
  18781. break;
  18782. }
  18783. }
  18784. if (pos2 == -1)
  18785. return null;
  18786. if (remove)
  18787. this._readPos = pos2;
  18788. return result;
  18789. };
  18790. UBBParser.prototype.parse = function (text, remove) {
  18791. this._text = text;
  18792. this.lastColor = null;
  18793. this.lastSize = null;
  18794. var pos1 = 0, pos2, pos3;
  18795. var end;
  18796. var tag, attr;
  18797. var repl;
  18798. var func;
  18799. var result = "";
  18800. while ((pos2 = this._text.indexOf("[", pos1)) != -1) {
  18801. if (pos2 > 0 && this._text.charCodeAt(pos2 - 1) == 92) {
  18802. result += this._text.substring(pos1, pos2 - 1);
  18803. result += "[";
  18804. pos1 = pos2 + 1;
  18805. continue;
  18806. }
  18807. result += this._text.substring(pos1, pos2);
  18808. pos1 = pos2;
  18809. pos2 = this._text.indexOf("]", pos1);
  18810. if (pos2 == -1)
  18811. break;
  18812. end = this._text.charAt(pos1 + 1) == '/';
  18813. tag = this._text.substring(end ? pos1 + 2 : pos1 + 1, pos2);
  18814. this._readPos = pos2 + 1;
  18815. attr = null;
  18816. repl = null;
  18817. pos3 = tag.indexOf("=");
  18818. if (pos3 != -1) {
  18819. attr = tag.substring(pos3 + 1);
  18820. tag = tag.substring(0, pos3);
  18821. }
  18822. tag = tag.toLowerCase();
  18823. func = this._handlers[tag];
  18824. if (func != null) {
  18825. repl = func.call(this, tag, end, attr);
  18826. if (repl != null && !remove)
  18827. result += repl;
  18828. }
  18829. else
  18830. result += this._text.substring(pos1, this._readPos);
  18831. pos1 = this._readPos;
  18832. }
  18833. if (pos1 < this._text.length)
  18834. result += this._text.substr(pos1);
  18835. this._text = null;
  18836. return result;
  18837. };
  18838. UBBParser.inst = new UBBParser();
  18839. return UBBParser;
  18840. }());
  18841. fgui.UBBParser = UBBParser;
  18842. })(fgui || (fgui = {}));
  18843. (function (fgui) {
  18844. var ToolSet = (function () {
  18845. function ToolSet() {
  18846. }
  18847. ToolSet.startsWith = function (source, str, ignoreCase) {
  18848. if (!source)
  18849. return false;
  18850. else if (source.length < str.length)
  18851. return false;
  18852. else {
  18853. source = source.substring(0, str.length);
  18854. if (!ignoreCase)
  18855. return source == str;
  18856. else
  18857. return source.toLowerCase() == str.toLowerCase();
  18858. }
  18859. };
  18860. ToolSet.encodeHTML = function (str) {
  18861. if (!str)
  18862. return "";
  18863. else
  18864. return str.replace(/&/g, "&amp;").replace(/</g, "&lt;")
  18865. .replace(/>/g, "&gt;").replace(/'/g, "&apos;").replace(/"/g, "&quot;");
  18866. };
  18867. ToolSet.clamp = function (value, min, max) {
  18868. if (value < min)
  18869. value = min;
  18870. else if (value > max)
  18871. value = max;
  18872. return value;
  18873. };
  18874. ToolSet.clamp01 = function (value) {
  18875. if (value > 1)
  18876. value = 1;
  18877. else if (value < 0)
  18878. value = 0;
  18879. return value;
  18880. };
  18881. ToolSet.lerp = function (start, end, percent) {
  18882. return (start + percent * (end - start));
  18883. };
  18884. ToolSet.getTime = function () {
  18885. var currentTime = new Date();
  18886. return currentTime.getMilliseconds() / 1000;
  18887. };
  18888. ToolSet.toGrayed = function (c) {
  18889. var v = c.getR() * 0.299 + c.getG() * 0.587 + c.getB() * 0.114;
  18890. return new cc.Color(v, v, v, c.getA());
  18891. };
  18892. ToolSet.repeat = function (t, length) {
  18893. return t - Math.floor(t / length) * length;
  18894. };
  18895. ToolSet.distance = function (x1, y1, x2, y2) {
  18896. return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
  18897. };
  18898. return ToolSet;
  18899. }());
  18900. fgui.ToolSet = ToolSet;
  18901. })(fgui || (fgui = {}));